Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ to geth v1.14 with tracing updates and new StateDB methods.
setup. Namely, blobs (Cancun) and Verkle additions for zkEVM.
- The jump to v1.14 was necessary to use an up-to-date "cockroach/pebble" DB
dependency and leverage new generics features added in Go 1.23+.
- [#2289](https://github.com/NibiruChain/nibiru/pull/2289) - fix(eth-rpc): error propagation fixes and tests for the methods exposed by Nibiru's EVM JSON-RPC
- [#2288](https://github.com/NibiruChain/nibiru/pull/2288) - chore(ci): add workflow to check for missing upgrade handler
- [#2278](https://github.com/NibiruChain/nibiru/pull/2278) - chore: migrate to cosmossdk.io/mathLegacyDec and cosmossdk.io/math.Int

Expand Down
12 changes: 6 additions & 6 deletions eth/assert.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ package eth
import (
"bytes"

errorsmod "cosmossdk.io/errors"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
sdkioerrors "cosmossdk.io/errors"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/ethereum/go-ethereum/common"
)

Expand All @@ -22,8 +22,8 @@ func IsZeroAddress(address string) bool {
// ValidateAddress returns an error if the provided string is either not a hex formatted string address
func ValidateAddress(address string) error {
if !common.IsHexAddress(address) {
return errorsmod.Wrapf(
errortypes.ErrInvalidAddress, "address '%s' is not a valid ethereum hex address",
return sdkioerrors.Wrapf(
sdkerrors.ErrInvalidAddress, "address '%s' is not a valid ethereum hex address",
address,
)
}
Expand All @@ -34,8 +34,8 @@ func ValidateAddress(address string) error {
// formatted string address or is equal to zero
func ValidateNonZeroAddress(address string) error {
if IsZeroAddress(address) {
return errorsmod.Wrapf(
errortypes.ErrInvalidAddress, "address '%s' must not be zero",
return sdkioerrors.Wrapf(
sdkerrors.ErrInvalidAddress, "address '%s' must not be zero",
address,
)
}
Expand Down
6 changes: 3 additions & 3 deletions eth/crypto/ethsecp256k1/ethsecp256k1.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
"crypto/subtle"
"fmt"

errorsmod "cosmossdk.io/errors"
sdkioerrors "cosmossdk.io/errors"
tmcrypto "github.com/cometbft/cometbft/crypto"
"github.com/cosmos/cosmos-sdk/codec"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/ethereum/go-ethereum/crypto"

"github.com/NibiruChain/nibiru/v2/eth/eip712"
Expand Down Expand Up @@ -186,7 +186,7 @@
// UnmarshalAmino overrides Amino binary marshaling.
func (pubKey *PubKey) UnmarshalAmino(bz []byte) error {
if len(bz) != PubKeySize {
return errorsmod.Wrapf(errortypes.ErrInvalidPubKey, "invalid pubkey size, expected %d, got %d", PubKeySize, len(bz))
return sdkioerrors.Wrapf(sdkerrors.ErrInvalidPubKey, "invalid pubkey size, expected %d, got %d", PubKeySize, len(bz))

Check warning on line 189 in eth/crypto/ethsecp256k1/ethsecp256k1.go

View check run for this annotation

Codecov / codecov/patch

eth/crypto/ethsecp256k1/ethsecp256k1.go#L189

Added line #L189 was not covered by tests
}
pubKey.Key = bz

Expand Down
12 changes: 6 additions & 6 deletions eth/eip712/eip712_legacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
"strings"
"time"

errorsmod "cosmossdk.io/errors"
sdkioerrors "cosmossdk.io/errors"
sdkmath "cosmossdk.io/math"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
sdk "github.com/cosmos/cosmos-sdk/types"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

"github.com/ethereum/go-ethereum/common"
gethmath "github.com/ethereum/go-ethereum/common/math"
Expand All @@ -41,7 +41,7 @@
txData := make(map[string]any)

if err := json.Unmarshal(data, &txData); err != nil {
return apitypes.TypedData{}, errorsmod.Wrap(errortypes.ErrJSONUnmarshal, "failed to JSON unmarshal data")
return apitypes.TypedData{}, sdkioerrors.Wrap(sdkerrors.ErrJSONUnmarshal, "failed to JSON unmarshal data")

Check warning on line 44 in eth/eip712/eip712_legacy.go

View check run for this annotation

Codecov / codecov/patch

eth/eip712/eip712_legacy.go#L44

Added line #L44 was not covered by tests
}

domain := apitypes.TypedDataDomain{
Expand All @@ -60,7 +60,7 @@
if feeDelegation != nil {
feeInfo, ok := txData["fee"].(map[string]any)
if !ok {
return apitypes.TypedData{}, errorsmod.Wrap(errortypes.ErrInvalidType, "cannot parse fee from tx data")
return apitypes.TypedData{}, sdkioerrors.Wrap(sdkerrors.ErrInvalidType, "cannot parse fee from tx data")

Check warning on line 63 in eth/eip712/eip712_legacy.go

View check run for this annotation

Codecov / codecov/patch

eth/eip712/eip712_legacy.go#L63

Added line #L63 was not covered by tests
}

feeInfo["feePayer"] = feeDelegation.FeePayer.String()
Expand Down Expand Up @@ -369,15 +369,15 @@
func UnpackAny(cdc codectypes.AnyUnpacker, field reflect.Value) (reflect.Type, reflect.Value, error) {
anyData, ok := field.Interface().(*codectypes.Any)
if !ok {
return nil, reflect.Value{}, errorsmod.Wrapf(errortypes.ErrPackAny, "%T", field.Interface())
return nil, reflect.Value{}, sdkioerrors.Wrapf(sdkerrors.ErrPackAny, "%T", field.Interface())

Check warning on line 372 in eth/eip712/eip712_legacy.go

View check run for this annotation

Codecov / codecov/patch

eth/eip712/eip712_legacy.go#L372

Added line #L372 was not covered by tests
}

anyWrapper := &CosmosAnyWrapper{
Type: anyData.TypeUrl,
}

if err := cdc.UnpackAny(anyData, &anyWrapper.Value); err != nil {
return nil, reflect.Value{}, errorsmod.Wrap(err, "failed to unpack Any in msg struct")
return nil, reflect.Value{}, sdkioerrors.Wrap(err, "failed to unpack Any in msg struct")

Check warning on line 380 in eth/eip712/eip712_legacy.go

View check run for this annotation

Codecov / codecov/patch

eth/eip712/eip712_legacy.go#L380

Added line #L380 was not covered by tests
}

fieldType := reflect.TypeOf(anyWrapper)
Expand Down
22 changes: 11 additions & 11 deletions eth/eip712/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import (
"fmt"

errorsmod "cosmossdk.io/errors"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
sdkioerrors "cosmossdk.io/errors"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

"github.com/tidwall/gjson"
"github.com/tidwall/sjson"
Expand All @@ -31,12 +31,12 @@

payload, numPayloadMsgs, err := FlattenPayloadMessages(basicPayload)
if err != nil {
return eip712MessagePayload{}, errorsmod.Wrap(err, "failed to flatten payload JSON messages")
return eip712MessagePayload{}, sdkioerrors.Wrap(err, "failed to flatten payload JSON messages")
}

message, ok := payload.Value().(map[string]any)
if !ok {
return eip712MessagePayload{}, errorsmod.Wrap(errortypes.ErrInvalidType, "failed to parse JSON as map")
return eip712MessagePayload{}, sdkioerrors.Wrap(sdkerrors.ErrInvalidType, "failed to parse JSON as map")

Check warning on line 39 in eth/eip712/message.go

View check run for this annotation

Codecov / codecov/patch

eth/eip712/message.go#L39

Added line #L39 was not covered by tests
}

messagePayload := eip712MessagePayload{
Expand All @@ -52,13 +52,13 @@
// a JSON object, then makes sure the JSON is an object.
func unmarshalBytesToJSONObject(data []byte) (gjson.Result, error) {
if !gjson.ValidBytes(data) {
return gjson.Result{}, errorsmod.Wrap(errortypes.ErrJSONUnmarshal, "invalid JSON received")
return gjson.Result{}, sdkioerrors.Wrap(sdkerrors.ErrJSONUnmarshal, "invalid JSON received")
}

payload := gjson.ParseBytes(data)

if !payload.IsObject() {
return gjson.Result{}, errorsmod.Wrap(errortypes.ErrJSONUnmarshal, "failed to JSON unmarshal data as object")
return gjson.Result{}, sdkioerrors.Wrap(sdkerrors.ErrJSONUnmarshal, "failed to JSON unmarshal data as object")

Check warning on line 61 in eth/eip712/message.go

View check run for this annotation

Codecov / codecov/patch

eth/eip712/message.go#L61

Added line #L61 was not covered by tests
}

return payload, nil
Expand Down Expand Up @@ -96,11 +96,11 @@
rawMsgs := payload.Get(payloadMsgsField)

if !rawMsgs.Exists() {
return nil, errorsmod.Wrap(errortypes.ErrInvalidRequest, "no messages found in payload, unable to parse")
return nil, sdkioerrors.Wrap(sdkerrors.ErrInvalidRequest, "no messages found in payload, unable to parse")
}

if !rawMsgs.IsArray() {
return nil, errorsmod.Wrap(errortypes.ErrInvalidRequest, "expected type array of messages, cannot parse")
return nil, sdkioerrors.Wrap(sdkerrors.ErrInvalidRequest, "expected type array of messages, cannot parse")
}

return rawMsgs.Array(), nil
Expand All @@ -112,14 +112,14 @@
field := msgFieldForIndex(index)

if payload.Get(field).Exists() {
return gjson.Result{}, errorsmod.Wrapf(
errortypes.ErrInvalidRequest,
return gjson.Result{}, sdkioerrors.Wrapf(
sdkerrors.ErrInvalidRequest,
"malformed payload received, did not expect to find key at field %v", field,
)
}

if !msg.IsObject() {
return gjson.Result{}, errorsmod.Wrapf(errortypes.ErrInvalidRequest, "msg at index %d is not valid JSON: %v", index, msg)
return gjson.Result{}, sdkioerrors.Wrapf(sdkerrors.ErrInvalidRequest, "msg at index %d is not valid JSON: %v", index, msg)
}

newRaw, err := sjson.SetRaw(payload.Raw, field, msg.Raw)
Expand Down
16 changes: 8 additions & 8 deletions eth/eip712/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"golang.org/x/text/cases"
"golang.org/x/text/language"

errorsmod "cosmossdk.io/errors"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
sdkioerrors "cosmossdk.io/errors"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

"github.com/ethereum/go-ethereum/signer/core/apitypes"
"github.com/tidwall/gjson"
Expand Down Expand Up @@ -93,7 +93,7 @@
defer doRecover(&err)

if !msg.IsObject() {
return errorsmod.Wrapf(errortypes.ErrInvalidRequest, "message is not valid JSON, cannot parse types")
return sdkioerrors.Wrapf(sdkerrors.ErrInvalidRequest, "message is not valid JSON, cannot parse types")

Check warning on line 96 in eth/eip712/types.go

View check run for this annotation

Codecov / codecov/patch

eth/eip712/types.go#L96

Added line #L96 was not covered by tests
}

msgRootType, err := msgRootType(msg)
Expand All @@ -117,7 +117,7 @@
msgType := msg.Get(msgTypeField).Str
if msgType == "" {
// .Str is empty for arrays and objects
return "", errorsmod.Wrap(errortypes.ErrInvalidType, "malformed message type value, expected type string")
return "", sdkioerrors.Wrap(sdkerrors.ErrInvalidType, "malformed message type value, expected type string")
}

// Convert e.g. cosmos-sdk/MsgSend to TypeMsgSend
Expand Down Expand Up @@ -152,7 +152,7 @@
// Must sort the JSON keys for deterministic type generation.
sortedFieldNames, err := sortedJSONKeys(payload)
if err != nil {
return "", errorsmod.Wrap(err, "unable to sort object keys")
return "", sdkioerrors.Wrap(err, "unable to sort object keys")

Check warning on line 155 in eth/eip712/types.go

View check run for this annotation

Codecov / codecov/patch

eth/eip712/types.go#L155

Added line #L155 was not covered by tests
}

typeDef := typeDefForPrefix(prefix, rootType)
Expand Down Expand Up @@ -224,7 +224,7 @@
// to be used for deterministic iteration.
func sortedJSONKeys(json gjson.Result) ([]string, error) {
if !json.IsObject() {
return nil, errorsmod.Wrap(errortypes.ErrInvalidType, "expected JSON map to parse")
return nil, sdkioerrors.Wrap(sdkerrors.ErrInvalidType, "expected JSON map to parse")

Check warning on line 227 in eth/eip712/types.go

View check run for this annotation

Codecov / codecov/patch

eth/eip712/types.go#L227

Added line #L227 was not covered by tests
}

jsonMap := json.Map()
Expand Down Expand Up @@ -299,7 +299,7 @@
indexAsDuplicate++

if indexAsDuplicate == maxDuplicateTypeDefs {
return "", errorsmod.Wrap(errortypes.ErrInvalidRequest, "exceeded maximum number of duplicates for a single type definition")
return "", sdkioerrors.Wrap(sdkerrors.ErrInvalidRequest, "exceeded maximum number of duplicates for a single type definition")
}
}

Expand Down Expand Up @@ -380,7 +380,7 @@
func doRecover(err *error) {
if r := recover(); r != nil {
if e, ok := r.(error); ok {
e = errorsmod.Wrap(e, "panicked with error")
e = sdkioerrors.Wrap(e, "panicked with error")

Check warning on line 383 in eth/eip712/types.go

View check run for this annotation

Codecov / codecov/patch

eth/eip712/types.go#L383

Added line #L383 was not covered by tests
*err = e
return
}
Expand Down
6 changes: 3 additions & 3 deletions eth/errors.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package eth

import (
sdkerrors "cosmossdk.io/errors"
sdkioerrors "cosmossdk.io/errors"
)

var moduleErrorCodeIdx uint32 = 1

func registerError(msg string) *sdkerrors.Error {
func registerError(msg string) *sdkioerrors.Error {
moduleErrorCodeIdx += 1
return sdkerrors.Register("eth", moduleErrorCodeIdx, msg)
return sdkioerrors.Register("eth", moduleErrorCodeIdx, msg)
}

// Module "sentinel" errors
Expand Down
22 changes: 11 additions & 11 deletions eth/indexer/evm_tx_indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import (
"fmt"

errorsmod "cosmossdk.io/errors"
sdkioerrors "cosmossdk.io/errors"
dbm "github.com/cometbft/cometbft-db"
abci "github.com/cometbft/cometbft/abci/types"
"github.com/cometbft/cometbft/libs/log"
Expand Down Expand Up @@ -122,12 +122,12 @@
ethTxIndex++

if err := saveTxResult(indexer.clientCtx.Codec, batch, txHash, &txResult); err != nil {
return errorsmod.Wrapf(err, "IndexBlock %d", height)
return sdkioerrors.Wrapf(err, "IndexBlock %d", height)

Check warning on line 125 in eth/indexer/evm_tx_indexer.go

View check run for this annotation

Codecov / codecov/patch

eth/indexer/evm_tx_indexer.go#L125

Added line #L125 was not covered by tests
}
}
}
if err := batch.Write(); err != nil {
return errorsmod.Wrapf(err, "IndexBlock %d, write batch", block.Height)
return sdkioerrors.Wrapf(err, "IndexBlock %d, write batch", block.Height)

Check warning on line 130 in eth/indexer/evm_tx_indexer.go

View check run for this annotation

Codecov / codecov/patch

eth/indexer/evm_tx_indexer.go#L130

Added line #L130 was not covered by tests
}
return nil
}
Expand All @@ -146,14 +146,14 @@
func (indexer *EVMTxIndexer) GetByTxHash(hash common.Hash) (*eth.TxResult, error) {
bz, err := indexer.db.Get(TxHashKey(hash))
if err != nil {
return nil, errorsmod.Wrapf(err, "GetByTxHash %s", hash.Hex())
return nil, sdkioerrors.Wrapf(err, "GetByTxHash %s", hash.Hex())

Check warning on line 149 in eth/indexer/evm_tx_indexer.go

View check run for this annotation

Codecov / codecov/patch

eth/indexer/evm_tx_indexer.go#L149

Added line #L149 was not covered by tests
}
if len(bz) == 0 {
return nil, fmt.Errorf("tx not found, hash: %s", hash.Hex())
}
var txKey eth.TxResult
if err := indexer.clientCtx.Codec.Unmarshal(bz, &txKey); err != nil {
return nil, errorsmod.Wrapf(err, "GetByTxHash %s", hash.Hex())
return nil, sdkioerrors.Wrapf(err, "GetByTxHash %s", hash.Hex())

Check warning on line 156 in eth/indexer/evm_tx_indexer.go

View check run for this annotation

Codecov / codecov/patch

eth/indexer/evm_tx_indexer.go#L156

Added line #L156 was not covered by tests
}
return &txKey, nil
}
Expand All @@ -162,7 +162,7 @@
func (indexer *EVMTxIndexer) GetByBlockAndIndex(blockNumber int64, txIndex int32) (*eth.TxResult, error) {
bz, err := indexer.db.Get(TxIndexKey(blockNumber, txIndex))
if err != nil {
return nil, errorsmod.Wrapf(err, "GetByBlockAndIndex %d %d", blockNumber, txIndex)
return nil, sdkioerrors.Wrapf(err, "GetByBlockAndIndex %d %d", blockNumber, txIndex)

Check warning on line 165 in eth/indexer/evm_tx_indexer.go

View check run for this annotation

Codecov / codecov/patch

eth/indexer/evm_tx_indexer.go#L165

Added line #L165 was not covered by tests
}
if len(bz) == 0 {
return nil, fmt.Errorf("tx not found, block: %d, eth-index: %d", blockNumber, txIndex)
Expand All @@ -186,7 +186,7 @@
func LoadLastBlock(db dbm.DB) (int64, error) {
it, err := db.ReverseIterator([]byte{KeyPrefixTxIndex}, []byte{KeyPrefixTxIndex + 1})
if err != nil {
return 0, errorsmod.Wrap(err, "LoadLastBlock")
return 0, sdkioerrors.Wrap(err, "LoadLastBlock")

Check warning on line 189 in eth/indexer/evm_tx_indexer.go

View check run for this annotation

Codecov / codecov/patch

eth/indexer/evm_tx_indexer.go#L189

Added line #L189 was not covered by tests
}
defer it.Close()
if !it.Valid() {
Expand All @@ -199,7 +199,7 @@
func LoadFirstBlock(db dbm.DB) (int64, error) {
it, err := db.Iterator([]byte{KeyPrefixTxIndex}, []byte{KeyPrefixTxIndex + 1})
if err != nil {
return 0, errorsmod.Wrap(err, "LoadFirstBlock")
return 0, sdkioerrors.Wrap(err, "LoadFirstBlock")

Check warning on line 202 in eth/indexer/evm_tx_indexer.go

View check run for this annotation

Codecov / codecov/patch

eth/indexer/evm_tx_indexer.go#L202

Added line #L202 was not covered by tests
}
defer it.Close()
if !it.Valid() {
Expand All @@ -213,7 +213,7 @@
indexer.logger.Info("Closing EVMTxIndexer DB")
err := indexer.db.Close()
if err != nil {
return errorsmod.Wrap(err, "CloseDBAndExit")
return sdkioerrors.Wrap(err, "CloseDBAndExit")

Check warning on line 216 in eth/indexer/evm_tx_indexer.go

View check run for this annotation

Codecov / codecov/patch

eth/indexer/evm_tx_indexer.go#L216

Added line #L216 was not covered by tests
}
return nil
}
Expand All @@ -235,10 +235,10 @@
func saveTxResult(codec codec.Codec, batch dbm.Batch, txHash common.Hash, txResult *eth.TxResult) error {
bz := codec.MustMarshal(txResult)
if err := batch.Set(TxHashKey(txHash), bz); err != nil {
return errorsmod.Wrap(err, "set tx-hash key")
return sdkioerrors.Wrap(err, "set tx-hash key")

Check warning on line 238 in eth/indexer/evm_tx_indexer.go

View check run for this annotation

Codecov / codecov/patch

eth/indexer/evm_tx_indexer.go#L238

Added line #L238 was not covered by tests
}
if err := batch.Set(TxIndexKey(txResult.Height, txResult.EthTxIndex), txHash.Bytes()); err != nil {
return errorsmod.Wrap(err, "set tx-index key")
return sdkioerrors.Wrap(err, "set tx-index key")

Check warning on line 241 in eth/indexer/evm_tx_indexer.go

View check run for this annotation

Codecov / codecov/patch

eth/indexer/evm_tx_indexer.go#L241

Added line #L241 was not covered by tests
}
return nil
}
Expand Down
5 changes: 2 additions & 3 deletions eth/rpc/backend/account_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
"math"
"math/big"

errorsmod "cosmossdk.io/errors"

sdkioerrors "cosmossdk.io/errors"
sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
Expand Down Expand Up @@ -204,7 +203,7 @@

currentHeight := int64(bn) //#nosec G701 -- checked for int overflow already
if height > currentHeight {
return &n, errorsmod.Wrapf(
return &n, sdkioerrors.Wrapf(

Check warning on line 206 in eth/rpc/backend/account_info.go

View check run for this annotation

Codecov / codecov/patch

eth/rpc/backend/account_info.go#L206

Added line #L206 was not covered by tests
sdkerrors.ErrInvalidHeight,
"cannot query with height in the future (current: %d, queried: %d); please provide a valid height",
currentHeight, height,
Expand Down
5 changes: 4 additions & 1 deletion eth/rpc/backend/backend_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,10 @@ func (s *BackendSuite) SetupSuite() {
}

for _, tx := range s.SuccessfulTxs {
s.T().Logf("SuccessfulTx{ BlockNumber: %s, BlockHash: %s, TxHash: %s }", tx.BlockNumber, tx.BlockHash.Hex(), tx.Receipt.TxHash.Hex())
s.T().Logf(
"SuccessfulTx{ BlockNumber: %s, BlockHash: %s, TxHash: %s }",
tx.BlockNumber, tx.BlockHash.Hex(), tx.Receipt.TxHash.Hex(),
)
}
}

Expand Down
Loading
Loading