git.delta.rocks / unique-network / refs/commits / 74c60c798ed6

difftreelog

CORE-300 Add tests

Trubnikov Sergey2022-03-18parent: #d030d8a.patch.diff
in: master

3 files changed

modifiedpallets/unique/src/tests.rsdiffbeforeafterboth
18use super::*;18use super::*;
19use crate::mock::*;19use crate::mock::*;
20use crate::{AccessMode, CollectionMode};20use crate::{AccessMode, CollectionMode};
21use sp_runtime::AccountId32;
21use up_data_structs::{22use up_data_structs::{
22 COLLECTION_NUMBER_LIMIT, CollectionId, CreateItemData, CreateFungibleData, CreateNftData,23 COLLECTION_NUMBER_LIMIT, CollectionId, CreateItemData, CreateFungibleData, CreateNftData,
23 CreateReFungibleData, MAX_DECIMAL_POINTS, COLLECTION_ADMINS_LIMIT, MetaUpdatePermission,24 CreateReFungibleData, MAX_DECIMAL_POINTS, COLLECTION_ADMINS_LIMIT, MetaUpdatePermission,
2855 });2856 });
2856}2857}
28572858
2859#[test]
2860fn collection_sponsoring() {
2861 new_test_ext().execute_with(|| {
2862 // default_limits();
2863 let user1 = 1_u64;
2864 let user2 = 777_u64;
2865 let origin1 = Origin::signed(user1);
2866 let origin2 = Origin::signed(user2);
2867 let account2 = account(user2);
2868
2869 let collection_id =
2870 create_test_collection_for_owner(&CollectionMode::NFT, user1, CollectionId(1));
2871 assert_ok!(TemplateModule::set_collection_sponsor(origin1.clone(), collection_id, user1));
2872 assert_ok!(TemplateModule::confirm_sponsorship(origin1.clone(), collection_id));
2873
2874 // Expect error while have no permissions
2875 assert!(TemplateModule::create_item(origin2.clone(), collection_id, account2.clone(), default_nft_data().into()).is_err());
2876
2877 assert_ok!(TemplateModule::set_public_access_mode(origin1.clone(), collection_id, AccessMode::AllowList));
2878 assert_ok!(TemplateModule::add_to_allow_list(origin1.clone(), collection_id, account2.clone()));
2879 assert_ok!(TemplateModule::set_mint_permission(origin1.clone(), collection_id, true));
2880
2881 assert_eq!(<pallet_balances::Pallet<Test>>::free_balance(user2), 0);
2882 let balance_before = <pallet_balances::Pallet<Test>>::free_balance(user1);
2883
2884 assert_ok!(TemplateModule::create_item(origin2, collection_id, account2, default_nft_data().into()));
2885 let balance_after = <pallet_balances::Pallet<Test>>::free_balance(user1);
2886 assert_ne!(balance_before, balance_after);
2887 });
2888}
modifiedtests/src/eth/contractSponsoring.test.tsdiffbeforeafterboth
24 itWeb3,24 itWeb3,
25 SponsoringMode,25 SponsoringMode,
26 createEthAccount,26 createEthAccount,
27 collectionIdToAddress,
28 GAS_ARGS,
29 normalizeEvents,
27} from './util/helpers';30} from './util/helpers';
31import {
32 createCollectionExpectSuccess,
33 createItemExpectSuccess,
34 getCreateCollectionResult,
35 normalizeAccountId,
36 toSubstrateAddress,
37} from '../util/helpers';
38import nonFungibleAbi from './nonFungibleAbi.json';
39import {
40 submitTransactionAsync,
41} from '../substrate/substrate-api';
42import { evmToAddress } from '@polkadot/util-crypto';
2843
29describe('Sponsoring EVM contracts', () => {44describe('Sponsoring EVM contracts', () => {
30 itWeb3('Sponsoring can be set by the address that has deployed the contract', async ({api, web3}) => {45 itWeb3('Sponsoring can be set by the address that has deployed the contract', async ({api, web3}) => {
222
223
224
225 itWeb3.only('Sponsoring evm address from substrate collection', async ({api, web3}) => {
226 const owner = privateKey('//Alice');
227 const userEth = createEthAccount(web3);
228 const userSub = evmToAddress(userEth);
229 const collectionId = await createCollectionExpectSuccess();
230
231 {
232 const tx = api.tx.unique.setCollectionSponsor(collectionId, owner.address);
233 const events = await submitTransactionAsync(owner, tx);
234 const result = getCreateCollectionResult(events);
235 expect(result.success).to.be.true;
236 }
237 {
238 const tx = api.tx.unique.confirmSponsorship(collectionId);
239 const events = await submitTransactionAsync(owner, tx);
240 const result = getCreateCollectionResult(events);
241 expect(result.success).to.be.true;
242 }
243
244 const address = collectionIdToAddress(collectionId);
245 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: userEth, ...GAS_ARGS});
246 const receiver = createEthAccount(web3);
247
248 {
249 const nextTokenId = await contract.methods.nextTokenId().call();
250 expect(nextTokenId).to.be.equal('1');
251 // const result = await contract.methods.mintWithTokenURI(
252 // receiver,
253 // nextTokenId,
254 // 'Test URI',
255 // ).send({from: userEth});
256 // const events = normalizeEvents(result.events);
257
258 // expect(events).to.be.deep.equal([
259 // {
260 // address,
261 // event: 'Transfer',
262 // args: {
263 // from: '0x0000000000000000000000000000000000000000',
264 // to: receiver,
265 // tokenId: nextTokenId,
266 // },
267 // },
268 // ]);
269
270 // expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');
271 }
272
273 {
274 const tx = api.tx.unique.setPublicAccessMode(collectionId, 'AllowList');
275 const events = await submitTransactionAsync(owner, tx);
276 const result = getCreateCollectionResult(events);
277 expect(result.success).to.be.true;
278 }
279 {
280 const tx = api.tx.unique.addToAllowList(collectionId, {Ethereum: userEth});
281 const events = await submitTransactionAsync(owner, tx);
282 const result = getCreateCollectionResult(events);
283 expect(result.success).to.be.true;
284 }
285 {
286 const tx = api.tx.unique.setMintPermission(collectionId, true);
287 const events = await submitTransactionAsync(owner, tx);
288 const result = getCreateCollectionResult(events);
289 expect(result.success).to.be.true;
290 }
291 {
292 const nextTokenId = await contract.methods.nextTokenId().call();
293 expect(nextTokenId).to.be.equal('1');
294 // const result = await contract.methods.mintWithTokenURI(
295 // receiver,
296 // nextTokenId,
297 // 'Test URI',
298 // ).send({from: userEth});
299 // const events = normalizeEvents(result.events);
300
301 // expect(events).to.be.deep.equal([
302 // {
303 // address,
304 // event: 'Transfer',
305 // args: {
306 // from: '0x0000000000000000000000000000000000000000',
307 // to: receiver,
308 // tokenId: nextTokenId,
309 // },
310 // },
311 // ]);
312
313 // expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');
314 }
315
316 });
202});317});
203318
modifiedtests/src/eth/util/helpers.tsdiffbeforeafterboth
241 return collector;241 return collector;
242}242}
243243
244/**
245 * pallet evm_contract_helpers
246 * @param web3
247 * @param caller - eth address
248 * @returns
249 */
244export function contractHelpers(web3: Web3, caller: string) {250export function contractHelpers(web3: Web3, caller: string) {
245 return new web3.eth.Contract(contractHelpersAbi as any, '0x842899ECF380553E8a4de75bF534cdf6fBF64049', {from: caller, ...GAS_ARGS});251 return new web3.eth.Contract(contractHelpersAbi as any, '0x842899ECF380553E8a4de75bF534cdf6fBF64049', {from: caller, ...GAS_ARGS});
246}252}