difftreelog
tests: fix tests for optional collections
in: master
10 files changed
tests/package.jsondiffbeforeafterboth--- a/tests/package.json
+++ b/tests/package.json
@@ -32,6 +32,7 @@
"testRemoveFromWhiteList": "mocha --timeout 9999999 -r ts-node/register ./**/removeFromWhiteList.test.ts",
"testConnection": "mocha --timeout 9999999 -r ts-node/register ./**/connection.test.ts",
"testCollection": "mocha --timeout 9999999 -r ts-node/register ./**/createCollection.test.ts",
+ "testContracts": "mocha --timeout 9999999 -r ts-node/register ./**/contracts.test.ts",
"testCreateItem": "mocha --timeout 9999999 -r ts-node/register ./**/createItem.test.ts",
"testCreateMultipleItems": "mocha --timeout 9999999 -r ts-node/register ./**/createMultipleItems.test.ts",
"testApprove": "mocha --timeout 9999999 -r ts-node/register ./**/approve.test.ts",
@@ -44,6 +45,7 @@
"testSetMintPermission": "mocha --timeout 9999999 -r ts-node/register ./**/setMintPermission.test.ts",
"testCreditFeesToTreasury": "mocha --timeout 9999999 -r ts-node/register ./**/creditFeesToTreasury.test.ts",
"testEnableContractSponsoring": "mocha --timeout 9999999 -r ts-node/register ./**/enableContractSponsoring.test.ts",
+ "testRemoveFromContractWhiteList": "mocha --timeout 9999999 -r ts-node/register ./**/removeFromContractWhiteList.test.ts",
"testSetContractSponsoringRateLimit": "mocha --timeout 9999999 -r ts-node/register ./**/setContractSponsoringRateLimit.test.ts",
"testSetOffchainSchema": "mocha --timeout 9999999 -r ts-node/register ./**/setOffchainSchema.test.ts",
"testOverflow": "mocha --timeout 9999999 -r ts-node/register ./**/overflow.test.ts",
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.tsdiffbeforeafterboth1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56import { IKeyringPair } from '@polkadot/types/types';7import chai from 'chai';8import chaiAsPromised from 'chai-as-promised';9import privateKey from './substrate/privateKey';10import usingApi from './substrate/substrate-api';11import {12 burnItemExpectSuccess,13 createCollectionExpectSuccess,14 createItemExpectSuccess,15 destroyCollectionExpectSuccess,16 findNotExistingCollection,17 setVariableMetaDataExpectFailure,18 setVariableMetaDataExpectSuccess,19} from './util/helpers';2021chai.use(chaiAsPromised);22const expect = chai.expect;2324describe('Integration Test setVariableMetaData', () => {25 const data = [1, 2, 254, 255];2627 let alice: IKeyringPair;28 let collectionId: number;29 let tokenId: number;30 before(async () => {31 await usingApi(async () => {32 alice = privateKey('//Alice');33 collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });34 tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');35 });36 });3738 it('execute setVariableMetaData', async () => {39 await setVariableMetaDataExpectSuccess(alice, collectionId, tokenId, data);40 });4142 it('verify data was set', async () => {43 await usingApi(async api => {44 const item: any = await api.query.nft.nftItemList(collectionId, tokenId);4546 expect(Array.from(item.VariableData)).to.deep.equal(Array.from(data));47 });48 });49});5051describe('Negative Integration Test setVariableMetaData', () => {52 let data = [1];5354 let alice: IKeyringPair;55 let bob: IKeyringPair;5657 let validCollectionId: number;58 let validTokenId: number;5960 before(async () => {61 await usingApi(async () => {62 alice = privateKey('//Alice');63 bob = privateKey('//Bob');6465 validCollectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });66 validTokenId = await createItemExpectSuccess(alice, validCollectionId, 'NFT');67 });68 });6970 it('fails on not existing collection id', async () => {71 await usingApi(async api => {72 let nonExistingCollectionId = await findNotExistingCollection(api);73 await setVariableMetaDataExpectFailure(alice, nonExistingCollectionId, 1, data);74 });75 });76 it('fails on removed collection id', async () => {77 const removedCollectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });78 const removedCollectionTokenId = await createItemExpectSuccess(alice, removedCollectionId, 'NFT');7980 await destroyCollectionExpectSuccess(removedCollectionId);81 await setVariableMetaDataExpectFailure(alice, removedCollectionId, removedCollectionTokenId, data);82 });83 it('fails on removed token', async () => {84 const removedTokenCollectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });85 const removedTokenId = await createItemExpectSuccess(alice, removedTokenCollectionId, 'NFT');86 await burnItemExpectSuccess(alice, removedTokenCollectionId, removedTokenId);8788 await setVariableMetaDataExpectFailure(alice, removedTokenCollectionId, removedTokenId, data);89 });90 it('fails on not existing token', async () => {91 const nonExistingTokenId = validTokenId + 1;9293 await setVariableMetaDataExpectFailure(alice, validCollectionId, nonExistingTokenId, data);94 });95 it('fails on too long data', async () => {96 const tooLongData = new Array(4097).fill(0xff);9798 await setVariableMetaDataExpectFailure(alice, validCollectionId, validTokenId, tooLongData);99 });100 it('fails on fungible token', async () => {101 const fungibleCollectionId = await createCollectionExpectSuccess({ mode: { type: 'Fungible', decimalPoints: 0 } });102 const fungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');103104 await setVariableMetaDataExpectFailure(alice, fungibleCollectionId, fungibleTokenId, data);105 });106 it('fails on bad sender', async () => {107 await setVariableMetaDataExpectFailure(bob, validCollectionId, validTokenId, data);108 });109});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());
}
});
}