difftreelog
test upgrade for split pallets
in: master
77 files changed
tests/.eslintrc.jsondiffbeforeafterboth--- a/tests/.eslintrc.json
+++ b/tests/.eslintrc.json
@@ -63,6 +63,41 @@
{
"destructuring": "all"
}
+ ],
+ "object-curly-spacing": "warn",
+ "arrow-spacing": "warn",
+ "array-bracket-spacing": "warn",
+ "template-curly-spacing": "warn",
+ "space-in-parens": "warn",
+ "@typescript-eslint/naming-convention": [
+ "warn",
+ {
+ "selector": "default",
+ "format": [
+ "camelCase"
+ ],
+ "leadingUnderscore": "allow",
+ "trailingUnderscore": "allow"
+ },
+ {
+ "selector": "variable",
+ "format": [
+ "camelCase",
+ "UPPER_CASE"
+ ],
+ "leadingUnderscore": "allow",
+ "trailingUnderscore": "allow"
+ },
+ {
+ "selector": "typeLike",
+ "format": [
+ "PascalCase"
+ ]
+ },
+ {
+ "selector": "memberLike",
+ "format": null
+ }
]
}
-}
\ No newline at end of file
+}
tests/src/addCollectionAdmin.test.tsdiffbeforeafterboth--- a/tests/src/addCollectionAdmin.test.ts
+++ b/tests/src/addCollectionAdmin.test.ts
@@ -3,12 +3,12 @@
// file 'LICENSE', which is part of this source code package.
//
-import { ApiPromise } from '@polkadot/api';
+import {ApiPromise} from '@polkadot/api';
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, destroyCollectionExpectSuccess, normalizeAccountId} from './util/helpers';
+import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';
+import {addCollectionAdminExpectSuccess, createCollectionExpectSuccess, destroyCollectionExpectSuccess, getAdminList, normalizeAccountId} from './util/helpers';
chai.use(chaiAsPromised);
const expect = chai.expect;
@@ -20,38 +20,38 @@
const alice = privateKey('//Alice');
const bob = privateKey('//Bob');
- const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
- expect(collection.owner).to.be.equal(alice.address);
+ const collection = (await api.query.common.collectionById(collectionId)).unwrap();
+ expect(collection.owner.toString()).to.be.equal(alice.address);
const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));
await submitTransactionAsync(alice, changeAdminTx);
- const adminListAfterAddAdmin: any = (await api.query.nft.adminList(collectionId));
- expect(adminListAfterAddAdmin).to.be.contains(normalizeAccountId(bob.address));
+ const adminListAfterAddAdmin = await getAdminList(api, collectionId);
+ expect(adminListAfterAddAdmin).to.be.deep.contains(normalizeAccountId(bob.address));
});
});
it('Add admin using added collection admin.', async () => {
await usingApi(async (api) => {
const collectionId = await createCollectionExpectSuccess();
- const Alice = privateKey('//Alice');
- const Bob = privateKey('//Bob');
- const Charlie = privateKey('//CHARLIE');
+ const alice = privateKey('//Alice');
+ const bob = privateKey('//Bob');
+ const charlie = privateKey('//CHARLIE');
- const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
- expect(collection.owner).to.be.equal(Alice.address);
+ const collection = (await api.query.common.collectionById(collectionId)).unwrap();
+ expect(collection.owner.toString()).to.be.equal(alice.address);
- const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Bob.address));
- await submitTransactionAsync(Alice, changeAdminTx);
+ const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));
+ await submitTransactionAsync(alice, changeAdminTx);
- const adminListAfterAddAdmin: any = (await api.query.nft.adminList(collectionId));
- expect(adminListAfterAddAdmin).to.be.contains(normalizeAccountId(Bob.address));
+ const adminListAfterAddAdmin = await getAdminList(api, collectionId);
+ expect(adminListAfterAddAdmin).to.be.deep.contains(normalizeAccountId(bob.address));
- const changeAdminTxCharlie = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Charlie.address));
- await submitTransactionAsync(Bob, changeAdminTxCharlie);
- const adminListAfterAddNewAdmin: any = (await api.query.nft.adminList(collectionId));
- expect(adminListAfterAddNewAdmin).to.be.contains(normalizeAccountId(Bob.address));
- expect(adminListAfterAddNewAdmin).to.be.contains(normalizeAccountId(Charlie.address));
+ const changeAdminTxCharlie = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(charlie.address));
+ await submitTransactionAsync(bob, changeAdminTxCharlie);
+ const adminListAfterAddNewAdmin = await getAdminList(api, collectionId);
+ expect(adminListAfterAddNewAdmin).to.be.deep.contains(normalizeAccountId(bob.address));
+ expect(adminListAfterAddNewAdmin).to.be.deep.contains(normalizeAccountId(charlie.address));
});
});
});
@@ -66,8 +66,8 @@
const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(alice.address));
await expect(submitTransactionExpectFailAsync(nonOwner, changeAdminTx)).to.be.rejected;
- const adminListAfterAddAdmin: any = (await api.query.nft.adminList(collectionId));
- expect(adminListAfterAddAdmin).not.to.be.contains(normalizeAccountId(alice.address));
+ const adminListAfterAddAdmin = await getAdminList(api, collectionId);
+ expect(adminListAfterAddAdmin).not.to.be.deep.contains(normalizeAccountId(alice.address));
// Verifying that nothing bad happened (network is live, new collections can be created, etc.)
await createCollectionExpectSuccess();
@@ -91,11 +91,11 @@
it("Can't add an admin to a destroyed collection.", async () => {
await usingApi(async (api) => {
const collectionId = await createCollectionExpectSuccess();
- const Alice = privateKey('//Alice');
- const Bob = privateKey('//Bob');
+ const alice = privateKey('//Alice');
+ const bob = privateKey('//Bob');
await destroyCollectionExpectSuccess(collectionId);
- const changeOwnerTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Bob.address));
- await expect(submitTransactionExpectFailAsync(Alice, changeOwnerTx)).to.be.rejected;
+ const changeOwnerTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(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();
@@ -104,30 +104,29 @@
it('Add an admin to a collection that has reached the maximum number of admins limit', async () => {
await usingApi(async (api: ApiPromise) => {
- const Alice = privateKey('//Alice');
+ const alice = privateKey('//Alice');
const accounts = [
- 'GsvVmjr1CBHwQHw84pPHMDxgNY3iBLz6Qn7qS3CH8qPhrHz',
- 'FoQJpPyadYccjavVdTWxpxU7rUEaYhfLCPwXgkfD6Zat9QP',
- 'JKspFU6ohf1Grg3Phdzj2pSgWvsYWzSfKghhfzMbdhNBWs5',
- 'Fr4NzY1udSFFLzb2R3qxVQkwz9cZraWkyfH4h3mVVk7BK7P',
- 'DfnTB4z7eUvYRqcGtTpFsLC69o6tvBSC1pEv8vWPZFtCkaK',
- 'HnMAUz7r2G8G3hB27SYNyit5aJmh2a5P4eMdDtACtMFDbam',
- 'DE14BzQ1bDXWPKeLoAqdLAm1GpyAWaWF1knF74cEZeomTBM',
+ privateKey('//AdminTest/1').address,
+ privateKey('//AdminTest/2').address,
+ privateKey('//AdminTest/3').address,
+ privateKey('//AdminTest/4').address,
+ privateKey('//AdminTest/5').address,
+ privateKey('//AdminTest/6').address,
+ privateKey('//AdminTest/7').address,
];
const collectionId = await createCollectionExpectSuccess();
- const chainAdminLimit = (api.consts.nft.collectionAdminsLimit as any).toNumber();
+ const chainAdminLimit = api.consts.common.collectionAdminsLimit.toNumber();
expect(chainAdminLimit).to.be.equal(5);
for (let i = 0; i < chainAdminLimit; i++) {
- const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(accounts[i]));
- await submitTransactionAsync(Alice, changeAdminTx);
- const adminListAfterAddAdmin: any = (await api.query.nft.adminList(collectionId));
- expect(adminListAfterAddAdmin).to.be.contains(normalizeAccountId(accounts[i]));
+ await addCollectionAdminExpectSuccess(alice, collectionId, accounts[i]);
+ const adminListAfterAddAdmin = await getAdminList(api, collectionId);
+ expect(adminListAfterAddAdmin).to.be.deep.contains(normalizeAccountId(accounts[i]));
}
const tx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(accounts[chainAdminLimit]));
- await expect(submitTransactionExpectFailAsync(Alice, tx)).to.be.rejected;
+ await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;
});
});
});
tests/src/addToContractWhiteList.test.tsdiffbeforeafterboth--- a/tests/src/addToContractWhiteList.test.ts
+++ b/tests/src/addToContractWhiteList.test.ts
@@ -5,7 +5,7 @@
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
-import usingApi, { submitTransactionAsync, submitTransactionExpectFailAsync } from './substrate/substrate-api';
+import usingApi, {submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';
import privateKey from './substrate/privateKey';
import {
deployFlipper,
tests/src/addToWhiteList.test.tsdiffbeforeafterboth--- a/tests/src/addToWhiteList.test.ts
+++ b/tests/src/addToWhiteList.test.ts
@@ -3,11 +3,11 @@
// file 'LICENSE', which is part of this source code package.
//
-import { IKeyringPair } from '@polkadot/types/types';
+import {IKeyringPair} from '@polkadot/types/types';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import privateKey from './substrate/privateKey';
-import usingApi, { submitTransactionExpectFailAsync } from './substrate/substrate-api';
+import usingApi, {submitTransactionExpectFailAsync} from './substrate/substrate-api';
import {
addToWhiteListExpectSuccess,
createCollectionExpectSuccess,
@@ -23,30 +23,30 @@
chai.use(chaiAsPromised);
const expect = chai.expect;
-let Alice: IKeyringPair;
-let Bob: IKeyringPair;
-let Charlie: IKeyringPair;
+let alice: IKeyringPair;
+let bob: IKeyringPair;
+let charlie: IKeyringPair;
describe('Integration Test ext. addToWhiteList()', () => {
before(async () => {
await usingApi(async () => {
- Alice = privateKey('//Alice');
- Bob = privateKey('//Bob');
+ alice = privateKey('//Alice');
+ bob = privateKey('//Bob');
});
});
it('Execute the extrinsic with parameters: Collection ID and address to add to the white list', async () => {
const collectionId = await createCollectionExpectSuccess();
- await addToWhiteListExpectSuccess(Alice, collectionId, Bob.address);
+ await addToWhiteListExpectSuccess(alice, collectionId, bob.address);
});
it('Whitelisted minting: list restrictions', async () => {
const collectionId = await createCollectionExpectSuccess();
- await addToWhiteListExpectSuccess(Alice, collectionId, Bob.address);
- await enableWhiteListExpectSuccess(Alice, collectionId);
- await enablePublicMintingExpectSuccess(Alice, collectionId);
- await createItemExpectSuccess(Bob, collectionId, 'NFT', Bob.address);
+ await addToWhiteListExpectSuccess(alice, collectionId, bob.address);
+ await enableWhiteListExpectSuccess(alice, collectionId);
+ await enablePublicMintingExpectSuccess(alice, collectionId);
+ await createItemExpectSuccess(bob, collectionId, 'NFT', bob.address);
});
});
@@ -55,35 +55,35 @@
it('White list an address in the collection that does not exist', async () => {
await usingApi(async (api) => {
// tslint:disable-next-line: no-bitwise
- const collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;
- const Bob = privateKey('//Bob');
+ const collectionId = ((await api.query.common.createdCollectionCount()).toNumber()) + 1;
+ const bob = privateKey('//Bob');
- const tx = api.tx.nft.addToWhiteList(collectionId, normalizeAccountId(Bob.address));
- await expect(submitTransactionExpectFailAsync(Alice, tx)).to.be.rejected;
+ const tx = api.tx.nft.addToWhiteList(collectionId, normalizeAccountId(bob.address));
+ await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;
});
});
it('White list an address in the collection that was destroyed', async () => {
await usingApi(async (api) => {
- const Alice = privateKey('//Alice');
- const Bob = privateKey('//Bob');
+ const alice = privateKey('//Alice');
+ const bob = privateKey('//Bob');
// tslint:disable-next-line: no-bitwise
const collectionId = await createCollectionExpectSuccess();
await destroyCollectionExpectSuccess(collectionId);
- const tx = api.tx.nft.addToWhiteList(collectionId, normalizeAccountId(Bob.address));
- await expect(submitTransactionExpectFailAsync(Alice, tx)).to.be.rejected;
+ const tx = api.tx.nft.addToWhiteList(collectionId, normalizeAccountId(bob.address));
+ await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;
});
});
it('White list an address in the collection that does not have white list access enabled', async () => {
await usingApi(async (api) => {
- const Alice = privateKey('//Alice');
- const Ferdie = privateKey('//Ferdie');
+ const alice = privateKey('//Alice');
+ const ferdie = privateKey('//Ferdie');
const collectionId = await createCollectionExpectSuccess();
- await enableWhiteListExpectSuccess(Alice, collectionId);
- await enablePublicMintingExpectSuccess(Alice, collectionId);
- const tx = api.tx.nft.createItem(collectionId, normalizeAccountId(Ferdie.address), 'NFT');
- await expect(submitTransactionExpectFailAsync(Ferdie, tx)).to.be.rejected;
+ await enableWhiteListExpectSuccess(alice, collectionId);
+ await enablePublicMintingExpectSuccess(alice, collectionId);
+ const tx = api.tx.nft.createItem(collectionId, normalizeAccountId(ferdie.address), 'NFT');
+ await expect(submitTransactionExpectFailAsync(ferdie, tx)).to.be.rejected;
});
});
@@ -93,32 +93,32 @@
before(async () => {
await usingApi(async () => {
- Alice = privateKey('//Alice');
- Bob = privateKey('//Bob');
- Charlie = privateKey('//Charlie');
+ alice = privateKey('//Alice');
+ bob = privateKey('//Bob');
+ charlie = privateKey('//Charlie');
});
});
it('Negative. Add to the white list by regular user', async () => {
const collectionId = await createCollectionExpectSuccess();
- await addToWhiteListExpectFail(Bob, collectionId, Charlie.address);
+ await addToWhiteListExpectFail(bob, collectionId, charlie.address);
});
it('Execute the extrinsic with parameters: Collection ID and address to add to the white list', async () => {
const collectionId = await createCollectionExpectSuccess();
- await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);
- await addToWhiteListExpectSuccess(Bob, collectionId, Charlie.address);
+ await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
+ await addToWhiteListExpectSuccess(bob, collectionId, charlie.address);
});
it('Whitelisted minting: list restrictions', async () => {
const collectionId = await createCollectionExpectSuccess();
- await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);
- await addToWhiteListExpectSuccess(Bob, collectionId, Charlie.address);
+ await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
+ await addToWhiteListExpectSuccess(bob, collectionId, charlie.address);
// allowed only for collection owner
- await enableWhiteListExpectSuccess(Alice, collectionId);
- await enablePublicMintingExpectSuccess(Alice, collectionId);
+ await enableWhiteListExpectSuccess(alice, collectionId);
+ await enablePublicMintingExpectSuccess(alice, collectionId);
- await createItemExpectSuccess(Charlie, collectionId, 'NFT', Charlie.address);
+ await createItemExpectSuccess(charlie, collectionId, 'NFT', charlie.address);
});
-});
\ No newline at end of file
+});
tests/src/approve.test.tsdiffbeforeafterboth--- a/tests/src/approve.test.ts
+++ b/tests/src/approve.test.ts
@@ -2,12 +2,12 @@
// This file is subject to the terms and conditions defined in
// file 'LICENSE', which is part of this source code package.
//
-import { IKeyringPair } from '@polkadot/types/types';
-import { ApiPromise } from '@polkadot/api';
+import {IKeyringPair} from '@polkadot/types/types';
+import {ApiPromise} from '@polkadot/api';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import privateKey from './substrate/privateKey';
-import { default as usingApi } from './substrate/substrate-api';
+import {default as usingApi} from './substrate/substrate-api';
import {
approveExpectFail,
approveExpectSuccess,
@@ -17,90 +17,91 @@
setCollectionLimitsExpectSuccess,
transferExpectSuccess,
addCollectionAdminExpectSuccess,
+ adminApproveFromExpectSuccess,
} from './util/helpers';
chai.use(chaiAsPromised);
describe('Integration Test approve(spender, collection_id, item_id, amount):', () => {
- let Alice: IKeyringPair;
- let Bob: IKeyringPair;
- let Charlie: IKeyringPair;
+ let alice: IKeyringPair;
+ let bob: IKeyringPair;
+ let charlie: IKeyringPair;
before(async () => {
await usingApi(async () => {
- Alice = privateKey('//Alice');
- Bob = privateKey('//Bob');
- Charlie = privateKey('//Charlie');
+ alice = privateKey('//Alice');
+ bob = privateKey('//Bob');
+ charlie = privateKey('//Charlie');
});
});
it('Execute the extrinsic and check approvedList', async () => {
const nftCollectionId = await createCollectionExpectSuccess();
// nft
- const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
- await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob);
+ const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
+ await approveExpectSuccess(nftCollectionId, newNftTokenId, alice, bob.address);
// fungible
const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
- const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');
- await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);
+ const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');
+ await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob.address);
// reFungible
const reFungibleCollectionId =
await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
- const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');
- await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);
+ const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');
+ await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, alice, bob.address);
});
it('Remove approval by using 0 amount', async () => {
const nftCollectionId = await createCollectionExpectSuccess();
// nft
- const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
- await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 1);
- await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 0);
+ const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
+ await approveExpectSuccess(nftCollectionId, newNftTokenId, alice, bob.address, 1);
+ await approveExpectSuccess(nftCollectionId, newNftTokenId, alice, bob.address, 0);
// fungible
const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
- const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');
- await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob, 1);
- await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob, 0);
+ const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');
+ await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob.address, 1);
+ await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob.address, 0);
// reFungible
const reFungibleCollectionId =
await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
- const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');
- await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob, 1);
- await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob, 0);
+ const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');
+ await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, alice, bob.address, 1);
+ await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, alice, bob.address, 0);
});
it('can be called by collection owner on non-owned item when OwnerCanTransfer == true', async () => {
const collectionId = await createCollectionExpectSuccess();
- const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Bob.address);
+ const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', bob.address);
- await approveExpectSuccess(collectionId, itemId, Alice, Charlie);
+ await adminApproveFromExpectSuccess(collectionId, itemId, alice, bob.address, charlie.address);
});
});
describe('Negative Integration Test approve(spender, collection_id, item_id, amount):', () => {
- let Alice: IKeyringPair;
- let Bob: IKeyringPair;
- let Charlie: IKeyringPair;
+ let alice: IKeyringPair;
+ let bob: IKeyringPair;
+ let charlie: IKeyringPair;
before(async () => {
await usingApi(async () => {
- Alice = privateKey('//Alice');
- Bob = privateKey('//Bob');
- Charlie = privateKey('//Charlie');
+ alice = privateKey('//Alice');
+ bob = privateKey('//Bob');
+ charlie = privateKey('//Charlie');
});
});
it('Approve for a collection that does not exist', async () => {
await usingApi(async (api: ApiPromise) => {
// nft
- const nftCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;
- await approveExpectFail(nftCollectionCount + 1, 1, Alice, Bob);
+ const nftCollectionCount = (await api.query.common.createdCollectionCount()).toNumber();
+ await approveExpectFail(nftCollectionCount + 1, 1, alice, bob);
// fungible
- const fungibleCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;
- await approveExpectFail(fungibleCollectionCount + 1, 1, Alice, Bob);
+ const fungibleCollectionCount = (await api.query.common.createdCollectionCount()).toNumber();
+ await approveExpectFail(fungibleCollectionCount + 1, 0, alice, bob);
// reFungible
- const reFungibleCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;
- await approveExpectFail(reFungibleCollectionCount + 1, 1, Alice, Bob);
+ const reFungibleCollectionCount = (await api.query.common.createdCollectionCount()).toNumber();
+ await approveExpectFail(reFungibleCollectionCount + 1, 1, alice, bob);
});
});
@@ -108,95 +109,87 @@
// nft
const nftCollectionId = await createCollectionExpectSuccess();
await destroyCollectionExpectSuccess(nftCollectionId);
- await approveExpectFail(nftCollectionId, 1, Alice, Bob);
+ await approveExpectFail(nftCollectionId, 1, alice, bob);
// fungible
const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
await destroyCollectionExpectSuccess(fungibleCollectionId);
- await approveExpectFail(fungibleCollectionId, 1, Alice, Bob);
+ await approveExpectFail(fungibleCollectionId, 0, alice, bob);
// reFungible
const reFungibleCollectionId =
await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
await destroyCollectionExpectSuccess(reFungibleCollectionId);
- await approveExpectFail(reFungibleCollectionId, 1, Alice, Bob);
+ await approveExpectFail(reFungibleCollectionId, 1, alice, bob);
});
it('Approve transfer of a token that does not exist', async () => {
// nft
const nftCollectionId = await createCollectionExpectSuccess();
- await approveExpectFail(nftCollectionId, 2, Alice, Bob);
+ await approveExpectFail(nftCollectionId, 2, alice, bob);
// reFungible
const reFungibleCollectionId =
await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
- await approveExpectFail(reFungibleCollectionId, 2, Alice, Bob);
+ await approveExpectFail(reFungibleCollectionId, 2, alice, bob);
});
it('Approve using the address that does not own the approved token', async () => {
const nftCollectionId = await createCollectionExpectSuccess();
// nft
- const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
- await approveExpectFail(nftCollectionId, newNftTokenId, Bob, Alice);
+ const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
+ await approveExpectFail(nftCollectionId, newNftTokenId, bob, alice);
// fungible
const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
- const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');
- await approveExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice);
+ const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');
+ await approveExpectFail(fungibleCollectionId, newFungibleTokenId, bob, alice);
// reFungible
const reFungibleCollectionId =
await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
- const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');
- await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, Bob, Alice);
- });
-
- it('should fail if approved more NFTs than owned', async () => {
- const nftCollectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });
- const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
- await transferExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 1, 'NFT');
- await approveExpectSuccess(nftCollectionId, newNftTokenId, Bob, Alice);
- await approveExpectFail(nftCollectionId, newNftTokenId, Bob, Alice);
+ const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');
+ await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, bob, alice);
});
it('should fail if approved more ReFungibles than owned', async () => {
- const nftCollectionId = await createCollectionExpectSuccess({ mode: { type: 'ReFungible' } });
- const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'ReFungible');
- await transferExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 100, 'ReFungible');
- await approveExpectSuccess(nftCollectionId, newNftTokenId, Bob, Alice, 100);
- await approveExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, 1);
+ const nftCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
+ const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'ReFungible');
+ await transferExpectSuccess(nftCollectionId, newNftTokenId, alice, bob, 100, 'ReFungible');
+ await approveExpectSuccess(nftCollectionId, newNftTokenId, bob, alice.address, 100);
+ await approveExpectFail(nftCollectionId, newNftTokenId, bob, alice, 101);
});
it('should fail if approved more Fungibles than owned', async () => {
- const nftCollectionId = await createCollectionExpectSuccess({ mode: { type: 'Fungible', decimalPoints: 0 } });
- const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'Fungible');
- await transferExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 10, 'Fungible');
- await approveExpectSuccess(nftCollectionId, newNftTokenId, Bob, Alice, 10);
- await approveExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, 1);
+ const nftCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
+ const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'Fungible');
+ await transferExpectSuccess(nftCollectionId, newNftTokenId, alice, bob, 10, 'Fungible');
+ await approveExpectSuccess(nftCollectionId, newNftTokenId, bob, alice.address, 10);
+ await approveExpectFail(nftCollectionId, newNftTokenId, bob, alice, 11);
});
it('fails when called by collection owner on non-owned item when OwnerCanTransfer == false', async () => {
const collectionId = await createCollectionExpectSuccess();
- const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Bob.address);
- await setCollectionLimitsExpectSuccess(Alice, collectionId, { ownerCanTransfer: false });
+ const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', bob.address);
+ await setCollectionLimitsExpectSuccess(alice, collectionId, {ownerCanTransfer: false});
- await approveExpectFail(collectionId, itemId, Alice, Charlie);
+ await approveExpectFail(collectionId, itemId, alice, charlie);
});
});
describe('Integration Test approve(spender, collection_id, item_id, amount) with collection admin permissions:', () => {
- let Alice: IKeyringPair;
- let Bob: IKeyringPair;
- let Charlie: IKeyringPair;
+ let alice: IKeyringPair;
+ let bob: IKeyringPair;
+ let charlie: IKeyringPair;
before(async () => {
await usingApi(async () => {
- Alice = privateKey('//Alice');
- Bob = privateKey('//Bob');
- Charlie = privateKey('//Charlie');
+ alice = privateKey('//Alice');
+ bob = privateKey('//Bob');
+ charlie = privateKey('//Charlie');
});
});
it('can be called by collection admin on non-owned item', async () => {
const collectionId = await createCollectionExpectSuccess();
- const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Alice.address);
+ const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
- await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);
- await approveExpectSuccess(collectionId, itemId, Bob, Charlie);
+ await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
+ await adminApproveFromExpectSuccess(collectionId, itemId, bob, alice.address, charlie.address);
});
});
tests/src/block-production.test.tsdiffbeforeafterboth--- a/tests/src/block-production.test.ts
+++ b/tests/src/block-production.test.ts
@@ -4,17 +4,17 @@
//
import usingApi from './substrate/substrate-api';
-import { expect } from 'chai';
-import { ApiPromise } from '@polkadot/api';
+import {expect} from 'chai';
+import {ApiPromise} from '@polkadot/api';
-const BlockTimeMs = 12000;
-const ToleranceMs = 1000;
+const BLOCK_TIME_MS = 3000;
+const TOLERANCE_MS = 1000;
/* eslint no-async-promise-executor: "off" */
function getBlocks(api: ApiPromise): Promise<number[]> {
return new Promise<number[]>(async (resolve, reject) => {
const blockNumbers: number[] = [];
- setTimeout(() => reject('Block production test failed due to timeout.'), BlockTimeMs + ToleranceMs);
+ setTimeout(() => reject('Block production test failed due to timeout.'), BLOCK_TIME_MS + TOLERANCE_MS);
const unsubscribe = await api.rpc.chain.subscribeNewHeads((head: any) => {
blockNumbers.push(head.number.toNumber());
if(blockNumbers.length >= 2) {
tests/src/burnItem.test.tsdiffbeforeafterboth--- a/tests/src/burnItem.test.ts
+++ b/tests/src/burnItem.test.ts
@@ -3,9 +3,9 @@
// file 'LICENSE', which is part of this source code package.
//
-import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from './substrate/substrate-api';
-import { Keyring } from '@polkadot/api';
-import { IKeyringPair } from '@polkadot/types/types';
+import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';
+import {Keyring} from '@polkadot/api';
+import {IKeyringPair} from '@polkadot/types/types';
import {
createCollectionExpectSuccess,
createItemExpectSuccess,
@@ -13,6 +13,8 @@
destroyCollectionExpectSuccess,
normalizeAccountId,
addCollectionAdminExpectSuccess,
+ getBalance,
+ isTokenExists,
} from './util/helpers';
import chai from 'chai';
@@ -26,7 +28,7 @@
describe('integration test: ext. burnItem():', () => {
before(async () => {
await usingApi(async () => {
- const keyring = new Keyring({ type: 'sr25519' });
+ const keyring = new Keyring({type: 'sr25519'});
alice = keyring.addFromUri('//Alice');
bob = keyring.addFromUri('//Bob');
});
@@ -41,19 +43,16 @@
const tx = api.tx.nft.burnItem(collectionId, tokenId, 1);
const events = await submitTransactionAsync(alice, tx);
const result = getGenericResult(events);
- // Get the item
- const item: any = (await api.query.nft.nftItemList(collectionId, tokenId)).toJSON();
- // What to expect
- // tslint:disable-next-line:no-unused-expression
+
expect(result.success).to.be.true;
- // tslint:disable-next-line:no-unused-expression
- expect(item).to.be.null;
+ // Get the item
+ expect(await isTokenExists(api, collectionId, tokenId)).to.be.false;
});
});
it('Burn item in Fungible collection', async () => {
const createMode = 'Fungible';
- const collectionId = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0 }});
+ const collectionId = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});
await createItemExpectSuccess(alice, collectionId, createMode); // Helper creates 10 fungible tokens
const tokenId = 0; // ignored
@@ -64,18 +63,17 @@
const result = getGenericResult(events);
// Get alice balance
- const balance: any = (await api.query.nft.fungibleItemList(collectionId, alice.address)).toJSON();
+ const balance = await getBalance(api, collectionId, alice.address, 0);
// What to expect
expect(result.success).to.be.true;
- expect(balance).to.be.not.null;
- expect(balance.value).to.be.equal(9);
+ expect(balance).to.be.equal(9n);
});
});
it('Burn item in ReFungible collection', async () => {
const createMode = 'ReFungible';
- const collectionId = await createCollectionExpectSuccess({mode: {type: createMode }});
+ const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}});
const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);
await usingApi(async (api) => {
@@ -84,11 +82,11 @@
const result = getGenericResult(events);
// Get alice balance
- const balance: any = (await api.query.nft.reFungibleItemList(collectionId, tokenId)).toJSON();
+ const balance = await getBalance(api, collectionId, alice.address, tokenId);
// What to expect
expect(result.success).to.be.true;
- expect(balance).to.be.null;
+ expect(balance).to.be.equal(0n);
});
});
@@ -104,7 +102,8 @@
const result1 = getGenericResult(events1);
// Get balances
- const balanceBefore: any = (await api.query.nft.reFungibleItemList(collectionId, tokenId)).toJSON();
+ const bobBalanceBefore = await getBalance(api, collectionId, bob.address, tokenId);
+ const aliceBalanceBefore = await getBalance(api, collectionId, alice.address, tokenId);
// Bob burns his portion
const tx = api.tx.nft.burnItem(collectionId, tokenId, 1);
@@ -112,24 +111,19 @@
const result2 = getGenericResult(events2);
// Get balances
- const balance: any = (await api.query.nft.reFungibleItemList(collectionId, tokenId)).toJSON();
+ const bobBalanceAfter = await getBalance(api, collectionId, bob.address, tokenId);
+ const aliceBalanceAfter = await getBalance(api, collectionId, alice.address, tokenId);
// console.log(balance);
// What to expect before burning
expect(result1.success).to.be.true;
- expect(balanceBefore).to.be.not.null;
- expect(balanceBefore.owner.length).to.be.equal(2);
- expect(balanceBefore.owner[0].owner).to.be.deep.equal(normalizeAccountId(alice.address));
- expect(balanceBefore.owner[0].fraction).to.be.equal(99);
- expect(balanceBefore.owner[1].owner).to.be.deep.equal(normalizeAccountId(bob.address));
- expect(balanceBefore.owner[1].fraction).to.be.equal(1);
+ expect(aliceBalanceBefore).to.be.equal(99n);
+ expect(bobBalanceBefore).to.be.equal(1n);
// What to expect after burning
expect(result2.success).to.be.true;
- expect(balance).to.be.not.null;
- expect(balance.owner.length).to.be.equal(1);
- expect(balance.owner[0].fraction).to.be.equal(99);
- expect(balance.owner[0].owner).to.be.deep.equal(normalizeAccountId(alice.address));
+ expect(aliceBalanceAfter).to.be.equal(99n);
+ expect(bobBalanceAfter).to.be.equal(0n);
});
});
@@ -139,7 +133,7 @@
describe('integration test: ext. burnItem() with admin permissions:', () => {
before(async () => {
await usingApi(async () => {
- const keyring = new Keyring({ type: 'sr25519' });
+ const keyring = new Keyring({type: 'sr25519'});
alice = keyring.addFromUri('//Alice');
bob = keyring.addFromUri('//Bob');
});
@@ -149,28 +143,25 @@
const createMode = 'NFT';
const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}});
const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);
- await addCollectionAdminExpectSuccess(alice, collectionId, bob);
+ await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
await usingApi(async (api) => {
const tx = api.tx.nft.burnItem(collectionId, tokenId, 1);
const events = await submitTransactionAsync(bob, tx);
const result = getGenericResult(events);
+
+ expect(result.success).to.be.true;
// Get the item
- const item: any = (await api.query.nft.nftItemList(collectionId, tokenId)).toJSON();
- // What to expect
- // tslint:disable-next-line:no-unused-expression
- expect(result.success).to.be.true;
- // tslint:disable-next-line:no-unused-expression
- expect(item).to.be.null;
+ expect(await isTokenExists(api, collectionId, tokenId)).to.be.false;
});
});
-
+ // TODO: burnFrom
it('Burn item in Fungible collection', async () => {
const createMode = 'Fungible';
- const collectionId = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0 }});
+ const collectionId = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});
const tokenId = await createItemExpectSuccess(alice, collectionId, createMode); // Helper creates 10 fungible tokens
- await addCollectionAdminExpectSuccess(alice, collectionId, bob);
+ await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
await usingApi(async (api) => {
// Destroy 1 of 10
@@ -179,31 +170,29 @@
const result = getGenericResult(events);
// Get alice balance
- const balance: any = (await api.query.nft.fungibleItemList(collectionId, alice.address)).toJSON();
+ const balance = await getBalance(api, collectionId, alice.address, 0);
// What to expect
expect(result.success).to.be.true;
- expect(balance).to.be.not.null;
- expect(balance.value).to.be.equal(9);
+ expect(balance).to.be.equal(9n);
});
});
+ // TODO: burnFrom
it('Burn item in ReFungible collection', async () => {
const createMode = 'ReFungible';
- const collectionId = await createCollectionExpectSuccess({mode: {type: createMode }});
+ const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}});
const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);
- await addCollectionAdminExpectSuccess(alice, collectionId, bob);
+ await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
await usingApi(async (api) => {
const tx = api.tx.nft.burnFrom(collectionId, normalizeAccountId(alice.address), tokenId, 100);
const events = await submitTransactionAsync(bob, tx);
const result = getGenericResult(events);
// Get alice balance
- const balance: any = (await api.query.nft.reFungibleItemList(collectionId, tokenId)).toJSON();
-
- // What to expect
expect(result.success).to.be.true;
- expect(balance).to.be.null;
+ // Get the item
+ expect(await isTokenExists(api, collectionId, tokenId)).to.be.false;
});
});
});
@@ -211,7 +200,7 @@
describe('Negative integration test: ext. burnItem():', () => {
before(async () => {
await usingApi(async () => {
- const keyring = new Keyring({ type: 'sr25519' });
+ const keyring = new Keyring({type: 'sr25519'});
alice = keyring.addFromUri('//Alice');
bob = keyring.addFromUri('//Bob');
});
@@ -219,7 +208,7 @@
it('Burn a token in a destroyed collection', async () => {
const createMode = 'NFT';
- const collectionId = await createCollectionExpectSuccess({mode: {type: createMode }});
+ const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}});
const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);
await destroyCollectionExpectSuccess(collectionId);
@@ -235,7 +224,7 @@
it('Burn a token that was never created', async () => {
const createMode = 'NFT';
- const collectionId = await createCollectionExpectSuccess({mode: {type: createMode }});
+ const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}});
const tokenId = 10;
await usingApi(async (api) => {
@@ -250,11 +239,11 @@
it('Burn a token using the address that does not own it', async () => {
const createMode = 'NFT';
- const collectionId = await createCollectionExpectSuccess({mode: {type: createMode }});
+ const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}});
const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);
await usingApi(async (api) => {
- const tx = api.tx.nft.burnItem(collectionId, tokenId, 0);
+ const tx = api.tx.nft.burnItem(collectionId, tokenId, 1);
const badTransaction = async function () {
await submitTransactionExpectFailAsync(bob, tx);
};
@@ -265,7 +254,7 @@
it('Transfer a burned a token', async () => {
const createMode = 'NFT';
- const collectionId = await createCollectionExpectSuccess({mode: {type: createMode }});
+ const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}});
const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);
await usingApi(async (api) => {
@@ -275,7 +264,7 @@
const result1 = getGenericResult(events1);
expect(result1.success).to.be.true;
- const tx = api.tx.nft.transfer(normalizeAccountId(bob.address), collectionId, tokenId, 0);
+ const tx = api.tx.nft.transfer(normalizeAccountId(bob.address), collectionId, tokenId, 1);
const badTransaction = async function () {
await submitTransactionExpectFailAsync(alice, tx);
};
@@ -286,7 +275,7 @@
it('Burn more than owned in Fungible collection', async () => {
const createMode = 'Fungible';
- const collectionId = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0 }});
+ const collectionId = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});
// Helper creates 10 fungible tokens
await createItemExpectSuccess(alice, collectionId, createMode);
const tokenId = 0; // ignored
@@ -300,11 +289,10 @@
await expect(badTransaction()).to.be.rejected;
// Get alice balance
- const balance: any = (await api.query.nft.fungibleItemList(collectionId, alice.address)).toJSON();
+ const balance = await getBalance(api, collectionId, alice.address, 0);
// What to expect
- expect(balance).to.be.not.null;
- expect(balance.value).to.be.equal(10);
+ expect(balance).to.be.equal(10n);
});
});
tests/src/change-collection-owner.test.tsdiffbeforeafterboth--- a/tests/src/change-collection-owner.test.ts
+++ b/tests/src/change-collection-owner.test.ts
@@ -6,8 +6,8 @@
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,
+import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';
+import {createCollectionExpectSuccess,
addCollectionAdminExpectSuccess,
setCollectionSponsorExpectSuccess,
confirmSponsorshipExpectSuccess,
@@ -34,14 +34,14 @@
const alice = privateKey('//Alice');
const bob = privateKey('//Bob');
- const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
- expect(collection.owner).to.be.deep.eq(alice.address);
+ const collection = (await api.query.common.collectionById(collectionId)).unwrap();
+ expect(collection.owner.toString()).to.be.deep.eq(alice.address);
const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);
await submitTransactionAsync(alice, changeOwnerTx);
- const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();
- expect(collectionAfterOwnerChange.owner).to.be.deep.eq(bob.address);
+ const collectionAfterOwnerChange = (await api.query.common.collectionById(collectionId)).unwrap();
+ expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(bob.address);
});
});
});
@@ -53,8 +53,8 @@
const alice = privateKey('//Alice');
const bob = privateKey('//Bob');
- const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
- expect(collection.owner).to.be.deep.eq(alice.address);
+ const collection = (await api.query.common.collectionById(collectionId)).unwrap();
+ expect(collection.owner.toString()).to.be.deep.eq(alice.address);
const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);
await submitTransactionAsync(alice, changeOwnerTx);
@@ -62,8 +62,8 @@
const badChangeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, alice.address);
await expect(submitTransactionExpectFailAsync(alice, badChangeOwnerTx)).to.be.rejected;
- const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();
- expect(collectionAfterOwnerChange.owner).to.be.deep.eq(bob.address);
+ const collectionAfterOwnerChange = (await api.query.common.collectionById(collectionId)).unwrap();
+ expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(bob.address);
});
});
@@ -74,14 +74,14 @@
const bob = privateKey('//Bob');
const charlie = privateKey('//Charlie');
- const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
- expect(collection.owner).to.be.deep.eq(alice.address);
+ const collection = (await api.query.common.collectionById(collectionId)).unwrap();
+ expect(collection.owner.toString()).to.be.deep.eq(alice.address);
const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);
await submitTransactionAsync(alice, changeOwnerTx);
- const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();
- expect(collectionAfterOwnerChange.owner).to.be.deep.eq(bob.address);
+ const collectionAfterOwnerChange = (await api.query.common.collectionById(collectionId)).unwrap();
+ expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(bob.address);
// After changing the owner of the collection, all privileged methods are available to the new owner
// The new owner of the collection has access to sponsorship management operations in the collection
@@ -94,7 +94,7 @@
accountTokenOwnershipLimit: 1,
sponsoredMintSize: 1,
tokenLimit: 1,
- sponsorTimeout: 1,
+ sponsorTransferTimeout: 1,
ownerCanTransfer: true,
ownerCanDestroy: true,
};
@@ -118,21 +118,21 @@
const bob = privateKey('//Bob');
const charlie = privateKey('//Charlie');
- const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
- expect(collection.owner).to.be.deep.eq(alice.address);
+ const collection = (await api.query.common.collectionById(collectionId)).unwrap();
+ expect(collection.owner.toString()).to.be.deep.eq(alice.address);
const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);
await submitTransactionAsync(alice, changeOwnerTx);
- const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();
- expect(collectionAfterOwnerChange.owner).to.be.deep.eq(bob.address);
+ const collectionAfterOwnerChange = (await api.query.common.collectionById(collectionId)).unwrap();
+ expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(bob.address);
const changeOwnerTx2 = api.tx.nft.changeCollectionOwner(collectionId, charlie.address);
await submitTransactionAsync(bob, changeOwnerTx2);
// ownership lost
- const collectionAfterOwnerChange2: any = (await api.query.nft.collectionById(collectionId)).toJSON();
- expect(collectionAfterOwnerChange2.owner).to.be.deep.eq(charlie.address);
+ const collectionAfterOwnerChange2 = (await api.query.common.collectionById(collectionId)).unwrap();
+ expect(collectionAfterOwnerChange2.owner.toString()).to.be.deep.eq(charlie.address);
});
});
});
@@ -147,8 +147,8 @@
const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);
await expect(submitTransactionExpectFailAsync(bob, changeOwnerTx)).to.be.rejected;
- const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();
- expect(collectionAfterOwnerChange.owner).to.be.deep.eq(alice.address);
+ const collectionAfterOwnerChange = (await api.query.common.collectionById(collectionId)).unwrap();
+ expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(alice.address);
// Verifying that nothing bad happened (network is live, new collections can be created, etc.)
await createCollectionExpectSuccess();
@@ -161,13 +161,13 @@
const alice = privateKey('//Alice');
const bob = privateKey('//Bob');
- await addCollectionAdminExpectSuccess(alice, collectionId, bob);
+ await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);
await expect(submitTransactionExpectFailAsync(bob, changeOwnerTx)).to.be.rejected;
- const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();
- expect(collectionAfterOwnerChange.owner).to.be.deep.eq(alice.address);
+ const collectionAfterOwnerChange = (await api.query.common.collectionById(collectionId)).unwrap();
+ expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(alice.address);
// Verifying that nothing bad happened (network is live, new collections can be created, etc.)
await createCollectionExpectSuccess();
@@ -195,8 +195,8 @@
const bob = privateKey('//Bob');
const charlie = privateKey('//Charlie');
- const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
- expect(collection.owner).to.be.deep.eq(alice.address);
+ const collection = (await api.query.common.collectionById(collectionId)).unwrap();
+ expect(collection.owner.toString()).to.be.deep.eq(alice.address);
const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);
await submitTransactionAsync(alice, changeOwnerTx);
@@ -204,8 +204,8 @@
const badChangeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, alice.address);
await expect(submitTransactionExpectFailAsync(alice, badChangeOwnerTx)).to.be.rejected;
- const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();
- expect(collectionAfterOwnerChange.owner).to.be.deep.eq(bob.address);
+ const collectionAfterOwnerChange = (await api.query.common.collectionById(collectionId)).unwrap();
+ expect(collectionAfterOwnerChange.owner.toString()).to.be.deep.eq(bob.address);
await setCollectionSponsorExpectFailure(collectionId, charlie.address, '//Alice');
await confirmSponsorshipExpectFailure(collectionId, '//Alice');
@@ -215,7 +215,7 @@
accountTokenOwnershipLimit: 1,
sponsoredMintSize: 1,
tokenLimit: 1,
- sponsorTimeout: 1,
+ sponsorTransferTimeout: 1,
ownerCanTransfer: true,
ownerCanDestroy: true,
};
tests/src/check-event/burnItemEvent.test.tsdiffbeforeafterboth--- a/tests/src/check-event/burnItemEvent.test.ts
+++ b/tests/src/check-event/burnItemEvent.test.ts
@@ -4,33 +4,33 @@
//
// https://unique-network.readthedocs.io/en/latest/jsapi.html#setchainlimits
-import { ApiPromise } from '@polkadot/api';
-import { IKeyringPair } from '@polkadot/types/types';
+import {ApiPromise} from '@polkadot/api';
+import {IKeyringPair} from '@polkadot/types/types';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import privateKey from '../substrate/privateKey';
import usingApi, {submitTransactionAsync} from '../substrate/substrate-api';
-import { createCollectionExpectSuccess, createItemExpectSuccess, nftEventMessage } from '../util/helpers';
+import {createCollectionExpectSuccess, createItemExpectSuccess, nftEventMessage} from '../util/helpers';
chai.use(chaiAsPromised);
const expect = chai.expect;
describe('Burn Item event ', () => {
- let Alice: IKeyringPair;
+ let alice: IKeyringPair;
const checkSection = 'ItemDestroyed';
const checkTreasury = 'Deposit';
const checkSystem = 'ExtrinsicSuccess';
before(async () => {
await usingApi(async () => {
- Alice = privateKey('//Alice');
+ alice = privateKey('//Alice');
});
});
it('Check event from burnItem(): ', async () => {
await usingApi(async (api: ApiPromise) => {
const collectionID = await createCollectionExpectSuccess();
- const itemID = await createItemExpectSuccess(Alice, collectionID, 'NFT');
+ const itemID = await createItemExpectSuccess(alice, collectionID, 'NFT');
const burnItem = api.tx.nft.burnItem(collectionID, itemID, 1);
- const events = await submitTransactionAsync(Alice, burnItem);
+ const events = await submitTransactionAsync(alice, burnItem);
const msg = JSON.stringify(nftEventMessage(events));
expect(msg).to.be.contain(checkSection);
expect(msg).to.be.contain(checkTreasury);
@@ -38,4 +38,3 @@
});
});
});
-
tests/src/check-event/createCollectionEvent.test.tsdiffbeforeafterboth--- a/tests/src/check-event/createCollectionEvent.test.ts
+++ b/tests/src/check-event/createCollectionEvent.test.ts
@@ -4,31 +4,31 @@
//
// https://unique-network.readthedocs.io/en/latest/jsapi.html#setchainlimits
-import { ApiPromise } from '@polkadot/api';
-import { IKeyringPair } from '@polkadot/types/types';
+import {ApiPromise} from '@polkadot/api';
+import {IKeyringPair} from '@polkadot/types/types';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import privateKey from '../substrate/privateKey';
import usingApi, {submitTransactionAsync} from '../substrate/substrate-api';
-import { nftEventMessage } from '../util/helpers';
+import {nftEventMessage} from '../util/helpers';
chai.use(chaiAsPromised);
const expect = chai.expect;
describe('Create collection event ', () => {
- let Alice: IKeyringPair;
+ let alice: IKeyringPair;
const checkSection = 'CollectionCreated';
const checkTreasury = 'Deposit';
const checkSystem = 'ExtrinsicSuccess';
before(async () => {
await usingApi(async () => {
- Alice = privateKey('//Alice');
+ alice = privateKey('//Alice');
});
});
it('Check event from createCollection(): ', async () => {
await usingApi(async (api: ApiPromise) => {
- const tx = api.tx.nft.createCollection('0x31', '0x32', '0x33', 'NFT');
- const events = await submitTransactionAsync(Alice, tx);
+ const tx = api.tx.nft.createCollection([0x31], [0x32], '0x33', 'NFT');
+ const events = await submitTransactionAsync(alice, tx);
const msg = JSON.stringify(nftEventMessage(events));
expect(msg).to.be.contain(checkSection);
expect(msg).to.be.contain(checkTreasury);
@@ -36,4 +36,3 @@
});
});
});
-
\ No newline at end of file
tests/src/check-event/createItemEvent.test.tsdiffbeforeafterboth--- a/tests/src/check-event/createItemEvent.test.ts
+++ b/tests/src/check-event/createItemEvent.test.ts
@@ -4,32 +4,32 @@
//
// https://unique-network.readthedocs.io/en/latest/jsapi.html#setchainlimits
-import { ApiPromise } from '@polkadot/api';
-import { IKeyringPair } from '@polkadot/types/types';
+import {ApiPromise} from '@polkadot/api';
+import {IKeyringPair} from '@polkadot/types/types';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import privateKey from '../substrate/privateKey';
import usingApi, {submitTransactionAsync} from '../substrate/substrate-api';
-import { createCollectionExpectSuccess, nftEventMessage, normalizeAccountId } from '../util/helpers';
+import {createCollectionExpectSuccess, nftEventMessage, normalizeAccountId} from '../util/helpers';
chai.use(chaiAsPromised);
const expect = chai.expect;
describe('Create Item event ', () => {
- let Alice: IKeyringPair;
+ let alice: IKeyringPair;
const checkSection = 'ItemCreated';
const checkTreasury = 'Deposit';
const checkSystem = 'ExtrinsicSuccess';
before(async () => {
await usingApi(async () => {
- Alice = privateKey('//Alice');
+ alice = privateKey('//Alice');
});
});
it('Check event from createItem(): ', async () => {
await usingApi(async (api: ApiPromise) => {
const collectionID = await createCollectionExpectSuccess();
- const createItem = api.tx.nft.createItem(collectionID, normalizeAccountId(Alice.address), 'NFT');
- const events = await submitTransactionAsync(Alice, createItem);
+ const createItem = api.tx.nft.createItem(collectionID, normalizeAccountId(alice.address), 'NFT');
+ const events = await submitTransactionAsync(alice, createItem);
const msg = JSON.stringify(nftEventMessage(events));
expect(msg).to.be.contain(checkSection);
expect(msg).to.be.contain(checkTreasury);
@@ -37,4 +37,3 @@
});
});
});
-
tests/src/check-event/createMultipleItemsEvent.test.tsdiffbeforeafterboth--- a/tests/src/check-event/createMultipleItemsEvent.test.ts
+++ b/tests/src/check-event/createMultipleItemsEvent.test.ts
@@ -4,33 +4,33 @@
//
// https://unique-network.readthedocs.io/en/latest/jsapi.html#setchainlimits
-import { ApiPromise } from '@polkadot/api';
-import { IKeyringPair } from '@polkadot/types/types';
+import {ApiPromise} from '@polkadot/api';
+import {IKeyringPair} from '@polkadot/types/types';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import privateKey from '../substrate/privateKey';
import usingApi, {submitTransactionAsync} from '../substrate/substrate-api';
-import { createCollectionExpectSuccess, nftEventMessage, normalizeAccountId } from '../util/helpers';
+import {createCollectionExpectSuccess, nftEventMessage, normalizeAccountId} from '../util/helpers';
chai.use(chaiAsPromised);
const expect = chai.expect;
describe('Create Multiple Items Event event ', () => {
- let Alice: IKeyringPair;
+ let alice: IKeyringPair;
const checkSection = 'ItemCreated';
const checkTreasury = 'Deposit';
const checkSystem = 'ExtrinsicSuccess';
before(async () => {
await usingApi(async () => {
- Alice = privateKey('//Alice');
+ alice = privateKey('//Alice');
});
});
it('Check event from createMultipleItems(): ', async () => {
await usingApi(async (api: ApiPromise) => {
const collectionID = await createCollectionExpectSuccess();
- const args = [{ nft: ['0x31', '0x31'] }, { nft: ['0x32', '0x32'] }, { nft: ['0x33', '0x33'] }];
- const createMultipleItems = api.tx.nft.createMultipleItems(collectionID, normalizeAccountId(Alice.address), args);
- const events = await submitTransactionAsync(Alice, createMultipleItems);
+ const args = [{NFT: ['0x31', '0x31']}, {NFT: ['0x32', '0x32']}, {NFT: ['0x33', '0x33']}];
+ const createMultipleItems = api.tx.nft.createMultipleItems(collectionID, normalizeAccountId(alice.address), args);
+ const events = await submitTransactionAsync(alice, createMultipleItems);
const msg = JSON.stringify(nftEventMessage(events));
expect(msg).to.be.contain(checkSection);
expect(msg).to.be.contain(checkTreasury);
@@ -38,4 +38,3 @@
});
});
});
-
tests/src/check-event/destroyCollectionEvent.test.tsdiffbeforeafterboth--- a/tests/src/check-event/destroyCollectionEvent.test.ts
+++ b/tests/src/check-event/destroyCollectionEvent.test.ts
@@ -4,35 +4,34 @@
//
// https://unique-network.readthedocs.io/en/latest/jsapi.html#setchainlimits
-import { ApiPromise } from '@polkadot/api';
-import { IKeyringPair } from '@polkadot/types/types';
+import {ApiPromise} from '@polkadot/api';
+import {IKeyringPair} from '@polkadot/types/types';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import privateKey from '../substrate/privateKey';
import usingApi, {submitTransactionAsync} from '../substrate/substrate-api';
-import { createCollectionExpectSuccess, nftEventMessage } from '../util/helpers';
+import {createCollectionExpectSuccess, nftEventMessage} from '../util/helpers';
chai.use(chaiAsPromised);
const expect = chai.expect;
describe('Destroy collection event ', () => {
- let Alice: IKeyringPair;
+ let alice: IKeyringPair;
const checkTreasury = 'Deposit';
const checkSystem = 'ExtrinsicSuccess';
before(async () => {
await usingApi(async () => {
- Alice = privateKey('//Alice');
+ alice = privateKey('//Alice');
});
});
it('Check event from destroyCollection(): ', async () => {
await usingApi(async (api: ApiPromise) => {
const collectionID = await createCollectionExpectSuccess();
const destroyCollection = api.tx.nft.destroyCollection(collectionID);
- const events = await submitTransactionAsync(Alice, destroyCollection);
+ const events = await submitTransactionAsync(alice, destroyCollection);
const msg = JSON.stringify(nftEventMessage(events));
expect(msg).to.be.contain(checkTreasury);
expect(msg).to.be.contain(checkSystem);
});
});
});
-
tests/src/check-event/transferEvent.test.tsdiffbeforeafterboth--- a/tests/src/check-event/transferEvent.test.ts
+++ b/tests/src/check-event/transferEvent.test.ts
@@ -4,35 +4,35 @@
//
// https://unique-network.readthedocs.io/en/latest/jsapi.html#setchainlimits
-import { ApiPromise } from '@polkadot/api';
-import { IKeyringPair } from '@polkadot/types/types';
+import {ApiPromise} from '@polkadot/api';
+import {IKeyringPair} from '@polkadot/types/types';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import privateKey from '../substrate/privateKey';
import usingApi, {submitTransactionAsync} from '../substrate/substrate-api';
-import { createCollectionExpectSuccess, createItemExpectSuccess, nftEventMessage, normalizeAccountId } from '../util/helpers';
+import {createCollectionExpectSuccess, createItemExpectSuccess, nftEventMessage, normalizeAccountId} from '../util/helpers';
chai.use(chaiAsPromised);
const expect = chai.expect;
describe('Transfer event ', () => {
- let Alice: IKeyringPair;
- let Bob: IKeyringPair;
+ let alice: IKeyringPair;
+ let bob: IKeyringPair;
const checkSection = 'Transfer';
const checkTreasury = 'Deposit';
const checkSystem = 'ExtrinsicSuccess';
before(async () => {
await usingApi(async () => {
- Alice = privateKey('//Alice');
- Bob = privateKey('//Bob');
+ alice = privateKey('//Alice');
+ bob = privateKey('//Bob');
});
});
it('Check event from transfer(): ', async () => {
await usingApi(async (api: ApiPromise) => {
const collectionID = await createCollectionExpectSuccess();
- const itemID = await createItemExpectSuccess(Alice, collectionID, 'NFT');
- const transfer = api.tx.nft.transfer(normalizeAccountId(Bob.address), collectionID, itemID, 1);
- const events = await submitTransactionAsync(Alice, transfer);
+ const itemID = await createItemExpectSuccess(alice, collectionID, 'NFT');
+ const transfer = api.tx.nft.transfer(normalizeAccountId(bob.address), collectionID, itemID, 1);
+ const events = await submitTransactionAsync(alice, transfer);
const msg = JSON.stringify(nftEventMessage(events));
expect(msg).to.be.contain(checkSection);
expect(msg).to.be.contain(checkTreasury);
@@ -40,5 +40,3 @@
});
});
});
-
-
tests/src/check-event/transferFromEvent.test.tsdiffbeforeafterboth--- a/tests/src/check-event/transferFromEvent.test.ts
+++ b/tests/src/check-event/transferFromEvent.test.ts
@@ -4,35 +4,35 @@
//
// https://unique-network.readthedocs.io/en/latest/jsapi.html#setchainlimits
-import { ApiPromise } from '@polkadot/api';
-import { IKeyringPair } from '@polkadot/types/types';
+import {ApiPromise} from '@polkadot/api';
+import {IKeyringPair} from '@polkadot/types/types';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import privateKey from '../substrate/privateKey';
import usingApi, {submitTransactionAsync} from '../substrate/substrate-api';
-import { createCollectionExpectSuccess, createItemExpectSuccess, nftEventMessage, normalizeAccountId } from '../util/helpers';
+import {createCollectionExpectSuccess, createItemExpectSuccess, nftEventMessage, normalizeAccountId} from '../util/helpers';
chai.use(chaiAsPromised);
const expect = chai.expect;
describe('Transfer from event ', () => {
- let Alice: IKeyringPair;
- let Bob: IKeyringPair;
+ let alice: IKeyringPair;
+ let bob: IKeyringPair;
const checkSection = 'Transfer';
const checkTreasury = 'Deposit';
const checkSystem = 'ExtrinsicSuccess';
before(async () => {
await usingApi(async () => {
- Alice = privateKey('//Alice');
- Bob = privateKey('//Bob');
+ alice = privateKey('//Alice');
+ bob = privateKey('//Bob');
});
});
it('Check event from transferFrom(): ', async () => {
await usingApi(async (api: ApiPromise) => {
const collectionID = await createCollectionExpectSuccess();
- const itemID = await createItemExpectSuccess(Alice, collectionID, 'NFT');
- const transferFrom = api.tx.nft.transferFrom(normalizeAccountId(Alice.address), normalizeAccountId(Bob.address), collectionID, itemID, 1);
- const events = await submitTransactionAsync(Alice, transferFrom);
+ const itemID = await createItemExpectSuccess(alice, collectionID, 'NFT');
+ const transferFrom = api.tx.nft.transferFrom(normalizeAccountId(alice.address), normalizeAccountId(bob.address), collectionID, itemID, 1);
+ const events = await submitTransactionAsync(alice, transferFrom);
const msg = JSON.stringify(nftEventMessage(events));
expect(msg).to.be.contain(checkSection);
expect(msg).to.be.contain(checkTreasury);
@@ -40,4 +40,3 @@
});
});
});
-
tests/src/confirmSponsorship.test.tsdiffbeforeafterboth--- a/tests/src/confirmSponsorship.test.ts
+++ b/tests/src/confirmSponsorship.test.ts
@@ -5,11 +5,11 @@
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
-import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from './substrate/substrate-api';
-import {
- createCollectionExpectSuccess,
- setCollectionSponsorExpectSuccess,
- destroyCollectionExpectSuccess,
+import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';
+import {
+ createCollectionExpectSuccess,
+ setCollectionSponsorExpectSuccess,
+ destroyCollectionExpectSuccess,
confirmSponsorshipExpectSuccess,
confirmSponsorshipExpectFailure,
createItemExpectSuccess,
@@ -21,9 +21,8 @@
normalizeAccountId,
addCollectionAdminExpectSuccess,
} from './util/helpers';
-import { Keyring } from '@polkadot/api';
-import { IKeyringPair } from '@polkadot/types/types';
-import { BigNumber } from 'bignumber.js';
+import {Keyring} from '@polkadot/api';
+import {IKeyringPair} from '@polkadot/types/types';
chai.use(chaiAsPromised);
const expect = chai.expect;
@@ -36,7 +35,7 @@
before(async () => {
await usingApi(async () => {
- const keyring = new Keyring({ type: 'sr25519' });
+ const keyring = new Keyring({type: 'sr25519'});
alice = keyring.addFromUri('//Alice');
bob = keyring.addFromUri('//Bob');
charlie = keyring.addFromUri('//Charlie');
@@ -67,7 +66,7 @@
await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
await usingApi(async (api) => {
- const AsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());
+ const sponsorBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();
// Find unused address
const zeroBalance = await findUnusedAddress(api);
@@ -79,22 +78,22 @@
const zeroToAlice = api.tx.nft.transfer(normalizeAccountId(zeroBalance.address), collectionId, itemId, 0);
const events = await submitTransactionAsync(zeroBalance, zeroToAlice);
const result = getGenericResult(events);
+ expect(result.success).to.be.true;
- const BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());
+ const sponsorBalanceAfter = (await api.query.system.account(bob.address)).data.free.toBigInt();
- expect(result.success).to.be.true;
- expect(BsponsorBalance.lt(AsponsorBalance)).to.be.true;
+ expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;
});
});
it('Fungible: Transfer fees are paid by the sponsor after confirmation', async () => {
- const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0 }});
+ const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
await setCollectionSponsorExpectSuccess(collectionId, bob.address);
await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
await usingApi(async (api) => {
- const AsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());
+ const sponsorBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();
// Find unused address
const zeroBalance = await findUnusedAddress(api);
@@ -106,11 +105,11 @@
const zeroToAlice = api.tx.nft.transfer(normalizeAccountId(zeroBalance.address), collectionId, itemId, 1);
const events1 = await submitTransactionAsync(zeroBalance, zeroToAlice);
const result1 = getGenericResult(events1);
+ expect(result1.success).to.be.true;
- const BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());
+ const sponsorBalanceAfter = (await api.query.system.account(bob.address)).data.free.toBigInt();
- expect(result1.success).to.be.true;
- expect(BsponsorBalance.lt(AsponsorBalance)).to.be.true;
+ expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;
});
});
@@ -120,7 +119,7 @@
await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
await usingApi(async (api) => {
- const AsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());
+ const sponsorBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();
// Find unused address
const zeroBalance = await findUnusedAddress(api);
@@ -133,10 +132,10 @@
const events1 = await submitTransactionAsync(zeroBalance, zeroToAlice);
const result1 = getGenericResult(events1);
- const BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());
+ const sponsorBalanceAfter = (await api.query.system.account(bob.address)).data.free.toBigInt();
expect(result1.success).to.be.true;
- expect(BsponsorBalance.lt(AsponsorBalance)).to.be.true;
+ expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;
});
});
@@ -145,15 +144,15 @@
await setCollectionSponsorExpectSuccess(collectionId, bob.address);
await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
- // Enable collection white list
+ // Enable collection white list
await enableWhiteListExpectSuccess(alice, collectionId);
// Enable public minting
await enablePublicMintingExpectSuccess(alice, collectionId);
- // Create Item
+ // Create Item
await usingApi(async (api) => {
- const AsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());
+ const sponsorBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();
// Find unused address
const zeroBalance = await findUnusedAddress(api);
@@ -164,9 +163,9 @@
// Mint token using unused address as signer
await createItemExpectSuccess(zeroBalance, collectionId, 'NFT', zeroBalance.address);
- const BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());
+ const sponsorBalanceAfter = (await api.query.system.account(bob.address)).data.free.toBigInt();
- expect(BsponsorBalance.lt(AsponsorBalance)).to.be.true;
+ expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;
});
});
@@ -189,13 +188,13 @@
const result1 = getGenericResult(events1);
// Second transfer should fail
- const AsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());
+ const sponsorBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();
const zeroToAlice = api.tx.nft.transfer(normalizeAccountId(alice.address), collectionId, itemId, 0);
- const badTransaction = async function () {
+ const badTransaction = async function () {
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());
+ const sponsorBalanceAfter = (await api.query.system.account(bob.address)).data.free.toBigInt();
// Try again after Zero gets some balance - now it should succeed
const balancetx = api.tx.balances.transfer(zeroBalance.address, 1e15);
@@ -205,12 +204,12 @@
expect(result1.success).to.be.true;
expect(result2.success).to.be.true;
- expect(BsponsorBalance.isEqualTo(AsponsorBalance)).to.be.true;
+ expect(sponsorBalanceAfter).to.be.equal(sponsorBalanceBefore);
});
});
it('Fungible: Sponsoring is rate limited', async () => {
- const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0 }});
+ const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
await setCollectionSponsorExpectSuccess(collectionId, bob.address);
await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
@@ -225,20 +224,20 @@
const zeroToAlice = api.tx.nft.transfer(normalizeAccountId(zeroBalance.address), collectionId, itemId, 1);
const events1 = await submitTransactionAsync(zeroBalance, zeroToAlice);
const result1 = getGenericResult(events1);
+ expect(result1.success).to.be.true;
- const AsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());
+ const sponsorBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();
await expect(submitTransactionExpectFailAsync(zeroBalance, zeroToAlice)).to.be.rejected;
- const BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());
+ const sponsorBalanceAfter = (await api.query.system.account(bob.address)).data.free.toBigInt();
// Try again after Zero gets some balance - now it should succeed
const balancetx = api.tx.balances.transfer(zeroBalance.address, 1e15);
await submitTransactionAsync(alice, balancetx);
const events2 = await submitTransactionAsync(zeroBalance, zeroToAlice);
const result2 = getGenericResult(events2);
-
- expect(result1.success).to.be.true;
expect(result2.success).to.be.true;
- expect(BsponsorBalance.isEqualTo(AsponsorBalance)).to.be.true;
+
+ expect(sponsorBalanceAfter).to.be.equal(sponsorBalanceBefore);
});
});
@@ -259,25 +258,25 @@
const aliceToZero = api.tx.nft.transfer(normalizeAccountId(zeroBalance.address), collectionId, itemId, 1);
const events1 = await submitTransactionAsync(alice, aliceToZero);
const result1 = getGenericResult(events1);
+ expect(result1.success).to.be.true;
// Second transfer should fail
- const AsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());
+ const sponsorBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();
const zeroToAlice = api.tx.nft.transfer(normalizeAccountId(alice.address), collectionId, itemId, 1);
- const badTransaction = async function () {
+ const badTransaction = async function () {
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());
+ const sponsorBalanceAfter = (await api.query.system.account(bob.address)).data.free.toBigInt();
// Try again after Zero gets some balance - now it should succeed
const balancetx = api.tx.balances.transfer(zeroBalance.address, 1e15);
await submitTransactionAsync(alice, balancetx);
const events2 = await submitTransactionAsync(zeroBalance, zeroToAlice);
const result2 = getGenericResult(events2);
+ expect(result2.success).to.be.true;
- expect(result1.success).to.be.true;
- expect(result2.success).to.be.true;
- expect(BsponsorBalance.isEqualTo(AsponsorBalance)).to.be.true;
+ expect(sponsorBalanceAfter).to.be.equal(sponsorBalanceBefore);
});
});
@@ -286,7 +285,7 @@
await setCollectionSponsorExpectSuccess(collectionId, bob.address);
await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
- // Enable collection white list
+ // Enable collection white list
await enableWhiteListExpectSuccess(alice, collectionId);
// Enable public minting
@@ -303,26 +302,20 @@
await createItemExpectSuccess(zeroBalance, collectionId, 'NFT', zeroBalance.address);
// Second mint should fail
- const AsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());
-
- const consoleError = console.error;
- const consoleLog = console.log;
- console.error = () => {};
- console.log = () => {};
- const badTransaction = async function () {
+ const sponsorBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();
+
+ const badTransaction = async function () {
await createItemExpectSuccess(zeroBalance, collectionId, 'NFT', zeroBalance.address);
};
await expect(badTransaction()).to.be.rejectedWith('Inability to pay some fees');
- console.error = consoleError;
- console.log = consoleLog;
- const BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());
+ const sponsorBalanceAfter = (await api.query.system.account(bob.address)).data.free.toBigInt();
// Try again after Zero gets some balance - now it should succeed
const balancetx = api.tx.balances.transfer(zeroBalance.address, 1e15);
await submitTransactionAsync(alice, balancetx);
await createItemExpectSuccess(zeroBalance, collectionId, 'NFT', zeroBalance.address);
- expect(BsponsorBalance.isEqualTo(AsponsorBalance)).to.be.true;
+ expect(sponsorBalanceAfter).to.be.equal(sponsorBalanceBefore);
});
});
@@ -331,7 +324,7 @@
describe('(!negative test!) integration test: ext. confirmSponsorship():', () => {
before(async () => {
await usingApi(async () => {
- const keyring = new Keyring({ type: 'sr25519' });
+ const keyring = new Keyring({type: 'sr25519'});
alice = keyring.addFromUri('//Alice');
bob = keyring.addFromUri('//Bob');
charlie = keyring.addFromUri('//Charlie');
@@ -342,7 +335,7 @@
// Find the collection that never existed
let collectionId = 0;
await usingApi(async (api) => {
- collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;
+ collectionId = (await api.query.common.createdCollectionCount()).toNumber() + 1;
});
await confirmSponsorshipExpectFailure(collectionId, '//Bob');
@@ -369,7 +362,7 @@
it('(!negative test!) Confirm sponsorship by collection admin', async () => {
const collectionId = await createCollectionExpectSuccess();
await setCollectionSponsorExpectSuccess(collectionId, bob.address);
- await addCollectionAdminExpectSuccess(alice, collectionId, charlie);
+ await addCollectionAdminExpectSuccess(alice, collectionId, charlie.address);
await confirmSponsorshipExpectFailure(collectionId, '//Charlie');
});
@@ -377,7 +370,7 @@
const collectionId = await createCollectionExpectSuccess();
await confirmSponsorshipExpectFailure(collectionId, '//Bob');
});
-
+
it('(!negative test!) Confirm sponsorship in a collection that was destroyed', async () => {
const collectionId = await createCollectionExpectSuccess();
await destroyCollectionExpectSuccess(collectionId);
tests/src/connection.test.tsdiffbeforeafterboth--- a/tests/src/connection.test.ts
+++ b/tests/src/connection.test.ts
@@ -4,7 +4,7 @@
//
import usingApi from './substrate/substrate-api';
-import { WsProvider } from '@polkadot/api';
+import {WsProvider} from '@polkadot/api';
import * as chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
@@ -21,19 +21,11 @@
});
it('Cannot connect to 255.255.255.255', async () => {
- const log = console.log;
- const error = console.error;
- console.log = function () {};
- console.error = function () {};
-
const neverConnectProvider = new WsProvider('ws://255.255.255.255:9944');
await expect((async () => {
await usingApi(async api => {
await api.rpc.system.health();
- }, { provider: neverConnectProvider });
+ }, {provider: neverConnectProvider});
})()).to.be.eventually.rejected;
-
- 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
@@ -5,9 +5,9 @@
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
-import usingApi, { submitTransactionAsync } from './substrate/substrate-api';
+import usingApi, {submitTransactionAsync} from './substrate/substrate-api';
import fs from 'fs';
-import { Abi, ContractPromise as Contract } from '@polkadot/api-contract';
+import {Abi, ContractPromise as Contract} from '@polkadot/api-contract';
import privateKey from './substrate/privateKey';
import {
deployFlipper,
@@ -26,6 +26,7 @@
normalizeAccountId,
isWhitelisted,
transferFromExpectSuccess,
+ getTokenOwner,
} from './util/helpers';
@@ -75,18 +76,15 @@
const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, contract.address);
await submitTransactionAsync(alice, changeAdminTx);
- const tokenBefore: any = (await api.query.nft.nftItemList(collectionId, tokenId) as any).toJSON();
+ expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal(normalizeAccountId(alice.address));
// 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) as any).toJSON();
-
- // tslint:disable-next-line:no-unused-expression
expect(result.success).to.be.true;
- expect(tokenBefore.owner).to.be.deep.equal(normalizeAccountId(alice.address));
- expect(tokenAfter.owner).to.be.deep.equal(normalizeAccountId(bob.address));
+
+ expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal(normalizeAccountId(bob.address));
});
});
@@ -102,17 +100,17 @@
await addToWhiteListExpectSuccess(alice, collectionId, contract.address);
await addToWhiteListExpectSuccess(alice, collectionId, bob.address);
- const transferTx = contract.tx.createItem(value, gasLimit, bob.address, collectionId, { Nft: {const_data: '0x010203', variable_data: '0x020304' }});
+ const transferTx = contract.tx.createItem(value, gasLimit, bob.address, collectionId, {Nft: {const_data: '0x010203', variable_data: '0x020304'}});
const events = await submitTransactionAsync(alice, transferTx);
const result = getGenericResult(events);
expect(result.success).to.be.true;
- const tokensAfter: any = (await api.query.nft.nftItemList.entries(collectionId) as any).map((kv: any) => kv[1].toJSON());
+ const tokensAfter = (await api.query.nft.nftItemList.entries(collectionId)).map((kv: any) => kv[1].toJSON());
expect(tokensAfter).to.be.deep.equal([
{
- Owner: bob.address,
- ConstData: '0x010203',
- VariableData: '0x020304',
+ owner: bob.address,
+ constData: '0x010203',
+ variableData: '0x020304',
},
]);
});
@@ -131,9 +129,9 @@
await addToWhiteListExpectSuccess(alice, collectionId, bob.address);
const transferTx = contract.tx.createMultipleItems(value, gasLimit, bob.address, collectionId, [
- { Nft: { const_data: '0x010203', variable_data: '0x020304' } },
- { Nft: { const_data: '0x010204', variable_data: '0x020305' } },
- { Nft: { const_data: '0x010205', variable_data: '0x020306' } },
+ {Nft: {const_data: '0x010203', variable_data: '0x020304'}},
+ {Nft: {const_data: '0x010204', variable_data: '0x020305'}},
+ {Nft: {const_data: '0x010205', variable_data: '0x020306'}},
]);
const events = await submitTransactionAsync(alice, transferTx);
const result = getGenericResult(events);
tests/src/createCollection.test.tsdiffbeforeafterboth--- a/tests/src/createCollection.test.ts
+++ b/tests/src/createCollection.test.ts
@@ -5,11 +5,9 @@
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
-import { default as usingApi } from './substrate/substrate-api';
-import { createCollectionExpectFailure, createCollectionExpectSuccess } from './util/helpers';
+import {createCollectionExpectFailure, createCollectionExpectSuccess} from './util/helpers';
chai.use(chaiAsPromised);
-const expect = chai.expect;
describe('integration test: ext. createCollection():', () => {
it('Create new NFT collection', async () => {
@@ -34,10 +32,10 @@
describe('(!negative test!) integration test: ext. createCollection():', () => {
it('(!negative test!) create new NFT collection whith incorrect data (collection_name)', async () => {
- await createCollectionExpectFailure({ name: 'A'.repeat(65), mode: {type: 'NFT'}});
+ await createCollectionExpectFailure({name: 'A'.repeat(65), mode: {type: 'NFT'}});
});
it('(!negative test!) create new NFT collection whith incorrect data (collection_description)', async () => {
- await createCollectionExpectFailure({ description: 'A'.repeat(257), mode: { type: 'NFT' }});
+ await createCollectionExpectFailure({description: 'A'.repeat(257), mode: {type: 'NFT'}});
});
it('(!negative test!) create new NFT collection whith incorrect data (token_prefix)', async () => {
await createCollectionExpectFailure({tokenPrefix: 'A'.repeat(17), mode: {type: 'NFT'}});
tests/src/createItem.test.tsdiffbeforeafterboth--- a/tests/src/createItem.test.ts
+++ b/tests/src/createItem.test.ts
@@ -3,12 +3,12 @@
// file 'LICENSE', which is part of this source code package.
//
-import { default as usingApi } from './substrate/substrate-api';
+import {default as usingApi} from './substrate/substrate-api';
import chai from 'chai';
-import { Keyring } from '@polkadot/api';
-import { IKeyringPair } from '@polkadot/types/types';
-import {
- createCollectionExpectSuccess,
+import {Keyring} from '@polkadot/api';
+import {IKeyringPair} from '@polkadot/types/types';
+import {
+ createCollectionExpectSuccess,
createItemExpectSuccess,
addCollectionAdminExpectSuccess,
} from './util/helpers';
@@ -20,7 +20,7 @@
describe('integration test: ext. createItem():', () => {
before(async () => {
await usingApi(async () => {
- const keyring = new Keyring({ type: 'sr25519' });
+ const keyring = new Keyring({type: 'sr25519'});
alice = keyring.addFromUri('//Alice');
bob = keyring.addFromUri('//Bob');
});
@@ -44,19 +44,19 @@
it('Create new item in NFT collection with collection admin permissions', async () => {
const createMode = 'NFT';
const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});
- await addCollectionAdminExpectSuccess(alice, newCollectionID, bob);
+ await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);
await createItemExpectSuccess(bob, newCollectionID, createMode);
});
it('Create new item in Fungible collection with collection admin permissions', async () => {
const createMode = 'Fungible';
const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});
- await addCollectionAdminExpectSuccess(alice, newCollectionID, bob);
+ await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);
await createItemExpectSuccess(bob, newCollectionID, createMode);
});
it('Create new item in ReFungible collection with collection admin permissions', async () => {
const createMode = 'ReFungible';
const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});
- await addCollectionAdminExpectSuccess(alice, newCollectionID, bob);
+ await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);
await createItemExpectSuccess(bob, newCollectionID, createMode);
});
});
@@ -64,7 +64,7 @@
describe('Negative integration test: ext. createItem():', () => {
before(async () => {
await usingApi(async () => {
- const keyring = new Keyring({ type: 'sr25519' });
+ const keyring = new Keyring({type: 'sr25519'});
alice = keyring.addFromUri('//Alice');
bob = keyring.addFromUri('//Bob');
});
tests/src/createMultipleItems.test.tsdiffbeforeafterboth--- a/tests/src/createMultipleItems.test.ts
+++ b/tests/src/createMultipleItems.test.ts
@@ -2,120 +2,105 @@
// This file is subject to the terms and conditions defined in
// file 'LICENSE', which is part of this source code package.
//
-import { ApiPromise } from '@polkadot/api';
-import { IKeyringPair } from '@polkadot/types/types';
-import BN from 'bn.js';
+import {ApiPromise} from '@polkadot/api';
+import {IKeyringPair} from '@polkadot/types/types';
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 {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';
import {
createCollectionExpectSuccess,
destroyCollectionExpectSuccess,
getGenericResult,
- IFungibleTokenDataType,
- IReFungibleTokenDataType,
normalizeAccountId,
setCollectionLimitsExpectSuccess,
addCollectionAdminExpectSuccess,
+ getBalance,
+ getTokenOwner,
+ getLastTokenId,
+ getVariableMetadata,
+ getConstMetadata,
} from './util/helpers';
chai.use(chaiAsPromised);
const expect = chai.expect;
-interface ITokenDataType {
- owner: number[];
- constData: number[];
- variableData: number[];
-}
-
describe('Integration Test createMultipleItems(collection_id, owner, items_data):', () => {
it('Create 0x31, 0x32, 0x33 items in active NFT collection and verify tokens data in chain', async () => {
await usingApi(async (api: ApiPromise) => {
const collectionId = await createCollectionExpectSuccess();
- const itemsListIndexBefore = await api.query.nft.itemListIndex(collectionId) as unknown as BN;
- expect(itemsListIndexBefore.toNumber()).to.be.equal(0);
- const Alice = privateKey('//Alice');
- const args = [{ nft: ['0x31', '0x31'] }, { nft: ['0x32', '0x32'] }, { nft: ['0x33', '0x33'] }];
+ const itemsListIndexBefore = await getLastTokenId(api, collectionId);
+ expect(itemsListIndexBefore).to.be.equal(0);
+ const alice = privateKey('//Alice');
+ const args = [{NFT: ['0x31', '0x31']}, {NFT: ['0x32', '0x32']}, {NFT: ['0x33', '0x33']}];
const createMultipleItemsTx = api.tx.nft
- .createMultipleItems(collectionId, normalizeAccountId(Alice.address), args);
- 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)).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;
+ .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);
+ await submitTransactionAsync(alice, createMultipleItemsTx);
+ const itemsListIndexAfter = await getLastTokenId(api, collectionId);
+ expect(itemsListIndexAfter).to.be.equal(3);
- expect(token1Data.owner).to.be.deep.equal(normalizeAccountId(Alice.address));
- expect(token2Data.owner).to.be.deep.equal(normalizeAccountId(Alice.address));
- expect(token3Data.owner).to.be.deep.equal(normalizeAccountId(Alice.address));
+ expect(await getTokenOwner(api, collectionId, 1)).to.be.deep.equal(normalizeAccountId(alice.address));
+ expect(await getTokenOwner(api, collectionId, 2)).to.be.deep.equal(normalizeAccountId(alice.address));
+ expect(await getTokenOwner(api, collectionId, 3)).to.be.deep.equal(normalizeAccountId(alice.address));
- expect(token1Data.constData.toString()).to.be.equal('0x31');
- expect(token2Data.constData.toString()).to.be.equal('0x32');
- expect(token3Data.constData.toString()).to.be.equal('0x33');
+ expect(await getConstMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);
+ expect(await getConstMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);
+ expect(await getConstMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);
- expect(token1Data.variableData.toString()).to.be.equal('0x31');
- expect(token2Data.variableData.toString()).to.be.equal('0x32');
- expect(token3Data.variableData.toString()).to.be.equal('0x33');
+ expect(await getVariableMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);
+ expect(await getVariableMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);
+ expect(await getVariableMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);
});
});
it('Create 0x01, 0x02, 0x03 items in active Fungible collection and verify tokens data in chain', async () => {
await usingApi(async (api: ApiPromise) => {
const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
- const itemsListIndexBefore = await api.query.nft.itemListIndex(collectionId) as unknown as BN;
- expect(itemsListIndexBefore.toNumber()).to.be.equal(0);
- const Alice = privateKey('//Alice');
+ const itemsListIndexBefore = await getLastTokenId(api, collectionId);
+ expect(itemsListIndexBefore).to.be.equal(0);
+ const alice = privateKey('//Alice');
const args = [
- {fungible: { value: 1 }},
- {fungible: { value: 2 }},
- {fungible: { value: 3 }},
+ {Fungible: {value: 1}},
+ {Fungible: {value: 2}},
+ {Fungible: {value: 3}},
];
const createMultipleItemsTx = api.tx.nft
- .createMultipleItems(collectionId, normalizeAccountId(Alice.address), args);
- await submitTransactionAsync(Alice, createMultipleItemsTx);
- const token1Data = (await api.query.nft.fungibleItemList(collectionId, Alice.address) as any).toJSON() as unknown as IFungibleTokenDataType;
+ .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);
+ await submitTransactionAsync(alice, createMultipleItemsTx);
+ const token1Data = await getBalance(api, collectionId, alice.address, 0);
- expect(token1Data.value).to.be.equal(6); // 1 + 2 + 3
+ expect(token1Data).to.be.equal(6n); // 1 + 2 + 3
});
});
it('Create 0x31, 0x32, 0x33 items in active ReFungible collection and verify tokens data in chain', async () => {
await usingApi(async (api: ApiPromise) => {
const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
- const itemsListIndexBefore = await api.query.nft.itemListIndex(collectionId) as unknown as BN;
- expect(itemsListIndexBefore.toNumber()).to.be.equal(0);
- const Alice = privateKey('//Alice');
+ const itemsListIndexBefore = await getLastTokenId(api, collectionId);
+ expect(itemsListIndexBefore).to.be.equal(0);
+ const alice = privateKey('//Alice');
const args = [
- {refungible: {const_data: [0x31], variable_data: [0x31], pieces: 1}},
- {refungible: {const_data: [0x32], variable_data: [0x32], pieces: 1}},
- {refungible: {const_data: [0x33], variable_data: [0x33], pieces: 1}},
+ {ReFungible: {const_data: [0x31], variable_data: [0x31], pieces: 1}},
+ {ReFungible: {const_data: [0x32], variable_data: [0x32], pieces: 1}},
+ {ReFungible: {const_data: [0x33], variable_data: [0x33], pieces: 1}},
];
const createMultipleItemsTx = api.tx.nft
- .createMultipleItems(collectionId, normalizeAccountId(Alice.address), args);
- 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 any).toJSON() as unknown as IReFungibleTokenDataType;
- const token2Data = (await api.query.nft.reFungibleItemList(collectionId, 2) as any).toJSON() as unknown as IReFungibleTokenDataType;
- const token3Data = (await api.query.nft.reFungibleItemList(collectionId, 3) as any).toJSON() as unknown as IReFungibleTokenDataType;
+ .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);
+ await submitTransactionAsync(alice, createMultipleItemsTx);
+ const itemsListIndexAfter = await getLastTokenId(api, collectionId);
+ expect(itemsListIndexAfter).to.be.equal(3);
- expect(token1Data.owner[0].owner).to.be.deep.equal(normalizeAccountId(Alice.address));
- expect(token1Data.owner[0].fraction).to.be.equal(1);
+ expect(await getBalance(api, collectionId, alice.address, 1)).to.be.equal(1n);
+ expect(await getBalance(api, collectionId, alice.address, 2)).to.be.equal(1n);
+ expect(await getBalance(api, collectionId, alice.address, 3)).to.be.equal(1n);
- expect(token2Data.owner[0].owner).to.be.deep.equal(normalizeAccountId(Alice.address));
- expect(token2Data.owner[0].fraction).to.be.equal(1);
+ expect(await getConstMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);
+ expect(await getConstMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);
+ expect(await getConstMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);
- expect(token3Data.owner[0].owner).to.be.deep.equal(normalizeAccountId(Alice.address));
- expect(token3Data.owner[0].fraction).to.be.equal(1);
-
- expect(token1Data.constData.toString()).to.be.equal('0x31');
- expect(token2Data.constData.toString()).to.be.equal('0x32');
- expect(token3Data.constData.toString()).to.be.equal('0x33');
-
- expect(token1Data.variableData.toString()).to.be.equal('0x31');
- expect(token2Data.variableData.toString()).to.be.equal('0x32');
- expect(token3Data.variableData.toString()).to.be.equal('0x33');
+ expect(await getVariableMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);
+ expect(await getVariableMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);
+ expect(await getVariableMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);
});
});
@@ -128,8 +113,8 @@
tokenLimit: 2,
});
const args = [
- { nft: ['A', 'A'] },
- { nft: ['B', 'B'] },
+ {NFT: ['A', 'A']},
+ {NFT: ['B', 'B']},
];
const createMultipleItemsTx = api.tx.nft.createMultipleItems(collectionId, normalizeAccountId(alice.address), args);
const events = await submitTransactionAsync(alice, createMultipleItemsTx);
@@ -141,183 +126,157 @@
describe('Integration Test createMultipleItems(collection_id, owner, items_data) with collection admin permissions:', () => {
- let Alice: IKeyringPair;
- let Bob: IKeyringPair;
+ let alice: IKeyringPair;
+ let bob: IKeyringPair;
before(async () => {
await usingApi(async () => {
- Alice = privateKey('//Alice');
- Bob = privateKey('//Bob');
+ alice = privateKey('//Alice');
+ bob = privateKey('//Bob');
});
});
it('Create 0x31, 0x32, 0x33 items in active NFT collection and verify tokens data in chain', async () => {
await usingApi(async (api: ApiPromise) => {
const collectionId = await createCollectionExpectSuccess();
- const itemsListIndexBefore = await api.query.nft.itemListIndex(collectionId) as unknown as BN;
- expect(itemsListIndexBefore.toNumber()).to.be.equal(0);
- await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);
- const args = [{ nft: ['0x31', '0x31'] }, { nft: ['0x32', '0x32'] }, { nft: ['0x33', '0x33'] }];
+ const itemsListIndexBefore = await getLastTokenId(api, collectionId);
+ expect(itemsListIndexBefore).to.be.equal(0);
+ await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
+ const args = [{NFT: ['0x31', '0x31']}, {NFT: ['0x32', '0x32']}, {NFT: ['0x33', '0x33']}];
const createMultipleItemsTx = api.tx.nft
- .createMultipleItems(collectionId, normalizeAccountId(Bob.address), args);
- await submitTransactionAsync(Bob, 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)).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;
+ .createMultipleItems(collectionId, normalizeAccountId(bob.address), args);
+ await submitTransactionAsync(bob, createMultipleItemsTx);
+ const itemsListIndexAfter = await getLastTokenId(api, collectionId);
+ expect(itemsListIndexAfter).to.be.equal(3);
- expect(token1Data.owner).to.be.deep.equal(normalizeAccountId(Bob.address));
- expect(token2Data.owner).to.be.deep.equal(normalizeAccountId(Bob.address));
- expect(token3Data.owner).to.be.deep.equal(normalizeAccountId(Bob.address));
+ expect(await getTokenOwner(api, collectionId, 1)).to.be.deep.equal(normalizeAccountId(bob.address));
+ expect(await getTokenOwner(api, collectionId, 2)).to.be.deep.equal(normalizeAccountId(bob.address));
+ expect(await getTokenOwner(api, collectionId, 3)).to.be.deep.equal(normalizeAccountId(bob.address));
- expect(token1Data.constData.toString()).to.be.equal('0x31');
- expect(token2Data.constData.toString()).to.be.equal('0x32');
- expect(token3Data.constData.toString()).to.be.equal('0x33');
+ expect(await getConstMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);
+ expect(await getConstMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);
+ expect(await getConstMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);
- expect(token1Data.variableData.toString()).to.be.equal('0x31');
- expect(token2Data.variableData.toString()).to.be.equal('0x32');
- expect(token3Data.variableData.toString()).to.be.equal('0x33');
+ expect(await getVariableMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);
+ expect(await getVariableMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);
+ expect(await getVariableMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);
});
});
it('Create 0x01, 0x02, 0x03 items in active Fungible collection and verify tokens data in chain', async () => {
await usingApi(async (api: ApiPromise) => {
const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
- const itemsListIndexBefore = await api.query.nft.itemListIndex(collectionId) as unknown as BN;
- expect(itemsListIndexBefore.toNumber()).to.be.equal(0);
- await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);
+ const itemsListIndexBefore = await getLastTokenId(api, collectionId);
+ expect(itemsListIndexBefore).to.be.equal(0);
+ await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
const args = [
- {fungible: { value: 1 }},
- {fungible: { value: 2 }},
- {fungible: { value: 3 }},
+ {Fungible: {value: 1}},
+ {Fungible: {value: 2}},
+ {Fungible: {value: 3}},
];
const createMultipleItemsTx = api.tx.nft
- .createMultipleItems(collectionId, normalizeAccountId(Bob.address), args);
- await submitTransactionAsync(Bob, createMultipleItemsTx);
- const token1Data = (await api.query.nft.fungibleItemList(collectionId, Bob.address) as any).toJSON() as unknown as IFungibleTokenDataType;
+ .createMultipleItems(collectionId, normalizeAccountId(bob.address), args);
+ await submitTransactionAsync(bob, createMultipleItemsTx);
+ const token1Data = await getBalance(api, collectionId, bob.address, 0);
- expect(token1Data.value).to.be.equal(6); // 1 + 2 + 3
+ expect(token1Data).to.be.equal(6n); // 1 + 2 + 3
});
});
it('Create 0x31, 0x32, 0x33 items in active ReFungible collection and verify tokens data in chain', async () => {
await usingApi(async (api: ApiPromise) => {
const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
- const itemsListIndexBefore = await api.query.nft.itemListIndex(collectionId) as unknown as BN;
- expect(itemsListIndexBefore.toNumber()).to.be.equal(0);
- await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);
+ const itemsListIndexBefore = await getLastTokenId(api, collectionId);
+ expect(itemsListIndexBefore).to.be.equal(0);
+ await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
const args = [
- {refungible: {const_data: [0x31], variable_data: [0x31], pieces: 1}},
- {refungible: {const_data: [0x32], variable_data: [0x32], pieces: 1}},
- {refungible: {const_data: [0x33], variable_data: [0x33], pieces: 1}},
+ {ReFungible: {const_data: [0x31], variable_data: [0x31], pieces: 1}},
+ {ReFungible: {const_data: [0x32], variable_data: [0x32], pieces: 1}},
+ {ReFungible: {const_data: [0x33], variable_data: [0x33], pieces: 1}},
];
const createMultipleItemsTx = api.tx.nft
- .createMultipleItems(collectionId, normalizeAccountId(Bob.address), args);
- await submitTransactionAsync(Bob, 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 any).toJSON() as unknown as IReFungibleTokenDataType;
- const token2Data = (await api.query.nft.reFungibleItemList(collectionId, 2) as any).toJSON() as unknown as IReFungibleTokenDataType;
- const token3Data = (await api.query.nft.reFungibleItemList(collectionId, 3) as any).toJSON() as unknown as IReFungibleTokenDataType;
+ .createMultipleItems(collectionId, normalizeAccountId(bob.address), args);
+ await submitTransactionAsync(bob, createMultipleItemsTx);
+ const itemsListIndexAfter = await getLastTokenId(api, collectionId);
+ expect(itemsListIndexAfter).to.be.equal(3);
- expect(token1Data.owner[0].owner).to.be.deep.equal(normalizeAccountId(Bob.address));
- expect(token1Data.owner[0].fraction).to.be.equal(1);
+ expect(await getBalance(api, collectionId, bob.address, 1)).to.be.equal(1n);
+ expect(await getBalance(api, collectionId, bob.address, 2)).to.be.equal(1n);
+ expect(await getBalance(api, collectionId, bob.address, 3)).to.be.equal(1n);
- expect(token2Data.owner[0].owner).to.be.deep.equal(normalizeAccountId(Bob.address));
- expect(token2Data.owner[0].fraction).to.be.equal(1);
-
- expect(token3Data.owner[0].owner).to.be.deep.equal(normalizeAccountId(Bob.address));
- expect(token3Data.owner[0].fraction).to.be.equal(1);
+ expect(await getConstMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);
+ expect(await getConstMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);
+ expect(await getConstMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);
- expect(token1Data.constData.toString()).to.be.equal('0x31');
- expect(token2Data.constData.toString()).to.be.equal('0x32');
- expect(token3Data.constData.toString()).to.be.equal('0x33');
-
- expect(token1Data.variableData.toString()).to.be.equal('0x31');
- expect(token2Data.variableData.toString()).to.be.equal('0x32');
- expect(token3Data.variableData.toString()).to.be.equal('0x33');
+ expect(await getVariableMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);
+ expect(await getVariableMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);
+ expect(await getVariableMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);
});
});
});
describe('Negative Integration Test createMultipleItems(collection_id, owner, items_data):', () => {
- let Alice: IKeyringPair;
- let Bob: IKeyringPair;
+ let alice: IKeyringPair;
+ let bob: IKeyringPair;
before(async () => {
await usingApi(async () => {
- Alice = privateKey('//Alice');
- Bob = privateKey('//Bob');
+ alice = privateKey('//Alice');
+ bob = privateKey('//Bob');
});
});
it('Regular user cannot create items in active NFT collection', async () => {
await usingApi(async (api: ApiPromise) => {
const collectionId = await createCollectionExpectSuccess();
- const itemsListIndexBefore = await api.query.nft.itemListIndex(collectionId) as unknown as BN;
- expect(itemsListIndexBefore.toNumber()).to.be.equal(0);
- const args = [{ nft: ['0x31', '0x31'] }, { nft: ['0x32', '0x32'] }, { nft: ['0x33', '0x33'] }];
+ const itemsListIndexBefore = await getLastTokenId(api, collectionId);
+ expect(itemsListIndexBefore).to.be.equal(0);
+ const args = [{NFT: ['0x31', '0x31']}, {NFT: ['0x32', '0x32']}, {NFT: ['0x33', '0x33']}];
const createMultipleItemsTx = api.tx.nft
- .createMultipleItems(collectionId, normalizeAccountId(Alice.address), args);
- await expect(submitTransactionAsync(Bob, createMultipleItemsTx)).to.be.rejected;
+ .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);
+ await expect(submitTransactionAsync(bob, createMultipleItemsTx)).to.be.rejected;
});
});
it('Regular user cannot create items in active Fungible collection', async () => {
await usingApi(async (api: ApiPromise) => {
const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
- const itemsListIndexBefore = await api.query.nft.itemListIndex(collectionId) as unknown as BN;
- expect(itemsListIndexBefore.toNumber()).to.be.equal(0);
+ const itemsListIndexBefore = await getLastTokenId(api, collectionId);
+ expect(itemsListIndexBefore).to.be.equal(0);
const args = [
- {fungible: { value: 1 }},
- {fungible: { value: 2 }},
- {fungible: { value: 3 }},
+ {Fungible: {value: 1}},
+ {Fungible: {value: 2}},
+ {Fungible: {value: 3}},
];
const createMultipleItemsTx = api.tx.nft
- .createMultipleItems(collectionId, normalizeAccountId(Alice.address), args);
- await expect(submitTransactionAsync(Bob, createMultipleItemsTx)).to.be.rejected;
+ .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);
+ await expect(submitTransactionAsync(bob, createMultipleItemsTx)).to.be.rejected;
});
});
it('Regular user cannot create items in active ReFungible collection', async () => {
await usingApi(async (api: ApiPromise) => {
const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
- const itemsListIndexBefore = await api.query.nft.itemListIndex(collectionId) as unknown as BN;
- expect(itemsListIndexBefore.toNumber()).to.be.equal(0);
+ const itemsListIndexBefore = await getLastTokenId(api, collectionId);
+ expect(itemsListIndexBefore).to.be.equal(0);
const args = [
- {refungible: {const_data: [0x31], variable_data: [0x31], pieces: 1}},
- {refungible: {const_data: [0x32], variable_data: [0x32], pieces: 1}},
- {refungible: {const_data: [0x33], variable_data: [0x33], pieces: 1}},
+ {ReFungible: {const_data: [0x31], variable_data: [0x31], pieces: 1}},
+ {ReFungible: {const_data: [0x32], variable_data: [0x32], pieces: 1}},
+ {ReFungible: {const_data: [0x33], variable_data: [0x33], pieces: 1}},
];
const createMultipleItemsTx = api.tx.nft
- .createMultipleItems(collectionId, normalizeAccountId(Alice.address), args);
- await expect(submitTransactionAsync(Bob, createMultipleItemsTx)).to.be.rejected;
- });
- });
-
- it('Create token with not existing type', async () => {
- await usingApi(async (api: ApiPromise) => {
- const collectionId = await createCollectionExpectSuccess();
- try {
- const args = [{ invalid: null }, { invalid: null }, { invalid: null }];
- const createMultipleItemsTx = await api.tx.nft
- .createMultipleItems(collectionId, normalizeAccountId(Alice.address), args);
- await expect(submitTransactionExpectFailAsync(Alice, createMultipleItemsTx)).to.be.rejected;
- } catch (e) {
- // tslint:disable-next-line:no-unused-expression
- expect(e).to.be.exist;
- }
+ .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);
+ await expect(submitTransactionAsync(bob, createMultipleItemsTx)).to.be.rejected;
});
});
it('Create token in not existing collection', async () => {
await usingApi(async (api: ApiPromise) => {
- const collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;
+ const collectionId = (await api.query.common.createdCollectionCount()).toNumber() + 1;
const createMultipleItemsTx = api.tx.nft
- .createMultipleItems(collectionId, normalizeAccountId(Alice.address), ['NFT', 'NFT', 'NFT']);
- await expect(submitTransactionExpectFailAsync(Alice, createMultipleItemsTx)).to.be.rejected;
+ .createMultipleItems(collectionId, normalizeAccountId(alice.address), ['NFT', 'NFT', 'NFT']);
+ await expect(submitTransactionExpectFailAsync(alice, createMultipleItemsTx)).to.be.rejected;
});
});
@@ -325,27 +284,27 @@
await usingApi(async (api: ApiPromise) => {
// NFT
const collectionId = await createCollectionExpectSuccess();
- const Alice = privateKey('//Alice');
+ const alice = privateKey('//Alice');
const args = [
- { nft: ['A'.repeat(2049), 'A'.repeat(2049)] },
- { nft: ['B'.repeat(2049), 'B'.repeat(2049)] },
- { nft: ['C'.repeat(2049), 'C'.repeat(2049)] },
+ {NFT: ['A'.repeat(2049), 'A'.repeat(2049)]},
+ {NFT: ['B'.repeat(2049), 'B'.repeat(2049)]},
+ {NFT: ['C'.repeat(2049), 'C'.repeat(2049)]},
];
const createMultipleItemsTx = api.tx.nft
- .createMultipleItems(collectionId, normalizeAccountId(Alice.address), args);
- await expect(submitTransactionExpectFailAsync(Alice, createMultipleItemsTx)).to.be.rejected;
+ .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);
+ await expect(submitTransactionExpectFailAsync(alice, createMultipleItemsTx)).to.be.rejected;
// ReFungible
const collectionIdReFungible =
await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
const argsReFungible = [
- { ReFungible: ['1'.repeat(2049), '1'.repeat(2049), 10] },
- { ReFungible: ['2'.repeat(2049), '2'.repeat(2049), 10] },
- { ReFungible: ['3'.repeat(2049), '3'.repeat(2049), 10] },
+ {ReFungible: ['1'.repeat(2049), '1'.repeat(2049), 10]},
+ {ReFungible: ['2'.repeat(2049), '2'.repeat(2049), 10]},
+ {ReFungible: ['3'.repeat(2049), '3'.repeat(2049), 10]},
];
const createMultipleItemsTxFungible = api.tx.nft
- .createMultipleItems(collectionIdReFungible, normalizeAccountId(Alice.address), argsReFungible);
- await expect(submitTransactionExpectFailAsync(Alice, createMultipleItemsTxFungible)).to.be.rejected;
+ .createMultipleItems(collectionIdReFungible, normalizeAccountId(alice.address), argsReFungible);
+ await expect(submitTransactionExpectFailAsync(alice, createMultipleItemsTxFungible)).to.be.rejected;
});
});
@@ -353,8 +312,8 @@
await usingApi(async (api: ApiPromise) => {
const collectionId = await createCollectionExpectSuccess();
const createMultipleItemsTx = api.tx.nft
- .createMultipleItems(collectionId, normalizeAccountId(Alice.address), ['NFT', 'Fungible', 'ReFungible']);
- await expect(submitTransactionExpectFailAsync(Alice, createMultipleItemsTx)).to.be.rejected;
+ .createMultipleItems(collectionId, normalizeAccountId(alice.address), ['NFT', 'Fungible', 'ReFungible']);
+ await expect(submitTransactionExpectFailAsync(alice, createMultipleItemsTx)).to.be.rejected;
// garbage collection :-D
await destroyCollectionExpectSuccess(collectionId);
});
@@ -364,13 +323,13 @@
await usingApi(async (api: ApiPromise) => {
const collectionId = await createCollectionExpectSuccess();
const args = [
- { nft: ['A', 'A'] },
- { nft: ['B', 'B'.repeat(2049)] },
- { nft: ['C'.repeat(2049), 'C'] },
+ {NFT: ['A', 'A']},
+ {NFT: ['B', 'B'.repeat(2049)]},
+ {NFT: ['C'.repeat(2049), 'C']},
];
const createMultipleItemsTx = await api.tx.nft
- .createMultipleItems(collectionId, normalizeAccountId(Alice.address), args);
- await expect(submitTransactionExpectFailAsync(Alice, createMultipleItemsTx)).to.be.rejected;
+ .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);
+ await expect(submitTransactionExpectFailAsync(alice, createMultipleItemsTx)).to.be.rejected;
});
});
@@ -378,15 +337,15 @@
await usingApi(async (api) => {
const collectionId = await createCollectionExpectSuccess();
- await setCollectionLimitsExpectSuccess(Alice, collectionId, {
+ await setCollectionLimitsExpectSuccess(alice, collectionId, {
tokenLimit: 1,
});
const args = [
- { nft: ['A', 'A'] },
- { nft: ['B', 'B'] },
+ {NFT: ['A', 'A']},
+ {NFT: ['B', 'B']},
];
- const createMultipleItemsTx = api.tx.nft.createMultipleItems(collectionId, normalizeAccountId(Alice.address), args);
- await expect(submitTransactionExpectFailAsync(Alice, createMultipleItemsTx)).to.be.rejected;
+ const createMultipleItemsTx = api.tx.nft.createMultipleItems(collectionId, normalizeAccountId(alice.address), args);
+ await expect(submitTransactionExpectFailAsync(alice, createMultipleItemsTx)).to.be.rejected;
});
});
});
tests/src/creditFeesToTreasury.test.tsdiffbeforeafterboth--- a/tests/src/creditFeesToTreasury.test.ts
+++ b/tests/src/creditFeesToTreasury.test.ts
@@ -5,25 +5,24 @@
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
-import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from './substrate/substrate-api';
-import { alicesPublicKey, bobsPublicKey } from './accounts';
+import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';
+import {alicesPublicKey, bobsPublicKey} from './accounts';
import privateKey from './substrate/privateKey';
-import { BigNumber } from 'bignumber.js';
-import { IKeyringPair } from '@polkadot/types/types';
-import {
- createCollectionExpectSuccess,
+import {IKeyringPair} from '@polkadot/types/types';
+import {
+ createCollectionExpectSuccess,
createItemExpectSuccess,
getGenericResult,
transferExpectSuccess,
} from './util/helpers';
-import { default as waitNewBlocks } from './substrate/wait-new-blocks';
-import { ApiPromise } from '@polkadot/api';
+import {default as waitNewBlocks} from './substrate/wait-new-blocks';
+import {ApiPromise} from '@polkadot/api';
chai.use(chaiAsPromised);
const expect = chai.expect;
-const Treasury = '5EYCAe5ijiYfyeZ2JJCGq56LmPyNRAKzpG4QkoQkkQNB5e6Z';
+const TREASURY = '5EYCAe5ijiYfyeZ2JJCGq56LmPyNRAKzpG4QkoQkkQNB5e6Z';
const saneMinimumFee = 0.05;
const saneMaximumFee = 0.5;
const createCollectionDeposit = 100;
@@ -31,14 +30,14 @@
let alice: IKeyringPair;
let bob: IKeyringPair;
-// Skip the inflation block pauses if the block is close to inflation block
+// Skip the inflation block pauses if the block is close to inflation block
// until the inflation happens
/*eslint no-async-promise-executor: "off"*/
function skipInflationBlock(api: ApiPromise): Promise<void> {
const promise = new Promise<void>(async (resolve) => {
- const blockInterval = parseInt((await api.consts.inflation.inflationBlockInterval).toString());
+ const blockInterval = (await api.consts.inflation.inflationBlockInterval).toNumber();
const unsubscribe = await api.rpc.chain.subscribeNewHeads(head => {
- const currentBlock = parseInt(head.number.toString());
+ const currentBlock = head.number.toNumber();
if (currentBlock % blockInterval < blockInterval - 10) {
unsubscribe();
resolve();
@@ -64,18 +63,18 @@
await skipInflationBlock(api);
await waitNewBlocks(api, 1);
- const totalBefore = new BigNumber((await api.query.balances.totalIssuance()).toString());
+ const totalBefore = (await api.query.balances.totalIssuance()).toBigInt();
const alicePrivateKey = privateKey('//Alice');
- const amount = new BigNumber(1);
- const transfer = api.tx.balances.transfer(bobsPublicKey, amount.toFixed());
+ const amount = 1n;
+ const transfer = api.tx.balances.transfer(bobsPublicKey, amount);
const result = getGenericResult(await submitTransactionAsync(alicePrivateKey, transfer));
- const totalAfter = new BigNumber((await api.query.balances.totalIssuance()).toString());
+ const totalAfter = (await api.query.balances.totalIssuance()).toBigInt();
expect(result.success).to.be.true;
- expect(totalAfter.toFixed()).to.be.equal(totalBefore.toFixed());
+ expect(totalAfter).to.be.equal(totalBefore);
});
});
@@ -85,20 +84,20 @@
await waitNewBlocks(api, 1);
const alicePrivateKey = privateKey('//Alice');
- 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());
+ const treasuryBalanceBefore: bigint = (await api.query.system.account(TREASURY)).data.free.toBigInt();
+ const aliceBalanceBefore: bigint = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();
- const amount = new BigNumber(1);
- const transfer = api.tx.balances.transfer(bobsPublicKey, amount.toFixed());
+ const amount = 1n;
+ const transfer = api.tx.balances.transfer(bobsPublicKey, amount);
const result = getGenericResult(await submitTransactionAsync(alicePrivateKey, transfer));
- 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());
- const fee = aliceBalanceBefore.minus(aliceBalanceAfter).minus(amount);
- const treasuryIncrease = treasuryBalanceAfter.minus(treasuryBalanceBefore);
+ const treasuryBalanceAfter: bigint = (await api.query.system.account(TREASURY)).data.free.toBigInt();
+ const aliceBalanceAfter: bigint = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();
+ const fee = aliceBalanceBefore - aliceBalanceAfter - amount;
+ const treasuryIncrease = treasuryBalanceAfter - treasuryBalanceBefore;
expect(result.success).to.be.true;
- expect(treasuryIncrease.toFixed()).to.be.equal(fee.toFixed());
+ expect(treasuryIncrease).to.be.equal(fee);
});
});
@@ -108,18 +107,18 @@
await waitNewBlocks(api, 1);
const bobPrivateKey = privateKey('//Bob');
- const treasuryBalanceBefore = new BigNumber((await api.query.system.account(Treasury)).data.free.toString());
- const bobBalanceBefore = new BigNumber((await api.query.system.account(bobsPublicKey)).data.free.toString());
+ const treasuryBalanceBefore = (await api.query.system.account(TREASURY)).data.free.toBigInt();
+ const bobBalanceBefore = (await api.query.system.account(bobsPublicKey)).data.free.toBigInt();
const badTx = api.tx.balances.setBalance(alicesPublicKey, 0, 0);
await expect(submitTransactionExpectFailAsync(bobPrivateKey, badTx)).to.be.rejected;
- const treasuryBalanceAfter = new BigNumber((await api.query.system.account(Treasury)).data.free.toString());
- const bobBalanceAfter = new BigNumber((await api.query.system.account(bobsPublicKey)).data.free.toString());
- const fee = bobBalanceBefore.minus(bobBalanceAfter);
- const treasuryIncrease = treasuryBalanceAfter.minus(treasuryBalanceBefore);
+ const treasuryBalanceAfter = (await api.query.system.account(TREASURY)).data.free.toBigInt();
+ const bobBalanceAfter = (await api.query.system.account(bobsPublicKey)).data.free.toBigInt();
+ const fee = bobBalanceBefore - bobBalanceAfter;
+ const treasuryIncrease = treasuryBalanceAfter - treasuryBalanceBefore;
- expect(treasuryIncrease.toFixed()).to.be.equal(fee.toFixed());
+ expect(treasuryIncrease).to.be.equal(fee);
});
});
@@ -128,17 +127,17 @@
await skipInflationBlock(api);
await waitNewBlocks(api, 1);
- 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());
+ const treasuryBalanceBefore = (await api.query.system.account(TREASURY)).data.free.toBigInt();
+ const aliceBalanceBefore = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();
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());
- const fee = aliceBalanceBefore.minus(aliceBalanceAfter);
- const treasuryIncrease = treasuryBalanceAfter.minus(treasuryBalanceBefore);
+ const treasuryBalanceAfter = (await api.query.system.account(TREASURY)).data.free.toBigInt();
+ const aliceBalanceAfter = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();
+ const fee = aliceBalanceBefore - aliceBalanceAfter;
+ const treasuryIncrease = treasuryBalanceAfter - treasuryBalanceBefore;
- expect(treasuryIncrease.toFixed()).to.be.equal(fee.toFixed());
+ expect(treasuryIncrease).to.be.equal(fee);
});
});
@@ -147,15 +146,15 @@
await skipInflationBlock(api);
await waitNewBlocks(api, 1);
- const aliceBalanceBefore = new BigNumber((await api.query.system.account(alicesPublicKey)).data.free.toString());
+ const aliceBalanceBefore: bigint = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();
await createCollectionExpectSuccess();
- const aliceBalanceAfter = new BigNumber((await api.query.system.account(alicesPublicKey)).data.free.toString());
- const fee = aliceBalanceBefore.minus(aliceBalanceAfter);
+ const aliceBalanceAfter: bigint = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();
+ const fee = aliceBalanceBefore - aliceBalanceAfter;
- expect(fee.dividedBy(1e15).toNumber()).to.be.lessThan(saneMaximumFee + createCollectionDeposit);
- expect(fee.dividedBy(1e15).toNumber()).to.be.greaterThan(saneMinimumFee + createCollectionDeposit);
+ expect(fee / 10n ** 15n < BigInt(Math.ceil(saneMaximumFee + createCollectionDeposit))).to.be.true;
+ expect(fee / 10n ** 15n < BigInt(Math.ceil(saneMinimumFee + createCollectionDeposit))).to.be.true;
});
});
@@ -167,17 +166,16 @@
const collectionId = await createCollectionExpectSuccess();
const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');
- const aliceBalanceBefore = new BigNumber((await api.query.system.account(alicesPublicKey)).data.free.toString());
+ const aliceBalanceBefore: bigint = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();
await transferExpectSuccess(collectionId, tokenId, alice, bob, 1, 'NFT');
- const aliceBalanceAfter = new BigNumber((await api.query.system.account(alicesPublicKey)).data.free.toString());
- const fee = aliceBalanceBefore.minus(aliceBalanceAfter);
+ const aliceBalanceAfter: bigint = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();
+ const fee = aliceBalanceBefore - aliceBalanceAfter;
// console.log(fee.toString());
const expectedTransferFee = 0.1;
const tolerance = 0.001;
- expect(fee.dividedBy(1e15).minus(expectedTransferFee).abs().toNumber()).to.be.lessThan(tolerance);
+ expect(Number(fee) / 1e15 - expectedTransferFee).to.be.lessThan(tolerance);
});
});
});
-
tests/src/destroyCollection.test.tsdiffbeforeafterboth--- a/tests/src/destroyCollection.test.ts
+++ b/tests/src/destroyCollection.test.ts
@@ -3,12 +3,12 @@
// file 'LICENSE', which is part of this source code package.
//
-import { IKeyringPair } from '@polkadot/types/types';
+import {IKeyringPair} from '@polkadot/types/types';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import privateKey from './substrate/privateKey';
-import { default as usingApi } from './substrate/substrate-api';
-import { createCollectionExpectSuccess,
+import {default as usingApi} from './substrate/substrate-api';
+import {createCollectionExpectSuccess,
destroyCollectionExpectSuccess,
destroyCollectionExpectFailure,
setCollectionLimitsExpectSuccess,
@@ -46,7 +46,7 @@
it('(!negative test!) Destroy a collection that never existed', async () => {
await usingApi(async (api) => {
// Find the collection that never existed
- const collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;
+ const collectionId = (await api.query.common.createdCollectionCount()).toNumber() + 1;
await destroyCollectionExpectFailure(collectionId);
});
});
@@ -62,12 +62,12 @@
});
it('(!negative test!) Destroy a collection using collection admin account', async () => {
const collectionId = await createCollectionExpectSuccess();
- await addCollectionAdminExpectSuccess(alice, collectionId, bob);
+ await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
await destroyCollectionExpectFailure(collectionId, '//Bob');
});
it('fails when OwnerCanDestroy == false', async () => {
const collectionId = await createCollectionExpectSuccess();
- await setCollectionLimitsExpectSuccess(alice, collectionId, { ownerCanDestroy: false });
+ await setCollectionLimitsExpectSuccess(alice, collectionId, {ownerCanDestroy: false});
await destroyCollectionExpectFailure(collectionId, '//Alice');
});
tests/src/enableContractSponsoring.test.tsdiffbeforeafterboth--- a/tests/src/enableContractSponsoring.test.ts
+++ b/tests/src/enableContractSponsoring.test.ts
@@ -3,12 +3,12 @@
// file 'LICENSE', which is part of this source code package.
//
-import { IKeyringPair } from '@polkadot/types/types';
+import {IKeyringPair} from '@polkadot/types/types';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import privateKey from './substrate/privateKey';
import usingApi from './substrate/substrate-api';
-import { deployFlipper, getFlipValue, toggleFlipValueExpectSuccess } from './util/contracthelpers';
+import {deployFlipper, getFlipValue, toggleFlipValueExpectSuccess} from './util/contracthelpers';
import {
enableContractSponsoringExpectFailure,
enableContractSponsoringExpectSuccess,
tests/src/enableDisableTransfer.test.tsdiffbeforeafterboth--- a/tests/src/enableDisableTransfer.test.ts
+++ b/tests/src/enableDisableTransfer.test.ts
@@ -21,31 +21,31 @@
describe('Enable/Disable Transfers', () => {
it('User can transfer token with enabled transfer flag', async () => {
await usingApi(async () => {
- const Alice = privateKey('//Alice');
- const Bob = privateKey('//Bob');
+ const alice = privateKey('//Alice');
+ const bob = privateKey('//Bob');
// nft
const nftCollectionId = await createCollectionExpectSuccess();
- const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
+ const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
// explicitely set transfer flag
- await setTransferFlagExpectSuccess(Alice, nftCollectionId, true);
+ await setTransferFlagExpectSuccess(alice, nftCollectionId, true);
- await transferExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 1);
+ await transferExpectSuccess(nftCollectionId, newNftTokenId, alice, bob, 1);
});
});
it('User can\'n transfer token with disabled transfer flag', async () => {
await usingApi(async () => {
- const Alice = privateKey('//Alice');
- const Bob = privateKey('//Bob');
+ const alice = privateKey('//Alice');
+ const bob = privateKey('//Bob');
// nft
const nftCollectionId = await createCollectionExpectSuccess();
- const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
+ const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
// explicitely set transfer flag
- await setTransferFlagExpectSuccess(Alice, nftCollectionId, false);
+ await setTransferFlagExpectSuccess(alice, nftCollectionId, false);
- await transferExpectFailure(nftCollectionId, newNftTokenId, Alice, Bob, 1);
+ await transferExpectFailure(nftCollectionId, newNftTokenId, alice, bob, 1);
});
});
});
@@ -53,12 +53,12 @@
describe('Negative Enable/Disable Transfers', () => {
it('Non-owner cannot change transfer flag', async () => {
await usingApi(async () => {
- const Bob = privateKey('//Bob');
+ const bob = privateKey('//Bob');
// nft
const nftCollectionId = await createCollectionExpectSuccess();
// Change transfer flag
- await setTransferFlagExpectFailure(Bob, nftCollectionId, false);
+ await setTransferFlagExpectFailure(bob, nftCollectionId, false);
});
});
});
tests/src/eth/allowlist.test.tsdiffbeforeafterboth--- a/tests/src/eth/allowlist.test.ts
+++ b/tests/src/eth/allowlist.test.ts
@@ -1,61 +1,48 @@
-import { expect } from 'chai';
-import waitNewBlocks from '../substrate/wait-new-blocks';
-import { contractHelpers, createEthAccount, createEthAccountWithBalance, deployFlipper, itWeb3, usingWeb3Http } from './util/helpers';
+import {expect} from 'chai';
+import {contractHelpers, createEthAccount, createEthAccountWithBalance, deployFlipper, itWeb3} from './util/helpers';
describe('EVM allowlist', () => {
- itWeb3('Contract allowlist can be toggled', async ({ api }) => {
- await usingWeb3Http(async web3Http => {
- const owner = await createEthAccountWithBalance(api, web3Http);
- const flipper = await deployFlipper(web3Http, owner);
- await waitNewBlocks(api, 1);
- const randomUser = createEthAccount(web3Http);
+ itWeb3('Contract allowlist can be toggled', async ({api, web3}) => {
+ const owner = await createEthAccountWithBalance(api, web3);
+ const flipper = await deployFlipper(web3, owner);
+ const randomUser = createEthAccount(web3);
- const helpers = contractHelpers(web3Http, owner);
+ const helpers = contractHelpers(web3, owner);
- // Any user is allowed by default
- expect(await helpers.methods.allowlistEnabled(flipper.options.address).call()).to.be.false;
- expect(await helpers.methods.allowed(flipper.options.address, randomUser).call()).to.be.true;
- await waitNewBlocks(api, 1);
+ // Any user is allowed by default
+ expect(await helpers.methods.allowlistEnabled(flipper.options.address).call()).to.be.false;
+ expect(await helpers.methods.allowed(flipper.options.address, randomUser).call()).to.be.true;
- // Enable
- await helpers.methods.toggleAllowlist(flipper.options.address, true).send({ from: owner });
- await waitNewBlocks(api, 1);
- expect(await helpers.methods.allowlistEnabled(flipper.options.address).call()).to.be.true;
- expect(await helpers.methods.allowed(flipper.options.address, randomUser).call()).to.be.false;
+ // Enable
+ await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});
+ expect(await helpers.methods.allowlistEnabled(flipper.options.address).call()).to.be.true;
+ expect(await helpers.methods.allowed(flipper.options.address, randomUser).call()).to.be.false;
- // Disable
- await helpers.methods.toggleAllowlist(flipper.options.address, false).send({ from: owner });
- await waitNewBlocks(api, 1);
- expect(await helpers.methods.allowlistEnabled(flipper.options.address).call()).to.be.false;
- expect(await helpers.methods.allowed(flipper.options.address, randomUser).call()).to.be.true;
- });
+ // Disable
+ await helpers.methods.toggleAllowlist(flipper.options.address, false).send({from: owner});
+ expect(await helpers.methods.allowlistEnabled(flipper.options.address).call()).to.be.false;
+ expect(await helpers.methods.allowed(flipper.options.address, randomUser).call()).to.be.true;
});
- itWeb3('Non-whitelisted user can\'t call contract with allowlist enabled', async ({ api }) => {
- await usingWeb3Http(async web3Http => {
- const owner = await createEthAccountWithBalance(api, web3Http);
- const flipper = await deployFlipper(web3Http, owner);
- await waitNewBlocks(api, 1);
- const caller = await createEthAccountWithBalance(api, web3Http);
+ itWeb3('Non-whitelisted user can\'t call contract with allowlist enabled', async ({api, web3}) => {
+ const owner = await createEthAccountWithBalance(api, web3);
+ const flipper = await deployFlipper(web3, owner);
+ const caller = await createEthAccountWithBalance(api, web3);
- const helpers = contractHelpers(web3Http, owner);
+ const helpers = contractHelpers(web3, owner);
- // User can flip with allowlist disabled
- await flipper.methods.flip().send({ from: caller });
- await waitNewBlocks(api, 1);
- expect(await flipper.methods.getValue().call()).to.be.true;
+ // User can flip with allowlist disabled
+ await flipper.methods.flip().send({from: caller});
+ expect(await flipper.methods.getValue().call()).to.be.true;
- // Tx will be reverted if user is not in whitelist
- await helpers.methods.toggleAllowlist(flipper.options.address, true).send({ from: owner });
- await expect(flipper.methods.flip().send({ from: caller })).to.rejected;
- await waitNewBlocks(api, 1);
- expect(await flipper.methods.getValue().call()).to.be.true;
+ // Tx will be reverted if user is not in whitelist
+ await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});
+ await expect(flipper.methods.flip().send({from: caller})).to.rejected;
+ expect(await flipper.methods.getValue().call()).to.be.true;
- // Adding caller to allowlist will make contract callable again
- await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner});
- await flipper.methods.flip().send({ from: caller });
- await waitNewBlocks(api, 1);
- expect(await flipper.methods.getValue().call()).to.be.false;
- });
+ // Adding caller to allowlist will make contract callable again
+ await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner});
+ await flipper.methods.flip().send({from: caller});
+ expect(await flipper.methods.getValue().call()).to.be.false;
});
-});
\ No newline at end of file
+});
tests/src/eth/base.test.tsdiffbeforeafterboth--- a/tests/src/eth/base.test.ts
+++ b/tests/src/eth/base.test.ts
@@ -1,22 +1,22 @@
-import { createEthAccount, createEthAccountWithBalance, deployFlipper, ethBalanceViaSub, GAS_ARGS, itWeb3, recordEthFee } from './util/helpers';
-import { expect } from 'chai';
-import { UNIQUE } from '../util/helpers';
+import {createEthAccount, createEthAccountWithBalance, deployFlipper, ethBalanceViaSub, GAS_ARGS, itWeb3, recordEthFee} from './util/helpers';
+import {expect} from 'chai';
+import {UNIQUE} from '../util/helpers';
describe('Contract calls', () => {
- itWeb3('Call of simple contract fee is less than 0.2 UNQ', async ({ web3, api }) => {
+ itWeb3('Call of simple contract fee is less than 0.2 UNQ', async ({web3, api}) => {
const deployer = await createEthAccountWithBalance(api, web3);
- const flipper = await deployFlipper(web3 as any, deployer);
+ const flipper = await deployFlipper(web3, deployer);
const cost = await recordEthFee(api, deployer, () => flipper.methods.flip().send({from: deployer}));
expect(cost < BigInt(0.2 * Number(UNIQUE))).to.be.true;
});
- itWeb3('Balance transfer fee is less than 0.2 UNQ', async ({ web3, api }) => {
+ itWeb3('Balance transfer fee is less than 0.2 UNQ', async ({web3, api}) => {
const userA = await createEthAccountWithBalance(api, web3);
const userB = createEthAccount(web3);
- const cost = await recordEthFee(api, userA, () => web3.eth.sendTransaction({ from: userA, to: userB, value: '1000000', ...GAS_ARGS }));
+ const cost = await recordEthFee(api, userA, () => web3.eth.sendTransaction({from: userA, to: userB, value: '1000000', ...GAS_ARGS}));
expect(cost - await ethBalanceViaSub(api, userB) < BigInt(0.2 * Number(UNIQUE))).to.be.true;
});
-});
\ No newline at end of file
+});
tests/src/eth/contractSponsoring.test.tsdiffbeforeafterboth--- a/tests/src/eth/contractSponsoring.test.ts
+++ b/tests/src/eth/contractSponsoring.test.ts
@@ -4,26 +4,21 @@
//
import privateKey from '../substrate/privateKey';
-import { expect } from 'chai';
-import {
+import {expect} from 'chai';
+import {
contractHelpers,
createEthAccountWithBalance,
transferBalanceToEth,
deployFlipper,
- itWeb3 } from './util/helpers';
-import waitNewBlocks from '../substrate/wait-new-blocks';
+ itWeb3} from './util/helpers';
describe('Sponsoring EVM contracts', () => {
itWeb3('Sponsoring can be set by the address that has deployed the contract', async ({api, web3}) => {
const owner = await createEthAccountWithBalance(api, web3);
const flipper = await deployFlipper(web3, owner);
- await waitNewBlocks(api, 1);
const helpers = contractHelpers(web3, owner);
- await waitNewBlocks(api, 1);
expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;
- await waitNewBlocks(api, 1);
await helpers.methods.toggleSponsoring(flipper.options.address, true).send({from: owner});
- await waitNewBlocks(api, 1);
expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;
});
@@ -31,13 +26,9 @@
const owner = await createEthAccountWithBalance(api, web3);
const notOwner = await createEthAccountWithBalance(api, web3);
const flipper = await deployFlipper(web3, owner);
- await waitNewBlocks(api, 1);
const helpers = contractHelpers(web3, owner);
- await waitNewBlocks(api, 1);
expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;
- await waitNewBlocks(api, 1);
await expect(helpers.methods.toggleSponsoring(notOwner, true).send({from: notOwner})).to.rejected;
- await waitNewBlocks(api, 1);
expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;
});
@@ -48,29 +39,22 @@
const caller = await createEthAccountWithBalance(api, web3);
const flipper = await deployFlipper(web3, owner);
- await waitNewBlocks(api, 1);
-
+
const helpers = contractHelpers(web3, owner);
- await helpers.methods.toggleAllowlist(flipper.options.address, true).send({ from: owner });
- await waitNewBlocks(api, 1);
- await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({ from: owner });
- await waitNewBlocks(api, 1);
+ await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});
+ await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner});
expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;
await helpers.methods.toggleSponsoring(flipper.options.address, true).send({from: owner});
- await waitNewBlocks(api, 1);
await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});
- await waitNewBlocks(api, 1);
expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;
await transferBalanceToEth(api, alice, flipper.options.address);
- await waitNewBlocks(api, 2);
const originalFlipperBalance = await web3.eth.getBalance(flipper.options.address);
expect(originalFlipperBalance).to.be.not.equal('0');
- await flipper.methods.flip().send({ from: caller });
- await waitNewBlocks(api, 1);
+ await flipper.methods.flip().send({from: caller});
expect(await flipper.methods.getValue().call()).to.be.true;
// Balance should be taken from flipper instead of caller
@@ -85,25 +69,20 @@
const caller = await createEthAccountWithBalance(api, web3);
const flipper = await deployFlipper(web3, owner);
- await waitNewBlocks(api, 1);
-
+
const helpers = contractHelpers(web3, owner);
expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;
await helpers.methods.toggleSponsoring(flipper.options.address, true).send({from: owner});
- await waitNewBlocks(api, 1);
await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});
- await waitNewBlocks(api, 1);
expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;
await transferBalanceToEth(api, alice, flipper.options.address);
- await waitNewBlocks(api, 2);
const originalFlipperBalance = await web3.eth.getBalance(flipper.options.address);
expect(originalFlipperBalance).to.be.not.equal('0');
- await flipper.methods.flip().send({ from: caller });
- await waitNewBlocks(api, 1);
+ await flipper.methods.flip().send({from: caller});
expect(await flipper.methods.getValue().call()).to.be.true;
// Balance should be taken from flipper instead of caller
@@ -119,29 +98,22 @@
const originalCallerBalance = await web3.eth.getBalance(caller);
const flipper = await deployFlipper(web3, owner);
- await waitNewBlocks(api, 1);
-
+
const helpers = contractHelpers(web3, owner);
- await helpers.methods.toggleAllowlist(flipper.options.address, true).send({ from: owner });
- await waitNewBlocks(api, 1);
- await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({ from: owner });
- await waitNewBlocks(api, 1);
+ await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});
+ await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner});
expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;
await helpers.methods.toggleSponsoring(flipper.options.address, true).send({from: owner});
- await waitNewBlocks(api, 1);
await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});
- await waitNewBlocks(api, 1);
expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;
await transferBalanceToEth(api, alice, flipper.options.address);
- await waitNewBlocks(api, 2);
const originalFlipperBalance = await web3.eth.getBalance(flipper.options.address);
expect(originalFlipperBalance).to.be.not.equal('0');
- await flipper.methods.flip().send({ from: caller });
- await waitNewBlocks(api, 1);
+ await flipper.methods.flip().send({from: caller});
expect(await flipper.methods.getValue().call()).to.be.true;
expect(await web3.eth.getBalance(caller)).to.be.equals(originalCallerBalance);
@@ -155,44 +127,34 @@
const originalCallerBalance = await web3.eth.getBalance(caller);
const flipper = await deployFlipper(web3, owner);
- await waitNewBlocks(api, 1);
-
+
const helpers = contractHelpers(web3, owner);
- await helpers.methods.toggleAllowlist(flipper.options.address, true).send({ from: owner });
- await waitNewBlocks(api, 1);
- await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({ from: owner });
- await waitNewBlocks(api, 1);
+ await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});
+ await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner});
expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;
await helpers.methods.toggleSponsoring(flipper.options.address, true).send({from: owner});
- await waitNewBlocks(api, 1);
await helpers.methods.setSponsoringRateLimit(flipper.options.address, 10).send({from: owner});
- await waitNewBlocks(api, 1);
expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;
await transferBalanceToEth(api, alice, flipper.options.address);
- await waitNewBlocks(api, 2);
const originalFlipperBalance = await web3.eth.getBalance(flipper.options.address);
expect(originalFlipperBalance).to.be.not.equal('0');
- await flipper.methods.flip().send({ from: caller });
- await waitNewBlocks(api, 1);
+ await flipper.methods.flip().send({from: caller});
expect(await flipper.methods.getValue().call()).to.be.true;
expect(await web3.eth.getBalance(caller)).to.be.equals(originalCallerBalance);
- await flipper.methods.flip().send({ from: caller });
- await waitNewBlocks(api, 1);
+ await flipper.methods.flip().send({from: caller});
expect(await web3.eth.getBalance(caller)).to.be.not.equals(originalCallerBalance);
});
- // TODO: Find a way to calculate default rate limit
+ // TODO: Find a way to calculate default rate limit
itWeb3('Default rate limit equals 7200', async ({api, web3}) => {
const owner = await createEthAccountWithBalance(api, web3);
const flipper = await deployFlipper(web3, owner);
- await waitNewBlocks(api, 1);
const helpers = contractHelpers(web3, owner);
- await waitNewBlocks(api, 1);
expect(await helpers.methods.getSponsoringRateLimit(flipper.options.address).call()).to.be.equals('7200');
});
@@ -203,25 +165,20 @@
const caller = await createEthAccountWithBalance(api, web3);
const flipper = await deployFlipper(web3, owner);
- await waitNewBlocks(api, 1);
-
+
const helpers = contractHelpers(web3, owner);
expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;
await helpers.methods.toggleSponsoring(flipper.options.address, true).send({from: owner});
- await waitNewBlocks(api, 1);
await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});
- await waitNewBlocks(api, 1);
expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;
await transferBalanceToEth(api, alice, flipper.options.address);
- await waitNewBlocks(api, 2);
const originalFlipperBalance = await web3.eth.getBalance(flipper.options.address);
expect(originalFlipperBalance).to.be.not.equal('0');
- await flipper.methods.flip().send({ from: caller });
- await waitNewBlocks(api, 1);
+ await flipper.methods.flip().send({from: caller});
expect(await flipper.methods.getValue().call()).to.be.true;
// Balance should be taken from flipper instead of caller
tests/src/eth/crossTransfer.test.tsdiffbeforeafterboth--- a/tests/src/eth/crossTransfer.test.ts
+++ b/tests/src/eth/crossTransfer.test.ts
@@ -4,15 +4,15 @@
//
import privateKey from '../substrate/privateKey';
-import { createCollectionExpectSuccess,
- createFungibleItemExpectSuccess,
- transferExpectSuccess,
- transferFromExpectSuccess,
- createItemExpectSuccess } from '../util/helpers';
-import { collectionIdToAddress,
- createEthAccountWithBalance,
+import {createCollectionExpectSuccess,
+ createFungibleItemExpectSuccess,
+ transferExpectSuccess,
+ transferFromExpectSuccess,
+ createItemExpectSuccess} from '../util/helpers';
+import {collectionIdToAddress,
+ createEthAccountWithBalance,
subToEth,
- GAS_ARGS, itWeb3 } from './util/helpers';
+ GAS_ARGS, itWeb3} from './util/helpers';
import fungibleAbi from './fungibleAbi.json';
import nonFungibleAbi from './nonFungibleAbi.json';
@@ -20,34 +20,34 @@
itWeb3('The private key X create a substrate address. Alice sends a token to the corresponding EVM address, and X can send it to Bob in the substrate', async () => {
const collection = await createCollectionExpectSuccess({
name: 'token name',
- mode: { type: 'Fungible', decimalPoints: 0 },
+ mode: {type: 'Fungible', decimalPoints: 0},
});
const alice = privateKey('//Alice');
const bob = privateKey('//Bob');
const charlie = privateKey('//Charlie');
- await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { substrate: alice.address });
- await transferExpectSuccess(collection, 0, alice, {ethereum: subToEth(charlie.address)} , 200, 'Fungible');
- await transferFromExpectSuccess(collection, 0, alice, {ethereum: subToEth(charlie.address)}, charlie, 50, 'Fungible');
+ await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Substrate: alice.address});
+ await transferExpectSuccess(collection, 0, alice, {Ethereum: subToEth(charlie.address)} , 200, 'Fungible');
+ await transferFromExpectSuccess(collection, 0, alice, {Ethereum: subToEth(charlie.address)}, charlie, 50, 'Fungible');
await transferExpectSuccess(collection, 0, charlie, bob, 50, 'Fungible');
});
- itWeb3('The private key X create a EVM address. Alice sends a token to the substrate address corresponding to this EVM address, and X can send it to Bob in the EVM', async ({ api, web3 }) => {
+ itWeb3('The private key X create a EVM address. Alice sends a token to the substrate address corresponding to this EVM address, and X can send it to Bob in the EVM', async ({api, web3}) => {
const collection = await createCollectionExpectSuccess({
name: 'token name',
- mode: { type: 'Fungible', decimalPoints: 0 },
+ mode: {type: 'Fungible', decimalPoints: 0},
});
const alice = privateKey('//Alice');
const bob = privateKey('//Bob');
const bobProxy = await createEthAccountWithBalance(api, web3);
const aliceProxy = await createEthAccountWithBalance(api, web3);
- await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, alice.address);
- await transferExpectSuccess(collection, 0, alice, { ethereum: aliceProxy } , 200, 'Fungible');
+ await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, alice.address);
+ await transferExpectSuccess(collection, 0, alice, {Ethereum: aliceProxy} , 200, 'Fungible');
const address = collectionIdToAddress(collection);
const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: aliceProxy, ...GAS_ARGS});
- await contract.methods.transfer(bobProxy, 50).send({ from: aliceProxy });
- await transferFromExpectSuccess(collection, 0, alice, {ethereum: bobProxy}, bob, 50, 'Fungible');
+ await contract.methods.transfer(bobProxy, 50).send({from: aliceProxy});
+ await transferFromExpectSuccess(collection, 0, alice, {Ethereum: bobProxy}, bob, 50, 'Fungible');
await transferExpectSuccess(collection, 0, bob, alice, 50, 'Fungible');
});
});
@@ -56,33 +56,33 @@
itWeb3('The private key X create a substrate address. Alice sends a token to the corresponding EVM address, and X can send it to Bob in the substrate', async () => {
const collection = await createCollectionExpectSuccess({
name: 'token name',
- mode: { type: 'NFT' },
+ mode: {type: 'NFT'},
});
const alice = privateKey('//Alice');
const bob = privateKey('//Bob');
const charlie = privateKey('//Charlie');
- const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { substrate: alice.address });
- await transferExpectSuccess(collection, tokenId, alice, { ethereum: subToEth(charlie.address) }, 1, 'NFT');
- await transferFromExpectSuccess(collection, tokenId, alice, {ethereum: subToEth(charlie.address)}, charlie, 1, 'NFT');
+ const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Substrate: alice.address});
+ await transferExpectSuccess(collection, tokenId, alice, {Ethereum: subToEth(charlie.address)}, 1, 'NFT');
+ await transferFromExpectSuccess(collection, tokenId, alice, {Ethereum: subToEth(charlie.address)}, charlie, 1, 'NFT');
await transferExpectSuccess(collection, tokenId, charlie, bob, 1, 'NFT');
});
- itWeb3('The private key X create a EVM address. Alice sends a token to the substrate address corresponding to this EVM address, and X can send it to Bob in the EVM', async ({ api, web3 }) => {
+ itWeb3('The private key X create a EVM address. Alice sends a token to the substrate address corresponding to this EVM address, and X can send it to Bob in the EVM', async ({api, web3}) => {
const collection = await createCollectionExpectSuccess({
name: 'token name',
- mode: { type: 'NFT' },
+ mode: {type: 'NFT'},
});
const alice = privateKey('//Alice');
const bob = privateKey('//Bob');
const charlie = privateKey('//Charlie');
const bobProxy = await createEthAccountWithBalance(api, web3);
const aliceProxy = await createEthAccountWithBalance(api, web3);
- const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { substrate: alice.address });
- await transferExpectSuccess(collection, tokenId, alice, { ethereum: aliceProxy } , 1, 'NFT');
+ const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Substrate: alice.address});
+ await transferExpectSuccess(collection, tokenId, alice, {Ethereum: aliceProxy} , 1, 'NFT');
const address = collectionIdToAddress(collection);
const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: aliceProxy, ...GAS_ARGS});
- await contract.methods.transfer(bobProxy, 1).send({ from: aliceProxy });
- await transferFromExpectSuccess(collection, tokenId, alice, {ethereum: bobProxy}, bob, 1, 'NFT');
+ await contract.methods.transfer(bobProxy, 1).send({from: aliceProxy});
+ await transferFromExpectSuccess(collection, tokenId, alice, {Ethereum: bobProxy}, bob, 1, 'NFT');
await transferExpectSuccess(collection, tokenId, bob, charlie, 1, 'NFT');
});
-});
\ No newline at end of file
+});
tests/src/eth/fungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/fungible.test.ts
+++ b/tests/src/eth/fungible.test.ts
@@ -4,41 +4,40 @@
//
import privateKey from '../substrate/privateKey';
-import { approveExpectSuccess, createCollectionExpectSuccess, createFungibleItemExpectSuccess, transferExpectSuccess, transferFromExpectSuccess, UNIQUE } from '../util/helpers';
-import { collectionIdToAddress, createEthAccount, createEthAccountWithBalance, GAS_ARGS, itWeb3, normalizeEvents, recordEthFee, recordEvents, subToEth, transferBalanceToEth } from './util/helpers';
+import {approveExpectSuccess, createCollectionExpectSuccess, createFungibleItemExpectSuccess, transferExpectSuccess, transferFromExpectSuccess, UNIQUE} from '../util/helpers';
+import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, GAS_ARGS, itWeb3, normalizeEvents, recordEthFee, recordEvents, subToEth, transferBalanceToEth} from './util/helpers';
import fungibleAbi from './fungibleAbi.json';
-import { expect } from 'chai';
+import {expect} from 'chai';
describe('Fungible: Information getting', () => {
- itWeb3('totalSupply', async ({ api, web3 }) => {
+ itWeb3('totalSupply', async ({api, web3}) => {
const collection = await createCollectionExpectSuccess({
name: 'token name',
- mode: { type: 'Fungible', decimalPoints: 0 },
+ mode: {type: 'Fungible', decimalPoints: 0},
});
const alice = privateKey('//Alice');
const caller = await createEthAccountWithBalance(api, web3);
-
- await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { substrate: alice.address });
+ await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Substrate: alice.address});
+
const address = collectionIdToAddress(collection);
const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: caller, ...GAS_ARGS});
const totalSupply = await contract.methods.totalSupply().call();
- // FIXME: always equals to 0, because this method is not implemented
- expect(totalSupply).to.equal('0');
+ expect(totalSupply).to.equal('200');
});
- itWeb3('balanceOf', async ({ api, web3 }) => {
+ itWeb3('balanceOf', async ({api, web3}) => {
const collection = await createCollectionExpectSuccess({
name: 'token name',
- mode: { type: 'Fungible', decimalPoints: 0 },
+ mode: {type: 'Fungible', decimalPoints: 0},
});
const alice = privateKey('//Alice');
const caller = await createEthAccountWithBalance(api, web3);
- await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { ethereum: caller });
+ await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: caller});
const address = collectionIdToAddress(collection);
const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: caller, ...GAS_ARGS});
@@ -49,16 +48,16 @@
});
describe('Fungible: Plain calls', () => {
- itWeb3('Can perform approve()', async ({ web3, api }) => {
+ itWeb3('Can perform approve()', async ({web3, api}) => {
const collection = await createCollectionExpectSuccess({
name: 'token name',
- mode: { type: 'Fungible', decimalPoints: 0 },
+ mode: {type: 'Fungible', decimalPoints: 0},
});
const alice = privateKey('//Alice');
const owner = await createEthAccountWithBalance(api, web3);
- await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { ethereum: owner });
+ await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: owner});
const spender = createEthAccount(web3);
@@ -88,17 +87,17 @@
}
});
- itWeb3('Can perform transferFrom()', async ({ web3, api }) => {
+ itWeb3('Can perform transferFrom()', async ({web3, api}) => {
const collection = await createCollectionExpectSuccess({
name: 'token name',
- mode: { type: 'Fungible', decimalPoints: 0 },
+ mode: {type: 'Fungible', decimalPoints: 0},
});
const alice = privateKey('//Alice');
const owner = createEthAccount(web3);
await transferBalanceToEth(api, alice, owner, 999999999999999);
- await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { ethereum: owner });
+ await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: owner});
const spender = createEthAccount(web3);
await transferBalanceToEth(api, alice, spender, 999999999999999);
@@ -146,17 +145,17 @@
}
});
- itWeb3('Can perform transfer()', async ({ web3, api }) => {
+ itWeb3('Can perform transfer()', async ({web3, api}) => {
const collection = await createCollectionExpectSuccess({
name: 'token name',
- mode: { type: 'Fungible', decimalPoints: 0 },
+ mode: {type: 'Fungible', decimalPoints: 0},
});
const alice = privateKey('//Alice');
const owner = createEthAccount(web3);
await transferBalanceToEth(api, alice, owner, 999999999999999);
- await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { ethereum: owner });
+ await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: owner});
const receiver = createEthAccount(web3);
await transferBalanceToEth(api, alice, receiver, 999999999999999);
@@ -165,7 +164,7 @@
const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: owner, ...GAS_ARGS});
{
- const result = await contract.methods.transfer(receiver, 50).send({ from: owner});
+ const result = await contract.methods.transfer(receiver, 50).send({from: owner});
const events = normalizeEvents(result.events);
expect(events).to.be.deep.equal([
{
@@ -193,79 +192,79 @@
});
describe('Fungible: Fees', () => {
- itWeb3('approve() call fee is less than 0.2UNQ', async ({ web3, api }) => {
+ itWeb3('approve() call fee is less than 0.2UNQ', async ({web3, api}) => {
const collection = await createCollectionExpectSuccess({
- mode: { type: 'Fungible', decimalPoints: 0 },
+ mode: {type: 'Fungible', decimalPoints: 0},
});
const alice = privateKey('//Alice');
const owner = await createEthAccountWithBalance(api, web3);
const spender = createEthAccount(web3);
- await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { ethereum: owner });
+ await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: owner});
const address = collectionIdToAddress(collection);
- const contract = new web3.eth.Contract(fungibleAbi as any, address, { from: owner, ...GAS_ARGS });
+ const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: owner, ...GAS_ARGS});
- const cost = await recordEthFee(api, owner, () => contract.methods.approve(spender, 100).send({ from: owner }));
+ const cost = await recordEthFee(api, owner, () => contract.methods.approve(spender, 100).send({from: owner}));
expect(cost < BigInt(0.2 * Number(UNIQUE)));
});
- itWeb3('transferFrom() call fee is less than 0.2UNQ', async ({ web3, api }) => {
+ itWeb3('transferFrom() call fee is less than 0.2UNQ', async ({web3, api}) => {
const collection = await createCollectionExpectSuccess({
mode: {type: 'Fungible', decimalPoints: 0},
});
const alice = privateKey('//Alice');
-
+
const owner = await createEthAccountWithBalance(api, web3);
const spender = await createEthAccountWithBalance(api, web3);
- await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { ethereum: owner });
+ await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: owner});
const address = collectionIdToAddress(collection);
- const contract = new web3.eth.Contract(fungibleAbi as any, address, { from: owner, ...GAS_ARGS });
+ const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: owner, ...GAS_ARGS});
- await contract.methods.approve(spender, 100).send({ from: owner });
+ await contract.methods.approve(spender, 100).send({from: owner});
- const cost = await recordEthFee(api, spender, () => contract.methods.transferFrom(owner, spender, 100).send({ from: spender }));
+ const cost = await recordEthFee(api, spender, () => contract.methods.transferFrom(owner, spender, 100).send({from: spender}));
expect(cost < BigInt(0.2 * Number(UNIQUE)));
});
- itWeb3('transfer() call fee is less than 0.2UNQ', async ({ web3, api }) => {
+ itWeb3('transfer() call fee is less than 0.2UNQ', async ({web3, api}) => {
const collection = await createCollectionExpectSuccess({
- mode: { type: 'Fungible', decimalPoints: 0 },
+ mode: {type: 'Fungible', decimalPoints: 0},
});
const alice = privateKey('//Alice');
const owner = await createEthAccountWithBalance(api, web3);
const receiver = createEthAccount(web3);
- await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { ethereum: owner });
+ await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: owner});
const address = collectionIdToAddress(collection);
- const contract = new web3.eth.Contract(fungibleAbi as any, address, { from: owner, ...GAS_ARGS });
+ const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: owner, ...GAS_ARGS});
- const cost = await recordEthFee(api, owner, () => contract.methods.transfer(receiver, 100).send({ from: owner }));
+ const cost = await recordEthFee(api, owner, () => contract.methods.transfer(receiver, 100).send({from: owner}));
expect(cost < BigInt(0.2 * Number(UNIQUE)));
});
});
describe('Fungible: Substrate calls', () => {
- itWeb3('Events emitted for approve()', async ({ web3 }) => {
+ itWeb3('Events emitted for approve()', async ({web3}) => {
const collection = await createCollectionExpectSuccess({
- mode: { type: 'Fungible', decimalPoints: 0 },
+ mode: {type: 'Fungible', decimalPoints: 0},
});
const alice = privateKey('//Alice');
const receiver = createEthAccount(web3);
- await createFungibleItemExpectSuccess(alice, collection, { Value: 200n });
+ await createFungibleItemExpectSuccess(alice, collection, {Value: 200n});
const address = collectionIdToAddress(collection);
const contract = new web3.eth.Contract(fungibleAbi as any, address);
const events = await recordEvents(contract, async () => {
- await approveExpectSuccess(collection, 1, alice, { ethereum: receiver }, 100);
+ await approveExpectSuccess(collection, 0, alice, {Ethereum: receiver}, 100);
});
expect(events).to.be.deep.equal([
@@ -281,23 +280,23 @@
]);
});
- itWeb3('Events emitted for transferFrom()', async ({ web3 }) => {
+ itWeb3('Events emitted for transferFrom()', async ({web3}) => {
const collection = await createCollectionExpectSuccess({
- mode: { type: 'Fungible', decimalPoints: 0 },
+ mode: {type: 'Fungible', decimalPoints: 0},
});
const alice = privateKey('//Alice');
const bob = privateKey('//Bob');
const receiver = createEthAccount(web3);
- await createFungibleItemExpectSuccess(alice, collection, { Value: 200n });
- await approveExpectSuccess(collection, 1, alice, bob, 100);
+ await createFungibleItemExpectSuccess(alice, collection, {Value: 200n});
+ await approveExpectSuccess(collection, 0, alice, bob.address, 100);
const address = collectionIdToAddress(collection);
const contract = new web3.eth.Contract(fungibleAbi as any, address);
const events = await recordEvents(contract, async () => {
- await transferFromExpectSuccess(collection, 1, bob, alice, { ethereum: receiver }, 51, 'Fungible');
+ await transferFromExpectSuccess(collection, 0, bob, alice, {Ethereum: receiver}, 51, 'Fungible');
});
expect(events).to.be.deep.equal([
@@ -322,21 +321,21 @@
]);
});
- itWeb3('Events emitted for transfer()', async ({ web3 }) => {
+ itWeb3('Events emitted for transfer()', async ({web3}) => {
const collection = await createCollectionExpectSuccess({
- mode: { type: 'Fungible', decimalPoints: 0 },
+ mode: {type: 'Fungible', decimalPoints: 0},
});
const alice = privateKey('//Alice');
const receiver = createEthAccount(web3);
- await createFungibleItemExpectSuccess(alice, collection, { Value: 200n });
+ await createFungibleItemExpectSuccess(alice, collection, {Value: 200n});
const address = collectionIdToAddress(collection);
const contract = new web3.eth.Contract(fungibleAbi as any, address);
const events = await recordEvents(contract, async () => {
- await transferExpectSuccess(collection, 1, alice, { ethereum: receiver }, 51, 'Fungible');
+ await transferExpectSuccess(collection, 0, alice, {Ethereum:receiver}, 51, 'Fungible');
});
expect(events).to.be.deep.equal([
@@ -351,4 +350,4 @@
},
]);
});
-});
\ No newline at end of file
+});
tests/src/eth/helpersSmoke.test.tsdiffbeforeafterboth--- a/tests/src/eth/helpersSmoke.test.ts
+++ b/tests/src/eth/helpersSmoke.test.ts
@@ -1,25 +1,21 @@
-import { expect } from 'chai';
-import waitNewBlocks from '../substrate/wait-new-blocks';
-import { createEthAccountWithBalance, deployFlipper, itWeb3, contractHelpers } from './util/helpers';
+import {expect} from 'chai';
+import {createEthAccountWithBalance, deployFlipper, itWeb3, contractHelpers} from './util/helpers';
describe('Helpers sanity check', () => {
- itWeb3('Contract owner is recorded', async ({ api, web3 }) => {
+ itWeb3('Contract owner is recorded', async ({api, web3}) => {
const owner = await createEthAccountWithBalance(api, web3);
const flipper = await deployFlipper(web3, owner);
- await waitNewBlocks(api, 1);
expect(await contractHelpers(web3, owner).methods.contractOwner(flipper.options.address).call()).to.be.equal(owner);
});
- itWeb3('Flipper is working', async ({ api, web3 }) => {
+ itWeb3('Flipper is working', async ({api, web3}) => {
const owner = await createEthAccountWithBalance(api, web3);
const flipper = await deployFlipper(web3, owner);
- await waitNewBlocks(api, 1);
expect(await flipper.methods.getValue().call()).to.be.false;
- await flipper.methods.flip().send({ from: owner });
- await waitNewBlocks(api, 1);
+ await flipper.methods.flip().send({from: owner});
expect(await flipper.methods.getValue().call()).to.be.true;
});
-});
\ No newline at end of file
+});
tests/src/eth/marketplace/marketplace.test.tsdiffbeforeafterboth--- a/tests/src/eth/marketplace/marketplace.test.ts
+++ b/tests/src/eth/marketplace/marketplace.test.ts
@@ -1,109 +1,106 @@
-import { readFile } from 'fs/promises';
-import { getBalanceSingle, transferBalanceExpectSuccess } from '../../substrate/get-balance';
+import {readFile} from 'fs/promises';
+import {getBalanceSingle, transferBalanceExpectSuccess} from '../../substrate/get-balance';
import privateKey from '../../substrate/privateKey';
-import { createCollectionExpectSuccess, createFungibleItemExpectSuccess, createItemExpectSuccess, queryNftOwner, transferExpectSuccess, transferFromExpectSuccess } from '../../util/helpers';
-import { collectionIdToAddress, createEthAccountWithBalance, executeEthTxOnSub, GAS_ARGS, itWeb3, subToEth, subToEthLowercase } from '../util/helpers';
-import { evmToAddress } from '@polkadot/util-crypto';
+import {createCollectionExpectSuccess, createFungibleItemExpectSuccess, createItemExpectSuccess, getTokenOwner, transferExpectSuccess, transferFromExpectSuccess} from '../../util/helpers';
+import {collectionIdToAddress, createEthAccountWithBalance, executeEthTxOnSub, GAS_ARGS, itWeb3, subToEth, subToEthLowercase} from '../util/helpers';
+import {evmToAddress} from '@polkadot/util-crypto';
import nonFungibleAbi from '../nonFungibleAbi.json';
import fungibleAbi from '../fungibleAbi.json';
-import waitNewBlocks from '../../substrate/wait-new-blocks';
-import { expect } from 'chai';
+import {expect} from 'chai';
const PRICE = 2000n;
describe('Matcher contract usage', () => {
itWeb3('With UNQ', async ({api, web3}) => {
const matcherOwner = await createEthAccountWithBalance(api, web3);
- const Matcher = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/MarketPlaceUNQ.abi`)).toString()), undefined, {
+ const matcherContract = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/MarketPlaceUNQ.abi`)).toString()), undefined, {
from: matcherOwner,
...GAS_ARGS,
});
- const matcher = await Matcher.deploy({ data: (await readFile(`${__dirname}/MarketPlaceUNQ.bin`)).toString() }).send({ from: matcherOwner });
+ const matcher = await matcherContract.deploy({data: (await readFile(`${__dirname}/MarketPlaceUNQ.bin`)).toString()}).send({from: matcherOwner});
const alice = privateKey('//Alice');
const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- const evmCollection = new web3.eth.Contract(nonFungibleAbi as any, collectionIdToAddress(collectionId), { from: matcherOwner });
+ const evmCollection = new web3.eth.Contract(nonFungibleAbi as any, collectionIdToAddress(collectionId), {from: matcherOwner});
const seller = privateKey('//Bob');
-
+
const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT', seller.address);
// To transfer item to matcher it first needs to be transfered to EVM account of bob
- await transferExpectSuccess(collectionId, tokenId, seller, {ethereum: subToEth(seller.address)});
+ await transferExpectSuccess(collectionId, tokenId, seller, {Ethereum: subToEth(seller.address)});
// Fees will be paid from EVM account, so we should have some balance here
await transferBalanceExpectSuccess(api, seller, evmToAddress(subToEth(seller.address)), 10n ** 18n);
await transferBalanceExpectSuccess(api, alice, evmToAddress(subToEth(alice.address)), 10n ** 18n);
- await waitNewBlocks(api, 1);
// Token is owned by seller initially
- expect(await queryNftOwner(api, collectionId, tokenId)).to.be.deep.equal({ ethereum: subToEthLowercase(seller.address) });
+ expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal({Ethereum: subToEthLowercase(seller.address)});
// Ask
{
await executeEthTxOnSub(api, seller, evmCollection, m => m.approve(matcher.options.address, tokenId));
await executeEthTxOnSub(api, seller, matcher, m => m.setAsk(PRICE, '0x0000000000000000000000000000000000000000', evmCollection.options.address, tokenId, 1));
}
-
+
// Token is transferred to matcher
- expect(await queryNftOwner(api, collectionId, tokenId)).to.be.deep.equal({ ethereum: matcher.options.address.toLowerCase() });
+ expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal({Ethereum: matcher.options.address.toLowerCase()});
// Buy
{
const sellerBalanceBeforePurchase = await getBalanceSingle(api, seller.address);
// There is two functions named 'buy', so we should provide full signature
- await executeEthTxOnSub(api, alice, matcher, m => m['buy(address,uint256)'](evmCollection.options.address, tokenId), { value: PRICE });
+ await executeEthTxOnSub(api, alice, matcher, m => m['buy(address,uint256)'](evmCollection.options.address, tokenId), {value: PRICE});
expect(await getBalanceSingle(api, seller.address) - sellerBalanceBeforePurchase === PRICE);
}
// Token is transferred to evm account of alice
- expect(await queryNftOwner(api, collectionId, tokenId)).to.be.deep.equal({ ethereum: subToEthLowercase(alice.address) });
+ expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal({Ethereum: subToEthLowercase(alice.address)});
+
-
// Transfer token to substrate side of alice
- await transferFromExpectSuccess(collectionId, tokenId, alice, { ethereum: subToEth(alice.address) }, { substrate: alice.address });
-
+ await transferFromExpectSuccess(collectionId, tokenId, alice, {Ethereum: subToEth(alice.address)}, {Substrate: alice.address});
+
// Token is transferred to substrate account of alice, seller received funds
- expect(await queryNftOwner(api, collectionId, tokenId)).to.be.deep.equal({ substrate: alice.address });
+ expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal({Substrate: alice.address});
});
itWeb3('With custom ERC20', async ({api, web3}) => {
const matcherOwner = await createEthAccountWithBalance(api, web3);
- const Matcher = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/MarketPlaceUNQ.abi`)).toString()), undefined, {
+ const matcherContract = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/MarketPlaceUNQ.abi`)).toString()), undefined, {
from: matcherOwner,
...GAS_ARGS,
});
- const matcher = await Matcher.deploy({ data: (await readFile(`${__dirname}/MarketPlaceUNQ.bin`)).toString() }).send({ from: matcherOwner });
+ const matcher = await matcherContract.deploy({data: (await readFile(`${__dirname}/MarketPlaceUNQ.bin`)).toString()}).send({from: matcherOwner});
const alice = privateKey('//Alice');
const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- const evmCollection = new web3.eth.Contract(nonFungibleAbi as any, collectionIdToAddress(collectionId), { from: matcherOwner });
+ const evmCollection = new web3.eth.Contract(nonFungibleAbi as any, collectionIdToAddress(collectionId), {from: matcherOwner});
- const fungibleId = await createCollectionExpectSuccess({ mode: { type: 'Fungible', decimalPoints: 0 } });
- const evmFungible = new web3.eth.Contract(fungibleAbi as any, collectionIdToAddress(fungibleId), { from: matcherOwner, ...GAS_ARGS });
- await createFungibleItemExpectSuccess(alice, fungibleId, { Value: PRICE }, { ethereum: subToEth(alice.address) });
+ const fungibleId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
+ const evmFungible = new web3.eth.Contract(fungibleAbi as any, collectionIdToAddress(fungibleId), {from: matcherOwner, ...GAS_ARGS});
+ await createFungibleItemExpectSuccess(alice, fungibleId, {Value: PRICE}, {Ethereum: subToEth(alice.address)});
const seller = privateKey('//Bob');
-
+
const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT', seller.address);
// To transfer item to matcher it first needs to be transfered to EVM account of bob
- await transferExpectSuccess(collectionId, tokenId, seller, {ethereum: subToEth(seller.address)});
+ await transferExpectSuccess(collectionId, tokenId, seller, {Ethereum: subToEth(seller.address)});
// Fees will be paid from EVM account, so we should have some balance here
await transferBalanceExpectSuccess(api, seller, evmToAddress(subToEth(seller.address)), 10n ** 18n);
await transferBalanceExpectSuccess(api, alice, evmToAddress(subToEth(alice.address)), 10n ** 18n);
- await waitNewBlocks(api, 1);
// Token is owned by seller initially
- expect(await queryNftOwner(api, collectionId, tokenId)).to.be.deep.equal({ ethereum: subToEthLowercase(seller.address) });
+ expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal({Ethereum: subToEthLowercase(seller.address)});
// Ask
{
await executeEthTxOnSub(api, seller, evmCollection, m => m.approve(matcher.options.address, tokenId));
await executeEthTxOnSub(api, seller, matcher, m => m.setAsk(PRICE, evmFungible.options.address, evmCollection.options.address, tokenId, 1));
}
-
+
// Token is transferred to matcher
- expect(await queryNftOwner(api, collectionId, tokenId)).to.be.deep.equal({ ethereum: matcher.options.address.toLowerCase() });
+ expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal({Ethereum: matcher.options.address.toLowerCase()});
// Buy
{
@@ -121,65 +118,62 @@
}
// Token is transferred to evm account of alice
- expect(await queryNftOwner(api, collectionId, tokenId)).to.be.deep.equal({ ethereum: subToEthLowercase(alice.address) });
+ expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal({Ethereum: subToEthLowercase(alice.address)});
+
-
// Transfer token to substrate side of alice
- await transferFromExpectSuccess(collectionId, tokenId, alice, { ethereum: subToEth(alice.address) }, { substrate: alice.address });
-
+ await transferFromExpectSuccess(collectionId, tokenId, alice, {Ethereum: subToEth(alice.address)}, {Substrate: alice.address});
+
// Token is transferred to substrate account of alice
- expect(await queryNftOwner(api, collectionId, tokenId)).to.be.deep.equal({ substrate: alice.address });
+ expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal({Substrate: alice.address});
});
- itWeb3('With escrow', async ({ api, web3 }) => {
+ itWeb3('With escrow', async ({api, web3}) => {
const matcherOwner = await createEthAccountWithBalance(api, web3);
const escrow = await createEthAccountWithBalance(api, web3);
- const Matcher = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/MarketPlaceKSM.abi`)).toString()), undefined, {
+ const matcherContract = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/MarketPlaceKSM.abi`)).toString()), undefined, {
from: matcherOwner,
...GAS_ARGS,
});
- const matcher = await Matcher.deploy({ data: (await readFile(`${__dirname}/MarketPlaceKSM.bin`)).toString(), arguments: [escrow] }).send({ from: matcherOwner });
-
+ const matcher = await matcherContract.deploy({data: (await readFile(`${__dirname}/MarketPlaceKSM.bin`)).toString(), arguments: [escrow]}).send({from: matcherOwner});
+
const ksmToken = 11;
const alice = privateKey('//Alice');
const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- const evmCollection = new web3.eth.Contract(nonFungibleAbi as any, collectionIdToAddress(collectionId), { from: matcherOwner });
+ const evmCollection = new web3.eth.Contract(nonFungibleAbi as any, collectionIdToAddress(collectionId), {from: matcherOwner});
const seller = privateKey('//Bob');
-
+
const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT', seller.address);
// To transfer item to matcher it first needs to be transfered to EVM account of bob
- await transferExpectSuccess(collectionId, tokenId, seller, {ethereum: subToEth(seller.address)});
+ await transferExpectSuccess(collectionId, tokenId, seller, {Ethereum: subToEth(seller.address)});
// Fees will be paid from EVM account, so we should have some balance here
await transferBalanceExpectSuccess(api, seller, evmToAddress(subToEth(seller.address)), 10n ** 18n);
await transferBalanceExpectSuccess(api, alice, evmToAddress(subToEth(alice.address)), 10n ** 18n);
- await waitNewBlocks(api, 1);
// Token is owned by seller initially
- expect(await queryNftOwner(api, collectionId, tokenId)).to.be.deep.equal({ ethereum: subToEthLowercase(seller.address) });
+ expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal({Ethereum: subToEthLowercase(seller.address)});
// Ask
{
await executeEthTxOnSub(api, seller, evmCollection, m => m.approve(matcher.options.address, tokenId));
await executeEthTxOnSub(api, seller, matcher, m => m.setAsk(PRICE, ksmToken, evmCollection.options.address, tokenId, 1));
}
-
+
// Token is transferred to matcher
- expect(await queryNftOwner(api, collectionId, tokenId)).to.be.deep.equal({ ethereum: matcher.options.address.toLowerCase() });
+ expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal({Ethereum: matcher.options.address.toLowerCase()});
// Give buyer KSM
- await matcher.methods.deposit(PRICE, ksmToken, subToEth(alice.address)).send({ from: escrow });
- await waitNewBlocks(api, 1);
-
+ await matcher.methods.deposit(PRICE, ksmToken, subToEth(alice.address)).send({from: escrow});
+
// Buy
{
expect(await matcher.methods.escrowBalance(ksmToken, subToEth(seller.address)).call()).to.be.equal('0');
expect(await matcher.methods.escrowBalance(ksmToken, subToEth(alice.address)).call()).to.be.equal(PRICE.toString());
await executeEthTxOnSub(api, alice, matcher, m => m.buy(evmCollection.options.address, tokenId));
- await waitNewBlocks(api, 1);
// Price is removed from buyer balance, and added to seller
expect(await matcher.methods.escrowBalance(ksmToken, subToEth(alice.address)).call()).to.be.equal('0');
@@ -187,12 +181,12 @@
}
// Token is transferred to evm account of alice
- expect(await queryNftOwner(api, collectionId, tokenId)).to.be.deep.equal({ ethereum: subToEthLowercase(alice.address) });
-
+ expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal({Ethereum: subToEthLowercase(alice.address)});
+
// Transfer token to substrate side of alice
- await transferFromExpectSuccess(collectionId, tokenId, alice, { ethereum: subToEth(alice.address) }, { substrate: alice.address });
-
+ await transferFromExpectSuccess(collectionId, tokenId, alice, {Ethereum: subToEth(alice.address)}, {Substrate: alice.address});
+
// Token is transferred to substrate account of alice, seller received funds
- expect(await queryNftOwner(api, collectionId, tokenId)).to.be.deep.equal({ substrate: alice.address });
+ expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal({Substrate: alice.address});
});
});
tests/src/eth/metadata.test.tsdiffbeforeafterboth--- a/tests/src/eth/metadata.test.ts
+++ b/tests/src/eth/metadata.test.ts
@@ -3,35 +3,35 @@
// file 'LICENSE', which is part of this source code package.
//
-import { expect } from 'chai';
-import { createCollectionExpectSuccess } from '../util/helpers';
-import { collectionIdToAddress, createEthAccountWithBalance, GAS_ARGS, itWeb3 } from './util/helpers';
+import {expect} from 'chai';
+import {createCollectionExpectSuccess} from '../util/helpers';
+import {collectionIdToAddress, createEthAccountWithBalance, GAS_ARGS, itWeb3} from './util/helpers';
import fungibleMetadataAbi from './fungibleMetadataAbi.json';
describe('Common metadata', () => {
- itWeb3('Returns collection name', async ({ api, web3 }) => {
+ itWeb3('Returns collection name', async ({api, web3}) => {
const collection = await createCollectionExpectSuccess({
name: 'token name',
- mode: { type: 'NFT' },
+ mode: {type: 'NFT'},
});
const caller = await createEthAccountWithBalance(api, web3);
const address = collectionIdToAddress(collection);
- const contract = new web3.eth.Contract(fungibleMetadataAbi as any, address, { from: caller, ...GAS_ARGS });
+ const contract = new web3.eth.Contract(fungibleMetadataAbi as any, address, {from: caller, ...GAS_ARGS});
const name = await contract.methods.name().call();
expect(name).to.equal('token name');
});
- itWeb3('Returns symbol name', async ({ api, web3 }) => {
+ itWeb3('Returns symbol name', async ({api, web3}) => {
const collection = await createCollectionExpectSuccess({
tokenPrefix: 'TOK',
- mode: { type: 'NFT' },
+ mode: {type: 'NFT'},
});
const caller = await createEthAccountWithBalance(api, web3);
const address = collectionIdToAddress(collection);
- const contract = new web3.eth.Contract(fungibleMetadataAbi as any, address, { from: caller, ...GAS_ARGS });
+ const contract = new web3.eth.Contract(fungibleMetadataAbi as any, address, {from: caller, ...GAS_ARGS});
const symbol = await contract.methods.symbol().call();
expect(symbol).to.equal('TOK');
@@ -39,14 +39,14 @@
});
describe('Fungible metadata', () => {
- itWeb3('Returns fungible decimals', async ({ api, web3 }) => {
+ itWeb3('Returns fungible decimals', async ({api, web3}) => {
const collection = await createCollectionExpectSuccess({
- mode: { type: 'Fungible', decimalPoints: 6 },
+ mode: {type: 'Fungible', decimalPoints: 6},
});
const caller = await createEthAccountWithBalance(api, web3);
const address = collectionIdToAddress(collection);
- const contract = new web3.eth.Contract(fungibleMetadataAbi as any, address, { from: caller, ...GAS_ARGS });
+ const contract = new web3.eth.Contract(fungibleMetadataAbi as any, address, {from: caller, ...GAS_ARGS});
const decimals = await contract.methods.decimals().call();
expect(+decimals).to.equal(6);
tests/src/eth/migration.test.tsdiffbeforeafterboth--- a/tests/src/eth/migration.test.ts
+++ b/tests/src/eth/migration.test.ts
@@ -1,10 +1,10 @@
-import { expect } from 'chai';
+import {expect} from 'chai';
import privateKey from '../substrate/privateKey';
-import { submitTransactionAsync } from '../substrate/substrate-api';
-import { createEthAccountWithBalance, GAS_ARGS, itWeb3 } from './util/helpers';
+import {submitTransactionAsync} from '../substrate/substrate-api';
+import {createEthAccountWithBalance, GAS_ARGS, itWeb3} from './util/helpers';
describe('EVM Migrations', () => {
- itWeb3('Deploy contract saved state', async ({ web3, api }) => {
+ itWeb3('Deploy contract saved state', async ({web3, api}) => {
/*
contract StatefulContract {
uint counter;
@@ -41,9 +41,9 @@
const alice = privateKey('//Alice');
const caller = await createEthAccountWithBalance(api, web3);
- await submitTransactionAsync(alice, api.tx.sudo.sudo(api.tx.evmMigration.begin(ADDRESS)));
- await submitTransactionAsync(alice, api.tx.sudo.sudo(api.tx.evmMigration.setData(ADDRESS, DATA)));
- await submitTransactionAsync(alice, api.tx.sudo.sudo(api.tx.evmMigration.finish(ADDRESS, CODE)));
+ await submitTransactionAsync(alice, api.tx.sudo.sudo(api.tx.evmMigration.begin(ADDRESS) as any));
+ await submitTransactionAsync(alice, api.tx.sudo.sudo(api.tx.evmMigration.setData(ADDRESS, DATA as any) as any));
+ await submitTransactionAsync(alice, api.tx.sudo.sudo(api.tx.evmMigration.finish(ADDRESS, CODE) as any));
const contract = new web3.eth.Contract([
{
@@ -72,11 +72,11 @@
stateMutability: 'view',
type: 'function',
},
- ], ADDRESS, { from: caller, ...GAS_ARGS });
-
+ ], ADDRESS, {from: caller, ...GAS_ARGS});
+
expect(await contract.methods.counterValue().call()).to.be.equal('10');
for (let i = 1; i <= 4; i++) {
expect(await contract.methods.get(i).call()).to.be.equal(i.toString());
}
});
-});
\ No newline at end of file
+});
tests/src/eth/nonFungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/nonFungible.test.ts
+++ b/tests/src/eth/nonFungible.test.ts
@@ -4,41 +4,39 @@
//
import privateKey from '../substrate/privateKey';
-import { approveExpectSuccess, burnItemExpectSuccess, createCollectionExpectSuccess, createItemExpectSuccess, setVariableMetaDataExpectSuccess, transferExpectSuccess, transferFromExpectSuccess, UNIQUE, setMetadataUpdatePermissionFlagExpectSuccess } from '../util/helpers';
-import { collectionIdToAddress, createEthAccount, createEthAccountWithBalance, GAS_ARGS, itWeb3, normalizeEvents, recordEthFee, recordEvents, subToEth, transferBalanceToEth } from './util/helpers';
+import {approveExpectSuccess, burnItemExpectSuccess, createCollectionExpectSuccess, createItemExpectSuccess, setVariableMetaDataExpectSuccess, transferExpectSuccess, transferFromExpectSuccess, UNIQUE, setMetadataUpdatePermissionFlagExpectSuccess} from '../util/helpers';
+import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, GAS_ARGS, itWeb3, normalizeEvents, recordEthFee, recordEvents, subToEth, transferBalanceToEth} from './util/helpers';
import nonFungibleAbi from './nonFungibleAbi.json';
-import { expect } from 'chai';
-import waitNewBlocks from '../substrate/wait-new-blocks';
-import { submitTransactionAsync } from '../substrate/substrate-api';
+import {expect} from 'chai';
+import {submitTransactionAsync} from '../substrate/substrate-api';
describe('NFT: Information getting', () => {
- itWeb3('totalSupply', async ({ api, web3 }) => {
+ itWeb3('totalSupply', async ({api, web3}) => {
const collection = await createCollectionExpectSuccess({
- mode: { type: 'NFT' },
+ mode: {type: 'NFT'},
});
const alice = privateKey('//Alice');
const caller = await createEthAccountWithBalance(api, web3);
- await createItemExpectSuccess(alice, collection, 'NFT', { substrate: alice.address });
+ await createItemExpectSuccess(alice, collection, 'NFT', {Substrate: alice.address});
const address = collectionIdToAddress(collection);
const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});
const totalSupply = await contract.methods.totalSupply().call();
- // FIXME: always equals to 0, because this method is not implemented
- expect(totalSupply).to.equal('0');
+ expect(totalSupply).to.equal('1');
});
- itWeb3('balanceOf', async ({ api, web3 }) => {
+ itWeb3('balanceOf', async ({api, web3}) => {
const collection = await createCollectionExpectSuccess({
- mode: { type: 'NFT' },
+ mode: {type: 'NFT'},
});
const alice = privateKey('//Alice');
const caller = await createEthAccountWithBalance(api, web3);
- await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: caller });
- await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: caller });
- await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: caller });
+ await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum:caller});
+ await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: caller});
+ await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: caller});
const address = collectionIdToAddress(collection);
const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});
@@ -47,14 +45,14 @@
expect(balance).to.equal('3');
});
- itWeb3('ownerOf', async ({ api, web3 }) => {
+ itWeb3('ownerOf', async ({api, web3}) => {
const collection = await createCollectionExpectSuccess({
- mode: { type: 'NFT' },
+ mode: {type: 'NFT'},
});
const alice = privateKey('//Alice');
const caller = await createEthAccountWithBalance(api, web3);
- const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: caller });
+ const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: caller});
const address = collectionIdToAddress(collection);
const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});
@@ -65,14 +63,14 @@
});
describe('NFT: Plain calls', () => {
- itWeb3('Can perform mint()', async ({ web3, api }) => {
+ itWeb3('Can perform mint()', async ({web3, api}) => {
const collection = await createCollectionExpectSuccess({
- mode: { type: 'NFT' },
+ mode: {type: 'NFT'},
});
const alice = privateKey('//Alice');
const caller = await createEthAccountWithBalance(api, web3);
- const changeAdminTx = api.tx.nft.addCollectionAdmin(collection, { ethereum: caller });
+ const changeAdminTx = api.tx.nft.addCollectionAdmin(collection, {Ethereum: caller});
await submitTransactionAsync(alice, changeAdminTx);
const receiver = createEthAccount(web3);
@@ -101,18 +99,17 @@
},
]);
- await waitNewBlocks(api, 1);
expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');
}
});
- itWeb3('Can perform mintBulk()', async ({ web3, api }) => {
+ itWeb3('Can perform mintBulk()', async ({web3, api}) => {
const collection = await createCollectionExpectSuccess({
- mode: { type: 'NFT' },
+ mode: {type: 'NFT'},
});
const alice = privateKey('//Alice');
const caller = await createEthAccountWithBalance(api, web3);
- const changeAdminTx = api.tx.nft.addCollectionAdmin(collection, { ethereum: caller });
+ const changeAdminTx = api.tx.nft.addCollectionAdmin(collection, {Ethereum: caller});
await submitTransactionAsync(alice, changeAdminTx);
const receiver = createEthAccount(web3);
@@ -129,7 +126,7 @@
[+nextTokenId + 1, 'Test URI 1'],
[+nextTokenId + 2, 'Test URI 2'],
],
- ).send({ from: caller });
+ ).send({from: caller});
const events = normalizeEvents(result.events);
expect(events).to.be.deep.equal([
@@ -162,14 +159,13 @@
},
]);
- await waitNewBlocks(api, 1);
expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI 0');
expect(await contract.methods.tokenURI(+nextTokenId + 1).call()).to.be.equal('Test URI 1');
expect(await contract.methods.tokenURI(+nextTokenId + 2).call()).to.be.equal('Test URI 2');
}
});
- itWeb3('Can perform burn()', async ({ web3, api }) => {
+ itWeb3('Can perform burn()', async ({web3, api}) => {
const collection = await createCollectionExpectSuccess({
mode: {type: 'NFT'},
});
@@ -177,15 +173,15 @@
const owner = await createEthAccountWithBalance(api, web3);
- const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner });
-
+ const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: owner});
+
const address = collectionIdToAddress(collection);
const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: owner, ...GAS_ARGS});
{
- const result = await contract.methods.burn(tokenId).send({ from: owner });
+ const result = await contract.methods.burn(tokenId).send({from: owner});
const events = normalizeEvents(result.events);
-
+
expect(events).to.be.deep.equal([
{
address,
@@ -200,16 +196,16 @@
}
});
- itWeb3('Can perform approve()', async ({ web3, api }) => {
+ itWeb3('Can perform approve()', async ({web3, api}) => {
const collection = await createCollectionExpectSuccess({
- mode: { type: 'NFT' },
+ mode: {type: 'NFT'},
});
const alice = privateKey('//Alice');
const owner = createEthAccount(web3);
await transferBalanceToEth(api, alice, owner, 999999999999999);
- const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner });
+ const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: owner});
const spender = createEthAccount(web3);
@@ -217,7 +213,7 @@
const contract = new web3.eth.Contract(nonFungibleAbi as any, address);
{
- const result = await contract.methods.approve(spender, tokenId).send({ from: owner, gas: '0x1000000', gasPrice: '0x01' });
+ const result = await contract.methods.approve(spender, tokenId).send({from: owner, gas: '0x1000000', gasPrice: '0x01'});
const events = normalizeEvents(result.events);
expect(events).to.be.deep.equal([
@@ -234,16 +230,16 @@
}
});
- itWeb3('Can perform transferFrom()', async ({ web3, api }) => {
+ itWeb3('Can perform transferFrom()', async ({web3, api}) => {
const collection = await createCollectionExpectSuccess({
- mode: { type: 'NFT' },
+ mode: {type: 'NFT'},
});
const alice = privateKey('//Alice');
const owner = createEthAccount(web3);
await transferBalanceToEth(api, alice, owner, 999999999999999);
- const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner });
+ const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: owner});
const spender = createEthAccount(web3);
await transferBalanceToEth(api, alice, spender, 999999999999999);
@@ -253,10 +249,10 @@
const address = collectionIdToAddress(collection);
const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: owner, ...GAS_ARGS});
- await contract.methods.approve(spender, tokenId).send({ from: owner });
+ await contract.methods.approve(spender, tokenId).send({from: owner});
{
- const result = await contract.methods.transferFrom(owner, receiver, tokenId).send({ from: spender });
+ const result = await contract.methods.transferFrom(owner, receiver, tokenId).send({from: spender});
const events = normalizeEvents(result.events);
expect(events).to.be.deep.equal([
{
@@ -282,16 +278,16 @@
}
});
- itWeb3('Can perform transfer()', async ({ web3, api }) => {
+ itWeb3('Can perform transfer()', async ({web3, api}) => {
const collection = await createCollectionExpectSuccess({
- mode: { type: 'NFT' },
+ mode: {type: 'NFT'},
});
const alice = privateKey('//Alice');
const owner = createEthAccount(web3);
await transferBalanceToEth(api, alice, owner, 999999999999999);
- const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner });
+ const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: owner});
const receiver = createEthAccount(web3);
await transferBalanceToEth(api, alice, receiver, 999999999999999);
@@ -300,8 +296,7 @@
const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: owner, ...GAS_ARGS});
{
- const result = await contract.methods.transfer(receiver, tokenId).send({ from: owner });
- await waitNewBlocks(api, 1);
+ const result = await contract.methods.transfer(receiver, tokenId).send({from: owner});
const events = normalizeEvents(result.events);
expect(events).to.be.deep.equal([
{
@@ -327,105 +322,104 @@
}
});
- itWeb3('Can perform getVariableMetadata', async ({ web3, api }) => {
+ itWeb3('Can perform getVariableMetadata', async ({web3, api}) => {
const collection = await createCollectionExpectSuccess({
- mode: { type: 'NFT' },
+ mode: {type: 'NFT'},
});
const alice = privateKey('//Alice');
const owner = await createEthAccountWithBalance(api, web3);
- const item = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner });
+ const item = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: owner});
await setMetadataUpdatePermissionFlagExpectSuccess(alice, collection, 'Admin');
await setVariableMetaDataExpectSuccess(alice, collection, item, [1, 2, 3]);
const address = collectionIdToAddress(collection);
- const contract = new web3.eth.Contract(nonFungibleAbi as any, address, { from: owner, ...GAS_ARGS });
-
+ const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: owner, ...GAS_ARGS});
+
expect(await contract.methods.getVariableMetadata(item).call()).to.be.equal('0x010203');
});
- itWeb3('Can perform setVariableMetadata', async ({ web3, api }) => {
+ itWeb3('Can perform setVariableMetadata', async ({web3, api}) => {
const collection = await createCollectionExpectSuccess({
- mode: { type: 'NFT' },
+ mode: {type: 'NFT'},
});
const alice = privateKey('//Alice');
const owner = await createEthAccountWithBalance(api, web3);
- const item = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner });
+ const item = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: owner});
const address = collectionIdToAddress(collection);
- const contract = new web3.eth.Contract(nonFungibleAbi as any, address, { from: owner, ...GAS_ARGS });
-
- expect(await contract.methods.setVariableMetadata(item, '0x010203').send({ from: owner }));
- await waitNewBlocks(api, 1);
+ const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: owner, ...GAS_ARGS});
+
+ expect(await contract.methods.setVariableMetadata(item, '0x010203').send({from: owner}));
expect(await contract.methods.getVariableMetadata(item).call()).to.be.equal('0x010203');
});
});
describe('NFT: Fees', () => {
- itWeb3('approve() call fee is less than 0.2UNQ', async ({ web3, api }) => {
+ itWeb3('approve() call fee is less than 0.2UNQ', async ({web3, api}) => {
const collection = await createCollectionExpectSuccess({
- mode: { type: 'NFT' },
+ mode: {type: 'NFT'},
});
const alice = privateKey('//Alice');
const owner = await createEthAccountWithBalance(api, web3);
const spender = createEthAccount(web3);
- const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner });
+ const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: owner});
const address = collectionIdToAddress(collection);
- const contract = new web3.eth.Contract(nonFungibleAbi as any, address, { from: owner, ...GAS_ARGS });
+ const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: owner, ...GAS_ARGS});
- const cost = await recordEthFee(api, owner, () => contract.methods.approve(spender, tokenId).send({ from: owner }));
+ const cost = await recordEthFee(api, owner, () => contract.methods.approve(spender, tokenId).send({from: owner}));
expect(cost < BigInt(0.2 * Number(UNIQUE)));
});
- itWeb3('transferFrom() call fee is less than 0.2UNQ', async ({ web3, api }) => {
+ itWeb3('transferFrom() call fee is less than 0.2UNQ', async ({web3, api}) => {
const collection = await createCollectionExpectSuccess({
- mode: { type: 'NFT' },
+ mode: {type: 'NFT'},
});
const alice = privateKey('//Alice');
-
+
const owner = await createEthAccountWithBalance(api, web3);
const spender = await createEthAccountWithBalance(api, web3);
- const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner });
+ const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: owner});
const address = collectionIdToAddress(collection);
- const contract = new web3.eth.Contract(nonFungibleAbi as any, address, { from: owner, ...GAS_ARGS });
+ const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: owner, ...GAS_ARGS});
- await contract.methods.approve(spender, tokenId).send({ from: owner });
+ await contract.methods.approve(spender, tokenId).send({from: owner});
- const cost = await recordEthFee(api, spender, () => contract.methods.transferFrom(owner, spender, tokenId).send({ from: spender }));
+ const cost = await recordEthFee(api, spender, () => contract.methods.transferFrom(owner, spender, tokenId).send({from: spender}));
expect(cost < BigInt(0.2 * Number(UNIQUE)));
});
- itWeb3('transfer() call fee is less than 0.2UNQ', async ({ web3, api }) => {
+ itWeb3('transfer() call fee is less than 0.2UNQ', async ({web3, api}) => {
const collection = await createCollectionExpectSuccess({
- mode: { type: 'NFT' },
+ mode: {type: 'NFT'},
});
const alice = privateKey('//Alice');
const owner = await createEthAccountWithBalance(api, web3);
const receiver = createEthAccount(web3);
- const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner });
+ const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: owner});
const address = collectionIdToAddress(collection);
- const contract = new web3.eth.Contract(nonFungibleAbi as any, address, { from: owner, ...GAS_ARGS });
+ const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: owner, ...GAS_ARGS});
- const cost = await recordEthFee(api, owner, () => contract.methods.transfer(receiver, tokenId).send({ from: owner }));
+ const cost = await recordEthFee(api, owner, () => contract.methods.transfer(receiver, tokenId).send({from: owner}));
expect(cost < BigInt(0.2 * Number(UNIQUE)));
});
});
describe('NFT: Substrate calls', () => {
- itWeb3('Events emitted for mint()', async ({ web3 }) => {
+ itWeb3('Events emitted for mint()', async ({web3}) => {
const collection = await createCollectionExpectSuccess({
- mode: { type: 'NFT' },
+ mode: {type: 'NFT'},
});
const alice = privateKey('//Alice');
@@ -450,9 +444,9 @@
]);
});
- itWeb3('Events emitted for burn()', async ({ web3 }) => {
+ itWeb3('Events emitted for burn()', async ({web3}) => {
const collection = await createCollectionExpectSuccess({
- mode: { type: 'NFT' },
+ mode: {type: 'NFT'},
});
const alice = privateKey('//Alice');
@@ -477,9 +471,9 @@
]);
});
- itWeb3('Events emitted for approve()', async ({ web3 }) => {
+ itWeb3('Events emitted for approve()', async ({web3}) => {
const collection = await createCollectionExpectSuccess({
- mode: { type: 'NFT' },
+ mode: {type: 'NFT'},
});
const alice = privateKey('//Alice');
@@ -491,7 +485,7 @@
const contract = new web3.eth.Contract(nonFungibleAbi as any, address);
const events = await recordEvents(contract, async () => {
- await approveExpectSuccess(collection, tokenId, alice, { ethereum: receiver }, 1);
+ await approveExpectSuccess(collection, tokenId, alice, {Ethereum: receiver}, 1);
});
expect(events).to.be.deep.equal([
@@ -507,9 +501,9 @@
]);
});
- itWeb3('Events emitted for transferFrom()', async ({ web3 }) => {
+ itWeb3('Events emitted for transferFrom()', async ({web3}) => {
const collection = await createCollectionExpectSuccess({
- mode: { type: 'NFT' },
+ mode: {type: 'NFT'},
});
const alice = privateKey('//Alice');
const bob = privateKey('//Bob');
@@ -517,13 +511,13 @@
const receiver = createEthAccount(web3);
const tokenId = await createItemExpectSuccess(alice, collection, 'NFT');
- await approveExpectSuccess(collection, tokenId, alice, bob, 1);
+ await approveExpectSuccess(collection, tokenId, alice, bob.address, 1);
const address = collectionIdToAddress(collection);
const contract = new web3.eth.Contract(nonFungibleAbi as any, address);
const events = await recordEvents(contract, async () => {
- await transferFromExpectSuccess(collection, tokenId, bob, alice, { ethereum: receiver }, 1, 'NFT');
+ await transferFromExpectSuccess(collection, tokenId, bob, alice, {Ethereum: receiver}, 1, 'NFT');
});
expect(events).to.be.deep.equal([
@@ -539,9 +533,9 @@
]);
});
- itWeb3('Events emitted for transfer()', async ({ web3 }) => {
+ itWeb3('Events emitted for transfer()', async ({web3}) => {
const collection = await createCollectionExpectSuccess({
- mode: { type: 'NFT' },
+ mode: {type: 'NFT'},
});
const alice = privateKey('//Alice');
@@ -553,7 +547,7 @@
const contract = new web3.eth.Contract(nonFungibleAbi as any, address);
const events = await recordEvents(contract, async () => {
- await transferExpectSuccess(collection, tokenId, alice, { ethereum: receiver }, 1, 'NFT');
+ await transferExpectSuccess(collection, tokenId, alice, {Ethereum: receiver}, 1, 'NFT');
});
expect(events).to.be.deep.equal([
tests/src/eth/payable.test.tsdiffbeforeafterboth--- a/tests/src/eth/payable.test.ts
+++ b/tests/src/eth/payable.test.ts
@@ -1,19 +1,17 @@
-import { expect } from 'chai';
+import {expect} from 'chai';
import privateKey from '../substrate/privateKey';
-import { submitTransactionAsync } from '../substrate/substrate-api';
-import waitNewBlocks from '../substrate/wait-new-blocks';
-import { createEthAccountWithBalance, deployCollector, GAS_ARGS, itWeb3, subToEth } from './util/helpers';
+import {submitTransactionAsync} from '../substrate/substrate-api';
+import {createEthAccountWithBalance, deployCollector, GAS_ARGS, itWeb3, subToEth} from './util/helpers';
import {evmToAddress} from '@polkadot/util-crypto';
-import { getGenericResult } from '../util/helpers';
-import { getBalanceSingle, transferBalanceExpectSuccess } from '../substrate/get-balance';
+import {getGenericResult} from '../util/helpers';
+import {getBalanceSingle, transferBalanceExpectSuccess} from '../substrate/get-balance';
-describe('EVM payable contracts', ()=>{
+describe('EVM payable contracts', () => {
itWeb3('Evm contract can receive wei from eth account', async ({api, web3}) => {
const deployer = await createEthAccountWithBalance(api, web3);
const contract = await deployCollector(web3, deployer);
await web3.eth.sendTransaction({from: deployer, to: contract.options.address, value: '10000', ...GAS_ARGS});
- await waitNewBlocks(api, 1);
expect(await contract.methods.getCollected().call()).to.be.equal('10000');
});
@@ -52,7 +50,7 @@
const alice = privateKey('//Alice');
await transferBalanceExpectSuccess(api, alice, evmToAddress(contract.options.address), '10000');
-
+
expect(await contract.methods.getUnaccounted().call()).to.be.equal('10000');
});
@@ -65,7 +63,6 @@
const alice = privateKey('//Alice');
await web3.eth.sendTransaction({from: deployer, to: contract.options.address, value: CONTRACT_BALANCE.toString(), ...GAS_ARGS});
- await waitNewBlocks(api, 1);
const receiver = privateKey(`//Receiver${Date.now()}`);
@@ -95,4 +92,4 @@
expect(finalReceiverBalance > initialReceiverBalance).to.be.true;
}
});
-});
\ No newline at end of file
+});
tests/src/eth/proxy/fungibleProxy.test.tsdiffbeforeafterboth--- a/tests/src/eth/proxy/fungibleProxy.test.ts
+++ b/tests/src/eth/proxy/fungibleProxy.test.ts
@@ -4,53 +4,52 @@
//
import privateKey from '../../substrate/privateKey';
-import { createCollectionExpectSuccess, createFungibleItemExpectSuccess } from '../../util/helpers';
-import { collectionIdToAddress, createEthAccount, createEthAccountWithBalance, GAS_ARGS, itWeb3, normalizeEvents } from '../util/helpers';
+import {createCollectionExpectSuccess, createFungibleItemExpectSuccess} from '../../util/helpers';
+import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, GAS_ARGS, itWeb3, normalizeEvents} from '../util/helpers';
import fungibleAbi from '../fungibleAbi.json';
-import { expect } from 'chai';
-import { ApiPromise } from '@polkadot/api';
+import {expect} from 'chai';
+import {ApiPromise} from '@polkadot/api';
import Web3 from 'web3';
-import { readFile } from 'fs/promises';
+import {readFile} from 'fs/promises';
async function proxyWrap(api: ApiPromise, web3: Web3, wrapped: any) {
// Proxy owner has no special privilegies, we don't need to reuse them
const owner = await createEthAccountWithBalance(api, web3);
- const Proxy = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/UniqueFungibleProxy.abi`)).toString()), undefined, {
+ const proxyContract = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/UniqueFungibleProxy.abi`)).toString()), undefined, {
from: owner,
...GAS_ARGS,
});
- const proxy = await Proxy.deploy({ data: (await readFile(`${__dirname}/UniqueFungibleProxy.bin`)).toString(), arguments: [wrapped.options.address] }).send({ from: owner });
+ const proxy = await proxyContract.deploy({data: (await readFile(`${__dirname}/UniqueFungibleProxy.bin`)).toString(), arguments: [wrapped.options.address]}).send({from: owner});
return proxy;
}
describe('Fungible (Via EVM proxy): Information getting', () => {
- itWeb3('totalSupply', async ({ api, web3 }) => {
+ itWeb3('totalSupply', async ({api, web3}) => {
const collection = await createCollectionExpectSuccess({
name: 'token name',
- mode: { type: 'Fungible', decimalPoints: 0 },
+ mode: {type: 'Fungible', decimalPoints: 0},
});
const alice = privateKey('//Alice');
const caller = await createEthAccountWithBalance(api, web3);
-
- await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { substrate: alice.address });
+ await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Substrate: alice.address});
+
const address = collectionIdToAddress(collection);
const contract = await proxyWrap(api, web3, new web3.eth.Contract(fungibleAbi as any, address, {from: caller, ...GAS_ARGS}));
const totalSupply = await contract.methods.totalSupply().call();
- // FIXME: always equals to 0, because this method is not implemented
- expect(totalSupply).to.equal('0');
+ expect(totalSupply).to.equal('200');
});
- itWeb3('balanceOf', async ({ api, web3 }) => {
+ itWeb3('balanceOf', async ({api, web3}) => {
const collection = await createCollectionExpectSuccess({
name: 'token name',
- mode: { type: 'Fungible', decimalPoints: 0 },
+ mode: {type: 'Fungible', decimalPoints: 0},
});
const alice = privateKey('//Alice');
const caller = await createEthAccountWithBalance(api, web3);
- await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { ethereum: caller });
+ await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: caller});
const address = collectionIdToAddress(collection);
const contract = await proxyWrap(api, web3, new web3.eth.Contract(fungibleAbi as any, address, {from: caller, ...GAS_ARGS}));
@@ -61,10 +60,10 @@
});
describe('Fungible (Via EVM proxy): Plain calls', () => {
- itWeb3('Can perform approve()', async ({ web3, api }) => {
+ itWeb3('Can perform approve()', async ({web3, api}) => {
const collection = await createCollectionExpectSuccess({
name: 'token name',
- mode: { type: 'Fungible', decimalPoints: 0 },
+ mode: {type: 'Fungible', decimalPoints: 0},
});
const alice = privateKey('//Alice');
const caller = await createEthAccountWithBalance(api, web3);
@@ -72,7 +71,7 @@
const address = collectionIdToAddress(collection);
const contract = await proxyWrap(api, web3, new web3.eth.Contract(fungibleAbi as any, address, {from: caller, ...GAS_ARGS}));
- await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { ethereum: contract.options.address });
+ await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: contract.options.address});
{
const result = await contract.methods.approve(spender, 100).send({from: caller});
@@ -97,21 +96,21 @@
}
});
- itWeb3('Can perform transferFrom()', async ({ web3, api }) => {
+ itWeb3('Can perform transferFrom()', async ({web3, api}) => {
const collection = await createCollectionExpectSuccess({
name: 'token name',
- mode: { type: 'Fungible', decimalPoints: 0 },
+ mode: {type: 'Fungible', decimalPoints: 0},
});
const alice = privateKey('//Alice');
const caller = await createEthAccountWithBalance(api, web3);
const owner = await createEthAccountWithBalance(api, web3);
- await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { ethereum: owner });
+ await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: owner});
const receiver = createEthAccount(web3);
const address = collectionIdToAddress(collection);
- const evmCollection = new web3.eth.Contract(fungibleAbi as any, address, { from: caller, ...GAS_ARGS });
+ const evmCollection = new web3.eth.Contract(fungibleAbi as any, address, {from: caller, ...GAS_ARGS});
const contract = await proxyWrap(api, web3, evmCollection);
await evmCollection.methods.approve(contract.options.address, 100).send({from: owner});
@@ -152,10 +151,10 @@
}
});
- itWeb3('Can perform transfer()', async ({ web3, api }) => {
+ itWeb3('Can perform transfer()', async ({web3, api}) => {
const collection = await createCollectionExpectSuccess({
name: 'token name',
- mode: { type: 'Fungible', decimalPoints: 0 },
+ mode: {type: 'Fungible', decimalPoints: 0},
});
const alice = privateKey('//Alice');
const caller = await createEthAccountWithBalance(api, web3);
@@ -163,10 +162,10 @@
const address = collectionIdToAddress(collection);
const contract = await proxyWrap(api, web3, new web3.eth.Contract(fungibleAbi as any, address, {from: caller, ...GAS_ARGS}));
- await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { ethereum: contract.options.address });
+ await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: contract.options.address});
{
- const result = await contract.methods.transfer(receiver, 50).send({ from: caller});
+ const result = await contract.methods.transfer(receiver, 50).send({from: caller});
const events = normalizeEvents(result.events);
expect(events).to.be.deep.equal([
{
tests/src/eth/proxy/nonFungibleProxy.test.tsdiffbeforeafterboth--- a/tests/src/eth/proxy/nonFungibleProxy.test.ts
+++ b/tests/src/eth/proxy/nonFungibleProxy.test.ts
@@ -4,55 +4,53 @@
//
import privateKey from '../../substrate/privateKey';
-import { createCollectionExpectSuccess, createItemExpectSuccess, setVariableMetaDataExpectSuccess, setMetadataUpdatePermissionFlagExpectSuccess } from '../../util/helpers';
-import { collectionIdToAddress, createEthAccount, createEthAccountWithBalance, GAS_ARGS, itWeb3, normalizeEvents } from '../util/helpers';
+import {createCollectionExpectSuccess, createItemExpectSuccess, setVariableMetaDataExpectSuccess, setMetadataUpdatePermissionFlagExpectSuccess} from '../../util/helpers';
+import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, GAS_ARGS, itWeb3, normalizeEvents} from '../util/helpers';
import nonFungibleAbi from '../nonFungibleAbi.json';
-import { expect } from 'chai';
-import waitNewBlocks from '../../substrate/wait-new-blocks';
-import { submitTransactionAsync } from '../../substrate/substrate-api';
+import {expect} from 'chai';
+import {submitTransactionAsync} from '../../substrate/substrate-api';
import Web3 from 'web3';
-import { readFile } from 'fs/promises';
-import { ApiPromise } from '@polkadot/api';
+import {readFile} from 'fs/promises';
+import {ApiPromise} from '@polkadot/api';
async function proxyWrap(api: ApiPromise, web3: Web3, wrapped: any) {
// Proxy owner has no special privilegies, we don't need to reuse them
const owner = await createEthAccountWithBalance(api, web3);
- const Proxy = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/UniqueNFTProxy.abi`)).toString()), undefined, {
+ const proxyContract = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/UniqueNFTProxy.abi`)).toString()), undefined, {
from: owner,
...GAS_ARGS,
});
- const proxy = await Proxy.deploy({ data: (await readFile(`${__dirname}/UniqueNFTProxy.bin`)).toString(), arguments: [wrapped.options.address] }).send({ from: owner });
+ const proxy = await proxyContract.deploy({data: (await readFile(`${__dirname}/UniqueNFTProxy.bin`)).toString(), arguments: [wrapped.options.address]}).send({from: owner});
return proxy;
}
describe('NFT (Via EVM proxy): Information getting', () => {
- itWeb3('totalSupply', async ({ api, web3 }) => {
+ itWeb3('totalSupply', async ({api, web3}) => {
const collection = await createCollectionExpectSuccess({
- mode: { type: 'NFT' },
+ mode: {type: 'NFT'},
});
const alice = privateKey('//Alice');
const caller = await createEthAccountWithBalance(api, web3);
- await createItemExpectSuccess(alice, collection, 'NFT', { substrate: alice.address });
+ await createItemExpectSuccess(alice, collection, 'NFT', {Substrate: alice.address});
const address = collectionIdToAddress(collection);
const contract = await proxyWrap(api, web3, new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS}));
const totalSupply = await contract.methods.totalSupply().call();
- // FIXME: always equals to 0, because this method is not implemented
- expect(totalSupply).to.equal('0');
+ expect(totalSupply).to.equal('1');
});
- itWeb3('balanceOf', async ({ api, web3 }) => {
+ itWeb3('balanceOf', async ({api, web3}) => {
const collection = await createCollectionExpectSuccess({
- mode: { type: 'NFT' },
+ mode: {type: 'NFT'},
});
const alice = privateKey('//Alice');
const caller = await createEthAccountWithBalance(api, web3);
- await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: caller });
- await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: caller });
- await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: caller });
+ await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: caller});
+ await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: caller});
+ await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: caller});
const address = collectionIdToAddress(collection);
const contract = await proxyWrap(api, web3, new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS}));
@@ -61,14 +59,14 @@
expect(balance).to.equal('3');
});
- itWeb3('ownerOf', async ({ api, web3 }) => {
+ itWeb3('ownerOf', async ({api, web3}) => {
const collection = await createCollectionExpectSuccess({
- mode: { type: 'NFT' },
+ mode: {type: 'NFT'},
});
const alice = privateKey('//Alice');
const caller = await createEthAccountWithBalance(api, web3);
- const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: caller });
+ const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: caller});
const address = collectionIdToAddress(collection);
const contract = await proxyWrap(api, web3, new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS}));
@@ -79,18 +77,18 @@
});
describe('NFT (Via EVM proxy): Plain calls', () => {
- itWeb3('Can perform mint()', async ({ web3, api }) => {
+ itWeb3('Can perform mint()', async ({web3, api}) => {
const collection = await createCollectionExpectSuccess({
- mode: { type: 'NFT' },
+ mode: {type: 'NFT'},
});
const alice = privateKey('//Alice');
const caller = await createEthAccountWithBalance(api, web3);
const receiver = createEthAccount(web3);
const address = collectionIdToAddress(collection);
- const contract = await proxyWrap(api, web3, new web3.eth.Contract(nonFungibleAbi as any, address, { from: caller, ...GAS_ARGS }));
+ const contract = await proxyWrap(api, web3, new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS}));
- const changeAdminTx = api.tx.nft.addCollectionAdmin(collection, { ethereum: contract.options.address });
+ const changeAdminTx = api.tx.nft.addCollectionAdmin(collection, {Ethereum: contract.options.address});
await submitTransactionAsync(alice, changeAdminTx);
{
@@ -100,7 +98,7 @@
receiver,
nextTokenId,
'Test URI',
- ).send({ from: caller });
+ ).send({from: caller});
const events = normalizeEvents(result.events);
expect(events).to.be.deep.equal([
@@ -115,13 +113,12 @@
},
]);
- await waitNewBlocks(api, 1);
expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');
}
});
- itWeb3('Can perform mintBulk()', async ({ web3, api }) => {
+ itWeb3('Can perform mintBulk()', async ({web3, api}) => {
const collection = await createCollectionExpectSuccess({
- mode: { type: 'NFT' },
+ mode: {type: 'NFT'},
});
const alice = privateKey('//Alice');
@@ -129,8 +126,8 @@
const receiver = createEthAccount(web3);
const address = collectionIdToAddress(collection);
- const contract = await proxyWrap(api, web3, new web3.eth.Contract(nonFungibleAbi as any, address, { from: caller, ...GAS_ARGS }));
- const changeAdminTx = api.tx.nft.addCollectionAdmin(collection, { ethereum: contract.options.address });
+ const contract = await proxyWrap(api, web3, new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS}));
+ const changeAdminTx = api.tx.nft.addCollectionAdmin(collection, {Ethereum: contract.options.address});
await submitTransactionAsync(alice, changeAdminTx);
{
@@ -143,7 +140,7 @@
[+nextTokenId + 1, 'Test URI 1'],
[+nextTokenId + 2, 'Test URI 2'],
],
- ).send({ from: caller });
+ ).send({from: caller});
const events = normalizeEvents(result.events);
expect(events).to.be.deep.equal([
@@ -176,31 +173,30 @@
},
]);
- await waitNewBlocks(api, 1);
expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI 0');
expect(await contract.methods.tokenURI(+nextTokenId + 1).call()).to.be.equal('Test URI 1');
expect(await contract.methods.tokenURI(+nextTokenId + 2).call()).to.be.equal('Test URI 2');
}
});
- itWeb3('Can perform burn()', async ({ web3, api }) => {
+ itWeb3('Can perform burn()', async ({web3, api}) => {
const collection = await createCollectionExpectSuccess({
mode: {type: 'NFT'},
});
const alice = privateKey('//Alice');
const caller = await createEthAccountWithBalance(api, web3);
-
+
const address = collectionIdToAddress(collection);
const contract = await proxyWrap(api, web3, new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS}));
- const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: contract.options.address });
+ const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: contract.options.address});
- const changeAdminTx = api.tx.nft.addCollectionAdmin(collection, { ethereum: contract.options.address });
+ const changeAdminTx = api.tx.nft.addCollectionAdmin(collection, {Ethereum: contract.options.address});
await submitTransactionAsync(alice, changeAdminTx);
{
- const result = await contract.methods.burn(tokenId).send({ from: caller });
+ const result = await contract.methods.burn(tokenId).send({from: caller});
const events = normalizeEvents(result.events);
-
+
expect(events).to.be.deep.equal([
{
address,
@@ -215,9 +211,9 @@
}
});
- itWeb3('Can perform approve()', async ({ web3, api }) => {
+ itWeb3('Can perform approve()', async ({web3, api}) => {
const collection = await createCollectionExpectSuccess({
- mode: { type: 'NFT' },
+ mode: {type: 'NFT'},
});
const alice = privateKey('//Alice');
const caller = await createEthAccountWithBalance(api, web3);
@@ -225,10 +221,10 @@
const address = collectionIdToAddress(collection);
const contract = await proxyWrap(api, web3, new web3.eth.Contract(nonFungibleAbi as any, address));
- const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: contract.options.address });
+ const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: contract.options.address});
{
- const result = await contract.methods.approve(spender, tokenId).send({ from: caller, gas: '0x1000000', gasPrice: '0x01' });
+ const result = await contract.methods.approve(spender, tokenId).send({from: caller, gas: '0x1000000', gasPrice: '0x01'});
const events = normalizeEvents(result.events);
expect(events).to.be.deep.equal([
@@ -245,9 +241,9 @@
}
});
- itWeb3('Can perform transferFrom()', async ({ web3, api }) => {
+ itWeb3('Can perform transferFrom()', async ({web3, api}) => {
const collection = await createCollectionExpectSuccess({
- mode: { type: 'NFT' },
+ mode: {type: 'NFT'},
});
const alice = privateKey('//Alice');
const caller = await createEthAccountWithBalance(api, web3);
@@ -256,14 +252,14 @@
const receiver = createEthAccount(web3);
const address = collectionIdToAddress(collection);
- const evmCollection = new web3.eth.Contract(nonFungibleAbi as any, address, { from: caller, ...GAS_ARGS });
+ const evmCollection = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});
const contract = await proxyWrap(api, web3, evmCollection);
- const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner });
+ const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: owner});
- await evmCollection.methods.approve(contract.options.address, tokenId).send({ from: owner });
+ await evmCollection.methods.approve(contract.options.address, tokenId).send({from: owner});
{
- const result = await contract.methods.transferFrom(owner, receiver, tokenId).send({ from: caller });
+ const result = await contract.methods.transferFrom(owner, receiver, tokenId).send({from: caller});
const events = normalizeEvents(result.events);
expect(events).to.be.deep.equal([
{
@@ -289,9 +285,9 @@
}
});
- itWeb3('Can perform transfer()', async ({ web3, api }) => {
+ itWeb3('Can perform transfer()', async ({web3, api}) => {
const collection = await createCollectionExpectSuccess({
- mode: { type: 'NFT' },
+ mode: {type: 'NFT'},
});
const alice = privateKey('//Alice');
const caller = await createEthAccountWithBalance(api, web3);
@@ -299,11 +295,10 @@
const address = collectionIdToAddress(collection);
const contract = await proxyWrap(api, web3, new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS}));
- const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: contract.options.address });
+ const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: contract.options.address});
{
- const result = await contract.methods.transfer(receiver, tokenId).send({ from: caller });
- await waitNewBlocks(api, 1);
+ const result = await contract.methods.transfer(receiver, tokenId).send({from: caller});
const events = normalizeEvents(result.events);
expect(events).to.be.deep.equal([
{
@@ -329,35 +324,34 @@
}
});
- itWeb3('Can perform getVariableMetadata', async ({ web3, api }) => {
+ itWeb3('Can perform getVariableMetadata', async ({web3, api}) => {
const collection = await createCollectionExpectSuccess({
- mode: { type: 'NFT' },
+ mode: {type: 'NFT'},
});
const alice = privateKey('//Alice');
const caller = await createEthAccountWithBalance(api, web3);
const address = collectionIdToAddress(collection);
- const contract = await proxyWrap(api, web3, new web3.eth.Contract(nonFungibleAbi as any, address, { from: caller, ...GAS_ARGS }));
- const item = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: contract.options.address });
+ const contract = await proxyWrap(api, web3, new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS}));
+ const item = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: contract.options.address});
await setMetadataUpdatePermissionFlagExpectSuccess(alice, collection, 'Admin');
await setVariableMetaDataExpectSuccess(alice, collection, item, [1, 2, 3]);
-
+
expect(await contract.methods.getVariableMetadata(item).call()).to.be.equal('0x010203');
});
- itWeb3('Can perform setVariableMetadata', async ({ web3, api }) => {
+ itWeb3('Can perform setVariableMetadata', async ({web3, api}) => {
const collection = await createCollectionExpectSuccess({
- mode: { type: 'NFT' },
+ mode: {type: 'NFT'},
});
const alice = privateKey('//Alice');
const caller = await createEthAccountWithBalance(api, web3);
const address = collectionIdToAddress(collection);
- const contract = await proxyWrap(api, web3, new web3.eth.Contract(nonFungibleAbi as any, address, { from: caller, ...GAS_ARGS }));
- const item = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: contract.options.address });
-
- expect(await contract.methods.setVariableMetadata(item, '0x010203').send({ from: caller }));
- await waitNewBlocks(api, 1);
+ const contract = await proxyWrap(api, web3, new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS}));
+ const item = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: contract.options.address});
+
+ expect(await contract.methods.setVariableMetadata(item, '0x010203').send({from: caller}));
expect(await contract.methods.getVariableMetadata(item).call()).to.be.equal('0x010203');
});
});
tests/src/eth/sponsoring.test.tsdiffbeforeafterboth--- a/tests/src/eth/sponsoring.test.ts
+++ b/tests/src/eth/sponsoring.test.ts
@@ -1,88 +1,68 @@
-import { expect } from 'chai';
+import {expect} from 'chai';
import privateKey from '../substrate/privateKey';
-import waitNewBlocks from '../substrate/wait-new-blocks';
-import { contractHelpers, createEthAccount, createEthAccountWithBalance, deployCollector, deployFlipper, itWeb3, transferBalanceToEth, usingWeb3Http } from './util/helpers';
+import {contractHelpers, createEthAccount, createEthAccountWithBalance, deployCollector, deployFlipper, itWeb3, transferBalanceToEth} from './util/helpers';
describe('EVM sponsoring', () => {
itWeb3('Fee is deducted from contract if sponsoring is enabled', async ({api, web3}) => {
- await usingWeb3Http(async web3Http => {
- const alice = privateKey('//Alice');
+ const alice = privateKey('//Alice');
- const owner = await createEthAccountWithBalance(api, web3Http);
- const caller = createEthAccount(web3Http);
- const originalCallerBalance = await web3.eth.getBalance(caller);
- expect(originalCallerBalance).to.be.equal('0');
+ const owner = await createEthAccountWithBalance(api, web3);
+ const caller = createEthAccount(web3);
+ const originalCallerBalance = await web3.eth.getBalance(caller);
+ expect(originalCallerBalance).to.be.equal('0');
- const flipper = await deployFlipper(web3Http, owner);
- await waitNewBlocks(api, 1);
-
- const helpers = contractHelpers(web3Http, owner);
- await helpers.methods.toggleAllowlist(flipper.options.address, true).send({ from: owner });
- await waitNewBlocks(api, 1);
- await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({ from: owner });
- await waitNewBlocks(api, 1);
+ const flipper = await deployFlipper(web3, owner);
- expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;
- await helpers.methods.toggleSponsoring(flipper.options.address, true).send({from: owner});
- await waitNewBlocks(api, 1);
- await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});
- await waitNewBlocks(api, 1);
- expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;
+ const helpers = contractHelpers(web3, owner);
+ await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});
+ await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner});
+
+ expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;
+ await helpers.methods.toggleSponsoring(flipper.options.address, true).send({from: owner});
+ await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});
+ expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;
- await transferBalanceToEth(api, alice, flipper.options.address);
- await waitNewBlocks(api, 2);
+ await transferBalanceToEth(api, alice, flipper.options.address);
- const originalFlipperBalance = await web3.eth.getBalance(flipper.options.address);
- expect(originalFlipperBalance).to.be.not.equal('0');
+ const originalFlipperBalance = await web3.eth.getBalance(flipper.options.address);
+ expect(originalFlipperBalance).to.be.not.equal('0');
- await flipper.methods.flip().send({ from: caller });
- await waitNewBlocks(api, 1);
- expect(await flipper.methods.getValue().call()).to.be.true;
+ await flipper.methods.flip().send({from: caller});
+ expect(await flipper.methods.getValue().call()).to.be.true;
- // Balance should be taken from flipper instead of caller
- expect(await web3.eth.getBalance(caller)).to.be.equals(originalCallerBalance);
- expect(await web3.eth.getBalance(flipper.options.address)).to.be.not.equals(originalFlipperBalance);
- });
+ // Balance should be taken from flipper instead of caller
+ expect(await web3.eth.getBalance(caller)).to.be.equals(originalCallerBalance);
+ expect(await web3.eth.getBalance(flipper.options.address)).to.be.not.equals(originalFlipperBalance);
});
itWeb3('...but this doesn\'t applies to payable value', async ({api, web3}) => {
- await usingWeb3Http(async web3Http => {
- const alice = privateKey('//Alice');
+ const alice = privateKey('//Alice');
- const owner = await createEthAccountWithBalance(api, web3Http);
- const caller = await createEthAccountWithBalance(api, web3Http);
- await waitNewBlocks(api, 1);
- const originalCallerBalance = await web3.eth.getBalance(caller);
- expect(originalCallerBalance).to.be.not.equal('0');
+ const owner = await createEthAccountWithBalance(api, web3);
+ const caller = await createEthAccountWithBalance(api, web3);
+ const originalCallerBalance = await web3.eth.getBalance(caller);
+ expect(originalCallerBalance).to.be.not.equal('0');
- const collector = await deployCollector(web3Http, owner);
- await waitNewBlocks(api, 1);
-
- const helpers = contractHelpers(web3Http, owner);
- await helpers.methods.toggleAllowlist(collector.options.address, true).send({ from: owner });
- await waitNewBlocks(api, 1);
- await helpers.methods.toggleAllowed(collector.options.address, caller, true).send({ from: owner });
- await waitNewBlocks(api, 1);
+ const collector = await deployCollector(web3, owner);
- expect(await helpers.methods.sponsoringEnabled(collector.options.address).call()).to.be.false;
- await helpers.methods.toggleSponsoring(collector.options.address, true).send({ from: owner });
- await waitNewBlocks(api, 1);
- await helpers.methods.setSponsoringRateLimit(collector.options.address, 0).send({ from: owner });
- await waitNewBlocks(api, 1);
- expect(await helpers.methods.sponsoringEnabled(collector.options.address).call()).to.be.true;
+ const helpers = contractHelpers(web3, owner);
+ await helpers.methods.toggleAllowlist(collector.options.address, true).send({from: owner});
+ await helpers.methods.toggleAllowed(collector.options.address, caller, true).send({from: owner});
+
+ expect(await helpers.methods.sponsoringEnabled(collector.options.address).call()).to.be.false;
+ await helpers.methods.toggleSponsoring(collector.options.address, true).send({from: owner});
+ await helpers.methods.setSponsoringRateLimit(collector.options.address, 0).send({from: owner});
+ expect(await helpers.methods.sponsoringEnabled(collector.options.address).call()).to.be.true;
- await transferBalanceToEth(api, alice, collector.options.address);
- await waitNewBlocks(api, 2);
+ await transferBalanceToEth(api, alice, collector.options.address);
- const originalCollectorBalance = await web3.eth.getBalance(collector.options.address);
- expect(originalCollectorBalance).to.be.not.equal('0');
+ const originalCollectorBalance = await web3.eth.getBalance(collector.options.address);
+ expect(originalCollectorBalance).to.be.not.equal('0');
- await collector.methods.giveMoney().send({ from: caller, value: '10000' });
- await waitNewBlocks(api, 1);
+ await collector.methods.giveMoney().send({from: caller, value: '10000'});
- // Balance will be taken from both caller (value) and from collector (fee)
- expect(await web3.eth.getBalance(caller)).to.be.equals((BigInt(originalCallerBalance) - 10000n).toString());
- expect(await web3.eth.getBalance(collector.options.address)).to.be.not.equals(originalCollectorBalance);
- expect(await collector.methods.getCollected().call()).to.be.equal('10000');
- });
+ // Balance will be taken from both caller (value) and from collector (fee)
+ expect(await web3.eth.getBalance(caller)).to.be.equals((BigInt(originalCallerBalance) - 10000n).toString());
+ expect(await web3.eth.getBalance(collector.options.address)).to.be.not.equals(originalCollectorBalance);
+ expect(await collector.methods.getCollected().call()).to.be.equal('10000');
});
-});
\ No newline at end of file
+});
tests/src/eth/util/helpers.tsdiffbeforeafterboth--- a/tests/src/eth/util/helpers.ts
+++ b/tests/src/eth/util/helpers.ts
@@ -6,21 +6,20 @@
// eslint-disable-next-line @typescript-eslint/triple-slash-reference
/// <reference path="helpers.d.ts" />
-import { ApiPromise } from '@polkadot/api';
-import { addressToEvm, evmToAddress } from '@polkadot/util-crypto';
+import {ApiPromise} from '@polkadot/api';
+import {addressToEvm, evmToAddress} from '@polkadot/util-crypto';
import Web3 from 'web3';
-import usingApi, { submitTransactionAsync } from '../../substrate/substrate-api';
-import { IKeyringPair } from '@polkadot/types/types';
-import { expect } from 'chai';
-import { getGenericResult } from '../../util/helpers';
+import usingApi, {submitTransactionAsync} from '../../substrate/substrate-api';
+import {IKeyringPair} from '@polkadot/types/types';
+import {expect} from 'chai';
+import {getGenericResult} from '../../util/helpers';
import * as solc from 'solc';
import config from '../../config';
import privateKey from '../../substrate/privateKey';
import contractHelpersAbi from './contractHelpersAbi.json';
import getBalance from '../../substrate/get-balance';
-import waitNewBlocks from '../../substrate/wait-new-blocks';
-export const GAS_ARGS = { gas: 0x1000000, gasPrice: '0x01' };
+export const GAS_ARGS = {gas: 0x1000000, gasPrice: '0x01'};
let web3Connected = false;
export async function usingWeb3<T>(cb: (web3: Web3) => Promise<T> | T): Promise<T> {
@@ -37,16 +36,6 @@
provider.connection.close();
web3Connected = false;
}
-}
-
-/**
- * @deprecated Web3 update solved issue with deployment over ws provider
- */
-export async function usingWeb3Http<T>(cb: (web3: Web3) => Promise<T> | T): Promise<T> {
- const provider = new Web3.providers.HttpProvider(config.frontierUrl);
- const web3: Web3 = new Web3(provider);
-
- return await cb(web3);
}
export function collectionIdToAddress(address: number): string {
@@ -88,13 +77,13 @@
i(name, async () => {
await usingApi(async api => {
await usingWeb3(async web3 => {
- await cb({ api, web3 });
+ await cb({api, web3});
});
});
});
}
-itWeb3.only = (name: string, cb: (apis: { web3: Web3, api: ApiPromise }) => any) => itWeb3(name, cb, { only: true });
-itWeb3.skip = (name: string, cb: (apis: { web3: Web3, api: ApiPromise }) => any) => itWeb3(name, cb, { skip: true });
+itWeb3.only = (name: string, cb: (apis: { web3: Web3, api: ApiPromise }) => any) => itWeb3(name, cb, {only: true});
+itWeb3.skip = (name: string, cb: (apis: { web3: Web3, api: ApiPromise }) => any) => itWeb3(name, cb, {skip: true});
export async function generateSubstrateEthPair(web3: Web3) {
const account = web3.eth.accounts.create();
@@ -119,7 +108,7 @@
}
}
output.sort((a, b) => a.logIndex - b.logIndex);
- return output.map(({ address, event, returnValues }) => {
+ return output.map(({address, event, returnValues}) => {
const args: { [key: string]: string } = {};
for (const key of Object.keys(returnValues)) {
if (!key.match(/^[0-9]+$/)) {
@@ -192,12 +181,12 @@
}
}
`);
- const Flipper = new web3.eth.Contract(compiled.abi, undefined, {
+ const flipperContract = new web3.eth.Contract(compiled.abi, undefined, {
data: compiled.object,
from: deployer,
...GAS_ARGS,
});
- const flipper = await Flipper.deploy({ data: compiled.object }).send({from: deployer});
+ const flipper = await flipperContract.deploy({data: compiled.object}).send({from: deployer});
return flipper;
}
@@ -225,12 +214,12 @@
}
}
`);
- const Collector = new web3.eth.Contract(compiled.abi, undefined, {
+ const collectorContract = new web3.eth.Contract(compiled.abi, undefined, {
data: compiled.object,
from: deployer,
...GAS_ARGS,
});
- const collector = await Collector.deploy({ data: compiled.object }).send({ from: deployer });
+ const collector = await collectorContract.deploy({data: compiled.object}).send({from: deployer});
return collector;
}
@@ -239,7 +228,7 @@
return new web3.eth.Contract(contractHelpersAbi as any, '0x842899ECF380553E8a4de75bF534cdf6fBF64049', {from: caller, ...GAS_ARGS});
}
-export async function executeEthTxOnSub(api: ApiPromise, from: IKeyringPair, to: any, mkTx: (methods: any) => any, { value = 0 }: {value?: bigint | number} = { }) {
+export async function executeEthTxOnSub(api: ApiPromise, from: IKeyringPair, to: any, mkTx: (methods: any) => any, {value = 0}: {value?: bigint | number} = { }) {
const tx = api.tx.evm.call(
subToEth(from.address),
to.options.address,
@@ -250,7 +239,7 @@
null,
);
const events = await submitTransactionAsync(from, tx);
- expect(events.find(({ event: {section, method}})=>section === 'evm' && method === 'Executed')).to.be.not.undefined;
+ expect(events.some(({event: {section, method}}) => section == 'evm' && method == 'Executed')).to.be.true;
}
export async function ethBalanceViaSub(api: ApiPromise, address: string): Promise<bigint> {
@@ -261,7 +250,6 @@
const before = await ethBalanceViaSub(api, user);
await call();
- await waitNewBlocks(api, 1);
const after = await ethBalanceViaSub(api, user);
tests/src/inflation.test.tsdiffbeforeafterboth--- a/tests/src/inflation.test.ts
+++ b/tests/src/inflation.test.ts
@@ -5,8 +5,7 @@
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
-import { default as usingApi } from './substrate/substrate-api';
-import { BigNumber } from 'bignumber.js';
+import {default as usingApi} from './substrate/substrate-api';
chai.use(chaiAsPromised);
const expect = chai.expect;
@@ -15,16 +14,20 @@
it('First year inflation is 10%', async () => {
await usingApi(async (api) => {
- const blockInterval = parseInt((await api.consts.inflation.inflationBlockInterval).toString());
- const totalIssuanceStart = new BigNumber((await api.query.inflation.startingYearTotalIssuance()).toString());
- const blockInflation = new BigNumber((await api.query.inflation.blockInflation()).toString());
+ const blockInterval = (api.consts.inflation.inflationBlockInterval).toBigInt();
+ const totalIssuanceStart = (await api.query.inflation.startingYearTotalIssuance()).toBigInt();
+ const blockInflation = (await api.query.inflation.blockInflation()).toBigInt();
- const YEAR = 5259600; // Blocks in one year
- const totalExpectedInflation = totalIssuanceStart.multipliedBy(0.1);
- const totalActualInflation = blockInflation.multipliedBy(YEAR / blockInterval);
+ const YEAR = 5259600n; // Blocks in one year
+ const totalExpectedInflation = totalIssuanceStart / 10n;
+ const totalActualInflation = blockInflation * YEAR / blockInterval;
const tolerance = 0.00001; // Relative difference per year between theoretical and actual inflation
- expect(totalExpectedInflation.dividedBy(totalActualInflation).minus(1).abs().toNumber()).to.be.lessThan(tolerance);
+ let abs = totalExpectedInflation / totalActualInflation - 1n;
+ if (abs < 0n) {
+ abs = -abs;
+ }
+ expect(abs <= tolerance).to.be.true;
});
});
tests/src/limits.test.tsdiffbeforeafterboth--- a/tests/src/limits.test.ts
+++ b/tests/src/limits.test.ts
@@ -3,7 +3,7 @@
// file 'LICENSE', which is part of this source code package.
//
-import { IKeyringPair } from '@polkadot/types/types';
+import {IKeyringPair} from '@polkadot/types/types';
import privateKey from './substrate/privateKey';
import usingApi from './substrate/substrate-api';
import {
@@ -18,98 +18,98 @@
getFreeBalance,
waitNewBlocks,
} from './util/helpers';
-import { expect } from 'chai';
+import {expect} from 'chai';
describe('Number of tokens per address (NFT)', () => {
- let Alice: IKeyringPair;
+ let alice: IKeyringPair;
before(async () => {
await usingApi(async () => {
- Alice = privateKey('//Alice');
+ alice = privateKey('//Alice');
});
});
it.skip('Collection limits allow greater number than chain limits, chain limits are enforced', async () => {
- const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });
- await setCollectionLimitsExpectSuccess(Alice, collectionId, { accountTokenOwnershipLimit: 20 });
+ const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
+ await setCollectionLimitsExpectSuccess(alice, collectionId, {accountTokenOwnershipLimit: 20});
for(let i = 0; i < 10; i++){
- await createItemExpectSuccess(Alice, collectionId, 'NFT');
+ await createItemExpectSuccess(alice, collectionId, 'NFT');
}
- await createItemExpectFailure(Alice, collectionId, 'NFT');
+ await createItemExpectFailure(alice, collectionId, 'NFT');
await destroyCollectionExpectSuccess(collectionId);
});
it('Collection limits allow lower number than chain limits, collection limits are enforced', async () => {
- const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });
- await setCollectionLimitsExpectSuccess(Alice, collectionId, { accountTokenOwnershipLimit: 1 });
- await createItemExpectSuccess(Alice, collectionId, 'NFT');
- await createItemExpectFailure(Alice, collectionId, 'NFT');
+ const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
+ await setCollectionLimitsExpectSuccess(alice, collectionId, {accountTokenOwnershipLimit: 1});
+ await createItemExpectSuccess(alice, collectionId, 'NFT');
+ await createItemExpectFailure(alice, collectionId, 'NFT');
await destroyCollectionExpectSuccess(collectionId);
});
});
describe('Number of tokens per address (ReFungible)', () => {
- let Alice: IKeyringPair;
+ let alice: IKeyringPair;
before(async () => {
await usingApi(async () => {
- Alice = privateKey('//Alice');
+ alice = privateKey('//Alice');
});
});
it.skip('Collection limits allow greater number than chain limits, chain limits are enforced', async () => {
- const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible' }});
- await setCollectionLimitsExpectSuccess(Alice, collectionId, { accountTokenOwnershipLimit: 20 });
+ const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
+ await setCollectionLimitsExpectSuccess(alice, collectionId, {accountTokenOwnershipLimit: 20});
for(let i = 0; i < 10; i++){
- await createItemExpectSuccess(Alice, collectionId, 'ReFungible');
+ await createItemExpectSuccess(alice, collectionId, 'ReFungible');
}
- await createItemExpectFailure(Alice, collectionId, 'ReFungible');
+ await createItemExpectFailure(alice, collectionId, 'ReFungible');
await destroyCollectionExpectSuccess(collectionId);
});
it('Collection limits allow lower number than chain limits, collection limits are enforced', async () => {
- const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible' }});
- await setCollectionLimitsExpectSuccess(Alice, collectionId, { accountTokenOwnershipLimit: 1 });
- await createItemExpectSuccess(Alice, collectionId, 'ReFungible');
- await createItemExpectFailure(Alice, collectionId, 'ReFungible');
+ const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
+ await setCollectionLimitsExpectSuccess(alice, collectionId, {accountTokenOwnershipLimit: 1});
+ await createItemExpectSuccess(alice, collectionId, 'ReFungible');
+ await createItemExpectFailure(alice, collectionId, 'ReFungible');
await destroyCollectionExpectSuccess(collectionId);
});
});
describe('Sponsor timeout (NFT)', () => {
- let Alice: IKeyringPair;
- let Bob: IKeyringPair;
- let Charlie: IKeyringPair;
+ let alice: IKeyringPair;
+ let bob: IKeyringPair;
+ let charlie: IKeyringPair;
before(async () => {
await usingApi(async () => {
- Alice = privateKey('//Alice');
- Bob = privateKey('//Bob');
- Charlie = privateKey('//Charlie');
+ alice = privateKey('//Alice');
+ bob = privateKey('//Bob');
+ charlie = privateKey('//Charlie');
});
});
it('Collection limits have greater timeout value than chain limits, collection limits are enforced', async () => {
- const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });
- await setCollectionLimitsExpectSuccess(Alice, collectionId, { sponsorTimeout: 7 });
- const tokenId = await createItemExpectSuccess(Alice, collectionId, 'NFT');
- await setCollectionSponsorExpectSuccess(collectionId, Alice.address);
+ const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
+ await setCollectionLimitsExpectSuccess(alice, collectionId, {sponsorTransferTimeout: 7});
+ const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');
+ await setCollectionSponsorExpectSuccess(collectionId, alice.address);
await confirmSponsorshipExpectSuccess(collectionId, '//Alice');
- await transferExpectSuccess(collectionId, tokenId, Alice, Bob);
- const aliceBalanceBefore = await getFreeBalance(Alice);
+ await transferExpectSuccess(collectionId, tokenId, alice, bob);
+ const aliceBalanceBefore = await getFreeBalance(alice);
// check setting SponsorTimeout = 5, fail
await waitNewBlocks(5);
- await transferExpectSuccess(collectionId, tokenId, Bob, Charlie);
- const aliceBalanceAfterUnsponsoredTransaction = await getFreeBalance(Alice);
+ await transferExpectSuccess(collectionId, tokenId, bob, charlie);
+ const aliceBalanceAfterUnsponsoredTransaction = await getFreeBalance(alice);
expect(aliceBalanceAfterUnsponsoredTransaction).to.be.equals(aliceBalanceBefore);
// check setting SponsorTimeout = 7, success
await waitNewBlocks(2); // 5 + 2
- await transferExpectSuccess(collectionId, tokenId, Charlie, Bob);
- const aliceBalanceAfterSponsoredTransaction = await getFreeBalance(Alice);
+ await transferExpectSuccess(collectionId, tokenId, charlie, bob);
+ const aliceBalanceAfterSponsoredTransaction = await getFreeBalance(alice);
expect(aliceBalanceAfterSponsoredTransaction < aliceBalanceBefore).to.be.true;
//expect(aliceBalanceAfterSponsoredTransaction).to.be.lessThan(aliceBalanceBefore);
await destroyCollectionExpectSuccess(collectionId);
@@ -117,24 +117,24 @@
it('Collection limits have lower timeout value than chain limits, chain limits are enforced', async () => {
- const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });
- await setCollectionLimitsExpectSuccess(Alice, collectionId, { sponsorTimeout: 1 });
- const tokenId = await createItemExpectSuccess(Alice, collectionId, 'NFT');
- await setCollectionSponsorExpectSuccess(collectionId, Alice.address);
+ const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
+ await setCollectionLimitsExpectSuccess(alice, collectionId, {sponsorTransferTimeout: 1});
+ const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');
+ await setCollectionSponsorExpectSuccess(collectionId, alice.address);
await confirmSponsorshipExpectSuccess(collectionId, '//Alice');
- await transferExpectSuccess(collectionId, tokenId, Alice, Bob);
- const aliceBalanceBefore = await getFreeBalance(Alice);
+ await transferExpectSuccess(collectionId, tokenId, alice, bob);
+ const aliceBalanceBefore = await getFreeBalance(alice);
// check setting SponsorTimeout = 1, fail
await waitNewBlocks(1);
- await transferExpectSuccess(collectionId, tokenId, Bob, Charlie);
- const aliceBalanceAfterUnsponsoredTransaction = await getFreeBalance(Alice);
+ await transferExpectSuccess(collectionId, tokenId, bob, charlie);
+ const aliceBalanceAfterUnsponsoredTransaction = await getFreeBalance(alice);
expect(aliceBalanceAfterUnsponsoredTransaction).to.be.equals(aliceBalanceBefore);
// check setting SponsorTimeout = 5, success
await waitNewBlocks(4);
- await transferExpectSuccess(collectionId, tokenId, Charlie, Bob);
- const aliceBalanceAfterSponsoredTransaction = await getFreeBalance(Alice);
+ await transferExpectSuccess(collectionId, tokenId, charlie, bob);
+ const aliceBalanceAfterSponsoredTransaction = await getFreeBalance(alice);
expect(aliceBalanceAfterSponsoredTransaction < aliceBalanceBefore).to.be.true;
//expect(aliceBalanceAfterSponsoredTransaction).to.be.lessThan(aliceBalanceBefore);
await destroyCollectionExpectSuccess(collectionId);
@@ -142,38 +142,38 @@
});
describe('Sponsor timeout (Fungible)', () => {
- let Alice: IKeyringPair;
- let Bob: IKeyringPair;
- let Charlie: IKeyringPair;
+ let alice: IKeyringPair;
+ let bob: IKeyringPair;
+ let charlie: IKeyringPair;
before(async () => {
await usingApi(async () => {
- Alice = privateKey('//Alice');
- Bob = privateKey('//Bob');
- Charlie = privateKey('//Charlie');
+ alice = privateKey('//Alice');
+ bob = privateKey('//Bob');
+ charlie = privateKey('//Charlie');
});
});
it('Collection limits have greater timeout value than chain limits, collection limits are enforced', async () => {
const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
- await setCollectionLimitsExpectSuccess(Alice, collectionId, { sponsorTimeout: 7 });
- const tokenId = await createItemExpectSuccess(Alice, collectionId, 'Fungible');
- await setCollectionSponsorExpectSuccess(collectionId, Alice.address);
+ await setCollectionLimitsExpectSuccess(alice, collectionId, {sponsorTransferTimeout: 7});
+ const tokenId = await createItemExpectSuccess(alice, collectionId, 'Fungible');
+ await setCollectionSponsorExpectSuccess(collectionId, alice.address);
await confirmSponsorshipExpectSuccess(collectionId, '//Alice');
- await transferExpectSuccess(collectionId, tokenId, Alice, Bob, 10, 'Fungible');
- await transferExpectSuccess(collectionId, tokenId, Bob, Charlie, 2, 'Fungible');
- const aliceBalanceBefore = await getFreeBalance(Alice);
+ await transferExpectSuccess(collectionId, tokenId, alice, bob, 10, 'Fungible');
+ await transferExpectSuccess(collectionId, tokenId, bob, charlie, 2, 'Fungible');
+ const aliceBalanceBefore = await getFreeBalance(alice);
// check setting SponsorTimeout = 5, fail
await waitNewBlocks(5);
- await transferExpectSuccess(collectionId, tokenId, Bob, Charlie, 2, 'Fungible');
- const aliceBalanceAfterUnsponsoredTransaction = await getFreeBalance(Alice);
+ await transferExpectSuccess(collectionId, tokenId, bob, charlie, 2, 'Fungible');
+ const aliceBalanceAfterUnsponsoredTransaction = await getFreeBalance(alice);
expect(aliceBalanceAfterUnsponsoredTransaction).to.be.equals(aliceBalanceBefore);
// check setting SponsorTimeout = 7, success
await waitNewBlocks(2); // 5 + 2
- await transferExpectSuccess(collectionId, tokenId, Bob, Charlie, 2, 'Fungible');
- const aliceBalanceAfterSponsoredTransaction = await getFreeBalance(Alice);
+ await transferExpectSuccess(collectionId, tokenId, bob, charlie, 2, 'Fungible');
+ const aliceBalanceAfterSponsoredTransaction = await getFreeBalance(alice);
expect(aliceBalanceAfterSponsoredTransaction < aliceBalanceBefore).to.be.true;
//expect(aliceBalanceAfterSponsoredTransaction).to.be.lessThan(aliceBalanceBefore);
@@ -183,24 +183,24 @@
it('Collection limits have lower timeout value than chain limits, chain limits are enforced', async () => {
const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
- await setCollectionLimitsExpectSuccess(Alice, collectionId, { sponsorTimeout: 1 });
- const tokenId = await createItemExpectSuccess(Alice, collectionId, 'Fungible');
- await setCollectionSponsorExpectSuccess(collectionId, Alice.address);
+ await setCollectionLimitsExpectSuccess(alice, collectionId, {sponsorTransferTimeout: 1});
+ const tokenId = await createItemExpectSuccess(alice, collectionId, 'Fungible');
+ await setCollectionSponsorExpectSuccess(collectionId, alice.address);
await confirmSponsorshipExpectSuccess(collectionId, '//Alice');
- await transferExpectSuccess(collectionId, tokenId, Alice, Bob, 10, 'Fungible');
- await transferExpectSuccess(collectionId, tokenId, Bob, Charlie, 2, 'Fungible');
- const aliceBalanceBefore = await getFreeBalance(Alice);
+ await transferExpectSuccess(collectionId, tokenId, alice, bob, 10, 'Fungible');
+ await transferExpectSuccess(collectionId, tokenId, bob, charlie, 2, 'Fungible');
+ const aliceBalanceBefore = await getFreeBalance(alice);
// check setting SponsorTimeout = 1, fail
await waitNewBlocks(1);
- await transferExpectSuccess(collectionId, tokenId, Bob, Charlie, 2, 'Fungible');
- const aliceBalanceAfterUnsponsoredTransaction = await getFreeBalance(Alice);
+ await transferExpectSuccess(collectionId, tokenId, bob, charlie, 2, 'Fungible');
+ const aliceBalanceAfterUnsponsoredTransaction = await getFreeBalance(alice);
expect(aliceBalanceAfterUnsponsoredTransaction).to.be.equals(aliceBalanceBefore);
// check setting SponsorTimeout = 5, success
await waitNewBlocks(4);
- await transferExpectSuccess(collectionId, tokenId, Bob, Charlie, 2, 'Fungible');
- const aliceBalanceAfterSponsoredTransaction = await getFreeBalance(Alice);
+ await transferExpectSuccess(collectionId, tokenId, bob, charlie, 2, 'Fungible');
+ const aliceBalanceAfterSponsoredTransaction = await getFreeBalance(alice);
expect(aliceBalanceAfterSponsoredTransaction < aliceBalanceBefore).to.be.true;
//expect(aliceBalanceAfterSponsoredTransaction).to.be.lessThan(aliceBalanceBefore);
@@ -209,37 +209,37 @@
});
describe('Sponsor timeout (ReFungible)', () => {
- let Alice: IKeyringPair;
- let Bob: IKeyringPair;
- let Charlie: IKeyringPair;
+ let alice: IKeyringPair;
+ let bob: IKeyringPair;
+ let charlie: IKeyringPair;
before(async () => {
await usingApi(async () => {
- Alice = privateKey('//Alice');
- Bob = privateKey('//Bob');
- Charlie = privateKey('//Charlie');
+ alice = privateKey('//Alice');
+ bob = privateKey('//Bob');
+ charlie = privateKey('//Charlie');
});
});
it('Collection limits have greater timeout value than chain limits, collection limits are enforced', async () => {
- const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible' }});
- await setCollectionLimitsExpectSuccess(Alice, collectionId, { sponsorTimeout: 7 });
- const tokenId = await createItemExpectSuccess(Alice, collectionId, 'ReFungible');
- await setCollectionSponsorExpectSuccess(collectionId, Alice.address);
+ const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
+ await setCollectionLimitsExpectSuccess(alice, collectionId, {sponsorTransferTimeout: 7});
+ const tokenId = await createItemExpectSuccess(alice, collectionId, 'ReFungible');
+ await setCollectionSponsorExpectSuccess(collectionId, alice.address);
await confirmSponsorshipExpectSuccess(collectionId, '//Alice');
- await transferExpectSuccess(collectionId, tokenId, Alice, Bob, 100, 'ReFungible');
- const aliceBalanceBefore = await getFreeBalance(Alice);
+ await transferExpectSuccess(collectionId, tokenId, alice, bob, 100, 'ReFungible');
+ const aliceBalanceBefore = await getFreeBalance(alice);
// check setting SponsorTimeout = 5, fail
await waitNewBlocks(5);
- await transferExpectSuccess(collectionId, tokenId, Bob, Charlie, 20, 'ReFungible');
- const aliceBalanceAfterUnsponsoredTransaction = await getFreeBalance(Alice);
+ await transferExpectSuccess(collectionId, tokenId, bob, charlie, 20, 'ReFungible');
+ const aliceBalanceAfterUnsponsoredTransaction = await getFreeBalance(alice);
expect(aliceBalanceAfterUnsponsoredTransaction).to.be.equals(aliceBalanceBefore);
// check setting SponsorTimeout = 7, success
await waitNewBlocks(2); // 5 + 2
- await transferExpectSuccess(collectionId, tokenId, Bob, Charlie, 20, 'ReFungible');
- const aliceBalanceAfterSponsoredTransaction = await getFreeBalance(Alice);
+ await transferExpectSuccess(collectionId, tokenId, bob, charlie, 20, 'ReFungible');
+ const aliceBalanceAfterSponsoredTransaction = await getFreeBalance(alice);
expect(aliceBalanceAfterSponsoredTransaction < aliceBalanceBefore).to.be.true;
//expect(aliceBalanceAfterSponsoredTransaction).to.be.lessThan(aliceBalanceBefore);
await destroyCollectionExpectSuccess(collectionId);
@@ -247,24 +247,24 @@
it('Collection limits have lower timeout value than chain limits, chain limits are enforced', async () => {
- const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });
- await setCollectionLimitsExpectSuccess(Alice, collectionId, { sponsorTimeout: 1 });
- const tokenId = await createItemExpectSuccess(Alice, collectionId, 'NFT');
- await setCollectionSponsorExpectSuccess(collectionId, Alice.address);
+ const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
+ await setCollectionLimitsExpectSuccess(alice, collectionId, {sponsorTransferTimeout: 1});
+ const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');
+ await setCollectionSponsorExpectSuccess(collectionId, alice.address);
await confirmSponsorshipExpectSuccess(collectionId, '//Alice');
- await transferExpectSuccess(collectionId, tokenId, Alice, Bob);
- const aliceBalanceBefore = await getFreeBalance(Alice);
+ await transferExpectSuccess(collectionId, tokenId, alice, bob);
+ const aliceBalanceBefore = await getFreeBalance(alice);
// check setting SponsorTimeout = 1, fail
await waitNewBlocks(1);
- await transferExpectSuccess(collectionId, tokenId, Bob, Charlie);
- const aliceBalanceAfterUnsponsoredTransaction = await getFreeBalance(Alice);
+ await transferExpectSuccess(collectionId, tokenId, bob, charlie);
+ const aliceBalanceAfterUnsponsoredTransaction = await getFreeBalance(alice);
expect(aliceBalanceAfterUnsponsoredTransaction).to.be.equals(aliceBalanceBefore);
// check setting SponsorTimeout = 5, success
await waitNewBlocks(4);
- await transferExpectSuccess(collectionId, tokenId, Charlie, Bob);
- const aliceBalanceAfterSponsoredTransaction = await getFreeBalance(Alice);
+ await transferExpectSuccess(collectionId, tokenId, charlie, bob);
+ const aliceBalanceAfterSponsoredTransaction = await getFreeBalance(alice);
expect(aliceBalanceAfterSponsoredTransaction < aliceBalanceBefore).to.be.true;
//expect(aliceBalanceAfterSponsoredTransaction).to.be.lessThan(aliceBalanceBefore);
await destroyCollectionExpectSuccess(collectionId);
@@ -272,115 +272,115 @@
});
describe('Collection zero limits (NFT)', () => {
- let Alice: IKeyringPair;
- let Bob: IKeyringPair;
- let Charlie: IKeyringPair;
+ let alice: IKeyringPair;
+ let bob: IKeyringPair;
+ let charlie: IKeyringPair;
before(async () => {
await usingApi(async () => {
- Alice = privateKey('//Alice');
- Bob = privateKey('//Bob');
- Charlie = privateKey('//Charlie');
+ alice = privateKey('//Alice');
+ bob = privateKey('//Bob');
+ charlie = privateKey('//Charlie');
});
});
it.skip('Limits have 0 in tokens per address field, the chain limits are applied', async () => {
- const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });
- await setCollectionLimitsExpectSuccess(Alice, collectionId, { accountTokenOwnershipLimit: 0 });
+ const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
+ await setCollectionLimitsExpectSuccess(alice, collectionId, {accountTokenOwnershipLimit: 0});
for(let i = 0; i < 10; i++){
- await createItemExpectSuccess(Alice, collectionId, 'NFT');
+ await createItemExpectSuccess(alice, collectionId, 'NFT');
}
- await createItemExpectFailure(Alice, collectionId, 'NFT');
+ await createItemExpectFailure(alice, collectionId, 'NFT');
});
it('Limits have 0 in sponsor timeout, no limits are applied', async () => {
- const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });
- await setCollectionLimitsExpectSuccess(Alice, collectionId, { sponsorTimeout: 0 });
- const tokenId = await createItemExpectSuccess(Alice, collectionId, 'NFT');
- await setCollectionSponsorExpectSuccess(collectionId, Alice.address);
+ const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
+ await setCollectionLimitsExpectSuccess(alice, collectionId, {sponsorTransferTimeout: 0});
+ const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');
+ await setCollectionSponsorExpectSuccess(collectionId, alice.address);
await confirmSponsorshipExpectSuccess(collectionId, '//Alice');
- await transferExpectSuccess(collectionId, tokenId, Alice, Bob);
- const aliceBalanceBefore = await getFreeBalance(Alice);
+ await transferExpectSuccess(collectionId, tokenId, alice, bob);
+ const aliceBalanceBefore = await getFreeBalance(alice);
// check setting SponsorTimeout = 0, success with next block
await waitNewBlocks(1);
- await transferExpectSuccess(collectionId, tokenId, Bob, Charlie);
- const aliceBalanceAfterSponsoredTransaction1 = await getFreeBalance(Alice);
+ await transferExpectSuccess(collectionId, tokenId, bob, charlie);
+ const aliceBalanceAfterSponsoredTransaction1 = await getFreeBalance(alice);
expect(aliceBalanceAfterSponsoredTransaction1 < aliceBalanceBefore).to.be.true;
//expect(aliceBalanceAfterSponsoredTransaction1).to.be.lessThan(aliceBalanceBefore);
});
});
describe('Collection zero limits (Fungible)', () => {
- let Alice: IKeyringPair;
- let Bob: IKeyringPair;
- let Charlie: IKeyringPair;
+ let alice: IKeyringPair;
+ let bob: IKeyringPair;
+ let charlie: IKeyringPair;
before(async () => {
await usingApi(async () => {
- Alice = privateKey('//Alice');
- Bob = privateKey('//Bob');
- Charlie = privateKey('//Charlie');
+ alice = privateKey('//Alice');
+ bob = privateKey('//Bob');
+ charlie = privateKey('//Charlie');
});
});
it('Limits have 0 in sponsor timeout, no limits are applied', async () => {
const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
- await setCollectionLimitsExpectSuccess(Alice, collectionId, { sponsorTimeout: 0 });
- const tokenId = await createItemExpectSuccess(Alice, collectionId, 'Fungible');
- await setCollectionSponsorExpectSuccess(collectionId, Alice.address);
+ await setCollectionLimitsExpectSuccess(alice, collectionId, {sponsorTransferTimeout: 0});
+ const tokenId = await createItemExpectSuccess(alice, collectionId, 'Fungible');
+ await setCollectionSponsorExpectSuccess(collectionId, alice.address);
await confirmSponsorshipExpectSuccess(collectionId, '//Alice');
- await transferExpectSuccess(collectionId, tokenId, Alice, Bob, 10, 'Fungible');
- const aliceBalanceBefore = await getFreeBalance(Alice);
- await transferExpectSuccess(collectionId, tokenId, Bob, Charlie, 2, 'Fungible');
+ await transferExpectSuccess(collectionId, tokenId, alice, bob, 10, 'Fungible');
+ const aliceBalanceBefore = await getFreeBalance(alice);
+ await transferExpectSuccess(collectionId, tokenId, bob, charlie, 2, 'Fungible');
// check setting SponsorTimeout = 0, success with next block
await waitNewBlocks(1);
- await transferExpectSuccess(collectionId, tokenId, Bob, Charlie, 2, 'Fungible');
- const aliceBalanceAfterSponsoredTransaction1 = await getFreeBalance(Alice);
+ await transferExpectSuccess(collectionId, tokenId, bob, charlie, 2, 'Fungible');
+ const aliceBalanceAfterSponsoredTransaction1 = await getFreeBalance(alice);
expect(aliceBalanceAfterSponsoredTransaction1 < aliceBalanceBefore).to.be.true;
//expect(aliceBalanceAfterSponsoredTransaction1).to.be.lessThan(aliceBalanceBefore);
});
});
describe('Collection zero limits (ReFungible)', () => {
- let Alice: IKeyringPair;
- let Bob: IKeyringPair;
- let Charlie: IKeyringPair;
+ let alice: IKeyringPair;
+ let bob: IKeyringPair;
+ let charlie: IKeyringPair;
before(async () => {
await usingApi(async () => {
- Alice = privateKey('//Alice');
- Bob = privateKey('//Bob');
- Charlie = privateKey('//Charlie');
+ alice = privateKey('//Alice');
+ bob = privateKey('//Bob');
+ charlie = privateKey('//Charlie');
});
});
it.skip('Limits have 0 in tokens per address field, the chain limits are applied', async () => {
- const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible' }});
- await setCollectionLimitsExpectSuccess(Alice, collectionId, { accountTokenOwnershipLimit: 0 });
+ const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
+ await setCollectionLimitsExpectSuccess(alice, collectionId, {accountTokenOwnershipLimit: 0});
for(let i = 0; i < 10; i++){
- await createItemExpectSuccess(Alice, collectionId, 'ReFungible');
+ await createItemExpectSuccess(alice, collectionId, 'ReFungible');
}
- await createItemExpectFailure(Alice, collectionId, 'ReFungible');
+ await createItemExpectFailure(alice, collectionId, 'ReFungible');
});
it('Limits have 0 in sponsor timeout, no limits are applied', async () => {
- const collectionId = await createCollectionExpectSuccess({ mode: { type: 'ReFungible' } });
- await setCollectionLimitsExpectSuccess(Alice, collectionId, { sponsorTimeout: 0 });
- const tokenId = await createItemExpectSuccess(Alice, collectionId, 'ReFungible');
- await setCollectionSponsorExpectSuccess(collectionId, Alice.address);
+ const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
+ await setCollectionLimitsExpectSuccess(alice, collectionId, {sponsorTransferTimeout: 0});
+ const tokenId = await createItemExpectSuccess(alice, collectionId, 'ReFungible');
+ await setCollectionSponsorExpectSuccess(collectionId, alice.address);
await confirmSponsorshipExpectSuccess(collectionId, '//Alice');
- await transferExpectSuccess(collectionId, tokenId, Alice, Bob, 100, 'ReFungible');
- await transferExpectSuccess(collectionId, tokenId, Bob, Charlie, 20, 'ReFungible');
- const aliceBalanceBefore = await getFreeBalance(Alice);
+ await transferExpectSuccess(collectionId, tokenId, alice, bob, 100, 'ReFungible');
+ await transferExpectSuccess(collectionId, tokenId, bob, charlie, 20, 'ReFungible');
+ const aliceBalanceBefore = await getFreeBalance(alice);
// check setting SponsorTimeout = 0, success with next block
await waitNewBlocks(1);
- await transferExpectSuccess(collectionId, tokenId, Bob, Charlie, 20, 'ReFungible');
- const aliceBalanceAfterSponsoredTransaction1 = await getFreeBalance(Alice);
+ await transferExpectSuccess(collectionId, tokenId, bob, charlie, 20, 'ReFungible');
+ const aliceBalanceAfterSponsoredTransaction1 = await getFreeBalance(alice);
expect(aliceBalanceAfterSponsoredTransaction1 < aliceBalanceBefore).to.be.true;
//expect(aliceBalanceAfterSponsoredTransaction1).to.be.lessThan(aliceBalanceBefore);
});
tests/src/metadataUpdate.test.tsdiffbeforeafterboth--- a/tests/src/metadataUpdate.test.ts
+++ b/tests/src/metadataUpdate.test.ts
@@ -27,53 +27,53 @@
describe('Metadata update permissions with ItemOwner flag', () => {
it('ItemOwner can set variable metadata with ItemOwner permission flag', async () => {
await usingApi(async () => {
- const Alice = privateKey('//Alice');
+ const alice = privateKey('//Alice');
const data = [1, 2, 254, 255];
// nft
const nftCollectionId = await createCollectionExpectSuccess();
- const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
- await setMetadataUpdatePermissionFlagExpectSuccess(Alice, nftCollectionId, 'ItemOwner');
+ const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
+ await setMetadataUpdatePermissionFlagExpectSuccess(alice, nftCollectionId, 'ItemOwner');
- await setVariableMetaDataExpectSuccess(Alice, nftCollectionId, newNftTokenId, data);
+ await setVariableMetaDataExpectSuccess(alice, nftCollectionId, newNftTokenId, data);
});
});
it('Admin can\'n set variable metadata with ItemOwner permission flag', async () => {
await usingApi(async () => {
- const Alice = privateKey('//Alice');
- const Bob = privateKey('//Bob');
-
+ const alice = privateKey('//Alice');
+ const bob = privateKey('//Bob');
+
const data = [1, 2, 254, 255];
-
+
// nft
const nftCollectionId = await createCollectionExpectSuccess();
- const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
- await setMetadataUpdatePermissionFlagExpectSuccess(Alice, nftCollectionId, 'ItemOwner');
+ const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
+ await setMetadataUpdatePermissionFlagExpectSuccess(alice, nftCollectionId, 'ItemOwner');
+
+ await setMintPermissionExpectSuccess(alice, nftCollectionId, true);
+ await addToWhiteListExpectSuccess(alice, nftCollectionId, bob.address);
+ await addCollectionAdminExpectSuccess(alice, nftCollectionId, bob.address);
- await setMintPermissionExpectSuccess(Alice, nftCollectionId, true);
- await addToWhiteListExpectSuccess(Alice, nftCollectionId, Bob.address);
- await addCollectionAdminExpectSuccess(Alice, nftCollectionId, Bob);
-
- await setVariableMetaDataExpectFailure(Bob, nftCollectionId, newNftTokenId, data);
+ await setVariableMetaDataExpectFailure(bob, nftCollectionId, newNftTokenId, data);
});
});
it('User can\'n set variable metadata with ItemOwner permission flag', async () => {
await usingApi(async () => {
- const Alice = privateKey('//Alice');
- const Bob = privateKey('//Bob');
-
+ const alice = privateKey('//Alice');
+ const bob = privateKey('//Bob');
+
const data = [1, 2, 254, 255];
-
+
// nft
const nftCollectionId = await createCollectionExpectSuccess();
- const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
- await setMetadataUpdatePermissionFlagExpectSuccess(Alice, nftCollectionId, 'ItemOwner');
+ const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
+ await setMetadataUpdatePermissionFlagExpectSuccess(alice, nftCollectionId, 'ItemOwner');
- await setMintPermissionExpectSuccess(Alice, nftCollectionId, true);
- await setVariableMetaDataExpectFailure(Bob, nftCollectionId, newNftTokenId, data);
+ await setMintPermissionExpectSuccess(alice, nftCollectionId, true);
+ await setVariableMetaDataExpectFailure(bob, nftCollectionId, newNftTokenId, data);
});
});
});
@@ -81,60 +81,60 @@
describe('Metadata update permissions with Admin flag', () => {
it('Admin can set variable metadata with Admin permission flag', async () => {
await usingApi(async () => {
- const Alice = privateKey('//Alice');
- const Bob = privateKey('//Bob');
-
+ const alice = privateKey('//Alice');
+ const bob = privateKey('//Bob');
+
const data = [1, 2, 254, 255];
-
+
// nft
const nftCollectionId = await createCollectionExpectSuccess();
- const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
- await setMetadataUpdatePermissionFlagExpectSuccess(Alice, nftCollectionId, 'Admin');
+ const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
+ await setMetadataUpdatePermissionFlagExpectSuccess(alice, nftCollectionId, 'Admin');
- await setMintPermissionExpectSuccess(Alice, nftCollectionId, true);
- await addToWhiteListExpectSuccess(Alice, nftCollectionId, Bob.address);
- await addCollectionAdminExpectSuccess(Alice, nftCollectionId, Bob);
-
- await setVariableMetaDataExpectSuccess(Bob, nftCollectionId, newNftTokenId, data);
+ await setMintPermissionExpectSuccess(alice, nftCollectionId, true);
+ await addToWhiteListExpectSuccess(alice, nftCollectionId, bob.address);
+ await addCollectionAdminExpectSuccess(alice, nftCollectionId, bob.address);
+
+ await setVariableMetaDataExpectSuccess(bob, nftCollectionId, newNftTokenId, data);
});
});
it('User can\'n can set variable metadata with Admin permission flag', async () => {
await usingApi(async () => {
- const Alice = privateKey('//Alice');
- const Bob = privateKey('//Bob');
-
+ const alice = privateKey('//Alice');
+ const bob = privateKey('//Bob');
+
const data = [1, 2, 254, 255];
-
+
// nft
const nftCollectionId = await createCollectionExpectSuccess();
- const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
- await setMetadataUpdatePermissionFlagExpectSuccess(Alice, nftCollectionId, 'Admin');
+ const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
+ await setMetadataUpdatePermissionFlagExpectSuccess(alice, nftCollectionId, 'Admin');
+
+ await setMintPermissionExpectSuccess(alice, nftCollectionId, true);
+ await addToWhiteListExpectSuccess(alice, nftCollectionId, bob.address);
+ await addCollectionAdminExpectSuccess(alice, nftCollectionId, bob.address);
- await setMintPermissionExpectSuccess(Alice, nftCollectionId, true);
- await addToWhiteListExpectSuccess(Alice, nftCollectionId, Bob.address);
- await addCollectionAdminExpectSuccess(Alice, nftCollectionId, Bob);
-
- await setVariableMetaDataExpectSuccess(Bob, nftCollectionId, newNftTokenId, data);
+ await setVariableMetaDataExpectSuccess(bob, nftCollectionId, newNftTokenId, data);
});
});
it('ItemOwner can\'n can set variable metadata with Admin permission flag', async () => {
await usingApi(async () => {
- const Alice = privateKey('//Alice');
- const Bob = privateKey('//Bob');
-
+ const alice = privateKey('//Alice');
+ const bob = privateKey('//Bob');
+
const data = [1, 2, 254, 255];
-
+
// nft
const nftCollectionId = await createCollectionExpectSuccess();
- await enablePublicMintingExpectSuccess(Alice, nftCollectionId);
- await addToWhiteListExpectSuccess(Alice, nftCollectionId, Bob.address);
- await enableWhiteListExpectSuccess(Alice, nftCollectionId);
- const newNftTokenId = await createItemExpectSuccess(Bob, nftCollectionId, 'NFT');
- await setMetadataUpdatePermissionFlagExpectSuccess(Alice, nftCollectionId, 'Admin');
-
- await setVariableMetaDataExpectFailure(Bob, nftCollectionId, newNftTokenId, data);
+ await enablePublicMintingExpectSuccess(alice, nftCollectionId);
+ await addToWhiteListExpectSuccess(alice, nftCollectionId, bob.address);
+ await enableWhiteListExpectSuccess(alice, nftCollectionId);
+ const newNftTokenId = await createItemExpectSuccess(bob, nftCollectionId, 'NFT');
+ await setMetadataUpdatePermissionFlagExpectSuccess(alice, nftCollectionId, 'Admin');
+
+ await setVariableMetaDataExpectFailure(bob, nftCollectionId, newNftTokenId, data);
});
});
});
@@ -142,63 +142,63 @@
describe('Metadata update permissions with None flag', () => {
it('Nobody can set variable metadata with None flag (Regular)', async () => {
await usingApi(async () => {
- const Alice = privateKey('//Alice');
- const Bob = privateKey('//Bob');
-
+ const alice = privateKey('//Alice');
+ const bob = privateKey('//Bob');
+
const data = [1, 2, 254, 255];
-
+
// nft
const nftCollectionId = await createCollectionExpectSuccess();
- const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
- await setMetadataUpdatePermissionFlagExpectSuccess(Alice, nftCollectionId, 'None');
-
- await setVariableMetaDataExpectFailure(Bob, nftCollectionId, newNftTokenId, data);
+ const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
+ await setMetadataUpdatePermissionFlagExpectSuccess(alice, nftCollectionId, 'None');
+
+ await setVariableMetaDataExpectFailure(bob, nftCollectionId, newNftTokenId, data);
});
});
it('Nobody can set variable metadata with None flag (Admin)', async () => {
await usingApi(async () => {
- const Alice = privateKey('//Alice');
- const Bob = privateKey('//Bob');
-
+ const alice = privateKey('//Alice');
+ const bob = privateKey('//Bob');
+
const data = [1, 2, 254, 255];
-
+
// nft
const nftCollectionId = await createCollectionExpectSuccess();
- const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
- await setMetadataUpdatePermissionFlagExpectSuccess(Alice, nftCollectionId, 'None');
-
- await setMintPermissionExpectSuccess(Alice, nftCollectionId, true);
- await addToWhiteListExpectSuccess(Alice, nftCollectionId, Bob.address);
- await addCollectionAdminExpectSuccess(Alice, nftCollectionId, Bob);
-
- await setVariableMetaDataExpectFailure(Bob, nftCollectionId, newNftTokenId, data);
+ const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
+ await setMetadataUpdatePermissionFlagExpectSuccess(alice, nftCollectionId, 'None');
+
+ await setMintPermissionExpectSuccess(alice, nftCollectionId, true);
+ await addToWhiteListExpectSuccess(alice, nftCollectionId, bob.address);
+ await addCollectionAdminExpectSuccess(alice, nftCollectionId, bob.address);
+
+ await setVariableMetaDataExpectFailure(bob, nftCollectionId, newNftTokenId, data);
});
});
it('Nobody can set variable metadata with None flag (ItemOwner)', async () => {
await usingApi(async () => {
- const Alice = privateKey('//Alice');
-
+ const alice = privateKey('//Alice');
+
const data = [1, 2, 254, 255];
-
+
// nft
const nftCollectionId = await createCollectionExpectSuccess();
- const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
- await setMetadataUpdatePermissionFlagExpectSuccess(Alice, nftCollectionId, 'None');
-
- await setVariableMetaDataExpectFailure(Alice, nftCollectionId, newNftTokenId, data);
+ const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
+ await setMetadataUpdatePermissionFlagExpectSuccess(alice, nftCollectionId, 'None');
+
+ await setVariableMetaDataExpectFailure(alice, nftCollectionId, newNftTokenId, data);
});
});
it('Nobody can set variable metadata flag after freeze', async () => {
await usingApi(async () => {
- const Alice = privateKey('//Alice');
-
+ const alice = privateKey('//Alice');
+
// nft
const nftCollectionId = await createCollectionExpectSuccess();
- await setMetadataUpdatePermissionFlagExpectSuccess(Alice, nftCollectionId, 'None');
- await setMetadataUpdatePermissionFlagExpectFailure(Alice, nftCollectionId, 'Admin');
+ await setMetadataUpdatePermissionFlagExpectSuccess(alice, nftCollectionId, 'None');
+ await setMetadataUpdatePermissionFlagExpectFailure(alice, nftCollectionId, 'Admin');
});
});
});
tests/src/mintModes.test.tsdiffbeforeafterboth--- a/tests/src/mintModes.test.ts
+++ b/tests/src/mintModes.test.ts
@@ -3,7 +3,7 @@
// file 'LICENSE', which is part of this source code package.
//
-import { IKeyringPair } from '@polkadot/types/types';
+import {IKeyringPair} from '@polkadot/types/types';
import privateKey from './substrate/privateKey';
import usingApi from './substrate/substrate-api';
import {
@@ -30,7 +30,7 @@
it('If the AllowList mode is enabled, then the address added to the whitelist and not the owner or administrator can create tokens', async () => {
await usingApi(async () => {
- const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });
+ const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
await enableWhiteListExpectSuccess(alice, collectionId);
await setMintPermissionExpectSuccess(alice, collectionId, true);
await addToWhiteListExpectSuccess(alice, collectionId, bob.address);
@@ -41,7 +41,7 @@
it('If the AllowList mode is enabled, address not included in whitelist that is regular user cannot create tokens', async () => {
await usingApi(async () => {
- const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });
+ const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
await enableWhiteListExpectSuccess(alice, collectionId);
await setMintPermissionExpectSuccess(alice, collectionId, true);
await createItemExpectFailure(bob, collectionId, 'NFT');
@@ -50,17 +50,17 @@
it('If the AllowList mode is enabled, address not included in whitelist that is admin can create tokens', async () => {
await usingApi(async () => {
- const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });
+ const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
await enableWhiteListExpectSuccess(alice, collectionId);
await setMintPermissionExpectSuccess(alice, collectionId, true);
- await addCollectionAdminExpectSuccess(alice, collectionId, bob);
+ await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
await createItemExpectSuccess(bob, collectionId, 'NFT');
});
});
it('If the AllowList mode is enabled, address not included in whitelist that is owner can create tokens', async () => {
await usingApi(async () => {
- const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });
+ const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
await enableWhiteListExpectSuccess(alice, collectionId);
await setMintPermissionExpectSuccess(alice, collectionId, true);
await createItemExpectSuccess(alice, collectionId, 'NFT');
@@ -69,7 +69,7 @@
it('If the AllowList mode is disabled, owner can create tokens', async () => {
await usingApi(async () => {
- const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });
+ const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
await disableWhiteListExpectSuccess(alice, collectionId);
await setMintPermissionExpectSuccess(alice, collectionId, true);
await createItemExpectSuccess(alice, collectionId, 'NFT');
@@ -78,17 +78,17 @@
it('If the AllowList mode is disabled, collection admin can create tokens', async () => {
await usingApi(async () => {
- const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });
+ const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
await disableWhiteListExpectSuccess(alice, collectionId);
await setMintPermissionExpectSuccess(alice, collectionId, true);
- await addCollectionAdminExpectSuccess(alice, collectionId, bob);
+ await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
await createItemExpectSuccess(bob, collectionId, 'NFT');
});
});
it('If the AllowList mode is disabled, regular user can`t create tokens', async () => {
await usingApi(async () => {
- const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });
+ const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
await disableWhiteListExpectSuccess(alice, collectionId);
await setMintPermissionExpectSuccess(alice, collectionId, true);
await createItemExpectFailure(bob, collectionId, 'NFT');
@@ -109,7 +109,7 @@
it('Address that is the not owner or not admin cannot create tokens', async () => {
await usingApi(async () => {
- const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });
+ const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
await enableWhiteListExpectSuccess(alice, collectionId);
await setMintPermissionExpectSuccess(alice, collectionId, false);
await addToWhiteListExpectSuccess(alice, collectionId, bob.address);
@@ -119,7 +119,7 @@
it('Address that is collection owner can create tokens', async () => {
await usingApi(async () => {
- const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });
+ const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
await disableWhiteListExpectSuccess(alice, collectionId);
await setMintPermissionExpectSuccess(alice, collectionId, false);
await createItemExpectSuccess(alice, collectionId, 'NFT');
@@ -128,10 +128,10 @@
it('Address that is admin can create tokens', async () => {
await usingApi(async () => {
- const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });
+ const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
await disableWhiteListExpectSuccess(alice, collectionId);
await setMintPermissionExpectSuccess(alice, collectionId, false);
- await addCollectionAdminExpectSuccess(alice, collectionId, bob);
+ await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
await createItemExpectSuccess(bob, collectionId, 'NFT');
});
});
tests/src/overflow.test.tsdiffbeforeafterboth--- a/tests/src/overflow.test.ts
+++ b/tests/src/overflow.test.ts
@@ -3,12 +3,12 @@
// file 'LICENSE', which is part of this source code package.
//
-import { IKeyringPair } from '@polkadot/types/types';
+import {IKeyringPair} from '@polkadot/types/types';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import privateKey from './substrate/privateKey';
import usingApi from './substrate/substrate-api';
-import { approveExpectFail, approveExpectSuccess, createCollectionExpectSuccess, createFungibleItemExpectSuccess, getAllowance, getFungibleBalance, transferExpectFailure, transferExpectSuccess, transferFromExpectFail, transferFromExpectSuccess, U128_MAX } from './util/helpers';
+import {approveExpectSuccess, createCollectionExpectSuccess, createFungibleItemExpectSuccess, getAllowance, getBalance, transferExpectFailure, transferExpectSuccess, transferFromExpectFail, transferFromExpectSuccess, U128_MAX} from './util/helpers';
chai.use(chaiAsPromised);
const expect = chai.expect;
@@ -27,41 +27,36 @@
});
it('fails when overflows on transfer', async () => {
- const fungibleCollectionId = await createCollectionExpectSuccess({ mode: { type: 'Fungible', decimalPoints: 0 } });
+ await usingApi(async api => {
+ const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
- await createFungibleItemExpectSuccess(alice, fungibleCollectionId, { Value: U128_MAX });
- await transferExpectSuccess(fungibleCollectionId, 0, alice, bob, U128_MAX, 'Fungible');
-
- await createFungibleItemExpectSuccess(alice, fungibleCollectionId, { Value: 1n });
- await transferExpectFailure(fungibleCollectionId, 0, alice, bob, 1);
-
- expect(await getFungibleBalance(fungibleCollectionId, alice.address)).to.equal(1n);
- expect(await getFungibleBalance(fungibleCollectionId, bob.address)).to.equal(U128_MAX);
- });
+ await createFungibleItemExpectSuccess(alice, fungibleCollectionId, {Value: U128_MAX});
+ await transferExpectSuccess(fungibleCollectionId, 0, alice, bob, U128_MAX, 'Fungible');
- it('fails on allowance overflow', async () => {
- const fungibleCollectionId = await createCollectionExpectSuccess({ mode: { type: 'Fungible', decimalPoints: 0 } });
+ await createFungibleItemExpectSuccess(alice, fungibleCollectionId, {Value: 1n});
+ await transferExpectFailure(fungibleCollectionId, 0, alice, bob, 1);
- await createFungibleItemExpectSuccess(alice, fungibleCollectionId, { Value: U128_MAX });
- await approveExpectSuccess(fungibleCollectionId, 0, alice, bob, U128_MAX);
- await approveExpectFail(fungibleCollectionId, 0, alice, bob, U128_MAX);
+ expect(await getBalance(api, fungibleCollectionId, alice.address, 0)).to.equal(1n);
+ expect(await getBalance(api, fungibleCollectionId, bob.address, 0)).to.equal(U128_MAX);
+ });
});
it('fails when overflows on transferFrom', async () => {
- const fungibleCollectionId = await createCollectionExpectSuccess({ mode: { type: 'Fungible', decimalPoints: 0 } });
+ await usingApi(async api => {
+ const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
+ await createFungibleItemExpectSuccess(alice, fungibleCollectionId, {Value: U128_MAX});
+ await approveExpectSuccess(fungibleCollectionId, 0, alice, bob.address, U128_MAX);
+ await transferFromExpectSuccess(fungibleCollectionId, 0, bob, alice, charlie, U128_MAX, 'Fungible');
- await createFungibleItemExpectSuccess(alice, fungibleCollectionId, { Value: U128_MAX });
- await approveExpectSuccess(fungibleCollectionId, 0, alice, bob, U128_MAX);
- await transferFromExpectSuccess(fungibleCollectionId, 0, bob, alice, charlie, U128_MAX, 'Fungible');
+ expect(await getBalance(api, fungibleCollectionId, charlie.address, 0)).to.equal(U128_MAX);
+ expect(await getAllowance(api, fungibleCollectionId, alice.address, bob.address, 0)).to.equal(0n);
- expect(await getFungibleBalance(fungibleCollectionId, charlie.address)).to.equal(U128_MAX);
- expect((await getAllowance(fungibleCollectionId, 0, alice.address, bob.address)).toString()).to.equal('0');
-
- await createFungibleItemExpectSuccess(alice, fungibleCollectionId, { Value: U128_MAX });
- await approveExpectSuccess(fungibleCollectionId, 0, alice, bob, 1n);
- await transferFromExpectFail(fungibleCollectionId, 0, bob, alice, charlie, 1);
+ await createFungibleItemExpectSuccess(alice, fungibleCollectionId, {Value: U128_MAX});
+ await approveExpectSuccess(fungibleCollectionId, 0, alice, bob.address, 1n);
+ await transferFromExpectFail(fungibleCollectionId, 0, bob, alice, charlie, 1);
- expect(await getFungibleBalance(fungibleCollectionId, charlie.address)).to.equal(U128_MAX);
- expect((await getAllowance(fungibleCollectionId, 0, alice.address, bob.address)).toString()).to.equal('1');
+ expect(await getBalance(api, fungibleCollectionId, charlie.address, 0)).to.equal(U128_MAX);
+ expect(await getAllowance(api, fungibleCollectionId, alice.address, bob.address, 0)).to.equal(1n);
+ });
});
});
tests/src/pallet-presence.test.tsdiffbeforeafterboth--- a/tests/src/pallet-presence.test.ts
+++ b/tests/src/pallet-presence.test.ts
@@ -3,8 +3,8 @@
// file 'LICENSE', which is part of this source code package.
//
-import { ApiPromise } from '@polkadot/api';
-import { expect } from 'chai';
+import {ApiPromise} from '@polkadot/api';
+import {expect} from 'chai';
import usingApi from './substrate/substrate-api';
function getModuleNames(api: ApiPromise): string[] {
@@ -14,6 +14,7 @@
// Pallets that must always be present
const requiredPallets = [
'balances',
+ 'common',
'randomnesscollectiveflip',
'timestamp',
'transactionpayment',
@@ -28,12 +29,15 @@
'evmmigration',
'evmtransactionpayment',
'ethereum',
+ 'fungible',
'xcmpqueue',
'polkadotxcm',
'cumulusxcm',
'dmpqueue',
'inflation',
'nft',
+ 'nonfungible',
+ 'refungible',
'scheduler',
'nftpayment',
'charging',
tests/src/removeCollectionAdmin.test.tsdiffbeforeafterboth--- a/tests/src/removeCollectionAdmin.test.ts
+++ b/tests/src/removeCollectionAdmin.test.ts
@@ -3,12 +3,12 @@
// file 'LICENSE', which is part of this source code package.
//
-import { ApiPromise } from '@polkadot/api';
+import {ApiPromise} from '@polkadot/api';
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, destroyCollectionExpectSuccess, normalizeAccountId} from './util/helpers';
+import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';
+import {createCollectionExpectSuccess, destroyCollectionExpectSuccess, getAdminList, normalizeAccountId} from './util/helpers';
chai.use(chaiAsPromised);
const expect = chai.expect;
@@ -17,63 +17,63 @@
it('Remove collection admin.', async () => {
await usingApi(async (api: ApiPromise) => {
const collectionId = await createCollectionExpectSuccess();
- const Alice = privateKey('//Alice');
- const Bob = privateKey('//Bob');
- const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
- expect(collection.owner).to.be.deep.eq(Alice.address);
+ const alice = privateKey('//Alice');
+ const bob = privateKey('//Bob');
+ const collection = (await api.query.common.collectionById(collectionId)).unwrap();
+ expect(collection.owner.toString()).to.be.deep.eq(alice.address);
// first - add collection admin Bob
- const addAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Bob.address));
- await submitTransactionAsync(Alice, addAdminTx);
+ const addAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));
+ await submitTransactionAsync(alice, addAdminTx);
- const adminListAfterAddAdmin: any = (await api.query.nft.adminList(collectionId)).toJSON();
- expect(adminListAfterAddAdmin).to.be.deep.contains(normalizeAccountId(Bob.address));
+ const adminListAfterAddAdmin = await getAdminList(api, collectionId);
+ expect(adminListAfterAddAdmin).to.be.deep.contains(normalizeAccountId(bob.address));
// then remove bob from admins of collection
- const removeAdminTx = api.tx.nft.removeCollectionAdmin(collectionId, normalizeAccountId(Bob.address));
- await submitTransactionAsync(Alice, removeAdminTx);
+ const removeAdminTx = api.tx.nft.removeCollectionAdmin(collectionId, normalizeAccountId(bob.address));
+ await submitTransactionAsync(alice, removeAdminTx);
- const adminListAfterRemoveAdmin: any = (await api.query.nft.adminList(collectionId)).toJSON;
- expect(adminListAfterRemoveAdmin).not.to.be.deep.contains(normalizeAccountId(Bob.address));
+ const adminListAfterRemoveAdmin = await getAdminList(api, collectionId);
+ expect(adminListAfterRemoveAdmin).not.to.be.deep.contains(normalizeAccountId(bob.address));
});
});
it('Remove collection admin by admin.', async () => {
await usingApi(async (api: ApiPromise) => {
const collectionId = await createCollectionExpectSuccess();
- const Alice = privateKey('//Alice');
- const Bob = privateKey('//Bob');
- const Charlie = privateKey('//Charlie');
- const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
- expect(collection.owner).to.be.deep.eq(Alice.address);
+ const alice = privateKey('//Alice');
+ const bob = privateKey('//Bob');
+ const charlie = privateKey('//Charlie');
+ const collection = (await api.query.common.collectionById(collectionId)).unwrap();
+ expect(collection.owner.toString()).to.be.eq(alice.address);
// first - add collection admin Bob
- const addAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Bob.address));
- await submitTransactionAsync(Alice, addAdminTx);
+ const addAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));
+ await submitTransactionAsync(alice, addAdminTx);
- const addAdminTx2 = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Charlie.address));
- await submitTransactionAsync(Alice, addAdminTx2);
+ const addAdminTx2 = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(charlie.address));
+ await submitTransactionAsync(alice, addAdminTx2);
- const adminListAfterAddAdmin: any = (await api.query.nft.adminList(collectionId)).toJSON();
- expect(adminListAfterAddAdmin).to.be.deep.contains(normalizeAccountId(Bob.address));
+ const adminListAfterAddAdmin = await getAdminList(api, collectionId);
+ expect(adminListAfterAddAdmin).to.be.deep.contains(normalizeAccountId(bob.address));
// then remove bob from admins of collection
- const removeAdminTx = api.tx.nft.removeCollectionAdmin(collectionId, normalizeAccountId(Bob.address));
- await submitTransactionAsync(Charlie, removeAdminTx);
+ const removeAdminTx = api.tx.nft.removeCollectionAdmin(collectionId, normalizeAccountId(bob.address));
+ await submitTransactionAsync(charlie, removeAdminTx);
- const adminListAfterRemoveAdmin: any = (await api.query.nft.adminList(collectionId)).toJSON;
- expect(adminListAfterRemoveAdmin).not.to.be.deep.contains(normalizeAccountId(Bob.address));
+ const adminListAfterRemoveAdmin = await getAdminList(api, collectionId);
+ expect(adminListAfterRemoveAdmin).not.to.be.deep.contains(normalizeAccountId(bob.address));
});
});
it('Remove admin from collection that has no admins', async () => {
await usingApi(async (api: ApiPromise) => {
- const Alice = privateKey('//Alice');
+ const alice = privateKey('//Alice');
const collectionId = await createCollectionExpectSuccess();
- const adminListBeforeAddAdmin: any = (await api.query.nft.adminList(collectionId));
+ const adminListBeforeAddAdmin = await getAdminList(api, collectionId);
expect(adminListBeforeAddAdmin).to.have.lengthOf(0);
- const tx = api.tx.nft.removeCollectionAdmin(collectionId, normalizeAccountId(Alice.address));
- await submitTransactionAsync(Alice, tx);
+ const tx = api.tx.nft.removeCollectionAdmin(collectionId, normalizeAccountId(alice.address));
+ await submitTransactionAsync(alice, tx);
});
});
});
@@ -98,13 +98,13 @@
await usingApi(async (api: ApiPromise) => {
// tslint:disable-next-line: no-bitwise
const collectionId = await createCollectionExpectSuccess();
- const Alice = privateKey('//Alice');
- const Bob = privateKey('//Bob');
+ const alice = privateKey('//Alice');
+ const bob = privateKey('//Bob');
await destroyCollectionExpectSuccess(collectionId);
- const changeOwnerTx = api.tx.nft.removeCollectionAdmin(collectionId, normalizeAccountId(Bob.address));
- await expect(submitTransactionExpectFailAsync(Alice, changeOwnerTx)).to.be.rejected;
+ const changeOwnerTx = api.tx.nft.removeCollectionAdmin(collectionId, normalizeAccountId(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();
@@ -114,15 +114,15 @@
it('Regular user Can\'t remove collection admin', async () => {
await usingApi(async (api: ApiPromise) => {
const collectionId = await createCollectionExpectSuccess();
- const Alice = privateKey('//Alice');
- const Bob = privateKey('//Bob');
- const Charlie = privateKey('//Charlie');
+ const alice = privateKey('//Alice');
+ const bob = privateKey('//Bob');
+ const charlie = privateKey('//Charlie');
- const addAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Bob.address));
- await submitTransactionAsync(Alice, addAdminTx);
+ const addAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));
+ await submitTransactionAsync(alice, addAdminTx);
- const changeOwnerTx = api.tx.nft.removeCollectionAdmin(collectionId, normalizeAccountId(Bob.address));
- await expect(submitTransactionExpectFailAsync(Charlie, changeOwnerTx)).to.be.rejected;
+ const changeOwnerTx = api.tx.nft.removeCollectionAdmin(collectionId, normalizeAccountId(bob.address));
+ await expect(submitTransactionExpectFailAsync(charlie, changeOwnerTx)).to.be.rejected;
// Verifying that nothing bad happened (network is live, new collections can be created, etc.)
await createCollectionExpectSuccess();
tests/src/removeCollectionSponsor.test.tsdiffbeforeafterboth--- a/tests/src/removeCollectionSponsor.test.ts
+++ b/tests/src/removeCollectionSponsor.test.ts
@@ -5,11 +5,11 @@
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
-import { default as usingApi, submitTransactionExpectFailAsync } from './substrate/substrate-api';
-import {
- createCollectionExpectSuccess,
- setCollectionSponsorExpectSuccess,
- destroyCollectionExpectSuccess,
+import {default as usingApi, submitTransactionExpectFailAsync} from './substrate/substrate-api';
+import {
+ createCollectionExpectSuccess,
+ setCollectionSponsorExpectSuccess,
+ destroyCollectionExpectSuccess,
confirmSponsorshipExpectSuccess,
confirmSponsorshipExpectFailure,
createItemExpectSuccess,
@@ -19,9 +19,8 @@
normalizeAccountId,
addCollectionAdminExpectSuccess,
} from './util/helpers';
-import { Keyring } from '@polkadot/api';
-import { IKeyringPair } from '@polkadot/types/types';
-import { BigNumber } from 'bignumber.js';
+import {Keyring} from '@polkadot/api';
+import {IKeyringPair} from '@polkadot/types/types';
chai.use(chaiAsPromised);
const expect = chai.expect;
@@ -33,7 +32,7 @@
before(async () => {
await usingApi(async () => {
- const keyring = new Keyring({ type: 'sr25519' });
+ const keyring = new Keyring({type: 'sr25519'});
alice = keyring.addFromUri('//Alice');
bob = keyring.addFromUri('//Bob');
});
@@ -53,15 +52,15 @@
const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', zeroBalance.address);
// Transfer this tokens from unused address to Alice - should fail
- const AsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());
+ const sponsorBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();
const zeroToAlice = api.tx.nft.transfer(normalizeAccountId(alice.address), collectionId, itemId, 0);
- const badTransaction = async function () {
+ const badTransaction = async function () {
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());
+ const sponsorBalanceAfter = (await api.query.system.account(bob.address)).data.free.toBigInt();
- expect(BsponsorBalance.isEqualTo(AsponsorBalance)).to.be.true;
+ expect(sponsorBalanceAfter).to.be.equal(sponsorBalanceBefore);
});
});
@@ -89,7 +88,7 @@
describe('(!negative test!) integration test: ext. removeCollectionSponsor():', () => {
before(async () => {
await usingApi(async () => {
- const keyring = new Keyring({ type: 'sr25519' });
+ const keyring = new Keyring({type: 'sr25519'});
alice = keyring.addFromUri('//Alice');
bob = keyring.addFromUri('//Bob');
});
@@ -99,7 +98,7 @@
// Find the collection that never existed
let collectionId = 0;
await usingApi(async (api) => {
- collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;
+ collectionId = (await api.query.common.createdCollectionCount()).toNumber() + 1;
});
await removeCollectionSponsorExpectFailure(collectionId);
@@ -108,7 +107,7 @@
it('(!negative test!) Remove sponsor for a collection with collection admin permissions', async () => {
const collectionId = await createCollectionExpectSuccess();
await setCollectionSponsorExpectSuccess(collectionId, bob.address);
- await addCollectionAdminExpectSuccess(alice, collectionId, bob);
+ await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
await removeCollectionSponsorExpectFailure(collectionId, '//Bob');
});
tests/src/removeFromContractWhiteList.test.tsdiffbeforeafterboth--- a/tests/src/removeFromContractWhiteList.test.ts
+++ b/tests/src/removeFromContractWhiteList.test.ts
@@ -5,10 +5,10 @@
import privateKey from './substrate/privateKey';
import usingApi from './substrate/substrate-api';
-import { deployFlipper, toggleFlipValueExpectFailure, toggleFlipValueExpectSuccess } from './util/contracthelpers';
-import { addToContractWhiteListExpectSuccess, isWhitelistedInContract, removeFromContractWhiteListExpectFailure, removeFromContractWhiteListExpectSuccess, toggleContractWhitelistExpectSuccess } from './util/helpers';
-import { IKeyringPair } from '@polkadot/types/types';
-import { expect } from 'chai';
+import {deployFlipper, toggleFlipValueExpectFailure, toggleFlipValueExpectSuccess} from './util/contracthelpers';
+import {addToContractWhiteListExpectSuccess, isWhitelistedInContract, removeFromContractWhiteListExpectFailure, removeFromContractWhiteListExpectSuccess, toggleContractWhitelistExpectSuccess} from './util/helpers';
+import {IKeyringPair} from '@polkadot/types/types';
+import {expect} from 'chai';
describe.skip('Integration Test removeFromContractWhiteList', () => {
let bob: IKeyringPair;
tests/src/removeFromWhiteList.test.tsdiffbeforeafterboth--- a/tests/src/removeFromWhiteList.test.ts
+++ b/tests/src/removeFromWhiteList.test.ts
@@ -5,7 +5,7 @@
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
-import { default as usingApi } from './substrate/substrate-api';
+import {default as usingApi} from './substrate/substrate-api';
import {
createCollectionExpectSuccess,
destroyCollectionExpectSuccess,
@@ -19,7 +19,7 @@
normalizeAccountId,
addCollectionAdminExpectSuccess,
} from './util/helpers';
-import { IKeyringPair } from '@polkadot/types/types';
+import {IKeyringPair} from '@polkadot/types/types';
import privateKey from './substrate/privateKey';
chai.use(chaiAsPromised);
@@ -38,7 +38,7 @@
it('ensure bob is not in whitelist after removal', async () => {
await usingApi(async () => {
- const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });
+ const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
await enableWhiteListExpectSuccess(alice, collectionId);
await addToWhiteListExpectSuccess(alice, collectionId, bob.address);
@@ -105,9 +105,9 @@
it('ensure address is not in whitelist after removal', async () => {
await usingApi(async () => {
- const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });
+ const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
await enableWhiteListExpectSuccess(alice, collectionId);
- await addCollectionAdminExpectSuccess(alice, collectionId, bob);
+ await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
await addToWhiteListExpectSuccess(alice, collectionId, charlie.address);
await removeFromWhiteListExpectSuccess(bob, collectionId, normalizeAccountId(charlie.address));
expect(await isWhitelisted(collectionId, charlie.address)).to.be.false;
@@ -118,7 +118,7 @@
await usingApi(async () => {
const collectionWithoutWhitelistId = await createCollectionExpectSuccess();
await enableWhiteListExpectSuccess(alice, collectionWithoutWhitelistId);
- await addCollectionAdminExpectSuccess(alice, collectionWithoutWhitelistId, bob);
+ await addCollectionAdminExpectSuccess(alice, collectionWithoutWhitelistId, bob.address);
await addToWhiteListExpectSuccess(alice, collectionWithoutWhitelistId, charlie.address);
await disableWhiteListExpectSuccess(alice, collectionWithoutWhitelistId);
await removeFromWhiteListExpectSuccess(bob, collectionWithoutWhitelistId, normalizeAccountId(charlie.address));
@@ -133,4 +133,4 @@
await removeFromWhiteListExpectFailure(bob, collectionWithoutWhitelistId, normalizeAccountId(charlie.address));
});
});
-});
\ No newline at end of file
+});
tests/src/rpc.load.tsdiffbeforeafterboth--- a/tests/src/rpc.load.ts
+++ b/tests/src/rpc.load.ts
@@ -3,12 +3,11 @@
// file 'LICENSE', which is part of this source code package.
//
-import usingApi, { submitTransactionAsync } from './substrate/substrate-api';
-import { IKeyringPair } from '@polkadot/types/types';
-import { Abi, BlueprintPromise as Blueprint, CodePromise, ContractPromise as Contract } from '@polkadot/api-contract';
-import { ApiPromise, Keyring } from '@polkadot/api';
-import { BigNumber } from 'bignumber.js';
-import { findUnusedAddress } from './util/helpers';
+import usingApi, {submitTransactionAsync} from './substrate/substrate-api';
+import {IKeyringPair} from '@polkadot/types/types';
+import {Abi, BlueprintPromise as Blueprint, CodePromise, ContractPromise as Contract} from '@polkadot/api-contract';
+import {ApiPromise, Keyring} from '@polkadot/api';
+import {findUnusedAddress} from './util/helpers';
import fs from 'fs';
import privateKey from './substrate/privateKey';
@@ -41,7 +40,7 @@
unsub();
resolve(result);
}
- });
+ });
});
}
@@ -50,11 +49,10 @@
const deployer = await findUnusedAddress(api);
// Transfer balance to it
- const keyring = new Keyring({ type: 'sr25519' });
+ const keyring = new Keyring({type: 'sr25519'});
const alice = keyring.addFromUri('//Alice');
- let amount = new BigNumber(endowment);
- amount = amount.plus(1e15);
- const tx = api.tx.balances.transfer(deployer.address, amount.toFixed());
+ const amount = BigInt(endowment) + 10n**15n;
+ const tx = api.tx.balances.transfer(deployer.address, amount);
await submitTransactionAsync(alice, tx);
return deployer;
@@ -100,7 +98,7 @@
await api.rpc.system.chain();
count++;
process.stdout.write(`RPC reads: ${count} times at rate ${rate} r/s \r`);
-
+
if (count % checkPoint == 0) {
hrTime = process.hrtime();
const microsec2 = hrTime[0] * 1000000 + hrTime[1] / 1000;
@@ -134,7 +132,7 @@
await getScData(contract, deployer);
count++;
process.stdout.write(`SC reads: ${count} times at rate ${rate} r/s \r`);
-
+
if (count % checkPoint == 0) {
hrTime = process.hrtime();
const microsec2 = hrTime[0] * 1000000 + hrTime[1] / 1000;
tests/src/scheduler.test.tsdiffbeforeafterboth--- a/tests/src/scheduler.test.ts
+++ b/tests/src/scheduler.test.ts
@@ -20,15 +20,15 @@
describe('Integration Test scheduler base transaction', () => {
it('User can transfer owned token with delay (scheduler)', async () => {
await usingApi(async () => {
- const Alice = privateKey('//Alice');
- const Bob = privateKey('//Bob');
+ const alice = privateKey('//Alice');
+ const bob = privateKey('//Bob');
// nft
const nftCollectionId = await createCollectionExpectSuccess();
- const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
- await setCollectionSponsorExpectSuccess(nftCollectionId, Alice.address);
+ const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
+ await setCollectionSponsorExpectSuccess(nftCollectionId, alice.address);
await confirmSponsorshipExpectSuccess(nftCollectionId);
- await scheduleTransferExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 1, 12000, 4);
+ await scheduleTransferExpectSuccess(nftCollectionId, newNftTokenId, alice, bob, 1, 4);
});
});
});
tests/src/setChainLimits.test.tsdiffbeforeafterboth--- a/tests/src/setChainLimits.test.ts
+++ b/tests/src/setChainLimits.test.ts
@@ -3,7 +3,7 @@
// file 'LICENSE', which is part of this source code package.
//
-import { IKeyringPair } from '@polkadot/types/types';
+import {IKeyringPair} from '@polkadot/types/types';
import privateKey from './substrate/privateKey';
import usingApi from './substrate/substrate-api';
import {
@@ -40,16 +40,16 @@
});
it('Collection owner cannot set chain limits', async () => {
- await createCollectionExpectSuccess({ mode: { type: 'NFT' } });
+ await createCollectionExpectSuccess({mode: {type: 'NFT'}});
await setChainLimitsExpectFailure(alice, limits);
});
it('Collection admin cannot set chain limits', async () => {
- const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });
- await addCollectionAdminExpectSuccess(alice, collectionId, bob);
+ const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
+ await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
await setChainLimitsExpectFailure(bob, limits);
});
-
+
it('Regular user cannot set chain limits', async () => {
await setChainLimitsExpectFailure(dave, limits);
});
tests/src/setCollectionLimits.test.tsdiffbeforeafterboth--- a/tests/src/setCollectionLimits.test.ts
+++ b/tests/src/setCollectionLimits.test.ts
@@ -4,19 +4,18 @@
//
// https://unique-network.readthedocs.io/en/latest/jsapi.html#setchainlimits
-import { ApiPromise, Keyring } from '@polkadot/api';
-import { IKeyringPair } from '@polkadot/types/types';
+import {ApiPromise, Keyring} from '@polkadot/api';
+import {IKeyringPair} from '@polkadot/types/types';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import usingApi, {submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';
-import { ICollectionInterface } from './types';
import {
createCollectionExpectSuccess, getCreatedCollectionCount,
getCreateItemResult,
- getDetailedCollectionInfo,
setCollectionLimitsExpectFailure,
setCollectionLimitsExpectSuccess,
addCollectionAdminExpectSuccess,
+ queryCollectionExpectSuccess,
} from './util/helpers';
chai.use(chaiAsPromised);
@@ -28,15 +27,14 @@
const accountTokenOwnershipLimit = 0;
const sponsoredDataSize = 0;
-const sponsoredMintSize = 0;
-const sponsorTimeout = 1;
+const sponsorTransferTimeout = 1;
const tokenLimit = 10;
describe('setCollectionLimits positive', () => {
let tx;
before(async () => {
await usingApi(async () => {
- const keyring = new Keyring({ type: 'sr25519' });
+ const keyring = new Keyring({type: 'sr25519'});
alice = keyring.addFromUri('//Alice');
collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});
});
@@ -47,9 +45,9 @@
collectionIdForTesting,
{
accountTokenOwnershipLimit: accountTokenOwnershipLimit,
- sponsoredMintSize: sponsoredDataSize,
+ sponsoredDataSize: sponsoredDataSize,
tokenLimit: tokenLimit,
- sponsorTimeout: sponsorTimeout,
+ sponsorTransferTimeout,
ownerCanTransfer: true,
ownerCanDestroy: true,
},
@@ -58,16 +56,16 @@
const result = getCreateItemResult(events);
// get collection limits defined previously
- const collectionInfo = await getDetailedCollectionInfo(api, collectionIdForTesting) as ICollectionInterface;
+ const collectionInfo = await queryCollectionExpectSuccess(api, collectionIdForTesting);
// tslint:disable-next-line:no-unused-expression
expect(result.success).to.be.true;
- expect(collectionInfo.limits.accountTokenOwnershipLimit).to.be.equal(accountTokenOwnershipLimit);
- expect(collectionInfo.limits.sponsoredDataSize).to.be.equal(sponsoredDataSize);
- expect(collectionInfo.limits.tokenLimit).to.be.equal(tokenLimit);
- expect(collectionInfo.limits.sponsorTimeout).to.be.equal(sponsorTimeout);
- expect(collectionInfo.limits.ownerCanTransfer).to.be.true;
- expect(collectionInfo.limits.ownerCanDestroy).to.be.true;
+ expect(collectionInfo.limits.accountTokenOwnershipLimit.unwrap().toNumber()).to.be.equal(accountTokenOwnershipLimit);
+ expect(collectionInfo.limits.sponsoredDataSize.unwrap().toNumber()).to.be.equal(sponsoredDataSize);
+ expect(collectionInfo.limits.tokenLimit.unwrap().toNumber()).to.be.equal(tokenLimit);
+ expect(collectionInfo.limits.sponsorTransferTimeout.unwrap().toNumber()).to.be.equal(sponsorTransferTimeout);
+ expect(collectionInfo.limits.ownerCanTransfer.unwrap().toJSON()).to.be.true;
+ expect(collectionInfo.limits.ownerCanDestroy.unwrap().toJSON()).to.be.true;
});
});
@@ -78,7 +76,7 @@
accountTokenOwnershipLimit: accountTokenOwnershipLimit,
sponsoredMintSize: sponsoredDataSize,
tokenLimit: tokenLimit,
- sponsorTimeout: sponsorTimeout,
+ sponsorTransferTimeout,
ownerCanTransfer: true,
ownerCanDestroy: true,
};
@@ -90,7 +88,9 @@
);
const events1 = await submitTransactionAsync(alice, tx1);
const result1 = getCreateItemResult(events1);
- const collectionInfo1 = await getDetailedCollectionInfo(api, collectionIdForTesting) as ICollectionInterface;
+ expect(result1.success).to.be.true;
+ const collectionInfo1 = await queryCollectionExpectSuccess(api, collectionIdForTesting);
+ expect(collectionInfo1.limits.tokenLimit.unwrap().toNumber()).to.be.equal(tokenLimit);
// The second time
const tx2 = api.tx.nft.setCollectionLimits(
@@ -99,13 +99,9 @@
);
const events2 = await submitTransactionAsync(alice, tx2);
const result2 = getCreateItemResult(events2);
- const collectionInfo2 = await getDetailedCollectionInfo(api, collectionIdForTesting) as ICollectionInterface;
-
- // tslint:disable-next-line:no-unused-expression
- expect(result1.success).to.be.true;
- expect(collectionInfo1.limits.tokenLimit).to.be.equal(tokenLimit);
expect(result2.success).to.be.true;
- expect(collectionInfo2.limits.tokenLimit).to.be.equal(tokenLimit);
+ const collectionInfo2 = await queryCollectionExpectSuccess(api, collectionIdForTesting);
+ expect(collectionInfo2.limits.tokenLimit.unwrap().toNumber()).to.be.equal(tokenLimit);
});
});
@@ -115,7 +111,7 @@
let tx;
before(async () => {
await usingApi(async () => {
- const keyring = new Keyring({ type: 'sr25519' });
+ const keyring = new Keyring({type: 'sr25519'});
alice = keyring.addFromUri('//Alice');
bob = keyring.addFromUri('//Bob');
collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});
@@ -130,7 +126,7 @@
{
accountTokenOwnershipLimit,
sponsoredDataSize,
- sponsoredMintSize,
+ // sponsoredMintSize,
tokenLimit,
},
);
@@ -144,7 +140,7 @@
{
accountTokenOwnershipLimit,
sponsoredDataSize,
- sponsoredMintSize,
+ // sponsoredMintSize,
tokenLimit,
},
);
@@ -152,14 +148,14 @@
});
});
it('execute setCollectionLimits from admin collection', async () => {
- await addCollectionAdminExpectSuccess(alice, collectionIdForTesting, bob);
+ await addCollectionAdminExpectSuccess(alice, collectionIdForTesting, bob.address);
await usingApi(async (api: ApiPromise) => {
tx = api.tx.nft.setCollectionLimits(
collectionIdForTesting,
{
accountTokenOwnershipLimit,
sponsoredDataSize,
- sponsoredMintSize,
+ // sponsoredMintSize,
tokenLimit,
},
);
@@ -173,7 +169,7 @@
accountTokenOwnershipLimit: accountTokenOwnershipLimit,
sponsoredMintSize: sponsoredDataSize,
tokenLimit: tokenLimit,
- sponsorTimeout: sponsorTimeout,
+ sponsorTransferTimeout,
ownerCanTransfer: false,
ownerCanDestroy: true,
});
@@ -181,7 +177,7 @@
accountTokenOwnershipLimit: accountTokenOwnershipLimit,
sponsoredMintSize: sponsoredDataSize,
tokenLimit: tokenLimit,
- sponsorTimeout: sponsorTimeout,
+ sponsorTransferTimeout,
ownerCanTransfer: true,
ownerCanDestroy: true,
});
@@ -193,7 +189,7 @@
accountTokenOwnershipLimit: accountTokenOwnershipLimit,
sponsoredMintSize: sponsoredDataSize,
tokenLimit: tokenLimit,
- sponsorTimeout: sponsorTimeout,
+ sponsorTransferTimeout,
ownerCanTransfer: true,
ownerCanDestroy: false,
});
@@ -201,7 +197,7 @@
accountTokenOwnershipLimit: accountTokenOwnershipLimit,
sponsoredMintSize: sponsoredDataSize,
tokenLimit: tokenLimit,
- sponsorTimeout: sponsorTimeout,
+ sponsorTransferTimeout,
ownerCanTransfer: true,
ownerCanDestroy: true,
});
@@ -215,7 +211,7 @@
accountTokenOwnershipLimit: accountTokenOwnershipLimit,
sponsoredMintSize: sponsoredDataSize,
tokenLimit: tokenLimit,
- sponsorTimeout: sponsorTimeout,
+ sponsorTransferTimeout,
ownerCanTransfer: true,
ownerCanDestroy: true,
};
tests/src/setCollectionSponsor.test.tsdiffbeforeafterboth--- a/tests/src/setCollectionSponsor.test.ts
+++ b/tests/src/setCollectionSponsor.test.ts
@@ -5,15 +5,15 @@
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
-import { default as usingApi } from './substrate/substrate-api';
-import { createCollectionExpectSuccess,
- setCollectionSponsorExpectSuccess,
- destroyCollectionExpectSuccess,
+import {default as usingApi} from './substrate/substrate-api';
+import {createCollectionExpectSuccess,
+ setCollectionSponsorExpectSuccess,
+ destroyCollectionExpectSuccess,
setCollectionSponsorExpectFailure,
addCollectionAdminExpectSuccess,
} from './util/helpers';
-import { Keyring } from '@polkadot/api';
-import { IKeyringPair } from '@polkadot/types/types';
+import {Keyring} from '@polkadot/api';
+import {IKeyringPair} from '@polkadot/types/types';
chai.use(chaiAsPromised);
@@ -25,7 +25,7 @@
before(async () => {
await usingApi(async () => {
- const keyring = new Keyring({ type: 'sr25519' });
+ const keyring = new Keyring({type: 'sr25519'});
alice = keyring.addFromUri('//Alice');
bob = keyring.addFromUri('//Bob');
});
@@ -36,11 +36,11 @@
await setCollectionSponsorExpectSuccess(collectionId, bob.address);
});
it('Set Fungible collection sponsor', async () => {
- const collectionId = await createCollectionExpectSuccess({ mode: {type: 'Fungible', decimalPoints: 0} });
+ const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
await setCollectionSponsorExpectSuccess(collectionId, bob.address);
});
it('Set ReFungible collection sponsor', async () => {
- const collectionId = await createCollectionExpectSuccess({ mode: {type: 'ReFungible'} });
+ const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
await setCollectionSponsorExpectSuccess(collectionId, bob.address);
});
@@ -52,7 +52,7 @@
it('Replace collection sponsor', async () => {
const collectionId = await createCollectionExpectSuccess();
- const keyring = new Keyring({ type: 'sr25519' });
+ const keyring = new Keyring({type: 'sr25519'});
const charlie = keyring.addFromUri('//Charlie');
await setCollectionSponsorExpectSuccess(collectionId, bob.address);
await setCollectionSponsorExpectSuccess(collectionId, charlie.address);
@@ -62,7 +62,7 @@
describe('(!negative test!) integration test: ext. setCollectionSponsor():', () => {
before(async () => {
await usingApi(async () => {
- const keyring = new Keyring({ type: 'sr25519' });
+ const keyring = new Keyring({type: 'sr25519'});
alice = keyring.addFromUri('//Alice');
bob = keyring.addFromUri('//Bob');
charlie = keyring.addFromUri('//Charlie');
@@ -77,7 +77,7 @@
// Find the collection that never existed
let collectionId = 0;
await usingApi(async (api) => {
- collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;
+ collectionId = (await api.query.common.createdCollectionCount()).toNumber() + 1;
});
await setCollectionSponsorExpectFailure(collectionId, bob.address);
@@ -89,7 +89,7 @@
});
it('(!negative test!) Collection admin add sponsor', async () => {
const collectionId = await createCollectionExpectSuccess();
- await addCollectionAdminExpectSuccess(alice, collectionId, bob);
+ await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
await setCollectionSponsorExpectFailure(collectionId, charlie.address, '//Bob');
});
});
tests/src/setConstOnChainSchema.test.tsdiffbeforeafterboth17chai.use(chaiAsPromised);17chai.use(chaiAsPromised);18const expect = chai.expect;18const expect = chai.expect;191920let Alice: IKeyringPair;20let alice: IKeyringPair;21let Bob: IKeyringPair;21let bob: IKeyringPair;22let Shema: any;22let shema: any;23let largeShema: any;23let largeShema: any;242425before(async () => {25before(async () => {26 await usingApi(async () => {26 await usingApi(async () => {27 const keyring = new Keyring({ type: 'sr25519' });27 const keyring = new Keyring({type: 'sr25519'});28 Alice = keyring.addFromUri('//Alice');28 alice = keyring.addFromUri('//Alice');29 Bob = keyring.addFromUri('//Bob');29 bob = keyring.addFromUri('//Bob');30 Shema = '0x31';30 shema = '0x31';31 largeShema = new Array(4097).fill(0xff);31 largeShema = new Array(4097).fill(0xff);323233 });33 });37 it('Run extrinsic with parameters of the collection id, set the scheme', async () => {37 it('Run extrinsic with parameters of the collection id, set the scheme', async () => {38 await usingApi(async (api) => {38 await usingApi(async (api) => {39 const collectionId = await createCollectionExpectSuccess();39 const collectionId = await createCollectionExpectSuccess();40 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();40 const collection = (await api.query.common.collectionById(collectionId)).unwrap();41 expect(collection.owner).to.be.eq(Alice.address);41 expect(collection.owner.toString()).to.be.eq(alice.address);42 const setShema = api.tx.nft.setConstOnChainSchema(collectionId, Shema);42 const setShema = api.tx.nft.setConstOnChainSchema(collectionId, shema);43 await submitTransactionAsync(Alice, setShema);43 await submitTransactionAsync(alice, setShema);44 });44 });45 });45 });464647 it('Collection admin can set the scheme', async () => {47 it('Collection admin can set the scheme', async () => {48 await usingApi(async (api) => {48 await usingApi(async (api) => {49 const collectionId = await createCollectionExpectSuccess();49 const collectionId = await createCollectionExpectSuccess();50 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();50 const collection = (await api.query.common.collectionById(collectionId)).unwrap();51 expect(collection.owner).to.be.eq(Alice.address);51 expect(collection.owner.toString()).to.be.eq(alice.address);52 await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);52 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);53 const setShema = api.tx.nft.setConstOnChainSchema(collectionId, Shema);53 const setShema = api.tx.nft.setConstOnChainSchema(collectionId, shema);54 await submitTransactionAsync(Bob, setShema);54 await submitTransactionAsync(bob, setShema);55 });55 });56 });56 });575758 it('Checking collection data using the ConstOnChainSchema parameter', async () => {58 it('Checking collection data using the ConstOnChainSchema parameter', async () => {59 await usingApi(async (api) => {59 await usingApi(async (api) => {60 const collectionId = await createCollectionExpectSuccess();60 const collectionId = await createCollectionExpectSuccess();61 const setShema = api.tx.nft.setConstOnChainSchema(collectionId, Shema);61 const setShema = api.tx.nft.setConstOnChainSchema(collectionId, shema);62 await submitTransactionAsync(Alice, setShema);62 await submitTransactionAsync(alice, setShema);63 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();63 const collection = (await api.query.common.collectionById(collectionId)).unwrap();64 expect(collection.constOnChainSchema.toString()).to.be.eq(Shema);64 expect(collection.constOnChainSchema.toString()).to.be.eq(shema);6566 });65 });67 });66 });72 it('Set a non-existent collection', async () => {71 it('Set a non-existent collection', async () => {73 await usingApi(async (api) => {72 await usingApi(async (api) => {74 // tslint:disable-next-line: radix73 // tslint:disable-next-line: radix75 const collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;74 const collectionId = (await api.query.common.createdCollectionCount()).toNumber() + 1;76 const setShema = api.tx.nft.setConstOnChainSchema(collectionId, Shema);75 const setShema = api.tx.nft.setConstOnChainSchema(collectionId, shema);77 await expect(submitTransactionExpectFailAsync(Alice, setShema)).to.be.rejected;76 await expect(submitTransactionExpectFailAsync(alice, setShema)).to.be.rejected;78 });77 });79 });78 });807981 it('Set a previously deleted collection', async () => {80 it('Set a previously deleted collection', async () => {82 await usingApi(async (api) => {81 await usingApi(async (api) => {83 const collectionId = await createCollectionExpectSuccess();82 const collectionId = await createCollectionExpectSuccess();84 await destroyCollectionExpectSuccess(collectionId);83 await destroyCollectionExpectSuccess(collectionId);85 const setShema = api.tx.nft.setConstOnChainSchema(collectionId, Shema);84 const setShema = api.tx.nft.setConstOnChainSchema(collectionId, shema);86 await expect(submitTransactionExpectFailAsync(Alice, setShema)).to.be.rejected;85 await expect(submitTransactionExpectFailAsync(alice, setShema)).to.be.rejected;87 });86 });88 });87 });898890 it('Set invalid data in schema (size too large:> 1024b)', async () => {89 it('Set invalid data in schema (size too large:> 1024b)', async () => {91 await usingApi(async (api) => {90 await usingApi(async (api) => {92 const collectionId = await createCollectionExpectSuccess();91 const collectionId = await createCollectionExpectSuccess();93 const setShema = api.tx.nft.setConstOnChainSchema(collectionId, largeShema);92 const setShema = api.tx.nft.setConstOnChainSchema(collectionId, largeShema);94 await expect(submitTransactionExpectFailAsync(Alice, setShema)).to.be.rejected;93 await expect(submitTransactionExpectFailAsync(alice, setShema)).to.be.rejected;95 });94 });96 });95 });979698 it('Execute method not on behalf of the collection owner', async () => {97 it('Execute method not on behalf of the collection owner', async () => {99 await usingApi(async (api) => {98 await usingApi(async (api) => {100 const collectionId = await createCollectionExpectSuccess();99 const collectionId = await createCollectionExpectSuccess();101 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();100 const collection = (await api.query.common.collectionById(collectionId)).unwrap();102 expect(collection.owner).to.be.eq(Alice.address);101 expect(collection.owner.toString()).to.be.eq(alice.address);103 const setShema = api.tx.nft.setConstOnChainSchema(collectionId, Shema);102 const setShema = api.tx.nft.setConstOnChainSchema(collectionId, shema);104 await expect(submitTransactionExpectFailAsync(Bob, setShema)).to.be.rejected;103 await expect(submitTransactionExpectFailAsync(bob, setShema)).to.be.rejected;105 });104 });106 });105 });107106tests/src/setContractSponsoringRateLimit.test.tsdiffbeforeafterboth--- a/tests/src/setContractSponsoringRateLimit.test.ts
+++ b/tests/src/setContractSponsoringRateLimit.test.ts
@@ -3,11 +3,11 @@
// file 'LICENSE', which is part of this source code package.
//
-import { IKeyringPair } from '@polkadot/types/types';
+import {IKeyringPair} from '@polkadot/types/types';
import privateKey from './substrate/privateKey';
import usingApi from './substrate/substrate-api';
import waitNewBlocks from './substrate/wait-new-blocks';
-import { deployFlipper, toggleFlipValueExpectFailure, toggleFlipValueExpectSuccess } from './util/contracthelpers';
+import {deployFlipper, toggleFlipValueExpectFailure, toggleFlipValueExpectSuccess} from './util/contracthelpers';
import {
enableContractSponsoringExpectSuccess,
findUnusedAddress,
tests/src/setMintPermission.test.tsdiffbeforeafterboth--- a/tests/src/setMintPermission.test.ts
+++ b/tests/src/setMintPermission.test.ts
@@ -3,7 +3,7 @@
// file 'LICENSE', which is part of this source code package.
//
-import { IKeyringPair } from '@polkadot/types/types';
+import {IKeyringPair} from '@polkadot/types/types';
import privateKey from './substrate/privateKey';
import usingApi from './substrate/substrate-api';
import {
@@ -32,7 +32,7 @@
it('ensure white-listed non-privileged address can mint tokens', async () => {
await usingApi(async () => {
- const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });
+ const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
await enableWhiteListExpectSuccess(alice, collectionId);
await setMintPermissionExpectSuccess(alice, collectionId, true);
await addToWhiteListExpectSuccess(alice, collectionId, bob.address);
@@ -43,7 +43,7 @@
it('can be enabled twice', async () => {
await usingApi(async () => {
- const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });
+ const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
await setMintPermissionExpectSuccess(alice, collectionId, true);
await setMintPermissionExpectSuccess(alice, collectionId, true);
});
@@ -51,7 +51,7 @@
it('can be disabled twice', async () => {
await usingApi(async () => {
- const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });
+ const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
await setMintPermissionExpectSuccess(alice, collectionId, true);
await setMintPermissionExpectSuccess(alice, collectionId, false);
await setMintPermissionExpectSuccess(alice, collectionId, false);
@@ -79,7 +79,7 @@
it('fails on removed collection', async () => {
await usingApi(async () => {
- const removedCollectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });
+ const removedCollectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
await destroyCollectionExpectSuccess(removedCollectionId);
await setMintPermissionExpectFailure(alice, removedCollectionId, true);
@@ -87,22 +87,22 @@
});
it('fails when not collection owner tries to set mint status', async () => {
- const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });
+ const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
await enableWhiteListExpectSuccess(alice, collectionId);
await setMintPermissionExpectFailure(bob, collectionId, true);
});
it('Collection admin fails on set', async () => {
await usingApi(async () => {
- const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });
- await addCollectionAdminExpectSuccess(alice, collectionId, bob);
+ const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
+ await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
await setMintPermissionExpectFailure(bob, collectionId, true);
});
});
it('ensure non-white-listed non-privileged address can\'t mint tokens', async () => {
await usingApi(async () => {
- const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });
+ const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
await enableWhiteListExpectSuccess(alice, collectionId);
await setMintPermissionExpectSuccess(alice, collectionId, true);
tests/src/setOffchainSchema.test.tsdiffbeforeafterboth--- a/tests/src/setOffchainSchema.test.ts
+++ b/tests/src/setOffchainSchema.test.ts
@@ -3,7 +3,7 @@
// file 'LICENSE', which is part of this source code package.
//
-import { IKeyringPair } from '@polkadot/types/types';
+import {IKeyringPair} from '@polkadot/types/types';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import privateKey from './substrate/privateKey';
@@ -35,20 +35,24 @@
});
it('execute setOffchainSchema, verify data was set', async () => {
- const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });
- await setOffchainSchemaExpectSuccess(alice, collectionId, DATA);
- const collection = await queryCollectionExpectSuccess(collectionId);
+ await usingApi(async api => {
+ const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
+ await setOffchainSchemaExpectSuccess(alice, collectionId, DATA);
+ const collection = await queryCollectionExpectSuccess(api, collectionId);
- expect(collection.offchainSchema).to.be.equal('0x' + Buffer.from(DATA).toString('hex'));
+ expect(collection.offchainSchema).to.be.equal('0x' + Buffer.from(DATA).toString('hex'));
+ });
});
it('execute setOffchainSchema (collection admin), verify data was set', async () => {
- const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });
- await addCollectionAdminExpectSuccess(alice, collectionId, bob);
- await setOffchainSchemaExpectSuccess(bob, collectionId, DATA);
- const collection = await queryCollectionExpectSuccess(collectionId);
+ await usingApi(async api => {
+ const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
+ await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
+ await setOffchainSchemaExpectSuccess(bob, collectionId, DATA);
+ const collection = await queryCollectionExpectSuccess(api, collectionId);
- expect(collection.offchainSchema).to.be.equal('0x' + Buffer.from(DATA).toString('hex'));
+ expect(collection.offchainSchema).to.be.equal('0x' + Buffer.from(DATA).toString('hex'));
+ });
});
});
@@ -63,7 +67,7 @@
alice = privateKey('//Alice');
bob = privateKey('//Bob');
- validCollectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });
+ validCollectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
});
});
@@ -74,7 +78,7 @@
});
it('fails on destroyed collection id', async () => {
- const destroyedCollectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });
+ const destroyedCollectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
await destroyCollectionExpectSuccess(destroyedCollectionId);
await setOffchainSchemaExpectFailure(alice, destroyedCollectionId, DATA);
tests/src/setPublicAccessMode.test.tsdiffbeforeafterboth--- a/tests/src/setPublicAccessMode.test.ts
+++ b/tests/src/setPublicAccessMode.test.ts
@@ -4,8 +4,8 @@
//
// https://unique-network.readthedocs.io/en/latest/jsapi.html#setschemaversion
-import { ApiPromise } from '@polkadot/api';
-import { IKeyringPair } from '@polkadot/types/types';
+import {ApiPromise} from '@polkadot/api';
+import {IKeyringPair} from '@polkadot/types/types';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import privateKey from './substrate/privateKey';
@@ -24,34 +24,34 @@
chai.use(chaiAsPromised);
const expect = chai.expect;
-let Alice: IKeyringPair;
-let Bob: IKeyringPair;
+let alice: IKeyringPair;
+let bob: IKeyringPair;
describe('Integration Test setPublicAccessMode(): ', () => {
before(async () => {
await usingApi(async () => {
- Alice = privateKey('//Alice');
- Bob = privateKey('//Bob');
+ alice = privateKey('//Alice');
+ bob = privateKey('//Bob');
});
});
it('Run extrinsic with collection id parameters, set the whitelist mode for the collection', async () => {
await usingApi(async () => {
const collectionId: number = await createCollectionExpectSuccess();
- await enableWhiteListExpectSuccess(Alice, collectionId);
- await enablePublicMintingExpectSuccess(Alice, collectionId);
- await addToWhiteListExpectSuccess(Alice, collectionId, Bob.address);
- await createItemExpectSuccess(Bob, collectionId, 'NFT', Bob.address);
+ await enableWhiteListExpectSuccess(alice, collectionId);
+ await enablePublicMintingExpectSuccess(alice, collectionId);
+ await addToWhiteListExpectSuccess(alice, collectionId, bob.address);
+ await createItemExpectSuccess(bob, collectionId, 'NFT', bob.address);
});
});
it('Whitelisted collection limits', async () => {
await usingApi(async (api: ApiPromise) => {
const collectionId = await createCollectionExpectSuccess();
- await enableWhiteListExpectSuccess(Alice, collectionId);
- await enablePublicMintingExpectSuccess(Alice, collectionId);
- const tx = api.tx.nft.createItem(collectionId, normalizeAccountId(Bob.address), 'NFT');
- await expect(submitTransactionExpectFailAsync(Bob, tx)).to.be.rejected;
+ await enableWhiteListExpectSuccess(alice, collectionId);
+ await enablePublicMintingExpectSuccess(alice, collectionId);
+ const tx = api.tx.nft.createItem(collectionId, normalizeAccountId(bob.address), 'NFT');
+ await expect(submitTransactionExpectFailAsync(bob, tx)).to.be.rejected;
});
});
});
@@ -60,9 +60,9 @@
it('Set a non-existent collection', async () => {
await usingApi(async (api: ApiPromise) => {
// tslint:disable-next-line: radix
- const collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;
+ const collectionId = (await api.query.common.createdCollectionCount()).toNumber() + 1;
const tx = api.tx.nft.setPublicAccessMode(collectionId, 'WhiteList');
- await expect(submitTransactionExpectFailAsync(Alice, tx)).to.be.rejected;
+ await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;
});
});
@@ -72,15 +72,15 @@
const collectionId = await createCollectionExpectSuccess();
await destroyCollectionExpectSuccess(collectionId);
const tx = api.tx.nft.setPublicAccessMode(collectionId, 'WhiteList');
- await expect(submitTransactionExpectFailAsync(Alice, tx)).to.be.rejected;
+ await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;
});
});
it('Re-set the list mode already set in quantity', async () => {
await usingApi(async () => {
const collectionId: number = await createCollectionExpectSuccess();
- await enableWhiteListExpectSuccess(Alice, collectionId);
- await enableWhiteListExpectSuccess(Alice, collectionId);
+ await enableWhiteListExpectSuccess(alice, collectionId);
+ await enableWhiteListExpectSuccess(alice, collectionId);
});
});
@@ -89,7 +89,7 @@
// tslint:disable-next-line: no-bitwise
const collectionId = await createCollectionExpectSuccess();
const tx = api.tx.nft.setPublicAccessMode(collectionId, 'WhiteList');
- await expect(submitTransactionExpectFailAsync(Bob, tx)).to.be.rejected;
+ await expect(submitTransactionExpectFailAsync(bob, tx)).to.be.rejected;
});
});
});
@@ -97,17 +97,17 @@
describe('Negative Integration Test ext. collection admin setPublicAccessMode(): ', () => {
before(async () => {
await usingApi(async () => {
- Alice = privateKey('//Alice');
- Bob = privateKey('//Bob');
+ alice = privateKey('//Alice');
+ bob = privateKey('//Bob');
});
});
it('setPublicAccessMode by collection admin', async () => {
await usingApi(async (api: ApiPromise) => {
// tslint:disable-next-line: no-bitwise
const collectionId = await createCollectionExpectSuccess();
- await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);
+ await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
const tx = api.tx.nft.setPublicAccessMode(collectionId, 'WhiteList');
- await expect(submitTransactionExpectFailAsync(Bob, tx)).to.be.rejected;
+ await expect(submitTransactionExpectFailAsync(bob, tx)).to.be.rejected;
});
});
});
tests/src/setSchemaVersion.test.tsdiffbeforeafterboth--- a/tests/src/setSchemaVersion.test.ts
+++ b/tests/src/setSchemaVersion.test.ts
@@ -4,12 +4,11 @@
//
// https://unique-network.readthedocs.io/en/latest/jsapi.html#setschemaversion
-import { ApiPromise, Keyring } from '@polkadot/api';
-import { IKeyringPair } from '@polkadot/types/types';
+import {ApiPromise, Keyring} from '@polkadot/api';
+import {IKeyringPair} from '@polkadot/types/types';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import usingApi, {submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';
-import { ICollectionInterface } from './types';
import {
createCollectionExpectSuccess,
destroyCollectionExpectSuccess,
@@ -25,42 +24,27 @@
let alice: IKeyringPair;
let bob: IKeyringPair;
let charlie: IKeyringPair;
-let collectionIdForTesting: number;
/*
1. We create collection.
2. Save just created collection id.
3. Use this id for setSchemaVersion.
*/
-
-describe('hooks', () => {
- before(async () => {
- await usingApi(async () => {
- const keyring = new Keyring({ type: 'sr25519' });
- alice = keyring.addFromUri('//Alice');
- });
- });
- it('choose or create collection for testing', async () => {
- await usingApi(async () => {
- collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});
- });
- });
-});
-
describe('setSchemaVersion positive', () => {
let tx;
before(async () => {
await usingApi(async () => {
- const keyring = new Keyring({ type: 'sr25519' });
+ const keyring = new Keyring({type: 'sr25519'});
alice = keyring.addFromUri('//Alice');
});
});
it('execute setSchemaVersion with image url and unique ', async () => {
await usingApi(async (api: ApiPromise) => {
+ const collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});
tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'Unique');
const events = await submitTransactionAsync(alice, tx);
const result = getCreateItemResult(events);
- const collectionInfo = await getDetailedCollectionInfo(api, collectionIdForTesting) as ICollectionInterface;
+ const collectionInfo = await getDetailedCollectionInfo(api, collectionIdForTesting);
// tslint:disable-next-line:no-unused-expression
expect(result.success).to.be.true;
// tslint:disable-next-line:no-unused-expression
@@ -73,12 +57,15 @@
describe('Collection admin setSchemaVersion positive', () => {
let tx;
+ let collectionIdForTesting: any;
+
before(async () => {
await usingApi(async () => {
- const keyring = new Keyring({ type: 'sr25519' });
+ const keyring = new Keyring({type: 'sr25519'});
alice = keyring.addFromUri('//Alice');
bob = keyring.addFromUri('//Bob');
- await addCollectionAdminExpectSuccess(alice, collectionIdForTesting, bob);
+ collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});
+ await addCollectionAdminExpectSuccess(alice, collectionIdForTesting, bob.address);
});
});
it('execute setSchemaVersion with image url and unique ', async () => {
@@ -86,7 +73,7 @@
tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'Unique');
const events = await submitTransactionAsync(bob, tx);
const result = getCreateItemResult(events);
- const collectionInfo = await getDetailedCollectionInfo(api, collectionIdForTesting) as ICollectionInterface;
+ const collectionInfo = await getDetailedCollectionInfo(api, collectionIdForTesting);
// tslint:disable-next-line:no-unused-expression
expect(result.success).to.be.true;
// tslint:disable-next-line:no-unused-expression
@@ -101,7 +88,7 @@
tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'ImageURL');
const events = await submitTransactionAsync(bob, tx);
const result = getCreateItemResult(events);
- const collectionInfo = await getDetailedCollectionInfo(api, collectionIdForTesting) as ICollectionInterface;
+ const collectionInfo = await getDetailedCollectionInfo(api, collectionIdForTesting);
// tslint:disable-next-line:no-unused-expression
expect(result.success).to.be.true;
// tslint:disable-next-line:no-unused-expression
@@ -114,11 +101,13 @@
describe('setSchemaVersion negative', () => {
let tx;
+ let collectionIdForTesting: any;
before(async () => {
await usingApi(async () => {
- const keyring = new Keyring({ type: 'sr25519' });
+ const keyring = new Keyring({type: 'sr25519'});
alice = keyring.addFromUri('//Alice');
charlie = keyring.addFromUri('//Charlie');
+ collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});
});
});
it('execute setSchemaVersion for not exists collection', async () => {
@@ -127,21 +116,6 @@
const nonExistedCollectionId = collectionCount + 1;
tx = api.tx.nft.setSchemaVersion(nonExistedCollectionId, 'ImageURL');
await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;
- });
- });
- it('execute setSchemaVersion with not correct schema version', async () => {
- await usingApi(async (api: ApiPromise) => {
- const consoleError = console.error;
- console.error = () => {};
- try {
- tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'Test');
- await submitTransactionAsync(alice, tx);
- } catch (e) {
- // tslint:disable-next-line:no-unused-expression
- expect(e).to.be.exist;
- } finally {
- console.error = consoleError;
- }
});
});
it('execute setSchemaVersion for deleted collection', async () => {
tests/src/setVariableMetaData.test.tsdiffbeforeafterboth--- a/tests/src/setVariableMetaData.test.ts
+++ b/tests/src/setVariableMetaData.test.ts
@@ -3,7 +3,7 @@
// file 'LICENSE', which is part of this source code package.
//
-import { IKeyringPair } from '@polkadot/types/types';
+import {IKeyringPair} from '@polkadot/types/types';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import privateKey from './substrate/privateKey';
@@ -18,6 +18,7 @@
setVariableMetaDataExpectSuccess,
addCollectionAdminExpectSuccess,
setMetadataUpdatePermissionFlagExpectSuccess,
+ getVariableMetadata,
} from './util/helpers';
chai.use(chaiAsPromised);
@@ -32,7 +33,7 @@
before(async () => {
await usingApi(async () => {
alice = privateKey('//Alice');
- collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });
+ collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');
});
});
@@ -43,9 +44,7 @@
it('verify data was set', async () => {
await usingApi(async api => {
- const item: any = (await api.query.nft.nftItemList(collectionId, tokenId) as any).unwrap();
-
- expect(Array.from(item.variableData)).to.deep.equal(Array.from(data));
+ expect(await getVariableMetadata(api, collectionId, tokenId)).to.deep.equal(data);
});
});
});
@@ -61,10 +60,10 @@
await usingApi(async () => {
alice = privateKey('//Alice');
bob = privateKey('//Bob');
- collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });
+ collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');
await setMetadataUpdatePermissionFlagExpectSuccess(alice, collectionId, 'Admin');
- await addCollectionAdminExpectSuccess(alice, collectionId, bob);
+ await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
});
});
@@ -74,9 +73,7 @@
it('verify data was set', async () => {
await usingApi(async api => {
- const item: any = (await api.query.nft.nftItemList(collectionId, tokenId) as any).unwrap();
-
- expect(Array.from(item.variableData)).to.deep.equal(Array.from(data));
+ expect(await getVariableMetadata(api, collectionId, tokenId)).to.deep.equal(data);
});
});
});
@@ -95,7 +92,7 @@
alice = privateKey('//Alice');
bob = privateKey('//Bob');
- validCollectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });
+ validCollectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
validTokenId = await createItemExpectSuccess(alice, validCollectionId, 'NFT');
});
});
@@ -107,14 +104,14 @@
});
});
it('fails on removed collection id', async () => {
- const removedCollectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });
+ const removedCollectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
const removedCollectionTokenId = await createItemExpectSuccess(alice, removedCollectionId, 'NFT');
await destroyCollectionExpectSuccess(removedCollectionId);
await setVariableMetaDataExpectFailure(alice, removedCollectionId, removedCollectionTokenId, data);
});
it('fails on removed token', async () => {
- const removedTokenCollectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });
+ const removedTokenCollectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
const removedTokenId = await createItemExpectSuccess(alice, removedTokenCollectionId, 'NFT');
await burnItemExpectSuccess(alice, removedTokenCollectionId, removedTokenId);
@@ -131,7 +128,7 @@
await setVariableMetaDataExpectFailure(alice, validCollectionId, validTokenId, tooLongData);
});
it('fails on fungible token', async () => {
- const fungibleCollectionId = await createCollectionExpectSuccess({ mode: { type: 'Fungible', decimalPoints: 0 } });
+ const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
const fungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');
await setVariableMetaDataExpectFailure(alice, fungibleCollectionId, fungibleTokenId, data);
tests/src/setVariableMetadataSponsoringRateLimit.test.tsdiffbeforeafterboth--- a/tests/src/setVariableMetadataSponsoringRateLimit.test.ts
+++ b/tests/src/setVariableMetadataSponsoringRateLimit.test.ts
@@ -3,7 +3,7 @@
// file 'LICENSE', which is part of this source code package.
//
-import { IKeyringPair } from '@polkadot/types/types';
+import {IKeyringPair} from '@polkadot/types/types';
import privateKey from './substrate/privateKey';
import usingApi from './substrate/substrate-api';
import {
tests/src/setVariableOnChainSchema.test.tsdiffbeforeafterboth--- a/tests/src/setVariableOnChainSchema.test.ts
+++ b/tests/src/setVariableOnChainSchema.test.ts
@@ -3,11 +3,11 @@
// file 'LICENSE', which is part of this source code package.
//
-import { Keyring } from '@polkadot/api';
-import { IKeyringPair } from '@polkadot/types/types';
+import {Keyring} from '@polkadot/api';
+import {IKeyringPair} from '@polkadot/types/types';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
-import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from './substrate/substrate-api';
+import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';
import {
createCollectionExpectSuccess,
destroyCollectionExpectSuccess,
@@ -17,17 +17,17 @@
chai.use(chaiAsPromised);
const expect = chai.expect;
-let Alice: IKeyringPair;
-let Bob: IKeyringPair;
-let Schema: any;
+let alice: IKeyringPair;
+let bob: IKeyringPair;
+let schema: any;
let largeSchema: any;
before(async () => {
await usingApi(async () => {
- const keyring = new Keyring({ type: 'sr25519' });
- Alice = keyring.addFromUri('//Alice');
- Bob = keyring.addFromUri('//Bob');
- Schema = '0x31';
+ const keyring = new Keyring({type: 'sr25519'});
+ alice = keyring.addFromUri('//Alice');
+ bob = keyring.addFromUri('//Bob');
+ schema = '0x31';
largeSchema = new Array(4097).fill(0xff);
});
@@ -37,20 +37,20 @@
it('Run extrinsic with parameters of the collection id, set the scheme', async () => {
await usingApi(async (api) => {
const collectionId = await createCollectionExpectSuccess();
- const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
- expect(collection.owner).to.be.eq(Alice.address);
- const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema);
- await submitTransactionAsync(Alice, setSchema);
+ const collection = (await api.query.common.collectionById(collectionId)).unwrap();
+ expect(collection.owner.toString()).to.be.eq(alice.address);
+ const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, schema);
+ await submitTransactionAsync(alice, setSchema);
});
});
it('Checking collection data using the setVariableOnChainSchema parameter', async () => {
await usingApi(async (api) => {
const collectionId = await createCollectionExpectSuccess();
- const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema);
- await submitTransactionAsync(Alice, setSchema);
- const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
- expect(collection.variableOnChainSchema.toString()).to.be.eq(Schema);
+ const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, schema);
+ await submitTransactionAsync(alice, setSchema);
+ const collection = (await api.query.common.collectionById(collectionId)).unwrap();
+ expect(collection.variableOnChainSchema.toString()).to.be.eq(schema);
});
});
@@ -61,22 +61,22 @@
it('Run extrinsic with parameters of the collection id, set the scheme', async () => {
await usingApi(async (api) => {
const collectionId = await createCollectionExpectSuccess();
- const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
- expect(collection.owner).to.be.eq(Alice.address);
- await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);
- const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema);
- await submitTransactionAsync(Bob, setSchema);
+ const collection = (await api.query.common.collectionById(collectionId)).unwrap();
+ expect(collection.owner.toString()).to.be.eq(alice.address);
+ await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
+ const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, schema);
+ await submitTransactionAsync(bob, setSchema);
});
});
it('Checking collection data using the setVariableOnChainSchema parameter', async () => {
await usingApi(async (api) => {
const collectionId = await createCollectionExpectSuccess();
- await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);
- const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema);
- await submitTransactionAsync(Bob, setSchema);
- const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
- expect(collection.variableOnChainSchema.toString()).to.be.eq(Schema);
+ await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
+ const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, schema);
+ await submitTransactionAsync(bob, setSchema);
+ const collection = (await api.query.common.collectionById(collectionId)).unwrap();
+ expect(collection.variableOnChainSchema.toString()).to.be.eq(schema);
});
});
@@ -87,9 +87,9 @@
it('Set a non-existent collection', async () => {
await usingApi(async (api) => {
// tslint:disable-next-line: radix
- const collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;
- const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema);
- await expect(submitTransactionExpectFailAsync(Alice, setSchema)).to.be.rejected;
+ const collectionId = (await api.query.common.createdCollectionCount()).toNumber() + 1;
+ const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, schema);
+ await expect(submitTransactionExpectFailAsync(alice, setSchema)).to.be.rejected;
});
});
@@ -97,8 +97,8 @@
await usingApi(async (api) => {
const collectionId = await createCollectionExpectSuccess();
await destroyCollectionExpectSuccess(collectionId);
- const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema);
- await expect(submitTransactionExpectFailAsync(Alice, setSchema)).to.be.rejected;
+ const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, schema);
+ await expect(submitTransactionExpectFailAsync(alice, setSchema)).to.be.rejected;
});
});
@@ -106,17 +106,17 @@
await usingApi(async (api) => {
const collectionId = await createCollectionExpectSuccess();
const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, largeSchema);
- await expect(submitTransactionExpectFailAsync(Alice, setSchema)).to.be.rejected;
+ await expect(submitTransactionExpectFailAsync(alice, setSchema)).to.be.rejected;
});
});
it('Execute method not on behalf of the collection owner', async () => {
await usingApi(async (api) => {
const collectionId = await createCollectionExpectSuccess();
- const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
- expect(collection.owner).to.be.eq(Alice.address);
- const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema);
- await expect(submitTransactionExpectFailAsync(Bob, setSchema)).to.be.rejected;
+ const collection = (await api.query.common.collectionById(collectionId)).unwrap();
+ expect(collection.owner.toString()).to.be.eq(alice.address);
+ const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, schema);
+ await expect(submitTransactionExpectFailAsync(bob, setSchema)).to.be.rejected;
});
});
tests/src/substrate/get-balance.tsdiffbeforeafterboth--- a/tests/src/substrate/get-balance.ts
+++ b/tests/src/substrate/get-balance.ts
@@ -3,13 +3,13 @@
// file 'LICENSE', which is part of this source code package.
//
-import { ApiPromise } from '@polkadot/api';
+import {ApiPromise} from '@polkadot/api';
import {AccountInfo} from '@polkadot/types/interfaces/system';
import promisifySubstrate from './promisify-substrate';
-import { IKeyringPair } from '@polkadot/types/types';
-import { submitTransactionAsync } from './substrate-api';
-import { getGenericResult } from '../util/helpers';
-import { expect } from 'chai';
+import {IKeyringPair} from '@polkadot/types/types';
+import {submitTransactionAsync} from './substrate-api';
+import {getGenericResult} from '../util/helpers';
+import {expect} from 'chai';
export default async function getBalance(api: ApiPromise, accounts: string[]): Promise<Array<bigint>> {
const balance = promisifySubstrate(api, (acc: string[]) => api.query.system.account.multi(acc));
@@ -26,4 +26,4 @@
const events = await submitTransactionAsync(from, tx);
const result = getGenericResult(events);
expect(result.success).to.be.true;
-}
\ No newline at end of file
+}
tests/src/substrate/privateKey.tsdiffbeforeafterboth--- a/tests/src/substrate/privateKey.ts
+++ b/tests/src/substrate/privateKey.ts
@@ -3,11 +3,11 @@
// file 'LICENSE', which is part of this source code package.
//
-import { Keyring } from '@polkadot/api';
-import { IKeyringPair } from '@polkadot/types/types';
+import {Keyring} from '@polkadot/api';
+import {IKeyringPair} from '@polkadot/types/types';
export default function privateKey(account: string): IKeyringPair {
- const keyring = new Keyring({ type: 'sr25519' });
-
+ const keyring = new Keyring({type: 'sr25519'});
+
return keyring.addFromUri(account);
-}
\ No newline at end of file
+}
tests/src/substrate/promisify-substrate.tsdiffbeforeafterboth--- a/tests/src/substrate/promisify-substrate.ts
+++ b/tests/src/substrate/promisify-substrate.ts
@@ -3,7 +3,7 @@
// file 'LICENSE', which is part of this source code package.
//
-import { ApiPromise } from '@polkadot/api';
+import {ApiPromise} from '@polkadot/api';
type PromiseType<T> = T extends PromiseLike<infer TInner> ? TInner : T;
@@ -25,7 +25,7 @@
reject && reject(error);
cleanup();
};
-
+
api.on('disconnected', fail);
api.on('error', fail);
tests/src/substrate/substrate-api.tsdiffbeforeafterboth--- a/tests/src/substrate/substrate-api.ts
+++ b/tests/src/substrate/substrate-api.ts
@@ -3,14 +3,14 @@
// file 'LICENSE', which is part of this source code package.
//
-import { WsProvider, ApiPromise } from '@polkadot/api';
-import { EventRecord } from '@polkadot/types/interfaces/system/types';
-import { ExtrinsicStatus } from '@polkadot/types/interfaces/author/types';
-import { IKeyringPair } from '@polkadot/types/types';
+import {WsProvider, ApiPromise} from '@polkadot/api';
+import {EventRecord} from '@polkadot/types/interfaces/system/types';
+import {ExtrinsicStatus} from '@polkadot/types/interfaces/author/types';
+import {IKeyringPair} from '@polkadot/types/types';
import config from '../config';
import promisifySubstrate from './promisify-substrate';
-import { ApiOptions, SubmittableExtrinsic, ApiTypes } from '@polkadot/api/types';
+import {ApiOptions, SubmittableExtrinsic, ApiTypes} from '@polkadot/api/types';
import * as defs from '../interfaces/definitions';
@@ -40,20 +40,19 @@
const consoleLog = console.log;
const consoleWarn = console.warn;
- const outFn = (message: any, ...rest: any[]) => {
- if (typeof message !== 'string') {
- consoleErr(message, ...rest);
- return;
+ const outFn = (printer: any) => (...args: any[]) => {
+ for (const arg of args) {
+ if (typeof arg !== 'string')
+ continue;
+ if (arg.includes('1000:: Normal connection closure' || arg === 'Normal connection closure'))
+ return;
}
- if (!message.includes('StorageChangeSet:: WebSocket is not connected') &&
- !message.includes('2021-') &&
- !message.includes('StorageChangeSet:: Normal connection closure'))
- consoleErr(message, ...rest);
+ printer(...args);
};
- console.error = outFn;
- console.log = outFn;
- console.warn = outFn;
+ console.error = outFn(consoleErr.bind(console));
+ console.log = outFn(consoleLog.bind(console));
+ console.warn = outFn(consoleWarn.bind(console));
try {
await promisifySubstrate(api, async () => {
@@ -101,7 +100,7 @@
/* eslint no-async-promise-executor: "off" */
return new Promise(async (resolve, reject) => {
try {
- await transaction.signAndSend(sender, ({ events = [], status }) => {
+ await transaction.signAndSend(sender, ({events = [], status}) => {
const transactionStatus = getTransactionStatus(events, status);
if (transactionStatus === TransactionStatus.Success) {
@@ -119,8 +118,6 @@
}
export function submitTransactionExpectFailAsync(sender: IKeyringPair, transaction: SubmittableExtrinsic<ApiTypes>): Promise<EventRecord[]> {
- const consoleError = console.error;
- const consoleLog = console.log;
console.error = () => {};
console.log = () => {};
@@ -129,19 +126,15 @@
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 }) => {
+ await transaction.signAndSend(sender, ({events = [], status}) => {
const transactionStatus = getTransactionStatus(events, status);
// console.log('transactionStatus', transactionStatus, 'events', events);
tests/src/substrate/wait-new-blocks.tsdiffbeforeafterboth--- a/tests/src/substrate/wait-new-blocks.ts
+++ b/tests/src/substrate/wait-new-blocks.ts
@@ -3,12 +3,12 @@
// file 'LICENSE', which is part of this source code package.
//
-import { ApiPromise } from '@polkadot/api';
+import {ApiPromise} from '@polkadot/api';
/* eslint no-async-promise-executor: "off" */
export default function waitNewBlocks(api: ApiPromise, blocksCount = 1): Promise<void> {
const promise = new Promise<void>(async (resolve) => {
-
+
const unsubscribe = await api.rpc.chain.subscribeNewHeads(() => {
if (blocksCount > 0) {
blocksCount--;
@@ -20,4 +20,4 @@
});
return promise;
-}
\ No newline at end of file
+}
tests/src/toggleContractWhiteList.test.tsdiffbeforeafterboth--- a/tests/src/toggleContractWhiteList.test.ts
+++ b/tests/src/toggleContractWhiteList.test.ts
@@ -5,7 +5,7 @@
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
-import usingApi, { submitTransactionAsync, submitTransactionExpectFailAsync } from './substrate/substrate-api';
+import usingApi, {submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';
import privateKey from './substrate/privateKey';
import {
deployFlipper,
tests/src/transfer.nload.tsdiffbeforeafterboth--- a/tests/src/transfer.nload.ts
+++ b/tests/src/transfer.nload.ts
@@ -3,12 +3,12 @@
// file 'LICENSE', which is part of this source code package.
//
-import { ApiPromise } from '@polkadot/api';
-import { IKeyringPair } from '@polkadot/types/types';
+import {ApiPromise} from '@polkadot/api';
+import {IKeyringPair} from '@polkadot/types/types';
import privateKey from './substrate/privateKey';
-import usingApi, { submitTransactionAsync } from './substrate/substrate-api';
+import usingApi, {submitTransactionAsync} from './substrate/substrate-api';
import waitNewBlocks from './substrate/wait-new-blocks';
-import { findUnusedAddresses } from './util/helpers';
+import {findUnusedAddresses} from './util/helpers';
import * as cluster from 'cluster';
import os from 'os';
@@ -115,4 +115,4 @@
flushCounterToMaster();
}, 100);
interval.unref();
-}
\ No newline at end of file
+}
tests/src/transfer.test.tsdiffbeforeafterboth--- a/tests/src/transfer.test.ts
+++ b/tests/src/transfer.test.ts
@@ -3,13 +3,13 @@
// file 'LICENSE', which is part of this source code package.
//
-import { ApiPromise } from '@polkadot/api';
-import { IKeyringPair } from '@polkadot/types/types';
-import { expect } from 'chai';
-import { alicesPublicKey, bobsPublicKey } from './accounts';
+import {ApiPromise} from '@polkadot/api';
+import {IKeyringPair} from '@polkadot/types/types';
+import {expect} from 'chai';
+import {alicesPublicKey, bobsPublicKey} from './accounts';
import getBalance from './substrate/get-balance';
import privateKey from './substrate/privateKey';
-import { default as usingApi, submitTransactionAsync } from './substrate/substrate-api';
+import {default as usingApi, submitTransactionAsync} from './substrate/substrate-api';
import {
burnItemExpectSuccess, createCollectionExpectSuccess, createItemExpectSuccess,
destroyCollectionExpectSuccess,
@@ -21,9 +21,9 @@
addCollectionAdminExpectSuccess,
} from './util/helpers';
-let Alice: IKeyringPair;
-let Bob: IKeyringPair;
-let Charlie: IKeyringPair;
+let alice: IKeyringPair;
+let bob: IKeyringPair;
+let charlie: IKeyringPair;
describe('Integration Test Transfer(recipient, collection_id, item_id, value)', () => {
it('Balance transfers and check balance', async () => {
@@ -66,25 +66,25 @@
it('User can transfer owned token', async () => {
await usingApi(async () => {
- const Alice = privateKey('//Alice');
- const Bob = privateKey('//Bob');
+ const alice = privateKey('//Alice');
+ const bob = privateKey('//Bob');
// nft
const nftCollectionId = await createCollectionExpectSuccess();
- const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
- await transferExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 1, 'NFT');
+ const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
+ await transferExpectSuccess(nftCollectionId, newNftTokenId, alice, bob, 1, 'NFT');
// fungible
const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
- const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');
- await transferExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob, 1, 'Fungible');
+ const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');
+ await transferExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob, 1, 'Fungible');
// reFungible
const reFungibleCollectionId = await
createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
- const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');
+ const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');
await transferExpectSuccess(
reFungibleCollectionId,
newReFungibleTokenId,
- Alice,
- Bob,
+ alice,
+ bob,
100,
'ReFungible',
);
@@ -93,27 +93,27 @@
it('Collection admin can transfer owned token', async () => {
await usingApi(async () => {
- const Alice = privateKey('//Alice');
- const Bob = privateKey('//Bob');
+ const alice = privateKey('//Alice');
+ const bob = privateKey('//Bob');
// nft
const nftCollectionId = await createCollectionExpectSuccess();
- await addCollectionAdminExpectSuccess(Alice, nftCollectionId, Bob);
- const newNftTokenId = await createItemExpectSuccess(Bob, nftCollectionId, 'NFT', Bob.address);
- await transferExpectSuccess(nftCollectionId, newNftTokenId, Bob, Alice, 1, 'NFT');
+ await addCollectionAdminExpectSuccess(alice, nftCollectionId, bob.address);
+ const newNftTokenId = await createItemExpectSuccess(bob, nftCollectionId, 'NFT', bob.address);
+ await transferExpectSuccess(nftCollectionId, newNftTokenId, bob, alice, 1, 'NFT');
// fungible
const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
- await addCollectionAdminExpectSuccess(Alice, fungibleCollectionId, Bob);
- const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible', Bob.address);
- await transferExpectSuccess(fungibleCollectionId, newFungibleTokenId, Bob, Alice, 1, 'Fungible');
+ await addCollectionAdminExpectSuccess(alice, fungibleCollectionId, bob.address);
+ const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible', bob.address);
+ await transferExpectSuccess(fungibleCollectionId, newFungibleTokenId, bob, alice, 1, 'Fungible');
// reFungible
const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
- await addCollectionAdminExpectSuccess(Alice, reFungibleCollectionId, Bob);
- const newReFungibleTokenId = await createItemExpectSuccess(Bob, reFungibleCollectionId, 'ReFungible', Bob.address);
+ await addCollectionAdminExpectSuccess(alice, reFungibleCollectionId, bob.address);
+ const newReFungibleTokenId = await createItemExpectSuccess(bob, reFungibleCollectionId, 'ReFungible', bob.address);
await transferExpectSuccess(
reFungibleCollectionId,
newReFungibleTokenId,
- Bob,
- Alice,
+ bob,
+ alice,
100,
'ReFungible',
);
@@ -124,108 +124,108 @@
describe('Negative Integration Test Transfer(recipient, collection_id, item_id, value)', () => {
before(async () => {
await usingApi(async () => {
- Alice = privateKey('//Alice');
- Bob = privateKey('//Bob');
- Charlie = privateKey('//Charlie');
+ alice = privateKey('//Alice');
+ bob = privateKey('//Bob');
+ charlie = privateKey('//Charlie');
});
});
it('Transfer with not existed collection_id', async () => {
await usingApi(async (api) => {
// nft
- const nftCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;
- await transferExpectFailure(nftCollectionCount + 1, 1, Alice, Bob, 1);
+ const nftCollectionCount = (await api.query.common.createdCollectionCount()).toNumber();
+ await transferExpectFailure(nftCollectionCount + 1, 1, alice, bob, 1);
// fungible
- const fungibleCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;
- await transferExpectFailure(fungibleCollectionCount + 1, 1, Alice, Bob, 1);
+ const fungibleCollectionCount = (await api.query.common.createdCollectionCount()).toNumber();
+ await transferExpectFailure(fungibleCollectionCount + 1, 0, alice, bob, 1);
// reFungible
- const reFungibleCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;
- await transferExpectFailure(reFungibleCollectionCount + 1, 1, Alice, Bob, 1);
+ const reFungibleCollectionCount = (await api.query.common.createdCollectionCount()).toNumber();
+ await transferExpectFailure(reFungibleCollectionCount + 1, 1, alice, bob, 1);
});
});
it('Transfer with deleted collection_id', async () => {
// nft
const nftCollectionId = await createCollectionExpectSuccess();
- const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
+ const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
await destroyCollectionExpectSuccess(nftCollectionId);
- await transferExpectFailure(nftCollectionId, newNftTokenId, Alice, Bob, 1);
+ await transferExpectFailure(nftCollectionId, newNftTokenId, alice, bob, 1);
// fungible
const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
- const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');
+ const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');
await destroyCollectionExpectSuccess(fungibleCollectionId);
- await transferExpectFailure(fungibleCollectionId, newFungibleTokenId, Alice, Bob, 1);
+ await transferExpectFailure(fungibleCollectionId, newFungibleTokenId, alice, bob, 1);
// reFungible
const reFungibleCollectionId = await
createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
- const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');
+ const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');
await destroyCollectionExpectSuccess(reFungibleCollectionId);
await transferExpectFailure(
reFungibleCollectionId,
newReFungibleTokenId,
- Alice,
- Bob,
+ alice,
+ bob,
1,
);
});
it('Transfer with not existed item_id', async () => {
// nft
const nftCollectionId = await createCollectionExpectSuccess();
- await transferExpectFailure(nftCollectionId, 2, Alice, Bob, 1);
+ await transferExpectFailure(nftCollectionId, 2, alice, bob, 1);
// fungible
const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
- await transferExpectFailure(fungibleCollectionId, 2, Alice, Bob, 1);
+ await transferExpectFailure(fungibleCollectionId, 2, alice, bob, 1);
// reFungible
const reFungibleCollectionId = await
createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
await transferExpectFailure(
reFungibleCollectionId,
2,
- Alice,
- Bob,
+ alice,
+ bob,
1,
);
});
it('Transfer with deleted item_id', async () => {
// nft
const nftCollectionId = await createCollectionExpectSuccess();
- const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
- await burnItemExpectSuccess(Alice, nftCollectionId, newNftTokenId, 1);
- await transferExpectFailure(nftCollectionId, newNftTokenId, Alice, Bob, 1);
+ const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
+ await burnItemExpectSuccess(alice, nftCollectionId, newNftTokenId, 1);
+ await transferExpectFailure(nftCollectionId, newNftTokenId, alice, bob, 1);
// fungible
const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
- const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');
- await burnItemExpectSuccess(Alice, fungibleCollectionId, newFungibleTokenId, 10);
- await transferExpectFailure(fungibleCollectionId, newFungibleTokenId, Alice, Bob, 1);
+ const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');
+ await burnItemExpectSuccess(alice, fungibleCollectionId, newFungibleTokenId, 10);
+ await transferExpectFailure(fungibleCollectionId, newFungibleTokenId, alice, bob, 1);
// reFungible
const reFungibleCollectionId = await
createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
- const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');
- await burnItemExpectSuccess(Alice, reFungibleCollectionId, newReFungibleTokenId, 100);
+ const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');
+ await burnItemExpectSuccess(alice, reFungibleCollectionId, newReFungibleTokenId, 100);
await transferExpectFailure(
reFungibleCollectionId,
newReFungibleTokenId,
- Alice,
- Bob,
+ alice,
+ bob,
1,
);
});
it('Transfer with recipient that is not owner', async () => {
// nft
const nftCollectionId = await createCollectionExpectSuccess();
- const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
- await transferExpectFailure(nftCollectionId, newNftTokenId, Charlie, Bob, 1);
+ const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
+ await transferExpectFailure(nftCollectionId, newNftTokenId, charlie, bob, 1);
// fungible
const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
- const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');
- await transferExpectFailure(fungibleCollectionId, newFungibleTokenId, Charlie, Bob, 1);
+ const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');
+ await transferExpectFailure(fungibleCollectionId, newFungibleTokenId, charlie, bob, 1);
// reFungible
const reFungibleCollectionId = await
createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
- const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');
+ const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');
await transferExpectFailure(
reFungibleCollectionId,
newReFungibleTokenId,
- Charlie,
- Bob,
+ charlie,
+ bob,
1,
);
});
tests/src/transferFrom.test.tsdiffbeforeafterboth--- a/tests/src/transferFrom.test.ts
+++ b/tests/src/transferFrom.test.ts
@@ -2,12 +2,12 @@
// This file is subject to the terms and conditions defined in
// file 'LICENSE', which is part of this source code package.
//
-import { ApiPromise } from '@polkadot/api';
-import { IKeyringPair } from '@polkadot/types/types';
+import {ApiPromise} from '@polkadot/api';
+import {IKeyringPair} from '@polkadot/types/types';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import privateKey from './substrate/privateKey';
-import { default as usingApi } from './substrate/substrate-api';
+import {default as usingApi} from './substrate/substrate-api';
import {
approveExpectFail,
approveExpectSuccess,
@@ -25,15 +25,15 @@
const expect = chai.expect;
describe('Integration Test transferFrom(from, recipient, collection_id, item_id, value):', () => {
- let Alice: IKeyringPair;
- let Bob: IKeyringPair;
- let Charlie: IKeyringPair;
+ let alice: IKeyringPair;
+ let bob: IKeyringPair;
+ let charlie: IKeyringPair;
before(async () => {
await usingApi(async () => {
- Alice = privateKey('//Alice');
- Bob = privateKey('//Bob');
- Charlie = privateKey('//Charlie');
+ alice = privateKey('//Alice');
+ bob = privateKey('//Bob');
+ charlie = privateKey('//Charlie');
});
});
@@ -41,28 +41,28 @@
await usingApi(async () => {
// nft
const nftCollectionId = await createCollectionExpectSuccess();
- const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
- await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob);
+ const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
+ await approveExpectSuccess(nftCollectionId, newNftTokenId, alice, bob.address);
- await transferFromExpectSuccess(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 1, 'NFT');
+ await transferFromExpectSuccess(nftCollectionId, newNftTokenId, bob, alice, charlie, 1, 'NFT');
// fungible
const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
- const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');
- await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);
- await transferFromExpectSuccess(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 1, 'Fungible');
+ const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');
+ await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob.address);
+ await transferFromExpectSuccess(fungibleCollectionId, newFungibleTokenId, bob, alice, charlie, 1, 'Fungible');
// reFungible
const reFungibleCollectionId = await
createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
- const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');
- await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob, 100);
+ const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');
+ await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, alice, bob.address, 100);
await transferFromExpectSuccess(
reFungibleCollectionId,
newReFungibleTokenId,
- Bob,
- Alice,
- Charlie,
+ bob,
+ alice,
+ charlie,
100,
'ReFungible',
);
@@ -70,60 +70,60 @@
});
it('Should reduce allowance if value is big', async () => {
- await usingApi(async () => {
+ await usingApi(async (api) => {
const alice = privateKey('//Alice');
const bob = privateKey('//Bob');
const charlie = privateKey('//Charlie');
// fungible
const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
- const newFungibleTokenId = await createFungibleItemExpectSuccess(alice, fungibleCollectionId, { Value: 500000n });
+ const newFungibleTokenId = await createFungibleItemExpectSuccess(alice, fungibleCollectionId, {Value: 500000n});
- await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob, 500000n);
+ await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob.address, 500000n);
await transferFromExpectSuccess(fungibleCollectionId, newFungibleTokenId, bob, alice, charlie, 500000n, 'Fungible');
- expect((await getAllowance(fungibleCollectionId, newFungibleTokenId, alice.address, bob.address)).toString()).to.equal('0');
+ expect(await getAllowance(api, fungibleCollectionId, alice.address, bob.address, newFungibleTokenId)).to.equal(0n);
});
});
it('can be called by collection owner on non-owned item when OwnerCanTransfer == true', async () => {
const collectionId = await createCollectionExpectSuccess();
- const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Bob.address);
+ const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', bob.address);
- await transferFromExpectSuccess(collectionId, itemId, Alice, Bob, Charlie);
+ await transferFromExpectSuccess(collectionId, itemId, alice, bob, charlie);
});
});
describe('Negative Integration Test transferFrom(from, recipient, collection_id, item_id, value):', () => {
- let Alice: IKeyringPair;
- let Bob: IKeyringPair;
- let Charlie: IKeyringPair;
+ let alice: IKeyringPair;
+ let bob: IKeyringPair;
+ let charlie: IKeyringPair;
before(async () => {
await usingApi(async () => {
- Alice = privateKey('//Alice');
- Bob = privateKey('//Bob');
- Charlie = privateKey('//Charlie');
+ alice = privateKey('//Alice');
+ bob = privateKey('//Bob');
+ charlie = privateKey('//Charlie');
});
});
it('transferFrom for a collection that does not exist', async () => {
await usingApi(async (api: ApiPromise) => {
// nft
- const nftCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;
- await approveExpectFail(nftCollectionCount + 1, 1, Alice, Bob);
+ const nftCollectionCount = (await api.query.common.createdCollectionCount()).toNumber();
+ await approveExpectFail(nftCollectionCount + 1, 1, alice, bob);
- await transferFromExpectFail(nftCollectionCount + 1, 1, Bob, Alice, Charlie, 1);
+ await transferFromExpectFail(nftCollectionCount + 1, 1, bob, alice, charlie, 1);
// fungible
- const fungibleCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;
- await approveExpectFail(fungibleCollectionCount + 1, 1, Alice, Bob);
+ const fungibleCollectionCount = (await api.query.common.createdCollectionCount()).toNumber();
+ await approveExpectFail(fungibleCollectionCount + 1, 0, alice, bob);
- await transferFromExpectFail(fungibleCollectionCount + 1, 1, Bob, Alice, Charlie, 1);
+ await transferFromExpectFail(fungibleCollectionCount + 1, 0, bob, alice, charlie, 1);
// reFungible
- const reFungibleCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;
- await approveExpectFail(reFungibleCollectionCount + 1, 1, Alice, Bob);
+ const reFungibleCollectionCount = (await api.query.common.createdCollectionCount()).toNumber();
+ await approveExpectFail(reFungibleCollectionCount + 1, 1, alice, bob);
- await transferFromExpectFail(reFungibleCollectionCount + 1, 1, Bob, Alice, Charlie, 1);
+ await transferFromExpectFail(reFungibleCollectionCount + 1, 1, bob, alice, charlie, 1);
});
});
@@ -149,24 +149,24 @@
await usingApi(async () => {
// nft
const nftCollectionId = await createCollectionExpectSuccess();
- const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
+ const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
- await transferFromExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 1);
+ await transferFromExpectFail(nftCollectionId, newNftTokenId, bob, alice, charlie, 1);
// fungible
const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
- const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');
- await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 1);
+ const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');
+ await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, bob, alice, charlie, 1);
// reFungible
const reFungibleCollectionId = await
createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
- const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');
+ const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');
await transferFromExpectFail(
reFungibleCollectionId,
newReFungibleTokenId,
- Bob,
- Alice,
- Charlie,
+ bob,
+ alice,
+ charlie,
1,
);
});
@@ -176,27 +176,27 @@
await usingApi(async () => {
// nft
const nftCollectionId = await createCollectionExpectSuccess();
- const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
- await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob);
+ const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
+ await approveExpectSuccess(nftCollectionId, newNftTokenId, alice, bob.address);
- await transferFromExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 2);
+ await transferFromExpectFail(nftCollectionId, newNftTokenId, bob, alice, charlie, 2);
// fungible
const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
- const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');
- await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);
- await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 2);
+ const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');
+ await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob.address);
+ await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, bob, alice, charlie, 2);
// reFungible
const reFungibleCollectionId = await
createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
- const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');
- await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);
+ const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');
+ await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, alice, bob.address);
await transferFromExpectFail(
reFungibleCollectionId,
newReFungibleTokenId,
- Bob,
- Alice,
- Charlie,
+ bob,
+ alice,
+ charlie,
2,
);
});
@@ -204,13 +204,13 @@
it('execute transferFrom from account that is not owner of collection', async () => {
await usingApi(async () => {
- const Dave = privateKey('//Dave');
+ const dave = privateKey('//Dave');
// nft
const nftCollectionId = await createCollectionExpectSuccess();
- const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
+ const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
try {
- await approveExpectFail(nftCollectionId, newNftTokenId, Dave, Bob);
- await transferFromExpectFail(nftCollectionId, newNftTokenId, Dave, Alice, Charlie, 1);
+ await approveExpectFail(nftCollectionId, newNftTokenId, dave, bob);
+ await transferFromExpectFail(nftCollectionId, newNftTokenId, dave, alice, charlie, 1);
} catch (e) {
// tslint:disable-next-line:no-unused-expression
expect(e).to.be.exist;
@@ -220,10 +220,10 @@
// fungible
const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
- const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');
+ const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');
try {
- await approveExpectFail(fungibleCollectionId, newFungibleTokenId, Dave, Bob);
- await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Dave, Alice, Charlie, 1);
+ await approveExpectFail(fungibleCollectionId, newFungibleTokenId, dave, bob);
+ await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, dave, alice, charlie, 1);
} catch (e) {
// tslint:disable-next-line:no-unused-expression
expect(e).to.be.exist;
@@ -231,83 +231,83 @@
// reFungible
const reFungibleCollectionId = await
createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
- const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');
+ const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');
try {
- await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, Dave, Bob);
- await transferFromExpectFail(reFungibleCollectionId, newReFungibleTokenId, Dave, Alice, Charlie, 1);
+ await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, dave, bob);
+ await transferFromExpectFail(reFungibleCollectionId, newReFungibleTokenId, dave, alice, charlie, 1);
} catch (e) {
// tslint:disable-next-line:no-unused-expression
expect(e).to.be.exist;
}
});
});
- it( 'transferFrom burnt token before approve NFT', async () => {
+ it('transferFrom burnt token before approve NFT', async () => {
await usingApi(async () => {
// nft
const nftCollectionId = await createCollectionExpectSuccess();
- const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
- await burnItemExpectSuccess(Alice, nftCollectionId, newNftTokenId, 1);
- await approveExpectFail(nftCollectionId, newNftTokenId, Alice, Bob);
- await transferFromExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 1);
+ const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
+ await burnItemExpectSuccess(alice, nftCollectionId, newNftTokenId, 1);
+ await approveExpectFail(nftCollectionId, newNftTokenId, alice, bob);
+ await transferFromExpectFail(nftCollectionId, newNftTokenId, bob, alice, charlie, 1);
});
});
- it( 'transferFrom burnt token before approve Fungible', async () => {
+ it('transferFrom burnt token before approve Fungible', async () => {
await usingApi(async () => {
const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
- const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');
- await burnItemExpectSuccess(Alice, fungibleCollectionId, 1, 10);
- await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);
- await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 1);
+ const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');
+ await burnItemExpectSuccess(alice, fungibleCollectionId, newFungibleTokenId, 10);
+ await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob.address);
+ await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, bob, alice, charlie, 1);
});
});
- it( 'transferFrom burnt token before approve ReFungible', async () => {
+ it('transferFrom burnt token before approve ReFungible', async () => {
await usingApi(async () => {
const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
- const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');
- await burnItemExpectSuccess(Alice, reFungibleCollectionId, newReFungibleTokenId, 100);
- await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);
- await transferFromExpectFail(reFungibleCollectionId, newReFungibleTokenId, Bob, Alice, Charlie, 1);
+ const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');
+ await burnItemExpectSuccess(alice, reFungibleCollectionId, newReFungibleTokenId, 100);
+ await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, alice, bob);
+ await transferFromExpectFail(reFungibleCollectionId, newReFungibleTokenId, bob, alice, charlie, 1);
});
});
- it( 'transferFrom burnt token after approve NFT', async () => {
+ it('transferFrom burnt token after approve NFT', async () => {
await usingApi(async () => {
// nft
const nftCollectionId = await createCollectionExpectSuccess();
- const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
- await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob);
- await burnItemExpectSuccess(Alice, nftCollectionId, newNftTokenId, 1);
- await transferFromExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 1);
+ const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
+ await approveExpectSuccess(nftCollectionId, newNftTokenId, alice, bob.address);
+ await burnItemExpectSuccess(alice, nftCollectionId, newNftTokenId, 1);
+ await transferFromExpectFail(nftCollectionId, newNftTokenId, bob, alice, charlie, 1);
});
});
- it( 'transferFrom burnt token after approve Fungible', async () => {
+ it('transferFrom burnt token after approve Fungible', async () => {
await usingApi(async () => {
const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
- const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');
- await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);
- await burnItemExpectSuccess(Alice, fungibleCollectionId, 1, 10);
- await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 1);
+ const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');
+ await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob.address);
+ await burnItemExpectSuccess(alice, fungibleCollectionId, newFungibleTokenId, 10);
+ await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, bob, alice, charlie, 1);
});
});
- it( 'transferFrom burnt token after approve ReFungible', async () => {
+ it('transferFrom burnt token after approve ReFungible', async () => {
await usingApi(async () => {
const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
- const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');
- await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);
- await burnItemExpectSuccess(Alice, reFungibleCollectionId, newReFungibleTokenId, 100);
- await transferFromExpectFail(reFungibleCollectionId, newReFungibleTokenId, Bob, Alice, Charlie, 1);
+ const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');
+ await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, alice, bob.address);
+ await burnItemExpectSuccess(alice, reFungibleCollectionId, newReFungibleTokenId, 100);
+ await transferFromExpectFail(reFungibleCollectionId, newReFungibleTokenId, bob, alice, charlie, 1);
});
});
it('fails when called by collection owner on non-owned item when OwnerCanTransfer == false', async () => {
const collectionId = await createCollectionExpectSuccess();
- const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Bob.address);
- await setCollectionLimitsExpectSuccess(Alice, collectionId, { ownerCanTransfer: false });
+ const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', bob.address);
+ await setCollectionLimitsExpectSuccess(alice, collectionId, {ownerCanTransfer: false});
- await transferFromExpectFail(collectionId, itemId, Alice, Bob, Charlie);
+ await transferFromExpectFail(collectionId, itemId, alice, bob, charlie);
});
});
tests/src/types.tsdiffbeforeafterboth--- a/tests/src/types.ts
+++ /dev/null
@@ -1,37 +0,0 @@
-//
-// This file is subject to the terms and conditions defined in
-// file 'LICENSE', which is part of this source code package.
-//
-
-import BN from 'bn.js';
-
-export interface ICollectionInterface {
- access: string;
- id: number;
- decimalPoints: BN;
- // constOnChainSchema
- description: [BN, BN]; // utf16
- isReFungible: boolean;
- limits: {
- accountTokenOwnershipLimit: number;
- sponsoredDataSize: number;
- sponsoredDataRateLimit?: number,
- tokenLimit: number;
- sponsorTimeout: number;
- ownerCanTransfer: boolean;
- ownerCanDestroy: boolean;
- };
- mintMode: boolean;
- mode: {
- nft: null;
- };
- name: [BN, BN]; // utf16
- offchainSchema: [Uint8Array];
- owner: [Uint8Array];
- schemaVersion: string;
- // prefix
- // sponsor
- // tokenPrefix
- // unconfirmedSponsor
- // variableOnChainSchema
-}
tests/src/util/contracthelpers.tsdiffbeforeafterboth--- a/tests/src/util/contracthelpers.ts
+++ b/tests/src/util/contracthelpers.ts
@@ -5,16 +5,15 @@
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
-import { submitTransactionAsync, submitTransactionExpectFailAsync } from '../substrate/substrate-api';
+import {submitTransactionAsync, submitTransactionExpectFailAsync} from '../substrate/substrate-api';
import fs from 'fs';
-import { Abi, CodePromise, ContractPromise as Contract } from '@polkadot/api-contract';
-import { IKeyringPair } from '@polkadot/types/types';
-import { ApiPromise, Keyring } from '@polkadot/api';
+import {Abi, CodePromise, ContractPromise as Contract} from '@polkadot/api-contract';
+import {IKeyringPair} from '@polkadot/types/types';
+import {ApiPromise, Keyring} from '@polkadot/api';
chai.use(chaiAsPromised);
const expect = chai.expect;
-import { BigNumber } from 'bignumber.js';
-import { findUnusedAddress, getGenericResult } from '../util/helpers';
+import {findUnusedAddress, getGenericResult} from '../util/helpers';
const value = 0;
const gasLimit = '200000000000';
@@ -40,11 +39,10 @@
const deployer = await findUnusedAddress(api);
// Transfer balance to it
- const keyring = new Keyring({ type: 'sr25519' });
+ const keyring = new Keyring({type: 'sr25519'});
const alice = keyring.addFromUri('//Alice');
- let amount = new BigNumber(endowment);
- amount = amount.plus(100e15);
- const tx = api.tx.balances.transfer(deployer.address, amount.toFixed());
+ const amount = BigInt(endowment) + 10n**15n;
+ const tx = api.tx.balances.transfer(deployer.address, amount);
await submitTransactionAsync(alice, tx);
return deployer;
tests/src/util/helpers.tsdiffbeforeafterboth--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -3,51 +3,67 @@
// file 'LICENSE', which is part of this source code package.
//
-import { ApiPromise, Keyring } from '@polkadot/api';
-import type { AccountId, EventRecord } from '@polkadot/types/interfaces';
-import { IKeyringPair } from '@polkadot/types/types';
-import { evmToAddress } from '@polkadot/util-crypto';
-import { BigNumber } from 'bignumber.js';
+import {ApiPromise, Keyring} from '@polkadot/api';
+import type {AccountId, EventRecord} from '@polkadot/types/interfaces';
+import {IKeyringPair} from '@polkadot/types/types';
+import {evmToAddress} from '@polkadot/util-crypto';
import BN from 'bn.js';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
-import { alicesPublicKey } from '../accounts';
+import {alicesPublicKey} from '../accounts';
+import {NftDataStructsCollection} from '../interfaces';
import privateKey from '../substrate/privateKey';
-import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from '../substrate/substrate-api';
-import { ICollectionInterface } from '../types';
-import { hexToStr, strToUTF16, utf16ToStr } from './util';
+import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from '../substrate/substrate-api';
+import {hexToStr, strToUTF16, utf16ToStr} from './util';
chai.use(chaiAsPromised);
const expect = chai.expect;
export type CrossAccountId = {
- substrate: string,
+ Substrate: string,
} | {
- ethereum: string,
+ Ethereum: string,
};
export function normalizeAccountId(input: string | AccountId | CrossAccountId | IKeyringPair): CrossAccountId {
- if (typeof input === 'string')
- return { substrate: input };
- if ('address' in input) {
- return { substrate: input.address };
+ if (typeof input === 'string') {
+ if (input.length === 48 || input.length === 47) {
+ return {Substrate: input};
+ } else if (input.length === 42 && input.startsWith('0x')) {
+ return {Ethereum: input.toLowerCase()};
+ } else if (input.length === 40 && !input.startsWith('0x')) {
+ return {Ethereum: '0x' + input.toLowerCase()};
+ } else {
+ throw new Error(`Unknown address format: "${input}"`);
+ }
}
- if ('ethereum' in input) {
- input.ethereum = input.ethereum.toLowerCase();
- return input;
+ if ('address' in input) {
+ return {Substrate: input.address};
}
- if ('substrate' in input) {
+ if ('Ethereum' in input) {
+ return {
+ Ethereum: input.Ethereum.toLowerCase(),
+ };
+ } else if ('ethereum' in input) {
+ return {
+ Ethereum: (input as any).ethereum.toLowerCase(),
+ };
+ } else if ('Substrate' in input) {
return input;
+ }else if ('substrate' in input) {
+ return {
+ Substrate: (input as any).substrate,
+ };
}
// AccountId
- return {substrate: input.toString()};
+ return {Substrate: input.toString()};
}
export function toSubstrateAddress(input: string | CrossAccountId | IKeyringPair): string {
input = normalizeAccountId(input);
- if ('substrate' in input) {
- return input.substrate;
+ if ('Substrate' in input) {
+ return input.Substrate;
} else {
- return evmToAddress(input.ethereum);
+ return evmToAddress(input.Ethereum);
}
}
@@ -86,12 +102,6 @@
interface IReFungibleOwner {
fraction: BN;
owner: number[];
-}
-
-interface ITokenDataType {
- owner: IKeyringPair;
- constData: number[];
- variableData: number[];
}
interface IGetMessage {
@@ -127,8 +137,8 @@
let checkMsgNftMethod = '';
let checkMsgTrsMethod = '';
let checkMsgSysMethod = '';
- events.forEach(({ event: { method, section } }) => {
- if (section === 'nft') {
+ events.forEach(({event: {method, section}}) => {
+ if (section === 'common') {
checkMsgNftMethod = method;
} else if (section === 'treasury') {
checkMsgTrsMethod = method;
@@ -148,7 +158,7 @@
const result: GenericResult = {
success: false,
};
- events.forEach(({ event: { method } }) => {
+ events.forEach(({event: {method}}) => {
// console.log(` ${phase}: ${section}.${method}:: ${data}`);
if (method === 'ExtrinsicSuccess') {
result.success = true;
@@ -162,12 +172,12 @@
export function getCreateCollectionResult(events: EventRecord[]): CreateCollectionResult {
let success = false;
let collectionId = 0;
- events.forEach(({ event: { data, method, section } }) => {
+ events.forEach(({event: {data, method, section}}) => {
// console.log(` ${phase}: ${section}.${method}:: ${data}`);
if (method == 'ExtrinsicSuccess') {
success = true;
- } else if ((section == 'nft') && (method == 'CollectionCreated')) {
- collectionId = parseInt(data[0].toString());
+ } else if ((section == 'common') && (method == 'CollectionCreated')) {
+ collectionId = parseInt(data[0].toString(), 10);
}
});
const result: CreateCollectionResult = {
@@ -182,14 +192,14 @@
let collectionId = 0;
let itemId = 0;
let recipient;
- events.forEach(({ event: { data, method, section } }) => {
+ events.forEach(({event: {data, method, section}}) => {
// console.log(` ${phase}: ${section}.${method}:: ${data}`);
if (method == 'ExtrinsicSuccess') {
success = true;
- } else if ((section == 'nft') && (method == 'ItemCreated')) {
- collectionId = parseInt(data[0].toString());
- itemId = parseInt(data[1].toString());
- recipient = data[2].toJSON();
+ } else if ((section == 'common') && (method == 'ItemCreated')) {
+ collectionId = parseInt(data[0].toString(), 10);
+ itemId = parseInt(data[1].toString(), 10);
+ recipient = normalizeAccountId(data[2].toJSON() as any);
}
});
const result: CreateItemResult = {
@@ -209,14 +219,14 @@
value: 0n,
};
- events.forEach(({ event: { data, method, section } }) => {
+ events.forEach(({event: {data, method, section}}) => {
if (method === 'ExtrinsicSuccess') {
result.success = true;
- } else if (section === 'nft' && method === 'Transfer') {
+ } else if (section === 'common' && method === 'Transfer') {
result.collectionId = +data[0].toString();
result.itemId = +data[1].toString();
- result.sender = data[2].toJSON() as CrossAccountId;
- result.recipient = data[3].toJSON() as CrossAccountId;
+ result.sender = normalizeAccountId(data[2].toJSON() as any);
+ result.recipient = normalizeAccountId(data[3].toJSON() as any);
result.value = BigInt(data[4].toString());
}
});
@@ -248,52 +258,52 @@
const defaultCreateCollectionParams: CreateCollectionParams = {
description: 'description',
- mode: { type: 'NFT' },
+ mode: {type: 'NFT'},
name: 'name',
tokenPrefix: 'prefix',
};
export async function createCollectionExpectSuccess(params: Partial<CreateCollectionParams> = {}): Promise<number> {
- const { name, description, mode, tokenPrefix } = { ...defaultCreateCollectionParams, ...params };
+ const {name, description, mode, tokenPrefix} = {...defaultCreateCollectionParams, ...params};
let collectionId = 0;
await usingApi(async (api) => {
// Get number of collections before the transaction
- const AcollectionCount = parseInt((await api.query.nft.createdCollectionCount()).toString(), 10);
+ const collectionCountBefore = (await api.query.common.createdCollectionCount()).toNumber();
// Run the CreateCollection transaction
const alicePrivateKey = privateKey('//Alice');
let modeprm = {};
if (mode.type === 'NFT') {
- modeprm = { nft: null };
+ modeprm = {nft: null};
} else if (mode.type === 'Fungible') {
- modeprm = { fungible: mode.decimalPoints };
+ modeprm = {fungible: mode.decimalPoints};
} else if (mode.type === 'ReFungible') {
- modeprm = { refungible: null };
+ modeprm = {refungible: null};
}
- const tx = api.tx.nft.createCollection(strToUTF16(name), strToUTF16(description), strToUTF16(tokenPrefix), modeprm);
+ const tx = api.tx.nft.createCollection(strToUTF16(name), strToUTF16(description), strToUTF16(tokenPrefix), modeprm as any);
const events = await submitTransactionAsync(alicePrivateKey, tx);
const result = getCreateCollectionResult(events);
// Get number of collections after the transaction
- const BcollectionCount = parseInt((await api.query.nft.createdCollectionCount()).toString(), 10);
+ const collectionCountAfter = (await api.query.common.createdCollectionCount()).toNumber();
// Get the collection
- const collection: any = (await api.query.nft.collectionById(result.collectionId) as any).toJSON();
+ const collection = (await api.query.common.collectionById(result.collectionId)).unwrap();
// What to expect
// tslint:disable-next-line:no-unused-expression
expect(result.success).to.be.true;
- expect(result.collectionId).to.be.equal(BcollectionCount);
+ expect(result.collectionId).to.be.equal(collectionCountAfter);
// tslint:disable-next-line:no-unused-expression
expect(collection).to.be.not.null;
- expect(BcollectionCount).to.be.equal(AcollectionCount + 1, 'Error: NFT collection NOT created.');
- expect(collection.owner).to.be.equal(toSubstrateAddress(alicesPublicKey));
- expect(utf16ToStr(collection.name)).to.be.equal(name);
- expect(utf16ToStr(collection.description)).to.be.equal(description);
- expect(hexToStr(collection.tokenPrefix)).to.be.equal(tokenPrefix);
+ expect(collectionCountAfter).to.be.equal(collectionCountBefore + 1, 'Error: NFT collection NOT created.');
+ expect(collection.owner.toString()).to.be.equal(toSubstrateAddress(alicesPublicKey));
+ expect(utf16ToStr(collection.name.toJSON() as any)).to.be.equal(name);
+ expect(utf16ToStr(collection.description.toJSON() as any)).to.be.equal(description);
+ expect(hexToStr(collection.tokenPrefix.toJSON())).to.be.equal(tokenPrefix);
collectionId = result.collectionId;
});
@@ -302,54 +312,51 @@
}
export async function createCollectionExpectFailure(params: Partial<CreateCollectionParams> = {}) {
- const { name, description, mode, tokenPrefix } = { ...defaultCreateCollectionParams, ...params };
+ const {name, description, mode, tokenPrefix} = {...defaultCreateCollectionParams, ...params};
let modeprm = {};
if (mode.type === 'NFT') {
- modeprm = { nft: null };
+ modeprm = {nft: null};
} else if (mode.type === 'Fungible') {
- modeprm = { fungible: mode.decimalPoints };
+ modeprm = {fungible: mode.decimalPoints};
} else if (mode.type === 'ReFungible') {
- modeprm = { refungible: null };
+ modeprm = {refungible: null};
}
await usingApi(async (api) => {
// Get number of collections before the transaction
- const AcollectionCount = parseInt((await api.query.nft.createdCollectionCount()).toString());
+ const collectionCountBefore = (await api.query.common.createdCollectionCount()).toNumber();
// Run the CreateCollection transaction
const alicePrivateKey = privateKey('//Alice');
- const tx = api.tx.nft.createCollection(strToUTF16(name), strToUTF16(description), strToUTF16(tokenPrefix), modeprm);
+ const tx = api.tx.nft.createCollection(strToUTF16(name), strToUTF16(description), strToUTF16(tokenPrefix), modeprm as any);
const events = await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;
const result = getCreateCollectionResult(events);
// Get number of collections after the transaction
- const BcollectionCount = parseInt((await api.query.nft.createdCollectionCount()).toString());
+ const collectionCountAfter = (await api.query.common.createdCollectionCount()).toNumber();
// What to expect
// tslint:disable-next-line:no-unused-expression
expect(result.success).to.be.false;
- expect(BcollectionCount).to.be.equal(AcollectionCount, 'Error: Collection with incorrect data created.');
+ expect(collectionCountAfter).to.be.equal(collectionCountBefore, 'Error: Collection with incorrect data created.');
});
}
export async function findUnusedAddress(api: ApiPromise, seedAddition = ''): Promise<IKeyringPair> {
- let bal = new BigNumber(0);
+ let bal = 0n;
let unused;
do {
const randomSeed = 'seed' + Math.floor(Math.random() * Math.floor(10000)) + seedAddition;
- const keyring = new Keyring({ type: 'sr25519' });
+ const keyring = new Keyring({type: 'sr25519'});
unused = keyring.addFromUri(`//${randomSeed}`);
- bal = new BigNumber((await api.query.system.account(unused.address)).data.free.toString());
- } while (bal.toFixed() != '0');
+ bal = (await api.query.system.account(unused.address)).data.free.toBigInt();
+ } while (bal !== 0n);
return unused;
}
-export async function getAllowance(collectionId: number, tokenId: number, owner: string, approved: string) {
- return await usingApi(async (api) => {
- const bn = await api.query.nft.allowances(collectionId, [tokenId, owner, approved]) as unknown as BN;
- return BigInt(bn.toString());
- });
+export async function getAllowance(api: ApiPromise, collectionId: number, owner: CrossAccountId | string, approved: CrossAccountId | string, tokenId: number) {
+ return (await api.rpc.nft.allowance(collectionId, normalizeAccountId(owner), normalizeAccountId(approved), tokenId)).toBigInt();
}
export function findUnusedAddresses(api: ApiPromise, amount: number): Promise<IKeyringPair[]> {
@@ -357,14 +364,14 @@
}
export async function findNotExistingCollection(api: ApiPromise): Promise<number> {
- const totalNumber = parseInt((await api.query.nft.createdCollectionCount()).toString(), 10) as unknown as number;
+ const totalNumber = (await api.query.common.createdCollectionCount()).toNumber();
const newCollection: number = totalNumber + 1;
return newCollection;
}
function getDestroyResult(events: EventRecord[]): boolean {
let success = false;
- events.forEach(({ event: { method } }) => {
+ events.forEach(({event: {method}}) => {
if (method == 'ExtrinsicSuccess') {
success = true;
}
@@ -388,27 +395,16 @@
const tx = api.tx.nft.destroyCollection(collectionId);
const events = await submitTransactionAsync(alicePrivateKey, tx);
const result = getDestroyResult(events);
-
- // Get the collection
- const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
+ expect(result).to.be.true;
// What to expect
- expect(result).to.be.true;
- expect(collection).to.be.null;
- });
-}
-
-export async function queryCollectionLimits(collectionId: number) {
- return await usingApi(async (api) => {
- return ((await api.query.nft.collectionById(collectionId)).toJSON() as any).limits;
+ expect((await api.query.common.collectionById(collectionId)).isNone).to.be.true;
});
}
export async function setCollectionLimitsExpectSuccess(sender: IKeyringPair, collectionId: number, limits: any) {
await usingApi(async (api) => {
- const oldLimits = await queryCollectionLimits(collectionId);
- const newLimits = { ...oldLimits as any, ...limits };
- const tx = api.tx.nft.setCollectionLimits(collectionId, newLimits);
+ const tx = api.tx.nft.setCollectionLimits(collectionId, limits);
const events = await submitTransactionAsync(sender, tx);
const result = getGenericResult(events);
@@ -418,9 +414,7 @@
export async function setCollectionLimitsExpectFailure(sender: IKeyringPair, collectionId: number, limits: any) {
await usingApi(async (api) => {
- const oldLimits = await queryCollectionLimits(collectionId);
- const newLimits = { ...oldLimits as any, ...limits };
- const tx = api.tx.nft.setCollectionLimits(collectionId, newLimits);
+ const tx = api.tx.nft.setCollectionLimits(collectionId, limits);
const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;
const result = getGenericResult(events);
@@ -438,11 +432,11 @@
const result = getGenericResult(events);
// Get the collection
- const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
+ const collection = (await api.query.common.collectionById(collectionId)).unwrap();
// What to expect
expect(result.success).to.be.true;
- expect(collection.sponsorship).to.deep.equal({
+ expect(collection.sponsorship.toJSON()).to.deep.equal({
unconfirmed: sponsor,
});
});
@@ -458,11 +452,11 @@
const result = getGenericResult(events);
// Get the collection
- const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
+ const collection = (await api.query.common.collectionById(collectionId)).unwrap();
// What to expect
expect(result.success).to.be.true;
- expect(collection.sponsorship).to.be.deep.equal({ disabled: null });
+ expect(collection.sponsorship.toJSON()).to.be.deep.equal({disabled: null});
});
}
@@ -496,11 +490,11 @@
const result = getGenericResult(events);
// Get the collection
- const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
+ const collection = (await api.query.common.collectionById(collectionId)).unwrap();
// What to expect
expect(result.success).to.be.true;
- expect(collection.sponsorship).to.be.deep.equal({
+ expect(collection.sponsorship.toJSON()).to.be.deep.equal({
confirmed: sender.address,
});
});
@@ -520,7 +514,7 @@
export async function setMetadataUpdatePermissionFlagExpectSuccess(sender: IKeyringPair, collectionId: number, flag: string) {
await usingApi(async (api) => {
- const tx = api.tx.nft.setMetaUpdatePermissionFlag(collectionId, flag);
+ const tx = api.tx.nft.setMetaUpdatePermissionFlag(collectionId, flag as any);
const events = await submitTransactionAsync(sender, tx);
const result = getGenericResult(events);
@@ -531,7 +525,7 @@
export async function setMetadataUpdatePermissionFlagExpectFailure(sender: IKeyringPair, collectionId: number, flag: string) {
await usingApi(async (api) => {
- const tx = api.tx.nft.setMetaUpdatePermissionFlag(collectionId, flag);
+ const tx = api.tx.nft.setMetaUpdatePermissionFlag(collectionId, flag as any);
const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;
const result = getGenericResult(events);
@@ -702,36 +696,46 @@
export async function burnItemExpectSuccess(sender: IKeyringPair, collectionId: number, tokenId: number, value = 1) {
await usingApi(async (api) => {
+ const balanceBefore = await getBalance(api, collectionId, normalizeAccountId(sender), tokenId);
+ // if burning token by admin - use adminButnItemExpectSuccess
+ expect(balanceBefore >= BigInt(value)).to.be.true;
+
const tx = api.tx.nft.burnItem(collectionId, tokenId, value);
const events = await submitTransactionAsync(sender, tx);
const result = getGenericResult(events);
- // Get the item
- const item: any = (await api.query.nft.nftItemList(collectionId, tokenId)).toJSON();
- // What to expect
- // tslint:disable-next-line:no-unused-expression
expect(result.success).to.be.true;
- // tslint:disable-next-line:no-unused-expression
- expect(item).to.be.null;
+
+ const balanceAfter = await getBalance(api, collectionId, normalizeAccountId(sender), tokenId);
+ expect(balanceAfter + BigInt(value)).to.be.equal(balanceBefore);
});
}
export async function
approveExpectSuccess(
collectionId: number,
- tokenId: number, owner: IKeyringPair, approved: IKeyringPair | CrossAccountId | string, amount: number | bigint = 1,
+ tokenId: number, owner: IKeyringPair, approved: CrossAccountId | string, amount: number | bigint = 1,
) {
await usingApi(async (api: ApiPromise) => {
- approved = normalizeAccountId(approved);
- const allowanceBefore =
- await api.query.nft.allowances(collectionId, [tokenId, owner.address, toSubstrateAddress(approved)]) as unknown as BN;
- const approveNftTx = api.tx.nft.approve(approved, collectionId, tokenId, amount);
+ const approveNftTx = api.tx.nft.approve(normalizeAccountId(approved), collectionId, tokenId, amount);
const events = await submitTransactionAsync(owner, approveNftTx);
- const result = getCreateItemResult(events);
- // tslint:disable-next-line:no-unused-expression
+ const result = getGenericResult(events);
+ expect(result.success).to.be.true;
+
+ expect(await getAllowance(api, collectionId, owner.address, approved, tokenId)).to.be.equal(BigInt(amount));
+ });
+}
+
+export async function adminApproveFromExpectSuccess(
+ collectionId: number,
+ tokenId: number, admin: IKeyringPair, owner: CrossAccountId | string, approved: CrossAccountId | string, amount: number | bigint = 1,
+) {
+ await usingApi(async (api: ApiPromise) => {
+ const approveNftTx = api.tx.nft.approve(normalizeAccountId(approved), collectionId, tokenId, amount);
+ const events = await submitTransactionAsync(admin, approveNftTx);
+ const result = getGenericResult(events);
expect(result.success).to.be.true;
- const allowanceAfter =
- await api.query.nft.allowances(collectionId, [tokenId, owner.address, toSubstrateAddress(approved)]) as unknown as BN;
- expect(allowanceAfter.sub(allowanceBefore).toString()).to.be.equal(amount.toString());
+
+ expect(await getAllowance(api, collectionId, owner, approved, tokenId)).to.be.equal(BigInt(amount));
});
}
@@ -747,9 +751,9 @@
) {
await usingApi(async (api: ApiPromise) => {
const to = normalizeAccountId(accountTo);
- let balanceBefore = new BN(0);
+ let balanceBefore = 0n;
if (type === 'Fungible') {
- balanceBefore = await api.query.nft.balance(collectionId, toSubstrateAddress(to)) as unknown as BN;
+ balanceBefore = await getBalance(api, collectionId, to, tokenId);
}
const transferFromTx = api.tx.nft.transferFrom(normalizeAccountId(accountFrom), to, collectionId, tokenId, value);
const events = await submitTransactionAsync(accountApproved, transferFromTx);
@@ -757,18 +761,14 @@
// 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 any).toJSON() as ITokenDataType;
- expect(nftItemData.owner).to.be.deep.equal(to);
+ expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal(to);
}
if (type === 'Fungible') {
- const balanceAfter = (await api.query.nft.fungibleItemList(collectionId, toSubstrateAddress(to)) as any).value as unknown as BN;
- expect(balanceAfter.sub(balanceBefore).toString()).to.be.equal(value.toString());
+ const balanceAfter = await getBalance(api, collectionId, to, tokenId);
+ expect(balanceAfter - balanceBefore).to.be.equal(BigInt(value));
}
if (type === 'ReFungible') {
- const nftItemData =
- (await api.query.nft.reFungibleItemList(collectionId, tokenId) as any).toJSON() as IReFungibleTokenDataType;
- expect(nftItemData.owner[0].owner).to.be.deep.equal(normalizeAccountId(to));
- expect(nftItemData.owner[0].fraction).to.be.equal(value);
+ expect(await getBalance(api, collectionId, to, tokenId)).to.be.equal(BigInt(value));
}
});
}
@@ -801,9 +801,9 @@
});
}
-export async function addCollectionAdminExpectSuccess(sender: IKeyringPair, collectionId: number, address: IKeyringPair) {
+export async function addCollectionAdminExpectSuccess(sender: IKeyringPair, collectionId: number, address: string | CrossAccountId) {
await usingApi(async (api) => {
- const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(address.address));
+ const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(address));
const events = await submitTransactionAsync(sender, changeAdminTx);
const result = getCreateCollectionResult(events);
expect(result.success).to.be.true;
@@ -828,7 +828,6 @@
sender: IKeyringPair,
recipient: IKeyringPair,
value: number | bigint = 1,
- blockTimeMs: number,
blockSchedule: number,
) {
await usingApi(async (api: ApiPromise) => {
@@ -836,24 +835,22 @@
const expectedBlockNumber = blockNumber + blockSchedule;
expect(blockNumber).to.be.greaterThan(0);
- const transferTx = await api.tx.nft.transfer(normalizeAccountId(recipient.address), collectionId, tokenId, value);
- const scheduleTx = await api.tx.scheduler.schedule(expectedBlockNumber, null, 0, transferTx);
+ const transferTx = api.tx.nft.transfer(normalizeAccountId(recipient.address), collectionId, tokenId, value);
+ const scheduleTx = api.tx.scheduler.schedule(expectedBlockNumber, null, 0, transferTx as any);
await submitTransactionAsync(sender, scheduleTx);
- const recipientBalanceBefore = new BigNumber((await api.query.system.account(recipient.address)).data.free.toString());
+ const recipientBalanceBefore = (await api.query.system.account(recipient.address)).data.free.toBigInt();
- const nftItemDataBefore = (await api.query.nft.nftItemList(collectionId, tokenId)).toJSON() as any as ITokenDataType;
- expect(toSubstrateAddress(nftItemDataBefore.owner)).to.be.equal(sender.address);
+ expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal(normalizeAccountId(sender.address));
// sleep for 4 blocks
- await new Promise(resolve => setTimeout(resolve, blockTimeMs * (blockSchedule + 1)));
+ await waitNewBlocks(blockSchedule + 1);
- const recipientBalanceAfter = new BigNumber((await api.query.system.account(recipient.address)).data.free.toString());
+ const recipientBalanceAfter = (await api.query.system.account(recipient.address)).data.free.toBigInt();
- const nftItemData = (await api.query.nft.nftItemList(collectionId, tokenId)).toJSON() as unknown as ITokenDataType;
- expect(toSubstrateAddress(nftItemData.owner)).to.be.equal(recipient.address);
- expect(recipientBalanceAfter.toNumber()).to.be.equal(recipientBalanceBefore.toNumber());
+ expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal(normalizeAccountId(recipient.address));
+ expect(recipientBalanceAfter).to.be.equal(recipientBalanceBefore);
});
}
@@ -870,9 +867,9 @@
await usingApi(async (api: ApiPromise) => {
const to = normalizeAccountId(recipient);
- let balanceBefore = new BN(0);
+ let balanceBefore = 0n;
if (type === 'Fungible') {
- balanceBefore = await api.query.nft.balance(collectionId, toSubstrateAddress(to)) as unknown as BN;
+ balanceBefore = await getBalance(api, collectionId, to, tokenId);
}
const transferTx = api.tx.nft.transfer(to, collectionId, tokenId, value);
const events = await submitTransactionAsync(sender, transferTx);
@@ -883,23 +880,16 @@
expect(result.itemId).to.be.equal(tokenId);
expect(result.sender).to.be.deep.equal(normalizeAccountId(sender.address));
expect(result.recipient).to.be.deep.equal(to);
- expect(result.value.toString()).to.be.equal(value.toString());
+ expect(result.value).to.be.equal(BigInt(value));
if (type === 'NFT') {
- const nftItemData = (await api.query.nft.nftItemList(collectionId, tokenId)).toJSON() as unknown as ITokenDataType;
- expect(nftItemData.owner).to.be.deep.equal(to);
+ expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal(to);
}
if (type === 'Fungible') {
- const balanceAfter = (await api.query.nft.fungibleItemList(collectionId, toSubstrateAddress(to)) as any).value as unknown as BN;
- expect(balanceAfter.sub(balanceBefore).toString()).to.be.equal(value.toString());
+ const balanceAfter = await getBalance(api, collectionId, to, tokenId);
+ expect(balanceAfter - balanceBefore).to.be.equal(BigInt(value));
}
if (type === 'ReFungible') {
- const nftItemData =
- (await api.query.nft.reFungibleItemList(collectionId, tokenId)).toJSON() as unknown as IReFungibleTokenDataType;
- const expectedOwner = toSubstrateAddress(to);
- const ownerIndex = nftItemData.owner.findIndex(v => toSubstrateAddress(v.owner as any as string) == expectedOwner);
- expect(ownerIndex).to.not.equal(-1);
- expect(nftItemData.owner[ownerIndex].owner).to.be.deep.equal(normalizeAccountId(to));
- expect(nftItemData.owner[ownerIndex].fraction).to.be.greaterThanOrEqual(value as number);
+ expect(await getBalance(api, collectionId, to, tokenId) >= value).to.be.true;
}
});
}
@@ -937,15 +927,54 @@
});
}
-export async function getFungibleBalance(
+export async function getBalance(
+ api: ApiPromise,
+ collectionId: number,
+ owner: string | CrossAccountId,
+ token: number,
+): Promise<bigint> {
+ return (await api.rpc.nft.balance(collectionId, normalizeAccountId(owner), token)).toBigInt();
+}
+export async function getTokenOwner(
+ api: ApiPromise,
+ collectionId: number,
+ token: number,
+): Promise<CrossAccountId> {
+ return normalizeAccountId((await api.rpc.nft.tokenOwner(collectionId, token)).toJSON() as any);
+}
+export async function isTokenExists(
+ api: ApiPromise,
+ collectionId: number,
+ token: number,
+): Promise<boolean> {
+ return (await api.rpc.nft.tokenExists(collectionId, token)).toJSON();
+}
+export async function getLastTokenId(
+ api: ApiPromise,
collectionId: number,
- owner: string,
-) {
- return await usingApi(async (api) => {
- const response = (await api.query.nft.fungibleItemList(collectionId, owner)).toJSON() as unknown as { value: string };
- return BigInt(response.value);
- });
+): Promise<number> {
+ return (await api.rpc.nft.lastTokenId(collectionId)).toJSON();
}
+export async function getAdminList(
+ api: ApiPromise,
+ collectionId: number,
+): Promise<string[]> {
+ return (await api.rpc.nft.adminlist(collectionId)).toHuman() as any;
+}
+export async function getVariableMetadata(
+ api: ApiPromise,
+ collectionId: number,
+ tokenId: number,
+): Promise<number[]> {
+ return [...(await api.rpc.nft.variableMetadata(collectionId, tokenId))];
+}
+export async function getConstMetadata(
+ api: ApiPromise,
+ collectionId: number,
+ tokenId: number,
+): Promise<number[]> {
+ return [...(await api.rpc.nft.constMetadata(collectionId, tokenId))];
+}
export async function createFungibleItemExpectSuccess(
sender: IKeyringPair,
@@ -954,7 +983,7 @@
owner: CrossAccountId | string = sender.address,
) {
return await usingApi(async (api) => {
- const tx = api.tx.nft.createItem(collectionId, normalizeAccountId(owner), { Fungible: data });
+ const tx = api.tx.nft.createItem(collectionId, normalizeAccountId(owner), {Fungible: data});
const events = await submitTransactionAsync(sender, tx);
const result = getCreateItemResult(events);
@@ -968,39 +997,37 @@
let newItemId = 0;
await usingApi(async (api) => {
const to = normalizeAccountId(owner);
- const AItemCount = parseInt((await api.query.nft.itemListIndex(collectionId)).toString(), 10);
- const Aitem: any = (await api.query.nft.fungibleItemList(collectionId, toSubstrateAddress(to))).toJSON();
- const AItemBalance = new BigNumber(Aitem.value);
+ const itemCountBefore = await getLastTokenId(api, collectionId);
+ const itemBalanceBefore = await getBalance(api, collectionId, to, newItemId);
let tx;
if (createMode === 'Fungible') {
- const createData = { fungible: { value: 10 } };
- tx = api.tx.nft.createItem(collectionId, to, createData);
+ const createData = {fungible: {value: 10}};
+ tx = api.tx.nft.createItem(collectionId, to, createData as any);
} else if (createMode === 'ReFungible') {
- const createData = { refungible: { const_data: [], variable_data: [], pieces: 100 } };
- tx = api.tx.nft.createItem(collectionId, to, createData);
+ const createData = {refungible: {const_data: [], variable_data: [], pieces: 100}};
+ tx = api.tx.nft.createItem(collectionId, to, createData as any);
} else {
- const createData = { nft: { const_data: [], variable_data: [] } };
- tx = api.tx.nft.createItem(collectionId, to, createData);
+ const createData = {nft: {const_data: [], variable_data: []}};
+ tx = api.tx.nft.createItem(collectionId, to, createData as any);
}
const events = await submitTransactionAsync(sender, tx);
const result = getCreateItemResult(events);
- const BItemCount = parseInt((await api.query.nft.itemListIndex(collectionId)).toString(), 10);
- const Bitem: any = (await api.query.nft.fungibleItemList(collectionId, toSubstrateAddress(to))).toJSON();
- const BItemBalance = new BigNumber(Bitem.value);
+ const itemCountAfter = await getLastTokenId(api, collectionId);
+ const itemBalanceAfter = await getBalance(api, collectionId, to, newItemId);
// What to expect
// tslint:disable-next-line:no-unused-expression
expect(result.success).to.be.true;
if (createMode === 'Fungible') {
- expect(BItemBalance.minus(AItemBalance).toNumber()).to.be.equal(10);
+ expect(itemBalanceAfter - itemBalanceBefore).to.be.equal(10n);
} else {
- expect(BItemCount).to.be.equal(AItemCount + 1);
+ expect(itemCountAfter).to.be.equal(itemCountBefore + 1);
}
expect(collectionId).to.be.equal(result.collectionId);
- expect(BItemCount.toString()).to.be.equal(result.itemId.toString());
+ expect(itemCountAfter.toString()).to.be.equal(result.itemId.toString());
expect(to).to.be.deep.equal(result.recipient);
newItemId = result.itemId;
});
@@ -1030,12 +1057,12 @@
const result = getGenericResult(events);
// Get the collection
- const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
+ const collection = (await api.query.common.collectionById(collectionId)).unwrap();
// What to expect
// tslint:disable-next-line:no-unused-expression
expect(result.success).to.be.true;
- expect(collection.access).to.be.equal(accessMode);
+ expect(collection.access.toHuman()).to.be.equal(accessMode);
});
}
@@ -1075,14 +1102,12 @@
const tx = api.tx.nft.setMintPermission(collectionId, enabled);
const events = await submitTransactionAsync(sender, tx);
const result = getGenericResult(events);
+ expect(result.success).to.be.true;
// Get the collection
- const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
+ const collection = (await api.query.common.collectionById(collectionId)).unwrap();
- // What to expect
- // tslint:disable-next-line:no-unused-expression
- expect(result.success).to.be.true;
- expect(collection.mintMode).to.be.equal(enabled);
+ expect(collection.mintMode.toHuman()).to.be.equal(enabled);
});
}
@@ -1112,55 +1137,38 @@
});
}
-export async function isWhitelisted(collectionId: number, address: string) {
- let whitelisted = false;
- await usingApi(async (api) => {
- whitelisted = (await api.query.nft.whiteList(collectionId, address)).toJSON() as unknown as boolean;
+export async function isWhitelisted(collectionId: number, address: string | CrossAccountId) {
+ return await usingApi(async (api) => {
+ return (await api.query.common.allowlist(collectionId, normalizeAccountId(address))).toJSON();
});
- return whitelisted;
}
-export async function addToWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number, address: string | AccountId) {
+export async function addToWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number, address: string | AccountId | CrossAccountId) {
await usingApi(async (api) => {
+ expect(await isWhitelisted(collectionId, normalizeAccountId(address))).to.be.false;
- const whiteListedBefore = (await api.query.nft.whiteList(collectionId, address)).toJSON();
-
// Run the transaction
const tx = api.tx.nft.addToWhiteList(collectionId, normalizeAccountId(address));
const events = await submitTransactionAsync(sender, tx);
const result = getGenericResult(events);
-
- const whiteListedAfter = (await api.query.nft.whiteList(collectionId, address)).toJSON();
+ expect(result.success).to.be.true;
- // What to expect
- // tslint:disable-next-line:no-unused-expression
- expect(result.success).to.be.true;
- // tslint:disable-next-line: no-unused-expression
- expect(whiteListedBefore).to.be.false;
- // tslint:disable-next-line: no-unused-expression
- expect(whiteListedAfter).to.be.true;
+ expect(await isWhitelisted(collectionId, normalizeAccountId(address))).to.be.true;
});
}
export async function addToWhiteListAgainExpectSuccess(sender: IKeyringPair, collectionId: number, address: string | AccountId) {
await usingApi(async (api) => {
- const whiteListedBefore = (await api.query.nft.whiteList(collectionId, address)).toJSON();
+ expect(await isWhitelisted(collectionId, normalizeAccountId(address))).to.be.true;
// Run the transaction
const tx = api.tx.nft.addToWhiteList(collectionId, normalizeAccountId(address));
const events = await submitTransactionAsync(sender, tx);
const result = getGenericResult(events);
-
- const whiteListedAfter = (await api.query.nft.whiteList(collectionId, address)).toJSON();
+ expect(result.success).to.be.true;
- // What to expect
- // tslint:disable-next-line:no-unused-expression
- expect(result.success).to.be.true;
- // tslint:disable-next-line: no-unused-expression
- expect(whiteListedBefore).to.be.true;
- // tslint:disable-next-line: no-unused-expression
- expect(whiteListedAfter).to.be.true;
+ expect(await isWhitelisted(collectionId, normalizeAccountId(address))).to.be.true;
});
}
@@ -1205,23 +1213,17 @@
}
export const getDetailedCollectionInfo = async (api: ApiPromise, collectionId: number)
- : Promise<ICollectionInterface | null> => {
- return (await api.query.nft.collectionById(collectionId)).toJSON() as unknown as ICollectionInterface;
+ : Promise<NftDataStructsCollection | null> => {
+ return (await api.query.common.collectionById(collectionId)).unwrapOr(null);
};
export const getCreatedCollectionCount = async (api: ApiPromise): Promise<number> => {
// set global object - collectionsCount
- return (await api.query.nft.createdCollectionCount() as unknown as BN).toNumber();
+ return (await api.query.common.createdCollectionCount()).toNumber();
};
-export async function queryCollectionExpectSuccess(collectionId: number): Promise<ICollectionInterface> {
- return await usingApi(async (api) => {
- return (await api.query.nft.collectionById(collectionId)).toJSON() as unknown as ICollectionInterface;
- });
-}
-
-export async function queryNftOwner(api: ApiPromise, collectionId: number, tokenId: number): Promise<CrossAccountId> {
- return normalizeAccountId((await api.query.nft.nftItemList(collectionId, tokenId) as any).toJSON().owner);
+export async function queryCollectionExpectSuccess(api: ApiPromise, collectionId: number): Promise<NftDataStructsCollection> {
+ return (await api.query.common.collectionById(collectionId)).unwrap();
}
export async function waitNewBlocks(blocksCount = 1): Promise<void> {
tests/src/whiteLists.test.tsdiffbeforeafterboth--- a/tests/src/whiteLists.test.ts
+++ b/tests/src/whiteLists.test.ts
@@ -3,11 +3,11 @@
// file 'LICENSE', which is part of this source code package.
//
-import { IKeyringPair } from '@polkadot/types/types';
+import {IKeyringPair} from '@polkadot/types/types';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import privateKey from './substrate/privateKey';
-import usingApi, { submitTransactionExpectFailAsync } from './substrate/substrate-api';
+import usingApi, {submitTransactionExpectFailAsync} from './substrate/substrate-api';
import {
addToWhiteListExpectSuccess,
createCollectionExpectSuccess,
@@ -32,276 +32,273 @@
chai.use(chaiAsPromised);
const expect = chai.expect;
-let Alice: IKeyringPair;
-let Bob: IKeyringPair;
-let Charlie: IKeyringPair;
+let alice: IKeyringPair;
+let bob: IKeyringPair;
+let charlie: IKeyringPair;
describe('Integration Test ext. White list tests', () => {
before(async () => {
await usingApi(async () => {
- Alice = privateKey('//Alice');
- Bob = privateKey('//Bob');
- Charlie = privateKey('//Charlie');
+ alice = privateKey('//Alice');
+ bob = privateKey('//Bob');
+ charlie = privateKey('//Charlie');
});
});
it('Owner can add address to white list', async () => {
const collectionId = await createCollectionExpectSuccess();
- await addToWhiteListExpectSuccess(Alice, collectionId, Bob.address);
+ await addToWhiteListExpectSuccess(alice, collectionId, bob.address);
});
it('Admin can add address to white list', async () => {
const collectionId = await createCollectionExpectSuccess();
- await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);
- await addToWhiteListExpectSuccess(Bob, collectionId, Charlie.address);
+ await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
+ await addToWhiteListExpectSuccess(bob, collectionId, charlie.address);
});
it('Non-privileged user cannot add address to white list', async () => {
const collectionId = await createCollectionExpectSuccess();
- await addToWhiteListExpectFail(Bob, collectionId, Charlie.address);
+ await addToWhiteListExpectFail(bob, collectionId, charlie.address);
});
it('Nobody can add address to white list of non-existing collection', async () => {
const collectionId = (1<<32) - 1;
- await addToWhiteListExpectFail(Alice, collectionId, Bob.address);
+ await addToWhiteListExpectFail(alice, collectionId, bob.address);
});
it('Nobody can add address to white list of destroyed collection', async () => {
const collectionId = await createCollectionExpectSuccess();
await destroyCollectionExpectSuccess(collectionId, '//Alice');
- await addToWhiteListExpectFail(Alice, collectionId, Bob.address);
+ await addToWhiteListExpectFail(alice, collectionId, bob.address);
});
it('If address is already added to white list, nothing happens', async () => {
const collectionId = await createCollectionExpectSuccess();
- await addToWhiteListExpectSuccess(Alice, collectionId, Bob.address);
- await addToWhiteListAgainExpectSuccess(Alice, collectionId, Bob.address);
+ await addToWhiteListExpectSuccess(alice, collectionId, bob.address);
+ await addToWhiteListAgainExpectSuccess(alice, collectionId, bob.address);
});
it('Owner can remove address from white list', async () => {
const collectionId = await createCollectionExpectSuccess();
- await addToWhiteListExpectSuccess(Alice, collectionId, Bob.address);
- await removeFromWhiteListExpectSuccess(Alice, collectionId, normalizeAccountId(Bob));
- });
+ await addToWhiteListExpectSuccess(alice, collectionId, bob.address);
+ await removeFromWhiteListExpectSuccess(alice, collectionId, normalizeAccountId(bob));
+ });
it('Admin can remove address from white list', async () => {
const collectionId = await createCollectionExpectSuccess();
- await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);
- await addToWhiteListExpectSuccess(Alice, collectionId, Charlie.address);
- await removeFromWhiteListExpectSuccess(Bob, collectionId, normalizeAccountId(Charlie));
- });
+ await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
+ await addToWhiteListExpectSuccess(alice, collectionId, charlie.address);
+ await removeFromWhiteListExpectSuccess(bob, collectionId, normalizeAccountId(charlie));
+ });
it('Non-privileged user cannot remove address from white list', async () => {
const collectionId = await createCollectionExpectSuccess();
- await addToWhiteListExpectSuccess(Alice, collectionId, Charlie.address);
- await removeFromWhiteListExpectFailure(Bob, collectionId, normalizeAccountId(Charlie));
- });
+ await addToWhiteListExpectSuccess(alice, collectionId, charlie.address);
+ await removeFromWhiteListExpectFailure(bob, collectionId, normalizeAccountId(charlie));
+ });
it('Nobody can remove address from white list of non-existing collection', async () => {
const collectionId = (1<<32) - 1;
- await removeFromWhiteListExpectFailure(Alice, collectionId, normalizeAccountId(Charlie));
- });
-
+ await removeFromWhiteListExpectFailure(alice, collectionId, normalizeAccountId(charlie));
+ });
-
it('Nobody can remove address from white list of deleted collection', async () => {
const collectionId = await createCollectionExpectSuccess();
- await addToWhiteListExpectSuccess(Alice, collectionId, Charlie.address);
+ await addToWhiteListExpectSuccess(alice, collectionId, charlie.address);
await destroyCollectionExpectSuccess(collectionId, '//Alice');
- await removeFromWhiteListExpectFailure(Alice, collectionId, normalizeAccountId(Charlie));
- });
+ await removeFromWhiteListExpectFailure(alice, collectionId, normalizeAccountId(charlie));
+ });
it('If address is already removed from white list, nothing happens', async () => {
const collectionId = await createCollectionExpectSuccess();
- await addToWhiteListExpectSuccess(Alice, collectionId, Charlie.address);
- await removeFromWhiteListExpectSuccess(Alice, collectionId, normalizeAccountId(Charlie));
- await removeFromWhiteListExpectSuccess(Alice, collectionId, normalizeAccountId(Charlie));
- });
+ await addToWhiteListExpectSuccess(alice, collectionId, charlie.address);
+ await removeFromWhiteListExpectSuccess(alice, collectionId, normalizeAccountId(charlie));
+ await removeFromWhiteListExpectSuccess(alice, collectionId, normalizeAccountId(charlie));
+ });
it('If Public Access mode is set to WhiteList, tokens can’t be transferred from a non-whitelisted address with transfer or transferFrom. Test1', async () => {
const collectionId = await createCollectionExpectSuccess();
- const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Alice.address);
- await enableWhiteListExpectSuccess(Alice, collectionId);
- await addToWhiteListExpectSuccess(Alice, collectionId, Charlie.address);
+ const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
+ await enableWhiteListExpectSuccess(alice, collectionId);
+ await addToWhiteListExpectSuccess(alice, collectionId, charlie.address);
await transferExpectFailure(
collectionId,
itemId,
- Alice,
- Charlie,
+ alice,
+ charlie,
1,
);
- });
+ });
it('If Public Access mode is set to WhiteList, tokens can’t be transferred from a non-whitelisted address with transfer or transferFrom. Test2', async () => {
const collectionId = await createCollectionExpectSuccess();
- const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Alice.address);
- await enableWhiteListExpectSuccess(Alice, collectionId);
- await addToWhiteListExpectSuccess(Alice, collectionId, Alice.address);
- await addToWhiteListExpectSuccess(Alice, collectionId, Charlie.address);
- await approveExpectSuccess(collectionId, itemId, Alice, Charlie);
- await removeFromWhiteListExpectSuccess(Alice, collectionId, normalizeAccountId(Alice));
+ const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
+ await enableWhiteListExpectSuccess(alice, collectionId);
+ await addToWhiteListExpectSuccess(alice, collectionId, alice.address);
+ await addToWhiteListExpectSuccess(alice, collectionId, charlie.address);
+ await approveExpectSuccess(collectionId, itemId, alice, charlie.address);
+ await removeFromWhiteListExpectSuccess(alice, collectionId, normalizeAccountId(alice));
await transferExpectFailure(
collectionId,
itemId,
- Alice,
- Charlie,
+ alice,
+ charlie,
1,
);
- });
+ });
it('If Public Access mode is set to WhiteList, tokens can’t be transferred to a non-whitelisted address with transfer or transferFrom. Test1', async () => {
const collectionId = await createCollectionExpectSuccess();
- const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Alice.address);
- await enableWhiteListExpectSuccess(Alice, collectionId);
- await addToWhiteListExpectSuccess(Alice, collectionId, Alice.address);
+ const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
+ await enableWhiteListExpectSuccess(alice, collectionId);
+ await addToWhiteListExpectSuccess(alice, collectionId, alice.address);
await transferExpectFailure(
collectionId,
itemId,
- Alice,
- Charlie,
+ alice,
+ charlie,
1,
);
- });
+ });
it('If Public Access mode is set to WhiteList, tokens can’t be transferred to a non-whitelisted address with transfer or transferFrom. Test2', async () => {
const collectionId = await createCollectionExpectSuccess();
- const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Alice.address);
- await enableWhiteListExpectSuccess(Alice, collectionId);
- await addToWhiteListExpectSuccess(Alice, collectionId, Alice.address);
- await addToWhiteListExpectSuccess(Alice, collectionId, Charlie.address);
- await approveExpectSuccess(collectionId, itemId, Alice, Charlie);
- await removeFromWhiteListExpectSuccess(Alice, collectionId, normalizeAccountId(Alice));
+ const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
+ await enableWhiteListExpectSuccess(alice, collectionId);
+ await addToWhiteListExpectSuccess(alice, collectionId, alice.address);
+ await addToWhiteListExpectSuccess(alice, collectionId, charlie.address);
+ await approveExpectSuccess(collectionId, itemId, alice, charlie.address);
+ await removeFromWhiteListExpectSuccess(alice, collectionId, normalizeAccountId(alice));
await transferExpectFailure(
collectionId,
itemId,
- Alice,
- Charlie,
+ alice,
+ charlie,
1,
);
- });
+ });
it('If Public Access mode is set to WhiteList, tokens can’t be destroyed by a non-whitelisted address (even if it owned them before enabling WhiteList mode)', async () => {
const collectionId = await createCollectionExpectSuccess();
- const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Alice.address);
- await enableWhiteListExpectSuccess(Alice, collectionId);
+ const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
+ await enableWhiteListExpectSuccess(alice, collectionId);
await usingApi(async (api) => {
const tx = api.tx.nft.burnItem(collectionId, itemId, /*normalizeAccountId(Alice.address),*/ 11);
- const badTransaction = async function () {
- await submitTransactionExpectFailAsync(Alice, tx);
+ const badTransaction = async function () {
+ await submitTransactionExpectFailAsync(alice, tx);
};
await expect(badTransaction()).to.be.rejected;
});
- });
-
+ });
+
it('If Public Access mode is set to WhiteList, token transfers can’t be Approved by a non-whitelisted address (see Approve method)', async () => {
const collectionId = await createCollectionExpectSuccess();
- const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Alice.address);
- await enableWhiteListExpectSuccess(Alice, collectionId);
- await approveExpectFail(collectionId, itemId, Alice, Bob);
- });
-
+ const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
+ await enableWhiteListExpectSuccess(alice, collectionId);
+ await approveExpectFail(collectionId, itemId, alice, bob);
+ });
+
it('If Public Access mode is set to WhiteList, tokens can be transferred to a whitelisted address with transfer.', async () => {
const collectionId = await createCollectionExpectSuccess();
- const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Alice.address);
- await enableWhiteListExpectSuccess(Alice, collectionId);
- await addToWhiteListExpectSuccess(Alice, collectionId, Alice.address);
- await addToWhiteListExpectSuccess(Alice, collectionId, Charlie.address);
- await transferExpectSuccess(collectionId, itemId, Alice, Charlie, 1, 'NFT');
- });
+ const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
+ await enableWhiteListExpectSuccess(alice, collectionId);
+ await addToWhiteListExpectSuccess(alice, collectionId, alice.address);
+ await addToWhiteListExpectSuccess(alice, collectionId, charlie.address);
+ await transferExpectSuccess(collectionId, itemId, alice, charlie, 1, 'NFT');
+ });
it('If Public Access mode is set to WhiteList, tokens can be transferred to a whitelisted address with transferFrom.', async () => {
const collectionId = await createCollectionExpectSuccess();
- const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Alice.address);
- await enableWhiteListExpectSuccess(Alice, collectionId);
- await addToWhiteListExpectSuccess(Alice, collectionId, Alice.address);
- await addToWhiteListExpectSuccess(Alice, collectionId, Charlie.address);
- await approveExpectSuccess(collectionId, itemId, Alice, Charlie);
- await transferFromExpectSuccess(collectionId, itemId, Alice, Alice, Charlie, 1, 'NFT');
+ const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
+ await enableWhiteListExpectSuccess(alice, collectionId);
+ await addToWhiteListExpectSuccess(alice, collectionId, alice.address);
+ await addToWhiteListExpectSuccess(alice, collectionId, charlie.address);
+ await approveExpectSuccess(collectionId, itemId, alice, charlie.address);
+ await transferFromExpectSuccess(collectionId, itemId, alice, alice, charlie, 1, 'NFT');
});
it('If Public Access mode is set to WhiteList, tokens can be transferred from a whitelisted address with transfer', async () => {
const collectionId = await createCollectionExpectSuccess();
- const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Alice.address);
- await enableWhiteListExpectSuccess(Alice, collectionId);
- await addToWhiteListExpectSuccess(Alice, collectionId, Alice.address);
- await addToWhiteListExpectSuccess(Alice, collectionId, Charlie.address);
- await transferExpectSuccess(collectionId, itemId, Alice, Charlie, 1, 'NFT');
+ const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
+ await enableWhiteListExpectSuccess(alice, collectionId);
+ await addToWhiteListExpectSuccess(alice, collectionId, alice.address);
+ await addToWhiteListExpectSuccess(alice, collectionId, charlie.address);
+ await transferExpectSuccess(collectionId, itemId, alice, charlie, 1, 'NFT');
});
it('If Public Access mode is set to WhiteList, tokens can be transferred from a whitelisted address with transferFrom', async () => {
const collectionId = await createCollectionExpectSuccess();
- const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Alice.address);
- await enableWhiteListExpectSuccess(Alice, collectionId);
- await addToWhiteListExpectSuccess(Alice, collectionId, Alice.address);
- await addToWhiteListExpectSuccess(Alice, collectionId, Charlie.address);
- await approveExpectSuccess(collectionId, itemId, Alice, Charlie);
- await transferFromExpectSuccess(collectionId, itemId, Alice, Alice, Charlie, 1, 'NFT');
+ const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
+ await enableWhiteListExpectSuccess(alice, collectionId);
+ await addToWhiteListExpectSuccess(alice, collectionId, alice.address);
+ await addToWhiteListExpectSuccess(alice, collectionId, charlie.address);
+ await approveExpectSuccess(collectionId, itemId, alice, charlie.address);
+ await transferFromExpectSuccess(collectionId, itemId, alice, alice, charlie, 1, 'NFT');
});
it('If Public Access mode is set to WhiteList, and Mint Permission is set to false, tokens can be created by owner', async () => {
const collectionId = await createCollectionExpectSuccess();
- await enableWhiteListExpectSuccess(Alice, collectionId);
- await setMintPermissionExpectSuccess(Alice, collectionId, false);
- await createItemExpectSuccess(Alice, collectionId, 'NFT', Alice.address);
+ await enableWhiteListExpectSuccess(alice, collectionId);
+ await setMintPermissionExpectSuccess(alice, collectionId, false);
+ await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
});
it('If Public Access mode is set to WhiteList, and Mint Permission is set to false, tokens can be created by admin', async () => {
const collectionId = await createCollectionExpectSuccess();
- await enableWhiteListExpectSuccess(Alice, collectionId);
- await setMintPermissionExpectSuccess(Alice, collectionId, false);
- await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);
- await createItemExpectSuccess(Bob, collectionId, 'NFT', Bob.address);
+ await enableWhiteListExpectSuccess(alice, collectionId);
+ await setMintPermissionExpectSuccess(alice, collectionId, false);
+ await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
+ await createItemExpectSuccess(bob, collectionId, 'NFT', bob.address);
});
it('If Public Access mode is set to WhiteList, and Mint Permission is set to false, tokens cannot be created by non-privileged and white-listed address', async () => {
const collectionId = await createCollectionExpectSuccess();
- await enableWhiteListExpectSuccess(Alice, collectionId);
- await setMintPermissionExpectSuccess(Alice, collectionId, false);
- await addToWhiteListExpectSuccess(Alice, collectionId, Bob.address);
- await createItemExpectFailure(Bob, collectionId, 'NFT', Bob.address);
+ await enableWhiteListExpectSuccess(alice, collectionId);
+ await setMintPermissionExpectSuccess(alice, collectionId, false);
+ await addToWhiteListExpectSuccess(alice, collectionId, bob.address);
+ await createItemExpectFailure(bob, collectionId, 'NFT', bob.address);
});
it('If Public Access mode is set to WhiteList, and Mint Permission is set to false, tokens cannot be created by non-privileged and non-white listed address', async () => {
const collectionId = await createCollectionExpectSuccess();
- await enableWhiteListExpectSuccess(Alice, collectionId);
- await setMintPermissionExpectSuccess(Alice, collectionId, false);
- await createItemExpectFailure(Bob, collectionId, 'NFT', Bob.address);
+ await enableWhiteListExpectSuccess(alice, collectionId);
+ await setMintPermissionExpectSuccess(alice, collectionId, false);
+ await createItemExpectFailure(bob, collectionId, 'NFT', bob.address);
});
it('If Public Access mode is set to WhiteList, and Mint Permission is set to true, tokens can be created by owner', async () => {
const collectionId = await createCollectionExpectSuccess();
- await enableWhiteListExpectSuccess(Alice, collectionId);
- await setMintPermissionExpectSuccess(Alice, collectionId, true);
- await createItemExpectSuccess(Alice, collectionId, 'NFT', Alice.address);
- });
+ await enableWhiteListExpectSuccess(alice, collectionId);
+ await setMintPermissionExpectSuccess(alice, collectionId, true);
+ await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
+ });
it('If Public Access mode is set to WhiteList, and Mint Permission is set to true, tokens can be created by admin', async () => {
const collectionId = await createCollectionExpectSuccess();
- await enableWhiteListExpectSuccess(Alice, collectionId);
- await setMintPermissionExpectSuccess(Alice, collectionId, true);
- await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);
- await createItemExpectSuccess(Bob, collectionId, 'NFT', Bob.address);
+ await enableWhiteListExpectSuccess(alice, collectionId);
+ await setMintPermissionExpectSuccess(alice, collectionId, true);
+ await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
+ await createItemExpectSuccess(bob, collectionId, 'NFT', bob.address);
});
it('If Public Access mode is set to WhiteList, and Mint Permission is set to true, tokens cannot be created by non-privileged and non-white listed address', async () => {
const collectionId = await createCollectionExpectSuccess();
- await enableWhiteListExpectSuccess(Alice, collectionId);
- await setMintPermissionExpectSuccess(Alice, collectionId, true);
- await createItemExpectFailure(Bob, collectionId, 'NFT', Bob.address);
+ await enableWhiteListExpectSuccess(alice, collectionId);
+ await setMintPermissionExpectSuccess(alice, collectionId, true);
+ await createItemExpectFailure(bob, collectionId, 'NFT', bob.address);
});
it('If Public Access mode is set to WhiteList, and Mint Permission is set to true, tokens can be created by non-privileged and white listed address', async () => {
const collectionId = await createCollectionExpectSuccess();
- await enableWhiteListExpectSuccess(Alice, collectionId);
- await setMintPermissionExpectSuccess(Alice, collectionId, true);
- await addToWhiteListExpectSuccess(Alice, collectionId, Bob.address);
- await createItemExpectSuccess(Bob, collectionId, 'NFT', Bob.address);
+ await enableWhiteListExpectSuccess(alice, collectionId);
+ await setMintPermissionExpectSuccess(alice, collectionId, true);
+ await addToWhiteListExpectSuccess(alice, collectionId, bob.address);
+ await createItemExpectSuccess(bob, collectionId, 'NFT', bob.address);
});
});
-