difftreelog
test(refungible-pallet) add tests for repartition events
in: master
3 files changed
tests/src/eth/reFungibleToken.test.tsdiffbeforeafterboth--- a/tests/src/eth/reFungibleToken.test.ts
+++ b/tests/src/eth/reFungibleToken.test.ts
@@ -239,10 +239,69 @@
expect(+await contract.methods.balanceOf(owner).call()).to.be.equal(0);
expect(+await contract.methods.balanceOf(receiver).call()).to.be.equal(200);
- await contract.methods.repartition(150).send({from: receiver});
+ const result = await contract.methods.repartition(150).send({from: receiver});
+ console.log(result.events);
await expect(contract.methods.transfer(owner, 160).send({from: receiver})).to.eventually.be.rejected;
expect(+await contract.methods.balanceOf(receiver).call()).to.be.equal(150);
});
+
+ itWeb3('Can repartition with increased amount', async ({web3, api, privateKeyWrapper}) => {
+ const alice = privateKeyWrapper('//Alice');
+
+ const collectionId = (await createCollection(api, alice, {name: 'token name', mode: {type: 'ReFungible'}})).collectionId;
+
+ const owner = createEthAccount(web3);
+ await transferBalanceToEth(api, alice, owner);
+
+ const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n, {Ethereum: owner})).itemId;
+
+ const address = tokenIdToAddress(collectionId, tokenId);
+ const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: owner, ...GAS_ARGS});
+
+ const result = await contract.methods.repartition(200).send();
+ const events = normalizeEvents(result.events);
+
+ expect(events).to.include.deep.members([
+ {
+ address,
+ event: 'Transfer',
+ args: {
+ from: '0x0000000000000000000000000000000000000000',
+ to: owner,
+ value: '100',
+ },
+ },
+ ]);
+ });
+
+ itWeb3('Can repartition with decreased amount', async ({web3, api, privateKeyWrapper}) => {
+ const alice = privateKeyWrapper('//Alice');
+
+ const collectionId = (await createCollection(api, alice, {name: 'token name', mode: {type: 'ReFungible'}})).collectionId;
+
+ const owner = createEthAccount(web3);
+ await transferBalanceToEth(api, alice, owner);
+
+ const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n, {Ethereum: owner})).itemId;
+
+ const address = tokenIdToAddress(collectionId, tokenId);
+ const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: owner, ...GAS_ARGS});
+
+ const result = await contract.methods.repartition(50).send();
+ const events = normalizeEvents(result.events);
+
+ expect(events).to.include.deep.members([
+ {
+ address,
+ event: 'Transfer',
+ args: {
+ from: owner,
+ to: '0x0000000000000000000000000000000000000000',
+ value: '50',
+ },
+ },
+ ]);
+ });
});
describe('Refungible: Fees', () => {
tests/src/refungible.test.tsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {default as usingApi, executeTransaction} from './substrate/substrate-api';18import {IKeyringPair} from '@polkadot/types/types';19import {20 createCollectionExpectSuccess,21 getBalance,22 createMultipleItemsExpectSuccess,23 isTokenExists,24 getLastTokenId,25 getAllowance,26 approve,27 transferFrom,28 createCollection,29 createRefungibleToken,30 transfer,31 burnItem,32 repartitionRFT,33 createCollectionWithPropsExpectSuccess,34 getDetailedCollectionInfo,35} from './util/helpers';3637import chai from 'chai';38import chaiAsPromised from 'chai-as-promised';39chai.use(chaiAsPromised);40const expect = chai.expect;4142let alice: IKeyringPair;43let bob: IKeyringPair;4445describe('integration test: Refungible functionality:', () => {46 before(async () => {47 await usingApi(async (api, privateKeyWrapper) => {48 alice = privateKeyWrapper('//Alice');49 bob = privateKeyWrapper('//Bob');50 });51 });5253 it('Create refungible collection and token', async () => {54 await usingApi(async api => {55 const createCollectionResult = await createCollection(api, alice, {mode: {type: 'ReFungible'}});56 expect(createCollectionResult.success).to.be.true; 57 const collectionId = createCollectionResult.collectionId;5859 const itemCountBefore = await getLastTokenId(api, collectionId);60 const result = await createRefungibleToken(api, alice, collectionId, 100n);6162 const itemCountAfter = await getLastTokenId(api, collectionId);6364 // What to expect65 // tslint:disable-next-line:no-unused-expression66 expect(result.success).to.be.true;67 expect(itemCountAfter).to.be.equal(itemCountBefore + 1);68 expect(collectionId).to.be.equal(result.collectionId);69 expect(itemCountAfter.toString()).to.be.equal(result.itemId.toString());70 });71 });7273 it('Transfer token pieces', async () => {74 await usingApi(async api => {75 const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;76 const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n)).itemId;7778 expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(100n);79 expect(await transfer(api, collectionId, tokenId, alice, bob, 60n)).to.be.true;8081 expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(40n);82 expect(await getBalance(api, collectionId, bob, tokenId)).to.be.equal(60n);83 await expect(transfer(api, collectionId, tokenId, alice, bob, 41n)).to.eventually.be.rejected;84 });85 });8687 it('Create multiple tokens', async () => {88 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});89 const args = [90 {ReFungible: {pieces: 1}},91 {ReFungible: {pieces: 2}},92 {ReFungible: {pieces: 100}},93 ];94 await createMultipleItemsExpectSuccess(alice, collectionId, args);9596 await usingApi(async api => { 97 const tokenId = await getLastTokenId(api, collectionId);98 expect(tokenId).to.be.equal(3);99 expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(100n);100 });101 });102103 it('Burn some pieces', async () => {104 await usingApi(async api => { 105 const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;106 const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n)).itemId;107 expect(await isTokenExists(api, collectionId, tokenId)).to.be.true;108 expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(100n);109 expect(await burnItem(api, alice, collectionId, tokenId, 99n)).to.be.true;110 expect(await isTokenExists(api, collectionId, tokenId)).to.be.true;111 expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(1n);112 });113 });114115 it('Burn all pieces', async () => {116 await usingApi(async api => { 117 const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;118 const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n)).itemId;119 expect(await isTokenExists(api, collectionId, tokenId)).to.be.true;120 expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(100n);121 expect(await burnItem(api, alice, collectionId, tokenId, 100n)).to.be.true;122 expect(await isTokenExists(api, collectionId, tokenId)).to.be.false;123 });124 });125126 it('Burn some pieces for multiple users', async () => {127 await usingApi(async api => { 128 const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;129 const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n)).itemId;130 expect(await isTokenExists(api, collectionId, tokenId)).to.be.true;131132 expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(100n);133 expect(await transfer(api, collectionId, tokenId, alice, bob, 60n)).to.be.true;134135 136 expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(40n);137 expect(await getBalance(api, collectionId, bob, tokenId)).to.be.equal(60n);138 expect(await burnItem(api, alice, collectionId, tokenId, 40n)).to.be.true;139140 expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(0n);141 expect(await isTokenExists(api, collectionId, tokenId)).to.be.true;142 expect(await burnItem(api, bob, collectionId, tokenId, 59n)).to.be.true;143144 expect(await getBalance(api, collectionId, bob, tokenId)).to.be.equal(1n);145 expect(await isTokenExists(api, collectionId, tokenId)).to.be.true;146 expect(await burnItem(api, bob, collectionId, tokenId, 1n)).to.be.true;147 148 expect(await isTokenExists(api, collectionId, tokenId)).to.be.false;149 });150 });151152 it('Set allowance for token', async () => {153 await usingApi(async api => {154 const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;155 const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n)).itemId;156157 expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(100n);158159 expect(await approve(api, collectionId, tokenId, alice, bob, 60n)).to.be.true;160 expect(await getAllowance(api, collectionId, alice, bob, tokenId)).to.be.equal(60n);161162 expect(await transferFrom(api, collectionId, tokenId, bob, alice, bob, 20n)).to.be.true;163 expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(80n);164 expect(await getBalance(api, collectionId, bob, tokenId)).to.be.equal(20n);165 expect(await getAllowance(api, collectionId, alice, bob, tokenId)).to.be.equal(40n);166 });167 });168169 it('Repartition', async () => {170 await usingApi(async api => {171 const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;172 const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n)).itemId;173174 expect(await repartitionRFT(api, collectionId, alice, tokenId, 200n)).to.be.true;175 expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(200n);176177 expect(await transfer(api, collectionId, tokenId, alice, bob, 110n)).to.be.true;178 expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(90n);179 expect(await getBalance(api, collectionId, bob, tokenId)).to.be.equal(110n);180181 await expect(repartitionRFT(api, collectionId, alice, tokenId, 80n)).to.eventually.be.rejected;182183 expect(await transfer(api, collectionId, tokenId, alice, bob, 90n)).to.be.true;184 expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(0n);185 expect(await getBalance(api, collectionId, bob, tokenId)).to.be.equal(200n);186187 expect(await repartitionRFT(api, collectionId, bob, tokenId, 150n)).to.be.true;188 await expect(transfer(api, collectionId, tokenId, bob, alice, 160n)).to.eventually.be.rejected;189 });190 });191});192193describe('Test Refungible properties:', () => {194 before(async () => {195 await usingApi(async (api, privateKeyWrapper) => {196 alice = privateKeyWrapper('//Alice');197 bob = privateKeyWrapper('//Bob');198 });199 });200 201 it('Сreate new collection with properties', async () => {202 await usingApi(async api => {203 const properties = [{key: 'key1', value: 'val1'}];204 const propertyPermissions = [{key: 'key1', permission: {tokenOwner: true, mutable: false, collectionAdmin: true}}];205 const collectionId = await createCollectionWithPropsExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'ReFungible'},206 properties: properties,207 propPerm: propertyPermissions, 208 });209 const collection = (await getDetailedCollectionInfo(api, collectionId))!;210 expect(collection.properties.toHuman()).to.be.deep.equal(properties);211 expect(collection.tokenPropertyPermissions.toHuman()).to.be.deep.equal(propertyPermissions);212 });213 });214});1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {default as usingApi, submitTransactionAsync} from './substrate/substrate-api';18import {IKeyringPair} from '@polkadot/types/types';19import {20 createCollectionExpectSuccess,21 getBalance,22 createMultipleItemsExpectSuccess,23 isTokenExists,24 getLastTokenId,25 getAllowance,26 approve,27 transferFrom,28 createCollection,29 createRefungibleToken,30 transfer,31 burnItem,32 repartitionRFT,33 createCollectionWithPropsExpectSuccess,34 getDetailedCollectionInfo,35 getCreateItemsResult,36 getDestroyItemsResult,37} from './util/helpers';3839import chai from 'chai';40import chaiAsPromised from 'chai-as-promised';41chai.use(chaiAsPromised);42const expect = chai.expect;4344let alice: IKeyringPair;45let bob: IKeyringPair;4647describe('integration test: Refungible functionality:', () => {48 before(async () => {49 await usingApi(async (api, privateKeyWrapper) => {50 alice = privateKeyWrapper('//Alice');51 bob = privateKeyWrapper('//Bob');52 });53 });5455 it('Create refungible collection and token', async () => {56 await usingApi(async api => {57 const createCollectionResult = await createCollection(api, alice, {mode: {type: 'ReFungible'}});58 expect(createCollectionResult.success).to.be.true; 59 const collectionId = createCollectionResult.collectionId;6061 const itemCountBefore = await getLastTokenId(api, collectionId);62 const result = await createRefungibleToken(api, alice, collectionId, 100n);6364 const itemCountAfter = await getLastTokenId(api, collectionId);6566 // What to expect67 // tslint:disable-next-line:no-unused-expression68 expect(result.success).to.be.true;69 expect(itemCountAfter).to.be.equal(itemCountBefore + 1);70 expect(collectionId).to.be.equal(result.collectionId);71 expect(itemCountAfter.toString()).to.be.equal(result.itemId.toString());72 });73 });7475 it('Transfer token pieces', async () => {76 await usingApi(async api => {77 const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;78 const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n)).itemId;7980 expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(100n);81 expect(await transfer(api, collectionId, tokenId, alice, bob, 60n)).to.be.true;8283 expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(40n);84 expect(await getBalance(api, collectionId, bob, tokenId)).to.be.equal(60n);85 await expect(transfer(api, collectionId, tokenId, alice, bob, 41n)).to.eventually.be.rejected;86 });87 });8889 it('Create multiple tokens', async () => {90 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});91 const args = [92 {ReFungible: {pieces: 1}},93 {ReFungible: {pieces: 2}},94 {ReFungible: {pieces: 100}},95 ];96 await createMultipleItemsExpectSuccess(alice, collectionId, args);9798 await usingApi(async api => { 99 const tokenId = await getLastTokenId(api, collectionId);100 expect(tokenId).to.be.equal(3);101 expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(100n);102 });103 });104105 it('Burn some pieces', async () => {106 await usingApi(async api => { 107 const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;108 const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n)).itemId;109 expect(await isTokenExists(api, collectionId, tokenId)).to.be.true;110 expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(100n);111 expect(await burnItem(api, alice, collectionId, tokenId, 99n)).to.be.true;112 expect(await isTokenExists(api, collectionId, tokenId)).to.be.true;113 expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(1n);114 });115 });116117 it('Burn all pieces', async () => {118 await usingApi(async api => { 119 const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;120 const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n)).itemId;121 expect(await isTokenExists(api, collectionId, tokenId)).to.be.true;122 expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(100n);123 expect(await burnItem(api, alice, collectionId, tokenId, 100n)).to.be.true;124 expect(await isTokenExists(api, collectionId, tokenId)).to.be.false;125 });126 });127128 it('Burn some pieces for multiple users', async () => {129 await usingApi(async api => { 130 const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;131 const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n)).itemId;132 expect(await isTokenExists(api, collectionId, tokenId)).to.be.true;133134 expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(100n);135 expect(await transfer(api, collectionId, tokenId, alice, bob, 60n)).to.be.true;136137 138 expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(40n);139 expect(await getBalance(api, collectionId, bob, tokenId)).to.be.equal(60n);140 expect(await burnItem(api, alice, collectionId, tokenId, 40n)).to.be.true;141142 expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(0n);143 expect(await isTokenExists(api, collectionId, tokenId)).to.be.true;144 expect(await burnItem(api, bob, collectionId, tokenId, 59n)).to.be.true;145146 expect(await getBalance(api, collectionId, bob, tokenId)).to.be.equal(1n);147 expect(await isTokenExists(api, collectionId, tokenId)).to.be.true;148 expect(await burnItem(api, bob, collectionId, tokenId, 1n)).to.be.true;149 150 expect(await isTokenExists(api, collectionId, tokenId)).to.be.false;151 });152 });153154 it('Set allowance for token', async () => {155 await usingApi(async api => {156 const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;157 const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n)).itemId;158159 expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(100n);160161 expect(await approve(api, collectionId, tokenId, alice, bob, 60n)).to.be.true;162 expect(await getAllowance(api, collectionId, alice, bob, tokenId)).to.be.equal(60n);163164 expect(await transferFrom(api, collectionId, tokenId, bob, alice, bob, 20n)).to.be.true;165 expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(80n);166 expect(await getBalance(api, collectionId, bob, tokenId)).to.be.equal(20n);167 expect(await getAllowance(api, collectionId, alice, bob, tokenId)).to.be.equal(40n);168 });169 });170171 it('Repartition', async () => {172 await usingApi(async api => {173 const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;174 const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n)).itemId;175176 expect(await repartitionRFT(api, collectionId, alice, tokenId, 200n)).to.be.true;177 expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(200n);178179 expect(await transfer(api, collectionId, tokenId, alice, bob, 110n)).to.be.true;180 expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(90n);181 expect(await getBalance(api, collectionId, bob, tokenId)).to.be.equal(110n);182183 await expect(repartitionRFT(api, collectionId, alice, tokenId, 80n)).to.eventually.be.rejected;184185 expect(await transfer(api, collectionId, tokenId, alice, bob, 90n)).to.be.true;186 expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(0n);187 expect(await getBalance(api, collectionId, bob, tokenId)).to.be.equal(200n);188189 expect(await repartitionRFT(api, collectionId, bob, tokenId, 150n)).to.be.true;190 await expect(transfer(api, collectionId, tokenId, bob, alice, 160n)).to.eventually.be.rejected;191 });192 });193194 it('Repartition with increased amount', async () => {195 await usingApi(async api => {196 const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;197 const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n)).itemId;198199 const tx = api.tx.unique.repartition(collectionId, tokenId, 200n);200 const events = await submitTransactionAsync(alice, tx);201 const substrateEvents = getCreateItemsResult(events);202 expect(substrateEvents).to.include.deep.members([203 {204 success: true,205 collectionId,206 itemId: tokenId,207 recipient: {Substrate: alice.address},208 amount: 100,209 },210 ]);211 });212 });213214 it('Repartition with decreased amount', async () => {215 await usingApi(async api => {216 const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;217 const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n)).itemId;218219 const tx = api.tx.unique.repartition(collectionId, tokenId, 50n);220 const events = await submitTransactionAsync(alice, tx);221 const substrateEvents = getDestroyItemsResult(events);222 expect(substrateEvents).to.include.deep.members([223 {224 success: true,225 collectionId,226 itemId: tokenId,227 owner: {Substrate: alice.address},228 amount: 50,229 },230 ]);231 });232 });233});234235describe('Test Refungible properties:', () => {236 before(async () => {237 await usingApi(async (api, privateKeyWrapper) => {238 alice = privateKeyWrapper('//Alice');239 bob = privateKeyWrapper('//Bob');240 });241 });242 243 it('Сreate new collection with properties', async () => {244 await usingApi(async api => {245 const properties = [{key: 'key1', value: 'val1'}];246 const propertyPermissions = [{key: 'key1', permission: {tokenOwner: true, mutable: false, collectionAdmin: true}}];247 const collectionId = await createCollectionWithPropsExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'ReFungible'},248 properties: properties,249 propPerm: propertyPermissions, 250 });251 const collection = (await getDetailedCollectionInfo(api, collectionId))!;252 expect(collection.properties.toHuman()).to.be.deep.equal(properties);253 expect(collection.tokenPropertyPermissions.toHuman()).to.be.deep.equal(propertyPermissions);254 });255 });256});tests/src/util/helpers.tsdiffbeforeafterboth--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -103,6 +103,15 @@
collectionId: number;
itemId: number;
recipient?: CrossAccountId;
+ amount?: number;
+}
+
+interface DestroyItemResult {
+ success: boolean;
+ collectionId: number;
+ itemId: number;
+ owner: CrossAccountId;
+ amount: number;
}
interface TransferResult {
@@ -220,12 +229,14 @@
const collectionId = parseInt(data[0].toString(), 10);
const itemId = parseInt(data[1].toString(), 10);
const recipient = normalizeAccountId(data[2].toJSON() as any);
+ const amount = parseInt(data[3].toString(), 10);
const itemRes: CreateItemResult = {
success: true,
collectionId,
itemId,
recipient,
+ amount,
};
results.push(itemRes);
@@ -255,6 +266,31 @@
return result;
}
+export function getDestroyItemsResult(events: EventRecord[]): DestroyItemResult[] {
+ const results: DestroyItemResult[] = [];
+
+ const genericResult = getGenericResult<DestroyItemResult[]>(events, 'common', 'ItemDestroyed', (data) => {
+ const collectionId = parseInt(data[0].toString(), 10);
+ const itemId = parseInt(data[1].toString(), 10);
+ const owner = normalizeAccountId(data[2].toJSON() as any);
+ const amount = parseInt(data[3].toString(), 10);
+
+ const itemRes: DestroyItemResult = {
+ success: true,
+ collectionId,
+ itemId,
+ owner,
+ amount,
+ };
+
+ results.push(itemRes);
+ return results;
+ });
+
+ if (!genericResult.success) return [];
+ return results;
+}
+
export function getTransferResult(api: ApiPromise, events: EventRecord[]): TransferResult {
for (const {event} of events) {
if (api.events.common.Transfer.is(event)) {