From 723337089349a79c9cbaa732f7087aa44805dbf1 Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Tue, 27 Jul 2021 16:47:16 +0000 Subject: [PATCH] test: fix tests for updated frontier --- --- a/tests/src/eth/fungible.test.ts +++ b/tests/src/eth/fungible.test.ts @@ -5,41 +5,44 @@ import privateKey from '../substrate/privateKey'; import { approveExpectSuccess, createCollectionExpectSuccess, createFungibleItemExpectSuccess, 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 fungibleAbi from './fungibleAbi.json'; import { expect } from 'chai'; describe('Information getting', () => { - itWeb3('totalSupply', async ({ web3 }) => { + itWeb3('totalSupply', async ({ api, web3 }) => { const collection = await createCollectionExpectSuccess({ name: 'token name', mode: { type: 'Fungible', decimalPoints: 0 }, }); const alice = privateKey('//Alice'); + const caller = await createEthAccountWithBalance(api, web3); + 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(); + const totalSupply = await contract.methods.totalSupply().call({ from: caller, ...GAS_ARGS }); // 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({ name: 'token name', mode: { type: 'Fungible', decimalPoints: 0 }, }); const alice = privateKey('//Alice'); - const caller = createEthAccount(web3); + const caller = await createEthAccountWithBalance(api, web3); + 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(); + const balance = await contract.methods.balanceOf(caller).call({ from: caller, ...GAS_ARGS }); expect(balance).to.equal('200'); }); @@ -53,18 +56,17 @@ }); const alice = privateKey('//Alice'); - const owner = createEthAccount(web3); - await transferBalanceToEth(api, alice, owner, 999999999999999); + const owner = await createEthAccountWithBalance(api, web3); await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { ethereum: owner }); const spender = createEthAccount(web3); const address = collectionIdToAddress(collection); - const contract = new web3.eth.Contract(fungibleAbi as any, address); + const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: owner, ...GAS_ARGS}); { - const result = await contract.methods.approve(spender, 100).send({ from: owner, gas: '0x1000000', gasPrice: '0x01' }); + const result = await contract.methods.approve(spender, 100).send({from: owner}); const events = normalizeEvents(result.events); expect(events).to.be.deep.equal([ @@ -104,12 +106,12 @@ const receiver = createEthAccount(web3); const address = collectionIdToAddress(collection); - const contract = new web3.eth.Contract(fungibleAbi as any, address); + const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: owner, ...GAS_ARGS}); - await contract.methods.approve(spender, 100).send({ from: owner, gas: '0x1000000', gasPrice: '0x01' }); + await contract.methods.approve(spender, 100).send(); { - const result = await contract.methods.transferFrom(owner, receiver, 49).send({ from: spender, gas: '0x1000000', gasPrice: '0x01' }); + const result = await contract.methods.transferFrom(owner, receiver, 49).send({from: spender}); const events = normalizeEvents(result.events); expect(events).to.be.deep.equal([ { @@ -160,10 +162,10 @@ await transferBalanceToEth(api, alice, receiver, 999999999999999); const address = collectionIdToAddress(collection); - const contract = new web3.eth.Contract(fungibleAbi as any, address); + const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: owner, ...GAS_ARGS}); { - const result = await contract.methods.transfer(receiver, 50).send({ from: owner, gas: '0x1000000', gasPrice: '0x01' }); + const result = await contract.methods.transfer(receiver, 50).send({ from: owner}); const events = normalizeEvents(result.events); expect(events).to.be.deep.equal([ { --- a/tests/src/eth/nonFungible.test.ts +++ b/tests/src/eth/nonFungible.test.ts @@ -61,7 +61,7 @@ }); }); -describe.only('Plain calls', () => { +describe('Plain calls', () => { itWeb3('Can perform approve()', async ({ web3, api }) => { const collection = await createCollectionExpectSuccess({ mode: { type: 'NFT' }, --- a/tests/src/eth/util/helpers.ts +++ b/tests/src/eth/util/helpers.ts @@ -16,7 +16,7 @@ if (web3Connected) throw new Error('do not nest usingWeb3 calls'); web3Connected = true; - const provider = new Web3.providers.WebsocketProvider('http://localhost:9944'); + const provider = new Web3.providers.WebsocketProvider(config.substrateUrl); const web3 = new Web3(provider); try { @@ -45,7 +45,15 @@ return account.address; } -export async function transferBalanceToEth(api: ApiPromise, source: IKeyringPair, target: string, amount: number) { +export async function createEthAccountWithBalance(api: ApiPromise, web3: Web3) { + const alice = privateKey('//Alice'); + const account = createEthAccount(web3); + await transferBalanceToEth(api, alice, account); + + return account; +} + +export async function transferBalanceToEth(api: ApiPromise, source: IKeyringPair, target: string, amount = 999999999999999) { const tx = api.tx.balances.transfer(evmToAddress(target), amount); const events = await submitTransactionAsync(source, tx); const result = getGenericResult(events); -- gitstuff