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
before · tests/src/scheduler.test.ts
1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56import chai from 'chai';7import chaiAsPromised from 'chai-as-promised';8import privateKey from './substrate/privateKey';9import usingApi from './substrate/substrate-api';10import {11  createItemExpectSuccess,12  createCollectionExpectSuccess,13  scheduleTransferExpectSuccess,14  setCollectionSponsorExpectSuccess,15  confirmSponsorshipExpectSuccess,16} from './util/helpers';1718chai.use(chaiAsPromised);1920describe('Integration Test scheduler base transaction', () => {21  it('User can transfer owned token with delay (scheduler)', async () => {22    await usingApi(async () => {23      const Alice = privateKey('//Alice');24      const Bob = privateKey('//Bob');25      // nft26      const nftCollectionId = await createCollectionExpectSuccess();27      const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');28      await setCollectionSponsorExpectSuccess(nftCollectionId, Alice.address);29      await confirmSponsorshipExpectSuccess(nftCollectionId);3031      await scheduleTransferExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 1);32    });33  });34});
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -84,7 +84,7 @@
 }
 
 interface ITokenDataType {
-  Owner: number[];
+  Owner: IKeyringPair;
   ConstData: number[];
   VariableData: number[];
 }
@@ -748,29 +748,31 @@
   sender: IKeyringPair,
   recipient: IKeyringPair,
   value: number | bigint = 1,
+  blockTimeMs: number,
+  blockSchedule: number
 ) {
   await usingApi(async (api: ApiPromise) => {
     const blockNumber: number | undefined = await getBlockNumber(api);
-    const expectedBlockNumber = blockNumber + 2;
+    const expectedBlockNumber = blockNumber + blockSchedule;
 
     expect(blockNumber).to.be.greaterThan(0);
-    const transferTx = await api.tx.nft.transfer(recipient.address, collectionId, tokenId, value); 
+    const transferTx = await api.tx.nft.transfer(normalizeAccountId(recipient.address), collectionId, tokenId, value); 
     const scheduleTx = await api.tx.scheduler.schedule(expectedBlockNumber, null, 0, transferTx);
 
     await submitTransactionAsync(sender, scheduleTx);
 
     const recipientBalanceBefore = new BigNumber((await api.query.system.account(recipient.address)).data.free.toString());
 
-    const nftItemDataBefore = (await api.query.nft.nftItemList(collectionId, tokenId)).toJSON() as unknown as ITokenDataType;
-    expect(nftItemDataBefore.Owner.toString()).to.be.equal(sender.address);
+    const nftItemDataBefore = (await api.query.nft.nftItemList(collectionId, tokenId)).toJSON() as any as ITokenDataType;
+    expect(toSubstrateAddress(nftItemDataBefore.Owner)).to.be.equal(sender.address);
 
-    // sleep for 2 blocks
-    await new Promise(resolve => setTimeout(resolve, 6000 * 2));
+    // sleep for 4 blocks
+    await new Promise(resolve => setTimeout(resolve, blockTimeMs * (blockSchedule + 1)));
 
     const recipientBalanceAfter = new BigNumber((await api.query.system.account(recipient.address)).data.free.toString());
 
     const nftItemData = (await api.query.nft.nftItemList(collectionId, tokenId)).toJSON() as unknown as ITokenDataType;
-    expect(nftItemData.Owner.toString()).to.be.equal(recipient.address);
+    expect(toSubstrateAddress(nftItemData.Owner)).to.be.equal(recipient.address);
     expect(recipientBalanceAfter.toNumber()).to.be.equal(recipientBalanceBefore.toNumber());
   });
 }