difftreelog
NFTPAR-237 Integration Test changeCollectionOwner(collection_id, new_owner).
in: master
13 files changed
tests/src/change-collection-owner.test.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/change-collection-owner.test.ts
@@ -0,0 +1,59 @@
+import chai from 'chai';
+import chaiAsPromised from 'chai-as-promised';
+import privateKey from './substrate/privateKey';
+import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from "./substrate/substrate-api";
+import { createCollectionExpectSuccess, createCollectionExpectFailure } from "./util/helpers";
+
+chai.use(chaiAsPromised);
+const expect = chai.expect;
+
+describe('Integration Test changeCollectionOwner(collection_id, new_owner):', () => {
+ it('Changing owner changes owner.', async () => {
+ await usingApi(async api => {
+ const collectionId = await createCollectionExpectSuccess();
+ const alice = privateKey('//Alice');
+ const bob = privateKey('//Bob');
+
+ const collection: any = (await api.query.nft.collection(collectionId));
+ expect(collection.Owner.toString()).to.be.eq(alice.address);
+
+ const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);
+ await submitTransactionAsync(alice, changeOwnerTx);
+
+ const collectionAfterOwnerChange: any = (await api.query.nft.collection(collectionId));
+ expect(collectionAfterOwnerChange.Owner.toString()).to.be.eq(bob.address);
+ });
+ });
+});
+
+describe('Negative Integration Test changeCollectionOwner(collection_id, new_owner):', () => {
+ it(`Not owner can't change owner.`, async () => {
+ await usingApi(async api => {
+ const collectionId = await createCollectionExpectSuccess();
+ const alice = privateKey('//Alice');
+ const bob = privateKey('//Bob');
+
+ const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);
+ await expect(submitTransactionExpectFailAsync(bob, changeOwnerTx)).to.be.rejected;
+
+ const collectionAfterOwnerChange: any = (await api.query.nft.collection(collectionId));
+ expect(collectionAfterOwnerChange.Owner.toString()).to.be.eq(alice.address);
+
+ // Verifying that nothing bad happened (network is live, new collections can be created, etc.)
+ await createCollectionExpectSuccess();
+ });
+ });
+ it(`Can't change owner of not existing collection.`, async () => {
+ await usingApi(async api => {
+ const collectionId = (1<<32) - 1;
+ const alice = privateKey('//Alice');
+ const bob = privateKey('//Bob');
+
+ const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);
+ await expect(submitTransactionExpectFailAsync(alice, changeOwnerTx)).to.be.rejected;
+
+ // Verifying that nothing bad happened (network is live, new collections can be created, etc.)
+ await createCollectionExpectSuccess();
+ });
+ });
+});
tests/src/confirmSponsorship.test.tsdiffbeforeafterboth--- a/tests/src/confirmSponsorship.test.ts
+++ b/tests/src/confirmSponsorship.test.ts
@@ -5,7 +5,7 @@
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
-import { default as usingApi, submitTransactionAsync } from "./substrate/substrate-api";
+import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from "./substrate/substrate-api";
import {
createCollectionExpectSuccess,
setCollectionSponsorExpectSuccess,
@@ -44,25 +44,25 @@
});
it('Confirm collection sponsorship', async () => {
- const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');
+ const collectionId = await createCollectionExpectSuccess();
await setCollectionSponsorExpectSuccess(collectionId, bob.address);
await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
});
it('Add sponsor to a collection after the same sponsor was already added and confirmed', async () => {
- const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');
+ const collectionId = await createCollectionExpectSuccess();
await setCollectionSponsorExpectSuccess(collectionId, bob.address);
await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
await setCollectionSponsorExpectSuccess(collectionId, bob.address);
});
it('Add new sponsor to a collection after another sponsor was already added and confirmed', async () => {
- const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');
+ const collectionId = await createCollectionExpectSuccess();
await setCollectionSponsorExpectSuccess(collectionId, bob.address);
await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
await setCollectionSponsorExpectSuccess(collectionId, charlie.address);
});
it('NFT: Transfer fees are paid by the sponsor after confirmation', async () => {
- const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');
+ const collectionId = await createCollectionExpectSuccess();
await setCollectionSponsorExpectSuccess(collectionId, bob.address);
await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
@@ -89,7 +89,7 @@
});
it('Fungible: Transfer fees are paid by the sponsor after confirmation', async () => {
- const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'Fungible');
+ const collectionId = await createCollectionExpectSuccess();
await setCollectionSponsorExpectSuccess(collectionId, bob.address);
await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
@@ -115,7 +115,7 @@
});
it('ReFungible: Transfer fees are paid by the sponsor after confirmation', async () => {
- const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'ReFungible');
+ const collectionId = await createCollectionExpectSuccess();
await setCollectionSponsorExpectSuccess(collectionId, bob.address);
await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
@@ -141,7 +141,7 @@
});
it('CreateItem fees are paid by the sponsor after confirmation', async () => {
- const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');
+ const collectionId = await createCollectionExpectSuccess();
await setCollectionSponsorExpectSuccess(collectionId, bob.address);
await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
@@ -171,7 +171,7 @@
});
it('NFT: Sponsoring is rate limited', async () => {
- const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');
+ const collectionId = await createCollectionExpectSuccess();
await setCollectionSponsorExpectSuccess(collectionId, bob.address);
await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
@@ -192,11 +192,7 @@
const AsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());
const zeroToAlice = api.tx.nft.transfer(alice.address, collectionId, itemId, 0);
const badTransaction = async function () {
- console.log = function () {};
- console.error = function () {};
- await submitTransactionAsync(zeroBalance, zeroToAlice);
- delete console.log;
- delete console.error;
+ await submitTransactionExpectFailAsync(zeroBalance, zeroToAlice);
};
await expect(badTransaction()).to.be.rejectedWith("Inability to pay some fees");
const BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());
@@ -214,7 +210,7 @@
});
it('Fungible: Sponsoring is rate limited', async () => {
- const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'Fungible');
+ const collectionId = await createCollectionExpectSuccess();
await setCollectionSponsorExpectSuccess(collectionId, bob.address);
await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
@@ -233,11 +229,7 @@
const AsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());
const badTransaction = async function () {
- console.log = function () {};
- console.error = function () {};
- await submitTransactionAsync(zeroBalance, zeroToAlice);
- delete console.log;
- delete console.error;
+ await submitTransactionExpectFailAsync(zeroBalance, zeroToAlice);
};
const BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());
@@ -255,7 +247,7 @@
});
it('ReFungible: Sponsoring is rate limited', async () => {
- const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'ReFungible');
+ const collectionId = await createCollectionExpectSuccess();
await setCollectionSponsorExpectSuccess(collectionId, bob.address);
await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
@@ -276,11 +268,7 @@
const AsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());
const zeroToAlice = api.tx.nft.transfer(alice.address, collectionId, itemId, 1);
const badTransaction = async function () {
- console.log = function () {};
- console.error = function () {};
- await submitTransactionAsync(zeroBalance, zeroToAlice);
- delete console.log;
- delete console.error;
+ await submitTransactionExpectFailAsync(zeroBalance, zeroToAlice);
};
await expect(badTransaction()).to.be.rejectedWith("Inability to pay some fees");
const BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());
@@ -320,7 +308,7 @@
});
it('(!negative test!) Confirm sponsorship using a non-sponsor address', async () => {
- const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');
+ const collectionId = await createCollectionExpectSuccess();
await setCollectionSponsorExpectSuccess(collectionId, bob.address);
await usingApi(async (api) => {
@@ -332,18 +320,18 @@
});
it('(!negative test!) Confirm sponsorship using owner address', async () => {
- const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');
+ const collectionId = await createCollectionExpectSuccess();
await setCollectionSponsorExpectSuccess(collectionId, bob.address);
await confirmSponsorshipExpectFailure(collectionId, '//Alice');
});
it('(!negative test!) Confirm sponsorship without sponsor being set with setCollectionSponsor', async () => {
- const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');
+ const collectionId = await createCollectionExpectSuccess();
await confirmSponsorshipExpectFailure(collectionId, '//Bob');
});
it('(!negative test!) Confirm sponsorship in a collection that was destroyed', async () => {
- const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');
+ const collectionId = await createCollectionExpectSuccess();
await destroyCollectionExpectSuccess(collectionId);
await confirmSponsorshipExpectFailure(collectionId, '//Bob');
});
tests/src/connection.test.tsdiffbeforeafterboth--- a/tests/src/connection.test.ts
+++ b/tests/src/connection.test.ts
@@ -21,6 +21,8 @@
});
it('Cannot connect to 255.255.255.255', async () => {
+ const log = console.log;
+ const error = console.error;
console.log = function () {};
console.error = function () {};
@@ -31,7 +33,7 @@
}, { provider: neverConnectProvider });
})()).to.be.eventually.rejected;
- delete console.log;
- delete console.error;
+ console.log = log;
+ console.error = error;
});
});
\ No newline at end of file
tests/src/contracts.test.tsdiffbeforeafterboth--- a/tests/src/contracts.test.ts
+++ b/tests/src/contracts.test.ts
@@ -109,9 +109,6 @@
const bob = privateKey("//Bob");
const [contract, deployer] = await deployFlipper(api);
- const consoleError = console.error;
- console.error = (...data: any[]) => {
- };
let expectedFlipValue = await getFlipValue(contract, deployer);
@@ -166,7 +163,6 @@
const afterWhiteListDisabled = await getFlipValue(contract,deployer);
expect(afterWhiteListDisabled).to.be.eq(expectedFlipValue, `Anyone can call contract with disabled whitelist.`);
- console.error = consoleError;
});
});
tests/src/createCollection.test.tsdiffbeforeafterboth6import chai from 'chai';
6import chai from 'chai';
7import chaiAsPromised from 'chai-as-promised';
7import chaiAsPromised from 'chai-as-promised';
8import { default as usingApi } from "./substrate/substrate-api";
8import { default as usingApi } from "./substrate/substrate-api";
9import { createCollectionExpectSuccess, createCollectionExpectFailure } from "./util/helpers";
9import { createCollectionExpectSuccess, createCollectionExpectFailure, CollectionMode } from "./util/helpers";
10
10
11chai.use(chaiAsPromised);
11chai.use(chaiAsPromised);
12const expect = chai.expect;
12const expect = chai.expect;
13
13
14describe('integration test: ext. createCollection():', () => {
14describe('integration test: ext. createCollection():', () => {
15 it('Create new NFT collection', async () => {
15 it('Create new NFT collection', async () => {
16 await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');
16 await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: 'NFT'});
17 });
17 });
18 it('Create new NFT collection whith collection_name of maximum length (64 bytes)', async () => {
18 it('Create new NFT collection whith collection_name of maximum length (64 bytes)', async () => {
19 await createCollectionExpectSuccess(
19 await createCollectionExpectSuccess({name: 'A'.repeat(64)});
20 'ABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCD',
21 '1', '1', 'NFT');
22 });
20 });
23 it('Create new NFT collection whith collection_description of maximum length (256 bytes)', async () => {
21 it('Create new NFT collection whith collection_description of maximum length (256 bytes)', async () => {
24 await createCollectionExpectSuccess(
22 await createCollectionExpectSuccess({description: 'A'.repeat(256)});
25 'A',
26 'ABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJabcdef',
27 '1', 'NFT');
28 });
23 });
29 it('Create new NFT collection whith token_prefix of maximum length (16 bytes)', async () => {
24 it('Create new NFT collection whith token_prefix of maximum length (16 bytes)', async () => {
30 await createCollectionExpectSuccess(
25 await createCollectionExpectSuccess({tokenPrefix: 'A'.repeat(16)});
31 '1',
32 '1',
33 'ABCDEFGHIJABCDEF', 'NFT');
34 });
26 });
35 it('Create new Fungible collection', async () => {
27 it('Create new Fungible collection', async () => {
36 await createCollectionExpectSuccess('1', '1', '1', 'Fungible');
28 await createCollectionExpectSuccess({mode: 'Fungible'});
37 });
29 });
38 it('Create new ReFungible collection', async () => {
30 it('Create new ReFungible collection', async () => {
39 await createCollectionExpectSuccess('1', '1', '1', 'ReFungible');
31 await createCollectionExpectSuccess({mode: 'ReFungible'});
40 });
32 });
41});
33});
42
34
46 const AcollectionCount = parseInt((await api.query.nft.collectionCount()).toString());
38 const AcollectionCount = parseInt((await api.query.nft.collectionCount()).toString());
47
39
48 const badTransaction = async function () {
40 const badTransaction = async function () {
49 await createCollectionExpectSuccess('1', '1', '1', 'BadMode');
41 await createCollectionExpectSuccess({mode: 'BadMode' as CollectionMode});
50 };
42 };
51 expect(badTransaction()).to.be.rejected;
43 expect(badTransaction()).to.be.rejected;
52
44
55 });
47 });
56 });
48 });
57 it('(!negative test!) create new NFT collection whith incorrect data (collection_name)', async () => {
49 it('(!negative test!) create new NFT collection whith incorrect data (collection_name)', async () => {
58 await createCollectionExpectFailure(
50 await createCollectionExpectFailure({name: 'A'.repeat(65)});
59 'ABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDE',
60 '1', '1', 'NFT');
61 });
51 });
62 it('(!negative test!) create new NFT collection whith incorrect data (collection_description)', async () => {
52 it('(!negative test!) create new NFT collection whith incorrect data (collection_description)', async () => {
63 await createCollectionExpectFailure('1',
53 await createCollectionExpectFailure({description: 'A'.repeat(257)});
64 'ABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJabcdefg',
65 '1', 'NFT');
66 });
54 });
67 it('(!negative test!) create new NFT collection whith incorrect data (token_prefix)', async () => {
55 it('(!negative test!) create new NFT collection whith incorrect data (token_prefix)', async () => {
68 await createCollectionExpectFailure('1', '1',
56 await createCollectionExpectFailure({tokenPrefix: 'A'.repeat(17)});
69 'ABCDEFGHIJABCDEFG',
70 'NFT');
71 });
57 });
72});
58});
7359tests/src/createItem.test.tsdiffbeforeafterboth--- a/tests/src/createItem.test.ts
+++ b/tests/src/createItem.test.ts
@@ -18,17 +18,17 @@
it('Create new item in NFT collection', async () => {
const createMode = 'NFT';
- const newCollectionID = await createCollectionExpectSuccess('0', '0', '0', createMode);
+ const newCollectionID = await createCollectionExpectSuccess({mode: createMode});
await createItemExpectSuccess(alice, newCollectionID, createMode);
});
it('Create new item in Fungible collection', async () => {
const createMode = 'Fungible';
- const newCollectionID = await createCollectionExpectSuccess('0', '0', '0', createMode);
+ const newCollectionID = await createCollectionExpectSuccess({mode: createMode});
await createItemExpectSuccess(alice, newCollectionID, createMode);
});
it('Create new item in ReFungible collection', async () => {
const createMode = 'ReFungible';
- const newCollectionID = await createCollectionExpectSuccess('0', '0', '0', createMode);
+ const newCollectionID = await createCollectionExpectSuccess({mode: createMode});
await createItemExpectSuccess(alice, newCollectionID, createMode);
});
});
tests/src/creditFeesToTreasury.test.tsdiffbeforeafterboth--- a/tests/src/creditFeesToTreasury.test.ts
+++ b/tests/src/creditFeesToTreasury.test.ts
@@ -80,7 +80,7 @@
const treasuryBalanceBefore = new BigNumber((await api.query.system.account(Treasury)).data.free.toString());
const aliceBalanceBefore = new BigNumber((await api.query.system.account(alicesPublicKey)).data.free.toString());
- await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');
+ await createCollectionExpectSuccess();
const treasuryBalanceAfter = new BigNumber((await api.query.system.account(Treasury)).data.free.toString());
const aliceBalanceAfter = new BigNumber((await api.query.system.account(alicesPublicKey)).data.free.toString());
@@ -96,7 +96,7 @@
const treasuryBalanceBefore = new BigNumber((await api.query.system.account(Treasury)).data.free.toString());
const aliceBalanceBefore = new BigNumber((await api.query.system.account(alicesPublicKey)).data.free.toString());
- await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');
+ await createCollectionExpectSuccess();
const treasuryBalanceAfter = new BigNumber((await api.query.system.account(Treasury)).data.free.toString());
const aliceBalanceAfter = new BigNumber((await api.query.system.account(alicesPublicKey)).data.free.toString());
tests/src/destroyCollection.test.tsdiffbeforeafterboth--- a/tests/src/destroyCollection.test.ts
+++ b/tests/src/destroyCollection.test.ts
@@ -10,15 +10,15 @@
describe('integration test: ext. destroyCollection():', () => {
it('NFT collection can be destroyed', async () => {
- const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');
+ const collectionId = await createCollectionExpectSuccess();
await destroyCollectionExpectSuccess(collectionId);
});
it('Fungible collection can be destroyed', async () => {
- const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'Fungible');
+ const collectionId = await createCollectionExpectSuccess({ mode: 'Fungible' });
await destroyCollectionExpectSuccess(collectionId);
});
it('ReFungible collection can be destroyed', async () => {
- const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'ReFungible');
+ const collectionId = await createCollectionExpectSuccess({ mode: 'ReFungible' });
await destroyCollectionExpectSuccess(collectionId);
});
});
@@ -32,12 +32,12 @@
});
});
it('(!negative test!) Destroy a collection that has already been destroyed', async () => {
- const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');
+ const collectionId = await createCollectionExpectSuccess();
await destroyCollectionExpectSuccess(collectionId);
await destroyCollectionExpectFailure(collectionId);
});
it('(!negative test!) Destroy a collection using non-owner account', async () => {
- const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');
+ const collectionId = await createCollectionExpectSuccess();
await destroyCollectionExpectFailure(collectionId, '//Bob');
await destroyCollectionExpectSuccess(collectionId, '//Alice');
});
tests/src/removeCollectionSponsor.test.tsdiffbeforeafterboth--- a/tests/src/removeCollectionSponsor.test.ts
+++ b/tests/src/removeCollectionSponsor.test.ts
@@ -5,7 +5,7 @@
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
-import { default as usingApi, submitTransactionAsync } from "./substrate/substrate-api";
+import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from "./substrate/substrate-api";
import {
createCollectionExpectSuccess,
setCollectionSponsorExpectSuccess,
@@ -46,7 +46,7 @@
});
it('Remove NFT collection sponsor stops sponsorship', async () => {
- const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');
+ const collectionId = await createCollectionExpectSuccess();
await setCollectionSponsorExpectSuccess(collectionId, bob.address);
await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
await removeCollectionSponsorExpectSuccess(collectionId);
@@ -62,11 +62,7 @@
const AsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());
const zeroToAlice = api.tx.nft.transfer(alice.address, collectionId, itemId, 0);
const badTransaction = async function () {
- console.log = function () {};
- console.error = function () {};
- await submitTransactionAsync(zeroBalance, zeroToAlice);
- delete console.log;
- delete console.error;
+ await submitTransactionExpectFailAsync(zeroBalance, zeroToAlice);
};
await expect(badTransaction()).to.be.rejectedWith("Inability to pay some fees");
const BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());
@@ -76,7 +72,7 @@
});
it('Remove a sponsor after it was already removed', async () => {
- const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');
+ const collectionId = await createCollectionExpectSuccess();
await setCollectionSponsorExpectSuccess(collectionId, bob.address);
await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
await removeCollectionSponsorExpectSuccess(collectionId);
@@ -84,12 +80,12 @@
});
it('Remove sponsor in a collection that never had the sponsor set', async () => {
- const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');
+ const collectionId = await createCollectionExpectSuccess();
await removeCollectionSponsorExpectSuccess(collectionId);
});
it('Remove sponsor for a collection that had the sponsor set, but not confirmed', async () => {
- const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');
+ const collectionId = await createCollectionExpectSuccess();
await setCollectionSponsorExpectSuccess(collectionId, bob.address);
await removeCollectionSponsorExpectSuccess(collectionId);
});
@@ -117,21 +113,21 @@
});
it('(!negative test!) Remove sponsor in a destroyed collection', async () => {
- const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');
+ const collectionId = await createCollectionExpectSuccess();
await setCollectionSponsorExpectSuccess(collectionId, bob.address);
await destroyCollectionExpectSuccess(collectionId);
await removeCollectionSponsorExpectFailure(collectionId);
});
it('Set - remove - confirm: fails', async () => {
- const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');
+ const collectionId = await createCollectionExpectSuccess();
await setCollectionSponsorExpectSuccess(collectionId, bob.address);
await removeCollectionSponsorExpectSuccess(collectionId);
await confirmSponsorshipExpectFailure(collectionId, '//Bob');
});
it('Set - confirm - remove - confirm: Sponsor cannot come back', async () => {
- const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');
+ const collectionId = await createCollectionExpectSuccess();
await setCollectionSponsorExpectSuccess(collectionId, bob.address);
await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
await removeCollectionSponsorExpectSuccess(collectionId);
tests/src/setCollectionSponsor.test.tsdiffbeforeafterboth--- a/tests/src/setCollectionSponsor.test.ts
+++ b/tests/src/setCollectionSponsor.test.ts
@@ -26,25 +26,25 @@
});
it('Set NFT collection sponsor', async () => {
- const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');
+ const collectionId = await createCollectionExpectSuccess();
await setCollectionSponsorExpectSuccess(collectionId, bob.address);
});
it('Set Fungible collection sponsor', async () => {
- const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'Fungible');
+ const collectionId = await createCollectionExpectSuccess({ mode: 'Fungible' });
await setCollectionSponsorExpectSuccess(collectionId, bob.address);
});
it('Set ReFungible collection sponsor', async () => {
- const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'ReFungible');
+ const collectionId = await createCollectionExpectSuccess({ mode: 'ReFungible' });
await setCollectionSponsorExpectSuccess(collectionId, bob.address);
});
it('Set the same sponsor repeatedly', async () => {
- const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');
+ const collectionId = await createCollectionExpectSuccess();
await setCollectionSponsorExpectSuccess(collectionId, bob.address);
await setCollectionSponsorExpectSuccess(collectionId, bob.address);
});
it('Replace collection sponsor', async () => {
- const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');
+ const collectionId = await createCollectionExpectSuccess();
const keyring = new Keyring({ type: 'sr25519' });
const charlie = keyring.addFromUri(`//Charlie`);
@@ -62,7 +62,7 @@
});
it('(!negative test!) Add sponsor with a non-owner', async () => {
- const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');
+ const collectionId = await createCollectionExpectSuccess();
await setCollectionSponsorExpectFailure(collectionId, bob.address, '//Bob');
});
it('(!negative test!) Add sponsor to a collection that never existed', async () => {
@@ -75,7 +75,7 @@
await setCollectionSponsorExpectFailure(collectionId, bob.address);
});
it('(!negative test!) Add sponsor to a collection that was destroyed', async () => {
- const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');
+ const collectionId = await createCollectionExpectSuccess();
await destroyCollectionExpectSuccess(collectionId);
await setCollectionSponsorExpectFailure(collectionId, bob.address);
});
tests/src/substrate/substrate-api.tsdiffbeforeafterboth--- a/tests/src/substrate/substrate-api.ts
+++ b/tests/src/substrate/substrate-api.ts
@@ -33,19 +33,40 @@
}
}
+enum TransactionStatus {
+ Success,
+ Fail,
+ NotReady
+}
+
+function getTransactionStatus(events: EventRecord[], status: ExtrinsicStatus): TransactionStatus {
+ if (status.isReady) {
+ return TransactionStatus.NotReady;
+ }
+ if (status.isBroadcast) {
+ return TransactionStatus.NotReady;
+ }
+ if (status.isInBlock || status.isFinalized) {
+ if(events.filter(e => e.event.data.method === 'ExtrinsicFailed').length > 0) {
+ return TransactionStatus.Fail;
+ }
+ if(events.filter(e => e.event.data.method === 'ExtrinsicSuccess').length > 0) {
+ return TransactionStatus.Success;
+ }
+ }
+
+ return TransactionStatus.Fail;
+}
+
export function submitTransactionAsync(sender: IKeyringPair, transaction: SubmittableExtrinsic<ApiTypes>): Promise<EventRecord[]> {
return new Promise(async function(resolve, reject) {
try {
await transaction.signAndSend(sender, ({ events = [], status }) => {
- if (status.isReady) {
- // nothing to do
- // console.log(`Current tx status is Ready`);
- } else if (status.isBroadcast) {
- // nothing to do
- // console.log(`Current tx status is Broadcast`);
- } else if (status.isInBlock || status.isFinalized) {
+ const transactionStatus = getTransactionStatus(events, status);
+
+ if (transactionStatus == TransactionStatus.Success) {
resolve(events);
- } else {
+ } else if (transactionStatus == TransactionStatus.Fail) {
console.log(`Something went wrong with transaction. Status: ${status}`);
reject("Transaction failed");
}
@@ -58,18 +79,34 @@
}
export function submitTransactionExpectFailAsync(sender: IKeyringPair, transaction: SubmittableExtrinsic<ApiTypes>): Promise<EventRecord[]> {
- return new Promise(async function(resolve, reject) {
+ const consoleError = console.error;
+ const consoleLog = console.log;
+ console.error = () => {};
+ console.log = () => {};
+
+ return new Promise<EventRecord[]>(async function(res, rej) {
+ const resolve = (rec: EventRecord[]) => {
+ setTimeout(() => {
+ res(rec);
+ console.error = consoleError;
+ console.log = consoleLog;
+
+ });
+ };
+ const reject = (errror: any) => {
+ setTimeout(() => {
+ rej(errror);
+ console.error = consoleError;
+ console.log = consoleLog;
+ });
+ };
try {
await transaction.signAndSend(sender, ({ events = [], status }) => {
- if (status.isReady) {
- // nothing to do
- // console.log(`Current tx status is Ready`);
- } else if (status.isBroadcast) {
- // nothing to do
- // console.log(`Current tx status is Broadcast`);
- } else if (status.isInBlock || status.isFinalized) {
+ const transactionStatus = getTransactionStatus(events, status);
+
+ if (transactionStatus == TransactionStatus.Success) {
resolve(events);
- } else {
+ } else if (transactionStatus == TransactionStatus.Fail) {
reject("Transaction failed");
}
});
tests/src/transfer.test.tsdiffbeforeafterboth--- a/tests/src/transfer.test.ts
+++ b/tests/src/transfer.test.ts
@@ -33,6 +33,8 @@
// Find unused address
const pk = await findUnusedAddress(api);
+ const error = console.error;
+ const log = console.log;
console.log = function () {};
console.error = function () {};
@@ -42,8 +44,8 @@
};
await expect(badTransaction()).to.be.rejectedWith("Inability to pay some fees");
- delete console.log;
- delete console.error;
+ console.log = log;
+ console.error = error;
});
});
});
tests/src/util/helpers.tsdiffbeforeafterboth--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -86,7 +86,24 @@
return result;
}
-export async function createCollectionExpectSuccess(name: string, description: string, tokenPrefix: string, mode: string): Promise<number> {
+export type CollectionMode = 'NFT' | 'Fungible' | 'ReFungible';
+export type CreateCollectionParams = {
+ mode: CollectionMode,
+ name: string,
+ description: string,
+ tokenPrefix: string
+};
+
+const defaultCreateCollectionParams: CreateCollectionParams = {
+ name: 'name',
+ description: 'description',
+ mode: 'NFT',
+ tokenPrefix: 'prefix'
+}
+
+export async function createCollectionExpectSuccess(params: Partial<CreateCollectionParams> = {}): Promise<number> {
+ const {name, description, mode, tokenPrefix } = {...defaultCreateCollectionParams, ...params};
+
let collectionId: number = 0;
await usingApi(async (api) => {
// Get number of collections before the transaction
@@ -120,14 +137,16 @@
return collectionId;
}
-export async function createCollectionExpectFailure(name: string, description: string, tokenPrefix: string, mode: string) {
+export async function createCollectionExpectFailure(params: Partial<CreateCollectionParams> = {}) {
+ const {name, description, mode, tokenPrefix } = {...defaultCreateCollectionParams, ...params};
+
await usingApi(async (api) => {
// Get number of collections before the transaction
const AcollectionCount = parseInt((await api.query.nft.createdCollectionCount()).toString());
// Run the CreateCollection transaction
const alicePrivateKey = privateKey('//Alice');
- const tx = api.tx.nft.createCollection(name, description, tokenPrefix, mode);
+ const tx = api.tx.nft.createCollection(strToUTF16(name), strToUTF16(description), strToUTF16(tokenPrefix), mode);
const events = await submitTransactionAsync(alicePrivateKey, tx);
const result = getCreateCollectionResult(events);