Skip to content

Commit

Permalink
Update startBlockHeight config variable for E2E tests and fix failing…
Browse files Browse the repository at this point in the history
… tests
  • Loading branch information
m-Peter committed Oct 23, 2024
1 parent c9f3d95 commit f4763b1
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 24 deletions.
8 changes: 5 additions & 3 deletions tests/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
"github.com/onflow/flow-evm-gateway/config"
)

const startingBlockHeight = uint64(3)

// Test_ConcurrentTransactionSubmission test submits multiple transactions concurrently
// and makes sure the transactions were submitted successfully. This is using the
// key-rotation signer that can handle multiple concurrent transactions.
Expand Down Expand Up @@ -192,11 +194,11 @@ func Test_EthClientTest(t *testing.T) {

blockNumber, err := ethClient.BlockNumber(context.Background())
require.NoError(t, err)
assert.Equal(t, uint64(3), blockNumber)
assert.Equal(t, uint64(startingBlockHeight+2), blockNumber)

block, err := ethClient.BlockByNumber(context.Background(), big.NewInt(3))
block, err := ethClient.BlockByNumber(context.Background(), big.NewInt(int64(blockNumber)))
require.NoError(t, err)
assert.Equal(t, big.NewInt(3), block.Number())
assert.Equal(t, big.NewInt(int64(startingBlockHeight)+2), block.Number())
}

func Test_CloudKMSConcurrentTransactionSubmission(t *testing.T) {
Expand Down
18 changes: 14 additions & 4 deletions tests/web3js/build_evm_state_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const web3 = conf.web3

it('should handle a large number of EVM interactions', async () => {
let latest = await web3.eth.getBlockNumber()
assert.equal(latest, 2n)
let expectedBlockHeight = conf.startBlockHeight
assert.equal(latest, expectedBlockHeight)

let eoaCount = 20
let accounts = []
Expand Down Expand Up @@ -37,12 +38,15 @@ it('should handle a large number of EVM interactions', async () => {

accounts.push(receiver)
}
// Add 20 to the expected block height, as we did 20 transactions,
// which formed 20 blocks.
expectedBlockHeight += 20n

let senderBalance = await web3.eth.getBalance(conf.eoa.address)
assert.equal(senderBalance, 1999999999937000000n)

latest = await web3.eth.getBlockNumber()
assert.equal(latest, 22n)
assert.equal(latest, expectedBlockHeight)

// Add some calls to test historic heights, for balance and nonce
let randomEOA = randomItem(accounts)
Expand Down Expand Up @@ -85,9 +89,12 @@ it('should handle a large number of EVM interactions', async () => {
assert.equal(transfer.receipt.to, receiver.address)
}
}
// Add 60 to the expected block height, as we did 60 transactions,
// which formed 60 blocks.
expectedBlockHeight += 60n

latest = await web3.eth.getBlockNumber()
assert.equal(latest, 82n)
assert.equal(latest, expectedBlockHeight)

// Add some calls to test historic heights, for balance and nonce
randomEOABalance = await web3.eth.getBalance(randomEOA.address, latest)
Expand Down Expand Up @@ -133,9 +140,12 @@ it('should handle a large number of EVM interactions', async () => {
})
assert.equal(res.receipt.status, conf.successStatus)
}
// Add 60 to the expected block height, as we did 60 transactions,
// which formed 60 blocks.
expectedBlockHeight += 60n

latest = await web3.eth.getBlockNumber()
assert.equal(latest, 142n)
assert.equal(latest, expectedBlockHeight)

// Add calls to verify correctness of eth_estimateGas on historical heights
let storeData = deployed.contract.methods.store(0).encodeABI()
Expand Down
9 changes: 4 additions & 5 deletions tests/web3js/config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
const { Web3 } = require('web3')

const web3 = new Web3("http://127.0.0.1:8545")
const web3 = new Web3('http://127.0.0.1:8545')

module.exports = {
web3: web3,
eoa: web3.eth.accounts.privateKeyToAccount("0xf6d5333177711e562cabf1f311916196ee6ffc2a07966d9d4628094073bd5442"), // eoa is 0xfacf71692421039876a5bb4f10ef7a439d8ef61e
eoa: web3.eth.accounts.privateKeyToAccount('0xf6d5333177711e562cabf1f311916196ee6ffc2a07966d9d4628094073bd5442'), // eoa is 0xfacf71692421039876a5bb4f10ef7a439d8ef61e
fundedAmount: 5.0,
startBlockHeight: 2n, // start block height after setup accounts
coinbase: "0x658bdf435d810c91414ec09147daa6db62406379", // configured account to receive fees
startBlockHeight: 3n, // start block height after setup accounts
coinbase: '0x658bdf435d810c91414ec09147daa6db62406379', // configured account to receive fees
successStatus: 1n,
minGasPrice: 150n
}
4 changes: 2 additions & 2 deletions tests/web3js/eth_filter_endpoints_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ describe('eth_getFilterChanges', async () => {
assert.lengthOf(transactions, 2) // the last transaction is the COA transfer for gas fees
let expectedTx = {
blockHash: res.receipt.blockHash,
blockNumber: '0xc',
blockNumber: '0xd',
from: '0xFACF71692421039876a5BB4F10EF7A439D8ef61E',
gas: '0xf4240',
gasPrice: '0x96',
Expand All @@ -410,7 +410,7 @@ describe('eth_getFilterChanges', async () => {

let expectedCoaTx = {
blockHash: res.receipt.blockHash,
blockNumber: '0xc',
blockNumber: '0xd',
from: '0x0000000000000000000000030000000000000000',
gas: '0x5b04',
gasPrice: '0x0',
Expand Down
14 changes: 7 additions & 7 deletions tests/web3js/eth_non_interactive_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,12 @@ it('get block and transactions with COA interactions', async () => {
}

// get block transaction
let tx = await web3.eth.getTransactionFromBlock(2n, 0)
let tx = await web3.eth.getTransactionFromBlock(conf.startBlockHeight, 0)
assert.equal(tx.v, "0xff")
assert.equal(tx.r, "0x0000000000000000000000000000000000000000000000020000000000000000")
assert.equal(tx.s, "0x0000000000000000000000000000000000000000000000000000000000000004")

tx = await web3.eth.getTransactionFromBlock(2n, 1)
tx = await web3.eth.getTransactionFromBlock(conf.startBlockHeight, 1)
assert.equal(tx.v, "0xff")
assert.equal(tx.r, "0x0000000000000000000000000000000000000000000000010000000000000000")
assert.equal(tx.s, "0x0000000000000000000000000000000000000000000000000000000000000001")
Expand Down Expand Up @@ -314,7 +314,7 @@ it('can make batch requests', async () => {
jsonrpc: '2.0',
id: 5,
method: 'eth_getBlockTransactionCountByNumber',
params: ['0x2'],
params: ['0x3'],
}

batch.add(getBlockNumber)
Expand All @@ -327,7 +327,7 @@ it('can make batch requests', async () => {

assert.deepEqual(
results[0],
{ jsonrpc: '2.0', id: 1, result: '0x2' }
{ jsonrpc: '2.0', id: 1, result: '0x3' }
)
assert.deepEqual(
results[1],
Expand Down Expand Up @@ -378,9 +378,9 @@ it('get fee history', async () => {
response,
{
oldestBlock: 1n,
reward: [['0x96'], ['0x96']], // gas price is 150 during testing
baseFeePerGas: [0n, 0n],
gasUsedRatio: [0, 0.006205458333333334]
reward: [['0x96'], ['0x96'], ['0x96']], // gas price is 150 during testing
baseFeePerGas: [0n, 0n, 0n],
gasUsedRatio: [0, 0, 0.006205458333333334]
}
)
})
6 changes: 3 additions & 3 deletions tests/web3js/eth_revert_reason_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const helpers = require('./helpers')
const web3 = conf.web3

it('store revertReason field in transaction receipts', async () => {
let deployed = await helpers.deployContract("storage")
let deployed = await helpers.deployContract('storage')
let contractAddress = deployed.receipt.contractAddress

// make sure deploy was successful
Expand Down Expand Up @@ -43,7 +43,7 @@ it('store revertReason field in transaction receipts', async () => {

let latestHeight = await web3.eth.getBlockNumber()
let block = await web3.eth.getBlock(latestHeight)
assert.equal(block.number, 4n)
assert.equal(block.number, conf.startBlockHeight + 2n)

let revertedTx = await web3.eth.getTransactionFromBlock(latestHeight, 0)
// Give some time to the engine to ingest the latest transaction
Expand Down Expand Up @@ -77,7 +77,7 @@ it('store revertReason field in transaction receipts', async () => {

latestHeight = await web3.eth.getBlockNumber()
block = await web3.eth.getBlock(latestHeight)
assert.equal(block.number, 5n)
assert.equal(block.number, conf.startBlockHeight + 3n)

revertedTx = await web3.eth.getTransactionFromBlock(latestHeight, 0)
// Give some time to the engine to ingest the latest transaction
Expand Down

0 comments on commit f4763b1

Please sign in to comment.