From 1015b2dde87e464f79c7573aade7b95b86b8a3ba Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Wed, 26 Feb 2025 20:46:08 -0500 Subject: [PATCH] rewrite dynamic_fees test --- go.mod | 2 +- go.sum | 4 +- tests/e2e/c/consume_gas.go | 14 ++++++ tests/e2e/c/consume_gas.sol | 9 ++++ tests/e2e/c/dynamic_fees.go | 77 +++++++++++++++++++----------- tests/e2e/c/hashing.sol | 15 ------ tests/e2e/c/hashing_contract.go | 11 ----- tests/e2e/c/interchain_workflow.go | 3 +- tests/fixture/e2e/helpers.go | 7 ++- 9 files changed, 82 insertions(+), 60 deletions(-) create mode 100644 tests/e2e/c/consume_gas.go create mode 100644 tests/e2e/c/consume_gas.sol delete mode 100644 tests/e2e/c/hashing.sol delete mode 100644 tests/e2e/c/hashing_contract.go diff --git a/go.mod b/go.mod index e12e9b2c286c..f9c2759ed62b 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/DataDog/zstd v1.5.2 github.com/NYTimes/gziphandler v1.1.1 github.com/antithesishq/antithesis-sdk-go v0.3.8 - github.com/ava-labs/coreth v0.14.1-rc.1.0.20250219185827-6a9db205a450 + github.com/ava-labs/coreth v0.14.1-acp-176.0 github.com/ava-labs/ledger-avalanche/go v0.0.0-20241009183145-e6f90a8a1a60 github.com/btcsuite/btcd/btcutil v1.1.3 github.com/cockroachdb/pebble v0.0.0-20230928194634-aa077af62593 diff --git a/go.sum b/go.sum index f9928533c5bb..c76d3d8ad8c4 100644 --- a/go.sum +++ b/go.sum @@ -64,8 +64,8 @@ github.com/antithesishq/antithesis-sdk-go v0.3.8/go.mod h1:IUpT2DPAKh6i/YhSbt6Gl github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= -github.com/ava-labs/coreth v0.14.1-rc.1.0.20250219185827-6a9db205a450 h1:xSoL6plkPrb2w21v4JRnQg3BIJSg2svBHXyil09RMAg= -github.com/ava-labs/coreth v0.14.1-rc.1.0.20250219185827-6a9db205a450/go.mod h1:AEQcF8MWrKH0sS114wEZlkSfeGF5F66xTbQYqqimNLI= +github.com/ava-labs/coreth v0.14.1-acp-176.0 h1:VczY4/UNcayESdade0PvW0nmt7966wKwWYAaYaURF0s= +github.com/ava-labs/coreth v0.14.1-acp-176.0/go.mod h1:AEQcF8MWrKH0sS114wEZlkSfeGF5F66xTbQYqqimNLI= github.com/ava-labs/ledger-avalanche/go v0.0.0-20241009183145-e6f90a8a1a60 h1:EL66gtXOAwR/4KYBjOV03LTWgkEXvLePribLlJNu4g0= github.com/ava-labs/ledger-avalanche/go v0.0.0-20241009183145-e6f90a8a1a60/go.mod h1:/7qKobTfbzBu7eSTVaXMTr56yTYk4j2Px6/8G+idxHo= github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g= diff --git a/tests/e2e/c/consume_gas.go b/tests/e2e/c/consume_gas.go new file mode 100644 index 000000000000..fbe5bfc13d2a --- /dev/null +++ b/tests/e2e/c/consume_gas.go @@ -0,0 +1,14 @@ +// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package c + +const ( + // consumeGasCompiledContract is the compiled bytecode of the contract + // defined in consume_gas.sol. + consumeGasCompiledContract = "6080604052348015600f57600080fd5b5060788061001e6000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c8063c040622614602d575b600080fd5b60336035565b005b5b6001156040576036565b56fea264697066735822122070cfeeb0992270b4ff725a1264654534853d25ea6bb28c85d986beccfdbc997164736f6c63430008060033" + // consumeGasABIJson is the ABI of the contract defined in consume_gas.sol. + consumeGasABIJson = `[{"inputs":[],"name":"run","outputs":[],"stateMutability":"nonpayable","type":"function"}]` + // consumeGasFunction is the name of the function to call to consume gas. + consumeGasFunction = "run" +) diff --git a/tests/e2e/c/consume_gas.sol b/tests/e2e/c/consume_gas.sol new file mode 100644 index 000000000000..66e6bc11e2c3 --- /dev/null +++ b/tests/e2e/c/consume_gas.sol @@ -0,0 +1,9 @@ +// SPDX-License-Identifier: MIT + +pragma solidity = 0.8.6; + +contract ConsumeGas { + function run() public { + while (true){} + } +} diff --git a/tests/e2e/c/dynamic_fees.go b/tests/e2e/c/dynamic_fees.go index effb012ef5d8..3dff4969ed91 100644 --- a/tests/e2e/c/dynamic_fees.go +++ b/tests/e2e/c/dynamic_fees.go @@ -9,6 +9,7 @@ import ( "github.com/ava-labs/coreth/core/types" "github.com/ava-labs/coreth/params" + "github.com/ava-labs/coreth/plugin/evm/upgrade/cortina" "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common" "github.com/onsi/ginkgo/v2" @@ -19,19 +20,27 @@ import ( "github.com/ava-labs/avalanchego/tests/fixture/tmpnet" ) -// This test uses the compiled bin for `hashing.sol` as -// well as its ABI contained in `hashing_contract.go`. +// This test uses the compiled bytecode for `consume_gas.sol` as well as its ABI +// contained in `consume_gas.go`. var _ = e2e.DescribeCChain("[Dynamic Fees]", func() { tc := e2e.NewTestContext() require := require.New(tc) - // Need a gas limit much larger than the standard 21_000 to enable - // the contract to induce a gas price increase - const largeGasLimit = uint64(8_000_000) - - // TODO(marun) What is the significance of this value? - gasTip := big.NewInt(1000 * params.GWei) + const ( + // gasLimit is the maximum amount of gas that can be used in a block. + gasLimit = cortina.GasLimit // acp176.MinMaxCapacity + // maxFeePerGas is the maximum fee that transactions issued by this test + // will be willing to pay. + maxFeePerGas = 1000 * params.GWei + // minFeePerGas is the minimum fee that transactions issued by this test + // will pay. + minFeePerGas = 1 * params.Wei + ) + var ( + gasFeeCap = big.NewInt(maxFeePerGas) + gasTipCap = big.NewInt(minFeePerGas) + ) ginkgo.It("should ensure that the gas price is affected by load", func() { tc.By("creating a new private network to ensure isolation from other tests") @@ -73,18 +82,21 @@ var _ = e2e.DescribeCChain("[Dynamic Fees]", func() { // Create transaction nonce, err := ethClient.AcceptedNonceAt(tc.DefaultContext(), ethAddress) require.NoError(err) - compiledContract := common.Hex2Bytes(hashingCompiledContract) - tx := types.NewTx(&types.LegacyTx{ - Nonce: nonce, - GasPrice: gasTip, - Gas: largeGasLimit, - Value: common.Big0, - Data: compiledContract, + compiledContract := common.Hex2Bytes(consumeGasCompiledContract) + tx := types.NewTx(&types.DynamicFeeTx{ + ChainID: cChainID, + Nonce: nonce, + GasTipCap: gasTipCap, + GasFeeCap: gasFeeCap, + Gas: gasLimit, + To: nil, // contract creation + Data: compiledContract, }) // Send the transaction and wait for acceptance signedTx := sign(tx) receipt := e2e.SendEthTransaction(tc, ethClient, signedTx) + require.Equal(types.ReceiptStatusSuccessful, receipt.Status) contractAddress = receipt.ContractAddress }) @@ -92,25 +104,30 @@ var _ = e2e.DescribeCChain("[Dynamic Fees]", func() { var gasPrice *big.Int tc.By("calling the expensive contract repeatedly until a gas price increase is detected", func() { // Evaluate the bytes representation of the contract - hashingABI, err := abi.JSON(strings.NewReader(hashingABIJson)) + hashingABI, err := abi.JSON(strings.NewReader(consumeGasABIJson)) require.NoError(err) - contractData, err := hashingABI.Pack("hashIt") + contractData, err := hashingABI.Pack(consumeGasFunction) require.NoError(err) var initialGasPrice *big.Int tc.Eventually(func() bool { // Check the gas price - var err error gasPrice, err = ethClient.SuggestGasPrice(tc.DefaultContext()) require.NoError(err) + + // If this is the first iteration, record the initial gas price. if initialGasPrice == nil { initialGasPrice = gasPrice tc.Log().Info("initial gas price", - zap.Uint64("price", initialGasPrice.Uint64()), + zap.Stringer("price", initialGasPrice), ) - } else if gasPrice.Cmp(initialGasPrice) > 0 { + } + + // If the gas price has increased, stop the loop. + if gasPrice.Cmp(initialGasPrice) > 0 { tc.Log().Info("gas price has increased", - zap.Uint64("price", gasPrice.Uint64()), + zap.Stringer("initialPrice", initialGasPrice), + zap.Stringer("newPrice", gasPrice), ) return true } @@ -118,13 +135,14 @@ var _ = e2e.DescribeCChain("[Dynamic Fees]", func() { // Create the transaction nonce, err := ethClient.AcceptedNonceAt(tc.DefaultContext(), ethAddress) require.NoError(err) - tx := types.NewTx(&types.LegacyTx{ - Nonce: nonce, - GasPrice: gasTip, - Gas: largeGasLimit, - To: &contractAddress, - Value: common.Big0, - Data: contractData, + tx := types.NewTx(&types.DynamicFeeTx{ + ChainID: cChainID, + Nonce: nonce, + GasTipCap: gasTipCap, + GasFeeCap: gasFeeCap, + Gas: gasLimit, + To: &contractAddress, + Data: contractData, }) // Send the transaction and wait for acceptance @@ -145,7 +163,8 @@ var _ = e2e.DescribeCChain("[Dynamic Fees]", func() { return initialGasPrice.Cmp(gasPrice) > 0 }, e2e.DefaultTimeout, e2e.DefaultPollingInterval, "failed to see gas price decrease before timeout") tc.Log().Info("gas price has decreased", - zap.Uint64("price", gasPrice.Uint64()), + zap.Stringer("initialPrice", initialGasPrice), + zap.Stringer("newPrice", gasPrice), ) }) diff --git a/tests/e2e/c/hashing.sol b/tests/e2e/c/hashing.sol deleted file mode 100644 index 0457ac428e01..000000000000 --- a/tests/e2e/c/hashing.sol +++ /dev/null @@ -1,15 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity = 0.8.6; - -contract ConsumeGas { - - bytes hashVar = bytes("This is the hashing text for the test"); - - function hashIt() public { - for (uint i=0; i<3700; i++) { - ripemd160(hashVar); - } - } - -} diff --git a/tests/e2e/c/hashing_contract.go b/tests/e2e/c/hashing_contract.go deleted file mode 100644 index 7bf1db76c7cf..000000000000 --- a/tests/e2e/c/hashing_contract.go +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. -// See the file LICENSE for licensing terms. - -// AUTOMATICALLY GENERATED. DO NOT EDIT! -// Generated from hashing.sol by compile-contract.sh -package c - -const ( - hashingCompiledContract = "60806040526040518060600160405280602581526020016103ba6025913960009080519060200190610032929190610045565b5034801561003f57600080fd5b50610149565b828054610051906100e8565b90600052602060002090601f01602090048101928261007357600085556100ba565b82601f1061008c57805160ff19168380011785556100ba565b828001600101855582156100ba579182015b828111156100b957825182559160200191906001019061009e565b5b5090506100c791906100cb565b5090565b5b808211156100e45760008160009055506001016100cc565b5090565b6000600282049050600182168061010057607f821691505b602082108114156101145761011361011a565b5b50919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b610262806101586000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c80636f37ecea14610030575b600080fd5b61003861003a565b005b60005b610e7481101561009057600360006040516100589190610112565b602060405180830381855afa158015610075573d6000803e3d6000fd5b5050506040515150808061008890610185565b91505061003d565b50565b600081546100a081610153565b6100aa818661013e565b945060018216600081146100c557600181146100d657610109565b60ff19831686528186019350610109565b6100df85610129565b60005b83811015610101578154818901526001820191506020810190506100e2565b838801955050505b50505092915050565b600061011e8284610093565b915081905092915050565b60008190508160005260206000209050919050565b600081905092915050565b6000819050919050565b6000600282049050600182168061016b57607f821691505b6020821081141561017f5761017e6101fd565b5b50919050565b600061019082610149565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8214156101c3576101c26101ce565b5b600182019050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fdfea2646970667358221220cc5de5cd3c7aa5bda60e63e0f3156691253f7a78191eb336ec6699b38a8a777c64736f6c6343000806003354686973206973207468652068617368696e67207465787420666f72207468652074657374" - hashingABIJson = `[{"inputs":[],"name":"hashIt","outputs":[],"stateMutability":"nonpayable","type":"function"}]` -) diff --git a/tests/e2e/c/interchain_workflow.go b/tests/e2e/c/interchain_workflow.go index 791d73888f3e..3ae333e21aac 100644 --- a/tests/e2e/c/interchain_workflow.go +++ b/tests/e2e/c/interchain_workflow.go @@ -64,7 +64,8 @@ var _ = e2e.DescribeCChain("[Interchain Workflow]", func() { signedTx, err := types.SignTx(tx, signer, senderKey.ToECDSA()) require.NoError(err) - _ = e2e.SendEthTransaction(tc, ethClient, signedTx) + receipt := e2e.SendEthTransaction(tc, ethClient, signedTx) + require.Equal(types.ReceiptStatusSuccessful, receipt.Status) tc.By("waiting for the C-Chain recipient address to have received the sent funds") tc.Eventually(func() bool { diff --git a/tests/fixture/e2e/helpers.go b/tests/fixture/e2e/helpers.go index 9b7f6c45522e..16952634a780 100644 --- a/tests/fixture/e2e/helpers.go +++ b/tests/fixture/e2e/helpers.go @@ -183,7 +183,12 @@ func SendEthTransaction(tc tests.TestContext, ethClient ethclient.Client, signed return true }, DefaultTimeout, DefaultPollingInterval, "failed to see transaction acceptance before timeout") - require.Equal(types.ReceiptStatusSuccessful, receipt.Status) + tc.Log().Info("eth transaction accepted", + zap.Stringer("txID", txID), + zap.Uint64("gasUsed", receipt.GasUsed), + zap.Stringer("gasPrice", receipt.EffectiveGasPrice), + zap.Stringer("blockNumber", receipt.BlockNumber), + ) return receipt }