difftreelog
test use rtt from metadata
in: master
33 files changed
docker-compose-tests-parachain.ymldiffbeforeafterboth7 ports:7 ports:8 - 9944:99448 - 9944:99449 - 9844:98449 - 9844:984410 - 9933:993410 - 9933:993311 build:11 build:12 context: ./12 context: ./13 dockerfile: Dockerfile-parachain13 dockerfile: Dockerfile-parachain19 volumes:19 volumes:20# - ./chain-data:/chain-data20# - ./chain-data:/chain-data21 - ./launch-config.json:/polkadot-launch/launch-config.json21 - ./launch-config.json:/polkadot-launch/launch-config.json22 - ./runtime_types.json:/polkadot-launch/runtime_types.json23 env_file:22 env_file:24 - ./.env23 - ./.env25 networks:24 networks:34 context: tests/33 context: tests/35 dockerfile: Dockerfile-tests34 dockerfile: Dockerfile-tests36 environment:35 environment:37 RPC_URL: http://blockchain_nodes:9934/36 RPC_URL: http://blockchain_nodes:9933/38 volumes:37 volumes:39 - ./tests/src/config_docker.ts:/nft_parachain/src/config.ts38 - ./tests/src/config_docker.ts:/nft_parachain/src/config.ts40 - /home/ubuntu/mochawesome-report:/nft_parachain/mochawesome-report39 - /home/ubuntu/mochawesome-report:/nft_parachain/mochawesome-report41 - ./runtime_types.json:/runtime_types.json42# command: bash -c 'while true; do sleep 20; df -h; done'40# command: bash -c 'while true; do sleep 20; df -h; done'43 networks:41 networks:44 - node_test_network42 - node_test_networkexamples/re-fungible/create_collection.jsdiffbeforeafterboth45async function main() {45async function main() {46 // Initialise the provider to connect to the node46 // Initialise the provider to connect to the node47 const wsProvider = new WsProvider(config.wsEndpoint);47 const wsProvider = new WsProvider(config.wsEndpoint);48 const rtt = JSON.parse(fs.readFileSync("runtime_types.json"));4950 // Create the API and wait until ready48 // Create the API and wait until ready51 const api = await ApiPromise.create({ 49 const api = await ApiPromise.create({52 provider: wsProvider,50 provider: wsProvider,53 types: rtt54 });51 });555256 // Owners's keypair53 // Owners's keypairexamples/testnft/create_collection.jsdiffbeforeafterboth48async function main() {48async function main() {49 // Initialise the provider to connect to the node49 // Initialise the provider to connect to the node50 const wsProvider = new WsProvider(config.wsEndpoint);50 const wsProvider = new WsProvider(config.wsEndpoint);51 const rtt = JSON.parse(fs.readFileSync("runtime_types.json"));525153 // Create the API and wait until ready52 // Create the API and wait until ready54 const api = await ApiPromise.create({ 53 const api = await ApiPromise.create({55 provider: wsProvider,54 provider: wsProvider,56 types: rtt57 });55 });585659 // Owners's keypair57 // Owners's keypairexamples/testnft/create_tokens.jsdiffbeforeafterboth34async function main() {34async function main() {35 // Initialise the provider to connect to the node35 // Initialise the provider to connect to the node36 const wsProvider = new WsProvider(config.wsEndpoint);36 const wsProvider = new WsProvider(config.wsEndpoint);37 const rtt = require("./runtime_types.json");383739 // Create the API and wait until ready38 // Create the API and wait until ready40 const api = await ApiPromise.create({ 39 const api = await ApiPromise.create({41 provider: wsProvider,40 provider: wsProvider,42 types: rtt43 });41 });444245 // Retrieve the chain & node information information via rpc calls43 // Retrieve the chain & node information information via rpc calls53 console.log(`You are connected to chain ${chain} using ${nodeName} v${nodeVersion}`);51 console.log(`You are connected to chain ${chain} using ${nodeName} v${nodeVersion}`);54 console.log(`Collection: ${collection}`);52 console.log(`Collection: ${collection}`);555356 if (checkOwner(collection.Owner.toString())) {54 if (checkOwner(collection.owner.toString())) {57 // Import account from mnemonic phrase in config file55 // Import account from mnemonic phrase in config file58 const keyring = new Keyring({ type: 'sr25519' });56 const keyring = new Keyring({ type: 'sr25519' });59 const owner = keyring.addFromUri(config.ownerSeed);57 const owner = keyring.addFromUri(config.ownerSeed);launch-config.jsondiffbeforeafterboth88 ],88 ],89 "simpleParachains": [],89 "simpleParachains": [],90 "hrmpChannels": [],90 "hrmpChannels": [],91 "types": "./runtime_types.json",92 "finalization": false91 "finalization": false93}92}9493launch-test-env.shdiffbeforeafterboth1cp launch-config.json ../polkadot-launch/launch-config.json1cp launch-config.json ../polkadot-launch/launch-config.json2cp runtime_types.json ../polkadot-launch/runtime_types.json324cd ../polkadot-launch3cd ../polkadot-launch5yarn install4yarn installruntime_types.jsondiffbeforeafterbothno changes
tests/src/addCollectionAdmin.test.tsdiffbeforeafterboth21 const bob = privateKey('//Bob');21 const bob = privateKey('//Bob');222223 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();23 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();24 expect(collection.Owner).to.be.equal(alice.address);24 expect(collection.owner).to.be.equal(alice.address);252526 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);39 const Charlie = privateKey('//CHARLIE');39 const Charlie = privateKey('//CHARLIE');404041 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();41 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();42 expect(collection.Owner).to.be.equal(Alice.address);42 expect(collection.owner).to.be.equal(Alice.address);434344 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);tests/src/approve.test.tsdiffbeforeafterboth173 it('fails when called by collection owner on non-owned item when OwnerCanTransfer == false', async () => {173 it('fails when called by collection owner on non-owned item when OwnerCanTransfer == false', async () => {174 const collectionId = await createCollectionExpectSuccess();174 const collectionId = await createCollectionExpectSuccess();175 const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Bob.address);175 const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Bob.address);176 await setCollectionLimitsExpectSuccess(Alice, collectionId, { OwnerCanTransfer: false });176 await setCollectionLimitsExpectSuccess(Alice, collectionId, { ownerCanTransfer: false });177177178 await approveExpectFail(collectionId, itemId, Alice, Charlie);178 await approveExpectFail(collectionId, itemId, Alice, Charlie);179 });179 });tests/src/burnItem.test.tsdiffbeforeafterboth63 const events = await submitTransactionAsync(alice, tx);63 const events = await submitTransactionAsync(alice, tx);64 const result = getGenericResult(events);64 const result = getGenericResult(events);65 6566 // Get alice balance 66 // Get alice balance67 const balance: any = (await api.query.nft.fungibleItemList(collectionId, alice.address)).toJSON();67 const balance: any = (await api.query.nft.fungibleItemList(collectionId, alice.address)).toJSON();68 6869 // What to expect69 // What to expect70 expect(result.success).to.be.true;70 expect(result.success).to.be.true;71 expect(balance).to.be.not.null;71 expect(balance).to.be.not.null;72 expect(balance.Value).to.be.equal(9);72 expect(balance.value).to.be.equal(9);73 });73 });74 });74 });757583 const events = await submitTransactionAsync(alice, tx);83 const events = await submitTransactionAsync(alice, tx);84 const result = getGenericResult(events);84 const result = getGenericResult(events);85 8586 // Get alice balance 86 // Get alice balance87 const balance: any = (await api.query.nft.reFungibleItemList(collectionId, tokenId)).toJSON();87 const balance: any = (await api.query.nft.reFungibleItemList(collectionId, tokenId)).toJSON();88 8889 // What to expect89 // What to expect111 const events2 = await submitTransactionAsync(bob, tx);111 const events2 = await submitTransactionAsync(bob, tx);112 const result2 = getGenericResult(events2);112 const result2 = getGenericResult(events2);113113114 // Get balances 114 // Get balances115 const balance: any = (await api.query.nft.reFungibleItemList(collectionId, tokenId)).toJSON();115 const balance: any = (await api.query.nft.reFungibleItemList(collectionId, tokenId)).toJSON();116 // console.log(balance);116 // console.log(balance);117 117118 // What to expect before burning118 // What to expect before burning119 expect(result1.success).to.be.true;119 expect(result1.success).to.be.true;120 expect(balanceBefore).to.be.not.null;120 expect(balanceBefore).to.be.not.null;121 expect(balanceBefore.Owner.length).to.be.equal(2);121 expect(balanceBefore.owner.length).to.be.equal(2);122 expect(balanceBefore.Owner[0].Owner).to.be.deep.equal(normalizeAccountId(alice.address));122 expect(balanceBefore.owner[0].owner).to.be.deep.equal(normalizeAccountId(alice.address));123 expect(balanceBefore.Owner[0].Fraction).to.be.equal(99);123 expect(balanceBefore.owner[0].fraction).to.be.equal(99);124 expect(balanceBefore.Owner[1].Owner).to.be.deep.equal(normalizeAccountId(bob.address));124 expect(balanceBefore.owner[1].owner).to.be.deep.equal(normalizeAccountId(bob.address));125 expect(balanceBefore.Owner[1].Fraction).to.be.equal(1);125 expect(balanceBefore.owner[1].fraction).to.be.equal(1);126126127 // What to expect after burning127 // What to expect after burning128 expect(result2.success).to.be.true;128 expect(result2.success).to.be.true;129 expect(balance).to.be.not.null;129 expect(balance).to.be.not.null;130 expect(balance.Owner.length).to.be.equal(1);130 expect(balance.owner.length).to.be.equal(1);131 expect(balance.Owner[0].Fraction).to.be.equal(99);131 expect(balance.owner[0].fraction).to.be.equal(99);132 expect(balance.Owner[0].Owner).to.be.deep.equal(normalizeAccountId(alice.address));132 expect(balance.owner[0].owner).to.be.deep.equal(normalizeAccountId(alice.address));133 });133 });134134135 });135 });257 };257 };258 await expect(badTransaction()).to.be.rejected;258 await expect(badTransaction()).to.be.rejected;259 259260 // Get alice balance 260 // Get alice balance261 const balance: any = (await api.query.nft.fungibleItemList(collectionId, alice.address)).toJSON();261 const balance: any = (await api.query.nft.fungibleItemList(collectionId, alice.address)).toJSON();262 262263 // What to expect263 // What to expect264 expect(balance).to.be.not.null;264 expect(balance).to.be.not.null;265 expect(balance.Value).to.be.equal(10);265 expect(balance.value).to.be.equal(10);266 });266 });267267268 });268 });tests/src/change-collection-owner.test.tsdiffbeforeafterboth35 const bob = privateKey('//Bob');35 const bob = privateKey('//Bob');363637 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();37 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();38 expect(collection.Owner).to.be.deep.eq(alice.address);38 expect(collection.owner).to.be.deep.eq(alice.address);393940 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);424243 const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();43 const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();44 expect(collectionAfterOwnerChange.Owner).to.be.deep.eq(bob.address);44 expect(collectionAfterOwnerChange.owner).to.be.deep.eq(bob.address);45 });45 });46 });46 });47});47});54 const bob = privateKey('//Bob');54 const bob = privateKey('//Bob');555556 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();56 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();57 expect(collection.Owner).to.be.deep.eq(alice.address);57 expect(collection.owner).to.be.deep.eq(alice.address);585859 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);63 await expect(submitTransactionExpectFailAsync(alice, badChangeOwnerTx)).to.be.rejected;63 await expect(submitTransactionExpectFailAsync(alice, badChangeOwnerTx)).to.be.rejected;646465 const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();65 const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();66 expect(collectionAfterOwnerChange.Owner).to.be.deep.eq(bob.address);66 expect(collectionAfterOwnerChange.owner).to.be.deep.eq(bob.address);67 });67 });68 });68 });696975 const charlie = privateKey('//Charlie');75 const charlie = privateKey('//Charlie');767677 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();77 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();78 expect(collection.Owner).to.be.deep.eq(alice.address);78 expect(collection.owner).to.be.deep.eq(alice.address);797980 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);828283 const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();83 const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();84 expect(collectionAfterOwnerChange.Owner).to.be.deep.eq(bob.address);84 expect(collectionAfterOwnerChange.owner).to.be.deep.eq(bob.address);858586 // 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 owner87 // 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 collection919192 // The new owner of the collection has access to operations for managing the collection parameters92 // The new owner of the collection has access to operations for managing the collection parameters93 const collectionLimits = {93 const collectionLimits = {94 AccountTokenOwnershipLimit: 1,94 accountTokenOwnershipLimit: 1,95 SponsoredMintSize: 1,95 sponsoredMintSize: 1,96 TokenLimit: 1,96 tokenLimit: 1,97 SponsorTimeout: 1,97 sponsorTimeout: 1,98 OwnerCanTransfer: true,98 ownerCanTransfer: true,99 OwnerCanDestroy: true,99 ownerCanDestroy: true,100 };100 };101 const tx1 = api.tx.nft.setCollectionLimits(101 const tx1 = api.tx.nft.setCollectionLimits(102 collectionId,102 collectionId,119 const charlie = privateKey('//Charlie');119 const charlie = privateKey('//Charlie');120 120121 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();121 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();122 expect(collection.Owner).to.be.deep.eq(alice.address);122 expect(collection.owner).to.be.deep.eq(alice.address);123 123124 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);126 126127 const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();127 const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();128 expect(collectionAfterOwnerChange.Owner).to.be.deep.eq(bob.address);128 expect(collectionAfterOwnerChange.owner).to.be.deep.eq(bob.address);129129130 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);132 132133 // ownership lost133 // ownership lost134 const collectionAfterOwnerChange2: any = (await api.query.nft.collectionById(collectionId)).toJSON();134 const collectionAfterOwnerChange2: any = (await api.query.nft.collectionById(collectionId)).toJSON();135 expect(collectionAfterOwnerChange2.Owner).to.be.deep.eq(charlie.address);135 expect(collectionAfterOwnerChange2.owner).to.be.deep.eq(charlie.address);136 });136 });137 });137 });138});138});148 await expect(submitTransactionExpectFailAsync(bob, changeOwnerTx)).to.be.rejected;148 await expect(submitTransactionExpectFailAsync(bob, changeOwnerTx)).to.be.rejected;149149150 const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();150 const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();151 expect(collectionAfterOwnerChange.Owner).to.be.deep.eq(alice.address);151 expect(collectionAfterOwnerChange.owner).to.be.deep.eq(alice.address);152152153 // 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();167 await expect(submitTransactionExpectFailAsync(bob, changeOwnerTx)).to.be.rejected;167 await expect(submitTransactionExpectFailAsync(bob, changeOwnerTx)).to.be.rejected;168168169 const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();169 const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();170 expect(collectionAfterOwnerChange.Owner).to.be.deep.eq(alice.address);170 expect(collectionAfterOwnerChange.owner).to.be.deep.eq(alice.address);171171172 // 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();196 const charlie = privateKey('//Charlie');196 const charlie = privateKey('//Charlie');197197198 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();198 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();199 expect(collection.Owner).to.be.deep.eq(alice.address);199 expect(collection.owner).to.be.deep.eq(alice.address);200200201 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);205 await expect(submitTransactionExpectFailAsync(alice, badChangeOwnerTx)).to.be.rejected;205 await expect(submitTransactionExpectFailAsync(alice, badChangeOwnerTx)).to.be.rejected;206206207 const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();207 const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();208 expect(collectionAfterOwnerChange.Owner).to.be.deep.eq(bob.address);208 expect(collectionAfterOwnerChange.owner).to.be.deep.eq(bob.address);209209210 await setCollectionSponsorExpectFailure(collectionId, charlie.address, '//Alice');210 await setCollectionSponsorExpectFailure(collectionId, charlie.address, '//Alice');211 await confirmSponsorshipExpectFailure(collectionId, '//Alice');211 await confirmSponsorshipExpectFailure(collectionId, '//Alice');212 await removeCollectionSponsorExpectFailure(collectionId, '//Alice');212 await removeCollectionSponsorExpectFailure(collectionId, '//Alice');213213214 const collectionLimits = {214 const collectionLimits = {215 AccountTokenOwnershipLimit: 1,215 accountTokenOwnershipLimit: 1,216 SponsoredMintSize: 1,216 sponsoredMintSize: 1,217 TokenLimit: 1,217 tokenLimit: 1,218 SponsorTimeout: 1,218 sponsorTimeout: 1,219 OwnerCanTransfer: true,219 ownerCanTransfer: true,220 OwnerCanDestroy: true,220 ownerCanDestroy: true,221 };221 };222 const tx1 = api.tx.nft.setCollectionLimits(222 const tx1 = api.tx.nft.setCollectionLimits(223 collectionId,223 collectionId,tests/src/collision-tests/admVsOwnerChanges.test.tsdiffbeforeafterboth45 sendItem.signAndSend(Ferdie),45 sendItem.signAndSend(Ferdie),46 ]);46 ]);47 const itemBefore: any = await api.query.nft.nftItemList(collectionId, itemId);47 const itemBefore: any = await api.query.nft.nftItemList(collectionId, itemId);48 expect(itemBefore.Owner).not.to.be.eq(Bob.address);48 expect(itemBefore.owner).not.to.be.eq(Bob.address);49 await waitNewBlocks(2);49 await waitNewBlocks(2);50 });50 });51 });51 });tests/src/collision-tests/admVsOwnerData.test.tsdiffbeforeafterboth41 BobTx.signAndSend(Bob),41 BobTx.signAndSend(Bob),42 ]);42 ]);43 const item: any = await api.query.nft.nftItemList(collectionId, itemId);43 const item: any = await api.query.nft.nftItemList(collectionId, itemId);44 expect(item.VariableData).not.to.be.eq(null); // Pseudo-random selection of one of two values44 expect(item.variableData).not.to.be.eq(null); // Pseudo-random selection of one of two values45 await waitNewBlocks(2);45 await waitNewBlocks(2);46 });46 });47 });47 });tests/src/collision-tests/setSponsorNewOwner.test.tsdiffbeforeafterboth38 ]);38 ]);39 await waitNewBlocks(2);39 await waitNewBlocks(2);40 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();40 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();41 expect(collection.Sponsorship.confirmed).to.be.eq(Bob.address);41 expect(collection.sponsorship.confirmed).to.be.eq(Bob.address);42 expect(collection.Owner).to.be.eq(Ferdie.address);42 expect(collection.owner).to.be.eq(Ferdie.address);43 await waitNewBlocks(2);43 await waitNewBlocks(2);44 });44 });45 });45 });tests/src/collision-tests/tokenLimitsOff.test.tsdiffbeforeafterboth19let Bob: IKeyringPair;19let Bob: IKeyringPair;20let Ferdie: IKeyringPair;20let Ferdie: IKeyringPair;212122const AccountTokenOwnershipLimit = 4;22const accountTokenOwnershipLimit = 4;23const SponsoredMintSize = 4294967295;23const sponsoredMintSize = 4294967295;24const TokenLimit = 4;24const tokenLimit = 4;25const SponsorTimeout = 14400;25const sponsorTimeout = 14400;26const OwnerCanTransfer = false;26const ownerCanTransfer = false;27const OwnerCanDestroy = false;27const ownerCanDestroy = false;282829before(async () => {29before(async () => {30 await usingApi(async () => {30 await usingApi(async () => {45 const setCollectionLim = api.tx.nft.setCollectionLimits(45 const setCollectionLim = api.tx.nft.setCollectionLimits(46 collectionId,46 collectionId,47 {47 {48 AccountTokenOwnershipLimit,48 accountTokenOwnershipLimit,49 SponsoredMintSize,49 sponsoredMintSize,50 TokenLimit,50 tokenLimit,51 // tslint:disable-next-line: object-literal-sort-keys51 // tslint:disable-next-line: object-literal-sort-keys52 SponsorTimeout,52 sponsorTimeout,53 OwnerCanTransfer,53 ownerCanTransfer,54 OwnerCanDestroy,54 ownerCanDestroy,55 },55 },56 );56 );57 const subTx = await submitTransactionAsync(Alice, setCollectionLim);57 const subTx = await submitTransactionAsync(Alice, setCollectionLim);tests/src/contracts.test.tsdiffbeforeafterboth858586 // tslint:disable-next-line:no-unused-expression86 // tslint:disable-next-line:no-unused-expression87 expect(result.success).to.be.true;87 expect(result.success).to.be.true;88 expect(tokenBefore.Owner).to.be.deep.equal(normalizeAccountId(alice.address));88 expect(tokenBefore.owner).to.be.deep.equal(normalizeAccountId(alice.address));89 expect(tokenAfter.Owner).to.be.deep.equal(normalizeAccountId(bob.address));89 expect(tokenAfter.owner).to.be.deep.equal(normalizeAccountId(bob.address));90 });90 });91 });91 });9292141141142 const tokensAfter: any = (await api.query.nft.nftItemList.entries(collectionId) as any)142 const tokensAfter: any = (await api.query.nft.nftItemList.entries(collectionId) as any)143 .map((kv: any) => kv[1].toJSON())143 .map((kv: any) => kv[1].toJSON())144 .sort((a: any, b: any) => a.ConstData.localeCompare(b.ConstData));144 .sort((a: any, b: any) => a.constData.localeCompare(b.constData));145 expect(tokensAfter).to.be.deep.equal([145 expect(tokensAfter).to.be.deep.equal([146 {146 {147 Owner: bob.address,147 Owner: bob.address,198 expect(result.success).to.be.true;198 expect(result.success).to.be.true;199199200 const token: any = (await api.query.nft.nftItemList(collectionId, tokenId) as any).unwrap();200 const token: any = (await api.query.nft.nftItemList(collectionId, tokenId) as any).unwrap();201 expect(token.Owner.toString()).to.be.equal(charlie.address);201 expect(token.owner.toString()).to.be.equal(charlie.address);202 });202 });203 });203 });204204216 expect(result.success).to.be.true;216 expect(result.success).to.be.true;217217218 const token: any = (await api.query.nft.nftItemList(collectionId, tokenId) as any).unwrap();218 const token: any = (await api.query.nft.nftItemList(collectionId, tokenId) as any).unwrap();219 expect(token.VariableData.toString()).to.be.equal('0x121314');219 expect(token.variableData.toString()).to.be.equal('0x121314');220 });220 });221 });221 });222222tests/src/createMultipleItems.test.tsdiffbeforeafterboth24const expect = chai.expect;24const expect = chai.expect;252526interface ITokenDataType {26interface ITokenDataType {27 Owner: number[];27 owner: number[];28 ConstData: number[];28 constData: number[];29 VariableData: number[];29 variableData: number[];30}30}313132describe('Integration Test createMultipleItems(collection_id, owner, items_data):', () => {32describe('Integration Test createMultipleItems(collection_id, owner, items_data):', () => {46 const token2Data = (await api.query.nft.nftItemList(collectionId, 2)).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;47 const token3Data = (await api.query.nft.nftItemList(collectionId, 3)).toJSON() as unknown as ITokenDataType;484849 expect(token1Data.Owner).to.be.deep.equal(normalizeAccountId(Alice.address));49 expect(token1Data.owner).to.be.deep.equal(normalizeAccountId(Alice.address));50 expect(token2Data.Owner).to.be.deep.equal(normalizeAccountId(Alice.address));50 expect(token2Data.owner).to.be.deep.equal(normalizeAccountId(Alice.address));51 expect(token3Data.Owner).to.be.deep.equal(normalizeAccountId(Alice.address));51 expect(token3Data.owner).to.be.deep.equal(normalizeAccountId(Alice.address));525253 expect(token1Data.ConstData.toString()).to.be.equal('0x31');53 expect(token1Data.constData.toString()).to.be.equal('0x31');54 expect(token2Data.ConstData.toString()).to.be.equal('0x32');54 expect(token2Data.constData.toString()).to.be.equal('0x32');55 expect(token3Data.ConstData.toString()).to.be.equal('0x33');55 expect(token3Data.constData.toString()).to.be.equal('0x33');565657 expect(token1Data.VariableData.toString()).to.be.equal('0x31');57 expect(token1Data.variableData.toString()).to.be.equal('0x31');58 expect(token2Data.VariableData.toString()).to.be.equal('0x32');58 expect(token2Data.variableData.toString()).to.be.equal('0x32');59 expect(token3Data.VariableData.toString()).to.be.equal('0x33');59 expect(token3Data.variableData.toString()).to.be.equal('0x33');60 });60 });61 });61 });626276 await submitTransactionAsync(Alice, createMultipleItemsTx);76 await submitTransactionAsync(Alice, createMultipleItemsTx);77 const token1Data = (await api.query.nft.fungibleItemList(collectionId, Alice.address) as any).toJSON() as unknown as IFungibleTokenDataType;77 const token1Data = (await api.query.nft.fungibleItemList(collectionId, Alice.address) as any).toJSON() as unknown as IFungibleTokenDataType;787879 expect(token1Data.Value).to.be.equal(6); // 1 + 2 + 379 expect(token1Data.value).to.be.equal(6); // 1 + 2 + 380 });80 });81 });81 });8282100 const token2Data = (await api.query.nft.reFungibleItemList(collectionId, 2) 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;101 const token3Data = (await api.query.nft.reFungibleItemList(collectionId, 3) as any).toJSON() as unknown as IReFungibleTokenDataType;102102103 expect(token1Data.Owner[0].Owner).to.be.deep.equal(normalizeAccountId(Alice.address));103 expect(token1Data.owner[0].owner).to.be.deep.equal(normalizeAccountId(Alice.address));104 expect(token1Data.Owner[0].Fraction).to.be.equal(1);104 expect(token1Data.owner[0].fraction).to.be.equal(1);105105106 expect(token2Data.Owner[0].Owner).to.be.deep.equal(normalizeAccountId(Alice.address));106 expect(token2Data.owner[0].owner).to.be.deep.equal(normalizeAccountId(Alice.address));107 expect(token2Data.Owner[0].Fraction).to.be.equal(1);107 expect(token2Data.owner[0].fraction).to.be.equal(1);108108109 expect(token3Data.Owner[0].Owner).to.be.deep.equal(normalizeAccountId(Alice.address));109 expect(token3Data.owner[0].owner).to.be.deep.equal(normalizeAccountId(Alice.address));110 expect(token3Data.Owner[0].Fraction).to.be.equal(1);110 expect(token3Data.owner[0].fraction).to.be.equal(1);111111112 expect(token1Data.ConstData.toString()).to.be.equal('0x31');112 expect(token1Data.constData.toString()).to.be.equal('0x31');113 expect(token2Data.ConstData.toString()).to.be.equal('0x32');113 expect(token2Data.constData.toString()).to.be.equal('0x32');114 expect(token3Data.ConstData.toString()).to.be.equal('0x33');114 expect(token3Data.constData.toString()).to.be.equal('0x33');115115116 expect(token1Data.VariableData.toString()).to.be.equal('0x31');116 expect(token1Data.variableData.toString()).to.be.equal('0x31');117 expect(token2Data.VariableData.toString()).to.be.equal('0x32');117 expect(token2Data.variableData.toString()).to.be.equal('0x32');118 expect(token3Data.VariableData.toString()).to.be.equal('0x33');118 expect(token3Data.variableData.toString()).to.be.equal('0x33');119 });119 });120 });120 });121121125125126 const collectionId = await createCollectionExpectSuccess();126 const collectionId = await createCollectionExpectSuccess();127 await setCollectionLimitsExpectSuccess(alice, collectionId, {127 await setCollectionLimitsExpectSuccess(alice, collectionId, {128 TokenLimit: 2,128 tokenLimit: 2,129 });129 });130 const args = [130 const args = [131 { nft: ['A', 'A'] },131 { nft: ['A', 'A'] },167 const token2Data = (await api.query.nft.nftItemList(collectionId, 2)).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;168 const token3Data = (await api.query.nft.nftItemList(collectionId, 3)).toJSON() as unknown as ITokenDataType;169169170 expect(token1Data.Owner).to.be.deep.equal(normalizeAccountId(Bob.address));170 expect(token1Data.owner).to.be.deep.equal(normalizeAccountId(Bob.address));171 expect(token2Data.Owner).to.be.deep.equal(normalizeAccountId(Bob.address));171 expect(token2Data.owner).to.be.deep.equal(normalizeAccountId(Bob.address));172 expect(token3Data.Owner).to.be.deep.equal(normalizeAccountId(Bob.address));172 expect(token3Data.owner).to.be.deep.equal(normalizeAccountId(Bob.address));173173174 expect(token1Data.ConstData.toString()).to.be.equal('0x31');174 expect(token1Data.constData.toString()).to.be.equal('0x31');175 expect(token2Data.ConstData.toString()).to.be.equal('0x32');175 expect(token2Data.constData.toString()).to.be.equal('0x32');176 expect(token3Data.ConstData.toString()).to.be.equal('0x33');176 expect(token3Data.constData.toString()).to.be.equal('0x33');177177178 expect(token1Data.VariableData.toString()).to.be.equal('0x31');178 expect(token1Data.variableData.toString()).to.be.equal('0x31');179 expect(token2Data.VariableData.toString()).to.be.equal('0x32');179 expect(token2Data.variableData.toString()).to.be.equal('0x32');180 expect(token3Data.VariableData.toString()).to.be.equal('0x33');180 expect(token3Data.variableData.toString()).to.be.equal('0x33');181 });181 });182 });182 });183183197 await submitTransactionAsync(Bob, createMultipleItemsTx);197 await submitTransactionAsync(Bob, createMultipleItemsTx);198 const token1Data = (await api.query.nft.fungibleItemList(collectionId, Bob.address) as any).toJSON() as unknown as IFungibleTokenDataType;198 const token1Data = (await api.query.nft.fungibleItemList(collectionId, Bob.address) as any).toJSON() as unknown as IFungibleTokenDataType;199199200 expect(token1Data.Value).to.be.equal(6); // 1 + 2 + 3200 expect(token1Data.value).to.be.equal(6); // 1 + 2 + 3201 });201 });202 });202 });203203221 const token2Data = (await api.query.nft.reFungibleItemList(collectionId, 2) 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;222 const token3Data = (await api.query.nft.reFungibleItemList(collectionId, 3) as any).toJSON() as unknown as IReFungibleTokenDataType;223223224 expect(token1Data.Owner[0].Owner).to.be.deep.equal(normalizeAccountId(Bob.address));224 expect(token1Data.owner[0].owner).to.be.deep.equal(normalizeAccountId(Bob.address));225 expect(token1Data.Owner[0].Fraction).to.be.equal(1);225 expect(token1Data.owner[0].fraction).to.be.equal(1);226226227 expect(token2Data.Owner[0].Owner).to.be.deep.equal(normalizeAccountId(Bob.address));227 expect(token2Data.owner[0].owner).to.be.deep.equal(normalizeAccountId(Bob.address));228 expect(token2Data.Owner[0].Fraction).to.be.equal(1);228 expect(token2Data.owner[0].fraction).to.be.equal(1);229229230 expect(token3Data.Owner[0].Owner).to.be.deep.equal(normalizeAccountId(Bob.address));230 expect(token3Data.owner[0].owner).to.be.deep.equal(normalizeAccountId(Bob.address));231 expect(token3Data.Owner[0].Fraction).to.be.equal(1);231 expect(token3Data.owner[0].fraction).to.be.equal(1);232232233 expect(token1Data.ConstData.toString()).to.be.equal('0x31');233 expect(token1Data.constData.toString()).to.be.equal('0x31');234 expect(token2Data.ConstData.toString()).to.be.equal('0x32');234 expect(token2Data.constData.toString()).to.be.equal('0x32');235 expect(token3Data.ConstData.toString()).to.be.equal('0x33');235 expect(token3Data.constData.toString()).to.be.equal('0x33');236236237 expect(token1Data.VariableData.toString()).to.be.equal('0x31');237 expect(token1Data.variableData.toString()).to.be.equal('0x31');238 expect(token2Data.VariableData.toString()).to.be.equal('0x32');238 expect(token2Data.variableData.toString()).to.be.equal('0x32');239 expect(token3Data.VariableData.toString()).to.be.equal('0x33');239 expect(token3Data.variableData.toString()).to.be.equal('0x33');240 });240 });241 });241 });242});242});379379380 const collectionId = await createCollectionExpectSuccess();380 const collectionId = await createCollectionExpectSuccess();381 await setCollectionLimitsExpectSuccess(Alice, collectionId, {381 await setCollectionLimitsExpectSuccess(Alice, collectionId, {382 TokenLimit: 1,382 tokenLimit: 1,383 });383 });384 const args = [384 const args = [385 { nft: ['A', 'A'] },385 { nft: ['A', 'A'] },tests/src/destroyCollection.test.tsdiffbeforeafterboth67 });67 });68 it('fails when OwnerCanDestroy == false', async () => {68 it('fails when OwnerCanDestroy == false', async () => {69 const collectionId = await createCollectionExpectSuccess();69 const collectionId = await createCollectionExpectSuccess();70 await setCollectionLimitsExpectSuccess(alice, collectionId, { OwnerCanDestroy: false });70 await setCollectionLimitsExpectSuccess(alice, collectionId, { ownerCanDestroy: false });717172 await destroyCollectionExpectFailure(collectionId, '//Alice');72 await destroyCollectionExpectFailure(collectionId, '//Alice');73 });73 });tests/src/limits.test.tsdiffbeforeafterboth32 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 () => {33 3334 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 }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 () => {444445 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);616162 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 }717172 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);939394 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, { sponsorTimeout: 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');117 it('Collection limits have lower timeout value than chain limits, chain limits are enforced', async () => {117 it('Collection limits have lower timeout value than chain limits, chain limits are enforced', async () => {118118119 const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });119 const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });120 await setCollectionLimitsExpectSuccess(Alice, collectionId, { SponsorTimeout: 1 });120 await setCollectionLimitsExpectSuccess(Alice, collectionId, { sponsorTimeout: 1 });121 const tokenId = await createItemExpectSuccess(Alice, collectionId, 'NFT');121 const tokenId = await createItemExpectSuccess(Alice, collectionId, 'NFT');122 await setCollectionSponsorExpectSuccess(collectionId, Alice.address);122 await setCollectionSponsorExpectSuccess(collectionId, Alice.address);123 await confirmSponsorshipExpectSuccess(collectionId, '//Alice');123 await confirmSponsorshipExpectSuccess(collectionId, '//Alice');154154155 it('Collection limits have greater timeout value than chain limits, collection limits are enforced', async () => { 155 it('Collection limits have greater timeout value than chain limits, collection limits are enforced', async () => {156 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});156 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});157 await setCollectionLimitsExpectSuccess(Alice, collectionId, { SponsorTimeout: 7 });157 await setCollectionLimitsExpectSuccess(Alice, collectionId, { sponsorTimeout: 7 });158 const tokenId = await createItemExpectSuccess(Alice, collectionId, 'Fungible');158 const tokenId = await createItemExpectSuccess(Alice, collectionId, 'Fungible');159 await setCollectionSponsorExpectSuccess(collectionId, Alice.address);159 await setCollectionSponsorExpectSuccess(collectionId, Alice.address);160 await confirmSponsorshipExpectSuccess(collectionId, '//Alice');160 await confirmSponsorshipExpectSuccess(collectionId, '//Alice');180 it('Collection limits have lower timeout value than chain limits, chain limits are enforced', async () => {180 it('Collection limits have lower timeout value than chain limits, chain limits are enforced', async () => {181181182 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});182 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});183 await setCollectionLimitsExpectSuccess(Alice, collectionId, { SponsorTimeout: 1 });183 await setCollectionLimitsExpectSuccess(Alice, collectionId, { sponsorTimeout: 1 });184 const tokenId = await createItemExpectSuccess(Alice, collectionId, 'Fungible');184 const tokenId = await createItemExpectSuccess(Alice, collectionId, 'Fungible');185 await setCollectionSponsorExpectSuccess(collectionId, Alice.address);185 await setCollectionSponsorExpectSuccess(collectionId, Alice.address);186 await confirmSponsorshipExpectSuccess(collectionId, '//Alice');186 await confirmSponsorshipExpectSuccess(collectionId, '//Alice');219219220 it('Collection limits have greater timeout value than chain limits, collection limits are enforced', async () => { 220 it('Collection limits have greater timeout value than chain limits, collection limits are enforced', async () => {221 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible' }});221 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible' }});222 await setCollectionLimitsExpectSuccess(Alice, collectionId, { SponsorTimeout: 7 });222 await setCollectionLimitsExpectSuccess(Alice, collectionId, { sponsorTimeout: 7 });223 const tokenId = await createItemExpectSuccess(Alice, collectionId, 'ReFungible');223 const tokenId = await createItemExpectSuccess(Alice, collectionId, 'ReFungible');224 await setCollectionSponsorExpectSuccess(collectionId, Alice.address);224 await setCollectionSponsorExpectSuccess(collectionId, Alice.address);225 await confirmSponsorshipExpectSuccess(collectionId, '//Alice');225 await confirmSponsorshipExpectSuccess(collectionId, '//Alice');243 it('Collection limits have lower timeout value than chain limits, chain limits are enforced', async () => {243 it('Collection limits have lower timeout value than chain limits, chain limits are enforced', async () => {244244245 const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });245 const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });246 await setCollectionLimitsExpectSuccess(Alice, collectionId, { SponsorTimeout: 1 });246 await setCollectionLimitsExpectSuccess(Alice, collectionId, { sponsorTimeout: 1 });247 const tokenId = await createItemExpectSuccess(Alice, collectionId, 'NFT');247 const tokenId = await createItemExpectSuccess(Alice, collectionId, 'NFT');248 await setCollectionSponsorExpectSuccess(collectionId, Alice.address);248 await setCollectionSponsorExpectSuccess(collectionId, Alice.address);249 await confirmSponsorshipExpectSuccess(collectionId, '//Alice');249 await confirmSponsorshipExpectSuccess(collectionId, '//Alice');280280281 it.skip('Limits have 0 in tokens per address field, the chain limits are applied', async () => { 281 it.skip('Limits have 0 in tokens per address field, the chain limits are applied', async () => {282 const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });282 const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });283 await setCollectionLimitsExpectSuccess(Alice, collectionId, { AccountTokenOwnershipLimit: 0 });283 await setCollectionLimitsExpectSuccess(Alice, collectionId, { accountTokenOwnershipLimit: 0 });284 for(let i = 0; i < 10; i++){284 for(let i = 0; i < 10; i++){285 await createItemExpectSuccess(Alice, collectionId, 'NFT');285 await createItemExpectSuccess(Alice, collectionId, 'NFT');286 }286 }290 it('Limits have 0 in sponsor timeout, no limits are applied', async () => {290 it('Limits have 0 in sponsor timeout, no limits are applied', async () => {291291292 const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });292 const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });293 await setCollectionLimitsExpectSuccess(Alice, collectionId, { SponsorTimeout: 0 });293 await setCollectionLimitsExpectSuccess(Alice, collectionId, { sponsorTimeout: 0 });294 const tokenId = await createItemExpectSuccess(Alice, collectionId, 'NFT');294 const tokenId = await createItemExpectSuccess(Alice, collectionId, 'NFT');295 await setCollectionSponsorExpectSuccess(collectionId, Alice.address);295 await setCollectionSponsorExpectSuccess(collectionId, Alice.address);296 await confirmSponsorshipExpectSuccess(collectionId, '//Alice');296 await confirmSponsorshipExpectSuccess(collectionId, '//Alice');320320321 it('Limits have 0 in sponsor timeout, no limits are applied', async () => {321 it('Limits have 0 in sponsor timeout, no limits are applied', async () => {322 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});322 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});323 await setCollectionLimitsExpectSuccess(Alice, collectionId, { SponsorTimeout: 0 });323 await setCollectionLimitsExpectSuccess(Alice, collectionId, { sponsorTimeout: 0 });324 const tokenId = await createItemExpectSuccess(Alice, collectionId, 'Fungible');324 const tokenId = await createItemExpectSuccess(Alice, collectionId, 'Fungible');325 await setCollectionSponsorExpectSuccess(collectionId, Alice.address);325 await setCollectionSponsorExpectSuccess(collectionId, Alice.address);326 await confirmSponsorshipExpectSuccess(collectionId, '//Alice');326 await confirmSponsorshipExpectSuccess(collectionId, '//Alice');351351352 it.skip('Limits have 0 in tokens per address field, the chain limits are applied', async () => { 352 it.skip('Limits have 0 in tokens per address field, the chain limits are applied', async () => {353 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible' }});353 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible' }});354 await setCollectionLimitsExpectSuccess(Alice, collectionId, { AccountTokenOwnershipLimit: 0 });354 await setCollectionLimitsExpectSuccess(Alice, collectionId, { accountTokenOwnershipLimit: 0 });355 for(let i = 0; i < 10; i++){355 for(let i = 0; i < 10; i++){356 await createItemExpectSuccess(Alice, collectionId, 'ReFungible');356 await createItemExpectSuccess(Alice, collectionId, 'ReFungible');357 }357 }361 it('Limits have 0 in sponsor timeout, no limits are applied', async () => {361 it('Limits have 0 in sponsor timeout, no limits are applied', async () => {362362363 const collectionId = await createCollectionExpectSuccess({ mode: { type: 'ReFungible' } });363 const collectionId = await createCollectionExpectSuccess({ mode: { type: 'ReFungible' } });364 await setCollectionLimitsExpectSuccess(Alice, collectionId, { SponsorTimeout: 0 });364 await setCollectionLimitsExpectSuccess(Alice, collectionId, { sponsorTimeout: 0 });365 const tokenId = await createItemExpectSuccess(Alice, collectionId, 'ReFungible');365 const tokenId = await createItemExpectSuccess(Alice, collectionId, 'ReFungible');366 await setCollectionSponsorExpectSuccess(collectionId, Alice.address);366 await setCollectionSponsorExpectSuccess(collectionId, Alice.address);367 await confirmSponsorshipExpectSuccess(collectionId, '//Alice');367 await confirmSponsorshipExpectSuccess(collectionId, '//Alice');tests/src/pallet-presence.test.tsdiffbeforeafterboth8import usingApi from './substrate/substrate-api';8import usingApi from './substrate/substrate-api';9910function getModuleNames(api: ApiPromise): string[] {10function getModuleNames(api: ApiPromise): string[] {11 return api.runtimeMetadata.asLatest.modules.map(m => m.name.toString().toLowerCase());11 return api.runtimeMetadata.asLatest.pallets.map(m => m.name.toString().toLowerCase());12}12}131314// Pallets that must always be present14// Pallets that must always be presenttests/src/removeCollectionAdmin.test.tsdiffbeforeafterboth20 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: any = (await api.query.nft.collectionById(collectionId)).toJSON();23 expect(collection.Owner).to.be.deep.eq(Alice.address);23 expect(collection.owner).to.be.deep.eq(Alice.address);24 // first - add collection admin Bob24 // first - add collection admin Bob25 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);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: any = (await api.query.nft.collectionById(collectionId)).toJSON();47 expect(collection.Owner).to.be.deep.eq(Alice.address);47 expect(collection.owner).to.be.deep.eq(Alice.address);48 // first - add collection admin Bob48 // first - add collection admin Bob49 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);tests/src/setChainLimits.test.tsdiffbeforeafterboth25 bob = privateKey('//Bob');25 bob = privateKey('//Bob');26 dave = privateKey('//Dave');26 dave = privateKey('//Dave');27 limits = {27 limits = {28 CollectionNumbersLimit : 1,28 collectionNumbersLimit : 1,29 AccountTokenOwnershipLimit: 1,29 accountTokenOwnershipLimit: 1,30 CollectionsAdminsLimit: 1,30 collectionsAdminsLimit: 1,31 CustomDataLimit: 1,31 customDataLimit: 1,32 NftSponsorTransferTimeout: 1,32 nftSponsorTransferTimeout: 1,33 FungibleSponsorTransferTimeout: 1,33 fungibleSponsorTransferTimeout: 1,34 RefungibleSponsorTransferTimeout: 1,34 refungibleSponsorTransferTimeout: 1,35 OffchainSchemaLimit: 1,35 offchainSchemaLimit: 1,36 VariableOnChainSchemaLimit: 1,36 variableOnChainSchemaLimit: 1,37 ConstOnChainSchemaLimit: 1,37 constOnChainSchemaLimit: 1,38 };38 };39 });39 });40 });40 });tests/src/setCollectionLimits.test.tsdiffbeforeafterboth46 tx = api.tx.nft.setCollectionLimits(46 tx = api.tx.nft.setCollectionLimits(47 collectionIdForTesting,47 collectionIdForTesting,48 {48 {49 AccountTokenOwnershipLimit: accountTokenOwnershipLimit,49 accountTokenOwnershipLimit: accountTokenOwnershipLimit,50 SponsoredMintSize: sponsoredDataSize,50 sponsoredMintSize: sponsoredDataSize,51 TokenLimit: tokenLimit,51 tokenLimit: tokenLimit,52 SponsorTimeout: sponsorTimeout,52 sponsorTimeout: sponsorTimeout,53 OwnerCanTransfer: true,53 ownerCanTransfer: true,54 OwnerCanDestroy: true,54 ownerCanDestroy: true,55 },55 },56 );56 );57 const events = await submitTransactionAsync(alice, tx);57 const events = await submitTransactionAsync(alice, tx);626263 // tslint:disable-next-line:no-unused-expression63 // tslint:disable-next-line:no-unused-expression64 expect(result.success).to.be.true;64 expect(result.success).to.be.true;65 expect(collectionInfo.Limits.AccountTokenOwnershipLimit).to.be.equal(accountTokenOwnershipLimit);65 expect(collectionInfo.limits.accountTokenOwnershipLimit).to.be.equal(accountTokenOwnershipLimit);66 expect(collectionInfo.Limits.SponsoredDataSize).to.be.equal(sponsoredDataSize);66 expect(collectionInfo.limits.sponsoredDataSize).to.be.equal(sponsoredDataSize);67 expect(collectionInfo.Limits.TokenLimit).to.be.equal(tokenLimit);67 expect(collectionInfo.limits.tokenLimit).to.be.equal(tokenLimit);68 expect(collectionInfo.Limits.SponsorTimeout).to.be.equal(sponsorTimeout);68 expect(collectionInfo.limits.sponsorTimeout).to.be.equal(sponsorTimeout);69 expect(collectionInfo.Limits.OwnerCanTransfer).to.be.true;69 expect(collectionInfo.limits.ownerCanTransfer).to.be.true;70 expect(collectionInfo.Limits.OwnerCanDestroy).to.be.true;70 expect(collectionInfo.limits.ownerCanDestroy).to.be.true;71 });71 });72 });72 });737374 it('Set the same token limit twice', async () => {74 it('Set the same token limit twice', async () => {75 await usingApi(async (api: ApiPromise) => {75 await usingApi(async (api: ApiPromise) => {767677 const collectionLimits = {77 const collectionLimits = {78 AccountTokenOwnershipLimit: accountTokenOwnershipLimit,78 accountTokenOwnershipLimit: accountTokenOwnershipLimit,79 SponsoredMintSize: sponsoredDataSize,79 sponsoredMintSize: sponsoredDataSize,80 TokenLimit: tokenLimit,80 tokenLimit: tokenLimit,81 SponsorTimeout: sponsorTimeout,81 sponsorTimeout: sponsorTimeout,82 OwnerCanTransfer: true,82 ownerCanTransfer: true,83 OwnerCanDestroy: true,83 ownerCanDestroy: true,84 };84 };858586 // The first time86 // The first time103103104 // tslint:disable-next-line:no-unused-expression104 // tslint:disable-next-line:no-unused-expression105 expect(result1.success).to.be.true;105 expect(result1.success).to.be.true;106 expect(collectionInfo1.Limits.TokenLimit).to.be.equal(tokenLimit);106 expect(collectionInfo1.limits.tokenLimit).to.be.equal(tokenLimit);107 expect(result2.success).to.be.true;107 expect(result2.success).to.be.true;108 expect(collectionInfo2.Limits.TokenLimit).to.be.equal(tokenLimit);108 expect(collectionInfo2.limits.tokenLimit).to.be.equal(tokenLimit);109 });109 });110 });110 });111111184 it('fails when trying to enable OwnerCanTransfer after it was disabled', async () => {184 it('fails when trying to enable OwnerCanTransfer after it was disabled', async () => {185 const collectionId = await createCollectionExpectSuccess();185 const collectionId = await createCollectionExpectSuccess();186 await setCollectionLimitsExpectSuccess(alice, collectionId, { 186 await setCollectionLimitsExpectSuccess(alice, collectionId, {187 AccountTokenOwnershipLimit: accountTokenOwnershipLimit,187 accountTokenOwnershipLimit: accountTokenOwnershipLimit,188 SponsoredMintSize: sponsoredDataSize,188 sponsoredMintSize: sponsoredDataSize,189 TokenLimit: tokenLimit,189 tokenLimit: tokenLimit,190 SponsorTimeout: sponsorTimeout,190 sponsorTimeout: sponsorTimeout,191 OwnerCanTransfer: false,191 ownerCanTransfer: false,192 OwnerCanDestroy: true,192 ownerCanDestroy: true,193 });193 });194 await setCollectionLimitsExpectFailure(alice, collectionId, { 194 await setCollectionLimitsExpectFailure(alice, collectionId, {195 AccountTokenOwnershipLimit: accountTokenOwnershipLimit,195 accountTokenOwnershipLimit: accountTokenOwnershipLimit,196 SponsoredMintSize: sponsoredDataSize,196 sponsoredMintSize: sponsoredDataSize,197 TokenLimit: tokenLimit,197 tokenLimit: tokenLimit,198 SponsorTimeout: sponsorTimeout,198 sponsorTimeout: sponsorTimeout,199 OwnerCanTransfer: true,199 ownerCanTransfer: true,200 OwnerCanDestroy: true,200 ownerCanDestroy: true,201 });201 });202 });202 });203203204 it('fails when trying to enable OwnerCanDestroy after it was disabled', async () => {204 it('fails when trying to enable OwnerCanDestroy after it was disabled', async () => {205 const collectionId = await createCollectionExpectSuccess();205 const collectionId = await createCollectionExpectSuccess();206 await setCollectionLimitsExpectSuccess(alice, collectionId, {206 await setCollectionLimitsExpectSuccess(alice, collectionId, {207 AccountTokenOwnershipLimit: accountTokenOwnershipLimit,207 accountTokenOwnershipLimit: accountTokenOwnershipLimit,208 SponsoredMintSize: sponsoredDataSize,208 sponsoredMintSize: sponsoredDataSize,209 TokenLimit: tokenLimit,209 tokenLimit: tokenLimit,210 SponsorTimeout: sponsorTimeout,210 sponsorTimeout: sponsorTimeout,211 OwnerCanTransfer: true,211 ownerCanTransfer: true,212 OwnerCanDestroy: false,212 ownerCanDestroy: false,213 });213 });214 await setCollectionLimitsExpectFailure(alice, collectionId, { 214 await setCollectionLimitsExpectFailure(alice, collectionId, {215 AccountTokenOwnershipLimit: accountTokenOwnershipLimit,215 accountTokenOwnershipLimit: accountTokenOwnershipLimit,216 SponsoredMintSize: sponsoredDataSize,216 sponsoredMintSize: sponsoredDataSize,217 TokenLimit: tokenLimit,217 tokenLimit: tokenLimit,218 SponsorTimeout: sponsorTimeout,218 sponsorTimeout: sponsorTimeout,219 OwnerCanTransfer: true,219 ownerCanTransfer: true,220 OwnerCanDestroy: true,220 ownerCanDestroy: true,221 });221 });222 });222 });223223226226227 const collectionId = await createCollectionExpectSuccess();227 const collectionId = await createCollectionExpectSuccess();228 const collectionLimits = {228 const collectionLimits = {229 AccountTokenOwnershipLimit: accountTokenOwnershipLimit,229 accountTokenOwnershipLimit: accountTokenOwnershipLimit,230 SponsoredMintSize: sponsoredDataSize,230 sponsoredMintSize: sponsoredDataSize,231 TokenLimit: tokenLimit,231 tokenLimit: tokenLimit,232 SponsorTimeout: sponsorTimeout,232 sponsorTimeout: sponsorTimeout,233 OwnerCanTransfer: true,233 ownerCanTransfer: true,234 OwnerCanDestroy: true,234 ownerCanDestroy: true,235 };235 };236236237 // The first time237 // The first time238 await setCollectionLimitsExpectSuccess(alice, collectionId, collectionLimits);238 await setCollectionLimitsExpectSuccess(alice, collectionId, collectionLimits);239239240 // The second time - higher token limit240 // The second time - higher token limit241 collectionLimits.TokenLimit += 1;241 collectionLimits.tokenLimit += 1;242 await setCollectionLimitsExpectFailure(alice, collectionId, collectionLimits);242 await setCollectionLimitsExpectFailure(alice, collectionId, collectionLimits);243 });243 });244 });244 });tests/src/setConstOnChainSchema.test.tsdiffbeforeafterboth38 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: any = (await api.query.nft.collectionById(collectionId)).toJSON();41 expect(collection.Owner).to.be.eq(Alice.address);41 expect(collection.owner).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 });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: any = (await api.query.nft.collectionById(collectionId)).toJSON();51 expect(collection.Owner).to.be.eq(Alice.address);51 expect(collection.owner).to.be.eq(Alice.address);52 await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);52 await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);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);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: any = (await api.query.nft.collectionById(collectionId)).toJSON();64 expect(collection.ConstOnChainSchema.toString()).to.be.eq(Shema);64 expect(collection.constOnChainSchema.toString()).to.be.eq(Shema);656566 });66 });67 });67 });99 await usingApi(async (api) => {99 await usingApi(async (api) => {100 const collectionId = await createCollectionExpectSuccess();100 const collectionId = await createCollectionExpectSuccess();101 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();101 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();102 expect(collection.Owner).to.be.eq(Alice.address);102 expect(collection.owner).to.be.eq(Alice.address);103 const setShema = api.tx.nft.setConstOnChainSchema(collectionId, Shema);103 const setShema = api.tx.nft.setConstOnChainSchema(collectionId, Shema);104 await expect(submitTransactionExpectFailAsync(Bob, setShema)).to.be.rejected;104 await expect(submitTransactionExpectFailAsync(Bob, setShema)).to.be.rejected;105 });105 });tests/src/setOffchainSchema.test.tsdiffbeforeafterboth39 await setOffchainSchemaExpectSuccess(alice, collectionId, DATA);39 await setOffchainSchemaExpectSuccess(alice, collectionId, DATA);40 const collection = await queryCollectionExpectSuccess(collectionId);40 const collection = await queryCollectionExpectSuccess(collectionId);414142 expect(collection.OffchainSchema).to.be.equal('0x' + Buffer.from(DATA).toString('hex'));42 expect(collection.offchainSchema).to.be.equal('0x' + Buffer.from(DATA).toString('hex'));43 });43 });444445 it('execute setOffchainSchema (collection admin), verify data was set', async () => {45 it('execute setOffchainSchema (collection admin), verify data was set', async () => {48 await setOffchainSchemaExpectSuccess(bob, collectionId, DATA);48 await setOffchainSchemaExpectSuccess(bob, collectionId, DATA);49 const collection = await queryCollectionExpectSuccess(collectionId);49 const collection = await queryCollectionExpectSuccess(collectionId);505051 expect(collection.OffchainSchema).to.be.equal('0x' + Buffer.from(DATA).toString('hex'));51 expect(collection.offchainSchema).to.be.equal('0x' + Buffer.from(DATA).toString('hex'));52 });52 });53});53});5454tests/src/setSchemaVersion.test.tsdiffbeforeafterboth66 // tslint:disable-next-line:no-unused-expression66 // tslint:disable-next-line:no-unused-expression67 expect(collectionInfo).to.be.exist;67 expect(collectionInfo).to.be.exist;68 // tslint:disable-next-line:no-unused-expression68 // tslint:disable-next-line:no-unused-expression69 expect(collectionInfo ? collectionInfo.SchemaVersion.toString() : '').to.be.equal('Unique');69 expect(collectionInfo ? collectionInfo.schemaVersion.toString() : '').to.be.equal('Unique');70 });70 });71 });71 });72});72});92 // tslint:disable-next-line:no-unused-expression92 // tslint:disable-next-line:no-unused-expression93 expect(collectionInfo).to.be.exist;93 expect(collectionInfo).to.be.exist;94 // tslint:disable-next-line:no-unused-expression94 // tslint:disable-next-line:no-unused-expression95 expect(collectionInfo ? collectionInfo.SchemaVersion.toString() : '').to.be.equal('Unique');95 expect(collectionInfo ? collectionInfo.schemaVersion.toString() : '').to.be.equal('Unique');96 });96 });97 });97 });9898107 // tslint:disable-next-line:no-unused-expression107 // tslint:disable-next-line:no-unused-expression108 expect(collectionInfo).to.be.exist;108 expect(collectionInfo).to.be.exist;109 // tslint:disable-next-line:no-unused-expression109 // tslint:disable-next-line:no-unused-expression110 expect(collectionInfo ? collectionInfo.SchemaVersion.toString() : '').to.be.equal('ImageURL');110 expect(collectionInfo ? collectionInfo.schemaVersion.toString() : '').to.be.equal('ImageURL');111 });111 });112 });112 });113});113});tests/src/setVariableMetaData.test.tsdiffbeforeafterboth45 await usingApi(async api => {45 await usingApi(async api => {46 const item: any = (await api.query.nft.nftItemList(collectionId, tokenId) as any).unwrap();46 const item: any = (await api.query.nft.nftItemList(collectionId, tokenId) as any).unwrap();474748 expect(Array.from(item.VariableData)).to.deep.equal(Array.from(data));48 expect(Array.from(item.variableData)).to.deep.equal(Array.from(data));49 });49 });50 });50 });51});51});76 await usingApi(async api => {76 await usingApi(async api => {77 const item: any = (await api.query.nft.nftItemList(collectionId, tokenId) as any).unwrap();77 const item: any = (await api.query.nft.nftItemList(collectionId, tokenId) as any).unwrap();787879 expect(Array.from(item.VariableData)).to.deep.equal(Array.from(data));79 expect(Array.from(item.variableData)).to.deep.equal(Array.from(data));80 });80 });81 });81 });82});82});tests/src/setVariableMetadataSponsoringRateLimit.test.tsdiffbeforeafterboth33 await setCollectionSponsorExpectSuccess(collectionId, alice.address);33 await setCollectionSponsorExpectSuccess(collectionId, alice.address);34 await confirmSponsorshipExpectSuccess(collectionId);34 await confirmSponsorshipExpectSuccess(collectionId);35 await setCollectionLimitsExpectSuccess(alice, collectionId, {35 await setCollectionLimitsExpectSuccess(alice, collectionId, {36 SponsoredDataRateLimit: 0,36 sponsoredDataRateLimit: 0,37 });37 });383839 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', userWithNoBalance.address);39 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', userWithNoBalance.address);46 await setCollectionSponsorExpectSuccess(collectionId, alice.address);46 await setCollectionSponsorExpectSuccess(collectionId, alice.address);47 await confirmSponsorshipExpectSuccess(collectionId);47 await confirmSponsorshipExpectSuccess(collectionId);48 await setCollectionLimitsExpectSuccess(alice, collectionId, {48 await setCollectionLimitsExpectSuccess(alice, collectionId, {49 SponsoredDataRateLimit: 10,49 sponsoredDataRateLimit: 10,50 });50 });515152 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', userWithNoBalance.address);52 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', userWithNoBalance.address);59 await setCollectionSponsorExpectSuccess(collectionId, alice.address);59 await setCollectionSponsorExpectSuccess(collectionId, alice.address);60 await confirmSponsorshipExpectSuccess(collectionId);60 await confirmSponsorshipExpectSuccess(collectionId);61 await setCollectionLimitsExpectSuccess(alice, collectionId, {61 await setCollectionLimitsExpectSuccess(alice, collectionId, {62 SponsoredDataRateLimit: 0,62 sponsoredDataRateLimit: 0,63 SponsoredDataSize: 1,63 sponsoredDataSize: 1,64 });64 });65 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', userWithNoBalance.address);65 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', userWithNoBalance.address);6666tests/src/setVariableOnChainSchema.test.tsdiffbeforeafterboth38 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: any = (await api.query.nft.collectionById(collectionId)).toJSON();41 expect(collection.Owner).to.be.eq(Alice.address);41 expect(collection.owner).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 });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: any = (await api.query.nft.collectionById(collectionId)).toJSON();53 expect(collection.VariableOnChainSchema.toString()).to.be.eq(Schema);53 expect(collection.variableOnChainSchema.toString()).to.be.eq(Schema);545455 });55 });56 });56 });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: any = (await api.query.nft.collectionById(collectionId)).toJSON();65 expect(collection.Owner).to.be.eq(Alice.address);65 expect(collection.owner).to.be.eq(Alice.address);66 await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);66 await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);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);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: any = (await api.query.nft.collectionById(collectionId)).toJSON();79 expect(collection.VariableOnChainSchema.toString()).to.be.eq(Schema);79 expect(collection.variableOnChainSchema.toString()).to.be.eq(Schema);808081 });81 });82 });82 });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: any = (await api.query.nft.collectionById(collectionId)).toJSON();117 expect(collection.Owner).to.be.eq(Alice.address);117 expect(collection.owner).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 });tests/src/substrate/substrate-api.tsdiffbeforeafterboth11import config from '../config';11import config from '../config';12import promisifySubstrate from './promisify-substrate';12import promisifySubstrate from './promisify-substrate';13import { ApiOptions, SubmittableExtrinsic, ApiTypes } from '@polkadot/api/types';13import { ApiOptions, SubmittableExtrinsic, ApiTypes } from '@polkadot/api/types';14import rtt from '../../../runtime_types.json';151416function defaultApiOptions(): ApiOptions {15function defaultApiOptions(): ApiOptions {17 const wsProvider = new WsProvider(config.substrateUrl);16 const wsProvider = new WsProvider(config.substrateUrl);18 return {17 return {19 provider: wsProvider, types: rtt, signedExtensions: {18 provider: wsProvider, signedExtensions: {20 ContractHelpers: {19 ContractHelpers: {21 extrinsic: {},20 extrinsic: {},22 payload: {},21 payload: {},30 const api: ApiPromise = new ApiPromise(settings);29 const api: ApiPromise = new ApiPromise(settings);31 let result: T = null as unknown as T;30 let result: T = null as unknown as T;323133 // TODO: Remove, this is temporary: Filter unneeded API output 32 // TODO: Remove, this is temporary: Filter unneeded API output34 // (Jaco promised it will be removed in the next version)33 // (Jaco promised it will be removed in the next version)35 const consoleErr = console.error;34 const consoleErr = console.error;36 const consoleLog = console.log;35 const consoleLog = console.log;tests/src/transferFrom.test.tsdiffbeforeafterboth306 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 });310310311 await transferFromExpectFail(collectionId, itemId, Alice, Bob, Charlie);311 await transferFromExpectFail(collectionId, itemId, Alice, Bob, Charlie);312 });312 });tests/src/types.tsdiffbeforeafterboth6import BN from 'bn.js';6import BN from 'bn.js';778export interface ICollectionInterface {8export interface ICollectionInterface {9 Access: string;9 access: string;10 id: number;10 id: number;11 DecimalPoints: BN;11 decimalPoints: BN;12 // constOnChainSchema12 // constOnChainSchema13 Description: [BN, BN]; // utf1613 description: [BN, BN]; // utf1614 isReFungible: boolean;14 isReFungible: boolean;15 Limits: {15 limits: {16 AccountTokenOwnershipLimit: number;16 accountTokenOwnershipLimit: number;17 SponsoredDataSize: number;17 sponsoredDataSize: number;18 SponsoredDataRateLimit?: number,18 sponsoredDataRateLimit?: number,19 TokenLimit: number;19 tokenLimit: number;20 SponsorTimeout: number;20 sponsorTimeout: number;21 OwnerCanTransfer: boolean;21 ownerCanTransfer: boolean;22 OwnerCanDestroy: boolean;22 ownerCanDestroy: boolean;23 };23 };24 MintMode: boolean;24 mintMode: boolean;25 Mode: {25 mode: {26 Nft: null;26 nft: null;27 };27 };28 Name: [BN, BN]; // utf1628 name: [BN, BN]; // utf1629 OffchainSchema: [Uint8Array];29 offchainSchema: [Uint8Array];30 Owner: [Uint8Array];30 owner: [Uint8Array];31 SchemaVersion: string;31 schemaVersion: string;32 // prefix32 // prefix33 // sponsor33 // sponsor34 // tokenPrefix34 // tokenPrefixtests/src/util/helpers.tsdiffbeforeafterboth84}84}858586interface IReFungibleOwner {86interface IReFungibleOwner {87 Fraction: BN;87 fraction: BN;88 Owner: number[];88 owner: number[];89}89}909091interface ITokenDataType {91interface ITokenDataType {92 Owner: IKeyringPair;92 owner: IKeyringPair;93 ConstData: number[];93 constData: number[];94 VariableData: number[];94 variableData: number[];95}95}969697interface IGetMessage {97interface IGetMessage {101}101}102102103export interface IFungibleTokenDataType {103export interface IFungibleTokenDataType {104 Value: number;104 value: number;105}105}106106107export interface IChainLimits {107export interface IChainLimits {108 CollectionNumbersLimit: number;108 collectionNumbersLimit: number;109 AccountTokenOwnershipLimit: number;109 accountTokenOwnershipLimit: number;110 CollectionsAdminsLimit: number;110 collectionsAdminsLimit: number;111 CustomDataLimit: number;111 customDataLimit: number;112 NftSponsorTransferTimeout: number;112 nftSponsorTransferTimeout: number;113 FungibleSponsorTransferTimeout: number;113 fungibleSponsorTransferTimeout: number;114 RefungibleSponsorTransferTimeout: number;114 refungibleSponsorTransferTimeout: number;115 OffchainSchemaLimit: number;115 offchainSchemaLimit: number;116 VariableOnChainSchemaLimit: number;116 variableOnChainSchemaLimit: number;117 ConstOnChainSchemaLimit: number;117 constOnChainSchemaLimit: number;118}118}119119120export interface IReFungibleTokenDataType {120export interface IReFungibleTokenDataType {121 Owner: IReFungibleOwner[];121 owner: IReFungibleOwner[];122 ConstData: number[];122 constData: number[];123 VariableData: number[];123 variableData: number[];124}124}125125126export function nftEventMessage(events: EventRecord[]): IGetMessage {126export function nftEventMessage(events: EventRecord[]): IGetMessage {290 // tslint:disable-next-line:no-unused-expression290 // tslint:disable-next-line:no-unused-expression291 expect(collection).to.be.not.null;291 expect(collection).to.be.not.null;292 expect(BcollectionCount).to.be.equal(AcollectionCount + 1, 'Error: NFT collection NOT created.');292 expect(BcollectionCount).to.be.equal(AcollectionCount + 1, 'Error: NFT collection NOT created.');293 expect(collection.Owner).to.be.equal(toSubstrateAddress(alicesPublicKey));293 expect(collection.owner).to.be.equal(toSubstrateAddress(alicesPublicKey));294 expect(utf16ToStr(collection.Name)).to.be.equal(name);294 expect(utf16ToStr(collection.name)).to.be.equal(name);295 expect(utf16ToStr(collection.Description)).to.be.equal(description);295 expect(utf16ToStr(collection.description)).to.be.equal(description);296 expect(hexToStr(collection.TokenPrefix)).to.be.equal(tokenPrefix);296 expect(hexToStr(collection.tokenPrefix)).to.be.equal(tokenPrefix);297297298 collectionId = result.collectionId;298 collectionId = result.collectionId;299 });299 });400400401export async function queryCollectionLimits(collectionId: number) {401export async function queryCollectionLimits(collectionId: number) {402 return await usingApi(async (api) => {402 return await usingApi(async (api) => {403 return ((await api.query.nft.collectionById(collectionId)).toJSON() as any).Limits;403 return ((await api.query.nft.collectionById(collectionId)).toJSON() as any).limits;404 });404 });405}405}406406442442443 // What to expect443 // What to expect444 expect(result.success).to.be.true;444 expect(result.success).to.be.true;445 expect(collection.Sponsorship).to.deep.equal({445 expect(collection.sponsorship).to.deep.equal({446 unconfirmed: sponsor,446 unconfirmed: sponsor,447 });447 });448 });448 });462462463 // What to expect463 // What to expect464 expect(result.success).to.be.true;464 expect(result.success).to.be.true;465 expect(collection.Sponsorship).to.be.deep.equal({ disabled: null });465 expect(collection.sponsorship).to.be.deep.equal({ disabled: null });466 });466 });467}467}468468500500501 // What to expect501 // What to expect502 expect(result.success).to.be.true;502 expect(result.success).to.be.true;503 expect(collection.Sponsorship).to.be.deep.equal({503 expect(collection.sponsorship).to.be.deep.equal({504 confirmed: sender.address,504 confirmed: sender.address,505 });505 });506 });506 });758 expect(result.success).to.be.true;758 expect(result.success).to.be.true;759 if (type === 'NFT') {759 if (type === 'NFT') {760 const nftItemData = (await api.query.nft.nftItemList(collectionId, tokenId) as any).toJSON() as ITokenDataType;760 const nftItemData = (await api.query.nft.nftItemList(collectionId, tokenId) as any).toJSON() as ITokenDataType;761 expect(nftItemData.Owner).to.be.deep.equal(to);761 expect(nftItemData.owner).to.be.deep.equal(to);762 }762 }763 if (type === 'Fungible') {763 if (type === 'Fungible') {764 const balanceAfter = (await api.query.nft.fungibleItemList(collectionId, toSubstrateAddress(to)) as any).Value as unknown as BN;764 const balanceAfter = (await api.query.nft.fungibleItemList(collectionId, toSubstrateAddress(to)) as any).value as unknown as BN;765 expect(balanceAfter.sub(balanceBefore).toString()).to.be.equal(value.toString());765 expect(balanceAfter.sub(balanceBefore).toString()).to.be.equal(value.toString());766 }766 }767 if (type === 'ReFungible') {767 if (type === 'ReFungible') {768 const nftItemData =768 const nftItemData =769 (await api.query.nft.reFungibleItemList(collectionId, tokenId) as any).toJSON() as IReFungibleTokenDataType;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));770 expect(nftItemData.owner[0].owner).to.be.deep.equal(normalizeAccountId(to));771 expect(nftItemData.Owner[0].Fraction).to.be.equal(value);771 expect(nftItemData.owner[0].fraction).to.be.equal(value);772 }772 }773 });773 });774}774}844 const recipientBalanceBefore = new BigNumber((await api.query.system.account(recipient.address)).data.free.toString());844 const recipientBalanceBefore = new BigNumber((await api.query.system.account(recipient.address)).data.free.toString());845845846 const nftItemDataBefore = (await api.query.nft.nftItemList(collectionId, tokenId)).toJSON() as any as ITokenDataType;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);847 expect(toSubstrateAddress(nftItemDataBefore.owner)).to.be.equal(sender.address);848848849 // sleep for 4 blocks849 // sleep for 4 blocks850 await new Promise(resolve => setTimeout(resolve, blockTimeMs * (blockSchedule + 1)));850 await new Promise(resolve => setTimeout(resolve, blockTimeMs * (blockSchedule + 1)));851851852 const recipientBalanceAfter = new BigNumber((await api.query.system.account(recipient.address)).data.free.toString());852 const recipientBalanceAfter = new BigNumber((await api.query.system.account(recipient.address)).data.free.toString());853853854 const nftItemData = (await api.query.nft.nftItemList(collectionId, tokenId)).toJSON() as unknown as ITokenDataType;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);855 expect(toSubstrateAddress(nftItemData.owner)).to.be.equal(recipient.address);856 expect(recipientBalanceAfter.toNumber()).to.be.equal(recipientBalanceBefore.toNumber());856 expect(recipientBalanceAfter.toNumber()).to.be.equal(recipientBalanceBefore.toNumber());857 });857 });858}858}886 expect(result.value.toString()).to.be.equal(value.toString());886 expect(result.value.toString()).to.be.equal(value.toString());887 if (type === 'NFT') {887 if (type === 'NFT') {888 const nftItemData = (await api.query.nft.nftItemList(collectionId, tokenId)).toJSON() as unknown as ITokenDataType;888 const nftItemData = (await api.query.nft.nftItemList(collectionId, tokenId)).toJSON() as unknown as ITokenDataType;889 expect(nftItemData.Owner).to.be.deep.equal(to);889 expect(nftItemData.owner).to.be.deep.equal(to);890 }890 }891 if (type === 'Fungible') {891 if (type === 'Fungible') {892 const balanceAfter = (await api.query.nft.fungibleItemList(collectionId, toSubstrateAddress(to)) as any).Value as unknown as BN;892 const balanceAfter = (await api.query.nft.fungibleItemList(collectionId, toSubstrateAddress(to)) as any).value as unknown as BN;893 expect(balanceAfter.sub(balanceBefore).toString()).to.be.equal(value.toString());893 expect(balanceAfter.sub(balanceBefore).toString()).to.be.equal(value.toString());894 }894 }895 if (type === 'ReFungible') {895 if (type === 'ReFungible') {896 const nftItemData =896 const nftItemData =897 (await api.query.nft.reFungibleItemList(collectionId, tokenId)).toJSON() as unknown as IReFungibleTokenDataType;897 (await api.query.nft.reFungibleItemList(collectionId, tokenId)).toJSON() as unknown as IReFungibleTokenDataType;898 const expectedOwner = toSubstrateAddress(to);898 const expectedOwner = toSubstrateAddress(to);899 const ownerIndex = nftItemData.Owner.findIndex(v => toSubstrateAddress(v.Owner as any as string) == expectedOwner);899 const ownerIndex = nftItemData.owner.findIndex(v => toSubstrateAddress(v.owner as any as string) == expectedOwner);900 expect(ownerIndex).to.not.equal(-1);900 expect(ownerIndex).to.not.equal(-1);901 expect(nftItemData.Owner[ownerIndex].Owner).to.be.deep.equal(normalizeAccountId(to));901 expect(nftItemData.owner[ownerIndex].owner).to.be.deep.equal(normalizeAccountId(to));902 expect(nftItemData.Owner[ownerIndex].Fraction).to.be.greaterThanOrEqual(value as number);902 expect(nftItemData.owner[ownerIndex].fraction).to.be.greaterThanOrEqual(value as number);903 }903 }904 });904 });905}905}942 owner: string,942 owner: string,943) {943) {944 return await usingApi(async (api) => {944 return await usingApi(async (api) => {945 const response = (await api.query.nft.fungibleItemList(collectionId, owner)).toJSON() as unknown as { Value: string };945 const response = (await api.query.nft.fungibleItemList(collectionId, owner)).toJSON() as unknown as { value: string };946 return BigInt(response.Value);946 return BigInt(response.value);947 });947 });948}948}949949970 const to = normalizeAccountId(owner);970 const to = normalizeAccountId(owner);971 const AItemCount = parseInt((await api.query.nft.itemListIndex(collectionId)).toString(), 10);971 const AItemCount = parseInt((await api.query.nft.itemListIndex(collectionId)).toString(), 10);972 const Aitem: any = (await api.query.nft.fungibleItemList(collectionId, toSubstrateAddress(to))).toJSON();972 const Aitem: any = (await api.query.nft.fungibleItemList(collectionId, toSubstrateAddress(to))).toJSON();973 const AItemBalance = new BigNumber(Aitem.Value);973 const AItemBalance = new BigNumber(Aitem.value);974974975 let tx;975 let tx;976 if (createMode === 'Fungible') {976 if (createMode === 'Fungible') {989989990 const BItemCount = parseInt((await api.query.nft.itemListIndex(collectionId)).toString(), 10);990 const BItemCount = parseInt((await api.query.nft.itemListIndex(collectionId)).toString(), 10);991 const Bitem: any = (await api.query.nft.fungibleItemList(collectionId, toSubstrateAddress(to))).toJSON();991 const Bitem: any = (await api.query.nft.fungibleItemList(collectionId, toSubstrateAddress(to))).toJSON();992 const BItemBalance = new BigNumber(Bitem.Value);992 const BItemBalance = new BigNumber(Bitem.value);993993994 // What to expect994 // What to expect995 // tslint:disable-next-line:no-unused-expression995 // tslint:disable-next-line:no-unused-expression1035 // What to expect1035 // What to expect1036 // tslint:disable-next-line:no-unused-expression1036 // tslint:disable-next-line:no-unused-expression1037 expect(result.success).to.be.true;1037 expect(result.success).to.be.true;1038 expect(collection.Access).to.be.equal(accessMode);1038 expect(collection.access).to.be.equal(accessMode);1039 });1039 });1040}1040}104110411082 // What to expect1082 // What to expect1083 // tslint:disable-next-line:no-unused-expression1083 // tslint:disable-next-line:no-unused-expression1084 expect(result.success).to.be.true;1084 expect(result.success).to.be.true;1085 expect(collection.MintMode).to.be.equal(enabled);1085 expect(collection.mintMode).to.be.equal(enabled);1086 });1086 });1087}1087}108810881221}1221}122212221223export async function queryNftOwner(api: ApiPromise, collectionId: number, tokenId: number): Promise<CrossAccountId> {1223export async function queryNftOwner(api: ApiPromise, collectionId: number, tokenId: number): Promise<CrossAccountId> {1224 return normalizeAccountId((await api.query.nft.nftItemList(collectionId, tokenId) as any).toJSON().Owner);1224 return normalizeAccountId((await api.query.nft.nftItemList(collectionId, tokenId) as any).toJSON().owner);1225}1225}122612261227export async function waitNewBlocks(blocksCount = 1): Promise<void> {1227export async function waitNewBlocks(blocksCount = 1): Promise<void> {