forked from cerc-io/laconicd-deprecated
!feat(deps): Upgrade cosmos-sdk to v0.46.0 (#1168)
* Reuse cosmos-sdk client library to create keyring Extracted from https://github.com/evmos/ethermint/pull/1168 Cleanup cmd code for easier to migration to cosmos-sdk 0.46 * Update cosmos-sdk v0.46 prepare for implementing cosmos-sdk feemarket and tx prioritization changelog refactor cmd use sdkmath fix lint fix unit tests fix unit test genesis fix unit tests fix unit test env setup fix unit tests fix unit tests register PrivKey impl fix extension options fix lint fix unit tests make HandlerOption.Validate private gofumpt fix msg response decoding fix sim test bump cosmos-sdk version fix sim test sdk 46 fix unit test fix unit tests update ibc-go
This commit is contained in:
@@ -25,7 +25,7 @@ func cosmosAddressFromArg(addr string) (sdk.AccAddress, error) {
|
||||
// Strip 0x prefix if exists
|
||||
addr = strings.TrimPrefix(addr, "0x")
|
||||
|
||||
return sdk.AccAddressFromHex(addr)
|
||||
return sdk.AccAddressFromHexUnsafe(addr)
|
||||
}
|
||||
|
||||
func TestAddressFormats(t *testing.T) {
|
||||
@@ -59,7 +59,7 @@ func TestAddressFormats(t *testing.T) {
|
||||
|
||||
func TestCosmosToEthereumTypes(t *testing.T) {
|
||||
hexString := "0x3B98D72760f7bbA69d62Ed6F48278451251948E7"
|
||||
cosmosAddr, err := sdk.AccAddressFromHex(hexString[2:])
|
||||
cosmosAddr, err := sdk.AccAddressFromHexUnsafe(hexString[2:])
|
||||
require.NoError(t, err)
|
||||
|
||||
cosmosFormatted := cosmosAddr.String()
|
||||
@@ -81,7 +81,7 @@ func TestCosmosToEthereumTypes(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAddressToCosmosAddress(t *testing.T) {
|
||||
baseAddr, err := sdk.AccAddressFromHex("6A98D72760f7bbA69d62Ed6F48278451251948E7")
|
||||
baseAddr, err := sdk.AccAddressFromHexUnsafe("6A98D72760f7bbA69d62Ed6F48278451251948E7")
|
||||
require.NoError(t, err)
|
||||
|
||||
// Test cosmos string back to address
|
||||
|
||||
@@ -1,116 +0,0 @@
|
||||
package rest
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"math/big"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
clientrest "github.com/cosmos/cosmos-sdk/client/rest"
|
||||
"github.com/cosmos/cosmos-sdk/types/rest"
|
||||
authrest "github.com/cosmos/cosmos-sdk/x/auth/client/rest"
|
||||
|
||||
rpctypes "github.com/evmos/ethermint/rpc/types"
|
||||
feemarkettypes "github.com/evmos/ethermint/x/feemarket/types"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
)
|
||||
|
||||
// RegisterTxRoutes - Central function to define routes that get registered by the main application
|
||||
func RegisterTxRoutes(clientCtx client.Context, rtr *mux.Router) {
|
||||
r := clientrest.WithHTTPDeprecationHeaders(rtr)
|
||||
r.HandleFunc("/txs/{hash}", QueryTxRequestHandlerFn(clientCtx)).Methods("GET")
|
||||
r.HandleFunc("/txs", authrest.QueryTxsRequestHandlerFn(clientCtx)).Methods("GET")
|
||||
r.HandleFunc("/txs/decode", authrest.DecodeTxRequestHandlerFn(clientCtx)).Methods("POST")
|
||||
}
|
||||
|
||||
// QueryTxRequestHandlerFn implements a REST handler that queries a transaction
|
||||
// by hash in a committed block.
|
||||
func QueryTxRequestHandlerFn(clientCtx client.Context) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
hashHexStr := vars["hash"]
|
||||
|
||||
clientCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, clientCtx, r)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
ethHashPrefix := "0x"
|
||||
if !strings.HasPrefix(hashHexStr, ethHashPrefix) {
|
||||
authrest.QueryTxRequestHandlerFn(clientCtx)
|
||||
return
|
||||
}
|
||||
|
||||
// eth Tx
|
||||
ethHashPrefixLength := len(ethHashPrefix)
|
||||
output, err := getEthTransactionByHash(clientCtx, hashHexStr[ethHashPrefixLength:])
|
||||
if err != nil {
|
||||
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
rest.PostProcessResponseBare(w, clientCtx, output)
|
||||
}
|
||||
}
|
||||
|
||||
// GetTransactionByHash returns the transaction identified by hash.
|
||||
func getEthTransactionByHash(clientCtx client.Context, hashHex string) ([]byte, error) {
|
||||
hash, err := hex.DecodeString(hashHex)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
node, err := clientCtx.GetNode()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
tx, err := node.Tx(context.Background(), hash, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Can either cache or just leave this out if not necessary
|
||||
block, err := node.Block(context.Background(), &tx.Height)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
client := feemarkettypes.NewQueryClient(clientCtx)
|
||||
res, err := client.BaseFee(context.Background(), &feemarkettypes.QueryBaseFeeRequest{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var baseFee *big.Int
|
||||
if res.BaseFee != nil {
|
||||
baseFee = res.BaseFee.BigInt()
|
||||
}
|
||||
|
||||
blockHash := common.BytesToHash(block.Block.Header.Hash())
|
||||
|
||||
ethTxs, err := rpctypes.RawTxToEthTx(clientCtx, tx.Tx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
height := uint64(tx.Height)
|
||||
|
||||
for _, ethTx := range ethTxs {
|
||||
if common.HexToHash(ethTx.Hash) == common.BytesToHash(hash) {
|
||||
rpcTx, err := rpctypes.NewRPCTransaction(ethTx.AsTransaction(), blockHash, height, uint64(tx.Index), baseFee)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return json.Marshal(rpcTx)
|
||||
}
|
||||
}
|
||||
|
||||
return nil, errors.New("eth tx not found")
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
sdkmath "cosmossdk.io/math"
|
||||
"github.com/gogo/protobuf/proto"
|
||||
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
@@ -86,7 +87,7 @@ func (suite *EvmTestSuite) DoSetupTest(t require.TestingT) {
|
||||
return genesis
|
||||
})
|
||||
|
||||
coins := sdk.NewCoins(sdk.NewCoin(types.DefaultEVMDenom, sdk.NewInt(100000000000000)))
|
||||
coins := sdk.NewCoins(sdk.NewCoin(types.DefaultEVMDenom, sdkmath.NewInt(100000000000000)))
|
||||
genesisState := app.NewTestGenesisState(suite.app.AppCodec())
|
||||
b32address := sdk.MustBech32ifyAddressBytes(sdk.GetConfig().GetBech32AccountAddrPrefix(), priv.PubKey().Address().Bytes())
|
||||
balances := []banktypes.Balance{
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"math/big"
|
||||
"testing"
|
||||
|
||||
sdkmath "cosmossdk.io/math"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
@@ -25,7 +26,7 @@ func SetupContract(b *testing.B) (*KeeperTestSuite, common.Address) {
|
||||
err = suite.app.BankKeeper.SendCoinsFromModuleToAccount(suite.ctx, types.ModuleName, suite.address.Bytes(), amt)
|
||||
require.NoError(b, err)
|
||||
|
||||
contractAddr := suite.DeployTestContract(b, suite.address, sdk.NewIntWithDecimal(1000, 18).BigInt())
|
||||
contractAddr := suite.DeployTestContract(b, suite.address, sdkmath.NewIntWithDecimal(1000, 18).BigInt())
|
||||
suite.Commit()
|
||||
|
||||
return &suite, contractAddr
|
||||
@@ -66,7 +67,7 @@ func DoBenchmark(b *testing.B, txBuilder TxBuilder) {
|
||||
txData, err := types.UnpackTxData(msg.Data)
|
||||
require.NoError(b, err)
|
||||
|
||||
fees := sdk.Coins{sdk.NewCoin(suite.EvmDenom(), sdk.NewIntFromBigInt(txData.Fee()))}
|
||||
fees := sdk.Coins{sdk.NewCoin(suite.EvmDenom(), sdkmath.NewIntFromBigInt(txData.Fee()))}
|
||||
err = authante.DeductFees(suite.app.BankKeeper, suite.ctx, suite.app.AccountKeeper.GetAccount(ctx, msg.GetFrom()), fees)
|
||||
require.NoError(b, err)
|
||||
|
||||
@@ -133,7 +134,7 @@ func BenchmarkMessageCall(b *testing.B) {
|
||||
txData, err := types.UnpackTxData(msg.Data)
|
||||
require.NoError(b, err)
|
||||
|
||||
fees := sdk.Coins{sdk.NewCoin(suite.EvmDenom(), sdk.NewIntFromBigInt(txData.Fee()))}
|
||||
fees := sdk.Coins{sdk.NewCoin(suite.EvmDenom(), sdkmath.NewIntFromBigInt(txData.Fee()))}
|
||||
err = authante.DeductFees(suite.app.BankKeeper, suite.ctx, suite.app.AccountKeeper.GetAccount(ctx, msg.GetFrom()), fees)
|
||||
require.NoError(b, err)
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
|
||||
sdkmath "cosmossdk.io/math"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
@@ -572,7 +573,7 @@ func (k Keeper) BaseFee(c context.Context, _ *types.QueryBaseFeeRequest) (*types
|
||||
|
||||
res := &types.QueryBaseFeeResponse{}
|
||||
if baseFee != nil {
|
||||
aux := sdk.NewIntFromBigInt(baseFee)
|
||||
aux := sdkmath.NewIntFromBigInt(baseFee)
|
||||
res.BaseFee = &aux
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@ import (
|
||||
"fmt"
|
||||
"math/big"
|
||||
|
||||
sdkmath "cosmossdk.io/math"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
"github.com/ethereum/go-ethereum/core/vm"
|
||||
@@ -524,7 +526,7 @@ func (suite *KeeperTestSuite) TestEstimateGas() {
|
||||
}, false, 0, false},
|
||||
// estimate gas of an erc20 contract deployment, the exact gas number is checked with geth
|
||||
{"contract deployment", func() {
|
||||
ctorArgs, err := types.ERC20Contract.ABI.Pack("", &suite.address, sdk.NewIntWithDecimal(1000, 18).BigInt())
|
||||
ctorArgs, err := types.ERC20Contract.ABI.Pack("", &suite.address, sdkmath.NewIntWithDecimal(1000, 18).BigInt())
|
||||
suite.Require().NoError(err)
|
||||
data := append(types.ERC20Contract.Bin, ctorArgs...)
|
||||
args = types.TransactionArgs{
|
||||
@@ -534,7 +536,7 @@ func (suite *KeeperTestSuite) TestEstimateGas() {
|
||||
}, true, 1186778, false},
|
||||
// estimate gas of an erc20 transfer, the exact gas number is checked with geth
|
||||
{"erc20 transfer", func() {
|
||||
contractAddr := suite.DeployTestContract(suite.T(), suite.address, sdk.NewIntWithDecimal(1000, 18).BigInt())
|
||||
contractAddr := suite.DeployTestContract(suite.T(), suite.address, sdkmath.NewIntWithDecimal(1000, 18).BigInt())
|
||||
suite.Commit()
|
||||
transferData, err := types.ERC20Contract.ABI.Pack("transfer", common.HexToAddress("0x378c50D9264C63F3F92B806d4ee56E9D86FfB3Ec"), big.NewInt(1000))
|
||||
suite.Require().NoError(err)
|
||||
@@ -559,7 +561,7 @@ func (suite *KeeperTestSuite) TestEstimateGas() {
|
||||
gasCap = 20000
|
||||
}, false, 0, true},
|
||||
{"contract deployment w/ enableFeemarket", func() {
|
||||
ctorArgs, err := types.ERC20Contract.ABI.Pack("", &suite.address, sdk.NewIntWithDecimal(1000, 18).BigInt())
|
||||
ctorArgs, err := types.ERC20Contract.ABI.Pack("", &suite.address, sdkmath.NewIntWithDecimal(1000, 18).BigInt())
|
||||
suite.Require().NoError(err)
|
||||
data := append(types.ERC20Contract.Bin, ctorArgs...)
|
||||
args = types.TransactionArgs{
|
||||
@@ -568,7 +570,7 @@ func (suite *KeeperTestSuite) TestEstimateGas() {
|
||||
}
|
||||
}, true, 1186778, true},
|
||||
{"erc20 transfer w/ enableFeemarket", func() {
|
||||
contractAddr := suite.DeployTestContract(suite.T(), suite.address, sdk.NewIntWithDecimal(1000, 18).BigInt())
|
||||
contractAddr := suite.DeployTestContract(suite.T(), suite.address, sdkmath.NewIntWithDecimal(1000, 18).BigInt())
|
||||
suite.Commit()
|
||||
transferData, err := types.ERC20Contract.ABI.Pack("transfer", common.HexToAddress("0x378c50D9264C63F3F92B806d4ee56E9D86FfB3Ec"), big.NewInt(1000))
|
||||
suite.Require().NoError(err)
|
||||
@@ -687,11 +689,11 @@ func (suite *KeeperTestSuite) TestTraceTx() {
|
||||
vmdb.SetNonce(suite.address, vmdb.GetNonce(suite.address)+1)
|
||||
suite.Require().NoError(vmdb.Commit())
|
||||
|
||||
contractAddr := suite.DeployTestContract(suite.T(), suite.address, sdk.NewIntWithDecimal(1000, 18).BigInt())
|
||||
contractAddr := suite.DeployTestContract(suite.T(), suite.address, sdkmath.NewIntWithDecimal(1000, 18).BigInt())
|
||||
suite.Commit()
|
||||
// Generate token transfer transaction
|
||||
firstTx := suite.TransferERC20Token(suite.T(), contractAddr, suite.address, common.HexToAddress("0x378c50D9264C63F3F92B806d4ee56E9D86FfB3Ec"), sdk.NewIntWithDecimal(1, 18).BigInt())
|
||||
txMsg = suite.TransferERC20Token(suite.T(), contractAddr, suite.address, common.HexToAddress("0x378c50D9264C63F3F92B806d4ee56E9D86FfB3Ec"), sdk.NewIntWithDecimal(1, 18).BigInt())
|
||||
firstTx := suite.TransferERC20Token(suite.T(), contractAddr, suite.address, common.HexToAddress("0x378c50D9264C63F3F92B806d4ee56E9D86FfB3Ec"), sdkmath.NewIntWithDecimal(1, 18).BigInt())
|
||||
txMsg = suite.TransferERC20Token(suite.T(), contractAddr, suite.address, common.HexToAddress("0x378c50D9264C63F3F92B806d4ee56E9D86FfB3Ec"), sdkmath.NewIntWithDecimal(1, 18).BigInt())
|
||||
suite.Commit()
|
||||
|
||||
predecessors = append(predecessors, firstTx)
|
||||
@@ -707,10 +709,10 @@ func (suite *KeeperTestSuite) TestTraceTx() {
|
||||
suite.enableFeemarket = tc.enableFeemarket
|
||||
suite.SetupTest()
|
||||
// Deploy contract
|
||||
contractAddr := suite.DeployTestContract(suite.T(), suite.address, sdk.NewIntWithDecimal(1000, 18).BigInt())
|
||||
contractAddr := suite.DeployTestContract(suite.T(), suite.address, sdkmath.NewIntWithDecimal(1000, 18).BigInt())
|
||||
suite.Commit()
|
||||
// Generate token transfer transaction
|
||||
txMsg = suite.TransferERC20Token(suite.T(), contractAddr, suite.address, common.HexToAddress("0x378c50D9264C63F3F92B806d4ee56E9D86FfB3Ec"), sdk.NewIntWithDecimal(1, 18).BigInt())
|
||||
txMsg = suite.TransferERC20Token(suite.T(), contractAddr, suite.address, common.HexToAddress("0x378c50D9264C63F3F92B806d4ee56E9D86FfB3Ec"), sdkmath.NewIntWithDecimal(1, 18).BigInt())
|
||||
suite.Commit()
|
||||
|
||||
tc.malleate()
|
||||
@@ -821,11 +823,11 @@ func (suite *KeeperTestSuite) TestTraceBlock() {
|
||||
vmdb.SetNonce(suite.address, vmdb.GetNonce(suite.address)+1)
|
||||
suite.Require().NoError(vmdb.Commit())
|
||||
|
||||
contractAddr := suite.DeployTestContract(suite.T(), suite.address, sdk.NewIntWithDecimal(1000, 18).BigInt())
|
||||
contractAddr := suite.DeployTestContract(suite.T(), suite.address, sdkmath.NewIntWithDecimal(1000, 18).BigInt())
|
||||
suite.Commit()
|
||||
// create multiple transactions in the same block
|
||||
firstTx := suite.TransferERC20Token(suite.T(), contractAddr, suite.address, common.HexToAddress("0x378c50D9264C63F3F92B806d4ee56E9D86FfB3Ec"), sdk.NewIntWithDecimal(1, 18).BigInt())
|
||||
secondTx := suite.TransferERC20Token(suite.T(), contractAddr, suite.address, common.HexToAddress("0x378c50D9264C63F3F92B806d4ee56E9D86FfB3Ec"), sdk.NewIntWithDecimal(1, 18).BigInt())
|
||||
firstTx := suite.TransferERC20Token(suite.T(), contractAddr, suite.address, common.HexToAddress("0x378c50D9264C63F3F92B806d4ee56E9D86FfB3Ec"), sdkmath.NewIntWithDecimal(1, 18).BigInt())
|
||||
secondTx := suite.TransferERC20Token(suite.T(), contractAddr, suite.address, common.HexToAddress("0x378c50D9264C63F3F92B806d4ee56E9D86FfB3Ec"), sdkmath.NewIntWithDecimal(1, 18).BigInt())
|
||||
suite.Commit()
|
||||
// overwrite txs to include only the ones on new block
|
||||
txs = append([]*types.MsgEthereumTx{}, firstTx, secondTx)
|
||||
@@ -842,10 +844,10 @@ func (suite *KeeperTestSuite) TestTraceBlock() {
|
||||
suite.enableFeemarket = tc.enableFeemarket
|
||||
suite.SetupTest()
|
||||
// Deploy contract
|
||||
contractAddr := suite.DeployTestContract(suite.T(), suite.address, sdk.NewIntWithDecimal(1000, 18).BigInt())
|
||||
contractAddr := suite.DeployTestContract(suite.T(), suite.address, sdkmath.NewIntWithDecimal(1000, 18).BigInt())
|
||||
suite.Commit()
|
||||
// Generate token transfer transaction
|
||||
txMsg := suite.TransferERC20Token(suite.T(), contractAddr, suite.address, common.HexToAddress("0x378c50D9264C63F3F92B806d4ee56E9D86FfB3Ec"), sdk.NewIntWithDecimal(1, 18).BigInt())
|
||||
txMsg := suite.TransferERC20Token(suite.T(), contractAddr, suite.address, common.HexToAddress("0x378c50D9264C63F3F92B806d4ee56E9D86FfB3Ec"), sdkmath.NewIntWithDecimal(1, 18).BigInt())
|
||||
suite.Commit()
|
||||
|
||||
txs = append(txs, txMsg)
|
||||
@@ -880,7 +882,7 @@ func (suite *KeeperTestSuite) TestNonceInQuery() {
|
||||
suite.Require().NoError(err)
|
||||
address := common.BytesToAddress(priv.PubKey().Address().Bytes())
|
||||
suite.Require().Equal(uint64(0), suite.app.EvmKeeper.GetNonce(suite.ctx, address))
|
||||
supply := sdk.NewIntWithDecimal(1000, 18).BigInt()
|
||||
supply := sdkmath.NewIntWithDecimal(1000, 18).BigInt()
|
||||
|
||||
// accupy nonce 0
|
||||
_ = suite.DeployTestContract(suite.T(), address, supply)
|
||||
@@ -909,7 +911,7 @@ func (suite *KeeperTestSuite) TestNonceInQuery() {
|
||||
|
||||
func (suite *KeeperTestSuite) TestQueryBaseFee() {
|
||||
var (
|
||||
aux sdk.Int
|
||||
aux sdkmath.Int
|
||||
expRes *types.QueryBaseFeeResponse
|
||||
)
|
||||
|
||||
@@ -923,7 +925,7 @@ func (suite *KeeperTestSuite) TestQueryBaseFee() {
|
||||
{
|
||||
"pass - default Base Fee",
|
||||
func() {
|
||||
initialBaseFee := sdk.NewInt(ethparams.InitialBaseFee)
|
||||
initialBaseFee := sdkmath.NewInt(ethparams.InitialBaseFee)
|
||||
expRes = &types.QueryBaseFeeResponse{BaseFee: &initialBaseFee}
|
||||
},
|
||||
true, true, true,
|
||||
@@ -934,7 +936,7 @@ func (suite *KeeperTestSuite) TestQueryBaseFee() {
|
||||
baseFee := sdk.OneInt().BigInt()
|
||||
suite.app.FeeMarketKeeper.SetBaseFee(suite.ctx, baseFee)
|
||||
|
||||
aux = sdk.NewIntFromBigInt(baseFee)
|
||||
aux = sdkmath.NewIntFromBigInt(baseFee)
|
||||
expRes = &types.QueryBaseFeeResponse{BaseFee: &aux}
|
||||
},
|
||||
true, true, true,
|
||||
|
||||
@@ -183,7 +183,7 @@ func setupChain(localMinGasPricesStr string) {
|
||||
baseapp.SetMinGasPrices(localMinGasPricesStr),
|
||||
)
|
||||
|
||||
genesisState := app.NewDefaultGenesisState()
|
||||
genesisState := app.NewTestGenesisState(newapp.AppCodec())
|
||||
genesisState[types.ModuleName] = newapp.AppCodec().MustMarshalJSON(types.DefaultGenesisState())
|
||||
|
||||
stateBytes, err := json.MarshalIndent(genesisState, "", " ")
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/store/prefix"
|
||||
storetypes "github.com/cosmos/cosmos-sdk/store/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
|
||||
@@ -29,10 +30,10 @@ type Keeper struct {
|
||||
// - storing account's Code
|
||||
// - storing transaction Logs
|
||||
// - storing Bloom filters by block height. Needed for the Web3 API.
|
||||
storeKey sdk.StoreKey
|
||||
storeKey storetypes.StoreKey
|
||||
|
||||
// key to access the transient store, which is reset on every block during Commit
|
||||
transientKey sdk.StoreKey
|
||||
transientKey storetypes.StoreKey
|
||||
|
||||
// module specific parameter space that can be configured through governance
|
||||
paramSpace paramtypes.Subspace
|
||||
@@ -58,7 +59,7 @@ type Keeper struct {
|
||||
// NewKeeper generates new evm module keeper
|
||||
func NewKeeper(
|
||||
cdc codec.BinaryCodec,
|
||||
storeKey, transientKey sdk.StoreKey, paramSpace paramtypes.Subspace,
|
||||
storeKey, transientKey storetypes.StoreKey, paramSpace paramtypes.Subspace,
|
||||
ak types.AccountKeeper, bankKeeper types.BankKeeper, sk types.StakingKeeper,
|
||||
fmk types.FeeMarketKeeper,
|
||||
tracer string,
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
sdkmath "cosmossdk.io/math"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
@@ -49,7 +50,7 @@ import (
|
||||
"github.com/tendermint/tendermint/version"
|
||||
)
|
||||
|
||||
var testTokens = sdk.NewIntWithDecimal(1000, 18)
|
||||
var testTokens = sdkmath.NewIntWithDecimal(1000, 18)
|
||||
|
||||
type KeeperTestSuite struct {
|
||||
suite.Suite
|
||||
@@ -120,7 +121,7 @@ func (suite *KeeperTestSuite) SetupApp(checkTx bool) {
|
||||
genesis[feemarkettypes.ModuleName] = app.AppCodec().MustMarshalJSON(feemarketGenesis)
|
||||
if !suite.enableLondonHF {
|
||||
evmGenesis := types.DefaultGenesisState()
|
||||
maxInt := sdk.NewInt(math.MaxInt64)
|
||||
maxInt := sdkmath.NewInt(math.MaxInt64)
|
||||
evmGenesis.Params.ChainConfig.LondonBlock = &maxInt
|
||||
evmGenesis.Params.ChainConfig.ArrowGlacierBlock = &maxInt
|
||||
evmGenesis.Params.ChainConfig.GrayGlacierBlock = &maxInt
|
||||
@@ -132,7 +133,7 @@ func (suite *KeeperTestSuite) SetupApp(checkTx bool) {
|
||||
|
||||
if suite.mintFeeCollector {
|
||||
// mint some coin to fee collector
|
||||
coins := sdk.NewCoins(sdk.NewCoin(types.DefaultEVMDenom, sdk.NewInt(int64(params.TxGas)-1)))
|
||||
coins := sdk.NewCoins(sdk.NewCoin(types.DefaultEVMDenom, sdkmath.NewInt(int64(params.TxGas)-1)))
|
||||
genesisState := app.NewTestGenesisState(suite.app.AppCodec())
|
||||
balances := []banktypes.Balance{
|
||||
{
|
||||
@@ -208,7 +209,7 @@ func (suite *KeeperTestSuite) SetupApp(checkTx bool) {
|
||||
encodingConfig := encoding.MakeConfig(app.ModuleBasics)
|
||||
suite.clientCtx = client.Context{}.WithTxConfig(encodingConfig.TxConfig)
|
||||
suite.ethSigner = ethtypes.LatestSignerForChainID(suite.app.EvmKeeper.ChainID())
|
||||
suite.appCodec = encodingConfig.Marshaler
|
||||
suite.appCodec = encodingConfig.Codec
|
||||
suite.denom = evmtypes.DefaultEVMDenom
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"math"
|
||||
"math/big"
|
||||
|
||||
sdkmath "cosmossdk.io/math"
|
||||
|
||||
tmtypes "github.com/tendermint/tendermint/types"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
@@ -484,7 +486,7 @@ func (k *Keeper) RefundGas(ctx sdk.Context, msg core.Message, leftoverGas uint64
|
||||
return sdkerrors.Wrapf(types.ErrInvalidRefund, "refunded amount value cannot be negative %d", remaining.Int64())
|
||||
case 1:
|
||||
// positive amount refund
|
||||
refundedCoins := sdk.Coins{sdk.NewCoin(denom, sdk.NewIntFromBigInt(remaining))}
|
||||
refundedCoins := sdk.Coins{sdk.NewCoin(denom, sdkmath.NewIntFromBigInt(remaining))}
|
||||
|
||||
// refund to sender from the fee collector module account, which is the escrow account in charge of collecting tx fees
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@ import (
|
||||
"fmt"
|
||||
"math/big"
|
||||
|
||||
sdkmath "cosmossdk.io/math"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/store/prefix"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
@@ -79,7 +81,7 @@ func (k *Keeper) SetBalance(ctx sdk.Context, addr common.Address, amount *big.In
|
||||
switch delta.Sign() {
|
||||
case 1:
|
||||
// mint
|
||||
coins := sdk.NewCoins(sdk.NewCoin(params.EvmDenom, sdk.NewIntFromBigInt(delta)))
|
||||
coins := sdk.NewCoins(sdk.NewCoin(params.EvmDenom, sdkmath.NewIntFromBigInt(delta)))
|
||||
if err := k.bankKeeper.MintCoins(ctx, types.ModuleName, coins); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -88,7 +90,7 @@ func (k *Keeper) SetBalance(ctx sdk.Context, addr common.Address, amount *big.In
|
||||
}
|
||||
case -1:
|
||||
// burn
|
||||
coins := sdk.NewCoins(sdk.NewCoin(params.EvmDenom, sdk.NewIntFromBigInt(new(big.Int).Neg(delta))))
|
||||
coins := sdk.NewCoins(sdk.NewCoin(params.EvmDenom, sdkmath.NewIntFromBigInt(new(big.Int).Neg(delta))))
|
||||
if err := k.bankKeeper.SendCoinsFromAccountToModule(ctx, cosmosAddr, types.ModuleName, coins); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package keeper
|
||||
import (
|
||||
"math/big"
|
||||
|
||||
sdkmath "cosmossdk.io/math"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
authante "github.com/cosmos/cosmos-sdk/x/auth/ante"
|
||||
@@ -71,7 +72,7 @@ func (k Keeper) DeductTxCostsFromUserBalance(
|
||||
return sdk.Coins{}, nil
|
||||
}
|
||||
|
||||
fees := sdk.Coins{sdk.NewCoin(denom, sdk.NewIntFromBigInt(feeAmt))}
|
||||
fees := sdk.Coins{sdk.NewCoin(denom, sdkmath.NewIntFromBigInt(feeAmt))}
|
||||
|
||||
// deduct the full gas cost from the user balance
|
||||
if err := authante.DeductFees(k.bankKeeper, ctx, signerAcc, fees); err != nil {
|
||||
@@ -87,7 +88,7 @@ func (k Keeper) DeductTxCostsFromUserBalance(
|
||||
// CheckSenderBalance validates that the tx cost value is positive and that the
|
||||
// sender has enough funds to pay for the fees and value of the transaction.
|
||||
func CheckSenderBalance(
|
||||
balance sdk.Int,
|
||||
balance sdkmath.Int,
|
||||
txData evmtypes.TxData,
|
||||
) error {
|
||||
cost := txData.Cost()
|
||||
|
||||
+17
-16
@@ -3,6 +3,7 @@ package keeper_test
|
||||
import (
|
||||
"math/big"
|
||||
|
||||
sdkmath "cosmossdk.io/math"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
ethtypes "github.com/ethereum/go-ethereum/core/types"
|
||||
@@ -12,21 +13,21 @@ import (
|
||||
)
|
||||
|
||||
func (suite *KeeperTestSuite) TestCheckSenderBalance() {
|
||||
hundredInt := sdk.NewInt(100)
|
||||
hundredInt := sdkmath.NewInt(100)
|
||||
zeroInt := sdk.ZeroInt()
|
||||
oneInt := sdk.OneInt()
|
||||
fiveInt := sdk.NewInt(5)
|
||||
fiftyInt := sdk.NewInt(50)
|
||||
negInt := sdk.NewInt(-10)
|
||||
fiveInt := sdkmath.NewInt(5)
|
||||
fiftyInt := sdkmath.NewInt(50)
|
||||
negInt := sdkmath.NewInt(-10)
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
to string
|
||||
gasLimit uint64
|
||||
gasPrice *sdk.Int
|
||||
gasPrice *sdkmath.Int
|
||||
gasFeeCap *big.Int
|
||||
gasTipCap *big.Int
|
||||
cost *sdk.Int
|
||||
cost *sdkmath.Int
|
||||
from string
|
||||
accessList *ethtypes.AccessList
|
||||
expectPass bool
|
||||
@@ -237,7 +238,7 @@ func (suite *KeeperTestSuite) TestCheckSenderBalance() {
|
||||
|
||||
acct := suite.app.EvmKeeper.GetAccountOrEmpty(suite.ctx, suite.address)
|
||||
err := evmkeeper.CheckSenderBalance(
|
||||
sdk.NewIntFromBigInt(acct.Balance),
|
||||
sdkmath.NewIntFromBigInt(acct.Balance),
|
||||
txData,
|
||||
)
|
||||
|
||||
@@ -251,22 +252,22 @@ func (suite *KeeperTestSuite) TestCheckSenderBalance() {
|
||||
}
|
||||
|
||||
func (suite *KeeperTestSuite) TestDeductTxCostsFromUserBalance() {
|
||||
hundredInt := sdk.NewInt(100)
|
||||
hundredInt := sdkmath.NewInt(100)
|
||||
zeroInt := sdk.ZeroInt()
|
||||
oneInt := sdk.NewInt(1)
|
||||
fiveInt := sdk.NewInt(5)
|
||||
fiftyInt := sdk.NewInt(50)
|
||||
oneInt := sdkmath.NewInt(1)
|
||||
fiveInt := sdkmath.NewInt(5)
|
||||
fiftyInt := sdkmath.NewInt(50)
|
||||
|
||||
// should be enough to cover all test cases
|
||||
initBalance := sdk.NewInt((ethparams.InitialBaseFee + 10) * 105)
|
||||
initBalance := sdkmath.NewInt((ethparams.InitialBaseFee + 10) * 105)
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
gasLimit uint64
|
||||
gasPrice *sdk.Int
|
||||
gasPrice *sdkmath.Int
|
||||
gasFeeCap *big.Int
|
||||
gasTipCap *big.Int
|
||||
cost *sdk.Int
|
||||
cost *sdkmath.Int
|
||||
accessList *ethtypes.AccessList
|
||||
expectPass bool
|
||||
enableFeemarket bool
|
||||
@@ -419,7 +420,7 @@ func (suite *KeeperTestSuite) TestDeductTxCostsFromUserBalance() {
|
||||
suite.Require().Equal(
|
||||
fees,
|
||||
sdk.NewCoins(
|
||||
sdk.NewCoin(evmtypes.DefaultEVMDenom, sdk.NewIntFromBigInt(txData.EffectiveFee(baseFee))),
|
||||
sdk.NewCoin(evmtypes.DefaultEVMDenom, sdkmath.NewIntFromBigInt(txData.EffectiveFee(baseFee))),
|
||||
),
|
||||
"valid test %d failed, fee value is wrong ", i,
|
||||
)
|
||||
@@ -427,7 +428,7 @@ func (suite *KeeperTestSuite) TestDeductTxCostsFromUserBalance() {
|
||||
suite.Require().Equal(
|
||||
fees,
|
||||
sdk.NewCoins(
|
||||
sdk.NewCoin(evmtypes.DefaultEVMDenom, tc.gasPrice.Mul(sdk.NewIntFromUint64(tc.gasLimit))),
|
||||
sdk.NewCoin(evmtypes.DefaultEVMDenom, tc.gasPrice.Mul(sdkmath.NewIntFromUint64(tc.gasLimit))),
|
||||
),
|
||||
"valid test %d failed, fee value is wrong ", i,
|
||||
)
|
||||
|
||||
@@ -24,7 +24,7 @@ func TestMigrateStore(t *testing.T) {
|
||||
tFeeMarketKey := sdk.NewTransientStoreKey(fmt.Sprintf("%s_test", types.StoreKey))
|
||||
ctx := testutil.DefaultContext(feemarketKey, tFeeMarketKey)
|
||||
paramstore := paramtypes.NewSubspace(
|
||||
encCfg.Marshaler, encCfg.Amino, feemarketKey, tFeeMarketKey, "evm",
|
||||
encCfg.Codec, encCfg.Amino, feemarketKey, tFeeMarketKey, "evm",
|
||||
).WithKeyTable(v2types.ParamKeyTable())
|
||||
|
||||
params := v2types.DefaultParams()
|
||||
@@ -36,7 +36,7 @@ func TestMigrateStore(t *testing.T) {
|
||||
})
|
||||
|
||||
paramstore = paramtypes.NewSubspace(
|
||||
encCfg.Marshaler, encCfg.Amino, feemarketKey, tFeeMarketKey, "evm",
|
||||
encCfg.Codec, encCfg.Amino, feemarketKey, tFeeMarketKey, "evm",
|
||||
).WithKeyTable(types.ParamKeyTable())
|
||||
err := v2.MigrateStore(ctx, ¶mstore)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"math/big"
|
||||
"strings"
|
||||
|
||||
sdkmath "cosmossdk.io/math"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
|
||||
@@ -77,7 +79,7 @@ func DefaultChainConfig() ChainConfig {
|
||||
}
|
||||
}
|
||||
|
||||
func getBlockValue(block *sdk.Int) *big.Int {
|
||||
func getBlockValue(block *sdkmath.Int) *big.Int {
|
||||
if block == nil || block.IsNegative() {
|
||||
return nil
|
||||
}
|
||||
@@ -149,7 +151,7 @@ func validateHash(hex string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateBlock(block *sdk.Int) error {
|
||||
func validateBlock(block *sdkmath.Int) error {
|
||||
// nil value means that the fork has not yet been applied
|
||||
if block == nil {
|
||||
return nil
|
||||
|
||||
Generated
+1
-1
@@ -107,7 +107,7 @@ func (m *Params) GetChainConfig() ChainConfig {
|
||||
return ChainConfig{}
|
||||
}
|
||||
|
||||
// ChainConfig defines the Ethereum ChainConfig parameters using *sdk.Int values
|
||||
// ChainConfig defines the Ethereum ChainConfig parameters using *sdkmath.Int values
|
||||
// instead of *big.Int.
|
||||
type ChainConfig struct {
|
||||
// Homestead switch block (nil no fork, 0 = already homestead)
|
||||
|
||||
@@ -2,9 +2,10 @@ package v3_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
v3 "github.com/evmos/ethermint/x/evm/migrations/v3"
|
||||
"testing"
|
||||
|
||||
v3 "github.com/evmos/ethermint/x/evm/migrations/v3"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
@@ -24,7 +25,7 @@ func TestMigrateStore(t *testing.T) {
|
||||
tEvmKey := sdk.NewTransientStoreKey(fmt.Sprintf("%s_test", types.StoreKey))
|
||||
ctx := testutil.DefaultContext(evmKey, tEvmKey)
|
||||
paramstore := paramtypes.NewSubspace(
|
||||
encCfg.Marshaler, encCfg.Amino, evmKey, tEvmKey, "evm",
|
||||
encCfg.Codec, encCfg.Amino, evmKey, tEvmKey, "evm",
|
||||
).WithKeyTable(v3types.ParamKeyTable())
|
||||
|
||||
params := v3types.DefaultParams()
|
||||
@@ -39,7 +40,7 @@ func TestMigrateStore(t *testing.T) {
|
||||
require.NotNil(t, preMigrationConfig.MergeForkBlock)
|
||||
|
||||
paramstore = paramtypes.NewSubspace(
|
||||
encCfg.Marshaler, encCfg.Amino, evmKey, tEvmKey, "evm",
|
||||
encCfg.Codec, encCfg.Amino, evmKey, tEvmKey, "evm",
|
||||
).WithKeyTable(types.ParamKeyTable())
|
||||
err := v3.MigrateStore(ctx, ¶mstore)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"math/big"
|
||||
"strings"
|
||||
|
||||
sdkmath "cosmossdk.io/math"
|
||||
|
||||
"github.com/evmos/ethermint/x/evm/types"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
@@ -76,7 +78,7 @@ func DefaultChainConfig() ChainConfig {
|
||||
}
|
||||
}
|
||||
|
||||
func getBlockValue(block *sdk.Int) *big.Int {
|
||||
func getBlockValue(block *sdkmath.Int) *big.Int {
|
||||
if block == nil || block.IsNegative() {
|
||||
return nil
|
||||
}
|
||||
@@ -148,7 +150,7 @@ func validateHash(hex string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateBlock(block *sdk.Int) error {
|
||||
func validateBlock(block *sdkmath.Int) error {
|
||||
// nil value means that the fork has not yet been applied
|
||||
if block == nil {
|
||||
return nil
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"math/rand"
|
||||
"testing"
|
||||
|
||||
sdkmath "cosmossdk.io/math"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
@@ -31,7 +32,7 @@ func TestRandomizedGenState(t *testing.T) {
|
||||
Rand: r,
|
||||
NumBonded: 3,
|
||||
Accounts: simtypes.RandomAccounts(r, 3),
|
||||
InitialStake: 1000,
|
||||
InitialStake: sdkmath.NewInt(1000),
|
||||
GenState: make(map[string]json.RawMessage),
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,8 @@ import (
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
sdkmath "cosmossdk.io/math"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/baseapp"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
@@ -123,7 +125,7 @@ func SimulateEthCreateContract(ak types.AccountKeeper, k *keeper.Keeper) simtype
|
||||
from := common.BytesToAddress(simAccount.Address)
|
||||
nonce := k.GetNonce(ctx, from)
|
||||
|
||||
ctorArgs, err := types.ERC20Contract.ABI.Pack("", from, sdk.NewIntWithDecimal(1000, 18).BigInt())
|
||||
ctorArgs, err := types.ERC20Contract.ABI.Pack("", from, sdkmath.NewIntWithDecimal(1000, 18).BigInt())
|
||||
if err != nil {
|
||||
return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgEthereumTx, "can not pack owner and supply"), nil, err
|
||||
}
|
||||
@@ -192,7 +194,7 @@ func SimulateEthTx(
|
||||
return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgEthereumTx, "can not sign ethereum tx"), nil, err
|
||||
}
|
||||
|
||||
_, _, err = ctx.bapp.Deliver(txConfig.TxEncoder(), signedTx)
|
||||
_, _, err = ctx.bapp.SimDeliver(txConfig.TxEncoder(), signedTx)
|
||||
if err != nil {
|
||||
return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgEthereumTx, "failed to deliver tx"), nil, err
|
||||
}
|
||||
@@ -258,7 +260,7 @@ func RandomTransferableAmount(ctx *simulateContext, address common.Address, esti
|
||||
amount = new(big.Int).Set(spendable)
|
||||
return amount, nil
|
||||
}
|
||||
simAmount, err := simtypes.RandPositiveInt(ctx.rand, sdk.NewIntFromBigInt(spendable))
|
||||
simAmount, err := simtypes.RandPositiveInt(ctx.rand, sdkmath.NewIntFromBigInt(spendable))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -291,7 +293,7 @@ func GetSignedTx(ctx *simulateContext, txBuilder client.TxBuilder, msg *types.Ms
|
||||
return nil, err
|
||||
}
|
||||
|
||||
fees := sdk.NewCoins(sdk.NewCoin(ctx.keeper.GetParams(ctx.context).EvmDenom, sdk.NewIntFromBigInt(txData.Fee())))
|
||||
fees := sdk.NewCoins(sdk.NewCoin(ctx.keeper.GetParams(ctx.context).EvmDenom, sdkmath.NewIntFromBigInt(txData.Fee())))
|
||||
builder.SetFeeAmount(fees)
|
||||
builder.SetGasLimit(msg.GetGas())
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package types
|
||||
import (
|
||||
"math/big"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
sdkmath "cosmossdk.io/math"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
@@ -174,7 +174,7 @@ func (tx *AccessListTx) SetSignatureValues(chainID, v, r, s *big.Int) {
|
||||
tx.S = s.Bytes()
|
||||
}
|
||||
if chainID != nil {
|
||||
chainIDInt := sdk.NewIntFromBigInt(chainID)
|
||||
chainIDInt := sdkmath.NewIntFromBigInt(chainID)
|
||||
tx.ChainID = &chainIDInt
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"math/big"
|
||||
"strings"
|
||||
|
||||
sdkmath "cosmossdk.io/math"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
|
||||
@@ -78,7 +80,7 @@ func DefaultChainConfig() ChainConfig {
|
||||
}
|
||||
}
|
||||
|
||||
func getBlockValue(block *sdk.Int) *big.Int {
|
||||
func getBlockValue(block *sdkmath.Int) *big.Int {
|
||||
if block == nil || block.IsNegative() {
|
||||
return nil
|
||||
}
|
||||
@@ -153,7 +155,7 @@ func validateHash(hex string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateBlock(block *sdk.Int) error {
|
||||
func validateBlock(block *sdkmath.Int) error {
|
||||
// nil value means that the fork has not yet been applied
|
||||
if block == nil {
|
||||
return nil
|
||||
|
||||
@@ -3,17 +3,16 @@ package types
|
||||
import (
|
||||
"testing"
|
||||
|
||||
sdkmath "cosmossdk.io/math"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
)
|
||||
|
||||
var defaultEIP150Hash = common.Hash{}.String()
|
||||
|
||||
func newIntPtr(i int64) *sdk.Int {
|
||||
v := sdk.NewInt(i)
|
||||
func newIntPtr(i int64) *sdkmath.Int {
|
||||
v := sdkmath.NewInt(i)
|
||||
return &v
|
||||
}
|
||||
|
||||
|
||||
@@ -6,24 +6,20 @@ import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
"github.com/cosmos/cosmos-sdk/types/msgservice"
|
||||
"github.com/cosmos/cosmos-sdk/types/tx"
|
||||
proto "github.com/gogo/protobuf/proto"
|
||||
)
|
||||
|
||||
var ModuleCdc = codec.NewProtoCodec(codectypes.NewInterfaceRegistry())
|
||||
|
||||
type (
|
||||
ExtensionOptionsEthereumTxI interface{}
|
||||
)
|
||||
|
||||
// RegisterInterfaces registers the client interfaces to protobuf Any.
|
||||
func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
|
||||
registry.RegisterImplementations(
|
||||
(*sdk.Msg)(nil),
|
||||
&MsgEthereumTx{},
|
||||
)
|
||||
registry.RegisterInterface(
|
||||
"ethermint.evm.v1.ExtensionOptionsEthereumTx",
|
||||
(*ExtensionOptionsEthereumTxI)(nil),
|
||||
registry.RegisterImplementations(
|
||||
(*tx.TxExtensionOptionI)(nil),
|
||||
&ExtensionOptionsEthereumTx{},
|
||||
)
|
||||
registry.RegisterInterface(
|
||||
|
||||
@@ -3,7 +3,7 @@ package types
|
||||
import (
|
||||
"math/big"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
sdkmath "cosmossdk.io/math"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
@@ -188,7 +188,7 @@ func (tx *DynamicFeeTx) SetSignatureValues(chainID, v, r, s *big.Int) {
|
||||
tx.S = s.Bytes()
|
||||
}
|
||||
if chainID != nil {
|
||||
chainIDInt := sdk.NewIntFromBigInt(chainID)
|
||||
chainIDInt := sdkmath.NewIntFromBigInt(chainID)
|
||||
tx.ChainID = &chainIDInt
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"math/big"
|
||||
"testing"
|
||||
|
||||
sdkmath "cosmossdk.io/math"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
ethtypes "github.com/ethereum/go-ethereum/core/types"
|
||||
@@ -14,24 +16,24 @@ import (
|
||||
type TxDataTestSuite struct {
|
||||
suite.Suite
|
||||
|
||||
sdkInt sdk.Int
|
||||
sdkInt sdkmath.Int
|
||||
uint64 uint64
|
||||
bigInt *big.Int
|
||||
overflowBigInt *big.Int
|
||||
sdkZeroInt sdk.Int
|
||||
sdkMinusOneInt sdk.Int
|
||||
sdkZeroInt sdkmath.Int
|
||||
sdkMinusOneInt sdkmath.Int
|
||||
invalidAddr string
|
||||
addr common.Address
|
||||
hexAddr string
|
||||
}
|
||||
|
||||
func (suite *TxDataTestSuite) SetupTest() {
|
||||
suite.sdkInt = sdk.NewInt(100)
|
||||
suite.sdkInt = sdkmath.NewInt(100)
|
||||
suite.uint64 = suite.sdkInt.Uint64()
|
||||
suite.bigInt = big.NewInt(1)
|
||||
suite.overflowBigInt = big.NewInt(0).Exp(big.NewInt(10), big.NewInt(256), nil)
|
||||
suite.sdkZeroInt = sdk.ZeroInt()
|
||||
suite.sdkMinusOneInt = sdk.NewInt(-1)
|
||||
suite.sdkMinusOneInt = sdkmath.NewInt(-1)
|
||||
suite.invalidAddr = "123456"
|
||||
suite.addr = tests.GenerateAddress()
|
||||
suite.hexAddr = suite.addr.Hex()
|
||||
|
||||
Generated
+1
-1
@@ -117,7 +117,7 @@ func (m *Params) GetAllowUnprotectedTxs() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// ChainConfig defines the Ethereum ChainConfig parameters using *sdk.Int values
|
||||
// ChainConfig defines the Ethereum ChainConfig parameters using *sdkmath.Int values
|
||||
// instead of *big.Int.
|
||||
type ChainConfig struct {
|
||||
// Homestead switch block (nil no fork, 0 = already homestead)
|
||||
|
||||
@@ -27,10 +27,9 @@ type AccountKeeper interface {
|
||||
|
||||
// BankKeeper defines the expected interface needed to retrieve account balances.
|
||||
type BankKeeper interface {
|
||||
authtypes.BankKeeper
|
||||
GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin
|
||||
SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error
|
||||
// SendCoinsFromModuleToModule(ctx sdk.Context, senderModule, recipientModule string, amt sdk.Coins) error
|
||||
SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error
|
||||
MintCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error
|
||||
BurnCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error
|
||||
}
|
||||
|
||||
+9
-7
@@ -5,6 +5,8 @@ import (
|
||||
"fmt"
|
||||
"math/big"
|
||||
|
||||
sdkmath "cosmossdk.io/math"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
@@ -62,7 +64,7 @@ func newMsgEthereumTx(
|
||||
gasLimit uint64, gasPrice, gasFeeCap, gasTipCap *big.Int, input []byte, accesses *ethtypes.AccessList,
|
||||
) *MsgEthereumTx {
|
||||
var (
|
||||
cid, amt, gp *sdk.Int
|
||||
cid, amt, gp *sdkmath.Int
|
||||
toAddr string
|
||||
txData TxData
|
||||
)
|
||||
@@ -72,17 +74,17 @@ func newMsgEthereumTx(
|
||||
}
|
||||
|
||||
if amount != nil {
|
||||
amountInt := sdk.NewIntFromBigInt(amount)
|
||||
amountInt := sdkmath.NewIntFromBigInt(amount)
|
||||
amt = &amountInt
|
||||
}
|
||||
|
||||
if chainID != nil {
|
||||
chainIDInt := sdk.NewIntFromBigInt(chainID)
|
||||
chainIDInt := sdkmath.NewIntFromBigInt(chainID)
|
||||
cid = &chainIDInt
|
||||
}
|
||||
|
||||
if gasPrice != nil {
|
||||
gasPriceInt := sdk.NewIntFromBigInt(gasPrice)
|
||||
gasPriceInt := sdkmath.NewIntFromBigInt(gasPrice)
|
||||
gp = &gasPriceInt
|
||||
}
|
||||
|
||||
@@ -97,8 +99,8 @@ func newMsgEthereumTx(
|
||||
Data: input,
|
||||
}
|
||||
case accesses != nil && gasFeeCap != nil && gasTipCap != nil:
|
||||
gtc := sdk.NewIntFromBigInt(gasTipCap)
|
||||
gfc := sdk.NewIntFromBigInt(gasFeeCap)
|
||||
gtc := sdkmath.NewIntFromBigInt(gasTipCap)
|
||||
gfc := sdkmath.NewIntFromBigInt(gasFeeCap)
|
||||
|
||||
txData = &DynamicFeeTx{
|
||||
ChainID: cid,
|
||||
@@ -352,7 +354,7 @@ func (msg *MsgEthereumTx) BuildTx(b client.TxBuilder, evmDenom string) (signing.
|
||||
return nil, err
|
||||
}
|
||||
fees := make(sdk.Coins, 0)
|
||||
feeAmt := sdk.NewIntFromBigInt(txData.Fee())
|
||||
feeAmt := sdkmath.NewIntFromBigInt(txData.Fee())
|
||||
if feeAmt.Sign() > 0 {
|
||||
fees = append(fees, sdk.NewCoin(evmDenom, feeAmt))
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
sdkmath "cosmossdk.io/math"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
@@ -104,7 +105,7 @@ func (suite *MsgsTestSuite) TestMsgEthereumTx_BuildTx() {
|
||||
suite.Require().Empty(tx.GetMemo())
|
||||
suite.Require().Empty(tx.GetTimeoutHeight())
|
||||
suite.Require().Equal(uint64(100000), tx.GetGas())
|
||||
suite.Require().Equal(sdk.NewCoins(sdk.NewCoin("aphoton", sdk.NewInt(100000))), tx.GetFee())
|
||||
suite.Require().Equal(sdk.NewCoins(sdk.NewCoin("aphoton", sdkmath.NewInt(100000))), tx.GetFee())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,8 @@ import (
|
||||
"fmt"
|
||||
"math/big"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
sdkmath "cosmossdk.io/math"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
"github.com/ethereum/go-ethereum/common/math"
|
||||
@@ -55,14 +56,14 @@ func (args *TransactionArgs) String() string {
|
||||
// This assumes that setTxDefaults has been called.
|
||||
func (args *TransactionArgs) ToTransaction() *MsgEthereumTx {
|
||||
var (
|
||||
chainID, value, gasPrice, maxFeePerGas, maxPriorityFeePerGas sdk.Int
|
||||
chainID, value, gasPrice, maxFeePerGas, maxPriorityFeePerGas sdkmath.Int
|
||||
gas, nonce uint64
|
||||
from, to string
|
||||
)
|
||||
|
||||
// Set sender address or use zero address if none specified.
|
||||
if args.ChainID != nil {
|
||||
chainID = sdk.NewIntFromBigInt(args.ChainID.ToInt())
|
||||
chainID = sdkmath.NewIntFromBigInt(args.ChainID.ToInt())
|
||||
}
|
||||
|
||||
if args.Nonce != nil {
|
||||
@@ -74,19 +75,19 @@ func (args *TransactionArgs) ToTransaction() *MsgEthereumTx {
|
||||
}
|
||||
|
||||
if args.GasPrice != nil {
|
||||
gasPrice = sdk.NewIntFromBigInt(args.GasPrice.ToInt())
|
||||
gasPrice = sdkmath.NewIntFromBigInt(args.GasPrice.ToInt())
|
||||
}
|
||||
|
||||
if args.MaxFeePerGas != nil {
|
||||
maxFeePerGas = sdk.NewIntFromBigInt(args.MaxFeePerGas.ToInt())
|
||||
maxFeePerGas = sdkmath.NewIntFromBigInt(args.MaxFeePerGas.ToInt())
|
||||
}
|
||||
|
||||
if args.MaxPriorityFeePerGas != nil {
|
||||
maxPriorityFeePerGas = sdk.NewIntFromBigInt(args.MaxPriorityFeePerGas.ToInt())
|
||||
maxPriorityFeePerGas = sdkmath.NewIntFromBigInt(args.MaxPriorityFeePerGas.ToInt())
|
||||
}
|
||||
|
||||
if args.Value != nil {
|
||||
value = sdk.NewIntFromBigInt(args.Value.ToInt())
|
||||
value = sdkmath.NewIntFromBigInt(args.Value.ToInt())
|
||||
}
|
||||
|
||||
if args.To != nil {
|
||||
|
||||
@@ -4,13 +4,12 @@ import (
|
||||
"math/big"
|
||||
"testing"
|
||||
|
||||
sdkmath "cosmossdk.io/math"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
func TestTxData_chainID(t *testing.T) {
|
||||
chainID := sdk.NewInt(1)
|
||||
chainID := sdkmath.NewInt(1)
|
||||
|
||||
testCases := []struct {
|
||||
msg string
|
||||
|
||||
@@ -21,15 +21,12 @@ func DecodeTxResponse(in []byte) (*MsgEthereumTxResponse, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
data := txMsgData.GetData()
|
||||
if len(data) == 0 {
|
||||
if len(txMsgData.MsgResponses) == 0 {
|
||||
return &MsgEthereumTxResponse{}, nil
|
||||
}
|
||||
|
||||
var res MsgEthereumTxResponse
|
||||
|
||||
err := proto.Unmarshal(data[0].GetData(), &res)
|
||||
if err != nil {
|
||||
if err := proto.Unmarshal(txMsgData.MsgResponses[0].Value, &res); err != nil {
|
||||
return nil, sdkerrors.Wrap(err, "failed to unmarshal tx response message data")
|
||||
}
|
||||
|
||||
@@ -41,7 +38,7 @@ func EncodeTransactionLogs(res *TransactionLogs) ([]byte, error) {
|
||||
return proto.Marshal(res)
|
||||
}
|
||||
|
||||
// DecodeTxResponse decodes an protobuf-encoded byte slice into TransactionLogs
|
||||
// DecodeTransactionLogs decodes an protobuf-encoded byte slice into TransactionLogs
|
||||
func DecodeTransactionLogs(data []byte) (TransactionLogs, error) {
|
||||
var logs TransactionLogs
|
||||
err := proto.Unmarshal(data, &logs)
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
|
||||
"github.com/evmos/ethermint/app"
|
||||
@@ -30,11 +31,9 @@ func TestEvmDataEncoding(t *testing.T) {
|
||||
Ret: ret,
|
||||
}
|
||||
|
||||
enc, err := proto.Marshal(data)
|
||||
require.NoError(t, err)
|
||||
|
||||
any := codectypes.UnsafePackAny(data)
|
||||
txData := &sdk.TxMsgData{
|
||||
Data: []*sdk.MsgData{{MsgType: evmtypes.TypeMsgEthereumTx, Data: enc}},
|
||||
MsgResponses: []*codectypes.Any{any},
|
||||
}
|
||||
|
||||
txDataBz, err := proto.Marshal(txData)
|
||||
|
||||
Reference in New Issue
Block a user