difftreelog
Merge branch 'feature/fix-tests' of github.com:usetech-llc/nft_private into feature/fix-tests
in: master
2 files changed
tests/src/scheduler.test.tsdiffbeforeafterboth18chai.use(chaiAsPromised);18chai.use(chaiAsPromised);191920describe('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);303031 await scheduleTransferExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 1);31 await scheduleTransferExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 1, 6000, 4);32 });32 });33 });33 });34});34});tests/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());
});
}