diff --git a/evmrpc/setup_test.go b/evmrpc/setup_test.go index 73b861e388..3d6ff7ddb5 100644 --- a/evmrpc/setup_test.go +++ b/evmrpc/setup_test.go @@ -871,6 +871,12 @@ func formatParam(p interface{}) string { kvs = append(kvs, fmt.Sprintf("\"%s\":%s", k, formatParam(v))) } return fmt.Sprintf("{%s}", strings.Join(kvs, ",")) + case map[string]map[string]interface{}: + kvs := []string{} + for k, v := range v { + kvs = append(kvs, fmt.Sprintf("\"%s\":%s", k, formatParam(v))) + } + return fmt.Sprintf("{%s}", strings.Join(kvs, ",")) default: panic("did not match on type") } diff --git a/evmrpc/simulate.go b/evmrpc/simulate.go index fe1b755677..17ffa8a7cf 100644 --- a/evmrpc/simulate.go +++ b/evmrpc/simulate.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "math/big" + "strings" "time" "github.com/sei-protocol/sei-chain/utils/helpers" @@ -90,6 +91,15 @@ func (s *SimulationAPI) EstimateGas(ctx context.Context, args ethapi.Transaction func (s *SimulationAPI) Call(ctx context.Context, args ethapi.TransactionArgs, blockNrOrHash *rpc.BlockNumberOrHash, overrides *ethapi.StateOverride, blockOverrides *ethapi.BlockOverrides) (result hexutil.Bytes, returnErr error) { startTime := time.Now() defer recordMetrics("eth_call", s.connectionType, startTime, returnErr == nil) + defer func() { + if r := recover(); r != nil { + if strings.Contains(fmt.Sprintf("%s", r), "Int overflow") { + returnErr = errors.New("error: balance override overflow") + } else { + returnErr = fmt.Errorf("something went wrong: %v", r) + } + } + }() if blockNrOrHash == nil { latest := rpc.BlockNumberOrHashWithNumber(rpc.LatestBlockNumber) blockNrOrHash = &latest diff --git a/evmrpc/simulate_test.go b/evmrpc/simulate_test.go index b626ba637c..5375722f64 100644 --- a/evmrpc/simulate_test.go +++ b/evmrpc/simulate_test.go @@ -132,6 +132,31 @@ func TestCall(t *testing.T) { Ctx = Ctx.WithBlockHeight(8) } +func TestEthCallHighAmount(t *testing.T) { + Ctx = Ctx.WithBlockHeight(1) + _, from := testkeeper.MockAddressPair() + _, to := testkeeper.MockAddressPair() + txArgs := map[string]interface{}{ + "from": from.Hex(), + "to": to.Hex(), + "value": "0x0", + "nonce": "0x2", + "chainId": fmt.Sprintf("%#x", EVMKeeper.ChainID(Ctx)), + } + + overrides := map[string]map[string]interface{}{ + from.Hex(): {"balance": "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"}, + } + resObj := sendRequestGood(t, "call", txArgs, "latest", overrides) + fmt.Println("resObj = ", resObj) + errMap := resObj["error"].(map[string]interface{}) + result := errMap["message"] + fmt.Println("res = ", result) + require.Equal(t, result, "error: balance override overflow") + + Ctx = Ctx.WithBlockHeight(8) +} + func TestNewRevertError(t *testing.T) { err := evmrpc.NewRevertError(&core.ExecutionResult{}) require.NotNil(t, err)