Skip to content

Commit

Permalink
rewrite dynamic_fees test
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenButtolph committed Feb 27, 2025
1 parent 37e79d4 commit 1015b2d
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 60 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
14 changes: 14 additions & 0 deletions tests/e2e/c/consume_gas.go
Original file line number Diff line number Diff line change
@@ -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"
)
9 changes: 9 additions & 0 deletions tests/e2e/c/consume_gas.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// SPDX-License-Identifier: MIT

pragma solidity = 0.8.6;

contract ConsumeGas {
function run() public {
while (true){}
}
}
77 changes: 48 additions & 29 deletions tests/e2e/c/dynamic_fees.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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")
Expand Down Expand Up @@ -73,58 +82,67 @@ 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
})

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
}

// 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
Expand All @@ -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),
)
})

Expand Down
15 changes: 0 additions & 15 deletions tests/e2e/c/hashing.sol

This file was deleted.

11 changes: 0 additions & 11 deletions tests/e2e/c/hashing_contract.go

This file was deleted.

3 changes: 2 additions & 1 deletion tests/e2e/c/interchain_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 6 additions & 1 deletion tests/fixture/e2e/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 1015b2d

Please sign in to comment.