difftreelog
test make eth tests pass
in: master
5 files changed
tests/src/eth/allowlist.test.tsdiffbeforeafterboth1import { expect } from 'chai';2import waitNewBlocks from '../substrate/wait-new-blocks';3import { setContractSponsoringRateLimitExpectFailure } from '../util/helpers';4import { contractHelpers, createEthAccount, createEthAccountWithBalance, deployFlipper, itWeb3, usingWeb3Http } from './util/helpers';56describe('EVM allowlist', () => {7 itWeb3('Contract allowlist can be toggled', async ({ api }) => {8 await usingWeb3Http(async web3Http => {9 const owner = await createEthAccountWithBalance(api, web3Http);10 const flipper = await deployFlipper(web3Http, owner);11 await waitNewBlocks(api, 1);12 const randomUser = createEthAccount(web3Http);1314 const helpers = contractHelpers(web3Http, owner);1516 // Any user is allowed by default17 expect(await helpers.methods.allowlistEnabled(flipper.options.address).call()).to.be.false;18 expect(await helpers.methods.allowed(flipper.options.address, randomUser).call()).to.be.true;19 await waitNewBlocks(api, 1);2021 // Enable22 await helpers.methods.toggleAllowlist(flipper.options.address, true).send({ from: owner });23 await waitNewBlocks(api, 1);24 expect(await helpers.methods.allowlistEnabled(flipper.options.address).call()).to.be.true;25 expect(await helpers.methods.allowed(flipper.options.address, randomUser).call()).to.be.false;2627 // Disable28 await helpers.methods.toggleAllowlist(flipper.options.address, false).send({ from: owner });29 await waitNewBlocks(api, 1);30 expect(await helpers.methods.allowlistEnabled(flipper.options.address).call()).to.be.false;31 expect(await helpers.methods.allowed(flipper.options.address, randomUser).call()).to.be.true;32 });33 });3435 itWeb3('Non-whitelisted user can\'t call contract with allowlist enabled', async ({ api }) => {36 await usingWeb3Http(async web3Http => {37 const owner = await createEthAccountWithBalance(api, web3Http);38 const flipper = await deployFlipper(web3Http, owner);39 await waitNewBlocks(api, 1);40 const caller = await createEthAccountWithBalance(api, web3Http);4142 const helpers = contractHelpers(web3Http, owner);4344 // User can flip with allowlist disabled45 await flipper.methods.flip().send({ from: caller });46 await waitNewBlocks(api, 1);47 expect(await flipper.methods.getValue().call()).to.be.true;4849 // Tx will be reverted if user is not in whitelist50 await helpers.methods.toggleAllowlist(flipper.options.address, true).send({ from: owner });51 await expect(flipper.methods.flip().send({ from: caller })).to.rejected;52 await waitNewBlocks(api, 1);53 expect(await flipper.methods.getValue().call()).to.be.true;5455 // Adding caller to allowlist will make contract callable again56 await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner});57 await flipper.methods.flip().send({ from: caller });58 await waitNewBlocks(api, 1);59 expect(await flipper.methods.getValue().call()).to.be.false;60 });61 });62});1import { expect } from 'chai';2import waitNewBlocks from '../substrate/wait-new-blocks';3import { contractHelpers, createEthAccount, createEthAccountWithBalance, deployFlipper, itWeb3, usingWeb3Http } from './util/helpers';45describe('EVM allowlist', () => {6 itWeb3('Contract allowlist can be toggled', async ({ api }) => {7 await usingWeb3Http(async web3Http => {8 const owner = await createEthAccountWithBalance(api, web3Http);9 const flipper = await deployFlipper(web3Http, owner);10 await waitNewBlocks(api, 1);11 const randomUser = createEthAccount(web3Http);1213 const helpers = contractHelpers(web3Http, owner);1415 // Any user is allowed by default16 expect(await helpers.methods.allowlistEnabled(flipper.options.address).call()).to.be.false;17 expect(await helpers.methods.allowed(flipper.options.address, randomUser).call()).to.be.true;18 await waitNewBlocks(api, 1);1920 // Enable21 await helpers.methods.toggleAllowlist(flipper.options.address, true).send({ from: owner });22 await waitNewBlocks(api, 1);23 expect(await helpers.methods.allowlistEnabled(flipper.options.address).call()).to.be.true;24 expect(await helpers.methods.allowed(flipper.options.address, randomUser).call()).to.be.false;2526 // Disable27 await helpers.methods.toggleAllowlist(flipper.options.address, false).send({ from: owner });28 await waitNewBlocks(api, 1);29 expect(await helpers.methods.allowlistEnabled(flipper.options.address).call()).to.be.false;30 expect(await helpers.methods.allowed(flipper.options.address, randomUser).call()).to.be.true;31 });32 });3334 itWeb3('Non-whitelisted user can\'t call contract with allowlist enabled', async ({ api }) => {35 await usingWeb3Http(async web3Http => {36 const owner = await createEthAccountWithBalance(api, web3Http);37 const flipper = await deployFlipper(web3Http, owner);38 await waitNewBlocks(api, 1);39 const caller = await createEthAccountWithBalance(api, web3Http);4041 const helpers = contractHelpers(web3Http, owner);4243 // User can flip with allowlist disabled44 await flipper.methods.flip().send({ from: caller });45 await waitNewBlocks(api, 1);46 expect(await flipper.methods.getValue().call()).to.be.true;4748 // Tx will be reverted if user is not in whitelist49 await helpers.methods.toggleAllowlist(flipper.options.address, true).send({ from: owner });50 await expect(flipper.methods.flip().send({ from: caller })).to.rejected;51 await waitNewBlocks(api, 1);52 expect(await flipper.methods.getValue().call()).to.be.true;5354 // Adding caller to allowlist will make contract callable again55 await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner});56 await flipper.methods.flip().send({ from: caller });57 await waitNewBlocks(api, 1);58 expect(await flipper.methods.getValue().call()).to.be.false;59 });60 });61});tests/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 },
tests/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);
});
tests/src/eth/nonFungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/nonFungible.test.ts
+++ b/tests/src/eth/nonFungible.test.ts
@@ -5,63 +5,65 @@
import privateKey from '../substrate/privateKey';
import { approveExpectSuccess, createCollectionExpectSuccess, createItemExpectSuccess, 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 nonFungibleAbi from './nonFungibleAbi.json';
import { expect } from 'chai';
+import waitNewBlocks from '../substrate/wait-new-blocks';
-describe('Information getting', () => {
- itWeb3('totalSupply', async ({ web3 }) => {
+describe('NFT: Information getting', () => {
+ itWeb3('totalSupply', async ({ api, web3 }) => {
const collection = await createCollectionExpectSuccess({
mode: { type: 'NFT' },
});
const alice = privateKey('//Alice');
+ const caller = await createEthAccountWithBalance(api, web3);
await createItemExpectSuccess(alice, collection, 'NFT', { substrate: alice.address });
const address = collectionIdToAddress(collection);
- const contract = new web3.eth.Contract(nonFungibleAbi as any, address);
+ const contract = new web3.eth.Contract(nonFungibleAbi 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');
});
- itWeb3('balanceOf', async ({ web3 }) => {
+ itWeb3('balanceOf', async ({ api, web3 }) => {
const collection = await createCollectionExpectSuccess({
mode: { type: 'NFT' },
});
const alice = privateKey('//Alice');
- const caller = createEthAccount(web3);
+ const caller = await createEthAccountWithBalance(api, web3);
await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: caller });
await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: caller });
await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: caller });
const address = collectionIdToAddress(collection);
- const contract = new web3.eth.Contract(nonFungibleAbi as any, address);
+ const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});
const balance = await contract.methods.balanceOf(caller).call();
expect(balance).to.equal('3');
});
- itWeb3('ownerOf', async ({ web3 }) => {
+ itWeb3('ownerOf', async ({ api, web3 }) => {
const collection = await createCollectionExpectSuccess({
mode: { type: 'NFT' },
});
const alice = privateKey('//Alice');
- const caller = createEthAccount(web3);
+ const caller = await createEthAccountWithBalance(api, web3);
const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: caller });
const address = collectionIdToAddress(collection);
- const contract = new web3.eth.Contract(nonFungibleAbi as any, address);
+ const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});
const owner = await contract.methods.ownerOf(tokenId).call();
expect(owner).to.equal(caller);
});
});
-describe('Plain calls', () => {
+describe('NFT: Plain calls', () => {
itWeb3('Can perform approve()', async ({ web3, api }) => {
const collection = await createCollectionExpectSuccess({
mode: { type: 'NFT' },
@@ -113,12 +115,12 @@
const receiver = createEthAccount(web3);
const address = collectionIdToAddress(collection);
- const contract = new web3.eth.Contract(nonFungibleAbi as any, address);
+ const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: owner, ...GAS_ARGS});
- await contract.methods.approve(spender, tokenId).send({ from: owner, gas: '0x1000000', gasPrice: '0x01' });
+ await contract.methods.approve(spender, tokenId).send({ from: owner });
{
- const result = await contract.methods.transferFrom(owner, receiver, tokenId).send({ from: spender, gas: '0x1000000', gasPrice: '0x01' });
+ const result = await contract.methods.transferFrom(owner, receiver, tokenId).send({ from: spender });
const events = normalizeEvents(result.events);
expect(events).to.be.deep.equal([
{
@@ -159,11 +161,11 @@
await transferBalanceToEth(api, alice, receiver, 999999999999999);
const address = collectionIdToAddress(collection);
- const contract = new web3.eth.Contract(nonFungibleAbi as any, address);
+ const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: owner, ...GAS_ARGS});
{
- const result = await contract.methods.transfer(receiver, tokenId).send({ from: owner, gas: '0x1000000', gasPrice: '0x01' });
- console.log(result);
+ const result = await contract.methods.transfer(receiver, tokenId).send({ from: owner });
+ await waitNewBlocks(api, 1);
const events = normalizeEvents(result.events);
expect(events).to.be.deep.equal([
{
@@ -190,7 +192,7 @@
});
});
-describe('Substrate calls', () => {
+describe('NFT: Substrate calls', () => {
itWeb3('Events emitted for approve()', async ({ web3 }) => {
const collection = await createCollectionExpectSuccess({
mode: { type: 'NFT' },
tests/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'))