difftreelog
test fix tests for updated frontier
in: master
3 files changed
tests/src/eth/fungible.test.tsdiffbeforeafterboth--- 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([
{
tests/src/eth/nonFungible.test.tsdiffbeforeafterboth--- 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' },
tests/src/eth/util/helpers.tsdiffbeforeafterboth16 if (web3Connected) throw new Error('do not nest usingWeb3 calls');16 if (web3Connected) throw new Error('do not nest usingWeb3 calls');17 web3Connected = true;17 web3Connected = true;181819 const provider = new Web3.providers.WebsocketProvider('http://localhost:9944');19 const provider = new Web3.providers.WebsocketProvider(config.substrateUrl);20 const web3 = new Web3(provider);20 const web3 = new Web3(provider);212122 try {22 try {45 return account.address;45 return account.address;46}46}4748export async function createEthAccountWithBalance(api: ApiPromise, web3: Web3) {49 const alice = privateKey('//Alice');50 const account = createEthAccount(web3);51 await transferBalanceToEth(api, alice, account);5253 return account;54}475548export async function transferBalanceToEth(api: ApiPromise, source: IKeyringPair, target: string, amount: number) {56export async function transferBalanceToEth(api: ApiPromise, source: IKeyringPair, target: string, amount = 999999999999999) {49 const tx = api.tx.balances.transfer(evmToAddress(target), amount);57 const tx = api.tx.balances.transfer(evmToAddress(target), amount);50 const events = await submitTransactionAsync(source, tx);58 const events = await submitTransactionAsync(source, tx);51 const result = getGenericResult(events);59 const result = getGenericResult(events);