difftreelog
Add tests
in: master
NFTPAR-218
7 files changed
tests/src/collision-tests/admVsOwnerChanges.test.tsdiffbeforeafterboth--- a/tests/src/collision-tests/admVsOwnerChanges.test.ts
+++ b/tests/src/collision-tests/admVsOwnerChanges.test.ts
@@ -48,8 +48,6 @@
]);
const itemBefore: any = await api.query.nft.nftItemList(collectionId, itemId);
expect(itemBefore.Owner.toString()).not.to.be.eq(Bob.address);
- const blockHash = await api.query.system.number();
- console.log(`blockHash: ${blockHash}`);
});
});
});
tests/src/collision-tests/admVsOwnerData.test.tsdiffbeforeafterboth--- a/tests/src/collision-tests/admVsOwnerData.test.ts
+++ b/tests/src/collision-tests/admVsOwnerData.test.ts
@@ -47,8 +47,6 @@
]);
const item: any = await api.query.nft.nftItemList(collectionId, itemId);
expect(Array.from(item.VariableData)).to.deep.equal(Array.from([]));
- const blockHash = await api.query.system.number();
- console.log(`blockHash: ${blockHash}`);
});
});
});
tests/src/collision-tests/admVsOwnerTake.test.tsdiffbeforeafterboth--- a/tests/src/collision-tests/admVsOwnerTake.test.ts
+++ b/tests/src/collision-tests/admVsOwnerTake.test.ts
@@ -44,8 +44,6 @@
]);
const itemBurn: any = await api.query.nft.nftItemList(collectionId, itemId);
expect(itemBurn.Owner.toString()).to.be.eq('5C4hrfjw9DjXZTzV3MwzrrAr9P1MJhSrvWGWqi1eSuyUpnhM');
- const blockHash = await api.query.system.number();
- console.log(`blockHash: ${blockHash}`);
});
});
});
tests/src/collision-tests/adminLimitsOff.test.tsdiffbeforeafterboth1import { IKeyringPair } from '@polkadot/types/types';2import BN from 'bn.js';3import chai from 'chai';4import chaiAsPromised from 'chai-as-promised';5import privateKey from '../substrate/privateKey';6import usingApi, { submitTransactionAsync, submitTransactionExpectFailAsync } from '../substrate/substrate-api';7import {8 createCollectionExpectSuccess,9} from '../util/helpers';1011chai.use(chaiAsPromised);12const expect = chai.expect;13interface ITokenDataType {14 Owner: number[];15 ConstData: number[];16 VariableData: number[];17}18let Alice: IKeyringPair;19let Bob: IKeyringPair;20let Ferdie: IKeyringPair;21let Charlie: IKeyringPair;22let Eve: IKeyringPair;23let Dave: IKeyringPair;2425before(async () => {26 await usingApi(async () => {27 Alice = privateKey('//Alice');28 Bob = privateKey('//Bob');29 Ferdie = privateKey('//Ferdie');30 Charlie = privateKey('//Charlie');31 Eve = privateKey('//Eve');32 Dave = privateKey('//Dave');33 });34});3536describe('Admin limit exceeded collection: ', () => {37 // tslint:disable-next-line: max-line-length38 it('In one block, the owner and admin add new admins to the collection more than the limit ', async () => {39 await usingApi(async (api) => {40 const collectionId = await createCollectionExpectSuccess();4142 const chainLimit = await api.query.nft.chainLimit() as unknown as { CollectionAdminsLimit: BN };43 const chainAdminLimit = chainLimit.CollectionAdminsLimit.toNumber();44 expect(chainAdminLimit).to.be.equal(5);4546 const changeAdminTx1 = api.tx.nft.addCollectionAdmin(collectionId, Eve.address);47 await submitTransactionAsync(Alice, changeAdminTx1);48 const changeAdminTx2 = api.tx.nft.addCollectionAdmin(collectionId, Dave.address);49 await submitTransactionAsync(Alice, changeAdminTx2);50 const changeAdminTx3 = api.tx.nft.addCollectionAdmin(collectionId, Bob.address);51 await submitTransactionAsync(Alice, changeAdminTx3);5253 const timeoutPromise = (timeout: number) => new Promise((resolve) => setTimeout(resolve, timeout));54 //55 const addAdmOne = api.tx.nft.addCollectionAdmin(collectionId, Ferdie.address);56 const addAdmTwo = api.tx.nft.addCollectionAdmin(collectionId, Charlie.address);57 await Promise.all58 ([59 addAdmOne.signAndSend(Bob),60 addAdmTwo.signAndSend(Alice),61 ]);62 await timeoutPromise(10000);63 const changeAdminTx4 = api.tx.nft.addCollectionAdmin(collectionId, Alice.address);64 // tslint:disable-next-line: no-unused-expression65 expect(submitTransactionExpectFailAsync(Alice, changeAdminTx4)).to.be.rejected;6667 const adminListAfterAddAdmin: any = (await api.query.nft.adminList(collectionId));68 expect(adminListAfterAddAdmin).to.be.contains(Eve.address);69 expect(adminListAfterAddAdmin).to.be.contains(Ferdie.address);70 expect(adminListAfterAddAdmin).not.to.be.contains(Alice.address);71 });72 });73});tests/src/collision-tests/sponsorPayments.test.tsdiffbeforeafterboth--- a/tests/src/collision-tests/sponsorPayments.test.ts
+++ b/tests/src/collision-tests/sponsorPayments.test.ts
@@ -51,8 +51,6 @@
expect(alicesBalanceAfter === alicesBalanceBefore).to.be.true;
// tslint:disable-next-line:no-unused-expression
expect(bobsBalanceAfter === bobsBalanceBefore).to.be.true;
- const blockHash = await api.query.system.number();
- console.log(`blockHash: ${blockHash}`);
});
});
});
tests/src/collision-tests/tokenLimitsOff.test.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/collision-tests/tokenLimitsOff.test.ts
@@ -0,0 +1,95 @@
+import { IKeyringPair } from '@polkadot/types/types';
+import BN from 'bn.js';
+import chai from 'chai';
+import chaiAsPromised from 'chai-as-promised';
+import privateKey from '../substrate/privateKey';
+import usingApi, { submitTransactionAsync } from '../substrate/substrate-api';
+import {
+ addToWhiteListExpectSuccess,
+ createCollectionExpectSuccess,
+ getCreateItemResult,
+ setMintPermissionExpectSuccess,
+} from '../util/helpers';
+
+chai.use(chaiAsPromised);
+const expect = chai.expect;
+interface ITokenDataType {
+ Owner: number[];
+ ConstData: number[];
+ VariableData: number[];
+}
+let Alice: IKeyringPair;
+let Bob: IKeyringPair;
+let Ferdie: IKeyringPair;
+
+const AccountTokenOwnershipLimit = 4;
+const SponsoredMintSize = 4294967295;
+const TokenLimit = 4;
+const SponsorTimeout = 14400;
+const OwnerCanTransfer = false;
+const OwnerCanDestroy = false;
+
+before(async () => {
+ await usingApi(async () => {
+ Alice = privateKey('//Alice');
+ Bob = privateKey('//Bob');
+ Ferdie = privateKey('//Ferdie');
+ });
+});
+
+describe('Token limit exceeded collection: ', () => {
+ // tslint:disable-next-line: max-line-length
+ it('The number of tokens created in the collection from different addresses exceeds the allowed collection limit ', async () => {
+ await usingApi(async (api) => {
+ const collectionId = await createCollectionExpectSuccess();
+ await setMintPermissionExpectSuccess(Alice, collectionId, true);
+ await addToWhiteListExpectSuccess(Alice, collectionId, Ferdie.address);
+ await addToWhiteListExpectSuccess(Alice, collectionId, Bob.address);
+ const setCollectionLim = api.tx.nft.setCollectionLimits(
+ collectionId,
+ {
+ AccountTokenOwnershipLimit,
+ SponsoredMintSize,
+ TokenLimit,
+ // tslint:disable-next-line: object-literal-sort-keys
+ SponsorTimeout,
+ OwnerCanTransfer,
+ OwnerCanDestroy,
+ },
+ );
+ const subTx = await submitTransactionAsync(Alice, setCollectionLim);
+ const subTxTesult = getCreateItemResult(subTx);
+ // tslint:disable-next-line:no-unused-expression
+ expect(subTxTesult.success).to.be.true;
+ const timeoutPromise = (timeout: number) => new Promise((resolve) => setTimeout(resolve, timeout));
+ await timeoutPromise(10000);
+ //
+ const args = [{ nft: ['0x31', '0x31'] }, { nft: ['0x32', '0x32'] }, { nft: ['0x33', '0x33'] }];
+ const mintItemOne = api.tx.nft
+ .createMultipleItems(collectionId, Ferdie.address, args);
+ const mintItemTwo = api.tx.nft
+ .createMultipleItems(collectionId, Bob.address, args);
+ await Promise.all
+ ([
+ mintItemOne.signAndSend(Ferdie),
+ mintItemTwo.signAndSend(Bob),
+ ]);
+ await timeoutPromise(10000);
+ const itemsListIndexAfter = await api.query.nft.itemListIndex(collectionId) as unknown as BN;
+ expect(itemsListIndexAfter.toNumber()).to.be.equal(6); // Maybe 4? TokenLimit = 4.
+ const token1Data = await api.query.nft.nftItemList(collectionId, 1) as unknown as ITokenDataType;
+ const token2Data = await api.query.nft.nftItemList(collectionId, 2) as unknown as ITokenDataType;
+ const token3Data = await api.query.nft.nftItemList(collectionId, 3) as unknown as ITokenDataType;
+ const token4Data = await api.query.nft.nftItemList(collectionId, 4) as unknown as ITokenDataType;
+ const token5Data = await api.query.nft.nftItemList(collectionId, 5) as unknown as ITokenDataType;
+ const token6Data = await api.query.nft.nftItemList(collectionId, 6) as unknown as ITokenDataType;
+
+ expect(token1Data.Owner.toString()).to.be.equal(Bob.address);
+ expect(token2Data.Owner.toString()).to.be.equal(Bob.address);
+ expect(token3Data.Owner.toString()).to.be.equal(Bob.address);
+ expect(token4Data.Owner.toString()).to.be.equal(Ferdie.address);
+ expect(token5Data.Owner.toString()).to.be.equal(Ferdie.address);
+ expect(token6Data.Owner.toString()).to.be.equal(Ferdie.address);
+ });
+ });
+});
tests/src/collision-tests/turnsOffMinting.test.tsdiffbeforeafterboth--- a/tests/src/collision-tests/turnsOffMinting.test.ts
+++ b/tests/src/collision-tests/turnsOffMinting.test.ts
@@ -41,8 +41,6 @@
]);
const itemList: any = await api.query.nft.nftItemList(collectionId, mintItem);
expect(itemList.Owner.toString()).to.be.eq('5C4hrfjw9DjXZTzV3MwzrrAr9P1MJhSrvWGWqi1eSuyUpnhM');
- const blockHash = await api.query.system.number();
- console.log(`blockHash: ${blockHash}`);
});
});
});