Skip to content

Commit

Permalink
Merge pull request CosmWasm#2 from oraichain/feat/move-test-prepare-v050
Browse files Browse the repository at this point in the history
Feat/move test prepare v050
  • Loading branch information
tubackkhoa authored Oct 2, 2024
2 parents 5fe3251 + 8ccfa31 commit 7209273
Show file tree
Hide file tree
Showing 64 changed files with 3,011 additions and 613 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*.swl
*.swm
*.swn
*.txt
.vscode
.idea

Expand Down Expand Up @@ -46,4 +47,4 @@ dependency-graph.png
*.out
*.synctex.gz

.oraid
.oraid
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ ifeq ($(OS),Windows_NT)
$(error oraid server not supported. Use "make build-windows-client" for client)
exit 1
else
go build -mod=readonly $(BUILD_FLAGS) -o build/oraid ./cmd/wasmd
go build -mod=readonly $(BUILD_FLAGS) -o build/oraid ./cmd/wasmd && mv build/oraid $(GOPATH)/bin/oraid
endif

build-windows-client: go.sum
Expand Down
52 changes: 33 additions & 19 deletions app/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,51 @@ import (
"cosmossdk.io/log"
circuitante "cosmossdk.io/x/circuit/ante"
circuitkeeper "cosmossdk.io/x/circuit/keeper"
globalfeekeeper "github.com/CosmosContracts/juno/v18/x/globalfee/keeper"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
ibcante "github.com/cosmos/ibc-go/v8/modules/core/ante"
"github.com/cosmos/ibc-go/v8/modules/core/keeper"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"

wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmTypes "github.com/CosmWasm/wasmd/x/wasm/types"

"github.com/cosmos/cosmos-sdk/types/tx/signing"

storetypes "cosmossdk.io/store/types"
globalfeeante "github.com/CosmosContracts/juno/v18/x/globalfee/ante"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
evmante "github.com/evmos/ethermint/app/ante"
"github.com/evmos/ethermint/crypto/ethsecp256k1"
evmkeeper "github.com/evmos/ethermint/x/evm/keeper"
emvtypes "github.com/evmos/ethermint/x/evm/types"
evmtypes "github.com/evmos/ethermint/x/evm/types"
feemarketkeeper "github.com/evmos/ethermint/x/feemarket/keeper"
)

const maxBypassMinFeeMsgGasUsage = 1_000_000

// HandlerOptions extend the SDK's AnteHandler options by requiring the IBC
// channel keeper.
type HandlerOptions struct {
ante.HandlerOptions
AccountKeeper emvtypes.AccountKeeper
AccountKeeper evmtypes.AccountKeeper
IBCKeeper *keeper.Keeper
EvmKeeper *evmkeeper.Keeper
GlobalFeeKeeper globalfeekeeper.Keeper
StakingKeeper stakingkeeper.Keeper
FeeMarketKeeper feemarketkeeper.Keeper
WasmConfig *wasmTypes.WasmConfig
WasmKeeper *wasmkeeper.Keeper
TXCounterStoreService corestoretypes.KVStoreService
TxCounterStoreKey storetypes.StoreKey
MaxTxGasWanted uint64
CircuitKeeper *circuitkeeper.Keeper
BankKeeper evmtypes.BankKeeper
DisabledAuthzMsgs []string
BypassMinFeeMsgTypes []string
}

func (options *HandlerOptions) Validate() error {
Expand Down Expand Up @@ -103,9 +113,19 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
anteHandler = newEthAnteHandler(options)
case "/ethermint.types.v1.ExtensionOptionsWeb3Tx":
// handle as normal Cosmos SDK tx, except signature is checked for EIP712 representation
anteHandler = newCosmosAnteHandler(cosmosHandlerOptions{
HandlerOptions: options,
isEIP712: true,
anteHandler = evmante.NewLegacyCosmosAnteHandlerEip712(evmante.HandlerOptions{
AccountKeeper: options.AccountKeeper,
BankKeeper: options.BankKeeper,
SignModeHandler: options.SignModeHandler,
FeegrantKeeper: options.FeegrantKeeper,
SigGasConsumer: options.SigGasConsumer,
IBCKeeper: options.IBCKeeper,
EvmKeeper: options.EvmKeeper,
FeeMarketKeeper: options.FeeMarketKeeper,
MaxTxGasWanted: options.MaxTxGasWanted,
ExtensionOptionChecker: options.ExtensionOptionChecker,
TxFeeChecker: options.TxFeeChecker,
DisabledAuthzMsgs: options.DisabledAuthzMsgs,
})
default:
return ctx, errorsmod.Wrapf(
Expand All @@ -121,10 +141,7 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
// handle as totally normal Cosmos SDK tx
switch tx.(type) {
case sdk.Tx:
anteHandler = newCosmosAnteHandler(cosmosHandlerOptions{
HandlerOptions: options,
isEIP712: false,
})
anteHandler = newCosmosAnteHandler(options)
default:
return ctx, errorsmod.Wrapf(sdkerrors.ErrUnknownRequest, "invalid transaction type: %T", tx)
}
Expand All @@ -133,16 +150,10 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
}, nil
}

// cosmosHandlerOptions extends HandlerOptions to provide some Cosmos specific configurations
type cosmosHandlerOptions struct {
HandlerOptions
isEIP712 bool
}

// NewAnteHandler returns an AnteHandler that checks and increments sequence
// numbers, checks signatures & account numbers, and deducts fees from the first
// signer.
func newCosmosAnteHandler(options cosmosHandlerOptions) sdk.AnteHandler {
func newCosmosAnteHandler(options HandlerOptions) sdk.AnteHandler {

var sigGasConsumer = options.SigGasConsumer
if sigGasConsumer == nil {
Expand All @@ -161,8 +172,11 @@ func newCosmosAnteHandler(options cosmosHandlerOptions) sdk.AnteHandler {
ante.NewTxTimeoutHeightDecorator(),
ante.NewValidateMemoDecorator(options.AccountKeeper),
ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TxFeeChecker),
ante.NewSetPubKeyDecorator(options.AccountKeeper), // SetPubKeyDecorator must be called before all signature verification decorators
// nil so that it only checks with the min gas price of the chain, not the custom fee checker. For cosmos messages, the default tx fee checker is enough
globalfeeante.NewFeeDecorator(options.BypassMinFeeMsgTypes, options.GlobalFeeKeeper, options.StakingKeeper, maxBypassMinFeeMsgGasUsage),
ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, nil),
// we use evmante.NewSetPubKeyDecorator so that for eth_secp256k1 accs, we can validate the signer using the evm-cosmos mapping logic
evmante.NewSetPubKeyDecorator(options.AccountKeeper, options.EvmKeeper), // SetPubKeyDecorator must be called before all signature verification decorators
ante.NewValidateSigCountDecorator(options.AccountKeeper),
ante.NewSigGasConsumeDecorator(options.AccountKeeper, options.SigGasConsumer),
ante.NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler),
Expand All @@ -182,7 +196,7 @@ func newEthAnteHandler(options HandlerOptions) sdk.AnteHandler {
evmante.NewEthAccountVerificationDecorator(options.AccountKeeper, options.EvmKeeper),
evmante.NewEthGasConsumeDecorator(options.EvmKeeper, options.MaxTxGasWanted),
evmante.NewCanTransferDecorator(options.EvmKeeper),
evmante.NewEthIncrementSenderSequenceDecorator(options.AccountKeeper), // innermost AnteDecorator.
evmante.NewEthIncrementSenderSequenceDecorator(options.AccountKeeper, options.EvmKeeper), // innermost AnteDecorator.
)
}

Expand Down
55 changes: 43 additions & 12 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ import (
"github.com/cosmos/cosmos-sdk/server/api"
"github.com/cosmos/cosmos-sdk/server/config"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
"github.com/cosmos/cosmos-sdk/std"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/types/msgservice"
Expand Down Expand Up @@ -153,7 +152,9 @@ import (

simappparams "cosmossdk.io/simapp/params"
evmv1 "github.com/evmos/ethermint/api/ethermint/evm/v1"
evmante "github.com/evmos/ethermint/app/ante"
"github.com/evmos/ethermint/ethereum/eip712"
etherminttypes "github.com/evmos/ethermint/types"
"github.com/evmos/ethermint/x/evm"
evmkeeper "github.com/evmos/ethermint/x/evm/keeper"
evmtypes "github.com/evmos/ethermint/x/evm/types"
Expand All @@ -163,9 +164,15 @@ import (
feemarkettypes "github.com/evmos/ethermint/x/feemarket/types"
protov2 "google.golang.org/protobuf/proto"

appconfig "github.com/CosmWasm/wasmd/cmd/config"
enccodec "github.com/evmos/ethermint/encoding/codec"
"github.com/evmos/ethermint/x/erc20"
erc20keeper "github.com/evmos/ethermint/x/erc20/keeper"
erc20types "github.com/evmos/ethermint/x/erc20/types"

"github.com/CosmosContracts/juno/v18/x/globalfee"
globalfeekeeper "github.com/CosmosContracts/juno/v18/x/globalfee/keeper"
globalfeetypes "github.com/CosmosContracts/juno/v18/x/globalfee/types"
)

const appName = "WasmApp"
Expand Down Expand Up @@ -285,6 +292,7 @@ type WasmApp struct {
EvmKeeper *evmkeeper.Keeper
Erc20Keeper erc20keeper.Keeper
FeeMarketKeeper feemarketkeeper.Keeper
GlobalFeeKeeper globalfeekeeper.Keeper

// Middleware wrapper
Ics20WasmHooks *ibchooks.WasmHooks
Expand Down Expand Up @@ -347,10 +355,6 @@ func NewWasmApp(

eip712.SetEncodingConfig(encodingConfig)

std.RegisterLegacyAminoCodec(legacyAmino)
std.RegisterInterfaces(interfaceRegistry)
clockkeeper.RegisterProposalTypes()

// Below we could construct and set an application specific mempool and
// ABCI 1.0 PrepareProposal and ProcessProposal handlers. These defaults are
// already set in the SDK's BaseApp, this shows an example of how to override
Expand Down Expand Up @@ -399,7 +403,7 @@ func NewWasmApp(
// non sdk store keys
capabilitytypes.StoreKey, ibcexported.StoreKey, ibctransfertypes.StoreKey, ibcfeetypes.StoreKey,
wasmtypes.StoreKey, icahosttypes.StoreKey,
icacontrollertypes.StoreKey, clocktypes.StoreKey, ibchookstypes.StoreKey, packetforwardtypes.StoreKey, tokenfactorytypes.StoreKey,
icacontrollertypes.StoreKey, clocktypes.StoreKey, globalfeetypes.StoreKey, ibchookstypes.StoreKey, packetforwardtypes.StoreKey, tokenfactorytypes.StoreKey,
evmtypes.StoreKey, feemarkettypes.StoreKey, erc20types.StoreKey,
)

Expand Down Expand Up @@ -607,9 +611,10 @@ func NewWasmApp(

evmSs := app.GetSubspace(evmtypes.ModuleName)
tracer := cast.ToString(appOpts.Get(srvflags.EVMTracer))
evmBankKeeper := evmkeeper.NewEvmBankKeeperWithDenoms(app.BankKeeper, app.AccountKeeper, appconfig.EvmDenom, appconfig.CosmosDenom)
app.EvmKeeper = evmkeeper.NewKeeper(
appCodec, runtime.NewKVStoreService(keys[evmtypes.StoreKey]), tkeys[evmtypes.TransientKey], Authority,
app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.FeeMarketKeeper,
app.AccountKeeper, evmBankKeeper, app.StakingKeeper, app.FeeMarketKeeper,
nil, geth.NewEVM, tracer, evmSs,
)

Expand All @@ -626,7 +631,6 @@ func NewWasmApp(
govRouter := govv1beta1.NewRouter()
govRouter.AddRoute(govtypes.RouterKey, govv1beta1.ProposalHandler).
AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(app.ParamsKeeper)).
AddRoute(clocktypes.RouterKey, clockkeeper.NewClockProposalHandler(app.ClockKeeper)).
AddRoute(erc20types.RouterKey, erc20.NewErc20ProposalHandler(&app.Erc20Keeper))
govConfig := govtypes.DefaultConfig()
/*
Expand Down Expand Up @@ -754,6 +758,7 @@ func NewWasmApp(
}

wasmOpts = append(bindings.RegisterCustomPlugins(&app.BankKeeper, &app.TokenFactoryKeeper), wasmOpts...)
wasmOpts = append(RegisterStargateQueries(*bApp.GRPCQueryRouter(), appCodec), wasmOpts...)

// The last arguments can contain custom message handlers, and custom query handlers,
// if we want to allow any custom callbacks
Expand Down Expand Up @@ -783,6 +788,13 @@ func NewWasmApp(
app.keys[clocktypes.StoreKey],
appCodec,
*app.ContractKeeper,
AuthorityAddr,
)

app.GlobalFeeKeeper = globalfeekeeper.NewKeeper(
appCodec,
app.keys[globalfeetypes.StoreKey],
AuthorityAddr,
)

app.TokenFactoryKeeper = tokenfactorykeeper.NewKeeper(
Expand Down Expand Up @@ -883,6 +895,7 @@ func NewWasmApp(
// sdk
crisis.NewAppModule(app.CrisisKeeper, skipGenesisInvariants, app.GetSubspace(crisistypes.ModuleName)), // always be last to make sure that it checks for all invariants and not only part of them
clock.NewAppModule(appCodec, app.ClockKeeper),
globalfee.NewAppModule(appCodec, app.GlobalFeeKeeper),
ibchooks.NewAppModule(app.AccountKeeper),
packetforward.NewAppModule(app.PacketForwardKeeper, app.GetSubspace(packetforwardtypes.ModuleName)),
tokenfactory.NewAppModule(app.TokenFactoryKeeper, app.AccountKeeper, app.BankKeeper),
Expand Down Expand Up @@ -912,9 +925,13 @@ func NewWasmApp(
evmtypes.ModuleName: evm.AppModuleBasic{},
feemarkettypes.ModuleName: feemarket.AppModuleBasic{},
erc20types.ModuleName: erc20.AppModuleBasic{},
globalfee.ModuleName: globalfee.AppModuleBasic{},
})
app.BasicModuleManager.RegisterLegacyAminoCodec(legacyAmino)
app.BasicModuleManager.RegisterInterfaces(interfaceRegistry)
enccodec.RegisterLegacyAminoCodec(legacyAmino)
enccodec.RegisterInterfaces(interfaceRegistry)
clocktypes.RegisterInterfaces(interfaceRegistry)

// NOTE: upgrade module is required to be prioritized
app.ModuleManager.SetOrderPreBlockers(
Expand Down Expand Up @@ -943,6 +960,7 @@ func NewWasmApp(
clocktypes.ModuleName,
ibchookstypes.ModuleName,
packetforwardtypes.ModuleName,
globalfee.ModuleName,
tokenfactorytypes.ModuleName,
feemarkettypes.ModuleName,
evmtypes.ModuleName,
Expand All @@ -966,6 +984,7 @@ func NewWasmApp(
clocktypes.ModuleName,
ibchookstypes.ModuleName,
packetforwardtypes.ModuleName,
globalfee.ModuleName,
tokenfactorytypes.ModuleName,
feemarkettypes.ModuleName,
evmtypes.ModuleName,
Expand Down Expand Up @@ -998,6 +1017,7 @@ func NewWasmApp(
clocktypes.ModuleName,
ibchookstypes.ModuleName,
packetforwardtypes.ModuleName,
globalfee.ModuleName,
tokenfactorytypes.ModuleName,
feemarkettypes.ModuleName,
evmtypes.ModuleName,
Expand Down Expand Up @@ -1119,19 +1139,29 @@ func (app *WasmApp) setAnteHandler(txConfig client.TxConfig, wasmConfig wasmtype
anteHandler, err := NewAnteHandler(
HandlerOptions{
HandlerOptions: ante.HandlerOptions{
BankKeeper: app.BankKeeper,
SignModeHandler: txConfig.SignModeHandler(),
FeegrantKeeper: app.FeeGrantKeeper,
SigGasConsumer: DefaultSigGasConsumer,
SignModeHandler: txConfig.SignModeHandler(),
FeegrantKeeper: app.FeeGrantKeeper,
SigGasConsumer: DefaultSigGasConsumer,
ExtensionOptionChecker: etherminttypes.HasDynamicFeeExtensionOption,
TxFeeChecker: evmante.NewDynamicFeeChecker(app.EvmKeeper),
},
AccountKeeper: app.AccountKeeper,
BankKeeper: app.BankKeeper,
IBCKeeper: app.IBCKeeper,
EvmKeeper: app.EvmKeeper,
StakingKeeper: *app.StakingKeeper,
GlobalFeeKeeper: app.GlobalFeeKeeper,
FeeMarketKeeper: app.FeeMarketKeeper,
WasmConfig: &wasmConfig,
WasmKeeper: &app.WasmKeeper,
TXCounterStoreService: runtime.NewKVStoreService(txCounterStoreKey),
CircuitKeeper: &app.CircuitKeeper,
DisabledAuthzMsgs: []string{
sdk.MsgTypeURL(&evmtypes.MsgEthereumTx{}),
sdk.MsgTypeURL(&vestingtypes.MsgCreateVestingAccount{}),
sdk.MsgTypeURL(&vestingtypes.MsgCreatePermanentLockedAccount{}),
sdk.MsgTypeURL(&vestingtypes.MsgCreatePeriodicVestingAccount{}),
},
},
)
if err != nil {
Expand Down Expand Up @@ -1382,6 +1412,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino

paramsKeeper.Subspace(wasmtypes.ModuleName)
paramsKeeper.Subspace(clocktypes.ModuleName)
paramsKeeper.Subspace(globalfeetypes.ModuleName)
paramsKeeper.Subspace(ibchookstypes.ModuleName)
paramsKeeper.Subspace(packetforwardtypes.ModuleName).WithKeyTable(packetforwardtypes.ParamKeyTable())
paramsKeeper.Subspace(tokenfactorytypes.ModuleName)
Expand Down
Loading

0 comments on commit 7209273

Please sign in to comment.