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.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 { ApiPromise } from '@polkadot/api';7import chai from 'chai';8import chaiAsPromised from 'chai-as-promised';9import privateKey from './substrate/privateKey';10import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from './substrate/substrate-api';11import {createCollectionExpectSuccess, destroyCollectionExpectSuccess} from './util/helpers';1213chai.use(chaiAsPromised);14const expect = chai.expect;1516describe('Integration Test removeCollectionAdmin(collection_id, account_id):', () => {17 it('Remove collection admin.', async () => {18 await usingApi(async (api: ApiPromise) => {19 const collectionId = await createCollectionExpectSuccess();20 const Alice = privateKey('//Alice');21 const Bob = privateKey('//Bob');22 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();23 expect(collection.Owner.toString()).to.be.eq(Alice.address);24 // first - add collection admin Bob25 const addAdminTx = api.tx.nft.addCollectionAdmin(collectionId, Bob.address);26 await submitTransactionAsync(Alice, addAdminTx);2728 const adminListAfterAddAdmin: any = (await api.query.nft.adminList(collectionId));29 expect(adminListAfterAddAdmin).to.be.contains(Bob.address);3031 // then remove bob from admins of collection32 const removeAdminTx = api.tx.nft.removeCollectionAdmin(collectionId, Bob.address);33 await submitTransactionAsync(Alice, removeAdminTx);3435 const adminListAfterRemoveAdmin: any = (await api.query.nft.adminList(collectionId));36 expect(adminListAfterRemoveAdmin).not.to.be.contains(Bob.address);37 });38 });39});4041describe('Negative Integration Test removeCollectionAdmin(collection_id, account_id):', () => {42 it('Can\'t remove collection admin from not existing collection', async () => {43 await usingApi(async (api: ApiPromise) => {44 // tslint:disable-next-line: no-bitwise45 const collectionId = (1 << 32) - 1;46 const alice = privateKey('//Alice');47 const bob = privateKey('//Bob');4849 const changeOwnerTx = api.tx.nft.removeCollectionAdmin(collectionId, bob.address);50 await expect(submitTransactionExpectFailAsync(alice, changeOwnerTx)).to.be.rejected;5152 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)53 await createCollectionExpectSuccess();54 });55 });5657 it('Can\'t remove collection admin from deleted collection', async () => {58 await usingApi(async (api: ApiPromise) => {59 // tslint:disable-next-line: no-bitwise60 const collectionId = await createCollectionExpectSuccess();61 const Alice = privateKey('//Alice');62 const Bob = privateKey('//Bob');6364 await destroyCollectionExpectSuccess(collectionId);6566 const changeOwnerTx = api.tx.nft.removeCollectionAdmin(collectionId, Bob.address);67 await expect(submitTransactionExpectFailAsync(Alice, changeOwnerTx)).to.be.rejected;6869 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)70 await createCollectionExpectSuccess();71 });72 });7374 it('Remove admin from collection that has no admins', async () => {75 await usingApi(async (api: ApiPromise) => {76 const Alice = privateKey('//Alice');77 const collectionId = await createCollectionExpectSuccess();7879 const adminListBeforeAddAdmin: any = (await api.query.nft.adminList(collectionId));80 expect(adminListBeforeAddAdmin).to.have.lengthOf(0);8182 const tx = api.tx.nft.removeCollectionAdmin(collectionId, Alice.address);83 await expect(submitTransactionExpectFailAsync(Alice, tx)).to.be.rejected;84 });85 });86});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 { ApiPromise } from '@polkadot/api';7import chai from 'chai';8import chaiAsPromised from 'chai-as-promised';9import privateKey from './substrate/privateKey';10import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from './substrate/substrate-api';11import {createCollectionExpectSuccess, destroyCollectionExpectSuccess} from './util/helpers';1213chai.use(chaiAsPromised);14const expect = chai.expect;1516describe('Integration Test removeCollectionAdmin(collection_id, account_id):', () => {17 it('Remove collection admin.', async () => {18 await usingApi(async (api: ApiPromise) => {19 const collectionId = await createCollectionExpectSuccess();20 const Alice = privateKey('//Alice');21 const Bob = privateKey('//Bob');22 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();23 expect(collection.Owner.toString()).to.be.eq(Alice.address);24 // first - add collection admin Bob25 const addAdminTx = api.tx.nft.addCollectionAdmin(collectionId, Bob.address);26 await submitTransactionAsync(Alice, addAdminTx);2728 const adminListAfterAddAdmin: any = (await api.query.nft.adminList(collectionId));29 expect(adminListAfterAddAdmin).to.be.contains(Bob.address);3031 // then remove bob from admins of collection32 const removeAdminTx = api.tx.nft.removeCollectionAdmin(collectionId, Bob.address);33 await submitTransactionAsync(Alice, removeAdminTx);3435 const adminListAfterRemoveAdmin: any = (await api.query.nft.adminList(collectionId));36 expect(adminListAfterRemoveAdmin).not.to.be.contains(Bob.address);37 });38 });3940 it('Remove admin from collection that has no admins', async () => {41 await usingApi(async (api: ApiPromise) => {42 const Alice = privateKey('//Alice');43 const collectionId = await createCollectionExpectSuccess();4445 const adminListBeforeAddAdmin: any = (await api.query.nft.adminList(collectionId));46 expect(adminListBeforeAddAdmin).to.have.lengthOf(0);4748 const tx = api.tx.nft.removeCollectionAdmin(collectionId, Alice.address);49 await submitTransactionAsync(Alice, tx);50 });51 });52});5354describe('Negative Integration Test removeCollectionAdmin(collection_id, account_id):', () => {55 it('Can\'t remove collection admin from not existing collection', async () => {56 await usingApi(async (api: ApiPromise) => {57 // tslint:disable-next-line: no-bitwise58 const collectionId = (1 << 32) - 1;59 const alice = privateKey('//Alice');60 const bob = privateKey('//Bob');6162 const changeOwnerTx = api.tx.nft.removeCollectionAdmin(collectionId, bob.address);63 await expect(submitTransactionExpectFailAsync(alice, changeOwnerTx)).to.be.rejected;6465 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)66 await createCollectionExpectSuccess();67 });68 });6970 it('Can\'t remove collection admin from deleted collection', async () => {71 await usingApi(async (api: ApiPromise) => {72 // tslint:disable-next-line: no-bitwise73 const collectionId = await createCollectionExpectSuccess();74 const Alice = privateKey('//Alice');75 const Bob = privateKey('//Bob');7677 await destroyCollectionExpectSuccess(collectionId);7879 const changeOwnerTx = api.tx.nft.removeCollectionAdmin(collectionId, Bob.address);80 await expect(submitTransactionExpectFailAsync(Alice, changeOwnerTx)).to.be.rejected;8182 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)83 await createCollectionExpectSuccess();84 });85 });86});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());
}
});
}