-
Notifications
You must be signed in to change notification settings - Fork 193
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
fix(evm): proper nonce management in statedb #2130
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
03ac44e
fix(evm): proper nonce management in statedb
onikonychev 6f88642
chore: changelog update
onikonychev 929ef63
chore: resolve conflicts
onikonychev 3a6013f
chore: resolve conflicts
onikonychev caddee0
test: fixed statedb journal test
onikonychev 14a5200
fix: text comment
onikonychev 817c7ba
Merge branch 'main' into fix/evm-multi-tx
Unique-Divine 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 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 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 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 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,75 @@ | ||
package backend_test | ||
|
||
import ( | ||
sdkmath "cosmossdk.io/math" | ||
codectypes "github.com/cosmos/cosmos-sdk/codec/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx" | ||
gethcore "github.com/ethereum/go-ethereum/core/types" | ||
|
||
"github.com/NibiruChain/nibiru/v2/x/evm" | ||
) | ||
|
||
// TestNonceIncrementWithMultipleMsgsTx tests that the nonce is incremented correctly | ||
// when multiple messages are included in a single transaction. | ||
func (s *BackendSuite) TestNonceIncrementWithMultipleMsgsTx() { | ||
nonce := s.getCurrentNonce(s.fundedAccEthAddr) | ||
|
||
// Create series of 3 tx messages. Expecting nonce to be incremented by 3 | ||
creationTx := s.buildContractCreationTx(nonce) | ||
firstTransferTx := s.buildContractCallTx(nonce+1, testContractAddress) | ||
secondTransferTx := s.buildContractCallTx(nonce+2, testContractAddress) | ||
|
||
// Create and broadcast SDK transaction | ||
sdkTx := s.buildSDKTxWithEVMMessages( | ||
creationTx, | ||
firstTransferTx, | ||
secondTransferTx, | ||
) | ||
|
||
// Broadcast transaction | ||
rsp := s.broadcastSDKTx(sdkTx) | ||
s.Assert().NotEqual(rsp.Code, 0) | ||
s.Require().NoError(s.network.WaitForNextBlock()) | ||
|
||
// Expected nonce should be incremented by 3 | ||
currentNonce := s.getCurrentNonce(s.fundedAccEthAddr) | ||
s.Assert().Equal(nonce+3, currentNonce) | ||
|
||
// Assert all transactions included in block | ||
for _, tx := range []gethcore.Transaction{creationTx, firstTransferTx, secondTransferTx} { | ||
blockNum, blockHash := WaitForReceipt(s, tx.Hash()) | ||
s.Require().NotNil(blockNum) | ||
s.Require().NotNil(blockHash) | ||
} | ||
} | ||
|
||
// buildSDKTxWithEVMMessages creates an SDK transaction with EVM messages | ||
func (s *BackendSuite) buildSDKTxWithEVMMessages(txs ...gethcore.Transaction) sdk.Tx { | ||
msgs := make([]sdk.Msg, len(txs)) | ||
for i, tx := range txs { | ||
msg := &evm.MsgEthereumTx{} | ||
err := msg.FromEthereumTx(&tx) | ||
s.Require().NoError(err) | ||
msgs[i] = msg | ||
} | ||
|
||
option, err := codectypes.NewAnyWithValue(&evm.ExtensionOptionsEthereumTx{}) | ||
s.Require().NoError(err) | ||
|
||
txBuilder, _ := s.backend.ClientCtx().TxConfig.NewTxBuilder().(authtx.ExtensionOptionsTxBuilder) | ||
txBuilder.SetExtensionOptions(option) | ||
err = txBuilder.SetMsgs(msgs...) | ||
s.Require().NoError(err) | ||
|
||
// Set fees for all messages | ||
totalGas := uint64(0) | ||
for _, tx := range txs { | ||
totalGas += tx.Gas() | ||
} | ||
fees := sdk.NewCoins(sdk.NewCoin("unibi", sdkmath.NewIntFromUint64(totalGas))) | ||
txBuilder.SetFeeAmount(fees) | ||
txBuilder.SetGasLimit(totalGas) | ||
|
||
return txBuilder.GetTx() | ||
} |
This file contains 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 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assertion should check for success, not failure
The assertion is checking for non-zero response code, which typically indicates failure. For a successful transaction, the response code should be zero.
📝 Committable suggestion