Skip to content

Commit

Permalink
Resolve go lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianBorst committed Mar 4, 2024
1 parent ab5a2fc commit 47207db
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 238 deletions.
42 changes: 21 additions & 21 deletions app/ante/account_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,32 +33,32 @@ func isEthPubKey(pubKey cryptotypes.PubKey) bool {
_, ok := pubKey.(*ethsecp256k1.PubKey)
return ok
}
func (suite *AnteTestSuite) testCaseSetup(ctx sdk.Context, addr sdk.AccAddress, isBaseAccount bool) {
var acc authtypes.AccountI
suite.enableFeemarket = false

if isBaseAccount {
acc = suite.app.AccountKeeper.NewAccountWithAddress(ctx, addr)
suite.Require().True(isCosmosAccount(acc), "account type should be BaseAccount")
} else {
acc = ethtypes.ProtoAccount()
suite.Require().NoError(acc.SetAddress(addr))
suite.app.AccountKeeper.SetAccount(ctx, acc)
acc = suite.app.AccountKeeper.GetAccount(ctx, addr)
suite.Require().True(isEthAccount(acc), "account type should be EthAccount")
}
evmAddr := common.BytesToAddress(addr.Bytes())
suite.Require().NoError(suite.app.EvmKeeper.SetBalance(ctx, evmAddr, big.NewInt(10000000000)))

suite.app.FeemarketKeeper.SetBaseFee(ctx, big.NewInt(100))
}

// Checks that the account types are updated correctly
func (suite AnteTestSuite) TestAccountTypeAnteHandler() {
var acc authtypes.AccountI
func (suite *AnteTestSuite) TestAccountTypeAnteHandler() {
to := tests.GenerateAddress()
suite.SetupTest()

// Setup will create the account as either a BaseAccount or an EthAccount (based on isBaseAccount) and set the balance
setup := func(ctx sdk.Context, addr sdk.AccAddress, isBaseAccount bool) {
suite.enableFeemarket = false

if isBaseAccount {
acc = suite.app.AccountKeeper.NewAccountWithAddress(ctx, addr)
suite.Require().True(isCosmosAccount(acc), "account type should be BaseAccount")
} else {
acc = ethtypes.ProtoAccount()
suite.Require().NoError(acc.SetAddress(addr))
suite.app.AccountKeeper.SetAccount(ctx, acc)
acc = suite.app.AccountKeeper.GetAccount(ctx, addr)
suite.Require().True(isEthAccount(acc), "account type should be EthAccount")
}
evmAddr := common.BytesToAddress(addr.Bytes())
suite.app.EvmKeeper.SetBalance(ctx, evmAddr, big.NewInt(10000000000))

suite.app.FeemarketKeeper.SetBaseFee(ctx, big.NewInt(100))
}

testCases := []struct {
name string // A name which is printed when the test fails
Expand Down Expand Up @@ -177,7 +177,7 @@ func (suite AnteTestSuite) TestAccountTypeAnteHandler() {
builder, privKey := tc.txPrivKeyFn()
addr := sdk.AccAddress(privKey.PubKey().Address())
// Create the account for the test, which will be a BaseAccount or an EthAccount depending on startBaseAcc
setup(ctx, addr, tc.startBaseAcc)
suite.testCaseSetup(ctx, addr, tc.startBaseAcc)
acc := suite.app.AccountKeeper.GetAccount(ctx, addr)

if tc.signCosmosTx {
Expand Down
13 changes: 8 additions & 5 deletions app/ante/ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

// These tests have been copied from ethermint but duplicated here to ensure that
// our changes to the AnteHandler do not cause conflicts
func (suite AnteTestSuite) TestAnteHandler() {
func (suite *AnteTestSuite) TestAnteHandler() {
var acc authtypes.AccountI
addr, privKey := tests.NewAddrKey()
to := tests.GenerateAddress()
Expand All @@ -29,7 +29,7 @@ func (suite AnteTestSuite) TestAnteHandler() {
suite.Require().NoError(acc.SetSequence(1))
suite.app.AccountKeeper.SetAccount(suite.ctx, acc)

suite.app.EvmKeeper.SetBalance(suite.ctx, addr, big.NewInt(10000000000))
suite.Require().NoError(suite.app.EvmKeeper.SetBalance(suite.ctx, addr, big.NewInt(10000000000)))

suite.app.FeemarketKeeper.SetBaseFee(suite.ctx, big.NewInt(100))
}
Expand Down Expand Up @@ -349,8 +349,9 @@ func (suite AnteTestSuite) TestAnteHandler() {
amount := sdk.NewCoins(sdk.NewCoin(altheaconfig.BaseDenom, sdk.NewInt(20)))
gas := uint64(200000)
txBuilder := suite.CreateTestEIP712TxBuilderMsgSend(from, privKey, suite.ctx.ChainID(), gas, amount)
// nolint: exhaustruct
sigsV2 := signing.SignatureV2{}
txBuilder.SetSignatures(sigsV2)
suite.Require().NoError(txBuilder.SetSignatures(sigsV2))
return txBuilder.GetTx()
}, false, false, false,
},
Expand All @@ -363,14 +364,15 @@ func (suite AnteTestSuite) TestAnteHandler() {
txBuilder := suite.CreateTestEIP712TxBuilderMsgSend(from, privKey, suite.ctx.ChainID(), gas, amount)
nonce, err := suite.app.AccountKeeper.GetSequence(suite.ctx, acc.GetAddress())
suite.Require().NoError(err)
// nolint: exhaustruct
sigsV2 := signing.SignatureV2{
PubKey: privKey.PubKey(),
Data: &signing.SingleSignatureData{
SignMode: signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON,
},
Sequence: nonce - 1,
}
txBuilder.SetSignatures(sigsV2)
suite.Require().NoError(txBuilder.SetSignatures(sigsV2))
return txBuilder.GetTx()
}, false, false, false,
},
Expand All @@ -383,14 +385,15 @@ func (suite AnteTestSuite) TestAnteHandler() {
txBuilder := suite.CreateTestEIP712TxBuilderMsgSend(from, privKey, suite.ctx.ChainID(), gas, amount)
nonce, err := suite.app.AccountKeeper.GetSequence(suite.ctx, acc.GetAddress())
suite.Require().NoError(err)
// nolint: exhaustruct
sigsV2 := signing.SignatureV2{
PubKey: privKey.PubKey(),
Data: &signing.SingleSignatureData{
SignMode: signing.SignMode_SIGN_MODE_UNSPECIFIED,
},
Sequence: nonce,
}
txBuilder.SetSignatures(sigsV2)
suite.Require().NoError(txBuilder.SetSignatures(sigsV2))
return txBuilder.GetTx()
}, false, false, false,
},
Expand Down
11 changes: 0 additions & 11 deletions app/ante/doc.go

This file was deleted.

3 changes: 3 additions & 0 deletions app/ante/eth_set_pubkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ func recoverPubKey(config *params.ChainConfig, blockNumber *big.Int, ethTx *etht
signer := ethtypes.NewEIP155Signer(config.ChainID)
pubkeyUncompressed, err = eip155PubKey(config, ethTx, signer)
case config.IsHomestead(blockNumber):
// nolint: exhaustruct
signer := ethtypes.HomesteadSigner{}
pubkeyUncompressed, err = homesteadPubKey(ethTx, signer)
default:
Expand Down Expand Up @@ -166,6 +167,7 @@ func eip2930PubKey(config *params.ChainConfig, tx *ethtypes.Transaction, signer
switch tx.Type() {
case LegacyTxType:
if !tx.Protected() {
// nolint: exhaustruct
return homesteadPubKey(tx, ethtypes.HomesteadSigner{})
}
V = new(big.Int).Sub(V, new(big.Int).Mul(config.ChainID, big.NewInt(2)))
Expand All @@ -191,6 +193,7 @@ func eip155PubKey(config *params.ChainConfig, tx *ethtypes.Transaction, signer e
return nil, ErrTxTypeNotSupported
}
if !tx.Protected() {
// nolint: exhaustruct
return homesteadPubKey(tx, ethtypes.HomesteadSigner{})
}
if tx.ChainId().Cmp(config.ChainID) != 0 {
Expand Down
31 changes: 4 additions & 27 deletions app/ante/eth_set_pubkey_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,15 @@ import (
"github.com/cosmos/cosmos-sdk/client"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/ethereum/go-ethereum/common"
"github.com/evmos/ethermint/tests"
ethtypes "github.com/evmos/ethermint/types"
evmtypes "github.com/evmos/ethermint/x/evm/types"
)

// Checks that the PubKey types are updated correctly, and that the new ante handler succeeds where the old one failed
func (suite AnteTestSuite) TestEthSetPubkeyHandler() {
var acc authtypes.AccountI
func (suite *AnteTestSuite) TestEthSetPubkeyHandler() {
to := tests.GenerateAddress()
suite.SetupTest()

// Setup will create the account as either a BaseAccount or an EthAccount (based on isBaseAccount) and set the balance
setup := func(ctx sdk.Context, addr sdk.AccAddress, isBaseAccount bool) {
suite.enableFeemarket = false

if isBaseAccount {
acc = suite.app.AccountKeeper.NewAccountWithAddress(ctx, addr)
suite.Require().True(isCosmosAccount(acc), "account type should be BaseAccount")
} else {
acc = ethtypes.ProtoAccount()
suite.Require().NoError(acc.SetAddress(addr))
suite.app.AccountKeeper.SetAccount(ctx, acc)
acc = suite.app.AccountKeeper.GetAccount(ctx, addr)
suite.Require().True(isEthAccount(acc), "account type should be EthAccount")
}
evmAddr := common.BytesToAddress(addr.Bytes())
suite.app.EvmKeeper.SetBalance(ctx, evmAddr, big.NewInt(10000000000))

suite.app.FeemarketKeeper.SetBaseFee(ctx, big.NewInt(100))
}

testCases := []struct {
name string // A name which is printed when the test fails
txPrivKeyFn func() (client.TxBuilder, cryptotypes.PrivKey) // generates a tx and privkey for the test
Expand Down Expand Up @@ -157,7 +133,7 @@ func (suite AnteTestSuite) TestEthSetPubkeyHandler() {
builder, privKey := tc.txPrivKeyFn()
addr := sdk.AccAddress(privKey.PubKey().Address())
// Create the account for the test, which will be a BaseAccount or an EthAccount depending on startBaseAcc
setup(ctx, addr, tc.startBaseAcc)
suite.testCaseSetup(ctx, addr, tc.startBaseAcc)
acc := suite.app.AccountKeeper.GetAccount(ctx, addr)

if tc.signCosmosTx {
Expand All @@ -180,7 +156,8 @@ func (suite AnteTestSuite) TestEthSetPubkeyHandler() {

// Now check the old antehandler against the same Tx, see if it would create a pubkey
ctx, _ = suite.ctx.CacheContext()
setup(ctx, addr, tc.startBaseAcc)
suite.testCaseSetup(ctx, addr, tc.startBaseAcc)
// nolint: errcheck
_, _ = suite.oldAnteHandler(ctx, tx, false)
acc = suite.app.AccountKeeper.GetAccount(ctx, addr)
pubKey = acc.GetPubKey()
Expand Down
24 changes: 18 additions & 6 deletions app/ante/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ func (suite *AnteTestSuite) SetupTest() {
return genesis
})

// nolint: exhaustruct
suite.ctx = suite.app.BaseApp.NewContext(checkTx, tmproto.Header{Height: 2, ChainID: "althea_417834-1", Time: time.Now().UTC()})
suite.ctx = suite.ctx.WithMinGasPrices(sdk.NewDecCoins(sdk.NewDecCoin(altheaconfig.BaseDenom, sdk.OneInt())))
suite.ctx = suite.ctx.WithBlockGasMeter(sdk.NewGasMeter(1000000000000000000))
Expand All @@ -116,12 +117,14 @@ func (suite *AnteTestSuite) SetupTest() {

encodingConfig := encoding.MakeConfig(app.ModuleBasics)
// We're using TestMsg amino encoding in some tests, so register it here.

// nolint: exhaustruct
encodingConfig.Amino.RegisterConcrete(&testdata.TestMsg{}, "testdata.TestMsg", nil)

// nolint: exhaustruct
suite.clientCtx = client.Context{}.WithTxConfig(encodingConfig.TxConfig)

// altheaconfig.SetBech32Prefixes(sdk.GetConfig())

// nolint: exhaustruct
anteHandler := ante.NewAnteHandler(ante.HandlerOptions{
AccountKeeper: suite.app.AccountKeeper,
BankKeeper: suite.app.BankKeeper,
Expand All @@ -136,6 +139,7 @@ func (suite *AnteTestSuite) SetupTest() {
suite.anteHandler = anteHandler

// Also make a copy of the old Canto antehandler we were using to ensure that our changes fix the problem
// nolint: exhaustruct
oldAnteHandler := cantoante.NewAnteHandler(cantoante.HandlerOptions{
AccountKeeper: suite.app.AccountKeeper,
BankKeeper: suite.app.BankKeeper,
Expand All @@ -154,6 +158,7 @@ func (suite *AnteTestSuite) SetupTest() {

// DefaultConsensusParams defines the default Tendermint consensus params used in
// EthermintApp testing.
// nolint: exhaustruct
var DefaultConsensusParams = &abci.ConsensusParams{
Block: &abci.BlockParams{
MaxBytes: 200000,
Expand Down Expand Up @@ -189,6 +194,7 @@ func Setup(isCheckTx bool, patchGenesis func(*althea.AltheaApp, althea.GenesisSt

// Initialize the chain
app.InitChain(
// nolint: exhaustruct
abci.RequestInitChain{
ChainId: "althea_417834-1",
Validators: []abci.ValidatorUpdate{},
Expand All @@ -202,14 +208,18 @@ func Setup(isCheckTx bool, patchGenesis func(*althea.AltheaApp, althea.GenesisSt
}

func TestAnteTestSuite(t *testing.T) {
// nolint: exhaustruct
suite.Run(t, &AnteTestSuite{
enableLondonHF: true,
})
}

func (s *AnteTestSuite) NewEthermintPrivkey() *ethsecp256k1.PrivKey {
privkey, _ := ethsecp256k1.GenerateKey()
_, err := privkey.ToECDSA()
privkey, err := ethsecp256k1.GenerateKey()
if err != nil {
return nil
}
_, err = privkey.ToECDSA()
if err != nil {
return nil
}
Expand Down Expand Up @@ -395,7 +405,7 @@ func (suite *AnteTestSuite) SignTestCosmosTx(ctx sdk.Context, txBuilder client.T
Sequence: sequence,
}

txBuilder.SetSignatures(sig)
suite.Require().NoError(txBuilder.SetSignatures(sig))
return txBuilder
}

Expand Down Expand Up @@ -428,6 +438,7 @@ func (suite *AnteTestSuite) CreateTestEIP712CosmosTxBuilder(

// GenerateTypedData TypedData
var ethermintCodec codec.ProtoCodecMarshaler
// nolint: staticcheck
fee := legacytx.NewStdFee(gas, gasAmount)
accNumber := suite.app.AccountKeeper.GetAccount(suite.ctx, from).GetAccountNumber()

Expand Down Expand Up @@ -467,7 +478,8 @@ func (suite *AnteTestSuite) CreateTestEIP712CosmosTxBuilder(
sigsV2 := signing.SignatureV2{
PubKey: pubKey,
Data: &signing.SingleSignatureData{
SignMode: signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON,
SignMode: signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON,
Signature: []byte{},
},
Sequence: nonce,
}
Expand Down
Loading

0 comments on commit 47207db

Please sign in to comment.