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.tsdiffbeforeafterboth61 });61 });62});62});636364describe.only('Plain calls', () => {64describe('Plain calls', () => {65 itWeb3('Can perform approve()', async ({ web3, api }) => {65 itWeb3('Can perform approve()', async ({ web3, api }) => {66 const collection = await createCollectionExpectSuccess({66 const collection = await createCollectionExpectSuccess({67 mode: { type: 'NFT' },67 mode: { type: 'NFT' },tests/src/eth/util/helpers.tsdiffbeforeafterboth--- 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);