diff --git a/package.json b/package.json index fbf6b0a..661067e 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,8 @@ "scripts": { "compile": "truffle compile", "add-liquidity": "mocha --timeout 1000000 --exit web3tests/addLiquidity.js", - "all-tests": "ts-mocha --timeout 100000 --exit web3tests" + "all-tests": "ts-mocha --timeout 100000 --exit web3tests", + "test": "ts-mocha --timeout 100000 --exit" }, "author": "", "license": "ISC", diff --git a/utils.js b/utils.js index 11adacb..8bfed69 100644 --- a/utils.js +++ b/utils.js @@ -7,6 +7,9 @@ const account = '0x19e7e376e7c213b7e7e7e46cc70a5dd086daff2a'; // const privKey = '99B3C12287537E38C90A9219D4CB074A89A16E9CDB20BF85728EBD97C343E342'; const privKey = '1111111111111111111111111111111111111111111111111111111111111111'; +const GAS_LIMIT = 6_700_000; // eth block gas limit is 15m now +const GAS_PRICE = 1_000_000_000; // 1 gwei + const initWeb3 = (pkey = privKey) => { console.log('Initializing web3 provider at http://localhost:9933/'); // const provider = new Web3.providers.HttpProvider('http://localhost:9933/'); @@ -72,4 +75,6 @@ module.exports = { deployContract, convertToEvmAddress, convertToSubstrateAddress, + GAS_PRICE, + GAS_LIMIT } diff --git a/web3tests/addLiquidity.js b/web3tests/addLiquidity.js index 685abc8..1e7e8d6 100644 --- a/web3tests/addLiquidity.js +++ b/web3tests/addLiquidity.js @@ -1,6 +1,6 @@ const contract = require("@truffle/contract"); const { assert } = require("chai"); -const { account, initWeb3 } = require('../utils'); +const { account, initWeb3, GAS_PRICE, GAS_LIMIT } = require('../utils'); const { deploy } = require('../deploy'); const TokenA = require('../build/contracts/TokenA.json'); @@ -10,9 +10,6 @@ const UniswapV2Router02 = require('../node_modules/@uniswap/v2-periphery/build/U const UniswapV2Factory = require('../node_modules/@uniswap/v2-core/build/UniswapV2Factory.json'); const UniswapV2Pair = require('../node_modules/@uniswap/v2-core/build/UniswapV2Pair.json'); -const GAS_LIMIT = 6_700_000; // eth block gas limit is 15m now -const GAS_PRICE = 1_000_000_000; // 1 gwei - describe('Add Liquidity Test', () => { let FACTORY_ADDRESS let ROUTER_ADDRESS diff --git a/web3tests/testCreate.js b/web3tests/testCreate.js index 2e82aae..627b669 100644 --- a/web3tests/testCreate.js +++ b/web3tests/testCreate.js @@ -1,7 +1,7 @@ const { assert } = require("chai"); const rlp = require('rlp'); const keccak = require('keccak'); -const { account, initWeb3 } = require('../utils'); +const { account, initWeb3, GAS_PRICE, GAS_LIMIT } = require('../utils'); const CreateContract = require('../build/contracts/CreateContract.json'); const SubContract = require('../build/contracts/SubContract.json'); @@ -17,12 +17,12 @@ describe("CreateContract test", async () => { }); Create.setProvider(web3.currentProvider); - let c = await Create.new({ from: account }); + let c = await Create.new({ from: account, gasLimit: GAS_LIMIT }); let startNonce = await web3.eth.getTransactionCount(c.address); console.log(`CreateContract address: ${c.address}, nonce: ${startNonce}`); // create without value - let receipt = await c.spawn({ from: account }); - let address = await c.deployed.call({ from: account }); + let receipt = await c.spawn({ from: account, gasLimit: GAS_LIMIT }); + let address = await c.deployed.call({ from: account, gasLimit: GAS_LIMIT }); var Sub = contract({ abi: SubContract.abi, @@ -47,13 +47,13 @@ describe("CreateContract test", async () => { }); Create.setProvider(web3.currentProvider); - let c = await Create.new({ from: account }); + let c = await Create.new({ from: account, gasLimit: GAS_LIMIT }); let startNonce = await web3.eth.getTransactionCount(c.address); console.log(`CreateContract address: ${c.address}, nonce: ${startNonce}`); // create with value const value = web3.utils.toWei('10', 'ether'); - await c.spawnWithValue({ value, from: account }); - address = await c.deployed.call({ from: account }); + await c.spawnWithValue({ value, from: account, gasLimit: GAS_LIMIT }); + address = await c.deployed.call({ from: account, gasLimit: GAS_LIMIT }); var Sub = contract({ abi: SubContract.abi, unlinked_binary: SubContract.bytecode, @@ -61,7 +61,7 @@ describe("CreateContract test", async () => { Sub.setProvider(web3.currentProvider); let cSub = await Sub.at(address); - let balOnContract = await cSub.getValue.call({ from: account }); + let balOnContract = await cSub.getValue.call({ from: account, gasLimit: GAS_LIMIT }); let balance = await web3.eth.getBalance(cSub.address); assert.equal(balOnContract, value, 'new subcontract should have balance paid to it'); assert.equal(balOnContract, balance, 'new subcontract should have balance paid to it'); diff --git a/web3tests/testCreate2.js b/web3tests/testCreate2.js index 286a0ff..09650bd 100644 --- a/web3tests/testCreate2.js +++ b/web3tests/testCreate2.js @@ -1,7 +1,7 @@ const { assert } = require('chai'); const Create2Factory = require('../build/contracts/Create2Factory.json'); const ValueContract = require('../build/contracts/ValueContract.json'); -const { deployContract, account, initWeb3 } = require('../utils'); +const { deployContract, account, initWeb3, GAS_PRICE, GAS_LIMIT } = require('../utils'); const contract = require("@truffle/contract"); describe('Create2Factory test', async () => { @@ -13,11 +13,11 @@ describe('Create2Factory test', async () => { }); Create2.setProvider(web3.currentProvider); - let c = await Create2.new({ from: account }); + let c = await Create2.new({ from: account, gasLimit: GAS_LIMIT }); // load bytecode and deploy - await c.deploy(5, { from: account, gasPrice: 1000000000 }); - const addr = await c.viewAddr.call({ from: account, gasPrice: 1000000000 }); + await c.deploy(5, { from: account, gasLimit: GAS_LIMIT }); + const addr = await c.viewAddr.call({ from: account, gasLimit: GAS_LIMIT }); let Value = contract({ abi: ValueContract.abi, @@ -27,7 +27,7 @@ describe('Create2Factory test', async () => { // load new contract and check methods const valueContract = await Value.at(addr); - const value = await valueContract.getValue.call({ from: account, gasPrice: 1000000000 }); + const value = await valueContract.getValue.call({ from: account, gasLimit: GAS_LIMIT }); assert.equal(value, '0'); }); }); diff --git a/web3tests/testECRecovery.js b/web3tests/testECRecovery.js index 5099cb0..48816f6 100644 --- a/web3tests/testECRecovery.js +++ b/web3tests/testECRecovery.js @@ -1,6 +1,6 @@ const { assert } = require('chai'); const contract = require("@truffle/contract"); -const { account, initWeb3, privKey } = require('../utils'); +const { account, initWeb3, privKey, GAS_PRICE, GAS_LIMIT } = require('../utils'); const ECRecovery = require('../build/contracts/ECRecovery.json'); const EdgewarePrivateKeyProvider = require('../private-provider'); const signing_account = account; @@ -16,7 +16,7 @@ describe('ECRecovery test', async () => { const web3 = new Web3(provider); return web3; }; - + signWeb3 = signingWeb3(signing_privKey); }); @@ -36,7 +36,7 @@ describe('ECRecovery test', async () => { const messageHex = '0x' + Buffer.from(message).toString('hex'); const signature = await signWeb3.eth.sign(messageHex, signing_account); const hash = signWeb3.utils.sha3('\x19Ethereum Signed Message:\n' + message.length + message); - + // recover the signer const address = await c.recover(hash, signature, { from: account, gas: web3.utils.toWei('1', 'ether') }); assert.equal(address.toLowerCase(), signing_account.toLowerCase()); @@ -58,7 +58,7 @@ describe('ECRecovery test', async () => { const RAW_TX = { from: signing_account, gasPrice: "0x01", - gas: web3.utils.toWei('1', 'ether'), + gas: GAS_LIMIT, to: ECRECOVER_PRECOMPILE_ADDRESS, value: "0x0", data: `0x${hash.toString('hex')}${sigPart}`, @@ -73,7 +73,7 @@ describe('ECRecovery test', async () => { from: signing_account, to: ECRECOVER_PRECOMPILE_ADDRESS, value: '0x0', - gas: web3.utils.toWei('1', 'ether'), + gas: GAS_LIMIT, data: `0x${hash.toString('hex')}${sigPart}`, }); diff --git a/web3tests/testFallback.js b/web3tests/testFallback.js index 5eb38f1..1ba5e64 100644 --- a/web3tests/testFallback.js +++ b/web3tests/testFallback.js @@ -1,5 +1,5 @@ const { assert } = require('chai'); -const { account, initWeb3 } = require('../utils'); +const { account, initWeb3, GAS_PRICE, GAS_LIMIT } = require('../utils'); const contract = require("@truffle/contract"); const FallbackContract = require('../build/contracts/FallbackContract.json'); @@ -23,7 +23,7 @@ describe('Fallback test', async () => { from: account, to: c.address, value: valueSent.toString(), - gas: web3.utils.toWei('1', 'ether'), + gas: GAS_LIMIT, data: functionSig, }); const balanceAfter = await web3.eth.getBalance(account); @@ -35,4 +35,4 @@ describe('Fallback test', async () => { // ensure some gas fees were spent assert.isTrue(balanceDiff.gtn(0)); }); -}) \ No newline at end of file +}) diff --git a/web3tests/testLockdrop.js b/web3tests/testLockdrop.js index 5273530..befd1ca 100644 --- a/web3tests/testLockdrop.js +++ b/web3tests/testLockdrop.js @@ -4,7 +4,7 @@ const rlp = require('rlp'); const keccak = require('keccak'); const { assert } = require('chai'); const contract = require("@truffle/contract"); -const { deployContract, account, initWeb3 } = require('../utils'); +const { deployContract, account, initWeb3, GAS_PRICE, GAS_LIMIT } = require('../utils'); describe("Lockdrop test", async () => { const SECONDS_IN_DAY = 86400; @@ -47,7 +47,7 @@ describe("Lockdrop test", async () => { time = await utility.getCurrentTimestamp(web3); assert.equal(web3.utils.toBN(lockdrop.address).toString(), web3.utils.toBN(contractAddr).toString()); }); - + // Events don't work it('should lock funds and increment nonce', async function () { let time = await utility.getCurrentTimestamp(web3); @@ -68,7 +68,7 @@ describe("Lockdrop test", async () => { await lockdrop.lock(THREE_MONTHS, account, true, { from: account, value: value, - gas: 1500000, + gas: GAS_LIMIT, gasPrice: 1000, }); @@ -98,7 +98,7 @@ describe("Lockdrop test", async () => { await lockdrop.lock(THREE_MONTHS, account, true, { from: account, value: value2, - gas: 1500000, + gas: GAS_LIMIT, gasPrice: 1000000000, }); @@ -127,4 +127,4 @@ function getContractAddress(address, nonce) { const contractAddressLong = keccak('keccak256').update(rlpEncoded).digest('hex'); const contractAddr = contractAddressLong.substring(24); return contractAddr; -} \ No newline at end of file +}