difftreelog
WaitNewBlocks instead timeout function
in: master
11 files changed
tests/src/collision-tests/admVsOwnerChanges.test.tsdiffbeforeafterboth4import privateKey from '../substrate/privateKey';4import privateKey from '../substrate/privateKey';5import usingApi, { submitTransactionAsync } from '../substrate/substrate-api';5import usingApi, { submitTransactionAsync } from '../substrate/substrate-api';6import {6import {7 addCollectionAdminExpectSuccess,8 approveExpectSuccess,9 createCollectionExpectSuccess,7 createCollectionExpectSuccess,10 createItemExpectSuccess,8 createItemExpectSuccess,11 transferFromExpectSuccess,12 transferExpectSuccess,13 normalizeAccountId,9 normalizeAccountId,10 waitNewBlocks,14} from '../util/helpers';11} from '../util/helpers';151216chai.use(chaiAsPromised);13chai.use(chaiAsPromised);35 const collectionId = await createCollectionExpectSuccess();32 const collectionId = await createCollectionExpectSuccess();36 const changeAdminTxBob = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Bob.address));33 const changeAdminTxBob = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Bob.address));37 await submitTransactionAsync(Alice, changeAdminTxBob);34 await submitTransactionAsync(Alice, changeAdminTxBob);38 const timeoutPromise = (timeout: number) => new Promise((resolve) => setTimeout(resolve, timeout));39 const changeAdminTxFerdie = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Ferdie.address));35 const changeAdminTxFerdie = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Ferdie.address));40 await submitTransactionAsync(Bob, changeAdminTxFerdie);36 await submitTransactionAsync(Bob, changeAdminTxFerdie);41 const itemId = await createItemExpectSuccess(Ferdie, collectionId, 'NFT');37 const itemId = await createItemExpectSuccess(Ferdie, collectionId, 'NFT');50 ]);46 ]);51 const itemBefore: any = await api.query.nft.nftItemList(collectionId, itemId);47 const itemBefore: any = await api.query.nft.nftItemList(collectionId, itemId);52 expect(itemBefore.Owner).not.to.be.eq(Bob.address);48 expect(itemBefore.Owner).not.to.be.eq(Bob.address);53 await timeoutPromise(20000);49 await waitNewBlocks(2);54 });50 });55 });51 });56});52});tests/src/collision-tests/admVsOwnerData.test.tsdiffbeforeafterboth7 createCollectionExpectSuccess,7 createCollectionExpectSuccess,8 createItemExpectSuccess,8 createItemExpectSuccess,9 normalizeAccountId,9 normalizeAccountId,10 waitNewBlocks,10} from '../util/helpers';11} from '../util/helpers';111212chai.use(chaiAsPromised);13chai.use(chaiAsPromised);29 const collectionId = await createCollectionExpectSuccess();30 const collectionId = await createCollectionExpectSuccess();30 const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Bob.address));31 const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Bob.address));31 await submitTransactionAsync(Alice, changeAdminTx);32 await submitTransactionAsync(Alice, changeAdminTx);32 const timeoutPromise = (timeout: number) => new Promise((resolve) => setTimeout(resolve, timeout));33 const itemId = await createItemExpectSuccess(Bob, collectionId, 'NFT');33 const itemId = await createItemExpectSuccess(Bob, collectionId, 'NFT');34 //34 //35 // tslint:disable-next-line: max-line-length35 // tslint:disable-next-line: max-line-length42 ]);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 timeoutPromise(20000);45 await waitNewBlocks(2);46 });46 });47 });47 });48});48});tests/src/collision-tests/admVsOwnerTake.test.tsdiffbeforeafterboth7 createCollectionExpectSuccess,7 createCollectionExpectSuccess,8 createItemExpectSuccess,8 createItemExpectSuccess,9 normalizeAccountId,9 normalizeAccountId,10 waitNewBlocks,10} from '../util/helpers';11} from '../util/helpers';111212chai.use(chaiAsPromised);13chai.use(chaiAsPromised);30 const collectionId = await createCollectionExpectSuccess();31 const collectionId = await createCollectionExpectSuccess();31 const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Bob.address));32 const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Bob.address));32 await submitTransactionAsync(Alice, changeAdminTx);33 await submitTransactionAsync(Alice, changeAdminTx);33 const timeoutPromise = (timeout: number) => new Promise((resolve) => setTimeout(resolve, timeout));34 const itemId = await createItemExpectSuccess(Bob, collectionId, 'NFT');34 const itemId = await createItemExpectSuccess(Bob, collectionId, 'NFT');35 //35 //36 const sendItem = api.tx.nft.transfer(normalizeAccountId(Ferdie.address), collectionId, itemId, 1);36 const sendItem = api.tx.nft.transfer(normalizeAccountId(Ferdie.address), collectionId, itemId, 1);39 sendItem.signAndSend(Bob),39 sendItem.signAndSend(Bob),40 burnItem.signAndSend(Alice),40 burnItem.signAndSend(Alice),41 ]);41 ]);42 await timeoutPromise(20000);42 await waitNewBlocks(2);43 let itemBurn = false;43 let itemBurn = false;44 itemBurn = (await (api.query.nft.nftItemList(collectionId, itemId))).toJSON() as boolean;44 itemBurn = (await (api.query.nft.nftItemList(collectionId, itemId))).toJSON() as boolean;45 // tslint:disable-next-line: no-unused-expression45 // tslint:disable-next-line: no-unused-expression46 expect(itemBurn).to.be.null;46 expect(itemBurn).to.be.null;47 await timeoutPromise(20000);47 await waitNewBlocks(2);48 });48 });49 });49 });50});50});tests/src/collision-tests/adminDestroyCollection.test.tsdiffbeforeafterboth6import {6import {7 createCollectionExpectSuccess,7 createCollectionExpectSuccess,8 normalizeAccountId,8 normalizeAccountId,9 waitNewBlocks,9} from '../util/helpers';10} from '../util/helpers';101111chai.use(chaiAsPromised);12chai.use(chaiAsPromised);29 const collectionId = await createCollectionExpectSuccess();30 const collectionId = await createCollectionExpectSuccess();30 const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Bob.address));31 const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Bob.address));31 await submitTransactionAsync(Alice, changeAdminTx);32 await submitTransactionAsync(Alice, changeAdminTx);32 const timeoutPromise = (timeout: number) => new Promise((resolve) => setTimeout(resolve, timeout));33 await timeoutPromise(10000);33 await waitNewBlocks(1);34 //34 //35 const addWhitelistAdm = api.tx.nft.addToWhiteList(collectionId, normalizeAccountId(Ferdie.address));35 const addWhitelistAdm = api.tx.nft.addToWhiteList(collectionId, normalizeAccountId(Ferdie.address));36 const destroyCollection = api.tx.nft.destroyCollection(collectionId);36 const destroyCollection = api.tx.nft.destroyCollection(collectionId);37 await Promise.all([37 await Promise.all([38 addWhitelistAdm.signAndSend(Bob),38 addWhitelistAdm.signAndSend(Bob),39 destroyCollection.signAndSend(Alice),39 destroyCollection.signAndSend(Alice),40 ]);40 ]);41 await timeoutPromise(10000);41 await waitNewBlocks(1);42 let whiteList = false;42 let whiteList = false;43 whiteList = (await api.query.nft.whiteList(collectionId, Ferdie.address)).toJSON() as boolean;43 whiteList = (await api.query.nft.whiteList(collectionId, Ferdie.address)).toJSON() as boolean;44 // tslint:disable-next-line: no-unused-expression44 // tslint:disable-next-line: no-unused-expression45 expect(whiteList).to.be.false;45 expect(whiteList).to.be.false;46 await timeoutPromise(20000);46 await waitNewBlocks(2);47 });47 });48 });48 });49});49});tests/src/collision-tests/adminLimitsOff.test.tsdiffbeforeafterboth7import {7import {8 createCollectionExpectSuccess,8 createCollectionExpectSuccess,9 normalizeAccountId,9 normalizeAccountId,10 waitNewBlocks,10} from '../util/helpers';11} from '../util/helpers';111212chai.use(chaiAsPromised);13chai.use(chaiAsPromised);45 const changeAdminTx3 = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Bob.address));46 const changeAdminTx3 = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Bob.address));46 await submitTransactionAsync(Alice, changeAdminTx3);47 await submitTransactionAsync(Alice, changeAdminTx3);474848 const timeoutPromise = (timeout: number) => new Promise((resolve) => setTimeout(resolve, timeout));49 const addAdmOne = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Ferdie.address));49 const addAdmOne = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Ferdie.address));50 const addAdmTwo = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Charlie.address));50 const addAdmTwo = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Charlie.address));51 await Promise.all([51 await Promise.all([52 addAdmOne.signAndSend(Bob),52 addAdmOne.signAndSend(Bob),53 addAdmTwo.signAndSend(Alice),53 addAdmTwo.signAndSend(Alice),54 ]);54 ]);55 await timeoutPromise(20000);55 await waitNewBlocks(2);56 const changeAdminTx4 = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Alice.address));56 const changeAdminTx4 = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Alice.address));57 await expect(submitTransactionExpectFailAsync(Alice, changeAdminTx4)).to.be.rejected;57 await expect(submitTransactionExpectFailAsync(Alice, changeAdminTx4)).to.be.rejected;585859 const adminListAfterAddAdmin: any = (await api.query.nft.adminList(collectionId));59 const adminListAfterAddAdmin: any = (await api.query.nft.adminList(collectionId));60 expect(adminListAfterAddAdmin).to.be.contains(normalizeAccountId(Eve.address));60 expect(adminListAfterAddAdmin).to.be.contains(normalizeAccountId(Eve.address));61 expect(adminListAfterAddAdmin).to.be.contains(normalizeAccountId(Ferdie.address));61 expect(adminListAfterAddAdmin).to.be.contains(normalizeAccountId(Ferdie.address));62 expect(adminListAfterAddAdmin).not.to.be.contains(normalizeAccountId(Alice.address));62 expect(adminListAfterAddAdmin).not.to.be.contains(normalizeAccountId(Alice.address));63 await timeoutPromise(20000);63 await waitNewBlocks(2);64 });64 });65 });65 });66});66});tests/src/collision-tests/adminRightsOff.test.tsdiffbeforeafterboth7import {7import {8 createCollectionExpectSuccess,8 createCollectionExpectSuccess,9 normalizeAccountId,9 normalizeAccountId,10 waitNewBlocks,10} from '../util/helpers';11} from '../util/helpers';111212chai.use(chaiAsPromised);13chai.use(chaiAsPromised);28 const collectionId = await createCollectionExpectSuccess();29 const collectionId = await createCollectionExpectSuccess();29 const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Bob.address));30 const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Bob.address));30 await submitTransactionAsync(Alice, changeAdminTx);31 await submitTransactionAsync(Alice, changeAdminTx);31 const timeoutPromise = (timeout: number) => new Promise((resolve) => setTimeout(resolve, timeout));32 await timeoutPromise(10000);32 await waitNewBlocks(1);33 const args = [{ nft: ['0x31', '0x31'] }, { nft: ['0x32', '0x32'] }, { nft: ['0x33', '0x33'] }];33 const args = [{ nft: ['0x31', '0x31'] }, { nft: ['0x32', '0x32'] }, { nft: ['0x33', '0x33'] }];34 const addItemAdm = api.tx.nft.createMultipleItems(collectionId, normalizeAccountId(Bob.address), args);34 const addItemAdm = api.tx.nft.createMultipleItems(collectionId, normalizeAccountId(Bob.address), args);35 const removeAdm = api.tx.nft.removeCollectionAdmin(collectionId, normalizeAccountId(Bob.address));35 const removeAdm = api.tx.nft.removeCollectionAdmin(collectionId, normalizeAccountId(Bob.address));36 await Promise.all([36 await Promise.all([37 addItemAdm.signAndSend(Bob),37 addItemAdm.signAndSend(Bob),38 removeAdm.signAndSend(Alice),38 removeAdm.signAndSend(Alice),39 ]);39 ]);40 await timeoutPromise(20000);40 await waitNewBlocks(2);41 const itemsListIndex = await api.query.nft.itemListIndex(collectionId) as unknown as BN;41 const itemsListIndex = await api.query.nft.itemListIndex(collectionId) as unknown as BN;42 expect(itemsListIndex.toNumber()).to.be.equal(0);42 expect(itemsListIndex.toNumber()).to.be.equal(0);43 const adminList: any = (await api.query.nft.adminList(collectionId));43 const adminList: any = (await api.query.nft.adminList(collectionId));44 expect(adminList).not.to.be.contains(normalizeAccountId(Bob.address));44 expect(adminList).not.to.be.contains(normalizeAccountId(Bob.address));45 await timeoutPromise(20000);45 await waitNewBlocks(2);46 });46 });47 });47 });48});48});tests/src/collision-tests/setSponsorNewOwner.test.tsdiffbeforeafterboth6import {6import {7 createCollectionExpectSuccess, 7 createCollectionExpectSuccess, 8 setCollectionSponsorExpectSuccess,8 setCollectionSponsorExpectSuccess,9 normalizeAccountId,9 waitNewBlocks,10} from '../util/helpers';10} from '../util/helpers';111112chai.use(chaiAsPromised);12chai.use(chaiAsPromised);29 await usingApi(async (api) => {29 await usingApi(async (api) => {30 const collectionId = await createCollectionExpectSuccess();30 const collectionId = await createCollectionExpectSuccess();31 await setCollectionSponsorExpectSuccess(collectionId, Bob.address);31 await setCollectionSponsorExpectSuccess(collectionId, Bob.address);32 const timeoutPromise = (timeout: number) => new Promise((resolve) => setTimeout(resolve, timeout));33 await timeoutPromise(20000);32 await waitNewBlocks(2);34 const confirmSponsorship = api.tx.nft.confirmSponsorship(collectionId);33 const confirmSponsorship = api.tx.nft.confirmSponsorship(collectionId);35 const changeCollectionOwner = api.tx.nft.changeCollectionOwner(collectionId, Ferdie.address);34 const changeCollectionOwner = api.tx.nft.changeCollectionOwner(collectionId, Ferdie.address);36 await Promise.all([35 await Promise.all([37 confirmSponsorship.signAndSend(Bob),36 confirmSponsorship.signAndSend(Bob),38 changeCollectionOwner.signAndSend(Alice),37 changeCollectionOwner.signAndSend(Alice),39 ]);38 ]);40 await timeoutPromise(20000);39 await waitNewBlocks(2);41 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();40 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();42 expect(collection.Sponsorship.confirmed).to.be.eq(Bob.address);41 expect(collection.Sponsorship.confirmed).to.be.eq(Bob.address);43 expect(collection.Owner).to.be.eq(Ferdie.address);42 expect(collection.Owner).to.be.eq(Ferdie.address);44 await timeoutPromise(20000);43 await waitNewBlocks(2);45 });44 });46 });45 });47});46});tests/src/collision-tests/sponsorPayments.test.tsdiffbeforeafterboth11 createItemExpectSuccess,11 createItemExpectSuccess,12 setCollectionSponsorExpectSuccess,12 setCollectionSponsorExpectSuccess,13 normalizeAccountId,13 normalizeAccountId,14 waitNewBlocks,14} from '../util/helpers';15} from '../util/helpers';151616chai.use(chaiAsPromised);17chai.use(chaiAsPromised);32 const collectionId = await createCollectionExpectSuccess();33 const collectionId = await createCollectionExpectSuccess();33 const changeAdminTxBob = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Bob.address));34 const changeAdminTxBob = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Bob.address));34 await submitTransactionAsync(Alice, changeAdminTxBob);35 await submitTransactionAsync(Alice, changeAdminTxBob);35 const timeoutPromise = (timeout: number) => new Promise((resolve) => setTimeout(resolve, timeout));36 const itemId = await createItemExpectSuccess(Bob, collectionId, 'NFT');36 const itemId = await createItemExpectSuccess(Bob, collectionId, 'NFT');37 await setCollectionSponsorExpectSuccess(collectionId, Bob.address);37 await setCollectionSponsorExpectSuccess(collectionId, Bob.address);38 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');38 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');49 expect(alicesBalanceAfter === alicesBalanceBefore).to.be.true;49 expect(alicesBalanceAfter === alicesBalanceBefore).to.be.true;50 // tslint:disable-next-line:no-unused-expression50 // tslint:disable-next-line:no-unused-expression51 expect(bobsBalanceAfter === bobsBalanceBefore).to.be.true;51 expect(bobsBalanceAfter === bobsBalanceBefore).to.be.true;52 await timeoutPromise(20000);52 await waitNewBlocks(2);53 });53 });54 });54 });55});55});tests/src/collision-tests/tokenLimitsOff.test.tsdiffbeforeafterboth10 getCreateItemResult,10 getCreateItemResult,11 setMintPermissionExpectSuccess,11 setMintPermissionExpectSuccess,12 normalizeAccountId,12 normalizeAccountId,13 waitNewBlocks,13} from '../util/helpers';14} from '../util/helpers';141515chai.use(chaiAsPromised);16chai.use(chaiAsPromised);57 const subTxTesult = getCreateItemResult(subTx);58 const subTxTesult = getCreateItemResult(subTx);58 // tslint:disable-next-line:no-unused-expression59 // tslint:disable-next-line:no-unused-expression59 expect(subTxTesult.success).to.be.true;60 expect(subTxTesult.success).to.be.true;60 const timeoutPromise = (timeout: number) => new Promise((resolve) => setTimeout(resolve, timeout));61 await timeoutPromise(20000);61 await waitNewBlocks(2);626263 const args = [{ nft: ['0x31', '0x31'] }, { nft: ['0x32', '0x32'] }, { nft: ['0x33', '0x33'] }];63 const args = [{ nft: ['0x31', '0x31'] }, { nft: ['0x32', '0x32'] }, { nft: ['0x33', '0x33'] }];64 const mintItemOne = api.tx.nft64 const mintItemOne = api.tx.nft69 mintItemOne.signAndSend(Ferdie),69 mintItemOne.signAndSend(Ferdie),70 mintItemTwo.signAndSend(Bob),70 mintItemTwo.signAndSend(Bob),71 ]);71 ]);72 await timeoutPromise(20000);72 await waitNewBlocks(2);73 const itemsListIndexAfter = await api.query.nft.itemListIndex(collectionId) as unknown as BN;73 const itemsListIndexAfter = await api.query.nft.itemListIndex(collectionId) as unknown as BN;74 expect(itemsListIndexAfter.toNumber()).to.be.equal(3);74 expect(itemsListIndexAfter.toNumber()).to.be.equal(3);75 // TokenLimit = 4. The first transaction is successful. The second should fail.75 // TokenLimit = 4. The first transaction is successful. The second should fail.76 await timeoutPromise(20000);76 await waitNewBlocks(2);77 });77 });78 });78 });79});79});tests/src/collision-tests/turnsOffMinting.test.tsdiffbeforeafterboth8 createCollectionExpectSuccess,8 createCollectionExpectSuccess,9 setMintPermissionExpectSuccess,9 setMintPermissionExpectSuccess,10 normalizeAccountId,10 normalizeAccountId,11 waitNewBlocks,11} from '../util/helpers';12} from '../util/helpers';121313chai.use(chaiAsPromised);14chai.use(chaiAsPromised);27 it('The collection owner turns off minting mode and there are minting transactions in the same block ', async () => {28 it('The collection owner turns off minting mode and there are minting transactions in the same block ', async () => {28 await usingApi(async (api) => {29 await usingApi(async (api) => {29 const collectionId = await createCollectionExpectSuccess();30 const collectionId = await createCollectionExpectSuccess();30 const timeoutPromise = (timeout: number) => new Promise((resolve) => setTimeout(resolve, timeout));31 await setMintPermissionExpectSuccess(Alice, collectionId, true);31 await setMintPermissionExpectSuccess(Alice, collectionId, true);32 await addToWhiteListExpectSuccess(Alice, collectionId, Ferdie.address);32 await addToWhiteListExpectSuccess(Alice, collectionId, Ferdie.address);333341 itemList = (await (api.query.nft.nftItemList(collectionId, mintItem))).toJSON() as boolean;41 itemList = (await (api.query.nft.nftItemList(collectionId, mintItem))).toJSON() as boolean;42 // tslint:disable-next-line: no-unused-expression42 // tslint:disable-next-line: no-unused-expression43 expect(itemList).to.be.null;43 expect(itemList).to.be.null;44 await timeoutPromise(20000);44 await waitNewBlocks(2);45 });45 });46 });46 });47});47});tests/src/util/helpers.tsdiffbeforeafterboth1173 return normalizeAccountId((await api.query.nft.nftItemList(collectionId, tokenId) as any).toJSON().Owner);1173 return normalizeAccountId((await api.query.nft.nftItemList(collectionId, tokenId) as any).toJSON().Owner);1174}1174}11751176export async function waitNewBlocks(blocksCount = 1): Promise<void> {1177 await usingApi(async (api) => {1178 const promise = new Promise<void>(async (resolve) => {11791180 const unsubscribe = await api.rpc.chain.subscribeNewHeads(() => {1181 if (blocksCount > 0) {1182 blocksCount--;1183 } else {1184 unsubscribe();1185 resolve();1186 }1187 });1188 });1189 return promise;1190 });1191}1192