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.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 { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from './substrate/substrate-api';7import { Keyring } from "@polkadot/api";8import { IKeyringPair } from "@polkadot/types/types";9import { 10 createCollectionExpectSuccess, 11 createItemExpectSuccess,12 getGenericResult,13 destroyCollectionExpectSuccess14} from './util/helpers';15import { nullPublicKey } from "./accounts";1617import chai from 'chai';18import chaiAsPromised from 'chai-as-promised';19chai.use(chaiAsPromised);20const expect = chai.expect;2122let alice: IKeyringPair;23let bob: IKeyringPair;2425describe('integration test: ext. burnItem():', () => {26 before(async () => {27 await usingApi(async (api) => {28 const keyring = new Keyring({ type: 'sr25519' });29 alice = keyring.addFromUri(`//Alice`);30 bob = keyring.addFromUri(`//Bob`);31 });32 });3334 it('Burn item in NFT collection', async () => {35 const createMode = 'NFT';36 const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}});37 const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);3839 await usingApi(async (api) => {40 const tx = api.tx.nft.burnItem(collectionId, tokenId, 0);41 const events = await submitTransactionAsync(alice, tx);42 const result = getGenericResult(events);43 // Get the item44 const item: any = (await api.query.nft.nftItemList(collectionId, tokenId)).toJSON();45 // What to expect46 // tslint:disable-next-line:no-unused-expression47 expect(result.success).to.be.true;48 // tslint:disable-next-line:no-unused-expression49 expect(item).to.be.not.null;50 expect(item.Owner).to.be.equal(nullPublicKey);51 });5253 });54 it('Burn item in Fungible collection', async () => {55 const createMode = 'Fungible';56 const collectionId = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0 }});57 await createItemExpectSuccess(alice, collectionId, createMode); // Helper creates 10 fungible tokens58 const tokenId = 0; // ignored5960 await usingApi(async (api) => {61 // Destroy 1 of 1062 const tx = api.tx.nft.burnItem(collectionId, tokenId, 1);63 const events = await submitTransactionAsync(alice, tx);64 const result = getGenericResult(events);65 66 // Get alice balance 67 const balance: any = (await api.query.nft.fungibleItemList(collectionId, alice.address)).toJSON();68 69 // What to expect70 expect(result.success).to.be.true;71 expect(balance).to.be.not.null;72 expect(balance.Value).to.be.equal(9);73 });7475 });76 it('Burn item in ReFungible collection', async () => {77 const createMode = 'ReFungible';78 const collectionId = await createCollectionExpectSuccess({mode: {type: createMode }});79 const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);8081 await usingApi(async (api) => {82 const tx = api.tx.nft.burnItem(collectionId, tokenId, 1);83 const events = await submitTransactionAsync(alice, tx);84 const result = getGenericResult(events);85 86 // Get alice balance 87 const balance: any = (await api.query.nft.reFungibleItemList(collectionId, tokenId)).toJSON();88 89 // What to expect90 expect(result.success).to.be.true;91 expect(balance).to.be.not.null;92 expect(balance.Owner.length).to.be.equal(0);93 });9495 });9697 it('Burn owned portion of item in ReFungible collection', async () => {98 const createMode = 'ReFungible';99 const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}});100 const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);101102 await usingApi(async (api) => {103 // Transfer 1/100 of the token to Bob104 const transfertx = api.tx.nft.transfer(bob.address, collectionId, tokenId, 1);105 const events1 = await submitTransactionAsync(alice, transfertx);106 const result1 = getGenericResult(events1);107108 // Get balances109 const balanceBefore: any = (await api.query.nft.reFungibleItemList(collectionId, tokenId)).toJSON();110111 // Bob burns his portion112 const tx = api.tx.nft.burnItem(collectionId, tokenId, 0);113 const events2 = await submitTransactionAsync(bob, tx);114 const result2 = getGenericResult(events2);115116 // Get balances 117 const balance: any = (await api.query.nft.reFungibleItemList(collectionId, tokenId)).toJSON();118 // console.log(balance);119 120 // What to expect before burning121 expect(result1.success).to.be.true;122 expect(balanceBefore).to.be.not.null;123 expect(balanceBefore.Owner.length).to.be.equal(2);124 expect(balanceBefore.Owner[0].Owner).to.be.equal(alice.address);125 expect(balanceBefore.Owner[0].Fraction).to.be.equal(99);126 expect(balanceBefore.Owner[1].Owner).to.be.equal(bob.address);127 expect(balanceBefore.Owner[1].Fraction).to.be.equal(1);128129 // What to expect after burning130 expect(result2.success).to.be.true;131 expect(balance).to.be.not.null;132 expect(balance.Owner.length).to.be.equal(1);133 expect(balance.Owner[0].Fraction).to.be.equal(99);134 expect(balance.Owner[0].Owner).to.be.equal(alice.address);135 });136137 });138139});140141describe('Negative integration test: ext. burnItem():', () => {142 before(async () => {143 await usingApi(async (api) => {144 const keyring = new Keyring({ type: 'sr25519' });145 alice = keyring.addFromUri(`//Alice`);146 bob = keyring.addFromUri(`//Bob`);147 });148 });149150 it('Burn a token in a destroyed collection', async () => {151 const createMode = 'NFT';152 const collectionId = await createCollectionExpectSuccess({mode: {type: createMode }});153 const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);154 await destroyCollectionExpectSuccess(collectionId);155156 await usingApi(async (api) => {157 const tx = api.tx.nft.burnItem(collectionId, tokenId, 0);158 const badTransaction = async function () { 159 await submitTransactionExpectFailAsync(alice, tx);160 };161 await expect(badTransaction()).to.be.rejected;162 });163164 });165166 it('Burn a token that was never created', async () => {167 const createMode = 'NFT';168 const collectionId = await createCollectionExpectSuccess({mode: {type: createMode }});169 const tokenId = 10;170171 await usingApi(async (api) => {172 const tx = api.tx.nft.burnItem(collectionId, tokenId, 0);173 const badTransaction = async function () { 174 await submitTransactionExpectFailAsync(alice, tx);175 };176 await expect(badTransaction()).to.be.rejected;177 });178179 });180181 it('Burn a token using the address that does not own it', async () => {182 const createMode = 'NFT';183 const collectionId = await createCollectionExpectSuccess({mode: {type: createMode }});184 const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);185186 await usingApi(async (api) => {187 const tx = api.tx.nft.burnItem(collectionId, tokenId, 0);188 const badTransaction = async function () { 189 await submitTransactionExpectFailAsync(bob, tx);190 };191 await expect(badTransaction()).to.be.rejected;192 });193194 });195196 it('Transfer a burned a token', async () => {197 const createMode = 'NFT';198 const collectionId = await createCollectionExpectSuccess({mode: {type: createMode }});199 const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);200201 await usingApi(async (api) => {202203 const burntx = api.tx.nft.burnItem(collectionId, tokenId, 0);204 const events1 = await submitTransactionAsync(alice, burntx);205 const result1 = getGenericResult(events1);206 expect(result1.success).to.be.true;207 208 const tx = api.tx.nft.transfer(bob.address, collectionId, tokenId, 0);209 const badTransaction = async function () { 210 await submitTransactionExpectFailAsync(alice, tx);211 };212 await expect(badTransaction()).to.be.rejected;213 });214215 });216217 it('Burn more than owned in Fungible collection', async () => {218 const createMode = 'Fungible';219 const collectionId = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0 }});220 // Helper creates 10 fungible tokens221 await createItemExpectSuccess(alice, collectionId, createMode);222 const tokenId = 0; // ignored223224 await usingApi(async (api) => {225 // Destroy 11 of 10226 const tx = api.tx.nft.burnItem(collectionId, tokenId, 11);227 const badTransaction = async function () { 228 await submitTransactionExpectFailAsync(alice, tx);229 };230 await expect(badTransaction()).to.be.rejected;231 232 // Get alice balance 233 const balance: any = (await api.query.nft.fungibleItemList(collectionId, alice.address)).toJSON();234 235 // What to expect236 expect(balance).to.be.not.null;237 expect(balance.Value).to.be.equal(10);238 });239240 });241242});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());
}
});
}