-
Notifications
You must be signed in to change notification settings - Fork 113
test(mempool): add integration test #512
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 19 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
fca99f2
WIP: test(mempool): add integration test
cloudgray 3591815
WIP: test(mempool): add integration test
cloudgray ad31857
test(mempool): refactor integration test
cloudgray a656805
test(mempool): fix integration test
cloudgray 5a384a7
test(mempool): refactor integration test
cloudgray d74f5ad
chore: modify comments
cloudgray 9a4d096
Merge branch 'main' into test/appside-mempool
cloudgray abbe071
test(mempool): add PrepareProposal check to integration test
cloudgray 603c890
chore: fix lint
cloudgray bc522eb
chore: update changelog
cloudgray 375fee6
Merge branch 'main' into test/appside-mempool
cloudgray dbe047b
test(mempool): modify testcode
cloudgray 29fd29f
chore: fix lint
cloudgray 142fbca
chore: fix lint
cloudgray c6054ca
Merge branch 'main' into test/appside-mempool
cloudgray fd4e829
chore: remove fmt unnecessary logs
cloudgray b39c89d
chore: change file name
cloudgray 8e1f74a
Merge branch 'main' into test/appside-mempool
aljo242 8f43b76
Merge branch 'main' into test/appside-mempool
cloudgray 1f252b0
Update CHANGELOG.md
aljo242 606d801
Merge branch 'main' into test/appside-mempool
aljo242 e0ff4d1
Merge branch 'main' into test/appside-mempool
aljo242 550b0a4
Merge branch 'main' into test/appside-mempool
aljo242 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
| package mempool | ||
|
|
||
| import ( | ||
| "encoding/hex" | ||
| "fmt" | ||
| "math/big" | ||
|
|
||
| abci "github.com/cometbft/cometbft/abci/types" | ||
| "github.com/cometbft/cometbft/crypto/tmhash" | ||
|
|
||
| "github.com/cosmos/evm/testutil/integration/base/factory" | ||
| "github.com/cosmos/evm/testutil/keyring" | ||
| evmtypes "github.com/cosmos/evm/x/vm/types" | ||
|
|
||
| sdkmath "cosmossdk.io/math" | ||
|
|
||
| sdk "github.com/cosmos/cosmos-sdk/types" | ||
| banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" | ||
| ) | ||
|
|
||
| // Constants | ||
| const ( | ||
| TxGas = 100_000 | ||
| ) | ||
|
|
||
| // createCosmosSendTransactionWithKey creates a simple bank send transaction with the specified key | ||
| func (s *IntegrationTestSuite) createCosmosSendTx(key keyring.Key, gasPrice *big.Int) sdk.Tx { | ||
| feeDenom := "aatom" | ||
|
|
||
| fromAddr := key.AccAddr | ||
| toAddr := s.keyring.GetKey(1).AccAddr | ||
| amount := sdk.NewCoins(sdk.NewInt64Coin(feeDenom, 1000)) | ||
|
|
||
| bankMsg := banktypes.NewMsgSend(fromAddr, toAddr, amount) | ||
|
|
||
| gasPriceConverted := sdkmath.NewIntFromBigInt(gasPrice) | ||
|
|
||
| txArgs := factory.CosmosTxArgs{ | ||
| Msgs: []sdk.Msg{bankMsg}, | ||
| GasPrice: &gasPriceConverted, | ||
| } | ||
| tx, err := s.factory.BuildCosmosTx(key.Priv, txArgs) | ||
| s.Require().NoError(err) | ||
|
|
||
| return tx | ||
| } | ||
|
|
||
| // createEVMTransaction creates an EVM transaction using the provided key | ||
| func (s *IntegrationTestSuite) createEVMValueTransferTx(key keyring.Key, nonce int, gasPrice *big.Int) sdk.Tx { | ||
| to := s.keyring.GetKey(1).Addr | ||
|
|
||
| if nonce < 0 { | ||
| s.Require().NoError(fmt.Errorf("nonce must be non-negative")) | ||
| } | ||
|
|
||
| ethTxArgs := evmtypes.EvmTxArgs{ | ||
| Nonce: uint64(nonce), | ||
| To: &to, | ||
| Amount: big.NewInt(1000), | ||
| GasLimit: TxGas, | ||
| GasPrice: gasPrice, | ||
| Input: nil, | ||
| } | ||
| tx, err := s.factory.GenerateSignedEthTx(key.Priv, ethTxArgs) | ||
| s.Require().NoError(err) | ||
|
|
||
| return tx | ||
| } | ||
|
|
||
| // createEVMContractDeployTx creates an EVM transaction for contract deployment | ||
| func (s *IntegrationTestSuite) createEVMContractDeployTx(key keyring.Key, gasPrice *big.Int, data []byte) sdk.Tx { | ||
| ethTxArgs := evmtypes.EvmTxArgs{ | ||
| Nonce: 0, | ||
| To: nil, | ||
| Amount: nil, | ||
| GasLimit: TxGas, | ||
| GasPrice: gasPrice, | ||
| Input: data, | ||
| } | ||
| tx, err := s.factory.GenerateSignedEthTx(key.Priv, ethTxArgs) | ||
| s.Require().NoError(err) | ||
|
|
||
| return tx | ||
| } | ||
|
|
||
| // checkTxs call abci CheckTx for multipile transactions | ||
| func (s *IntegrationTestSuite) checkTxs(txs []sdk.Tx) error { | ||
| for _, tx := range txs { | ||
| if err := s.checkTx(tx); err != nil { | ||
| return err | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // checkTxs call abci CheckTx for a transaction | ||
| func (s *IntegrationTestSuite) checkTx(tx sdk.Tx) error { | ||
| txBytes, err := s.network.App.GetTxConfig().TxEncoder()(tx) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to encode cosmos tx: %w", err) | ||
| } | ||
|
|
||
| _, err = s.network.App.CheckTx(&abci.RequestCheckTx{ | ||
| Tx: txBytes, | ||
| Type: abci.CheckTxType_New, | ||
| }) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to encode cosmos tx: %w", err) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // getTxHashes returns transaction hashes for multiple transactions | ||
| func (s *IntegrationTestSuite) getTxHashes(txs []sdk.Tx) []string { | ||
| txHashes := []string{} | ||
| for _, tx := range txs { | ||
| txHash := s.getTxHash(tx) | ||
| txHashes = append(txHashes, txHash) | ||
| } | ||
|
|
||
| return txHashes | ||
| } | ||
|
|
||
| // getTxHash returns transaction hash for a transaction | ||
| func (s *IntegrationTestSuite) getTxHash(tx sdk.Tx) string { | ||
| txEncoder := s.network.App.GetTxConfig().TxEncoder() | ||
| txBytes, err := txEncoder(tx) | ||
| s.Require().NoError(err) | ||
|
|
||
| return hex.EncodeToString(tmhash.Sum(txBytes)) | ||
| } | ||
|
|
||
| // calculateCosmosGasPrice calculates the gas price for a Cosmos transaction | ||
| func (s *IntegrationTestSuite) calculateCosmosGasPrice(feeAmount int64, gasLimit uint64) *big.Int { | ||
| return new(big.Int).Div(big.NewInt(feeAmount), big.NewInt(int64(gasLimit))) //#nosec G115 -- not concern, test | ||
| } | ||
|
|
||
| // calculateCosmosEffectiveTip calculates the effective tip for a Cosmos transaction | ||
| // This aligns with EVM transaction prioritization: effective_tip = gas_price - base_fee | ||
| func (s *IntegrationTestSuite) calculateCosmosEffectiveTip(feeAmount int64, gasLimit uint64, baseFee *big.Int) *big.Int { | ||
| gasPrice := s.calculateCosmosGasPrice(feeAmount, gasLimit) | ||
| if baseFee == nil || baseFee.Sign() == 0 { | ||
| return gasPrice // No base fee, effective tip equals gas price | ||
| } | ||
|
|
||
| if gasPrice.Cmp(baseFee) < 0 { | ||
| return big.NewInt(0) // Gas price lower than base fee, effective tip is zero | ||
| } | ||
|
|
||
| return new(big.Int).Sub(gasPrice, baseFee) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.