git.delta.rocks / unique-network / refs/commits / 369492c78777

difftreelog

test upgrade for split pallets

Yaroslav Bolyukin2021-11-04parent: #7ac9c8c.patch.diff
in: master

77 files changed

modifiedtests/.eslintrc.jsondiffbeforeafterboth
63 {63 {
64 "destructuring": "all"64 "destructuring": "all"
65 }65 }
66 ]66 ],
67 "object-curly-spacing": "warn",
68 "arrow-spacing": "warn",
69 "array-bracket-spacing": "warn",
70 "template-curly-spacing": "warn",
71 "space-in-parens": "warn",
72 "@typescript-eslint/naming-convention": [
73 "warn",
74 {
75 "selector": "default",
76 "format": [
77 "camelCase"
78 ],
79 "leadingUnderscore": "allow",
80 "trailingUnderscore": "allow"
81 },
82 {
83 "selector": "variable",
84 "format": [
85 "camelCase",
86 "UPPER_CASE"
87 ],
88 "leadingUnderscore": "allow",
89 "trailingUnderscore": "allow"
90 },
91 {
92 "selector": "typeLike",
93 "format": [
94 "PascalCase"
95 ]
96 },
97 {
98 "selector": "memberLike",
99 "format": null
100 }
101 ]
67 }102 }
68}103}
104
modifiedtests/src/addCollectionAdmin.test.tsdiffbeforeafterboth
8import chaiAsPromised from 'chai-as-promised';8import chaiAsPromised from 'chai-as-promised';
9import privateKey from './substrate/privateKey';9import privateKey from './substrate/privateKey';
10import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from './substrate/substrate-api';10import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';
11import {createCollectionExpectSuccess, destroyCollectionExpectSuccess, normalizeAccountId} from './util/helpers';11import {addCollectionAdminExpectSuccess, createCollectionExpectSuccess, destroyCollectionExpectSuccess, getAdminList, normalizeAccountId} from './util/helpers';
1212
13chai.use(chaiAsPromised);13chai.use(chaiAsPromised);
14const expect = chai.expect;14const expect = chai.expect;
20 const alice = privateKey('//Alice');20 const alice = privateKey('//Alice');
21 const bob = privateKey('//Bob');21 const bob = privateKey('//Bob');
2222
23 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();23 const collection = (await api.query.common.collectionById(collectionId)).unwrap();
24 expect(collection.owner).to.be.equal(alice.address);24 expect(collection.owner.toString()).to.be.equal(alice.address);
2525
26 const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));26 const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));
27 await submitTransactionAsync(alice, changeAdminTx);27 await submitTransactionAsync(alice, changeAdminTx);
2828
29 const adminListAfterAddAdmin: any = (await api.query.nft.adminList(collectionId));29 const adminListAfterAddAdmin = await getAdminList(api, collectionId);
30 expect(adminListAfterAddAdmin).to.be.contains(normalizeAccountId(bob.address));30 expect(adminListAfterAddAdmin).to.be.deep.contains(normalizeAccountId(bob.address));
31 });31 });
32 });32 });
3333
34 it('Add admin using added collection admin.', async () => {34 it('Add admin using added collection admin.', async () => {
35 await usingApi(async (api) => {35 await usingApi(async (api) => {
36 const collectionId = await createCollectionExpectSuccess();36 const collectionId = await createCollectionExpectSuccess();
37 const Alice = privateKey('//Alice');37 const alice = privateKey('//Alice');
38 const Bob = privateKey('//Bob');38 const bob = privateKey('//Bob');
39 const Charlie = privateKey('//CHARLIE');39 const charlie = privateKey('//CHARLIE');
4040
41 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();41 const collection = (await api.query.common.collectionById(collectionId)).unwrap();
42 expect(collection.owner).to.be.equal(Alice.address);42 expect(collection.owner.toString()).to.be.equal(alice.address);
4343
44 const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Bob.address));44 const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));
45 await submitTransactionAsync(Alice, changeAdminTx);45 await submitTransactionAsync(alice, changeAdminTx);
4646
47 const adminListAfterAddAdmin: any = (await api.query.nft.adminList(collectionId));47 const adminListAfterAddAdmin = await getAdminList(api, collectionId);
48 expect(adminListAfterAddAdmin).to.be.contains(normalizeAccountId(Bob.address));48 expect(adminListAfterAddAdmin).to.be.deep.contains(normalizeAccountId(bob.address));
4949
50 const changeAdminTxCharlie = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Charlie.address));50 const changeAdminTxCharlie = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(charlie.address));
51 await submitTransactionAsync(Bob, changeAdminTxCharlie);51 await submitTransactionAsync(bob, changeAdminTxCharlie);
52 const adminListAfterAddNewAdmin: any = (await api.query.nft.adminList(collectionId));52 const adminListAfterAddNewAdmin = await getAdminList(api, collectionId);
53 expect(adminListAfterAddNewAdmin).to.be.contains(normalizeAccountId(Bob.address));53 expect(adminListAfterAddNewAdmin).to.be.deep.contains(normalizeAccountId(bob.address));
54 expect(adminListAfterAddNewAdmin).to.be.contains(normalizeAccountId(Charlie.address));54 expect(adminListAfterAddNewAdmin).to.be.deep.contains(normalizeAccountId(charlie.address));
55 });55 });
56 });56 });
57});57});
66 const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(alice.address));66 const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(alice.address));
67 await expect(submitTransactionExpectFailAsync(nonOwner, changeAdminTx)).to.be.rejected;67 await expect(submitTransactionExpectFailAsync(nonOwner, changeAdminTx)).to.be.rejected;
6868
69 const adminListAfterAddAdmin: any = (await api.query.nft.adminList(collectionId));69 const adminListAfterAddAdmin = await getAdminList(api, collectionId);
70 expect(adminListAfterAddAdmin).not.to.be.contains(normalizeAccountId(alice.address));70 expect(adminListAfterAddAdmin).not.to.be.deep.contains(normalizeAccountId(alice.address));
7171
72 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)72 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)
73 await createCollectionExpectSuccess();73 await createCollectionExpectSuccess();
91 it("Can't add an admin to a destroyed collection.", async () => {91 it("Can't add an admin to a destroyed collection.", async () => {
92 await usingApi(async (api) => {92 await usingApi(async (api) => {
93 const collectionId = await createCollectionExpectSuccess();93 const collectionId = await createCollectionExpectSuccess();
94 const Alice = privateKey('//Alice');94 const alice = privateKey('//Alice');
95 const Bob = privateKey('//Bob');95 const bob = privateKey('//Bob');
96 await destroyCollectionExpectSuccess(collectionId);96 await destroyCollectionExpectSuccess(collectionId);
97 const changeOwnerTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Bob.address));97 const changeOwnerTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));
98 await expect(submitTransactionExpectFailAsync(Alice, changeOwnerTx)).to.be.rejected;98 await expect(submitTransactionExpectFailAsync(alice, changeOwnerTx)).to.be.rejected;
9999
100 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)100 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)
101 await createCollectionExpectSuccess();101 await createCollectionExpectSuccess();
104104
105 it('Add an admin to a collection that has reached the maximum number of admins limit', async () => {105 it('Add an admin to a collection that has reached the maximum number of admins limit', async () => {
106 await usingApi(async (api: ApiPromise) => {106 await usingApi(async (api: ApiPromise) => {
107 const Alice = privateKey('//Alice');107 const alice = privateKey('//Alice');
108 const accounts = [108 const accounts = [
109 'GsvVmjr1CBHwQHw84pPHMDxgNY3iBLz6Qn7qS3CH8qPhrHz',109 privateKey('//AdminTest/1').address,
110 'FoQJpPyadYccjavVdTWxpxU7rUEaYhfLCPwXgkfD6Zat9QP',110 privateKey('//AdminTest/2').address,
111 'JKspFU6ohf1Grg3Phdzj2pSgWvsYWzSfKghhfzMbdhNBWs5',111 privateKey('//AdminTest/3').address,
112 'Fr4NzY1udSFFLzb2R3qxVQkwz9cZraWkyfH4h3mVVk7BK7P',112 privateKey('//AdminTest/4').address,
113 'DfnTB4z7eUvYRqcGtTpFsLC69o6tvBSC1pEv8vWPZFtCkaK',113 privateKey('//AdminTest/5').address,
114 'HnMAUz7r2G8G3hB27SYNyit5aJmh2a5P4eMdDtACtMFDbam',114 privateKey('//AdminTest/6').address,
115 'DE14BzQ1bDXWPKeLoAqdLAm1GpyAWaWF1knF74cEZeomTBM',115 privateKey('//AdminTest/7').address,
116 ];116 ];
117 const collectionId = await createCollectionExpectSuccess();117 const collectionId = await createCollectionExpectSuccess();
118118
119 const chainAdminLimit = (api.consts.nft.collectionAdminsLimit as any).toNumber();119 const chainAdminLimit = api.consts.common.collectionAdminsLimit.toNumber();
120 expect(chainAdminLimit).to.be.equal(5);120 expect(chainAdminLimit).to.be.equal(5);
121121
122 for (let i = 0; i < chainAdminLimit; i++) {122 for (let i = 0; i < chainAdminLimit; i++) {
123 const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(accounts[i]));123 await addCollectionAdminExpectSuccess(alice, collectionId, accounts[i]);
124 await submitTransactionAsync(Alice, changeAdminTx);
125 const adminListAfterAddAdmin: any = (await api.query.nft.adminList(collectionId));124 const adminListAfterAddAdmin = await getAdminList(api, collectionId);
126 expect(adminListAfterAddAdmin).to.be.contains(normalizeAccountId(accounts[i]));125 expect(adminListAfterAddAdmin).to.be.deep.contains(normalizeAccountId(accounts[i]));
127 }126 }
128127
129 const tx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(accounts[chainAdminLimit]));128 const tx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(accounts[chainAdminLimit]));
130 await expect(submitTransactionExpectFailAsync(Alice, tx)).to.be.rejected;129 await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;
131 });130 });
132 });131 });
133});132});
modifiedtests/src/addToContractWhiteList.test.tsdiffbeforeafterboth

no syntactic changes

modifiedtests/src/addToWhiteList.test.tsdiffbeforeafterboth
23chai.use(chaiAsPromised);23chai.use(chaiAsPromised);
24const expect = chai.expect;24const expect = chai.expect;
2525
26let Alice: IKeyringPair;26let alice: IKeyringPair;
27let Bob: IKeyringPair;27let bob: IKeyringPair;
28let Charlie: IKeyringPair;28let charlie: IKeyringPair;
2929
30describe('Integration Test ext. addToWhiteList()', () => {30describe('Integration Test ext. addToWhiteList()', () => {
3131
32 before(async () => {32 before(async () => {
33 await usingApi(async () => {33 await usingApi(async () => {
34 Alice = privateKey('//Alice');34 alice = privateKey('//Alice');
35 Bob = privateKey('//Bob');35 bob = privateKey('//Bob');
36 });36 });
37 });37 });
3838
39 it('Execute the extrinsic with parameters: Collection ID and address to add to the white list', async () => {39 it('Execute the extrinsic with parameters: Collection ID and address to add to the white list', async () => {
40 const collectionId = await createCollectionExpectSuccess();40 const collectionId = await createCollectionExpectSuccess();
41 await addToWhiteListExpectSuccess(Alice, collectionId, Bob.address);41 await addToWhiteListExpectSuccess(alice, collectionId, bob.address);
42 });42 });
4343
44 it('Whitelisted minting: list restrictions', async () => {44 it('Whitelisted minting: list restrictions', async () => {
45 const collectionId = await createCollectionExpectSuccess();45 const collectionId = await createCollectionExpectSuccess();
46 await addToWhiteListExpectSuccess(Alice, collectionId, Bob.address);46 await addToWhiteListExpectSuccess(alice, collectionId, bob.address);
47 await enableWhiteListExpectSuccess(Alice, collectionId);47 await enableWhiteListExpectSuccess(alice, collectionId);
48 await enablePublicMintingExpectSuccess(Alice, collectionId);48 await enablePublicMintingExpectSuccess(alice, collectionId);
49 await createItemExpectSuccess(Bob, collectionId, 'NFT', Bob.address);49 await createItemExpectSuccess(bob, collectionId, 'NFT', bob.address);
50 });50 });
51});51});
5252
55 it('White list an address in the collection that does not exist', async () => {55 it('White list an address in the collection that does not exist', async () => {
56 await usingApi(async (api) => {56 await usingApi(async (api) => {
57 // tslint:disable-next-line: no-bitwise57 // tslint:disable-next-line: no-bitwise
58 const collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;58 const collectionId = ((await api.query.common.createdCollectionCount()).toNumber()) + 1;
59 const Bob = privateKey('//Bob');59 const bob = privateKey('//Bob');
6060
61 const tx = api.tx.nft.addToWhiteList(collectionId, normalizeAccountId(Bob.address));61 const tx = api.tx.nft.addToWhiteList(collectionId, normalizeAccountId(bob.address));
62 await expect(submitTransactionExpectFailAsync(Alice, tx)).to.be.rejected;62 await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;
63 });63 });
64 });64 });
6565
66 it('White list an address in the collection that was destroyed', async () => {66 it('White list an address in the collection that was destroyed', async () => {
67 await usingApi(async (api) => {67 await usingApi(async (api) => {
68 const Alice = privateKey('//Alice');68 const alice = privateKey('//Alice');
69 const Bob = privateKey('//Bob');69 const bob = privateKey('//Bob');
70 // tslint:disable-next-line: no-bitwise70 // tslint:disable-next-line: no-bitwise
71 const collectionId = await createCollectionExpectSuccess();71 const collectionId = await createCollectionExpectSuccess();
72 await destroyCollectionExpectSuccess(collectionId);72 await destroyCollectionExpectSuccess(collectionId);
73 const tx = api.tx.nft.addToWhiteList(collectionId, normalizeAccountId(Bob.address));73 const tx = api.tx.nft.addToWhiteList(collectionId, normalizeAccountId(bob.address));
74 await expect(submitTransactionExpectFailAsync(Alice, tx)).to.be.rejected;74 await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;
75 });75 });
76 });76 });
7777
78 it('White list an address in the collection that does not have white list access enabled', async () => {78 it('White list an address in the collection that does not have white list access enabled', async () => {
79 await usingApi(async (api) => {79 await usingApi(async (api) => {
80 const Alice = privateKey('//Alice');80 const alice = privateKey('//Alice');
81 const Ferdie = privateKey('//Ferdie');81 const ferdie = privateKey('//Ferdie');
82 const collectionId = await createCollectionExpectSuccess();82 const collectionId = await createCollectionExpectSuccess();
83 await enableWhiteListExpectSuccess(Alice, collectionId);83 await enableWhiteListExpectSuccess(alice, collectionId);
84 await enablePublicMintingExpectSuccess(Alice, collectionId);84 await enablePublicMintingExpectSuccess(alice, collectionId);
85 const tx = api.tx.nft.createItem(collectionId, normalizeAccountId(Ferdie.address), 'NFT');85 const tx = api.tx.nft.createItem(collectionId, normalizeAccountId(ferdie.address), 'NFT');
86 await expect(submitTransactionExpectFailAsync(Ferdie, tx)).to.be.rejected;86 await expect(submitTransactionExpectFailAsync(ferdie, tx)).to.be.rejected;
87 });87 });
88 });88 });
8989
9393
94 before(async () => {94 before(async () => {
95 await usingApi(async () => {95 await usingApi(async () => {
96 Alice = privateKey('//Alice');96 alice = privateKey('//Alice');
97 Bob = privateKey('//Bob');97 bob = privateKey('//Bob');
98 Charlie = privateKey('//Charlie');98 charlie = privateKey('//Charlie');
99 });99 });
100 });100 });
101101
102 it('Negative. Add to the white list by regular user', async () => {102 it('Negative. Add to the white list by regular user', async () => {
103 const collectionId = await createCollectionExpectSuccess();103 const collectionId = await createCollectionExpectSuccess();
104 await addToWhiteListExpectFail(Bob, collectionId, Charlie.address);104 await addToWhiteListExpectFail(bob, collectionId, charlie.address);
105 });105 });
106106
107 it('Execute the extrinsic with parameters: Collection ID and address to add to the white list', async () => {107 it('Execute the extrinsic with parameters: Collection ID and address to add to the white list', async () => {
108 const collectionId = await createCollectionExpectSuccess();108 const collectionId = await createCollectionExpectSuccess();
109 await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);109 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
110 await addToWhiteListExpectSuccess(Bob, collectionId, Charlie.address);110 await addToWhiteListExpectSuccess(bob, collectionId, charlie.address);
111 });111 });
112112
113 it('Whitelisted minting: list restrictions', async () => {113 it('Whitelisted minting: list restrictions', async () => {
114 const collectionId = await createCollectionExpectSuccess();114 const collectionId = await createCollectionExpectSuccess();
115 await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);115 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
116 await addToWhiteListExpectSuccess(Bob, collectionId, Charlie.address);116 await addToWhiteListExpectSuccess(bob, collectionId, charlie.address);
117117
118 // allowed only for collection owner118 // allowed only for collection owner
119 await enableWhiteListExpectSuccess(Alice, collectionId);119 await enableWhiteListExpectSuccess(alice, collectionId);
120 await enablePublicMintingExpectSuccess(Alice, collectionId);120 await enablePublicMintingExpectSuccess(alice, collectionId);
121121
122 await createItemExpectSuccess(Charlie, collectionId, 'NFT', Charlie.address);122 await createItemExpectSuccess(charlie, collectionId, 'NFT', charlie.address);
123 });123 });
124});124});
125
modifiedtests/src/approve.test.tsdiffbeforeafterboth
17 setCollectionLimitsExpectSuccess,17 setCollectionLimitsExpectSuccess,
18 transferExpectSuccess,18 transferExpectSuccess,
19 addCollectionAdminExpectSuccess,19 addCollectionAdminExpectSuccess,
20 adminApproveFromExpectSuccess,
20} from './util/helpers';21} from './util/helpers';
2122
22chai.use(chaiAsPromised);23chai.use(chaiAsPromised);
2324
24describe('Integration Test approve(spender, collection_id, item_id, amount):', () => {25describe('Integration Test approve(spender, collection_id, item_id, amount):', () => {
25 let Alice: IKeyringPair;26 let alice: IKeyringPair;
26 let Bob: IKeyringPair;27 let bob: IKeyringPair;
27 let Charlie: IKeyringPair;28 let charlie: IKeyringPair;
2829
29 before(async () => {30 before(async () => {
30 await usingApi(async () => {31 await usingApi(async () => {
31 Alice = privateKey('//Alice');32 alice = privateKey('//Alice');
32 Bob = privateKey('//Bob');33 bob = privateKey('//Bob');
33 Charlie = privateKey('//Charlie');34 charlie = privateKey('//Charlie');
34 });35 });
35 });36 });
3637
37 it('Execute the extrinsic and check approvedList', async () => {38 it('Execute the extrinsic and check approvedList', async () => {
38 const nftCollectionId = await createCollectionExpectSuccess();39 const nftCollectionId = await createCollectionExpectSuccess();
39 // nft40 // nft
40 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');41 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
41 await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob);42 await approveExpectSuccess(nftCollectionId, newNftTokenId, alice, bob.address);
42 // fungible43 // fungible
43 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});44 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
44 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');45 const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');
45 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);46 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob.address);
46 // reFungible47 // reFungible
47 const reFungibleCollectionId =48 const reFungibleCollectionId =
48 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});49 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
49 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');50 const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');
50 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);51 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, alice, bob.address);
51 });52 });
5253
53 it('Remove approval by using 0 amount', async () => {54 it('Remove approval by using 0 amount', async () => {
54 const nftCollectionId = await createCollectionExpectSuccess();55 const nftCollectionId = await createCollectionExpectSuccess();
55 // nft56 // nft
56 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');57 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
57 await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 1);58 await approveExpectSuccess(nftCollectionId, newNftTokenId, alice, bob.address, 1);
58 await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 0);59 await approveExpectSuccess(nftCollectionId, newNftTokenId, alice, bob.address, 0);
59 // fungible60 // fungible
60 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});61 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
61 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');62 const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');
62 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob, 1);63 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob.address, 1);
63 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob, 0);64 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob.address, 0);
64 // reFungible65 // reFungible
65 const reFungibleCollectionId =66 const reFungibleCollectionId =
66 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});67 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
67 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');68 const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');
68 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob, 1);69 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, alice, bob.address, 1);
69 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob, 0);70 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, alice, bob.address, 0);
70 });71 });
7172
72 it('can be called by collection owner on non-owned item when OwnerCanTransfer == true', async () => {73 it('can be called by collection owner on non-owned item when OwnerCanTransfer == true', async () => {
73 const collectionId = await createCollectionExpectSuccess();74 const collectionId = await createCollectionExpectSuccess();
74 const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Bob.address);75 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', bob.address);
7576
76 await approveExpectSuccess(collectionId, itemId, Alice, Charlie);77 await adminApproveFromExpectSuccess(collectionId, itemId, alice, bob.address, charlie.address);
77 });78 });
78});79});
7980
80describe('Negative Integration Test approve(spender, collection_id, item_id, amount):', () => {81describe('Negative Integration Test approve(spender, collection_id, item_id, amount):', () => {
81 let Alice: IKeyringPair;82 let alice: IKeyringPair;
82 let Bob: IKeyringPair;83 let bob: IKeyringPair;
83 let Charlie: IKeyringPair;84 let charlie: IKeyringPair;
8485
85 before(async () => {86 before(async () => {
86 await usingApi(async () => {87 await usingApi(async () => {
87 Alice = privateKey('//Alice');88 alice = privateKey('//Alice');
88 Bob = privateKey('//Bob');89 bob = privateKey('//Bob');
89 Charlie = privateKey('//Charlie');90 charlie = privateKey('//Charlie');
90 });91 });
91 });92 });
9293
93 it('Approve for a collection that does not exist', async () => {94 it('Approve for a collection that does not exist', async () => {
94 await usingApi(async (api: ApiPromise) => {95 await usingApi(async (api: ApiPromise) => {
95 // nft96 // nft
96 const nftCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;97 const nftCollectionCount = (await api.query.common.createdCollectionCount()).toNumber();
97 await approveExpectFail(nftCollectionCount + 1, 1, Alice, Bob);98 await approveExpectFail(nftCollectionCount + 1, 1, alice, bob);
98 // fungible99 // fungible
99 const fungibleCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;100 const fungibleCollectionCount = (await api.query.common.createdCollectionCount()).toNumber();
100 await approveExpectFail(fungibleCollectionCount + 1, 1, Alice, Bob);101 await approveExpectFail(fungibleCollectionCount + 1, 0, alice, bob);
101 // reFungible102 // reFungible
102 const reFungibleCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;103 const reFungibleCollectionCount = (await api.query.common.createdCollectionCount()).toNumber();
103 await approveExpectFail(reFungibleCollectionCount + 1, 1, Alice, Bob);104 await approveExpectFail(reFungibleCollectionCount + 1, 1, alice, bob);
104 });105 });
105 });106 });
106107
107 it('Approve for a collection that was destroyed', async () => {108 it('Approve for a collection that was destroyed', async () => {
108 // nft109 // nft
109 const nftCollectionId = await createCollectionExpectSuccess();110 const nftCollectionId = await createCollectionExpectSuccess();
110 await destroyCollectionExpectSuccess(nftCollectionId);111 await destroyCollectionExpectSuccess(nftCollectionId);
111 await approveExpectFail(nftCollectionId, 1, Alice, Bob);112 await approveExpectFail(nftCollectionId, 1, alice, bob);
112 // fungible113 // fungible
113 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});114 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
114 await destroyCollectionExpectSuccess(fungibleCollectionId);115 await destroyCollectionExpectSuccess(fungibleCollectionId);
115 await approveExpectFail(fungibleCollectionId, 1, Alice, Bob);116 await approveExpectFail(fungibleCollectionId, 0, alice, bob);
116 // reFungible117 // reFungible
117 const reFungibleCollectionId =118 const reFungibleCollectionId =
118 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});119 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
119 await destroyCollectionExpectSuccess(reFungibleCollectionId);120 await destroyCollectionExpectSuccess(reFungibleCollectionId);
120 await approveExpectFail(reFungibleCollectionId, 1, Alice, Bob);121 await approveExpectFail(reFungibleCollectionId, 1, alice, bob);
121 });122 });
122123
123 it('Approve transfer of a token that does not exist', async () => {124 it('Approve transfer of a token that does not exist', async () => {
124 // nft125 // nft
125 const nftCollectionId = await createCollectionExpectSuccess();126 const nftCollectionId = await createCollectionExpectSuccess();
126 await approveExpectFail(nftCollectionId, 2, Alice, Bob);127 await approveExpectFail(nftCollectionId, 2, alice, bob);
127 // reFungible128 // reFungible
128 const reFungibleCollectionId =129 const reFungibleCollectionId =
129 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});130 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
130 await approveExpectFail(reFungibleCollectionId, 2, Alice, Bob);131 await approveExpectFail(reFungibleCollectionId, 2, alice, bob);
131 });132 });
132133
133 it('Approve using the address that does not own the approved token', async () => {134 it('Approve using the address that does not own the approved token', async () => {
134 const nftCollectionId = await createCollectionExpectSuccess();135 const nftCollectionId = await createCollectionExpectSuccess();
135 // nft136 // nft
136 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');137 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
137 await approveExpectFail(nftCollectionId, newNftTokenId, Bob, Alice);138 await approveExpectFail(nftCollectionId, newNftTokenId, bob, alice);
138 // fungible139 // fungible
139 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});140 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
140 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');141 const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');
141 await approveExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice);142 await approveExpectFail(fungibleCollectionId, newFungibleTokenId, bob, alice);
142 // reFungible143 // reFungible
143 const reFungibleCollectionId =144 const reFungibleCollectionId =
144 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});145 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
145 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');146 const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');
146 await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, Bob, Alice);147 await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, bob, alice);
147 });148 });
148
149 it('should fail if approved more NFTs than owned', async () => {
150 const nftCollectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });
151 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
152 await transferExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 1, 'NFT');
153 await approveExpectSuccess(nftCollectionId, newNftTokenId, Bob, Alice);
154 await approveExpectFail(nftCollectionId, newNftTokenId, Bob, Alice);
155 });
156149
157 it('should fail if approved more ReFungibles than owned', async () => {150 it('should fail if approved more ReFungibles than owned', async () => {
158 const nftCollectionId = await createCollectionExpectSuccess({ mode: { type: 'ReFungible' } });151 const nftCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
159 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'ReFungible');152 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'ReFungible');
160 await transferExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 100, 'ReFungible');153 await transferExpectSuccess(nftCollectionId, newNftTokenId, alice, bob, 100, 'ReFungible');
161 await approveExpectSuccess(nftCollectionId, newNftTokenId, Bob, Alice, 100);154 await approveExpectSuccess(nftCollectionId, newNftTokenId, bob, alice.address, 100);
162 await approveExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, 1);155 await approveExpectFail(nftCollectionId, newNftTokenId, bob, alice, 101);
163 });156 });
164157
165 it('should fail if approved more Fungibles than owned', async () => {158 it('should fail if approved more Fungibles than owned', async () => {
166 const nftCollectionId = await createCollectionExpectSuccess({ mode: { type: 'Fungible', decimalPoints: 0 } });159 const nftCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
167 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'Fungible');160 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'Fungible');
168 await transferExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 10, 'Fungible');161 await transferExpectSuccess(nftCollectionId, newNftTokenId, alice, bob, 10, 'Fungible');
169 await approveExpectSuccess(nftCollectionId, newNftTokenId, Bob, Alice, 10);162 await approveExpectSuccess(nftCollectionId, newNftTokenId, bob, alice.address, 10);
170 await approveExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, 1);163 await approveExpectFail(nftCollectionId, newNftTokenId, bob, alice, 11);
171 });164 });
172165
173 it('fails when called by collection owner on non-owned item when OwnerCanTransfer == false', async () => {166 it('fails when called by collection owner on non-owned item when OwnerCanTransfer == false', async () => {
174 const collectionId = await createCollectionExpectSuccess();167 const collectionId = await createCollectionExpectSuccess();
175 const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Bob.address);168 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', bob.address);
176 await setCollectionLimitsExpectSuccess(Alice, collectionId, { ownerCanTransfer: false });169 await setCollectionLimitsExpectSuccess(alice, collectionId, {ownerCanTransfer: false});
177170
178 await approveExpectFail(collectionId, itemId, Alice, Charlie);171 await approveExpectFail(collectionId, itemId, alice, charlie);
179 });172 });
180});173});
181174
182describe('Integration Test approve(spender, collection_id, item_id, amount) with collection admin permissions:', () => {175describe('Integration Test approve(spender, collection_id, item_id, amount) with collection admin permissions:', () => {
183 let Alice: IKeyringPair;176 let alice: IKeyringPair;
184 let Bob: IKeyringPair;177 let bob: IKeyringPair;
185 let Charlie: IKeyringPair;178 let charlie: IKeyringPair;
186179
187 before(async () => {180 before(async () => {
188 await usingApi(async () => {181 await usingApi(async () => {
189 Alice = privateKey('//Alice');182 alice = privateKey('//Alice');
190 Bob = privateKey('//Bob');183 bob = privateKey('//Bob');
191 Charlie = privateKey('//Charlie');184 charlie = privateKey('//Charlie');
192 });185 });
193 });186 });
194187
195 it('can be called by collection admin on non-owned item', async () => {188 it('can be called by collection admin on non-owned item', async () => {
196 const collectionId = await createCollectionExpectSuccess();189 const collectionId = await createCollectionExpectSuccess();
197 const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Alice.address);190 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
198191
199 await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);192 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
200 await approveExpectSuccess(collectionId, itemId, Bob, Charlie);193 await adminApproveFromExpectSuccess(collectionId, itemId, bob, alice.address, charlie.address);
201 });194 });
202});195});
203196
modifiedtests/src/block-production.test.tsdiffbeforeafterboth
7import { expect } from 'chai';7import {expect} from 'chai';
8import { ApiPromise } from '@polkadot/api';8import {ApiPromise} from '@polkadot/api';
99
10const BlockTimeMs = 12000;10const BLOCK_TIME_MS = 3000;
11const ToleranceMs = 1000;11const TOLERANCE_MS = 1000;
1212
13/* eslint no-async-promise-executor: "off" */13/* eslint no-async-promise-executor: "off" */
14function getBlocks(api: ApiPromise): Promise<number[]> {14function getBlocks(api: ApiPromise): Promise<number[]> {
15 return new Promise<number[]>(async (resolve, reject) => {15 return new Promise<number[]>(async (resolve, reject) => {
16 const blockNumbers: number[] = [];16 const blockNumbers: number[] = [];
17 setTimeout(() => reject('Block production test failed due to timeout.'), BlockTimeMs + ToleranceMs);17 setTimeout(() => reject('Block production test failed due to timeout.'), BLOCK_TIME_MS + TOLERANCE_MS);
18 const unsubscribe = await api.rpc.chain.subscribeNewHeads((head: any) => {18 const unsubscribe = await api.rpc.chain.subscribeNewHeads((head: any) => {
19 blockNumbers.push(head.number.toNumber());19 blockNumbers.push(head.number.toNumber());
20 if(blockNumbers.length >= 2) {20 if(blockNumbers.length >= 2) {
modifiedtests/src/burnItem.test.tsdiffbeforeafterboth
13 destroyCollectionExpectSuccess,13 destroyCollectionExpectSuccess,
14 normalizeAccountId,14 normalizeAccountId,
15 addCollectionAdminExpectSuccess,15 addCollectionAdminExpectSuccess,
16 getBalance,
17 isTokenExists,
16} from './util/helpers';18} from './util/helpers';
1719
18import chai from 'chai';20import chai from 'chai';
41 const tx = api.tx.nft.burnItem(collectionId, tokenId, 1);43 const tx = api.tx.nft.burnItem(collectionId, tokenId, 1);
42 const events = await submitTransactionAsync(alice, tx);44 const events = await submitTransactionAsync(alice, tx);
43 const result = getGenericResult(events);45 const result = getGenericResult(events);
44 // Get the item46
45 const item: any = (await api.query.nft.nftItemList(collectionId, tokenId)).toJSON();
46 // What to expect
47 // tslint:disable-next-line:no-unused-expression
48 expect(result.success).to.be.true;47 expect(result.success).to.be.true;
49 // tslint:disable-next-line:no-unused-expression48 // Get the item
50 expect(item).to.be.null;49 expect(await isTokenExists(api, collectionId, tokenId)).to.be.false;
51 });50 });
52 });51 });
5352
64 const result = getGenericResult(events);63 const result = getGenericResult(events);
6564
66 // Get alice balance65 // Get alice balance
67 const balance: any = (await api.query.nft.fungibleItemList(collectionId, alice.address)).toJSON();66 const balance = await getBalance(api, collectionId, alice.address, 0);
6867
69 // What to expect68 // What to expect
70 expect(result.success).to.be.true;69 expect(result.success).to.be.true;
71 expect(balance).to.be.not.null;
72 expect(balance.value).to.be.equal(9);70 expect(balance).to.be.equal(9n);
73 });71 });
74 });72 });
7573
84 const result = getGenericResult(events);82 const result = getGenericResult(events);
8583
86 // Get alice balance84 // Get alice balance
87 const balance: any = (await api.query.nft.reFungibleItemList(collectionId, tokenId)).toJSON();85 const balance = await getBalance(api, collectionId, alice.address, tokenId);
8886
89 // What to expect87 // What to expect
90 expect(result.success).to.be.true;88 expect(result.success).to.be.true;
91 expect(balance).to.be.null;89 expect(balance).to.be.equal(0n);
92 });90 });
93 });91 });
9492
104 const result1 = getGenericResult(events1);102 const result1 = getGenericResult(events1);
105103
106 // Get balances104 // Get balances
107 const balanceBefore: any = (await api.query.nft.reFungibleItemList(collectionId, tokenId)).toJSON();105 const bobBalanceBefore = await getBalance(api, collectionId, bob.address, tokenId);
106 const aliceBalanceBefore = await getBalance(api, collectionId, alice.address, tokenId);
108107
109 // Bob burns his portion108 // Bob burns his portion
110 const tx = api.tx.nft.burnItem(collectionId, tokenId, 1);109 const tx = api.tx.nft.burnItem(collectionId, tokenId, 1);
111 const events2 = await submitTransactionAsync(bob, tx);110 const events2 = await submitTransactionAsync(bob, tx);
112 const result2 = getGenericResult(events2);111 const result2 = getGenericResult(events2);
113112
114 // Get balances113 // Get balances
115 const balance: any = (await api.query.nft.reFungibleItemList(collectionId, tokenId)).toJSON();114 const bobBalanceAfter = await getBalance(api, collectionId, bob.address, tokenId);
115 const aliceBalanceAfter = await getBalance(api, collectionId, alice.address, tokenId);
116 // console.log(balance);116 // console.log(balance);
117117
118 // What to expect before burning118 // What to expect before burning
119 expect(result1.success).to.be.true;119 expect(result1.success).to.be.true;
120 expect(balanceBefore).to.be.not.null;
121 expect(balanceBefore.owner.length).to.be.equal(2);120 expect(aliceBalanceBefore).to.be.equal(99n);
122 expect(balanceBefore.owner[0].owner).to.be.deep.equal(normalizeAccountId(alice.address));
123 expect(balanceBefore.owner[0].fraction).to.be.equal(99);121 expect(bobBalanceBefore).to.be.equal(1n);
124 expect(balanceBefore.owner[1].owner).to.be.deep.equal(normalizeAccountId(bob.address));
125 expect(balanceBefore.owner[1].fraction).to.be.equal(1);
126122
127 // What to expect after burning123 // What to expect after burning
128 expect(result2.success).to.be.true;124 expect(result2.success).to.be.true;
129 expect(balance).to.be.not.null;
130 expect(balance.owner.length).to.be.equal(1);125 expect(aliceBalanceAfter).to.be.equal(99n);
131 expect(balance.owner[0].fraction).to.be.equal(99);126 expect(bobBalanceAfter).to.be.equal(0n);
132 expect(balance.owner[0].owner).to.be.deep.equal(normalizeAccountId(alice.address));
133 });127 });
134128
135 });129 });
149 const createMode = 'NFT';143 const createMode = 'NFT';
150 const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}});144 const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}});
151 const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);145 const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);
152 await addCollectionAdminExpectSuccess(alice, collectionId, bob);146 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
153147
154 await usingApi(async (api) => {148 await usingApi(async (api) => {
155 const tx = api.tx.nft.burnItem(collectionId, tokenId, 1);149 const tx = api.tx.nft.burnItem(collectionId, tokenId, 1);
156 const events = await submitTransactionAsync(bob, tx);150 const events = await submitTransactionAsync(bob, tx);
157 const result = getGenericResult(events);151 const result = getGenericResult(events);
158 // Get the item152
159 const item: any = (await api.query.nft.nftItemList(collectionId, tokenId)).toJSON();
160 // What to expect
161 // tslint:disable-next-line:no-unused-expression
162 expect(result.success).to.be.true;153 expect(result.success).to.be.true;
163 // tslint:disable-next-line:no-unused-expression154 // Get the item
164 expect(item).to.be.null;155 expect(await isTokenExists(api, collectionId, tokenId)).to.be.false;
165 });156 });
166 });157 });
167158
168159 // TODO: burnFrom
169 it('Burn item in Fungible collection', async () => {160 it('Burn item in Fungible collection', async () => {
170 const createMode = 'Fungible';161 const createMode = 'Fungible';
171 const collectionId = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0 }});162 const collectionId = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});
172 const tokenId = await createItemExpectSuccess(alice, collectionId, createMode); // Helper creates 10 fungible tokens163 const tokenId = await createItemExpectSuccess(alice, collectionId, createMode); // Helper creates 10 fungible tokens
173 await addCollectionAdminExpectSuccess(alice, collectionId, bob);164 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
174165
175 await usingApi(async (api) => {166 await usingApi(async (api) => {
176 // Destroy 1 of 10167 // Destroy 1 of 10
179 const result = getGenericResult(events);170 const result = getGenericResult(events);
180171
181 // Get alice balance172 // Get alice balance
182 const balance: any = (await api.query.nft.fungibleItemList(collectionId, alice.address)).toJSON();173 const balance = await getBalance(api, collectionId, alice.address, 0);
183174
184 // What to expect175 // What to expect
185 expect(result.success).to.be.true;176 expect(result.success).to.be.true;
186 expect(balance).to.be.not.null;
187 expect(balance.value).to.be.equal(9);177 expect(balance).to.be.equal(9n);
188 });178 });
189 });179 });
190180
181 // TODO: burnFrom
191 it('Burn item in ReFungible collection', async () => {182 it('Burn item in ReFungible collection', async () => {
192 const createMode = 'ReFungible';183 const createMode = 'ReFungible';
193 const collectionId = await createCollectionExpectSuccess({mode: {type: createMode }});184 const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}});
194 const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);185 const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);
195 await addCollectionAdminExpectSuccess(alice, collectionId, bob);186 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
196187
197 await usingApi(async (api) => {188 await usingApi(async (api) => {
198 const tx = api.tx.nft.burnFrom(collectionId, normalizeAccountId(alice.address), tokenId, 100);189 const tx = api.tx.nft.burnFrom(collectionId, normalizeAccountId(alice.address), tokenId, 100);
199 const events = await submitTransactionAsync(bob, tx);190 const events = await submitTransactionAsync(bob, tx);
200 const result = getGenericResult(events);191 const result = getGenericResult(events);
201 // Get alice balance192 // Get alice balance
202 const balance: any = (await api.query.nft.reFungibleItemList(collectionId, tokenId)).toJSON();
203
204 // What to expect
205 expect(result.success).to.be.true;193 expect(result.success).to.be.true;
194 // Get the item
206 expect(balance).to.be.null;195 expect(await isTokenExists(api, collectionId, tokenId)).to.be.false;
207 });196 });
208 });197 });
209});198});
254 const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);243 const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);
255244
256 await usingApi(async (api) => {245 await usingApi(async (api) => {
257 const tx = api.tx.nft.burnItem(collectionId, tokenId, 0);246 const tx = api.tx.nft.burnItem(collectionId, tokenId, 1);
258 const badTransaction = async function () {247 const badTransaction = async function () {
259 await submitTransactionExpectFailAsync(bob, tx);248 await submitTransactionExpectFailAsync(bob, tx);
260 };249 };
275 const result1 = getGenericResult(events1);264 const result1 = getGenericResult(events1);
276 expect(result1.success).to.be.true;265 expect(result1.success).to.be.true;
277266
278 const tx = api.tx.nft.transfer(normalizeAccountId(bob.address), collectionId, tokenId, 0);267 const tx = api.tx.nft.transfer(normalizeAccountId(bob.address), collectionId, tokenId, 1);
279 const badTransaction = async function () {268 const badTransaction = async function () {
280 await submitTransactionExpectFailAsync(alice, tx);269 await submitTransactionExpectFailAsync(alice, tx);
281 };270 };
300 await expect(badTransaction()).to.be.rejected;289 await expect(badTransaction()).to.be.rejected;
301290
302 // Get alice balance291 // Get alice balance
303 const balance: any = (await api.query.nft.fungibleItemList(collectionId, alice.address)).toJSON();292 const balance = await getBalance(api, collectionId, alice.address, 0);
304293
305 // What to expect294 // What to expect
306 expect(balance).to.be.not.null;
307 expect(balance.value).to.be.equal(10);295 expect(balance).to.be.equal(10n);
308 });296 });
309297
310 });298 });
modifiedtests/src/change-collection-owner.test.tsdiffbeforeafterboth
34 const alice = privateKey('//Alice');34 const alice = privateKey('//Alice');
35 const bob = privateKey('//Bob');35 const bob = privateKey('//Bob');
3636
37 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();37 const collection = (await api.query.common.collectionById(collectionId)).unwrap();
38 expect(collection.owner).to.be.deep.eq(alice.address);38 expect(collection.owner.toString()).to.be.deep.eq(alice.address);
3939
40 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);40 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);
41 await submitTransactionAsync(alice, changeOwnerTx);41 await submitTransactionAsync(alice, changeOwnerTx);
4242
43 const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();43 const collectionAfterOwnerChange = (await api.query.common.collectionById(collectionId)).unwrap();
44 expect(collectionAfterOwnerChange.owner).to.be.deep.eq(bob.address);44 expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(bob.address);
45 });45 });
46 });46 });
47});47});
53 const alice = privateKey('//Alice');53 const alice = privateKey('//Alice');
54 const bob = privateKey('//Bob');54 const bob = privateKey('//Bob');
5555
56 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();56 const collection = (await api.query.common.collectionById(collectionId)).unwrap();
57 expect(collection.owner).to.be.deep.eq(alice.address);57 expect(collection.owner.toString()).to.be.deep.eq(alice.address);
5858
59 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);59 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);
60 await submitTransactionAsync(alice, changeOwnerTx);60 await submitTransactionAsync(alice, changeOwnerTx);
6161
62 const badChangeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, alice.address);62 const badChangeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, alice.address);
63 await expect(submitTransactionExpectFailAsync(alice, badChangeOwnerTx)).to.be.rejected;63 await expect(submitTransactionExpectFailAsync(alice, badChangeOwnerTx)).to.be.rejected;
6464
65 const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();65 const collectionAfterOwnerChange = (await api.query.common.collectionById(collectionId)).unwrap();
66 expect(collectionAfterOwnerChange.owner).to.be.deep.eq(bob.address);66 expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(bob.address);
67 });67 });
68 });68 });
6969
74 const bob = privateKey('//Bob');74 const bob = privateKey('//Bob');
75 const charlie = privateKey('//Charlie');75 const charlie = privateKey('//Charlie');
7676
77 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();77 const collection = (await api.query.common.collectionById(collectionId)).unwrap();
78 expect(collection.owner).to.be.deep.eq(alice.address);78 expect(collection.owner.toString()).to.be.deep.eq(alice.address);
7979
80 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);80 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);
81 await submitTransactionAsync(alice, changeOwnerTx);81 await submitTransactionAsync(alice, changeOwnerTx);
8282
83 const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();83 const collectionAfterOwnerChange = (await api.query.common.collectionById(collectionId)).unwrap();
84 expect(collectionAfterOwnerChange.owner).to.be.deep.eq(bob.address);84 expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(bob.address);
8585
86 // After changing the owner of the collection, all privileged methods are available to the new owner86 // After changing the owner of the collection, all privileged methods are available to the new owner
87 // The new owner of the collection has access to sponsorship management operations in the collection87 // The new owner of the collection has access to sponsorship management operations in the collection
94 accountTokenOwnershipLimit: 1,94 accountTokenOwnershipLimit: 1,
95 sponsoredMintSize: 1,95 sponsoredMintSize: 1,
96 tokenLimit: 1,96 tokenLimit: 1,
97 sponsorTimeout: 1,97 sponsorTransferTimeout: 1,
98 ownerCanTransfer: true,98 ownerCanTransfer: true,
99 ownerCanDestroy: true,99 ownerCanDestroy: true,
100 };100 };
118 const bob = privateKey('//Bob');118 const bob = privateKey('//Bob');
119 const charlie = privateKey('//Charlie');119 const charlie = privateKey('//Charlie');
120120
121 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();121 const collection = (await api.query.common.collectionById(collectionId)).unwrap();
122 expect(collection.owner).to.be.deep.eq(alice.address);122 expect(collection.owner.toString()).to.be.deep.eq(alice.address);
123123
124 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);124 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);
125 await submitTransactionAsync(alice, changeOwnerTx);125 await submitTransactionAsync(alice, changeOwnerTx);
126126
127 const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();127 const collectionAfterOwnerChange = (await api.query.common.collectionById(collectionId)).unwrap();
128 expect(collectionAfterOwnerChange.owner).to.be.deep.eq(bob.address);128 expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(bob.address);
129129
130 const changeOwnerTx2 = api.tx.nft.changeCollectionOwner(collectionId, charlie.address);130 const changeOwnerTx2 = api.tx.nft.changeCollectionOwner(collectionId, charlie.address);
131 await submitTransactionAsync(bob, changeOwnerTx2);131 await submitTransactionAsync(bob, changeOwnerTx2);
132132
133 // ownership lost133 // ownership lost
134 const collectionAfterOwnerChange2: any = (await api.query.nft.collectionById(collectionId)).toJSON();134 const collectionAfterOwnerChange2 = (await api.query.common.collectionById(collectionId)).unwrap();
135 expect(collectionAfterOwnerChange2.owner).to.be.deep.eq(charlie.address);135 expect(collectionAfterOwnerChange2.owner.toString()).to.be.deep.eq(charlie.address);
136 });136 });
137 });137 });
138});138});
147 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);147 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);
148 await expect(submitTransactionExpectFailAsync(bob, changeOwnerTx)).to.be.rejected;148 await expect(submitTransactionExpectFailAsync(bob, changeOwnerTx)).to.be.rejected;
149149
150 const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();150 const collectionAfterOwnerChange = (await api.query.common.collectionById(collectionId)).unwrap();
151 expect(collectionAfterOwnerChange.owner).to.be.deep.eq(alice.address);151 expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(alice.address);
152152
153 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)153 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)
154 await createCollectionExpectSuccess();154 await createCollectionExpectSuccess();
161 const alice = privateKey('//Alice');161 const alice = privateKey('//Alice');
162 const bob = privateKey('//Bob');162 const bob = privateKey('//Bob');
163163
164 await addCollectionAdminExpectSuccess(alice, collectionId, bob);164 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
165165
166 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);166 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);
167 await expect(submitTransactionExpectFailAsync(bob, changeOwnerTx)).to.be.rejected;167 await expect(submitTransactionExpectFailAsync(bob, changeOwnerTx)).to.be.rejected;
168168
169 const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();169 const collectionAfterOwnerChange = (await api.query.common.collectionById(collectionId)).unwrap();
170 expect(collectionAfterOwnerChange.owner).to.be.deep.eq(alice.address);170 expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(alice.address);
171171
172 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)172 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)
173 await createCollectionExpectSuccess();173 await createCollectionExpectSuccess();
195 const bob = privateKey('//Bob');195 const bob = privateKey('//Bob');
196 const charlie = privateKey('//Charlie');196 const charlie = privateKey('//Charlie');
197197
198 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();198 const collection = (await api.query.common.collectionById(collectionId)).unwrap();
199 expect(collection.owner).to.be.deep.eq(alice.address);199 expect(collection.owner.toString()).to.be.deep.eq(alice.address);
200200
201 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);201 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);
202 await submitTransactionAsync(alice, changeOwnerTx);202 await submitTransactionAsync(alice, changeOwnerTx);
203203
204 const badChangeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, alice.address);204 const badChangeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, alice.address);
205 await expect(submitTransactionExpectFailAsync(alice, badChangeOwnerTx)).to.be.rejected;205 await expect(submitTransactionExpectFailAsync(alice, badChangeOwnerTx)).to.be.rejected;
206206
207 const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();207 const collectionAfterOwnerChange = (await api.query.common.collectionById(collectionId)).unwrap();
208 expect(collectionAfterOwnerChange.owner).to.be.deep.eq(bob.address);208 expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(bob.address);
209209
210 await setCollectionSponsorExpectFailure(collectionId, charlie.address, '//Alice');210 await setCollectionSponsorExpectFailure(collectionId, charlie.address, '//Alice');
211 await confirmSponsorshipExpectFailure(collectionId, '//Alice');211 await confirmSponsorshipExpectFailure(collectionId, '//Alice');
215 accountTokenOwnershipLimit: 1,215 accountTokenOwnershipLimit: 1,
216 sponsoredMintSize: 1,216 sponsoredMintSize: 1,
217 tokenLimit: 1,217 tokenLimit: 1,
218 sponsorTimeout: 1,218 sponsorTransferTimeout: 1,
219 ownerCanTransfer: true,219 ownerCanTransfer: true,
220 ownerCanDestroy: true,220 ownerCanDestroy: true,
221 };221 };
modifiedtests/src/check-event/burnItemEvent.test.tsdiffbeforeafterboth
16const expect = chai.expect;16const expect = chai.expect;
1717
18describe('Burn Item event ', () => {18describe('Burn Item event ', () => {
19 let Alice: IKeyringPair;19 let alice: IKeyringPair;
20 const checkSection = 'ItemDestroyed';20 const checkSection = 'ItemDestroyed';
21 const checkTreasury = 'Deposit';21 const checkTreasury = 'Deposit';
22 const checkSystem = 'ExtrinsicSuccess';22 const checkSystem = 'ExtrinsicSuccess';
23 before(async () => {23 before(async () => {
24 await usingApi(async () => {24 await usingApi(async () => {
25 Alice = privateKey('//Alice');25 alice = privateKey('//Alice');
26 });26 });
27 });27 });
28 it('Check event from burnItem(): ', async () => {28 it('Check event from burnItem(): ', async () => {
29 await usingApi(async (api: ApiPromise) => {29 await usingApi(async (api: ApiPromise) => {
30 const collectionID = await createCollectionExpectSuccess();30 const collectionID = await createCollectionExpectSuccess();
31 const itemID = await createItemExpectSuccess(Alice, collectionID, 'NFT');31 const itemID = await createItemExpectSuccess(alice, collectionID, 'NFT');
32 const burnItem = api.tx.nft.burnItem(collectionID, itemID, 1);32 const burnItem = api.tx.nft.burnItem(collectionID, itemID, 1);
33 const events = await submitTransactionAsync(Alice, burnItem);33 const events = await submitTransactionAsync(alice, burnItem);
34 const msg = JSON.stringify(nftEventMessage(events));34 const msg = JSON.stringify(nftEventMessage(events));
35 expect(msg).to.be.contain(checkSection);35 expect(msg).to.be.contain(checkSection);
36 expect(msg).to.be.contain(checkTreasury);36 expect(msg).to.be.contain(checkTreasury);
modifiedtests/src/check-event/createCollectionEvent.test.tsdiffbeforeafterboth
16const expect = chai.expect;16const expect = chai.expect;
1717
18describe('Create collection event ', () => {18describe('Create collection event ', () => {
19 let Alice: IKeyringPair;19 let alice: IKeyringPair;
20 const checkSection = 'CollectionCreated';20 const checkSection = 'CollectionCreated';
21 const checkTreasury = 'Deposit';21 const checkTreasury = 'Deposit';
22 const checkSystem = 'ExtrinsicSuccess';22 const checkSystem = 'ExtrinsicSuccess';
23 before(async () => {23 before(async () => {
24 await usingApi(async () => {24 await usingApi(async () => {
25 Alice = privateKey('//Alice');25 alice = privateKey('//Alice');
26 });26 });
27 });27 });
28 it('Check event from createCollection(): ', async () => {28 it('Check event from createCollection(): ', async () => {
29 await usingApi(async (api: ApiPromise) => {29 await usingApi(async (api: ApiPromise) => {
30 const tx = api.tx.nft.createCollection('0x31', '0x32', '0x33', 'NFT');30 const tx = api.tx.nft.createCollection([0x31], [0x32], '0x33', 'NFT');
31 const events = await submitTransactionAsync(Alice, tx);31 const events = await submitTransactionAsync(alice, tx);
32 const msg = JSON.stringify(nftEventMessage(events));32 const msg = JSON.stringify(nftEventMessage(events));
33 expect(msg).to.be.contain(checkSection);33 expect(msg).to.be.contain(checkSection);
34 expect(msg).to.be.contain(checkTreasury);34 expect(msg).to.be.contain(checkTreasury);
modifiedtests/src/check-event/createItemEvent.test.tsdiffbeforeafterboth
16const expect = chai.expect;16const expect = chai.expect;
1717
18describe('Create Item event ', () => {18describe('Create Item event ', () => {
19 let Alice: IKeyringPair;19 let alice: IKeyringPair;
20 const checkSection = 'ItemCreated';20 const checkSection = 'ItemCreated';
21 const checkTreasury = 'Deposit';21 const checkTreasury = 'Deposit';
22 const checkSystem = 'ExtrinsicSuccess';22 const checkSystem = 'ExtrinsicSuccess';
23 before(async () => {23 before(async () => {
24 await usingApi(async () => {24 await usingApi(async () => {
25 Alice = privateKey('//Alice');25 alice = privateKey('//Alice');
26 });26 });
27 });27 });
28 it('Check event from createItem(): ', async () => {28 it('Check event from createItem(): ', async () => {
29 await usingApi(async (api: ApiPromise) => {29 await usingApi(async (api: ApiPromise) => {
30 const collectionID = await createCollectionExpectSuccess();30 const collectionID = await createCollectionExpectSuccess();
31 const createItem = api.tx.nft.createItem(collectionID, normalizeAccountId(Alice.address), 'NFT');31 const createItem = api.tx.nft.createItem(collectionID, normalizeAccountId(alice.address), 'NFT');
32 const events = await submitTransactionAsync(Alice, createItem);32 const events = await submitTransactionAsync(alice, createItem);
33 const msg = JSON.stringify(nftEventMessage(events));33 const msg = JSON.stringify(nftEventMessage(events));
34 expect(msg).to.be.contain(checkSection);34 expect(msg).to.be.contain(checkSection);
35 expect(msg).to.be.contain(checkTreasury);35 expect(msg).to.be.contain(checkTreasury);
modifiedtests/src/check-event/createMultipleItemsEvent.test.tsdiffbeforeafterboth
16const expect = chai.expect;16const expect = chai.expect;
1717
18describe('Create Multiple Items Event event ', () => {18describe('Create Multiple Items Event event ', () => {
19 let Alice: IKeyringPair;19 let alice: IKeyringPair;
20 const checkSection = 'ItemCreated';20 const checkSection = 'ItemCreated';
21 const checkTreasury = 'Deposit';21 const checkTreasury = 'Deposit';
22 const checkSystem = 'ExtrinsicSuccess';22 const checkSystem = 'ExtrinsicSuccess';
23 before(async () => {23 before(async () => {
24 await usingApi(async () => {24 await usingApi(async () => {
25 Alice = privateKey('//Alice');25 alice = privateKey('//Alice');
26 });26 });
27 });27 });
28 it('Check event from createMultipleItems(): ', async () => {28 it('Check event from createMultipleItems(): ', async () => {
29 await usingApi(async (api: ApiPromise) => {29 await usingApi(async (api: ApiPromise) => {
30 const collectionID = await createCollectionExpectSuccess();30 const collectionID = await createCollectionExpectSuccess();
31 const args = [{ nft: ['0x31', '0x31'] }, { nft: ['0x32', '0x32'] }, { nft: ['0x33', '0x33'] }];31 const args = [{NFT: ['0x31', '0x31']}, {NFT: ['0x32', '0x32']}, {NFT: ['0x33', '0x33']}];
32 const createMultipleItems = api.tx.nft.createMultipleItems(collectionID, normalizeAccountId(Alice.address), args);32 const createMultipleItems = api.tx.nft.createMultipleItems(collectionID, normalizeAccountId(alice.address), args);
33 const events = await submitTransactionAsync(Alice, createMultipleItems);33 const events = await submitTransactionAsync(alice, createMultipleItems);
34 const msg = JSON.stringify(nftEventMessage(events));34 const msg = JSON.stringify(nftEventMessage(events));
35 expect(msg).to.be.contain(checkSection);35 expect(msg).to.be.contain(checkSection);
36 expect(msg).to.be.contain(checkTreasury);36 expect(msg).to.be.contain(checkTreasury);
modifiedtests/src/check-event/destroyCollectionEvent.test.tsdiffbeforeafterboth
16const expect = chai.expect;16const expect = chai.expect;
1717
18describe('Destroy collection event ', () => {18describe('Destroy collection event ', () => {
19 let Alice: IKeyringPair;19 let alice: IKeyringPair;
20 const checkTreasury = 'Deposit';20 const checkTreasury = 'Deposit';
21 const checkSystem = 'ExtrinsicSuccess';21 const checkSystem = 'ExtrinsicSuccess';
22 before(async () => {22 before(async () => {
23 await usingApi(async () => {23 await usingApi(async () => {
24 Alice = privateKey('//Alice');24 alice = privateKey('//Alice');
25 });25 });
26 });26 });
27 it('Check event from destroyCollection(): ', async () => {27 it('Check event from destroyCollection(): ', async () => {
28 await usingApi(async (api: ApiPromise) => {28 await usingApi(async (api: ApiPromise) => {
29 const collectionID = await createCollectionExpectSuccess();29 const collectionID = await createCollectionExpectSuccess();
30 const destroyCollection = api.tx.nft.destroyCollection(collectionID);30 const destroyCollection = api.tx.nft.destroyCollection(collectionID);
31 const events = await submitTransactionAsync(Alice, destroyCollection);31 const events = await submitTransactionAsync(alice, destroyCollection);
32 const msg = JSON.stringify(nftEventMessage(events));32 const msg = JSON.stringify(nftEventMessage(events));
33 expect(msg).to.be.contain(checkTreasury);33 expect(msg).to.be.contain(checkTreasury);
34 expect(msg).to.be.contain(checkSystem);34 expect(msg).to.be.contain(checkSystem);
modifiedtests/src/check-event/transferEvent.test.tsdiffbeforeafterboth
16const expect = chai.expect;16const expect = chai.expect;
1717
18describe('Transfer event ', () => {18describe('Transfer event ', () => {
19 let Alice: IKeyringPair;19 let alice: IKeyringPair;
20 let Bob: IKeyringPair;20 let bob: IKeyringPair;
21 const checkSection = 'Transfer';21 const checkSection = 'Transfer';
22 const checkTreasury = 'Deposit';22 const checkTreasury = 'Deposit';
23 const checkSystem = 'ExtrinsicSuccess';23 const checkSystem = 'ExtrinsicSuccess';
24 before(async () => {24 before(async () => {
25 await usingApi(async () => {25 await usingApi(async () => {
26 Alice = privateKey('//Alice');26 alice = privateKey('//Alice');
27 Bob = privateKey('//Bob');27 bob = privateKey('//Bob');
28 });28 });
29 });29 });
30 it('Check event from transfer(): ', async () => {30 it('Check event from transfer(): ', async () => {
31 await usingApi(async (api: ApiPromise) => {31 await usingApi(async (api: ApiPromise) => {
32 const collectionID = await createCollectionExpectSuccess();32 const collectionID = await createCollectionExpectSuccess();
33 const itemID = await createItemExpectSuccess(Alice, collectionID, 'NFT');33 const itemID = await createItemExpectSuccess(alice, collectionID, 'NFT');
34 const transfer = api.tx.nft.transfer(normalizeAccountId(Bob.address), collectionID, itemID, 1);34 const transfer = api.tx.nft.transfer(normalizeAccountId(bob.address), collectionID, itemID, 1);
35 const events = await submitTransactionAsync(Alice, transfer);35 const events = await submitTransactionAsync(alice, transfer);
36 const msg = JSON.stringify(nftEventMessage(events));36 const msg = JSON.stringify(nftEventMessage(events));
37 expect(msg).to.be.contain(checkSection);37 expect(msg).to.be.contain(checkSection);
38 expect(msg).to.be.contain(checkTreasury);38 expect(msg).to.be.contain(checkTreasury);
modifiedtests/src/check-event/transferFromEvent.test.tsdiffbeforeafterboth
16const expect = chai.expect;16const expect = chai.expect;
1717
18describe('Transfer from event ', () => {18describe('Transfer from event ', () => {
19 let Alice: IKeyringPair;19 let alice: IKeyringPair;
20 let Bob: IKeyringPair;20 let bob: IKeyringPair;
21 const checkSection = 'Transfer';21 const checkSection = 'Transfer';
22 const checkTreasury = 'Deposit';22 const checkTreasury = 'Deposit';
23 const checkSystem = 'ExtrinsicSuccess';23 const checkSystem = 'ExtrinsicSuccess';
24 before(async () => {24 before(async () => {
25 await usingApi(async () => {25 await usingApi(async () => {
26 Alice = privateKey('//Alice');26 alice = privateKey('//Alice');
27 Bob = privateKey('//Bob');27 bob = privateKey('//Bob');
28 });28 });
29 });29 });
30 it('Check event from transferFrom(): ', async () => {30 it('Check event from transferFrom(): ', async () => {
31 await usingApi(async (api: ApiPromise) => {31 await usingApi(async (api: ApiPromise) => {
32 const collectionID = await createCollectionExpectSuccess();32 const collectionID = await createCollectionExpectSuccess();
33 const itemID = await createItemExpectSuccess(Alice, collectionID, 'NFT');33 const itemID = await createItemExpectSuccess(alice, collectionID, 'NFT');
34 const transferFrom = api.tx.nft.transferFrom(normalizeAccountId(Alice.address), normalizeAccountId(Bob.address), collectionID, itemID, 1);34 const transferFrom = api.tx.nft.transferFrom(normalizeAccountId(alice.address), normalizeAccountId(bob.address), collectionID, itemID, 1);
35 const events = await submitTransactionAsync(Alice, transferFrom);35 const events = await submitTransactionAsync(alice, transferFrom);
36 const msg = JSON.stringify(nftEventMessage(events));36 const msg = JSON.stringify(nftEventMessage(events));
37 expect(msg).to.be.contain(checkSection);37 expect(msg).to.be.contain(checkSection);
38 expect(msg).to.be.contain(checkTreasury);38 expect(msg).to.be.contain(checkTreasury);
modifiedtests/src/confirmSponsorship.test.tsdiffbeforeafterboth
23} from './util/helpers';23} from './util/helpers';
24import { Keyring } from '@polkadot/api';24import {Keyring} from '@polkadot/api';
25import { IKeyringPair } from '@polkadot/types/types';25import {IKeyringPair} from '@polkadot/types/types';
26import { BigNumber } from 'bignumber.js';
2726
28chai.use(chaiAsPromised);27chai.use(chaiAsPromised);
29const expect = chai.expect;28const expect = chai.expect;
67 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');66 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
6867
69 await usingApi(async (api) => {68 await usingApi(async (api) => {
70 const AsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());69 const sponsorBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();
7170
72 // Find unused address71 // Find unused address
73 const zeroBalance = await findUnusedAddress(api);72 const zeroBalance = await findUnusedAddress(api);
79 const zeroToAlice = api.tx.nft.transfer(normalizeAccountId(zeroBalance.address), collectionId, itemId, 0);78 const zeroToAlice = api.tx.nft.transfer(normalizeAccountId(zeroBalance.address), collectionId, itemId, 0);
80 const events = await submitTransactionAsync(zeroBalance, zeroToAlice);79 const events = await submitTransactionAsync(zeroBalance, zeroToAlice);
81 const result = getGenericResult(events);80 const result = getGenericResult(events);
81 expect(result.success).to.be.true;
8282
83 const BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());83 const sponsorBalanceAfter = (await api.query.system.account(bob.address)).data.free.toBigInt();
8484
85 expect(result.success).to.be.true;85 expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;
86 expect(BsponsorBalance.lt(AsponsorBalance)).to.be.true;
87 });86 });
8887
89 });88 });
94 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');93 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
9594
96 await usingApi(async (api) => {95 await usingApi(async (api) => {
97 const AsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());96 const sponsorBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();
9897
99 // Find unused address98 // Find unused address
100 const zeroBalance = await findUnusedAddress(api);99 const zeroBalance = await findUnusedAddress(api);
106 const zeroToAlice = api.tx.nft.transfer(normalizeAccountId(zeroBalance.address), collectionId, itemId, 1);105 const zeroToAlice = api.tx.nft.transfer(normalizeAccountId(zeroBalance.address), collectionId, itemId, 1);
107 const events1 = await submitTransactionAsync(zeroBalance, zeroToAlice);106 const events1 = await submitTransactionAsync(zeroBalance, zeroToAlice);
108 const result1 = getGenericResult(events1);107 const result1 = getGenericResult(events1);
108 expect(result1.success).to.be.true;
109109
110 const BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());110 const sponsorBalanceAfter = (await api.query.system.account(bob.address)).data.free.toBigInt();
111111
112 expect(result1.success).to.be.true;112 expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;
113 expect(BsponsorBalance.lt(AsponsorBalance)).to.be.true;
114 });113 });
115 });114 });
116115
120 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');119 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
121120
122 await usingApi(async (api) => {121 await usingApi(async (api) => {
123 const AsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());122 const sponsorBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();
124123
125 // Find unused address124 // Find unused address
126 const zeroBalance = await findUnusedAddress(api);125 const zeroBalance = await findUnusedAddress(api);
133 const events1 = await submitTransactionAsync(zeroBalance, zeroToAlice);132 const events1 = await submitTransactionAsync(zeroBalance, zeroToAlice);
134 const result1 = getGenericResult(events1);133 const result1 = getGenericResult(events1);
135134
136 const BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());135 const sponsorBalanceAfter = (await api.query.system.account(bob.address)).data.free.toBigInt();
137136
138 expect(result1.success).to.be.true;137 expect(result1.success).to.be.true;
139 expect(BsponsorBalance.lt(AsponsorBalance)).to.be.true;138 expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;
140 });139 });
141 });140 });
142141
145 await setCollectionSponsorExpectSuccess(collectionId, bob.address);144 await setCollectionSponsorExpectSuccess(collectionId, bob.address);
146 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');145 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
147146
148 // Enable collection white list 147 // Enable collection white list
149 await enableWhiteListExpectSuccess(alice, collectionId);148 await enableWhiteListExpectSuccess(alice, collectionId);
150149
151 // Enable public minting150 // Enable public minting
152 await enablePublicMintingExpectSuccess(alice, collectionId);151 await enablePublicMintingExpectSuccess(alice, collectionId);
153152
154 // Create Item 153 // Create Item
155 await usingApi(async (api) => {154 await usingApi(async (api) => {
156 const AsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());155 const sponsorBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();
157156
158 // Find unused address157 // Find unused address
159 const zeroBalance = await findUnusedAddress(api);158 const zeroBalance = await findUnusedAddress(api);
164 // Mint token using unused address as signer163 // Mint token using unused address as signer
165 await createItemExpectSuccess(zeroBalance, collectionId, 'NFT', zeroBalance.address);164 await createItemExpectSuccess(zeroBalance, collectionId, 'NFT', zeroBalance.address);
166165
167 const BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());166 const sponsorBalanceAfter = (await api.query.system.account(bob.address)).data.free.toBigInt();
168167
169 expect(BsponsorBalance.lt(AsponsorBalance)).to.be.true;168 expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;
170 });169 });
171 });170 });
172171
189 const result1 = getGenericResult(events1);188 const result1 = getGenericResult(events1);
190189
191 // Second transfer should fail190 // Second transfer should fail
192 const AsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());191 const sponsorBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();
193 const zeroToAlice = api.tx.nft.transfer(normalizeAccountId(alice.address), collectionId, itemId, 0);192 const zeroToAlice = api.tx.nft.transfer(normalizeAccountId(alice.address), collectionId, itemId, 0);
194 const badTransaction = async function () { 193 const badTransaction = async function () {
195 await submitTransactionExpectFailAsync(zeroBalance, zeroToAlice);194 await submitTransactionExpectFailAsync(zeroBalance, zeroToAlice);
196 };195 };
197 await expect(badTransaction()).to.be.rejectedWith('Inability to pay some fees');196 await expect(badTransaction()).to.be.rejectedWith('Inability to pay some fees');
198 const BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());197 const sponsorBalanceAfter = (await api.query.system.account(bob.address)).data.free.toBigInt();
199198
200 // Try again after Zero gets some balance - now it should succeed199 // Try again after Zero gets some balance - now it should succeed
201 const balancetx = api.tx.balances.transfer(zeroBalance.address, 1e15);200 const balancetx = api.tx.balances.transfer(zeroBalance.address, 1e15);
205204
206 expect(result1.success).to.be.true;205 expect(result1.success).to.be.true;
207 expect(result2.success).to.be.true;206 expect(result2.success).to.be.true;
208 expect(BsponsorBalance.isEqualTo(AsponsorBalance)).to.be.true;207 expect(sponsorBalanceAfter).to.be.equal(sponsorBalanceBefore);
209 });208 });
210 });209 });
211210
225 const zeroToAlice = api.tx.nft.transfer(normalizeAccountId(zeroBalance.address), collectionId, itemId, 1);224 const zeroToAlice = api.tx.nft.transfer(normalizeAccountId(zeroBalance.address), collectionId, itemId, 1);
226 const events1 = await submitTransactionAsync(zeroBalance, zeroToAlice);225 const events1 = await submitTransactionAsync(zeroBalance, zeroToAlice);
227 const result1 = getGenericResult(events1);226 const result1 = getGenericResult(events1);
227 expect(result1.success).to.be.true;
228228
229 const AsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());229 const sponsorBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();
230 await expect(submitTransactionExpectFailAsync(zeroBalance, zeroToAlice)).to.be.rejected;230 await expect(submitTransactionExpectFailAsync(zeroBalance, zeroToAlice)).to.be.rejected;
231 const BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());231 const sponsorBalanceAfter = (await api.query.system.account(bob.address)).data.free.toBigInt();
232232
233 // Try again after Zero gets some balance - now it should succeed233 // Try again after Zero gets some balance - now it should succeed
234 const balancetx = api.tx.balances.transfer(zeroBalance.address, 1e15);234 const balancetx = api.tx.balances.transfer(zeroBalance.address, 1e15);
235 await submitTransactionAsync(alice, balancetx);235 await submitTransactionAsync(alice, balancetx);
236 const events2 = await submitTransactionAsync(zeroBalance, zeroToAlice);236 const events2 = await submitTransactionAsync(zeroBalance, zeroToAlice);
237 const result2 = getGenericResult(events2);237 const result2 = getGenericResult(events2);
238
239 expect(result1.success).to.be.true;
240 expect(result2.success).to.be.true;238 expect(result2.success).to.be.true;
239
241 expect(BsponsorBalance.isEqualTo(AsponsorBalance)).to.be.true;240 expect(sponsorBalanceAfter).to.be.equal(sponsorBalanceBefore);
242 });241 });
243 });242 });
244243
259 const aliceToZero = api.tx.nft.transfer(normalizeAccountId(zeroBalance.address), collectionId, itemId, 1);258 const aliceToZero = api.tx.nft.transfer(normalizeAccountId(zeroBalance.address), collectionId, itemId, 1);
260 const events1 = await submitTransactionAsync(alice, aliceToZero);259 const events1 = await submitTransactionAsync(alice, aliceToZero);
261 const result1 = getGenericResult(events1);260 const result1 = getGenericResult(events1);
261 expect(result1.success).to.be.true;
262262
263 // Second transfer should fail263 // Second transfer should fail
264 const AsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());264 const sponsorBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();
265 const zeroToAlice = api.tx.nft.transfer(normalizeAccountId(alice.address), collectionId, itemId, 1);265 const zeroToAlice = api.tx.nft.transfer(normalizeAccountId(alice.address), collectionId, itemId, 1);
266 const badTransaction = async function () { 266 const badTransaction = async function () {
267 await submitTransactionExpectFailAsync(zeroBalance, zeroToAlice);267 await submitTransactionExpectFailAsync(zeroBalance, zeroToAlice);
268 };268 };
269 await expect(badTransaction()).to.be.rejectedWith('Inability to pay some fees');269 await expect(badTransaction()).to.be.rejectedWith('Inability to pay some fees');
270 const BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());270 const sponsorBalanceAfter = (await api.query.system.account(bob.address)).data.free.toBigInt();
271271
272 // Try again after Zero gets some balance - now it should succeed272 // Try again after Zero gets some balance - now it should succeed
273 const balancetx = api.tx.balances.transfer(zeroBalance.address, 1e15);273 const balancetx = api.tx.balances.transfer(zeroBalance.address, 1e15);
274 await submitTransactionAsync(alice, balancetx);274 await submitTransactionAsync(alice, balancetx);
275 const events2 = await submitTransactionAsync(zeroBalance, zeroToAlice);275 const events2 = await submitTransactionAsync(zeroBalance, zeroToAlice);
276 const result2 = getGenericResult(events2);276 const result2 = getGenericResult(events2);
277
278 expect(result1.success).to.be.true;
279 expect(result2.success).to.be.true;277 expect(result2.success).to.be.true;
278
280 expect(BsponsorBalance.isEqualTo(AsponsorBalance)).to.be.true;279 expect(sponsorBalanceAfter).to.be.equal(sponsorBalanceBefore);
281 });280 });
282 });281 });
283282
286 await setCollectionSponsorExpectSuccess(collectionId, bob.address);285 await setCollectionSponsorExpectSuccess(collectionId, bob.address);
287 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');286 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
288287
289 // Enable collection white list 288 // Enable collection white list
290 await enableWhiteListExpectSuccess(alice, collectionId);289 await enableWhiteListExpectSuccess(alice, collectionId);
291290
292 // Enable public minting291 // Enable public minting
303 await createItemExpectSuccess(zeroBalance, collectionId, 'NFT', zeroBalance.address);302 await createItemExpectSuccess(zeroBalance, collectionId, 'NFT', zeroBalance.address);
304303
305 // Second mint should fail304 // Second mint should fail
306 const AsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());305 const sponsorBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();
307 306
308 const consoleError = console.error;
309 const consoleLog = console.log;
310 console.error = () => {};
311 console.log = () => {};
312 const badTransaction = async function () { 307 const badTransaction = async function () {
313 await createItemExpectSuccess(zeroBalance, collectionId, 'NFT', zeroBalance.address);308 await createItemExpectSuccess(zeroBalance, collectionId, 'NFT', zeroBalance.address);
314 };309 };
315 await expect(badTransaction()).to.be.rejectedWith('Inability to pay some fees');310 await expect(badTransaction()).to.be.rejectedWith('Inability to pay some fees');
316 console.error = consoleError;
317 console.log = consoleLog;
318 const BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());311 const sponsorBalanceAfter = (await api.query.system.account(bob.address)).data.free.toBigInt();
319312
320 // Try again after Zero gets some balance - now it should succeed313 // Try again after Zero gets some balance - now it should succeed
321 const balancetx = api.tx.balances.transfer(zeroBalance.address, 1e15);314 const balancetx = api.tx.balances.transfer(zeroBalance.address, 1e15);
322 await submitTransactionAsync(alice, balancetx);315 await submitTransactionAsync(alice, balancetx);
323 await createItemExpectSuccess(zeroBalance, collectionId, 'NFT', zeroBalance.address);316 await createItemExpectSuccess(zeroBalance, collectionId, 'NFT', zeroBalance.address);
324317
325 expect(BsponsorBalance.isEqualTo(AsponsorBalance)).to.be.true;318 expect(sponsorBalanceAfter).to.be.equal(sponsorBalanceBefore);
326 });319 });
327 });320 });
328321
342 // Find the collection that never existed335 // Find the collection that never existed
343 let collectionId = 0;336 let collectionId = 0;
344 await usingApi(async (api) => {337 await usingApi(async (api) => {
345 collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;338 collectionId = (await api.query.common.createdCollectionCount()).toNumber() + 1;
346 });339 });
347340
348 await confirmSponsorshipExpectFailure(collectionId, '//Bob');341 await confirmSponsorshipExpectFailure(collectionId, '//Bob');
369 it('(!negative test!) Confirm sponsorship by collection admin', async () => {362 it('(!negative test!) Confirm sponsorship by collection admin', async () => {
370 const collectionId = await createCollectionExpectSuccess();363 const collectionId = await createCollectionExpectSuccess();
371 await setCollectionSponsorExpectSuccess(collectionId, bob.address);364 await setCollectionSponsorExpectSuccess(collectionId, bob.address);
372 await addCollectionAdminExpectSuccess(alice, collectionId, charlie);365 await addCollectionAdminExpectSuccess(alice, collectionId, charlie.address);
373 await confirmSponsorshipExpectFailure(collectionId, '//Charlie');366 await confirmSponsorshipExpectFailure(collectionId, '//Charlie');
374 });367 });
375368
modifiedtests/src/connection.test.tsdiffbeforeafterboth
21 });21 });
2222
23 it('Cannot connect to 255.255.255.255', async () => {23 it('Cannot connect to 255.255.255.255', async () => {
24 const log = console.log;
25 const error = console.error;
26 console.log = function () {};
27 console.error = function () {};
28
29 const neverConnectProvider = new WsProvider('ws://255.255.255.255:9944');24 const neverConnectProvider = new WsProvider('ws://255.255.255.255:9944');
30 await expect((async () => {25 await expect((async () => {
33 }, { provider: neverConnectProvider });28 }, {provider: neverConnectProvider});
34 })()).to.be.eventually.rejected;29 })()).to.be.eventually.rejected;
35
36 console.log = log;
37 console.error = error;
38 });30 });
39});31});
32
modifiedtests/src/contracts.test.tsdiffbeforeafterboth
26 normalizeAccountId,26 normalizeAccountId,
27 isWhitelisted,27 isWhitelisted,
28 transferFromExpectSuccess,28 transferFromExpectSuccess,
29 getTokenOwner,
29} from './util/helpers';30} from './util/helpers';
3031
3132
75 const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, contract.address);76 const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, contract.address);
76 await submitTransactionAsync(alice, changeAdminTx);77 await submitTransactionAsync(alice, changeAdminTx);
7778
78 const tokenBefore: any = (await api.query.nft.nftItemList(collectionId, tokenId) as any).toJSON();79 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal(normalizeAccountId(alice.address));
7980
80 // Transfer81 // Transfer
81 const transferTx = contract.tx.transfer(value, gasLimit, bob.address, collectionId, tokenId, 1);82 const transferTx = contract.tx.transfer(value, gasLimit, bob.address, collectionId, tokenId, 1);
82 const events = await submitTransactionAsync(alice, transferTx);83 const events = await submitTransactionAsync(alice, transferTx);
83 const result = getGenericResult(events);84 const result = getGenericResult(events);
84 const tokenAfter: any = (await api.query.nft.nftItemList(collectionId, tokenId) as any).toJSON();
85
86 // tslint:disable-next-line:no-unused-expression
87 expect(result.success).to.be.true;85 expect(result.success).to.be.true;
88 expect(tokenBefore.owner).to.be.deep.equal(normalizeAccountId(alice.address));86
89 expect(tokenAfter.owner).to.be.deep.equal(normalizeAccountId(bob.address));87 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal(normalizeAccountId(bob.address));
90 });88 });
91 });89 });
9290
107 const result = getGenericResult(events);105 const result = getGenericResult(events);
108 expect(result.success).to.be.true;106 expect(result.success).to.be.true;
109107
110 const tokensAfter: any = (await api.query.nft.nftItemList.entries(collectionId) as any).map((kv: any) => kv[1].toJSON());108 const tokensAfter = (await api.query.nft.nftItemList.entries(collectionId)).map((kv: any) => kv[1].toJSON());
111 expect(tokensAfter).to.be.deep.equal([109 expect(tokensAfter).to.be.deep.equal([
112 {110 {
113 Owner: bob.address,111 owner: bob.address,
114 ConstData: '0x010203',112 constData: '0x010203',
115 VariableData: '0x020304',113 variableData: '0x020304',
116 },114 },
117 ]);115 ]);
118 });116 });
modifiedtests/src/createCollection.test.tsdiffbeforeafterboth
55
6import chai from 'chai';6import chai from 'chai';
7import chaiAsPromised from 'chai-as-promised';7import chaiAsPromised from 'chai-as-promised';
8import { default as usingApi } from './substrate/substrate-api';
9import { createCollectionExpectFailure, createCollectionExpectSuccess } from './util/helpers';8import {createCollectionExpectFailure, createCollectionExpectSuccess} from './util/helpers';
109
11chai.use(chaiAsPromised);10chai.use(chaiAsPromised);
12const expect = chai.expect;
1311
14describe('integration test: ext. createCollection():', () => {12describe('integration test: ext. createCollection():', () => {
15 it('Create new NFT collection', async () => {13 it('Create new NFT collection', async () => {
modifiedtests/src/createItem.test.tsdiffbeforeafterboth
44 it('Create new item in NFT collection with collection admin permissions', async () => {44 it('Create new item in NFT collection with collection admin permissions', async () => {
45 const createMode = 'NFT';45 const createMode = 'NFT';
46 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});46 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});
47 await addCollectionAdminExpectSuccess(alice, newCollectionID, bob);47 await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);
48 await createItemExpectSuccess(bob, newCollectionID, createMode);48 await createItemExpectSuccess(bob, newCollectionID, createMode);
49 });49 });
50 it('Create new item in Fungible collection with collection admin permissions', async () => {50 it('Create new item in Fungible collection with collection admin permissions', async () => {
51 const createMode = 'Fungible';51 const createMode = 'Fungible';
52 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});52 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});
53 await addCollectionAdminExpectSuccess(alice, newCollectionID, bob);53 await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);
54 await createItemExpectSuccess(bob, newCollectionID, createMode);54 await createItemExpectSuccess(bob, newCollectionID, createMode);
55 });55 });
56 it('Create new item in ReFungible collection with collection admin permissions', async () => {56 it('Create new item in ReFungible collection with collection admin permissions', async () => {
57 const createMode = 'ReFungible';57 const createMode = 'ReFungible';
58 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});58 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});
59 await addCollectionAdminExpectSuccess(alice, newCollectionID, bob);59 await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);
60 await createItemExpectSuccess(bob, newCollectionID, createMode);60 await createItemExpectSuccess(bob, newCollectionID, createMode);
61 });61 });
62});62});
modifiedtests/src/createMultipleItems.test.tsdiffbeforeafterboth
2// This file is subject to the terms and conditions defined in2// This file is subject to the terms and conditions defined in
3// file 'LICENSE', which is part of this source code package.3// file 'LICENSE', which is part of this source code package.
4//4//
5import { ApiPromise } from '@polkadot/api';5import {ApiPromise} from '@polkadot/api';
6import { IKeyringPair } from '@polkadot/types/types';6import {IKeyringPair} from '@polkadot/types/types';
7import BN from 'bn.js';
8import chai from 'chai';7import chai from 'chai';
9import chaiAsPromised from 'chai-as-promised';8import chaiAsPromised from 'chai-as-promised';
10import privateKey from './substrate/privateKey';9import privateKey from './substrate/privateKey';
11import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from './substrate/substrate-api';10import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';
12import {11import {
13 createCollectionExpectSuccess,12 createCollectionExpectSuccess,
14 destroyCollectionExpectSuccess,13 destroyCollectionExpectSuccess,
15 getGenericResult,14 getGenericResult,
16 IFungibleTokenDataType,
17 IReFungibleTokenDataType,
18 normalizeAccountId,15 normalizeAccountId,
19 setCollectionLimitsExpectSuccess,16 setCollectionLimitsExpectSuccess,
20 addCollectionAdminExpectSuccess,17 addCollectionAdminExpectSuccess,
18 getBalance,
19 getTokenOwner,
20 getLastTokenId,
21 getVariableMetadata,
22 getConstMetadata,
21} from './util/helpers';23} from './util/helpers';
2224
23chai.use(chaiAsPromised);25chai.use(chaiAsPromised);
24const expect = chai.expect;26const expect = chai.expect;
2527
26interface ITokenDataType {
27 owner: number[];
28 constData: number[];
29 variableData: number[];
30}
31
32describe('Integration Test createMultipleItems(collection_id, owner, items_data):', () => {28describe('Integration Test createMultipleItems(collection_id, owner, items_data):', () => {
33 it('Create 0x31, 0x32, 0x33 items in active NFT collection and verify tokens data in chain', async () => {29 it('Create 0x31, 0x32, 0x33 items in active NFT collection and verify tokens data in chain', async () => {
34 await usingApi(async (api: ApiPromise) => {30 await usingApi(async (api: ApiPromise) => {
35 const collectionId = await createCollectionExpectSuccess();31 const collectionId = await createCollectionExpectSuccess();
36 const itemsListIndexBefore = await api.query.nft.itemListIndex(collectionId) as unknown as BN;32 const itemsListIndexBefore = await getLastTokenId(api, collectionId);
37 expect(itemsListIndexBefore.toNumber()).to.be.equal(0);33 expect(itemsListIndexBefore).to.be.equal(0);
38 const Alice = privateKey('//Alice');34 const alice = privateKey('//Alice');
39 const args = [{ nft: ['0x31', '0x31'] }, { nft: ['0x32', '0x32'] }, { nft: ['0x33', '0x33'] }];35 const args = [{NFT: ['0x31', '0x31']}, {NFT: ['0x32', '0x32']}, {NFT: ['0x33', '0x33']}];
40 const createMultipleItemsTx = api.tx.nft36 const createMultipleItemsTx = api.tx.nft
41 .createMultipleItems(collectionId, normalizeAccountId(Alice.address), args);37 .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);
42 await submitTransactionAsync(Alice, createMultipleItemsTx);38 await submitTransactionAsync(alice, createMultipleItemsTx);
43 const itemsListIndexAfter = await api.query.nft.itemListIndex(collectionId) as unknown as BN;39 const itemsListIndexAfter = await getLastTokenId(api, collectionId);
44 expect(itemsListIndexAfter.toNumber()).to.be.equal(3);40 expect(itemsListIndexAfter).to.be.equal(3);
45 const token1Data = (await api.query.nft.nftItemList(collectionId, 1)).toJSON() as unknown as ITokenDataType;
46 const token2Data = (await api.query.nft.nftItemList(collectionId, 2)).toJSON() as unknown as ITokenDataType;
47 const token3Data = (await api.query.nft.nftItemList(collectionId, 3)).toJSON() as unknown as ITokenDataType;
4841
49 expect(token1Data.owner).to.be.deep.equal(normalizeAccountId(Alice.address));42 expect(await getTokenOwner(api, collectionId, 1)).to.be.deep.equal(normalizeAccountId(alice.address));
50 expect(token2Data.owner).to.be.deep.equal(normalizeAccountId(Alice.address));43 expect(await getTokenOwner(api, collectionId, 2)).to.be.deep.equal(normalizeAccountId(alice.address));
51 expect(token3Data.owner).to.be.deep.equal(normalizeAccountId(Alice.address));44 expect(await getTokenOwner(api, collectionId, 3)).to.be.deep.equal(normalizeAccountId(alice.address));
5245
53 expect(token1Data.constData.toString()).to.be.equal('0x31');46 expect(await getConstMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);
54 expect(token2Data.constData.toString()).to.be.equal('0x32');47 expect(await getConstMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);
55 expect(token3Data.constData.toString()).to.be.equal('0x33');48 expect(await getConstMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);
5649
57 expect(token1Data.variableData.toString()).to.be.equal('0x31');50 expect(await getVariableMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);
58 expect(token2Data.variableData.toString()).to.be.equal('0x32');51 expect(await getVariableMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);
59 expect(token3Data.variableData.toString()).to.be.equal('0x33');52 expect(await getVariableMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);
60 });53 });
61 });54 });
6255
63 it('Create 0x01, 0x02, 0x03 items in active Fungible collection and verify tokens data in chain', async () => {56 it('Create 0x01, 0x02, 0x03 items in active Fungible collection and verify tokens data in chain', async () => {
64 await usingApi(async (api: ApiPromise) => {57 await usingApi(async (api: ApiPromise) => {
65 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});58 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
66 const itemsListIndexBefore = await api.query.nft.itemListIndex(collectionId) as unknown as BN;59 const itemsListIndexBefore = await getLastTokenId(api, collectionId);
67 expect(itemsListIndexBefore.toNumber()).to.be.equal(0);60 expect(itemsListIndexBefore).to.be.equal(0);
68 const Alice = privateKey('//Alice');61 const alice = privateKey('//Alice');
69 const args = [62 const args = [
70 {fungible: { value: 1 }},63 {Fungible: {value: 1}},
71 {fungible: { value: 2 }},64 {Fungible: {value: 2}},
72 {fungible: { value: 3 }},65 {Fungible: {value: 3}},
73 ];66 ];
74 const createMultipleItemsTx = api.tx.nft67 const createMultipleItemsTx = api.tx.nft
75 .createMultipleItems(collectionId, normalizeAccountId(Alice.address), args);68 .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);
76 await submitTransactionAsync(Alice, createMultipleItemsTx);69 await submitTransactionAsync(alice, createMultipleItemsTx);
77 const token1Data = (await api.query.nft.fungibleItemList(collectionId, Alice.address) as any).toJSON() as unknown as IFungibleTokenDataType;70 const token1Data = await getBalance(api, collectionId, alice.address, 0);
7871
79 expect(token1Data.value).to.be.equal(6); // 1 + 2 + 372 expect(token1Data).to.be.equal(6n); // 1 + 2 + 3
80 });73 });
81 });74 });
8275
83 it('Create 0x31, 0x32, 0x33 items in active ReFungible collection and verify tokens data in chain', async () => {76 it('Create 0x31, 0x32, 0x33 items in active ReFungible collection and verify tokens data in chain', async () => {
84 await usingApi(async (api: ApiPromise) => {77 await usingApi(async (api: ApiPromise) => {
85 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});78 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
86 const itemsListIndexBefore = await api.query.nft.itemListIndex(collectionId) as unknown as BN;79 const itemsListIndexBefore = await getLastTokenId(api, collectionId);
87 expect(itemsListIndexBefore.toNumber()).to.be.equal(0);80 expect(itemsListIndexBefore).to.be.equal(0);
88 const Alice = privateKey('//Alice');81 const alice = privateKey('//Alice');
89 const args = [82 const args = [
90 {refungible: {const_data: [0x31], variable_data: [0x31], pieces: 1}},83 {ReFungible: {const_data: [0x31], variable_data: [0x31], pieces: 1}},
91 {refungible: {const_data: [0x32], variable_data: [0x32], pieces: 1}},84 {ReFungible: {const_data: [0x32], variable_data: [0x32], pieces: 1}},
92 {refungible: {const_data: [0x33], variable_data: [0x33], pieces: 1}},85 {ReFungible: {const_data: [0x33], variable_data: [0x33], pieces: 1}},
93 ];86 ];
94 const createMultipleItemsTx = api.tx.nft87 const createMultipleItemsTx = api.tx.nft
95 .createMultipleItems(collectionId, normalizeAccountId(Alice.address), args);88 .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);
96 await submitTransactionAsync(Alice, createMultipleItemsTx);89 await submitTransactionAsync(alice, createMultipleItemsTx);
97 const itemsListIndexAfter = await api.query.nft.itemListIndex(collectionId) as unknown as BN;90 const itemsListIndexAfter = await getLastTokenId(api, collectionId);
98 expect(itemsListIndexAfter.toNumber()).to.be.equal(3);91 expect(itemsListIndexAfter).to.be.equal(3);
99 const token1Data = (await api.query.nft.reFungibleItemList(collectionId, 1) as any).toJSON() as unknown as IReFungibleTokenDataType;
100 const token2Data = (await api.query.nft.reFungibleItemList(collectionId, 2) as any).toJSON() as unknown as IReFungibleTokenDataType;
101 const token3Data = (await api.query.nft.reFungibleItemList(collectionId, 3) as any).toJSON() as unknown as IReFungibleTokenDataType;
10292
103 expect(token1Data.owner[0].owner).to.be.deep.equal(normalizeAccountId(Alice.address));93 expect(await getBalance(api, collectionId, alice.address, 1)).to.be.equal(1n);
94 expect(await getBalance(api, collectionId, alice.address, 2)).to.be.equal(1n);
104 expect(token1Data.owner[0].fraction).to.be.equal(1);95 expect(await getBalance(api, collectionId, alice.address, 3)).to.be.equal(1n);
10596
106 expect(token2Data.owner[0].owner).to.be.deep.equal(normalizeAccountId(Alice.address));97 expect(await getConstMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);
107 expect(token2Data.owner[0].fraction).to.be.equal(1);98 expect(await getConstMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);
99 expect(await getConstMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);
108100
109 expect(token3Data.owner[0].owner).to.be.deep.equal(normalizeAccountId(Alice.address));101 expect(await getVariableMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);
110 expect(token3Data.owner[0].fraction).to.be.equal(1);
111
112 expect(token1Data.constData.toString()).to.be.equal('0x31');
113 expect(token2Data.constData.toString()).to.be.equal('0x32');102 expect(await getVariableMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);
114 expect(token3Data.constData.toString()).to.be.equal('0x33');
115
116 expect(token1Data.variableData.toString()).to.be.equal('0x31');
117 expect(token2Data.variableData.toString()).to.be.equal('0x32');
118 expect(token3Data.variableData.toString()).to.be.equal('0x33');103 expect(await getVariableMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);
119 });104 });
120 });105 });
121106
128 tokenLimit: 2,113 tokenLimit: 2,
129 });114 });
130 const args = [115 const args = [
131 { nft: ['A', 'A'] },116 {NFT: ['A', 'A']},
132 { nft: ['B', 'B'] },117 {NFT: ['B', 'B']},
133 ];118 ];
134 const createMultipleItemsTx = api.tx.nft.createMultipleItems(collectionId, normalizeAccountId(alice.address), args);119 const createMultipleItemsTx = api.tx.nft.createMultipleItems(collectionId, normalizeAccountId(alice.address), args);
135 const events = await submitTransactionAsync(alice, createMultipleItemsTx);120 const events = await submitTransactionAsync(alice, createMultipleItemsTx);
141126
142describe('Integration Test createMultipleItems(collection_id, owner, items_data) with collection admin permissions:', () => {127describe('Integration Test createMultipleItems(collection_id, owner, items_data) with collection admin permissions:', () => {
143128
144 let Alice: IKeyringPair;129 let alice: IKeyringPair;
145 let Bob: IKeyringPair;130 let bob: IKeyringPair;
146131
147 before(async () => {132 before(async () => {
148 await usingApi(async () => {133 await usingApi(async () => {
149 Alice = privateKey('//Alice');134 alice = privateKey('//Alice');
150 Bob = privateKey('//Bob');135 bob = privateKey('//Bob');
151 });136 });
152 });137 });
153138
154 it('Create 0x31, 0x32, 0x33 items in active NFT collection and verify tokens data in chain', async () => {139 it('Create 0x31, 0x32, 0x33 items in active NFT collection and verify tokens data in chain', async () => {
155 await usingApi(async (api: ApiPromise) => {140 await usingApi(async (api: ApiPromise) => {
156 const collectionId = await createCollectionExpectSuccess();141 const collectionId = await createCollectionExpectSuccess();
157 const itemsListIndexBefore = await api.query.nft.itemListIndex(collectionId) as unknown as BN;142 const itemsListIndexBefore = await getLastTokenId(api, collectionId);
158 expect(itemsListIndexBefore.toNumber()).to.be.equal(0);143 expect(itemsListIndexBefore).to.be.equal(0);
159 await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);144 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
160 const args = [{ nft: ['0x31', '0x31'] }, { nft: ['0x32', '0x32'] }, { nft: ['0x33', '0x33'] }];145 const args = [{NFT: ['0x31', '0x31']}, {NFT: ['0x32', '0x32']}, {NFT: ['0x33', '0x33']}];
161 const createMultipleItemsTx = api.tx.nft146 const createMultipleItemsTx = api.tx.nft
162 .createMultipleItems(collectionId, normalizeAccountId(Bob.address), args);147 .createMultipleItems(collectionId, normalizeAccountId(bob.address), args);
163 await submitTransactionAsync(Bob, createMultipleItemsTx);148 await submitTransactionAsync(bob, createMultipleItemsTx);
164 const itemsListIndexAfter = await api.query.nft.itemListIndex(collectionId) as unknown as BN;149 const itemsListIndexAfter = await getLastTokenId(api, collectionId);
165 expect(itemsListIndexAfter.toNumber()).to.be.equal(3);150 expect(itemsListIndexAfter).to.be.equal(3);
166 const token1Data = (await api.query.nft.nftItemList(collectionId, 1)).toJSON() as unknown as ITokenDataType;
167 const token2Data = (await api.query.nft.nftItemList(collectionId, 2)).toJSON() as unknown as ITokenDataType;
168 const token3Data = (await api.query.nft.nftItemList(collectionId, 3)).toJSON() as unknown as ITokenDataType;
169151
170 expect(token1Data.owner).to.be.deep.equal(normalizeAccountId(Bob.address));152 expect(await getTokenOwner(api, collectionId, 1)).to.be.deep.equal(normalizeAccountId(bob.address));
171 expect(token2Data.owner).to.be.deep.equal(normalizeAccountId(Bob.address));153 expect(await getTokenOwner(api, collectionId, 2)).to.be.deep.equal(normalizeAccountId(bob.address));
172 expect(token3Data.owner).to.be.deep.equal(normalizeAccountId(Bob.address));154 expect(await getTokenOwner(api, collectionId, 3)).to.be.deep.equal(normalizeAccountId(bob.address));
173155
174 expect(token1Data.constData.toString()).to.be.equal('0x31');156 expect(await getConstMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);
175 expect(token2Data.constData.toString()).to.be.equal('0x32');157 expect(await getConstMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);
176 expect(token3Data.constData.toString()).to.be.equal('0x33');158 expect(await getConstMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);
177159
178 expect(token1Data.variableData.toString()).to.be.equal('0x31');160 expect(await getVariableMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);
179 expect(token2Data.variableData.toString()).to.be.equal('0x32');161 expect(await getVariableMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);
180 expect(token3Data.variableData.toString()).to.be.equal('0x33');162 expect(await getVariableMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);
181 });163 });
182 });164 });
183165
184 it('Create 0x01, 0x02, 0x03 items in active Fungible collection and verify tokens data in chain', async () => {166 it('Create 0x01, 0x02, 0x03 items in active Fungible collection and verify tokens data in chain', async () => {
185 await usingApi(async (api: ApiPromise) => {167 await usingApi(async (api: ApiPromise) => {
186 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});168 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
187 const itemsListIndexBefore = await api.query.nft.itemListIndex(collectionId) as unknown as BN;169 const itemsListIndexBefore = await getLastTokenId(api, collectionId);
188 expect(itemsListIndexBefore.toNumber()).to.be.equal(0);170 expect(itemsListIndexBefore).to.be.equal(0);
189 await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);171 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
190 const args = [172 const args = [
191 {fungible: { value: 1 }},173 {Fungible: {value: 1}},
192 {fungible: { value: 2 }},174 {Fungible: {value: 2}},
193 {fungible: { value: 3 }},175 {Fungible: {value: 3}},
194 ];176 ];
195 const createMultipleItemsTx = api.tx.nft177 const createMultipleItemsTx = api.tx.nft
196 .createMultipleItems(collectionId, normalizeAccountId(Bob.address), args);178 .createMultipleItems(collectionId, normalizeAccountId(bob.address), args);
197 await submitTransactionAsync(Bob, createMultipleItemsTx);179 await submitTransactionAsync(bob, createMultipleItemsTx);
198 const token1Data = (await api.query.nft.fungibleItemList(collectionId, Bob.address) as any).toJSON() as unknown as IFungibleTokenDataType;180 const token1Data = await getBalance(api, collectionId, bob.address, 0);
199181
200 expect(token1Data.value).to.be.equal(6); // 1 + 2 + 3182 expect(token1Data).to.be.equal(6n); // 1 + 2 + 3
201 });183 });
202 });184 });
203185
204 it('Create 0x31, 0x32, 0x33 items in active ReFungible collection and verify tokens data in chain', async () => {186 it('Create 0x31, 0x32, 0x33 items in active ReFungible collection and verify tokens data in chain', async () => {
205 await usingApi(async (api: ApiPromise) => {187 await usingApi(async (api: ApiPromise) => {
206 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});188 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
207 const itemsListIndexBefore = await api.query.nft.itemListIndex(collectionId) as unknown as BN;189 const itemsListIndexBefore = await getLastTokenId(api, collectionId);
208 expect(itemsListIndexBefore.toNumber()).to.be.equal(0);190 expect(itemsListIndexBefore).to.be.equal(0);
209 await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);191 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
210 const args = [192 const args = [
211 {refungible: {const_data: [0x31], variable_data: [0x31], pieces: 1}},193 {ReFungible: {const_data: [0x31], variable_data: [0x31], pieces: 1}},
212 {refungible: {const_data: [0x32], variable_data: [0x32], pieces: 1}},194 {ReFungible: {const_data: [0x32], variable_data: [0x32], pieces: 1}},
213 {refungible: {const_data: [0x33], variable_data: [0x33], pieces: 1}},195 {ReFungible: {const_data: [0x33], variable_data: [0x33], pieces: 1}},
214 ];196 ];
215 const createMultipleItemsTx = api.tx.nft197 const createMultipleItemsTx = api.tx.nft
216 .createMultipleItems(collectionId, normalizeAccountId(Bob.address), args);198 .createMultipleItems(collectionId, normalizeAccountId(bob.address), args);
217 await submitTransactionAsync(Bob, createMultipleItemsTx);199 await submitTransactionAsync(bob, createMultipleItemsTx);
218 const itemsListIndexAfter = await api.query.nft.itemListIndex(collectionId) as unknown as BN;200 const itemsListIndexAfter = await getLastTokenId(api, collectionId);
219 expect(itemsListIndexAfter.toNumber()).to.be.equal(3);201 expect(itemsListIndexAfter).to.be.equal(3);
220 const token1Data = (await api.query.nft.reFungibleItemList(collectionId, 1) as any).toJSON() as unknown as IReFungibleTokenDataType;
221 const token2Data = (await api.query.nft.reFungibleItemList(collectionId, 2) as any).toJSON() as unknown as IReFungibleTokenDataType;
222 const token3Data = (await api.query.nft.reFungibleItemList(collectionId, 3) as any).toJSON() as unknown as IReFungibleTokenDataType;
223202
224 expect(token1Data.owner[0].owner).to.be.deep.equal(normalizeAccountId(Bob.address));203 expect(await getBalance(api, collectionId, bob.address, 1)).to.be.equal(1n);
204 expect(await getBalance(api, collectionId, bob.address, 2)).to.be.equal(1n);
225 expect(token1Data.owner[0].fraction).to.be.equal(1);205 expect(await getBalance(api, collectionId, bob.address, 3)).to.be.equal(1n);
226206
227 expect(token2Data.owner[0].owner).to.be.deep.equal(normalizeAccountId(Bob.address));207 expect(await getConstMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);
228 expect(token2Data.owner[0].fraction).to.be.equal(1);208 expect(await getConstMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);
209 expect(await getConstMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);
229210
230 expect(token3Data.owner[0].owner).to.be.deep.equal(normalizeAccountId(Bob.address));211 expect(await getVariableMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);
231 expect(token3Data.owner[0].fraction).to.be.equal(1);
232
233 expect(token1Data.constData.toString()).to.be.equal('0x31');
234 expect(token2Data.constData.toString()).to.be.equal('0x32');212 expect(await getVariableMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);
235 expect(token3Data.constData.toString()).to.be.equal('0x33');
236
237 expect(token1Data.variableData.toString()).to.be.equal('0x31');
238 expect(token2Data.variableData.toString()).to.be.equal('0x32');
239 expect(token3Data.variableData.toString()).to.be.equal('0x33');213 expect(await getVariableMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);
240 });214 });
241 });215 });
242});216});
243217
244describe('Negative Integration Test createMultipleItems(collection_id, owner, items_data):', () => {218describe('Negative Integration Test createMultipleItems(collection_id, owner, items_data):', () => {
245219
246 let Alice: IKeyringPair;220 let alice: IKeyringPair;
247 let Bob: IKeyringPair;221 let bob: IKeyringPair;
248222
249 before(async () => {223 before(async () => {
250 await usingApi(async () => {224 await usingApi(async () => {
251 Alice = privateKey('//Alice');225 alice = privateKey('//Alice');
252 Bob = privateKey('//Bob');226 bob = privateKey('//Bob');
253 });227 });
254 });228 });
255229
256 it('Regular user cannot create items in active NFT collection', async () => {230 it('Regular user cannot create items in active NFT collection', async () => {
257 await usingApi(async (api: ApiPromise) => {231 await usingApi(async (api: ApiPromise) => {
258 const collectionId = await createCollectionExpectSuccess();232 const collectionId = await createCollectionExpectSuccess();
259 const itemsListIndexBefore = await api.query.nft.itemListIndex(collectionId) as unknown as BN;233 const itemsListIndexBefore = await getLastTokenId(api, collectionId);
260 expect(itemsListIndexBefore.toNumber()).to.be.equal(0);234 expect(itemsListIndexBefore).to.be.equal(0);
261 const args = [{ nft: ['0x31', '0x31'] }, { nft: ['0x32', '0x32'] }, { nft: ['0x33', '0x33'] }];235 const args = [{NFT: ['0x31', '0x31']}, {NFT: ['0x32', '0x32']}, {NFT: ['0x33', '0x33']}];
262 const createMultipleItemsTx = api.tx.nft236 const createMultipleItemsTx = api.tx.nft
263 .createMultipleItems(collectionId, normalizeAccountId(Alice.address), args);237 .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);
264 await expect(submitTransactionAsync(Bob, createMultipleItemsTx)).to.be.rejected;238 await expect(submitTransactionAsync(bob, createMultipleItemsTx)).to.be.rejected;
265 });239 });
266 });240 });
267241
268 it('Regular user cannot create items in active Fungible collection', async () => {242 it('Regular user cannot create items in active Fungible collection', async () => {
269 await usingApi(async (api: ApiPromise) => {243 await usingApi(async (api: ApiPromise) => {
270 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});244 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
271 const itemsListIndexBefore = await api.query.nft.itemListIndex(collectionId) as unknown as BN;245 const itemsListIndexBefore = await getLastTokenId(api, collectionId);
272 expect(itemsListIndexBefore.toNumber()).to.be.equal(0);246 expect(itemsListIndexBefore).to.be.equal(0);
273 const args = [247 const args = [
274 {fungible: { value: 1 }},248 {Fungible: {value: 1}},
275 {fungible: { value: 2 }},249 {Fungible: {value: 2}},
276 {fungible: { value: 3 }},250 {Fungible: {value: 3}},
277 ];251 ];
278 const createMultipleItemsTx = api.tx.nft252 const createMultipleItemsTx = api.tx.nft
279 .createMultipleItems(collectionId, normalizeAccountId(Alice.address), args);253 .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);
280 await expect(submitTransactionAsync(Bob, createMultipleItemsTx)).to.be.rejected;254 await expect(submitTransactionAsync(bob, createMultipleItemsTx)).to.be.rejected;
281 });255 });
282 });256 });
283257
284 it('Regular user cannot create items in active ReFungible collection', async () => {258 it('Regular user cannot create items in active ReFungible collection', async () => {
285 await usingApi(async (api: ApiPromise) => {259 await usingApi(async (api: ApiPromise) => {
286 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});260 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
287 const itemsListIndexBefore = await api.query.nft.itemListIndex(collectionId) as unknown as BN;261 const itemsListIndexBefore = await getLastTokenId(api, collectionId);
288 expect(itemsListIndexBefore.toNumber()).to.be.equal(0);262 expect(itemsListIndexBefore).to.be.equal(0);
289 const args = [263 const args = [
290 {refungible: {const_data: [0x31], variable_data: [0x31], pieces: 1}},264 {ReFungible: {const_data: [0x31], variable_data: [0x31], pieces: 1}},
291 {refungible: {const_data: [0x32], variable_data: [0x32], pieces: 1}},265 {ReFungible: {const_data: [0x32], variable_data: [0x32], pieces: 1}},
292 {refungible: {const_data: [0x33], variable_data: [0x33], pieces: 1}},266 {ReFungible: {const_data: [0x33], variable_data: [0x33], pieces: 1}},
293 ];267 ];
294 const createMultipleItemsTx = api.tx.nft268 const createMultipleItemsTx = api.tx.nft
295 .createMultipleItems(collectionId, normalizeAccountId(Alice.address), args);269 .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);
296 await expect(submitTransactionAsync(Bob, createMultipleItemsTx)).to.be.rejected;270 await expect(submitTransactionAsync(bob, createMultipleItemsTx)).to.be.rejected;
297 });271 });
298 });272 });
299273
300 it('Create token with not existing type', async () => {
301 await usingApi(async (api: ApiPromise) => {
302 const collectionId = await createCollectionExpectSuccess();
303 try {
304 const args = [{ invalid: null }, { invalid: null }, { invalid: null }];
305 const createMultipleItemsTx = await api.tx.nft
306 .createMultipleItems(collectionId, normalizeAccountId(Alice.address), args);
307 await expect(submitTransactionExpectFailAsync(Alice, createMultipleItemsTx)).to.be.rejected;
308 } catch (e) {
309 // tslint:disable-next-line:no-unused-expression
310 expect(e).to.be.exist;
311 }
312 });
313 });
314
315 it('Create token in not existing collection', async () => {274 it('Create token in not existing collection', async () => {
316 await usingApi(async (api: ApiPromise) => {275 await usingApi(async (api: ApiPromise) => {
317 const collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;276 const collectionId = (await api.query.common.createdCollectionCount()).toNumber() + 1;
318 const createMultipleItemsTx = api.tx.nft277 const createMultipleItemsTx = api.tx.nft
319 .createMultipleItems(collectionId, normalizeAccountId(Alice.address), ['NFT', 'NFT', 'NFT']);278 .createMultipleItems(collectionId, normalizeAccountId(alice.address), ['NFT', 'NFT', 'NFT']);
320 await expect(submitTransactionExpectFailAsync(Alice, createMultipleItemsTx)).to.be.rejected;279 await expect(submitTransactionExpectFailAsync(alice, createMultipleItemsTx)).to.be.rejected;
321 });280 });
322 });281 });
323282
324 it('Create NFT and Re-fungible tokens that has reached the maximum data limit', async () => {283 it('Create NFT and Re-fungible tokens that has reached the maximum data limit', async () => {
325 await usingApi(async (api: ApiPromise) => {284 await usingApi(async (api: ApiPromise) => {
326 // NFT285 // NFT
327 const collectionId = await createCollectionExpectSuccess();286 const collectionId = await createCollectionExpectSuccess();
328 const Alice = privateKey('//Alice');287 const alice = privateKey('//Alice');
329 const args = [288 const args = [
330 { nft: ['A'.repeat(2049), 'A'.repeat(2049)] },289 {NFT: ['A'.repeat(2049), 'A'.repeat(2049)]},
331 { nft: ['B'.repeat(2049), 'B'.repeat(2049)] },290 {NFT: ['B'.repeat(2049), 'B'.repeat(2049)]},
332 { nft: ['C'.repeat(2049), 'C'.repeat(2049)] },291 {NFT: ['C'.repeat(2049), 'C'.repeat(2049)]},
333 ];292 ];
334 const createMultipleItemsTx = api.tx.nft293 const createMultipleItemsTx = api.tx.nft
335 .createMultipleItems(collectionId, normalizeAccountId(Alice.address), args);294 .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);
336 await expect(submitTransactionExpectFailAsync(Alice, createMultipleItemsTx)).to.be.rejected;295 await expect(submitTransactionExpectFailAsync(alice, createMultipleItemsTx)).to.be.rejected;
337296
338 // ReFungible297 // ReFungible
339 const collectionIdReFungible =298 const collectionIdReFungible =
340 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});299 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
341 const argsReFungible = [300 const argsReFungible = [
342 { ReFungible: ['1'.repeat(2049), '1'.repeat(2049), 10] },301 {ReFungible: ['1'.repeat(2049), '1'.repeat(2049), 10]},
343 { ReFungible: ['2'.repeat(2049), '2'.repeat(2049), 10] },302 {ReFungible: ['2'.repeat(2049), '2'.repeat(2049), 10]},
344 { ReFungible: ['3'.repeat(2049), '3'.repeat(2049), 10] },303 {ReFungible: ['3'.repeat(2049), '3'.repeat(2049), 10]},
345 ];304 ];
346 const createMultipleItemsTxFungible = api.tx.nft305 const createMultipleItemsTxFungible = api.tx.nft
347 .createMultipleItems(collectionIdReFungible, normalizeAccountId(Alice.address), argsReFungible);306 .createMultipleItems(collectionIdReFungible, normalizeAccountId(alice.address), argsReFungible);
348 await expect(submitTransactionExpectFailAsync(Alice, createMultipleItemsTxFungible)).to.be.rejected;307 await expect(submitTransactionExpectFailAsync(alice, createMultipleItemsTxFungible)).to.be.rejected;
349 });308 });
350 });309 });
351310
352 it('Create tokens with different types', async () => {311 it('Create tokens with different types', async () => {
353 await usingApi(async (api: ApiPromise) => {312 await usingApi(async (api: ApiPromise) => {
354 const collectionId = await createCollectionExpectSuccess();313 const collectionId = await createCollectionExpectSuccess();
355 const createMultipleItemsTx = api.tx.nft314 const createMultipleItemsTx = api.tx.nft
356 .createMultipleItems(collectionId, normalizeAccountId(Alice.address), ['NFT', 'Fungible', 'ReFungible']);315 .createMultipleItems(collectionId, normalizeAccountId(alice.address), ['NFT', 'Fungible', 'ReFungible']);
357 await expect(submitTransactionExpectFailAsync(Alice, createMultipleItemsTx)).to.be.rejected;316 await expect(submitTransactionExpectFailAsync(alice, createMultipleItemsTx)).to.be.rejected;
358 // garbage collection :-D317 // garbage collection :-D
359 await destroyCollectionExpectSuccess(collectionId);318 await destroyCollectionExpectSuccess(collectionId);
360 });319 });
364 await usingApi(async (api: ApiPromise) => {323 await usingApi(async (api: ApiPromise) => {
365 const collectionId = await createCollectionExpectSuccess();324 const collectionId = await createCollectionExpectSuccess();
366 const args = [325 const args = [
367 { nft: ['A', 'A'] },326 {NFT: ['A', 'A']},
368 { nft: ['B', 'B'.repeat(2049)] },327 {NFT: ['B', 'B'.repeat(2049)]},
369 { nft: ['C'.repeat(2049), 'C'] },328 {NFT: ['C'.repeat(2049), 'C']},
370 ];329 ];
371 const createMultipleItemsTx = await api.tx.nft330 const createMultipleItemsTx = await api.tx.nft
372 .createMultipleItems(collectionId, normalizeAccountId(Alice.address), args);331 .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);
373 await expect(submitTransactionExpectFailAsync(Alice, createMultipleItemsTx)).to.be.rejected;332 await expect(submitTransactionExpectFailAsync(alice, createMultipleItemsTx)).to.be.rejected;
374 });333 });
375 });334 });
376335
377 it('Fails when minting tokens exceeds collectionLimits amount', async () => {336 it('Fails when minting tokens exceeds collectionLimits amount', async () => {
378 await usingApi(async (api) => {337 await usingApi(async (api) => {
379338
380 const collectionId = await createCollectionExpectSuccess();339 const collectionId = await createCollectionExpectSuccess();
381 await setCollectionLimitsExpectSuccess(Alice, collectionId, {340 await setCollectionLimitsExpectSuccess(alice, collectionId, {
382 tokenLimit: 1,341 tokenLimit: 1,
383 });342 });
384 const args = [343 const args = [
385 { nft: ['A', 'A'] },344 {NFT: ['A', 'A']},
386 { nft: ['B', 'B'] },345 {NFT: ['B', 'B']},
387 ];346 ];
388 const createMultipleItemsTx = api.tx.nft.createMultipleItems(collectionId, normalizeAccountId(Alice.address), args);347 const createMultipleItemsTx = api.tx.nft.createMultipleItems(collectionId, normalizeAccountId(alice.address), args);
389 await expect(submitTransactionExpectFailAsync(Alice, createMultipleItemsTx)).to.be.rejected;348 await expect(submitTransactionExpectFailAsync(alice, createMultipleItemsTx)).to.be.rejected;
390 });349 });
391 });350 });
392});351});
modifiedtests/src/creditFeesToTreasury.test.tsdiffbeforeafterboth
8import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from './substrate/substrate-api';8import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';
9import { alicesPublicKey, bobsPublicKey } from './accounts';9import {alicesPublicKey, bobsPublicKey} from './accounts';
10import privateKey from './substrate/privateKey';10import privateKey from './substrate/privateKey';
11import { BigNumber } from 'bignumber.js';
12import { IKeyringPair } from '@polkadot/types/types';11import {IKeyringPair} from '@polkadot/types/types';
13import { 12import {
14 createCollectionExpectSuccess, 13 createCollectionExpectSuccess,
23chai.use(chaiAsPromised);22chai.use(chaiAsPromised);
24const expect = chai.expect;23const expect = chai.expect;
2524
26const Treasury = '5EYCAe5ijiYfyeZ2JJCGq56LmPyNRAKzpG4QkoQkkQNB5e6Z';25const TREASURY = '5EYCAe5ijiYfyeZ2JJCGq56LmPyNRAKzpG4QkoQkkQNB5e6Z';
27const saneMinimumFee = 0.05;26const saneMinimumFee = 0.05;
28const saneMaximumFee = 0.5;27const saneMaximumFee = 0.5;
29const createCollectionDeposit = 100;28const createCollectionDeposit = 100;
3029
31let alice: IKeyringPair;30let alice: IKeyringPair;
32let bob: IKeyringPair;31let bob: IKeyringPair;
3332
34// Skip the inflation block pauses if the block is close to inflation block 33// Skip the inflation block pauses if the block is close to inflation block
35// until the inflation happens34// until the inflation happens
36/*eslint no-async-promise-executor: "off"*/35/*eslint no-async-promise-executor: "off"*/
37function skipInflationBlock(api: ApiPromise): Promise<void> {36function skipInflationBlock(api: ApiPromise): Promise<void> {
38 const promise = new Promise<void>(async (resolve) => {37 const promise = new Promise<void>(async (resolve) => {
39 const blockInterval = parseInt((await api.consts.inflation.inflationBlockInterval).toString());38 const blockInterval = (await api.consts.inflation.inflationBlockInterval).toNumber();
40 const unsubscribe = await api.rpc.chain.subscribeNewHeads(head => {39 const unsubscribe = await api.rpc.chain.subscribeNewHeads(head => {
41 const currentBlock = parseInt(head.number.toString());40 const currentBlock = head.number.toNumber();
42 if (currentBlock % blockInterval < blockInterval - 10) {41 if (currentBlock % blockInterval < blockInterval - 10) {
43 unsubscribe();42 unsubscribe();
44 resolve();43 resolve();
64 await skipInflationBlock(api);63 await skipInflationBlock(api);
65 await waitNewBlocks(api, 1);64 await waitNewBlocks(api, 1);
6665
67 const totalBefore = new BigNumber((await api.query.balances.totalIssuance()).toString());66 const totalBefore = (await api.query.balances.totalIssuance()).toBigInt();
6867
69 const alicePrivateKey = privateKey('//Alice');68 const alicePrivateKey = privateKey('//Alice');
70 const amount = new BigNumber(1);69 const amount = 1n;
71 const transfer = api.tx.balances.transfer(bobsPublicKey, amount.toFixed());70 const transfer = api.tx.balances.transfer(bobsPublicKey, amount);
7271
73 const result = getGenericResult(await submitTransactionAsync(alicePrivateKey, transfer));72 const result = getGenericResult(await submitTransactionAsync(alicePrivateKey, transfer));
7473
75 const totalAfter = new BigNumber((await api.query.balances.totalIssuance()).toString());74 const totalAfter = (await api.query.balances.totalIssuance()).toBigInt();
7675
77 expect(result.success).to.be.true;76 expect(result.success).to.be.true;
78 expect(totalAfter.toFixed()).to.be.equal(totalBefore.toFixed());77 expect(totalAfter).to.be.equal(totalBefore);
79 });78 });
80 });79 });
8180
85 await waitNewBlocks(api, 1);84 await waitNewBlocks(api, 1);
8685
87 const alicePrivateKey = privateKey('//Alice');86 const alicePrivateKey = privateKey('//Alice');
88 const treasuryBalanceBefore = new BigNumber((await api.query.system.account(Treasury)).data.free.toString());87 const treasuryBalanceBefore: bigint = (await api.query.system.account(TREASURY)).data.free.toBigInt();
89 const aliceBalanceBefore = new BigNumber((await api.query.system.account(alicesPublicKey)).data.free.toString());88 const aliceBalanceBefore: bigint = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();
9089
91 const amount = new BigNumber(1);90 const amount = 1n;
92 const transfer = api.tx.balances.transfer(bobsPublicKey, amount.toFixed());91 const transfer = api.tx.balances.transfer(bobsPublicKey, amount);
93 const result = getGenericResult(await submitTransactionAsync(alicePrivateKey, transfer));92 const result = getGenericResult(await submitTransactionAsync(alicePrivateKey, transfer));
9493
95 const treasuryBalanceAfter = new BigNumber((await api.query.system.account(Treasury)).data.free.toString());94 const treasuryBalanceAfter: bigint = (await api.query.system.account(TREASURY)).data.free.toBigInt();
96 const aliceBalanceAfter = new BigNumber((await api.query.system.account(alicesPublicKey)).data.free.toString());95 const aliceBalanceAfter: bigint = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();
97 const fee = aliceBalanceBefore.minus(aliceBalanceAfter).minus(amount);96 const fee = aliceBalanceBefore - aliceBalanceAfter - amount;
98 const treasuryIncrease = treasuryBalanceAfter.minus(treasuryBalanceBefore);97 const treasuryIncrease = treasuryBalanceAfter - treasuryBalanceBefore;
9998
100 expect(result.success).to.be.true;99 expect(result.success).to.be.true;
101 expect(treasuryIncrease.toFixed()).to.be.equal(fee.toFixed());100 expect(treasuryIncrease).to.be.equal(fee);
102 });101 });
103 });102 });
104103
108 await waitNewBlocks(api, 1);107 await waitNewBlocks(api, 1);
109108
110 const bobPrivateKey = privateKey('//Bob');109 const bobPrivateKey = privateKey('//Bob');
111 const treasuryBalanceBefore = new BigNumber((await api.query.system.account(Treasury)).data.free.toString());110 const treasuryBalanceBefore = (await api.query.system.account(TREASURY)).data.free.toBigInt();
112 const bobBalanceBefore = new BigNumber((await api.query.system.account(bobsPublicKey)).data.free.toString());111 const bobBalanceBefore = (await api.query.system.account(bobsPublicKey)).data.free.toBigInt();
113112
114 const badTx = api.tx.balances.setBalance(alicesPublicKey, 0, 0);113 const badTx = api.tx.balances.setBalance(alicesPublicKey, 0, 0);
115 await expect(submitTransactionExpectFailAsync(bobPrivateKey, badTx)).to.be.rejected;114 await expect(submitTransactionExpectFailAsync(bobPrivateKey, badTx)).to.be.rejected;
116115
117 const treasuryBalanceAfter = new BigNumber((await api.query.system.account(Treasury)).data.free.toString());116 const treasuryBalanceAfter = (await api.query.system.account(TREASURY)).data.free.toBigInt();
118 const bobBalanceAfter = new BigNumber((await api.query.system.account(bobsPublicKey)).data.free.toString());117 const bobBalanceAfter = (await api.query.system.account(bobsPublicKey)).data.free.toBigInt();
119 const fee = bobBalanceBefore.minus(bobBalanceAfter);118 const fee = bobBalanceBefore - bobBalanceAfter;
120 const treasuryIncrease = treasuryBalanceAfter.minus(treasuryBalanceBefore);119 const treasuryIncrease = treasuryBalanceAfter - treasuryBalanceBefore;
121120
122 expect(treasuryIncrease.toFixed()).to.be.equal(fee.toFixed());121 expect(treasuryIncrease).to.be.equal(fee);
123 });122 });
124 });123 });
125124
128 await skipInflationBlock(api);127 await skipInflationBlock(api);
129 await waitNewBlocks(api, 1);128 await waitNewBlocks(api, 1);
130129
131 const treasuryBalanceBefore = new BigNumber((await api.query.system.account(Treasury)).data.free.toString());130 const treasuryBalanceBefore = (await api.query.system.account(TREASURY)).data.free.toBigInt();
132 const aliceBalanceBefore = new BigNumber((await api.query.system.account(alicesPublicKey)).data.free.toString());131 const aliceBalanceBefore = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();
133132
134 await createCollectionExpectSuccess();133 await createCollectionExpectSuccess();
135134
136 const treasuryBalanceAfter = new BigNumber((await api.query.system.account(Treasury)).data.free.toString());135 const treasuryBalanceAfter = (await api.query.system.account(TREASURY)).data.free.toBigInt();
137 const aliceBalanceAfter = new BigNumber((await api.query.system.account(alicesPublicKey)).data.free.toString());136 const aliceBalanceAfter = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();
138 const fee = aliceBalanceBefore.minus(aliceBalanceAfter);137 const fee = aliceBalanceBefore - aliceBalanceAfter;
139 const treasuryIncrease = treasuryBalanceAfter.minus(treasuryBalanceBefore);138 const treasuryIncrease = treasuryBalanceAfter - treasuryBalanceBefore;
140139
141 expect(treasuryIncrease.toFixed()).to.be.equal(fee.toFixed());140 expect(treasuryIncrease).to.be.equal(fee);
142 });141 });
143 });142 });
144143
147 await skipInflationBlock(api);146 await skipInflationBlock(api);
148 await waitNewBlocks(api, 1);147 await waitNewBlocks(api, 1);
149148
150 const aliceBalanceBefore = new BigNumber((await api.query.system.account(alicesPublicKey)).data.free.toString());149 const aliceBalanceBefore: bigint = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();
151150
152 await createCollectionExpectSuccess();151 await createCollectionExpectSuccess();
153152
154 const aliceBalanceAfter = new BigNumber((await api.query.system.account(alicesPublicKey)).data.free.toString());153 const aliceBalanceAfter: bigint = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();
155 const fee = aliceBalanceBefore.minus(aliceBalanceAfter);154 const fee = aliceBalanceBefore - aliceBalanceAfter;
156155
157 expect(fee.dividedBy(1e15).toNumber()).to.be.lessThan(saneMaximumFee + createCollectionDeposit);156 expect(fee / 10n ** 15n < BigInt(Math.ceil(saneMaximumFee + createCollectionDeposit))).to.be.true;
158 expect(fee.dividedBy(1e15).toNumber()).to.be.greaterThan(saneMinimumFee + createCollectionDeposit);157 expect(fee / 10n ** 15n < BigInt(Math.ceil(saneMinimumFee + createCollectionDeposit))).to.be.true;
159 });158 });
160 });159 });
161160
167 const collectionId = await createCollectionExpectSuccess();166 const collectionId = await createCollectionExpectSuccess();
168 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');167 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');
169168
170 const aliceBalanceBefore = new BigNumber((await api.query.system.account(alicesPublicKey)).data.free.toString());169 const aliceBalanceBefore: bigint = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();
171 await transferExpectSuccess(collectionId, tokenId, alice, bob, 1, 'NFT');170 await transferExpectSuccess(collectionId, tokenId, alice, bob, 1, 'NFT');
172 const aliceBalanceAfter = new BigNumber((await api.query.system.account(alicesPublicKey)).data.free.toString());171 const aliceBalanceAfter: bigint = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();
173 const fee = aliceBalanceBefore.minus(aliceBalanceAfter);172 const fee = aliceBalanceBefore - aliceBalanceAfter;
174173
175 // console.log(fee.toString());174 // console.log(fee.toString());
176 const expectedTransferFee = 0.1;175 const expectedTransferFee = 0.1;
177 const tolerance = 0.001;176 const tolerance = 0.001;
178 expect(fee.dividedBy(1e15).minus(expectedTransferFee).abs().toNumber()).to.be.lessThan(tolerance);177 expect(Number(fee) / 1e15 - expectedTransferFee).to.be.lessThan(tolerance);
179 });178 });
180 });179 });
181180
modifiedtests/src/destroyCollection.test.tsdiffbeforeafterboth
46 it('(!negative test!) Destroy a collection that never existed', async () => {46 it('(!negative test!) Destroy a collection that never existed', async () => {
47 await usingApi(async (api) => {47 await usingApi(async (api) => {
48 // Find the collection that never existed48 // Find the collection that never existed
49 const collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;49 const collectionId = (await api.query.common.createdCollectionCount()).toNumber() + 1;
50 await destroyCollectionExpectFailure(collectionId);50 await destroyCollectionExpectFailure(collectionId);
51 });51 });
52 });52 });
62 });62 });
63 it('(!negative test!) Destroy a collection using collection admin account', async () => {63 it('(!negative test!) Destroy a collection using collection admin account', async () => {
64 const collectionId = await createCollectionExpectSuccess();64 const collectionId = await createCollectionExpectSuccess();
65 await addCollectionAdminExpectSuccess(alice, collectionId, bob);65 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
66 await destroyCollectionExpectFailure(collectionId, '//Bob');66 await destroyCollectionExpectFailure(collectionId, '//Bob');
67 });67 });
68 it('fails when OwnerCanDestroy == false', async () => {68 it('fails when OwnerCanDestroy == false', async () => {
modifiedtests/src/enableContractSponsoring.test.tsdiffbeforeafterboth

no syntactic changes

modifiedtests/src/enableDisableTransfer.test.tsdiffbeforeafterboth
21describe('Enable/Disable Transfers', () => {21describe('Enable/Disable Transfers', () => {
22 it('User can transfer token with enabled transfer flag', async () => {22 it('User can transfer token with enabled transfer flag', async () => {
23 await usingApi(async () => {23 await usingApi(async () => {
24 const Alice = privateKey('//Alice');24 const alice = privateKey('//Alice');
25 const Bob = privateKey('//Bob');25 const bob = privateKey('//Bob');
26 // nft26 // nft
27 const nftCollectionId = await createCollectionExpectSuccess();27 const nftCollectionId = await createCollectionExpectSuccess();
28 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');28 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
2929
30 // explicitely set transfer flag30 // explicitely set transfer flag
31 await setTransferFlagExpectSuccess(Alice, nftCollectionId, true);31 await setTransferFlagExpectSuccess(alice, nftCollectionId, true);
3232
33 await transferExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 1);33 await transferExpectSuccess(nftCollectionId, newNftTokenId, alice, bob, 1);
34 });34 });
35 });35 });
3636
37 it('User can\'n transfer token with disabled transfer flag', async () => {37 it('User can\'n transfer token with disabled transfer flag', async () => {
38 await usingApi(async () => {38 await usingApi(async () => {
39 const Alice = privateKey('//Alice');39 const alice = privateKey('//Alice');
40 const Bob = privateKey('//Bob');40 const bob = privateKey('//Bob');
41 // nft41 // nft
42 const nftCollectionId = await createCollectionExpectSuccess();42 const nftCollectionId = await createCollectionExpectSuccess();
43 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');43 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
4444
45 // explicitely set transfer flag45 // explicitely set transfer flag
46 await setTransferFlagExpectSuccess(Alice, nftCollectionId, false);46 await setTransferFlagExpectSuccess(alice, nftCollectionId, false);
4747
48 await transferExpectFailure(nftCollectionId, newNftTokenId, Alice, Bob, 1);48 await transferExpectFailure(nftCollectionId, newNftTokenId, alice, bob, 1);
49 });49 });
50 });50 });
51});51});
5252
53describe('Negative Enable/Disable Transfers', () => {53describe('Negative Enable/Disable Transfers', () => {
54 it('Non-owner cannot change transfer flag', async () => {54 it('Non-owner cannot change transfer flag', async () => {
55 await usingApi(async () => {55 await usingApi(async () => {
56 const Bob = privateKey('//Bob');56 const bob = privateKey('//Bob');
57 // nft57 // nft
58 const nftCollectionId = await createCollectionExpectSuccess();58 const nftCollectionId = await createCollectionExpectSuccess();
5959
60 // Change transfer flag60 // Change transfer flag
61 await setTransferFlagExpectFailure(Bob, nftCollectionId, false);61 await setTransferFlagExpectFailure(bob, nftCollectionId, false);
62 });62 });
63 });63 });
64});64});
modifiedtests/src/eth/allowlist.test.tsdiffbeforeafterboth
1import { expect } from 'chai';1import {expect} from 'chai';
2import waitNewBlocks from '../substrate/wait-new-blocks';
3import { contractHelpers, createEthAccount, createEthAccountWithBalance, deployFlipper, itWeb3, usingWeb3Http } from './util/helpers';2import {contractHelpers, createEthAccount, createEthAccountWithBalance, deployFlipper, itWeb3} from './util/helpers';
43
5describe('EVM allowlist', () => {4describe('EVM allowlist', () => {
6 itWeb3('Contract allowlist can be toggled', async ({ api }) => {5 itWeb3('Contract allowlist can be toggled', async ({api, web3}) => {
7 await usingWeb3Http(async web3Http => {6 const owner = await createEthAccountWithBalance(api, web3);
8 const owner = await createEthAccountWithBalance(api, web3Http);7 const flipper = await deployFlipper(web3, owner);
9 const flipper = await deployFlipper(web3Http, owner);8 const randomUser = createEthAccount(web3);
10 await waitNewBlocks(api, 1);9
11 const randomUser = createEthAccount(web3Http);10 const helpers = contractHelpers(web3, owner);
12
13 const helpers = contractHelpers(web3Http, owner);
1411
15 // Any user is allowed by default12 // Any user is allowed by default
16 expect(await helpers.methods.allowlistEnabled(flipper.options.address).call()).to.be.false;13 expect(await helpers.methods.allowlistEnabled(flipper.options.address).call()).to.be.false;
17 expect(await helpers.methods.allowed(flipper.options.address, randomUser).call()).to.be.true;14 expect(await helpers.methods.allowed(flipper.options.address, randomUser).call()).to.be.true;
18 await waitNewBlocks(api, 1);
1915
20 // Enable16 // Enable
21 await helpers.methods.toggleAllowlist(flipper.options.address, true).send({ from: owner });17 await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});
22 await waitNewBlocks(api, 1);
23 expect(await helpers.methods.allowlistEnabled(flipper.options.address).call()).to.be.true;18 expect(await helpers.methods.allowlistEnabled(flipper.options.address).call()).to.be.true;
24 expect(await helpers.methods.allowed(flipper.options.address, randomUser).call()).to.be.false;19 expect(await helpers.methods.allowed(flipper.options.address, randomUser).call()).to.be.false;
2520
26 // Disable21 // Disable
27 await helpers.methods.toggleAllowlist(flipper.options.address, false).send({ from: owner });22 await helpers.methods.toggleAllowlist(flipper.options.address, false).send({from: owner});
28 await waitNewBlocks(api, 1);
29 expect(await helpers.methods.allowlistEnabled(flipper.options.address).call()).to.be.false;23 expect(await helpers.methods.allowlistEnabled(flipper.options.address).call()).to.be.false;
30 expect(await helpers.methods.allowed(flipper.options.address, randomUser).call()).to.be.true;24 expect(await helpers.methods.allowed(flipper.options.address, randomUser).call()).to.be.true;
31 });
32 });25 });
3326
34 itWeb3('Non-whitelisted user can\'t call contract with allowlist enabled', async ({ api }) => {27 itWeb3('Non-whitelisted user can\'t call contract with allowlist enabled', async ({api, web3}) => {
35 await usingWeb3Http(async web3Http => {28 const owner = await createEthAccountWithBalance(api, web3);
36 const owner = await createEthAccountWithBalance(api, web3Http);29 const flipper = await deployFlipper(web3, owner);
37 const flipper = await deployFlipper(web3Http, owner);30 const caller = await createEthAccountWithBalance(api, web3);
38 await waitNewBlocks(api, 1);31
39 const caller = await createEthAccountWithBalance(api, web3Http);32 const helpers = contractHelpers(web3, owner);
40
41 const helpers = contractHelpers(web3Http, owner);
4233
43 // User can flip with allowlist disabled34 // User can flip with allowlist disabled
44 await flipper.methods.flip().send({ from: caller });35 await flipper.methods.flip().send({from: caller});
45 await waitNewBlocks(api, 1);
46 expect(await flipper.methods.getValue().call()).to.be.true;36 expect(await flipper.methods.getValue().call()).to.be.true;
4737
48 // Tx will be reverted if user is not in whitelist38 // Tx will be reverted if user is not in whitelist
49 await helpers.methods.toggleAllowlist(flipper.options.address, true).send({ from: owner });39 await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});
50 await expect(flipper.methods.flip().send({ from: caller })).to.rejected;40 await expect(flipper.methods.flip().send({from: caller})).to.rejected;
51 await waitNewBlocks(api, 1);
52 expect(await flipper.methods.getValue().call()).to.be.true;41 expect(await flipper.methods.getValue().call()).to.be.true;
5342
54 // Adding caller to allowlist will make contract callable again43 // Adding caller to allowlist will make contract callable again
55 await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner});44 await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner});
56 await flipper.methods.flip().send({ from: caller });45 await flipper.methods.flip().send({from: caller});
57 await waitNewBlocks(api, 1);
58 expect(await flipper.methods.getValue().call()).to.be.false;46 expect(await flipper.methods.getValue().call()).to.be.false;
59 });
60 });47 });
61});48});
49
modifiedtests/src/eth/base.test.tsdiffbeforeafterboth
6describe('Contract calls', () => {6describe('Contract calls', () => {
7 itWeb3('Call of simple contract fee is less than 0.2 UNQ', async ({ web3, api }) => {7 itWeb3('Call of simple contract fee is less than 0.2 UNQ', async ({web3, api}) => {
8 const deployer = await createEthAccountWithBalance(api, web3);8 const deployer = await createEthAccountWithBalance(api, web3);
9 const flipper = await deployFlipper(web3 as any, deployer);9 const flipper = await deployFlipper(web3, deployer);
1010
11 const cost = await recordEthFee(api, deployer, () => flipper.methods.flip().send({from: deployer}));11 const cost = await recordEthFee(api, deployer, () => flipper.methods.flip().send({from: deployer}));
12 expect(cost < BigInt(0.2 * Number(UNIQUE))).to.be.true;12 expect(cost < BigInt(0.2 * Number(UNIQUE))).to.be.true;
modifiedtests/src/eth/contractSponsoring.test.tsdiffbeforeafterboth
11 transferBalanceToEth,11 transferBalanceToEth,
12 deployFlipper,12 deployFlipper,
13 itWeb3 } from './util/helpers';13 itWeb3} from './util/helpers';
14import waitNewBlocks from '../substrate/wait-new-blocks';
1514
16describe('Sponsoring EVM contracts', () => {15describe('Sponsoring EVM contracts', () => {
17 itWeb3('Sponsoring can be set by the address that has deployed the contract', async ({api, web3}) => {16 itWeb3('Sponsoring can be set by the address that has deployed the contract', async ({api, web3}) => {
18 const owner = await createEthAccountWithBalance(api, web3);17 const owner = await createEthAccountWithBalance(api, web3);
19 const flipper = await deployFlipper(web3, owner);18 const flipper = await deployFlipper(web3, owner);
20 await waitNewBlocks(api, 1);
21 const helpers = contractHelpers(web3, owner);19 const helpers = contractHelpers(web3, owner);
22 await waitNewBlocks(api, 1);
23 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;20 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;
24 await waitNewBlocks(api, 1);
25 await helpers.methods.toggleSponsoring(flipper.options.address, true).send({from: owner});21 await helpers.methods.toggleSponsoring(flipper.options.address, true).send({from: owner});
26 await waitNewBlocks(api, 1);
27 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;22 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;
28 });23 });
2924
30 itWeb3('Sponsoring cannot be set by the address that did not deployed the contract', async ({api, web3}) => {25 itWeb3('Sponsoring cannot be set by the address that did not deployed the contract', async ({api, web3}) => {
31 const owner = await createEthAccountWithBalance(api, web3);26 const owner = await createEthAccountWithBalance(api, web3);
32 const notOwner = await createEthAccountWithBalance(api, web3);27 const notOwner = await createEthAccountWithBalance(api, web3);
33 const flipper = await deployFlipper(web3, owner);28 const flipper = await deployFlipper(web3, owner);
34 await waitNewBlocks(api, 1);
35 const helpers = contractHelpers(web3, owner);29 const helpers = contractHelpers(web3, owner);
36 await waitNewBlocks(api, 1);
37 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;30 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;
38 await waitNewBlocks(api, 1);
39 await expect(helpers.methods.toggleSponsoring(notOwner, true).send({from: notOwner})).to.rejected;31 await expect(helpers.methods.toggleSponsoring(notOwner, true).send({from: notOwner})).to.rejected;
40 await waitNewBlocks(api, 1);
41 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;32 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;
42 });33 });
4334
48 const caller = await createEthAccountWithBalance(api, web3);39 const caller = await createEthAccountWithBalance(api, web3);
4940
50 const flipper = await deployFlipper(web3, owner);41 const flipper = await deployFlipper(web3, owner);
51 await waitNewBlocks(api, 1);42
52
53 const helpers = contractHelpers(web3, owner);43 const helpers = contractHelpers(web3, owner);
54 await helpers.methods.toggleAllowlist(flipper.options.address, true).send({ from: owner });44 await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});
55 await waitNewBlocks(api, 1);
56 await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({ from: owner });45 await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner});
57 await waitNewBlocks(api, 1);
5846
59 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;47 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;
60 await helpers.methods.toggleSponsoring(flipper.options.address, true).send({from: owner});48 await helpers.methods.toggleSponsoring(flipper.options.address, true).send({from: owner});
61 await waitNewBlocks(api, 1);
62 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});49 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});
63 await waitNewBlocks(api, 1);
64 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;50 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;
6551
66 await transferBalanceToEth(api, alice, flipper.options.address);52 await transferBalanceToEth(api, alice, flipper.options.address);
67 await waitNewBlocks(api, 2);
6853
69 const originalFlipperBalance = await web3.eth.getBalance(flipper.options.address);54 const originalFlipperBalance = await web3.eth.getBalance(flipper.options.address);
70 expect(originalFlipperBalance).to.be.not.equal('0');55 expect(originalFlipperBalance).to.be.not.equal('0');
7156
72 await flipper.methods.flip().send({ from: caller });57 await flipper.methods.flip().send({from: caller});
73 await waitNewBlocks(api, 1);
74 expect(await flipper.methods.getValue().call()).to.be.true;58 expect(await flipper.methods.getValue().call()).to.be.true;
7559
76 // Balance should be taken from flipper instead of caller60 // Balance should be taken from flipper instead of caller
85 const caller = await createEthAccountWithBalance(api, web3);69 const caller = await createEthAccountWithBalance(api, web3);
8670
87 const flipper = await deployFlipper(web3, owner);71 const flipper = await deployFlipper(web3, owner);
88 await waitNewBlocks(api, 1);72
89
90 const helpers = contractHelpers(web3, owner);73 const helpers = contractHelpers(web3, owner);
9174
92 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;75 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;
93 await helpers.methods.toggleSponsoring(flipper.options.address, true).send({from: owner});76 await helpers.methods.toggleSponsoring(flipper.options.address, true).send({from: owner});
94 await waitNewBlocks(api, 1);
95 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});77 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});
96 await waitNewBlocks(api, 1);
97 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;78 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;
9879
99 await transferBalanceToEth(api, alice, flipper.options.address);80 await transferBalanceToEth(api, alice, flipper.options.address);
100 await waitNewBlocks(api, 2);
10181
102 const originalFlipperBalance = await web3.eth.getBalance(flipper.options.address);82 const originalFlipperBalance = await web3.eth.getBalance(flipper.options.address);
103 expect(originalFlipperBalance).to.be.not.equal('0');83 expect(originalFlipperBalance).to.be.not.equal('0');
10484
105 await flipper.methods.flip().send({ from: caller });85 await flipper.methods.flip().send({from: caller});
106 await waitNewBlocks(api, 1);
107 expect(await flipper.methods.getValue().call()).to.be.true;86 expect(await flipper.methods.getValue().call()).to.be.true;
10887
109 // Balance should be taken from flipper instead of caller88 // Balance should be taken from flipper instead of caller
119 const originalCallerBalance = await web3.eth.getBalance(caller);98 const originalCallerBalance = await web3.eth.getBalance(caller);
12099
121 const flipper = await deployFlipper(web3, owner);100 const flipper = await deployFlipper(web3, owner);
122 await waitNewBlocks(api, 1);101
123
124 const helpers = contractHelpers(web3, owner);102 const helpers = contractHelpers(web3, owner);
125 await helpers.methods.toggleAllowlist(flipper.options.address, true).send({ from: owner });103 await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});
126 await waitNewBlocks(api, 1);
127 await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({ from: owner });104 await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner});
128 await waitNewBlocks(api, 1);
129105
130 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;106 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;
131 await helpers.methods.toggleSponsoring(flipper.options.address, true).send({from: owner});107 await helpers.methods.toggleSponsoring(flipper.options.address, true).send({from: owner});
132 await waitNewBlocks(api, 1);
133 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});108 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});
134 await waitNewBlocks(api, 1);
135 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;109 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;
136110
137 await transferBalanceToEth(api, alice, flipper.options.address);111 await transferBalanceToEth(api, alice, flipper.options.address);
138 await waitNewBlocks(api, 2);
139112
140 const originalFlipperBalance = await web3.eth.getBalance(flipper.options.address);113 const originalFlipperBalance = await web3.eth.getBalance(flipper.options.address);
141 expect(originalFlipperBalance).to.be.not.equal('0');114 expect(originalFlipperBalance).to.be.not.equal('0');
142115
143 await flipper.methods.flip().send({ from: caller });116 await flipper.methods.flip().send({from: caller});
144 await waitNewBlocks(api, 1);
145 expect(await flipper.methods.getValue().call()).to.be.true;117 expect(await flipper.methods.getValue().call()).to.be.true;
146118
147 expect(await web3.eth.getBalance(caller)).to.be.equals(originalCallerBalance);119 expect(await web3.eth.getBalance(caller)).to.be.equals(originalCallerBalance);
155 const originalCallerBalance = await web3.eth.getBalance(caller);127 const originalCallerBalance = await web3.eth.getBalance(caller);
156128
157 const flipper = await deployFlipper(web3, owner);129 const flipper = await deployFlipper(web3, owner);
158 await waitNewBlocks(api, 1);130
159
160 const helpers = contractHelpers(web3, owner);131 const helpers = contractHelpers(web3, owner);
161 await helpers.methods.toggleAllowlist(flipper.options.address, true).send({ from: owner });132 await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});
162 await waitNewBlocks(api, 1);
163 await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({ from: owner });133 await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner});
164 await waitNewBlocks(api, 1);
165134
166 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;135 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;
167 await helpers.methods.toggleSponsoring(flipper.options.address, true).send({from: owner});136 await helpers.methods.toggleSponsoring(flipper.options.address, true).send({from: owner});
168 await waitNewBlocks(api, 1);
169 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 10).send({from: owner});137 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 10).send({from: owner});
170 await waitNewBlocks(api, 1);
171 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;138 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;
172139
173 await transferBalanceToEth(api, alice, flipper.options.address);140 await transferBalanceToEth(api, alice, flipper.options.address);
174 await waitNewBlocks(api, 2);
175141
176 const originalFlipperBalance = await web3.eth.getBalance(flipper.options.address);142 const originalFlipperBalance = await web3.eth.getBalance(flipper.options.address);
177 expect(originalFlipperBalance).to.be.not.equal('0');143 expect(originalFlipperBalance).to.be.not.equal('0');
178144
179 await flipper.methods.flip().send({ from: caller });145 await flipper.methods.flip().send({from: caller});
180 await waitNewBlocks(api, 1);
181 expect(await flipper.methods.getValue().call()).to.be.true;146 expect(await flipper.methods.getValue().call()).to.be.true;
182 expect(await web3.eth.getBalance(caller)).to.be.equals(originalCallerBalance);147 expect(await web3.eth.getBalance(caller)).to.be.equals(originalCallerBalance);
183148
184 await flipper.methods.flip().send({ from: caller });149 await flipper.methods.flip().send({from: caller});
185 await waitNewBlocks(api, 1);
186 expect(await web3.eth.getBalance(caller)).to.be.not.equals(originalCallerBalance);150 expect(await web3.eth.getBalance(caller)).to.be.not.equals(originalCallerBalance);
187 });151 });
188152
189 // TODO: Find a way to calculate default rate limit 153 // TODO: Find a way to calculate default rate limit
190 itWeb3('Default rate limit equals 7200', async ({api, web3}) => {154 itWeb3('Default rate limit equals 7200', async ({api, web3}) => {
191 const owner = await createEthAccountWithBalance(api, web3);155 const owner = await createEthAccountWithBalance(api, web3);
192 const flipper = await deployFlipper(web3, owner);156 const flipper = await deployFlipper(web3, owner);
193 await waitNewBlocks(api, 1);
194 const helpers = contractHelpers(web3, owner);157 const helpers = contractHelpers(web3, owner);
195 await waitNewBlocks(api, 1);
196 expect(await helpers.methods.getSponsoringRateLimit(flipper.options.address).call()).to.be.equals('7200');158 expect(await helpers.methods.getSponsoringRateLimit(flipper.options.address).call()).to.be.equals('7200');
197 });159 });
198160
203 const caller = await createEthAccountWithBalance(api, web3);165 const caller = await createEthAccountWithBalance(api, web3);
204166
205 const flipper = await deployFlipper(web3, owner);167 const flipper = await deployFlipper(web3, owner);
206 await waitNewBlocks(api, 1);168
207
208 const helpers = contractHelpers(web3, owner);169 const helpers = contractHelpers(web3, owner);
209170
210 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;171 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;
211 await helpers.methods.toggleSponsoring(flipper.options.address, true).send({from: owner});172 await helpers.methods.toggleSponsoring(flipper.options.address, true).send({from: owner});
212 await waitNewBlocks(api, 1);
213 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});173 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});
214 await waitNewBlocks(api, 1);
215 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;174 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;
216175
217 await transferBalanceToEth(api, alice, flipper.options.address);176 await transferBalanceToEth(api, alice, flipper.options.address);
218 await waitNewBlocks(api, 2);
219177
220 const originalFlipperBalance = await web3.eth.getBalance(flipper.options.address);178 const originalFlipperBalance = await web3.eth.getBalance(flipper.options.address);
221 expect(originalFlipperBalance).to.be.not.equal('0');179 expect(originalFlipperBalance).to.be.not.equal('0');
222180
223 await flipper.methods.flip().send({ from: caller });181 await flipper.methods.flip().send({from: caller});
224 await waitNewBlocks(api, 1);
225 expect(await flipper.methods.getValue().call()).to.be.true;182 expect(await flipper.methods.getValue().call()).to.be.true;
226183
227 // Balance should be taken from flipper instead of caller184 // Balance should be taken from flipper instead of caller
modifiedtests/src/eth/crossTransfer.test.tsdiffbeforeafterboth
25 const alice = privateKey('//Alice');25 const alice = privateKey('//Alice');
26 const bob = privateKey('//Bob');26 const bob = privateKey('//Bob');
27 const charlie = privateKey('//Charlie');27 const charlie = privateKey('//Charlie');
28 await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { substrate: alice.address });28 await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Substrate: alice.address});
29 await transferExpectSuccess(collection, 0, alice, {ethereum: subToEth(charlie.address)} , 200, 'Fungible');29 await transferExpectSuccess(collection, 0, alice, {Ethereum: subToEth(charlie.address)} , 200, 'Fungible');
30 await transferFromExpectSuccess(collection, 0, alice, {ethereum: subToEth(charlie.address)}, charlie, 50, 'Fungible');30 await transferFromExpectSuccess(collection, 0, alice, {Ethereum: subToEth(charlie.address)}, charlie, 50, 'Fungible');
31 await transferExpectSuccess(collection, 0, charlie, bob, 50, 'Fungible');31 await transferExpectSuccess(collection, 0, charlie, bob, 50, 'Fungible');
32 });32 });
3333
42 const aliceProxy = await createEthAccountWithBalance(api, web3);42 const aliceProxy = await createEthAccountWithBalance(api, web3);
4343
44 await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, alice.address);44 await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, alice.address);
45 await transferExpectSuccess(collection, 0, alice, { ethereum: aliceProxy } , 200, 'Fungible');45 await transferExpectSuccess(collection, 0, alice, {Ethereum: aliceProxy} , 200, 'Fungible');
46 const address = collectionIdToAddress(collection);46 const address = collectionIdToAddress(collection);
47 const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: aliceProxy, ...GAS_ARGS});47 const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: aliceProxy, ...GAS_ARGS});
4848
49 await contract.methods.transfer(bobProxy, 50).send({ from: aliceProxy });49 await contract.methods.transfer(bobProxy, 50).send({from: aliceProxy});
50 await transferFromExpectSuccess(collection, 0, alice, {ethereum: bobProxy}, bob, 50, 'Fungible');50 await transferFromExpectSuccess(collection, 0, alice, {Ethereum: bobProxy}, bob, 50, 'Fungible');
51 await transferExpectSuccess(collection, 0, bob, alice, 50, 'Fungible');51 await transferExpectSuccess(collection, 0, bob, alice, 50, 'Fungible');
52 });52 });
53});53});
61 const alice = privateKey('//Alice');61 const alice = privateKey('//Alice');
62 const bob = privateKey('//Bob');62 const bob = privateKey('//Bob');
63 const charlie = privateKey('//Charlie');63 const charlie = privateKey('//Charlie');
64 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { substrate: alice.address });64 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Substrate: alice.address});
65 await transferExpectSuccess(collection, tokenId, alice, { ethereum: subToEth(charlie.address) }, 1, 'NFT');65 await transferExpectSuccess(collection, tokenId, alice, {Ethereum: subToEth(charlie.address)}, 1, 'NFT');
66 await transferFromExpectSuccess(collection, tokenId, alice, {ethereum: subToEth(charlie.address)}, charlie, 1, 'NFT');66 await transferFromExpectSuccess(collection, tokenId, alice, {Ethereum: subToEth(charlie.address)}, charlie, 1, 'NFT');
67 await transferExpectSuccess(collection, tokenId, charlie, bob, 1, 'NFT');67 await transferExpectSuccess(collection, tokenId, charlie, bob, 1, 'NFT');
68 });68 });
6969
77 const charlie = privateKey('//Charlie');77 const charlie = privateKey('//Charlie');
78 const bobProxy = await createEthAccountWithBalance(api, web3);78 const bobProxy = await createEthAccountWithBalance(api, web3);
79 const aliceProxy = await createEthAccountWithBalance(api, web3);79 const aliceProxy = await createEthAccountWithBalance(api, web3);
80 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { substrate: alice.address });80 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Substrate: alice.address});
81 await transferExpectSuccess(collection, tokenId, alice, { ethereum: aliceProxy } , 1, 'NFT');81 await transferExpectSuccess(collection, tokenId, alice, {Ethereum: aliceProxy} , 1, 'NFT');
82 const address = collectionIdToAddress(collection);82 const address = collectionIdToAddress(collection);
83 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: aliceProxy, ...GAS_ARGS});83 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: aliceProxy, ...GAS_ARGS});
84 await contract.methods.transfer(bobProxy, 1).send({ from: aliceProxy });84 await contract.methods.transfer(bobProxy, 1).send({from: aliceProxy});
85 await transferFromExpectSuccess(collection, tokenId, alice, {ethereum: bobProxy}, bob, 1, 'NFT');85 await transferFromExpectSuccess(collection, tokenId, alice, {Ethereum: bobProxy}, bob, 1, 'NFT');
86 await transferExpectSuccess(collection, tokenId, bob, charlie, 1, 'NFT');86 await transferExpectSuccess(collection, tokenId, bob, charlie, 1, 'NFT');
87 });87 });
88});88});
modifiedtests/src/eth/fungible.test.tsdiffbeforeafterboth
1919
20 const caller = await createEthAccountWithBalance(api, web3);20 const caller = await createEthAccountWithBalance(api, web3);
21 21
22 await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { substrate: alice.address });22 await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Substrate: alice.address});
2323
24 const address = collectionIdToAddress(collection);24 const address = collectionIdToAddress(collection);
25 const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: caller, ...GAS_ARGS});25 const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: caller, ...GAS_ARGS});
26 const totalSupply = await contract.methods.totalSupply().call();26 const totalSupply = await contract.methods.totalSupply().call();
2727
28 // FIXME: always equals to 0, because this method is not implemented
29 expect(totalSupply).to.equal('0');28 expect(totalSupply).to.equal('200');
30 });29 });
3130
32 itWeb3('balanceOf', async ({ api, web3 }) => {31 itWeb3('balanceOf', async ({api, web3}) => {
3837
39 const caller = await createEthAccountWithBalance(api, web3);38 const caller = await createEthAccountWithBalance(api, web3);
4039
41 await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { ethereum: caller });40 await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: caller});
4241
43 const address = collectionIdToAddress(collection);42 const address = collectionIdToAddress(collection);
44 const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: caller, ...GAS_ARGS});43 const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: caller, ...GAS_ARGS});
5857
59 const owner = await createEthAccountWithBalance(api, web3);58 const owner = await createEthAccountWithBalance(api, web3);
6059
61 await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { ethereum: owner });60 await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: owner});
6261
63 const spender = createEthAccount(web3);62 const spender = createEthAccount(web3);
6463
98 const owner = createEthAccount(web3);97 const owner = createEthAccount(web3);
99 await transferBalanceToEth(api, alice, owner, 999999999999999);98 await transferBalanceToEth(api, alice, owner, 999999999999999);
10099
101 await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { ethereum: owner });100 await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: owner});
102101
103 const spender = createEthAccount(web3);102 const spender = createEthAccount(web3);
104 await transferBalanceToEth(api, alice, spender, 999999999999999);103 await transferBalanceToEth(api, alice, spender, 999999999999999);
156 const owner = createEthAccount(web3);155 const owner = createEthAccount(web3);
157 await transferBalanceToEth(api, alice, owner, 999999999999999);156 await transferBalanceToEth(api, alice, owner, 999999999999999);
158157
159 await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { ethereum: owner });158 await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: owner});
160159
161 const receiver = createEthAccount(web3);160 const receiver = createEthAccount(web3);
162 await transferBalanceToEth(api, alice, receiver, 999999999999999);161 await transferBalanceToEth(api, alice, receiver, 999999999999999);
202 const owner = await createEthAccountWithBalance(api, web3);201 const owner = await createEthAccountWithBalance(api, web3);
203 const spender = createEthAccount(web3);202 const spender = createEthAccount(web3);
204203
205 await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { ethereum: owner });204 await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: owner});
206205
207 const address = collectionIdToAddress(collection);206 const address = collectionIdToAddress(collection);
208 const contract = new web3.eth.Contract(fungibleAbi as any, address, { from: owner, ...GAS_ARGS });207 const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: owner, ...GAS_ARGS});
220 const owner = await createEthAccountWithBalance(api, web3);219 const owner = await createEthAccountWithBalance(api, web3);
221 const spender = await createEthAccountWithBalance(api, web3);220 const spender = await createEthAccountWithBalance(api, web3);
222221
223 await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { ethereum: owner });222 await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: owner});
224223
225 const address = collectionIdToAddress(collection);224 const address = collectionIdToAddress(collection);
226 const contract = new web3.eth.Contract(fungibleAbi as any, address, { from: owner, ...GAS_ARGS });225 const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: owner, ...GAS_ARGS});
240 const owner = await createEthAccountWithBalance(api, web3);239 const owner = await createEthAccountWithBalance(api, web3);
241 const receiver = createEthAccount(web3);240 const receiver = createEthAccount(web3);
242241
243 await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { ethereum: owner });242 await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: owner});
244243
245 const address = collectionIdToAddress(collection);244 const address = collectionIdToAddress(collection);
246 const contract = new web3.eth.Contract(fungibleAbi as any, address, { from: owner, ...GAS_ARGS });245 const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: owner, ...GAS_ARGS});
265 const contract = new web3.eth.Contract(fungibleAbi as any, address);264 const contract = new web3.eth.Contract(fungibleAbi as any, address);
266265
267 const events = await recordEvents(contract, async () => {266 const events = await recordEvents(contract, async () => {
268 await approveExpectSuccess(collection, 1, alice, { ethereum: receiver }, 100);267 await approveExpectSuccess(collection, 0, alice, {Ethereum: receiver}, 100);
269 });268 });
270269
271 expect(events).to.be.deep.equal([270 expect(events).to.be.deep.equal([
291 const receiver = createEthAccount(web3);290 const receiver = createEthAccount(web3);
292291
293 await createFungibleItemExpectSuccess(alice, collection, { Value: 200n });292 await createFungibleItemExpectSuccess(alice, collection, {Value: 200n});
294 await approveExpectSuccess(collection, 1, alice, bob, 100);293 await approveExpectSuccess(collection, 0, alice, bob.address, 100);
295294
296 const address = collectionIdToAddress(collection);295 const address = collectionIdToAddress(collection);
297 const contract = new web3.eth.Contract(fungibleAbi as any, address);296 const contract = new web3.eth.Contract(fungibleAbi as any, address);
298297
299 const events = await recordEvents(contract, async () => {298 const events = await recordEvents(contract, async () => {
300 await transferFromExpectSuccess(collection, 1, bob, alice, { ethereum: receiver }, 51, 'Fungible');299 await transferFromExpectSuccess(collection, 0, bob, alice, {Ethereum: receiver}, 51, 'Fungible');
301 });300 });
302301
303 expect(events).to.be.deep.equal([302 expect(events).to.be.deep.equal([
336 const contract = new web3.eth.Contract(fungibleAbi as any, address);335 const contract = new web3.eth.Contract(fungibleAbi as any, address);
337336
338 const events = await recordEvents(contract, async () => {337 const events = await recordEvents(contract, async () => {
339 await transferExpectSuccess(collection, 1, alice, { ethereum: receiver }, 51, 'Fungible');338 await transferExpectSuccess(collection, 0, alice, {Ethereum:receiver}, 51, 'Fungible');
340 });339 });
341340
342 expect(events).to.be.deep.equal([341 expect(events).to.be.deep.equal([
modifiedtests/src/eth/helpersSmoke.test.tsdiffbeforeafterboth
1import { expect } from 'chai';1import {expect} from 'chai';
2import waitNewBlocks from '../substrate/wait-new-blocks';
3import { createEthAccountWithBalance, deployFlipper, itWeb3, contractHelpers } from './util/helpers';2import {createEthAccountWithBalance, deployFlipper, itWeb3, contractHelpers} from './util/helpers';
43
5describe('Helpers sanity check', () => {4describe('Helpers sanity check', () => {
6 itWeb3('Contract owner is recorded', async ({ api, web3 }) => {5 itWeb3('Contract owner is recorded', async ({api, web3}) => {
7 const owner = await createEthAccountWithBalance(api, web3);6 const owner = await createEthAccountWithBalance(api, web3);
87
9 const flipper = await deployFlipper(web3, owner);8 const flipper = await deployFlipper(web3, owner);
10 await waitNewBlocks(api, 1);
119
12 expect(await contractHelpers(web3, owner).methods.contractOwner(flipper.options.address).call()).to.be.equal(owner);10 expect(await contractHelpers(web3, owner).methods.contractOwner(flipper.options.address).call()).to.be.equal(owner);
13 });11 });
1412
15 itWeb3('Flipper is working', async ({ api, web3 }) => {13 itWeb3('Flipper is working', async ({api, web3}) => {
16 const owner = await createEthAccountWithBalance(api, web3);14 const owner = await createEthAccountWithBalance(api, web3);
17 const flipper = await deployFlipper(web3, owner);15 const flipper = await deployFlipper(web3, owner);
18 await waitNewBlocks(api, 1);
1916
20 expect(await flipper.methods.getValue().call()).to.be.false;17 expect(await flipper.methods.getValue().call()).to.be.false;
21 await flipper.methods.flip().send({ from: owner });18 await flipper.methods.flip().send({from: owner});
22 await waitNewBlocks(api, 1);
23 expect(await flipper.methods.getValue().call()).to.be.true;19 expect(await flipper.methods.getValue().call()).to.be.true;
24 });20 });
25});21});
modifiedtests/src/eth/marketplace/marketplace.test.tsdiffbeforeafterboth
1import { readFile } from 'fs/promises';1import {readFile} from 'fs/promises';
2import { getBalanceSingle, transferBalanceExpectSuccess } from '../../substrate/get-balance';2import {getBalanceSingle, transferBalanceExpectSuccess} from '../../substrate/get-balance';
3import privateKey from '../../substrate/privateKey';3import privateKey from '../../substrate/privateKey';
4import { createCollectionExpectSuccess, createFungibleItemExpectSuccess, createItemExpectSuccess, queryNftOwner, transferExpectSuccess, transferFromExpectSuccess } from '../../util/helpers';4import {createCollectionExpectSuccess, createFungibleItemExpectSuccess, createItemExpectSuccess, getTokenOwner, transferExpectSuccess, transferFromExpectSuccess} from '../../util/helpers';
5import { collectionIdToAddress, createEthAccountWithBalance, executeEthTxOnSub, GAS_ARGS, itWeb3, subToEth, subToEthLowercase } from '../util/helpers';5import {collectionIdToAddress, createEthAccountWithBalance, executeEthTxOnSub, GAS_ARGS, itWeb3, subToEth, subToEthLowercase} from '../util/helpers';
6import { evmToAddress } from '@polkadot/util-crypto';6import {evmToAddress} from '@polkadot/util-crypto';
7import nonFungibleAbi from '../nonFungibleAbi.json';7import nonFungibleAbi from '../nonFungibleAbi.json';
8import fungibleAbi from '../fungibleAbi.json';8import fungibleAbi from '../fungibleAbi.json';
9import waitNewBlocks from '../../substrate/wait-new-blocks';
10import { expect } from 'chai';9import {expect} from 'chai';
1110
12const PRICE = 2000n;11const PRICE = 2000n;
1312
14describe('Matcher contract usage', () => {13describe('Matcher contract usage', () => {
15 itWeb3('With UNQ', async ({api, web3}) => {14 itWeb3('With UNQ', async ({api, web3}) => {
16 const matcherOwner = await createEthAccountWithBalance(api, web3);15 const matcherOwner = await createEthAccountWithBalance(api, web3);
17 const Matcher = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/MarketPlaceUNQ.abi`)).toString()), undefined, {16 const matcherContract = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/MarketPlaceUNQ.abi`)).toString()), undefined, {
18 from: matcherOwner,17 from: matcherOwner,
19 ...GAS_ARGS,18 ...GAS_ARGS,
20 });19 });
21 const matcher = await Matcher.deploy({ data: (await readFile(`${__dirname}/MarketPlaceUNQ.bin`)).toString() }).send({ from: matcherOwner });20 const matcher = await matcherContract.deploy({data: (await readFile(`${__dirname}/MarketPlaceUNQ.bin`)).toString()}).send({from: matcherOwner});
2221
23 const alice = privateKey('//Alice');22 const alice = privateKey('//Alice');
24 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});23 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
29 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT', seller.address);28 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT', seller.address);
3029
31 // To transfer item to matcher it first needs to be transfered to EVM account of bob30 // To transfer item to matcher it first needs to be transfered to EVM account of bob
32 await transferExpectSuccess(collectionId, tokenId, seller, {ethereum: subToEth(seller.address)});31 await transferExpectSuccess(collectionId, tokenId, seller, {Ethereum: subToEth(seller.address)});
33 // Fees will be paid from EVM account, so we should have some balance here32 // Fees will be paid from EVM account, so we should have some balance here
34 await transferBalanceExpectSuccess(api, seller, evmToAddress(subToEth(seller.address)), 10n ** 18n);33 await transferBalanceExpectSuccess(api, seller, evmToAddress(subToEth(seller.address)), 10n ** 18n);
35 await transferBalanceExpectSuccess(api, alice, evmToAddress(subToEth(alice.address)), 10n ** 18n);34 await transferBalanceExpectSuccess(api, alice, evmToAddress(subToEth(alice.address)), 10n ** 18n);
36 await waitNewBlocks(api, 1);
3735
38 // Token is owned by seller initially36 // Token is owned by seller initially
39 expect(await queryNftOwner(api, collectionId, tokenId)).to.be.deep.equal({ ethereum: subToEthLowercase(seller.address) });37 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal({Ethereum: subToEthLowercase(seller.address)});
4038
41 // Ask39 // Ask
42 {40 {
45 }43 }
46 44
47 // Token is transferred to matcher45 // Token is transferred to matcher
48 expect(await queryNftOwner(api, collectionId, tokenId)).to.be.deep.equal({ ethereum: matcher.options.address.toLowerCase() });46 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal({Ethereum: matcher.options.address.toLowerCase()});
4947
50 // Buy48 // Buy
51 {49 {
56 }54 }
5755
58 // Token is transferred to evm account of alice56 // Token is transferred to evm account of alice
59 expect(await queryNftOwner(api, collectionId, tokenId)).to.be.deep.equal({ ethereum: subToEthLowercase(alice.address) });57 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal({Ethereum: subToEthLowercase(alice.address)});
6058
61 59
62 // Transfer token to substrate side of alice60 // Transfer token to substrate side of alice
63 await transferFromExpectSuccess(collectionId, tokenId, alice, { ethereum: subToEth(alice.address) }, { substrate: alice.address });61 await transferFromExpectSuccess(collectionId, tokenId, alice, {Ethereum: subToEth(alice.address)}, {Substrate: alice.address});
64 62
65 // Token is transferred to substrate account of alice, seller received funds63 // Token is transferred to substrate account of alice, seller received funds
66 expect(await queryNftOwner(api, collectionId, tokenId)).to.be.deep.equal({ substrate: alice.address });64 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal({Substrate: alice.address});
67 });65 });
6866
69 itWeb3('With custom ERC20', async ({api, web3}) => {67 itWeb3('With custom ERC20', async ({api, web3}) => {
70 const matcherOwner = await createEthAccountWithBalance(api, web3);68 const matcherOwner = await createEthAccountWithBalance(api, web3);
71 const Matcher = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/MarketPlaceUNQ.abi`)).toString()), undefined, {69 const matcherContract = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/MarketPlaceUNQ.abi`)).toString()), undefined, {
72 from: matcherOwner,70 from: matcherOwner,
73 ...GAS_ARGS,71 ...GAS_ARGS,
74 });72 });
75 const matcher = await Matcher.deploy({ data: (await readFile(`${__dirname}/MarketPlaceUNQ.bin`)).toString() }).send({ from: matcherOwner });73 const matcher = await matcherContract.deploy({data: (await readFile(`${__dirname}/MarketPlaceUNQ.bin`)).toString()}).send({from: matcherOwner});
7674
77 const alice = privateKey('//Alice');75 const alice = privateKey('//Alice');
78 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});76 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
79 const evmCollection = new web3.eth.Contract(nonFungibleAbi as any, collectionIdToAddress(collectionId), { from: matcherOwner });77 const evmCollection = new web3.eth.Contract(nonFungibleAbi as any, collectionIdToAddress(collectionId), {from: matcherOwner});
8078
81 const fungibleId = await createCollectionExpectSuccess({ mode: { type: 'Fungible', decimalPoints: 0 } });79 const fungibleId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
82 const evmFungible = new web3.eth.Contract(fungibleAbi as any, collectionIdToAddress(fungibleId), { from: matcherOwner, ...GAS_ARGS });80 const evmFungible = new web3.eth.Contract(fungibleAbi as any, collectionIdToAddress(fungibleId), {from: matcherOwner, ...GAS_ARGS});
83 await createFungibleItemExpectSuccess(alice, fungibleId, { Value: PRICE }, { ethereum: subToEth(alice.address) });81 await createFungibleItemExpectSuccess(alice, fungibleId, {Value: PRICE}, {Ethereum: subToEth(alice.address)});
8482
85 const seller = privateKey('//Bob');83 const seller = privateKey('//Bob');
86 84
87 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT', seller.address);85 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT', seller.address);
8886
89 // To transfer item to matcher it first needs to be transfered to EVM account of bob87 // To transfer item to matcher it first needs to be transfered to EVM account of bob
90 await transferExpectSuccess(collectionId, tokenId, seller, {ethereum: subToEth(seller.address)});88 await transferExpectSuccess(collectionId, tokenId, seller, {Ethereum: subToEth(seller.address)});
91 // Fees will be paid from EVM account, so we should have some balance here89 // Fees will be paid from EVM account, so we should have some balance here
92 await transferBalanceExpectSuccess(api, seller, evmToAddress(subToEth(seller.address)), 10n ** 18n);90 await transferBalanceExpectSuccess(api, seller, evmToAddress(subToEth(seller.address)), 10n ** 18n);
93 await transferBalanceExpectSuccess(api, alice, evmToAddress(subToEth(alice.address)), 10n ** 18n);91 await transferBalanceExpectSuccess(api, alice, evmToAddress(subToEth(alice.address)), 10n ** 18n);
94 await waitNewBlocks(api, 1);
9592
96 // Token is owned by seller initially93 // Token is owned by seller initially
97 expect(await queryNftOwner(api, collectionId, tokenId)).to.be.deep.equal({ ethereum: subToEthLowercase(seller.address) });94 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal({Ethereum: subToEthLowercase(seller.address)});
9895
99 // Ask96 // Ask
100 {97 {
103 }100 }
104 101
105 // Token is transferred to matcher102 // Token is transferred to matcher
106 expect(await queryNftOwner(api, collectionId, tokenId)).to.be.deep.equal({ ethereum: matcher.options.address.toLowerCase() });103 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal({Ethereum: matcher.options.address.toLowerCase()});
107104
108 // Buy105 // Buy
109 {106 {
121 }118 }
122119
123 // Token is transferred to evm account of alice120 // Token is transferred to evm account of alice
124 expect(await queryNftOwner(api, collectionId, tokenId)).to.be.deep.equal({ ethereum: subToEthLowercase(alice.address) });121 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal({Ethereum: subToEthLowercase(alice.address)});
125122
126 123
127 // Transfer token to substrate side of alice124 // Transfer token to substrate side of alice
128 await transferFromExpectSuccess(collectionId, tokenId, alice, { ethereum: subToEth(alice.address) }, { substrate: alice.address });125 await transferFromExpectSuccess(collectionId, tokenId, alice, {Ethereum: subToEth(alice.address)}, {Substrate: alice.address});
129 126
130 // Token is transferred to substrate account of alice127 // Token is transferred to substrate account of alice
131 expect(await queryNftOwner(api, collectionId, tokenId)).to.be.deep.equal({ substrate: alice.address });128 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal({Substrate: alice.address});
132 });129 });
133130
134 itWeb3('With escrow', async ({ api, web3 }) => {131 itWeb3('With escrow', async ({api, web3}) => {
135 const matcherOwner = await createEthAccountWithBalance(api, web3);132 const matcherOwner = await createEthAccountWithBalance(api, web3);
136 const escrow = await createEthAccountWithBalance(api, web3);133 const escrow = await createEthAccountWithBalance(api, web3);
137 const Matcher = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/MarketPlaceKSM.abi`)).toString()), undefined, {134 const matcherContract = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/MarketPlaceKSM.abi`)).toString()), undefined, {
138 from: matcherOwner,135 from: matcherOwner,
139 ...GAS_ARGS,136 ...GAS_ARGS,
140 });137 });
141 const matcher = await Matcher.deploy({ data: (await readFile(`${__dirname}/MarketPlaceKSM.bin`)).toString(), arguments: [escrow] }).send({ from: matcherOwner });138 const matcher = await matcherContract.deploy({data: (await readFile(`${__dirname}/MarketPlaceKSM.bin`)).toString(), arguments: [escrow]}).send({from: matcherOwner});
142 139
143 const ksmToken = 11;140 const ksmToken = 11;
144141
151 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT', seller.address);148 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT', seller.address);
152149
153 // To transfer item to matcher it first needs to be transfered to EVM account of bob150 // To transfer item to matcher it first needs to be transfered to EVM account of bob
154 await transferExpectSuccess(collectionId, tokenId, seller, {ethereum: subToEth(seller.address)});151 await transferExpectSuccess(collectionId, tokenId, seller, {Ethereum: subToEth(seller.address)});
155 // Fees will be paid from EVM account, so we should have some balance here152 // Fees will be paid from EVM account, so we should have some balance here
156 await transferBalanceExpectSuccess(api, seller, evmToAddress(subToEth(seller.address)), 10n ** 18n);153 await transferBalanceExpectSuccess(api, seller, evmToAddress(subToEth(seller.address)), 10n ** 18n);
157 await transferBalanceExpectSuccess(api, alice, evmToAddress(subToEth(alice.address)), 10n ** 18n);154 await transferBalanceExpectSuccess(api, alice, evmToAddress(subToEth(alice.address)), 10n ** 18n);
158 await waitNewBlocks(api, 1);
159155
160 // Token is owned by seller initially156 // Token is owned by seller initially
161 expect(await queryNftOwner(api, collectionId, tokenId)).to.be.deep.equal({ ethereum: subToEthLowercase(seller.address) });157 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal({Ethereum: subToEthLowercase(seller.address)});
162158
163 // Ask159 // Ask
164 {160 {
167 }163 }
168 164
169 // Token is transferred to matcher165 // Token is transferred to matcher
170 expect(await queryNftOwner(api, collectionId, tokenId)).to.be.deep.equal({ ethereum: matcher.options.address.toLowerCase() });166 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal({Ethereum: matcher.options.address.toLowerCase()});
171167
172 // Give buyer KSM168 // Give buyer KSM
173 await matcher.methods.deposit(PRICE, ksmToken, subToEth(alice.address)).send({ from: escrow });169 await matcher.methods.deposit(PRICE, ksmToken, subToEth(alice.address)).send({from: escrow});
174 await waitNewBlocks(api, 1);170
175
176 // Buy171 // Buy
177 {172 {
178 expect(await matcher.methods.escrowBalance(ksmToken, subToEth(seller.address)).call()).to.be.equal('0');173 expect(await matcher.methods.escrowBalance(ksmToken, subToEth(seller.address)).call()).to.be.equal('0');
179 expect(await matcher.methods.escrowBalance(ksmToken, subToEth(alice.address)).call()).to.be.equal(PRICE.toString());174 expect(await matcher.methods.escrowBalance(ksmToken, subToEth(alice.address)).call()).to.be.equal(PRICE.toString());
180175
181 await executeEthTxOnSub(api, alice, matcher, m => m.buy(evmCollection.options.address, tokenId));176 await executeEthTxOnSub(api, alice, matcher, m => m.buy(evmCollection.options.address, tokenId));
182 await waitNewBlocks(api, 1);
183177
184 // Price is removed from buyer balance, and added to seller178 // Price is removed from buyer balance, and added to seller
185 expect(await matcher.methods.escrowBalance(ksmToken, subToEth(alice.address)).call()).to.be.equal('0');179 expect(await matcher.methods.escrowBalance(ksmToken, subToEth(alice.address)).call()).to.be.equal('0');
186 expect(await matcher.methods.escrowBalance(ksmToken, subToEth(seller.address)).call()).to.be.equal(PRICE.toString());180 expect(await matcher.methods.escrowBalance(ksmToken, subToEth(seller.address)).call()).to.be.equal(PRICE.toString());
187 }181 }
188182
189 // Token is transferred to evm account of alice183 // Token is transferred to evm account of alice
190 expect(await queryNftOwner(api, collectionId, tokenId)).to.be.deep.equal({ ethereum: subToEthLowercase(alice.address) });184 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal({Ethereum: subToEthLowercase(alice.address)});
191 185
192 // Transfer token to substrate side of alice186 // Transfer token to substrate side of alice
193 await transferFromExpectSuccess(collectionId, tokenId, alice, { ethereum: subToEth(alice.address) }, { substrate: alice.address });187 await transferFromExpectSuccess(collectionId, tokenId, alice, {Ethereum: subToEth(alice.address)}, {Substrate: alice.address});
194 188
195 // Token is transferred to substrate account of alice, seller received funds189 // Token is transferred to substrate account of alice, seller received funds
196 expect(await queryNftOwner(api, collectionId, tokenId)).to.be.deep.equal({ substrate: alice.address });190 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal({Substrate: alice.address});
197 });191 });
198});192});
199193
modifiedtests/src/eth/metadata.test.tsdiffbeforeafterboth

no syntactic changes

modifiedtests/src/eth/migration.test.tsdiffbeforeafterboth
41 const alice = privateKey('//Alice');41 const alice = privateKey('//Alice');
42 const caller = await createEthAccountWithBalance(api, web3);42 const caller = await createEthAccountWithBalance(api, web3);
4343
44 await submitTransactionAsync(alice, api.tx.sudo.sudo(api.tx.evmMigration.begin(ADDRESS)));44 await submitTransactionAsync(alice, api.tx.sudo.sudo(api.tx.evmMigration.begin(ADDRESS) as any));
45 await submitTransactionAsync(alice, api.tx.sudo.sudo(api.tx.evmMigration.setData(ADDRESS, DATA)));45 await submitTransactionAsync(alice, api.tx.sudo.sudo(api.tx.evmMigration.setData(ADDRESS, DATA as any) as any));
46 await submitTransactionAsync(alice, api.tx.sudo.sudo(api.tx.evmMigration.finish(ADDRESS, CODE)));46 await submitTransactionAsync(alice, api.tx.sudo.sudo(api.tx.evmMigration.finish(ADDRESS, CODE) as any));
4747
48 const contract = new web3.eth.Contract([48 const contract = new web3.eth.Contract([
49 {49 {
modifiedtests/src/eth/nonFungible.test.tsdiffbeforeafterboth
8import { collectionIdToAddress, createEthAccount, createEthAccountWithBalance, GAS_ARGS, itWeb3, normalizeEvents, recordEthFee, recordEvents, subToEth, transferBalanceToEth } from './util/helpers';8import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, GAS_ARGS, itWeb3, normalizeEvents, recordEthFee, recordEvents, subToEth, transferBalanceToEth} from './util/helpers';
9import nonFungibleAbi from './nonFungibleAbi.json';9import nonFungibleAbi from './nonFungibleAbi.json';
10import { expect } from 'chai';10import {expect} from 'chai';
11import waitNewBlocks from '../substrate/wait-new-blocks';
12import { submitTransactionAsync } from '../substrate/substrate-api';11import {submitTransactionAsync} from '../substrate/substrate-api';
1312
14describe('NFT: Information getting', () => {13describe('NFT: Information getting', () => {
19 const alice = privateKey('//Alice');18 const alice = privateKey('//Alice');
20 const caller = await createEthAccountWithBalance(api, web3);19 const caller = await createEthAccountWithBalance(api, web3);
2120
22 await createItemExpectSuccess(alice, collection, 'NFT', { substrate: alice.address });21 await createItemExpectSuccess(alice, collection, 'NFT', {Substrate: alice.address});
2322
24 const address = collectionIdToAddress(collection);23 const address = collectionIdToAddress(collection);
25 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});24 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});
26 const totalSupply = await contract.methods.totalSupply().call();25 const totalSupply = await contract.methods.totalSupply().call();
2726
28 // FIXME: always equals to 0, because this method is not implemented
29 expect(totalSupply).to.equal('0');27 expect(totalSupply).to.equal('1');
30 });28 });
3129
32 itWeb3('balanceOf', async ({ api, web3 }) => {30 itWeb3('balanceOf', async ({api, web3}) => {
36 const alice = privateKey('//Alice');34 const alice = privateKey('//Alice');
3735
38 const caller = await createEthAccountWithBalance(api, web3);36 const caller = await createEthAccountWithBalance(api, web3);
39 await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: caller });37 await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum:caller});
40 await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: caller });38 await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: caller});
41 await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: caller });39 await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: caller});
4240
43 const address = collectionIdToAddress(collection);41 const address = collectionIdToAddress(collection);
44 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});42 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});
54 const alice = privateKey('//Alice');52 const alice = privateKey('//Alice');
5553
56 const caller = await createEthAccountWithBalance(api, web3);54 const caller = await createEthAccountWithBalance(api, web3);
57 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: caller });55 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: caller});
5856
59 const address = collectionIdToAddress(collection);57 const address = collectionIdToAddress(collection);
60 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});58 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});
72 const alice = privateKey('//Alice');70 const alice = privateKey('//Alice');
7371
74 const caller = await createEthAccountWithBalance(api, web3);72 const caller = await createEthAccountWithBalance(api, web3);
75 const changeAdminTx = api.tx.nft.addCollectionAdmin(collection, { ethereum: caller });73 const changeAdminTx = api.tx.nft.addCollectionAdmin(collection, {Ethereum: caller});
76 await submitTransactionAsync(alice, changeAdminTx);74 await submitTransactionAsync(alice, changeAdminTx);
77 const receiver = createEthAccount(web3);75 const receiver = createEthAccount(web3);
7876
101 },99 },
102 ]);100 ]);
103101
104 await waitNewBlocks(api, 1);
105 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');102 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');
106 }103 }
107 });104 });
112 const alice = privateKey('//Alice');109 const alice = privateKey('//Alice');
113110
114 const caller = await createEthAccountWithBalance(api, web3);111 const caller = await createEthAccountWithBalance(api, web3);
115 const changeAdminTx = api.tx.nft.addCollectionAdmin(collection, { ethereum: caller });112 const changeAdminTx = api.tx.nft.addCollectionAdmin(collection, {Ethereum: caller});
116 await submitTransactionAsync(alice, changeAdminTx);113 await submitTransactionAsync(alice, changeAdminTx);
117 const receiver = createEthAccount(web3);114 const receiver = createEthAccount(web3);
118115
162 },159 },
163 ]);160 ]);
164161
165 await waitNewBlocks(api, 1);
166 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI 0');162 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI 0');
167 expect(await contract.methods.tokenURI(+nextTokenId + 1).call()).to.be.equal('Test URI 1');163 expect(await contract.methods.tokenURI(+nextTokenId + 1).call()).to.be.equal('Test URI 1');
168 expect(await contract.methods.tokenURI(+nextTokenId + 2).call()).to.be.equal('Test URI 2');164 expect(await contract.methods.tokenURI(+nextTokenId + 2).call()).to.be.equal('Test URI 2');
177173
178 const owner = await createEthAccountWithBalance(api, web3);174 const owner = await createEthAccountWithBalance(api, web3);
179175
180 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner });176 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: owner});
181 177
182 const address = collectionIdToAddress(collection);178 const address = collectionIdToAddress(collection);
183 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: owner, ...GAS_ARGS});179 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: owner, ...GAS_ARGS});
209 const owner = createEthAccount(web3);205 const owner = createEthAccount(web3);
210 await transferBalanceToEth(api, alice, owner, 999999999999999);206 await transferBalanceToEth(api, alice, owner, 999999999999999);
211207
212 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner });208 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: owner});
213209
214 const spender = createEthAccount(web3);210 const spender = createEthAccount(web3);
215211
243 const owner = createEthAccount(web3);239 const owner = createEthAccount(web3);
244 await transferBalanceToEth(api, alice, owner, 999999999999999);240 await transferBalanceToEth(api, alice, owner, 999999999999999);
245241
246 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner });242 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: owner});
247243
248 const spender = createEthAccount(web3);244 const spender = createEthAccount(web3);
249 await transferBalanceToEth(api, alice, spender, 999999999999999);245 await transferBalanceToEth(api, alice, spender, 999999999999999);
291 const owner = createEthAccount(web3);287 const owner = createEthAccount(web3);
292 await transferBalanceToEth(api, alice, owner, 999999999999999);288 await transferBalanceToEth(api, alice, owner, 999999999999999);
293289
294 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner });290 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: owner});
295291
296 const receiver = createEthAccount(web3);292 const receiver = createEthAccount(web3);
297 await transferBalanceToEth(api, alice, receiver, 999999999999999);293 await transferBalanceToEth(api, alice, receiver, 999999999999999);
301297
302 {298 {
303 const result = await contract.methods.transfer(receiver, tokenId).send({ from: owner });299 const result = await contract.methods.transfer(receiver, tokenId).send({from: owner});
304 await waitNewBlocks(api, 1);
305 const events = normalizeEvents(result.events);300 const events = normalizeEvents(result.events);
306 expect(events).to.be.deep.equal([301 expect(events).to.be.deep.equal([
307 {302 {
335330
336 const owner = await createEthAccountWithBalance(api, web3);331 const owner = await createEthAccountWithBalance(api, web3);
337332
338 const item = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner });333 const item = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: owner});
339 await setMetadataUpdatePermissionFlagExpectSuccess(alice, collection, 'Admin');334 await setMetadataUpdatePermissionFlagExpectSuccess(alice, collection, 'Admin');
340 await setVariableMetaDataExpectSuccess(alice, collection, item, [1, 2, 3]);335 await setVariableMetaDataExpectSuccess(alice, collection, item, [1, 2, 3]);
341336
353348
354 const owner = await createEthAccountWithBalance(api, web3);349 const owner = await createEthAccountWithBalance(api, web3);
355350
356 const item = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner });351 const item = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: owner});
357352
358 const address = collectionIdToAddress(collection);353 const address = collectionIdToAddress(collection);
359 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, { from: owner, ...GAS_ARGS });354 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: owner, ...GAS_ARGS});
360 355
361 expect(await contract.methods.setVariableMetadata(item, '0x010203').send({ from: owner }));356 expect(await contract.methods.setVariableMetadata(item, '0x010203').send({from: owner}));
362 await waitNewBlocks(api, 1);
363 expect(await contract.methods.getVariableMetadata(item).call()).to.be.equal('0x010203');357 expect(await contract.methods.getVariableMetadata(item).call()).to.be.equal('0x010203');
364 });358 });
365});359});
374 const owner = await createEthAccountWithBalance(api, web3);368 const owner = await createEthAccountWithBalance(api, web3);
375 const spender = createEthAccount(web3);369 const spender = createEthAccount(web3);
376370
377 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner });371 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: owner});
378372
379 const address = collectionIdToAddress(collection);373 const address = collectionIdToAddress(collection);
380 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, { from: owner, ...GAS_ARGS });374 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: owner, ...GAS_ARGS});
392 const owner = await createEthAccountWithBalance(api, web3);386 const owner = await createEthAccountWithBalance(api, web3);
393 const spender = await createEthAccountWithBalance(api, web3);387 const spender = await createEthAccountWithBalance(api, web3);
394388
395 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner });389 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: owner});
396390
397 const address = collectionIdToAddress(collection);391 const address = collectionIdToAddress(collection);
398 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, { from: owner, ...GAS_ARGS });392 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: owner, ...GAS_ARGS});
412 const owner = await createEthAccountWithBalance(api, web3);406 const owner = await createEthAccountWithBalance(api, web3);
413 const receiver = createEthAccount(web3);407 const receiver = createEthAccount(web3);
414408
415 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner });409 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: owner});
416410
417 const address = collectionIdToAddress(collection);411 const address = collectionIdToAddress(collection);
418 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, { from: owner, ...GAS_ARGS });412 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: owner, ...GAS_ARGS});
491 const contract = new web3.eth.Contract(nonFungibleAbi as any, address);485 const contract = new web3.eth.Contract(nonFungibleAbi as any, address);
492486
493 const events = await recordEvents(contract, async () => {487 const events = await recordEvents(contract, async () => {
494 await approveExpectSuccess(collection, tokenId, alice, { ethereum: receiver }, 1);488 await approveExpectSuccess(collection, tokenId, alice, {Ethereum: receiver}, 1);
495 });489 });
496490
497 expect(events).to.be.deep.equal([491 expect(events).to.be.deep.equal([
517 const receiver = createEthAccount(web3);511 const receiver = createEthAccount(web3);
518512
519 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT');513 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT');
520 await approveExpectSuccess(collection, tokenId, alice, bob, 1);514 await approveExpectSuccess(collection, tokenId, alice, bob.address, 1);
521515
522 const address = collectionIdToAddress(collection);516 const address = collectionIdToAddress(collection);
523 const contract = new web3.eth.Contract(nonFungibleAbi as any, address);517 const contract = new web3.eth.Contract(nonFungibleAbi as any, address);
524518
525 const events = await recordEvents(contract, async () => {519 const events = await recordEvents(contract, async () => {
526 await transferFromExpectSuccess(collection, tokenId, bob, alice, { ethereum: receiver }, 1, 'NFT');520 await transferFromExpectSuccess(collection, tokenId, bob, alice, {Ethereum: receiver}, 1, 'NFT');
527 });521 });
528522
529 expect(events).to.be.deep.equal([523 expect(events).to.be.deep.equal([
553 const contract = new web3.eth.Contract(nonFungibleAbi as any, address);547 const contract = new web3.eth.Contract(nonFungibleAbi as any, address);
554548
555 const events = await recordEvents(contract, async () => {549 const events = await recordEvents(contract, async () => {
556 await transferExpectSuccess(collection, tokenId, alice, { ethereum: receiver }, 1, 'NFT');550 await transferExpectSuccess(collection, tokenId, alice, {Ethereum: receiver}, 1, 'NFT');
557 });551 });
558552
559 expect(events).to.be.deep.equal([553 expect(events).to.be.deep.equal([
modifiedtests/src/eth/payable.test.tsdiffbeforeafterboth
1import { expect } from 'chai';1import {expect} from 'chai';
2import privateKey from '../substrate/privateKey';2import privateKey from '../substrate/privateKey';
3import { submitTransactionAsync } from '../substrate/substrate-api';3import {submitTransactionAsync} from '../substrate/substrate-api';
4import waitNewBlocks from '../substrate/wait-new-blocks';
5import { createEthAccountWithBalance, deployCollector, GAS_ARGS, itWeb3, subToEth } from './util/helpers';4import {createEthAccountWithBalance, deployCollector, GAS_ARGS, itWeb3, subToEth} from './util/helpers';
6import {evmToAddress} from '@polkadot/util-crypto';5import {evmToAddress} from '@polkadot/util-crypto';
7import { getGenericResult } from '../util/helpers';6import {getGenericResult} from '../util/helpers';
13 const contract = await deployCollector(web3, deployer);12 const contract = await deployCollector(web3, deployer);
1413
15 await web3.eth.sendTransaction({from: deployer, to: contract.options.address, value: '10000', ...GAS_ARGS});14 await web3.eth.sendTransaction({from: deployer, to: contract.options.address, value: '10000', ...GAS_ARGS});
16 await waitNewBlocks(api, 1);
1715
18 expect(await contract.methods.getCollected().call()).to.be.equal('10000');16 expect(await contract.methods.getCollected().call()).to.be.equal('10000');
19 });17 });
65 const alice = privateKey('//Alice');63 const alice = privateKey('//Alice');
6664
67 await web3.eth.sendTransaction({from: deployer, to: contract.options.address, value: CONTRACT_BALANCE.toString(), ...GAS_ARGS});65 await web3.eth.sendTransaction({from: deployer, to: contract.options.address, value: CONTRACT_BALANCE.toString(), ...GAS_ARGS});
68 await waitNewBlocks(api, 1);
6966
70 const receiver = privateKey(`//Receiver${Date.now()}`);67 const receiver = privateKey(`//Receiver${Date.now()}`);
7168
modifiedtests/src/eth/proxy/fungibleProxy.test.tsdiffbeforeafterboth
15async function proxyWrap(api: ApiPromise, web3: Web3, wrapped: any) {15async function proxyWrap(api: ApiPromise, web3: Web3, wrapped: any) {
16 // Proxy owner has no special privilegies, we don't need to reuse them16 // Proxy owner has no special privilegies, we don't need to reuse them
17 const owner = await createEthAccountWithBalance(api, web3);17 const owner = await createEthAccountWithBalance(api, web3);
18 const Proxy = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/UniqueFungibleProxy.abi`)).toString()), undefined, {18 const proxyContract = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/UniqueFungibleProxy.abi`)).toString()), undefined, {
19 from: owner,19 from: owner,
20 ...GAS_ARGS,20 ...GAS_ARGS,
21 });21 });
22 const proxy = await Proxy.deploy({ data: (await readFile(`${__dirname}/UniqueFungibleProxy.bin`)).toString(), arguments: [wrapped.options.address] }).send({ from: owner });22 const proxy = await proxyContract.deploy({data: (await readFile(`${__dirname}/UniqueFungibleProxy.bin`)).toString(), arguments: [wrapped.options.address]}).send({from: owner});
23 return proxy;23 return proxy;
24}24}
2525
32 const alice = privateKey('//Alice');32 const alice = privateKey('//Alice');
33 const caller = await createEthAccountWithBalance(api, web3);33 const caller = await createEthAccountWithBalance(api, web3);
34 34
35 await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { substrate: alice.address });35 await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Substrate: alice.address});
3636
37 const address = collectionIdToAddress(collection);37 const address = collectionIdToAddress(collection);
38 const contract = await proxyWrap(api, web3, new web3.eth.Contract(fungibleAbi as any, address, {from: caller, ...GAS_ARGS}));38 const contract = await proxyWrap(api, web3, new web3.eth.Contract(fungibleAbi as any, address, {from: caller, ...GAS_ARGS}));
39 const totalSupply = await contract.methods.totalSupply().call();39 const totalSupply = await contract.methods.totalSupply().call();
4040
41 // FIXME: always equals to 0, because this method is not implemented
42 expect(totalSupply).to.equal('0');41 expect(totalSupply).to.equal('200');
43 });42 });
4443
45 itWeb3('balanceOf', async ({ api, web3 }) => {44 itWeb3('balanceOf', async ({api, web3}) => {
50 const alice = privateKey('//Alice');49 const alice = privateKey('//Alice');
51 const caller = await createEthAccountWithBalance(api, web3);50 const caller = await createEthAccountWithBalance(api, web3);
5251
53 await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { ethereum: caller });52 await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: caller});
5453
55 const address = collectionIdToAddress(collection);54 const address = collectionIdToAddress(collection);
56 const contract = await proxyWrap(api, web3, new web3.eth.Contract(fungibleAbi as any, address, {from: caller, ...GAS_ARGS}));55 const contract = await proxyWrap(api, web3, new web3.eth.Contract(fungibleAbi as any, address, {from: caller, ...GAS_ARGS}));
7271
73 const address = collectionIdToAddress(collection);72 const address = collectionIdToAddress(collection);
74 const contract = await proxyWrap(api, web3, new web3.eth.Contract(fungibleAbi as any, address, {from: caller, ...GAS_ARGS}));73 const contract = await proxyWrap(api, web3, new web3.eth.Contract(fungibleAbi as any, address, {from: caller, ...GAS_ARGS}));
75 await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { ethereum: contract.options.address });74 await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: contract.options.address});
7675
77 {76 {
78 const result = await contract.methods.approve(spender, 100).send({from: caller});77 const result = await contract.methods.approve(spender, 100).send({from: caller});
106 const caller = await createEthAccountWithBalance(api, web3);105 const caller = await createEthAccountWithBalance(api, web3);
107 const owner = await createEthAccountWithBalance(api, web3);106 const owner = await createEthAccountWithBalance(api, web3);
108107
109 await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { ethereum: owner });108 await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: owner});
110109
111 const receiver = createEthAccount(web3);110 const receiver = createEthAccount(web3);
112111
163162
164 const address = collectionIdToAddress(collection);163 const address = collectionIdToAddress(collection);
165 const contract = await proxyWrap(api, web3, new web3.eth.Contract(fungibleAbi as any, address, {from: caller, ...GAS_ARGS}));164 const contract = await proxyWrap(api, web3, new web3.eth.Contract(fungibleAbi as any, address, {from: caller, ...GAS_ARGS}));
166 await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { ethereum: contract.options.address });165 await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: contract.options.address});
167166
168 {167 {
169 const result = await contract.methods.transfer(receiver, 50).send({ from: caller});168 const result = await contract.methods.transfer(receiver, 50).send({from: caller});
modifiedtests/src/eth/proxy/nonFungibleProxy.test.tsdiffbeforeafterboth
8import { collectionIdToAddress, createEthAccount, createEthAccountWithBalance, GAS_ARGS, itWeb3, normalizeEvents } from '../util/helpers';8import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, GAS_ARGS, itWeb3, normalizeEvents} from '../util/helpers';
9import nonFungibleAbi from '../nonFungibleAbi.json';9import nonFungibleAbi from '../nonFungibleAbi.json';
10import { expect } from 'chai';10import {expect} from 'chai';
11import waitNewBlocks from '../../substrate/wait-new-blocks';
12import { submitTransactionAsync } from '../../substrate/substrate-api';11import {submitTransactionAsync} from '../../substrate/substrate-api';
13import Web3 from 'web3';12import Web3 from 'web3';
14import { readFile } from 'fs/promises';13import {readFile} from 'fs/promises';
17async function proxyWrap(api: ApiPromise, web3: Web3, wrapped: any) {16async function proxyWrap(api: ApiPromise, web3: Web3, wrapped: any) {
18 // Proxy owner has no special privilegies, we don't need to reuse them17 // Proxy owner has no special privilegies, we don't need to reuse them
19 const owner = await createEthAccountWithBalance(api, web3);18 const owner = await createEthAccountWithBalance(api, web3);
20 const Proxy = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/UniqueNFTProxy.abi`)).toString()), undefined, {19 const proxyContract = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/UniqueNFTProxy.abi`)).toString()), undefined, {
21 from: owner,20 from: owner,
22 ...GAS_ARGS,21 ...GAS_ARGS,
23 });22 });
24 const proxy = await Proxy.deploy({ data: (await readFile(`${__dirname}/UniqueNFTProxy.bin`)).toString(), arguments: [wrapped.options.address] }).send({ from: owner });23 const proxy = await proxyContract.deploy({data: (await readFile(`${__dirname}/UniqueNFTProxy.bin`)).toString(), arguments: [wrapped.options.address]}).send({from: owner});
25 return proxy;24 return proxy;
26}25}
2726
33 const alice = privateKey('//Alice');32 const alice = privateKey('//Alice');
34 const caller = await createEthAccountWithBalance(api, web3);33 const caller = await createEthAccountWithBalance(api, web3);
3534
36 await createItemExpectSuccess(alice, collection, 'NFT', { substrate: alice.address });35 await createItemExpectSuccess(alice, collection, 'NFT', {Substrate: alice.address});
3736
38 const address = collectionIdToAddress(collection);37 const address = collectionIdToAddress(collection);
39 const contract = await proxyWrap(api, web3, new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS}));38 const contract = await proxyWrap(api, web3, new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS}));
40 const totalSupply = await contract.methods.totalSupply().call();39 const totalSupply = await contract.methods.totalSupply().call();
4140
42 // FIXME: always equals to 0, because this method is not implemented
43 expect(totalSupply).to.equal('0');41 expect(totalSupply).to.equal('1');
44 });42 });
4543
46 itWeb3('balanceOf', async ({ api, web3 }) => {44 itWeb3('balanceOf', async ({api, web3}) => {
50 const alice = privateKey('//Alice');48 const alice = privateKey('//Alice');
5149
52 const caller = await createEthAccountWithBalance(api, web3);50 const caller = await createEthAccountWithBalance(api, web3);
53 await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: caller });51 await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: caller});
54 await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: caller });52 await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: caller});
55 await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: caller });53 await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: caller});
5654
57 const address = collectionIdToAddress(collection);55 const address = collectionIdToAddress(collection);
58 const contract = await proxyWrap(api, web3, new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS}));56 const contract = await proxyWrap(api, web3, new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS}));
68 const alice = privateKey('//Alice');66 const alice = privateKey('//Alice');
6967
70 const caller = await createEthAccountWithBalance(api, web3);68 const caller = await createEthAccountWithBalance(api, web3);
71 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: caller });69 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: caller});
7270
73 const address = collectionIdToAddress(collection);71 const address = collectionIdToAddress(collection);
74 const contract = await proxyWrap(api, web3, new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS}));72 const contract = await proxyWrap(api, web3, new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS}));
90 const address = collectionIdToAddress(collection);88 const address = collectionIdToAddress(collection);
91 const contract = await proxyWrap(api, web3, new web3.eth.Contract(nonFungibleAbi as any, address, { from: caller, ...GAS_ARGS }));89 const contract = await proxyWrap(api, web3, new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS}));
9290
93 const changeAdminTx = api.tx.nft.addCollectionAdmin(collection, { ethereum: contract.options.address });91 const changeAdminTx = api.tx.nft.addCollectionAdmin(collection, {Ethereum: contract.options.address});
94 await submitTransactionAsync(alice, changeAdminTx);92 await submitTransactionAsync(alice, changeAdminTx);
9593
96 {94 {
115 },113 },
116 ]);114 ]);
117115
118 await waitNewBlocks(api, 1);
119 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');116 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');
120 }117 }
121 });118 });
130127
131 const address = collectionIdToAddress(collection);128 const address = collectionIdToAddress(collection);
132 const contract = await proxyWrap(api, web3, new web3.eth.Contract(nonFungibleAbi as any, address, { from: caller, ...GAS_ARGS }));129 const contract = await proxyWrap(api, web3, new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS}));
133 const changeAdminTx = api.tx.nft.addCollectionAdmin(collection, { ethereum: contract.options.address });130 const changeAdminTx = api.tx.nft.addCollectionAdmin(collection, {Ethereum: contract.options.address});
134 await submitTransactionAsync(alice, changeAdminTx);131 await submitTransactionAsync(alice, changeAdminTx);
135132
136 {133 {
176 },173 },
177 ]);174 ]);
178175
179 await waitNewBlocks(api, 1);
180 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI 0');176 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI 0');
181 expect(await contract.methods.tokenURI(+nextTokenId + 1).call()).to.be.equal('Test URI 1');177 expect(await contract.methods.tokenURI(+nextTokenId + 1).call()).to.be.equal('Test URI 1');
182 expect(await contract.methods.tokenURI(+nextTokenId + 2).call()).to.be.equal('Test URI 2');178 expect(await contract.methods.tokenURI(+nextTokenId + 2).call()).to.be.equal('Test URI 2');
192 188
193 const address = collectionIdToAddress(collection);189 const address = collectionIdToAddress(collection);
194 const contract = await proxyWrap(api, web3, new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS}));190 const contract = await proxyWrap(api, web3, new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS}));
195 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: contract.options.address });191 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: contract.options.address});
196192
197 const changeAdminTx = api.tx.nft.addCollectionAdmin(collection, { ethereum: contract.options.address });193 const changeAdminTx = api.tx.nft.addCollectionAdmin(collection, {Ethereum: contract.options.address});
198 await submitTransactionAsync(alice, changeAdminTx);194 await submitTransactionAsync(alice, changeAdminTx);
199195
200 {196 {
225221
226 const address = collectionIdToAddress(collection);222 const address = collectionIdToAddress(collection);
227 const contract = await proxyWrap(api, web3, new web3.eth.Contract(nonFungibleAbi as any, address));223 const contract = await proxyWrap(api, web3, new web3.eth.Contract(nonFungibleAbi as any, address));
228 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: contract.options.address });224 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: contract.options.address});
229225
230 {226 {
231 const result = await contract.methods.approve(spender, tokenId).send({ from: caller, gas: '0x1000000', gasPrice: '0x01' });227 const result = await contract.methods.approve(spender, tokenId).send({from: caller, gas: '0x1000000', gasPrice: '0x01'});
258 const address = collectionIdToAddress(collection);254 const address = collectionIdToAddress(collection);
259 const evmCollection = new web3.eth.Contract(nonFungibleAbi as any, address, { from: caller, ...GAS_ARGS });255 const evmCollection = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});
260 const contract = await proxyWrap(api, web3, evmCollection);256 const contract = await proxyWrap(api, web3, evmCollection);
261 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner });257 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: owner});
262258
263 await evmCollection.methods.approve(contract.options.address, tokenId).send({ from: owner });259 await evmCollection.methods.approve(contract.options.address, tokenId).send({from: owner});
264260
299295
300 const address = collectionIdToAddress(collection);296 const address = collectionIdToAddress(collection);
301 const contract = await proxyWrap(api, web3, new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS}));297 const contract = await proxyWrap(api, web3, new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS}));
302 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: contract.options.address });298 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: contract.options.address});
303299
304 {300 {
305 const result = await contract.methods.transfer(receiver, tokenId).send({ from: caller });301 const result = await contract.methods.transfer(receiver, tokenId).send({from: caller});
306 await waitNewBlocks(api, 1);
307 const events = normalizeEvents(result.events);302 const events = normalizeEvents(result.events);
308 expect(events).to.be.deep.equal([303 expect(events).to.be.deep.equal([
309 {304 {
338333
339 const address = collectionIdToAddress(collection);334 const address = collectionIdToAddress(collection);
340 const contract = await proxyWrap(api, web3, new web3.eth.Contract(nonFungibleAbi as any, address, { from: caller, ...GAS_ARGS }));335 const contract = await proxyWrap(api, web3, new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS}));
341 const item = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: contract.options.address });336 const item = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: contract.options.address});
342 await setMetadataUpdatePermissionFlagExpectSuccess(alice, collection, 'Admin');337 await setMetadataUpdatePermissionFlagExpectSuccess(alice, collection, 'Admin');
343 await setVariableMetaDataExpectSuccess(alice, collection, item, [1, 2, 3]);338 await setVariableMetaDataExpectSuccess(alice, collection, item, [1, 2, 3]);
344 339
354349
355 const address = collectionIdToAddress(collection);350 const address = collectionIdToAddress(collection);
356 const contract = await proxyWrap(api, web3, new web3.eth.Contract(nonFungibleAbi as any, address, { from: caller, ...GAS_ARGS }));351 const contract = await proxyWrap(api, web3, new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS}));
357 const item = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: contract.options.address });352 const item = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: contract.options.address});
358 353
359 expect(await contract.methods.setVariableMetadata(item, '0x010203').send({ from: caller }));354 expect(await contract.methods.setVariableMetadata(item, '0x010203').send({from: caller}));
360 await waitNewBlocks(api, 1);
361 expect(await contract.methods.getVariableMetadata(item).call()).to.be.equal('0x010203');355 expect(await contract.methods.getVariableMetadata(item).call()).to.be.equal('0x010203');
362 });356 });
363});357});
modifiedtests/src/eth/sponsoring.test.tsdiffbeforeafterboth
1import { expect } from 'chai';1import {expect} from 'chai';
2import privateKey from '../substrate/privateKey';2import privateKey from '../substrate/privateKey';
3import waitNewBlocks from '../substrate/wait-new-blocks';
4import { contractHelpers, createEthAccount, createEthAccountWithBalance, deployCollector, deployFlipper, itWeb3, transferBalanceToEth, usingWeb3Http } from './util/helpers';3import {contractHelpers, createEthAccount, createEthAccountWithBalance, deployCollector, deployFlipper, itWeb3, transferBalanceToEth} from './util/helpers';
54
6describe('EVM sponsoring', () => {5describe('EVM sponsoring', () => {
7 itWeb3('Fee is deducted from contract if sponsoring is enabled', async ({api, web3}) => {6 itWeb3('Fee is deducted from contract if sponsoring is enabled', async ({api, web3}) => {
8 await usingWeb3Http(async web3Http => {
9 const alice = privateKey('//Alice');7 const alice = privateKey('//Alice');
108
11 const owner = await createEthAccountWithBalance(api, web3Http);9 const owner = await createEthAccountWithBalance(api, web3);
12 const caller = createEthAccount(web3Http);10 const caller = createEthAccount(web3);
13 const originalCallerBalance = await web3.eth.getBalance(caller);11 const originalCallerBalance = await web3.eth.getBalance(caller);
14 expect(originalCallerBalance).to.be.equal('0');12 expect(originalCallerBalance).to.be.equal('0');
1513
16 const flipper = await deployFlipper(web3Http, owner);14 const flipper = await deployFlipper(web3, owner);
17 await waitNewBlocks(api, 1);15
18
19 const helpers = contractHelpers(web3Http, owner);16 const helpers = contractHelpers(web3, owner);
20 await helpers.methods.toggleAllowlist(flipper.options.address, true).send({ from: owner });17 await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});
21 await waitNewBlocks(api, 1);
22 await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({ from: owner });18 await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner});
23 await waitNewBlocks(api, 1);
2419
25 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;20 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;
26 await helpers.methods.toggleSponsoring(flipper.options.address, true).send({from: owner});21 await helpers.methods.toggleSponsoring(flipper.options.address, true).send({from: owner});
27 await waitNewBlocks(api, 1);
28 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});22 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});
29 await waitNewBlocks(api, 1);
30 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;23 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;
3124
32 await transferBalanceToEth(api, alice, flipper.options.address);25 await transferBalanceToEth(api, alice, flipper.options.address);
33 await waitNewBlocks(api, 2);
3426
35 const originalFlipperBalance = await web3.eth.getBalance(flipper.options.address);27 const originalFlipperBalance = await web3.eth.getBalance(flipper.options.address);
36 expect(originalFlipperBalance).to.be.not.equal('0');28 expect(originalFlipperBalance).to.be.not.equal('0');
3729
38 await flipper.methods.flip().send({ from: caller });30 await flipper.methods.flip().send({from: caller});
39 await waitNewBlocks(api, 1);
40 expect(await flipper.methods.getValue().call()).to.be.true;31 expect(await flipper.methods.getValue().call()).to.be.true;
4132
42 // Balance should be taken from flipper instead of caller33 // Balance should be taken from flipper instead of caller
43 expect(await web3.eth.getBalance(caller)).to.be.equals(originalCallerBalance);34 expect(await web3.eth.getBalance(caller)).to.be.equals(originalCallerBalance);
44 expect(await web3.eth.getBalance(flipper.options.address)).to.be.not.equals(originalFlipperBalance);35 expect(await web3.eth.getBalance(flipper.options.address)).to.be.not.equals(originalFlipperBalance);
45 });
46 });36 });
47 itWeb3('...but this doesn\'t applies to payable value', async ({api, web3}) => {37 itWeb3('...but this doesn\'t applies to payable value', async ({api, web3}) => {
48 await usingWeb3Http(async web3Http => {
49 const alice = privateKey('//Alice');38 const alice = privateKey('//Alice');
5039
51 const owner = await createEthAccountWithBalance(api, web3Http);40 const owner = await createEthAccountWithBalance(api, web3);
52 const caller = await createEthAccountWithBalance(api, web3Http);41 const caller = await createEthAccountWithBalance(api, web3);
53 await waitNewBlocks(api, 1);
54 const originalCallerBalance = await web3.eth.getBalance(caller);42 const originalCallerBalance = await web3.eth.getBalance(caller);
55 expect(originalCallerBalance).to.be.not.equal('0');43 expect(originalCallerBalance).to.be.not.equal('0');
5644
57 const collector = await deployCollector(web3Http, owner);45 const collector = await deployCollector(web3, owner);
58 await waitNewBlocks(api, 1);46
59
60 const helpers = contractHelpers(web3Http, owner);47 const helpers = contractHelpers(web3, owner);
61 await helpers.methods.toggleAllowlist(collector.options.address, true).send({ from: owner });48 await helpers.methods.toggleAllowlist(collector.options.address, true).send({from: owner});
62 await waitNewBlocks(api, 1);
63 await helpers.methods.toggleAllowed(collector.options.address, caller, true).send({ from: owner });49 await helpers.methods.toggleAllowed(collector.options.address, caller, true).send({from: owner});
64 await waitNewBlocks(api, 1);
6550
66 expect(await helpers.methods.sponsoringEnabled(collector.options.address).call()).to.be.false;51 expect(await helpers.methods.sponsoringEnabled(collector.options.address).call()).to.be.false;
67 await helpers.methods.toggleSponsoring(collector.options.address, true).send({ from: owner });52 await helpers.methods.toggleSponsoring(collector.options.address, true).send({from: owner});
68 await waitNewBlocks(api, 1);
69 await helpers.methods.setSponsoringRateLimit(collector.options.address, 0).send({ from: owner });53 await helpers.methods.setSponsoringRateLimit(collector.options.address, 0).send({from: owner});
70 await waitNewBlocks(api, 1);
71 expect(await helpers.methods.sponsoringEnabled(collector.options.address).call()).to.be.true;54 expect(await helpers.methods.sponsoringEnabled(collector.options.address).call()).to.be.true;
7255
73 await transferBalanceToEth(api, alice, collector.options.address);56 await transferBalanceToEth(api, alice, collector.options.address);
74 await waitNewBlocks(api, 2);
7557
76 const originalCollectorBalance = await web3.eth.getBalance(collector.options.address);58 const originalCollectorBalance = await web3.eth.getBalance(collector.options.address);
77 expect(originalCollectorBalance).to.be.not.equal('0');59 expect(originalCollectorBalance).to.be.not.equal('0');
7860
79 await collector.methods.giveMoney().send({ from: caller, value: '10000' });61 await collector.methods.giveMoney().send({from: caller, value: '10000'});
80 await waitNewBlocks(api, 1);
8162
82 // Balance will be taken from both caller (value) and from collector (fee)63 // Balance will be taken from both caller (value) and from collector (fee)
83 expect(await web3.eth.getBalance(caller)).to.be.equals((BigInt(originalCallerBalance) - 10000n).toString());64 expect(await web3.eth.getBalance(caller)).to.be.equals((BigInt(originalCallerBalance) - 10000n).toString());
84 expect(await web3.eth.getBalance(collector.options.address)).to.be.not.equals(originalCollectorBalance);65 expect(await web3.eth.getBalance(collector.options.address)).to.be.not.equals(originalCollectorBalance);
85 expect(await collector.methods.getCollected().call()).to.be.equal('10000');66 expect(await collector.methods.getCollected().call()).to.be.equal('10000');
86 });
87 });67 });
88});68});
69
modifiedtests/src/eth/util/helpers.tsdiffbeforeafterboth
18import privateKey from '../../substrate/privateKey';18import privateKey from '../../substrate/privateKey';
19import contractHelpersAbi from './contractHelpersAbi.json';19import contractHelpersAbi from './contractHelpersAbi.json';
20import getBalance from '../../substrate/get-balance';20import getBalance from '../../substrate/get-balance';
21import waitNewBlocks from '../../substrate/wait-new-blocks';
2221
23export const GAS_ARGS = { gas: 0x1000000, gasPrice: '0x01' };22export const GAS_ARGS = {gas: 0x1000000, gasPrice: '0x01'};
2423
39 }38 }
40}39}
41
42/**
43 * @deprecated Web3 update solved issue with deployment over ws provider
44 */
45export async function usingWeb3Http<T>(cb: (web3: Web3) => Promise<T> | T): Promise<T> {
46 const provider = new Web3.providers.HttpProvider(config.frontierUrl);
47 const web3: Web3 = new Web3(provider);
48
49 return await cb(web3);
50}
5140
52export function collectionIdToAddress(address: number): string {41export function collectionIdToAddress(address: number): string {
53 if (address >= 0xffffffff || address < 0) throw new Error('id overflow');42 if (address >= 0xffffffff || address < 0) throw new Error('id overflow');
192 }181 }
193 }182 }
194 `);183 `);
195 const Flipper = new web3.eth.Contract(compiled.abi, undefined, {184 const flipperContract = new web3.eth.Contract(compiled.abi, undefined, {
196 data: compiled.object,185 data: compiled.object,
197 from: deployer,186 from: deployer,
198 ...GAS_ARGS,187 ...GAS_ARGS,
199 });188 });
200 const flipper = await Flipper.deploy({ data: compiled.object }).send({from: deployer});189 const flipper = await flipperContract.deploy({data: compiled.object}).send({from: deployer});
201190
202 return flipper;191 return flipper;
203}192}
225 }214 }
226 }215 }
227 `);216 `);
228 const Collector = new web3.eth.Contract(compiled.abi, undefined, {217 const collectorContract = new web3.eth.Contract(compiled.abi, undefined, {
229 data: compiled.object,218 data: compiled.object,
230 from: deployer,219 from: deployer,
231 ...GAS_ARGS,220 ...GAS_ARGS,
232 });221 });
233 const collector = await Collector.deploy({ data: compiled.object }).send({ from: deployer });222 const collector = await collectorContract.deploy({data: compiled.object}).send({from: deployer});
234223
235 return collector;224 return collector;
236}225}
250 null,239 null,
251 );240 );
252 const events = await submitTransactionAsync(from, tx);241 const events = await submitTransactionAsync(from, tx);
253 expect(events.find(({ event: {section, method}})=>section === 'evm' && method === 'Executed')).to.be.not.undefined;242 expect(events.some(({event: {section, method}}) => section == 'evm' && method == 'Executed')).to.be.true;
254}243}
255244
256export async function ethBalanceViaSub(api: ApiPromise, address: string): Promise<bigint> {245export async function ethBalanceViaSub(api: ApiPromise, address: string): Promise<bigint> {
261 const before = await ethBalanceViaSub(api, user);250 const before = await ethBalanceViaSub(api, user);
262251
263 await call();252 await call();
264 await waitNewBlocks(api, 1);
265253
266 const after = await ethBalanceViaSub(api, user);254 const after = await ethBalanceViaSub(api, user);
267255
modifiedtests/src/inflation.test.tsdiffbeforeafterboth
6import chai from 'chai';6import chai from 'chai';
7import chaiAsPromised from 'chai-as-promised';7import chaiAsPromised from 'chai-as-promised';
8import { default as usingApi } from './substrate/substrate-api';8import {default as usingApi} from './substrate/substrate-api';
9import { BigNumber } from 'bignumber.js';
109
11chai.use(chaiAsPromised);10chai.use(chaiAsPromised);
12const expect = chai.expect;11const expect = chai.expect;
15 it('First year inflation is 10%', async () => {14 it('First year inflation is 10%', async () => {
16 await usingApi(async (api) => {15 await usingApi(async (api) => {
1716
18 const blockInterval = parseInt((await api.consts.inflation.inflationBlockInterval).toString());17 const blockInterval = (api.consts.inflation.inflationBlockInterval).toBigInt();
19 const totalIssuanceStart = new BigNumber((await api.query.inflation.startingYearTotalIssuance()).toString());18 const totalIssuanceStart = (await api.query.inflation.startingYearTotalIssuance()).toBigInt();
20 const blockInflation = new BigNumber((await api.query.inflation.blockInflation()).toString());19 const blockInflation = (await api.query.inflation.blockInflation()).toBigInt();
2120
22 const YEAR = 5259600; // Blocks in one year21 const YEAR = 5259600n; // Blocks in one year
23 const totalExpectedInflation = totalIssuanceStart.multipliedBy(0.1);22 const totalExpectedInflation = totalIssuanceStart / 10n;
24 const totalActualInflation = blockInflation.multipliedBy(YEAR / blockInterval);23 const totalActualInflation = blockInflation * YEAR / blockInterval;
2524
26 const tolerance = 0.00001; // Relative difference per year between theoretical and actual inflation25 const tolerance = 0.00001; // Relative difference per year between theoretical and actual inflation
26 let abs = totalExpectedInflation / totalActualInflation - 1n;
27 if (abs < 0n) {
28 abs = -abs;
29 }
27 expect(totalExpectedInflation.dividedBy(totalActualInflation).minus(1).abs().toNumber()).to.be.lessThan(tolerance);30 expect(abs <= tolerance).to.be.true;
28 });31 });
29 });32 });
3033
modifiedtests/src/limits.test.tsdiffbeforeafterboth
3// file 'LICENSE', which is part of this source code package.3// file 'LICENSE', which is part of this source code package.
4//4//
55
6import { IKeyringPair } from '@polkadot/types/types';6import {IKeyringPair} from '@polkadot/types/types';
7import privateKey from './substrate/privateKey';7import privateKey from './substrate/privateKey';
8import usingApi from './substrate/substrate-api';8import usingApi from './substrate/substrate-api';
9import {9import {
18 getFreeBalance,18 getFreeBalance,
19 waitNewBlocks,19 waitNewBlocks,
20} from './util/helpers';20} from './util/helpers';
21import { expect } from 'chai';21import {expect} from 'chai';
2222
23describe('Number of tokens per address (NFT)', () => {23describe('Number of tokens per address (NFT)', () => {
24 let Alice: IKeyringPair;24 let alice: IKeyringPair;
2525
26 before(async () => {26 before(async () => {
27 await usingApi(async () => {27 await usingApi(async () => {
28 Alice = privateKey('//Alice');28 alice = privateKey('//Alice');
29 });29 });
30 });30 });
3131
32 it.skip('Collection limits allow greater number than chain limits, chain limits are enforced', async () => {32 it.skip('Collection limits allow greater number than chain limits, chain limits are enforced', async () => {
3333
34 const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });34 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
35 await setCollectionLimitsExpectSuccess(Alice, collectionId, { accountTokenOwnershipLimit: 20 });35 await setCollectionLimitsExpectSuccess(alice, collectionId, {accountTokenOwnershipLimit: 20});
36 for(let i = 0; i < 10; i++){36 for(let i = 0; i < 10; i++){
37 await createItemExpectSuccess(Alice, collectionId, 'NFT');37 await createItemExpectSuccess(alice, collectionId, 'NFT');
38 }38 }
39 await createItemExpectFailure(Alice, collectionId, 'NFT');39 await createItemExpectFailure(alice, collectionId, 'NFT');
40 await destroyCollectionExpectSuccess(collectionId);40 await destroyCollectionExpectSuccess(collectionId);
41 });41 });
4242
43 it('Collection limits allow lower number than chain limits, collection limits are enforced', async () => {43 it('Collection limits allow lower number than chain limits, collection limits are enforced', async () => {
4444
45 const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });45 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
46 await setCollectionLimitsExpectSuccess(Alice, collectionId, { accountTokenOwnershipLimit: 1 });46 await setCollectionLimitsExpectSuccess(alice, collectionId, {accountTokenOwnershipLimit: 1});
47 await createItemExpectSuccess(Alice, collectionId, 'NFT');47 await createItemExpectSuccess(alice, collectionId, 'NFT');
48 await createItemExpectFailure(Alice, collectionId, 'NFT');48 await createItemExpectFailure(alice, collectionId, 'NFT');
49 await destroyCollectionExpectSuccess(collectionId);49 await destroyCollectionExpectSuccess(collectionId);
50 });50 });
51});51});
5252
53describe('Number of tokens per address (ReFungible)', () => {53describe('Number of tokens per address (ReFungible)', () => {
54 let Alice: IKeyringPair;54 let alice: IKeyringPair;
5555
56 before(async () => {56 before(async () => {
57 await usingApi(async () => {57 await usingApi(async () => {
58 Alice = privateKey('//Alice');58 alice = privateKey('//Alice');
59 });59 });
60 });60 });
6161
62 it.skip('Collection limits allow greater number than chain limits, chain limits are enforced', async () => {62 it.skip('Collection limits allow greater number than chain limits, chain limits are enforced', async () => {
63 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible' }});63 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
64 await setCollectionLimitsExpectSuccess(Alice, collectionId, { accountTokenOwnershipLimit: 20 });64 await setCollectionLimitsExpectSuccess(alice, collectionId, {accountTokenOwnershipLimit: 20});
65 for(let i = 0; i < 10; i++){65 for(let i = 0; i < 10; i++){
66 await createItemExpectSuccess(Alice, collectionId, 'ReFungible');66 await createItemExpectSuccess(alice, collectionId, 'ReFungible');
67 }67 }
68 await createItemExpectFailure(Alice, collectionId, 'ReFungible');68 await createItemExpectFailure(alice, collectionId, 'ReFungible');
69 await destroyCollectionExpectSuccess(collectionId);69 await destroyCollectionExpectSuccess(collectionId);
70 });70 });
7171
72 it('Collection limits allow lower number than chain limits, collection limits are enforced', async () => {72 it('Collection limits allow lower number than chain limits, collection limits are enforced', async () => {
73 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible' }});73 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
74 await setCollectionLimitsExpectSuccess(Alice, collectionId, { accountTokenOwnershipLimit: 1 });74 await setCollectionLimitsExpectSuccess(alice, collectionId, {accountTokenOwnershipLimit: 1});
75 await createItemExpectSuccess(Alice, collectionId, 'ReFungible');75 await createItemExpectSuccess(alice, collectionId, 'ReFungible');
76 await createItemExpectFailure(Alice, collectionId, 'ReFungible');76 await createItemExpectFailure(alice, collectionId, 'ReFungible');
77 await destroyCollectionExpectSuccess(collectionId);77 await destroyCollectionExpectSuccess(collectionId);
78 });78 });
79});79});
8080
81describe('Sponsor timeout (NFT)', () => {81describe('Sponsor timeout (NFT)', () => {
82 let Alice: IKeyringPair;82 let alice: IKeyringPair;
83 let Bob: IKeyringPair;83 let bob: IKeyringPair;
84 let Charlie: IKeyringPair;84 let charlie: IKeyringPair;
8585
86 before(async () => {86 before(async () => {
87 await usingApi(async () => {87 await usingApi(async () => {
88 Alice = privateKey('//Alice');88 alice = privateKey('//Alice');
89 Bob = privateKey('//Bob');89 bob = privateKey('//Bob');
90 Charlie = privateKey('//Charlie');90 charlie = privateKey('//Charlie');
91 });91 });
92 });92 });
9393
94 it('Collection limits have greater timeout value than chain limits, collection limits are enforced', async () => {94 it('Collection limits have greater timeout value than chain limits, collection limits are enforced', async () => {
95 const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });95 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
96 await setCollectionLimitsExpectSuccess(Alice, collectionId, { sponsorTimeout: 7 });96 await setCollectionLimitsExpectSuccess(alice, collectionId, {sponsorTransferTimeout: 7});
97 const tokenId = await createItemExpectSuccess(Alice, collectionId, 'NFT');97 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');
98 await setCollectionSponsorExpectSuccess(collectionId, Alice.address);98 await setCollectionSponsorExpectSuccess(collectionId, alice.address);
99 await confirmSponsorshipExpectSuccess(collectionId, '//Alice');99 await confirmSponsorshipExpectSuccess(collectionId, '//Alice');
100 await transferExpectSuccess(collectionId, tokenId, Alice, Bob);100 await transferExpectSuccess(collectionId, tokenId, alice, bob);
101 const aliceBalanceBefore = await getFreeBalance(Alice);101 const aliceBalanceBefore = await getFreeBalance(alice);
102102
103 // check setting SponsorTimeout = 5, fail103 // check setting SponsorTimeout = 5, fail
104 await waitNewBlocks(5);104 await waitNewBlocks(5);
105 await transferExpectSuccess(collectionId, tokenId, Bob, Charlie);105 await transferExpectSuccess(collectionId, tokenId, bob, charlie);
106 const aliceBalanceAfterUnsponsoredTransaction = await getFreeBalance(Alice);106 const aliceBalanceAfterUnsponsoredTransaction = await getFreeBalance(alice);
107 expect(aliceBalanceAfterUnsponsoredTransaction).to.be.equals(aliceBalanceBefore);107 expect(aliceBalanceAfterUnsponsoredTransaction).to.be.equals(aliceBalanceBefore);
108108
109 // check setting SponsorTimeout = 7, success109 // check setting SponsorTimeout = 7, success
110 await waitNewBlocks(2); // 5 + 2110 await waitNewBlocks(2); // 5 + 2
111 await transferExpectSuccess(collectionId, tokenId, Charlie, Bob);111 await transferExpectSuccess(collectionId, tokenId, charlie, bob);
112 const aliceBalanceAfterSponsoredTransaction = await getFreeBalance(Alice);112 const aliceBalanceAfterSponsoredTransaction = await getFreeBalance(alice);
113 expect(aliceBalanceAfterSponsoredTransaction < aliceBalanceBefore).to.be.true;113 expect(aliceBalanceAfterSponsoredTransaction < aliceBalanceBefore).to.be.true;
114 //expect(aliceBalanceAfterSponsoredTransaction).to.be.lessThan(aliceBalanceBefore);114 //expect(aliceBalanceAfterSponsoredTransaction).to.be.lessThan(aliceBalanceBefore);
115 await destroyCollectionExpectSuccess(collectionId);115 await destroyCollectionExpectSuccess(collectionId);
116 });116 });
117117
118 it('Collection limits have lower timeout value than chain limits, chain limits are enforced', async () => {118 it('Collection limits have lower timeout value than chain limits, chain limits are enforced', async () => {
119119
120 const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });120 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
121 await setCollectionLimitsExpectSuccess(Alice, collectionId, { sponsorTimeout: 1 });121 await setCollectionLimitsExpectSuccess(alice, collectionId, {sponsorTransferTimeout: 1});
122 const tokenId = await createItemExpectSuccess(Alice, collectionId, 'NFT');122 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');
123 await setCollectionSponsorExpectSuccess(collectionId, Alice.address);123 await setCollectionSponsorExpectSuccess(collectionId, alice.address);
124 await confirmSponsorshipExpectSuccess(collectionId, '//Alice');124 await confirmSponsorshipExpectSuccess(collectionId, '//Alice');
125 await transferExpectSuccess(collectionId, tokenId, Alice, Bob);125 await transferExpectSuccess(collectionId, tokenId, alice, bob);
126 const aliceBalanceBefore = await getFreeBalance(Alice);126 const aliceBalanceBefore = await getFreeBalance(alice);
127127
128 // check setting SponsorTimeout = 1, fail128 // check setting SponsorTimeout = 1, fail
129 await waitNewBlocks(1);129 await waitNewBlocks(1);
130 await transferExpectSuccess(collectionId, tokenId, Bob, Charlie);130 await transferExpectSuccess(collectionId, tokenId, bob, charlie);
131 const aliceBalanceAfterUnsponsoredTransaction = await getFreeBalance(Alice);131 const aliceBalanceAfterUnsponsoredTransaction = await getFreeBalance(alice);
132 expect(aliceBalanceAfterUnsponsoredTransaction).to.be.equals(aliceBalanceBefore);132 expect(aliceBalanceAfterUnsponsoredTransaction).to.be.equals(aliceBalanceBefore);
133133
134 // check setting SponsorTimeout = 5, success134 // check setting SponsorTimeout = 5, success
135 await waitNewBlocks(4);135 await waitNewBlocks(4);
136 await transferExpectSuccess(collectionId, tokenId, Charlie, Bob);136 await transferExpectSuccess(collectionId, tokenId, charlie, bob);
137 const aliceBalanceAfterSponsoredTransaction = await getFreeBalance(Alice);137 const aliceBalanceAfterSponsoredTransaction = await getFreeBalance(alice);
138 expect(aliceBalanceAfterSponsoredTransaction < aliceBalanceBefore).to.be.true;138 expect(aliceBalanceAfterSponsoredTransaction < aliceBalanceBefore).to.be.true;
139 //expect(aliceBalanceAfterSponsoredTransaction).to.be.lessThan(aliceBalanceBefore);139 //expect(aliceBalanceAfterSponsoredTransaction).to.be.lessThan(aliceBalanceBefore);
140 await destroyCollectionExpectSuccess(collectionId);140 await destroyCollectionExpectSuccess(collectionId);
141 });141 });
142});142});
143143
144describe('Sponsor timeout (Fungible)', () => {144describe('Sponsor timeout (Fungible)', () => {
145 let Alice: IKeyringPair;145 let alice: IKeyringPair;
146 let Bob: IKeyringPair;146 let bob: IKeyringPair;
147 let Charlie: IKeyringPair;147 let charlie: IKeyringPair;
148148
149 before(async () => {149 before(async () => {
150 await usingApi(async () => {150 await usingApi(async () => {
151 Alice = privateKey('//Alice');151 alice = privateKey('//Alice');
152 Bob = privateKey('//Bob');152 bob = privateKey('//Bob');
153 Charlie = privateKey('//Charlie');153 charlie = privateKey('//Charlie');
154 });154 });
155 });155 });
156156
157 it('Collection limits have greater timeout value than chain limits, collection limits are enforced', async () => {157 it('Collection limits have greater timeout value than chain limits, collection limits are enforced', async () => {
158 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});158 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
159 await setCollectionLimitsExpectSuccess(Alice, collectionId, { sponsorTimeout: 7 });159 await setCollectionLimitsExpectSuccess(alice, collectionId, {sponsorTransferTimeout: 7});
160 const tokenId = await createItemExpectSuccess(Alice, collectionId, 'Fungible');160 const tokenId = await createItemExpectSuccess(alice, collectionId, 'Fungible');
161 await setCollectionSponsorExpectSuccess(collectionId, Alice.address);161 await setCollectionSponsorExpectSuccess(collectionId, alice.address);
162 await confirmSponsorshipExpectSuccess(collectionId, '//Alice');162 await confirmSponsorshipExpectSuccess(collectionId, '//Alice');
163 await transferExpectSuccess(collectionId, tokenId, Alice, Bob, 10, 'Fungible');163 await transferExpectSuccess(collectionId, tokenId, alice, bob, 10, 'Fungible');
164 await transferExpectSuccess(collectionId, tokenId, Bob, Charlie, 2, 'Fungible');164 await transferExpectSuccess(collectionId, tokenId, bob, charlie, 2, 'Fungible');
165 const aliceBalanceBefore = await getFreeBalance(Alice);165 const aliceBalanceBefore = await getFreeBalance(alice);
166166
167 // check setting SponsorTimeout = 5, fail167 // check setting SponsorTimeout = 5, fail
168 await waitNewBlocks(5);168 await waitNewBlocks(5);
169 await transferExpectSuccess(collectionId, tokenId, Bob, Charlie, 2, 'Fungible');169 await transferExpectSuccess(collectionId, tokenId, bob, charlie, 2, 'Fungible');
170 const aliceBalanceAfterUnsponsoredTransaction = await getFreeBalance(Alice);170 const aliceBalanceAfterUnsponsoredTransaction = await getFreeBalance(alice);
171 expect(aliceBalanceAfterUnsponsoredTransaction).to.be.equals(aliceBalanceBefore);171 expect(aliceBalanceAfterUnsponsoredTransaction).to.be.equals(aliceBalanceBefore);
172172
173 // check setting SponsorTimeout = 7, success173 // check setting SponsorTimeout = 7, success
174 await waitNewBlocks(2); // 5 + 2174 await waitNewBlocks(2); // 5 + 2
175 await transferExpectSuccess(collectionId, tokenId, Bob, Charlie, 2, 'Fungible');175 await transferExpectSuccess(collectionId, tokenId, bob, charlie, 2, 'Fungible');
176 const aliceBalanceAfterSponsoredTransaction = await getFreeBalance(Alice);176 const aliceBalanceAfterSponsoredTransaction = await getFreeBalance(alice);
177 expect(aliceBalanceAfterSponsoredTransaction < aliceBalanceBefore).to.be.true;177 expect(aliceBalanceAfterSponsoredTransaction < aliceBalanceBefore).to.be.true;
178 //expect(aliceBalanceAfterSponsoredTransaction).to.be.lessThan(aliceBalanceBefore);178 //expect(aliceBalanceAfterSponsoredTransaction).to.be.lessThan(aliceBalanceBefore);
179179
183 it('Collection limits have lower timeout value than chain limits, chain limits are enforced', async () => {183 it('Collection limits have lower timeout value than chain limits, chain limits are enforced', async () => {
184184
185 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});185 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
186 await setCollectionLimitsExpectSuccess(Alice, collectionId, { sponsorTimeout: 1 });186 await setCollectionLimitsExpectSuccess(alice, collectionId, {sponsorTransferTimeout: 1});
187 const tokenId = await createItemExpectSuccess(Alice, collectionId, 'Fungible');187 const tokenId = await createItemExpectSuccess(alice, collectionId, 'Fungible');
188 await setCollectionSponsorExpectSuccess(collectionId, Alice.address);188 await setCollectionSponsorExpectSuccess(collectionId, alice.address);
189 await confirmSponsorshipExpectSuccess(collectionId, '//Alice');189 await confirmSponsorshipExpectSuccess(collectionId, '//Alice');
190 await transferExpectSuccess(collectionId, tokenId, Alice, Bob, 10, 'Fungible');190 await transferExpectSuccess(collectionId, tokenId, alice, bob, 10, 'Fungible');
191 await transferExpectSuccess(collectionId, tokenId, Bob, Charlie, 2, 'Fungible');191 await transferExpectSuccess(collectionId, tokenId, bob, charlie, 2, 'Fungible');
192 const aliceBalanceBefore = await getFreeBalance(Alice);192 const aliceBalanceBefore = await getFreeBalance(alice);
193193
194 // check setting SponsorTimeout = 1, fail194 // check setting SponsorTimeout = 1, fail
195 await waitNewBlocks(1);195 await waitNewBlocks(1);
196 await transferExpectSuccess(collectionId, tokenId, Bob, Charlie, 2, 'Fungible');196 await transferExpectSuccess(collectionId, tokenId, bob, charlie, 2, 'Fungible');
197 const aliceBalanceAfterUnsponsoredTransaction = await getFreeBalance(Alice);197 const aliceBalanceAfterUnsponsoredTransaction = await getFreeBalance(alice);
198 expect(aliceBalanceAfterUnsponsoredTransaction).to.be.equals(aliceBalanceBefore);198 expect(aliceBalanceAfterUnsponsoredTransaction).to.be.equals(aliceBalanceBefore);
199199
200 // check setting SponsorTimeout = 5, success200 // check setting SponsorTimeout = 5, success
201 await waitNewBlocks(4);201 await waitNewBlocks(4);
202 await transferExpectSuccess(collectionId, tokenId, Bob, Charlie, 2, 'Fungible');202 await transferExpectSuccess(collectionId, tokenId, bob, charlie, 2, 'Fungible');
203 const aliceBalanceAfterSponsoredTransaction = await getFreeBalance(Alice);203 const aliceBalanceAfterSponsoredTransaction = await getFreeBalance(alice);
204 expect(aliceBalanceAfterSponsoredTransaction < aliceBalanceBefore).to.be.true;204 expect(aliceBalanceAfterSponsoredTransaction < aliceBalanceBefore).to.be.true;
205 //expect(aliceBalanceAfterSponsoredTransaction).to.be.lessThan(aliceBalanceBefore);205 //expect(aliceBalanceAfterSponsoredTransaction).to.be.lessThan(aliceBalanceBefore);
206206
209});209});
210210
211describe('Sponsor timeout (ReFungible)', () => {211describe('Sponsor timeout (ReFungible)', () => {
212 let Alice: IKeyringPair;212 let alice: IKeyringPair;
213 let Bob: IKeyringPair;213 let bob: IKeyringPair;
214 let Charlie: IKeyringPair;214 let charlie: IKeyringPair;
215215
216 before(async () => {216 before(async () => {
217 await usingApi(async () => {217 await usingApi(async () => {
218 Alice = privateKey('//Alice');218 alice = privateKey('//Alice');
219 Bob = privateKey('//Bob');219 bob = privateKey('//Bob');
220 Charlie = privateKey('//Charlie');220 charlie = privateKey('//Charlie');
221 });221 });
222 });222 });
223223
224 it('Collection limits have greater timeout value than chain limits, collection limits are enforced', async () => {224 it('Collection limits have greater timeout value than chain limits, collection limits are enforced', async () => {
225 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible' }});225 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
226 await setCollectionLimitsExpectSuccess(Alice, collectionId, { sponsorTimeout: 7 });226 await setCollectionLimitsExpectSuccess(alice, collectionId, {sponsorTransferTimeout: 7});
227 const tokenId = await createItemExpectSuccess(Alice, collectionId, 'ReFungible');227 const tokenId = await createItemExpectSuccess(alice, collectionId, 'ReFungible');
228 await setCollectionSponsorExpectSuccess(collectionId, Alice.address);228 await setCollectionSponsorExpectSuccess(collectionId, alice.address);
229 await confirmSponsorshipExpectSuccess(collectionId, '//Alice');229 await confirmSponsorshipExpectSuccess(collectionId, '//Alice');
230 await transferExpectSuccess(collectionId, tokenId, Alice, Bob, 100, 'ReFungible');230 await transferExpectSuccess(collectionId, tokenId, alice, bob, 100, 'ReFungible');
231 const aliceBalanceBefore = await getFreeBalance(Alice);231 const aliceBalanceBefore = await getFreeBalance(alice);
232232
233 // check setting SponsorTimeout = 5, fail233 // check setting SponsorTimeout = 5, fail
234 await waitNewBlocks(5);234 await waitNewBlocks(5);
235 await transferExpectSuccess(collectionId, tokenId, Bob, Charlie, 20, 'ReFungible');235 await transferExpectSuccess(collectionId, tokenId, bob, charlie, 20, 'ReFungible');
236 const aliceBalanceAfterUnsponsoredTransaction = await getFreeBalance(Alice);236 const aliceBalanceAfterUnsponsoredTransaction = await getFreeBalance(alice);
237 expect(aliceBalanceAfterUnsponsoredTransaction).to.be.equals(aliceBalanceBefore);237 expect(aliceBalanceAfterUnsponsoredTransaction).to.be.equals(aliceBalanceBefore);
238238
239 // check setting SponsorTimeout = 7, success239 // check setting SponsorTimeout = 7, success
240 await waitNewBlocks(2); // 5 + 2240 await waitNewBlocks(2); // 5 + 2
241 await transferExpectSuccess(collectionId, tokenId, Bob, Charlie, 20, 'ReFungible');241 await transferExpectSuccess(collectionId, tokenId, bob, charlie, 20, 'ReFungible');
242 const aliceBalanceAfterSponsoredTransaction = await getFreeBalance(Alice);242 const aliceBalanceAfterSponsoredTransaction = await getFreeBalance(alice);
243 expect(aliceBalanceAfterSponsoredTransaction < aliceBalanceBefore).to.be.true;243 expect(aliceBalanceAfterSponsoredTransaction < aliceBalanceBefore).to.be.true;
244 //expect(aliceBalanceAfterSponsoredTransaction).to.be.lessThan(aliceBalanceBefore);244 //expect(aliceBalanceAfterSponsoredTransaction).to.be.lessThan(aliceBalanceBefore);
245 await destroyCollectionExpectSuccess(collectionId);245 await destroyCollectionExpectSuccess(collectionId);
246 });246 });
247247
248 it('Collection limits have lower timeout value than chain limits, chain limits are enforced', async () => {248 it('Collection limits have lower timeout value than chain limits, chain limits are enforced', async () => {
249249
250 const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });250 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
251 await setCollectionLimitsExpectSuccess(Alice, collectionId, { sponsorTimeout: 1 });251 await setCollectionLimitsExpectSuccess(alice, collectionId, {sponsorTransferTimeout: 1});
252 const tokenId = await createItemExpectSuccess(Alice, collectionId, 'NFT');252 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');
253 await setCollectionSponsorExpectSuccess(collectionId, Alice.address);253 await setCollectionSponsorExpectSuccess(collectionId, alice.address);
254 await confirmSponsorshipExpectSuccess(collectionId, '//Alice');254 await confirmSponsorshipExpectSuccess(collectionId, '//Alice');
255 await transferExpectSuccess(collectionId, tokenId, Alice, Bob);255 await transferExpectSuccess(collectionId, tokenId, alice, bob);
256 const aliceBalanceBefore = await getFreeBalance(Alice);256 const aliceBalanceBefore = await getFreeBalance(alice);
257257
258 // check setting SponsorTimeout = 1, fail258 // check setting SponsorTimeout = 1, fail
259 await waitNewBlocks(1);259 await waitNewBlocks(1);
260 await transferExpectSuccess(collectionId, tokenId, Bob, Charlie);260 await transferExpectSuccess(collectionId, tokenId, bob, charlie);
261 const aliceBalanceAfterUnsponsoredTransaction = await getFreeBalance(Alice);261 const aliceBalanceAfterUnsponsoredTransaction = await getFreeBalance(alice);
262 expect(aliceBalanceAfterUnsponsoredTransaction).to.be.equals(aliceBalanceBefore);262 expect(aliceBalanceAfterUnsponsoredTransaction).to.be.equals(aliceBalanceBefore);
263263
264 // check setting SponsorTimeout = 5, success264 // check setting SponsorTimeout = 5, success
265 await waitNewBlocks(4);265 await waitNewBlocks(4);
266 await transferExpectSuccess(collectionId, tokenId, Charlie, Bob);266 await transferExpectSuccess(collectionId, tokenId, charlie, bob);
267 const aliceBalanceAfterSponsoredTransaction = await getFreeBalance(Alice);267 const aliceBalanceAfterSponsoredTransaction = await getFreeBalance(alice);
268 expect(aliceBalanceAfterSponsoredTransaction < aliceBalanceBefore).to.be.true;268 expect(aliceBalanceAfterSponsoredTransaction < aliceBalanceBefore).to.be.true;
269 //expect(aliceBalanceAfterSponsoredTransaction).to.be.lessThan(aliceBalanceBefore);269 //expect(aliceBalanceAfterSponsoredTransaction).to.be.lessThan(aliceBalanceBefore);
270 await destroyCollectionExpectSuccess(collectionId);270 await destroyCollectionExpectSuccess(collectionId);
271 });271 });
272});272});
273273
274describe('Collection zero limits (NFT)', () => {274describe('Collection zero limits (NFT)', () => {
275 let Alice: IKeyringPair;275 let alice: IKeyringPair;
276 let Bob: IKeyringPair;276 let bob: IKeyringPair;
277 let Charlie: IKeyringPair;277 let charlie: IKeyringPair;
278278
279 before(async () => {279 before(async () => {
280 await usingApi(async () => {280 await usingApi(async () => {
281 Alice = privateKey('//Alice');281 alice = privateKey('//Alice');
282 Bob = privateKey('//Bob');282 bob = privateKey('//Bob');
283 Charlie = privateKey('//Charlie');283 charlie = privateKey('//Charlie');
284 });284 });
285 });285 });
286286
287 it.skip('Limits have 0 in tokens per address field, the chain limits are applied', async () => {287 it.skip('Limits have 0 in tokens per address field, the chain limits are applied', async () => {
288 const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });288 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
289 await setCollectionLimitsExpectSuccess(Alice, collectionId, { accountTokenOwnershipLimit: 0 });289 await setCollectionLimitsExpectSuccess(alice, collectionId, {accountTokenOwnershipLimit: 0});
290 for(let i = 0; i < 10; i++){290 for(let i = 0; i < 10; i++){
291 await createItemExpectSuccess(Alice, collectionId, 'NFT');291 await createItemExpectSuccess(alice, collectionId, 'NFT');
292 }292 }
293 await createItemExpectFailure(Alice, collectionId, 'NFT');293 await createItemExpectFailure(alice, collectionId, 'NFT');
294 });294 });
295295
296 it('Limits have 0 in sponsor timeout, no limits are applied', async () => {296 it('Limits have 0 in sponsor timeout, no limits are applied', async () => {
297297
298 const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });298 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
299 await setCollectionLimitsExpectSuccess(Alice, collectionId, { sponsorTimeout: 0 });299 await setCollectionLimitsExpectSuccess(alice, collectionId, {sponsorTransferTimeout: 0});
300 const tokenId = await createItemExpectSuccess(Alice, collectionId, 'NFT');300 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');
301 await setCollectionSponsorExpectSuccess(collectionId, Alice.address);301 await setCollectionSponsorExpectSuccess(collectionId, alice.address);
302 await confirmSponsorshipExpectSuccess(collectionId, '//Alice');302 await confirmSponsorshipExpectSuccess(collectionId, '//Alice');
303 await transferExpectSuccess(collectionId, tokenId, Alice, Bob);303 await transferExpectSuccess(collectionId, tokenId, alice, bob);
304 const aliceBalanceBefore = await getFreeBalance(Alice);304 const aliceBalanceBefore = await getFreeBalance(alice);
305305
306 // check setting SponsorTimeout = 0, success with next block306 // check setting SponsorTimeout = 0, success with next block
307 await waitNewBlocks(1);307 await waitNewBlocks(1);
308 await transferExpectSuccess(collectionId, tokenId, Bob, Charlie);308 await transferExpectSuccess(collectionId, tokenId, bob, charlie);
309 const aliceBalanceAfterSponsoredTransaction1 = await getFreeBalance(Alice);309 const aliceBalanceAfterSponsoredTransaction1 = await getFreeBalance(alice);
310 expect(aliceBalanceAfterSponsoredTransaction1 < aliceBalanceBefore).to.be.true;310 expect(aliceBalanceAfterSponsoredTransaction1 < aliceBalanceBefore).to.be.true;
311 //expect(aliceBalanceAfterSponsoredTransaction1).to.be.lessThan(aliceBalanceBefore);311 //expect(aliceBalanceAfterSponsoredTransaction1).to.be.lessThan(aliceBalanceBefore);
312 });312 });
313});313});
314314
315describe('Collection zero limits (Fungible)', () => {315describe('Collection zero limits (Fungible)', () => {
316 let Alice: IKeyringPair;316 let alice: IKeyringPair;
317 let Bob: IKeyringPair;317 let bob: IKeyringPair;
318 let Charlie: IKeyringPair;318 let charlie: IKeyringPair;
319319
320 before(async () => {320 before(async () => {
321 await usingApi(async () => {321 await usingApi(async () => {
322 Alice = privateKey('//Alice');322 alice = privateKey('//Alice');
323 Bob = privateKey('//Bob');323 bob = privateKey('//Bob');
324 Charlie = privateKey('//Charlie');324 charlie = privateKey('//Charlie');
325 });325 });
326 });326 });
327327
328 it('Limits have 0 in sponsor timeout, no limits are applied', async () => {328 it('Limits have 0 in sponsor timeout, no limits are applied', async () => {
329 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});329 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
330 await setCollectionLimitsExpectSuccess(Alice, collectionId, { sponsorTimeout: 0 });330 await setCollectionLimitsExpectSuccess(alice, collectionId, {sponsorTransferTimeout: 0});
331 const tokenId = await createItemExpectSuccess(Alice, collectionId, 'Fungible');331 const tokenId = await createItemExpectSuccess(alice, collectionId, 'Fungible');
332 await setCollectionSponsorExpectSuccess(collectionId, Alice.address);332 await setCollectionSponsorExpectSuccess(collectionId, alice.address);
333 await confirmSponsorshipExpectSuccess(collectionId, '//Alice');333 await confirmSponsorshipExpectSuccess(collectionId, '//Alice');
334 await transferExpectSuccess(collectionId, tokenId, Alice, Bob, 10, 'Fungible');334 await transferExpectSuccess(collectionId, tokenId, alice, bob, 10, 'Fungible');
335 const aliceBalanceBefore = await getFreeBalance(Alice);335 const aliceBalanceBefore = await getFreeBalance(alice);
336 await transferExpectSuccess(collectionId, tokenId, Bob, Charlie, 2, 'Fungible');336 await transferExpectSuccess(collectionId, tokenId, bob, charlie, 2, 'Fungible');
337337
338 // check setting SponsorTimeout = 0, success with next block338 // check setting SponsorTimeout = 0, success with next block
339 await waitNewBlocks(1);339 await waitNewBlocks(1);
340 await transferExpectSuccess(collectionId, tokenId, Bob, Charlie, 2, 'Fungible');340 await transferExpectSuccess(collectionId, tokenId, bob, charlie, 2, 'Fungible');
341 const aliceBalanceAfterSponsoredTransaction1 = await getFreeBalance(Alice);341 const aliceBalanceAfterSponsoredTransaction1 = await getFreeBalance(alice);
342 expect(aliceBalanceAfterSponsoredTransaction1 < aliceBalanceBefore).to.be.true;342 expect(aliceBalanceAfterSponsoredTransaction1 < aliceBalanceBefore).to.be.true;
343 //expect(aliceBalanceAfterSponsoredTransaction1).to.be.lessThan(aliceBalanceBefore);343 //expect(aliceBalanceAfterSponsoredTransaction1).to.be.lessThan(aliceBalanceBefore);
344 });344 });
345});345});
346346
347describe('Collection zero limits (ReFungible)', () => {347describe('Collection zero limits (ReFungible)', () => {
348 let Alice: IKeyringPair;348 let alice: IKeyringPair;
349 let Bob: IKeyringPair;349 let bob: IKeyringPair;
350 let Charlie: IKeyringPair;350 let charlie: IKeyringPair;
351351
352 before(async () => {352 before(async () => {
353 await usingApi(async () => {353 await usingApi(async () => {
354 Alice = privateKey('//Alice');354 alice = privateKey('//Alice');
355 Bob = privateKey('//Bob');355 bob = privateKey('//Bob');
356 Charlie = privateKey('//Charlie');356 charlie = privateKey('//Charlie');
357 });357 });
358 });358 });
359359
360 it.skip('Limits have 0 in tokens per address field, the chain limits are applied', async () => {360 it.skip('Limits have 0 in tokens per address field, the chain limits are applied', async () => {
361 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible' }});361 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
362 await setCollectionLimitsExpectSuccess(Alice, collectionId, { accountTokenOwnershipLimit: 0 });362 await setCollectionLimitsExpectSuccess(alice, collectionId, {accountTokenOwnershipLimit: 0});
363 for(let i = 0; i < 10; i++){363 for(let i = 0; i < 10; i++){
364 await createItemExpectSuccess(Alice, collectionId, 'ReFungible');364 await createItemExpectSuccess(alice, collectionId, 'ReFungible');
365 }365 }
366 await createItemExpectFailure(Alice, collectionId, 'ReFungible');366 await createItemExpectFailure(alice, collectionId, 'ReFungible');
367 });367 });
368368
369 it('Limits have 0 in sponsor timeout, no limits are applied', async () => {369 it('Limits have 0 in sponsor timeout, no limits are applied', async () => {
370370
371 const collectionId = await createCollectionExpectSuccess({ mode: { type: 'ReFungible' } });371 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
372 await setCollectionLimitsExpectSuccess(Alice, collectionId, { sponsorTimeout: 0 });372 await setCollectionLimitsExpectSuccess(alice, collectionId, {sponsorTransferTimeout: 0});
373 const tokenId = await createItemExpectSuccess(Alice, collectionId, 'ReFungible');373 const tokenId = await createItemExpectSuccess(alice, collectionId, 'ReFungible');
374 await setCollectionSponsorExpectSuccess(collectionId, Alice.address);374 await setCollectionSponsorExpectSuccess(collectionId, alice.address);
375 await confirmSponsorshipExpectSuccess(collectionId, '//Alice');375 await confirmSponsorshipExpectSuccess(collectionId, '//Alice');
376 await transferExpectSuccess(collectionId, tokenId, Alice, Bob, 100, 'ReFungible');376 await transferExpectSuccess(collectionId, tokenId, alice, bob, 100, 'ReFungible');
377 await transferExpectSuccess(collectionId, tokenId, Bob, Charlie, 20, 'ReFungible');377 await transferExpectSuccess(collectionId, tokenId, bob, charlie, 20, 'ReFungible');
378 const aliceBalanceBefore = await getFreeBalance(Alice);378 const aliceBalanceBefore = await getFreeBalance(alice);
379379
380 // check setting SponsorTimeout = 0, success with next block380 // check setting SponsorTimeout = 0, success with next block
381 await waitNewBlocks(1);381 await waitNewBlocks(1);
382 await transferExpectSuccess(collectionId, tokenId, Bob, Charlie, 20, 'ReFungible');382 await transferExpectSuccess(collectionId, tokenId, bob, charlie, 20, 'ReFungible');
383 const aliceBalanceAfterSponsoredTransaction1 = await getFreeBalance(Alice);383 const aliceBalanceAfterSponsoredTransaction1 = await getFreeBalance(alice);
384 expect(aliceBalanceAfterSponsoredTransaction1 < aliceBalanceBefore).to.be.true;384 expect(aliceBalanceAfterSponsoredTransaction1 < aliceBalanceBefore).to.be.true;
385 //expect(aliceBalanceAfterSponsoredTransaction1).to.be.lessThan(aliceBalanceBefore);385 //expect(aliceBalanceAfterSponsoredTransaction1).to.be.lessThan(aliceBalanceBefore);
386 });386 });
modifiedtests/src/metadataUpdate.test.tsdiffbeforeafterboth
27describe('Metadata update permissions with ItemOwner flag', () => {27describe('Metadata update permissions with ItemOwner flag', () => {
28 it('ItemOwner can set variable metadata with ItemOwner permission flag', async () => {28 it('ItemOwner can set variable metadata with ItemOwner permission flag', async () => {
29 await usingApi(async () => {29 await usingApi(async () => {
30 const Alice = privateKey('//Alice');30 const alice = privateKey('//Alice');
3131
32 const data = [1, 2, 254, 255];32 const data = [1, 2, 254, 255];
3333
34 // nft34 // nft
35 const nftCollectionId = await createCollectionExpectSuccess();35 const nftCollectionId = await createCollectionExpectSuccess();
36 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');36 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
37 await setMetadataUpdatePermissionFlagExpectSuccess(Alice, nftCollectionId, 'ItemOwner');37 await setMetadataUpdatePermissionFlagExpectSuccess(alice, nftCollectionId, 'ItemOwner');
3838
39 await setVariableMetaDataExpectSuccess(Alice, nftCollectionId, newNftTokenId, data);39 await setVariableMetaDataExpectSuccess(alice, nftCollectionId, newNftTokenId, data);
40 });40 });
41 });41 });
4242
43 it('Admin can\'n set variable metadata with ItemOwner permission flag', async () => {43 it('Admin can\'n set variable metadata with ItemOwner permission flag', async () => {
44 await usingApi(async () => {44 await usingApi(async () => {
45 const Alice = privateKey('//Alice');45 const alice = privateKey('//Alice');
46 const Bob = privateKey('//Bob');46 const bob = privateKey('//Bob');
47 47
48 const data = [1, 2, 254, 255];48 const data = [1, 2, 254, 255];
49 49
50 // nft50 // nft
51 const nftCollectionId = await createCollectionExpectSuccess();51 const nftCollectionId = await createCollectionExpectSuccess();
52 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');52 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
53 await setMetadataUpdatePermissionFlagExpectSuccess(Alice, nftCollectionId, 'ItemOwner');53 await setMetadataUpdatePermissionFlagExpectSuccess(alice, nftCollectionId, 'ItemOwner');
5454
55 await setMintPermissionExpectSuccess(Alice, nftCollectionId, true);55 await setMintPermissionExpectSuccess(alice, nftCollectionId, true);
56 await addToWhiteListExpectSuccess(Alice, nftCollectionId, Bob.address);56 await addToWhiteListExpectSuccess(alice, nftCollectionId, bob.address);
57 await addCollectionAdminExpectSuccess(Alice, nftCollectionId, Bob);57 await addCollectionAdminExpectSuccess(alice, nftCollectionId, bob.address);
58 58
59 await setVariableMetaDataExpectFailure(Bob, nftCollectionId, newNftTokenId, data);59 await setVariableMetaDataExpectFailure(bob, nftCollectionId, newNftTokenId, data);
60 });60 });
61 });61 });
6262
63 it('User can\'n set variable metadata with ItemOwner permission flag', async () => {63 it('User can\'n set variable metadata with ItemOwner permission flag', async () => {
64 await usingApi(async () => {64 await usingApi(async () => {
65 const Alice = privateKey('//Alice');65 const alice = privateKey('//Alice');
66 const Bob = privateKey('//Bob');66 const bob = privateKey('//Bob');
67 67
68 const data = [1, 2, 254, 255];68 const data = [1, 2, 254, 255];
69 69
70 // nft70 // nft
71 const nftCollectionId = await createCollectionExpectSuccess();71 const nftCollectionId = await createCollectionExpectSuccess();
72 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');72 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
73 await setMetadataUpdatePermissionFlagExpectSuccess(Alice, nftCollectionId, 'ItemOwner');73 await setMetadataUpdatePermissionFlagExpectSuccess(alice, nftCollectionId, 'ItemOwner');
7474
75 await setMintPermissionExpectSuccess(Alice, nftCollectionId, true); 75 await setMintPermissionExpectSuccess(alice, nftCollectionId, true);
76 await setVariableMetaDataExpectFailure(Bob, nftCollectionId, newNftTokenId, data);76 await setVariableMetaDataExpectFailure(bob, nftCollectionId, newNftTokenId, data);
77 });77 });
78 });78 });
79});79});
8080
81describe('Metadata update permissions with Admin flag', () => {81describe('Metadata update permissions with Admin flag', () => {
82 it('Admin can set variable metadata with Admin permission flag', async () => {82 it('Admin can set variable metadata with Admin permission flag', async () => {
83 await usingApi(async () => {83 await usingApi(async () => {
84 const Alice = privateKey('//Alice');84 const alice = privateKey('//Alice');
85 const Bob = privateKey('//Bob');85 const bob = privateKey('//Bob');
86 86
87 const data = [1, 2, 254, 255];87 const data = [1, 2, 254, 255];
88 88
89 // nft89 // nft
90 const nftCollectionId = await createCollectionExpectSuccess();90 const nftCollectionId = await createCollectionExpectSuccess();
91 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');91 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
92 await setMetadataUpdatePermissionFlagExpectSuccess(Alice, nftCollectionId, 'Admin');92 await setMetadataUpdatePermissionFlagExpectSuccess(alice, nftCollectionId, 'Admin');
9393
94 await setMintPermissionExpectSuccess(Alice, nftCollectionId, true);94 await setMintPermissionExpectSuccess(alice, nftCollectionId, true);
95 await addToWhiteListExpectSuccess(Alice, nftCollectionId, Bob.address);95 await addToWhiteListExpectSuccess(alice, nftCollectionId, bob.address);
96 await addCollectionAdminExpectSuccess(Alice, nftCollectionId, Bob);96 await addCollectionAdminExpectSuccess(alice, nftCollectionId, bob.address);
97 97
98 await setVariableMetaDataExpectSuccess(Bob, nftCollectionId, newNftTokenId, data);98 await setVariableMetaDataExpectSuccess(bob, nftCollectionId, newNftTokenId, data);
99 });99 });
100 });100 });
101101
102 it('User can\'n can set variable metadata with Admin permission flag', async () => {102 it('User can\'n can set variable metadata with Admin permission flag', async () => {
103 await usingApi(async () => {103 await usingApi(async () => {
104 const Alice = privateKey('//Alice');104 const alice = privateKey('//Alice');
105 const Bob = privateKey('//Bob');105 const bob = privateKey('//Bob');
106 106
107 const data = [1, 2, 254, 255];107 const data = [1, 2, 254, 255];
108 108
109 // nft109 // nft
110 const nftCollectionId = await createCollectionExpectSuccess();110 const nftCollectionId = await createCollectionExpectSuccess();
111 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');111 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
112 await setMetadataUpdatePermissionFlagExpectSuccess(Alice, nftCollectionId, 'Admin');112 await setMetadataUpdatePermissionFlagExpectSuccess(alice, nftCollectionId, 'Admin');
113113
114 await setMintPermissionExpectSuccess(Alice, nftCollectionId, true);114 await setMintPermissionExpectSuccess(alice, nftCollectionId, true);
115 await addToWhiteListExpectSuccess(Alice, nftCollectionId, Bob.address);115 await addToWhiteListExpectSuccess(alice, nftCollectionId, bob.address);
116 await addCollectionAdminExpectSuccess(Alice, nftCollectionId, Bob);116 await addCollectionAdminExpectSuccess(alice, nftCollectionId, bob.address);
117 117
118 await setVariableMetaDataExpectSuccess(Bob, nftCollectionId, newNftTokenId, data);118 await setVariableMetaDataExpectSuccess(bob, nftCollectionId, newNftTokenId, data);
119 });119 });
120 });120 });
121121
122 it('ItemOwner can\'n can set variable metadata with Admin permission flag', async () => {122 it('ItemOwner can\'n can set variable metadata with Admin permission flag', async () => {
123 await usingApi(async () => {123 await usingApi(async () => {
124 const Alice = privateKey('//Alice');124 const alice = privateKey('//Alice');
125 const Bob = privateKey('//Bob');125 const bob = privateKey('//Bob');
126 126
127 const data = [1, 2, 254, 255];127 const data = [1, 2, 254, 255];
128 128
129 // nft129 // nft
130 const nftCollectionId = await createCollectionExpectSuccess();130 const nftCollectionId = await createCollectionExpectSuccess();
131 await enablePublicMintingExpectSuccess(Alice, nftCollectionId);131 await enablePublicMintingExpectSuccess(alice, nftCollectionId);
132 await addToWhiteListExpectSuccess(Alice, nftCollectionId, Bob.address);132 await addToWhiteListExpectSuccess(alice, nftCollectionId, bob.address);
133 await enableWhiteListExpectSuccess(Alice, nftCollectionId);133 await enableWhiteListExpectSuccess(alice, nftCollectionId);
134 const newNftTokenId = await createItemExpectSuccess(Bob, nftCollectionId, 'NFT');134 const newNftTokenId = await createItemExpectSuccess(bob, nftCollectionId, 'NFT');
135 await setMetadataUpdatePermissionFlagExpectSuccess(Alice, nftCollectionId, 'Admin');135 await setMetadataUpdatePermissionFlagExpectSuccess(alice, nftCollectionId, 'Admin');
136 136
137 await setVariableMetaDataExpectFailure(Bob, nftCollectionId, newNftTokenId, data);137 await setVariableMetaDataExpectFailure(bob, nftCollectionId, newNftTokenId, data);
138 });138 });
139 });139 });
140});140});
141141
142describe('Metadata update permissions with None flag', () => {142describe('Metadata update permissions with None flag', () => {
143 it('Nobody can set variable metadata with None flag (Regular)', async () => {143 it('Nobody can set variable metadata with None flag (Regular)', async () => {
144 await usingApi(async () => {144 await usingApi(async () => {
145 const Alice = privateKey('//Alice');145 const alice = privateKey('//Alice');
146 const Bob = privateKey('//Bob');146 const bob = privateKey('//Bob');
147 147
148 const data = [1, 2, 254, 255];148 const data = [1, 2, 254, 255];
149 149
150 // nft150 // nft
151 const nftCollectionId = await createCollectionExpectSuccess();151 const nftCollectionId = await createCollectionExpectSuccess();
152 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');152 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
153 await setMetadataUpdatePermissionFlagExpectSuccess(Alice, nftCollectionId, 'None');153 await setMetadataUpdatePermissionFlagExpectSuccess(alice, nftCollectionId, 'None');
154 154
155 await setVariableMetaDataExpectFailure(Bob, nftCollectionId, newNftTokenId, data);155 await setVariableMetaDataExpectFailure(bob, nftCollectionId, newNftTokenId, data);
156 });156 });
157 });157 });
158158
159 it('Nobody can set variable metadata with None flag (Admin)', async () => {159 it('Nobody can set variable metadata with None flag (Admin)', async () => {
160 await usingApi(async () => {160 await usingApi(async () => {
161 const Alice = privateKey('//Alice');161 const alice = privateKey('//Alice');
162 const Bob = privateKey('//Bob');162 const bob = privateKey('//Bob');
163 163
164 const data = [1, 2, 254, 255];164 const data = [1, 2, 254, 255];
165 165
166 // nft166 // nft
167 const nftCollectionId = await createCollectionExpectSuccess();167 const nftCollectionId = await createCollectionExpectSuccess();
168 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');168 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
169 await setMetadataUpdatePermissionFlagExpectSuccess(Alice, nftCollectionId, 'None');169 await setMetadataUpdatePermissionFlagExpectSuccess(alice, nftCollectionId, 'None');
170 170
171 await setMintPermissionExpectSuccess(Alice, nftCollectionId, true);171 await setMintPermissionExpectSuccess(alice, nftCollectionId, true);
172 await addToWhiteListExpectSuccess(Alice, nftCollectionId, Bob.address);172 await addToWhiteListExpectSuccess(alice, nftCollectionId, bob.address);
173 await addCollectionAdminExpectSuccess(Alice, nftCollectionId, Bob);173 await addCollectionAdminExpectSuccess(alice, nftCollectionId, bob.address);
174 174
175 await setVariableMetaDataExpectFailure(Bob, nftCollectionId, newNftTokenId, data);175 await setVariableMetaDataExpectFailure(bob, nftCollectionId, newNftTokenId, data);
176 });176 });
177 });177 });
178178
179 it('Nobody can set variable metadata with None flag (ItemOwner)', async () => {179 it('Nobody can set variable metadata with None flag (ItemOwner)', async () => {
180 await usingApi(async () => {180 await usingApi(async () => {
181 const Alice = privateKey('//Alice');181 const alice = privateKey('//Alice');
182 182
183 const data = [1, 2, 254, 255];183 const data = [1, 2, 254, 255];
184 184
185 // nft185 // nft
186 const nftCollectionId = await createCollectionExpectSuccess();186 const nftCollectionId = await createCollectionExpectSuccess();
187 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');187 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
188 await setMetadataUpdatePermissionFlagExpectSuccess(Alice, nftCollectionId, 'None');188 await setMetadataUpdatePermissionFlagExpectSuccess(alice, nftCollectionId, 'None');
189 189
190 await setVariableMetaDataExpectFailure(Alice, nftCollectionId, newNftTokenId, data);190 await setVariableMetaDataExpectFailure(alice, nftCollectionId, newNftTokenId, data);
191 });191 });
192 });192 });
193193
194 it('Nobody can set variable metadata flag after freeze', async () => {194 it('Nobody can set variable metadata flag after freeze', async () => {
195 await usingApi(async () => {195 await usingApi(async () => {
196 const Alice = privateKey('//Alice');196 const alice = privateKey('//Alice');
197 197
198 // nft198 // nft
199 const nftCollectionId = await createCollectionExpectSuccess();199 const nftCollectionId = await createCollectionExpectSuccess();
200 await setMetadataUpdatePermissionFlagExpectSuccess(Alice, nftCollectionId, 'None');200 await setMetadataUpdatePermissionFlagExpectSuccess(alice, nftCollectionId, 'None');
201 await setMetadataUpdatePermissionFlagExpectFailure(Alice, nftCollectionId, 'Admin'); 201 await setMetadataUpdatePermissionFlagExpectFailure(alice, nftCollectionId, 'Admin');
202 });202 });
203 });203 });
204});204});
modifiedtests/src/mintModes.test.tsdiffbeforeafterboth
53 const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });53 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
54 await enableWhiteListExpectSuccess(alice, collectionId);54 await enableWhiteListExpectSuccess(alice, collectionId);
55 await setMintPermissionExpectSuccess(alice, collectionId, true);55 await setMintPermissionExpectSuccess(alice, collectionId, true);
56 await addCollectionAdminExpectSuccess(alice, collectionId, bob);56 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
57 await createItemExpectSuccess(bob, collectionId, 'NFT');57 await createItemExpectSuccess(bob, collectionId, 'NFT');
58 });58 });
59 });59 });
81 const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });81 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
82 await disableWhiteListExpectSuccess(alice, collectionId);82 await disableWhiteListExpectSuccess(alice, collectionId);
83 await setMintPermissionExpectSuccess(alice, collectionId, true);83 await setMintPermissionExpectSuccess(alice, collectionId, true);
84 await addCollectionAdminExpectSuccess(alice, collectionId, bob);84 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
85 await createItemExpectSuccess(bob, collectionId, 'NFT');85 await createItemExpectSuccess(bob, collectionId, 'NFT');
86 });86 });
87 });87 });
131 const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });131 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
132 await disableWhiteListExpectSuccess(alice, collectionId);132 await disableWhiteListExpectSuccess(alice, collectionId);
133 await setMintPermissionExpectSuccess(alice, collectionId, false);133 await setMintPermissionExpectSuccess(alice, collectionId, false);
134 await addCollectionAdminExpectSuccess(alice, collectionId, bob);134 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
135 await createItemExpectSuccess(bob, collectionId, 'NFT');135 await createItemExpectSuccess(bob, collectionId, 'NFT');
136 });136 });
137 });137 });
modifiedtests/src/overflow.test.tsdiffbeforeafterboth
8import chaiAsPromised from 'chai-as-promised';8import chaiAsPromised from 'chai-as-promised';
9import privateKey from './substrate/privateKey';9import privateKey from './substrate/privateKey';
10import usingApi from './substrate/substrate-api';10import usingApi from './substrate/substrate-api';
11import { approveExpectFail, approveExpectSuccess, createCollectionExpectSuccess, createFungibleItemExpectSuccess, getAllowance, getFungibleBalance, transferExpectFailure, transferExpectSuccess, transferFromExpectFail, transferFromExpectSuccess, U128_MAX } from './util/helpers';11import {approveExpectSuccess, createCollectionExpectSuccess, createFungibleItemExpectSuccess, getAllowance, getBalance, transferExpectFailure, transferExpectSuccess, transferFromExpectFail, transferFromExpectSuccess, U128_MAX} from './util/helpers';
1212
13chai.use(chaiAsPromised);13chai.use(chaiAsPromised);
14const expect = chai.expect;14const expect = chai.expect;
27 });27 });
2828
29 it('fails when overflows on transfer', async () => {29 it('fails when overflows on transfer', async () => {
30 await usingApi(async api => {
30 const fungibleCollectionId = await createCollectionExpectSuccess({ mode: { type: 'Fungible', decimalPoints: 0 } });31 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
3132
32 await createFungibleItemExpectSuccess(alice, fungibleCollectionId, { Value: U128_MAX });33 await createFungibleItemExpectSuccess(alice, fungibleCollectionId, {Value: U128_MAX});
35 await createFungibleItemExpectSuccess(alice, fungibleCollectionId, { Value: 1n });36 await createFungibleItemExpectSuccess(alice, fungibleCollectionId, {Value: 1n});
36 await transferExpectFailure(fungibleCollectionId, 0, alice, bob, 1);37 await transferExpectFailure(fungibleCollectionId, 0, alice, bob, 1);
3738
38 expect(await getFungibleBalance(fungibleCollectionId, alice.address)).to.equal(1n);39 expect(await getBalance(api, fungibleCollectionId, alice.address, 0)).to.equal(1n);
39 expect(await getFungibleBalance(fungibleCollectionId, bob.address)).to.equal(U128_MAX);40 expect(await getBalance(api, fungibleCollectionId, bob.address, 0)).to.equal(U128_MAX);
41 });
40 });42 });
41
42 it('fails on allowance overflow', async () => {
43 const fungibleCollectionId = await createCollectionExpectSuccess({ mode: { type: 'Fungible', decimalPoints: 0 } });
44
45 await createFungibleItemExpectSuccess(alice, fungibleCollectionId, { Value: U128_MAX });
46 await approveExpectSuccess(fungibleCollectionId, 0, alice, bob, U128_MAX);
47 await approveExpectFail(fungibleCollectionId, 0, alice, bob, U128_MAX);
48 });
4943
50 it('fails when overflows on transferFrom', async () => {44 it('fails when overflows on transferFrom', async () => {
45 await usingApi(async api => {
51 const fungibleCollectionId = await createCollectionExpectSuccess({ mode: { type: 'Fungible', decimalPoints: 0 } });46 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
52
53 await createFungibleItemExpectSuccess(alice, fungibleCollectionId, { Value: U128_MAX });47 await createFungibleItemExpectSuccess(alice, fungibleCollectionId, {Value: U128_MAX});
54 await approveExpectSuccess(fungibleCollectionId, 0, alice, bob, U128_MAX);48 await approveExpectSuccess(fungibleCollectionId, 0, alice, bob.address, U128_MAX);
55 await transferFromExpectSuccess(fungibleCollectionId, 0, bob, alice, charlie, U128_MAX, 'Fungible');49 await transferFromExpectSuccess(fungibleCollectionId, 0, bob, alice, charlie, U128_MAX, 'Fungible');
5650
57 expect(await getFungibleBalance(fungibleCollectionId, charlie.address)).to.equal(U128_MAX);51 expect(await getBalance(api, fungibleCollectionId, charlie.address, 0)).to.equal(U128_MAX);
58 expect((await getAllowance(fungibleCollectionId, 0, alice.address, bob.address)).toString()).to.equal('0');52 expect(await getAllowance(api, fungibleCollectionId, alice.address, bob.address, 0)).to.equal(0n);
5953
60 await createFungibleItemExpectSuccess(alice, fungibleCollectionId, { Value: U128_MAX });54 await createFungibleItemExpectSuccess(alice, fungibleCollectionId, {Value: U128_MAX});
61 await approveExpectSuccess(fungibleCollectionId, 0, alice, bob, 1n);55 await approveExpectSuccess(fungibleCollectionId, 0, alice, bob.address, 1n);
62 await transferFromExpectFail(fungibleCollectionId, 0, bob, alice, charlie, 1);56 await transferFromExpectFail(fungibleCollectionId, 0, bob, alice, charlie, 1);
6357
64 expect(await getFungibleBalance(fungibleCollectionId, charlie.address)).to.equal(U128_MAX);58 expect(await getBalance(api, fungibleCollectionId, charlie.address, 0)).to.equal(U128_MAX);
65 expect((await getAllowance(fungibleCollectionId, 0, alice.address, bob.address)).toString()).to.equal('1');59 expect(await getAllowance(api, fungibleCollectionId, alice.address, bob.address, 0)).to.equal(1n);
60 });
66 });61 });
67});62});
6863
modifiedtests/src/pallet-presence.test.tsdiffbeforeafterboth
14// Pallets that must always be present14// Pallets that must always be present
15const requiredPallets = [15const requiredPallets = [
16 'balances',16 'balances',
17 'common',
17 'randomnesscollectiveflip',18 'randomnesscollectiveflip',
18 'timestamp',19 'timestamp',
19 'transactionpayment',20 'transactionpayment',
28 'evmmigration',29 'evmmigration',
29 'evmtransactionpayment',30 'evmtransactionpayment',
30 'ethereum',31 'ethereum',
32 'fungible',
31 'xcmpqueue',33 'xcmpqueue',
32 'polkadotxcm',34 'polkadotxcm',
33 'cumulusxcm',35 'cumulusxcm',
34 'dmpqueue',36 'dmpqueue',
35 'inflation',37 'inflation',
36 'nft',38 'nft',
39 'nonfungible',
40 'refungible',
37 'scheduler',41 'scheduler',
38 'nftpayment',42 'nftpayment',
39 'charging',43 'charging',
modifiedtests/src/removeCollectionAdmin.test.tsdiffbeforeafterboth
8import chaiAsPromised from 'chai-as-promised';8import chaiAsPromised from 'chai-as-promised';
9import privateKey from './substrate/privateKey';9import privateKey from './substrate/privateKey';
10import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from './substrate/substrate-api';10import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';
11import {createCollectionExpectSuccess, destroyCollectionExpectSuccess, normalizeAccountId} from './util/helpers';11import {createCollectionExpectSuccess, destroyCollectionExpectSuccess, getAdminList, normalizeAccountId} from './util/helpers';
1212
13chai.use(chaiAsPromised);13chai.use(chaiAsPromised);
14const expect = chai.expect;14const expect = chai.expect;
17 it('Remove collection admin.', async () => {17 it('Remove collection admin.', async () => {
18 await usingApi(async (api: ApiPromise) => {18 await usingApi(async (api: ApiPromise) => {
19 const collectionId = await createCollectionExpectSuccess();19 const collectionId = await createCollectionExpectSuccess();
20 const Alice = privateKey('//Alice');20 const alice = privateKey('//Alice');
21 const Bob = privateKey('//Bob');21 const bob = privateKey('//Bob');
22 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();22 const collection = (await api.query.common.collectionById(collectionId)).unwrap();
23 expect(collection.owner).to.be.deep.eq(Alice.address);23 expect(collection.owner.toString()).to.be.deep.eq(alice.address);
24 // first - add collection admin Bob24 // first - add collection admin Bob
25 const addAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Bob.address));25 const addAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));
26 await submitTransactionAsync(Alice, addAdminTx);26 await submitTransactionAsync(alice, addAdminTx);
2727
28 const adminListAfterAddAdmin: any = (await api.query.nft.adminList(collectionId)).toJSON();28 const adminListAfterAddAdmin = await getAdminList(api, collectionId);
29 expect(adminListAfterAddAdmin).to.be.deep.contains(normalizeAccountId(Bob.address));29 expect(adminListAfterAddAdmin).to.be.deep.contains(normalizeAccountId(bob.address));
3030
31 // then remove bob from admins of collection31 // then remove bob from admins of collection
32 const removeAdminTx = api.tx.nft.removeCollectionAdmin(collectionId, normalizeAccountId(Bob.address));32 const removeAdminTx = api.tx.nft.removeCollectionAdmin(collectionId, normalizeAccountId(bob.address));
33 await submitTransactionAsync(Alice, removeAdminTx);33 await submitTransactionAsync(alice, removeAdminTx);
3434
35 const adminListAfterRemoveAdmin: any = (await api.query.nft.adminList(collectionId)).toJSON;35 const adminListAfterRemoveAdmin = await getAdminList(api, collectionId);
36 expect(adminListAfterRemoveAdmin).not.to.be.deep.contains(normalizeAccountId(Bob.address));36 expect(adminListAfterRemoveAdmin).not.to.be.deep.contains(normalizeAccountId(bob.address));
37 });37 });
38 });38 });
3939
40 it('Remove collection admin by admin.', async () => {40 it('Remove collection admin by admin.', async () => {
41 await usingApi(async (api: ApiPromise) => {41 await usingApi(async (api: ApiPromise) => {
42 const collectionId = await createCollectionExpectSuccess();42 const collectionId = await createCollectionExpectSuccess();
43 const Alice = privateKey('//Alice');43 const alice = privateKey('//Alice');
44 const Bob = privateKey('//Bob');44 const bob = privateKey('//Bob');
45 const Charlie = privateKey('//Charlie');45 const charlie = privateKey('//Charlie');
46 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();46 const collection = (await api.query.common.collectionById(collectionId)).unwrap();
47 expect(collection.owner).to.be.deep.eq(Alice.address);47 expect(collection.owner.toString()).to.be.eq(alice.address);
48 // first - add collection admin Bob48 // first - add collection admin Bob
49 const addAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Bob.address));49 const addAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));
50 await submitTransactionAsync(Alice, addAdminTx);50 await submitTransactionAsync(alice, addAdminTx);
5151
52 const addAdminTx2 = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Charlie.address));52 const addAdminTx2 = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(charlie.address));
53 await submitTransactionAsync(Alice, addAdminTx2);53 await submitTransactionAsync(alice, addAdminTx2);
5454
55 const adminListAfterAddAdmin: any = (await api.query.nft.adminList(collectionId)).toJSON();55 const adminListAfterAddAdmin = await getAdminList(api, collectionId);
56 expect(adminListAfterAddAdmin).to.be.deep.contains(normalizeAccountId(Bob.address));56 expect(adminListAfterAddAdmin).to.be.deep.contains(normalizeAccountId(bob.address));
5757
58 // then remove bob from admins of collection58 // then remove bob from admins of collection
59 const removeAdminTx = api.tx.nft.removeCollectionAdmin(collectionId, normalizeAccountId(Bob.address));59 const removeAdminTx = api.tx.nft.removeCollectionAdmin(collectionId, normalizeAccountId(bob.address));
60 await submitTransactionAsync(Charlie, removeAdminTx);60 await submitTransactionAsync(charlie, removeAdminTx);
6161
62 const adminListAfterRemoveAdmin: any = (await api.query.nft.adminList(collectionId)).toJSON;62 const adminListAfterRemoveAdmin = await getAdminList(api, collectionId);
63 expect(adminListAfterRemoveAdmin).not.to.be.deep.contains(normalizeAccountId(Bob.address));63 expect(adminListAfterRemoveAdmin).not.to.be.deep.contains(normalizeAccountId(bob.address));
64 });64 });
65 });65 });
6666
67 it('Remove admin from collection that has no admins', async () => {67 it('Remove admin from collection that has no admins', async () => {
68 await usingApi(async (api: ApiPromise) => {68 await usingApi(async (api: ApiPromise) => {
69 const Alice = privateKey('//Alice');69 const alice = privateKey('//Alice');
70 const collectionId = await createCollectionExpectSuccess();70 const collectionId = await createCollectionExpectSuccess();
7171
72 const adminListBeforeAddAdmin: any = (await api.query.nft.adminList(collectionId));72 const adminListBeforeAddAdmin = await getAdminList(api, collectionId);
73 expect(adminListBeforeAddAdmin).to.have.lengthOf(0);73 expect(adminListBeforeAddAdmin).to.have.lengthOf(0);
7474
75 const tx = api.tx.nft.removeCollectionAdmin(collectionId, normalizeAccountId(Alice.address));75 const tx = api.tx.nft.removeCollectionAdmin(collectionId, normalizeAccountId(alice.address));
76 await submitTransactionAsync(Alice, tx);76 await submitTransactionAsync(alice, tx);
77 });77 });
78 });78 });
79});79});
98 await usingApi(async (api: ApiPromise) => {98 await usingApi(async (api: ApiPromise) => {
99 // tslint:disable-next-line: no-bitwise99 // tslint:disable-next-line: no-bitwise
100 const collectionId = await createCollectionExpectSuccess();100 const collectionId = await createCollectionExpectSuccess();
101 const Alice = privateKey('//Alice');101 const alice = privateKey('//Alice');
102 const Bob = privateKey('//Bob');102 const bob = privateKey('//Bob');
103103
104 await destroyCollectionExpectSuccess(collectionId);104 await destroyCollectionExpectSuccess(collectionId);
105105
106 const changeOwnerTx = api.tx.nft.removeCollectionAdmin(collectionId, normalizeAccountId(Bob.address));106 const changeOwnerTx = api.tx.nft.removeCollectionAdmin(collectionId, normalizeAccountId(bob.address));
107 await expect(submitTransactionExpectFailAsync(Alice, changeOwnerTx)).to.be.rejected;107 await expect(submitTransactionExpectFailAsync(alice, changeOwnerTx)).to.be.rejected;
108108
109 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)109 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)
110 await createCollectionExpectSuccess();110 await createCollectionExpectSuccess();
114 it('Regular user Can\'t remove collection admin', async () => {114 it('Regular user Can\'t remove collection admin', async () => {
115 await usingApi(async (api: ApiPromise) => {115 await usingApi(async (api: ApiPromise) => {
116 const collectionId = await createCollectionExpectSuccess();116 const collectionId = await createCollectionExpectSuccess();
117 const Alice = privateKey('//Alice');117 const alice = privateKey('//Alice');
118 const Bob = privateKey('//Bob');118 const bob = privateKey('//Bob');
119 const Charlie = privateKey('//Charlie');119 const charlie = privateKey('//Charlie');
120120
121 const addAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Bob.address));121 const addAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));
122 await submitTransactionAsync(Alice, addAdminTx);122 await submitTransactionAsync(alice, addAdminTx);
123123
124 const changeOwnerTx = api.tx.nft.removeCollectionAdmin(collectionId, normalizeAccountId(Bob.address));124 const changeOwnerTx = api.tx.nft.removeCollectionAdmin(collectionId, normalizeAccountId(bob.address));
125 await expect(submitTransactionExpectFailAsync(Charlie, changeOwnerTx)).to.be.rejected;125 await expect(submitTransactionExpectFailAsync(charlie, changeOwnerTx)).to.be.rejected;
126126
127 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)127 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)
128 await createCollectionExpectSuccess();128 await createCollectionExpectSuccess();
modifiedtests/src/removeCollectionSponsor.test.tsdiffbeforeafterboth
21} from './util/helpers';21} from './util/helpers';
22import { Keyring } from '@polkadot/api';22import {Keyring} from '@polkadot/api';
23import { IKeyringPair } from '@polkadot/types/types';23import {IKeyringPair} from '@polkadot/types/types';
24import { BigNumber } from 'bignumber.js';
2524
26chai.use(chaiAsPromised);25chai.use(chaiAsPromised);
27const expect = chai.expect;26const expect = chai.expect;
53 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', zeroBalance.address);52 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', zeroBalance.address);
5453
55 // Transfer this tokens from unused address to Alice - should fail54 // Transfer this tokens from unused address to Alice - should fail
56 const AsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());55 const sponsorBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();
57 const zeroToAlice = api.tx.nft.transfer(normalizeAccountId(alice.address), collectionId, itemId, 0);56 const zeroToAlice = api.tx.nft.transfer(normalizeAccountId(alice.address), collectionId, itemId, 0);
58 const badTransaction = async function () { 57 const badTransaction = async function () {
59 await submitTransactionExpectFailAsync(zeroBalance, zeroToAlice);58 await submitTransactionExpectFailAsync(zeroBalance, zeroToAlice);
60 };59 };
61 await expect(badTransaction()).to.be.rejectedWith('Inability to pay some fees');60 await expect(badTransaction()).to.be.rejectedWith('Inability to pay some fees');
62 const BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());61 const sponsorBalanceAfter = (await api.query.system.account(bob.address)).data.free.toBigInt();
6362
64 expect(BsponsorBalance.isEqualTo(AsponsorBalance)).to.be.true;63 expect(sponsorBalanceAfter).to.be.equal(sponsorBalanceBefore);
65 });64 });
66 });65 });
6766
99 // Find the collection that never existed98 // Find the collection that never existed
100 let collectionId = 0;99 let collectionId = 0;
101 await usingApi(async (api) => {100 await usingApi(async (api) => {
102 collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;101 collectionId = (await api.query.common.createdCollectionCount()).toNumber() + 1;
103 });102 });
104103
105 await removeCollectionSponsorExpectFailure(collectionId);104 await removeCollectionSponsorExpectFailure(collectionId);
108 it('(!negative test!) Remove sponsor for a collection with collection admin permissions', async () => {107 it('(!negative test!) Remove sponsor for a collection with collection admin permissions', async () => {
109 const collectionId = await createCollectionExpectSuccess();108 const collectionId = await createCollectionExpectSuccess();
110 await setCollectionSponsorExpectSuccess(collectionId, bob.address);109 await setCollectionSponsorExpectSuccess(collectionId, bob.address);
111 await addCollectionAdminExpectSuccess(alice, collectionId, bob);110 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
112 await removeCollectionSponsorExpectFailure(collectionId, '//Bob');111 await removeCollectionSponsorExpectFailure(collectionId, '//Bob');
113 });112 });
114113
modifiedtests/src/removeFromContractWhiteList.test.tsdiffbeforeafterboth

no syntactic changes

modifiedtests/src/removeFromWhiteList.test.tsdiffbeforeafterboth
107 await usingApi(async () => {107 await usingApi(async () => {
108 const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });108 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
109 await enableWhiteListExpectSuccess(alice, collectionId);109 await enableWhiteListExpectSuccess(alice, collectionId);
110 await addCollectionAdminExpectSuccess(alice, collectionId, bob);110 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
111 await addToWhiteListExpectSuccess(alice, collectionId, charlie.address);111 await addToWhiteListExpectSuccess(alice, collectionId, charlie.address);
112 await removeFromWhiteListExpectSuccess(bob, collectionId, normalizeAccountId(charlie.address));112 await removeFromWhiteListExpectSuccess(bob, collectionId, normalizeAccountId(charlie.address));
113 expect(await isWhitelisted(collectionId, charlie.address)).to.be.false;113 expect(await isWhitelisted(collectionId, charlie.address)).to.be.false;
118 await usingApi(async () => {118 await usingApi(async () => {
119 const collectionWithoutWhitelistId = await createCollectionExpectSuccess();119 const collectionWithoutWhitelistId = await createCollectionExpectSuccess();
120 await enableWhiteListExpectSuccess(alice, collectionWithoutWhitelistId);120 await enableWhiteListExpectSuccess(alice, collectionWithoutWhitelistId);
121 await addCollectionAdminExpectSuccess(alice, collectionWithoutWhitelistId, bob);121 await addCollectionAdminExpectSuccess(alice, collectionWithoutWhitelistId, bob.address);
122 await addToWhiteListExpectSuccess(alice, collectionWithoutWhitelistId, charlie.address);122 await addToWhiteListExpectSuccess(alice, collectionWithoutWhitelistId, charlie.address);
123 await disableWhiteListExpectSuccess(alice, collectionWithoutWhitelistId);123 await disableWhiteListExpectSuccess(alice, collectionWithoutWhitelistId);
124 await removeFromWhiteListExpectSuccess(bob, collectionWithoutWhitelistId, normalizeAccountId(charlie.address));124 await removeFromWhiteListExpectSuccess(bob, collectionWithoutWhitelistId, normalizeAccountId(charlie.address));
modifiedtests/src/rpc.load.tsdiffbeforeafterboth
7import { IKeyringPair } from '@polkadot/types/types';7import {IKeyringPair} from '@polkadot/types/types';
8import { Abi, BlueprintPromise as Blueprint, CodePromise, ContractPromise as Contract } from '@polkadot/api-contract';8import {Abi, BlueprintPromise as Blueprint, CodePromise, ContractPromise as Contract} from '@polkadot/api-contract';
9import { ApiPromise, Keyring } from '@polkadot/api';9import {ApiPromise, Keyring} from '@polkadot/api';
10import { BigNumber } from 'bignumber.js';
11import { findUnusedAddress } from './util/helpers';10import {findUnusedAddress} from './util/helpers';
12import fs from 'fs';11import fs from 'fs';
13import privateKey from './substrate/privateKey';12import privateKey from './substrate/privateKey';
52 // Transfer balance to it51 // Transfer balance to it
53 const keyring = new Keyring({ type: 'sr25519' });52 const keyring = new Keyring({type: 'sr25519'});
54 const alice = keyring.addFromUri('//Alice');53 const alice = keyring.addFromUri('//Alice');
55 let amount = new BigNumber(endowment);54 const amount = BigInt(endowment) + 10n**15n;
56 amount = amount.plus(1e15);
57 const tx = api.tx.balances.transfer(deployer.address, amount.toFixed());55 const tx = api.tx.balances.transfer(deployer.address, amount);
58 await submitTransactionAsync(alice, tx);56 await submitTransactionAsync(alice, tx);
5957
60 return deployer;58 return deployer;
modifiedtests/src/scheduler.test.tsdiffbeforeafterboth
20describe('Integration Test scheduler base transaction', () => {20describe('Integration Test scheduler base transaction', () => {
21 it('User can transfer owned token with delay (scheduler)', async () => {21 it('User can transfer owned token with delay (scheduler)', async () => {
22 await usingApi(async () => {22 await usingApi(async () => {
23 const Alice = privateKey('//Alice');23 const alice = privateKey('//Alice');
24 const Bob = privateKey('//Bob');24 const bob = privateKey('//Bob');
25 // nft25 // nft
26 const nftCollectionId = await createCollectionExpectSuccess();26 const nftCollectionId = await createCollectionExpectSuccess();
27 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');27 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
28 await setCollectionSponsorExpectSuccess(nftCollectionId, Alice.address);28 await setCollectionSponsorExpectSuccess(nftCollectionId, alice.address);
29 await confirmSponsorshipExpectSuccess(nftCollectionId);29 await confirmSponsorshipExpectSuccess(nftCollectionId);
3030
31 await scheduleTransferExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 1, 12000, 4);31 await scheduleTransferExpectSuccess(nftCollectionId, newNftTokenId, alice, bob, 1, 4);
32 });32 });
33 });33 });
34});34});
modifiedtests/src/setChainLimits.test.tsdiffbeforeafterboth
4646
47 it('Collection admin cannot set chain limits', async () => {47 it('Collection admin cannot set chain limits', async () => {
48 const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });48 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
49 await addCollectionAdminExpectSuccess(alice, collectionId, bob);49 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
50 await setChainLimitsExpectFailure(bob, limits);50 await setChainLimitsExpectFailure(bob, limits);
51 });51 });
52 52
modifiedtests/src/setCollectionLimits.test.tsdiffbeforeafterboth
9import chai from 'chai';9import chai from 'chai';
10import chaiAsPromised from 'chai-as-promised';10import chaiAsPromised from 'chai-as-promised';
11import usingApi, {submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';11import usingApi, {submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';
12import { ICollectionInterface } from './types';
13import {12import {
14 createCollectionExpectSuccess, getCreatedCollectionCount,13 createCollectionExpectSuccess, getCreatedCollectionCount,
15 getCreateItemResult,14 getCreateItemResult,
16 getDetailedCollectionInfo,
17 setCollectionLimitsExpectFailure,15 setCollectionLimitsExpectFailure,
18 setCollectionLimitsExpectSuccess,16 setCollectionLimitsExpectSuccess,
19 addCollectionAdminExpectSuccess,17 addCollectionAdminExpectSuccess,
18 queryCollectionExpectSuccess,
20} from './util/helpers';19} from './util/helpers';
2120
22chai.use(chaiAsPromised);21chai.use(chaiAsPromised);
2827
29const accountTokenOwnershipLimit = 0;28const accountTokenOwnershipLimit = 0;
30const sponsoredDataSize = 0;29const sponsoredDataSize = 0;
31const sponsoredMintSize = 0;
32const sponsorTimeout = 1;30const sponsorTransferTimeout = 1;
33const tokenLimit = 10;31const tokenLimit = 10;
3432
35describe('setCollectionLimits positive', () => {33describe('setCollectionLimits positive', () => {
47 collectionIdForTesting,45 collectionIdForTesting,
48 {46 {
49 accountTokenOwnershipLimit: accountTokenOwnershipLimit,47 accountTokenOwnershipLimit: accountTokenOwnershipLimit,
50 sponsoredMintSize: sponsoredDataSize,48 sponsoredDataSize: sponsoredDataSize,
51 tokenLimit: tokenLimit,49 tokenLimit: tokenLimit,
52 sponsorTimeout: sponsorTimeout,50 sponsorTransferTimeout,
53 ownerCanTransfer: true,51 ownerCanTransfer: true,
54 ownerCanDestroy: true,52 ownerCanDestroy: true,
55 },53 },
58 const result = getCreateItemResult(events);56 const result = getCreateItemResult(events);
5957
60 // get collection limits defined previously58 // get collection limits defined previously
61 const collectionInfo = await getDetailedCollectionInfo(api, collectionIdForTesting) as ICollectionInterface;59 const collectionInfo = await queryCollectionExpectSuccess(api, collectionIdForTesting);
6260
63 // tslint:disable-next-line:no-unused-expression61 // tslint:disable-next-line:no-unused-expression
64 expect(result.success).to.be.true;62 expect(result.success).to.be.true;
65 expect(collectionInfo.limits.accountTokenOwnershipLimit).to.be.equal(accountTokenOwnershipLimit);63 expect(collectionInfo.limits.accountTokenOwnershipLimit.unwrap().toNumber()).to.be.equal(accountTokenOwnershipLimit);
66 expect(collectionInfo.limits.sponsoredDataSize).to.be.equal(sponsoredDataSize);64 expect(collectionInfo.limits.sponsoredDataSize.unwrap().toNumber()).to.be.equal(sponsoredDataSize);
67 expect(collectionInfo.limits.tokenLimit).to.be.equal(tokenLimit);65 expect(collectionInfo.limits.tokenLimit.unwrap().toNumber()).to.be.equal(tokenLimit);
68 expect(collectionInfo.limits.sponsorTimeout).to.be.equal(sponsorTimeout);66 expect(collectionInfo.limits.sponsorTransferTimeout.unwrap().toNumber()).to.be.equal(sponsorTransferTimeout);
69 expect(collectionInfo.limits.ownerCanTransfer).to.be.true;67 expect(collectionInfo.limits.ownerCanTransfer.unwrap().toJSON()).to.be.true;
70 expect(collectionInfo.limits.ownerCanDestroy).to.be.true;68 expect(collectionInfo.limits.ownerCanDestroy.unwrap().toJSON()).to.be.true;
71 });69 });
72 });70 });
7371
78 accountTokenOwnershipLimit: accountTokenOwnershipLimit,76 accountTokenOwnershipLimit: accountTokenOwnershipLimit,
79 sponsoredMintSize: sponsoredDataSize,77 sponsoredMintSize: sponsoredDataSize,
80 tokenLimit: tokenLimit,78 tokenLimit: tokenLimit,
81 sponsorTimeout: sponsorTimeout,79 sponsorTransferTimeout,
82 ownerCanTransfer: true,80 ownerCanTransfer: true,
83 ownerCanDestroy: true,81 ownerCanDestroy: true,
84 };82 };
90 );88 );
91 const events1 = await submitTransactionAsync(alice, tx1);89 const events1 = await submitTransactionAsync(alice, tx1);
92 const result1 = getCreateItemResult(events1);90 const result1 = getCreateItemResult(events1);
91 expect(result1.success).to.be.true;
93 const collectionInfo1 = await getDetailedCollectionInfo(api, collectionIdForTesting) as ICollectionInterface;92 const collectionInfo1 = await queryCollectionExpectSuccess(api, collectionIdForTesting);
93 expect(collectionInfo1.limits.tokenLimit.unwrap().toNumber()).to.be.equal(tokenLimit);
9494
95 // The second time95 // The second time
96 const tx2 = api.tx.nft.setCollectionLimits(96 const tx2 = api.tx.nft.setCollectionLimits(
99 );99 );
100 const events2 = await submitTransactionAsync(alice, tx2);100 const events2 = await submitTransactionAsync(alice, tx2);
101 const result2 = getCreateItemResult(events2);101 const result2 = getCreateItemResult(events2);
102 const collectionInfo2 = await getDetailedCollectionInfo(api, collectionIdForTesting) as ICollectionInterface;
103
104 // tslint:disable-next-line:no-unused-expression
105 expect(result1.success).to.be.true;102 expect(result2.success).to.be.true;
106 expect(collectionInfo1.limits.tokenLimit).to.be.equal(tokenLimit);
107 expect(result2.success).to.be.true;103 const collectionInfo2 = await queryCollectionExpectSuccess(api, collectionIdForTesting);
108 expect(collectionInfo2.limits.tokenLimit).to.be.equal(tokenLimit);104 expect(collectionInfo2.limits.tokenLimit.unwrap().toNumber()).to.be.equal(tokenLimit);
109 });105 });
110 });106 });
111107
130 {126 {
131 accountTokenOwnershipLimit,127 accountTokenOwnershipLimit,
132 sponsoredDataSize,128 sponsoredDataSize,
133 sponsoredMintSize,129 // sponsoredMintSize,
134 tokenLimit,130 tokenLimit,
135 },131 },
136 );132 );
144 {140 {
145 accountTokenOwnershipLimit,141 accountTokenOwnershipLimit,
146 sponsoredDataSize,142 sponsoredDataSize,
147 sponsoredMintSize,143 // sponsoredMintSize,
148 tokenLimit,144 tokenLimit,
149 },145 },
150 );146 );
151 await expect(submitTransactionExpectFailAsync(bob, tx)).to.be.rejected;147 await expect(submitTransactionExpectFailAsync(bob, tx)).to.be.rejected;
152 });148 });
153 });149 });
154 it('execute setCollectionLimits from admin collection', async () => {150 it('execute setCollectionLimits from admin collection', async () => {
155 await addCollectionAdminExpectSuccess(alice, collectionIdForTesting, bob);151 await addCollectionAdminExpectSuccess(alice, collectionIdForTesting, bob.address);
156 await usingApi(async (api: ApiPromise) => {152 await usingApi(async (api: ApiPromise) => {
157 tx = api.tx.nft.setCollectionLimits(153 tx = api.tx.nft.setCollectionLimits(
158 collectionIdForTesting,154 collectionIdForTesting,
159 {155 {
160 accountTokenOwnershipLimit,156 accountTokenOwnershipLimit,
161 sponsoredDataSize,157 sponsoredDataSize,
162 sponsoredMintSize,158 // sponsoredMintSize,
163 tokenLimit,159 tokenLimit,
164 },160 },
165 );161 );
173 accountTokenOwnershipLimit: accountTokenOwnershipLimit,169 accountTokenOwnershipLimit: accountTokenOwnershipLimit,
174 sponsoredMintSize: sponsoredDataSize,170 sponsoredMintSize: sponsoredDataSize,
175 tokenLimit: tokenLimit,171 tokenLimit: tokenLimit,
176 sponsorTimeout: sponsorTimeout,172 sponsorTransferTimeout,
177 ownerCanTransfer: false,173 ownerCanTransfer: false,
178 ownerCanDestroy: true,174 ownerCanDestroy: true,
179 });175 });
180 await setCollectionLimitsExpectFailure(alice, collectionId, {176 await setCollectionLimitsExpectFailure(alice, collectionId, {
181 accountTokenOwnershipLimit: accountTokenOwnershipLimit,177 accountTokenOwnershipLimit: accountTokenOwnershipLimit,
182 sponsoredMintSize: sponsoredDataSize,178 sponsoredMintSize: sponsoredDataSize,
183 tokenLimit: tokenLimit,179 tokenLimit: tokenLimit,
184 sponsorTimeout: sponsorTimeout,180 sponsorTransferTimeout,
185 ownerCanTransfer: true,181 ownerCanTransfer: true,
186 ownerCanDestroy: true,182 ownerCanDestroy: true,
187 });183 });
193 accountTokenOwnershipLimit: accountTokenOwnershipLimit,189 accountTokenOwnershipLimit: accountTokenOwnershipLimit,
194 sponsoredMintSize: sponsoredDataSize,190 sponsoredMintSize: sponsoredDataSize,
195 tokenLimit: tokenLimit,191 tokenLimit: tokenLimit,
196 sponsorTimeout: sponsorTimeout,192 sponsorTransferTimeout,
197 ownerCanTransfer: true,193 ownerCanTransfer: true,
198 ownerCanDestroy: false,194 ownerCanDestroy: false,
199 });195 });
200 await setCollectionLimitsExpectFailure(alice, collectionId, {196 await setCollectionLimitsExpectFailure(alice, collectionId, {
201 accountTokenOwnershipLimit: accountTokenOwnershipLimit,197 accountTokenOwnershipLimit: accountTokenOwnershipLimit,
202 sponsoredMintSize: sponsoredDataSize,198 sponsoredMintSize: sponsoredDataSize,
203 tokenLimit: tokenLimit,199 tokenLimit: tokenLimit,
204 sponsorTimeout: sponsorTimeout,200 sponsorTransferTimeout,
205 ownerCanTransfer: true,201 ownerCanTransfer: true,
206 ownerCanDestroy: true,202 ownerCanDestroy: true,
207 });203 });
215 accountTokenOwnershipLimit: accountTokenOwnershipLimit,211 accountTokenOwnershipLimit: accountTokenOwnershipLimit,
216 sponsoredMintSize: sponsoredDataSize,212 sponsoredMintSize: sponsoredDataSize,
217 tokenLimit: tokenLimit,213 tokenLimit: tokenLimit,
218 sponsorTimeout: sponsorTimeout,214 sponsorTransferTimeout,
219 ownerCanTransfer: true,215 ownerCanTransfer: true,
220 ownerCanDestroy: true,216 ownerCanDestroy: true,
221 };217 };
modifiedtests/src/setCollectionSponsor.test.tsdiffbeforeafterboth
77 // Find the collection that never existed77 // Find the collection that never existed
78 let collectionId = 0;78 let collectionId = 0;
79 await usingApi(async (api) => {79 await usingApi(async (api) => {
80 collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;80 collectionId = (await api.query.common.createdCollectionCount()).toNumber() + 1;
81 });81 });
8282
83 await setCollectionSponsorExpectFailure(collectionId, bob.address);83 await setCollectionSponsorExpectFailure(collectionId, bob.address);
89 });89 });
90 it('(!negative test!) Collection admin add sponsor', async () => {90 it('(!negative test!) Collection admin add sponsor', async () => {
91 const collectionId = await createCollectionExpectSuccess();91 const collectionId = await createCollectionExpectSuccess();
92 await addCollectionAdminExpectSuccess(alice, collectionId, bob);92 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
93 await setCollectionSponsorExpectFailure(collectionId, charlie.address, '//Bob');93 await setCollectionSponsorExpectFailure(collectionId, charlie.address, '//Bob');
94 });94 });
95});95});
modifiedtests/src/setConstOnChainSchema.test.tsdiffbeforeafterboth
17chai.use(chaiAsPromised);17chai.use(chaiAsPromised);
18const expect = chai.expect;18const expect = chai.expect;
1919
20let Alice: IKeyringPair;20let alice: IKeyringPair;
21let Bob: IKeyringPair;21let bob: IKeyringPair;
22let Shema: any;22let shema: any;
23let largeShema: any;23let largeShema: any;
2424
25before(async () => {25before(async () => {
26 await usingApi(async () => {26 await usingApi(async () => {
27 const keyring = new Keyring({ type: 'sr25519' });27 const keyring = new Keyring({type: 'sr25519'});
28 Alice = keyring.addFromUri('//Alice');28 alice = keyring.addFromUri('//Alice');
29 Bob = keyring.addFromUri('//Bob');29 bob = keyring.addFromUri('//Bob');
30 Shema = '0x31';30 shema = '0x31';
31 largeShema = new Array(4097).fill(0xff);31 largeShema = new Array(4097).fill(0xff);
3232
33 });33 });
37 it('Run extrinsic with parameters of the collection id, set the scheme', async () => {37 it('Run extrinsic with parameters of the collection id, set the scheme', async () => {
38 await usingApi(async (api) => {38 await usingApi(async (api) => {
39 const collectionId = await createCollectionExpectSuccess();39 const collectionId = await createCollectionExpectSuccess();
40 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();40 const collection = (await api.query.common.collectionById(collectionId)).unwrap();
41 expect(collection.owner).to.be.eq(Alice.address);41 expect(collection.owner.toString()).to.be.eq(alice.address);
42 const setShema = api.tx.nft.setConstOnChainSchema(collectionId, Shema);42 const setShema = api.tx.nft.setConstOnChainSchema(collectionId, shema);
43 await submitTransactionAsync(Alice, setShema);43 await submitTransactionAsync(alice, setShema);
44 });44 });
45 });45 });
4646
47 it('Collection admin can set the scheme', async () => {47 it('Collection admin can set the scheme', async () => {
48 await usingApi(async (api) => {48 await usingApi(async (api) => {
49 const collectionId = await createCollectionExpectSuccess();49 const collectionId = await createCollectionExpectSuccess();
50 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();50 const collection = (await api.query.common.collectionById(collectionId)).unwrap();
51 expect(collection.owner).to.be.eq(Alice.address);51 expect(collection.owner.toString()).to.be.eq(alice.address);
52 await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);52 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
53 const setShema = api.tx.nft.setConstOnChainSchema(collectionId, Shema);53 const setShema = api.tx.nft.setConstOnChainSchema(collectionId, shema);
54 await submitTransactionAsync(Bob, setShema);54 await submitTransactionAsync(bob, setShema);
55 });55 });
56 });56 });
5757
58 it('Checking collection data using the ConstOnChainSchema parameter', async () => {58 it('Checking collection data using the ConstOnChainSchema parameter', async () => {
59 await usingApi(async (api) => {59 await usingApi(async (api) => {
60 const collectionId = await createCollectionExpectSuccess();60 const collectionId = await createCollectionExpectSuccess();
61 const setShema = api.tx.nft.setConstOnChainSchema(collectionId, Shema);61 const setShema = api.tx.nft.setConstOnChainSchema(collectionId, shema);
62 await submitTransactionAsync(Alice, setShema);62 await submitTransactionAsync(alice, setShema);
63 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();63 const collection = (await api.query.common.collectionById(collectionId)).unwrap();
64 expect(collection.constOnChainSchema.toString()).to.be.eq(Shema);64 expect(collection.constOnChainSchema.toString()).to.be.eq(shema);
65
66 });65 });
67 });66 });
72 it('Set a non-existent collection', async () => {71 it('Set a non-existent collection', async () => {
73 await usingApi(async (api) => {72 await usingApi(async (api) => {
74 // tslint:disable-next-line: radix73 // tslint:disable-next-line: radix
75 const collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;74 const collectionId = (await api.query.common.createdCollectionCount()).toNumber() + 1;
76 const setShema = api.tx.nft.setConstOnChainSchema(collectionId, Shema);75 const setShema = api.tx.nft.setConstOnChainSchema(collectionId, shema);
77 await expect(submitTransactionExpectFailAsync(Alice, setShema)).to.be.rejected;76 await expect(submitTransactionExpectFailAsync(alice, setShema)).to.be.rejected;
78 });77 });
79 });78 });
8079
81 it('Set a previously deleted collection', async () => {80 it('Set a previously deleted collection', async () => {
82 await usingApi(async (api) => {81 await usingApi(async (api) => {
83 const collectionId = await createCollectionExpectSuccess();82 const collectionId = await createCollectionExpectSuccess();
84 await destroyCollectionExpectSuccess(collectionId);83 await destroyCollectionExpectSuccess(collectionId);
85 const setShema = api.tx.nft.setConstOnChainSchema(collectionId, Shema);84 const setShema = api.tx.nft.setConstOnChainSchema(collectionId, shema);
86 await expect(submitTransactionExpectFailAsync(Alice, setShema)).to.be.rejected;85 await expect(submitTransactionExpectFailAsync(alice, setShema)).to.be.rejected;
87 });86 });
88 });87 });
8988
90 it('Set invalid data in schema (size too large:> 1024b)', async () => {89 it('Set invalid data in schema (size too large:> 1024b)', async () => {
91 await usingApi(async (api) => {90 await usingApi(async (api) => {
92 const collectionId = await createCollectionExpectSuccess();91 const collectionId = await createCollectionExpectSuccess();
93 const setShema = api.tx.nft.setConstOnChainSchema(collectionId, largeShema);92 const setShema = api.tx.nft.setConstOnChainSchema(collectionId, largeShema);
94 await expect(submitTransactionExpectFailAsync(Alice, setShema)).to.be.rejected;93 await expect(submitTransactionExpectFailAsync(alice, setShema)).to.be.rejected;
95 });94 });
96 });95 });
9796
98 it('Execute method not on behalf of the collection owner', async () => {97 it('Execute method not on behalf of the collection owner', async () => {
99 await usingApi(async (api) => {98 await usingApi(async (api) => {
100 const collectionId = await createCollectionExpectSuccess();99 const collectionId = await createCollectionExpectSuccess();
101 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();100 const collection = (await api.query.common.collectionById(collectionId)).unwrap();
102 expect(collection.owner).to.be.eq(Alice.address);101 expect(collection.owner.toString()).to.be.eq(alice.address);
103 const setShema = api.tx.nft.setConstOnChainSchema(collectionId, Shema);102 const setShema = api.tx.nft.setConstOnChainSchema(collectionId, shema);
104 await expect(submitTransactionExpectFailAsync(Bob, setShema)).to.be.rejected;103 await expect(submitTransactionExpectFailAsync(bob, setShema)).to.be.rejected;
105 });104 });
106 });105 });
107106
modifiedtests/src/setContractSponsoringRateLimit.test.tsdiffbeforeafterboth

no syntactic changes

modifiedtests/src/setMintPermission.test.tsdiffbeforeafterboth
95 it('Collection admin fails on set', async () => {95 it('Collection admin fails on set', async () => {
96 await usingApi(async () => {96 await usingApi(async () => {
97 const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });97 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
98 await addCollectionAdminExpectSuccess(alice, collectionId, bob);98 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
99 await setMintPermissionExpectFailure(bob, collectionId, true);99 await setMintPermissionExpectFailure(bob, collectionId, true);
100 });100 });
101 });101 });
modifiedtests/src/setOffchainSchema.test.tsdiffbeforeafterboth
35 });35 });
3636
37 it('execute setOffchainSchema, verify data was set', async () => {37 it('execute setOffchainSchema, verify data was set', async () => {
38 await usingApi(async api => {
38 const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });39 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
39 await setOffchainSchemaExpectSuccess(alice, collectionId, DATA);40 await setOffchainSchemaExpectSuccess(alice, collectionId, DATA);
40 const collection = await queryCollectionExpectSuccess(collectionId);41 const collection = await queryCollectionExpectSuccess(api, collectionId);
4142
42 expect(collection.offchainSchema).to.be.equal('0x' + Buffer.from(DATA).toString('hex'));43 expect(collection.offchainSchema).to.be.equal('0x' + Buffer.from(DATA).toString('hex'));
44 });
43 });45 });
4446
45 it('execute setOffchainSchema (collection admin), verify data was set', async () => {47 it('execute setOffchainSchema (collection admin), verify data was set', async () => {
48 await usingApi(async api => {
46 const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });49 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
47 await addCollectionAdminExpectSuccess(alice, collectionId, bob);50 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
48 await setOffchainSchemaExpectSuccess(bob, collectionId, DATA);51 await setOffchainSchemaExpectSuccess(bob, collectionId, DATA);
49 const collection = await queryCollectionExpectSuccess(collectionId);52 const collection = await queryCollectionExpectSuccess(api, collectionId);
5053
51 expect(collection.offchainSchema).to.be.equal('0x' + Buffer.from(DATA).toString('hex'));54 expect(collection.offchainSchema).to.be.equal('0x' + Buffer.from(DATA).toString('hex'));
55 });
52 });56 });
53});57});
5458
modifiedtests/src/setPublicAccessMode.test.tsdiffbeforeafterboth
24chai.use(chaiAsPromised);24chai.use(chaiAsPromised);
25const expect = chai.expect;25const expect = chai.expect;
2626
27let Alice: IKeyringPair;27let alice: IKeyringPair;
28let Bob: IKeyringPair;28let bob: IKeyringPair;
2929
30describe('Integration Test setPublicAccessMode(): ', () => {30describe('Integration Test setPublicAccessMode(): ', () => {
31 before(async () => {31 before(async () => {
32 await usingApi(async () => {32 await usingApi(async () => {
33 Alice = privateKey('//Alice');33 alice = privateKey('//Alice');
34 Bob = privateKey('//Bob');34 bob = privateKey('//Bob');
35 });35 });
36 });36 });
3737
38 it('Run extrinsic with collection id parameters, set the whitelist mode for the collection', async () => {38 it('Run extrinsic with collection id parameters, set the whitelist mode for the collection', async () => {
39 await usingApi(async () => {39 await usingApi(async () => {
40 const collectionId: number = await createCollectionExpectSuccess();40 const collectionId: number = await createCollectionExpectSuccess();
41 await enableWhiteListExpectSuccess(Alice, collectionId);41 await enableWhiteListExpectSuccess(alice, collectionId);
42 await enablePublicMintingExpectSuccess(Alice, collectionId);42 await enablePublicMintingExpectSuccess(alice, collectionId);
43 await addToWhiteListExpectSuccess(Alice, collectionId, Bob.address);43 await addToWhiteListExpectSuccess(alice, collectionId, bob.address);
44 await createItemExpectSuccess(Bob, collectionId, 'NFT', Bob.address);44 await createItemExpectSuccess(bob, collectionId, 'NFT', bob.address);
45 });45 });
46 });46 });
4747
48 it('Whitelisted collection limits', async () => {48 it('Whitelisted collection limits', async () => {
49 await usingApi(async (api: ApiPromise) => {49 await usingApi(async (api: ApiPromise) => {
50 const collectionId = await createCollectionExpectSuccess();50 const collectionId = await createCollectionExpectSuccess();
51 await enableWhiteListExpectSuccess(Alice, collectionId);51 await enableWhiteListExpectSuccess(alice, collectionId);
52 await enablePublicMintingExpectSuccess(Alice, collectionId);52 await enablePublicMintingExpectSuccess(alice, collectionId);
53 const tx = api.tx.nft.createItem(collectionId, normalizeAccountId(Bob.address), 'NFT');53 const tx = api.tx.nft.createItem(collectionId, normalizeAccountId(bob.address), 'NFT');
54 await expect(submitTransactionExpectFailAsync(Bob, tx)).to.be.rejected;54 await expect(submitTransactionExpectFailAsync(bob, tx)).to.be.rejected;
55 });55 });
56 });56 });
57});57});
60 it('Set a non-existent collection', async () => {60 it('Set a non-existent collection', async () => {
61 await usingApi(async (api: ApiPromise) => {61 await usingApi(async (api: ApiPromise) => {
62 // tslint:disable-next-line: radix62 // tslint:disable-next-line: radix
63 const collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;63 const collectionId = (await api.query.common.createdCollectionCount()).toNumber() + 1;
64 const tx = api.tx.nft.setPublicAccessMode(collectionId, 'WhiteList');64 const tx = api.tx.nft.setPublicAccessMode(collectionId, 'WhiteList');
65 await expect(submitTransactionExpectFailAsync(Alice, tx)).to.be.rejected;65 await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;
66 });66 });
67 });67 });
6868
72 const collectionId = await createCollectionExpectSuccess();72 const collectionId = await createCollectionExpectSuccess();
73 await destroyCollectionExpectSuccess(collectionId);73 await destroyCollectionExpectSuccess(collectionId);
74 const tx = api.tx.nft.setPublicAccessMode(collectionId, 'WhiteList');74 const tx = api.tx.nft.setPublicAccessMode(collectionId, 'WhiteList');
75 await expect(submitTransactionExpectFailAsync(Alice, tx)).to.be.rejected;75 await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;
76 });76 });
77 });77 });
7878
79 it('Re-set the list mode already set in quantity', async () => {79 it('Re-set the list mode already set in quantity', async () => {
80 await usingApi(async () => {80 await usingApi(async () => {
81 const collectionId: number = await createCollectionExpectSuccess();81 const collectionId: number = await createCollectionExpectSuccess();
82 await enableWhiteListExpectSuccess(Alice, collectionId);82 await enableWhiteListExpectSuccess(alice, collectionId);
83 await enableWhiteListExpectSuccess(Alice, collectionId);83 await enableWhiteListExpectSuccess(alice, collectionId);
84 });84 });
85 });85 });
8686
89 // tslint:disable-next-line: no-bitwise89 // tslint:disable-next-line: no-bitwise
90 const collectionId = await createCollectionExpectSuccess();90 const collectionId = await createCollectionExpectSuccess();
91 const tx = api.tx.nft.setPublicAccessMode(collectionId, 'WhiteList');91 const tx = api.tx.nft.setPublicAccessMode(collectionId, 'WhiteList');
92 await expect(submitTransactionExpectFailAsync(Bob, tx)).to.be.rejected;92 await expect(submitTransactionExpectFailAsync(bob, tx)).to.be.rejected;
93 });93 });
94 });94 });
95});95});
9696
97describe('Negative Integration Test ext. collection admin setPublicAccessMode(): ', () => {97describe('Negative Integration Test ext. collection admin setPublicAccessMode(): ', () => {
98 before(async () => {98 before(async () => {
99 await usingApi(async () => {99 await usingApi(async () => {
100 Alice = privateKey('//Alice');100 alice = privateKey('//Alice');
101 Bob = privateKey('//Bob');101 bob = privateKey('//Bob');
102 });102 });
103 });103 });
104 it('setPublicAccessMode by collection admin', async () => {104 it('setPublicAccessMode by collection admin', async () => {
105 await usingApi(async (api: ApiPromise) => {105 await usingApi(async (api: ApiPromise) => {
106 // tslint:disable-next-line: no-bitwise106 // tslint:disable-next-line: no-bitwise
107 const collectionId = await createCollectionExpectSuccess();107 const collectionId = await createCollectionExpectSuccess();
108 await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);108 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
109 const tx = api.tx.nft.setPublicAccessMode(collectionId, 'WhiteList');109 const tx = api.tx.nft.setPublicAccessMode(collectionId, 'WhiteList');
110 await expect(submitTransactionExpectFailAsync(Bob, tx)).to.be.rejected;110 await expect(submitTransactionExpectFailAsync(bob, tx)).to.be.rejected;
111 });111 });
112 });112 });
113});113});
modifiedtests/src/setSchemaVersion.test.tsdiffbeforeafterboth
9import chai from 'chai';9import chai from 'chai';
10import chaiAsPromised from 'chai-as-promised';10import chaiAsPromised from 'chai-as-promised';
11import usingApi, {submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';11import usingApi, {submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';
12import { ICollectionInterface } from './types';
13import {12import {
14 createCollectionExpectSuccess,13 createCollectionExpectSuccess,
15 destroyCollectionExpectSuccess,14 destroyCollectionExpectSuccess,
25let alice: IKeyringPair;24let alice: IKeyringPair;
26let bob: IKeyringPair;25let bob: IKeyringPair;
27let charlie: IKeyringPair;26let charlie: IKeyringPair;
28let collectionIdForTesting: number;
2927
30/*28/*
311. We create collection.291. We create collection.
322. Save just created collection id.302. Save just created collection id.
333. Use this id for setSchemaVersion.313. Use this id for setSchemaVersion.
34*/32*/
35
36describe('hooks', () => {
37 before(async () => {
38 await usingApi(async () => {
39 const keyring = new Keyring({ type: 'sr25519' });
40 alice = keyring.addFromUri('//Alice');
41 });
42 });
43 it('choose or create collection for testing', async () => {
44 await usingApi(async () => {
45 collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});
46 });
47 });
48});
49
50describe('setSchemaVersion positive', () => {33describe('setSchemaVersion positive', () => {
51 let tx;34 let tx;
57 });40 });
58 it('execute setSchemaVersion with image url and unique ', async () => {41 it('execute setSchemaVersion with image url and unique ', async () => {
59 await usingApi(async (api: ApiPromise) => {42 await usingApi(async (api: ApiPromise) => {
43 const collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});
60 tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'Unique');44 tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'Unique');
61 const events = await submitTransactionAsync(alice, tx);45 const events = await submitTransactionAsync(alice, tx);
62 const result = getCreateItemResult(events);46 const result = getCreateItemResult(events);
63 const collectionInfo = await getDetailedCollectionInfo(api, collectionIdForTesting) as ICollectionInterface;47 const collectionInfo = await getDetailedCollectionInfo(api, collectionIdForTesting);
64 // tslint:disable-next-line:no-unused-expression48 // tslint:disable-next-line:no-unused-expression
65 expect(result.success).to.be.true;49 expect(result.success).to.be.true;
66 // tslint:disable-next-line:no-unused-expression50 // tslint:disable-next-line:no-unused-expression
7357
74describe('Collection admin setSchemaVersion positive', () => {58describe('Collection admin setSchemaVersion positive', () => {
75 let tx;59 let tx;
60 let collectionIdForTesting: any;
61
76 before(async () => {62 before(async () => {
77 await usingApi(async () => {63 await usingApi(async () => {
78 const keyring = new Keyring({ type: 'sr25519' });64 const keyring = new Keyring({type: 'sr25519'});
79 alice = keyring.addFromUri('//Alice');65 alice = keyring.addFromUri('//Alice');
80 bob = keyring.addFromUri('//Bob');66 bob = keyring.addFromUri('//Bob');
67 collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});
81 await addCollectionAdminExpectSuccess(alice, collectionIdForTesting, bob);68 await addCollectionAdminExpectSuccess(alice, collectionIdForTesting, bob.address);
82 });69 });
83 });70 });
84 it('execute setSchemaVersion with image url and unique ', async () => {71 it('execute setSchemaVersion with image url and unique ', async () => {
85 await usingApi(async (api: ApiPromise) => {72 await usingApi(async (api: ApiPromise) => {
86 tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'Unique');73 tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'Unique');
87 const events = await submitTransactionAsync(bob, tx);74 const events = await submitTransactionAsync(bob, tx);
88 const result = getCreateItemResult(events);75 const result = getCreateItemResult(events);
89 const collectionInfo = await getDetailedCollectionInfo(api, collectionIdForTesting) as ICollectionInterface;76 const collectionInfo = await getDetailedCollectionInfo(api, collectionIdForTesting);
90 // tslint:disable-next-line:no-unused-expression77 // tslint:disable-next-line:no-unused-expression
91 expect(result.success).to.be.true;78 expect(result.success).to.be.true;
92 // tslint:disable-next-line:no-unused-expression79 // tslint:disable-next-line:no-unused-expression
101 tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'ImageURL');88 tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'ImageURL');
102 const events = await submitTransactionAsync(bob, tx);89 const events = await submitTransactionAsync(bob, tx);
103 const result = getCreateItemResult(events);90 const result = getCreateItemResult(events);
104 const collectionInfo = await getDetailedCollectionInfo(api, collectionIdForTesting) as ICollectionInterface;91 const collectionInfo = await getDetailedCollectionInfo(api, collectionIdForTesting);
105 // tslint:disable-next-line:no-unused-expression92 // tslint:disable-next-line:no-unused-expression
106 expect(result.success).to.be.true;93 expect(result.success).to.be.true;
107 // tslint:disable-next-line:no-unused-expression94 // tslint:disable-next-line:no-unused-expression
114101
115describe('setSchemaVersion negative', () => {102describe('setSchemaVersion negative', () => {
116 let tx;103 let tx;
104 let collectionIdForTesting: any;
117 before(async () => {105 before(async () => {
118 await usingApi(async () => {106 await usingApi(async () => {
119 const keyring = new Keyring({ type: 'sr25519' });107 const keyring = new Keyring({type: 'sr25519'});
120 alice = keyring.addFromUri('//Alice');108 alice = keyring.addFromUri('//Alice');
121 charlie = keyring.addFromUri('//Charlie');109 charlie = keyring.addFromUri('//Charlie');
110 collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});
122 });111 });
123 });112 });
124 it('execute setSchemaVersion for not exists collection', async () => {113 it('execute setSchemaVersion for not exists collection', async () => {
129 await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;118 await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;
130 });119 });
131 });120 });
132 it('execute setSchemaVersion with not correct schema version', async () => {
133 await usingApi(async (api: ApiPromise) => {
134 const consoleError = console.error;
135 console.error = () => {};
136 try {
137 tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'Test');
138 await submitTransactionAsync(alice, tx);
139 } catch (e) {
140 // tslint:disable-next-line:no-unused-expression
141 expect(e).to.be.exist;
142 } finally {
143 console.error = consoleError;
144 }
145 });
146 });
147 it('execute setSchemaVersion for deleted collection', async () => {121 it('execute setSchemaVersion for deleted collection', async () => {
148 await usingApi(async (api: ApiPromise) => {122 await usingApi(async (api: ApiPromise) => {
149 await destroyCollectionExpectSuccess(collectionIdForTesting);123 await destroyCollectionExpectSuccess(collectionIdForTesting);
modifiedtests/src/setVariableMetaData.test.tsdiffbeforeafterboth
18 setVariableMetaDataExpectSuccess,18 setVariableMetaDataExpectSuccess,
19 addCollectionAdminExpectSuccess,19 addCollectionAdminExpectSuccess,
20 setMetadataUpdatePermissionFlagExpectSuccess,20 setMetadataUpdatePermissionFlagExpectSuccess,
21 getVariableMetadata,
21} from './util/helpers';22} from './util/helpers';
2223
23chai.use(chaiAsPromised);24chai.use(chaiAsPromised);
4344
44 it('verify data was set', async () => {45 it('verify data was set', async () => {
45 await usingApi(async api => {46 await usingApi(async api => {
46 const item: any = (await api.query.nft.nftItemList(collectionId, tokenId) as any).unwrap();
47
48 expect(Array.from(item.variableData)).to.deep.equal(Array.from(data));47 expect(await getVariableMetadata(api, collectionId, tokenId)).to.deep.equal(data);
49 });48 });
50 });49 });
51});50});
64 collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });63 collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
65 tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');64 tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');
66 await setMetadataUpdatePermissionFlagExpectSuccess(alice, collectionId, 'Admin');65 await setMetadataUpdatePermissionFlagExpectSuccess(alice, collectionId, 'Admin');
67 await addCollectionAdminExpectSuccess(alice, collectionId, bob);66 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
68 });67 });
69 });68 });
7069
7473
75 it('verify data was set', async () => {74 it('verify data was set', async () => {
76 await usingApi(async api => {75 await usingApi(async api => {
77 const item: any = (await api.query.nft.nftItemList(collectionId, tokenId) as any).unwrap();
78
79 expect(Array.from(item.variableData)).to.deep.equal(Array.from(data));76 expect(await getVariableMetadata(api, collectionId, tokenId)).to.deep.equal(data);
80 });77 });
81 });78 });
82});79});
modifiedtests/src/setVariableMetadataSponsoringRateLimit.test.tsdiffbeforeafterboth

no syntactic changes

modifiedtests/src/setVariableOnChainSchema.test.tsdiffbeforeafterboth
17chai.use(chaiAsPromised);17chai.use(chaiAsPromised);
18const expect = chai.expect;18const expect = chai.expect;
1919
20let Alice: IKeyringPair;20let alice: IKeyringPair;
21let Bob: IKeyringPair;21let bob: IKeyringPair;
22let Schema: any;22let schema: any;
23let largeSchema: any;23let largeSchema: any;
2424
25before(async () => {25before(async () => {
26 await usingApi(async () => {26 await usingApi(async () => {
27 const keyring = new Keyring({ type: 'sr25519' });27 const keyring = new Keyring({type: 'sr25519'});
28 Alice = keyring.addFromUri('//Alice');28 alice = keyring.addFromUri('//Alice');
29 Bob = keyring.addFromUri('//Bob');29 bob = keyring.addFromUri('//Bob');
30 Schema = '0x31';30 schema = '0x31';
31 largeSchema = new Array(4097).fill(0xff);31 largeSchema = new Array(4097).fill(0xff);
3232
33 });33 });
37 it('Run extrinsic with parameters of the collection id, set the scheme', async () => {37 it('Run extrinsic with parameters of the collection id, set the scheme', async () => {
38 await usingApi(async (api) => {38 await usingApi(async (api) => {
39 const collectionId = await createCollectionExpectSuccess();39 const collectionId = await createCollectionExpectSuccess();
40 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();40 const collection = (await api.query.common.collectionById(collectionId)).unwrap();
41 expect(collection.owner).to.be.eq(Alice.address);41 expect(collection.owner.toString()).to.be.eq(alice.address);
42 const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema);42 const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, schema);
43 await submitTransactionAsync(Alice, setSchema);43 await submitTransactionAsync(alice, setSchema);
44 });44 });
45 });45 });
4646
47 it('Checking collection data using the setVariableOnChainSchema parameter', async () => {47 it('Checking collection data using the setVariableOnChainSchema parameter', async () => {
48 await usingApi(async (api) => {48 await usingApi(async (api) => {
49 const collectionId = await createCollectionExpectSuccess();49 const collectionId = await createCollectionExpectSuccess();
50 const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema);50 const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, schema);
51 await submitTransactionAsync(Alice, setSchema);51 await submitTransactionAsync(alice, setSchema);
52 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();52 const collection = (await api.query.common.collectionById(collectionId)).unwrap();
53 expect(collection.variableOnChainSchema.toString()).to.be.eq(Schema);53 expect(collection.variableOnChainSchema.toString()).to.be.eq(schema);
5454
55 });55 });
56 });56 });
61 it('Run extrinsic with parameters of the collection id, set the scheme', async () => {61 it('Run extrinsic with parameters of the collection id, set the scheme', async () => {
62 await usingApi(async (api) => {62 await usingApi(async (api) => {
63 const collectionId = await createCollectionExpectSuccess();63 const collectionId = await createCollectionExpectSuccess();
64 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();64 const collection = (await api.query.common.collectionById(collectionId)).unwrap();
65 expect(collection.owner).to.be.eq(Alice.address);65 expect(collection.owner.toString()).to.be.eq(alice.address);
66 await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);66 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
67 const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema);67 const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, schema);
68 await submitTransactionAsync(Bob, setSchema);68 await submitTransactionAsync(bob, setSchema);
69 });69 });
70 });70 });
7171
72 it('Checking collection data using the setVariableOnChainSchema parameter', async () => {72 it('Checking collection data using the setVariableOnChainSchema parameter', async () => {
73 await usingApi(async (api) => {73 await usingApi(async (api) => {
74 const collectionId = await createCollectionExpectSuccess();74 const collectionId = await createCollectionExpectSuccess();
75 await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);75 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
76 const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema);76 const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, schema);
77 await submitTransactionAsync(Bob, setSchema);77 await submitTransactionAsync(bob, setSchema);
78 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();78 const collection = (await api.query.common.collectionById(collectionId)).unwrap();
79 expect(collection.variableOnChainSchema.toString()).to.be.eq(Schema);79 expect(collection.variableOnChainSchema.toString()).to.be.eq(schema);
8080
81 });81 });
82 });82 });
87 it('Set a non-existent collection', async () => {87 it('Set a non-existent collection', async () => {
88 await usingApi(async (api) => {88 await usingApi(async (api) => {
89 // tslint:disable-next-line: radix89 // tslint:disable-next-line: radix
90 const collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;90 const collectionId = (await api.query.common.createdCollectionCount()).toNumber() + 1;
91 const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema);91 const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, schema);
92 await expect(submitTransactionExpectFailAsync(Alice, setSchema)).to.be.rejected;92 await expect(submitTransactionExpectFailAsync(alice, setSchema)).to.be.rejected;
93 });93 });
94 });94 });
9595
96 it('Set a previously deleted collection', async () => {96 it('Set a previously deleted collection', async () => {
97 await usingApi(async (api) => {97 await usingApi(async (api) => {
98 const collectionId = await createCollectionExpectSuccess();98 const collectionId = await createCollectionExpectSuccess();
99 await destroyCollectionExpectSuccess(collectionId);99 await destroyCollectionExpectSuccess(collectionId);
100 const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema);100 const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, schema);
101 await expect(submitTransactionExpectFailAsync(Alice, setSchema)).to.be.rejected;101 await expect(submitTransactionExpectFailAsync(alice, setSchema)).to.be.rejected;
102 });102 });
103 });103 });
104104
105 it('Set invalid data in schema (size too large:> 1024b)', async () => {105 it('Set invalid data in schema (size too large:> 1024b)', async () => {
106 await usingApi(async (api) => {106 await usingApi(async (api) => {
107 const collectionId = await createCollectionExpectSuccess();107 const collectionId = await createCollectionExpectSuccess();
108 const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, largeSchema);108 const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, largeSchema);
109 await expect(submitTransactionExpectFailAsync(Alice, setSchema)).to.be.rejected;109 await expect(submitTransactionExpectFailAsync(alice, setSchema)).to.be.rejected;
110 });110 });
111 });111 });
112112
113 it('Execute method not on behalf of the collection owner', async () => {113 it('Execute method not on behalf of the collection owner', async () => {
114 await usingApi(async (api) => {114 await usingApi(async (api) => {
115 const collectionId = await createCollectionExpectSuccess();115 const collectionId = await createCollectionExpectSuccess();
116 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();116 const collection = (await api.query.common.collectionById(collectionId)).unwrap();
117 expect(collection.owner).to.be.eq(Alice.address);117 expect(collection.owner.toString()).to.be.eq(alice.address);
118 const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema);118 const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, schema);
119 await expect(submitTransactionExpectFailAsync(Bob, setSchema)).to.be.rejected;119 await expect(submitTransactionExpectFailAsync(bob, setSchema)).to.be.rejected;
120 });120 });
121 });121 });
122122
modifiedtests/src/substrate/get-balance.tsdiffbeforeafterboth

no syntactic changes

modifiedtests/src/substrate/privateKey.tsdiffbeforeafterboth

no syntactic changes

modifiedtests/src/substrate/promisify-substrate.tsdiffbeforeafterboth

no syntactic changes

modifiedtests/src/substrate/substrate-api.tsdiffbeforeafterboth
40 const consoleLog = console.log;40 const consoleLog = console.log;
41 const consoleWarn = console.warn;41 const consoleWarn = console.warn;
4242
43 const outFn = (message: any, ...rest: any[]) => {43 const outFn = (printer: any) => (...args: any[]) => {
44 for (const arg of args) {
44 if (typeof message !== 'string') {45 if (typeof arg !== 'string')
45 consoleErr(message, ...rest);
46 return;46 continue;
47 }
48 if (!message.includes('StorageChangeSet:: WebSocket is not connected') &&47 if (arg.includes('1000:: Normal connection closure' || arg === 'Normal connection closure'))
49 !message.includes('2021-') &&
50 !message.includes('StorageChangeSet:: Normal connection closure'))
51 consoleErr(message, ...rest);48 return;
49 }
50 printer(...args);
52 };51 };
5352
54 console.error = outFn;53 console.error = outFn(consoleErr.bind(console));
55 console.log = outFn;54 console.log = outFn(consoleLog.bind(console));
56 console.warn = outFn;55 console.warn = outFn(consoleWarn.bind(console));
5756
58 try {57 try {
59 await promisifySubstrate(api, async () => {58 await promisifySubstrate(api, async () => {
119}118}
120119
121export function submitTransactionExpectFailAsync(sender: IKeyringPair, transaction: SubmittableExtrinsic<ApiTypes>): Promise<EventRecord[]> {120export function submitTransactionExpectFailAsync(sender: IKeyringPair, transaction: SubmittableExtrinsic<ApiTypes>): Promise<EventRecord[]> {
122 const consoleError = console.error;
123 const consoleLog = console.log;
124 console.error = () => {};121 console.error = () => {};
125 console.log = () => {};122 console.log = () => {};
126123
129 const resolve = (rec: EventRecord[]) => {126 const resolve = (rec: EventRecord[]) => {
130 setTimeout(() => {127 setTimeout(() => {
131 res(rec);128 res(rec);
132 console.error = consoleError;
133 console.log = consoleLog;
134 });129 });
135 };130 };
136 const reject = (errror: any) => {131 const reject = (errror: any) => {
137 setTimeout(() => {132 setTimeout(() => {
138 rej(errror);133 rej(errror);
139 console.error = consoleError;
140 console.log = consoleLog;
141 });134 });
142 };135 };
143 try {136 try {
modifiedtests/src/substrate/wait-new-blocks.tsdiffbeforeafterboth

no syntactic changes

modifiedtests/src/toggleContractWhiteList.test.tsdiffbeforeafterboth

no syntactic changes

modifiedtests/src/transfer.nload.tsdiffbeforeafterboth

no syntactic changes

modifiedtests/src/transfer.test.tsdiffbeforeafterboth
21 addCollectionAdminExpectSuccess,21 addCollectionAdminExpectSuccess,
22} from './util/helpers';22} from './util/helpers';
2323
24let Alice: IKeyringPair;24let alice: IKeyringPair;
25let Bob: IKeyringPair;25let bob: IKeyringPair;
26let Charlie: IKeyringPair;26let charlie: IKeyringPair;
2727
28describe('Integration Test Transfer(recipient, collection_id, item_id, value)', () => {28describe('Integration Test Transfer(recipient, collection_id, item_id, value)', () => {
29 it('Balance transfers and check balance', async () => {29 it('Balance transfers and check balance', async () => {
6666
67 it('User can transfer owned token', async () => {67 it('User can transfer owned token', async () => {
68 await usingApi(async () => {68 await usingApi(async () => {
69 const Alice = privateKey('//Alice');69 const alice = privateKey('//Alice');
70 const Bob = privateKey('//Bob');70 const bob = privateKey('//Bob');
71 // nft71 // nft
72 const nftCollectionId = await createCollectionExpectSuccess();72 const nftCollectionId = await createCollectionExpectSuccess();
73 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');73 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
74 await transferExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 1, 'NFT');74 await transferExpectSuccess(nftCollectionId, newNftTokenId, alice, bob, 1, 'NFT');
75 // fungible75 // fungible
76 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});76 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
77 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');77 const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');
78 await transferExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob, 1, 'Fungible');78 await transferExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob, 1, 'Fungible');
79 // reFungible79 // reFungible
80 const reFungibleCollectionId = await80 const reFungibleCollectionId = await
81 createCollectionExpectSuccess({mode: {type: 'ReFungible'}});81 createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
82 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');82 const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');
83 await transferExpectSuccess(83 await transferExpectSuccess(
84 reFungibleCollectionId,84 reFungibleCollectionId,
85 newReFungibleTokenId,85 newReFungibleTokenId,
86 Alice,86 alice,
87 Bob,87 bob,
88 100,88 100,
89 'ReFungible',89 'ReFungible',
90 );90 );
9393
94 it('Collection admin can transfer owned token', async () => {94 it('Collection admin can transfer owned token', async () => {
95 await usingApi(async () => {95 await usingApi(async () => {
96 const Alice = privateKey('//Alice');96 const alice = privateKey('//Alice');
97 const Bob = privateKey('//Bob');97 const bob = privateKey('//Bob');
98 // nft98 // nft
99 const nftCollectionId = await createCollectionExpectSuccess();99 const nftCollectionId = await createCollectionExpectSuccess();
100 await addCollectionAdminExpectSuccess(Alice, nftCollectionId, Bob);100 await addCollectionAdminExpectSuccess(alice, nftCollectionId, bob.address);
101 const newNftTokenId = await createItemExpectSuccess(Bob, nftCollectionId, 'NFT', Bob.address);101 const newNftTokenId = await createItemExpectSuccess(bob, nftCollectionId, 'NFT', bob.address);
102 await transferExpectSuccess(nftCollectionId, newNftTokenId, Bob, Alice, 1, 'NFT');102 await transferExpectSuccess(nftCollectionId, newNftTokenId, bob, alice, 1, 'NFT');
103 // fungible103 // fungible
104 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});104 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
105 await addCollectionAdminExpectSuccess(Alice, fungibleCollectionId, Bob);105 await addCollectionAdminExpectSuccess(alice, fungibleCollectionId, bob.address);
106 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible', Bob.address);106 const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible', bob.address);
107 await transferExpectSuccess(fungibleCollectionId, newFungibleTokenId, Bob, Alice, 1, 'Fungible');107 await transferExpectSuccess(fungibleCollectionId, newFungibleTokenId, bob, alice, 1, 'Fungible');
108 // reFungible108 // reFungible
109 const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});109 const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
110 await addCollectionAdminExpectSuccess(Alice, reFungibleCollectionId, Bob);110 await addCollectionAdminExpectSuccess(alice, reFungibleCollectionId, bob.address);
111 const newReFungibleTokenId = await createItemExpectSuccess(Bob, reFungibleCollectionId, 'ReFungible', Bob.address);111 const newReFungibleTokenId = await createItemExpectSuccess(bob, reFungibleCollectionId, 'ReFungible', bob.address);
112 await transferExpectSuccess(112 await transferExpectSuccess(
113 reFungibleCollectionId,113 reFungibleCollectionId,
114 newReFungibleTokenId,114 newReFungibleTokenId,
115 Bob,115 bob,
116 Alice,116 alice,
117 100,117 100,
118 'ReFungible',118 'ReFungible',
119 );119 );
124describe('Negative Integration Test Transfer(recipient, collection_id, item_id, value)', () => {124describe('Negative Integration Test Transfer(recipient, collection_id, item_id, value)', () => {
125 before(async () => {125 before(async () => {
126 await usingApi(async () => {126 await usingApi(async () => {
127 Alice = privateKey('//Alice');127 alice = privateKey('//Alice');
128 Bob = privateKey('//Bob');128 bob = privateKey('//Bob');
129 Charlie = privateKey('//Charlie');129 charlie = privateKey('//Charlie');
130 });130 });
131 });131 });
132 it('Transfer with not existed collection_id', async () => {132 it('Transfer with not existed collection_id', async () => {
133 await usingApi(async (api) => {133 await usingApi(async (api) => {
134 // nft134 // nft
135 const nftCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;135 const nftCollectionCount = (await api.query.common.createdCollectionCount()).toNumber();
136 await transferExpectFailure(nftCollectionCount + 1, 1, Alice, Bob, 1);136 await transferExpectFailure(nftCollectionCount + 1, 1, alice, bob, 1);
137 // fungible137 // fungible
138 const fungibleCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;138 const fungibleCollectionCount = (await api.query.common.createdCollectionCount()).toNumber();
139 await transferExpectFailure(fungibleCollectionCount + 1, 1, Alice, Bob, 1);139 await transferExpectFailure(fungibleCollectionCount + 1, 0, alice, bob, 1);
140 // reFungible140 // reFungible
141 const reFungibleCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;141 const reFungibleCollectionCount = (await api.query.common.createdCollectionCount()).toNumber();
142 await transferExpectFailure(reFungibleCollectionCount + 1, 1, Alice, Bob, 1);142 await transferExpectFailure(reFungibleCollectionCount + 1, 1, alice, bob, 1);
143 });143 });
144 });144 });
145 it('Transfer with deleted collection_id', async () => {145 it('Transfer with deleted collection_id', async () => {
146 // nft146 // nft
147 const nftCollectionId = await createCollectionExpectSuccess();147 const nftCollectionId = await createCollectionExpectSuccess();
148 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');148 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
149 await destroyCollectionExpectSuccess(nftCollectionId);149 await destroyCollectionExpectSuccess(nftCollectionId);
150 await transferExpectFailure(nftCollectionId, newNftTokenId, Alice, Bob, 1);150 await transferExpectFailure(nftCollectionId, newNftTokenId, alice, bob, 1);
151 // fungible151 // fungible
152 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});152 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
153 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');153 const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');
154 await destroyCollectionExpectSuccess(fungibleCollectionId);154 await destroyCollectionExpectSuccess(fungibleCollectionId);
155 await transferExpectFailure(fungibleCollectionId, newFungibleTokenId, Alice, Bob, 1);155 await transferExpectFailure(fungibleCollectionId, newFungibleTokenId, alice, bob, 1);
156 // reFungible156 // reFungible
157 const reFungibleCollectionId = await157 const reFungibleCollectionId = await
158 createCollectionExpectSuccess({mode: {type: 'ReFungible'}});158 createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
159 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');159 const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');
160 await destroyCollectionExpectSuccess(reFungibleCollectionId);160 await destroyCollectionExpectSuccess(reFungibleCollectionId);
161 await transferExpectFailure(161 await transferExpectFailure(
162 reFungibleCollectionId,162 reFungibleCollectionId,
163 newReFungibleTokenId,163 newReFungibleTokenId,
164 Alice,164 alice,
165 Bob,165 bob,
166 1,166 1,
167 );167 );
168 });168 });
169 it('Transfer with not existed item_id', async () => {169 it('Transfer with not existed item_id', async () => {
170 // nft170 // nft
171 const nftCollectionId = await createCollectionExpectSuccess();171 const nftCollectionId = await createCollectionExpectSuccess();
172 await transferExpectFailure(nftCollectionId, 2, Alice, Bob, 1);172 await transferExpectFailure(nftCollectionId, 2, alice, bob, 1);
173 // fungible173 // fungible
174 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});174 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
175 await transferExpectFailure(fungibleCollectionId, 2, Alice, Bob, 1);175 await transferExpectFailure(fungibleCollectionId, 2, alice, bob, 1);
176 // reFungible176 // reFungible
177 const reFungibleCollectionId = await177 const reFungibleCollectionId = await
178 createCollectionExpectSuccess({mode: {type: 'ReFungible'}});178 createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
179 await transferExpectFailure(179 await transferExpectFailure(
180 reFungibleCollectionId,180 reFungibleCollectionId,
181 2,181 2,
182 Alice,182 alice,
183 Bob,183 bob,
184 1,184 1,
185 );185 );
186 });186 });
187 it('Transfer with deleted item_id', async () => {187 it('Transfer with deleted item_id', async () => {
188 // nft188 // nft
189 const nftCollectionId = await createCollectionExpectSuccess();189 const nftCollectionId = await createCollectionExpectSuccess();
190 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');190 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
191 await burnItemExpectSuccess(Alice, nftCollectionId, newNftTokenId, 1);191 await burnItemExpectSuccess(alice, nftCollectionId, newNftTokenId, 1);
192 await transferExpectFailure(nftCollectionId, newNftTokenId, Alice, Bob, 1);192 await transferExpectFailure(nftCollectionId, newNftTokenId, alice, bob, 1);
193 // fungible193 // fungible
194 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});194 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
195 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');195 const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');
196 await burnItemExpectSuccess(Alice, fungibleCollectionId, newFungibleTokenId, 10);196 await burnItemExpectSuccess(alice, fungibleCollectionId, newFungibleTokenId, 10);
197 await transferExpectFailure(fungibleCollectionId, newFungibleTokenId, Alice, Bob, 1);197 await transferExpectFailure(fungibleCollectionId, newFungibleTokenId, alice, bob, 1);
198 // reFungible198 // reFungible
199 const reFungibleCollectionId = await199 const reFungibleCollectionId = await
200 createCollectionExpectSuccess({mode: {type: 'ReFungible'}});200 createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
201 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');201 const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');
202 await burnItemExpectSuccess(Alice, reFungibleCollectionId, newReFungibleTokenId, 100);202 await burnItemExpectSuccess(alice, reFungibleCollectionId, newReFungibleTokenId, 100);
203 await transferExpectFailure(203 await transferExpectFailure(
204 reFungibleCollectionId,204 reFungibleCollectionId,
205 newReFungibleTokenId,205 newReFungibleTokenId,
206 Alice,206 alice,
207 Bob,207 bob,
208 1,208 1,
209 );209 );
210 });210 });
211 it('Transfer with recipient that is not owner', async () => {211 it('Transfer with recipient that is not owner', async () => {
212 // nft212 // nft
213 const nftCollectionId = await createCollectionExpectSuccess();213 const nftCollectionId = await createCollectionExpectSuccess();
214 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');214 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
215 await transferExpectFailure(nftCollectionId, newNftTokenId, Charlie, Bob, 1);215 await transferExpectFailure(nftCollectionId, newNftTokenId, charlie, bob, 1);
216 // fungible216 // fungible
217 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});217 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
218 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');218 const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');
219 await transferExpectFailure(fungibleCollectionId, newFungibleTokenId, Charlie, Bob, 1);219 await transferExpectFailure(fungibleCollectionId, newFungibleTokenId, charlie, bob, 1);
220 // reFungible220 // reFungible
221 const reFungibleCollectionId = await221 const reFungibleCollectionId = await
222 createCollectionExpectSuccess({mode: {type: 'ReFungible'}});222 createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
223 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');223 const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');
224 await transferExpectFailure(224 await transferExpectFailure(
225 reFungibleCollectionId,225 reFungibleCollectionId,
226 newReFungibleTokenId,226 newReFungibleTokenId,
227 Charlie,227 charlie,
228 Bob,228 bob,
229 1,229 1,
230 );230 );
231 });231 });
modifiedtests/src/transferFrom.test.tsdiffbeforeafterboth
25const expect = chai.expect;25const expect = chai.expect;
2626
27describe('Integration Test transferFrom(from, recipient, collection_id, item_id, value):', () => {27describe('Integration Test transferFrom(from, recipient, collection_id, item_id, value):', () => {
28 let Alice: IKeyringPair;28 let alice: IKeyringPair;
29 let Bob: IKeyringPair;29 let bob: IKeyringPair;
30 let Charlie: IKeyringPair;30 let charlie: IKeyringPair;
3131
32 before(async () => {32 before(async () => {
33 await usingApi(async () => {33 await usingApi(async () => {
34 Alice = privateKey('//Alice');34 alice = privateKey('//Alice');
35 Bob = privateKey('//Bob');35 bob = privateKey('//Bob');
36 Charlie = privateKey('//Charlie');36 charlie = privateKey('//Charlie');
37 });37 });
38 });38 });
3939
40 it('Execute the extrinsic and check nftItemList - owner of token', async () => {40 it('Execute the extrinsic and check nftItemList - owner of token', async () => {
41 await usingApi(async () => {41 await usingApi(async () => {
42 // nft42 // nft
43 const nftCollectionId = await createCollectionExpectSuccess();43 const nftCollectionId = await createCollectionExpectSuccess();
44 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');44 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
45 await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob);45 await approveExpectSuccess(nftCollectionId, newNftTokenId, alice, bob.address);
4646
47 await transferFromExpectSuccess(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 1, 'NFT');47 await transferFromExpectSuccess(nftCollectionId, newNftTokenId, bob, alice, charlie, 1, 'NFT');
4848
49 // fungible49 // fungible
50 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});50 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
51 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');51 const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');
52 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);52 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob.address);
53 await transferFromExpectSuccess(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 1, 'Fungible');53 await transferFromExpectSuccess(fungibleCollectionId, newFungibleTokenId, bob, alice, charlie, 1, 'Fungible');
5454
55 // reFungible55 // reFungible
56 const reFungibleCollectionId = await56 const reFungibleCollectionId = await
57 createCollectionExpectSuccess({mode: {type: 'ReFungible'}});57 createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
58 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');58 const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');
59 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob, 100);59 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, alice, bob.address, 100);
60 await transferFromExpectSuccess(60 await transferFromExpectSuccess(
61 reFungibleCollectionId,61 reFungibleCollectionId,
62 newReFungibleTokenId,62 newReFungibleTokenId,
63 Bob,63 bob,
64 Alice,64 alice,
65 Charlie,65 charlie,
66 100,66 100,
67 'ReFungible',67 'ReFungible',
68 );68 );
69 });69 });
70 });70 });
7171
72 it('Should reduce allowance if value is big', async () => {72 it('Should reduce allowance if value is big', async () => {
73 await usingApi(async () => {73 await usingApi(async (api) => {
74 const alice = privateKey('//Alice');74 const alice = privateKey('//Alice');
75 const bob = privateKey('//Bob');75 const bob = privateKey('//Bob');
76 const charlie = privateKey('//Charlie');76 const charlie = privateKey('//Charlie');
79 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});79 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
80 const newFungibleTokenId = await createFungibleItemExpectSuccess(alice, fungibleCollectionId, { Value: 500000n });80 const newFungibleTokenId = await createFungibleItemExpectSuccess(alice, fungibleCollectionId, {Value: 500000n});
8181
82 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob, 500000n);82 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob.address, 500000n);
83 await transferFromExpectSuccess(fungibleCollectionId, newFungibleTokenId, bob, alice, charlie, 500000n, 'Fungible');83 await transferFromExpectSuccess(fungibleCollectionId, newFungibleTokenId, bob, alice, charlie, 500000n, 'Fungible');
84 expect((await getAllowance(fungibleCollectionId, newFungibleTokenId, alice.address, bob.address)).toString()).to.equal('0');84 expect(await getAllowance(api, fungibleCollectionId, alice.address, bob.address, newFungibleTokenId)).to.equal(0n);
85 });85 });
86 });86 });
8787
88 it('can be called by collection owner on non-owned item when OwnerCanTransfer == true', async () => {88 it('can be called by collection owner on non-owned item when OwnerCanTransfer == true', async () => {
89 const collectionId = await createCollectionExpectSuccess();89 const collectionId = await createCollectionExpectSuccess();
90 const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Bob.address);90 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', bob.address);
9191
92 await transferFromExpectSuccess(collectionId, itemId, Alice, Bob, Charlie);92 await transferFromExpectSuccess(collectionId, itemId, alice, bob, charlie);
93 });93 });
94});94});
9595
96describe('Negative Integration Test transferFrom(from, recipient, collection_id, item_id, value):', () => {96describe('Negative Integration Test transferFrom(from, recipient, collection_id, item_id, value):', () => {
97 let Alice: IKeyringPair;97 let alice: IKeyringPair;
98 let Bob: IKeyringPair;98 let bob: IKeyringPair;
99 let Charlie: IKeyringPair;99 let charlie: IKeyringPair;
100100
101 before(async () => {101 before(async () => {
102 await usingApi(async () => {102 await usingApi(async () => {
103 Alice = privateKey('//Alice');103 alice = privateKey('//Alice');
104 Bob = privateKey('//Bob');104 bob = privateKey('//Bob');
105 Charlie = privateKey('//Charlie');105 charlie = privateKey('//Charlie');
106 });106 });
107 });107 });
108108
109 it('transferFrom for a collection that does not exist', async () => {109 it('transferFrom for a collection that does not exist', async () => {
110 await usingApi(async (api: ApiPromise) => {110 await usingApi(async (api: ApiPromise) => {
111 // nft111 // nft
112 const nftCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;112 const nftCollectionCount = (await api.query.common.createdCollectionCount()).toNumber();
113 await approveExpectFail(nftCollectionCount + 1, 1, Alice, Bob);113 await approveExpectFail(nftCollectionCount + 1, 1, alice, bob);
114114
115 await transferFromExpectFail(nftCollectionCount + 1, 1, Bob, Alice, Charlie, 1);115 await transferFromExpectFail(nftCollectionCount + 1, 1, bob, alice, charlie, 1);
116116
117 // fungible117 // fungible
118 const fungibleCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;118 const fungibleCollectionCount = (await api.query.common.createdCollectionCount()).toNumber();
119 await approveExpectFail(fungibleCollectionCount + 1, 1, Alice, Bob);119 await approveExpectFail(fungibleCollectionCount + 1, 0, alice, bob);
120120
121 await transferFromExpectFail(fungibleCollectionCount + 1, 1, Bob, Alice, Charlie, 1);121 await transferFromExpectFail(fungibleCollectionCount + 1, 0, bob, alice, charlie, 1);
122 // reFungible122 // reFungible
123 const reFungibleCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;123 const reFungibleCollectionCount = (await api.query.common.createdCollectionCount()).toNumber();
124 await approveExpectFail(reFungibleCollectionCount + 1, 1, Alice, Bob);124 await approveExpectFail(reFungibleCollectionCount + 1, 1, alice, bob);
125125
126 await transferFromExpectFail(reFungibleCollectionCount + 1, 1, Bob, Alice, Charlie, 1);126 await transferFromExpectFail(reFungibleCollectionCount + 1, 1, bob, alice, charlie, 1);
127 });127 });
128 });128 });
129129
149 await usingApi(async () => {149 await usingApi(async () => {
150 // nft150 // nft
151 const nftCollectionId = await createCollectionExpectSuccess();151 const nftCollectionId = await createCollectionExpectSuccess();
152 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');152 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
153153
154 await transferFromExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 1);154 await transferFromExpectFail(nftCollectionId, newNftTokenId, bob, alice, charlie, 1);
155155
156 // fungible156 // fungible
157 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});157 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
158 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');158 const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');
159 await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 1);159 await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, bob, alice, charlie, 1);
160 // reFungible160 // reFungible
161 const reFungibleCollectionId = await161 const reFungibleCollectionId = await
162 createCollectionExpectSuccess({mode: {type: 'ReFungible'}});162 createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
163 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');163 const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');
164 await transferFromExpectFail(164 await transferFromExpectFail(
165 reFungibleCollectionId,165 reFungibleCollectionId,
166 newReFungibleTokenId,166 newReFungibleTokenId,
167 Bob,167 bob,
168 Alice,168 alice,
169 Charlie,169 charlie,
170 1,170 1,
171 );171 );
172 });172 });
176 await usingApi(async () => {176 await usingApi(async () => {
177 // nft177 // nft
178 const nftCollectionId = await createCollectionExpectSuccess();178 const nftCollectionId = await createCollectionExpectSuccess();
179 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');179 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
180 await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob);180 await approveExpectSuccess(nftCollectionId, newNftTokenId, alice, bob.address);
181181
182 await transferFromExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 2);182 await transferFromExpectFail(nftCollectionId, newNftTokenId, bob, alice, charlie, 2);
183183
184 // fungible184 // fungible
185 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});185 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
186 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');186 const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');
187 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);187 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob.address);
188 await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 2);188 await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, bob, alice, charlie, 2);
189 // reFungible189 // reFungible
190 const reFungibleCollectionId = await190 const reFungibleCollectionId = await
191 createCollectionExpectSuccess({mode: {type: 'ReFungible'}});191 createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
192 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');192 const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');
193 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);193 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, alice, bob.address);
194 await transferFromExpectFail(194 await transferFromExpectFail(
195 reFungibleCollectionId,195 reFungibleCollectionId,
196 newReFungibleTokenId,196 newReFungibleTokenId,
197 Bob,197 bob,
198 Alice,198 alice,
199 Charlie,199 charlie,
200 2,200 2,
201 );201 );
202 });202 });
203 });203 });
204204
205 it('execute transferFrom from account that is not owner of collection', async () => {205 it('execute transferFrom from account that is not owner of collection', async () => {
206 await usingApi(async () => {206 await usingApi(async () => {
207 const Dave = privateKey('//Dave');207 const dave = privateKey('//Dave');
208 // nft208 // nft
209 const nftCollectionId = await createCollectionExpectSuccess();209 const nftCollectionId = await createCollectionExpectSuccess();
210 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');210 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
211 try {211 try {
212 await approveExpectFail(nftCollectionId, newNftTokenId, Dave, Bob);212 await approveExpectFail(nftCollectionId, newNftTokenId, dave, bob);
213 await transferFromExpectFail(nftCollectionId, newNftTokenId, Dave, Alice, Charlie, 1);213 await transferFromExpectFail(nftCollectionId, newNftTokenId, dave, alice, charlie, 1);
214 } catch (e) {214 } catch (e) {
215 // tslint:disable-next-line:no-unused-expression215 // tslint:disable-next-line:no-unused-expression
216 expect(e).to.be.exist;216 expect(e).to.be.exist;
220220
221 // fungible221 // fungible
222 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});222 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
223 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');223 const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');
224 try {224 try {
225 await approveExpectFail(fungibleCollectionId, newFungibleTokenId, Dave, Bob);225 await approveExpectFail(fungibleCollectionId, newFungibleTokenId, dave, bob);
226 await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Dave, Alice, Charlie, 1);226 await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, dave, alice, charlie, 1);
227 } catch (e) {227 } catch (e) {
228 // tslint:disable-next-line:no-unused-expression228 // tslint:disable-next-line:no-unused-expression
229 expect(e).to.be.exist;229 expect(e).to.be.exist;
230 }230 }
231 // reFungible231 // reFungible
232 const reFungibleCollectionId = await232 const reFungibleCollectionId = await
233 createCollectionExpectSuccess({mode: {type: 'ReFungible'}});233 createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
234 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');234 const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');
235 try {235 try {
236 await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, Dave, Bob);236 await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, dave, bob);
237 await transferFromExpectFail(reFungibleCollectionId, newReFungibleTokenId, Dave, Alice, Charlie, 1);237 await transferFromExpectFail(reFungibleCollectionId, newReFungibleTokenId, dave, alice, charlie, 1);
238 } catch (e) {238 } catch (e) {
239 // tslint:disable-next-line:no-unused-expression239 // tslint:disable-next-line:no-unused-expression
240 expect(e).to.be.exist;240 expect(e).to.be.exist;
245 await usingApi(async () => {245 await usingApi(async () => {
246 // nft246 // nft
247 const nftCollectionId = await createCollectionExpectSuccess();247 const nftCollectionId = await createCollectionExpectSuccess();
248 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');248 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
249 await burnItemExpectSuccess(Alice, nftCollectionId, newNftTokenId, 1);249 await burnItemExpectSuccess(alice, nftCollectionId, newNftTokenId, 1);
250 await approveExpectFail(nftCollectionId, newNftTokenId, Alice, Bob);250 await approveExpectFail(nftCollectionId, newNftTokenId, alice, bob);
251 await transferFromExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 1);251 await transferFromExpectFail(nftCollectionId, newNftTokenId, bob, alice, charlie, 1);
252 });252 });
253 });253 });
254 it( 'transferFrom burnt token before approve Fungible', async () => {254 it('transferFrom burnt token before approve Fungible', async () => {
255 await usingApi(async () => {255 await usingApi(async () => {
256 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});256 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
257 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');257 const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');
258 await burnItemExpectSuccess(Alice, fungibleCollectionId, 1, 10);258 await burnItemExpectSuccess(alice, fungibleCollectionId, newFungibleTokenId, 10);
259 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);259 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob.address);
260 await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 1);260 await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, bob, alice, charlie, 1);
261261
262 });262 });
263 });263 });
264 it( 'transferFrom burnt token before approve ReFungible', async () => {264 it('transferFrom burnt token before approve ReFungible', async () => {
265 await usingApi(async () => {265 await usingApi(async () => {
266 const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});266 const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
267 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');267 const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');
268 await burnItemExpectSuccess(Alice, reFungibleCollectionId, newReFungibleTokenId, 100);268 await burnItemExpectSuccess(alice, reFungibleCollectionId, newReFungibleTokenId, 100);
269 await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);269 await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, alice, bob);
270 await transferFromExpectFail(reFungibleCollectionId, newReFungibleTokenId, Bob, Alice, Charlie, 1);270 await transferFromExpectFail(reFungibleCollectionId, newReFungibleTokenId, bob, alice, charlie, 1);
271271
272 });272 });
273 });273 });
276 await usingApi(async () => {276 await usingApi(async () => {
277 // nft277 // nft
278 const nftCollectionId = await createCollectionExpectSuccess();278 const nftCollectionId = await createCollectionExpectSuccess();
279 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');279 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
280 await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob);280 await approveExpectSuccess(nftCollectionId, newNftTokenId, alice, bob.address);
281 await burnItemExpectSuccess(Alice, nftCollectionId, newNftTokenId, 1);281 await burnItemExpectSuccess(alice, nftCollectionId, newNftTokenId, 1);
282 await transferFromExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 1);282 await transferFromExpectFail(nftCollectionId, newNftTokenId, bob, alice, charlie, 1);
283 });283 });
284 });284 });
285 it( 'transferFrom burnt token after approve Fungible', async () => {285 it('transferFrom burnt token after approve Fungible', async () => {
286 await usingApi(async () => {286 await usingApi(async () => {
287 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});287 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
288 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');288 const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');
289 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);289 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob.address);
290 await burnItemExpectSuccess(Alice, fungibleCollectionId, 1, 10);290 await burnItemExpectSuccess(alice, fungibleCollectionId, newFungibleTokenId, 10);
291 await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 1);291 await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, bob, alice, charlie, 1);
292292
293 });293 });
294 });294 });
295 it( 'transferFrom burnt token after approve ReFungible', async () => {295 it('transferFrom burnt token after approve ReFungible', async () => {
296 await usingApi(async () => {296 await usingApi(async () => {
297 const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});297 const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
298 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');298 const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');
299 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);299 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, alice, bob.address);
300 await burnItemExpectSuccess(Alice, reFungibleCollectionId, newReFungibleTokenId, 100);300 await burnItemExpectSuccess(alice, reFungibleCollectionId, newReFungibleTokenId, 100);
301 await transferFromExpectFail(reFungibleCollectionId, newReFungibleTokenId, Bob, Alice, Charlie, 1);301 await transferFromExpectFail(reFungibleCollectionId, newReFungibleTokenId, bob, alice, charlie, 1);
302302
303 });303 });
304 });304 });
305305
306 it('fails when called by collection owner on non-owned item when OwnerCanTransfer == false', async () => {306 it('fails when called by collection owner on non-owned item when OwnerCanTransfer == false', async () => {
307 const collectionId = await createCollectionExpectSuccess();307 const collectionId = await createCollectionExpectSuccess();
308 const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Bob.address);308 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', bob.address);
309 await setCollectionLimitsExpectSuccess(Alice, collectionId, { ownerCanTransfer: false });309 await setCollectionLimitsExpectSuccess(alice, collectionId, {ownerCanTransfer: false});
310310
311 await transferFromExpectFail(collectionId, itemId, Alice, Bob, Charlie);311 await transferFromExpectFail(collectionId, itemId, alice, bob, charlie);
312 });312 });
313});313});
314314
deletedtests/src/types.tsdiffbeforeafterboth

no changes

modifiedtests/src/util/contracthelpers.tsdiffbeforeafterboth
1313
14chai.use(chaiAsPromised);14chai.use(chaiAsPromised);
15const expect = chai.expect;15const expect = chai.expect;
16import { BigNumber } from 'bignumber.js';
17import { findUnusedAddress, getGenericResult } from '../util/helpers';16import {findUnusedAddress, getGenericResult} from '../util/helpers';
1817
19const value = 0;18const value = 0;
42 // Transfer balance to it41 // Transfer balance to it
43 const keyring = new Keyring({ type: 'sr25519' });42 const keyring = new Keyring({type: 'sr25519'});
44 const alice = keyring.addFromUri('//Alice');43 const alice = keyring.addFromUri('//Alice');
45 let amount = new BigNumber(endowment);44 const amount = BigInt(endowment) + 10n**15n;
46 amount = amount.plus(100e15);
47 const tx = api.tx.balances.transfer(deployer.address, amount.toFixed());45 const tx = api.tx.balances.transfer(deployer.address, amount);
48 await submitTransactionAsync(alice, tx);46 await submitTransactionAsync(alice, tx);
4947
50 return deployer;48 return deployer;
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
7import type { AccountId, EventRecord } from '@polkadot/types/interfaces';7import type {AccountId, EventRecord} from '@polkadot/types/interfaces';
8import { IKeyringPair } from '@polkadot/types/types';8import {IKeyringPair} from '@polkadot/types/types';
9import { evmToAddress } from '@polkadot/util-crypto';9import {evmToAddress} from '@polkadot/util-crypto';
10import { BigNumber } from 'bignumber.js';
11import BN from 'bn.js';10import BN from 'bn.js';
12import chai from 'chai';11import chai from 'chai';
13import chaiAsPromised from 'chai-as-promised';12import chaiAsPromised from 'chai-as-promised';
14import { alicesPublicKey } from '../accounts';13import {alicesPublicKey} from '../accounts';
14import {NftDataStructsCollection} from '../interfaces';
15import privateKey from '../substrate/privateKey';15import privateKey from '../substrate/privateKey';
16import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from '../substrate/substrate-api';16import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from '../substrate/substrate-api';
17import { ICollectionInterface } from '../types';
18import { hexToStr, strToUTF16, utf16ToStr } from './util';17import {hexToStr, strToUTF16, utf16ToStr} from './util';
1918
20chai.use(chaiAsPromised);19chai.use(chaiAsPromised);
21const expect = chai.expect;20const expect = chai.expect;
2221
23export type CrossAccountId = {22export type CrossAccountId = {
24 substrate: string,23 Substrate: string,
25} | {24} | {
26 ethereum: string,25 Ethereum: string,
27};26};
28export function normalizeAccountId(input: string | AccountId | CrossAccountId | IKeyringPair): CrossAccountId {27export function normalizeAccountId(input: string | AccountId | CrossAccountId | IKeyringPair): CrossAccountId {
29 if (typeof input === 'string')28 if (typeof input === 'string') {
29 if (input.length === 48 || input.length === 47) {
30 return { substrate: input };30 return {Substrate: input};
31 } else if (input.length === 42 && input.startsWith('0x')) {
32 return {Ethereum: input.toLowerCase()};
33 } else if (input.length === 40 && !input.startsWith('0x')) {
34 return {Ethereum: '0x' + input.toLowerCase()};
35 } else {
36 throw new Error(`Unknown address format: "${input}"`);
37 }
38 }
31 if ('address' in input) {39 if ('address' in input) {
32 return { substrate: input.address };40 return {Substrate: input.address};
33 }41 }
34 if ('ethereum' in input) {42 if ('Ethereum' in input) {
43 return {
44 Ethereum: input.Ethereum.toLowerCase(),
45 };
46 } else if ('ethereum' in input) {
47 return {
35 input.ethereum = input.ethereum.toLowerCase();48 Ethereum: (input as any).ethereum.toLowerCase(),
36 return input;49 };
37 }50 } else if ('Substrate' in input) {
38 if ('substrate' in input) {51 return input;
39 return input;52 }else if ('substrate' in input) {
40 }53 return {
54 Substrate: (input as any).substrate,
55 };
56 }
4157
42 // AccountId58 // AccountId
43 return {substrate: input.toString()};59 return {Substrate: input.toString()};
44}60}
45export function toSubstrateAddress(input: string | CrossAccountId | IKeyringPair): string {61export function toSubstrateAddress(input: string | CrossAccountId | IKeyringPair): string {
46 input = normalizeAccountId(input);62 input = normalizeAccountId(input);
47 if ('substrate' in input) {63 if ('Substrate' in input) {
48 return input.substrate;64 return input.Substrate;
49 } else {65 } else {
50 return evmToAddress(input.ethereum);66 return evmToAddress(input.Ethereum);
51 }67 }
52}68}
5369
88 owner: number[];104 owner: number[];
89}105}
90
91interface ITokenDataType {
92 owner: IKeyringPair;
93 constData: number[];
94 variableData: number[];
95}
96106
97interface IGetMessage {107interface IGetMessage {
98 checkMsgNftMethod: string;108 checkMsgNftMethod: string;
128 let checkMsgTrsMethod = '';138 let checkMsgTrsMethod = '';
129 let checkMsgSysMethod = '';139 let checkMsgSysMethod = '';
130 events.forEach(({ event: { method, section } }) => {140 events.forEach(({event: {method, section}}) => {
131 if (section === 'nft') {141 if (section === 'common') {
132 checkMsgNftMethod = method;142 checkMsgNftMethod = method;
133 } else if (section === 'treasury') {143 } else if (section === 'treasury') {
134 checkMsgTrsMethod = method;144 checkMsgTrsMethod = method;
166 // console.log(` ${phase}: ${section}.${method}:: ${data}`);176 // console.log(` ${phase}: ${section}.${method}:: ${data}`);
167 if (method == 'ExtrinsicSuccess') {177 if (method == 'ExtrinsicSuccess') {
168 success = true;178 success = true;
169 } else if ((section == 'nft') && (method == 'CollectionCreated')) {179 } else if ((section == 'common') && (method == 'CollectionCreated')) {
170 collectionId = parseInt(data[0].toString());180 collectionId = parseInt(data[0].toString(), 10);
171 }181 }
172 });182 });
173 const result: CreateCollectionResult = {183 const result: CreateCollectionResult = {
186 // console.log(` ${phase}: ${section}.${method}:: ${data}`);196 // console.log(` ${phase}: ${section}.${method}:: ${data}`);
187 if (method == 'ExtrinsicSuccess') {197 if (method == 'ExtrinsicSuccess') {
188 success = true;198 success = true;
189 } else if ((section == 'nft') && (method == 'ItemCreated')) {199 } else if ((section == 'common') && (method == 'ItemCreated')) {
190 collectionId = parseInt(data[0].toString());200 collectionId = parseInt(data[0].toString(), 10);
191 itemId = parseInt(data[1].toString());201 itemId = parseInt(data[1].toString(), 10);
192 recipient = data[2].toJSON();202 recipient = normalizeAccountId(data[2].toJSON() as any);
193 }203 }
194 });204 });
195 const result: CreateItemResult = {205 const result: CreateItemResult = {
212 events.forEach(({ event: { data, method, section } }) => {222 events.forEach(({event: {data, method, section}}) => {
213 if (method === 'ExtrinsicSuccess') {223 if (method === 'ExtrinsicSuccess') {
214 result.success = true;224 result.success = true;
215 } else if (section === 'nft' && method === 'Transfer') {225 } else if (section === 'common' && method === 'Transfer') {
216 result.collectionId = +data[0].toString();226 result.collectionId = +data[0].toString();
217 result.itemId = +data[1].toString();227 result.itemId = +data[1].toString();
218 result.sender = data[2].toJSON() as CrossAccountId;228 result.sender = normalizeAccountId(data[2].toJSON() as any);
219 result.recipient = data[3].toJSON() as CrossAccountId;229 result.recipient = normalizeAccountId(data[3].toJSON() as any);
220 result.value = BigInt(data[4].toString());230 result.value = BigInt(data[4].toString());
221 }231 }
222 });232 });
259 let collectionId = 0;269 let collectionId = 0;
260 await usingApi(async (api) => {270 await usingApi(async (api) => {
261 // Get number of collections before the transaction271 // Get number of collections before the transaction
262 const AcollectionCount = parseInt((await api.query.nft.createdCollectionCount()).toString(), 10);272 const collectionCountBefore = (await api.query.common.createdCollectionCount()).toNumber();
263273
264 // Run the CreateCollection transaction274 // Run the CreateCollection transaction
265 const alicePrivateKey = privateKey('//Alice');275 const alicePrivateKey = privateKey('//Alice');
273 modeprm = { refungible: null };283 modeprm = {refungible: null};
274 }284 }
275285
276 const tx = api.tx.nft.createCollection(strToUTF16(name), strToUTF16(description), strToUTF16(tokenPrefix), modeprm);286 const tx = api.tx.nft.createCollection(strToUTF16(name), strToUTF16(description), strToUTF16(tokenPrefix), modeprm as any);
277 const events = await submitTransactionAsync(alicePrivateKey, tx);287 const events = await submitTransactionAsync(alicePrivateKey, tx);
278 const result = getCreateCollectionResult(events);288 const result = getCreateCollectionResult(events);
279289
280 // Get number of collections after the transaction290 // Get number of collections after the transaction
281 const BcollectionCount = parseInt((await api.query.nft.createdCollectionCount()).toString(), 10);291 const collectionCountAfter = (await api.query.common.createdCollectionCount()).toNumber();
282292
283 // Get the collection293 // Get the collection
284 const collection: any = (await api.query.nft.collectionById(result.collectionId) as any).toJSON();294 const collection = (await api.query.common.collectionById(result.collectionId)).unwrap();
285295
286 // What to expect296 // What to expect
287 // tslint:disable-next-line:no-unused-expression297 // tslint:disable-next-line:no-unused-expression
288 expect(result.success).to.be.true;298 expect(result.success).to.be.true;
289 expect(result.collectionId).to.be.equal(BcollectionCount);299 expect(result.collectionId).to.be.equal(collectionCountAfter);
290 // tslint:disable-next-line:no-unused-expression300 // tslint:disable-next-line:no-unused-expression
291 expect(collection).to.be.not.null;301 expect(collection).to.be.not.null;
292 expect(BcollectionCount).to.be.equal(AcollectionCount + 1, 'Error: NFT collection NOT created.');302 expect(collectionCountAfter).to.be.equal(collectionCountBefore + 1, 'Error: NFT collection NOT created.');
293 expect(collection.owner).to.be.equal(toSubstrateAddress(alicesPublicKey));303 expect(collection.owner.toString()).to.be.equal(toSubstrateAddress(alicesPublicKey));
294 expect(utf16ToStr(collection.name)).to.be.equal(name);304 expect(utf16ToStr(collection.name.toJSON() as any)).to.be.equal(name);
295 expect(utf16ToStr(collection.description)).to.be.equal(description);305 expect(utf16ToStr(collection.description.toJSON() as any)).to.be.equal(description);
296 expect(hexToStr(collection.tokenPrefix)).to.be.equal(tokenPrefix);306 expect(hexToStr(collection.tokenPrefix.toJSON())).to.be.equal(tokenPrefix);
297307
298 collectionId = result.collectionId;308 collectionId = result.collectionId;
299 });309 });
315325
316 await usingApi(async (api) => {326 await usingApi(async (api) => {
317 // Get number of collections before the transaction327 // Get number of collections before the transaction
318 const AcollectionCount = parseInt((await api.query.nft.createdCollectionCount()).toString());328 const collectionCountBefore = (await api.query.common.createdCollectionCount()).toNumber();
319329
320 // Run the CreateCollection transaction330 // Run the CreateCollection transaction
321 const alicePrivateKey = privateKey('//Alice');331 const alicePrivateKey = privateKey('//Alice');
322 const tx = api.tx.nft.createCollection(strToUTF16(name), strToUTF16(description), strToUTF16(tokenPrefix), modeprm);332 const tx = api.tx.nft.createCollection(strToUTF16(name), strToUTF16(description), strToUTF16(tokenPrefix), modeprm as any);
323 const events = await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;333 const events = await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;
324 const result = getCreateCollectionResult(events);334 const result = getCreateCollectionResult(events);
325335
326 // Get number of collections after the transaction336 // Get number of collections after the transaction
327 const BcollectionCount = parseInt((await api.query.nft.createdCollectionCount()).toString());337 const collectionCountAfter = (await api.query.common.createdCollectionCount()).toNumber();
328338
329 // What to expect339 // What to expect
330 // tslint:disable-next-line:no-unused-expression340 // tslint:disable-next-line:no-unused-expression
331 expect(result.success).to.be.false;341 expect(result.success).to.be.false;
332 expect(BcollectionCount).to.be.equal(AcollectionCount, 'Error: Collection with incorrect data created.');342 expect(collectionCountAfter).to.be.equal(collectionCountBefore, 'Error: Collection with incorrect data created.');
333 });343 });
334}344}
335345
336export async function findUnusedAddress(api: ApiPromise, seedAddition = ''): Promise<IKeyringPair> {346export async function findUnusedAddress(api: ApiPromise, seedAddition = ''): Promise<IKeyringPair> {
337 let bal = new BigNumber(0);347 let bal = 0n;
338 let unused;348 let unused;
339 do {349 do {
340 const randomSeed = 'seed' + Math.floor(Math.random() * Math.floor(10000)) + seedAddition;350 const randomSeed = 'seed' + Math.floor(Math.random() * Math.floor(10000)) + seedAddition;
341 const keyring = new Keyring({ type: 'sr25519' });351 const keyring = new Keyring({type: 'sr25519'});
342 unused = keyring.addFromUri(`//${randomSeed}`);352 unused = keyring.addFromUri(`//${randomSeed}`);
343 bal = new BigNumber((await api.query.system.account(unused.address)).data.free.toString());353 bal = (await api.query.system.account(unused.address)).data.free.toBigInt();
344 } while (bal.toFixed() != '0');354 } while (bal !== 0n);
345 return unused;355 return unused;
346}356}
347357
348export async function getAllowance(collectionId: number, tokenId: number, owner: string, approved: string) {358export async function getAllowance(api: ApiPromise, collectionId: number, owner: CrossAccountId | string, approved: CrossAccountId | string, tokenId: number) {
349 return await usingApi(async (api) => {359 return (await api.rpc.nft.allowance(collectionId, normalizeAccountId(owner), normalizeAccountId(approved), tokenId)).toBigInt();
350 const bn = await api.query.nft.allowances(collectionId, [tokenId, owner, approved]) as unknown as BN;
351 return BigInt(bn.toString());
352 });
353}360}
354361
355export function findUnusedAddresses(api: ApiPromise, amount: number): Promise<IKeyringPair[]> {362export function findUnusedAddresses(api: ApiPromise, amount: number): Promise<IKeyringPair[]> {
356 return Promise.all(new Array(amount).fill(null).map(() => findUnusedAddress(api, '_' + Date.now())));363 return Promise.all(new Array(amount).fill(null).map(() => findUnusedAddress(api, '_' + Date.now())));
357}364}
358365
359export async function findNotExistingCollection(api: ApiPromise): Promise<number> {366export async function findNotExistingCollection(api: ApiPromise): Promise<number> {
360 const totalNumber = parseInt((await api.query.nft.createdCollectionCount()).toString(), 10) as unknown as number;367 const totalNumber = (await api.query.common.createdCollectionCount()).toNumber();
361 const newCollection: number = totalNumber + 1;368 const newCollection: number = totalNumber + 1;
362 return newCollection;369 return newCollection;
363}370}
389 const events = await submitTransactionAsync(alicePrivateKey, tx);396 const events = await submitTransactionAsync(alicePrivateKey, tx);
390 const result = getDestroyResult(events);397 const result = getDestroyResult(events);
391
392 // Get the collection
393 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
394
395 // What to expect
396 expect(result).to.be.true;398 expect(result).to.be.true;
399
400 // What to expect
397 expect(collection).to.be.null;401 expect((await api.query.common.collectionById(collectionId)).isNone).to.be.true;
398 });402 });
399}403}
400
401export async function queryCollectionLimits(collectionId: number) {
402 return await usingApi(async (api) => {
403 return ((await api.query.nft.collectionById(collectionId)).toJSON() as any).limits;
404 });
405}
406404
407export async function setCollectionLimitsExpectSuccess(sender: IKeyringPair, collectionId: number, limits: any) {405export async function setCollectionLimitsExpectSuccess(sender: IKeyringPair, collectionId: number, limits: any) {
408 await usingApi(async (api) => {406 await usingApi(async (api) => {
409 const oldLimits = await queryCollectionLimits(collectionId);
410 const newLimits = { ...oldLimits as any, ...limits };
411 const tx = api.tx.nft.setCollectionLimits(collectionId, newLimits);407 const tx = api.tx.nft.setCollectionLimits(collectionId, limits);
412 const events = await submitTransactionAsync(sender, tx);408 const events = await submitTransactionAsync(sender, tx);
413 const result = getGenericResult(events);409 const result = getGenericResult(events);
414410
418414
419export async function setCollectionLimitsExpectFailure(sender: IKeyringPair, collectionId: number, limits: any) {415export async function setCollectionLimitsExpectFailure(sender: IKeyringPair, collectionId: number, limits: any) {
420 await usingApi(async (api) => {416 await usingApi(async (api) => {
421 const oldLimits = await queryCollectionLimits(collectionId);
422 const newLimits = { ...oldLimits as any, ...limits };
423 const tx = api.tx.nft.setCollectionLimits(collectionId, newLimits);417 const tx = api.tx.nft.setCollectionLimits(collectionId, limits);
424 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;418 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;
425 const result = getGenericResult(events);419 const result = getGenericResult(events);
426420
438 const result = getGenericResult(events);432 const result = getGenericResult(events);
439433
440 // Get the collection434 // Get the collection
441 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();435 const collection = (await api.query.common.collectionById(collectionId)).unwrap();
442436
443 // What to expect437 // What to expect
444 expect(result.success).to.be.true;438 expect(result.success).to.be.true;
445 expect(collection.sponsorship).to.deep.equal({439 expect(collection.sponsorship.toJSON()).to.deep.equal({
446 unconfirmed: sponsor,440 unconfirmed: sponsor,
447 });441 });
448 });442 });
458 const result = getGenericResult(events);452 const result = getGenericResult(events);
459453
460 // Get the collection454 // Get the collection
461 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();455 const collection = (await api.query.common.collectionById(collectionId)).unwrap();
462456
463 // What to expect457 // What to expect
464 expect(result.success).to.be.true;458 expect(result.success).to.be.true;
465 expect(collection.sponsorship).to.be.deep.equal({ disabled: null });459 expect(collection.sponsorship.toJSON()).to.be.deep.equal({disabled: null});
466 });460 });
467}461}
468462
496 const result = getGenericResult(events);490 const result = getGenericResult(events);
497491
498 // Get the collection492 // Get the collection
499 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();493 const collection = (await api.query.common.collectionById(collectionId)).unwrap();
500494
501 // What to expect495 // What to expect
502 expect(result.success).to.be.true;496 expect(result.success).to.be.true;
503 expect(collection.sponsorship).to.be.deep.equal({497 expect(collection.sponsorship.toJSON()).to.be.deep.equal({
504 confirmed: sender.address,498 confirmed: sender.address,
505 });499 });
506 });500 });
520export async function setMetadataUpdatePermissionFlagExpectSuccess(sender: IKeyringPair, collectionId: number, flag: string) {514export async function setMetadataUpdatePermissionFlagExpectSuccess(sender: IKeyringPair, collectionId: number, flag: string) {
521515
522 await usingApi(async (api) => {516 await usingApi(async (api) => {
523 const tx = api.tx.nft.setMetaUpdatePermissionFlag(collectionId, flag);517 const tx = api.tx.nft.setMetaUpdatePermissionFlag(collectionId, flag as any);
524 const events = await submitTransactionAsync(sender, tx);518 const events = await submitTransactionAsync(sender, tx);
525 const result = getGenericResult(events);519 const result = getGenericResult(events);
526520
531export async function setMetadataUpdatePermissionFlagExpectFailure(sender: IKeyringPair, collectionId: number, flag: string) {525export async function setMetadataUpdatePermissionFlagExpectFailure(sender: IKeyringPair, collectionId: number, flag: string) {
532526
533 await usingApi(async (api) => {527 await usingApi(async (api) => {
534 const tx = api.tx.nft.setMetaUpdatePermissionFlag(collectionId, flag);528 const tx = api.tx.nft.setMetaUpdatePermissionFlag(collectionId, flag as any);
535 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;529 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;
536 const result = getGenericResult(events);530 const result = getGenericResult(events);
537531
702696
703export async function burnItemExpectSuccess(sender: IKeyringPair, collectionId: number, tokenId: number, value = 1) {697export async function burnItemExpectSuccess(sender: IKeyringPair, collectionId: number, tokenId: number, value = 1) {
704 await usingApi(async (api) => {698 await usingApi(async (api) => {
699 const balanceBefore = await getBalance(api, collectionId, normalizeAccountId(sender), tokenId);
700 // if burning token by admin - use adminButnItemExpectSuccess
701 expect(balanceBefore >= BigInt(value)).to.be.true;
702
705 const tx = api.tx.nft.burnItem(collectionId, tokenId, value);703 const tx = api.tx.nft.burnItem(collectionId, tokenId, value);
706 const events = await submitTransactionAsync(sender, tx);704 const events = await submitTransactionAsync(sender, tx);
707 const result = getGenericResult(events);705 const result = getGenericResult(events);
708 // Get the item
709 const item: any = (await api.query.nft.nftItemList(collectionId, tokenId)).toJSON();
710 // What to expect
711 // tslint:disable-next-line:no-unused-expression
712 expect(result.success).to.be.true;706 expect(result.success).to.be.true;
713 // tslint:disable-next-line:no-unused-expression707
708 const balanceAfter = await getBalance(api, collectionId, normalizeAccountId(sender), tokenId);
714 expect(item).to.be.null;709 expect(balanceAfter + BigInt(value)).to.be.equal(balanceBefore);
715 });710 });
716}711}
717712
718export async function713export async function
719approveExpectSuccess(714approveExpectSuccess(
720 collectionId: number,715 collectionId: number,
721 tokenId: number, owner: IKeyringPair, approved: IKeyringPair | CrossAccountId | string, amount: number | bigint = 1,716 tokenId: number, owner: IKeyringPair, approved: CrossAccountId | string, amount: number | bigint = 1,
722) {717) {
723 await usingApi(async (api: ApiPromise) => {718 await usingApi(async (api: ApiPromise) => {
724 approved = normalizeAccountId(approved);
725 const allowanceBefore =
726 await api.query.nft.allowances(collectionId, [tokenId, owner.address, toSubstrateAddress(approved)]) as unknown as BN;
727 const approveNftTx = api.tx.nft.approve(approved, collectionId, tokenId, amount);719 const approveNftTx = api.tx.nft.approve(normalizeAccountId(approved), collectionId, tokenId, amount);
728 const events = await submitTransactionAsync(owner, approveNftTx);720 const events = await submitTransactionAsync(owner, approveNftTx);
729 const result = getCreateItemResult(events);721 const result = getGenericResult(events);
730 // tslint:disable-next-line:no-unused-expression
731 expect(result.success).to.be.true;722 expect(result.success).to.be.true;
732 const allowanceAfter =723
733 await api.query.nft.allowances(collectionId, [tokenId, owner.address, toSubstrateAddress(approved)]) as unknown as BN;
734 expect(allowanceAfter.sub(allowanceBefore).toString()).to.be.equal(amount.toString());724 expect(await getAllowance(api, collectionId, owner.address, approved, tokenId)).to.be.equal(BigInt(amount));
735 });725 });
736}726}
727
728export async function adminApproveFromExpectSuccess(
729 collectionId: number,
730 tokenId: number, admin: IKeyringPair, owner: CrossAccountId | string, approved: CrossAccountId | string, amount: number | bigint = 1,
731) {
732 await usingApi(async (api: ApiPromise) => {
733 const approveNftTx = api.tx.nft.approve(normalizeAccountId(approved), collectionId, tokenId, amount);
734 const events = await submitTransactionAsync(admin, approveNftTx);
735 const result = getGenericResult(events);
736 expect(result.success).to.be.true;
737
738 expect(await getAllowance(api, collectionId, owner, approved, tokenId)).to.be.equal(BigInt(amount));
739 });
740}
737741
738export async function742export async function
739transferFromExpectSuccess(743transferFromExpectSuccess(
747) {751) {
748 await usingApi(async (api: ApiPromise) => {752 await usingApi(async (api: ApiPromise) => {
749 const to = normalizeAccountId(accountTo);753 const to = normalizeAccountId(accountTo);
750 let balanceBefore = new BN(0);754 let balanceBefore = 0n;
751 if (type === 'Fungible') {755 if (type === 'Fungible') {
752 balanceBefore = await api.query.nft.balance(collectionId, toSubstrateAddress(to)) as unknown as BN;756 balanceBefore = await getBalance(api, collectionId, to, tokenId);
753 }757 }
754 const transferFromTx = api.tx.nft.transferFrom(normalizeAccountId(accountFrom), to, collectionId, tokenId, value);758 const transferFromTx = api.tx.nft.transferFrom(normalizeAccountId(accountFrom), to, collectionId, tokenId, value);
755 const events = await submitTransactionAsync(accountApproved, transferFromTx);759 const events = await submitTransactionAsync(accountApproved, transferFromTx);
756 const result = getCreateItemResult(events);760 const result = getCreateItemResult(events);
757 // tslint:disable-next-line:no-unused-expression761 // tslint:disable-next-line:no-unused-expression
758 expect(result.success).to.be.true;762 expect(result.success).to.be.true;
759 if (type === 'NFT') {763 if (type === 'NFT') {
760 const nftItemData = (await api.query.nft.nftItemList(collectionId, tokenId) as any).toJSON() as ITokenDataType;
761 expect(nftItemData.owner).to.be.deep.equal(to);764 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal(to);
762 }765 }
763 if (type === 'Fungible') {766 if (type === 'Fungible') {
764 const balanceAfter = (await api.query.nft.fungibleItemList(collectionId, toSubstrateAddress(to)) as any).value as unknown as BN;767 const balanceAfter = await getBalance(api, collectionId, to, tokenId);
765 expect(balanceAfter.sub(balanceBefore).toString()).to.be.equal(value.toString());768 expect(balanceAfter - balanceBefore).to.be.equal(BigInt(value));
766 }769 }
767 if (type === 'ReFungible') {770 if (type === 'ReFungible') {
768 const nftItemData =
769 (await api.query.nft.reFungibleItemList(collectionId, tokenId) as any).toJSON() as IReFungibleTokenDataType;
770 expect(nftItemData.owner[0].owner).to.be.deep.equal(normalizeAccountId(to));
771 expect(nftItemData.owner[0].fraction).to.be.equal(value);771 expect(await getBalance(api, collectionId, to, tokenId)).to.be.equal(BigInt(value));
772 }772 }
773 });773 });
774}774}
801 });801 });
802}802}
803803
804export async function addCollectionAdminExpectSuccess(sender: IKeyringPair, collectionId: number, address: IKeyringPair) {804export async function addCollectionAdminExpectSuccess(sender: IKeyringPair, collectionId: number, address: string | CrossAccountId) {
805 await usingApi(async (api) => {805 await usingApi(async (api) => {
806 const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(address.address));806 const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(address));
807 const events = await submitTransactionAsync(sender, changeAdminTx);807 const events = await submitTransactionAsync(sender, changeAdminTx);
808 const result = getCreateCollectionResult(events);808 const result = getCreateCollectionResult(events);
809 expect(result.success).to.be.true;809 expect(result.success).to.be.true;
828 sender: IKeyringPair,828 sender: IKeyringPair,
829 recipient: IKeyringPair,829 recipient: IKeyringPair,
830 value: number | bigint = 1,830 value: number | bigint = 1,
831 blockTimeMs: number,
832 blockSchedule: number,831 blockSchedule: number,
833) {832) {
834 await usingApi(async (api: ApiPromise) => {833 await usingApi(async (api: ApiPromise) => {
835 const blockNumber: number | undefined = await getBlockNumber(api);834 const blockNumber: number | undefined = await getBlockNumber(api);
836 const expectedBlockNumber = blockNumber + blockSchedule;835 const expectedBlockNumber = blockNumber + blockSchedule;
837836
838 expect(blockNumber).to.be.greaterThan(0);837 expect(blockNumber).to.be.greaterThan(0);
839 const transferTx = await api.tx.nft.transfer(normalizeAccountId(recipient.address), collectionId, tokenId, value);838 const transferTx = api.tx.nft.transfer(normalizeAccountId(recipient.address), collectionId, tokenId, value);
840 const scheduleTx = await api.tx.scheduler.schedule(expectedBlockNumber, null, 0, transferTx);839 const scheduleTx = api.tx.scheduler.schedule(expectedBlockNumber, null, 0, transferTx as any);
841840
842 await submitTransactionAsync(sender, scheduleTx);841 await submitTransactionAsync(sender, scheduleTx);
843842
844 const recipientBalanceBefore = new BigNumber((await api.query.system.account(recipient.address)).data.free.toString());843 const recipientBalanceBefore = (await api.query.system.account(recipient.address)).data.free.toBigInt();
845844
846 const nftItemDataBefore = (await api.query.nft.nftItemList(collectionId, tokenId)).toJSON() as any as ITokenDataType;
847 expect(toSubstrateAddress(nftItemDataBefore.owner)).to.be.equal(sender.address);845 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal(normalizeAccountId(sender.address));
848846
849 // sleep for 4 blocks847 // sleep for 4 blocks
850 await new Promise(resolve => setTimeout(resolve, blockTimeMs * (blockSchedule + 1)));848 await waitNewBlocks(blockSchedule + 1);
851849
852 const recipientBalanceAfter = new BigNumber((await api.query.system.account(recipient.address)).data.free.toString());850 const recipientBalanceAfter = (await api.query.system.account(recipient.address)).data.free.toBigInt();
853851
854 const nftItemData = (await api.query.nft.nftItemList(collectionId, tokenId)).toJSON() as unknown as ITokenDataType;
855 expect(toSubstrateAddress(nftItemData.owner)).to.be.equal(recipient.address);852 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal(normalizeAccountId(recipient.address));
856 expect(recipientBalanceAfter.toNumber()).to.be.equal(recipientBalanceBefore.toNumber());853 expect(recipientBalanceAfter).to.be.equal(recipientBalanceBefore);
857 });854 });
858}855}
859856
870 await usingApi(async (api: ApiPromise) => {867 await usingApi(async (api: ApiPromise) => {
871 const to = normalizeAccountId(recipient);868 const to = normalizeAccountId(recipient);
872869
873 let balanceBefore = new BN(0);870 let balanceBefore = 0n;
874 if (type === 'Fungible') {871 if (type === 'Fungible') {
875 balanceBefore = await api.query.nft.balance(collectionId, toSubstrateAddress(to)) as unknown as BN;872 balanceBefore = await getBalance(api, collectionId, to, tokenId);
876 }873 }
877 const transferTx = api.tx.nft.transfer(to, collectionId, tokenId, value);874 const transferTx = api.tx.nft.transfer(to, collectionId, tokenId, value);
878 const events = await submitTransactionAsync(sender, transferTx);875 const events = await submitTransactionAsync(sender, transferTx);
883 expect(result.itemId).to.be.equal(tokenId);880 expect(result.itemId).to.be.equal(tokenId);
884 expect(result.sender).to.be.deep.equal(normalizeAccountId(sender.address));881 expect(result.sender).to.be.deep.equal(normalizeAccountId(sender.address));
885 expect(result.recipient).to.be.deep.equal(to);882 expect(result.recipient).to.be.deep.equal(to);
886 expect(result.value.toString()).to.be.equal(value.toString());883 expect(result.value).to.be.equal(BigInt(value));
887 if (type === 'NFT') {884 if (type === 'NFT') {
888 const nftItemData = (await api.query.nft.nftItemList(collectionId, tokenId)).toJSON() as unknown as ITokenDataType;
889 expect(nftItemData.owner).to.be.deep.equal(to);885 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal(to);
890 }886 }
891 if (type === 'Fungible') {887 if (type === 'Fungible') {
892 const balanceAfter = (await api.query.nft.fungibleItemList(collectionId, toSubstrateAddress(to)) as any).value as unknown as BN;888 const balanceAfter = await getBalance(api, collectionId, to, tokenId);
893 expect(balanceAfter.sub(balanceBefore).toString()).to.be.equal(value.toString());889 expect(balanceAfter - balanceBefore).to.be.equal(BigInt(value));
894 }890 }
895 if (type === 'ReFungible') {891 if (type === 'ReFungible') {
896 const nftItemData =
897 (await api.query.nft.reFungibleItemList(collectionId, tokenId)).toJSON() as unknown as IReFungibleTokenDataType;892 expect(await getBalance(api, collectionId, to, tokenId) >= value).to.be.true;
898 const expectedOwner = toSubstrateAddress(to);
899 const ownerIndex = nftItemData.owner.findIndex(v => toSubstrateAddress(v.owner as any as string) == expectedOwner);
900 expect(ownerIndex).to.not.equal(-1);
901 expect(nftItemData.owner[ownerIndex].owner).to.be.deep.equal(normalizeAccountId(to));
902 expect(nftItemData.owner[ownerIndex].fraction).to.be.greaterThanOrEqual(value as number);
903 }893 }
904 });894 });
905}895}
937 });927 });
938}928}
939929
930export async function getBalance(
931 api: ApiPromise,
932 collectionId: number,
933 owner: string | CrossAccountId,
934 token: number,
935): Promise<bigint> {
936 return (await api.rpc.nft.balance(collectionId, normalizeAccountId(owner), token)).toBigInt();
937}
940export async function getFungibleBalance(938export async function getTokenOwner(
939 api: ApiPromise,
941 collectionId: number,940 collectionId: number,
942 owner: string,941 token: number,
943) {942): Promise<CrossAccountId> {
944 return await usingApi(async (api) => {943 return normalizeAccountId((await api.rpc.nft.tokenOwner(collectionId, token)).toJSON() as any);
945 const response = (await api.query.nft.fungibleItemList(collectionId, owner)).toJSON() as unknown as { value: string };
946 return BigInt(response.value);
947 });
948}944}
945export async function isTokenExists(
946 api: ApiPromise,
947 collectionId: number,
948 token: number,
949): Promise<boolean> {
950 return (await api.rpc.nft.tokenExists(collectionId, token)).toJSON();
951}
952export async function getLastTokenId(
953 api: ApiPromise,
954 collectionId: number,
955): Promise<number> {
956 return (await api.rpc.nft.lastTokenId(collectionId)).toJSON();
957}
958export async function getAdminList(
959 api: ApiPromise,
960 collectionId: number,
961): Promise<string[]> {
962 return (await api.rpc.nft.adminlist(collectionId)).toHuman() as any;
963}
964export async function getVariableMetadata(
965 api: ApiPromise,
966 collectionId: number,
967 tokenId: number,
968): Promise<number[]> {
969 return [...(await api.rpc.nft.variableMetadata(collectionId, tokenId))];
970}
971export async function getConstMetadata(
972 api: ApiPromise,
973 collectionId: number,
974 tokenId: number,
975): Promise<number[]> {
976 return [...(await api.rpc.nft.constMetadata(collectionId, tokenId))];
977}
949978
950export async function createFungibleItemExpectSuccess(979export async function createFungibleItemExpectSuccess(
951 sender: IKeyringPair,980 sender: IKeyringPair,
968 let newItemId = 0;997 let newItemId = 0;
969 await usingApi(async (api) => {998 await usingApi(async (api) => {
970 const to = normalizeAccountId(owner);999 const to = normalizeAccountId(owner);
971 const AItemCount = parseInt((await api.query.nft.itemListIndex(collectionId)).toString(), 10);1000 const itemCountBefore = await getLastTokenId(api, collectionId);
972 const Aitem: any = (await api.query.nft.fungibleItemList(collectionId, toSubstrateAddress(to))).toJSON();1001 const itemBalanceBefore = await getBalance(api, collectionId, to, newItemId);
973 const AItemBalance = new BigNumber(Aitem.value);
9741002
975 let tx;1003 let tx;
976 if (createMode === 'Fungible') {1004 if (createMode === 'Fungible') {
977 const createData = { fungible: { value: 10 } };1005 const createData = {fungible: {value: 10}};
978 tx = api.tx.nft.createItem(collectionId, to, createData);1006 tx = api.tx.nft.createItem(collectionId, to, createData as any);
979 } else if (createMode === 'ReFungible') {1007 } else if (createMode === 'ReFungible') {
980 const createData = { refungible: { const_data: [], variable_data: [], pieces: 100 } };1008 const createData = {refungible: {const_data: [], variable_data: [], pieces: 100}};
981 tx = api.tx.nft.createItem(collectionId, to, createData);1009 tx = api.tx.nft.createItem(collectionId, to, createData as any);
982 } else {1010 } else {
983 const createData = { nft: { const_data: [], variable_data: [] } };1011 const createData = {nft: {const_data: [], variable_data: []}};
984 tx = api.tx.nft.createItem(collectionId, to, createData);1012 tx = api.tx.nft.createItem(collectionId, to, createData as any);
985 }1013 }
9861014
987 const events = await submitTransactionAsync(sender, tx);1015 const events = await submitTransactionAsync(sender, tx);
988 const result = getCreateItemResult(events);1016 const result = getCreateItemResult(events);
9891017
990 const BItemCount = parseInt((await api.query.nft.itemListIndex(collectionId)).toString(), 10);1018 const itemCountAfter = await getLastTokenId(api, collectionId);
991 const Bitem: any = (await api.query.nft.fungibleItemList(collectionId, toSubstrateAddress(to))).toJSON();1019 const itemBalanceAfter = await getBalance(api, collectionId, to, newItemId);
992 const BItemBalance = new BigNumber(Bitem.value);
9931020
994 // What to expect1021 // What to expect
995 // tslint:disable-next-line:no-unused-expression1022 // tslint:disable-next-line:no-unused-expression
996 expect(result.success).to.be.true;1023 expect(result.success).to.be.true;
997 if (createMode === 'Fungible') {1024 if (createMode === 'Fungible') {
998 expect(BItemBalance.minus(AItemBalance).toNumber()).to.be.equal(10);1025 expect(itemBalanceAfter - itemBalanceBefore).to.be.equal(10n);
999 } else {1026 } else {
1000 expect(BItemCount).to.be.equal(AItemCount + 1);1027 expect(itemCountAfter).to.be.equal(itemCountBefore + 1);
1001 }1028 }
1002 expect(collectionId).to.be.equal(result.collectionId);1029 expect(collectionId).to.be.equal(result.collectionId);
1003 expect(BItemCount.toString()).to.be.equal(result.itemId.toString());1030 expect(itemCountAfter.toString()).to.be.equal(result.itemId.toString());
1004 expect(to).to.be.deep.equal(result.recipient);1031 expect(to).to.be.deep.equal(result.recipient);
1005 newItemId = result.itemId;1032 newItemId = result.itemId;
1006 });1033 });
1030 const result = getGenericResult(events);1057 const result = getGenericResult(events);
10311058
1032 // Get the collection1059 // Get the collection
1033 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();1060 const collection = (await api.query.common.collectionById(collectionId)).unwrap();
10341061
1035 // What to expect1062 // What to expect
1036 // tslint:disable-next-line:no-unused-expression1063 // tslint:disable-next-line:no-unused-expression
1037 expect(result.success).to.be.true;1064 expect(result.success).to.be.true;
1038 expect(collection.access).to.be.equal(accessMode);1065 expect(collection.access.toHuman()).to.be.equal(accessMode);
1039 });1066 });
1040}1067}
10411068
1075 const tx = api.tx.nft.setMintPermission(collectionId, enabled);1102 const tx = api.tx.nft.setMintPermission(collectionId, enabled);
1076 const events = await submitTransactionAsync(sender, tx);1103 const events = await submitTransactionAsync(sender, tx);
1077 const result = getGenericResult(events);1104 const result = getGenericResult(events);
1105 expect(result.success).to.be.true;
10781106
1079 // Get the collection1107 // Get the collection
1080 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();1108 const collection = (await api.query.common.collectionById(collectionId)).unwrap();
10811109
1082 // What to expect
1083 // tslint:disable-next-line:no-unused-expression
1084 expect(result.success).to.be.true;
1085 expect(collection.mintMode).to.be.equal(enabled);1110 expect(collection.mintMode.toHuman()).to.be.equal(enabled);
1086 });1111 });
1087}1112}
10881113
1112 });1137 });
1113}1138}
11141139
1115export async function isWhitelisted(collectionId: number, address: string) {1140export async function isWhitelisted(collectionId: number, address: string | CrossAccountId) {
1116 let whitelisted = false;
1117 await usingApi(async (api) => {1141 return await usingApi(async (api) => {
1118 whitelisted = (await api.query.nft.whiteList(collectionId, address)).toJSON() as unknown as boolean;1142 return (await api.query.common.allowlist(collectionId, normalizeAccountId(address))).toJSON();
1119 });1143 });
1120 return whitelisted;
1121}1144}
11221145
1123export async function addToWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number, address: string | AccountId) {1146export async function addToWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number, address: string | AccountId | CrossAccountId) {
1124 await usingApi(async (api) => {1147 await usingApi(async (api) => {
1125
1126 const whiteListedBefore = (await api.query.nft.whiteList(collectionId, address)).toJSON();1148 expect(await isWhitelisted(collectionId, normalizeAccountId(address))).to.be.false;
11271149
1128 // Run the transaction1150 // Run the transaction
1129 const tx = api.tx.nft.addToWhiteList(collectionId, normalizeAccountId(address));1151 const tx = api.tx.nft.addToWhiteList(collectionId, normalizeAccountId(address));
1130 const events = await submitTransactionAsync(sender, tx);1152 const events = await submitTransactionAsync(sender, tx);
1131 const result = getGenericResult(events);1153 const result = getGenericResult(events);
1132
1133 const whiteListedAfter = (await api.query.nft.whiteList(collectionId, address)).toJSON();
1134
1135 // What to expect
1136 // tslint:disable-next-line:no-unused-expression
1137 expect(result.success).to.be.true;1154 expect(result.success).to.be.true;
1138 // tslint:disable-next-line: no-unused-expression1155
1139 expect(whiteListedBefore).to.be.false;
1140 // tslint:disable-next-line: no-unused-expression
1141 expect(whiteListedAfter).to.be.true;1156 expect(await isWhitelisted(collectionId, normalizeAccountId(address))).to.be.true;
1142 });1157 });
1143}1158}
11441159
1145export async function addToWhiteListAgainExpectSuccess(sender: IKeyringPair, collectionId: number, address: string | AccountId) {1160export async function addToWhiteListAgainExpectSuccess(sender: IKeyringPair, collectionId: number, address: string | AccountId) {
1146 await usingApi(async (api) => {1161 await usingApi(async (api) => {
11471162
1148 const whiteListedBefore = (await api.query.nft.whiteList(collectionId, address)).toJSON();1163 expect(await isWhitelisted(collectionId, normalizeAccountId(address))).to.be.true;
11491164
1150 // Run the transaction1165 // Run the transaction
1151 const tx = api.tx.nft.addToWhiteList(collectionId, normalizeAccountId(address));1166 const tx = api.tx.nft.addToWhiteList(collectionId, normalizeAccountId(address));
1152 const events = await submitTransactionAsync(sender, tx);1167 const events = await submitTransactionAsync(sender, tx);
1153 const result = getGenericResult(events);1168 const result = getGenericResult(events);
1154
1155 const whiteListedAfter = (await api.query.nft.whiteList(collectionId, address)).toJSON();
1156
1157 // What to expect
1158 // tslint:disable-next-line:no-unused-expression
1159 expect(result.success).to.be.true;1169 expect(result.success).to.be.true;
1160 // tslint:disable-next-line: no-unused-expression1170
1161 expect(whiteListedBefore).to.be.true;1171 expect(await isWhitelisted(collectionId, normalizeAccountId(address))).to.be.true;
1162 // tslint:disable-next-line: no-unused-expression
1163 expect(whiteListedAfter).to.be.true;
1164 });1172 });
1165}1173}
11661174
1205}1213}
12061214
1207export const getDetailedCollectionInfo = async (api: ApiPromise, collectionId: number)1215export const getDetailedCollectionInfo = async (api: ApiPromise, collectionId: number)
1208 : Promise<ICollectionInterface | null> => {1216 : Promise<NftDataStructsCollection | null> => {
1209 return (await api.query.nft.collectionById(collectionId)).toJSON() as unknown as ICollectionInterface;1217 return (await api.query.common.collectionById(collectionId)).unwrapOr(null);
1210};1218};
12111219
1212export const getCreatedCollectionCount = async (api: ApiPromise): Promise<number> => {1220export const getCreatedCollectionCount = async (api: ApiPromise): Promise<number> => {
1213 // set global object - collectionsCount1221 // set global object - collectionsCount
1214 return (await api.query.nft.createdCollectionCount() as unknown as BN).toNumber();1222 return (await api.query.common.createdCollectionCount()).toNumber();
1215};1223};
1216
1217export async function queryCollectionExpectSuccess(collectionId: number): Promise<ICollectionInterface> {
1218 return await usingApi(async (api) => {
1219 return (await api.query.nft.collectionById(collectionId)).toJSON() as unknown as ICollectionInterface;
1220 });
1221}
12221224
1223export async function queryNftOwner(api: ApiPromise, collectionId: number, tokenId: number): Promise<CrossAccountId> {1225export async function queryCollectionExpectSuccess(api: ApiPromise, collectionId: number): Promise<NftDataStructsCollection> {
1224 return normalizeAccountId((await api.query.nft.nftItemList(collectionId, tokenId) as any).toJSON().owner);1226 return (await api.query.common.collectionById(collectionId)).unwrap();
1225}1227}
12261228
1227export async function waitNewBlocks(blocksCount = 1): Promise<void> {1229export async function waitNewBlocks(blocksCount = 1): Promise<void> {
modifiedtests/src/whiteLists.test.tsdiffbeforeafterboth
3// file 'LICENSE', which is part of this source code package.3// file 'LICENSE', which is part of this source code package.
4//4//
55
6import { IKeyringPair } from '@polkadot/types/types';6import {IKeyringPair} from '@polkadot/types/types';
7import chai from 'chai';7import chai from 'chai';
8import chaiAsPromised from 'chai-as-promised';8import chaiAsPromised from 'chai-as-promised';
9import privateKey from './substrate/privateKey';9import privateKey from './substrate/privateKey';
10import usingApi, { submitTransactionExpectFailAsync } from './substrate/substrate-api';10import usingApi, {submitTransactionExpectFailAsync} from './substrate/substrate-api';
11import {11import {
12 addToWhiteListExpectSuccess,12 addToWhiteListExpectSuccess,
13 createCollectionExpectSuccess,13 createCollectionExpectSuccess,
32chai.use(chaiAsPromised);32chai.use(chaiAsPromised);
33const expect = chai.expect;33const expect = chai.expect;
3434
35let Alice: IKeyringPair;35let alice: IKeyringPair;
36let Bob: IKeyringPair;36let bob: IKeyringPair;
37let Charlie: IKeyringPair;37let charlie: IKeyringPair;
3838
39describe('Integration Test ext. White list tests', () => {39describe('Integration Test ext. White list tests', () => {
4040
41 before(async () => {41 before(async () => {
42 await usingApi(async () => {42 await usingApi(async () => {
43 Alice = privateKey('//Alice');43 alice = privateKey('//Alice');
44 Bob = privateKey('//Bob');44 bob = privateKey('//Bob');
45 Charlie = privateKey('//Charlie');45 charlie = privateKey('//Charlie');
46 });46 });
47 });47 });
4848
49 it('Owner can add address to white list', async () => {49 it('Owner can add address to white list', async () => {
50 const collectionId = await createCollectionExpectSuccess();50 const collectionId = await createCollectionExpectSuccess();
51 await addToWhiteListExpectSuccess(Alice, collectionId, Bob.address);51 await addToWhiteListExpectSuccess(alice, collectionId, bob.address);
52 });52 });
5353
54 it('Admin can add address to white list', async () => {54 it('Admin can add address to white list', async () => {
55 const collectionId = await createCollectionExpectSuccess();55 const collectionId = await createCollectionExpectSuccess();
56 await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);56 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
57 await addToWhiteListExpectSuccess(Bob, collectionId, Charlie.address);57 await addToWhiteListExpectSuccess(bob, collectionId, charlie.address);
58 });58 });
5959
60 it('Non-privileged user cannot add address to white list', async () => {60 it('Non-privileged user cannot add address to white list', async () => {
61 const collectionId = await createCollectionExpectSuccess();61 const collectionId = await createCollectionExpectSuccess();
62 await addToWhiteListExpectFail(Bob, collectionId, Charlie.address);62 await addToWhiteListExpectFail(bob, collectionId, charlie.address);
63 });63 });
6464
65 it('Nobody can add address to white list of non-existing collection', async () => {65 it('Nobody can add address to white list of non-existing collection', async () => {
66 const collectionId = (1<<32) - 1;66 const collectionId = (1<<32) - 1;
67 await addToWhiteListExpectFail(Alice, collectionId, Bob.address);67 await addToWhiteListExpectFail(alice, collectionId, bob.address);
68 });68 });
6969
70 it('Nobody can add address to white list of destroyed collection', async () => {70 it('Nobody can add address to white list of destroyed collection', async () => {
71 const collectionId = await createCollectionExpectSuccess();71 const collectionId = await createCollectionExpectSuccess();
72 await destroyCollectionExpectSuccess(collectionId, '//Alice');72 await destroyCollectionExpectSuccess(collectionId, '//Alice');
73 await addToWhiteListExpectFail(Alice, collectionId, Bob.address);73 await addToWhiteListExpectFail(alice, collectionId, bob.address);
74 });74 });
7575
76 it('If address is already added to white list, nothing happens', async () => {76 it('If address is already added to white list, nothing happens', async () => {
77 const collectionId = await createCollectionExpectSuccess();77 const collectionId = await createCollectionExpectSuccess();
78 await addToWhiteListExpectSuccess(Alice, collectionId, Bob.address);78 await addToWhiteListExpectSuccess(alice, collectionId, bob.address);
79 await addToWhiteListAgainExpectSuccess(Alice, collectionId, Bob.address);79 await addToWhiteListAgainExpectSuccess(alice, collectionId, bob.address);
80 });80 });
8181
82 it('Owner can remove address from white list', async () => {82 it('Owner can remove address from white list', async () => {
83 const collectionId = await createCollectionExpectSuccess();83 const collectionId = await createCollectionExpectSuccess();
84 await addToWhiteListExpectSuccess(Alice, collectionId, Bob.address);84 await addToWhiteListExpectSuccess(alice, collectionId, bob.address);
85 await removeFromWhiteListExpectSuccess(Alice, collectionId, normalizeAccountId(Bob));85 await removeFromWhiteListExpectSuccess(alice, collectionId, normalizeAccountId(bob));
86 }); 86 });
8787
88 it('Admin can remove address from white list', async () => {88 it('Admin can remove address from white list', async () => {
89 const collectionId = await createCollectionExpectSuccess();89 const collectionId = await createCollectionExpectSuccess();
90 await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);90 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
91 await addToWhiteListExpectSuccess(Alice, collectionId, Charlie.address);91 await addToWhiteListExpectSuccess(alice, collectionId, charlie.address);
92 await removeFromWhiteListExpectSuccess(Bob, collectionId, normalizeAccountId(Charlie));92 await removeFromWhiteListExpectSuccess(bob, collectionId, normalizeAccountId(charlie));
93 }); 93 });
9494
95 it('Non-privileged user cannot remove address from white list', async () => {95 it('Non-privileged user cannot remove address from white list', async () => {
96 const collectionId = await createCollectionExpectSuccess();96 const collectionId = await createCollectionExpectSuccess();
97 await addToWhiteListExpectSuccess(Alice, collectionId, Charlie.address);97 await addToWhiteListExpectSuccess(alice, collectionId, charlie.address);
98 await removeFromWhiteListExpectFailure(Bob, collectionId, normalizeAccountId(Charlie));98 await removeFromWhiteListExpectFailure(bob, collectionId, normalizeAccountId(charlie));
99 }); 99 });
100100
101 it('Nobody can remove address from white list of non-existing collection', async () => {101 it('Nobody can remove address from white list of non-existing collection', async () => {
102 const collectionId = (1<<32) - 1;102 const collectionId = (1<<32) - 1;
103 await removeFromWhiteListExpectFailure(Alice, collectionId, normalizeAccountId(Charlie));103 await removeFromWhiteListExpectFailure(alice, collectionId, normalizeAccountId(charlie));
104 }); 104 });
105105
106
107
108 it('Nobody can remove address from white list of deleted collection', async () => {106 it('Nobody can remove address from white list of deleted collection', async () => {
109 const collectionId = await createCollectionExpectSuccess();107 const collectionId = await createCollectionExpectSuccess();
110 await addToWhiteListExpectSuccess(Alice, collectionId, Charlie.address);108 await addToWhiteListExpectSuccess(alice, collectionId, charlie.address);
111 await destroyCollectionExpectSuccess(collectionId, '//Alice');109 await destroyCollectionExpectSuccess(collectionId, '//Alice');
112 await removeFromWhiteListExpectFailure(Alice, collectionId, normalizeAccountId(Charlie));110 await removeFromWhiteListExpectFailure(alice, collectionId, normalizeAccountId(charlie));
113 }); 111 });
114112
115 it('If address is already removed from white list, nothing happens', async () => {113 it('If address is already removed from white list, nothing happens', async () => {
116 const collectionId = await createCollectionExpectSuccess();114 const collectionId = await createCollectionExpectSuccess();
117 await addToWhiteListExpectSuccess(Alice, collectionId, Charlie.address);115 await addToWhiteListExpectSuccess(alice, collectionId, charlie.address);
118 await removeFromWhiteListExpectSuccess(Alice, collectionId, normalizeAccountId(Charlie));116 await removeFromWhiteListExpectSuccess(alice, collectionId, normalizeAccountId(charlie));
119 await removeFromWhiteListExpectSuccess(Alice, collectionId, normalizeAccountId(Charlie));117 await removeFromWhiteListExpectSuccess(alice, collectionId, normalizeAccountId(charlie));
120 }); 118 });
121119
122 it('If Public Access mode is set to WhiteList, tokens can’t be transferred from a non-whitelisted address with transfer or transferFrom. Test1', async () => {120 it('If Public Access mode is set to WhiteList, tokens can’t be transferred from a non-whitelisted address with transfer or transferFrom. Test1', async () => {
123 const collectionId = await createCollectionExpectSuccess();121 const collectionId = await createCollectionExpectSuccess();
124 const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Alice.address);122 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
125 await enableWhiteListExpectSuccess(Alice, collectionId);123 await enableWhiteListExpectSuccess(alice, collectionId);
126 await addToWhiteListExpectSuccess(Alice, collectionId, Charlie.address);124 await addToWhiteListExpectSuccess(alice, collectionId, charlie.address);
127125
128 await transferExpectFailure(126 await transferExpectFailure(
129 collectionId,127 collectionId,
130 itemId,128 itemId,
131 Alice,129 alice,
132 Charlie,130 charlie,
133 1,131 1,
134 );132 );
135 }); 133 });
136134
137 it('If Public Access mode is set to WhiteList, tokens can’t be transferred from a non-whitelisted address with transfer or transferFrom. Test2', async () => {135 it('If Public Access mode is set to WhiteList, tokens can’t be transferred from a non-whitelisted address with transfer or transferFrom. Test2', async () => {
138 const collectionId = await createCollectionExpectSuccess();136 const collectionId = await createCollectionExpectSuccess();
139 const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Alice.address);137 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
140 await enableWhiteListExpectSuccess(Alice, collectionId);138 await enableWhiteListExpectSuccess(alice, collectionId);
141 await addToWhiteListExpectSuccess(Alice, collectionId, Alice.address);139 await addToWhiteListExpectSuccess(alice, collectionId, alice.address);
142 await addToWhiteListExpectSuccess(Alice, collectionId, Charlie.address);140 await addToWhiteListExpectSuccess(alice, collectionId, charlie.address);
143 await approveExpectSuccess(collectionId, itemId, Alice, Charlie);141 await approveExpectSuccess(collectionId, itemId, alice, charlie.address);
144 await removeFromWhiteListExpectSuccess(Alice, collectionId, normalizeAccountId(Alice));142 await removeFromWhiteListExpectSuccess(alice, collectionId, normalizeAccountId(alice));
145143
146 await transferExpectFailure(144 await transferExpectFailure(
147 collectionId,145 collectionId,
148 itemId,146 itemId,
149 Alice,147 alice,
150 Charlie,148 charlie,
151 1,149 1,
152 );150 );
153 }); 151 });
154152
155 it('If Public Access mode is set to WhiteList, tokens can’t be transferred to a non-whitelisted address with transfer or transferFrom. Test1', async () => {153 it('If Public Access mode is set to WhiteList, tokens can’t be transferred to a non-whitelisted address with transfer or transferFrom. Test1', async () => {
156 const collectionId = await createCollectionExpectSuccess();154 const collectionId = await createCollectionExpectSuccess();
157 const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Alice.address);155 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
158 await enableWhiteListExpectSuccess(Alice, collectionId);156 await enableWhiteListExpectSuccess(alice, collectionId);
159 await addToWhiteListExpectSuccess(Alice, collectionId, Alice.address);157 await addToWhiteListExpectSuccess(alice, collectionId, alice.address);
160158
161 await transferExpectFailure(159 await transferExpectFailure(
162 collectionId,160 collectionId,
163 itemId,161 itemId,
164 Alice,162 alice,
165 Charlie,163 charlie,
166 1,164 1,
167 );165 );
168 }); 166 });
169167
170 it('If Public Access mode is set to WhiteList, tokens can’t be transferred to a non-whitelisted address with transfer or transferFrom. Test2', async () => {168 it('If Public Access mode is set to WhiteList, tokens can’t be transferred to a non-whitelisted address with transfer or transferFrom. Test2', async () => {
171 const collectionId = await createCollectionExpectSuccess();169 const collectionId = await createCollectionExpectSuccess();
172 const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Alice.address);170 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
173 await enableWhiteListExpectSuccess(Alice, collectionId);171 await enableWhiteListExpectSuccess(alice, collectionId);
174 await addToWhiteListExpectSuccess(Alice, collectionId, Alice.address);172 await addToWhiteListExpectSuccess(alice, collectionId, alice.address);
175 await addToWhiteListExpectSuccess(Alice, collectionId, Charlie.address);173 await addToWhiteListExpectSuccess(alice, collectionId, charlie.address);
176 await approveExpectSuccess(collectionId, itemId, Alice, Charlie);174 await approveExpectSuccess(collectionId, itemId, alice, charlie.address);
177 await removeFromWhiteListExpectSuccess(Alice, collectionId, normalizeAccountId(Alice));175 await removeFromWhiteListExpectSuccess(alice, collectionId, normalizeAccountId(alice));
178176
179 await transferExpectFailure(177 await transferExpectFailure(
180 collectionId,178 collectionId,
181 itemId,179 itemId,
182 Alice,180 alice,
183 Charlie,181 charlie,
184 1,182 1,
185 );183 );
186 }); 184 });
187185
188 it('If Public Access mode is set to WhiteList, tokens can’t be destroyed by a non-whitelisted address (even if it owned them before enabling WhiteList mode)', async () => {186 it('If Public Access mode is set to WhiteList, tokens can’t be destroyed by a non-whitelisted address (even if it owned them before enabling WhiteList mode)', async () => {
189 const collectionId = await createCollectionExpectSuccess();187 const collectionId = await createCollectionExpectSuccess();
190 const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Alice.address);188 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
191 await enableWhiteListExpectSuccess(Alice, collectionId);189 await enableWhiteListExpectSuccess(alice, collectionId);
192190
193 await usingApi(async (api) => {191 await usingApi(async (api) => {
194 const tx = api.tx.nft.burnItem(collectionId, itemId, /*normalizeAccountId(Alice.address),*/ 11);192 const tx = api.tx.nft.burnItem(collectionId, itemId, /*normalizeAccountId(Alice.address),*/ 11);
195 const badTransaction = async function () { 193 const badTransaction = async function () {
196 await submitTransactionExpectFailAsync(Alice, tx);194 await submitTransactionExpectFailAsync(alice, tx);
197 };195 };
198 await expect(badTransaction()).to.be.rejected;196 await expect(badTransaction()).to.be.rejected;
199 });197 });
200 }); 198 });
201 199
202 it('If Public Access mode is set to WhiteList, token transfers can’t be Approved by a non-whitelisted address (see Approve method)', async () => {200 it('If Public Access mode is set to WhiteList, token transfers can’t be Approved by a non-whitelisted address (see Approve method)', async () => {
203 const collectionId = await createCollectionExpectSuccess();201 const collectionId = await createCollectionExpectSuccess();
204 const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Alice.address);202 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
205 await enableWhiteListExpectSuccess(Alice, collectionId);203 await enableWhiteListExpectSuccess(alice, collectionId);
206 await approveExpectFail(collectionId, itemId, Alice, Bob);204 await approveExpectFail(collectionId, itemId, alice, bob);
207 }); 205 });
208 206
209 it('If Public Access mode is set to WhiteList, tokens can be transferred to a whitelisted address with transfer.', async () => {207 it('If Public Access mode is set to WhiteList, tokens can be transferred to a whitelisted address with transfer.', async () => {
210 const collectionId = await createCollectionExpectSuccess();208 const collectionId = await createCollectionExpectSuccess();
211 const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Alice.address);209 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
212 await enableWhiteListExpectSuccess(Alice, collectionId);210 await enableWhiteListExpectSuccess(alice, collectionId);
213 await addToWhiteListExpectSuccess(Alice, collectionId, Alice.address);211 await addToWhiteListExpectSuccess(alice, collectionId, alice.address);
214 await addToWhiteListExpectSuccess(Alice, collectionId, Charlie.address);212 await addToWhiteListExpectSuccess(alice, collectionId, charlie.address);
215 await transferExpectSuccess(collectionId, itemId, Alice, Charlie, 1, 'NFT');213 await transferExpectSuccess(collectionId, itemId, alice, charlie, 1, 'NFT');
216 }); 214 });
217215
218 it('If Public Access mode is set to WhiteList, tokens can be transferred to a whitelisted address with transferFrom.', async () => {216 it('If Public Access mode is set to WhiteList, tokens can be transferred to a whitelisted address with transferFrom.', async () => {
219 const collectionId = await createCollectionExpectSuccess();217 const collectionId = await createCollectionExpectSuccess();
220 const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Alice.address);218 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
221 await enableWhiteListExpectSuccess(Alice, collectionId);219 await enableWhiteListExpectSuccess(alice, collectionId);
222 await addToWhiteListExpectSuccess(Alice, collectionId, Alice.address);220 await addToWhiteListExpectSuccess(alice, collectionId, alice.address);
223 await addToWhiteListExpectSuccess(Alice, collectionId, Charlie.address);221 await addToWhiteListExpectSuccess(alice, collectionId, charlie.address);
224 await approveExpectSuccess(collectionId, itemId, Alice, Charlie);222 await approveExpectSuccess(collectionId, itemId, alice, charlie.address);
225 await transferFromExpectSuccess(collectionId, itemId, Alice, Alice, Charlie, 1, 'NFT');223 await transferFromExpectSuccess(collectionId, itemId, alice, alice, charlie, 1, 'NFT');
226 });224 });
227225
228 it('If Public Access mode is set to WhiteList, tokens can be transferred from a whitelisted address with transfer', async () => {226 it('If Public Access mode is set to WhiteList, tokens can be transferred from a whitelisted address with transfer', async () => {
229 const collectionId = await createCollectionExpectSuccess();227 const collectionId = await createCollectionExpectSuccess();
230 const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Alice.address);228 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
231 await enableWhiteListExpectSuccess(Alice, collectionId);229 await enableWhiteListExpectSuccess(alice, collectionId);
232 await addToWhiteListExpectSuccess(Alice, collectionId, Alice.address);230 await addToWhiteListExpectSuccess(alice, collectionId, alice.address);
233 await addToWhiteListExpectSuccess(Alice, collectionId, Charlie.address);231 await addToWhiteListExpectSuccess(alice, collectionId, charlie.address);
234 await transferExpectSuccess(collectionId, itemId, Alice, Charlie, 1, 'NFT');232 await transferExpectSuccess(collectionId, itemId, alice, charlie, 1, 'NFT');
235 });233 });
236234
237 it('If Public Access mode is set to WhiteList, tokens can be transferred from a whitelisted address with transferFrom', async () => {235 it('If Public Access mode is set to WhiteList, tokens can be transferred from a whitelisted address with transferFrom', async () => {
238 const collectionId = await createCollectionExpectSuccess();236 const collectionId = await createCollectionExpectSuccess();
239 const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Alice.address);237 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
240 await enableWhiteListExpectSuccess(Alice, collectionId);238 await enableWhiteListExpectSuccess(alice, collectionId);
241 await addToWhiteListExpectSuccess(Alice, collectionId, Alice.address);239 await addToWhiteListExpectSuccess(alice, collectionId, alice.address);
242 await addToWhiteListExpectSuccess(Alice, collectionId, Charlie.address);240 await addToWhiteListExpectSuccess(alice, collectionId, charlie.address);
243 await approveExpectSuccess(collectionId, itemId, Alice, Charlie);241 await approveExpectSuccess(collectionId, itemId, alice, charlie.address);
244 await transferFromExpectSuccess(collectionId, itemId, Alice, Alice, Charlie, 1, 'NFT');242 await transferFromExpectSuccess(collectionId, itemId, alice, alice, charlie, 1, 'NFT');
245 });243 });
246244
247 it('If Public Access mode is set to WhiteList, and Mint Permission is set to false, tokens can be created by owner', async () => {245 it('If Public Access mode is set to WhiteList, and Mint Permission is set to false, tokens can be created by owner', async () => {
248 const collectionId = await createCollectionExpectSuccess();246 const collectionId = await createCollectionExpectSuccess();
249 await enableWhiteListExpectSuccess(Alice, collectionId);247 await enableWhiteListExpectSuccess(alice, collectionId);
250 await setMintPermissionExpectSuccess(Alice, collectionId, false);248 await setMintPermissionExpectSuccess(alice, collectionId, false);
251 await createItemExpectSuccess(Alice, collectionId, 'NFT', Alice.address);249 await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
252 });250 });
253251
254 it('If Public Access mode is set to WhiteList, and Mint Permission is set to false, tokens can be created by admin', async () => {252 it('If Public Access mode is set to WhiteList, and Mint Permission is set to false, tokens can be created by admin', async () => {
255 const collectionId = await createCollectionExpectSuccess();253 const collectionId = await createCollectionExpectSuccess();
256 await enableWhiteListExpectSuccess(Alice, collectionId);254 await enableWhiteListExpectSuccess(alice, collectionId);
257 await setMintPermissionExpectSuccess(Alice, collectionId, false);255 await setMintPermissionExpectSuccess(alice, collectionId, false);
258 await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);256 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
259 await createItemExpectSuccess(Bob, collectionId, 'NFT', Bob.address);257 await createItemExpectSuccess(bob, collectionId, 'NFT', bob.address);
260 });258 });
261259
262 it('If Public Access mode is set to WhiteList, and Mint Permission is set to false, tokens cannot be created by non-privileged and white-listed address', async () => {260 it('If Public Access mode is set to WhiteList, and Mint Permission is set to false, tokens cannot be created by non-privileged and white-listed address', async () => {
263 const collectionId = await createCollectionExpectSuccess();261 const collectionId = await createCollectionExpectSuccess();
264 await enableWhiteListExpectSuccess(Alice, collectionId);262 await enableWhiteListExpectSuccess(alice, collectionId);
265 await setMintPermissionExpectSuccess(Alice, collectionId, false);263 await setMintPermissionExpectSuccess(alice, collectionId, false);
266 await addToWhiteListExpectSuccess(Alice, collectionId, Bob.address);264 await addToWhiteListExpectSuccess(alice, collectionId, bob.address);
267 await createItemExpectFailure(Bob, collectionId, 'NFT', Bob.address);265 await createItemExpectFailure(bob, collectionId, 'NFT', bob.address);
268 });266 });
269267
270 it('If Public Access mode is set to WhiteList, and Mint Permission is set to false, tokens cannot be created by non-privileged and non-white listed address', async () => {268 it('If Public Access mode is set to WhiteList, and Mint Permission is set to false, tokens cannot be created by non-privileged and non-white listed address', async () => {
271 const collectionId = await createCollectionExpectSuccess();269 const collectionId = await createCollectionExpectSuccess();
272 await enableWhiteListExpectSuccess(Alice, collectionId);270 await enableWhiteListExpectSuccess(alice, collectionId);
273 await setMintPermissionExpectSuccess(Alice, collectionId, false);271 await setMintPermissionExpectSuccess(alice, collectionId, false);
274 await createItemExpectFailure(Bob, collectionId, 'NFT', Bob.address);272 await createItemExpectFailure(bob, collectionId, 'NFT', bob.address);
275 });273 });
276274
277 it('If Public Access mode is set to WhiteList, and Mint Permission is set to true, tokens can be created by owner', async () => {275 it('If Public Access mode is set to WhiteList, and Mint Permission is set to true, tokens can be created by owner', async () => {
278 const collectionId = await createCollectionExpectSuccess();276 const collectionId = await createCollectionExpectSuccess();
279 await enableWhiteListExpectSuccess(Alice, collectionId);277 await enableWhiteListExpectSuccess(alice, collectionId);
280 await setMintPermissionExpectSuccess(Alice, collectionId, true);278 await setMintPermissionExpectSuccess(alice, collectionId, true);
281 await createItemExpectSuccess(Alice, collectionId, 'NFT', Alice.address);279 await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
282 }); 280 });
283281
284 it('If Public Access mode is set to WhiteList, and Mint Permission is set to true, tokens can be created by admin', async () => {282 it('If Public Access mode is set to WhiteList, and Mint Permission is set to true, tokens can be created by admin', async () => {
285 const collectionId = await createCollectionExpectSuccess();283 const collectionId = await createCollectionExpectSuccess();
286 await enableWhiteListExpectSuccess(Alice, collectionId);284 await enableWhiteListExpectSuccess(alice, collectionId);
287 await setMintPermissionExpectSuccess(Alice, collectionId, true);285 await setMintPermissionExpectSuccess(alice, collectionId, true);
288 await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);286 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
289 await createItemExpectSuccess(Bob, collectionId, 'NFT', Bob.address);287 await createItemExpectSuccess(bob, collectionId, 'NFT', bob.address);
290 });288 });
291289
292 it('If Public Access mode is set to WhiteList, and Mint Permission is set to true, tokens cannot be created by non-privileged and non-white listed address', async () => {290 it('If Public Access mode is set to WhiteList, and Mint Permission is set to true, tokens cannot be created by non-privileged and non-white listed address', async () => {
293 const collectionId = await createCollectionExpectSuccess();291 const collectionId = await createCollectionExpectSuccess();
294 await enableWhiteListExpectSuccess(Alice, collectionId);292 await enableWhiteListExpectSuccess(alice, collectionId);
295 await setMintPermissionExpectSuccess(Alice, collectionId, true);293 await setMintPermissionExpectSuccess(alice, collectionId, true);
296 await createItemExpectFailure(Bob, collectionId, 'NFT', Bob.address);294 await createItemExpectFailure(bob, collectionId, 'NFT', bob.address);
297 });295 });
298296
299 it('If Public Access mode is set to WhiteList, and Mint Permission is set to true, tokens can be created by non-privileged and white listed address', async () => {297 it('If Public Access mode is set to WhiteList, and Mint Permission is set to true, tokens can be created by non-privileged and white listed address', async () => {
300 const collectionId = await createCollectionExpectSuccess();298 const collectionId = await createCollectionExpectSuccess();
301 await enableWhiteListExpectSuccess(Alice, collectionId);299 await enableWhiteListExpectSuccess(alice, collectionId);
302 await setMintPermissionExpectSuccess(Alice, collectionId, true);300 await setMintPermissionExpectSuccess(alice, collectionId, true);
303 await addToWhiteListExpectSuccess(Alice, collectionId, Bob.address);301 await addToWhiteListExpectSuccess(alice, collectionId, bob.address);
304 await createItemExpectSuccess(Bob, collectionId, 'NFT', Bob.address);302 await createItemExpectSuccess(bob, collectionId, 'NFT', bob.address);
305 });303 });
306});304});
307
308305