git.delta.rocks / unique-network / refs/commits / 12fbdbdcf4df

difftreelog

tests(playgrounds): updates and revisions for older tests on playgrounds

Fahrrader2022-09-30parent: #e106ad4.patch.diff
in: master

9 files changed

modifiedtests/src/change-collection-owner.test.tsdiffbeforeafterboth
31 itSub('Changing owner changes owner address', async ({helper}) => {31 itSub('Changing owner changes owner address', async ({helper}) => {
32 const collection = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});32 const collection = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
33 const beforeChanging = await helper.collection.getData(collection.collectionId);33 const beforeChanging = await helper.collection.getData(collection.collectionId);
34 expect(beforeChanging?.normalizedOwner).to.be.equal(helper.util.normalizeSubstrateAddress(alice.address));34 expect(beforeChanging?.normalizedOwner).to.be.equal(helper.address.normalizeSubstrate(alice.address));
3535
36 await collection.changeOwner(alice, bob.address);36 await collection.changeOwner(alice, bob.address);
37 const afterChanging = await helper.collection.getData(collection.collectionId);37 const afterChanging = await helper.collection.getData(collection.collectionId);
38 expect(afterChanging?.normalizedOwner).to.be.equal(helper.util.normalizeSubstrateAddress(bob.address));38 expect(afterChanging?.normalizedOwner).to.be.equal(helper.address.normalizeSubstrate(bob.address));
39 });39 });
40});40});
4141
60 await expect(changeOwnerTx()).to.be.rejectedWith(/common\.NoPermission/);60 await expect(changeOwnerTx()).to.be.rejectedWith(/common\.NoPermission/);
6161
62 const afterChanging = await helper.collection.getData(collection.collectionId);62 const afterChanging = await helper.collection.getData(collection.collectionId);
63 expect(afterChanging?.normalizedOwner).to.be.equal(helper.util.normalizeSubstrateAddress(bob.address));63 expect(afterChanging?.normalizedOwner).to.be.equal(helper.address.normalizeSubstrate(bob.address));
64 });64 });
6565
66 itSub('New collectionOwner has access to sponsorship management operations in the collection', async ({helper}) => {66 itSub('New collectionOwner has access to sponsorship management operations in the collection', async ({helper}) => {
67 const collection = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});67 const collection = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
68 await collection.changeOwner(alice, bob.address);68 await collection.changeOwner(alice, bob.address);
6969
70 const afterChanging = await helper.collection.getData(collection.collectionId);70 const afterChanging = await helper.collection.getData(collection.collectionId);
71 expect(afterChanging?.normalizedOwner).to.be.equal(helper.util.normalizeSubstrateAddress(bob.address));71 expect(afterChanging?.normalizedOwner).to.be.equal(helper.address.normalizeSubstrate(bob.address));
7272
73 await collection.setSponsor(bob, charlie.address);73 await collection.setSponsor(bob, charlie.address);
74 await collection.confirmSponsorship(charlie);74 await collection.confirmSponsorship(charlie);
97 await collection.changeOwner(alice, bob.address);97 await collection.changeOwner(alice, bob.address);
98 await collection.changeOwner(bob, charlie.address);98 await collection.changeOwner(bob, charlie.address);
99 const collectionData = await collection.getData();99 const collectionData = await collection.getData();
100 expect(collectionData?.normalizedOwner).to.be.equal(helper.util.normalizeSubstrateAddress(charlie.address));100 expect(collectionData?.normalizedOwner).to.be.equal(helper.address.normalizeSubstrate(charlie.address));
101 });101 });
102});102});
103103
140 await expect(changeOwnerTx()).to.be.rejectedWith(/common\.NoPermission/);140 await expect(changeOwnerTx()).to.be.rejectedWith(/common\.NoPermission/);
141141
142 const afterChanging = await helper.collection.getData(collection.collectionId);142 const afterChanging = await helper.collection.getData(collection.collectionId);
143 expect(afterChanging?.normalizedOwner).to.be.equal(helper.util.normalizeSubstrateAddress(bob.address));143 expect(afterChanging?.normalizedOwner).to.be.equal(helper.address.normalizeSubstrate(bob.address));
144144
145 const setSponsorTx = async () => collection.setSponsor(alice, charlie.address);145 const setSponsorTx = async () => collection.setSponsor(alice, charlie.address);
146 const confirmSponsorshipTx = async () => collection.confirmSponsorship(alice);146 const confirmSponsorshipTx = async () => collection.confirmSponsorship(alice);
modifiedtests/src/createCollection.test.tsdiffbeforeafterboth
14// You should have received a copy of the GNU General Public License14// You should have received a copy of the GNU General Public License
15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
1616
17import {IKeyringPair} from '@polkadot/types/types';
17import {usingPlaygrounds, expect, itSub, Pallets} from './util/playgrounds';18import {usingPlaygrounds, expect, itSub, Pallets} from './util/playgrounds';
18import {IKeyringPair} from '@polkadot/types/types';
19import {ICollectionCreationOptions, IProperty} from './util/playgrounds/types';19import {ICollectionCreationOptions, IProperty} from './util/playgrounds/types';
20import {DevUniqueHelper} from './util/playgrounds/unique.dev';20import {UniqueHelper} from './util/playgrounds/unique';
2121
22async function mintCollectionHelper(helper: DevUniqueHelper, signer: IKeyringPair, options: ICollectionCreationOptions, type?: 'nft' | 'fungible' | 'refungible') {22async function mintCollectionHelper(helper: UniqueHelper, signer: IKeyringPair, options: ICollectionCreationOptions, type?: 'nft' | 'fungible' | 'refungible') {
23 let collection;23 let collection;
24 if (type === 'nft') {24 if (type === 'nft') {
25 collection = await helper.nft.mintCollection(signer, options);25 collection = await helper.nft.mintCollection(signer, options);
29 collection = await helper.rft.mintCollection(signer, options);29 collection = await helper.rft.mintCollection(signer, options);
30 }30 }
31 const data = await collection.getData();31 const data = await collection.getData();
32 expect(data?.normalizedOwner).to.be.equal(helper.util.normalizeSubstrateAddress(signer.address));32 expect(data?.normalizedOwner).to.be.equal(helper.address.normalizeSubstrate(signer.address));
33 expect(data?.name).to.be.equal(options.name);33 expect(data?.name).to.be.equal(options.name);
34 expect(data?.description).to.be.equal(options.description);34 expect(data?.description).to.be.equal(options.description);
35 expect(data?.raw.tokenPrefix).to.be.equal(options.tokenPrefix);35 expect(data?.raw.tokenPrefix).to.be.equal(options.tokenPrefix);
96 const limits = await collection.getEffectiveLimits();90 const limits = await collection.getEffectiveLimits();
97 const raw = data?.raw;91 const raw = data?.raw;
9892
99 expect(data?.normalizedOwner).to.be.equal(helper.util.normalizeSubstrateAddress(alice.address));93 expect(data?.normalizedOwner).to.be.equal(helper.address.normalizeSubstrate(alice.address));
100 expect(data?.name).to.be.equal('name');94 expect(data?.name).to.be.equal('name');
101 expect(data?.description).to.be.equal('descr');95 expect(data?.description).to.be.equal('descr');
102 expect(raw.permissions.access).to.be.equal('AllowList');96 expect(raw.permissions.access).to.be.equal('AllowList');
modifiedtests/src/createItem.test.tsdiffbeforeafterboth
1616
17import {IKeyringPair} from '@polkadot/types/types';17import {IKeyringPair} from '@polkadot/types/types';
18
19import {
20 createCollection,
21 itApi,
22 normalizeAccountId,
23 getCreateItemResult,
24 CrossAccountId,
25} from './util/helpers';
26
27import {usingPlaygrounds, expect, itSub, Pallets} from './util/playgrounds';18import {usingPlaygrounds, expect, itSub, Pallets} from './util/playgrounds';
28import {IProperty} from './util/playgrounds/types';19import {IProperty, ICrossAccountId} from './util/playgrounds/types';
29import {executeTransaction} from './substrate/substrate-api';
30import {DevUniqueHelper} from './util/playgrounds/unique.dev';20import {UniqueHelper} from './util/playgrounds/unique';
3121
32async function mintTokenHelper(helper: DevUniqueHelper, collection: any, signer: IKeyringPair, owner: CrossAccountId, type: 'nft' | 'fungible' | 'refungible'='nft', properties?: IProperty[]) {22async function mintTokenHelper(helper: UniqueHelper, collection: any, signer: IKeyringPair, owner: ICrossAccountId, type: 'nft' | 'fungible' | 'refungible'='nft', properties?: IProperty[]) {
33 let token;23 let token;
34 const itemCountBefore = await helper.collection.getLastTokenId(collection.collectionId);24 const itemCountBefore = await helper.collection.getLastTokenId(collection.collectionId);
35 const itemBalanceBefore = (await helper.api!.rpc.unique.balance(collection.collectionId, owner, 0)).toBigInt();25 const itemBalanceBefore = (await helper.callRpc('api.rpc.unique.balance', [collection.collectionId, owner, 0])).toBigInt();
36 if (type === 'nft') {26 if (type === 'nft') {
37 token = await collection.mintToken(signer, owner, properties);27 token = await collection.mintToken(signer, owner, properties);
38 } else if (type === 'fungible') {28 } else if (type === 'fungible') {
42 }32 }
4333
44 const itemCountAfter = await helper.collection.getLastTokenId(collection.collectionId);34 const itemCountAfter = await helper.collection.getLastTokenId(collection.collectionId);
45 const itemBalanceAfter = (await helper.api!.rpc.unique.balance(collection.collectionId, owner, 0)).toBigInt();35 const itemBalanceAfter = (await helper.callRpc('api.rpc.unique.balance', [collection.collectionId, owner, 0])).toBigInt();
4636
47 if (type === 'fungible') {37 if (type === 'fungible') {
48 expect(itemBalanceAfter - itemBalanceBefore).to.be.equal(10n);38 expect(itemBalanceAfter - itemBalanceBefore).to.be.equal(10n);
75 });65 });
76 itSub('Check events on create new item in Fungible collection', async ({helper}) => {66 itSub('Check events on create new item in Fungible collection', async ({helper}) => {
77 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'}, 0);67 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'}, 0);
78 const api = helper.api!;
79
80
81 const to = normalizeAccountId(alice);68 const to = {Substrate: alice.address};
82 {69 {
83 const createData = {fungible: {value: 100}};70 const createData = {fungible: {value: 100}};
84 const tx = api.tx.unique.createItem(collectionId, to, createData as any);71 const events = await helper.executeExtrinsic(alice, 'api.tx.unique.createItem', [collectionId, to, createData as any]);
85 const events = await executeTransaction(api, alice, tx);
86 const result = getCreateItemResult(events);72 const result = helper.util.extractTokensFromCreationResult(events);
87 expect(result.amount).to.be.equal(100);73 expect(result.tokens[0].amount).to.be.equal(100n);
88 expect(result.collectionId).to.be.equal(collectionId);74 expect(result.tokens[0].collectionId).to.be.equal(collectionId);
89 expect(result.recipient).to.be.deep.equal(to);75 expect(result.tokens[0].owner).to.be.deep.equal(to);
90 }76 }
91 {77 {
92 const createData = {fungible: {value: 50}};78 const createData = {fungible: {value: 50}};
93 const tx = api.tx.unique.createItem(collectionId, to, createData as any);79 const events = await helper.executeExtrinsic(alice, 'api.tx.unique.createItem', [collectionId, to, createData as any]);
94 const events = await executeTransaction(api, alice, tx);
95 const result = getCreateItemResult(events);80 const result = helper.util.extractTokensFromCreationResult(events);
96 expect(result.amount).to.be.equal(50);81 expect(result.tokens[0].amount).to.be.equal(50n);
97 expect(result.collectionId).to.be.equal(collectionId);82 expect(result.tokens[0].collectionId).to.be.equal(collectionId);
98 expect(result.recipient).to.be.deep.equal(to);83 expect(result.tokens[0].owner).to.be.deep.equal(to);
99 }84 }
100 });85 });
101 itSub.ifWithPallets('Create new item in ReFungible collection', [Pallets.ReFungible], async ({helper}) => {86 itSub.ifWithPallets('Create new item in ReFungible collection', [Pallets.ReFungible], async ({helper}) => {
162 const amount = 1n;147 const amount = 1n;
163 const token = await mintTokenHelper(helper, collection, alice, {Substrate: bob.address});148 const token = await mintTokenHelper(helper, collection, alice, {Substrate: bob.address});
164 {149 {
165 const totalPieces = await helper.api?.rpc.unique.totalPieces(collection.collectionId, token.tokenId);150 const totalPieces = await helper.callRpc('api.rpc.unique.totalPieces', [collection.collectionId, token.tokenId]);
166 expect(totalPieces?.unwrap().toBigInt()).to.be.equal(amount);151 expect(totalPieces?.unwrap().toBigInt()).to.be.equal(amount);
167 }152 }
168 await token.transfer(bob, {Substrate: alice.address});153 await token.transfer(bob, {Substrate: alice.address});
169 {154 {
170 const totalPieces = await helper.api?.rpc.unique.totalPieces(collection.collectionId, token.tokenId);155 const totalPieces = await helper.callRpc('api.rpc.unique.totalPieces', [collection.collectionId, token.tokenId]);
171 expect(totalPieces?.unwrap().toBigInt()).to.be.equal(amount);156 expect(totalPieces?.unwrap().toBigInt()).to.be.equal(amount);
172 }157 }
173 });158 });
267 itSub('Check total pieces for invalid Fungible token', async ({helper}) => {252 itSub('Check total pieces for invalid Fungible token', async ({helper}) => {
268 const collection = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);253 const collection = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);
269 const invalidTokenId = 1_000_000;254 const invalidTokenId = 1_000_000;
270 expect((await helper.api?.rpc.unique.totalPieces(collection.collectionId, invalidTokenId))?.isNone).to.be.true;255 expect((await helper.callRpc('api.rpc.unique.totalPieces', [collection.collectionId, invalidTokenId]))?.isNone).to.be.true;
271 expect((await helper.api?.rpc.unique.tokenData(collection.collectionId, invalidTokenId))?.pieces.toBigInt()).to.be.equal(0n);256 expect((await helper.callRpc('api.rpc.unique.tokenData', [collection.collectionId, invalidTokenId]))?.pieces.toBigInt()).to.be.equal(0n);
272 });257 });
273258
274 itSub('Check total pieces for invalid NFT token', async ({helper}) => {259 itSub('Check total pieces for invalid NFT token', async ({helper}) => {
275 const collection = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});260 const collection = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
276 const invalidTokenId = 1_000_000;261 const invalidTokenId = 1_000_000;
277 expect((await helper.api?.rpc.unique.totalPieces(collection.collectionId, invalidTokenId))?.isNone).to.be.true;262 expect((await helper.callRpc('api.rpc.unique.totalPieces', [collection.collectionId, invalidTokenId]))?.isNone).to.be.true;
278 expect((await helper.api?.rpc.unique.tokenData(collection.collectionId, invalidTokenId))?.pieces.toBigInt()).to.be.equal(0n);263 expect((await helper.callRpc('api.rpc.unique.tokenData', [collection.collectionId, invalidTokenId]))?.pieces.toBigInt()).to.be.equal(0n);
279 });264 });
280265
281 itSub.ifWithPallets('Check total pieces for invalid Refungible token', [Pallets.ReFungible], async ({helper}) => {266 itSub.ifWithPallets('Check total pieces for invalid Refungible token', [Pallets.ReFungible], async ({helper}) => {
282 const collection = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});267 const collection = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
283 const invalidTokenId = 1_000_000;268 const invalidTokenId = 1_000_000;
284 expect((await helper.api?.rpc.unique.totalPieces(collection.collectionId, invalidTokenId))?.isNone).to.be.true;269 expect((await helper.callRpc('api.rpc.unique.totalPieces', [collection.collectionId, invalidTokenId]))?.isNone).to.be.true;
285 expect((await helper.api?.rpc.unique.tokenData(collection.collectionId, invalidTokenId))?.pieces.toBigInt()).to.be.equal(0n);270 expect((await helper.callRpc('api.rpc.unique.tokenData', [collection.collectionId, invalidTokenId]))?.pieces.toBigInt()).to.be.equal(0n);
286 });271 });
287});272});
288273
modifiedtests/src/createMultipleItems.test.tsdiffbeforeafterboth
15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
1616
17import {IKeyringPair} from '@polkadot/types/types';17import {IKeyringPair} from '@polkadot/types/types';
18import {
19 normalizeAccountId,
20} from './util/helpers';
21import {usingPlaygrounds, expect, Pallets, itSub} from './util/playgrounds';18import {usingPlaygrounds, expect, Pallets, itSub} from './util/playgrounds';
22
2319
48 const tokens = await helper.nft.mintMultipleTokensWithOneOwner(alice, collection.collectionId, {Substrate: alice.address}, args);44 const tokens = await helper.nft.mintMultipleTokensWithOneOwner(alice, collection.collectionId, {Substrate: alice.address}, args);
49 for (const [i, token] of tokens.entries()) {45 for (const [i, token] of tokens.entries()) {
50 const tokenData = await token.getData();46 const tokenData = await token.getData();
51 expect(tokenData?.normalizedOwner).to.be.deep.equal({Substrate: helper.util.normalizeSubstrateAddress(alice.address)});47 expect(tokenData?.normalizedOwner.Substrate).to.be.deep.equal(helper.address.normalizeSubstrate(alice.address));
52 expect(tokenData?.properties[0].value).to.be.equal(args[i].properties[0].value);48 expect(tokenData?.properties[0].value).to.be.equal(args[i].properties[0].value);
53 }49 }
54 });50 });
116 const tokens = await helper.nft.mintMultipleTokensWithOneOwner(alice, collection.collectionId, {Substrate: alice.address}, args);112 const tokens = await helper.nft.mintMultipleTokensWithOneOwner(alice, collection.collectionId, {Substrate: alice.address}, args);
117 for (const [i, token] of tokens.entries()) {113 for (const [i, token] of tokens.entries()) {
118 const tokenData = await token.getData();114 const tokenData = await token.getData();
119 expect(tokenData?.normalizedOwner).to.be.deep.equal({Substrate: helper.util.normalizeSubstrateAddress(alice.address)});115 expect(tokenData?.normalizedOwner.Substrate).to.be.deep.equal(helper.address.normalizeSubstrate(alice.address));
120 expect(tokenData?.properties[0].value).to.be.equal(args[i].properties[0].value);116 expect(tokenData?.properties[0].value).to.be.equal(args[i].properties[0].value);
121 }117 }
122 });118 });
138 const tokens = await helper.nft.mintMultipleTokensWithOneOwner(alice, collection.collectionId, {Substrate: alice.address}, args);134 const tokens = await helper.nft.mintMultipleTokensWithOneOwner(alice, collection.collectionId, {Substrate: alice.address}, args);
139 for (const [i, token] of tokens.entries()) {135 for (const [i, token] of tokens.entries()) {
140 const tokenData = await token.getData();136 const tokenData = await token.getData();
141 expect(tokenData?.normalizedOwner).to.be.deep.equal({Substrate: helper.util.normalizeSubstrateAddress(alice.address)});137 expect(tokenData?.normalizedOwner.Substrate).to.be.deep.equal(helper.address.normalizeSubstrate(alice.address));
142 expect(tokenData?.properties[0].value).to.be.equal(args[i].properties[0].value);138 expect(tokenData?.properties[0].value).to.be.equal(args[i].properties[0].value);
143 }139 }
144 });140 });
160 const tokens = await helper.nft.mintMultipleTokensWithOneOwner(alice, collection.collectionId, {Substrate: alice.address}, args);156 const tokens = await helper.nft.mintMultipleTokensWithOneOwner(alice, collection.collectionId, {Substrate: alice.address}, args);
161 for (const [i, token] of tokens.entries()) {157 for (const [i, token] of tokens.entries()) {
162 const tokenData = await token.getData();158 const tokenData = await token.getData();
163 expect(tokenData?.normalizedOwner).to.be.deep.equal({Substrate: helper.util.normalizeSubstrateAddress(alice.address)});159 expect(tokenData?.normalizedOwner.Substrate).to.be.equal(helper.address.normalizeSubstrate(alice.address));
164 expect(tokenData?.properties[0].value).to.be.equal(args[i].properties[0].value);160 expect(tokenData?.properties[0].value).to.be.equal(args[i].properties[0].value);
165 }161 }
166 });162 });
275 });271 });
276272
277 const types = ['NFT', 'Fungible', 'ReFungible'];273 const types = ['NFT', 'Fungible', 'ReFungible'];
278 const mintTx = helper.api?.tx.unique.createMultipleItems(collectionId, normalizeAccountId(alice.address), types);
279 await expect(helper.signTransaction(alice, mintTx)).to.be.rejected;274 await expect(helper.executeExtrinsic(
275 alice,
276 'api.tx.unique.createMultipleItems',
277 [collectionId, {Substrate: alice.address}, types],
278 )).to.be.rejectedWith(/nonfungible\.NotNonfungibleDataUsedToMintFungibleCollectionToken/);
280 });279 });
281280
282 itSub('Create tokens with different data limits <> maximum data limit', async ({helper}) => {281 itSub('Create tokens with different data limits <> maximum data limit', async ({helper}) => {
modifiedtests/src/creditFeesToTreasury.test.tsdiffbeforeafterboth
1616
17import './interfaces/augment-api-consts';17import './interfaces/augment-api-consts';
18import {IKeyringPair} from '@polkadot/types/types';18import {IKeyringPair} from '@polkadot/types/types';
19import {
20 UNIQUE,
21} from './util/helpers';
22
23import {default as waitNewBlocks} from './substrate/wait-new-blocks';
24import {ApiPromise} from '@polkadot/api';19import {ApiPromise} from '@polkadot/api';
25import {usingPlaygrounds, expect, itSub} from './util/playgrounds';20import {usingPlaygrounds, expect, itSub} from './util/playgrounds';
2621
63 itSub('Total issuance does not change', async ({helper}) => {58 itSub('Total issuance does not change', async ({helper}) => {
64 const api = helper.api!;59 const api = helper.api!;
65 await skipInflationBlock(api);60 await skipInflationBlock(api);
66 await waitNewBlocks(api, 1);61 await helper.wait.newBlocks(1);
6762
68 const totalBefore = (await api.query.balances.totalIssuance()).toBigInt();63 const totalBefore = (await api.query.balances.totalIssuance()).toBigInt();
6964
75 });70 });
7671
77 itSub('Sender balance decreased by fee+sent amount, Treasury balance increased by fee', async ({helper}) => {72 itSub('Sender balance decreased by fee+sent amount, Treasury balance increased by fee', async ({helper}) => {
78 const api = helper.api!;73 await skipInflationBlock(helper.api!);
79 await skipInflationBlock(api);
80 await waitNewBlocks(api, 1);74 await helper.wait.newBlocks(1);
8175
82 const treasuryBalanceBefore = await helper.balance.getSubstrate(TREASURY);76 const treasuryBalanceBefore = await helper.balance.getSubstrate(TREASURY);
83 const aliceBalanceBefore = await helper.balance.getSubstrate(alice.address);77 const aliceBalanceBefore = await helper.balance.getSubstrate(alice.address);
9690
97 itSub('Treasury balance increased by failed tx fee', async ({helper}) => {91 itSub('Treasury balance increased by failed tx fee', async ({helper}) => {
98 const api = helper.api!;92 const api = helper.api!;
99 await waitNewBlocks(api, 1);93 await helper.wait.newBlocks(1);
10094
101 const treasuryBalanceBefore = await helper.balance.getSubstrate(TREASURY);95 const treasuryBalanceBefore = await helper.balance.getSubstrate(TREASURY);
102 const bobBalanceBefore = await helper.balance.getSubstrate(bob.address);96 const bobBalanceBefore = await helper.balance.getSubstrate(bob.address);
113 });107 });
114108
115 itSub('NFT Transactions also send fees to Treasury', async ({helper}) => {109 itSub('NFT Transactions also send fees to Treasury', async ({helper}) => {
116 const api = helper.api!;110 await skipInflationBlock(helper.api!);
117 await skipInflationBlock(api);
118 await waitNewBlocks(api, 1);111 await helper.wait.newBlocks(1);
119112
120 const treasuryBalanceBefore = await helper.balance.getSubstrate(TREASURY);113 const treasuryBalanceBefore = await helper.balance.getSubstrate(TREASURY);
121 const aliceBalanceBefore = await helper.balance.getSubstrate(alice.address);114 const aliceBalanceBefore = await helper.balance.getSubstrate(alice.address);
131 });124 });
132125
133 itSub('Fees are sane', async ({helper}) => {126 itSub('Fees are sane', async ({helper}) => {
134 const api = helper.api!;127 const unique = helper.balance.getOneTokenNominal();
135 await skipInflationBlock(api);128 await skipInflationBlock(helper.api!);
136 await waitNewBlocks(api, 1);129 await helper.wait.newBlocks(1);
137130
138 const aliceBalanceBefore = await helper.balance.getSubstrate(alice.address);131 const aliceBalanceBefore = await helper.balance.getSubstrate(alice.address);
139132
142 const aliceBalanceAfter = await helper.balance.getSubstrate(alice.address);135 const aliceBalanceAfter = await helper.balance.getSubstrate(alice.address);
143 const fee = aliceBalanceBefore - aliceBalanceAfter;136 const fee = aliceBalanceBefore - aliceBalanceAfter;
144137
145 expect(fee / UNIQUE < BigInt(Math.ceil(saneMaximumFee + createCollectionDeposit))).to.be.true;138 expect(fee / unique < BigInt(Math.ceil(saneMaximumFee + createCollectionDeposit))).to.be.true;
146 expect(fee / UNIQUE < BigInt(Math.ceil(saneMinimumFee + createCollectionDeposit))).to.be.true;139 expect(fee / unique < BigInt(Math.ceil(saneMinimumFee + createCollectionDeposit))).to.be.true;
147 });140 });
148141
149 itSub('NFT Transfer fee is close to 0.1 Unique', async ({helper}) => {142 itSub('NFT Transfer fee is close to 0.1 Unique', async ({helper}) => {
150 const api = helper.api!;143 await skipInflationBlock(helper.api!);
151 await skipInflationBlock(api);
152 await waitNewBlocks(api, 1);144 await helper.wait.newBlocks(1);
153145
154 const collection = await helper.nft.mintCollection(alice, {146 const collection = await helper.nft.mintCollection(alice, {
155 name: 'test',147 name: 'test',
163 await token.transfer(alice, {Substrate: bob.address});155 await token.transfer(alice, {Substrate: bob.address});
164 const aliceBalanceAfter = await helper.balance.getSubstrate(alice.address);156 const aliceBalanceAfter = await helper.balance.getSubstrate(alice.address);
165157
166 const fee = Number(aliceBalanceBefore - aliceBalanceAfter) / Number(UNIQUE);158 const fee = Number(aliceBalanceBefore - aliceBalanceAfter) / Number(helper.balance.getOneTokenNominal());
167 const expectedTransferFee = 0.1;159 const expectedTransferFee = 0.1;
168 // fee drifts because of NextFeeMultiplier160 // fee drifts because of NextFeeMultiplier
169 const tolerance = 0.001;161 const tolerance = 0.001;
modifiedtests/src/destroyCollection.test.tsdiffbeforeafterboth
15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
1616
17import {IKeyringPair} from '@polkadot/types/types';17import {IKeyringPair} from '@polkadot/types/types';
18import {
19 Pallets,
20} from './util/helpers';
21import {itSub, expect, usingPlaygrounds} from './util/playgrounds';18import {itSub, expect, usingPlaygrounds, Pallets} from './util/playgrounds';
2219
23describe('integration test: ext. destroyCollection():', () => {20describe('integration test: ext. destroyCollection():', () => {
24 let alice: IKeyringPair;21 let alice: IKeyringPair;
modifiedtests/src/nesting/properties.test.tsdiffbeforeafterboth

no syntactic changes

modifiedtests/src/refungible.test.tsdiffbeforeafterboth
124 const token = await collection.mintToken(alice, 100n);124 const token = await collection.mintToken(alice, 100n);
125 expect(await collection.isTokenExists(token.tokenId)).to.be.true;125 expect(await collection.isTokenExists(token.tokenId)).to.be.true;
126 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);126 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);
127 expect((await token.burn(alice, 99n)).success).to.be.true;127 expect(await token.burn(alice, 99n)).to.be.true;
128 expect(await collection.isTokenExists(token.tokenId)).to.be.true;128 expect(await collection.isTokenExists(token.tokenId)).to.be.true;
129 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(1n);129 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(1n);
130 });130 });
136 expect(await collection.isTokenExists(token.tokenId)).to.be.true;136 expect(await collection.isTokenExists(token.tokenId)).to.be.true;
137 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);137 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);
138138
139 expect((await token.burn(alice, 100n)).success).to.be.true;139 expect(await token.burn(alice, 100n)).to.be.true;
140 expect(await collection.isTokenExists(token.tokenId)).to.be.false;140 expect(await collection.isTokenExists(token.tokenId)).to.be.false;
141 });141 });
142142
152 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(40n);152 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(40n);
153 expect(await token.getBalance({Substrate: bob.address})).to.be.equal(60n);153 expect(await token.getBalance({Substrate: bob.address})).to.be.equal(60n);
154154
155 expect((await token.burn(alice, 40n)).success).to.be.true;155 expect(await token.burn(alice, 40n)).to.be.true;
156156
157 expect(await collection.isTokenExists(token.tokenId)).to.be.true;157 expect(await collection.isTokenExists(token.tokenId)).to.be.true;
158 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(0n);158 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(0n);
159159
160 expect((await token.burn(bob, 59n)).success).to.be.true;160 expect(await token.burn(bob, 59n)).to.be.true;
161161
162 expect(await token.getBalance({Substrate: bob.address})).to.be.equal(1n);162 expect(await token.getBalance({Substrate: bob.address})).to.be.equal(1n);
163 expect(await collection.isTokenExists(token.tokenId)).to.be.true;163 expect(await collection.isTokenExists(token.tokenId)).to.be.true;
164164
165 expect((await token.burn(bob, 1n)).success).to.be.true;165 expect(await token.burn(bob, 1n)).to.be.true;
166166
167 expect(await collection.isTokenExists(token.tokenId)).to.be.false;167 expect(await collection.isTokenExists(token.tokenId)).to.be.false;
168 });168 });
modifiedtests/src/util/playgrounds/unique.tsdiffbeforeafterboth
120 return keyring.addFromUri(seed);120 return keyring.addFromUri(seed);
121 }121 }
122122
123 static extractCollectionIdFromCreationResult(creationResult: ITransactionResult) {123 static extractCollectionIdFromCreationResult(creationResult: ITransactionResult): number {
124 if (creationResult.status !== this.transactionStatus.SUCCESS) {124 if (creationResult.status !== this.transactionStatus.SUCCESS) {
125 throw Error('Unable to create collection!');125 throw Error('Unable to create collection!');
126 }126 }
139 return collectionId;139 return collectionId;
140 }140 }
141141
142 static extractTokensFromCreationResult(creationResult: ITransactionResult) {142 static extractTokensFromCreationResult(creationResult: ITransactionResult): {
143 success: boolean,
144 tokens: {collectionId: number, tokenId: number, owner: CrossAccountId, amount: bigint}[],
145 } {
143 if (creationResult.status !== this.transactionStatus.SUCCESS) {146 if (creationResult.status !== this.transactionStatus.SUCCESS) {
144 throw Error('Unable to create tokens!');147 throw Error('Unable to create tokens!');
145 }148 }
146 let success = false;149 let success = false;
147 const tokens = [] as any;150 const tokens = [] as {collectionId: number, tokenId: number, owner: CrossAccountId, amount: bigint}[];
148 creationResult.result.events.forEach(({event: {data, method, section}}) => {151 creationResult.result.events.forEach(({event: {data, method, section}}) => {
149 if (method === 'ExtrinsicSuccess') {152 if (method === 'ExtrinsicSuccess') {
150 success = true;153 success = true;
151 } else if ((section === 'common') && (method === 'ItemCreated')) {154 } else if ((section === 'common') && (method === 'ItemCreated')) {
152 tokens.push({155 tokens.push({
153 collectionId: parseInt(data[0].toString(), 10),156 collectionId: parseInt(data[0].toString(), 10),
154 tokenId: parseInt(data[1].toString(), 10),157 tokenId: parseInt(data[1].toString(), 10),
155 owner: data[2].toJSON(),158 owner: data[2].toHuman(),
159 amount: data[3].toBigInt(),
156 });160 });
157 }161 }
158 });162 });
159 return {success, tokens};163 return {success, tokens};
160 }164 }
161165
162 static extractTokensFromBurnResult(burnResult: ITransactionResult) {166 static extractTokensFromBurnResult(burnResult: ITransactionResult): {
167 success: boolean,
168 tokens: {collectionId: number, tokenId: number, owner: CrossAccountId, amount: bigint}[],
169 } {
163 if (burnResult.status !== this.transactionStatus.SUCCESS) {170 if (burnResult.status !== this.transactionStatus.SUCCESS) {
164 throw Error('Unable to burn tokens!');171 throw Error('Unable to burn tokens!');
165 }172 }
166 let success = false;173 let success = false;
167 const tokens = [] as any;174 const tokens = [] as {collectionId: number, tokenId: number, owner: CrossAccountId, amount: bigint}[];
168 burnResult.result.events.forEach(({event: {data, method, section}}) => {175 burnResult.result.events.forEach(({event: {data, method, section}}) => {
169 if (method === 'ExtrinsicSuccess') {176 if (method === 'ExtrinsicSuccess') {
170 success = true;177 success = true;
171 } else if ((section === 'common') && (method === 'ItemDestroyed')) {178 } else if ((section === 'common') && (method === 'ItemDestroyed')) {
172 tokens.push({179 tokens.push({
173 collectionId: parseInt(data[0].toString(), 10),180 collectionId: parseInt(data[0].toString(), 10),
174 tokenId: parseInt(data[1].toString(), 10),181 tokenId: parseInt(data[1].toString(), 10),
175 owner: data[2].toJSON(),182 owner: data[2].toHuman(),
183 amount: data[3].toBigInt(),
176 });184 });
177 }185 }
178 });186 });
179 return {success, tokens};187 return {success, tokens};
180 }188 }
181189
182 static findCollectionInEvents(events: {event: IEvent}[], collectionId: number, expectedSection: string, expectedMethod: string) {190 static findCollectionInEvents(events: {event: IEvent}[], collectionId: number, expectedSection: string, expectedMethod: string): boolean {
183 let eventId = null;191 let eventId = null;
184 events.forEach(({event: {data, method, section}}) => {192 events.forEach(({event: {data, method, section}}) => {
185 if ((section === expectedSection) && (method === expectedMethod)) {193 if ((section === expectedSection) && (method === expectedMethod)) {
992 return this.helper.util.isTokenTransferSuccess(result.result.events, collectionId, tokenId, fromAddressObj, toAddressObj, amount);1000 return this.helper.util.isTokenTransferSuccess(result.result.events, collectionId, tokenId, fromAddressObj, toAddressObj, amount);
993 }1001 }
9941002
995 /**1003 /**
996 *1004 *
997 * Destroys a concrete instance of NFT/RFT or burns a specified amount of fungible tokens.1005 * Destroys a concrete instance of NFT/RFT or burns a specified amount of fungible tokens.
998 *1006 *
999 * @param signer keyring of signer1007 * @param signer keyring of signer
1000 * @param collectionId ID of collection1008 * @param collectionId ID of collection
1001 * @param tokenId ID of token1009 * @param tokenId ID of token
1002 * @param amount amount of tokens to be burned. For NFT must be set to 1n1010 * @param amount amount of tokens to be burned. For NFT must be set to 1n
1003 * @example burnToken(aliceKeyring, 10, 5);1011 * @example burnToken(aliceKeyring, 10, 5);
1004 * @returns ```true``` and burnt token number is extrinsic success. Otherwise ```false``` and ```null```1012 * @returns ```true``` if the extrinsic is successful, otherwise ```false```
1005 */1013 */
1006 async burnToken(signer: TSigner, collectionId: number, tokenId: number, amount=1n): Promise<{1014 async burnToken(signer: TSigner, collectionId: number, tokenId: number, amount=1n): Promise<boolean> {
1007 success: boolean,
1008 token: number | null
1009 }> {
1010 const burnResult = await this.helper.executeExtrinsic(1015 const burnResult = await this.helper.executeExtrinsic(
1011 signer,1016 signer,
1012 'api.tx.unique.burnItem', [collectionId, tokenId, amount],1017 'api.tx.unique.burnItem', [collectionId, tokenId, amount],
1013 true, // `Unable to burn token for ${label}`,1018 true, // `Unable to burn token for ${label}`,
1014 );1019 );
1015 const burnedTokens = this.helper.util.extractTokensFromBurnResult(burnResult);1020 const burnedTokens = this.helper.util.extractTokensFromBurnResult(burnResult);
1016 if (burnedTokens.tokens.length > 1) throw Error('Burned multiple tokens');1021 if (burnedTokens.tokens.length > 1) throw Error('Burned multiple tokens');
1017 return {success: burnedTokens.success, token: burnedTokens.tokens.length > 0 ? burnedTokens.tokens[0] : null};1022 return burnedTokens.success;
1018 }1023 }
10191024
1020 /**1025 /**
1140 if (tokenData === null || tokenData.owner === null) return null;1145 if (tokenData === null || tokenData.owner === null) return null;
1141 const owner = {} as any;1146 const owner = {} as any;
1142 for (const key of Object.keys(tokenData.owner)) {1147 for (const key of Object.keys(tokenData.owner)) {
1143 owner[key.toLocaleLowerCase()] = new CrossAccountId(tokenData.owner[key]).withNormalizedSubstrate();1148 owner[key.toLocaleLowerCase()] = key.toLocaleLowerCase() == 'substrate'
1149 ? CrossAccountId.normalizeSubstrateAddress(tokenData.owner[key])
1150 : tokenData.owner[key];
1144 }1151 }
1145 tokenData.normalizedOwner = CrossAccountId.fromLowerCaseKeys(owner);1152 tokenData.normalizedOwner = CrossAccountId.fromLowerCaseKeys(owner);
1146 return tokenData;1153 return tokenData;
1683 return this.helper.util.extractTokensFromCreationResult(creationResult).tokens.map((x: IToken) => collection.getTokenObject(x.tokenId));1690 return this.helper.util.extractTokensFromCreationResult(creationResult).tokens.map((x: IToken) => collection.getTokenObject(x.tokenId));
1684 }1691 }
16851692
1686 /**1693 /**
1687 * Destroys a concrete instance of RFT.1694 * Destroys a concrete instance of RFT.
1688 * @param signer keyring of signer1695 * @param signer keyring of signer
1689 * @param collectionId ID of collection1696 * @param collectionId ID of collection
1690 * @param tokenId ID of token1697 * @param tokenId ID of token
1691 * @param amount number of pieces to be burnt1698 * @param amount number of pieces to be burnt
1692 * @example burnToken(aliceKeyring, 10, 5);1699 * @example burnToken(aliceKeyring, 10, 5);
1693 * @returns ```true``` and burnt token number, if extrinsic is successful. Otherwise ```false``` and ```null```1700 * @returns ```true``` if the extrinsic is successful, otherwise ```false```
1694 */1701 */
1695 async burnToken(signer: IKeyringPair, collectionId: number, tokenId: number, amount=1n): Promise<{ success: boolean; token: number | null; }> {1702 async burnToken(signer: IKeyringPair, collectionId: number, tokenId: number, amount=1n): Promise<boolean> {
1696 return await super.burnToken(signer, collectionId, tokenId, amount);1703 return await super.burnToken(signer, collectionId, tokenId, amount);
1697 }1704 }
16981705
1898 * @returns ```true``` if extrinsic success, otherwise ```false```1905 * @returns ```true``` if extrinsic success, otherwise ```false```
1899 */1906 */
1900 async burnTokens(signer: IKeyringPair, collectionId: number, amount=1n): Promise<boolean> {1907 async burnTokens(signer: IKeyringPair, collectionId: number, amount=1n): Promise<boolean> {
1901 return (await super.burnToken(signer, collectionId, 0, amount)).success;1908 return await super.burnToken(signer, collectionId, 0, amount);
1902 }1909 }
19031910
1904 /**1911 /**