difftreelog
Merge remote-tracking branch 'origin/develop' into feature/NFTPAR-265
in: master
13 files changed
tests/src/change-collection-owner.test.tsdiffbeforeafterbothno changes
tests/src/confirmSponsorship.test.tsdiffbeforeafterboth556import chai from 'chai';6import chai from 'chai';7import chaiAsPromised from 'chai-as-promised';7import chaiAsPromised from 'chai-as-promised';8import { default as usingApi, submitTransactionAsync } from "./substrate/substrate-api";8import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from "./substrate/substrate-api";9import { 9import { 10 createCollectionExpectSuccess, 10 createCollectionExpectSuccess, 11 setCollectionSponsorExpectSuccess, 11 setCollectionSponsorExpectSuccess, 44 });44 });454546 it('Confirm collection sponsorship', async () => {46 it('Confirm collection sponsorship', async () => {47 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');47 const collectionId = await createCollectionExpectSuccess();48 await setCollectionSponsorExpectSuccess(collectionId, bob.address);48 await setCollectionSponsorExpectSuccess(collectionId, bob.address);49 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');49 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');50 });50 });51 it('Add sponsor to a collection after the same sponsor was already added and confirmed', async () => {51 it('Add sponsor to a collection after the same sponsor was already added and confirmed', async () => {52 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');52 const collectionId = await createCollectionExpectSuccess();53 await setCollectionSponsorExpectSuccess(collectionId, bob.address);53 await setCollectionSponsorExpectSuccess(collectionId, bob.address);54 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');54 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');55 await setCollectionSponsorExpectSuccess(collectionId, bob.address);55 await setCollectionSponsorExpectSuccess(collectionId, bob.address);56 });56 });57 it('Add new sponsor to a collection after another sponsor was already added and confirmed', async () => {57 it('Add new sponsor to a collection after another sponsor was already added and confirmed', async () => {58 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');58 const collectionId = await createCollectionExpectSuccess();59 await setCollectionSponsorExpectSuccess(collectionId, bob.address);59 await setCollectionSponsorExpectSuccess(collectionId, bob.address);60 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');60 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');61 await setCollectionSponsorExpectSuccess(collectionId, charlie.address);61 await setCollectionSponsorExpectSuccess(collectionId, charlie.address);62 });62 });636364 it('NFT: Transfer fees are paid by the sponsor after confirmation', async () => {64 it('NFT: Transfer fees are paid by the sponsor after confirmation', async () => {65 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');65 const collectionId = await createCollectionExpectSuccess();66 await setCollectionSponsorExpectSuccess(collectionId, bob.address);66 await setCollectionSponsorExpectSuccess(collectionId, bob.address);67 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');67 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');686889 });89 });909091 it('Fungible: Transfer fees are paid by the sponsor after confirmation', async () => {91 it('Fungible: Transfer fees are paid by the sponsor after confirmation', async () => {92 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'Fungible');92 const collectionId = await createCollectionExpectSuccess({mode: 'Fungible'});93 await setCollectionSponsorExpectSuccess(collectionId, bob.address);93 await setCollectionSponsorExpectSuccess(collectionId, bob.address);94 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');94 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');9595115 });115 });116116117 it('ReFungible: Transfer fees are paid by the sponsor after confirmation', async () => {117 it('ReFungible: Transfer fees are paid by the sponsor after confirmation', async () => {118 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'ReFungible');118 const collectionId = await createCollectionExpectSuccess({mode: 'ReFungible'});119 await setCollectionSponsorExpectSuccess(collectionId, bob.address);119 await setCollectionSponsorExpectSuccess(collectionId, bob.address);120 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');120 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');121121141 });141 });142142143 it('CreateItem fees are paid by the sponsor after confirmation', async () => {143 it('CreateItem fees are paid by the sponsor after confirmation', async () => {144 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');144 const collectionId = await createCollectionExpectSuccess();145 await setCollectionSponsorExpectSuccess(collectionId, bob.address);145 await setCollectionSponsorExpectSuccess(collectionId, bob.address);146 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');146 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');147147171 });171 });172172173 it('NFT: Sponsoring is rate limited', async () => {173 it('NFT: Sponsoring is rate limited', async () => {174 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');174 const collectionId = await createCollectionExpectSuccess();175 await setCollectionSponsorExpectSuccess(collectionId, bob.address);175 await setCollectionSponsorExpectSuccess(collectionId, bob.address);176 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');176 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');177177192 const AsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());192 const AsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());193 const zeroToAlice = api.tx.nft.transfer(alice.address, collectionId, itemId, 0);193 const zeroToAlice = api.tx.nft.transfer(alice.address, collectionId, itemId, 0);194 const badTransaction = async function () { 194 const badTransaction = async function () { 195 console.log = function () {};196 console.error = function () {};197 await submitTransactionAsync(zeroBalance, zeroToAlice);195 await submitTransactionExpectFailAsync(zeroBalance, zeroToAlice);198 delete console.log;199 delete console.error;200 };196 };201 await expect(badTransaction()).to.be.rejectedWith("Inability to pay some fees");197 await expect(badTransaction()).to.be.rejectedWith("Inability to pay some fees");202 const BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());198 const BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());214 });210 });215211216 it('Fungible: Sponsoring is rate limited', async () => {212 it('Fungible: Sponsoring is rate limited', async () => {217 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'Fungible');213 const collectionId = await createCollectionExpectSuccess({mode: 'Fungible'});218 await setCollectionSponsorExpectSuccess(collectionId, bob.address);214 await setCollectionSponsorExpectSuccess(collectionId, bob.address);219 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');215 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');220216233 const AsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());229 const AsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());234230235 const badTransaction = async function () { 231 const badTransaction = async function () { 236 console.log = function () {};237 console.error = function () {};238 await submitTransactionAsync(zeroBalance, zeroToAlice);232 await submitTransactionExpectFailAsync(zeroBalance, zeroToAlice);239 delete console.log;240 delete console.error;241 };233 };242234243 const BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());235 const BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());255 });247 });256248257 it('ReFungible: Sponsoring is rate limited', async () => {249 it('ReFungible: Sponsoring is rate limited', async () => {258 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'ReFungible');250 const collectionId = await createCollectionExpectSuccess({mode: 'ReFungible'});259 await setCollectionSponsorExpectSuccess(collectionId, bob.address);251 await setCollectionSponsorExpectSuccess(collectionId, bob.address);260 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');252 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');261253276 const AsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());268 const AsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());277 const zeroToAlice = api.tx.nft.transfer(alice.address, collectionId, itemId, 1);269 const zeroToAlice = api.tx.nft.transfer(alice.address, collectionId, itemId, 1);278 const badTransaction = async function () { 270 const badTransaction = async function () { 279 console.log = function () {};280 console.error = function () {};281 await submitTransactionAsync(zeroBalance, zeroToAlice);271 await submitTransactionExpectFailAsync(zeroBalance, zeroToAlice);282 delete console.log;283 delete console.error;284 };272 };285 await expect(badTransaction()).to.be.rejectedWith("Inability to pay some fees");273 await expect(badTransaction()).to.be.rejectedWith("Inability to pay some fees");286 const BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());274 const BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());320 });308 });321309322 it('(!negative test!) Confirm sponsorship using a non-sponsor address', async () => {310 it('(!negative test!) Confirm sponsorship using a non-sponsor address', async () => {323 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');311 const collectionId = await createCollectionExpectSuccess();324 await setCollectionSponsorExpectSuccess(collectionId, bob.address);312 await setCollectionSponsorExpectSuccess(collectionId, bob.address);325313326 await usingApi(async (api) => {314 await usingApi(async (api) => {332 });320 });333321334 it('(!negative test!) Confirm sponsorship using owner address', async () => {322 it('(!negative test!) Confirm sponsorship using owner address', async () => {335 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');323 const collectionId = await createCollectionExpectSuccess();336 await setCollectionSponsorExpectSuccess(collectionId, bob.address);324 await setCollectionSponsorExpectSuccess(collectionId, bob.address);337 await confirmSponsorshipExpectFailure(collectionId, '//Alice');325 await confirmSponsorshipExpectFailure(collectionId, '//Alice');338 });326 });339327340 it('(!negative test!) Confirm sponsorship without sponsor being set with setCollectionSponsor', async () => {328 it('(!negative test!) Confirm sponsorship without sponsor being set with setCollectionSponsor', async () => {341 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');329 const collectionId = await createCollectionExpectSuccess();342 await confirmSponsorshipExpectFailure(collectionId, '//Bob');330 await confirmSponsorshipExpectFailure(collectionId, '//Bob');343 });331 });344 332 345 it('(!negative test!) Confirm sponsorship in a collection that was destroyed', async () => {333 it('(!negative test!) Confirm sponsorship in a collection that was destroyed', async () => {346 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');334 const collectionId = await createCollectionExpectSuccess();347 await destroyCollectionExpectSuccess(collectionId);335 await destroyCollectionExpectSuccess(collectionId);348 await confirmSponsorshipExpectFailure(collectionId, '//Bob');336 await confirmSponsorshipExpectFailure(collectionId, '//Bob');349 });337 });tests/src/connection.test.tsdiffbeforeafterboth21 });21 });222223 it('Cannot connect to 255.255.255.255', async () => {23 it('Cannot connect to 255.255.255.255', async () => {24 const log = console.log;25 const error = console.error;24 console.log = function () {};26 console.log = function () {};25 console.error = function () {};27 console.error = function () {};262831 }, { provider: neverConnectProvider });33 }, { provider: neverConnectProvider });32 })()).to.be.eventually.rejected;34 })()).to.be.eventually.rejected;333534 delete console.log;36 console.log = log;35 delete console.error;37 console.error = error;36 });38 });37});39});tests/src/contracts.test.tsdiffbeforeafterboth111 const bob = privateKey("//Bob");111 const bob = privateKey("//Bob");112112113 const [contract, deployer] = await deployFlipper(api);113 const [contract, deployer] = await deployFlipper(api);114 const consoleError = console.error;115 console.error = (...data: any[]) => {116 };117114118 let expectedFlipValue = await getFlipValue(contract, deployer);115 let expectedFlipValue = await getFlipValue(contract, deployer);119116168 const afterWhiteListDisabled = await getFlipValue(contract,deployer);165 const afterWhiteListDisabled = await getFlipValue(contract,deployer);169 expect(afterWhiteListDisabled).to.be.eq(expectedFlipValue, `Anyone can call contract with disabled whitelist.`);166 expect(afterWhiteListDisabled).to.be.eq(expectedFlipValue, `Anyone can call contract with disabled whitelist.`);170167171 console.error = consoleError;172 });168 });173 });169 });174170tests/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.tsdiffbeforeafterboth18
18
19 it('Create new item in NFT collection', async () => {
19 it('Create new item in NFT collection', async () => {
20 const createMode = 'NFT';
20 const createMode = 'NFT';
21 const newCollectionID = await createCollectionExpectSuccess('0', '0', '0', createMode);
21 const newCollectionID = await createCollectionExpectSuccess({mode: createMode});
22 await createItemExpectSuccess(alice, newCollectionID, createMode);
22 await createItemExpectSuccess(alice, newCollectionID, createMode);
23 });
23 });
24 it('Create new item in Fungible collection', async () => {
24 it('Create new item in Fungible collection', async () => {
25 const createMode = 'Fungible';
25 const createMode = 'Fungible';
26 const newCollectionID = await createCollectionExpectSuccess('0', '0', '0', createMode);
26 const newCollectionID = await createCollectionExpectSuccess({mode: createMode});
27 await createItemExpectSuccess(alice, newCollectionID, createMode);
27 await createItemExpectSuccess(alice, newCollectionID, createMode);
28 });
28 });
29 it('Create new item in ReFungible collection', async () => {
29 it('Create new item in ReFungible collection', async () => {
30 const createMode = 'ReFungible';
30 const createMode = 'ReFungible';
31 const newCollectionID = await createCollectionExpectSuccess('0', '0', '0', createMode);
31 const newCollectionID = await createCollectionExpectSuccess({mode: createMode});
32 await createItemExpectSuccess(alice, newCollectionID, createMode);
32 await createItemExpectSuccess(alice, newCollectionID, createMode);
33 });
33 });
34});
34});
tests/src/creditFeesToTreasury.test.tsdiffbeforeafterboth556import chai from 'chai';6import chai from 'chai';7import chaiAsPromised from 'chai-as-promised';7import chaiAsPromised from 'chai-as-promised';8import { default as usingApi, submitTransactionAsync } from "./substrate/substrate-api";8import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from "./substrate/substrate-api";9import { alicesPublicKey, bobsPublicKey } from "./accounts";9import { alicesPublicKey, bobsPublicKey } from "./accounts";10import privateKey from "./substrate/privateKey";10import privateKey from "./substrate/privateKey";11import { BigNumber } from 'bignumber.js';11import { BigNumber } from 'bignumber.js';63 const bobBalanceBefore = new BigNumber((await api.query.system.account(bobsPublicKey)).data.free.toString());63 const bobBalanceBefore = new BigNumber((await api.query.system.account(bobsPublicKey)).data.free.toString());646465 const badTx = api.tx.balances.setBalance(alicesPublicKey, 0, 0);65 const badTx = api.tx.balances.setBalance(alicesPublicKey, 0, 0);66 const result = getGenericResult(await submitTransactionAsync(bobPrivateKey, badTx));66 await expect(submitTransactionExpectFailAsync(bobPrivateKey, badTx)).to.be.rejected;676768 const treasuryBalanceAfter = new BigNumber((await api.query.system.account(Treasury)).data.free.toString());68 const treasuryBalanceAfter = new BigNumber((await api.query.system.account(Treasury)).data.free.toString());69 const bobBalanceAfter = new BigNumber((await api.query.system.account(bobsPublicKey)).data.free.toString());69 const bobBalanceAfter = new BigNumber((await api.query.system.account(bobsPublicKey)).data.free.toString());70 const fee = bobBalanceBefore.minus(bobBalanceAfter);70 const fee = bobBalanceBefore.minus(bobBalanceAfter);71 const treasuryIncrease = treasuryBalanceAfter.minus(treasuryBalanceBefore);71 const treasuryIncrease = treasuryBalanceAfter.minus(treasuryBalanceBefore);727273 expect(result.success).to.be.false;74 expect(treasuryIncrease.toFixed()).to.be.equal(fee.toFixed());73 expect(treasuryIncrease.toFixed()).to.be.equal(fee.toFixed());75 });74 });76 });75 });80 const treasuryBalanceBefore = new BigNumber((await api.query.system.account(Treasury)).data.free.toString());79 const treasuryBalanceBefore = new BigNumber((await api.query.system.account(Treasury)).data.free.toString());81 const aliceBalanceBefore = new BigNumber((await api.query.system.account(alicesPublicKey)).data.free.toString());80 const aliceBalanceBefore = new BigNumber((await api.query.system.account(alicesPublicKey)).data.free.toString());828183 await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');82 await createCollectionExpectSuccess();848385 const treasuryBalanceAfter = new BigNumber((await api.query.system.account(Treasury)).data.free.toString());84 const treasuryBalanceAfter = new BigNumber((await api.query.system.account(Treasury)).data.free.toString());86 const aliceBalanceAfter = new BigNumber((await api.query.system.account(alicesPublicKey)).data.free.toString());85 const aliceBalanceAfter = new BigNumber((await api.query.system.account(alicesPublicKey)).data.free.toString());96 const treasuryBalanceBefore = new BigNumber((await api.query.system.account(Treasury)).data.free.toString());95 const treasuryBalanceBefore = new BigNumber((await api.query.system.account(Treasury)).data.free.toString());97 const aliceBalanceBefore = new BigNumber((await api.query.system.account(alicesPublicKey)).data.free.toString());96 const aliceBalanceBefore = new BigNumber((await api.query.system.account(alicesPublicKey)).data.free.toString());989799 await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');98 await createCollectionExpectSuccess();10099101 const treasuryBalanceAfter = new BigNumber((await api.query.system.account(Treasury)).data.free.toString());100 const treasuryBalanceAfter = new BigNumber((await api.query.system.account(Treasury)).data.free.toString());102 const aliceBalanceAfter = new BigNumber((await api.query.system.account(alicesPublicKey)).data.free.toString());101 const aliceBalanceAfter = new BigNumber((await api.query.system.account(alicesPublicKey)).data.free.toString());tests/src/destroyCollection.test.tsdiffbeforeafterboth101011describe('integration test: ext. destroyCollection():', () => {11describe('integration test: ext. destroyCollection():', () => {12 it('NFT collection can be destroyed', async () => {12 it('NFT collection can be destroyed', async () => {13 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');13 const collectionId = await createCollectionExpectSuccess();14 await destroyCollectionExpectSuccess(collectionId);14 await destroyCollectionExpectSuccess(collectionId);15 });15 });16 it('Fungible collection can be destroyed', async () => {16 it('Fungible collection can be destroyed', async () => {17 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'Fungible');17 const collectionId = await createCollectionExpectSuccess({ mode: 'Fungible' });18 await destroyCollectionExpectSuccess(collectionId);18 await destroyCollectionExpectSuccess(collectionId);19 });19 });20 it('ReFungible collection can be destroyed', async () => {20 it('ReFungible collection can be destroyed', async () => {21 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'ReFungible');21 const collectionId = await createCollectionExpectSuccess({ mode: 'ReFungible' });22 await destroyCollectionExpectSuccess(collectionId);22 await destroyCollectionExpectSuccess(collectionId);23 });23 });24});24});32 });32 });33 });33 });34 it('(!negative test!) Destroy a collection that has already been destroyed', async () => {34 it('(!negative test!) Destroy a collection that has already been destroyed', async () => {35 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');35 const collectionId = await createCollectionExpectSuccess();36 await destroyCollectionExpectSuccess(collectionId);36 await destroyCollectionExpectSuccess(collectionId);37 await destroyCollectionExpectFailure(collectionId);37 await destroyCollectionExpectFailure(collectionId);38 });38 });39 it('(!negative test!) Destroy a collection using non-owner account', async () => {39 it('(!negative test!) Destroy a collection using non-owner account', async () => {40 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');40 const collectionId = await createCollectionExpectSuccess();41 await destroyCollectionExpectFailure(collectionId, '//Bob');41 await destroyCollectionExpectFailure(collectionId, '//Bob');42 await destroyCollectionExpectSuccess(collectionId, '//Alice');42 await destroyCollectionExpectSuccess(collectionId, '//Alice');43 });43 });tests/src/removeCollectionSponsor.test.tsdiffbeforeafterboth556import chai from 'chai';6import chai from 'chai';7import chaiAsPromised from 'chai-as-promised';7import chaiAsPromised from 'chai-as-promised';8import { default as usingApi, submitTransactionAsync } from "./substrate/substrate-api";8import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from "./substrate/substrate-api";9import { 9import { 10 createCollectionExpectSuccess, 10 createCollectionExpectSuccess, 11 setCollectionSponsorExpectSuccess, 11 setCollectionSponsorExpectSuccess, 46 });46 });474748 it('Remove NFT collection sponsor stops sponsorship', async () => {48 it('Remove NFT collection sponsor stops sponsorship', async () => {49 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');49 const collectionId = await createCollectionExpectSuccess();50 await setCollectionSponsorExpectSuccess(collectionId, bob.address);50 await setCollectionSponsorExpectSuccess(collectionId, bob.address);51 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');51 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');52 await removeCollectionSponsorExpectSuccess(collectionId);52 await removeCollectionSponsorExpectSuccess(collectionId);62 const AsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());62 const AsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());63 const zeroToAlice = api.tx.nft.transfer(alice.address, collectionId, itemId, 0);63 const zeroToAlice = api.tx.nft.transfer(alice.address, collectionId, itemId, 0);64 const badTransaction = async function () { 64 const badTransaction = async function () { 65 console.log = function () {};66 console.error = function () {};67 await submitTransactionAsync(zeroBalance, zeroToAlice);65 await submitTransactionExpectFailAsync(zeroBalance, zeroToAlice);68 delete console.log;69 delete console.error;70 };66 };71 await expect(badTransaction()).to.be.rejectedWith("Inability to pay some fees");67 await expect(badTransaction()).to.be.rejectedWith("Inability to pay some fees");72 const BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());68 const BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());76 });72 });777378 it('Remove a sponsor after it was already removed', async () => {74 it('Remove a sponsor after it was already removed', async () => {79 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');75 const collectionId = await createCollectionExpectSuccess();80 await setCollectionSponsorExpectSuccess(collectionId, bob.address);76 await setCollectionSponsorExpectSuccess(collectionId, bob.address);81 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');77 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');82 await removeCollectionSponsorExpectSuccess(collectionId);78 await removeCollectionSponsorExpectSuccess(collectionId);83 await removeCollectionSponsorExpectSuccess(collectionId);79 await removeCollectionSponsorExpectSuccess(collectionId);84 });80 });858186 it('Remove sponsor in a collection that never had the sponsor set', async () => {82 it('Remove sponsor in a collection that never had the sponsor set', async () => {87 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');83 const collectionId = await createCollectionExpectSuccess();88 await removeCollectionSponsorExpectSuccess(collectionId);84 await removeCollectionSponsorExpectSuccess(collectionId);89 });85 });908691 it('Remove sponsor for a collection that had the sponsor set, but not confirmed', async () => {87 it('Remove sponsor for a collection that had the sponsor set, but not confirmed', async () => {92 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');88 const collectionId = await createCollectionExpectSuccess();93 await setCollectionSponsorExpectSuccess(collectionId, bob.address);89 await setCollectionSponsorExpectSuccess(collectionId, bob.address);94 await removeCollectionSponsorExpectSuccess(collectionId);90 await removeCollectionSponsorExpectSuccess(collectionId);95 });91 });117 });113 });118114119 it('(!negative test!) Remove sponsor in a destroyed collection', async () => {115 it('(!negative test!) Remove sponsor in a destroyed collection', async () => {120 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');116 const collectionId = await createCollectionExpectSuccess();121 await setCollectionSponsorExpectSuccess(collectionId, bob.address);117 await setCollectionSponsorExpectSuccess(collectionId, bob.address);122 await destroyCollectionExpectSuccess(collectionId);118 await destroyCollectionExpectSuccess(collectionId);123 await removeCollectionSponsorExpectFailure(collectionId);119 await removeCollectionSponsorExpectFailure(collectionId);124 });120 });125121126 it('Set - remove - confirm: fails', async () => {122 it('Set - remove - confirm: fails', async () => {127 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');123 const collectionId = await createCollectionExpectSuccess();128 await setCollectionSponsorExpectSuccess(collectionId, bob.address);124 await setCollectionSponsorExpectSuccess(collectionId, bob.address);129 await removeCollectionSponsorExpectSuccess(collectionId);125 await removeCollectionSponsorExpectSuccess(collectionId);130 await confirmSponsorshipExpectFailure(collectionId, '//Bob');126 await confirmSponsorshipExpectFailure(collectionId, '//Bob');131 });127 });132128133 it('Set - confirm - remove - confirm: Sponsor cannot come back', async () => {129 it('Set - confirm - remove - confirm: Sponsor cannot come back', async () => {134 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');130 const collectionId = await createCollectionExpectSuccess();135 await setCollectionSponsorExpectSuccess(collectionId, bob.address);131 await setCollectionSponsorExpectSuccess(collectionId, bob.address);136 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');132 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');137 await removeCollectionSponsorExpectSuccess(collectionId);133 await removeCollectionSponsorExpectSuccess(collectionId);tests/src/setCollectionSponsor.test.tsdiffbeforeafterboth26 });26 });272728 it('Set NFT collection sponsor', async () => {28 it('Set NFT collection sponsor', async () => {29 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');29 const collectionId = await createCollectionExpectSuccess();30 await setCollectionSponsorExpectSuccess(collectionId, bob.address);30 await setCollectionSponsorExpectSuccess(collectionId, bob.address);31 });31 });32 it('Set Fungible collection sponsor', async () => {32 it('Set Fungible collection sponsor', async () => {33 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'Fungible');33 const collectionId = await createCollectionExpectSuccess({ mode: 'Fungible' });34 await setCollectionSponsorExpectSuccess(collectionId, bob.address);34 await setCollectionSponsorExpectSuccess(collectionId, bob.address);35 });35 });36 it('Set ReFungible collection sponsor', async () => {36 it('Set ReFungible collection sponsor', async () => {37 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'ReFungible');37 const collectionId = await createCollectionExpectSuccess({ mode: 'ReFungible' });38 await setCollectionSponsorExpectSuccess(collectionId, bob.address);38 await setCollectionSponsorExpectSuccess(collectionId, bob.address);39 });39 });404041 it('Set the same sponsor repeatedly', async () => {41 it('Set the same sponsor repeatedly', async () => {42 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');42 const collectionId = await createCollectionExpectSuccess();43 await setCollectionSponsorExpectSuccess(collectionId, bob.address);43 await setCollectionSponsorExpectSuccess(collectionId, bob.address);44 await setCollectionSponsorExpectSuccess(collectionId, bob.address);44 await setCollectionSponsorExpectSuccess(collectionId, bob.address);45 });45 });46 it('Replace collection sponsor', async () => {46 it('Replace collection sponsor', async () => {47 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');47 const collectionId = await createCollectionExpectSuccess();484849 const keyring = new Keyring({ type: 'sr25519' });49 const keyring = new Keyring({ type: 'sr25519' });50 const charlie = keyring.addFromUri(`//Charlie`);50 const charlie = keyring.addFromUri(`//Charlie`);62 });62 });636364 it('(!negative test!) Add sponsor with a non-owner', async () => {64 it('(!negative test!) Add sponsor with a non-owner', async () => {65 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');65 const collectionId = await createCollectionExpectSuccess();66 await setCollectionSponsorExpectFailure(collectionId, bob.address, '//Bob');66 await setCollectionSponsorExpectFailure(collectionId, bob.address, '//Bob');67 });67 });68 it('(!negative test!) Add sponsor to a collection that never existed', async () => {68 it('(!negative test!) Add sponsor to a collection that never existed', async () => {75 await setCollectionSponsorExpectFailure(collectionId, bob.address);75 await setCollectionSponsorExpectFailure(collectionId, bob.address);76 });76 });77 it('(!negative test!) Add sponsor to a collection that was destroyed', async () => {77 it('(!negative test!) Add sponsor to a collection that was destroyed', async () => {78 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');78 const collectionId = await createCollectionExpectSuccess();79 await destroyCollectionExpectSuccess(collectionId);79 await destroyCollectionExpectSuccess(collectionId);80 await setCollectionSponsorExpectFailure(collectionId, bob.address);80 await setCollectionSponsorExpectFailure(collectionId, bob.address);81 });81 });tests/src/substrate/substrate-api.tsdiffbeforeafterboth33 }33 }34}34}3536enum TransactionStatus {37 Success,38 Fail,39 NotReady40}4142function getTransactionStatus(events: EventRecord[], status: ExtrinsicStatus): TransactionStatus {43 if (status.isReady) {44 return TransactionStatus.NotReady;45 }46 if (status.isBroadcast) {47 return TransactionStatus.NotReady;48 } 49 if (status.isInBlock || status.isFinalized) {50 if(events.filter(e => e.event.data.method === 'ExtrinsicFailed').length > 0) {51 return TransactionStatus.Fail;52 }53 if(events.filter(e => e.event.data.method === 'ExtrinsicSuccess').length > 0) {54 return TransactionStatus.Success;55 }56 }5758 return TransactionStatus.Fail;59}356036export function submitTransactionAsync(sender: IKeyringPair, transaction: SubmittableExtrinsic<ApiTypes>): Promise<EventRecord[]> {61export function submitTransactionAsync(sender: IKeyringPair, transaction: SubmittableExtrinsic<ApiTypes>): Promise<EventRecord[]> {37 return new Promise(async function(resolve, reject) {62 return new Promise(async function(resolve, reject) {38 try {63 try {39 await transaction.signAndSend(sender, ({ events = [], status }) => {64 await transaction.signAndSend(sender, ({ events = [], status }) => {65 const transactionStatus = getTransactionStatus(events, status);6640 if (status.isReady) {67 if (transactionStatus == TransactionStatus.Success) {41 // nothing to do42 // console.log(`Current tx status is Ready`);43 } else if (status.isBroadcast) {44 // nothing to do45 // console.log(`Current tx status is Broadcast`);46 } else if (status.isInBlock || status.isFinalized) {47 resolve(events);68 resolve(events);48 } else {69 } else if (transactionStatus == TransactionStatus.Fail) {49 console.log(`Something went wrong with transaction. Status: ${status}`);70 console.log(`Something went wrong with transaction. Status: ${status}`);50 reject("Transaction failed");71 reject(events);51 }72 }52 });73 });53 } catch (e) {74 } catch (e) {58}79}598060export function submitTransactionExpectFailAsync(sender: IKeyringPair, transaction: SubmittableExtrinsic<ApiTypes>): Promise<EventRecord[]> {81export function submitTransactionExpectFailAsync(sender: IKeyringPair, transaction: SubmittableExtrinsic<ApiTypes>): Promise<EventRecord[]> {82 const consoleError = console.error;83 const consoleLog = console.log;84 console.error = () => {};85 console.log = () => {};8661 return new Promise(async function(resolve, reject) {87 return new Promise<EventRecord[]>(async function(res, rej) {88 const resolve = (rec: EventRecord[]) => {89 setTimeout(() => {90 res(rec);91 console.error = consoleError;92 console.log = consoleLog;93 94 });95 };96 const reject = (errror: any) => {97 setTimeout(() => {98 rej(errror);99 console.error = consoleError;100 console.log = consoleLog;101 });102 };62 try {103 try {63 await transaction.signAndSend(sender, ({ events = [], status }) => {104 await transaction.signAndSend(sender, ({ events = [], status }) => {105 const transactionStatus = getTransactionStatus(events, status);10664 if (status.isReady) {107 if (transactionStatus == TransactionStatus.Success) {65 // nothing to do66 // console.log(`Current tx status is Ready`);67 } else if (status.isBroadcast) {68 // nothing to do69 // console.log(`Current tx status is Broadcast`);70 } else if (status.isInBlock || status.isFinalized) {71 resolve(events);108 resolve(events);72 } else {109 } else if (transactionStatus == TransactionStatus.Fail) {73 reject("Transaction failed");110 reject(events);74 }111 }75 });112 });76 } catch (e) {113 } catch (e) {77 reject(e);114 reject(e);78 }115 }79 });116 });80}117}tests/src/transfer.test.tsdiffbeforeafterboth33 // Find unused address33 // Find unused address34 const pk = await findUnusedAddress(api);34 const pk = await findUnusedAddress(api);353536 const error = console.error;37 const log = console.log;36 console.log = function () {};38 console.log = function () {};37 console.error = function () {};39 console.error = function () {};38 40 42 };44 };43 await expect(badTransaction()).to.be.rejectedWith("Inability to pay some fees");45 await expect(badTransaction()).to.be.rejectedWith("Inability to pay some fees");444645 delete console.log;47 console.log = log;46 delete console.error;48 console.error = error;47 });49 });48 });50 });49});51});tests/src/util/helpers.tsdiffbeforeafterboth7import chaiAsPromised from 'chai-as-promised';7import chaiAsPromised from 'chai-as-promised';8import type { AccountId, EventRecord } from '@polkadot/types/interfaces';8import type { AccountId, EventRecord } from '@polkadot/types/interfaces';9import { ApiPromise, Keyring } from "@polkadot/api";9import { ApiPromise, Keyring } from "@polkadot/api";10import { default as usingApi, submitTransactionAsync } from "../substrate/substrate-api";10import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from "../substrate/substrate-api";11import privateKey from '../substrate/privateKey';11import privateKey from '../substrate/privateKey';12import { alicesPublicKey, nullPublicKey } from "../accounts";12import { alicesPublicKey, nullPublicKey } from "../accounts";13import { strToUTF16, utf16ToStr, hexToStr } from '../util/util';13import { strToUTF16, utf16ToStr, hexToStr } from '../util/util';86 return result;86 return result;87}87}8889export type CollectionMode = 'NFT' | 'Fungible' | 'ReFungible';90export type CreateCollectionParams = {91 mode: CollectionMode,92 name: string,93 description: string,94 tokenPrefix: string95};9697const defaultCreateCollectionParams: CreateCollectionParams = {98 name: 'name',99 description: 'description',100 mode: 'NFT',101 tokenPrefix: 'prefix'102}8810389export async function createCollectionExpectSuccess(name: string, description: string, tokenPrefix: string, mode: string): Promise<number> {104export async function createCollectionExpectSuccess(params: Partial<CreateCollectionParams> = {}): Promise<number> {105 const {name, description, mode, tokenPrefix } = {...defaultCreateCollectionParams, ...params};10690 let collectionId: number = 0;107 let collectionId: number = 0;91 await usingApi(async (api) => {108 await usingApi(async (api) => {120 return collectionId;137 return collectionId;121}138}122 139 123export async function createCollectionExpectFailure(name: string, description: string, tokenPrefix: string, mode: string) {140export async function createCollectionExpectFailure(params: Partial<CreateCollectionParams> = {}) {141 const {name, description, mode, tokenPrefix } = {...defaultCreateCollectionParams, ...params};142124 await usingApi(async (api) => {143 await usingApi(async (api) => {125 // Get number of collections before the transaction144 // Get number of collections before the transaction126 const AcollectionCount = parseInt((await api.query.nft.createdCollectionCount()).toString());145 const AcollectionCount = parseInt((await api.query.nft.createdCollectionCount()).toString());127146128 // Run the CreateCollection transaction147 // Run the CreateCollection transaction129 const alicePrivateKey = privateKey('//Alice');148 const alicePrivateKey = privateKey('//Alice');130 const tx = api.tx.nft.createCollection(name, description, tokenPrefix, mode);149 const tx = api.tx.nft.createCollection(strToUTF16(name), strToUTF16(description), strToUTF16(tokenPrefix), mode);131 const events = await submitTransactionAsync(alicePrivateKey, tx);150 const events = await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;132 const result = getCreateCollectionResult(events);151 const result = getCreateCollectionResult(events);133152134 // Get number of collections after the transaction153 // Get number of collections after the transaction138 expect(result.success).to.be.false;157 expect(result.success).to.be.false;139 expect(BcollectionCount).to.be.equal(AcollectionCount, 'Error: Collection with incorrect data created.');158 expect(BcollectionCount).to.be.equal(AcollectionCount, 'Error: Collection with incorrect data created.');140 });159 });141}160}142 161 143export async function findUnusedAddress(api: ApiPromise): Promise<IKeyringPair> {162export async function findUnusedAddress(api: ApiPromise): Promise<IKeyringPair> {144 let bal = new BigNumber(0);163 let bal = new BigNumber(0);168 // Run the DestroyCollection transaction187 // Run the DestroyCollection transaction169 const alicePrivateKey = privateKey(senderSeed);188 const alicePrivateKey = privateKey(senderSeed);170 const tx = api.tx.nft.destroyCollection(collectionId);189 const tx = api.tx.nft.destroyCollection(collectionId);171 const events = await submitTransactionAsync(alicePrivateKey, tx);172 const result = getDestroyResult(events);173174 // What to expect175 expect(result).to.be.false;190 await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;176 });191 });177}192}178193238 // Run the transaction253 // Run the transaction239 const alicePrivateKey = privateKey('//Alice');254 const alicePrivateKey = privateKey('//Alice');240 const tx = api.tx.nft.removeCollectionSponsor(collectionId);255 const tx = api.tx.nft.removeCollectionSponsor(collectionId);241 const events = await submitTransactionAsync(alicePrivateKey, tx);242 const result = getGenericResult(events);243244 // What to expect245 expect(result.success).to.be.false;256 await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;246 });257 });247}258}248259252 // Run the transaction263 // Run the transaction253 const alicePrivateKey = privateKey(senderSeed);264 const alicePrivateKey = privateKey(senderSeed);254 const tx = api.tx.nft.setCollectionSponsor(collectionId, sponsor);265 const tx = api.tx.nft.setCollectionSponsor(collectionId, sponsor);255 const events = await submitTransactionAsync(alicePrivateKey, tx);256 const result = getGenericResult(events);257258 // What to expect259 expect(result.success).to.be.false;266 await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;260 });267 });261}268}262269285 // Run the transaction292 // Run the transaction286 const sender = privateKey(senderSeed);293 const sender = privateKey(senderSeed);287 const tx = api.tx.nft.confirmSponsorship(collectionId);294 const tx = api.tx.nft.confirmSponsorship(collectionId);288 const events = await submitTransactionAsync(sender, tx);289 const result = getGenericResult(events);290291 // What to expect292 expect(result.success).to.be.false;295 await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;293 });296 });294}297}295298