Skip to content

Commit

Permalink
Merge pull request onflow#5061 from onflow/janez/add-evm-tx-to-bench
Browse files Browse the repository at this point in the history
Add EVM transactions to FVM benchmark tests
  • Loading branch information
janezpodhostnik authored Nov 29, 2023
2 parents 8e13ddc + 862a02b commit cb368bc
Show file tree
Hide file tree
Showing 3 changed files with 275 additions and 60 deletions.
14 changes: 13 additions & 1 deletion fvm/evm/testutils/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ func (a *EOATestAccount) signTx(
return tx
}

func (a *EOATestAccount) SetNonce(nonce uint64) {
a.lock.Lock()
defer a.lock.Unlock()

a.nonce = nonce
}

func GetTestEOAAccount(t testing.TB, keyHex string) *EOATestAccount {
key, _ := gethCrypto.HexToECDSA(keyHex)
address := gethCrypto.PubkeyToAddress(key.PublicKey)
Expand All @@ -111,6 +118,11 @@ func GetTestEOAAccount(t testing.TB, keyHex string) *EOATestAccount {
}

func RunWithEOATestAccount(t testing.TB, led atree.Ledger, flowEVMRootAddress flow.Address, f func(*EOATestAccount)) {
account := FundAndGetEOATestAccount(t, led, flowEVMRootAddress)
f(account)
}

func FundAndGetEOATestAccount(t testing.TB, led atree.Ledger, flowEVMRootAddress flow.Address) *EOATestAccount {
account := GetTestEOAAccount(t, EOATestAccount1KeyHex)

// fund account
Expand Down Expand Up @@ -138,5 +150,5 @@ func RunWithEOATestAccount(t testing.TB, led atree.Ledger, flowEVMRootAddress fl
require.NoError(t, err)
require.Greater(t, bal.Uint64(), uint64(0))

f(account)
return account
}
10 changes: 7 additions & 3 deletions fvm/evm/testutils/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ func (tc *TestContract) SetDeployedAt(deployedAt types.Address) {
tc.DeployedAt = deployedAt
}

func GetStorageTestContract(t *testing.T) *TestContract {
func GetStorageTestContract(tb testing.TB) *TestContract {
byteCodes, err := hex.DecodeString("608060405261022c806100136000396000f3fe608060405234801561001057600080fd5b50600436106100575760003560e01c80632e64cec11461005c57806348b151661461007a57806357e871e7146100985780636057361d146100b657806385df51fd146100d2575b600080fd5b610064610102565b6040516100719190610149565b60405180910390f35b61008261010b565b60405161008f9190610149565b60405180910390f35b6100a0610113565b6040516100ad9190610149565b60405180910390f35b6100d060048036038101906100cb9190610195565b61011b565b005b6100ec60048036038101906100e79190610195565b610125565b6040516100f991906101db565b60405180910390f35b60008054905090565b600042905090565b600043905090565b8060008190555050565b600081409050919050565b6000819050919050565b61014381610130565b82525050565b600060208201905061015e600083018461013a565b92915050565b600080fd5b61017281610130565b811461017d57600080fd5b50565b60008135905061018f81610169565b92915050565b6000602082840312156101ab576101aa610164565b5b60006101b984828501610180565b91505092915050565b6000819050919050565b6101d5816101c2565b82525050565b60006020820190506101f060008301846101cc565b9291505056fea26469706673582212203ee61567a25f0b1848386ae6b8fdbd7733c8a502c83b5ed305b921b7933f4e8164736f6c63430008120033")
require.NoError(t, err)
require.NoError(tb, err)
return &TestContract{
Code: `
contract Storage {
Expand Down Expand Up @@ -381,6 +381,11 @@ func GetDummyKittyTestContract(t testing.TB) *TestContract {
}

func RunWithDeployedContract(t testing.TB, tc *TestContract, led atree.Ledger, flowEVMRootAddress flow.Address, f func(*TestContract)) {
DeployContract(t, tc, led, flowEVMRootAddress)
f(tc)
}

func DeployContract(t testing.TB, tc *TestContract, led atree.Ledger, flowEVMRootAddress flow.Address) {
// deploy contract
db, err := database.NewDatabase(led, flowEVMRootAddress)
require.NoError(t, err)
Expand Down Expand Up @@ -413,5 +418,4 @@ func RunWithDeployedContract(t testing.TB, tc *TestContract, led atree.Ledger, f
require.NoError(t, err)

tc.SetDeployedAt(res.DeployedContractAddress)
f(tc)
}
Loading

0 comments on commit cb368bc

Please sign in to comment.