2021-05-31 09:05:32 +00:00
|
|
|
package ante_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math/big"
|
|
|
|
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
|
2021-06-22 10:49:18 +00:00
|
|
|
"github.com/tharsis/ethermint/app/ante"
|
2022-03-21 09:01:21 +00:00
|
|
|
"github.com/tharsis/ethermint/server/config"
|
2021-06-22 10:49:18 +00:00
|
|
|
"github.com/tharsis/ethermint/tests"
|
2022-01-05 07:28:27 +00:00
|
|
|
"github.com/tharsis/ethermint/x/evm/statedb"
|
2021-06-22 10:49:18 +00:00
|
|
|
evmtypes "github.com/tharsis/ethermint/x/evm/types"
|
2021-05-31 09:05:32 +00:00
|
|
|
|
|
|
|
ethtypes "github.com/ethereum/go-ethereum/core/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
func nextFn(ctx sdk.Context, _ sdk.Tx, _ bool) (sdk.Context, error) {
|
|
|
|
return ctx, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite AnteTestSuite) TestEthSigVerificationDecorator() {
|
|
|
|
dec := ante.NewEthSigVerificationDecorator(suite.app.EvmKeeper)
|
2021-09-07 17:29:24 +00:00
|
|
|
addr, privKey := tests.NewAddrKey()
|
2021-05-31 09:05:32 +00:00
|
|
|
|
2021-10-05 15:38:20 +00:00
|
|
|
signedTx := evmtypes.NewTxContract(suite.app.EvmKeeper.ChainID(), 1, big.NewInt(10), 1000, big.NewInt(1), nil, nil, nil, nil)
|
2021-05-31 09:05:32 +00:00
|
|
|
signedTx.From = addr.Hex()
|
2021-06-01 17:14:33 +00:00
|
|
|
err := signedTx.Sign(suite.ethSigner, tests.NewSigner(privKey))
|
2021-05-31 09:05:32 +00:00
|
|
|
suite.Require().NoError(err)
|
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
tx sdk.Tx
|
|
|
|
reCheckTx bool
|
|
|
|
expPass bool
|
|
|
|
}{
|
2022-01-14 09:37:33 +00:00
|
|
|
{"ReCheckTx", &invalidTx{}, true, false},
|
2021-05-31 09:05:32 +00:00
|
|
|
{"invalid transaction type", &invalidTx{}, false, false},
|
|
|
|
{
|
|
|
|
"invalid sender",
|
2021-10-05 15:38:20 +00:00
|
|
|
evmtypes.NewTx(suite.app.EvmKeeper.ChainID(), 1, &addr, big.NewInt(10), 1000, big.NewInt(1), nil, nil, nil, nil),
|
2021-05-31 09:05:32 +00:00
|
|
|
false,
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
{"successful signature verification", signedTx, false, true},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
suite.Run(tc.name, func() {
|
2021-06-30 09:31:30 +00:00
|
|
|
_, err := dec.AnteHandle(suite.ctx.WithIsReCheckTx(tc.reCheckTx), tc.tx, false, nextFn)
|
2021-05-31 09:05:32 +00:00
|
|
|
|
|
|
|
if tc.expPass {
|
|
|
|
suite.Require().NoError(err)
|
|
|
|
} else {
|
|
|
|
suite.Require().Error(err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite AnteTestSuite) TestNewEthAccountVerificationDecorator() {
|
|
|
|
dec := ante.NewEthAccountVerificationDecorator(
|
2022-05-02 16:48:40 +00:00
|
|
|
suite.app.AccountKeeper, suite.app.EvmKeeper,
|
2021-05-31 09:05:32 +00:00
|
|
|
)
|
|
|
|
|
2021-09-07 17:29:24 +00:00
|
|
|
addr := tests.GenerateAddress()
|
2021-05-31 09:05:32 +00:00
|
|
|
|
2021-10-05 15:38:20 +00:00
|
|
|
tx := evmtypes.NewTxContract(suite.app.EvmKeeper.ChainID(), 1, big.NewInt(10), 1000, big.NewInt(1), nil, nil, nil, nil)
|
2021-05-31 09:05:32 +00:00
|
|
|
tx.From = addr.Hex()
|
|
|
|
|
2022-01-05 07:28:27 +00:00
|
|
|
var vmdb *statedb.StateDB
|
|
|
|
|
2021-05-31 09:05:32 +00:00
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
tx sdk.Tx
|
|
|
|
malleate func()
|
|
|
|
checkTx bool
|
|
|
|
expPass bool
|
|
|
|
}{
|
|
|
|
{"not CheckTx", nil, func() {}, false, true},
|
|
|
|
{"invalid transaction type", &invalidTx{}, func() {}, true, false},
|
|
|
|
{
|
|
|
|
"sender not set to msg",
|
2021-10-05 15:38:20 +00:00
|
|
|
evmtypes.NewTxContract(suite.app.EvmKeeper.ChainID(), 1, big.NewInt(10), 1000, big.NewInt(1), nil, nil, nil, nil),
|
2021-05-31 09:05:32 +00:00
|
|
|
func() {},
|
|
|
|
true,
|
|
|
|
false,
|
|
|
|
},
|
2021-06-15 17:39:41 +00:00
|
|
|
{
|
|
|
|
"sender not EOA",
|
|
|
|
tx,
|
|
|
|
func() {
|
|
|
|
// set not as an EOA
|
2022-01-05 07:28:27 +00:00
|
|
|
vmdb.SetCode(addr, []byte("1"))
|
2021-06-15 17:39:41 +00:00
|
|
|
},
|
|
|
|
true,
|
|
|
|
false,
|
|
|
|
},
|
2021-05-31 09:05:32 +00:00
|
|
|
{
|
|
|
|
"not enough balance to cover tx cost",
|
|
|
|
tx,
|
2021-06-15 17:39:41 +00:00
|
|
|
func() {
|
|
|
|
// reset back to EOA
|
2022-01-05 07:28:27 +00:00
|
|
|
vmdb.SetCode(addr, nil)
|
2021-06-15 17:39:41 +00:00
|
|
|
},
|
2021-05-31 09:05:32 +00:00
|
|
|
true,
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"success new account",
|
|
|
|
tx,
|
|
|
|
func() {
|
2022-01-05 07:28:27 +00:00
|
|
|
vmdb.AddBalance(addr, big.NewInt(1000000))
|
2021-05-31 09:05:32 +00:00
|
|
|
},
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"success existing account",
|
|
|
|
tx,
|
|
|
|
func() {
|
|
|
|
acc := suite.app.AccountKeeper.NewAccountWithAddress(suite.ctx, addr.Bytes())
|
|
|
|
suite.app.AccountKeeper.SetAccount(suite.ctx, acc)
|
|
|
|
|
2022-01-05 07:28:27 +00:00
|
|
|
vmdb.AddBalance(addr, big.NewInt(1000000))
|
2021-05-31 09:05:32 +00:00
|
|
|
},
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
suite.Run(tc.name, func() {
|
2022-01-05 07:28:27 +00:00
|
|
|
vmdb = suite.StateDB()
|
2021-05-31 09:05:32 +00:00
|
|
|
tc.malleate()
|
2022-01-05 07:28:27 +00:00
|
|
|
suite.Require().NoError(vmdb.Commit())
|
|
|
|
|
2021-06-30 09:31:30 +00:00
|
|
|
_, err := dec.AnteHandle(suite.ctx.WithIsCheckTx(tc.checkTx), tc.tx, false, nextFn)
|
2021-05-31 09:05:32 +00:00
|
|
|
|
|
|
|
if tc.expPass {
|
|
|
|
suite.Require().NoError(err)
|
|
|
|
} else {
|
|
|
|
suite.Require().Error(err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite AnteTestSuite) TestEthNonceVerificationDecorator() {
|
2022-01-14 09:37:33 +00:00
|
|
|
suite.SetupTest()
|
|
|
|
dec := ante.NewEthIncrementSenderSequenceDecorator(suite.app.AccountKeeper)
|
2021-05-31 09:05:32 +00:00
|
|
|
|
2021-09-07 17:29:24 +00:00
|
|
|
addr := tests.GenerateAddress()
|
2021-05-31 09:05:32 +00:00
|
|
|
|
2021-10-05 15:38:20 +00:00
|
|
|
tx := evmtypes.NewTxContract(suite.app.EvmKeeper.ChainID(), 1, big.NewInt(10), 1000, big.NewInt(1), nil, nil, nil, nil)
|
2021-05-31 09:05:32 +00:00
|
|
|
tx.From = addr.Hex()
|
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
tx sdk.Tx
|
|
|
|
malleate func()
|
|
|
|
reCheckTx bool
|
|
|
|
expPass bool
|
|
|
|
}{
|
2022-01-14 09:37:33 +00:00
|
|
|
{"ReCheckTx", &invalidTx{}, func() {}, true, false},
|
2021-05-31 09:05:32 +00:00
|
|
|
{"invalid transaction type", &invalidTx{}, func() {}, false, false},
|
|
|
|
{"sender account not found", tx, func() {}, false, false},
|
|
|
|
{
|
|
|
|
"sender nonce missmatch",
|
|
|
|
tx,
|
|
|
|
func() {
|
|
|
|
acc := suite.app.AccountKeeper.NewAccountWithAddress(suite.ctx, addr.Bytes())
|
|
|
|
suite.app.AccountKeeper.SetAccount(suite.ctx, acc)
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"success",
|
|
|
|
tx,
|
|
|
|
func() {
|
|
|
|
acc := suite.app.AccountKeeper.NewAccountWithAddress(suite.ctx, addr.Bytes())
|
|
|
|
suite.Require().NoError(acc.SetSequence(1))
|
|
|
|
suite.app.AccountKeeper.SetAccount(suite.ctx, acc)
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
suite.Run(tc.name, func() {
|
|
|
|
tc.malleate()
|
2021-06-30 09:31:30 +00:00
|
|
|
_, err := dec.AnteHandle(suite.ctx.WithIsReCheckTx(tc.reCheckTx), tc.tx, false, nextFn)
|
2021-05-31 09:05:32 +00:00
|
|
|
|
|
|
|
if tc.expPass {
|
|
|
|
suite.Require().NoError(err)
|
|
|
|
} else {
|
|
|
|
suite.Require().Error(err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite AnteTestSuite) TestEthGasConsumeDecorator() {
|
2022-03-21 09:01:21 +00:00
|
|
|
dec := ante.NewEthGasConsumeDecorator(suite.app.EvmKeeper, config.DefaultMaxTxGasWanted)
|
2021-05-31 09:05:32 +00:00
|
|
|
|
2021-09-07 17:29:24 +00:00
|
|
|
addr := tests.GenerateAddress()
|
2021-05-31 09:05:32 +00:00
|
|
|
|
2022-03-06 14:09:28 +00:00
|
|
|
txGasLimit := uint64(1000)
|
|
|
|
tx := evmtypes.NewTxContract(suite.app.EvmKeeper.ChainID(), 1, big.NewInt(10), txGasLimit, big.NewInt(1), nil, nil, nil, nil)
|
2021-05-31 09:05:32 +00:00
|
|
|
tx.From = addr.Hex()
|
|
|
|
|
2022-03-06 14:09:28 +00:00
|
|
|
tx2GasLimit := uint64(1000000)
|
|
|
|
tx2 := evmtypes.NewTxContract(suite.app.EvmKeeper.ChainID(), 1, big.NewInt(10), tx2GasLimit, big.NewInt(1), nil, nil, nil, ðtypes.AccessList{{Address: addr, StorageKeys: nil}})
|
2021-05-31 09:05:32 +00:00
|
|
|
tx2.From = addr.Hex()
|
|
|
|
|
2022-01-05 07:28:27 +00:00
|
|
|
var vmdb *statedb.StateDB
|
|
|
|
|
2021-05-31 09:05:32 +00:00
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
tx sdk.Tx
|
2022-03-06 14:09:28 +00:00
|
|
|
gasLimit uint64
|
2021-05-31 09:05:32 +00:00
|
|
|
malleate func()
|
|
|
|
expPass bool
|
|
|
|
expPanic bool
|
|
|
|
}{
|
2022-03-06 14:09:28 +00:00
|
|
|
{"invalid transaction type", &invalidTx{}, 0, func() {}, false, false},
|
2021-05-31 09:05:32 +00:00
|
|
|
{
|
|
|
|
"sender not found",
|
2021-10-05 15:38:20 +00:00
|
|
|
evmtypes.NewTxContract(suite.app.EvmKeeper.ChainID(), 1, big.NewInt(10), 1000, big.NewInt(1), nil, nil, nil, nil),
|
2022-03-06 14:09:28 +00:00
|
|
|
0,
|
2021-05-31 09:05:32 +00:00
|
|
|
func() {},
|
|
|
|
false, false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"gas limit too low",
|
|
|
|
tx,
|
2022-03-06 14:09:28 +00:00
|
|
|
0,
|
2022-01-05 07:28:27 +00:00
|
|
|
func() {},
|
2021-05-31 09:05:32 +00:00
|
|
|
false, false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"not enough balance for fees",
|
|
|
|
tx2,
|
2022-03-06 14:09:28 +00:00
|
|
|
0,
|
2022-01-05 07:28:27 +00:00
|
|
|
func() {},
|
2021-05-31 09:05:32 +00:00
|
|
|
false, false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"not enough tx gas",
|
|
|
|
tx2,
|
2022-03-06 14:09:28 +00:00
|
|
|
0,
|
2021-05-31 09:05:32 +00:00
|
|
|
func() {
|
2022-01-05 07:28:27 +00:00
|
|
|
vmdb.AddBalance(addr, big.NewInt(1000000))
|
2021-05-31 09:05:32 +00:00
|
|
|
},
|
|
|
|
false, true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"not enough block gas",
|
|
|
|
tx2,
|
2022-03-06 14:09:28 +00:00
|
|
|
0,
|
2021-05-31 09:05:32 +00:00
|
|
|
func() {
|
2022-01-05 07:28:27 +00:00
|
|
|
vmdb.AddBalance(addr, big.NewInt(1000000))
|
2021-05-31 09:05:32 +00:00
|
|
|
|
|
|
|
suite.ctx = suite.ctx.WithBlockGasMeter(sdk.NewGasMeter(1))
|
|
|
|
},
|
|
|
|
false, true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"success",
|
|
|
|
tx2,
|
2022-03-22 09:24:26 +00:00
|
|
|
config.DefaultMaxTxGasWanted, // it's capped
|
2021-05-31 09:05:32 +00:00
|
|
|
func() {
|
2022-01-05 07:28:27 +00:00
|
|
|
vmdb.AddBalance(addr, big.NewInt(1000000))
|
2021-05-31 09:05:32 +00:00
|
|
|
|
|
|
|
suite.ctx = suite.ctx.WithBlockGasMeter(sdk.NewGasMeter(10000000000000000000))
|
|
|
|
},
|
|
|
|
true, false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
suite.Run(tc.name, func() {
|
2022-01-05 07:28:27 +00:00
|
|
|
vmdb = suite.StateDB()
|
2021-05-31 09:05:32 +00:00
|
|
|
tc.malleate()
|
2022-01-05 07:28:27 +00:00
|
|
|
suite.Require().NoError(vmdb.Commit())
|
2021-05-31 09:05:32 +00:00
|
|
|
|
|
|
|
if tc.expPanic {
|
|
|
|
suite.Require().Panics(func() {
|
|
|
|
_, _ = dec.AnteHandle(suite.ctx.WithIsCheckTx(true).WithGasMeter(sdk.NewGasMeter(1)), tc.tx, false, nextFn)
|
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-03-06 14:09:28 +00:00
|
|
|
ctx, err := dec.AnteHandle(suite.ctx.WithIsCheckTx(true).WithGasMeter(sdk.NewInfiniteGasMeter()), tc.tx, false, nextFn)
|
2021-05-31 09:05:32 +00:00
|
|
|
if tc.expPass {
|
|
|
|
suite.Require().NoError(err)
|
|
|
|
} else {
|
|
|
|
suite.Require().Error(err)
|
|
|
|
}
|
2022-03-06 14:09:28 +00:00
|
|
|
suite.Require().Equal(tc.gasLimit, ctx.GasMeter().Limit())
|
2021-05-31 09:05:32 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-02 08:52:53 +00:00
|
|
|
func (suite AnteTestSuite) TestCanTransferDecorator() {
|
2022-01-26 10:44:41 +00:00
|
|
|
dec := ante.NewCanTransferDecorator(suite.app.EvmKeeper)
|
2021-06-02 08:52:53 +00:00
|
|
|
|
2021-09-07 17:29:24 +00:00
|
|
|
addr, privKey := tests.NewAddrKey()
|
2021-06-02 08:52:53 +00:00
|
|
|
|
2021-11-19 16:22:25 +00:00
|
|
|
suite.app.FeeMarketKeeper.SetBaseFee(suite.ctx, big.NewInt(100))
|
|
|
|
|
|
|
|
tx := evmtypes.NewTxContract(
|
|
|
|
suite.app.EvmKeeper.ChainID(),
|
|
|
|
1,
|
|
|
|
big.NewInt(10),
|
|
|
|
1000,
|
|
|
|
big.NewInt(150),
|
|
|
|
big.NewInt(200),
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
ðtypes.AccessList{},
|
|
|
|
)
|
|
|
|
tx2 := evmtypes.NewTxContract(
|
|
|
|
suite.app.EvmKeeper.ChainID(),
|
|
|
|
1,
|
|
|
|
big.NewInt(10),
|
|
|
|
1000,
|
|
|
|
big.NewInt(150),
|
|
|
|
big.NewInt(200),
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
ðtypes.AccessList{},
|
|
|
|
)
|
2021-06-02 08:52:53 +00:00
|
|
|
|
|
|
|
tx.From = addr.Hex()
|
|
|
|
|
2021-06-11 13:38:51 +00:00
|
|
|
err := tx.Sign(suite.ethSigner, tests.NewSigner(privKey))
|
|
|
|
suite.Require().NoError(err)
|
|
|
|
|
2022-01-05 07:28:27 +00:00
|
|
|
var vmdb *statedb.StateDB
|
|
|
|
|
2021-06-02 08:52:53 +00:00
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
tx sdk.Tx
|
|
|
|
malleate func()
|
|
|
|
expPass bool
|
|
|
|
}{
|
|
|
|
{"invalid transaction type", &invalidTx{}, func() {}, false},
|
|
|
|
{"AsMessage failed", tx2, func() {}, false},
|
|
|
|
{
|
|
|
|
"evm CanTransfer failed",
|
|
|
|
tx,
|
|
|
|
func() {
|
|
|
|
acc := suite.app.AccountKeeper.NewAccountWithAddress(suite.ctx, addr.Bytes())
|
|
|
|
suite.app.AccountKeeper.SetAccount(suite.ctx, acc)
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"success",
|
|
|
|
tx,
|
|
|
|
func() {
|
|
|
|
acc := suite.app.AccountKeeper.NewAccountWithAddress(suite.ctx, addr.Bytes())
|
|
|
|
suite.app.AccountKeeper.SetAccount(suite.ctx, acc)
|
|
|
|
|
2022-01-05 07:28:27 +00:00
|
|
|
vmdb.AddBalance(addr, big.NewInt(1000000))
|
2021-06-02 08:52:53 +00:00
|
|
|
},
|
|
|
|
true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
suite.Run(tc.name, func() {
|
2022-01-05 07:28:27 +00:00
|
|
|
vmdb = suite.StateDB()
|
2021-06-02 08:52:53 +00:00
|
|
|
tc.malleate()
|
2022-01-05 07:28:27 +00:00
|
|
|
suite.Require().NoError(vmdb.Commit())
|
2021-06-02 08:52:53 +00:00
|
|
|
|
2021-06-30 09:31:30 +00:00
|
|
|
_, err := dec.AnteHandle(suite.ctx.WithIsCheckTx(true), tc.tx, false, nextFn)
|
2021-06-02 08:52:53 +00:00
|
|
|
|
|
|
|
if tc.expPass {
|
|
|
|
suite.Require().NoError(err)
|
|
|
|
} else {
|
|
|
|
suite.Require().Error(err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-31 09:05:32 +00:00
|
|
|
func (suite AnteTestSuite) TestEthIncrementSenderSequenceDecorator() {
|
|
|
|
dec := ante.NewEthIncrementSenderSequenceDecorator(suite.app.AccountKeeper)
|
2021-09-07 17:29:24 +00:00
|
|
|
addr, privKey := tests.NewAddrKey()
|
2021-05-31 09:05:32 +00:00
|
|
|
|
2021-10-05 15:38:20 +00:00
|
|
|
contract := evmtypes.NewTxContract(suite.app.EvmKeeper.ChainID(), 0, big.NewInt(10), 1000, big.NewInt(1), nil, nil, nil, nil)
|
2021-06-02 08:52:53 +00:00
|
|
|
contract.From = addr.Hex()
|
2021-12-16 22:35:28 +00:00
|
|
|
err := contract.Sign(suite.ethSigner, tests.NewSigner(privKey))
|
|
|
|
suite.Require().NoError(err)
|
2021-06-02 08:52:53 +00:00
|
|
|
|
|
|
|
to := tests.GenerateAddress()
|
2021-10-05 15:38:20 +00:00
|
|
|
tx := evmtypes.NewTx(suite.app.EvmKeeper.ChainID(), 0, &to, big.NewInt(10), 1000, big.NewInt(1), nil, nil, nil, nil)
|
2021-06-02 08:52:53 +00:00
|
|
|
tx.From = addr.Hex()
|
2021-12-16 22:35:28 +00:00
|
|
|
err = tx.Sign(suite.ethSigner, tests.NewSigner(privKey))
|
2021-06-02 08:52:53 +00:00
|
|
|
suite.Require().NoError(err)
|
|
|
|
|
2021-12-16 22:35:28 +00:00
|
|
|
tx2 := evmtypes.NewTx(suite.app.EvmKeeper.ChainID(), 1, &to, big.NewInt(10), 1000, big.NewInt(1), nil, nil, nil, nil)
|
|
|
|
tx2.From = addr.Hex()
|
|
|
|
err = tx2.Sign(suite.ethSigner, tests.NewSigner(privKey))
|
2021-05-31 09:05:32 +00:00
|
|
|
suite.Require().NoError(err)
|
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
tx sdk.Tx
|
|
|
|
malleate func()
|
|
|
|
expPass bool
|
|
|
|
expPanic bool
|
|
|
|
}{
|
2021-06-02 08:52:53 +00:00
|
|
|
{
|
|
|
|
"invalid transaction type",
|
|
|
|
&invalidTx{},
|
|
|
|
func() {},
|
2022-01-14 09:37:33 +00:00
|
|
|
false, false,
|
2021-06-02 08:52:53 +00:00
|
|
|
},
|
2021-05-31 09:05:32 +00:00
|
|
|
{
|
|
|
|
"no signers",
|
2021-10-05 15:38:20 +00:00
|
|
|
evmtypes.NewTx(suite.app.EvmKeeper.ChainID(), 1, &to, big.NewInt(10), 1000, big.NewInt(1), nil, nil, nil, nil),
|
2021-05-31 09:05:32 +00:00
|
|
|
func() {},
|
2022-01-14 09:37:33 +00:00
|
|
|
false, false,
|
2021-05-31 09:05:32 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"account not set to store",
|
2021-06-02 08:52:53 +00:00
|
|
|
tx,
|
2021-05-31 09:05:32 +00:00
|
|
|
func() {},
|
|
|
|
false, false,
|
|
|
|
},
|
|
|
|
{
|
2021-06-02 08:52:53 +00:00
|
|
|
"success - create contract",
|
|
|
|
contract,
|
2021-05-31 09:05:32 +00:00
|
|
|
func() {
|
|
|
|
acc := suite.app.AccountKeeper.NewAccountWithAddress(suite.ctx, addr.Bytes())
|
|
|
|
suite.app.AccountKeeper.SetAccount(suite.ctx, acc)
|
|
|
|
},
|
|
|
|
true, false,
|
|
|
|
},
|
2021-06-02 08:52:53 +00:00
|
|
|
{
|
|
|
|
"success - call",
|
2021-12-16 22:35:28 +00:00
|
|
|
tx2,
|
2021-06-02 08:52:53 +00:00
|
|
|
func() {},
|
|
|
|
true, false,
|
|
|
|
},
|
2021-05-31 09:05:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
suite.Run(tc.name, func() {
|
|
|
|
tc.malleate()
|
|
|
|
|
|
|
|
if tc.expPanic {
|
|
|
|
suite.Require().Panics(func() {
|
|
|
|
_, _ = dec.AnteHandle(suite.ctx, tc.tx, false, nextFn)
|
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-06-30 09:31:30 +00:00
|
|
|
_, err := dec.AnteHandle(suite.ctx, tc.tx, false, nextFn)
|
2021-05-31 09:05:32 +00:00
|
|
|
|
|
|
|
if tc.expPass {
|
|
|
|
suite.Require().NoError(err)
|
2021-06-02 08:52:53 +00:00
|
|
|
msg := tc.tx.(*evmtypes.MsgEthereumTx)
|
2021-07-05 16:39:08 +00:00
|
|
|
|
|
|
|
txData, err := evmtypes.UnpackTxData(msg.Data)
|
|
|
|
suite.Require().NoError(err)
|
|
|
|
|
2022-01-05 07:28:27 +00:00
|
|
|
nonce := suite.app.EvmKeeper.GetNonce(suite.ctx, addr)
|
2021-12-16 22:35:28 +00:00
|
|
|
suite.Require().Equal(txData.GetNonce()+1, nonce)
|
2021-05-31 09:05:32 +00:00
|
|
|
} else {
|
|
|
|
suite.Require().Error(err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2021-06-30 09:31:30 +00:00
|
|
|
|
|
|
|
func (suite AnteTestSuite) TestEthSetupContextDecorator() {
|
2022-01-14 09:37:33 +00:00
|
|
|
dec := ante.NewEthSetUpContextDecorator(suite.app.EvmKeeper)
|
2021-10-05 15:38:20 +00:00
|
|
|
tx := evmtypes.NewTxContract(suite.app.EvmKeeper.ChainID(), 1, big.NewInt(10), 1000, big.NewInt(1), nil, nil, nil, nil)
|
2021-06-30 09:31:30 +00:00
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
tx sdk.Tx
|
|
|
|
expPass bool
|
|
|
|
}{
|
|
|
|
{"invalid transaction type - does not implement GasTx", &invalidTx{}, false},
|
|
|
|
{
|
|
|
|
"success - transaction implement GasTx",
|
|
|
|
tx,
|
|
|
|
true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
suite.Run(tc.name, func() {
|
|
|
|
_, err := dec.AnteHandle(suite.ctx, tc.tx, false, nextFn)
|
|
|
|
|
|
|
|
if tc.expPass {
|
|
|
|
suite.Require().NoError(err)
|
|
|
|
} else {
|
|
|
|
suite.Require().Error(err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|