difftreelog
tests: fix tests for optional collections
in: master
10 files changed
tests/package.jsondiffbeforeafterboth1{2 "name": "NftTests",3 "version": "1.0.0",4 "description": "Substrate Nft tests",5 "main": "",6 "devDependencies": {7 "@polkadot/dev": "^0.61.24",8 "@polkadot/ts": "^0.3.59",9 "@polkadot/typegen": "^3.6.4",10 "@polkadot/util-crypto": "^5.4.4",11 "@types/chai": "^4.2.12",12 "@types/chai-as-promised": "^7.1.3",13 "@types/mocha": "^8.0.3",14 "chai": "^4.2.0",15 "mocha": "^8.1.1",16 "ts-node": "^9.0.0",17 "tslint": "^5.20.1",18 "typescript": "^3.9.7"19 },20 "scripts": {21 "test": "mocha --timeout 9999999 -r ts-node/register ./**/*.test.ts",22 "load": "mocha --timeout 9999999 -r ts-node/register ./**/*.load.ts",23 "loadTransfer": "ts-node src/transfer.nload.ts",24 "testAddCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/addCollectionAdmin.test.ts",25 "testSetSchemaVersion": "mocha --timeout 9999999 -r ts-node/register ./**/setSchemaVersion.test.ts",26 "testSetVariableMetaData": "mocha --timeout 9999999 -r ts-node/register ./**/setVariableMetaData.test.ts",27 "testSetCollectionLimits": "mocha --timeout 9999999 -r ts-node/register ./**/setCollectionLimits.test.ts",28 "testSetCollectionSponsor": "mocha --timeout 9999999 -r ts-node/register ./**/setCollectionSponsor.test.ts",29 "testConfirmSponsorship": "mocha --timeout 9999999 -r ts-node/register ./**/confirmSponsorship.test.ts",30 "testRemoveCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/removeCollectionAdmin.test.ts",31 "testRemoveCollectionSponsor": "mocha --timeout 9999999 -r ts-node/register ./**/removeCollectionSponsor.test.ts",32 "testRemoveFromWhiteList": "mocha --timeout 9999999 -r ts-node/register ./**/removeFromWhiteList.test.ts",33 "testConnection": "mocha --timeout 9999999 -r ts-node/register ./**/connection.test.ts",34 "testCollection": "mocha --timeout 9999999 -r ts-node/register ./**/createCollection.test.ts",35 "testCreateItem": "mocha --timeout 9999999 -r ts-node/register ./**/createItem.test.ts",36 "testCreateMultipleItems": "mocha --timeout 9999999 -r ts-node/register ./**/createMultipleItems.test.ts",37 "testApprove": "mocha --timeout 9999999 -r ts-node/register ./**/approve.test.ts",38 "testTransferFrom": "mocha --timeout 9999999 -r ts-node/register ./**/transferFrom.test.ts",39 "testCreateCollection": "mocha --timeout 9999999 -r ts-node/register ./**/createCollection.test.ts",40 "testToggleContractWhiteList": "mocha --timeout 9999999 -r ts-node/register ./**/toggleContractWhiteList.test.ts",41 "testAddToContractWhiteList": "mocha --timeout 9999999 -r ts-node/register ./**/addToContractWhiteList.test.ts",42 "testTransfer": "mocha --timeout 9999999 -r ts-node/register ./**/transfer.test.ts",43 "testBurnItem": "mocha --timeout 9999999 -r ts-node/register ./**/burnItem.test.ts",44 "testSetMintPermission": "mocha --timeout 9999999 -r ts-node/register ./**/setMintPermission.test.ts",45 "testCreditFeesToTreasury": "mocha --timeout 9999999 -r ts-node/register ./**/creditFeesToTreasury.test.ts",46 "testEnableContractSponsoring": "mocha --timeout 9999999 -r ts-node/register ./**/enableContractSponsoring.test.ts",47 "testSetContractSponsoringRateLimit": "mocha --timeout 9999999 -r ts-node/register ./**/setContractSponsoringRateLimit.test.ts",48 "testSetOffchainSchema": "mocha --timeout 9999999 -r ts-node/register ./**/setOffchainSchema.test.ts",49 "testOverflow": "mocha --timeout 9999999 -r ts-node/register ./**/overflow.test.ts",50 "testSetVariableMetadataSponsoringRateLimit": "mocha --timeout 9999999 -r ts-node/register ./**/setVariableMetadataSponsoringRateLimit.test.ts"51 },52 "author": "",53 "license": "SEE LICENSE IN ../LICENSE",54 "homepage": "",55 "dependencies": {56 "@polkadot/api": "3.8.1",57 "@polkadot/api-contract": "3.8.1",58 "@polkadot/util": "5.6.2",59 "bignumber.js": "^9.0.0",60 "chai-as-promised": "^7.1.1"61 },62 "standard": {63 "globals": [64 "it",65 "assert",66 "beforeEach",67 "afterEach",68 "describe",69 "contract",70 "artifacts"71 ]72 }73}tests/src/approve.test.tsdiffbeforeafterboth--- a/tests/src/approve.test.ts
+++ b/tests/src/approve.test.ts
@@ -123,9 +123,6 @@
// nft
const nftCollectionId = await createCollectionExpectSuccess();
await approveExpectFail(nftCollectionId, 2, Alice, Bob);
- // fungible
- const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
- await approveExpectFail(fungibleCollectionId, 2, Alice, Bob);
// reFungible
const reFungibleCollectionId =
await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
tests/src/burnItem.test.tsdiffbeforeafterboth--- a/tests/src/burnItem.test.ts
+++ b/tests/src/burnItem.test.ts
@@ -46,8 +46,7 @@
// tslint:disable-next-line:no-unused-expression
expect(result.success).to.be.true;
// tslint:disable-next-line:no-unused-expression
- expect(item).to.be.not.null;
- expect(item.Owner).to.be.equal(nullPublicKey);
+ expect(item).to.be.null;
});
});
@@ -88,8 +87,7 @@
// What to expect
expect(result.success).to.be.true;
- expect(balance).to.be.not.null;
- expect(balance.Owner.length).to.be.equal(0);
+ expect(balance).to.be.null;
});
});
tests/src/contracts.test.tsdiffbeforeafterboth--- a/tests/src/contracts.test.ts
+++ b/tests/src/contracts.test.ts
@@ -63,13 +63,13 @@
const collectionId = await createCollectionExpectSuccess();
const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');
const [contract, deployer] = await deployTransferContract(api);
- const tokenBefore: any = await api.query.nft.nftItemList(collectionId, tokenId);
+ const tokenBefore: any = (await api.query.nft.nftItemList(collectionId, tokenId) as any).unwrap();
// Transfer
const transferTx = contract.tx.transfer(value, gasLimit, bob.address, collectionId, tokenId, 1);
const events = await submitTransactionAsync(alice, transferTx);
const result = getGenericResult(events);
- const tokenAfter: any = await api.query.nft.nftItemList(collectionId, tokenId);
+ const tokenAfter: any = (await api.query.nft.nftItemList(collectionId, tokenId) as any).unwrap();
// tslint:disable-next-line:no-unused-expression
expect(result.success).to.be.true;
tests/src/createMultipleItems.test.tsdiffbeforeafterboth--- a/tests/src/createMultipleItems.test.ts
+++ b/tests/src/createMultipleItems.test.ts
@@ -38,9 +38,9 @@
await submitTransactionAsync(Alice, createMultipleItemsTx);
const itemsListIndexAfter = await api.query.nft.itemListIndex(collectionId) as unknown as BN;
expect(itemsListIndexAfter.toNumber()).to.be.equal(3);
- 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 token1Data = (await api.query.nft.nftItemList(collectionId, 1)).toJSON() as unknown as ITokenDataType;
+ const token2Data = (await api.query.nft.nftItemList(collectionId, 2)).toJSON() as unknown as ITokenDataType;
+ const token3Data = (await api.query.nft.nftItemList(collectionId, 3)).toJSON() as unknown as ITokenDataType;
expect(token1Data.Owner.toString()).to.be.equal(Alice.address);
expect(token2Data.Owner.toString()).to.be.equal(Alice.address);
@@ -72,9 +72,9 @@
await submitTransactionAsync(Alice, createMultipleItemsTx);
const itemsListIndexAfter = await api.query.nft.itemListIndex(collectionId) as unknown as BN;
expect(itemsListIndexAfter.toNumber()).to.be.equal(3);
- const token1Data = await api.query.nft.reFungibleItemList(collectionId, 1) as unknown as IReFungibleTokenDataType;
- const token2Data = await api.query.nft.reFungibleItemList(collectionId, 2) as unknown as IReFungibleTokenDataType;
- const token3Data = await api.query.nft.reFungibleItemList(collectionId, 3) as unknown as IReFungibleTokenDataType;
+ const token1Data = (await api.query.nft.reFungibleItemList(collectionId, 1) as any).unwrap() as unknown as IReFungibleTokenDataType;
+ const token2Data = (await api.query.nft.reFungibleItemList(collectionId, 2) as any).unwrap() as unknown as IReFungibleTokenDataType;
+ const token3Data = (await api.query.nft.reFungibleItemList(collectionId, 3) as any).unwrap() as unknown as IReFungibleTokenDataType;
expect(token1Data.Owner[0].Owner.toString()).to.be.equal(Alice.address);
expect(token1Data.Owner[0].Fraction.toNumber()).to.be.equal(1);
tests/src/removeCollectionAdmin.test.tsdiffbeforeafterboth--- a/tests/src/removeCollectionAdmin.test.ts
+++ b/tests/src/removeCollectionAdmin.test.ts
@@ -36,6 +36,19 @@
expect(adminListAfterRemoveAdmin).not.to.be.contains(Bob.address);
});
});
+
+ it('Remove admin from collection that has no admins', async () => {
+ await usingApi(async (api: ApiPromise) => {
+ const Alice = privateKey('//Alice');
+ const collectionId = await createCollectionExpectSuccess();
+
+ const adminListBeforeAddAdmin: any = (await api.query.nft.adminList(collectionId));
+ expect(adminListBeforeAddAdmin).to.have.lengthOf(0);
+
+ const tx = api.tx.nft.removeCollectionAdmin(collectionId, Alice.address);
+ await submitTransactionAsync(Alice, tx);
+ });
+ });
});
describe('Negative Integration Test removeCollectionAdmin(collection_id, account_id):', () => {
@@ -68,19 +81,6 @@
// Verifying that nothing bad happened (network is live, new collections can be created, etc.)
await createCollectionExpectSuccess();
- });
- });
-
- it('Remove admin from collection that has no admins', async () => {
- await usingApi(async (api: ApiPromise) => {
- const Alice = privateKey('//Alice');
- const collectionId = await createCollectionExpectSuccess();
-
- const adminListBeforeAddAdmin: any = (await api.query.nft.adminList(collectionId));
- expect(adminListBeforeAddAdmin).to.have.lengthOf(0);
-
- const tx = api.tx.nft.removeCollectionAdmin(collectionId, Alice.address);
- await expect(submitTransactionExpectFailAsync(Alice, tx)).to.be.rejected;
});
});
});
tests/src/removeFromContractWhiteList.test.tsdiffbeforeafterboth--- a/tests/src/removeFromContractWhiteList.test.ts
+++ b/tests/src/removeFromContractWhiteList.test.ts
@@ -13,8 +13,10 @@
describe('Integration Test removeFromContractWhiteList', () => {
let bob: IKeyringPair;
- before(() => {
- bob = privateKey('//Bob');
+ before(async () => {
+ await usingApi(async () => {
+ bob = privateKey('//Bob');
+ });
});
it('user is no longer whitelisted after removal', async () => {
@@ -56,9 +58,11 @@
let alice: IKeyringPair;
let bob: IKeyringPair;
- before(() => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
+ before(async () => {
+ await usingApi(async () => {
+ alice = privateKey('//Alice');
+ bob = privateKey('//Bob');
+ });
});
it('fails when called with non-contract address', async () => {
tests/src/setVariableMetaData.test.tsdiffbeforeafterboth--- a/tests/src/setVariableMetaData.test.ts
+++ b/tests/src/setVariableMetaData.test.ts
@@ -41,7 +41,7 @@
it('verify data was set', async () => {
await usingApi(async api => {
- const item: any = await api.query.nft.nftItemList(collectionId, tokenId);
+ const item: any = (await api.query.nft.nftItemList(collectionId, tokenId) as any).unwrap();
expect(Array.from(item.VariableData)).to.deep.equal(Array.from(data));
});
tests/src/transferFrom.test.tsdiffbeforeafterboth--- a/tests/src/transferFrom.test.ts
+++ b/tests/src/transferFrom.test.ts
@@ -237,7 +237,7 @@
const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');
await burnItemExpectSuccess(Alice, fungibleCollectionId, 1, 10);
- await approveExpectFail(fungibleCollectionId, newFungibleTokenId, Alice, Bob);
+ await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);
await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 1);
});
tests/src/util/helpers.tsdiffbeforeafterboth--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -599,8 +599,7 @@
// tslint:disable-next-line:no-unused-expression
expect(result.success).to.be.true;
// tslint:disable-next-line:no-unused-expression
- expect(item).to.be.not.null;
- expect(item.Owner).to.be.equal(nullPublicKey);
+ expect(item).to.be.null;
});
}
@@ -641,16 +640,16 @@
// tslint:disable-next-line:no-unused-expression
expect(result.success).to.be.true;
if (type === 'NFT') {
- const nftItemData = await api.query.nft.nftItemList(collectionId, tokenId) as unknown as ITokenDataType;
+ const nftItemData = (await api.query.nft.nftItemList(collectionId, tokenId) as any).unwrap() as ITokenDataType;
expect(nftItemData.Owner.toString()).to.be.equal(accountTo.address);
}
if (type === 'Fungible') {
- const balanceAfter = await api.query.nft.balance(collectionId, accountTo.address) as unknown as BN;
+ const balanceAfter = (await api.query.nft.fungibleItemList(collectionId, accountTo.address) as any).Value as unknown as BN;
expect(balanceAfter.sub(balanceBefore).toString()).to.be.equal(value.toString());
}
if (type === 'ReFungible') {
const nftItemData =
- await api.query.nft.reFungibleItemList(collectionId, tokenId) as unknown as IReFungibleTokenDataType;
+ (await api.query.nft.reFungibleItemList(collectionId, tokenId) as any).unwrap() as IReFungibleTokenDataType;
expect(nftItemData.Owner[0].Owner.toString()).to.be.equal(accountTo.address);
expect(nftItemData.Owner[0].Fraction.toNumber()).to.be.equal(value);
}
@@ -697,18 +696,18 @@
expect(result.recipient).to.be.equal(recipient.address);
expect(result.value.toString()).to.be.equal(value.toString());
if (type === 'NFT') {
- const nftItemData = await api.query.nft.nftItemList(collectionId, tokenId) as unknown as ITokenDataType;
+ const nftItemData = (await api.query.nft.nftItemList(collectionId, tokenId)).toJSON() as unknown as ITokenDataType;
expect(nftItemData.Owner.toString()).to.be.equal(recipient.address);
}
if (type === 'Fungible') {
- const balanceAfter = await api.query.nft.balance(collectionId, recipient.address) as unknown as BN;
+ const balanceAfter = (await api.query.nft.fungibleItemList(collectionId, recipient.address) as any).Value as unknown as BN;
expect(balanceAfter.sub(balanceBefore).toString()).to.be.equal(value.toString());
}
if (type === 'ReFungible') {
const nftItemData =
- await api.query.nft.reFungibleItemList(collectionId, tokenId) as unknown as IReFungibleTokenDataType;
+ (await api.query.nft.reFungibleItemList(collectionId, tokenId)).toJSON() as unknown as IReFungibleTokenDataType;
expect(nftItemData.Owner[0].Owner.toString()).to.be.equal(recipient.address);
- expect(nftItemData.Owner[0].Fraction.toNumber()).to.be.equal(value);
+ expect(nftItemData.Owner[0].Fraction.toString()).to.be.equal(value.toString());
}
});
}