git.delta.rocks / unique-network / refs/commits / 9eaef92b0444

difftreelog

test make eth tests pass

Yaroslav Bolyukin2021-07-27parent: #1cfdc4e.patch.diff
in: master

5 files changed

modifiedtests/src/eth/allowlist.test.tsdiffbeforeafterboth
--- a/tests/src/eth/allowlist.test.ts
+++ b/tests/src/eth/allowlist.test.ts
@@ -1,6 +1,5 @@
 import { expect } from 'chai';
 import waitNewBlocks from '../substrate/wait-new-blocks';
-import { setContractSponsoringRateLimitExpectFailure } from '../util/helpers';
 import { contractHelpers, createEthAccount, createEthAccountWithBalance, deployFlipper, itWeb3, usingWeb3Http } from './util/helpers';
 
 describe('EVM allowlist', () => {
modifiedtests/src/eth/fungible.test.tsdiffbeforeafterboth
--- a/tests/src/eth/fungible.test.ts
+++ b/tests/src/eth/fungible.test.ts
@@ -9,7 +9,7 @@
 import fungibleAbi from './fungibleAbi.json';
 import { expect } from 'chai';
 
-describe('Information getting', () => {
+describe('Fungible: Information getting', () => {
   itWeb3('totalSupply', async ({ api, web3 }) => {
     const collection = await createCollectionExpectSuccess({
       name: 'token name',
@@ -22,8 +22,8 @@
     await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { substrate: alice.address });
 
     const address = collectionIdToAddress(collection);
-    const contract = new web3.eth.Contract(fungibleAbi as any, address);
-    const totalSupply = await contract.methods.totalSupply().call({ from: caller, ...GAS_ARGS });
+    const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: caller, ...GAS_ARGS});
+    const totalSupply = await contract.methods.totalSupply().call();
 
     // FIXME: always equals to 0, because this method is not implemented
     expect(totalSupply).to.equal('0');
@@ -41,14 +41,14 @@
     await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { ethereum: caller });
 
     const address = collectionIdToAddress(collection);
-    const contract = new web3.eth.Contract(fungibleAbi as any, address);
-    const balance = await contract.methods.balanceOf(caller).call({ from: caller, ...GAS_ARGS });
+    const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: caller, ...GAS_ARGS});
+    const balance = await contract.methods.balanceOf(caller).call();
 
     expect(balance).to.equal('200');
   });
 });
 
-describe('Plain calls', () => {
+describe('Fungible: Plain calls', () => {
   itWeb3('Can perform approve()', async ({ web3, api }) => {
     const collection = await createCollectionExpectSuccess({
       name: 'token name',
@@ -192,7 +192,7 @@
   });
 });
 
-describe('Substrate calls', () => {
+describe('Fungible: Substrate calls', () => {
   itWeb3('Events emitted for approve()', async ({ web3 }) => {
     const collection = await createCollectionExpectSuccess({
       mode: { type: 'Fungible', decimalPoints: 0 },
modifiedtests/src/eth/metadata.test.tsdiffbeforeafterboth
--- a/tests/src/eth/metadata.test.ts
+++ b/tests/src/eth/metadata.test.ts
@@ -4,9 +4,8 @@
 //
 
 import { expect } from 'chai';
-import privateKey from '../substrate/privateKey';
 import { createCollectionExpectSuccess } from '../util/helpers';
-import { collectionIdToAddress, createEthAccount, itWeb3, transferBalanceToEth } from './util/helpers';
+import { collectionIdToAddress, createEthAccountWithBalance, GAS_ARGS, itWeb3 } from './util/helpers';
 import fungibleMetadataAbi from './fungibleMetadataAbi.json';
 
 describe('Common metadata', () => {
@@ -15,12 +14,11 @@
       name: 'token name',
       mode: { type: 'NFT' },
     });
-    const caller = createEthAccount(web3);
-    await transferBalanceToEth(api, privateKey('//Alice'), caller, 999999);
+    const caller = await createEthAccountWithBalance(api, web3);
 
     const address = collectionIdToAddress(collection);
-    const contract = new web3.eth.Contract(fungibleMetadataAbi as any, address);
-    const name = await contract.methods.name().call({ from: caller });
+    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');
   });
@@ -30,12 +28,11 @@
       tokenPrefix: 'TOK',
       mode: { type: 'NFT' },
     });
-    const caller = createEthAccount(web3);
-    await transferBalanceToEth(api, privateKey('//Alice'), caller, 999999);
+    const caller = await createEthAccountWithBalance(api, web3);
 
     const address = collectionIdToAddress(collection);
-    const contract = new web3.eth.Contract(fungibleMetadataAbi as any, address);
-    const symbol = await contract.methods.symbol().call({ from: caller });
+    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');
   });
@@ -46,12 +43,11 @@
     const collection = await createCollectionExpectSuccess({
       mode: { type: 'Fungible', decimalPoints: 6 },
     });
-    const caller = createEthAccount(web3);
-    await transferBalanceToEth(api, privateKey('//Alice'), caller, 999999);
+    const caller = await createEthAccountWithBalance(api, web3);
 
     const address = collectionIdToAddress(collection);
-    const contract = new web3.eth.Contract(fungibleMetadataAbi as any, address);
-    const decimals = await contract.methods.decimals().call({ from: caller });
+    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);
   });
modifiedtests/src/eth/nonFungible.test.tsdiffbeforeafterboth
before · tests/src/eth/nonFungible.test.ts
1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56import privateKey from '../substrate/privateKey';7import { approveExpectSuccess, createCollectionExpectSuccess, createItemExpectSuccess, transferExpectSuccess, transferFromExpectSuccess } from '../util/helpers';8import { collectionIdToAddress, createEthAccount, itWeb3, normalizeEvents, recordEvents, subToEth, transferBalanceToEth } from './util/helpers';9import nonFungibleAbi from './nonFungibleAbi.json';10import { expect } from 'chai';1112describe('Information getting', () => {13  itWeb3('totalSupply', async ({ web3 }) => {14    const collection = await createCollectionExpectSuccess({15      mode: { type: 'NFT' },16    });17    const alice = privateKey('//Alice');1819    await createItemExpectSuccess(alice, collection, 'NFT', { substrate: alice.address });2021    const address = collectionIdToAddress(collection);22    const contract = new web3.eth.Contract(nonFungibleAbi as any, address);23    const totalSupply = await contract.methods.totalSupply().call();2425    // FIXME: always equals to 0, because this method is not implemented26    expect(totalSupply).to.equal('0');27  });2829  itWeb3('balanceOf', async ({ web3 }) => {30    const collection = await createCollectionExpectSuccess({31      mode: { type: 'NFT' },32    });33    const alice = privateKey('//Alice');3435    const caller = createEthAccount(web3);36    await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: caller });37    await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: caller });38    await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: caller });3940    const address = collectionIdToAddress(collection);41    const contract = new web3.eth.Contract(nonFungibleAbi as any, address);42    const balance = await contract.methods.balanceOf(caller).call();4344    expect(balance).to.equal('3');45  });4647  itWeb3('ownerOf', async ({ web3 }) => {48    const collection = await createCollectionExpectSuccess({49      mode: { type: 'NFT' },50    });51    const alice = privateKey('//Alice');5253    const caller = createEthAccount(web3);54    const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: caller });5556    const address = collectionIdToAddress(collection);57    const contract = new web3.eth.Contract(nonFungibleAbi as any, address);58    const owner = await contract.methods.ownerOf(tokenId).call();5960    expect(owner).to.equal(caller);61  });62});6364describe('Plain calls', () => {65  itWeb3('Can perform approve()', async ({ web3, api }) => {66    const collection = await createCollectionExpectSuccess({67      mode: { type: 'NFT' },68    });69    const alice = privateKey('//Alice');7071    const owner = createEthAccount(web3);72    await transferBalanceToEth(api, alice, owner, 999999999999999);7374    const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner });7576    const spender = createEthAccount(web3);7778    const address = collectionIdToAddress(collection);79    const contract = new web3.eth.Contract(nonFungibleAbi as any, address);8081    {82      const result = await contract.methods.approve(spender, tokenId).send({ from: owner, gas: '0x1000000', gasPrice: '0x01' });83      const events = normalizeEvents(result.events);8485      expect(events).to.be.deep.equal([86        {87          address,88          event: 'Approval',89          args: {90            owner,91            approved: spender,92            tokenId: tokenId.toString(),93          },94        },95      ]);96    }97  });9899  itWeb3('Can perform transferFrom()', async ({ web3, api }) => {100    const collection = await createCollectionExpectSuccess({101      mode: { type: 'NFT' },102    });103    const alice = privateKey('//Alice');104105    const owner = createEthAccount(web3);106    await transferBalanceToEth(api, alice, owner, 999999999999999);107108    const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner });109110    const spender = createEthAccount(web3);111    await transferBalanceToEth(api, alice, spender, 999999999999999);112113    const receiver = createEthAccount(web3);114115    const address = collectionIdToAddress(collection);116    const contract = new web3.eth.Contract(nonFungibleAbi as any, address);117118    await contract.methods.approve(spender, tokenId).send({ from: owner, gas: '0x1000000', gasPrice: '0x01' });119120    {121      const result = await contract.methods.transferFrom(owner, receiver, tokenId).send({ from: spender, gas: '0x1000000', gasPrice: '0x01' });122      const events = normalizeEvents(result.events);123      expect(events).to.be.deep.equal([124        {125          address,126          event: 'Transfer',127          args: {128            from: owner,129            to: receiver,130            tokenId: tokenId.toString(),131          },132        },133      ]);134    }135136    {137      const balance = await contract.methods.balanceOf(receiver).call();138      expect(+balance).to.equal(1);139    }140141    {142      const balance = await contract.methods.balanceOf(owner).call();143      expect(+balance).to.equal(0);144    }145  });146147  itWeb3('Can perform transfer()', async ({ web3, api }) => {148    const collection = await createCollectionExpectSuccess({149      mode: { type: 'NFT' },150    });151    const alice = privateKey('//Alice');152153    const owner = createEthAccount(web3);154    await transferBalanceToEth(api, alice, owner, 999999999999999);155156    const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner });157158    const receiver = createEthAccount(web3);159    await transferBalanceToEth(api, alice, receiver, 999999999999999);160161    const address = collectionIdToAddress(collection);162    const contract = new web3.eth.Contract(nonFungibleAbi as any, address);163164    {165      const result = await contract.methods.transfer(receiver, tokenId).send({ from: owner, gas: '0x1000000', gasPrice: '0x01' });166      console.log(result);167      const events = normalizeEvents(result.events);168      expect(events).to.be.deep.equal([169        {170          address,171          event: 'Transfer',172          args: {173            from: owner,174            to: receiver,175            tokenId: tokenId.toString(),176          },177        },178      ]);179    }180181    {182      const balance = await contract.methods.balanceOf(owner).call();183      expect(+balance).to.equal(0);184    }185186    {187      const balance = await contract.methods.balanceOf(receiver).call();188      expect(+balance).to.equal(1);189    }190  });191});192193describe('Substrate calls', () => {194  itWeb3('Events emitted for approve()', async ({ web3 }) => {195    const collection = await createCollectionExpectSuccess({196      mode: { type: 'NFT' },197    });198    const alice = privateKey('//Alice');199200    const receiver = createEthAccount(web3);201202    const tokenId = await createItemExpectSuccess(alice, collection, 'NFT');203204    const address = collectionIdToAddress(collection);205    const contract = new web3.eth.Contract(nonFungibleAbi as any, address);206207    const events = await recordEvents(contract, async () => {208      await approveExpectSuccess(collection, tokenId, alice, { ethereum: receiver }, 1);209    });210211    expect(events).to.be.deep.equal([212      {213        address,214        event: 'Approval',215        args: {216          owner: subToEth(alice.address),217          approved: receiver,218          tokenId: tokenId.toString(),219        },220      },221    ]);222  });223224  itWeb3('Events emitted for transferFrom()', async ({ web3 }) => {225    const collection = await createCollectionExpectSuccess({226      mode: { type: 'NFT' },227    });228    const alice = privateKey('//Alice');229    const bob = privateKey('//Bob');230231    const receiver = createEthAccount(web3);232233    const tokenId = await createItemExpectSuccess(alice, collection, 'NFT');234    await approveExpectSuccess(collection, tokenId, alice, bob, 1);235236    const address = collectionIdToAddress(collection);237    const contract = new web3.eth.Contract(nonFungibleAbi as any, address);238239    const events = await recordEvents(contract, async () => {240      await transferFromExpectSuccess(collection, tokenId, bob, alice, { ethereum: receiver }, 1, 'NFT');241    });242243    expect(events).to.be.deep.equal([244      {245        address,246        event: 'Transfer',247        args: {248          from: subToEth(alice.address),249          to: receiver,250          tokenId: tokenId.toString(),251        },252      },253    ]);254  });255256  itWeb3('Events emitted for transfer()', async ({ web3 }) => {257    const collection = await createCollectionExpectSuccess({258      mode: { type: 'NFT' },259    });260    const alice = privateKey('//Alice');261262    const receiver = createEthAccount(web3);263264    const tokenId = await createItemExpectSuccess(alice, collection, 'NFT');265266    const address = collectionIdToAddress(collection);267    const contract = new web3.eth.Contract(nonFungibleAbi as any, address);268269    const events = await recordEvents(contract, async () => {270      await transferExpectSuccess(collection, tokenId, alice, { ethereum: receiver }, 1, 'NFT');271    });272273    expect(events).to.be.deep.equal([274      {275        address,276        event: 'Transfer',277        args: {278          from: subToEth(alice.address),279          to: receiver,280          tokenId: tokenId.toString(),281        },282      },283    ]);284  });285});
modifiedtests/src/substrate/substrate-api.tsdiffbeforeafterboth
--- a/tests/src/substrate/substrate-api.ts
+++ b/tests/src/substrate/substrate-api.ts
@@ -37,6 +37,10 @@
   const consoleWarn = console.warn;
 
   const outFn = (message: string) => {
+    if (typeof message !== 'string') {
+      consoleErr(message);
+      return;
+    }
     if (!message.includes('StorageChangeSet:: WebSocket is not connected') && 
         !message.includes('2021-') &&
         !message.includes('StorageChangeSet:: Normal connection closure'))