git.delta.rocks / unique-network / refs/commits / 7b3faa5ce573

difftreelog

CORE-302 Remove unused ABI

Trubnikov Sergey2022-04-26parent: #73ad884.patch.diff
in: master

4 files changed

modifiedtests/src/eth/fungible.test.tsdiffbeforeafterboth
before · tests/src/eth/fungible.test.ts
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 privateKey from '../substrate/privateKey';18import {approveExpectSuccess, createCollectionExpectSuccess, createFungibleItemExpectSuccess, transferExpectSuccess, transferFromExpectSuccess, UNIQUE} from '../util/helpers';19import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, GAS_ARGS, itWeb3, normalizeEvents, recordEthFee, recordEvents, subToEth, transferBalanceToEth} from './util/helpers';20import fungibleAbi from './fungibleAbi.json';21import {expect} from 'chai';2223describe('Fungible: Information getting', () => {24  itWeb3('totalSupply', async ({api, web3}) => {25    const collection = await createCollectionExpectSuccess({26      name: 'token name',27      mode: {type: 'Fungible', decimalPoints: 0},28    });29    const alice = privateKey('//Alice');3031    const caller = await createEthAccountWithBalance(api, web3);3233    await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Substrate: alice.address});3435    const address = collectionIdToAddress(collection);36    const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: caller, ...GAS_ARGS});37    const totalSupply = await contract.methods.totalSupply().call();3839    expect(totalSupply).to.equal('200');40  });4142  itWeb3('balanceOf', async ({api, web3}) => {43    const collection = await createCollectionExpectSuccess({44      name: 'token name',45      mode: {type: 'Fungible', decimalPoints: 0},46    });47    const alice = privateKey('//Alice');4849    const caller = await createEthAccountWithBalance(api, web3);5051    await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: caller});5253    const address = collectionIdToAddress(collection);54    const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: caller, ...GAS_ARGS});55    const balance = await contract.methods.balanceOf(caller).call();5657    expect(balance).to.equal('200');58  });59});6061describe('Fungible: Plain calls', () => {62  itWeb3('Can perform approve()', async ({web3, api}) => {63    const collection = await createCollectionExpectSuccess({64      name: 'token name',65      mode: {type: 'Fungible', decimalPoints: 0},66    });67    const alice = privateKey('//Alice');6869    const owner = await createEthAccountWithBalance(api, web3);7071    await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: owner});7273    const spender = createEthAccount(web3);7475    const address = collectionIdToAddress(collection);76    const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: owner, ...GAS_ARGS});7778    {79      const result = await contract.methods.approve(spender, 100).send({from: owner});80      const events = normalizeEvents(result.events);8182      expect(events).to.be.deep.equal([83        {84          address,85          event: 'Approval',86          args: {87            owner,88            spender,89            value: '100',90          },91        },92      ]);93    }9495    {96      const allowance = await contract.methods.allowance(owner, spender).call();97      expect(+allowance).to.equal(100);98    }99  });100101  itWeb3('Can perform transferFrom()', async ({web3, api}) => {102    const collection = await createCollectionExpectSuccess({103      name: 'token name',104      mode: {type: 'Fungible', decimalPoints: 0},105    });106    const alice = privateKey('//Alice');107108    const owner = createEthAccount(web3);109    await transferBalanceToEth(api, alice, owner);110111    await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: owner});112113    const spender = createEthAccount(web3);114    await transferBalanceToEth(api, alice, spender);115116    const receiver = createEthAccount(web3);117118    const address = collectionIdToAddress(collection);119    const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: owner, ...GAS_ARGS});120121    await contract.methods.approve(spender, 100).send();122123    {124      const result = await contract.methods.transferFrom(owner, receiver, 49).send({from: spender});125      const events = normalizeEvents(result.events);126      expect(events).to.be.deep.equal([127        {128          address,129          event: 'Transfer',130          args: {131            from: owner,132            to: receiver,133            value: '49',134          },135        },136        {137          address,138          event: 'Approval',139          args: {140            owner,141            spender,142            value: '51',143          },144        },145      ]);146    }147148    {149      const balance = await contract.methods.balanceOf(receiver).call();150      expect(+balance).to.equal(49);151    }152153    {154      const balance = await contract.methods.balanceOf(owner).call();155      expect(+balance).to.equal(151);156    }157  });158159  itWeb3('Can perform transfer()', async ({web3, api}) => {160    const collection = await createCollectionExpectSuccess({161      name: 'token name',162      mode: {type: 'Fungible', decimalPoints: 0},163    });164    const alice = privateKey('//Alice');165166    const owner = createEthAccount(web3);167    await transferBalanceToEth(api, alice, owner);168169    await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: owner});170171    const receiver = createEthAccount(web3);172    await transferBalanceToEth(api, alice, receiver);173174    const address = collectionIdToAddress(collection);175    const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: owner, ...GAS_ARGS});176177    {178      const result = await contract.methods.transfer(receiver, 50).send({from: owner});179      const events = normalizeEvents(result.events);180      expect(events).to.be.deep.equal([181        {182          address,183          event: 'Transfer',184          args: {185            from: owner,186            to: receiver,187            value: '50',188          },189        },190      ]);191    }192193    {194      const balance = await contract.methods.balanceOf(owner).call();195      expect(+balance).to.equal(150);196    }197198    {199      const balance = await contract.methods.balanceOf(receiver).call();200      expect(+balance).to.equal(50);201    }202  });203});204205describe('Fungible: Fees', () => {206  itWeb3('approve() call fee is less than 0.2UNQ', async ({web3, api}) => {207    const collection = await createCollectionExpectSuccess({208      mode: {type: 'Fungible', decimalPoints: 0},209    });210    const alice = privateKey('//Alice');211212    const owner = await createEthAccountWithBalance(api, web3);213    const spender = createEthAccount(web3);214215    await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: owner});216217    const address = collectionIdToAddress(collection);218    const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: owner, ...GAS_ARGS});219220    const cost = await recordEthFee(api, owner, () => contract.methods.approve(spender, 100).send({from: owner}));221    expect(cost < BigInt(0.2 * Number(UNIQUE)));222  });223224  itWeb3('transferFrom() call fee is less than 0.2UNQ', async ({web3, api}) => {225    const collection = await createCollectionExpectSuccess({226      mode: {type: 'Fungible', decimalPoints: 0},227    });228    const alice = privateKey('//Alice');229230    const owner = await createEthAccountWithBalance(api, web3);231    const spender = await createEthAccountWithBalance(api, web3);232233    await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: owner});234235    const address = collectionIdToAddress(collection);236    const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: owner, ...GAS_ARGS});237238    await contract.methods.approve(spender, 100).send({from: owner});239240    const cost = await recordEthFee(api, spender, () => contract.methods.transferFrom(owner, spender, 100).send({from: spender}));241    expect(cost < BigInt(0.2 * Number(UNIQUE)));242  });243244  itWeb3('transfer() call fee is less than 0.2UNQ', async ({web3, api}) => {245    const collection = await createCollectionExpectSuccess({246      mode: {type: 'Fungible', decimalPoints: 0},247    });248    const alice = privateKey('//Alice');249250    const owner = await createEthAccountWithBalance(api, web3);251    const receiver = createEthAccount(web3);252253    await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: owner});254255    const address = collectionIdToAddress(collection);256    const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: owner, ...GAS_ARGS});257258    const cost = await recordEthFee(api, owner, () => contract.methods.transfer(receiver, 100).send({from: owner}));259    expect(cost < BigInt(0.2 * Number(UNIQUE)));260  });261});262263describe('Fungible: Substrate calls', () => {264  itWeb3('Events emitted for approve()', async ({web3}) => {265    const collection = await createCollectionExpectSuccess({266      mode: {type: 'Fungible', decimalPoints: 0},267    });268    const alice = privateKey('//Alice');269270    const receiver = createEthAccount(web3);271272    await createFungibleItemExpectSuccess(alice, collection, {Value: 200n});273274    const address = collectionIdToAddress(collection);275    const contract = new web3.eth.Contract(fungibleAbi as any, address);276277    const events = await recordEvents(contract, async () => {278      await approveExpectSuccess(collection, 0, alice, {Ethereum: receiver}, 100);279    });280281    expect(events).to.be.deep.equal([282      {283        address,284        event: 'Approval',285        args: {286          owner: subToEth(alice.address),287          spender: receiver,288          value: '100',289        },290      },291    ]);292  });293294  itWeb3('Events emitted for transferFrom()', async ({web3}) => {295    const collection = await createCollectionExpectSuccess({296      mode: {type: 'Fungible', decimalPoints: 0},297    });298    const alice = privateKey('//Alice');299    const bob = privateKey('//Bob');300301    const receiver = createEthAccount(web3);302303    await createFungibleItemExpectSuccess(alice, collection, {Value: 200n});304    await approveExpectSuccess(collection, 0, alice, bob.address, 100);305306    const address = collectionIdToAddress(collection);307    const contract = new web3.eth.Contract(fungibleAbi as any, address);308309    const events = await recordEvents(contract, async () => {310      await transferFromExpectSuccess(collection, 0, bob, alice, {Ethereum: receiver}, 51, 'Fungible');311    });312313    expect(events).to.be.deep.equal([314      {315        address,316        event: 'Transfer',317        args: {318          from: subToEth(alice.address),319          to: receiver,320          value: '51',321        },322      },323      {324        address,325        event: 'Approval',326        args: {327          owner: subToEth(alice.address),328          spender: subToEth(bob.address),329          value: '49',330        },331      },332    ]);333  });334335  itWeb3('Events emitted for transfer()', async ({web3}) => {336    const collection = await createCollectionExpectSuccess({337      mode: {type: 'Fungible', decimalPoints: 0},338    });339    const alice = privateKey('//Alice');340341    const receiver = createEthAccount(web3);342343    await createFungibleItemExpectSuccess(alice, collection, {Value: 200n});344345    const address = collectionIdToAddress(collection);346    const contract = new web3.eth.Contract(fungibleAbi as any, address);347348    const events = await recordEvents(contract, async () => {349      await transferExpectSuccess(collection, 0, alice, {Ethereum:receiver}, 51, 'Fungible');350    });351352    expect(events).to.be.deep.equal([353      {354        address,355        event: 'Transfer',356        args: {357          from: subToEth(alice.address),358          to: receiver,359          value: '51',360        },361      },362    ]);363  });364});
deletedtests/src/eth/fungibleMetadataAbi.jsondiffbeforeafterboth
--- a/tests/src/eth/fungibleMetadataAbi.json
+++ /dev/null
@@ -1,41 +0,0 @@
-[
-    {
-        "inputs": [],
-        "name": "name",
-        "outputs": [
-            {
-                "internalType": "string",
-                "name": "",
-                "type": "string"
-            }
-        ],
-        "stateMutability": "view",
-        "type": "function"
-    },
-    {
-        "inputs": [],
-        "name": "symbol",
-        "outputs": [
-            {
-                "internalType": "string",
-                "name": "",
-                "type": "string"
-            }
-        ],
-        "stateMutability": "view",
-        "type": "function"
-    },
-    {
-        "inputs": [],
-        "name": "decimals",
-        "outputs": [
-            {
-                "internalType": "uint8",
-                "name": "",
-                "type": "uint8"
-            }
-        ],
-        "stateMutability": "view",
-        "type": "function"
-    }
-]
\ No newline at end of file
deletedtests/src/eth/metadata.test.tsdiffbeforeafterboth
--- a/tests/src/eth/metadata.test.ts
+++ /dev/null
@@ -1,210 +0,0 @@
-// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
-// This file is part of Unique Network.
-
-// Unique Network is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-
-// Unique Network is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-
-// 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 {createCollectionExpectSuccess} from '../util/helpers';
-import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, GAS_ARGS, itWeb3, normalizeEvents} from './util/helpers';
-import fungibleMetadataAbi from './fungibleMetadataAbi.json';
-import privateKey from '../substrate/privateKey';
-import {submitTransactionAsync} from '../substrate/substrate-api';
-import nonFungibleAbi from './nonFungibleAbi.json';
-
-describe('Common metadata', () => {
-  itWeb3('Returns collection name', async ({api, web3}) => {
-    const collection = await createCollectionExpectSuccess({
-      name: 'token name',
-      mode: {type: 'NFT'},
-    });
-    const caller = await createEthAccountWithBalance(api, web3);
-
-    const address = collectionIdToAddress(collection);
-    const contract = new web3.eth.Contract(fungibleMetadataAbi as any, address, {from: caller, ...GAS_ARGS});
-    const name = await contract.methods.name().call();
-
-    expect(name).to.equal('token name');
-  });
-
-  itWeb3('Returns symbol name', async ({api, web3}) => {
-    const collection = await createCollectionExpectSuccess({
-      tokenPrefix: 'TOK',
-      mode: {type: 'NFT'},
-    });
-    const caller = await createEthAccountWithBalance(api, web3);
-
-    const address = collectionIdToAddress(collection);
-    const contract = new web3.eth.Contract(fungibleMetadataAbi as any, address, {from: caller, ...GAS_ARGS});
-    const symbol = await contract.methods.symbol().call();
-
-    expect(symbol).to.equal('TOK');
-  });
-});
-
-describe('Fungible metadata', () => {
-  itWeb3('Returns fungible decimals', async ({api, web3}) => {
-    const collection = await createCollectionExpectSuccess({
-      mode: {type: 'Fungible', decimalPoints: 6},
-    });
-    const caller = await createEthAccountWithBalance(api, web3);
-
-    const address = collectionIdToAddress(collection);
-    const contract = new web3.eth.Contract(fungibleMetadataAbi as any, address, {from: caller, ...GAS_ARGS});
-    const decimals = await contract.methods.decimals().call();
-
-    expect(+decimals).to.equal(6);
-  });
-});
-
-describe('Support ERC721Metadata', () => {
-  itWeb3('Check unsupport ERC721Metadata SchemaVersion::Unique', async ({web3, api}) => {
-    const collectionId = await createCollectionExpectSuccess({
-      mode: {type: 'NFT'},
-      schemaVersion: 'Unique',
-      name: 'some_name',
-      tokenPrefix: 'some_prefix',
-    });
-    const collection = await api.rpc.unique.collectionById(collectionId);
-    expect(collection.isSome).to.be.true;
-    expect(collection.unwrap().schemaVersion.toHuman()).to.be.eq('Unique');
-
-    const alice = privateKey('//Alice');
-
-    const caller = await createEthAccountWithBalance(api, web3);
-    const changeAdminTx = api.tx.unique.addCollectionAdmin(collectionId, {Ethereum: caller});
-    await submitTransactionAsync(alice, changeAdminTx);
-
-    const address = collectionIdToAddress(collectionId);
-    const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});
-
-    expect(await contract.methods.name().call()).to.be.eq('some_name');
-    expect(await contract.methods.symbol().call()).to.be.eq('some_prefix');
-
-    const receiver = createEthAccount(web3);
-    const nextTokenId = await contract.methods.nextTokenId().call();
-    expect(nextTokenId).to.be.equal('1');
-    await expect(contract.methods.mintWithTokenURI(
-      receiver,
-      nextTokenId,
-      'Test URI',
-    ).call({from: caller})).to.be.rejectedWith('Unsupported schema version! Support only ImageURL');
-
-    await expect(contract.methods.mintBulkWithTokenURI(
-      receiver,
-      [
-        [nextTokenId, 'Test URI 0'],
-        [+nextTokenId + 1, 'Test URI 1'],
-        [+nextTokenId + 2, 'Test URI 2'],
-      ],
-    ).call({from: caller})).to.be.rejectedWith('Unsupported schema version! Support only ImageURL');
-  });
-
-  itWeb3('Check support ERC721Metadata for SchemaVersion::ImageURL', async ({web3, api}) => {
-    const collectionId = await createCollectionExpectSuccess({
-      mode: {type: 'NFT'},
-      name: 'some_name',
-      tokenPrefix: 'some_prefix',
-    });
-    const collection = await api.rpc.unique.collectionById(collectionId);
-    expect(collection.isSome).to.be.true;
-    expect(collection.unwrap().schemaVersion.toHuman()).to.be.eq('ImageURL');
-
-    const alice = privateKey('//Alice');
-
-    const caller = await createEthAccountWithBalance(api, web3);
-    const changeAdminTx = api.tx.unique.addCollectionAdmin(collectionId, {Ethereum: caller});
-    await submitTransactionAsync(alice, changeAdminTx);
-
-    const address = collectionIdToAddress(collectionId);
-    const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});
-    
-    expect(await contract.methods.name().call()).to.be.eq('some_name');
-    expect(await contract.methods.symbol().call()).to.be.eq('some_prefix');
-
-    const receiver = createEthAccount(web3);
-    { // mintWithTokenURI
-      const nextTokenId = await contract.methods.nextTokenId().call();
-      expect(nextTokenId).to.be.equal('1');
-      const result = await contract.methods.mintWithTokenURI(
-        receiver,
-        nextTokenId,
-        'Test URI',
-      ).send({from: caller});
-      const events = normalizeEvents(result.events);
-  
-      expect(events).to.be.deep.equal([
-        {
-          address,
-          event: 'Transfer',
-          args: {
-            from: '0x0000000000000000000000000000000000000000',
-            to: receiver,
-            tokenId: nextTokenId,
-          },
-        },
-      ]);
-  
-      expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');
-    }
-
-    { // mintBulkWithTokenURI
-      const nextTokenId = await contract.methods.nextTokenId().call();
-      expect(nextTokenId).to.be.equal('2');
-      const result = await contract.methods.mintBulkWithTokenURI(
-        receiver,
-        [
-          [nextTokenId, 'Test URI 0'],
-          [+nextTokenId + 1, 'Test URI 1'],
-          [+nextTokenId + 2, 'Test URI 2'],
-        ],
-      ).send({from: caller});
-      const events = normalizeEvents(result.events);
-
-      expect(events).to.be.deep.equal([
-        {
-          address,
-          event: 'Transfer',
-          args: {
-            from: '0x0000000000000000000000000000000000000000',
-            to: receiver,
-            tokenId: nextTokenId,
-          },
-        },
-        {
-          address,
-          event: 'Transfer',
-          args: {
-            from: '0x0000000000000000000000000000000000000000',
-            to: receiver,
-            tokenId: String(+nextTokenId + 1),
-          },
-        },
-        {
-          address,
-          event: 'Transfer',
-          args: {
-            from: '0x0000000000000000000000000000000000000000',
-            to: receiver,
-            tokenId: String(+nextTokenId + 2),
-          },
-        },
-      ]);
-
-      expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI 0');
-      expect(await contract.methods.tokenURI(+nextTokenId + 1).call()).to.be.equal('Test URI 1');
-      expect(await contract.methods.tokenURI(+nextTokenId + 2).call()).to.be.equal('Test URI 2');
-    }
-  });
-});
-
modifiedtests/src/eth/nonFungible.test.tsdiffbeforeafterboth
--- a/tests/src/eth/nonFungible.test.ts
+++ b/tests/src/eth/nonFungible.test.ts
@@ -539,3 +539,33 @@
     ]);
   });
 });
+
+describe('Common metadata', () => {
+  itWeb3('Returns collection name', async ({api, web3}) => {
+    const collection = await createCollectionExpectSuccess({
+      name: 'token name',
+      mode: {type: 'NFT'},
+    });
+    const caller = await createEthAccountWithBalance(api, web3);
+
+    const address = collectionIdToAddress(collection);
+    const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});
+    const name = await contract.methods.name().call();
+
+    expect(name).to.equal('token name');
+  });
+
+  itWeb3('Returns symbol name', async ({api, web3}) => {
+    const collection = await createCollectionExpectSuccess({
+      tokenPrefix: 'TOK',
+      mode: {type: 'NFT'},
+    });
+    const caller = await createEthAccountWithBalance(api, web3);
+
+    const address = collectionIdToAddress(collection);
+    const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});
+    const symbol = await contract.methods.symbol().call();
+
+    expect(symbol).to.equal('TOK');
+  });
+});
\ No newline at end of file