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
before · tests/src/eth/metadata.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 { expect } from 'chai';7import privateKey from '../substrate/privateKey';8import { createCollectionExpectSuccess } from '../util/helpers';9import { collectionIdToAddress, createEthAccount, itWeb3, transferBalanceToEth } from './util/helpers';10import fungibleMetadataAbi from './fungibleMetadataAbi.json';1112describe('Common metadata', () => {13  itWeb3('Returns collection name', async ({ api, web3 }) => {14    const collection = await createCollectionExpectSuccess({15      name: 'token name',16      mode: { type: 'NFT' },17    });18    const caller = createEthAccount(web3);19    await transferBalanceToEth(api, privateKey('//Alice'), caller, 999999);2021    const address = collectionIdToAddress(collection);22    const contract = new web3.eth.Contract(fungibleMetadataAbi as any, address);23    const name = await contract.methods.name().call({ from: caller });2425    expect(name).to.equal('token name');26  });2728  itWeb3('Returns symbol name', async ({ api, web3 }) => {29    const collection = await createCollectionExpectSuccess({30      tokenPrefix: 'TOK',31      mode: { type: 'NFT' },32    });33    const caller = createEthAccount(web3);34    await transferBalanceToEth(api, privateKey('//Alice'), caller, 999999);3536    const address = collectionIdToAddress(collection);37    const contract = new web3.eth.Contract(fungibleMetadataAbi as any, address);38    const symbol = await contract.methods.symbol().call({ from: caller });3940    expect(symbol).to.equal('TOK');41  });42});4344describe('Fungible metadata', () => {45  itWeb3('Returns fungible decimals', async ({ api, web3 }) => {46    const collection = await createCollectionExpectSuccess({47      mode: { type: 'Fungible', decimalPoints: 6 },48    });49    const caller = createEthAccount(web3);50    await transferBalanceToEth(api, privateKey('//Alice'), caller, 999999);5152    const address = collectionIdToAddress(collection);53    const contract = new web3.eth.Contract(fungibleMetadataAbi as any, address);54    const decimals = await contract.methods.decimals().call({ from: caller });5556    expect(+decimals).to.equal(6);57  });58});
after · tests/src/eth/metadata.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 { expect } from 'chai';7import { createCollectionExpectSuccess } from '../util/helpers';8import { collectionIdToAddress, createEthAccountWithBalance, GAS_ARGS, itWeb3 } from './util/helpers';9import fungibleMetadataAbi from './fungibleMetadataAbi.json';1011describe('Common metadata', () => {12  itWeb3('Returns collection name', async ({ api, web3 }) => {13    const collection = await createCollectionExpectSuccess({14      name: 'token name',15      mode: { type: 'NFT' },16    });17    const caller = await createEthAccountWithBalance(api, web3);1819    const address = collectionIdToAddress(collection);20    const contract = new web3.eth.Contract(fungibleMetadataAbi as any, address, { from: caller, ...GAS_ARGS });21    const name = await contract.methods.name().call();2223    expect(name).to.equal('token name');24  });2526  itWeb3('Returns symbol name', async ({ api, web3 }) => {27    const collection = await createCollectionExpectSuccess({28      tokenPrefix: 'TOK',29      mode: { type: 'NFT' },30    });31    const caller = await createEthAccountWithBalance(api, web3);3233    const address = collectionIdToAddress(collection);34    const contract = new web3.eth.Contract(fungibleMetadataAbi as any, address, { from: caller, ...GAS_ARGS });35    const symbol = await contract.methods.symbol().call();3637    expect(symbol).to.equal('TOK');38  });39});4041describe('Fungible metadata', () => {42  itWeb3('Returns fungible decimals', async ({ api, web3 }) => {43    const collection = await createCollectionExpectSuccess({44      mode: { type: 'Fungible', decimalPoints: 6 },45    });46    const caller = await createEthAccountWithBalance(api, web3);4748    const address = collectionIdToAddress(collection);49    const contract = new web3.eth.Contract(fungibleMetadataAbi as any, address, { from: caller, ...GAS_ARGS });50    const decimals = await contract.methods.decimals().call();5152    expect(+decimals).to.equal(6);53  });54});
modifiedtests/src/eth/nonFungible.test.tsdiffbeforeafterboth
--- a/tests/src/eth/nonFungible.test.ts
+++ b/tests/src/eth/nonFungible.test.ts
@@ -5,63 +5,65 @@
 
 import privateKey from '../substrate/privateKey';
 import { approveExpectSuccess, createCollectionExpectSuccess, createItemExpectSuccess, transferExpectSuccess, transferFromExpectSuccess } from '../util/helpers';
-import { collectionIdToAddress, createEthAccount, itWeb3, normalizeEvents, recordEvents, subToEth, transferBalanceToEth } from './util/helpers';
+import { collectionIdToAddress, createEthAccount, createEthAccountWithBalance, GAS_ARGS, itWeb3, normalizeEvents, recordEvents, subToEth, transferBalanceToEth } from './util/helpers';
 import nonFungibleAbi from './nonFungibleAbi.json';
 import { expect } from 'chai';
+import waitNewBlocks from '../substrate/wait-new-blocks';
 
-describe('Information getting', () => {
-  itWeb3('totalSupply', async ({ web3 }) => {
+describe('NFT: Information getting', () => {
+  itWeb3('totalSupply', async ({ api, web3 }) => {
     const collection = await createCollectionExpectSuccess({
       mode: { type: 'NFT' },
     });
     const alice = privateKey('//Alice');
+    const caller = await createEthAccountWithBalance(api, web3);
 
     await createItemExpectSuccess(alice, collection, 'NFT', { substrate: alice.address });
 
     const address = collectionIdToAddress(collection);
-    const contract = new web3.eth.Contract(nonFungibleAbi as any, address);
+    const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});
     const totalSupply = await contract.methods.totalSupply().call();
 
     // FIXME: always equals to 0, because this method is not implemented
     expect(totalSupply).to.equal('0');
   });
 
-  itWeb3('balanceOf', async ({ web3 }) => {
+  itWeb3('balanceOf', async ({ api, web3 }) => {
     const collection = await createCollectionExpectSuccess({
       mode: { type: 'NFT' },
     });
     const alice = privateKey('//Alice');
 
-    const caller = createEthAccount(web3);
+    const caller = await createEthAccountWithBalance(api, web3);
     await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: caller });
     await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: caller });
     await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: caller });
 
     const address = collectionIdToAddress(collection);
-    const contract = new web3.eth.Contract(nonFungibleAbi as any, address);
+    const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});
     const balance = await contract.methods.balanceOf(caller).call();
 
     expect(balance).to.equal('3');
   });
 
-  itWeb3('ownerOf', async ({ web3 }) => {
+  itWeb3('ownerOf', async ({ api, web3 }) => {
     const collection = await createCollectionExpectSuccess({
       mode: { type: 'NFT' },
     });
     const alice = privateKey('//Alice');
 
-    const caller = createEthAccount(web3);
+    const caller = await createEthAccountWithBalance(api, web3);
     const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: caller });
 
     const address = collectionIdToAddress(collection);
-    const contract = new web3.eth.Contract(nonFungibleAbi as any, address);
+    const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});
     const owner = await contract.methods.ownerOf(tokenId).call();
 
     expect(owner).to.equal(caller);
   });
 });
 
-describe('Plain calls', () => {
+describe('NFT: Plain calls', () => {
   itWeb3('Can perform approve()', async ({ web3, api }) => {
     const collection = await createCollectionExpectSuccess({
       mode: { type: 'NFT' },
@@ -113,12 +115,12 @@
     const receiver = createEthAccount(web3);
 
     const address = collectionIdToAddress(collection);
-    const contract = new web3.eth.Contract(nonFungibleAbi as any, address);
+    const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: owner, ...GAS_ARGS});
 
-    await contract.methods.approve(spender, tokenId).send({ from: owner, gas: '0x1000000', gasPrice: '0x01' });
+    await contract.methods.approve(spender, tokenId).send({ from: owner });
 
     {
-      const result = await contract.methods.transferFrom(owner, receiver, tokenId).send({ from: spender, gas: '0x1000000', gasPrice: '0x01' });
+      const result = await contract.methods.transferFrom(owner, receiver, tokenId).send({ from: spender });
       const events = normalizeEvents(result.events);
       expect(events).to.be.deep.equal([
         {
@@ -159,11 +161,11 @@
     await transferBalanceToEth(api, alice, receiver, 999999999999999);
 
     const address = collectionIdToAddress(collection);
-    const contract = new web3.eth.Contract(nonFungibleAbi as any, address);
+    const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: owner, ...GAS_ARGS});
 
     {
-      const result = await contract.methods.transfer(receiver, tokenId).send({ from: owner, gas: '0x1000000', gasPrice: '0x01' });
-      console.log(result);
+      const result = await contract.methods.transfer(receiver, tokenId).send({ from: owner });
+      await waitNewBlocks(api, 1);
       const events = normalizeEvents(result.events);
       expect(events).to.be.deep.equal([
         {
@@ -190,7 +192,7 @@
   });
 });
 
-describe('Substrate calls', () => {
+describe('NFT: Substrate calls', () => {
   itWeb3('Events emitted for approve()', async ({ web3 }) => {
     const collection = await createCollectionExpectSuccess({
       mode: { type: 'NFT' },
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'))