git.delta.rocks / unique-network / refs/commits / d68f54a2fa72

difftreelog

Fix broken tests

Antz0x0z2021-03-24parent: #4d1c4cc.patch.diff
in: master
Refactoting and added method timeoutPromise to ensure that tests are included in different blocks

10 files changed

modifiedtests/src/collision-tests/admVsOwnerChanges.test.tsdiffbeforeafterboth
33 const collectionId = await createCollectionExpectSuccess(); 33 const collectionId = await createCollectionExpectSuccess();
34 const changeAdminTxBob = api.tx.nft.addCollectionAdmin(collectionId, Bob.address); 34 const changeAdminTxBob = api.tx.nft.addCollectionAdmin(collectionId, Bob.address);
35 await submitTransactionAsync(Alice, changeAdminTxBob); 35 await submitTransactionAsync(Alice, changeAdminTxBob);
36 const timeoutPromise = (timeout: number) => new Promise((resolve) => setTimeout(resolve, timeout));
36 const changeAdminTxFerdie = api.tx.nft.addCollectionAdmin(collectionId, Ferdie.address); 37 const changeAdminTxFerdie = api.tx.nft.addCollectionAdmin(collectionId, Ferdie.address);
37 await submitTransactionAsync(Bob, changeAdminTxFerdie); 38 await submitTransactionAsync(Bob, changeAdminTxFerdie);
38 const itemId = await createItemExpectSuccess(Ferdie, collectionId, 'NFT'); 39 const itemId = await createItemExpectSuccess(Ferdie, collectionId, 'NFT');
47 sendItem.signAndSend(Ferdie), 48 sendItem.signAndSend(Ferdie),
48 ]); 49 ]);
49 const itemBefore: any = await api.query.nft.nftItemList(collectionId, itemId); 50 const itemBefore: any = await api.query.nft.nftItemList(collectionId, itemId);
50 expect(itemBefore.Owner.toString()).not.to.be.eq(Bob.address); 51 expect(itemBefore.Owner).not.to.be.eq(Bob.address);
52 await timeoutPromise(20000);
51 }); 53 });
52 }); 54 });
53}); 55});
modifiedtests/src/collision-tests/admVsOwnerData.test.tsdiffbeforeafterboth
29describe('Admin vs Owner changes the data in the token: ', () => { 29describe('Admin vs Owner changes the data in the token: ', () => {
30 it('The collection admin changes the data in the token and in the same block the token owner also changes the data in it ', async () => { 30 it('The collection admin changes the data in the token and in the same block the token owner also changes the data in it ', async () => {
31 await usingApi(async (api) => { 31 await usingApi(async (api) => {
32 const AliceData = [31]; 32 const AliceData = 1;
33 const BobData = [32]; 33 const BobData = 2;
34 const collectionId = await createCollectionExpectSuccess(); 34 const collectionId = await createCollectionExpectSuccess();
35 const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, Bob.address); 35 const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, Bob.address);
36 await submitTransactionAsync(Alice, changeAdminTx); 36 await submitTransactionAsync(Alice, changeAdminTx);
37 const timeoutPromise = (timeout: number) => new Promise((resolve) => setTimeout(resolve, timeout));
37 const itemId = await createItemExpectSuccess(Bob, collectionId, 'NFT'); 38 const itemId = await createItemExpectSuccess(Bob, collectionId, 'NFT');
38 // 39 //
39 // tslint:disable-next-line: max-line-length 40 // tslint:disable-next-line: max-line-length
40 const AliceTx = api.tx.nft.setVariableMetaData(collectionId, itemId, '0x' + Buffer.from(AliceData).toString('hex')); 41 const AliceTx = api.tx.nft.setVariableMetaData(collectionId, itemId, AliceData.toString());
41 // tslint:disable-next-line: max-line-length 42 // tslint:disable-next-line: max-line-length
42 const BobTx = api.tx.nft.setVariableMetaData(collectionId, itemId, '0x' + Buffer.from(BobData).toString('hex')); 43 const BobTx = api.tx.nft.setVariableMetaData(collectionId, itemId, BobData.toString());
43 await Promise.all 44 await Promise.all
44 ([ 45 ([
45 AliceTx.signAndSend(Alice), 46 AliceTx.signAndSend(Alice),
46 BobTx.signAndSend(Bob), 47 BobTx.signAndSend(Bob),
47 ]); 48 ]);
48 const item: any = await api.query.nft.nftItemList(collectionId, itemId); 49 const item: any = await api.query.nft.nftItemList(collectionId, itemId);
49 expect(Array.from(item.VariableData)).to.deep.equal(Array.from([])); 50 expect(item.VariableData).not.to.be.eq(null); // Pseudo-random selection of one of two values
51 await timeoutPromise(20000);
50 }); 52 });
51 }); 53 });
52}); 54});
modifiedtests/src/collision-tests/admVsOwnerTake.test.tsdiffbeforeafterboth
33 const collectionId = await createCollectionExpectSuccess(); 33 const collectionId = await createCollectionExpectSuccess();
34 const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, Bob.address); 34 const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, Bob.address);
35 await submitTransactionAsync(Alice, changeAdminTx); 35 await submitTransactionAsync(Alice, changeAdminTx);
36 const timeoutPromise = (timeout: number) => new Promise((resolve) => setTimeout(resolve, timeout));
36 const itemId = await createItemExpectSuccess(Bob, collectionId, 'NFT'); 37 const itemId = await createItemExpectSuccess(Bob, collectionId, 'NFT');
37 // 38 //
38 const sendItem = api.tx.nft.transfer(Ferdie.address, collectionId, itemId, 1); 39 const sendItem = api.tx.nft.transfer(Ferdie.address, collectionId, itemId, 1);
42 sendItem.signAndSend(Bob), 43 sendItem.signAndSend(Bob),
43 burnItem.signAndSend(Alice), 44 burnItem.signAndSend(Alice),
44 ]); 45 ]);
46 await timeoutPromise(10000);
47 let itemBurn: boolean = false;
45 const itemBurn: any = await api.query.nft.nftItemList(collectionId, itemId); 48 itemBurn = (await (api.query.nft.nftItemList(collectionId, itemId))).toJSON() as boolean;
49 // tslint:disable-next-line: no-unused-expression
46 expect(itemBurn.Owner.toString()).to.be.eq('5C4hrfjw9DjXZTzV3MwzrrAr9P1MJhSrvWGWqi1eSuyUpnhM'); 50 expect(itemBurn).to.be.null;
51 await timeoutPromise(20000);
47 }); 52 });
48 }); 53 });
49}); 54});
modifiedtests/src/collision-tests/adminDestroyCollection.test.tsdiffbeforeafterboth
55 whiteList = (await api.query.nft.whiteList(collectionId, Ferdie.address)).toJSON() as boolean;55 whiteList = (await api.query.nft.whiteList(collectionId, Ferdie.address)).toJSON() as boolean;
56 // tslint:disable-next-line: no-unused-expression56 // tslint:disable-next-line: no-unused-expression
57 expect(whiteList).to.be.false;57 expect(whiteList).to.be.false;
58 await timeoutPromise(20000);
58 });59 });
59 });60 });
60});61});
modifiedtests/src/collision-tests/adminLimitsOff.test.tsdiffbeforeafterboth
68 expect(adminListAfterAddAdmin).to.be.contains(Eve.address);68 expect(adminListAfterAddAdmin).to.be.contains(Eve.address);
69 expect(adminListAfterAddAdmin).to.be.contains(Ferdie.address);69 expect(adminListAfterAddAdmin).to.be.contains(Ferdie.address);
70 expect(adminListAfterAddAdmin).not.to.be.contains(Alice.address);70 expect(adminListAfterAddAdmin).not.to.be.contains(Alice.address);
71 await timeoutPromise(20000);
71 });72 });
72 });73 });
73});74});
modifiedtests/src/collision-tests/adminRightsOff.test.tsdiffbeforeafterboth
56 expect(itemsListIndex.toNumber()).to.be.equal(0);56 expect(itemsListIndex.toNumber()).to.be.equal(0);
57 const adminList: any = (await api.query.nft.adminList(collectionId));57 const adminList: any = (await api.query.nft.adminList(collectionId));
58 expect(adminList).not.to.be.contains(Bob.address);58 expect(adminList).not.to.be.contains(Bob.address);
59 await timeoutPromise(20000);
59 });60 });
60 });61 });
61});62});
modifiedtests/src/collision-tests/setSponsorNewOwner.test.tsdiffbeforeafterboth
44 changeCollectionOwner.signAndSend(Alice),44 changeCollectionOwner.signAndSend(Alice),
45 ]);45 ]);
46 await timeoutPromise(10000);46 await timeoutPromise(10000);
47 const collection: any = (await api.query.nft.collection(collectionId)).toJSON();47 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
48 expect(collection.Sponsor).to.be.eq(Bob.address);48 expect(collection.Sponsorship.Confirmed).to.be.eq(Bob.address);
49 // tslint:disable-next-line: no-unused-expression
50 expect(collection.SponsorConfirmed).to.be.true;
51 expect(collection.Owner).to.be.eq(Ferdie.address);49 expect(collection.Owner).to.be.eq(Ferdie.address);
50 await timeoutPromise(20000);
52 });51 });
53 });52 });
54});53});
modifiedtests/src/collision-tests/sponsorPayments.test.tsdiffbeforeafterboth
34 const collectionId = await createCollectionExpectSuccess(); 34 const collectionId = await createCollectionExpectSuccess();
35 const changeAdminTxBob = api.tx.nft.addCollectionAdmin(collectionId, Bob.address); 35 const changeAdminTxBob = api.tx.nft.addCollectionAdmin(collectionId, Bob.address);
36 await submitTransactionAsync(Alice, changeAdminTxBob); 36 await submitTransactionAsync(Alice, changeAdminTxBob);
37 const timeoutPromise = (timeout: number) => new Promise((resolve) => setTimeout(resolve, timeout));
37 const itemId = await createItemExpectSuccess(Bob, collectionId, 'NFT'); 38 const itemId = await createItemExpectSuccess(Bob, collectionId, 'NFT');
38 await setCollectionSponsorExpectSuccess(collectionId, Bob.address); 39 await setCollectionSponsorExpectSuccess(collectionId, Bob.address);
39 await confirmSponsorshipExpectSuccess(collectionId, '//Bob'); 40 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
51 expect(alicesBalanceAfter === alicesBalanceBefore).to.be.true; 52 expect(alicesBalanceAfter === alicesBalanceBefore).to.be.true;
52 // tslint:disable-next-line:no-unused-expression 53 // tslint:disable-next-line:no-unused-expression
53 expect(bobsBalanceAfter === bobsBalanceBefore).to.be.true; 54 expect(bobsBalanceAfter === bobsBalanceBefore).to.be.true;
55 await timeoutPromise(20000);
54 }); 56 });
55 }); 57 });
56}); 58});
modifiedtests/src/collision-tests/tokenLimitsOff.test.tsdiffbeforeafterboth
77 await timeoutPromise(10000);77 await timeoutPromise(10000);
78 const itemsListIndexAfter = await api.query.nft.itemListIndex(collectionId) as unknown as BN;78 const itemsListIndexAfter = await api.query.nft.itemListIndex(collectionId) as unknown as BN;
79 expect(itemsListIndexAfter.toNumber()).to.be.equal(3);79 expect(itemsListIndexAfter.toNumber()).to.be.equal(3);
80 // TokenLimit = 4. The first transaction is successful. The second should fail. (bug: NFTPAR-367)80 // TokenLimit = 4. The first transaction is successful. The second should fail.
81 await timeoutPromise(10000);
81 });82 });
82 });83 });
83});84});
modifiedtests/src/collision-tests/turnsOffMinting.test.tsdiffbeforeafterboth
29 it('The collection owner turns off minting mode and there are minting transactions in the same block ', async () => { 29 it('The collection owner turns off minting mode and there are minting transactions in the same block ', async () => {
30 await usingApi(async (api) => { 30 await usingApi(async (api) => {
31 const collectionId = await createCollectionExpectSuccess(); 31 const collectionId = await createCollectionExpectSuccess();
32 const timeoutPromise = (timeout: number) => new Promise((resolve) => setTimeout(resolve, timeout));
32 await setMintPermissionExpectSuccess(Alice, collectionId, true); 33 await setMintPermissionExpectSuccess(Alice, collectionId, true);
33 await addToWhiteListExpectSuccess(Alice, collectionId, Ferdie.address); 34 await addToWhiteListExpectSuccess(Alice, collectionId, Ferdie.address);
34 // 35 //
39 mintItem.signAndSend(Ferdie), 40 mintItem.signAndSend(Ferdie),
40 offMinting.signAndSend(Alice), 41 offMinting.signAndSend(Alice),
41 ]); 42 ]);
43 let itemList: boolean = false;
42 const itemList: any = await api.query.nft.nftItemList(collectionId, mintItem); 44 itemList = (await (api.query.nft.nftItemList(collectionId, mintItem))).toJSON() as boolean;
45 // tslint:disable-next-line: no-unused-expression
43 expect(itemList.Owner.toString()).to.be.eq('5C4hrfjw9DjXZTzV3MwzrrAr9P1MJhSrvWGWqi1eSuyUpnhM'); 46 expect(itemList).to.be.null;
47 await timeoutPromise(20000);
44 }); 48 });
45 }); 49 });
46}); 50});