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
1import { expect } from 'chai';1import { expect } from 'chai';
2import waitNewBlocks from '../substrate/wait-new-blocks';2import waitNewBlocks from '../substrate/wait-new-blocks';
3import { setContractSponsoringRateLimitExpectFailure } from '../util/helpers';
4import { contractHelpers, createEthAccount, createEthAccountWithBalance, deployFlipper, itWeb3, usingWeb3Http } from './util/helpers';3import { contractHelpers, createEthAccount, createEthAccountWithBalance, deployFlipper, itWeb3, usingWeb3Http } from './util/helpers';
54
6describe('EVM allowlist', () => {5describe('EVM allowlist', () => {
modifiedtests/src/eth/fungible.test.tsdiffbeforeafterboth
9import fungibleAbi from './fungibleAbi.json';9import fungibleAbi from './fungibleAbi.json';
10import { expect } from 'chai';10import { expect } from 'chai';
1111
12describe('Information getting', () => {12describe('Fungible: Information getting', () => {
13 itWeb3('totalSupply', async ({ api, web3 }) => {13 itWeb3('totalSupply', async ({ api, web3 }) => {
14 const collection = await createCollectionExpectSuccess({14 const collection = await createCollectionExpectSuccess({
15 name: 'token name',15 name: 'token name',
22 await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { substrate: alice.address });22 await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { substrate: alice.address });
2323
24 const address = collectionIdToAddress(collection);24 const address = collectionIdToAddress(collection);
25 const contract = new web3.eth.Contract(fungibleAbi as any, address);25 const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: caller, ...GAS_ARGS});
26 const totalSupply = await contract.methods.totalSupply().call({ from: caller, ...GAS_ARGS });26 const totalSupply = await contract.methods.totalSupply().call();
2727
28 // FIXME: always equals to 0, because this method is not implemented28 // FIXME: always equals to 0, because this method is not implemented
29 expect(totalSupply).to.equal('0');29 expect(totalSupply).to.equal('0');
41 await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { ethereum: caller });41 await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { ethereum: caller });
4242
43 const address = collectionIdToAddress(collection);43 const address = collectionIdToAddress(collection);
44 const contract = new web3.eth.Contract(fungibleAbi as any, address);44 const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: caller, ...GAS_ARGS});
45 const balance = await contract.methods.balanceOf(caller).call({ from: caller, ...GAS_ARGS });45 const balance = await contract.methods.balanceOf(caller).call();
4646
47 expect(balance).to.equal('200');47 expect(balance).to.equal('200');
48 });48 });
49});49});
5050
51describe('Plain calls', () => {51describe('Fungible: Plain calls', () => {
52 itWeb3('Can perform approve()', async ({ web3, api }) => {52 itWeb3('Can perform approve()', async ({ web3, api }) => {
53 const collection = await createCollectionExpectSuccess({53 const collection = await createCollectionExpectSuccess({
54 name: 'token name',54 name: 'token name',
192 });192 });
193});193});
194194
195describe('Substrate calls', () => {195describe('Fungible: Substrate calls', () => {
196 itWeb3('Events emitted for approve()', async ({ web3 }) => {196 itWeb3('Events emitted for approve()', async ({ web3 }) => {
197 const collection = await createCollectionExpectSuccess({197 const collection = await createCollectionExpectSuccess({
198 mode: { type: 'Fungible', decimalPoints: 0 },198 mode: { type: 'Fungible', decimalPoints: 0 },
modifiedtests/src/eth/metadata.test.tsdiffbeforeafterboth
4//4//
55
6import { expect } from 'chai';6import { expect } from 'chai';
7import privateKey from '../substrate/privateKey';
8import { createCollectionExpectSuccess } from '../util/helpers';7import { createCollectionExpectSuccess } from '../util/helpers';
9import { collectionIdToAddress, createEthAccount, itWeb3, transferBalanceToEth } from './util/helpers';8import { collectionIdToAddress, createEthAccountWithBalance, GAS_ARGS, itWeb3 } from './util/helpers';
10import fungibleMetadataAbi from './fungibleMetadataAbi.json';9import fungibleMetadataAbi from './fungibleMetadataAbi.json';
1110
12describe('Common metadata', () => {11describe('Common metadata', () => {
15 name: 'token name',14 name: 'token name',
16 mode: { type: 'NFT' },15 mode: { type: 'NFT' },
17 });16 });
18 const caller = createEthAccount(web3);17 const caller = await createEthAccountWithBalance(api, web3);
19 await transferBalanceToEth(api, privateKey('//Alice'), caller, 999999);
2018
21 const address = collectionIdToAddress(collection);19 const address = collectionIdToAddress(collection);
22 const contract = new web3.eth.Contract(fungibleMetadataAbi as any, address);20 const contract = new web3.eth.Contract(fungibleMetadataAbi as any, address, { from: caller, ...GAS_ARGS });
23 const name = await contract.methods.name().call({ from: caller });21 const name = await contract.methods.name().call();
2422
25 expect(name).to.equal('token name');23 expect(name).to.equal('token name');
26 });24 });
30 tokenPrefix: 'TOK',28 tokenPrefix: 'TOK',
31 mode: { type: 'NFT' },29 mode: { type: 'NFT' },
32 });30 });
33 const caller = createEthAccount(web3);31 const caller = await createEthAccountWithBalance(api, web3);
34 await transferBalanceToEth(api, privateKey('//Alice'), caller, 999999);
3532
36 const address = collectionIdToAddress(collection);33 const address = collectionIdToAddress(collection);
37 const contract = new web3.eth.Contract(fungibleMetadataAbi as any, address);34 const contract = new web3.eth.Contract(fungibleMetadataAbi as any, address, { from: caller, ...GAS_ARGS });
38 const symbol = await contract.methods.symbol().call({ from: caller });35 const symbol = await contract.methods.symbol().call();
3936
40 expect(symbol).to.equal('TOK');37 expect(symbol).to.equal('TOK');
41 });38 });
46 const collection = await createCollectionExpectSuccess({43 const collection = await createCollectionExpectSuccess({
47 mode: { type: 'Fungible', decimalPoints: 6 },44 mode: { type: 'Fungible', decimalPoints: 6 },
48 });45 });
49 const caller = createEthAccount(web3);46 const caller = await createEthAccountWithBalance(api, web3);
50 await transferBalanceToEth(api, privateKey('//Alice'), caller, 999999);
5147
52 const address = collectionIdToAddress(collection);48 const address = collectionIdToAddress(collection);
53 const contract = new web3.eth.Contract(fungibleMetadataAbi as any, address);49 const contract = new web3.eth.Contract(fungibleMetadataAbi as any, address, { from: caller, ...GAS_ARGS });
54 const decimals = await contract.methods.decimals().call({ from: caller });50 const decimals = await contract.methods.decimals().call();
5551
56 expect(+decimals).to.equal(6);52 expect(+decimals).to.equal(6);
57 });53 });
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
37 const consoleWarn = console.warn;37 const consoleWarn = console.warn;
3838
39 const outFn = (message: string) => {39 const outFn = (message: string) => {
40 if (typeof message !== 'string') {
41 consoleErr(message);
42 return;
43 }
40 if (!message.includes('StorageChangeSet:: WebSocket is not connected') && 44 if (!message.includes('StorageChangeSet:: WebSocket is not connected') &&
41 !message.includes('2021-') &&45 !message.includes('2021-') &&
42 !message.includes('StorageChangeSet:: Normal connection closure'))46 !message.includes('StorageChangeSet:: Normal connection closure'))