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
55
6import privateKey from '../substrate/privateKey';6import privateKey from '../substrate/privateKey';
7import { approveExpectSuccess, createCollectionExpectSuccess, createItemExpectSuccess, transferExpectSuccess, transferFromExpectSuccess } from '../util/helpers';7import { approveExpectSuccess, createCollectionExpectSuccess, createItemExpectSuccess, transferExpectSuccess, transferFromExpectSuccess } from '../util/helpers';
8import { collectionIdToAddress, createEthAccount, itWeb3, normalizeEvents, recordEvents, subToEth, transferBalanceToEth } from './util/helpers';8import { collectionIdToAddress, createEthAccount, createEthAccountWithBalance, GAS_ARGS, itWeb3, normalizeEvents, recordEvents, subToEth, transferBalanceToEth } from './util/helpers';
9import nonFungibleAbi from './nonFungibleAbi.json';9import nonFungibleAbi from './nonFungibleAbi.json';
10import { expect } from 'chai';10import { expect } from 'chai';
11import waitNewBlocks from '../substrate/wait-new-blocks';
1112
12describe('Information getting', () => {13describe('NFT: Information getting', () => {
13 itWeb3('totalSupply', async ({ web3 }) => {14 itWeb3('totalSupply', async ({ api, web3 }) => {
14 const collection = await createCollectionExpectSuccess({15 const collection = await createCollectionExpectSuccess({
15 mode: { type: 'NFT' },16 mode: { type: 'NFT' },
16 });17 });
17 const alice = privateKey('//Alice');18 const alice = privateKey('//Alice');
19 const caller = await createEthAccountWithBalance(api, web3);
1820
19 await createItemExpectSuccess(alice, collection, 'NFT', { substrate: alice.address });21 await createItemExpectSuccess(alice, collection, 'NFT', { substrate: alice.address });
2022
21 const address = collectionIdToAddress(collection);23 const address = collectionIdToAddress(collection);
22 const contract = new web3.eth.Contract(nonFungibleAbi as any, address);24 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});
23 const totalSupply = await contract.methods.totalSupply().call();25 const totalSupply = await contract.methods.totalSupply().call();
2426
25 // FIXME: always equals to 0, because this method is not implemented27 // FIXME: always equals to 0, because this method is not implemented
26 expect(totalSupply).to.equal('0');28 expect(totalSupply).to.equal('0');
27 });29 });
2830
29 itWeb3('balanceOf', async ({ web3 }) => {31 itWeb3('balanceOf', async ({ api, web3 }) => {
30 const collection = await createCollectionExpectSuccess({32 const collection = await createCollectionExpectSuccess({
31 mode: { type: 'NFT' },33 mode: { type: 'NFT' },
32 });34 });
33 const alice = privateKey('//Alice');35 const alice = privateKey('//Alice');
3436
35 const caller = createEthAccount(web3);37 const caller = await createEthAccountWithBalance(api, web3);
36 await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: caller });38 await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: caller });
37 await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: caller });39 await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: caller });
38 await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: caller });40 await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: caller });
3941
40 const address = collectionIdToAddress(collection);42 const address = collectionIdToAddress(collection);
41 const contract = new web3.eth.Contract(nonFungibleAbi as any, address);43 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});
42 const balance = await contract.methods.balanceOf(caller).call();44 const balance = await contract.methods.balanceOf(caller).call();
4345
44 expect(balance).to.equal('3');46 expect(balance).to.equal('3');
45 });47 });
4648
47 itWeb3('ownerOf', async ({ web3 }) => {49 itWeb3('ownerOf', async ({ api, web3 }) => {
48 const collection = await createCollectionExpectSuccess({50 const collection = await createCollectionExpectSuccess({
49 mode: { type: 'NFT' },51 mode: { type: 'NFT' },
50 });52 });
51 const alice = privateKey('//Alice');53 const alice = privateKey('//Alice');
5254
53 const caller = createEthAccount(web3);55 const caller = await createEthAccountWithBalance(api, web3);
54 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: caller });56 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: caller });
5557
56 const address = collectionIdToAddress(collection);58 const address = collectionIdToAddress(collection);
57 const contract = new web3.eth.Contract(nonFungibleAbi as any, address);59 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});
58 const owner = await contract.methods.ownerOf(tokenId).call();60 const owner = await contract.methods.ownerOf(tokenId).call();
5961
60 expect(owner).to.equal(caller);62 expect(owner).to.equal(caller);
61 });63 });
62});64});
6365
64describe('Plain calls', () => {66describe('NFT: Plain calls', () => {
65 itWeb3('Can perform approve()', async ({ web3, api }) => {67 itWeb3('Can perform approve()', async ({ web3, api }) => {
66 const collection = await createCollectionExpectSuccess({68 const collection = await createCollectionExpectSuccess({
67 mode: { type: 'NFT' },69 mode: { type: 'NFT' },
113 const receiver = createEthAccount(web3);115 const receiver = createEthAccount(web3);
114116
115 const address = collectionIdToAddress(collection);117 const address = collectionIdToAddress(collection);
116 const contract = new web3.eth.Contract(nonFungibleAbi as any, address);118 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: owner, ...GAS_ARGS});
117119
118 await contract.methods.approve(spender, tokenId).send({ from: owner, gas: '0x1000000', gasPrice: '0x01' });120 await contract.methods.approve(spender, tokenId).send({ from: owner });
119121
120 {122 {
121 const result = await contract.methods.transferFrom(owner, receiver, tokenId).send({ from: spender, gas: '0x1000000', gasPrice: '0x01' });123 const result = await contract.methods.transferFrom(owner, receiver, tokenId).send({ from: spender });
122 const events = normalizeEvents(result.events);124 const events = normalizeEvents(result.events);
123 expect(events).to.be.deep.equal([125 expect(events).to.be.deep.equal([
124 {126 {
159 await transferBalanceToEth(api, alice, receiver, 999999999999999);161 await transferBalanceToEth(api, alice, receiver, 999999999999999);
160162
161 const address = collectionIdToAddress(collection);163 const address = collectionIdToAddress(collection);
162 const contract = new web3.eth.Contract(nonFungibleAbi as any, address);164 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: owner, ...GAS_ARGS});
163165
164 {166 {
165 const result = await contract.methods.transfer(receiver, tokenId).send({ from: owner, gas: '0x1000000', gasPrice: '0x01' });167 const result = await contract.methods.transfer(receiver, tokenId).send({ from: owner });
166 console.log(result);168 await waitNewBlocks(api, 1);
167 const events = normalizeEvents(result.events);169 const events = normalizeEvents(result.events);
168 expect(events).to.be.deep.equal([170 expect(events).to.be.deep.equal([
169 {171 {
190 });192 });
191});193});
192194
193describe('Substrate calls', () => {195describe('NFT: Substrate calls', () => {
194 itWeb3('Events emitted for approve()', async ({ web3 }) => {196 itWeb3('Events emitted for approve()', async ({ web3 }) => {
195 const collection = await createCollectionExpectSuccess({197 const collection = await createCollectionExpectSuccess({
196 mode: { type: 'NFT' },198 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'))