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

difftreelog

Merge branch 'feature/fix-tests' of github.com:usetech-llc/nft_private into feature/fix-tests

Greg Zaitsev2021-07-15parents: #5af2b45 #0b237a5.patch.diff
in: master

2 files changed

modifiedtests/src/scheduler.test.tsdiffbeforeafterboth
18chai.use(chaiAsPromised);18chai.use(chaiAsPromised);
1919
20describe('Integration Test scheduler base transaction', () => {20describe('Integration Test scheduler base transaction', () => {
21 it('User can transfer owned token with delay (scheduler)', async () => {21 it.only('User can transfer owned token with delay (scheduler)', async () => {
22 await usingApi(async () => {22 await usingApi(async () => {
23 const Alice = privateKey('//Alice');23 const Alice = privateKey('//Alice');
24 const Bob = privateKey('//Bob');24 const Bob = privateKey('//Bob');
28 await setCollectionSponsorExpectSuccess(nftCollectionId, Alice.address);28 await setCollectionSponsorExpectSuccess(nftCollectionId, Alice.address);
29 await confirmSponsorshipExpectSuccess(nftCollectionId);29 await confirmSponsorshipExpectSuccess(nftCollectionId);
3030
31 await scheduleTransferExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 1);31 await scheduleTransferExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 1, 6000, 4);
32 });32 });
33 });33 });
34});34});
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
84}84}
8585
86interface ITokenDataType {86interface ITokenDataType {
87 Owner: number[];87 Owner: IKeyringPair;
88 ConstData: number[];88 ConstData: number[];
89 VariableData: number[];89 VariableData: number[];
90}90}
748 sender: IKeyringPair,748 sender: IKeyringPair,
749 recipient: IKeyringPair,749 recipient: IKeyringPair,
750 value: number | bigint = 1,750 value: number | bigint = 1,
751 blockTimeMs: number,
752 blockSchedule: number
751) {753) {
752 await usingApi(async (api: ApiPromise) => {754 await usingApi(async (api: ApiPromise) => {
753 const blockNumber: number | undefined = await getBlockNumber(api);755 const blockNumber: number | undefined = await getBlockNumber(api);
754 const expectedBlockNumber = blockNumber + 2;756 const expectedBlockNumber = blockNumber + blockSchedule;
755757
756 expect(blockNumber).to.be.greaterThan(0);758 expect(blockNumber).to.be.greaterThan(0);
757 const transferTx = await api.tx.nft.transfer(recipient.address, collectionId, tokenId, value); 759 const transferTx = await api.tx.nft.transfer(normalizeAccountId(recipient.address), collectionId, tokenId, value);
758 const scheduleTx = await api.tx.scheduler.schedule(expectedBlockNumber, null, 0, transferTx);760 const scheduleTx = await api.tx.scheduler.schedule(expectedBlockNumber, null, 0, transferTx);
759761
760 await submitTransactionAsync(sender, scheduleTx);762 await submitTransactionAsync(sender, scheduleTx);
761763
762 const recipientBalanceBefore = new BigNumber((await api.query.system.account(recipient.address)).data.free.toString());764 const recipientBalanceBefore = new BigNumber((await api.query.system.account(recipient.address)).data.free.toString());
763765
764 const nftItemDataBefore = (await api.query.nft.nftItemList(collectionId, tokenId)).toJSON() as unknown as ITokenDataType;766 const nftItemDataBefore = (await api.query.nft.nftItemList(collectionId, tokenId)).toJSON() as any as ITokenDataType;
765 expect(nftItemDataBefore.Owner.toString()).to.be.equal(sender.address);767 expect(toSubstrateAddress(nftItemDataBefore.Owner)).to.be.equal(sender.address);
766768
767 // sleep for 2 blocks769 // sleep for 4 blocks
768 await new Promise(resolve => setTimeout(resolve, 6000 * 2));770 await new Promise(resolve => setTimeout(resolve, blockTimeMs * (blockSchedule + 1)));
769771
770 const recipientBalanceAfter = new BigNumber((await api.query.system.account(recipient.address)).data.free.toString());772 const recipientBalanceAfter = new BigNumber((await api.query.system.account(recipient.address)).data.free.toString());
771773
772 const nftItemData = (await api.query.nft.nftItemList(collectionId, tokenId)).toJSON() as unknown as ITokenDataType;774 const nftItemData = (await api.query.nft.nftItemList(collectionId, tokenId)).toJSON() as unknown as ITokenDataType;
773 expect(nftItemData.Owner.toString()).to.be.equal(recipient.address);775 expect(toSubstrateAddress(nftItemData.Owner)).to.be.equal(recipient.address);
774 expect(recipientBalanceAfter.toNumber()).to.be.equal(recipientBalanceBefore.toNumber());776 expect(recipientBalanceAfter.toNumber()).to.be.equal(recipientBalanceBefore.toNumber());
775 });777 });
776}778}