From 5bbc77354b55ef036394a35d82f1ba1b11cc9de8 Mon Sep 17 00:00:00 2001 From: dudong2 Date: Mon, 15 Jan 2024 13:16:18 +0900 Subject: [PATCH] chore: uncomment or fix necessary parts --- .github/workflows/deploy-contract.yml | 2 - .golangci.yml | 1 + .semgrepignore | 2 +- app/ante/authz_test.go | 1 + ethereum/eip712/eip712_test.go | 295 ++++++++++---------- ethereum/eip712/encoding.go | 1 - rpc/backend/tx_info.go | 2 +- tests/integration_tests/hardhat/.gitignore | 2 +- x/evm/genesis_test.go | 302 +++++++++++---------- x/evm/keeper/hooks_test.go | 7 +- 10 files changed, 311 insertions(+), 304 deletions(-) diff --git a/.github/workflows/deploy-contract.yml b/.github/workflows/deploy-contract.yml index 0d0a308c48..63f5c8cd6f 100644 --- a/.github/workflows/deploy-contract.yml +++ b/.github/workflows/deploy-contract.yml @@ -38,8 +38,6 @@ jobs: go.sum - name: Test contract run: | - sudo env "PATH=$PATH" go version - sudo env "PATH=$PATH" go env sudo env "PATH=$PATH" make contract-tools sudo env "PATH=$PATH" make test-solidity if: env.GIT_DIFF diff --git a/.golangci.yml b/.golangci.yml index 96a31148eb..1ab3b62bae 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -6,6 +6,7 @@ run: linters: enable: - bodyclose + - depguard - dogsled - dupl - errcheck diff --git a/.semgrepignore b/.semgrepignore index 36a1c2e098..cb655af10c 100644 --- a/.semgrepignore +++ b/.semgrepignore @@ -8,7 +8,7 @@ node_modules/ build/ dist/ vendor/ -env/ +.env/ .venv/ .tox/ *.min.js diff --git a/app/ante/authz_test.go b/app/ante/authz_test.go index 344fa5f6a2..0b83d9081f 100644 --- a/app/ante/authz_test.go +++ b/app/ante/authz_test.go @@ -340,6 +340,7 @@ func (suite *AnteTestSuite) TestRejectDeliverMsgsInAuthz() { Txs: [][]byte{bz}, }, ) + suite.Require().Equal(len(resFinalizeBlock.TxResults), 1) suite.Require().Equal(resFinalizeBlock.TxResults[0].Code, tc.expectedCode, resFinalizeBlock.TxResults[0].Log) }) } diff --git a/ethereum/eip712/eip712_test.go b/ethereum/eip712/eip712_test.go index f1a6418c74..1e10007b1e 100644 --- a/ethereum/eip712/eip712_test.go +++ b/ethereum/eip712/eip712_test.go @@ -34,9 +34,14 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" "github.com/cosmos/cosmos-sdk/x/bank" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/cosmos-sdk/x/distribution" + distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types" "github.com/cosmos/cosmos-sdk/x/gov" + govtypesv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" "github.com/cosmos/cosmos-sdk/x/staking" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/stretchr/testify/suite" ) @@ -144,156 +149,156 @@ func (suite *EIP712TestSuite) TestEIP712() { timeoutHeight uint64 expectSuccess bool }{ - // { - // title: "Succeeds - Standard MsgSend", - // msgs: []sdk.Msg{ - // banktypes.NewMsgSend( - // suite.createTestAddress(), - // suite.createTestAddress(), - // suite.makeCoins(suite.denom, math.NewInt(1)), - // ), - // }, - // expectSuccess: true, - // }, - // { - // title: "Succeeds - Standard MsgVote", - // msgs: []sdk.Msg{ - // govtypes.NewMsgVote( - // suite.createTestAddress(), - // 5, - // govtypes.OptionNo, - // ), - // }, - // expectSuccess: true, - // }, - // { - // title: "Succeeds - Standard MsgDelegate", - // msgs: []sdk.Msg{ - // stakingtypes.NewMsgDelegate( - // suite.createTestAddress().String(), - // sdk.ValAddress(suite.createTestAddress()).String(), - // suite.makeCoins(suite.denom, math.NewInt(1))[0], - // ), - // }, - // expectSuccess: true, - // }, - // { - // title: "Succeeds - Standard MsgWithdrawDelegationReward", - // msgs: []sdk.Msg{ - // distributiontypes.NewMsgWithdrawDelegatorReward( - // suite.createTestAddress().String(), - // sdk.ValAddress(suite.createTestAddress()).String(), - // ), - // }, - // expectSuccess: true, - // }, - // { - // title: "Succeeds - Two Single-Signer MsgDelegate", - // msgs: []sdk.Msg{ - // stakingtypes.NewMsgDelegate( - // params.address.String(), - // sdk.ValAddress(suite.createTestAddress()).String(), - // suite.makeCoins(suite.denom, math.NewInt(1))[0], - // ), - // stakingtypes.NewMsgDelegate( - // params.address.String(), - // sdk.ValAddress(suite.createTestAddress()).String(), - // suite.makeCoins(suite.denom, math.NewInt(5))[0], - // ), - // }, - // expectSuccess: true, - // }, - // { - // title: "Succeeds - Single-Signer MsgVote V1 with Omitted Value", - // msgs: []sdk.Msg{ - // govtypesv1.NewMsgVote( - // params.address, - // 5, - // govtypesv1.VoteOption_VOTE_OPTION_NO, - // "", - // ), - // }, - // expectSuccess: true, - // }, - // { - // title: "Succeeds - Single-Signer MsgSend + MsgVote", - // msgs: []sdk.Msg{ - // govtypes.NewMsgVote( - // params.address, - // 5, - // govtypes.OptionNo, - // ), - // banktypes.NewMsgSend( - // params.address, - // suite.createTestAddress(), - // suite.makeCoins(suite.denom, math.NewInt(50)), - // ), - // }, - // expectSuccess: !suite.useLegacyEIP712TypedData, - // }, - // { - // title: "Succeeds - Single-Signer 2x MsgVoteV1 with Different Schemas", - // msgs: []sdk.Msg{ - // govtypesv1.NewMsgVote( - // params.address, - // 5, - // govtypesv1.VoteOption_VOTE_OPTION_NO, - // "", - // ), - // govtypesv1.NewMsgVote( - // params.address, - // 10, - // govtypesv1.VoteOption_VOTE_OPTION_YES, - // "Has Metadata", - // ), - // }, - // expectSuccess: !suite.useLegacyEIP712TypedData, - // }, - // { - // title: "Fails - Two MsgVotes with Different Signers", - // msgs: []sdk.Msg{ - // govtypes.NewMsgVote( - // suite.createTestAddress(), - // 5, - // govtypes.OptionNo, - // ), - // govtypes.NewMsgVote( - // suite.createTestAddress(), - // 25, - // govtypes.OptionAbstain, - // ), - // }, - // expectSuccess: false, - // }, + { + title: "Succeeds - Standard MsgSend", + msgs: []sdk.Msg{ + banktypes.NewMsgSend( + suite.createTestAddress(), + suite.createTestAddress(), + suite.makeCoins(suite.denom, math.NewInt(1)), + ), + }, + expectSuccess: true, + }, + { + title: "Succeeds - Standard MsgVote", + msgs: []sdk.Msg{ + govtypes.NewMsgVote( + suite.createTestAddress(), + 5, + govtypes.OptionNo, + ), + }, + expectSuccess: true, + }, + { + title: "Succeeds - Standard MsgDelegate", + msgs: []sdk.Msg{ + stakingtypes.NewMsgDelegate( + suite.createTestAddress().String(), + sdk.ValAddress(suite.createTestAddress()).String(), + suite.makeCoins(suite.denom, math.NewInt(1))[0], + ), + }, + expectSuccess: true, + }, + { + title: "Succeeds - Standard MsgWithdrawDelegationReward", + msgs: []sdk.Msg{ + distributiontypes.NewMsgWithdrawDelegatorReward( + suite.createTestAddress().String(), + sdk.ValAddress(suite.createTestAddress()).String(), + ), + }, + expectSuccess: true, + }, + { + title: "Succeeds - Two Single-Signer MsgDelegate", + msgs: []sdk.Msg{ + stakingtypes.NewMsgDelegate( + params.address.String(), + sdk.ValAddress(suite.createTestAddress()).String(), + suite.makeCoins(suite.denom, math.NewInt(1))[0], + ), + stakingtypes.NewMsgDelegate( + params.address.String(), + sdk.ValAddress(suite.createTestAddress()).String(), + suite.makeCoins(suite.denom, math.NewInt(5))[0], + ), + }, + expectSuccess: true, + }, + { + title: "Succeeds - Single-Signer MsgVote V1 with Omitted Value", + msgs: []sdk.Msg{ + govtypesv1.NewMsgVote( + params.address, + 5, + govtypesv1.VoteOption_VOTE_OPTION_NO, + "", + ), + }, + expectSuccess: true, + }, + { + title: "Succeeds - Single-Signer MsgSend + MsgVote", + msgs: []sdk.Msg{ + govtypes.NewMsgVote( + params.address, + 5, + govtypes.OptionNo, + ), + banktypes.NewMsgSend( + params.address, + suite.createTestAddress(), + suite.makeCoins(suite.denom, math.NewInt(50)), + ), + }, + expectSuccess: !suite.useLegacyEIP712TypedData, + }, + { + title: "Succeeds - Single-Signer 2x MsgVoteV1 with Different Schemas", + msgs: []sdk.Msg{ + govtypesv1.NewMsgVote( + params.address, + 5, + govtypesv1.VoteOption_VOTE_OPTION_NO, + "", + ), + govtypesv1.NewMsgVote( + params.address, + 10, + govtypesv1.VoteOption_VOTE_OPTION_YES, + "Has Metadata", + ), + }, + expectSuccess: !suite.useLegacyEIP712TypedData, + }, + { + title: "Fails - Two MsgVotes with Different Signers", + msgs: []sdk.Msg{ + govtypes.NewMsgVote( + suite.createTestAddress(), + 5, + govtypes.OptionNo, + ), + govtypes.NewMsgVote( + suite.createTestAddress(), + 25, + govtypes.OptionAbstain, + ), + }, + expectSuccess: false, + }, { title: "Fails - Empty Transaction", msgs: []sdk.Msg{}, expectSuccess: false, }, - // { - // title: "Fails - Invalid ChainID", - // chainID: "invalidchainid", - // msgs: []sdk.Msg{ - // govtypes.NewMsgVote( - // suite.createTestAddress(), - // 5, - // govtypes.OptionNo, - // ), - // }, - // expectSuccess: false, - // }, - // { - // title: "Fails - Includes TimeoutHeight", - // msgs: []sdk.Msg{ - // govtypes.NewMsgVote( - // suite.createTestAddress(), - // 5, - // govtypes.OptionNo, - // ), - // }, - // timeoutHeight: 1000, - // expectSuccess: false, - // }, + { + title: "Fails - Invalid ChainID", + chainID: "invalidchainid", + msgs: []sdk.Msg{ + govtypes.NewMsgVote( + suite.createTestAddress(), + 5, + govtypes.OptionNo, + ), + }, + expectSuccess: false, + }, + { + title: "Fails - Includes TimeoutHeight", + msgs: []sdk.Msg{ + govtypes.NewMsgVote( + suite.createTestAddress(), + 5, + govtypes.OptionNo, + ), + }, + timeoutHeight: 1000, + expectSuccess: false, + }, } for _, tc := range testCases { diff --git a/ethereum/eip712/encoding.go b/ethereum/eip712/encoding.go index 446775c32d..28d933584e 100644 --- a/ethereum/eip712/encoding.go +++ b/ethereum/eip712/encoding.go @@ -51,7 +51,6 @@ func SetEncodingConfig(cfg params.EncodingConfig) { func GetEIP712BytesForMsg(signDocBytes []byte) ([]byte, error) { typedData, err := GetEIP712TypedDataForMsg(signDocBytes) if err != nil { - _, err := GetEIP712TypedDataForMsg(signDocBytes) return nil, err } diff --git a/rpc/backend/tx_info.go b/rpc/backend/tx_info.go index d41084d9c3..93c355c20b 100644 --- a/rpc/backend/tx_info.go +++ b/rpc/backend/tx_info.go @@ -310,7 +310,7 @@ func (b *Backend) GetTransactionByBlockNumberAndIndex(blockNum rpctypes.BlockNum // GetTxByEthHash uses `/tx_query` to find transaction by ethereum tx hash // TODO: Don't need to convert once hashing is fixed on Tendermint -// https://github.com/cometbft/cometbft/issues/6539 +// https://github.com/tendermint/tendermint/issues/6539 func (b *Backend) GetTxByEthHash(hash common.Hash) (*ethermint.TxResult, error) { if b.indexer != nil { return b.indexer.GetByTxHash(hash) diff --git a/tests/integration_tests/hardhat/.gitignore b/tests/integration_tests/hardhat/.gitignore index f3a49e69ea..71f6a160fc 100644 --- a/tests/integration_tests/hardhat/.gitignore +++ b/tests/integration_tests/hardhat/.gitignore @@ -1,5 +1,5 @@ node_modules -env +.env coverage coverage.json typechain diff --git a/x/evm/genesis_test.go b/x/evm/genesis_test.go index ad82f7a6e0..4c4d8c246e 100644 --- a/x/evm/genesis_test.go +++ b/x/evm/genesis_test.go @@ -1,165 +1,167 @@ package evm_test import ( -// "math/big" + "math/big" -// "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common" -// authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" -// "github.com/evmos/ethermint/crypto/ethsecp256k1" -// etherminttypes "github.com/evmos/ethermint/types" -// "github.com/evmos/ethermint/x/evm" -// "github.com/evmos/ethermint/x/evm/statedb" -// "github.com/evmos/ethermint/x/evm/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/evmos/ethermint/crypto/ethsecp256k1" + etherminttypes "github.com/evmos/ethermint/types" + "github.com/evmos/ethermint/x/evm" + "github.com/evmos/ethermint/x/evm/statedb" + "github.com/evmos/ethermint/x/evm/types" ) -// func (suite *EvmTestSuite) TestInitGenesis() { -// privkey, err := ethsecp256k1.GenerateKey() -// suite.Require().NoError(err) +func (suite *EvmTestSuite) TestInitGenesis() { + privkey, err := ethsecp256k1.GenerateKey() + suite.Require().NoError(err) -// address := common.HexToAddress(privkey.PubKey().Address().String()) + address := common.HexToAddress(privkey.PubKey().Address().String()) -// var vmdb *statedb.StateDB + var vmdb *statedb.StateDB -// testCases := []struct { -// name string -// malleate func() -// genState *types.GenesisState -// expPanic bool -// }{ -// { -// "default", -// func() {}, -// types.DefaultGenesisState(), -// false, -// }, -// { -// "valid account", -// func() { -// vmdb.AddBalance(address, big.NewInt(1)) -// }, -// &types.GenesisState{ -// Params: types.DefaultParams(), -// Accounts: []types.GenesisAccount{ -// { -// Address: address.String(), -// Storage: types.Storage{ -// {Key: common.BytesToHash([]byte("key")).String(), Value: common.BytesToHash([]byte("value")).String()}, -// }, -// }, -// }, -// }, -// false, -// }, -// { -// "account not found", -// func() {}, -// &types.GenesisState{ -// Params: types.DefaultParams(), -// Accounts: []types.GenesisAccount{ -// { -// Address: address.String(), -// }, -// }, -// }, -// true, -// }, -// { -// "invalid account type", -// func() { -// acc := authtypes.NewBaseAccountWithAddress(address.Bytes()) -// suite.app.AccountKeeper.SetAccount(suite.ctx, acc) -// }, -// &types.GenesisState{ -// Params: types.DefaultParams(), -// Accounts: []types.GenesisAccount{ -// { -// Address: address.String(), -// }, -// }, -// }, -// true, -// }, -// { -// "invalid code hash", -// func() { -// acc := suite.app.AccountKeeper.NewAccountWithAddress(suite.ctx, address.Bytes()) -// suite.app.AccountKeeper.SetAccount(suite.ctx, acc) -// }, -// &types.GenesisState{ -// Params: types.DefaultParams(), -// Accounts: []types.GenesisAccount{ -// { -// Address: address.String(), -// Code: "ffffffff", -// }, -// }, -// }, -// true, -// }, -// { -// "ignore empty account code checking", -// func() { -// acc := suite.app.AccountKeeper.NewAccountWithAddress(suite.ctx, address.Bytes()) + testCases := []struct { + name string + malleate func() + genState *types.GenesisState + expPanic bool + }{ + { + "default", + func() {}, + types.DefaultGenesisState(), + false, + }, + { + "valid account", + func() { + vmdb.AddBalance(address, big.NewInt(1)) + }, + &types.GenesisState{ + Params: types.DefaultParams(), + Accounts: []types.GenesisAccount{ + { + Address: address.String(), + Storage: types.Storage{ + {Key: common.BytesToHash([]byte("key")).String(), Value: common.BytesToHash([]byte("value")).String()}, + }, + }, + }, + }, + false, + }, + { + "account not found", + func() {}, + &types.GenesisState{ + Params: types.DefaultParams(), + Accounts: []types.GenesisAccount{ + { + Address: address.String(), + }, + }, + }, + true, + }, + { + "invalid account type", + func() { + acc := authtypes.NewBaseAccountWithAddress(address.Bytes()) + accNum := suite.app.AccountKeeper.NextAccountNumber(suite.ctx) + acc.SetAccountNumber(accNum) + suite.app.AccountKeeper.SetAccount(suite.ctx, acc) + }, + &types.GenesisState{ + Params: types.DefaultParams(), + Accounts: []types.GenesisAccount{ + { + Address: address.String(), + }, + }, + }, + true, + }, + { + "invalid code hash", + func() { + acc := suite.app.AccountKeeper.NewAccountWithAddress(suite.ctx, address.Bytes()) + suite.app.AccountKeeper.SetAccount(suite.ctx, acc) + }, + &types.GenesisState{ + Params: types.DefaultParams(), + Accounts: []types.GenesisAccount{ + { + Address: address.String(), + Code: "ffffffff", + }, + }, + }, + true, + }, + { + "ignore empty account code checking", + func() { + acc := suite.app.AccountKeeper.NewAccountWithAddress(suite.ctx, address.Bytes()) -// suite.app.AccountKeeper.SetAccount(suite.ctx, acc) -// }, -// &types.GenesisState{ -// Params: types.DefaultParams(), -// Accounts: []types.GenesisAccount{ -// { -// Address: address.String(), -// Code: "", -// }, -// }, -// }, -// false, -// }, -// { -// "ignore empty account code checking with non-empty codehash", -// func() { -// accNum := suite.app.AccountKeeper.NextAccountNumber(suite.ctx) -// ethAcc := ðerminttypes.EthAccount{ -// BaseAccount: authtypes.NewBaseAccount(address.Bytes(), nil, accNum, 0), -// CodeHash: common.BytesToHash([]byte{1, 2, 3}).Hex(), -// } + suite.app.AccountKeeper.SetAccount(suite.ctx, acc) + }, + &types.GenesisState{ + Params: types.DefaultParams(), + Accounts: []types.GenesisAccount{ + { + Address: address.String(), + Code: "", + }, + }, + }, + false, + }, + { + "ignore empty account code checking with non-empty codehash", + func() { + accNum := suite.app.AccountKeeper.NextAccountNumber(suite.ctx) + ethAcc := ðerminttypes.EthAccount{ + BaseAccount: authtypes.NewBaseAccount(address.Bytes(), nil, accNum, 0), + CodeHash: common.BytesToHash([]byte{1, 2, 3}).Hex(), + } -// suite.app.AccountKeeper.SetAccount(suite.ctx, ethAcc) -// }, -// &types.GenesisState{ -// Params: types.DefaultParams(), -// Accounts: []types.GenesisAccount{ -// { -// Address: address.String(), -// Code: "", -// }, -// }, -// }, -// false, -// }, -// } + suite.app.AccountKeeper.SetAccount(suite.ctx, ethAcc) + }, + &types.GenesisState{ + Params: types.DefaultParams(), + Accounts: []types.GenesisAccount{ + { + Address: address.String(), + Code: "", + }, + }, + }, + false, + }, + } -// for _, tc := range testCases { -// suite.Run(tc.name, func() { -// suite.SetupTest() // reset values -// vmdb = suite.StateDB() + for _, tc := range testCases { + suite.Run(tc.name, func() { + suite.SetupTest() // reset values + vmdb = suite.StateDB() -// tc.malleate() -// vmdb.Commit() + tc.malleate() + vmdb.Commit() -// if tc.expPanic { -// suite.Require().Panics( -// func() { -// _ = evm.InitGenesis(suite.ctx, suite.app.EvmKeeper, suite.app.AccountKeeper, *tc.genState) -// }, -// ) -// } else { -// suite.Require().NotPanics( -// func() { -// _ = evm.InitGenesis(suite.ctx, suite.app.EvmKeeper, suite.app.AccountKeeper, *tc.genState) -// }, -// ) -// } -// }) -// } -// } + if tc.expPanic { + suite.Require().Panics( + func() { + _ = evm.InitGenesis(suite.ctx, suite.app.EvmKeeper, suite.app.AccountKeeper, *tc.genState) + }, + ) + } else { + suite.Require().NotPanics( + func() { + _ = evm.InitGenesis(suite.ctx, suite.app.EvmKeeper, suite.app.AccountKeeper, *tc.genState) + }, + ) + } + }) + } +} diff --git a/x/evm/keeper/hooks_test.go b/x/evm/keeper/hooks_test.go index 850a9828d3..d5afb55a11 100644 --- a/x/evm/keeper/hooks_test.go +++ b/x/evm/keeper/hooks_test.go @@ -64,9 +64,10 @@ func (suite *KeeperTestSuite) TestEvmHooks() { suite.app.EvmKeeper.SetHooks(keeper.NewMultiEvmHooks(hook)) k := suite.app.EvmKeeper + ctx := suite.ctx txHash := common.BigToHash(big.NewInt(1)) - vmdb := statedb.New(suite.ctx, k, statedb.NewTxConfig( - common.BytesToHash(suite.ctx.HeaderHash()), + vmdb := statedb.New(ctx, k, statedb.NewTxConfig( + common.BytesToHash(ctx.HeaderHash()), txHash, 0, 0, @@ -81,7 +82,7 @@ func (suite *KeeperTestSuite) TestEvmHooks() { TxHash: txHash, Logs: logs, } - result := k.PostTxProcessing(suite.ctx, ethtypes.Message{}, receipt) + result := k.PostTxProcessing(ctx, ethtypes.Message{}, receipt) tc.expFunc(hook, result) }