difftreelog
Merge branch 'develop' into feature/multi-assets-redone
in: master
15 files changed
tests/package.jsondiffbeforeafterboth--- a/tests/package.json
+++ b/tests/package.json
@@ -30,6 +30,7 @@
"testEth": "mocha --timeout 9999999 -r ts-node/register './**/eth/**/*.test.ts'",
"testEthMarketplace": "mocha --timeout 9999999 -r ts-node/register './**/eth/marketplace/**/*.test.ts'",
"testEthNesting": "mocha --timeout 9999999 -r ts-node/register './**/eth/nesting/**/*.test.ts'",
+ "testEthPayable": "mocha --timeout 9999999 -r ts-node/register './**/eth/payable.test.ts'",
"load": "mocha --timeout 9999999 -r ts-node/register './**/*.load.ts'",
"loadTransfer": "ts-node src/transfer.nload.ts",
"testCollision": "mocha --timeout 9999999 -r ts-node/register ./src/collision-tests/*.test.ts",
@@ -84,7 +85,8 @@
"testBlockProduction": "mocha --timeout 9999999 -r ts-node/register ./**/block-production.test.ts",
"testEnableDisableTransfers": "mocha --timeout 9999999 -r ts-node/register ./**/enableDisableTransfer.test.ts",
"testLimits": "mocha --timeout 9999999 -r ts-node/register ./**/limits.test.ts",
- "testEthCreateCollection": "mocha --timeout 9999999 -r ts-node/register ./**/eth/createCollection.test.ts",
+ "testEthCreateNFTCollection": "mocha --timeout 9999999 -r ts-node/register ./**/eth/createNFTCollection.test.ts",
+ "testEthCreateRFTCollection": "mocha --timeout 9999999 -r ts-node/register ./**/eth/createRFTCollection.test.ts",
"testRFT": "mocha --timeout 9999999 -r ts-node/register ./**/refungible.test.ts",
"testFT": "mocha --timeout 9999999 -r ts-node/register ./**/fungible.test.ts",
"testRPC": "mocha --timeout 9999999 -r ts-node/register ./**/rpc.test.ts",
tests/src/eth/collectionAdmin.test.tsdiffbeforeafterboth--- a/tests/src/eth/collectionAdmin.test.ts
+++ b/tests/src/eth/collectionAdmin.test.ts
@@ -24,7 +24,6 @@
getCollectionAddressFromResult,
itWeb3,
recordEthFee,
- subToEth,
} from './util/helpers';
describe('Add collection admins', () => {
@@ -37,7 +36,7 @@
.send();
const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
- const newAdmin = await createEthAccount(web3);
+ const newAdmin = createEthAccount(web3);
const collectionEvm = evmCollection(web3, owner, collectionIdAddress);
await collectionEvm.methods.addCollectionAdmin(newAdmin).send();
const adminList = await api.rpc.unique.adminlist(collectionId);
@@ -92,7 +91,7 @@
const collectionEvm = evmCollection(web3, owner, collectionIdAddress);
await collectionEvm.methods.addCollectionAdmin(admin).send();
- const user = await createEthAccount(web3);
+ const user = createEthAccount(web3);
await expect(collectionEvm.methods.addCollectionAdmin(user).call({from: admin}))
.to.be.rejectedWith('NoPermission');
@@ -114,7 +113,7 @@
const notAdmin = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
const collectionEvm = evmCollection(web3, owner, collectionIdAddress);
- const user = await createEthAccount(web3);
+ const user = createEthAccount(web3);
await expect(collectionEvm.methods.addCollectionAdmin(user).call({from: notAdmin}))
.to.be.rejectedWith('NoPermission');
@@ -175,7 +174,7 @@
.send();
const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
- const newAdmin = await createEthAccount(web3);
+ const newAdmin = createEthAccount(web3);
const collectionEvm = evmCollection(web3, owner, collectionIdAddress);
await collectionEvm.methods.addCollectionAdmin(newAdmin).send();
{
@@ -226,7 +225,7 @@
const admin0 = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
await collectionEvm.methods.addCollectionAdmin(admin0).send();
- const admin1 = await createEthAccount(web3);
+ const admin1 = createEthAccount(web3);
await collectionEvm.methods.addCollectionAdmin(admin1).send();
await expect(collectionEvm.methods.removeCollectionAdmin(admin1).call({from: admin0}))
@@ -253,7 +252,7 @@
const admin = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
await collectionEvm.methods.addCollectionAdmin(admin).send();
- const notAdmin = await createEthAccount(web3);
+ const notAdmin = createEthAccount(web3);
await expect(collectionEvm.methods.removeCollectionAdmin(admin).call({from: notAdmin}))
.to.be.rejectedWith('NoPermission');
tests/src/eth/collectionSponsoring.test.tsdiffbeforeafterboth--- a/tests/src/eth/collectionSponsoring.test.ts
+++ b/tests/src/eth/collectionSponsoring.test.ts
@@ -1,5 +1,5 @@
import {addToAllowListExpectSuccess, bigIntToSub, confirmSponsorshipExpectSuccess, createCollectionExpectSuccess, enablePublicMintingExpectSuccess, getDetailedCollectionInfo, setCollectionSponsorExpectSuccess} from '../util/helpers';
-import {itWeb3, createEthAccount, collectionIdToAddress, GAS_ARGS, normalizeEvents, createEthAccountWithBalance, evmCollectionHelpers, getCollectionAddressFromResult, evmCollection, ethBalanceViaSub, subToEth} from './util/helpers';
+import {itWeb3, createEthAccount, collectionIdToAddress, GAS_ARGS, normalizeEvents, createEthAccountWithBalance, evmCollectionHelpers, getCollectionAddressFromResult, evmCollection, ethBalanceViaSub} from './util/helpers';
import nonFungibleAbi from './nonFungibleAbi.json';
import {expect} from 'chai';
import {evmToAddress} from '@polkadot/util-crypto';
tests/src/eth/createNFTCollection.test.tsdiffbeforeafterboth--- a/tests/src/eth/createNFTCollection.test.ts
+++ b/tests/src/eth/createNFTCollection.test.ts
@@ -181,7 +181,7 @@
});
itWeb3('(!negative test!) Create collection (no funds)', async ({web3}) => {
- const owner = await createEthAccount(web3);
+ const owner = createEthAccount(web3);
const helper = evmCollectionHelpers(web3, owner);
const collectionName = 'A';
const description = 'A';
@@ -194,7 +194,7 @@
itWeb3('(!negative test!) Check owner', async ({api, web3, privateKeyWrapper}) => {
const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const notOwner = await createEthAccount(web3);
+ const notOwner = createEthAccount(web3);
const collectionHelpers = evmCollectionHelpers(web3, owner);
const result = await collectionHelpers.methods.createNonfungibleCollection('A', 'A', 'A').send();
const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);
tests/src/eth/createRFTCollection.test.tsdiffbeforeafterboth--- a/tests/src/eth/createRFTCollection.test.ts
+++ b/tests/src/eth/createRFTCollection.test.ts
@@ -189,7 +189,7 @@
});
itWeb3('(!negative test!) Create collection (no funds)', async ({web3}) => {
- const owner = await createEthAccount(web3);
+ const owner = createEthAccount(web3);
const helper = evmCollectionHelpers(web3, owner);
const collectionName = 'A';
const description = 'A';
@@ -202,7 +202,7 @@
itWeb3('(!negative test!) Check owner', async ({api, web3, privateKeyWrapper}) => {
const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const notOwner = await createEthAccount(web3);
+ const notOwner = createEthAccount(web3);
const collectionHelpers = evmCollectionHelpers(web3, owner);
const result = await collectionHelpers.methods.createRefungibleCollection('A', 'A', 'A').send();
const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);
tests/src/eth/nesting/nest.test.tsdiffbeforeafterboth--- a/tests/src/eth/nesting/nest.test.ts
+++ b/tests/src/eth/nesting/nest.test.ts
@@ -1,217 +1,220 @@
-import {ApiPromise} from '@polkadot/api';
+import {IKeyringPair} from '@polkadot/types/types';
import {Contract} from 'web3-eth-contract';
-import {expect} from 'chai';
-import Web3 from 'web3';
-import {createEthAccountWithBalance, evmCollectionHelpers, GAS_ARGS, getCollectionAddressFromResult, itWeb3, tokenIdToAddress} from '../../eth/util/helpers';
-import nonFungibleAbi from '../nonFungibleAbi.json';
+import {itEth, EthUniqueHelper, usingEthPlaygrounds, expect} from '../util/playgrounds';
+
const createNestingCollection = async (
- api: ApiPromise,
- web3: Web3,
+ helper: EthUniqueHelper,
owner: string,
): Promise<{ collectionId: number, collectionAddress: string, contract: Contract }> => {
- const collectionHelper = evmCollectionHelpers(web3, owner);
-
- const result = await collectionHelper.methods
- .createNonfungibleCollection('A', 'B', 'C')
- .send();
- const {collectionIdAddress: collectionAddress, collectionId} = await getCollectionAddressFromResult(api, result);
+ const {collectionAddress, collectionId} = await helper.eth.createNonfungibleCollection(owner, 'A', 'B', 'C');
- const contract = new web3.eth.Contract(nonFungibleAbi as any, collectionAddress, {from: owner, ...GAS_ARGS});
+ const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
await contract.methods.setCollectionNesting(true).send({from: owner});
return {collectionId, collectionAddress, contract};
};
-describe('Integration Test: EVM Nesting', () => {
- itWeb3('NFT: allows an Owner to nest/unnest their token', async ({api, web3, privateKeyWrapper}) => {
- const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const {collectionId, contract} = await createNestingCollection(api, web3, owner);
- // Create a token to be nested
- const targetNFTTokenId = await contract.methods.nextTokenId().call();
- await contract.methods.mint(
- owner,
- targetNFTTokenId,
- ).send({from: owner});
-
- const targetNftTokenAddress = tokenIdToAddress(collectionId, targetNFTTokenId);
-
- // Create a nested token
- const firstTokenId = await contract.methods.nextTokenId().call();
- await contract.methods.mint(
- targetNftTokenAddress,
- firstTokenId,
- ).send({from: owner});
+describe('EVM nesting tests group', () => {
+ let donor: IKeyringPair;
- expect(await contract.methods.ownerOf(firstTokenId).call()).to.be.equal(targetNftTokenAddress);
-
- // Create a token to be nested and nest
- const secondTokenId = await contract.methods.nextTokenId().call();
- await contract.methods.mint(
- owner,
- secondTokenId,
- ).send({from: owner});
-
- await contract.methods.transfer(targetNftTokenAddress, secondTokenId).send({from: owner});
-
- expect(await contract.methods.ownerOf(secondTokenId).call()).to.be.equal(targetNftTokenAddress);
-
- // Unnest token back
- await contract.methods.transferFrom(targetNftTokenAddress, owner, secondTokenId).send({from: owner});
- expect(await contract.methods.ownerOf(secondTokenId).call()).to.be.equal(owner);
+ before(async function() {
+ await usingEthPlaygrounds(async (helper, privateKey) => {
+ donor = privateKey('//Alice');
+ });
});
- itWeb3('NFT: allows an Owner to nest/unnest their token (Restricted nesting)', async ({api, web3, privateKeyWrapper}) => {
- const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
-
- const {collectionId: collectionIdA, collectionAddress: collectionAddressA, contract: contractA} = await createNestingCollection(api, web3, owner);
- const {collectionAddress: collectionAddressB, contract: contractB} = await createNestingCollection(api, web3, owner);
- await contractA.methods.setCollectionNesting(true, [collectionAddressA, collectionAddressB]).send({from: owner});
-
- // Create a token to nest into
- const targetNftTokenId = await contractA.methods.nextTokenId().call();
- await contractA.methods.mint(
- owner,
- targetNftTokenId,
- ).send({from: owner});
- const nftTokenAddressA1 = tokenIdToAddress(collectionIdA, targetNftTokenId);
-
- // Create a token for nesting in the same collection as the target
- const nftTokenIdA = await contractA.methods.nextTokenId().call();
- await contractA.methods.mint(
- owner,
- nftTokenIdA,
- ).send({from: owner});
-
- // Create a token for nesting in a different collection
- const nftTokenIdB = await contractB.methods.nextTokenId().call();
- await contractB.methods.mint(
- owner,
- nftTokenIdB,
- ).send({from: owner});
-
- // Nest
- await contractA.methods.transfer(nftTokenAddressA1, nftTokenIdA).send({from: owner});
- expect(await contractA.methods.ownerOf(nftTokenIdA).call()).to.be.equal(nftTokenAddressA1);
-
- await contractB.methods.transfer(nftTokenAddressA1, nftTokenIdB).send({from: owner});
- expect(await contractB.methods.ownerOf(nftTokenIdB).call()).to.be.equal(nftTokenAddressA1);
- });
-});
-
-describe('Negative Test: EVM Nesting', async() => {
- itWeb3('NFT: disallows to nest token if nesting is disabled', async ({api, web3, privateKeyWrapper}) => {
- const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
-
- const {collectionId, contract} = await createNestingCollection(api, web3, owner);
- await contract.methods.setCollectionNesting(false).send({from: owner});
-
- // Create a token to nest into
- const targetNftTokenId = await contract.methods.nextTokenId().call();
- await contract.methods.mint(
- owner,
- targetNftTokenId,
- ).send({from: owner});
-
- const targetNftTokenAddress = tokenIdToAddress(collectionId, targetNftTokenId);
-
- // Create a token to nest
- const nftTokenId = await contract.methods.nextTokenId().call();
- await contract.methods.mint(
- owner,
- nftTokenId,
- ).send({from: owner});
-
- // Try to nest
- await expect(contract.methods
- .transfer(targetNftTokenAddress, nftTokenId)
- .call({from: owner})).to.be.rejectedWith('UserIsNotAllowedToNest');
- });
-
- itWeb3('NFT: disallows a non-Owner to nest someone else\'s token', async ({api, web3, privateKeyWrapper}) => {
- const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const malignant = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
-
- const {collectionId, contract} = await createNestingCollection(api, web3, owner);
-
- // Mint a token
- const targetTokenId = await contract.methods.nextTokenId().call();
- await contract.methods.mint(
- owner,
- targetTokenId,
- ).send({from: owner});
- const targetTokenAddress = tokenIdToAddress(collectionId, targetTokenId);
-
- // Mint a token belonging to a different account
- const tokenId = await contract.methods.nextTokenId().call();
- await contract.methods.mint(
- malignant,
- tokenId,
- ).send({from: owner});
-
- // Try to nest one token in another as a non-owner account
- await expect(contract.methods
- .transfer(targetTokenAddress, tokenId)
- .call({from: malignant})).to.be.rejectedWith('UserIsNotAllowedToNest');
- });
-
- itWeb3('NFT: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async ({api, web3, privateKeyWrapper}) => {
- const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const malignant = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
-
- const {collectionId: collectionIdA, collectionAddress: collectionAddressA, contract: contractA} = await createNestingCollection(api, web3, owner);
- const {collectionAddress: collectionAddressB, contract: contractB} = await createNestingCollection(api, web3, owner);
-
- await contractA.methods.setCollectionNesting(true, [collectionAddressA, collectionAddressB]).send({from: owner});
-
- // Create a token in one collection
- const nftTokenIdA = await contractA.methods.nextTokenId().call();
- await contractA.methods.mint(
- owner,
- nftTokenIdA,
- ).send({from: owner});
- const nftTokenAddressA = tokenIdToAddress(collectionIdA, nftTokenIdA);
-
- // Create a token in another collection belonging to someone else
- const nftTokenIdB = await contractB.methods.nextTokenId().call();
- await contractB.methods.mint(
- malignant,
- nftTokenIdB,
- ).send({from: owner});
-
- // Try to drag someone else's token into the other collection and nest
- await expect(contractB.methods
- .transfer(nftTokenAddressA, nftTokenIdB)
- .call({from: malignant})).to.be.rejectedWith('UserIsNotAllowedToNest');
+ describe('Integration Test: EVM Nesting', () => {
+ itEth('NFT: allows an Owner to nest/unnest their token', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const {collectionId, contract} = await createNestingCollection(helper, owner);
+
+ // Create a token to be nested
+ const targetNFTTokenId = await contract.methods.nextTokenId().call();
+ await contract.methods.mint(
+ owner,
+ targetNFTTokenId,
+ ).send({from: owner});
+
+ const targetNftTokenAddress = helper.ethAddress.fromTokenId(collectionId, targetNFTTokenId);
+
+ // Create a nested token
+ const firstTokenId = await contract.methods.nextTokenId().call();
+ await contract.methods.mint(
+ targetNftTokenAddress,
+ firstTokenId,
+ ).send({from: owner});
+
+ expect(await contract.methods.ownerOf(firstTokenId).call()).to.be.equal(targetNftTokenAddress);
+
+ // Create a token to be nested and nest
+ const secondTokenId = await contract.methods.nextTokenId().call();
+ await contract.methods.mint(
+ owner,
+ secondTokenId,
+ ).send({from: owner});
+
+ await contract.methods.transfer(targetNftTokenAddress, secondTokenId).send({from: owner});
+
+ expect(await contract.methods.ownerOf(secondTokenId).call()).to.be.equal(targetNftTokenAddress);
+
+ // Unnest token back
+ await contract.methods.transferFrom(targetNftTokenAddress, owner, secondTokenId).send({from: owner});
+ expect(await contract.methods.ownerOf(secondTokenId).call()).to.be.equal(owner);
+ });
+
+ itEth('NFT: allows an Owner to nest/unnest their token (Restricted nesting)', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+
+ const {collectionId: collectionIdA, collectionAddress: collectionAddressA, contract: contractA} = await createNestingCollection(helper, owner);
+ const {collectionAddress: collectionAddressB, contract: contractB} = await createNestingCollection(helper, owner);
+ await contractA.methods.setCollectionNesting(true, [collectionAddressA, collectionAddressB]).send({from: owner});
+
+ // Create a token to nest into
+ const targetNftTokenId = await contractA.methods.nextTokenId().call();
+ await contractA.methods.mint(
+ owner,
+ targetNftTokenId,
+ ).send({from: owner});
+ const nftTokenAddressA1 = helper.ethAddress.fromTokenId(collectionIdA, targetNftTokenId);
+
+ // Create a token for nesting in the same collection as the target
+ const nftTokenIdA = await contractA.methods.nextTokenId().call();
+ await contractA.methods.mint(
+ owner,
+ nftTokenIdA,
+ ).send({from: owner});
+
+ // Create a token for nesting in a different collection
+ const nftTokenIdB = await contractB.methods.nextTokenId().call();
+ await contractB.methods.mint(
+ owner,
+ nftTokenIdB,
+ ).send({from: owner});
+
+ // Nest
+ await contractA.methods.transfer(nftTokenAddressA1, nftTokenIdA).send({from: owner});
+ expect(await contractA.methods.ownerOf(nftTokenIdA).call()).to.be.equal(nftTokenAddressA1);
+
+ await contractB.methods.transfer(nftTokenAddressA1, nftTokenIdB).send({from: owner});
+ expect(await contractB.methods.ownerOf(nftTokenIdB).call()).to.be.equal(nftTokenAddressA1);
+ });
});
- itWeb3('NFT: disallows to nest token in an unlisted collection', async ({api, web3, privateKeyWrapper}) => {
- const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
-
- const {collectionId: collectionIdA, collectionAddress: collectionAddressA, contract: contractA} = await createNestingCollection(api, web3, owner);
- const {contract: contractB} = await createNestingCollection(api, web3, owner);
-
- await contractA.methods.setCollectionNesting(true, [collectionAddressA]).send({from: owner});
-
- // Create a token in one collection
- const nftTokenIdA = await contractA.methods.nextTokenId().call();
- await contractA.methods.mint(
- owner,
- nftTokenIdA,
- ).send({from: owner});
- const nftTokenAddressA = tokenIdToAddress(collectionIdA, nftTokenIdA);
-
- // Create a token in another collection
- const nftTokenIdB = await contractB.methods.nextTokenId().call();
- await contractB.methods.mint(
- owner,
- nftTokenIdB,
- ).send({from: owner});
-
- // Try to nest into a token in the other collection, disallowed in the first
- await expect(contractB.methods
- .transfer(nftTokenAddressA, nftTokenIdB)
- .call()).to.be.rejectedWith('SourceCollectionIsNotAllowedToNest');
+ describe('Negative Test: EVM Nesting', async() => {
+ itEth('NFT: disallows to nest token if nesting is disabled', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+
+ const {collectionId, contract} = await createNestingCollection(helper, owner);
+ await contract.methods.setCollectionNesting(false).send({from: owner});
+
+ // Create a token to nest into
+ const targetNftTokenId = await contract.methods.nextTokenId().call();
+ await contract.methods.mint(
+ owner,
+ targetNftTokenId,
+ ).send({from: owner});
+
+ const targetNftTokenAddress = helper.ethAddress.fromTokenId(collectionId, targetNftTokenId);
+
+ // Create a token to nest
+ const nftTokenId = await contract.methods.nextTokenId().call();
+ await contract.methods.mint(
+ owner,
+ nftTokenId,
+ ).send({from: owner});
+
+ // Try to nest
+ await expect(contract.methods
+ .transfer(targetNftTokenAddress, nftTokenId)
+ .call({from: owner})).to.be.rejectedWith('UserIsNotAllowedToNest');
+ });
+
+ itEth('NFT: disallows a non-Owner to nest someone else\'s token', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const malignant = await helper.eth.createAccountWithBalance(donor);
+
+ const {collectionId, contract} = await createNestingCollection(helper, owner);
+
+ // Mint a token
+ const targetTokenId = await contract.methods.nextTokenId().call();
+ await contract.methods.mint(
+ owner,
+ targetTokenId,
+ ).send({from: owner});
+ const targetTokenAddress = helper.ethAddress.fromTokenId(collectionId, targetTokenId);
+
+ // Mint a token belonging to a different account
+ const tokenId = await contract.methods.nextTokenId().call();
+ await contract.methods.mint(
+ malignant,
+ tokenId,
+ ).send({from: owner});
+
+ // Try to nest one token in another as a non-owner account
+ await expect(contract.methods
+ .transfer(targetTokenAddress, tokenId)
+ .call({from: malignant})).to.be.rejectedWith('UserIsNotAllowedToNest');
+ });
+
+ itEth('NFT: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const malignant = await helper.eth.createAccountWithBalance(donor);
+
+ const {collectionId: collectionIdA, collectionAddress: collectionAddressA, contract: contractA} = await createNestingCollection(helper, owner);
+ const {collectionAddress: collectionAddressB, contract: contractB} = await createNestingCollection(helper, owner);
+
+ await contractA.methods.setCollectionNesting(true, [collectionAddressA, collectionAddressB]).send({from: owner});
+
+ // Create a token in one collection
+ const nftTokenIdA = await contractA.methods.nextTokenId().call();
+ await contractA.methods.mint(
+ owner,
+ nftTokenIdA,
+ ).send({from: owner});
+ const nftTokenAddressA = helper.ethAddress.fromTokenId(collectionIdA, nftTokenIdA);
+
+ // Create a token in another collection belonging to someone else
+ const nftTokenIdB = await contractB.methods.nextTokenId().call();
+ await contractB.methods.mint(
+ malignant,
+ nftTokenIdB,
+ ).send({from: owner});
+
+ // Try to drag someone else's token into the other collection and nest
+ await expect(contractB.methods
+ .transfer(nftTokenAddressA, nftTokenIdB)
+ .call({from: malignant})).to.be.rejectedWith('UserIsNotAllowedToNest');
+ });
+
+ itEth('NFT: disallows to nest token in an unlisted collection', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+
+ const {collectionId: collectionIdA, collectionAddress: collectionAddressA, contract: contractA} = await createNestingCollection(helper, owner);
+ const {contract: contractB} = await createNestingCollection(helper, owner);
+
+ await contractA.methods.setCollectionNesting(true, [collectionAddressA]).send({from: owner});
+
+ // Create a token in one collection
+ const nftTokenIdA = await contractA.methods.nextTokenId().call();
+ await contractA.methods.mint(
+ owner,
+ nftTokenIdA,
+ ).send({from: owner});
+ const nftTokenAddressA = helper.ethAddress.fromTokenId(collectionIdA, nftTokenIdA);
+
+ // Create a token in another collection
+ const nftTokenIdB = await contractB.methods.nextTokenId().call();
+ await contractB.methods.mint(
+ owner,
+ nftTokenIdB,
+ ).send({from: owner});
+
+ // Try to nest into a token in the other collection, disallowed in the first
+ await expect(contractB.methods
+ .transfer(nftTokenAddressA, nftTokenIdB)
+ .call()).to.be.rejectedWith('SourceCollectionIsNotAllowedToNest');
+ });
});
});
tests/src/eth/payable.test.tsdiffbeforeafterboth--- a/tests/src/eth/payable.test.ts
+++ b/tests/src/eth/payable.test.ts
@@ -14,97 +14,91 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-import {expect} from 'chai';
-import {submitTransactionAsync} from '../substrate/substrate-api';
-import {createEthAccountWithBalance, deployCollector, GAS_ARGS, itWeb3, subToEth, transferBalanceToEth} from './util/helpers';
-import {evmToAddress} from '@polkadot/util-crypto';
-import {getGenericResult, UNIQUE} from '../util/helpers';
-import {getBalanceSingle, transferBalanceExpectSuccess} from '../substrate/get-balance';
+import {IKeyringPair} from '@polkadot/types/types';
+
+import {itEth, expect, usingEthPlaygrounds} from './util/playgrounds';
describe('EVM payable contracts', () => {
- itWeb3('Evm contract can receive wei from eth account', async ({api, web3, privateKeyWrapper}) => {
- const deployer = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const contract = await deployCollector(web3, deployer);
+ let donor: IKeyringPair;
- await web3.eth.sendTransaction({from: deployer, to: contract.options.address, value: '10000', ...GAS_ARGS});
+ before(async function() {
+ await usingEthPlaygrounds(async (helper, privateKey) => {
+ donor = privateKey('//Alice');
+ });
+ });
+
+ itEth('Evm contract can receive wei from eth account', async ({helper}) => {
+ const deployer = await helper.eth.createAccountWithBalance(donor);
+ const contract = await helper.eth.deployCollectorContract(deployer);
+
+ const web3 = helper.getWeb3();
+
+ await web3.eth.sendTransaction({from: deployer, to: contract.options.address, value: '10000', gas: helper.eth.DEFAULT_GAS});
expect(await contract.methods.getCollected().call()).to.be.equal('10000');
});
- itWeb3('Evm contract can receive wei from substrate account', async ({api, web3, privateKeyWrapper}) => {
- const deployer = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const contract = await deployCollector(web3, deployer);
- const alice = privateKeyWrapper('//Alice');
+ itEth('Evm contract can receive wei from substrate account', async ({helper}) => {
+ const deployer = await helper.eth.createAccountWithBalance(donor);
+ const contract = await helper.eth.deployCollectorContract(deployer);
+ const [alice] = await helper.arrange.createAccounts([10n], donor);
+
+ const weiCount = '10000';
// Transaction fee/value will be payed from subToEth(sender) evm balance,
// which is backed by evmToAddress(subToEth(sender)) substrate balance
- await transferBalanceToEth(api, alice, subToEth(alice.address));
+ await helper.eth.transferBalanceFromSubstrate(alice, helper.address.substrateToEth(alice.address), 5n);
+
- {
- const tx = api.tx.evm.call(
- subToEth(alice.address),
- contract.options.address,
- contract.methods.giveMoney().encodeABI(),
- '10000',
- GAS_ARGS.gas,
- await web3.eth.getGasPrice(),
- null,
- null,
- [],
- );
- const events = await submitTransactionAsync(alice, tx);
- const result = getGenericResult(events);
- expect(result.success).to.be.true;
- }
+ await helper.eth.callEVM(alice, contract.options.address, contract.methods.giveMoney().encodeABI(), weiCount);
- expect(await contract.methods.getCollected().call()).to.be.equal('10000');
+ expect(await contract.methods.getCollected().call()).to.be.equal(weiCount);
});
// We can't handle sending balance to backing storage of evm balance, because evmToAddress operation is irreversible
- itWeb3('Wei sent directly to backing storage of evm contract balance is unaccounted', async({api, web3, privateKeyWrapper}) => {
- const deployer = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const contract = await deployCollector(web3, deployer);
- const alice = privateKeyWrapper('//Alice');
+ itEth('Wei sent directly to backing storage of evm contract balance is unaccounted', async({helper}) => {
+ const deployer = await helper.eth.createAccountWithBalance(donor);
+ const contract = await helper.eth.deployCollectorContract(deployer);
+ const [alice] = await helper.arrange.createAccounts([10n], donor);
+
+ const weiCount = 10_000n;
- await transferBalanceExpectSuccess(api, alice, evmToAddress(contract.options.address), '10000');
+ await helper.eth.transferBalanceFromSubstrate(alice, contract.options.address, weiCount, false);
- expect(await contract.methods.getUnaccounted().call()).to.be.equal('10000');
+ expect(await contract.methods.getUnaccounted().call()).to.be.equal(weiCount.toString());
});
- itWeb3('Balance can be retrieved from evm contract', async({api, web3, privateKeyWrapper}) => {
- const FEE_BALANCE = 1000n * UNIQUE;
- const CONTRACT_BALANCE = 1n * UNIQUE;
+ itEth('Balance can be retrieved from evm contract', async({helper, privateKey}) => {
+ const FEE_BALANCE = 10n * helper.balance.getOneTokenNominal();
+ const CONTRACT_BALANCE = 1n * helper.balance.getOneTokenNominal();
+
+ const deployer = await helper.eth.createAccountWithBalance(donor);
+ const contract = await helper.eth.deployCollectorContract(deployer);
+ const [alice] = await helper.arrange.createAccounts([20n], donor);
- const deployer = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const contract = await deployCollector(web3, deployer);
- const alice = privateKeyWrapper('//Alice');
+ const web3 = helper.getWeb3();
- await web3.eth.sendTransaction({from: deployer, to: contract.options.address, value: CONTRACT_BALANCE.toString(), ...GAS_ARGS});
+ await web3.eth.sendTransaction({from: deployer, to: contract.options.address, value: CONTRACT_BALANCE.toString(), gas: helper.eth.DEFAULT_GAS});
- const receiver = privateKeyWrapper(`//Receiver${Date.now()}`);
+ const receiver = privateKey(`//Receiver${Date.now()}`);
// First receive balance on eth balance of bob
{
- const ethReceiver = subToEth(receiver.address);
+ const ethReceiver = helper.address.substrateToEth(receiver.address);
expect(await web3.eth.getBalance(ethReceiver)).to.be.equal('0');
await contract.methods.withdraw(ethReceiver).send({from: deployer});
expect(await web3.eth.getBalance(ethReceiver)).to.be.equal(CONTRACT_BALANCE.toString());
}
// Some balance is required to pay fee for evm.withdraw call
- await transferBalanceExpectSuccess(api, alice, receiver.address, FEE_BALANCE.toString());
+ await helper.balance.transferToSubstrate(alice, receiver.address, FEE_BALANCE);
+ // await transferBalanceExpectSuccess(api, alice, receiver.address, FEE_BALANCE.toString());
// Withdraw balance from eth to substrate
{
- const initialReceiverBalance = await getBalanceSingle(api, receiver.address);
- const tx = api.tx.evm.withdraw(
- subToEth(receiver.address),
- CONTRACT_BALANCE.toString(),
- );
- const events = await submitTransactionAsync(receiver, tx);
- const result = getGenericResult(events);
- expect(result.success).to.be.true;
- const finalReceiverBalance = await getBalanceSingle(api, receiver.address);
+ const initialReceiverBalance = await helper.balance.getSubstrate(receiver.address);
+ await helper.executeExtrinsic(receiver, 'api.tx.evm.withdraw', [helper.address.substrateToEth(receiver.address), CONTRACT_BALANCE.toString()], true);
+ const finalReceiverBalance = await helper.balance.getSubstrate(receiver.address);
expect(finalReceiverBalance > initialReceiverBalance).to.be.true;
}
tests/src/eth/reFungibleToken.test.tsdiffbeforeafterboth--- a/tests/src/eth/reFungibleToken.test.ts
+++ b/tests/src/eth/reFungibleToken.test.ts
@@ -15,7 +15,7 @@
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
import {approve, createCollection, createRefungibleToken, transfer, transferFrom, UNIQUE, requirePallets, Pallets} from '../util/helpers';
-import {collectionIdFromAddress, collectionIdToAddress, createEthAccount, createEthAccountWithBalance, createNonfungibleCollection, createRefungibleCollection, evmCollection, evmCollectionHelpers, getCollectionAddressFromResult, itWeb3, normalizeEvents, recordEthFee, recordEvents, subToEth, tokenIdToAddress, transferBalanceToEth, uniqueNFT, uniqueRefungible, uniqueRefungibleToken} from './util/helpers';
+import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, createRefungibleCollection, evmCollection, evmCollectionHelpers, getCollectionAddressFromResult, itWeb3, normalizeEvents, recordEthFee, recordEvents, subToEth, tokenIdToAddress, transferBalanceToEth, uniqueRefungible, uniqueRefungibleToken} from './util/helpers';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
tests/src/eth/util/playgrounds/index.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/eth/util/playgrounds/index.ts
@@ -0,0 +1,49 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// SPDX-License-Identifier: Apache-2.0
+
+import {IKeyringPair} from '@polkadot/types/types';
+
+import config from '../../../config';
+
+import {EthUniqueHelper} from './unique.dev';
+import {SilentLogger, SilentConsole} from '../../../util/playgrounds/unique.dev';
+
+export {EthUniqueHelper} from './unique.dev';
+
+import chai from 'chai';
+import chaiAsPromised from 'chai-as-promised';
+chai.use(chaiAsPromised);
+export const expect = chai.expect;
+
+export const usingEthPlaygrounds = async (code: (helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair) => Promise<void>) => {
+ const silentConsole = new SilentConsole();
+ silentConsole.enable();
+
+ const helper = new EthUniqueHelper(new SilentLogger());
+
+ try {
+ await helper.connect(config.substrateUrl);
+ await helper.connectWeb3(config.substrateUrl);
+ const ss58Format = helper.chain.getChainProperties().ss58Format;
+ const privateKey = (seed: string) => helper.util.fromSeed(seed, ss58Format);
+ await code(helper, privateKey);
+ }
+ finally {
+ await helper.disconnect();
+ await helper.disconnectWeb3();
+ silentConsole.disable();
+ }
+};
+
+export async function itEth(name: string, cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any, opts: { only?: boolean, skip?: boolean } = {}) {
+ let i: any = it;
+ if (opts.only) i = i.only;
+ else if (opts.skip) i = i.skip;
+ i(name, async () => {
+ await usingEthPlaygrounds(async (helper, privateKey) => {
+ await cb({helper, privateKey});
+ });
+ });
+}
+itEth.only = (name: string, cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itEth(name, cb, {only: true});
+itEth.skip = (name: string, cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itEth(name, cb, {skip: true});
\ No newline at end of file
tests/src/eth/util/playgrounds/types.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/eth/util/playgrounds/types.ts
@@ -0,0 +1,9 @@
+export interface ContractImports {
+ solPath: string;
+ fsPath: string;
+}
+
+export interface CompiledContract {
+ abi: any;
+ object: string;
+}
\ No newline at end of file
tests/src/eth/util/playgrounds/unique.dev.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/eth/util/playgrounds/unique.dev.ts
@@ -0,0 +1,268 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// SPDX-License-Identifier: Apache-2.0
+
+/* eslint-disable function-call-argument-newline */
+
+import {readFile} from 'fs/promises';
+
+import Web3 from 'web3';
+import {WebsocketProvider} from 'web3-core';
+import {Contract} from 'web3-eth-contract';
+
+import * as solc from 'solc';
+
+import {evmToAddress} from '@polkadot/util-crypto';
+import {IKeyringPair} from '@polkadot/types/types';
+
+import {DevUniqueHelper} from '../../../util/playgrounds/unique.dev';
+
+import {ContractImports, CompiledContract} from './types';
+
+// Native contracts ABI
+import collectionHelpersAbi from '../../collectionHelpersAbi.json';
+import fungibleAbi from '../../fungibleAbi.json';
+import nonFungibleAbi from '../../nonFungibleAbi.json';
+import refungibleAbi from '../../reFungibleAbi.json';
+import refungibleTokenAbi from '../../reFungibleTokenAbi.json';
+import contractHelpersAbi from './../contractHelpersAbi.json';
+
+class EthGroupBase {
+ helper: EthUniqueHelper;
+
+ constructor(helper: EthUniqueHelper) {
+ this.helper = helper;
+ }
+}
+
+
+class ContractGroup extends EthGroupBase {
+ async findImports(imports?: ContractImports[]){
+ if(!imports) return function(path: string) {
+ return {error: `File not found: ${path}`};
+ };
+
+ const knownImports = {} as any;
+ for(const imp of imports) {
+ knownImports[imp.solPath] = (await readFile(imp.fsPath)).toString();
+ }
+
+ return function(path: string) {
+ if(knownImports.hasOwnPropertyDescriptor(path)) return {contents: knownImports[path]};
+ return {error: `File not found: ${path}`};
+ };
+ }
+
+ async compile(name: string, src: string, imports?: ContractImports[]): Promise<CompiledContract> {
+ const out = JSON.parse(solc.compile(JSON.stringify({
+ language: 'Solidity',
+ sources: {
+ [`${name}.sol`]: {
+ content: src,
+ },
+ },
+ settings: {
+ outputSelection: {
+ '*': {
+ '*': ['*'],
+ },
+ },
+ },
+ }), {import: await this.findImports(imports)})).contracts[`${name}.sol`][name];
+
+ return {
+ abi: out.abi,
+ object: '0x' + out.evm.bytecode.object,
+ };
+ }
+
+ async deployByCode(signer: string, name: string, src: string, imports?: ContractImports[]): Promise<Contract> {
+ const compiledContract = await this.compile(name, src, imports);
+ return this.deployByAbi(signer, compiledContract.abi, compiledContract.object);
+ }
+
+ async deployByAbi(signer: string, abi: any, object: string): Promise<Contract> {
+ const web3 = this.helper.getWeb3();
+ const contract = new web3.eth.Contract(abi, undefined, {
+ data: object,
+ from: signer,
+ gas: this.helper.eth.DEFAULT_GAS,
+ });
+ return await contract.deploy({data: object}).send({from: signer});
+ }
+
+}
+
+class NativeContractGroup extends EthGroupBase {
+
+ contractHelpers(caller: string): Contract {
+ const web3 = this.helper.getWeb3();
+ return new web3.eth.Contract(contractHelpersAbi as any, '0x842899ECF380553E8a4de75bF534cdf6fBF64049', {from: caller, gas: this.helper.eth.DEFAULT_GAS});
+ }
+
+ collectionHelpers(caller: string) {
+ const web3 = this.helper.getWeb3();
+ return new web3.eth.Contract(collectionHelpersAbi as any, '0x6c4e9fe1ae37a41e93cee429e8e1881abdcbb54f', {from: caller, gas: this.helper.eth.DEFAULT_GAS});
+ }
+
+ collection(address: string, mode: 'nft' | 'rft' | 'ft', caller?: string): Contract {
+ const abi = {
+ 'nft': nonFungibleAbi,
+ 'rft': refungibleAbi,
+ 'ft': fungibleAbi,
+ }[mode];
+ const web3 = this.helper.getWeb3();
+ return new web3.eth.Contract(abi as any, address, {gas: this.helper.eth.DEFAULT_GAS, ...(caller ? {from: caller} : {})});
+ }
+
+ rftTokenByAddress(address: string, caller?: string): Contract {
+ const web3 = this.helper.getWeb3();
+ return new web3.eth.Contract(refungibleTokenAbi as any, address, {gas: this.helper.eth.DEFAULT_GAS, ...(caller ? {from: caller} : {})});
+ }
+
+ rftToken(collectionId: number, tokenId: number, caller?: string): Contract {
+ return this.rftTokenByAddress(this.helper.ethAddress.fromTokenId(collectionId, tokenId), caller);
+ }
+}
+
+
+class EthGroup extends EthGroupBase {
+ DEFAULT_GAS = 2_500_000;
+
+ createAccount() {
+ const web3 = this.helper.getWeb3();
+ const account = web3.eth.accounts.create();
+ web3.eth.accounts.wallet.add(account.privateKey);
+ return account.address;
+ }
+
+ async createAccountWithBalance(donor: IKeyringPair, amount=1000n) {
+ const account = this.createAccount();
+ await this.transferBalanceFromSubstrate(donor, account, amount);
+
+ return account;
+ }
+
+ async transferBalanceFromSubstrate(donor: IKeyringPair, recepient: string, amount=1000n, inTokens=true) {
+ return await this.helper.balance.transferToSubstrate(donor, evmToAddress(recepient), amount * (inTokens ? this.helper.balance.getOneTokenNominal() : 1n));
+ }
+
+ async callEVM(signer: IKeyringPair, contractAddress: string, abi: any, value: string, gasLimit?: number) {
+ if(!gasLimit) gasLimit = this.DEFAULT_GAS;
+ const web3 = this.helper.getWeb3();
+ const gasPrice = await web3.eth.getGasPrice();
+ // TODO: check execution status
+ await this.helper.executeExtrinsic(
+ signer,
+ 'api.tx.evm.call', [this.helper.address.substrateToEth(signer.address), contractAddress, abi, value, gasLimit, gasPrice, null, null, []],
+ true,
+ );
+ }
+
+ async createNonfungibleCollection(signer: string, name: string, description: string, tokenPrefix: string): Promise<{collectionId: number, collectionAddress: string}> {
+ const collectionHelper = this.helper.ethNativeContract.collectionHelpers(signer);
+
+ const result = await collectionHelper.methods.createNonfungibleCollection(name, description, tokenPrefix).send();
+
+ const collectionAddress = this.helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);
+ const collectionId = this.helper.ethAddress.extractCollectionId(collectionAddress);
+
+ return {collectionId, collectionAddress};
+ }
+
+ async deployCollectorContract(signer: string): Promise<Contract> {
+ return await this.helper.ethContract.deployByCode(signer, 'Collector', `
+ // SPDX-License-Identifier: UNLICENSED
+ pragma solidity ^0.8.6;
+
+ contract Collector {
+ uint256 collected;
+ fallback() external payable {
+ giveMoney();
+ }
+ function giveMoney() public payable {
+ collected += msg.value;
+ }
+ function getCollected() public view returns (uint256) {
+ return collected;
+ }
+ function getUnaccounted() public view returns (uint256) {
+ return address(this).balance - collected;
+ }
+
+ function withdraw(address payable target) public {
+ target.transfer(collected);
+ collected = 0;
+ }
+ }
+ `);
+ }
+}
+
+
+class EthAddressGroup extends EthGroupBase {
+ extractCollectionId(address: string): number {
+ if (!(address.length === 42 || address.length === 40)) throw new Error('address wrong format');
+ return parseInt(address.substr(address.length - 8), 16);
+ }
+
+ fromCollectionId(collectionId: number): string {
+ if (collectionId >= 0xffffffff || collectionId < 0) throw new Error('collectionId overflow');
+ return Web3.utils.toChecksumAddress(`0x17c4e6453cc49aaaaeaca894e6d9683e${collectionId.toString(16).padStart(8, '0')}`);
+ }
+
+ extractTokenId(address: string): {collectionId: number, tokenId: number} {
+ if (!address.startsWith('0x'))
+ throw 'address not starts with "0x"';
+ if (address.length > 42)
+ throw 'address length is more than 20 bytes';
+ return {
+ collectionId: Number('0x' + address.substring(address.length - 16, address.length - 8)),
+ tokenId: Number('0x' + address.substring(address.length - 8)),
+ };
+ }
+
+ fromTokenId(collectionId: number, tokenId: number): string {
+ return this.helper.util.getNestingTokenAddress(collectionId, tokenId);
+ }
+
+ normalizeAddress(address: string): string {
+ return '0x' + address.substring(address.length - 40);
+ }
+}
+
+
+export class EthUniqueHelper extends DevUniqueHelper {
+ web3: Web3 | null = null;
+ web3Provider: WebsocketProvider | null = null;
+
+ eth: EthGroup;
+ ethAddress: EthAddressGroup;
+ ethNativeContract: NativeContractGroup;
+ ethContract: ContractGroup;
+
+ constructor(logger: { log: (msg: any, level: any) => void, level: any }) {
+ super(logger);
+ this.eth = new EthGroup(this);
+ this.ethAddress = new EthAddressGroup(this);
+ this.ethNativeContract = new NativeContractGroup(this);
+ this.ethContract = new ContractGroup(this);
+ }
+
+ getWeb3(): Web3 {
+ if(this.web3 === null) throw Error('Web3 not connected');
+ return this.web3;
+ }
+
+ async connectWeb3(wsEndpoint: string) {
+ if(this.web3 !== null) return;
+ this.web3Provider = new Web3.providers.WebsocketProvider(wsEndpoint);
+ this.web3 = new Web3(this.web3Provider);
+ }
+
+ async disconnectWeb3() {
+ if(this.web3 === null) return;
+ this.web3Provider?.connection.close();
+ this.web3 = null;
+ }
+}
+
\ No newline at end of file
tests/src/substrate/substrate-api.tsdiffbeforeafterboth--- a/tests/src/substrate/substrate-api.ts
+++ b/tests/src/substrate/substrate-api.ts
@@ -25,6 +25,8 @@
import privateKey from './privateKey';
import promisifySubstrate from './promisify-substrate';
+import {SilentConsole} from '../util/playgrounds/unique.dev';
+
function defaultApiOptions(): ApiOptions {
@@ -74,26 +76,9 @@
settings = settings || defaultApiOptions();
const api: ApiPromise = new ApiPromise(settings);
let result: T = null as unknown as T;
-
- // TODO: Remove, this is temporary: Filter unneeded API output
- // (Jaco promised it will be removed in the next version)
- const consoleErr = console.error;
- const consoleLog = console.log;
- const consoleWarn = console.warn;
- const outFn = (printer: any) => (...args: any[]) => {
- for (const arg of args) {
- if (typeof arg !== 'string')
- continue;
- if (arg.includes('1000:: Normal connection closure') || arg.includes('Not decorating unknown runtime apis:') || arg.includes('RPC methods not decorated:') || arg === 'Normal connection closure')
- return;
- }
- printer(...args);
- };
-
- console.error = outFn(consoleErr.bind(console));
- console.log = outFn(consoleLog.bind(console));
- console.warn = outFn(consoleWarn.bind(console));
+ const silentConsole = new SilentConsole();
+ silentConsole.enable();
try {
await promisifySubstrate(api, async () => {
@@ -106,9 +91,7 @@
})();
} finally {
await api.disconnect();
- console.error = consoleErr;
- console.log = consoleLog;
- console.warn = consoleWarn;
+ silentConsole.disable();
}
return result as T;
}
tests/src/util/playgrounds/index.tsdiffbeforeafterboth--- a/tests/src/util/playgrounds/index.ts
+++ b/tests/src/util/playgrounds/index.ts
@@ -4,37 +4,13 @@
import {IKeyringPair} from '@polkadot/types/types';
import config from '../../config';
import '../../interfaces/augment-api-events';
-import {DevUniqueHelper} from './unique.dev';
+import {DevUniqueHelper, SilentLogger, SilentConsole} from './unique.dev';
-class SilentLogger {
- log(msg: any, level: any): void { }
- level = {
- ERROR: 'ERROR' as const,
- WARNING: 'WARNING' as const,
- INFO: 'INFO' as const,
- };
-}
export const usingPlaygrounds = async (code: (helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair) => Promise<void>) => {
- // TODO: Remove, this is temporary: Filter unneeded API output
- // (Jaco promised it will be removed in the next version)
- const consoleErr = console.error;
- const consoleLog = console.log;
- const consoleWarn = console.warn;
+ const silentConsole = new SilentConsole();
+ silentConsole.enable();
- const outFn = (printer: any) => (...args: any[]) => {
- for (const arg of args) {
- if (typeof arg !== 'string')
- continue;
- if (arg.includes('1000:: Normal connection closure') || arg.includes('Not decorating unknown runtime apis:') || arg.includes('RPC methods not decorated:') || arg === 'Normal connection closure')
- return;
- }
- printer(...args);
- };
-
- console.error = outFn(consoleErr.bind(console));
- console.log = outFn(consoleLog.bind(console));
- console.warn = outFn(consoleWarn.bind(console));
const helper = new DevUniqueHelper(new SilentLogger());
try {
@@ -45,8 +21,6 @@
}
finally {
await helper.disconnect();
- console.error = consoleErr;
- console.log = consoleLog;
- console.warn = consoleWarn;
+ silentConsole.disable();
}
};
tests/src/util/playgrounds/unique.dev.tsdiffbeforeafterboth--- a/tests/src/util/playgrounds/unique.dev.ts
+++ b/tests/src/util/playgrounds/unique.dev.ts
@@ -5,10 +5,56 @@
import {UniqueHelper} from './unique';
import {ApiPromise, WsProvider} from '@polkadot/api';
import * as defs from '../../interfaces/definitions';
-import {TSigner} from './types';
import {IKeyringPair} from '@polkadot/types/types';
+export class SilentLogger {
+ log(_msg: any, _level: any): void { }
+ level = {
+ ERROR: 'ERROR' as const,
+ WARNING: 'WARNING' as const,
+ INFO: 'INFO' as const,
+ };
+}
+
+
+export class SilentConsole {
+ // TODO: Remove, this is temporary: Filter unneeded API output
+ // (Jaco promised it will be removed in the next version)
+ consoleErr: any;
+ consoleLog: any;
+ consoleWarn: any;
+
+ constructor() {
+ this.consoleErr = console.error;
+ this.consoleLog = console.log;
+ this.consoleWarn = console.warn;
+ }
+
+ enable() {
+ const outFn = (printer: any) => (...args: any[]) => {
+ for (const arg of args) {
+ if (typeof arg !== 'string')
+ continue;
+ if (arg.includes('1000:: Normal connection closure') || arg.includes('Not decorating unknown runtime apis: UniqueApi/2, RmrkApi/1') || arg.includes('RPC methods not decorated:') || arg === 'Normal connection closure')
+ return;
+ }
+ printer(...args);
+ };
+
+ console.error = outFn(this.consoleErr.bind(console));
+ console.log = outFn(this.consoleLog.bind(console));
+ console.warn = outFn(this.consoleWarn.bind(console));
+ }
+
+ disable() {
+ console.error = this.consoleErr;
+ console.log = this.consoleLog;
+ console.warn = this.consoleWarn;
+ }
+}
+
+
export class DevUniqueHelper extends UniqueHelper {
/**
* Arrange methods for tests
@@ -20,7 +66,7 @@
this.arrange = new ArrangeGroup(this);
}
- async connect(wsEndpoint: string, listeners?: any): Promise<void> {
+ async connect(wsEndpoint: string, _listeners?: any): Promise<void> {
const wsProvider = new WsProvider(wsEndpoint);
this.api = new ApiPromise({
provider: wsProvider,
@@ -85,7 +131,7 @@
}
}
- await Promise.all(transactions).catch(e => {});
+ await Promise.all(transactions).catch(_e => {});
//#region TODO remove this region, when nonce problem will be solved
const checkBalances = async () => {
@@ -113,13 +159,14 @@
return accounts;
};
-
+
/**
* Wait for specified bnumber of blocks
* @param blocksCount number of blocks to wait
* @returns
*/
async waitNewBlocks(blocksCount = 1): Promise<void> {
+ // eslint-disable-next-line no-async-promise-executor
const promise = new Promise<void>(async (resolve) => {
const unsubscribe = await this.helper.api!.rpc.chain.subscribeNewHeads(() => {
if (blocksCount > 0) {
tests/src/util/playgrounds/unique.tsdiffbeforeafterboth91 return encodeAddress(decodeAddress(address), ss58Format);91 return encodeAddress(decodeAddress(address), ss58Format);92 }92 }939394 static extractCollectionIdFromCreationResult(creationResult: ITransactionResult, label = 'new collection') {94 static extractCollectionIdFromCreationResult(creationResult: ITransactionResult) {95 if (creationResult.status !== this.transactionStatus.SUCCESS) {95 if (creationResult.status !== this.transactionStatus.SUCCESS) {96 throw Error(`Unable to create collection for ${label}`);96 throw Error('Unable to create collection!');97 }97 }989899 let collectionId = null;99 let collectionId = null;104 });104 });105105106 if (collectionId === null) {106 if (collectionId === null) {107 throw Error(`No CollectionCreated event for ${label}`);107 throw Error('No CollectionCreated event was found!');108 }108 }109109110 return collectionId;110 return collectionId;111 }111 }112112113 static extractTokensFromCreationResult(creationResult: ITransactionResult, label = 'new tokens') {113 static extractTokensFromCreationResult(creationResult: ITransactionResult) {114 if (creationResult.status !== this.transactionStatus.SUCCESS) {114 if (creationResult.status !== this.transactionStatus.SUCCESS) {115 throw Error(`Unable to create tokens for ${label}`);115 throw Error('Unable to create tokens!');116 }116 }117 let success = false;117 let success = false;118 const tokens = [] as any;118 const tokens = [] as any;130 return {success, tokens};130 return {success, tokens};131 }131 }132132133 static extractTokensFromBurnResult(burnResult: ITransactionResult, label = 'burned tokens') {133 static extractTokensFromBurnResult(burnResult: ITransactionResult) {134 if (burnResult.status !== this.transactionStatus.SUCCESS) {134 if (burnResult.status !== this.transactionStatus.SUCCESS) {135 throw Error(`Unable to burn tokens for ${label}`);135 throw Error('Unable to burn tokens!');136 }136 }137 let success = false;137 let success = false;138 const tokens = [] as any;138 const tokens = [] as any;150 return {success, tokens};150 return {success, tokens};151 }151 }152152153 static findCollectionInEvents(events: {event: IChainEvent}[], collectionId: number, expectedSection: string, expectedMethod: string, label?: string) {153 static findCollectionInEvents(events: {event: IChainEvent}[], collectionId: number, expectedSection: string, expectedMethod: string) {154 let eventId = null;154 let eventId = null;155 events.forEach(({event: {data, method, section}}) => {155 events.forEach(({event: {data, method, section}}) => {156 if ((section === expectedSection) && (method === expectedMethod)) {156 if ((section === expectedSection) && (method === expectedMethod)) {159 });159 });160160161 if (eventId === null) {161 if (eventId === null) {162 throw Error(`No ${expectedMethod} event for ${label}`);162 throw Error(`No ${expectedMethod} event was found!`);163 }163 }164 return eventId === collectionId;164 return eventId === collectionId;165 }165 }317 if(options !== null) return transaction.signAndSend(sender, options, callback);317 if(options !== null) return transaction.signAndSend(sender, options, callback);318 return transaction.signAndSend(sender, callback);318 return transaction.signAndSend(sender, callback);319 };319 };320 // eslint-disable-next-line no-async-promise-executor320 return new Promise(async (resolve, reject) => {321 return new Promise(async (resolve, reject) => {321 try {322 try {322 const unsub = await sign((result: any) => {323 const unsub = await sign((result: any) => {364 return call(...params);365 return call(...params);365 }366 }366367367 async executeExtrinsic(sender: TSigner, extrinsic: string, params: any[], expectSuccess=false, failureMessage='expected success') {368 async executeExtrinsic(sender: TSigner, extrinsic: string, params: any[], expectSuccess=false/*, failureMessage='expected success'*/) {368 if(this.api === null) throw Error('API not initialized');369 if(this.api === null) throw Error('API not initialized');369 if(!extrinsic.startsWith('api.tx.')) throw Error(`${extrinsic} is not transaction`);370 if(!extrinsic.startsWith('api.tx.')) throw Error(`${extrinsic} is not transaction`);370371388 type: this.chainLogType.EXTRINSIC,389 type: this.chainLogType.EXTRINSIC,389 status: result.status,390 status: result.status,390 call: extrinsic,391 call: extrinsic,392 signer: this.getSignerAddress(sender),391 params,393 params,392 } as IUniqueHelperLog;394 } as IUniqueHelperLog;393395396398397 this.chainLog.push(log);399 this.chainLog.push(log);398400399 if(expectSuccess && result.status !== this.transactionStatus.SUCCESS) throw Error(failureMessage);401 if(expectSuccess && result.status !== this.transactionStatus.SUCCESS) throw Error(`${result.moduleError}`);400 return result;402 return result;401 }403 }402404556 * 558 * 557 * @param signer keyring of signer559 * @param signer keyring of signer558 * @param collectionId ID of collection560 * @param collectionId ID of collection559 * @param label extra label for log560 * @example await helper.collection.burn(aliceKeyring, 3);561 * @example await helper.collection.burn(aliceKeyring, 3);561 * @returns ```true``` if extrinsic success, otherwise ```false```562 * @returns ```true``` if extrinsic success, otherwise ```false```562 */563 */563 async burn(signer: TSigner, collectionId: number, label?: string): Promise<boolean> {564 async burn(signer: TSigner, collectionId: number): Promise<boolean> {564 if(typeof label === 'undefined') label = `collection #${collectionId}`;565 const result = await this.helper.executeExtrinsic(565 const result = await this.helper.executeExtrinsic(566 signer,566 signer,567 'api.tx.unique.destroyCollection', [collectionId],567 'api.tx.unique.destroyCollection', [collectionId],568 true, `Unable to burn collection for ${label}`,568 true,569 );569 );570570571 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'CollectionDestroyed', label);571 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'CollectionDestroyed');572 }572 }573573574 /**574 /**577 * @param signer keyring of signer577 * @param signer keyring of signer578 * @param collectionId ID of collection578 * @param collectionId ID of collection579 * @param sponsorAddress Sponsor substrate address579 * @param sponsorAddress Sponsor substrate address580 * @param label extra label for log581 * @example setSponsor(aliceKeyring, 10, "5DyN4Y92vZCjv38fg...")580 * @example setSponsor(aliceKeyring, 10, "5DyN4Y92vZCjv38fg...")582 * @returns ```true``` if extrinsic success, otherwise ```false```581 * @returns ```true``` if extrinsic success, otherwise ```false```583 */582 */584 async setSponsor(signer: TSigner, collectionId: number, sponsorAddress: TSubstrateAccount, label?: string): Promise<boolean> {583 async setSponsor(signer: TSigner, collectionId: number, sponsorAddress: TSubstrateAccount): Promise<boolean> {585 if(typeof label === 'undefined') label = `collection #${collectionId}`;586 const result = await this.helper.executeExtrinsic(584 const result = await this.helper.executeExtrinsic(587 signer,585 signer,588 'api.tx.unique.setCollectionSponsor', [collectionId, sponsorAddress],586 'api.tx.unique.setCollectionSponsor', [collectionId, sponsorAddress],589 true, `Unable to set collection sponsor for ${label}`,587 true,590 );588 );591589592 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'CollectionSponsorSet', label);590 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'CollectionSponsorSet');593 }591 }594592595 /**593 /**596 * Confirms consent to sponsor the collection on behalf of the signer.594 * Confirms consent to sponsor the collection on behalf of the signer.597 * 595 * 598 * @param signer keyring of signer596 * @param signer keyring of signer599 * @param collectionId ID of collection597 * @param collectionId ID of collection600 * @param label extra label for log601 * @example confirmSponsorship(aliceKeyring, 10)598 * @example confirmSponsorship(aliceKeyring, 10)602 * @returns ```true``` if extrinsic success, otherwise ```false```599 * @returns ```true``` if extrinsic success, otherwise ```false```603 */600 */604 async confirmSponsorship(signer: TSigner, collectionId: number, label?: string): Promise<boolean> {601 async confirmSponsorship(signer: TSigner, collectionId: number): Promise<boolean> {605 if(typeof label === 'undefined') label = `collection #${collectionId}`;606 const result = await this.helper.executeExtrinsic(602 const result = await this.helper.executeExtrinsic(607 signer,603 signer,608 'api.tx.unique.confirmSponsorship', [collectionId],604 'api.tx.unique.confirmSponsorship', [collectionId],609 true, `Unable to confirm collection sponsorship for ${label}`,605 true,610 );606 );611607612 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'SponsorshipConfirmed', label);608 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'SponsorshipConfirmed');613 }609 }614610615 /**611 /**618 * @param signer keyring of signer614 * @param signer keyring of signer619 * @param collectionId ID of collection615 * @param collectionId ID of collection620 * @param limits collection limits object616 * @param limits collection limits object621 * @param label extra label for log622 * @example617 * @example623 * await setLimits(618 * await setLimits(624 * aliceKeyring,619 * aliceKeyring,630 * )625 * )631 * @returns ```true``` if extrinsic success, otherwise ```false```626 * @returns ```true``` if extrinsic success, otherwise ```false```632 */627 */633 async setLimits(signer: TSigner, collectionId: number, limits: ICollectionLimits, label?: string): Promise<boolean> {628 async setLimits(signer: TSigner, collectionId: number, limits: ICollectionLimits): Promise<boolean> {634 if(typeof label === 'undefined') label = `collection #${collectionId}`;635 const result = await this.helper.executeExtrinsic(629 const result = await this.helper.executeExtrinsic(636 signer,630 signer,637 'api.tx.unique.setCollectionLimits', [collectionId, limits],631 'api.tx.unique.setCollectionLimits', [collectionId, limits],638 true, `Unable to set collection limits for ${label}`,632 true,639 );633 );640634641 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'CollectionLimitSet', label);635 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'CollectionLimitSet');642 }636 }643637644 /**638 /**647 * @param signer keyring of signer641 * @param signer keyring of signer648 * @param collectionId ID of collection642 * @param collectionId ID of collection649 * @param ownerAddress substrate address of new owner643 * @param ownerAddress substrate address of new owner650 * @param label extra label for log651 * @example changeOwner(aliceKeyring, 10, "5DyN4Y92vZCjv38fg...")644 * @example changeOwner(aliceKeyring, 10, "5DyN4Y92vZCjv38fg...")652 * @returns ```true``` if extrinsic success, otherwise ```false```645 * @returns ```true``` if extrinsic success, otherwise ```false```653 */646 */654 async changeOwner(signer: TSigner, collectionId: number, ownerAddress: TSubstrateAccount, label?: string): Promise<boolean> {647 async changeOwner(signer: TSigner, collectionId: number, ownerAddress: TSubstrateAccount): Promise<boolean> {655 if(typeof label === 'undefined') label = `collection #${collectionId}`;656 const result = await this.helper.executeExtrinsic(648 const result = await this.helper.executeExtrinsic(657 signer,649 signer,658 'api.tx.unique.changeCollectionOwner', [collectionId, ownerAddress],650 'api.tx.unique.changeCollectionOwner', [collectionId, ownerAddress],659 true, `Unable to change collection owner for ${label}`,651 true,660 );652 );661653662 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'CollectionOwnedChanged', label);654 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'CollectionOwnedChanged');663 }655 }664656665 /**657 /**668 * @param signer keyring of signer660 * @param signer keyring of signer669 * @param collectionId ID of collection661 * @param collectionId ID of collection670 * @param adminAddressObj Administrator address (substrate or ethereum)662 * @param adminAddressObj Administrator address (substrate or ethereum)671 * @param label extra label for log672 * @example addAdmin(aliceKeyring, 10, {Substrate: "5DyN4Y92vZCjv38fg..."})663 * @example addAdmin(aliceKeyring, 10, {Substrate: "5DyN4Y92vZCjv38fg..."})673 * @returns ```true``` if extrinsic success, otherwise ```false```664 * @returns ```true``` if extrinsic success, otherwise ```false```674 */665 */675 async addAdmin(signer: TSigner, collectionId: number, adminAddressObj: ICrossAccountId, label?: string): Promise<boolean> {666 async addAdmin(signer: TSigner, collectionId: number, adminAddressObj: ICrossAccountId): Promise<boolean> {676 if(typeof label === 'undefined') label = `collection #${collectionId}`;677 const result = await this.helper.executeExtrinsic(667 const result = await this.helper.executeExtrinsic(678 signer,668 signer,679 'api.tx.unique.addCollectionAdmin', [collectionId, adminAddressObj],669 'api.tx.unique.addCollectionAdmin', [collectionId, adminAddressObj],680 true, `Unable to add collection admin for ${label}`,670 true,681 );671 );682672683 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'CollectionAdminAdded', label);673 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'CollectionAdminAdded');684 }674 }685675686 /**676 /**677 * Removes a collection administrator.678 * 679 * @param signer keyring of signer680 * @param collectionId ID of collection681 * @param adminAddressObj Administrator address (substrate or ethereum)682 * @example removeAdmin(aliceKeyring, 10, {Substrate: "5DyN4Y92vZCjv38fg..."})683 * @returns ```true``` if extrinsic success, otherwise ```false```684 */685 async removeAdmin(signer: TSigner, collectionId: number, adminAddressObj: ICrossAccountId): Promise<boolean> {686 const result = await this.helper.executeExtrinsic(687 signer,688 'api.tx.unique.removeCollectionAdmin', [collectionId, adminAddressObj],689 true,690 );691692 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'CollectionAdminRemoved');693 }694695 /**687 * Adds an address to allow list 696 * Adds an address to allow list 688 * @param signer keyring of signer697 * @param signer keyring of signer689 * @param collectionId ID of collection698 * @param collectionId ID of collection690 * @param addressObj address to add to the allow list699 * @param addressObj address to add to the allow list691 * @param label extra label for log692 * @returns ```true``` if extrinsic success, otherwise ```false```700 * @returns ```true``` if extrinsic success, otherwise ```false```693 */701 */694 async addToAllowList(signer: TSigner, collectionId: number, addressObj: ICrossAccountId, label?: string): Promise<boolean> {702 async addToAllowList(signer: TSigner, collectionId: number, addressObj: ICrossAccountId): Promise<boolean> {695 if(typeof label === 'undefined') label = `collection #${collectionId}`;696 const result = await this.helper.executeExtrinsic(703 const result = await this.helper.executeExtrinsic(697 signer,704 signer,698 'api.tx.unique.addToAllowList', [collectionId, addressObj],705 'api.tx.unique.addToAllowList', [collectionId, addressObj],699 true, `Unable to add address to allow list for ${label}`,706 true,700 );707 );701708702 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'AllowListAddressAdded');709 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'AllowListAddressAdded');703 }710 }704711705 /**712 /**706 * Removes a collection administrator.713 * Removes an address from allow list 707 * 714 * 708 * @param signer keyring of signer715 * @param signer keyring of signer709 * @param collectionId ID of collection716 * @param collectionId ID of collection710 * @param adminAddressObj Administrator address (substrate or ethereum)717 * @param addressObj address to remove from the allow list711 * @param label extra label for log712 * @example removeAdmin(aliceKeyring, 10, {Substrate: "5DyN4Y92vZCjv38fg..."})713 * @returns ```true``` if extrinsic success, otherwise ```false```718 * @returns ```true``` if extrinsic success, otherwise ```false```714 */719 */715 async removeAdmin(signer: TSigner, collectionId: number, adminAddressObj: ICrossAccountId, label?: string): Promise<boolean> {720 async removeFromAllowList(signer: TSigner, collectionId: number, addressObj: ICrossAccountId): Promise<boolean> {716 if(typeof label === 'undefined') label = `collection #${collectionId}`;717 const result = await this.helper.executeExtrinsic(721 const result = await this.helper.executeExtrinsic(718 signer,722 signer,719 'api.tx.unique.removeCollectionAdmin', [collectionId, adminAddressObj],723 'api.tx.unique.removeFromAllowList', [collectionId, addressObj],720 true, `Unable to remove collection admin for ${label}`,724 true,721 );725 );722726723 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'CollectionAdminRemoved', label);727 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'AllowListAddressRemoved');724 }728 }725729726 /**730 /**729 * @param signer keyring of signer733 * @param signer keyring of signer730 * @param collectionId ID of collection734 * @param collectionId ID of collection731 * @param permissions collection permissions object735 * @param permissions collection permissions object732 * @param label extra label for log733 * @example setPermissions(aliceKeyring, 10, {access:'AllowList', mintMode: true, nesting: {collectionAdmin: true, tokenOwner: true}});736 * @example setPermissions(aliceKeyring, 10, {access:'AllowList', mintMode: true, nesting: {collectionAdmin: true, tokenOwner: true}});734 * @returns ```true``` if extrinsic success, otherwise ```false```737 * @returns ```true``` if extrinsic success, otherwise ```false```735 */738 */736 async setPermissions(signer: TSigner, collectionId: number, permissions: ICollectionPermissions, label?: string): Promise<boolean> {739 async setPermissions(signer: TSigner, collectionId: number, permissions: ICollectionPermissions): Promise<boolean> {737 if(typeof label === 'undefined') label = `collection #${collectionId}`;738 const result = await this.helper.executeExtrinsic(740 const result = await this.helper.executeExtrinsic(739 signer,741 signer,740 'api.tx.unique.setCollectionPermissions', [collectionId, permissions],742 'api.tx.unique.setCollectionPermissions', [collectionId, permissions],741 true, `Unable to set collection permissions for ${label}`,743 true,742 );744 );743745744 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'CollectionPermissionSet', label);746 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'CollectionPermissionSet');745 }747 }746748747 /**749 /**750 * @param signer keyring of signer752 * @param signer keyring of signer751 * @param collectionId ID of collection753 * @param collectionId ID of collection752 * @param permissions nesting permissions object754 * @param permissions nesting permissions object753 * @param label extra label for log754 * @example enableNesting(aliceKeyring, 10, {collectionAdmin: true, tokenOwner: true});755 * @example enableNesting(aliceKeyring, 10, {collectionAdmin: true, tokenOwner: true});755 * @returns ```true``` if extrinsic success, otherwise ```false```756 * @returns ```true``` if extrinsic success, otherwise ```false```756 */757 */757 async enableNesting(signer: TSigner, collectionId: number, permissions: INestingPermissions, label?: string): Promise<boolean> {758 async enableNesting(signer: TSigner, collectionId: number, permissions: INestingPermissions): Promise<boolean> {758 return await this.setPermissions(signer, collectionId, {nesting: permissions}, label);759 return await this.setPermissions(signer, collectionId, {nesting: permissions});759 }760 }760761761 /**762 /**762 * Disables nesting for selected collection.763 * Disables nesting for selected collection.763 * 764 * 764 * @param signer keyring of signer765 * @param signer keyring of signer765 * @param collectionId ID of collection766 * @param collectionId ID of collection766 * @param label extra label for log767 * @example disableNesting(aliceKeyring, 10);767 * @example disableNesting(aliceKeyring, 10);768 * @returns ```true``` if extrinsic success, otherwise ```false```768 * @returns ```true``` if extrinsic success, otherwise ```false```769 */769 */770 async disableNesting(signer: TSigner, collectionId: number, label?: string): Promise<boolean> {770 async disableNesting(signer: TSigner, collectionId: number): Promise<boolean> {771 return await this.setPermissions(signer, collectionId, {nesting: {tokenOwner: false, collectionAdmin: false}}, label);771 return await this.setPermissions(signer, collectionId, {nesting: {tokenOwner: false, collectionAdmin: false}});772 }772 }773773774 /**774 /**777 * @param signer keyring of signer777 * @param signer keyring of signer778 * @param collectionId ID of collection778 * @param collectionId ID of collection779 * @param properties array of property objects779 * @param properties array of property objects780 * @param label extra label for log781 * @example setProperties(aliceKeyring, 10, [{key: "gender", value: "male"}]);780 * @example setProperties(aliceKeyring, 10, [{key: "gender", value: "male"}]);782 * @returns ```true``` if extrinsic success, otherwise ```false```781 * @returns ```true``` if extrinsic success, otherwise ```false```783 */782 */784 async setProperties(signer: TSigner, collectionId: number, properties: IProperty[], label?: string): Promise<boolean> {783 async setProperties(signer: TSigner, collectionId: number, properties: IProperty[]): Promise<boolean> {785 if(typeof label === 'undefined') label = `collection #${collectionId}`;786 const result = await this.helper.executeExtrinsic(784 const result = await this.helper.executeExtrinsic(787 signer,785 signer,788 'api.tx.unique.setCollectionProperties', [collectionId, properties],786 'api.tx.unique.setCollectionProperties', [collectionId, properties],789 true, `Unable to set collection properties for ${label}`,787 true,790 );788 );791789792 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'CollectionPropertySet', label);790 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'CollectionPropertySet');793 }791 }794792795 /**793 /**798 * @param signer keyring of signer796 * @param signer keyring of signer799 * @param collectionId ID of collection797 * @param collectionId ID of collection800 * @param propertyKeys array of property keys to delete798 * @param propertyKeys array of property keys to delete801 * @param label802 * @example deleteProperties(aliceKeyring, 10, ["gender", "age"]);799 * @example deleteProperties(aliceKeyring, 10, ["gender", "age"]);803 * @returns ```true``` if extrinsic success, otherwise ```false```800 * @returns ```true``` if extrinsic success, otherwise ```false```804 */801 */805 async deleteProperties(signer: TSigner, collectionId: number, propertyKeys: string[], label?: string): Promise<boolean> {802 async deleteProperties(signer: TSigner, collectionId: number, propertyKeys: string[]): Promise<boolean> {806 if(typeof label === 'undefined') label = `collection #${collectionId}`;807 const result = await this.helper.executeExtrinsic(803 const result = await this.helper.executeExtrinsic(808 signer,804 signer,809 'api.tx.unique.deleteCollectionProperties', [collectionId, propertyKeys],805 'api.tx.unique.deleteCollectionProperties', [collectionId, propertyKeys],810 true, `Unable to delete collection properties for ${label}`,806 true,811 );807 );812808813 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'CollectionPropertyDeleted', label);809 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'CollectionPropertyDeleted');814 }810 }815811816 /**812 /**828 const result = await this.helper.executeExtrinsic(824 const result = await this.helper.executeExtrinsic(829 signer,825 signer,830 'api.tx.unique.transfer', [addressObj, collectionId, tokenId, amount],826 'api.tx.unique.transfer', [addressObj, collectionId, tokenId, amount],831 true, `Unable to transfer token #${tokenId} from collection #${collectionId}`,827 true, // `Unable to transfer token #${tokenId} from collection #${collectionId}`,832 );828 );833829834 return this.helper.util.isTokenTransferSuccess(result.result.events, collectionId, tokenId, {Substrate: typeof signer === 'string' ? signer : signer.address}, addressObj, amount);830 return this.helper.util.isTokenTransferSuccess(result.result.events, collectionId, tokenId, {Substrate: typeof signer === 'string' ? signer : signer.address}, addressObj, amount);851 const result = await this.helper.executeExtrinsic(847 const result = await this.helper.executeExtrinsic(852 signer,848 signer,853 'api.tx.unique.transferFrom', [fromAddressObj, toAddressObj, collectionId, tokenId, amount],849 'api.tx.unique.transferFrom', [fromAddressObj, toAddressObj, collectionId, tokenId, amount],854 true, `Unable to transfer token #${tokenId} from collection #${collectionId}`,850 true, // `Unable to transfer token #${tokenId} from collection #${collectionId}`,855 );851 );856 return this.helper.util.isTokenTransferSuccess(result.result.events, collectionId, tokenId, fromAddressObj, toAddressObj, amount);852 return this.helper.util.isTokenTransferSuccess(result.result.events, collectionId, tokenId, fromAddressObj, toAddressObj, amount);857 }853 }863 * @param signer keyring of signer859 * @param signer keyring of signer864 * @param collectionId ID of collection860 * @param collectionId ID of collection865 * @param tokenId ID of token861 * @param tokenId ID of token866 * @param label 867 * @param amount amount of tokens to be burned. For NFT must be set to 1n862 * @param amount amount of tokens to be burned. For NFT must be set to 1n868 * @example burnToken(aliceKeyring, 10, 5);863 * @example burnToken(aliceKeyring, 10, 5);869 * @returns ```true``` and burnt token number is extrinsic success. Otherwise ```false``` and ```null```864 * @returns ```true``` and burnt token number is extrinsic success. Otherwise ```false``` and ```null```870 */865 */871 async burnToken(signer: TSigner, collectionId: number, tokenId: number, label?: string, amount=1n): Promise<{866 async burnToken(signer: TSigner, collectionId: number, tokenId: number, amount=1n): Promise<{872 success: boolean,867 success: boolean,873 token: number | null868 token: number | null874 }> {869 }> {875 if(typeof label === 'undefined') label = `collection #${collectionId}`;876 const burnResult = await this.helper.executeExtrinsic(870 const burnResult = await this.helper.executeExtrinsic(877 signer,871 signer,878 'api.tx.unique.burnItem', [collectionId, tokenId, amount],872 'api.tx.unique.burnItem', [collectionId, tokenId, amount],879 true, `Unable to burn token for ${label}`,873 true, // `Unable to burn token for ${label}`,880 );874 );881 const burnedTokens = this.helper.util.extractTokensFromBurnResult(burnResult, label);875 const burnedTokens = this.helper.util.extractTokensFromBurnResult(burnResult);882 if (burnedTokens.tokens.length > 1) throw Error('Burned multiple tokens');876 if (burnedTokens.tokens.length > 1) throw Error('Burned multiple tokens');883 return {success: burnedTokens.success, token: burnedTokens.tokens.length > 0 ? burnedTokens.tokens[0] : null};877 return {success: burnedTokens.success, token: burnedTokens.tokens.length > 0 ? burnedTokens.tokens[0] : null};884 }878 }890 * @param collectionId ID of collection884 * @param collectionId ID of collection891 * @param fromAddressObj address on behalf of which the token will be burnt885 * @param fromAddressObj address on behalf of which the token will be burnt892 * @param tokenId ID of token886 * @param tokenId ID of token893 * @param label 894 * @param amount amount of tokens to be burned. For NFT must be set to 1n887 * @param amount amount of tokens to be burned. For NFT must be set to 1n895 * @example burnTokenFrom(aliceKeyring, 10, {Substrate: "5DyN4Y92vZCjv38fg..."}, 5, {Ethereum: "0x9F0583DbB85..."})888 * @example burnTokenFrom(aliceKeyring, 10, {Substrate: "5DyN4Y92vZCjv38fg..."}, 5, {Ethereum: "0x9F0583DbB85..."})896 * @returns ```true``` if extrinsic success, otherwise ```false```889 * @returns ```true``` if extrinsic success, otherwise ```false```897 */890 */898 async burnTokenFrom(signer: TSigner, collectionId: number, fromAddressObj: ICrossAccountId, tokenId: number, label?: string, amount=1n): Promise<boolean> {891 async burnTokenFrom(signer: TSigner, collectionId: number, fromAddressObj: ICrossAccountId, tokenId: number, amount=1n): Promise<boolean> {899 if(typeof label === 'undefined') label = `collection #${collectionId}`;900 const burnResult = await this.helper.executeExtrinsic(892 const burnResult = await this.helper.executeExtrinsic(901 signer,893 signer,902 'api.tx.unique.burnFrom', [collectionId, fromAddressObj, tokenId, amount],894 'api.tx.unique.burnFrom', [collectionId, fromAddressObj, tokenId, amount],903 true, `Unable to burn token from for ${label}`,895 true, // `Unable to burn token from for ${label}`,904 );896 );905 const burnedTokens = this.helper.util.extractTokensFromBurnResult(burnResult, label);897 const burnedTokens = this.helper.util.extractTokensFromBurnResult(burnResult);906 return burnedTokens.success && burnedTokens.tokens.length > 0;898 return burnedTokens.success && burnedTokens.tokens.length > 0;907 }899 }908900912 * @param signer keyring of signer904 * @param signer keyring of signer913 * @param collectionId ID of collection905 * @param collectionId ID of collection914 * @param tokenId ID of token906 * @param tokenId ID of token915 * @param toAddressObj 907 * @param toAddressObj Substrate or Ethereum address which gets approved use of the signer's tokens916 * @param label 917 * @param amount amount of token to be approved. For NFT must be set to 1n908 * @param amount amount of token to be approved. For NFT must be set to 1n918 * @returns ```true``` if extrinsic success, otherwise ```false```909 * @returns ```true``` if extrinsic success, otherwise ```false```919 */910 */920 async approveToken(signer: IKeyringPair, collectionId: number, tokenId: number, toAddressObj: ICrossAccountId, label?: string, amount=1n) {911 async approveToken(signer: IKeyringPair, collectionId: number, tokenId: number, toAddressObj: ICrossAccountId, amount=1n) {921 if(typeof label === 'undefined') label = `collection #${collectionId}`;922 const approveResult = await this.helper.executeExtrinsic(912 const approveResult = await this.helper.executeExtrinsic(923 signer, 913 signer, 924 'api.tx.unique.approve', [toAddressObj, collectionId, tokenId, amount],914 'api.tx.unique.approve', [toAddressObj, collectionId, tokenId, amount],925 true, `Unable to approve token for ${label}`,915 true, // `Unable to approve token for ${label}`,926 );916 );927917928 return this.helper.util.findCollectionInEvents(approveResult.result.events, collectionId, 'common', 'Approved', label);918 return this.helper.util.findCollectionInEvents(approveResult.result.events, collectionId, 'common', 'Approved');929 }919 }930920931 /**921 /**932 * Get the amount of token pieces approved to transfer922 * Get the amount of token pieces approved to transfer or burn. Normally 0.923 * 933 * @param collectionId ID of collection924 * @param collectionId ID of collection934 * @param tokenId ID of token925 * @param tokenId ID of token935 * @param toAccountObj 926 * @param toAccountObj address which is approved to use token pieces936 * @param fromAccountObj927 * @param fromAccountObj address which may have allowed the use of its owned tokens937 * @example getTokenApprovedPieces(10, 5, {Substrate: "5DyN4Y92vZCjv38fg..."}, {Substrate: "5ERZNF88Mm7UGfPP3mdG..."})928 * @example getTokenApprovedPieces(10, 5, {Substrate: "5DyN4Y92vZCjv38fg..."}, {Substrate: "5ERZNF88Mm7UGfPP3mdG..."})938 * @returns number of approved to transfer pieces929 * @returns number of approved to transfer pieces939 */930 */942 }933 }943934944 /**935 /**945 * Get the last created token id936 * Get the last created token ID in a collection937 * 946 * @param collectionId ID of collection938 * @param collectionId ID of collection947 * @example getLastTokenId(10);939 * @example getLastTokenId(10);948 * @returns id of the last created token940 * @returns id of the last created token953945954 /**946 /**955 * Check if token exists947 * Check if token exists948 * 956 * @param collectionId ID of collection949 * @param collectionId ID of collection957 * @param tokenId ID of token950 * @param tokenId ID of token958 * @example isTokenExists(10, 20);951 * @example isTokenExists(10, 20);978971979 /**972 /**980 * Get token data973 * Get token data974 * 981 * @param collectionId ID of collection975 * @param collectionId ID of collection982 * @param tokenId ID of token976 * @param tokenId ID of token983 * @param blockHashAt 977 * @param propertyKeys optionally filter the token properties to only these keys984 * @param propertyKeys978 * @param blockHashAt optionally query the data at some block with this hash985 * @example getToken(10, 5);979 * @example getToken(10, 5);986 * @returns human readable token data 980 * @returns human readable token data 987 */981 */988 async getToken(collectionId: number, tokenId: number, blockHashAt?: string, propertyKeys?: string[]): Promise<{982 async getToken(collectionId: number, tokenId: number, propertyKeys: string[] = [], blockHashAt?: string): Promise<{989 properties: IProperty[];983 properties: IProperty[];990 owner: ICrossAccountId;984 owner: ICrossAccountId;991 normalizedOwner: ICrossAccountId;985 normalizedOwner: ICrossAccountId;995 tokenData = await this.helper.callRpc('api.rpc.unique.tokenData', [collectionId, tokenId]);989 tokenData = await this.helper.callRpc('api.rpc.unique.tokenData', [collectionId, tokenId]);996 }990 }997 else {991 else {998 if(typeof propertyKeys === 'undefined') {992 if(propertyKeys.length == 0) {999 const collection = (await this.helper.callRpc('api.rpc.unique.collectionById', [collectionId])).toHuman();993 const collection = (await this.helper.callRpc('api.rpc.unique.collectionById', [collectionId])).toHuman();1000 if(!collection) return null;994 if(!collection) return null;1001 propertyKeys = collection.tokenPropertyPermissions.map((x: ITokenPropertyPermission) => x.key);995 propertyKeys = collection.tokenPropertyPermissions.map((x: ITokenPropertyPermission) => x.key);101410081015 /**1009 /**1016 * Set permissions to change token properties1010 * Set permissions to change token properties1011 * 1017 * @param signer keyring of signer1012 * @param signer keyring of signer1018 * @param collectionId ID of collection1013 * @param collectionId ID of collection1019 * @param permissions permissions to change a property by the collection owner or admin1014 * @param permissions permissions to change a property by the collection owner or admin1020 * @param label 1021 * @example setTokenPropertyPermissions(1015 * @example setTokenPropertyPermissions(1022 * aliceKeyring, 10, [{key: "gender", permission: {tokenOwner: true, mutable: true, collectionAdmin: true}}]1016 * aliceKeyring, 10, [{key: "gender", permission: {tokenOwner: true, mutable: true, collectionAdmin: true}}]1023 * )1017 * )1024 * @returns true if extrinsic success otherwise false1018 * @returns true if extrinsic success otherwise false1025 */1019 */1026 async setTokenPropertyPermissions(signer: TSigner, collectionId: number, permissions: ITokenPropertyPermission[], label?: string): Promise<boolean> {1020 async setTokenPropertyPermissions(signer: TSigner, collectionId: number, permissions: ITokenPropertyPermission[]): Promise<boolean> {1027 if(typeof label === 'undefined') label = `collection #${collectionId}`;1028 const result = await this.helper.executeExtrinsic(1021 const result = await this.helper.executeExtrinsic(1029 signer,1022 signer,1030 'api.tx.unique.setTokenPropertyPermissions', [collectionId, permissions],1023 'api.tx.unique.setTokenPropertyPermissions', [collectionId, permissions],1031 true, `Unable to set token property permissions for ${label}`,1024 true,1032 );1025 );103310261034 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'PropertyPermissionSet', label);1027 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'PropertyPermissionSet');1035 }1028 }103610291037 /**1030 /**1038 * Set token properties1031 * Set token properties1032 * 1039 * @param signer keyring of signer1033 * @param signer keyring of signer1040 * @param collectionId ID of collection1034 * @param collectionId ID of collection1041 * @param tokenId ID of token1035 * @param tokenId ID of token1042 * @param properties 1036 * @param properties key-value pairs of metadata which to add to a token. Keys must be permitted in the collection1043 * @param label 1044 * @example setTokenProperties(aliceKeyring, 10, 5, [{key: "gender", value: "female"}, {key: "age", value: "23"}])1037 * @example setTokenProperties(aliceKeyring, 10, 5, [{key: "gender", value: "female"}, {key: "age", value: "23"}])1045 * @returns ```true``` if extrinsic success, otherwise ```false```1038 * @returns ```true``` if extrinsic success, otherwise ```false```1046 */1039 */1047 async setTokenProperties(signer: TSigner, collectionId: number, tokenId: number, properties: IProperty[], label?: string): Promise<boolean> {1040 async setTokenProperties(signer: TSigner, collectionId: number, tokenId: number, properties: IProperty[]): Promise<boolean> {1048 if(typeof label === 'undefined') label = `token #${tokenId} from collection #${collectionId}`;1049 const result = await this.helper.executeExtrinsic(1041 const result = await this.helper.executeExtrinsic(1050 signer,1042 signer,1051 'api.tx.unique.setTokenProperties', [collectionId, tokenId, properties],1043 'api.tx.unique.setTokenProperties', [collectionId, tokenId, properties],1052 true, `Unable to set token properties for ${label}`,1044 true,1053 );1045 );105410461055 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'TokenPropertySet', label);1047 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'TokenPropertySet');1056 }1048 }105710491058 /**1050 /**1061 * @param collectionId ID of collection1053 * @param collectionId ID of collection1062 * @param tokenId ID of token1054 * @param tokenId ID of token1063 * @param propertyKeys property keys to be deleted 1055 * @param propertyKeys property keys to be deleted 1064 * @param label 1065 * @example deleteTokenProperties(aliceKeyring, 10, 5, ["gender", "age"])1056 * @example deleteTokenProperties(aliceKeyring, 10, 5, ["gender", "age"])1066 * @returns ```true``` if extrinsic success, otherwise ```false```1057 * @returns ```true``` if extrinsic success, otherwise ```false```1067 */1058 */1068 async deleteTokenProperties(signer: TSigner, collectionId: number, tokenId: number, propertyKeys: string[], label?: string): Promise<boolean> {1059 async deleteTokenProperties(signer: TSigner, collectionId: number, tokenId: number, propertyKeys: string[]): Promise<boolean> {1069 if(typeof label === 'undefined') label = `token #${tokenId} from collection #${collectionId}`;1070 const result = await this.helper.executeExtrinsic(1060 const result = await this.helper.executeExtrinsic(1071 signer,1061 signer,1072 'api.tx.unique.deleteTokenProperties', [collectionId, tokenId, propertyKeys],1062 'api.tx.unique.deleteTokenProperties', [collectionId, tokenId, propertyKeys],1073 true, `Unable to delete token properties for ${label}`,1063 true,1074 );1064 );107510651076 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'TokenPropertyDeleted', label);1066 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'TokenPropertyDeleted');1077 }1067 }107810681079 /**1069 /**1080 * Mint new collection1070 * Mint new collection1071 * 1081 * @param signer keyring of signer1072 * @param signer keyring of signer1082 * @param collectionOptions basic collection options and properties 1073 * @param collectionOptions basic collection options and properties 1083 * @param mode NFT or RFT type of a collection1074 * @param mode NFT or RFT type of a collection1084 * @param errorLabel 1085 * @example mintCollection(aliceKeyring, {name: 'New', description: "New collection", tokenPrefix: "NEW"}, "NFT")1075 * @example mintCollection(aliceKeyring, {name: 'New', description: "New collection", tokenPrefix: "NEW"}, "NFT")1086 * @returns object of the created collection1076 * @returns object of the created collection1087 */1077 */1088 async mintCollection(signer: TSigner, collectionOptions: ICollectionCreationOptions, mode: 'NFT' | 'RFT', errorLabel = 'Unable to mint collection'): Promise<UniqueCollectionBase> {1078 async mintCollection(signer: TSigner, collectionOptions: ICollectionCreationOptions, mode: 'NFT' | 'RFT'): Promise<UniqueCollectionBase> {1089 collectionOptions = JSON.parse(JSON.stringify(collectionOptions)) as ICollectionCreationOptions; // Clone object1079 collectionOptions = JSON.parse(JSON.stringify(collectionOptions)) as ICollectionCreationOptions; // Clone object1090 collectionOptions.mode = (mode === 'NFT') ? {nft: null} : {refungible: null};1080 collectionOptions.mode = (mode === 'NFT') ? {nft: null} : {refungible: null};1091 for (const key of ['name', 'description', 'tokenPrefix']) {1081 for (const key of ['name', 'description', 'tokenPrefix']) {1094 const creationResult = await this.helper.executeExtrinsic(1084 const creationResult = await this.helper.executeExtrinsic(1095 signer,1085 signer,1096 'api.tx.unique.createCollectionEx', [collectionOptions],1086 'api.tx.unique.createCollectionEx', [collectionOptions],1097 true, errorLabel,1087 true, // errorLabel,1098 );1088 );1099 return this.getCollectionObject(this.helper.util.extractCollectionIdFromCreationResult(creationResult, errorLabel));1089 return this.getCollectionObject(this.helper.util.extractCollectionIdFromCreationResult(creationResult));1100 }1090 }110110911102 getCollectionObject(collectionId: number): any {1092 getCollectionObject(_collectionId: number): any {1103 return null;1093 return null;1104 }1094 }110510951106 getTokenObject(collectionId: number, tokenId: number): any {1096 getTokenObject(_collectionId: number, _tokenId: number): any {1107 return null;1097 return null;1108 }1098 }1109}1099}1135 * Get token's owner1125 * Get token's owner1136 * @param collectionId ID of collection1126 * @param collectionId ID of collection1137 * @param tokenId ID of token1127 * @param tokenId ID of token1138 * @param blockHashAt 1128 * @param blockHashAt optionally query the data at the block with this hash1139 * @example getTokenOwner(10, 5);1129 * @example getTokenOwner(10, 5);1140 * @returns Address in CrossAccountId format, e.g. {Substrate: "5DnSF6RRjwteE3BrCj..."}1130 * @returns Address in CrossAccountId format, e.g. {Substrate: "5DnSF6RRjwteE3BrCj..."}1141 */1131 */1217 * Get tokens nested in the provided token1207 * Get tokens nested in the provided token1218 * @param collectionId ID of collection1208 * @param collectionId ID of collection1219 * @param tokenId ID of token1209 * @param tokenId ID of token1220 * @param blockHashAt 1210 * @param blockHashAt optionally query the data at the block with this hash1221 * @example getTokenChildren(10, 5);1211 * @example getTokenChildren(10, 5);1222 * @returns tokens whose depth of nesting is <= 5 1212 * @returns tokens whose depth of nesting is <= 5 1223 */1213 */1239 * @param signer keyring of signer1229 * @param signer keyring of signer1240 * @param tokenObj token to be nested1230 * @param tokenObj token to be nested1241 * @param rootTokenObj token to be parent1231 * @param rootTokenObj token to be parent1242 * @param label 1243 * @example nestToken(aliceKeyring, {collectionId: 10, tokenId: 5}, {collectionId: 10, tokenId: 4});1232 * @example nestToken(aliceKeyring, {collectionId: 10, tokenId: 5}, {collectionId: 10, tokenId: 4});1244 * @returns ```true``` if extrinsic success, otherwise ```false```1233 * @returns ```true``` if extrinsic success, otherwise ```false```1245 */1234 */1246 async nestToken(signer: TSigner, tokenObj: IToken, rootTokenObj: IToken, label='nest token'): Promise<boolean> {1235 async nestToken(signer: TSigner, tokenObj: IToken, rootTokenObj: IToken): Promise<boolean> {1247 const rootTokenAddress = {Ethereum: this.helper.util.getNestingTokenAddress(rootTokenObj.collectionId, rootTokenObj.tokenId)};1236 const rootTokenAddress = {Ethereum: this.helper.util.getNestingTokenAddress(rootTokenObj.collectionId, rootTokenObj.tokenId)};1248 const result = await this.transferToken(signer, tokenObj.collectionId, tokenObj.tokenId, rootTokenAddress);1237 const result = await this.transferToken(signer, tokenObj.collectionId, tokenObj.tokenId, rootTokenAddress);1249 if(!result) {1238 if(!result) {1250 throw Error(`Unable to nest token for ${label}`);1239 throw Error('Unable to nest token!');1251 }1240 }1252 return result;1241 return result;1253 }1242 }1258 * @param tokenObj token to unnest1247 * @param tokenObj token to unnest1259 * @param rootTokenObj parent of a token1248 * @param rootTokenObj parent of a token1260 * @param toAddressObj address of a new token owner 1249 * @param toAddressObj address of a new token owner 1261 * @param label 1262 * @example unnestToken(aliceKeyring, {collectionId: 10, tokenId: 5}, {collectionId: 10, tokenId: 4}, {Substrate: "5DyN4Y92vZCjv38fg..."});1250 * @example unnestToken(aliceKeyring, {collectionId: 10, tokenId: 5}, {collectionId: 10, tokenId: 4}, {Substrate: "5DyN4Y92vZCjv38fg..."});1263 * @returns ```true``` if extrinsic success, otherwise ```false```1251 * @returns ```true``` if extrinsic success, otherwise ```false```1264 */1252 */1265 async unnestToken(signer: TSigner, tokenObj: IToken, rootTokenObj: IToken, toAddressObj: ICrossAccountId, label='unnest token'): Promise<boolean> {1253 async unnestToken(signer: TSigner, tokenObj: IToken, rootTokenObj: IToken, toAddressObj: ICrossAccountId): Promise<boolean> {1266 const rootTokenAddress = {Ethereum: this.helper.util.getNestingTokenAddress(rootTokenObj.collectionId, rootTokenObj.tokenId)};1254 const rootTokenAddress = {Ethereum: this.helper.util.getNestingTokenAddress(rootTokenObj.collectionId, rootTokenObj.tokenId)};1267 const result = await this.transferTokenFrom(signer, tokenObj.collectionId, tokenObj.tokenId, rootTokenAddress, toAddressObj);1255 const result = await this.transferTokenFrom(signer, tokenObj.collectionId, tokenObj.tokenId, rootTokenAddress, toAddressObj);1268 if(!result) {1256 if(!result) {1269 throw Error(`Unable to unnest token for ${label}`);1257 throw Error('Unable to unnest token!');1270 }1258 }1271 return result;1259 return result;1272 }1260 }1275 * Mint new collection1263 * Mint new collection1276 * @param signer keyring of signer1264 * @param signer keyring of signer1277 * @param collectionOptions Collection options1265 * @param collectionOptions Collection options1278 * @param label 1279 * @example 1266 * @example 1280 * mintCollection(aliceKeyring, {1267 * mintCollection(aliceKeyring, {1281 * name: 'New',1268 * name: 'New',1284 * })1271 * })1285 * @returns object of the created collection1272 * @returns object of the created collection1286 */1273 */1287 async mintCollection(signer: TSigner, collectionOptions: ICollectionCreationOptions, label = 'new collection'): Promise<UniqueNFTCollection> {1274 async mintCollection(signer: TSigner, collectionOptions: ICollectionCreationOptions): Promise<UniqueNFTCollection> {1288 return await super.mintCollection(signer, collectionOptions, 'NFT', `Unable to mint NFT collection for ${label}`) as UniqueNFTCollection;1275 return await super.mintCollection(signer, collectionOptions, 'NFT') as UniqueNFTCollection;1289 }1276 }129012771291 /**1278 /**1292 * Mint new token1279 * Mint new token1293 * @param signer keyring of signer1280 * @param signer keyring of signer1294 * @param data token data1281 * @param data token data1295 * @param label 1296 * @returns created token object1282 * @returns created token object1297 */1283 */1298 async mintToken(signer: TSigner, data: { collectionId: number; owner: ICrossAccountId | string; properties?: IProperty[]; }, label?: string): Promise<UniqueNFTToken> {1284 async mintToken(signer: TSigner, data: { collectionId: number; owner: ICrossAccountId | string; properties?: IProperty[]; }): Promise<UniqueNFTToken> {1299 if(typeof label === 'undefined') label = `collection #${data.collectionId}`;1300 const creationResult = await this.helper.executeExtrinsic(1285 const creationResult = await this.helper.executeExtrinsic(1301 signer,1286 signer,1302 'api.tx.unique.createItem', [data.collectionId, (typeof data.owner === 'string') ? {Substrate: data.owner} : data.owner, {1287 'api.tx.unique.createItem', [data.collectionId, (typeof data.owner === 'string') ? {Substrate: data.owner} : data.owner, {1303 nft: {1288 nft: {1304 properties: data.properties,1289 properties: data.properties,1305 },1290 },1306 }],1291 }],1307 true, `Unable to mint NFT token for ${label}`,1292 true,1308 );1293 );1309 const createdTokens = this.helper.util.extractTokensFromCreationResult(creationResult, label);1294 const createdTokens = this.helper.util.extractTokensFromCreationResult(creationResult);1310 if (createdTokens.tokens.length > 1) throw Error('Minted multiple tokens');1295 if (createdTokens.tokens.length > 1) throw Error('Minted multiple tokens');1311 if (createdTokens.tokens.length < 1) throw Error('No tokens minted');1296 if (createdTokens.tokens.length < 1) throw Error('No tokens minted');1312 return this.getTokenObject(data.collectionId, createdTokens.tokens[0].tokenId);1297 return this.getTokenObject(data.collectionId, createdTokens.tokens[0].tokenId);1317 * @param signer keyring of signer1302 * @param signer keyring of signer1318 * @param collectionId ID of collection1303 * @param collectionId ID of collection1319 * @param tokens array of tokens with owner and properties1304 * @param tokens array of tokens with owner and properties1320 * @param label 1321 * @example 1305 * @example 1322 * mintMultipleTokens(aliceKeyring, 10, [{1306 * mintMultipleTokens(aliceKeyring, 10, [{1323 * owner: {Substrate: "5DyN4Y92vZCjv38fg..."},1307 * owner: {Substrate: "5DyN4Y92vZCjv38fg..."},1328 * }]);1312 * }]);1329 * @returns ```true``` if extrinsic success, otherwise ```false```1313 * @returns ```true``` if extrinsic success, otherwise ```false```1330 */1314 */1331 async mintMultipleTokens(signer: TSigner, collectionId: number, tokens: {owner: ICrossAccountId, properties?: IProperty[]}[], label?: string): Promise<UniqueNFTToken[]> {1315 async mintMultipleTokens(signer: TSigner, collectionId: number, tokens: {owner: ICrossAccountId, properties?: IProperty[]}[]): Promise<UniqueNFTToken[]> {1332 if(typeof label === 'undefined') label = `collection #${collectionId}`;1333 const creationResult = await this.helper.executeExtrinsic(1316 const creationResult = await this.helper.executeExtrinsic(1334 signer,1317 signer,1335 'api.tx.unique.createMultipleItemsEx', [collectionId, {NFT: tokens}],1318 'api.tx.unique.createMultipleItemsEx', [collectionId, {NFT: tokens}],1336 true, `Unable to mint NFT tokens for ${label}`,1319 true,1337 );1320 );1338 const collection = this.getCollectionObject(collectionId);1321 const collection = this.getCollectionObject(collectionId);1339 return this.helper.util.extractTokensFromCreationResult(creationResult, label).tokens.map((x: IToken) => collection.getTokenObject(x.tokenId));1322 return this.helper.util.extractTokensFromCreationResult(creationResult).tokens.map((x: IToken) => collection.getTokenObject(x.tokenId));1340 }1323 }134113241342 /**1325 /**1345 * @param collectionId ID of collection1328 * @param collectionId ID of collection1346 * @param owner tokens owner1329 * @param owner tokens owner1347 * @param tokens array of tokens with owner and properties1330 * @param tokens array of tokens with owner and properties1348 * @param label 1349 * @example1331 * @example1350 * mintMultipleTokensWithOneOwner(aliceKeyring, 10, "5DyN4Y92vZCjv38fg...", [{1332 * mintMultipleTokensWithOneOwner(aliceKeyring, 10, "5DyN4Y92vZCjv38fg...", [{1351 * properties: [{1333 * properties: [{1358 * }]);1340 * }]);1359 * @returns array of newly created tokens1341 * @returns array of newly created tokens1360 */1342 */1361 async mintMultipleTokensWithOneOwner(signer: TSigner, collectionId: number, owner: ICrossAccountId, tokens: {properties?: IProperty[]}[], label?: string): Promise<UniqueNFTToken[]> {1343 async mintMultipleTokensWithOneOwner(signer: TSigner, collectionId: number, owner: ICrossAccountId, tokens: {properties?: IProperty[]}[]): Promise<UniqueNFTToken[]> {1362 if(typeof label === 'undefined') label = `collection #${collectionId}`;1363 const rawTokens = [];1344 const rawTokens = [];1364 for (const token of tokens) {1345 for (const token of tokens) {1365 const raw = {NFT: {properties: token.properties}};1346 const raw = {NFT: {properties: token.properties}};1368 const creationResult = await this.helper.executeExtrinsic(1349 const creationResult = await this.helper.executeExtrinsic(1369 signer,1350 signer,1370 'api.tx.unique.createMultipleItems', [collectionId, owner, rawTokens],1351 'api.tx.unique.createMultipleItems', [collectionId, owner, rawTokens],1371 true, `Unable to mint NFT tokens for ${label}`,1352 true,1372 );1353 );1373 const collection = this.getCollectionObject(collectionId);1354 const collection = this.getCollectionObject(collectionId);1374 return this.helper.util.extractTokensFromCreationResult(creationResult, label).tokens.map((x: IToken) => collection.getTokenObject(x.tokenId));1355 return this.helper.util.extractTokensFromCreationResult(creationResult).tokens.map((x: IToken) => collection.getTokenObject(x.tokenId));1375 }1356 }137613571377 /**1358 /**1378 * Destroys a concrete instance of NFT.1359 * Destroys a concrete instance of NFT.1379 * @param signer keyring of signer1360 * @param signer keyring of signer1380 * @param collectionId ID of collection1361 * @param collectionId ID of collection1381 * @param tokenId ID of token1362 * @param tokenId ID of token1382 * @param label 1383 * @example burnToken(aliceKeyring, 10, 5);1363 * @example burnToken(aliceKeyring, 10, 5);1384 * @returns ```true``` and burnt token number is extrinsic success. Otherwise ```false``` and ```null```1364 * @returns ```true``` and burnt token number is extrinsic success. Otherwise ```false``` and ```null```1385 */1365 */1386 async burnToken(signer: IKeyringPair, collectionId: number, tokenId: number, label?: string): Promise<{ success: boolean; token: number | null; }> {1366 async burnToken(signer: IKeyringPair, collectionId: number, tokenId: number): Promise<{ success: boolean; token: number | null; }> {1387 return await super.burnToken(signer, collectionId, tokenId, label, 1n);1367 return await super.burnToken(signer, collectionId, tokenId, 1n);1388 }1368 }138913691390 /**1370 /**1394 * @param collectionId ID of collection1374 * @param collectionId ID of collection1395 * @param tokenId ID of token1375 * @param tokenId ID of token1396 * @param toAddressObj address to approve1376 * @param toAddressObj address to approve1397 * @param label 1398 * @example approveToken(aliceKeyring, 10, 5, {Substrate: "5DyN4Y92vZCjv38fg..."})1377 * @example approveToken(aliceKeyring, 10, 5, {Substrate: "5DyN4Y92vZCjv38fg..."})1399 * @returns ```true``` if extrinsic success, otherwise ```false```1378 * @returns ```true``` if extrinsic success, otherwise ```false```1400 */1379 */1401 async approveToken(signer: IKeyringPair, collectionId: number, tokenId: number, toAddressObj: ICrossAccountId, label?: string) {1380 async approveToken(signer: IKeyringPair, collectionId: number, tokenId: number, toAddressObj: ICrossAccountId) {1402 return super.approveToken(signer, collectionId, tokenId, toAddressObj, label, 1n);1381 return super.approveToken(signer, collectionId, tokenId, toAddressObj, 1n);1403 }1382 }1404}1383}140513841459 * @example transferTokenFrom(aliceKeyring, 10, 5, {Substrate: "5DyN4Y92vZCjv38fg..."}, 2000n)1438 * @example transferTokenFrom(aliceKeyring, 10, 5, {Substrate: "5DyN4Y92vZCjv38fg..."}, 2000n)1460 * @returns ```true``` if extrinsic success, otherwise ```false```1439 * @returns ```true``` if extrinsic success, otherwise ```false```1461 */1440 */1462 async transferToken(signer: TSigner, collectionId: number, tokenId: number, addressObj: ICrossAccountId, amount=100n): Promise<boolean> {1441 async transferToken(signer: TSigner, collectionId: number, tokenId: number, addressObj: ICrossAccountId, amount=1n): Promise<boolean> {1463 return await super.transferToken(signer, collectionId, tokenId, addressObj, amount);1442 return await super.transferToken(signer, collectionId, tokenId, addressObj, amount);1464 }1443 }146514441474 * @example transferTokenFrom(aliceKeyring, 10, 5, {Substrate: "5DyN4Y92vZCjv38fg..."}, {Substrate: "5DfhbVfww7ThF8q6f3i..."}, 2000n)1453 * @example transferTokenFrom(aliceKeyring, 10, 5, {Substrate: "5DyN4Y92vZCjv38fg..."}, {Substrate: "5DfhbVfww7ThF8q6f3i..."}, 2000n)1475 * @returns ```true``` if extrinsic success, otherwise ```false```1454 * @returns ```true``` if extrinsic success, otherwise ```false```1476 */1455 */1477 async transferTokenFrom(signer: TSigner, collectionId: number, tokenId: number, fromAddressObj: ICrossAccountId, toAddressObj: ICrossAccountId, amount=100n): Promise<boolean> {1456 async transferTokenFrom(signer: TSigner, collectionId: number, tokenId: number, fromAddressObj: ICrossAccountId, toAddressObj: ICrossAccountId, amount=1n): Promise<boolean> {1478 return await super.transferTokenFrom(signer, collectionId, tokenId, fromAddressObj, toAddressObj, amount);1457 return await super.transferTokenFrom(signer, collectionId, tokenId, fromAddressObj, toAddressObj, amount);1479 }1458 }148014591481 /**1460 /**1482 * Mint new collection1461 * Mint new collection1483 * @param signer keyring of signer1462 * @param signer keyring of signer1484 * @param collectionOptions Collection options1463 * @param collectionOptions Collection options1485 * @param label 1486 * @example1464 * @example1487 * mintCollection(aliceKeyring, {1465 * mintCollection(aliceKeyring, {1488 * name: 'New',1466 * name: 'New',1491 * })1469 * })1492 * @returns object of the created collection1470 * @returns object of the created collection1493 */1471 */1494 async mintCollection(signer: TSigner, collectionOptions: ICollectionCreationOptions, label = 'new collection'): Promise<UniqueRFTCollection> {1472 async mintCollection(signer: TSigner, collectionOptions: ICollectionCreationOptions): Promise<UniqueRFTCollection> {1495 return await super.mintCollection(signer, collectionOptions, 'RFT', `Unable to mint RFT collection for ${label}`) as UniqueRFTCollection;1473 return await super.mintCollection(signer, collectionOptions, 'RFT') as UniqueRFTCollection;1496 }1474 }149714751498 /**1476 /**1499 * Mint new token1477 * Mint new token1500 * @param signer keyring of signer1478 * @param signer keyring of signer1501 * @param data token data1479 * @param data token data1502 * @param label 1503 * @example mintToken(aliceKeyring, {collectionId: 10, owner: {Substrate: '5GHoZe9c73RYbVzq...'}, pieces: 10000n});1480 * @example mintToken(aliceKeyring, {collectionId: 10, owner: {Substrate: '5GHoZe9c73RYbVzq...'}, pieces: 10000n});1504 * @returns created token object1481 * @returns created token object1505 */1482 */1506 async mintToken(signer: TSigner, data: { collectionId: number; owner: ICrossAccountId | string; pieces: bigint; properties?: IProperty[]; }, label?: string): Promise<UniqueRFTToken> {1483 async mintToken(signer: TSigner, data: { collectionId: number; owner: ICrossAccountId | string; pieces: bigint; properties?: IProperty[]; }): Promise<UniqueRFTToken> {1507 if(typeof label === 'undefined') label = `collection #${data.collectionId}`;1508 const creationResult = await this.helper.executeExtrinsic(1484 const creationResult = await this.helper.executeExtrinsic(1509 signer,1485 signer,1510 'api.tx.unique.createItem', [data.collectionId, (typeof data.owner === 'string') ? {Substrate: data.owner} : data.owner, {1486 'api.tx.unique.createItem', [data.collectionId, (typeof data.owner === 'string') ? {Substrate: data.owner} : data.owner, {1513 properties: data.properties,1489 properties: data.properties,1514 },1490 },1515 }],1491 }],1516 true, `Unable to mint RFT token for ${label}`,1492 true,1517 );1493 );1518 const createdTokens = this.helper.util.extractTokensFromCreationResult(creationResult, label);1494 const createdTokens = this.helper.util.extractTokensFromCreationResult(creationResult);1519 if (createdTokens.tokens.length > 1) throw Error('Minted multiple tokens');1495 if (createdTokens.tokens.length > 1) throw Error('Minted multiple tokens');1520 if (createdTokens.tokens.length < 1) throw Error('No tokens minted');1496 if (createdTokens.tokens.length < 1) throw Error('No tokens minted');1521 return this.getTokenObject(data.collectionId, createdTokens.tokens[0].tokenId);1497 return this.getTokenObject(data.collectionId, createdTokens.tokens[0].tokenId);1522 }1498 }152314991524 async mintMultipleTokens(signer: TSigner, collectionId: number, tokens: {owner: ICrossAccountId, pieces: bigint, properties?: IProperty[]}[], label?: string): Promise<UniqueRFTToken[]> {1500 async mintMultipleTokens(signer: TSigner, collectionId: number, tokens: {owner: ICrossAccountId, pieces: bigint, properties?: IProperty[]}[]): Promise<UniqueRFTToken[]> {1525 throw Error('Not implemented');1501 throw Error('Not implemented');1526 if(typeof label === 'undefined') label = `collection #${collectionId}`;1527 const creationResult = await this.helper.executeExtrinsic(1502 const creationResult = await this.helper.executeExtrinsic(1528 signer,1503 signer,1529 'api.tx.unique.createMultipleItemsEx', [collectionId, {RefungibleMultipleOwners: tokens}],1504 'api.tx.unique.createMultipleItemsEx', [collectionId, {RefungibleMultipleOwners: tokens}],1530 true, `Unable to mint RFT tokens for ${label}`,1505 true, // `Unable to mint RFT tokens for ${label}`,1531 );1506 );1532 const collection = this.getCollectionObject(collectionId);1507 const collection = this.getCollectionObject(collectionId);1533 return this.helper.util.extractTokensFromCreationResult(creationResult, label).tokens.map((x: IToken) => collection.getTokenObject(x.tokenId));1508 return this.helper.util.extractTokensFromCreationResult(creationResult).tokens.map((x: IToken) => collection.getTokenObject(x.tokenId));1534 }1509 }153515101536 /**1511 /**1539 * @param collectionId ID of collection1514 * @param collectionId ID of collection1540 * @param owner tokens owner1515 * @param owner tokens owner1541 * @param tokens array of tokens with properties and pieces1516 * @param tokens array of tokens with properties and pieces1542 * @param label 1543 * @example mintMultipleTokensWithOneOwner(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq..."}, [{pieces: 100000n, properties: [{key: "gender", value: "male"}]}]);1517 * @example mintMultipleTokensWithOneOwner(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq..."}, [{pieces: 100000n, properties: [{key: "gender", value: "male"}]}]);1544 * @returns array of newly created RFT tokens1518 * @returns array of newly created RFT tokens1545 */1519 */1546 async mintMultipleTokensWithOneOwner(signer: TSigner, collectionId: number, owner: ICrossAccountId, tokens: {pieces: bigint, properties?: IProperty[]}[], label?: string): Promise<UniqueRFTToken[]> {1520 async mintMultipleTokensWithOneOwner(signer: TSigner, collectionId: number, owner: ICrossAccountId, tokens: {pieces: bigint, properties?: IProperty[]}[]): Promise<UniqueRFTToken[]> {1547 if(typeof label === 'undefined') label = `collection #${collectionId}`;1548 const rawTokens = [];1521 const rawTokens = [];1549 for (const token of tokens) {1522 for (const token of tokens) {1550 const raw = {ReFungible: {pieces: token.pieces, properties: token.properties}};1523 const raw = {ReFungible: {pieces: token.pieces, properties: token.properties}};1553 const creationResult = await this.helper.executeExtrinsic(1526 const creationResult = await this.helper.executeExtrinsic(1554 signer,1527 signer,1555 'api.tx.unique.createMultipleItems', [collectionId, owner, rawTokens],1528 'api.tx.unique.createMultipleItems', [collectionId, owner, rawTokens],1556 true, `Unable to mint RFT tokens for ${label}`,1529 true,1557 );1530 );1558 const collection = this.getCollectionObject(collectionId);1531 const collection = this.getCollectionObject(collectionId);1559 return this.helper.util.extractTokensFromCreationResult(creationResult, label).tokens.map((x: IToken) => collection.getTokenObject(x.tokenId));1532 return this.helper.util.extractTokensFromCreationResult(creationResult).tokens.map((x: IToken) => collection.getTokenObject(x.tokenId));1560 }1533 }156115341562 /**1535 /**1563 * Destroys a concrete instance of RFT.1536 * Destroys a concrete instance of RFT.1564 * @param signer keyring of signer1537 * @param signer keyring of signer1565 * @param collectionId ID of collection1538 * @param collectionId ID of collection1566 * @param tokenId ID of token1539 * @param tokenId ID of token1567 * @param label 1568 * @param amount number of pieces to be burnt1540 * @param amount number of pieces to be burnt1569 * @example burnToken(aliceKeyring, 10, 5);1541 * @example burnToken(aliceKeyring, 10, 5);1570 * @returns ```true``` and burnt token number is extrinsic success. Otherwise ```false``` and ```null```1542 * @returns ```true``` and burnt token number is extrinsic success. Otherwise ```false``` and ```null```1571 */1543 */1572 async burnToken(signer: IKeyringPair, collectionId: number, tokenId: number, label?: string, amount=100n): Promise<{ success: boolean; token: number | null; }> {1544 async burnToken(signer: IKeyringPair, collectionId: number, tokenId: number, amount=1n): Promise<{ success: boolean; token: number | null; }> {1573 return await super.burnToken(signer, collectionId, tokenId, label, amount);1545 return await super.burnToken(signer, collectionId, tokenId, amount);1574 }1546 }157515471576 /**1548 /**1580 * @param collectionId ID of collection1552 * @param collectionId ID of collection1581 * @param tokenId ID of token1553 * @param tokenId ID of token1582 * @param toAddressObj address to approve1554 * @param toAddressObj address to approve1583 * @param label 1584 * @param amount number of pieces to be approved1555 * @param amount number of pieces to be approved1585 * @example approveToken(aliceKeyring, 10, 5, {Substrate: "5GHoZe9c73RYbVzq..."}, "", 10000n);1556 * @example approveToken(aliceKeyring, 10, 5, {Substrate: "5GHoZe9c73RYbVzq..."}, "", 10000n);1586 * @returns true if the token success, otherwise false1557 * @returns true if the token success, otherwise false1587 */1558 */1588 async approveToken(signer: IKeyringPair, collectionId: number, tokenId: number, toAddressObj: ICrossAccountId, label?: string, amount=100n) {1559 async approveToken(signer: IKeyringPair, collectionId: number, tokenId: number, toAddressObj: ICrossAccountId, amount=1n) {1589 return super.approveToken(signer, collectionId, tokenId, toAddressObj, label, amount);1560 return super.approveToken(signer, collectionId, tokenId, toAddressObj, amount);1590 }1561 }159115621592 /**1563 /**1606 * @param collectionId ID of collection1577 * @param collectionId ID of collection1607 * @param tokenId ID of token1578 * @param tokenId ID of token1608 * @param amount new number of pieces1579 * @param amount new number of pieces1609 * @param label 1610 * @example repartitionToken(aliceKeyring, 10, 5, 12345n);1580 * @example repartitionToken(aliceKeyring, 10, 5, 12345n);1611 * @returns true if the repartion was success, otherwise false1581 * @returns true if the repartion was success, otherwise false1612 */1582 */1613 async repartitionToken(signer: TSigner, collectionId: number, tokenId: number, amount: bigint, label?: string): Promise<boolean> {1583 async repartitionToken(signer: TSigner, collectionId: number, tokenId: number, amount: bigint): Promise<boolean> {1614 if(typeof label === 'undefined') label = `collection #${collectionId}`;1615 const currentAmount = await this.getTokenTotalPieces(collectionId, tokenId);1584 const currentAmount = await this.getTokenTotalPieces(collectionId, tokenId);1616 const repartitionResult = await this.helper.executeExtrinsic(1585 const repartitionResult = await this.helper.executeExtrinsic(1617 signer,1586 signer,1618 'api.tx.unique.repartition', [collectionId, tokenId, amount],1587 'api.tx.unique.repartition', [collectionId, tokenId, amount],1619 true, `Unable to repartition RFT token for ${label}`,1588 true,1620 );1589 );1621 if(currentAmount < amount) return this.helper.util.findCollectionInEvents(repartitionResult.result.events, collectionId, 'common', 'ItemCreated', label);1590 if(currentAmount < amount) return this.helper.util.findCollectionInEvents(repartitionResult.result.events, collectionId, 'common', 'ItemCreated');1622 return this.helper.util.findCollectionInEvents(repartitionResult.result.events, collectionId, 'common', 'ItemDestroyed', label);1591 return this.helper.util.findCollectionInEvents(repartitionResult.result.events, collectionId, 'common', 'ItemDestroyed');1623 }1592 }1624}1593}162515941640 * @param signer keyring of signer1609 * @param signer keyring of signer1641 * @param collectionOptions Collection options1610 * @param collectionOptions Collection options1642 * @param decimalPoints number of token decimals 1611 * @param decimalPoints number of token decimals 1643 * @param errorLabel 1644 * @example1612 * @example1645 * mintCollection(aliceKeyring, {1613 * mintCollection(aliceKeyring, {1646 * name: 'New',1614 * name: 'New',1649 * }, 18)1617 * }, 18)1650 * @returns newly created fungible collection1618 * @returns newly created fungible collection1651 */1619 */1652 async mintCollection(signer: TSigner, collectionOptions: ICollectionCreationOptions, decimalPoints = 0, errorLabel = 'Unable to mint collection'): Promise<UniqueFTCollection> {1620 async mintCollection(signer: TSigner, collectionOptions: ICollectionCreationOptions, decimalPoints = 0): Promise<UniqueFTCollection> {1653 collectionOptions = JSON.parse(JSON.stringify(collectionOptions)) as ICollectionCreationOptions; // Clone object1621 collectionOptions = JSON.parse(JSON.stringify(collectionOptions)) as ICollectionCreationOptions; // Clone object1654 if(collectionOptions.tokenPropertyPermissions) throw Error('Fungible collections has no tokenPropertyPermissions');1622 if(collectionOptions.tokenPropertyPermissions) throw Error('Fungible collections has no tokenPropertyPermissions');1655 collectionOptions.mode = {fungible: decimalPoints};1623 collectionOptions.mode = {fungible: decimalPoints};1659 const creationResult = await this.helper.executeExtrinsic(1627 const creationResult = await this.helper.executeExtrinsic(1660 signer,1628 signer,1661 'api.tx.unique.createCollectionEx', [collectionOptions],1629 'api.tx.unique.createCollectionEx', [collectionOptions],1662 true, errorLabel,1630 true,1663 );1631 );1664 return this.getCollectionObject(this.helper.util.extractCollectionIdFromCreationResult(creationResult, errorLabel));1632 return this.getCollectionObject(this.helper.util.extractCollectionIdFromCreationResult(creationResult));1665 }1633 }166616341667 /**1635 /**1670 * @param collectionId ID of collection1638 * @param collectionId ID of collection1671 * @param owner address owner of new tokens1639 * @param owner address owner of new tokens1672 * @param amount amount of tokens to be meanted1640 * @param amount amount of tokens to be meanted1673 * @param label 1674 * @example mintTokens(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq"}, 1000n);1641 * @example mintTokens(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq"}, 1000n);1675 * @returns ```true``` if extrinsic success, otherwise ```false``` 1642 * @returns ```true``` if extrinsic success, otherwise ```false``` 1676 */1643 */1677 async mintTokens(signer: TSigner, collectionId: number, owner: ICrossAccountId | string, amount: bigint, label?: string): Promise<boolean> {1644 async mintTokens(signer: TSigner, collectionId: number, owner: ICrossAccountId | string, amount: bigint): Promise<boolean> {1678 if(typeof label === 'undefined') label = `collection #${collectionId}`;1679 const creationResult = await this.helper.executeExtrinsic(1645 const creationResult = await this.helper.executeExtrinsic(1680 signer,1646 signer,1681 'api.tx.unique.createItem', [collectionId, (typeof owner === 'string') ? {Substrate: owner} : owner, {1647 'api.tx.unique.createItem', [collectionId, (typeof owner === 'string') ? {Substrate: owner} : owner, {1682 fungible: {1648 fungible: {1683 value: amount,1649 value: amount,1684 },1650 },1685 }],1651 }],1686 true, `Unable to mint fungible tokens for ${label}`,1652 true, // `Unable to mint fungible tokens for ${label}`,1687 );1653 );1688 return this.helper.util.findCollectionInEvents(creationResult.result.events, collectionId, 'common', 'ItemCreated', label);1654 return this.helper.util.findCollectionInEvents(creationResult.result.events, collectionId, 'common', 'ItemCreated');1689 }1655 }169016561691 /**1657 /**1694 * @param collectionId ID of collection1660 * @param collectionId ID of collection1695 * @param owner tokens owner1661 * @param owner tokens owner1696 * @param tokens array of tokens with properties and pieces1662 * @param tokens array of tokens with properties and pieces1697 * @param label 1698 * @returns ```true``` if extrinsic success, otherwise ```false``` 1663 * @returns ```true``` if extrinsic success, otherwise ```false``` 1699 */1664 */1700 async mintMultipleTokensWithOneOwner(signer: TSigner, collectionId: number, owner: ICrossAccountId, tokens: {value: bigint}[], label?: string): Promise<boolean> {1665 async mintMultipleTokensWithOneOwner(signer: TSigner, collectionId: number, owner: ICrossAccountId, tokens: {value: bigint}[]): Promise<boolean> {1701 if(typeof label === 'undefined') label = `collection #${collectionId}`;1702 const rawTokens = [];1666 const rawTokens = [];1703 for (const token of tokens) {1667 for (const token of tokens) {1704 const raw = {Fungible: {Value: token.value}};1668 const raw = {Fungible: {Value: token.value}};1707 const creationResult = await this.helper.executeExtrinsic(1671 const creationResult = await this.helper.executeExtrinsic(1708 signer,1672 signer,1709 'api.tx.unique.createMultipleItems', [collectionId, owner, rawTokens],1673 'api.tx.unique.createMultipleItems', [collectionId, owner, rawTokens],1710 true, `Unable to mint RFT tokens for ${label}`,1674 true,1711 );1675 );1712 return this.helper.util.findCollectionInEvents(creationResult.result.events, collectionId, 'common', 'ItemCreated', label);1676 return this.helper.util.findCollectionInEvents(creationResult.result.events, collectionId, 'common', 'ItemCreated');1713 }1677 }171416781715 /**1679 /**1737 * Transfer tokens to address1701 * Transfer tokens to address1738 * @param signer keyring of signer1702 * @param signer keyring of signer1739 * @param collectionId ID of collection1703 * @param collectionId ID of collection1740 * @param toAddressObj address recepient1704 * @param toAddressObj address recipient1741 * @param amount amount of tokens to be sent1705 * @param amount amount of tokens to be sent1742 * @example transfer(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq..."}, 1000n);1706 * @example transfer(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq..."}, 1000n);1743 * @returns ```true``` if extrinsic success, otherwise ```false``` 1707 * @returns ```true``` if extrinsic success, otherwise ```false``` 1744 */1708 */1745 async transfer(signer: TSigner, collectionId: number, toAddressObj: ICrossAccountId, amount: bigint) {1709 async transfer(signer: TSigner, collectionId: number, toAddressObj: ICrossAccountId, amount=1n) {1746 return await super.transferToken(signer, collectionId, 0, toAddressObj, amount);1710 return await super.transferToken(signer, collectionId, 0, toAddressObj, amount);1747 }1711 }174817121756 * @example transferFrom(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq..."}, {Substrate: "5DfhbVfww7ThF8q6f3ij..."}, 10000n);1720 * @example transferFrom(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq..."}, {Substrate: "5DfhbVfww7ThF8q6f3ij..."}, 10000n);1757 * @returns ```true``` if extrinsic success, otherwise ```false``` 1721 * @returns ```true``` if extrinsic success, otherwise ```false``` 1758 */1722 */1759 async transferFrom(signer: TSigner, collectionId: number, fromAddressObj: ICrossAccountId, toAddressObj: ICrossAccountId, amount: bigint) {1723 async transferFrom(signer: TSigner, collectionId: number, fromAddressObj: ICrossAccountId, toAddressObj: ICrossAccountId, amount=1n) {1760 return await super.transferTokenFrom(signer, collectionId, 0, fromAddressObj, toAddressObj, amount);1724 return await super.transferTokenFrom(signer, collectionId, 0, fromAddressObj, toAddressObj, amount);1761 }1725 }176217261765 * @param signer keyring of signer1729 * @param signer keyring of signer1766 * @param collectionId ID of collection1730 * @param collectionId ID of collection1767 * @param amount amount of tokens to be destroyed1731 * @param amount amount of tokens to be destroyed1768 * @param label 1769 * @example burnTokens(aliceKeyring, 10, 1000n);1732 * @example burnTokens(aliceKeyring, 10, 1000n);1770 * @returns ```true``` if extrinsic success, otherwise ```false``` 1733 * @returns ```true``` if extrinsic success, otherwise ```false``` 1771 */1734 */1772 async burnTokens(signer: IKeyringPair, collectionId: number, amount=100n, label?: string): Promise<boolean> {1735 async burnTokens(signer: IKeyringPair, collectionId: number, amount=1n): Promise<boolean> {1773 return (await super.burnToken(signer, collectionId, 0, label, amount)).success;1736 return (await super.burnToken(signer, collectionId, 0, amount)).success;1774 }1737 }177517381776 /**1739 /**1779 * @param collectionId ID of collection1742 * @param collectionId ID of collection1780 * @param fromAddressObj address on behalf of which tokens will be burnt1743 * @param fromAddressObj address on behalf of which tokens will be burnt1781 * @param amount amount of tokens to be burnt1744 * @param amount amount of tokens to be burnt1782 * @param label 1783 * @example burnTokensFrom(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq..."}, 1000n);1745 * @example burnTokensFrom(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq..."}, 1000n);1784 * @returns ```true``` if extrinsic success, otherwise ```false``` 1746 * @returns ```true``` if extrinsic success, otherwise ```false``` 1785 */1747 */1786 async burnTokensFrom(signer: IKeyringPair, collectionId: number, fromAddressObj: ICrossAccountId, amount=100n, label?: string): Promise<boolean> {1748 async burnTokensFrom(signer: IKeyringPair, collectionId: number, fromAddressObj: ICrossAccountId, amount=1n): Promise<boolean> {1787 return await super.burnTokenFrom(signer, collectionId, fromAddressObj, 0, label, amount);1749 return await super.burnTokenFrom(signer, collectionId, fromAddressObj, 0, amount);1788 }1750 }178917511790 /**1752 /**1803 * @param collectionId ID of collection1765 * @param collectionId ID of collection1804 * @param toAddressObj address to be approved1766 * @param toAddressObj address to be approved1805 * @param amount amount of tokens to be approved1767 * @param amount amount of tokens to be approved1806 * @param label 1807 * @example approveTokens(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq..."}, 1000n)1768 * @example approveTokens(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq..."}, 1000n)1808 * @returns ```true``` if extrinsic success, otherwise ```false``` 1769 * @returns ```true``` if extrinsic success, otherwise ```false``` 1809 */1770 */1810 async approveTokens(signer: IKeyringPair, collectionId: number, toAddressObj: ICrossAccountId, amount=100n, label?: string) {1771 async approveTokens(signer: IKeyringPair, collectionId: number, toAddressObj: ICrossAccountId, amount=1n) {1811 return super.approveToken(signer, collectionId, 0, toAddressObj, label, amount);1772 return super.approveToken(signer, collectionId, 0, toAddressObj, amount);1812 }1773 }181317741814 /**1775 /**1906 /**1867 /**1907 * Transfer tokens to substrate address1868 * Transfer tokens to substrate address1908 * @param signer keyring of signer1869 * @param signer keyring of signer1909 * @param address substrate address of a recepient1870 * @param address substrate address of a recipient1910 * @param amount amount of tokens to be transfered1871 * @param amount amount of tokens to be transfered1911 * @example transferToSubstrate(aliceKeyring, "5GrwvaEF5zXb26Fz...", 100_000_000_000n);1872 * @example transferToSubstrate(aliceKeyring, "5GrwvaEF5zXb26Fz...", 100_000_000_000n);1912 * @returns ```true``` if extrinsic success, otherwise ```false```1873 * @returns ```true``` if extrinsic success, otherwise ```false```1913 */1874 */1914 async transferToSubstrate(signer: TSigner, address: TSubstrateAccount, amount: bigint | string): Promise<boolean> {1875 async transferToSubstrate(signer: TSigner, address: TSubstrateAccount, amount: bigint | string): Promise<boolean> {1915 const result = await this.helper.executeExtrinsic(signer, 'api.tx.balances.transfer', [address, amount], true, `Unable to transfer balance from ${this.helper.getSignerAddress(signer)} to ${address}`);1876 const result = await this.helper.executeExtrinsic(signer, 'api.tx.balances.transfer', [address, amount], true/*, `Unable to transfer balance from ${this.helper.getSignerAddress(signer)} to ${address}`*/);191618771917 let transfer = {from: null, to: null, amount: 0n} as any;1878 let transfer = {from: null, to: null, amount: 0n} as any;1918 result.result.events.forEach(({event: {data, method, section}}) => {1879 result.result.events.forEach(({event: {data, method, section}}) => {203319942034 async getEffectiveLimits() {1995 async getEffectiveLimits() {2035 return await this.helper.collection.getEffectiveLimits(this.collectionId);1996 return await this.helper.collection.getEffectiveLimits(this.collectionId);1997 }19981999 async setSponsor(signer: TSigner, sponsorAddress: TSubstrateAccount) {2000 return await this.helper.collection.setSponsor(signer, this.collectionId, sponsorAddress);2001 }20022003 async confirmSponsorship(signer: TSigner) {2004 return await this.helper.collection.confirmSponsorship(signer, this.collectionId);2036 }2005 }203720062038 async setSponsor(signer: TSigner, sponsorAddress: TSubstrateAccount, label?: string) {2007 async setLimits(signer: TSigner, limits: ICollectionLimits) {2039 return await this.helper.collection.setSponsor(signer, this.collectionId, sponsorAddress, label);2008 return await this.helper.collection.setLimits(signer, this.collectionId, limits);2040 }2009 }204120102042 async confirmSponsorship(signer: TSigner, label?: string) {2011 async changeOwner(signer: TSigner, ownerAddress: TSubstrateAccount) {2043 return await this.helper.collection.confirmSponsorship(signer, this.collectionId, label);2012 return await this.helper.collection.changeOwner(signer, this.collectionId, ownerAddress);2044 }2013 }204520142046 async setLimits(signer: TSigner, limits: ICollectionLimits, label?: string) {2015 async addAdmin(signer: TSigner, adminAddressObj: ICrossAccountId) {2047 return await this.helper.collection.setLimits(signer, this.collectionId, limits, label);2016 return await this.helper.collection.addAdmin(signer, this.collectionId, adminAddressObj);2048 }2017 }204920182050 async changeOwner(signer: TSigner, ownerAddress: TSubstrateAccount, label?: string) {2019 async enableAllowList(signer: TSigner, value = true/*: 'Normal' | 'AllowList' = 'AllowList'*/) {2051 return await this.helper.collection.changeOwner(signer, this.collectionId, ownerAddress, label);2020 return await this.setPermissions(signer, value ? {access: 'AllowList', mintMode: true} : {access: 'Normal'});2052 }2021 }205320222054 async addAdmin(signer: TSigner, adminAddressObj: ICrossAccountId, label?: string) {2023 async addToAllowList(signer: TSigner, addressObj: ICrossAccountId) {2055 return await this.helper.collection.addAdmin(signer, this.collectionId, adminAddressObj, label);2024 return await this.helper.collection.addToAllowList(signer, this.collectionId, addressObj);2056 }2025 }205720262058 async addToAllowList(signer: TSigner, addressObj: ICrossAccountId, label?: string) {2027 async removeFromAllowList(signer: TSigner, addressObj: ICrossAccountId) {2059 return await this.helper.collection.addToAllowList(signer, this.collectionId, addressObj, label);2028 return await this.helper.collection.removeFromAllowList(signer, this.collectionId, addressObj);2060 }2029 }206120302062 async removeAdmin(signer: TSigner, adminAddressObj: ICrossAccountId, label?: string) {2031 async removeAdmin(signer: TSigner, adminAddressObj: ICrossAccountId) {2063 return await this.helper.collection.removeAdmin(signer, this.collectionId, adminAddressObj, label);2032 return await this.helper.collection.removeAdmin(signer, this.collectionId, adminAddressObj);2064 }2033 }206520342066 async setProperties(signer: TSigner, properties: IProperty[], label?: string) {2035 async setProperties(signer: TSigner, properties: IProperty[]) {2067 return await this.helper.collection.setProperties(signer, this.collectionId, properties, label);2036 return await this.helper.collection.setProperties(signer, this.collectionId, properties);2068 }2037 }206920382070 async deleteProperties(signer: TSigner, propertyKeys: string[], label?: string) {2039 async deleteProperties(signer: TSigner, propertyKeys: string[]) {2071 return await this.helper.collection.deleteProperties(signer, this.collectionId, propertyKeys, label);2040 return await this.helper.collection.deleteProperties(signer, this.collectionId, propertyKeys);2072 }2041 }207320422074 async getTokenNextSponsored(tokenId: number, addressObj: ICrossAccountId) {2043 async getTokenNextSponsored(tokenId: number, addressObj: ICrossAccountId) {2075 return await this.helper.collection.getTokenNextSponsored(this.collectionId, tokenId, addressObj);2044 return await this.helper.collection.getTokenNextSponsored(this.collectionId, tokenId, addressObj);2076 }2045 }207720462078 async setPermissions(signer: TSigner, permissions: ICollectionPermissions, label?: string) {2047 async setPermissions(signer: TSigner, permissions: ICollectionPermissions) {2079 return await this.helper.collection.setPermissions(signer, this.collectionId, permissions, label);2048 return await this.helper.collection.setPermissions(signer, this.collectionId, permissions);2080 }2049 }208120502082 async enableNesting(signer: TSigner, permissions: INestingPermissions, label?: string) {2051 async enableNesting(signer: TSigner, permissions: INestingPermissions) {2083 return await this.helper.collection.enableNesting(signer, this.collectionId, permissions, label);2052 return await this.helper.collection.enableNesting(signer, this.collectionId, permissions);2084 }2053 }208520542086 async disableNesting(signer: TSigner, label?: string) {2055 async disableNesting(signer: TSigner) {2087 return await this.helper.collection.disableNesting(signer, this.collectionId, label);2056 return await this.helper.collection.disableNesting(signer, this.collectionId);2088 }2057 }208920582090 async burn(signer: TSigner, label?: string) {2059 async burn(signer: TSigner) {2091 return await this.helper.collection.burn(signer, this.collectionId, label);2060 return await this.helper.collection.burn(signer, this.collectionId);2092 }2061 }2093}2062}209420632103 }2072 }210420732105 async getToken(tokenId: number, blockHashAt?: string) {2074 async getToken(tokenId: number, blockHashAt?: string) {2106 return await this.helper.nft.getToken(this.collectionId, tokenId, blockHashAt);2075 return await this.helper.nft.getToken(this.collectionId, tokenId, [], blockHashAt);2107 }2076 }210820772109 async getTokenOwner(tokenId: number, blockHashAt?: string) {2078 async getTokenOwner(tokenId: number, blockHashAt?: string) {2126 return await this.helper.nft.transferTokenFrom(signer, this.collectionId, tokenId, fromAddressObj, toAddressObj);2095 return await this.helper.nft.transferTokenFrom(signer, this.collectionId, tokenId, fromAddressObj, toAddressObj);2127 }2096 }212820972129 async approveToken(signer: TSigner, tokenId: number, toAddressObj: ICrossAccountId, label?: string) {2098 async approveToken(signer: TSigner, tokenId: number, toAddressObj: ICrossAccountId) {2130 return await this.helper.nft.approveToken(signer, this.collectionId, tokenId, toAddressObj, label);2099 return await this.helper.nft.approveToken(signer, this.collectionId, tokenId, toAddressObj);2131 }2100 }213221012133 async isTokenApproved(tokenId: number, toAddressObj: ICrossAccountId) {2102 async isTokenApproved(tokenId: number, toAddressObj: ICrossAccountId) {2134 return await this.helper.nft.isTokenApproved(this.collectionId, tokenId, toAddressObj);2103 return await this.helper.nft.isTokenApproved(this.collectionId, tokenId, toAddressObj);2135 }2104 }213621052137 async mintToken(signer: TSigner, owner: ICrossAccountId, properties?: IProperty[], label?: string) {2106 async mintToken(signer: TSigner, owner: ICrossAccountId, properties?: IProperty[]) {2138 return await this.helper.nft.mintToken(signer, {collectionId: this.collectionId, owner, properties}, label);2107 return await this.helper.nft.mintToken(signer, {collectionId: this.collectionId, owner, properties});2139 }2108 }214021092141 async mintMultipleTokens(signer: TSigner, tokens: {owner: ICrossAccountId, properties?: IProperty[]}[], label?: string) {2110 async mintMultipleTokens(signer: TSigner, tokens: {owner: ICrossAccountId, properties?: IProperty[]}[]) {2142 return await this.helper.nft.mintMultipleTokens(signer, this.collectionId, tokens, label);2111 return await this.helper.nft.mintMultipleTokens(signer, this.collectionId, tokens);2143 }2112 }214421132145 async burnToken(signer: TSigner, tokenId: number, label?: string) {2114 async burnToken(signer: TSigner, tokenId: number) {2146 return await this.helper.nft.burnToken(signer, this.collectionId, tokenId, label);2115 return await this.helper.nft.burnToken(signer, this.collectionId, tokenId);2147 }2116 }214821172149 async setTokenProperties(signer: TSigner, tokenId: number, properties: IProperty[], label?: string) {2118 async setTokenProperties(signer: TSigner, tokenId: number, properties: IProperty[]) {2150 return await this.helper.nft.setTokenProperties(signer, this.collectionId, tokenId, properties, label);2119 return await this.helper.nft.setTokenProperties(signer, this.collectionId, tokenId, properties);2151 }2120 }215221212153 async deleteTokenProperties(signer: TSigner, tokenId: number, propertyKeys: string[], label?: string) {2122 async deleteTokenProperties(signer: TSigner, tokenId: number, propertyKeys: string[]) {2154 return await this.helper.nft.deleteTokenProperties(signer, this.collectionId, tokenId, propertyKeys, label);2123 return await this.helper.nft.deleteTokenProperties(signer, this.collectionId, tokenId, propertyKeys);2155 }2124 }215621252157 async setTokenPropertyPermissions(signer: TSigner, permissions: ITokenPropertyPermission[], label?: string) {2126 async setTokenPropertyPermissions(signer: TSigner, permissions: ITokenPropertyPermission[]) {2158 return await this.helper.nft.setTokenPropertyPermissions(signer, this.collectionId, permissions, label);2127 return await this.helper.nft.setTokenPropertyPermissions(signer, this.collectionId, permissions);2159 }2128 }216021292161 async nestToken(signer: TSigner, tokenId: number, toTokenObj: IToken, label?: string) {2130 async nestToken(signer: TSigner, tokenId: number, toTokenObj: IToken) {2162 return await this.helper.nft.nestToken(signer, {collectionId: this.collectionId, tokenId}, toTokenObj, label);2131 return await this.helper.nft.nestToken(signer, {collectionId: this.collectionId, tokenId}, toTokenObj);2163 }2132 }216421332165 async unnestToken(signer: TSigner, tokenId: number, fromTokenObj: IToken, toAddressObj: ICrossAccountId, label?: string) {2134 async unnestToken(signer: TSigner, tokenId: number, fromTokenObj: IToken, toAddressObj: ICrossAccountId) {2166 return await this.helper.nft.unnestToken(signer, {collectionId: this.collectionId, tokenId}, fromTokenObj, toAddressObj, label);2135 return await this.helper.nft.unnestToken(signer, {collectionId: this.collectionId, tokenId}, fromTokenObj, toAddressObj);2167 }2136 }2168}2137}216921382189 return await this.helper.rft.getTokenTotalPieces(this.collectionId, tokenId);2158 return await this.helper.rft.getTokenTotalPieces(this.collectionId, tokenId);2190 }2159 }219121602192 async transferToken(signer: TSigner, tokenId: number, addressObj: ICrossAccountId, amount=100n) {2161 async transferToken(signer: TSigner, tokenId: number, addressObj: ICrossAccountId, amount=1n) {2193 return await this.helper.rft.transferToken(signer, this.collectionId, tokenId, addressObj, amount);2162 return await this.helper.rft.transferToken(signer, this.collectionId, tokenId, addressObj, amount);2194 }2163 }219521642196 async transferTokenFrom(signer: TSigner, tokenId: number, fromAddressObj: ICrossAccountId, toAddressObj: ICrossAccountId, amount=100n) {2165 async transferTokenFrom(signer: TSigner, tokenId: number, fromAddressObj: ICrossAccountId, toAddressObj: ICrossAccountId, amount=1n) {2197 return await this.helper.rft.transferTokenFrom(signer, this.collectionId, tokenId, fromAddressObj, toAddressObj, amount);2166 return await this.helper.rft.transferTokenFrom(signer, this.collectionId, tokenId, fromAddressObj, toAddressObj, amount);2198 }2167 }219921682200 async approveToken(signer: TSigner, tokenId: number, toAddressObj: ICrossAccountId, amount=100n, label?: string) {2169 async approveToken(signer: TSigner, tokenId: number, toAddressObj: ICrossAccountId, amount=1n) {2201 return await this.helper.rft.approveToken(signer, this.collectionId, tokenId, toAddressObj, label, amount);2170 return await this.helper.rft.approveToken(signer, this.collectionId, tokenId, toAddressObj, amount);2202 }2171 }220321722204 async getTokenApprovedPieces(tokenId: number, fromAddressObj: ICrossAccountId, toAddressObj: ICrossAccountId) {2173 async getTokenApprovedPieces(tokenId: number, fromAddressObj: ICrossAccountId, toAddressObj: ICrossAccountId) {2205 return await this.helper.rft.getTokenApprovedPieces(this.collectionId, tokenId, toAddressObj, fromAddressObj);2174 return await this.helper.rft.getTokenApprovedPieces(this.collectionId, tokenId, toAddressObj, fromAddressObj);2206 }2175 }220721762208 async repartitionToken(signer: TSigner, tokenId: number, amount: bigint, label?: string) {2177 async repartitionToken(signer: TSigner, tokenId: number, amount: bigint) {2209 return await this.helper.rft.repartitionToken(signer, this.collectionId, tokenId, amount, label);2178 return await this.helper.rft.repartitionToken(signer, this.collectionId, tokenId, amount);2210 }2179 }221121802212 async mintToken(signer: TSigner, owner: ICrossAccountId, pieces=100n, properties?: IProperty[], label?: string) {2181 async mintToken(signer: TSigner, owner: ICrossAccountId, pieces=100n, properties?: IProperty[]) {2213 return await this.helper.rft.mintToken(signer, {collectionId: this.collectionId, owner, pieces, properties}, label);2182 return await this.helper.rft.mintToken(signer, {collectionId: this.collectionId, owner, pieces, properties});2214 }2183 }221521842216 async mintMultipleTokens(signer: TSigner, tokens: {owner: ICrossAccountId, pieces: bigint, properties?: IProperty[]}[], label?: string) {2185 async mintMultipleTokens(signer: TSigner, tokens: {owner: ICrossAccountId, pieces: bigint, properties?: IProperty[]}[]) {2217 return await this.helper.rft.mintMultipleTokens(signer, this.collectionId, tokens, label);2186 return await this.helper.rft.mintMultipleTokens(signer, this.collectionId, tokens);2218 }2187 }221921882220 async burnToken(signer: TSigner, tokenId: number, amount=100n, label?: string) {2189 async burnToken(signer: TSigner, tokenId: number, amount=1n) {2221 return await this.helper.rft.burnToken(signer, this.collectionId, tokenId, label, amount);2190 return await this.helper.rft.burnToken(signer, this.collectionId, tokenId, amount);2222 }2191 }222321922224 async setTokenProperties(signer: TSigner, tokenId: number, properties: IProperty[], label?: string) {2193 async setTokenProperties(signer: TSigner, tokenId: number, properties: IProperty[]) {2225 return await this.helper.rft.setTokenProperties(signer, this.collectionId, tokenId, properties, label);2194 return await this.helper.rft.setTokenProperties(signer, this.collectionId, tokenId, properties);2226 }2195 }222721962228 async deleteTokenProperties(signer: TSigner, tokenId: number, propertyKeys: string[], label?: string) {2197 async deleteTokenProperties(signer: TSigner, tokenId: number, propertyKeys: string[]) {2229 return await this.helper.rft.deleteTokenProperties(signer, this.collectionId, tokenId, propertyKeys, label);2198 return await this.helper.rft.deleteTokenProperties(signer, this.collectionId, tokenId, propertyKeys);2230 }2199 }223122002232 async setTokenPropertyPermissions(signer: TSigner, permissions: ITokenPropertyPermission[], label?: string) {2201 async setTokenPropertyPermissions(signer: TSigner, permissions: ITokenPropertyPermission[]) {2233 return await this.helper.rft.setTokenPropertyPermissions(signer, this.collectionId, permissions, label);2202 return await this.helper.rft.setTokenPropertyPermissions(signer, this.collectionId, permissions);2234 }2203 }2235}2204}22362205223722062238class UniqueFTCollection extends UniqueCollectionBase {2207class UniqueFTCollection extends UniqueCollectionBase {2239 async mint(signer: TSigner, owner: ICrossAccountId, amount: bigint, label?: string) {2208 async mint(signer: TSigner, owner: ICrossAccountId, amount: bigint) {2240 return await this.helper.ft.mintTokens(signer, this.collectionId, owner, amount, label);2209 return await this.helper.ft.mintTokens(signer, this.collectionId, owner, amount);2241 }2210 }224222112243 async mintWithOneOwner(signer: TSigner, owner: ICrossAccountId, tokens: {value: bigint}[], label?: string) {2212 async mintWithOneOwner(signer: TSigner, owner: ICrossAccountId, tokens: {value: bigint}[]) {2244 return await this.helper.ft.mintMultipleTokensWithOneOwner(signer, this.collectionId, owner, tokens, label);2213 return await this.helper.ft.mintMultipleTokensWithOneOwner(signer, this.collectionId, owner, tokens);2245 }2214 }224622152247 async getBalance(addressObj: ICrossAccountId) {2216 async getBalance(addressObj: ICrossAccountId) {2252 return await this.helper.ft.getTop10Owners(this.collectionId);2221 return await this.helper.ft.getTop10Owners(this.collectionId);2253 }2222 }225422232255 async transfer(signer: TSigner, toAddressObj: ICrossAccountId, amount: bigint) {2224 async transfer(signer: TSigner, toAddressObj: ICrossAccountId, amount=1n) {2256 return await this.helper.ft.transfer(signer, this.collectionId, toAddressObj, amount);2225 return await this.helper.ft.transfer(signer, this.collectionId, toAddressObj, amount);2257 }2226 }225822272259 async transferFrom(signer: TSigner, fromAddressObj: ICrossAccountId, toAddressObj: ICrossAccountId, amount: bigint) {2228 async transferFrom(signer: TSigner, fromAddressObj: ICrossAccountId, toAddressObj: ICrossAccountId, amount=1n) {2260 return await this.helper.ft.transferFrom(signer, this.collectionId, fromAddressObj, toAddressObj, amount);2229 return await this.helper.ft.transferFrom(signer, this.collectionId, fromAddressObj, toAddressObj, amount);2261 }2230 }226222312263 async burnTokens(signer: TSigner, amount: bigint, label?: string) {2232 async burnTokens(signer: TSigner, amount=1n) {2264 return await this.helper.ft.burnTokens(signer, this.collectionId, amount, label);2233 return await this.helper.ft.burnTokens(signer, this.collectionId, amount);2265 }2234 }226622352267 async burnTokensFrom(signer: TSigner, fromAddressObj: ICrossAccountId, amount: bigint, label?: string) {2236 async burnTokensFrom(signer: TSigner, fromAddressObj: ICrossAccountId, amount=1n) {2268 return await this.helper.ft.burnTokensFrom(signer, this.collectionId, fromAddressObj, amount, label);2237 return await this.helper.ft.burnTokensFrom(signer, this.collectionId, fromAddressObj, amount);2269 }2238 }227022392271 async getTotalPieces() {2240 async getTotalPieces() {2272 return await this.helper.ft.getTotalPieces(this.collectionId);2241 return await this.helper.ft.getTotalPieces(this.collectionId);2273 }2242 }227422432275 async approveTokens(signer: TSigner, toAddressObj: ICrossAccountId, amount=100n, label?: string) {2244 async approveTokens(signer: TSigner, toAddressObj: ICrossAccountId, amount=1n) {2276 return await this.helper.ft.approveTokens(signer, this.collectionId, toAddressObj, amount, label);2245 return await this.helper.ft.approveTokens(signer, this.collectionId, toAddressObj, amount);2277 }2246 }227822472279 async getApprovedTokens(fromAddressObj: ICrossAccountId, toAddressObj: ICrossAccountId) {2248 async getApprovedTokens(fromAddressObj: ICrossAccountId, toAddressObj: ICrossAccountId) {2297 return await this.collection.getTokenNextSponsored(this.tokenId, addressObj);2266 return await this.collection.getTokenNextSponsored(this.tokenId, addressObj);2298 }2267 }229922682300 async setProperties(signer: TSigner, properties: IProperty[], label?: string) {2269 async setProperties(signer: TSigner, properties: IProperty[]) {2301 return await this.collection.setTokenProperties(signer, this.tokenId, properties, label);2270 return await this.collection.setTokenProperties(signer, this.tokenId, properties);2302 }2271 }230322722304 async deleteProperties(signer: TSigner, propertyKeys: string[], label?: string) {2273 async deleteProperties(signer: TSigner, propertyKeys: string[]) {2305 return await this.collection.deleteTokenProperties(signer, this.tokenId, propertyKeys, label);2274 return await this.collection.deleteTokenProperties(signer, this.tokenId, propertyKeys);2306 }2275 }2307}2276}230822772331 return await this.collection.getTokenChildren(this.tokenId, blockHashAt);2300 return await this.collection.getTokenChildren(this.tokenId, blockHashAt);2332 }2301 }233323022334 async nest(signer: TSigner, toTokenObj: IToken, label?: string) {2303 async nest(signer: TSigner, toTokenObj: IToken) {2335 return await this.collection.nestToken(signer, this.tokenId, toTokenObj, label);2304 return await this.collection.nestToken(signer, this.tokenId, toTokenObj);2336 }2305 }233723062338 async unnest(signer: TSigner, fromTokenObj: IToken, toAddressObj: ICrossAccountId, label?: string) {2307 async unnest(signer: TSigner, fromTokenObj: IToken, toAddressObj: ICrossAccountId) {2339 return await this.collection.unnestToken(signer, this.tokenId, fromTokenObj, toAddressObj, label);2308 return await this.collection.unnestToken(signer, this.tokenId, fromTokenObj, toAddressObj);2340 }2309 }234123102342 async transfer(signer: TSigner, addressObj: ICrossAccountId) {2311 async transfer(signer: TSigner, addressObj: ICrossAccountId) {2347 return await this.collection.transferTokenFrom(signer, this.tokenId, fromAddressObj, toAddressObj);2316 return await this.collection.transferTokenFrom(signer, this.tokenId, fromAddressObj, toAddressObj);2348 }2317 }234923182350 async approve(signer: TSigner, toAddressObj: ICrossAccountId, label?: string) {2319 async approve(signer: TSigner, toAddressObj: ICrossAccountId) {2351 return await this.collection.approveToken(signer, this.tokenId, toAddressObj, label);2320 return await this.collection.approveToken(signer, this.tokenId, toAddressObj);2352 }2321 }235323222354 async isApproved(toAddressObj: ICrossAccountId) {2323 async isApproved(toAddressObj: ICrossAccountId) {2355 return await this.collection.isTokenApproved(this.tokenId, toAddressObj);2324 return await this.collection.isTokenApproved(this.tokenId, toAddressObj);2356 }2325 }235723262358 async burn(signer: TSigner, label?: string) {2327 async burn(signer: TSigner) {2359 return await this.collection.burnToken(signer, this.tokenId, label);2328 return await this.collection.burnToken(signer, this.tokenId);2360 }2329 }2361}2330}236223312380 return await this.collection.getTokenTotalPieces(this.tokenId);2349 return await this.collection.getTokenTotalPieces(this.tokenId);2381 }2350 }238223512383 async transfer(signer: TSigner, addressObj: ICrossAccountId, amount=100n) {2352 async transfer(signer: TSigner, addressObj: ICrossAccountId, amount=1n) {2384 return await this.collection.transferToken(signer, this.tokenId, addressObj, amount);2353 return await this.collection.transferToken(signer, this.tokenId, addressObj, amount);2385 }2354 }238623552387 async transferFrom(signer: TSigner, fromAddressObj: ICrossAccountId, toAddressObj: ICrossAccountId, amount=100n) {2356 async transferFrom(signer: TSigner, fromAddressObj: ICrossAccountId, toAddressObj: ICrossAccountId, amount=1n) {2388 return await this.collection.transferTokenFrom(signer, this.tokenId, fromAddressObj, toAddressObj, amount);2357 return await this.collection.transferTokenFrom(signer, this.tokenId, fromAddressObj, toAddressObj, amount);2389 }2358 }239023592391 async approve(signer: TSigner, toAddressObj: ICrossAccountId, amount=100n, label?: string) {2360 async approve(signer: TSigner, toAddressObj: ICrossAccountId, amount=1n) {2392 return await this.collection.approveToken(signer, this.tokenId, toAddressObj, amount, label);2361 return await this.collection.approveToken(signer, this.tokenId, toAddressObj, amount);2393 }2362 }239423632395 async getApprovedPieces(fromAddressObj: ICrossAccountId, toAccountObj: ICrossAccountId) {2364 async getApprovedPieces(fromAddressObj: ICrossAccountId, toAccountObj: ICrossAccountId) {2396 return await this.collection.getTokenApprovedPieces(this.tokenId, fromAddressObj, toAccountObj);2365 return await this.collection.getTokenApprovedPieces(this.tokenId, fromAddressObj, toAccountObj);2397 }2366 }239823672399 async repartition(signer: TSigner, amount: bigint, label?: string) {2368 async repartition(signer: TSigner, amount: bigint) {2400 return await this.collection.repartitionToken(signer, this.tokenId, amount, label);2369 return await this.collection.repartitionToken(signer, this.tokenId, amount);2401 }2370 }240223712403 async burn(signer: TSigner, amount=100n, label?: string) {2372 async burn(signer: TSigner, amount=1n) {2404 return await this.collection.burnToken(signer, this.tokenId, amount, label);2373 return await this.collection.burnToken(signer, this.tokenId, amount);2405 }2374 }2406}2375}