bump SDK to v0.39.1 (#386)

* bump sdk version to v0.39.0 candidate

* updates

* update evm

* bump commit

* more changes

* build

* genesis

* fix tests

* fix tests

* bump commit

* bump commit

* bump commit

* add keygen func

* bump version to 0.39.0-rc0

* update AnteHandler

* fix TxDecoder

* lint

* fix test

* update statedb

* changelog

* fixes

* remove extra files

* update make test-import

* rename test

* bump SDK version to final release

* update to 0.39.1-rc1

* fix evm tests

* update RPC

* minor fixes

* update to rc2

* bump to v0.39.1

* fix personal API

* fix string type cast ambiguity (#449)

* init

* fix estimate gas test

* minor genesis change

* remove comments from unstable commit (stargate release)

Co-authored-by: Alessio Treglia <quadrispro@ubuntu.com>
This commit is contained in:
Federico Kunze
2020-08-23 17:41:54 -04:00
committed by GitHub
co-authored by Alessio Treglia
parent 6fa5fafb12
commit 261f86fdf2
65 changed files with 688 additions and 2696 deletions
+1 -1
View File
@@ -26,7 +26,7 @@ func BeginBlock(k Keeper, ctx sdk.Context, req abci.RequestBeginBlock) {
// EndBlock updates the accounts and commits states objects to the KV Store.
//
func EndBlock(k Keeper, ctx sdk.Context, req abci.RequestEndBlock) []abci.ValidatorUpdate {
func EndBlock(k Keeper, ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {
// Gas costs are handled within msg handler so costs should be ignored
ctx = ctx.WithBlockGasMeter(sdk.NewInfiniteGasMeter())
+4 -7
View File
@@ -19,16 +19,15 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
authclient "github.com/cosmos/cosmos-sdk/x/auth/client"
authclient "github.com/cosmos/cosmos-sdk/x/auth/client/utils"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
ethermintcodec "github.com/cosmos/ethermint/codec"
emint "github.com/cosmos/ethermint/types"
"github.com/cosmos/ethermint/x/evm/types"
)
// GetTxCmd defines the CLI commands regarding evm module transactions
func GetTxCmd(storeKey string, cdc *codec.Codec) *cobra.Command {
func GetTxCmd(cdc *codec.Codec) *cobra.Command {
evmTxCmd := &cobra.Command{
Use: types.ModuleName,
Short: "EVM transaction subcommands",
@@ -83,8 +82,7 @@ func GetCmdSendTx(cdc *codec.Codec) *cobra.Command {
from := cliCtx.GetFromAddress()
authclient.Codec = ethermintcodec.NewAppCodec(cdc)
_, seq, err := authtypes.NewAccountRetriever(authclient.Codec, cliCtx).GetAccountNumberSequence(from)
_, seq, err := authtypes.NewAccountRetriever(cliCtx).GetAccountNumberSequence(from)
if err != nil {
return errors.Wrap(err, "Could not retrieve account sequence")
}
@@ -136,8 +134,7 @@ func GetCmdGenCreateTx(cdc *codec.Codec) *cobra.Command {
from := cliCtx.GetFromAddress()
authclient.Codec = ethermintcodec.NewAppCodec(cdc)
_, seq, err := authtypes.NewAccountRetriever(authclient.Codec, cliCtx).GetAccountNumberSequence(from)
_, seq, err := authtypes.NewAccountRetriever(cliCtx).GetAccountNumberSequence(from)
if err != nil {
return errors.Wrap(err, "Could not retrieve account sequence")
}
+6 -10
View File
@@ -1,8 +1,6 @@
package evm
import (
"github.com/ethereum/go-ethereum/common"
sdk "github.com/cosmos/cosmos-sdk/types"
emint "github.com/cosmos/ethermint/types"
@@ -37,10 +35,12 @@ func InitGenesis(ctx sdk.Context, k Keeper, data GenesisState) []abci.ValidatorU
}
// set storage to store
err = k.Finalise(ctx, true)
// NOTE: don't delete empty object to prevent import-export simulation failure
err = k.Finalise(ctx, false)
if err != nil {
panic(err)
}
return []abci.ValidatorUpdate{}
}
@@ -50,20 +50,16 @@ func ExportGenesis(ctx sdk.Context, k Keeper, ak types.AccountKeeper) GenesisSta
var ethGenAccounts []types.GenesisAccount
accounts := ak.GetAllAccounts(ctx)
var err error
for _, account := range accounts {
ethAccount, ok := account.(*emint.EthAccount)
if !ok {
continue
}
addr := common.BytesToAddress(ethAccount.GetAddress().Bytes())
addr := ethAccount.EthAddress()
var storage types.Storage
err = k.CommitStateDB.ForEachStorage(addr, func(key, value common.Hash) bool {
storage = append(storage, types.NewState(key, value))
return false
})
storage, err := k.GetAccountStorage(ctx, addr)
if err != nil {
panic(err)
}
+2 -2
View File
@@ -105,7 +105,7 @@ func handleMsgEthereumTx(ctx sdk.Context, k Keeper, msg types.MsgEthereumTx) (*s
}
// set the events to the result
executionResult.Result.Events = ctx.EventManager().Events().ToABCIEvents()
executionResult.Result.Events = ctx.EventManager().Events()
return executionResult.Result, nil
}
@@ -181,6 +181,6 @@ func handleMsgEthermint(ctx sdk.Context, k Keeper, msg types.MsgEthermint) (*sdk
}
// set the events to the result
executionResult.Result.Events = ctx.EventManager().Events().ToABCIEvents()
executionResult.Result.Events = ctx.EventManager().Events()
return executionResult.Result, nil
}
+18 -4
View File
@@ -13,7 +13,7 @@ import (
"github.com/cosmos/ethermint/x/evm/types"
ethcmn "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
ethtypes "github.com/ethereum/go-ethereum/core/types"
)
@@ -39,12 +39,12 @@ type Keeper struct {
// NewKeeper generates new evm module keeper
func NewKeeper(
cdc *codec.Codec, storeKey sdk.StoreKey, ak types.AccountKeeper, bk types.BankKeeper,
cdc *codec.Codec, storeKey sdk.StoreKey, ak types.AccountKeeper,
) Keeper {
return Keeper{
cdc: cdc,
storeKey: storeKey,
CommitStateDB: types.NewCommitStateDB(sdk.Context{}, storeKey, ak, bk),
CommitStateDB: types.NewCommitStateDB(sdk.Context{}, storeKey, ak),
TxCount: 0,
Bloom: big.NewInt(0),
}
@@ -110,7 +110,7 @@ func (k Keeper) GetAllTxLogs(ctx sdk.Context) []types.TransactionLogs {
txsLogs := []types.TransactionLogs{}
for ; iterator.Valid(); iterator.Next() {
hash := ethcmn.BytesToHash(iterator.Key())
hash := common.BytesToHash(iterator.Key())
var logs []*ethtypes.Log
k.cdc.MustUnmarshalBinaryLengthPrefixed(iterator.Value(), &logs)
@@ -120,3 +120,17 @@ func (k Keeper) GetAllTxLogs(ctx sdk.Context) []types.TransactionLogs {
}
return txsLogs
}
// GetAccountStorage return state storage associated with an account
func (k Keeper) GetAccountStorage(ctx sdk.Context, address common.Address) (types.Storage, error) {
storage := types.Storage{}
err := k.ForEachStorage(ctx, address, func(key, value common.Hash) bool {
storage = append(storage, types.NewState(key, value))
return false
})
if err != nil {
return types.Storage{}, err
}
return storage, nil
}
+11
View File
@@ -8,12 +8,15 @@ import (
"github.com/stretchr/testify/suite"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/ethermint/app"
ethermint "github.com/cosmos/ethermint/types"
"github.com/cosmos/ethermint/x/evm/keeper"
ethcmn "github.com/ethereum/go-ethereum/common"
ethtypes "github.com/ethereum/go-ethereum/core/types"
ethcrypto "github.com/ethereum/go-ethereum/crypto"
abci "github.com/tendermint/tendermint/abci/types"
)
@@ -41,6 +44,14 @@ func (suite *KeeperTestSuite) SetupTest() {
suite.ctx = suite.app.BaseApp.NewContext(checkTx, abci.Header{Height: 1, ChainID: "3", Time: time.Now().UTC()})
suite.querier = keeper.NewQuerier(suite.app.EvmKeeper)
suite.address = ethcmn.HexToAddress(addrHex)
balance := sdk.NewCoins(sdk.NewCoin(ethermint.DenomDefault, sdk.NewInt(0)))
acc := &ethermint.EthAccount{
BaseAccount: auth.NewBaseAccount(sdk.AccAddress(suite.address.Bytes()), balance, nil, 0, 0),
CodeHash: ethcrypto.Keccak256(nil),
}
suite.app.AccountKeeper.SetAccount(suite.ctx, acc)
}
func TestKeeperTestSuite(t *testing.T) {
+5
View File
@@ -52,6 +52,11 @@ func (k *Keeper) SetLogs(ctx sdk.Context, hash ethcmn.Hash, logs []*ethtypes.Log
return k.CommitStateDB.WithContext(ctx).SetLogs(hash, logs)
}
// DeleteLogs calls CommitStateDB.DeleteLogs using the passed in context
func (k *Keeper) DeleteLogs(ctx sdk.Context, hash ethcmn.Hash) {
k.CommitStateDB.WithContext(ctx).DeleteLogs(hash)
}
// AddLog calls CommitStateDB.AddLog using the passed in context
func (k *Keeper) AddLog(ctx sdk.Context, log *ethtypes.Log) {
k.CommitStateDB.WithContext(ctx).AddLog(log)
+288 -79
View File
@@ -1,6 +1,7 @@
package keeper_test
import (
"fmt"
"math/big"
sdk "github.com/cosmos/cosmos-sdk/types"
@@ -11,6 +12,7 @@ import (
"github.com/cosmos/ethermint/crypto"
ethermint "github.com/cosmos/ethermint/types"
"github.com/cosmos/ethermint/x/evm/types"
)
func (suite *KeeperTestSuite) TestBloomFilter() {
@@ -67,7 +69,7 @@ func (suite *KeeperTestSuite) TestBloomFilter() {
}
}
func (suite *KeeperTestSuite) TestStateDBBalance() {
func (suite *KeeperTestSuite) TestStateDB_Balance() {
testCase := []struct {
name string
malleate func()
@@ -94,19 +96,11 @@ func (suite *KeeperTestSuite) TestStateDBBalance() {
},
big.NewInt(200),
},
{
"sub more than balance",
func() {
suite.app.EvmKeeper.SubBalance(suite.ctx, suite.address, big.NewInt(300))
},
big.NewInt(-100),
},
}
for _, tc := range testCase {
tc.malleate()
suite.Require().Equal(tc.balance, suite.app.EvmKeeper.GetBalance(suite.ctx, suite.address), tc.name)
}
}
@@ -116,26 +110,90 @@ func (suite *KeeperTestSuite) TestStateDBNonce() {
suite.Require().Equal(nonce, suite.app.EvmKeeper.GetNonce(suite.ctx, suite.address))
}
func (suite *KeeperTestSuite) TestStateDBState() {
func (suite *KeeperTestSuite) TestStateDB_Error() {
nonce := suite.app.EvmKeeper.GetNonce(suite.ctx, ethcmn.Address{})
suite.Require().Equal(0, int(nonce))
suite.Require().Error(suite.app.EvmKeeper.Error(suite.ctx))
}
func (suite *KeeperTestSuite) TestStateDB_Database() {
suite.Require().Nil(suite.app.EvmKeeper.Database(suite.ctx))
}
func (suite *KeeperTestSuite) TestStateDB_State() {
key := ethcmn.BytesToHash([]byte("foo"))
val := ethcmn.BytesToHash([]byte("bar"))
suite.app.EvmKeeper.SetState(suite.ctx, suite.address, key, val)
suite.Require().Equal(val, suite.app.EvmKeeper.GetState(suite.ctx, suite.address, key))
testCase := []struct {
name string
address ethcmn.Address
key ethcmn.Hash
value ethcmn.Hash
}{
{
"found state",
suite.address,
ethcmn.BytesToHash([]byte("foo")),
ethcmn.BytesToHash([]byte("bar")),
},
{
"state not found",
suite.address,
ethcmn.BytesToHash([]byte("key")),
ethcmn.Hash{},
},
{
"object not found",
ethcmn.Address{},
ethcmn.BytesToHash([]byte("foo")),
ethcmn.Hash{},
},
}
for _, tc := range testCase {
value := suite.app.EvmKeeper.GetState(suite.ctx, tc.address, tc.key)
suite.Require().Equal(tc.value, value, tc.name)
}
}
func (suite *KeeperTestSuite) TestStateDBCode() {
code := []byte("foobar")
func (suite *KeeperTestSuite) TestStateDB_Code() {
testCase := []struct {
name string
address ethcmn.Address
code []byte
malleate func()
}{
{
"no stored code for state object",
suite.address,
nil,
func() {},
},
{
"existing address",
suite.address,
[]byte("code"),
func() {
suite.app.EvmKeeper.SetCode(suite.ctx, suite.address, []byte("code"))
},
},
{
"state object not found",
ethcmn.Address{},
nil,
func() {},
},
}
suite.app.EvmKeeper.SetCode(suite.ctx, suite.address, code)
for _, tc := range testCase {
tc.malleate()
suite.Require().Equal(code, suite.app.EvmKeeper.GetCode(suite.ctx, suite.address))
codelen := len(code)
suite.Require().Equal(codelen, suite.app.EvmKeeper.GetCodeSize(suite.ctx, suite.address))
suite.Require().Equal(tc.code, suite.app.EvmKeeper.GetCode(suite.ctx, tc.address), tc.name)
suite.Require().Equal(len(tc.code), suite.app.EvmKeeper.GetCodeSize(suite.ctx, tc.address), tc.name)
}
}
func (suite *KeeperTestSuite) TestStateDBLogs() {
func (suite *KeeperTestSuite) TestStateDB_Logs() {
testCase := []struct {
name string
log ethtypes.Log
@@ -165,6 +223,13 @@ func (suite *KeeperTestSuite) TestStateDBLogs() {
dbLogs, err := suite.app.EvmKeeper.GetLogs(suite.ctx, hash)
suite.Require().NoError(err, tc.name)
suite.Require().Equal(logs, dbLogs, tc.name)
suite.app.EvmKeeper.DeleteLogs(suite.ctx, hash)
dbLogs, err = suite.app.EvmKeeper.GetLogs(suite.ctx, hash)
suite.Require().NoError(err, tc.name)
suite.Require().Empty(dbLogs, tc.name)
suite.app.EvmKeeper.AddLog(suite.ctx, &tc.log)
suite.Require().Equal(logs, suite.app.EvmKeeper.AllLogs(suite.ctx), tc.name)
//resets state but checking to see if storekey still persists.
@@ -174,72 +239,122 @@ func (suite *KeeperTestSuite) TestStateDBLogs() {
}
}
func (suite *KeeperTestSuite) TestStateDBPreimage() {
func (suite *KeeperTestSuite) TestStateDB_Preimage() {
hash := ethcmn.BytesToHash([]byte("hash"))
preimage := []byte("preimage")
suite.app.EvmKeeper.AddPreimage(suite.ctx, hash, preimage)
suite.Require().Equal(preimage, suite.app.EvmKeeper.Preimages(suite.ctx)[hash])
}
func (suite *KeeperTestSuite) TestStateDBRefund() {
func (suite *KeeperTestSuite) TestStateDB_Refund() {
testCase := []struct {
name string
amount uint64
name string
addAmount uint64
subAmount uint64
expRefund uint64
expPanic bool
}{
{
"refund",
100,
"refund 0",
0, 0, 0,
false,
},
{
"refund positive amount",
100, 0, 100,
false,
},
{
"refund panic",
100, 200, 100,
true,
},
}
for _, tc := range testCase {
suite.app.EvmKeeper.AddRefund(suite.ctx, tc.amount)
suite.Require().Equal(tc.amount, suite.app.EvmKeeper.GetRefund(suite.ctx), tc.name)
suite.Run(tc.name, func() {
suite.SetupTest() // reset
suite.app.EvmKeeper.SubRefund(suite.ctx, tc.amount)
suite.Require().Equal(uint64(0), suite.app.EvmKeeper.GetRefund(suite.ctx), tc.name)
suite.app.EvmKeeper.AddRefund(suite.ctx, tc.addAmount)
suite.Require().Equal(tc.addAmount, suite.app.EvmKeeper.GetRefund(suite.ctx))
if tc.expPanic {
suite.Panics(func() {
suite.app.EvmKeeper.SubRefund(suite.ctx, tc.subAmount)
})
} else {
suite.app.EvmKeeper.SubRefund(suite.ctx, tc.subAmount)
suite.Require().Equal(tc.expRefund, suite.app.EvmKeeper.GetRefund(suite.ctx))
}
})
}
}
func (suite *KeeperTestSuite) TestStateDBCreateAcct() {
suite.app.EvmKeeper.CreateAccount(suite.ctx, suite.address)
suite.Require().True(suite.app.EvmKeeper.Exist(suite.ctx, suite.address))
func (suite *KeeperTestSuite) TestStateDB_CreateAccount() {
prevBalance := big.NewInt(12)
value := big.NewInt(100)
suite.app.EvmKeeper.AddBalance(suite.ctx, suite.address, value)
testCase := []struct {
name string
address ethcmn.Address
malleate func()
}{
{
"existing account",
suite.address,
func() {
suite.app.EvmKeeper.AddBalance(suite.ctx, suite.address, prevBalance)
},
},
{
"new account",
ethcmn.HexToAddress("0x756F45E3FA69347A9A973A725E3C98bC4db0b4c1"),
func() {
prevBalance = big.NewInt(0)
},
},
}
suite.app.EvmKeeper.CreateAccount(suite.ctx, suite.address)
suite.Require().Equal(value, suite.app.EvmKeeper.GetBalance(suite.ctx, suite.address))
for _, tc := range testCase {
suite.Run(tc.name, func() {
suite.SetupTest() // reset
tc.malleate()
suite.app.EvmKeeper.CreateAccount(suite.ctx, tc.address)
suite.Require().True(suite.app.EvmKeeper.Exist(suite.ctx, tc.address))
suite.Require().Equal(prevBalance, suite.app.EvmKeeper.GetBalance(suite.ctx, tc.address))
})
}
}
func (suite *KeeperTestSuite) TestStateDBClearStateOjb() {
func (suite *KeeperTestSuite) TestStateDB_ClearStateObj() {
priv, err := crypto.GenerateKey()
suite.Require().NoError(err)
suite.app.EvmKeeper.CreateAccount(suite.ctx, suite.address)
suite.Require().True(suite.app.EvmKeeper.Exist(suite.ctx, suite.address))
addr := ethcrypto.PubkeyToAddress(priv.ToECDSA().PublicKey)
suite.app.EvmKeeper.CreateAccount(suite.ctx, addr)
suite.Require().True(suite.app.EvmKeeper.Exist(suite.ctx, addr))
suite.app.EvmKeeper.ClearStateObjects(suite.ctx)
suite.Require().False(suite.app.EvmKeeper.Exist(suite.ctx, suite.address))
suite.Require().False(suite.app.EvmKeeper.Exist(suite.ctx, addr))
}
func (suite *KeeperTestSuite) TestStateDBReset() {
hash := ethcmn.BytesToHash([]byte("hash"))
suite.app.EvmKeeper.CreateAccount(suite.ctx, suite.address)
suite.Require().True(suite.app.EvmKeeper.Exist(suite.ctx, suite.address))
err := suite.app.EvmKeeper.Reset(suite.ctx, hash)
func (suite *KeeperTestSuite) TestStateDB_Reset() {
priv, err := crypto.GenerateKey()
suite.Require().NoError(err)
suite.Require().False(suite.app.EvmKeeper.Exist(suite.ctx, suite.address))
addr := ethcrypto.PubkeyToAddress(priv.ToECDSA().PublicKey)
suite.app.EvmKeeper.CreateAccount(suite.ctx, addr)
suite.Require().True(suite.app.EvmKeeper.Exist(suite.ctx, addr))
err = suite.app.EvmKeeper.Reset(suite.ctx, ethcmn.BytesToHash(nil))
suite.Require().NoError(err)
suite.Require().False(suite.app.EvmKeeper.Exist(suite.ctx, addr))
}
func (suite *KeeperTestSuite) TestStateDBUpdateAcct() {
}
func (suite *KeeperTestSuite) TestSuiteDBPrepare() {
func (suite *KeeperTestSuite) TestSuiteDB_Prepare() {
thash := ethcmn.BytesToHash([]byte("thash"))
bhash := ethcmn.BytesToHash([]byte("bhash"))
txi := 1
@@ -248,24 +363,49 @@ func (suite *KeeperTestSuite) TestSuiteDBPrepare() {
suite.Require().Equal(txi, suite.app.EvmKeeper.TxIndex(suite.ctx))
suite.Require().Equal(bhash, suite.app.EvmKeeper.BlockHash(suite.ctx))
}
func (suite *KeeperTestSuite) TestSuiteDBCopyState() {
copyDB := suite.app.EvmKeeper.Copy(suite.ctx)
suite.Require().Equal(suite.app.EvmKeeper.Exist(suite.ctx, suite.address), copyDB.Exist(suite.address))
func (suite *KeeperTestSuite) TestSuiteDB_CopyState() {
testCase := []struct {
name string
log ethtypes.Log
}{
{
"copy state",
ethtypes.Log{
Address: suite.address,
Topics: []ethcmn.Hash{ethcmn.BytesToHash([]byte("topic"))},
Data: []byte("data"),
BlockNumber: 1,
TxHash: ethcmn.Hash{},
TxIndex: 1,
BlockHash: ethcmn.Hash{},
Index: 1,
Removed: false,
},
},
}
for _, tc := range testCase {
hash := ethcmn.BytesToHash([]byte("hash"))
logs := []*ethtypes.Log{&tc.log}
err := suite.app.EvmKeeper.SetLogs(suite.ctx, hash, logs)
suite.Require().NoError(err, tc.name)
copyDB := suite.app.EvmKeeper.Copy(suite.ctx)
suite.Require().Equal(suite.app.EvmKeeper.Exist(suite.ctx, suite.address), copyDB.Exist(suite.address), tc.name)
}
}
func (suite *KeeperTestSuite) TestSuiteDBEmpty() {
func (suite *KeeperTestSuite) TestSuiteDB_Empty() {
suite.Require().True(suite.app.EvmKeeper.Empty(suite.ctx, suite.address))
suite.app.EvmKeeper.SetBalance(suite.ctx, suite.address, big.NewInt(100))
suite.Require().False(suite.app.EvmKeeper.Empty(suite.ctx, suite.address))
}
func (suite *KeeperTestSuite) TestSuiteDBSuicide() {
func (suite *KeeperTestSuite) TestSuiteDB_Suicide() {
testCase := []struct {
name string
amount *big.Int
@@ -316,7 +456,6 @@ func (suite *KeeperTestSuite) TestSuiteDBSuicide() {
}
func (suite *KeeperTestSuite) TestCommitStateDB_Commit() {
suite.app.EvmKeeper.AddBalance(suite.ctx, suite.address, big.NewInt(100))
testCase := []struct {
name string
malleate func()
@@ -338,13 +477,6 @@ func (suite *KeeperTestSuite) TestCommitStateDB_Commit() {
},
false, true,
},
{
"faled to update state object",
func() {
suite.app.EvmKeeper.SubBalance(suite.ctx, suite.address, big.NewInt(10))
},
false, false,
},
}
for _, tc := range testCase {
@@ -374,7 +506,6 @@ func (suite *KeeperTestSuite) TestCommitStateDB_Commit() {
}
func (suite *KeeperTestSuite) TestCommitStateDB_Finalize() {
suite.app.EvmKeeper.AddBalance(suite.ctx, suite.address, big.NewInt(100))
testCase := []struct {
name string
malleate func()
@@ -403,13 +534,6 @@ func (suite *KeeperTestSuite) TestCommitStateDB_Finalize() {
},
false, true,
},
{
"faled to update state object",
func() {
suite.app.EvmKeeper.SubBalance(suite.ctx, suite.address, big.NewInt(10))
},
false, false,
},
}
for _, tc := range testCase {
@@ -419,6 +543,8 @@ func (suite *KeeperTestSuite) TestCommitStateDB_Finalize() {
if !tc.expPass {
suite.Require().Error(err, tc.name)
hash := suite.app.EvmKeeper.GetCommittedState(suite.ctx, suite.address, ethcmn.BytesToHash([]byte("key")))
suite.Require().NotEqual(ethcmn.Hash{}, hash, tc.name)
continue
}
@@ -433,3 +559,86 @@ func (suite *KeeperTestSuite) TestCommitStateDB_Finalize() {
suite.Require().NotNil(acc, tc.name)
}
}
func (suite *KeeperTestSuite) TestCommitStateDB_GetCommittedState() {
hash := suite.app.EvmKeeper.GetCommittedState(suite.ctx, ethcmn.Address{}, ethcmn.BytesToHash([]byte("key")))
suite.Require().Equal(ethcmn.Hash{}, hash)
}
func (suite *KeeperTestSuite) TestCommitStateDB_Snapshot() {
id := suite.app.EvmKeeper.Snapshot(suite.ctx)
suite.Require().NotPanics(func() {
suite.app.EvmKeeper.RevertToSnapshot(suite.ctx, id)
})
suite.Require().Panics(func() {
suite.app.EvmKeeper.RevertToSnapshot(suite.ctx, -1)
}, "invalid revision should panic")
}
func (suite *KeeperTestSuite) TestCommitStateDB_ForEachStorage() {
var storage types.Storage
testCase := []struct {
name string
malleate func()
callback func(key, value ethcmn.Hash) (stop bool)
expValues []ethcmn.Hash
}{
{
"aggregate state",
func() {
for i := 0; i < 5; i++ {
suite.app.EvmKeeper.SetState(suite.ctx, suite.address, ethcmn.BytesToHash([]byte(fmt.Sprintf("key%d", i))), ethcmn.BytesToHash([]byte(fmt.Sprintf("value%d", i))))
}
},
func(key, value ethcmn.Hash) bool {
storage = append(storage, types.NewState(key, value))
return false
},
[]ethcmn.Hash{
ethcmn.BytesToHash([]byte("value0")),
ethcmn.BytesToHash([]byte("value1")),
ethcmn.BytesToHash([]byte("value2")),
ethcmn.BytesToHash([]byte("value3")),
ethcmn.BytesToHash([]byte("value4")),
},
},
{
"filter state",
func() {
suite.app.EvmKeeper.SetState(suite.ctx, suite.address, ethcmn.BytesToHash([]byte("key")), ethcmn.BytesToHash([]byte("value")))
suite.app.EvmKeeper.SetState(suite.ctx, suite.address, ethcmn.BytesToHash([]byte("filterkey")), ethcmn.BytesToHash([]byte("filtervalue")))
},
func(key, value ethcmn.Hash) bool {
if value == ethcmn.BytesToHash([]byte("filtervalue")) {
storage = append(storage, types.NewState(key, value))
return true
}
return false
},
[]ethcmn.Hash{
ethcmn.BytesToHash([]byte("filtervalue")),
},
},
}
for _, tc := range testCase {
suite.Run(tc.name, func() {
suite.SetupTest() // reset
tc.malleate()
suite.app.EvmKeeper.Finalise(suite.ctx, false)
err := suite.app.EvmKeeper.ForEachStorage(suite.ctx, suite.address, tc.callback)
suite.Require().NoError(err)
suite.Require().Equal(len(tc.expValues), len(storage), fmt.Sprintf("Expected values:\n%v\nStorage Values\n%v", tc.expValues, storage))
vals := make([]ethcmn.Hash, len(storage))
for i := range storage {
vals[i] = storage[i].Value
}
suite.Require().ElementsMatch(tc.expValues, vals)
})
storage = types.Storage{}
}
}
+9 -9
View File
@@ -35,14 +35,14 @@ func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) {
}
// DefaultGenesis is json default structure
func (AppModuleBasic) DefaultGenesis(cdc codec.JSONMarshaler) json.RawMessage {
return cdc.MustMarshalJSON(types.DefaultGenesisState())
func (AppModuleBasic) DefaultGenesis() json.RawMessage {
return types.ModuleCdc.MustMarshalJSON(types.DefaultGenesisState())
}
// ValidateGenesis is the validation check of the Genesis
func (AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, bz json.RawMessage) error {
func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error {
var genesisState types.GenesisState
err := cdc.UnmarshalJSON(bz, &genesisState)
err := types.ModuleCdc.UnmarshalJSON(bz, &genesisState)
if err != nil {
return err
}
@@ -62,7 +62,7 @@ func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command {
// GetTxCmd Gets the root tx command of this module
func (AppModuleBasic) GetTxCmd(cdc *codec.Codec) *cobra.Command {
return cli.GetTxCmd(types.ModuleName, cdc)
return cli.GetTxCmd(cdc)
}
//____________________________________________________________________________
@@ -122,14 +122,14 @@ func (am AppModule) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) []abci.V
}
// InitGenesis instantiates the genesis state
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate {
func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate {
var genesisState types.GenesisState
cdc.MustUnmarshalJSON(data, &genesisState)
types.ModuleCdc.MustUnmarshalJSON(data, &genesisState)
return InitGenesis(ctx, am.keeper, genesisState)
}
// ExportGenesis exports the genesis state to be used by daemon
func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONMarshaler) json.RawMessage {
func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage {
gs := ExportGenesis(ctx, am.keeper, am.ak)
return cdc.MustMarshalJSON(gs)
return types.ModuleCdc.MustMarshalJSON(gs)
}
+1 -1
View File
@@ -25,7 +25,7 @@ var testJSON = `{
func (suite *EvmTestSuite) TestInitGenesis() {
am := evm.NewAppModule(suite.app.EvmKeeper, suite.app.AccountKeeper)
in := json.RawMessage([]byte(testJSON))
_ = am.InitGenesis(suite.ctx, suite.codec, in)
_ = am.InitGenesis(suite.ctx, in)
testAddr := common.HexToAddress("0x2cc7fdf9fde6746731d7f11979609d455c2c197a")
-6
View File
@@ -13,9 +13,3 @@ type AccountKeeper interface {
SetAccount(ctx sdk.Context, account authexported.Account)
RemoveAccount(ctx sdk.Context, account authexported.Account)
}
// BankKeeper defines the expected interface needed to retrieve account balances.
type BankKeeper interface {
GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin
SetBalance(ctx sdk.Context, addr sdk.AccAddress, balance sdk.Coin) error
}
+12 -17
View File
@@ -14,14 +14,12 @@ import (
"github.com/cosmos/cosmos-sdk/store"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/bank"
"github.com/cosmos/cosmos-sdk/x/params"
ethcmn "github.com/ethereum/go-ethereum/common"
ethtypes "github.com/ethereum/go-ethereum/core/types"
ethcrypto "github.com/ethereum/go-ethereum/crypto"
"github.com/cosmos/ethermint/codec"
"github.com/cosmos/ethermint/crypto"
ethermint "github.com/cosmos/ethermint/types"
)
@@ -35,18 +33,17 @@ type JournalTestSuite struct {
stateDB *CommitStateDB
}
func newTestCodec() *codec.Codec {
func newTestCodec() *sdkcodec.Codec {
cdc := sdkcodec.New()
RegisterCodec(cdc)
sdk.RegisterCodec(cdc)
crypto.RegisterCodec(cdc)
sdkcodec.RegisterCrypto(cdc)
auth.RegisterCodec(cdc)
ethermint.RegisterCodec(cdc)
appCodec := codec.NewAppCodec(cdc)
return appCodec
return cdc
}
func (suite *JournalTestSuite) SetupTest() {
@@ -58,13 +55,14 @@ func (suite *JournalTestSuite) SetupTest() {
suite.address = ethcmn.BytesToAddress(privkey.PubKey().Address().Bytes())
suite.journal = newJournal()
balance := sdk.NewCoins(sdk.NewCoin(ethermint.DenomDefault, sdk.NewInt(100)))
acc := &ethermint.EthAccount{
BaseAccount: auth.NewBaseAccount(sdk.AccAddress(suite.address.Bytes()), nil, 0, 0),
BaseAccount: auth.NewBaseAccount(sdk.AccAddress(suite.address.Bytes()), balance, nil, 0, 0),
CodeHash: ethcrypto.Keccak256(nil),
}
suite.stateDB.accountKeeper.SetAccount(suite.ctx, acc)
suite.stateDB.bankKeeper.SetBalance(suite.ctx, sdk.AccAddress(suite.address.Bytes()), sdk.NewCoin(ethermint.DenomDefault, sdk.NewInt(100)))
// suite.stateDB.bankKeeper.SetBalance(suite.ctx, sdk.AccAddress(suite.address.Bytes()), balance)
suite.stateDB.SetLogs(ethcmn.BytesToHash([]byte("txhash")), []*ethtypes.Log{
{
Address: suite.address,
@@ -97,7 +95,7 @@ func (suite *JournalTestSuite) SetupTest() {
// to maintain consistency with the Geth implementation.
func (suite *JournalTestSuite) setup() {
authKey := sdk.NewKVStoreKey(auth.StoreKey)
bankKey := sdk.NewKVStoreKey(bank.StoreKey)
// bankKey := sdk.NewKVStoreKey(bank.StoreKey)
storeKey := sdk.NewKVStoreKey(StoreKey)
db := tmdb.NewDB("state", tmdb.GoLevelDBBackend, "temp")
@@ -107,26 +105,24 @@ func (suite *JournalTestSuite) setup() {
cms := store.NewCommitMultiStore(db)
cms.MountStoreWithDB(authKey, sdk.StoreTypeIAVL, db)
cms.MountStoreWithDB(bankKey, sdk.StoreTypeIAVL, db)
// cms.MountStoreWithDB(bankKey, sdk.StoreTypeIAVL, db)
cms.MountStoreWithDB(storeKey, sdk.StoreTypeIAVL, db)
err := cms.LoadLatestVersion()
suite.Require().NoError(err)
appCodec := newTestCodec()
cdc := newTestCodec()
keyParams := sdk.NewKVStoreKey(params.StoreKey)
tkeyParams := sdk.NewTransientStoreKey(params.TStoreKey)
paramsKeeper := params.NewKeeper(appCodec, keyParams, tkeyParams)
paramsKeeper := params.NewKeeper(cdc, keyParams, tkeyParams)
authSubspace := paramsKeeper.Subspace(auth.DefaultParamspace)
bankSubspace := paramsKeeper.Subspace(bank.DefaultParamspace)
ak := auth.NewAccountKeeper(appCodec, authKey, authSubspace, ethermint.ProtoAccount)
bk := bank.NewBaseKeeper(appCodec, bankKey, ak, bankSubspace, nil)
ak := auth.NewAccountKeeper(cdc, authKey, authSubspace, ethermint.ProtoAccount)
suite.ctx = sdk.NewContext(cms, abci.Header{ChainID: "8"}, false, tmlog.NewNopLogger())
suite.stateDB = NewCommitStateDB(suite.ctx, storeKey, ak, bk).WithContext(suite.ctx)
suite.stateDB = NewCommitStateDB(suite.ctx, storeKey, ak).WithContext(suite.ctx)
}
func TestJournalTestSuite(t *testing.T) {
@@ -149,7 +145,6 @@ func (suite *JournalTestSuite) TestJournal_append_revert() {
resetObjectChange{
prev: &stateObject{
address: suite.address,
balance: sdk.OneInt(),
},
},
},
+2 -2
View File
@@ -46,7 +46,7 @@ type QueryResBlockNumber struct {
}
func (q QueryResBlockNumber) String() string {
return string(q.Number)
return fmt.Sprint(q.Number)
}
// QueryResStorage is response type for storage query
@@ -73,7 +73,7 @@ type QueryResNonce struct {
}
func (q QueryResNonce) String() string {
return string(q.Nonce)
return fmt.Sprint(q.Nonce)
}
// QueryETHLogs is response type for tx logs query
+14 -12
View File
@@ -65,7 +65,6 @@ type stateObject struct {
dbErr error
stateDB *CommitStateDB
account *types.EthAccount
balance sdk.Int
keyToOriginStorageIndex map[ethcmn.Hash]int
keyToDirtyStorageIndex map[ethcmn.Hash]int
@@ -81,7 +80,8 @@ type stateObject struct {
deleted bool
}
func newStateObject(db *CommitStateDB, accProto authexported.Account, balance sdk.Int) *stateObject {
func newStateObject(db *CommitStateDB, accProto authexported.Account) *stateObject {
// func newStateObject(db *CommitStateDB, accProto authexported.Account, balance sdk.Int) *stateObject {
ethermintAccount, ok := accProto.(*types.EthAccount)
if !ok {
panic(fmt.Sprintf("invalid account type for state object: %T", accProto))
@@ -95,8 +95,7 @@ func newStateObject(db *CommitStateDB, accProto authexported.Account, balance sd
return &stateObject{
stateDB: db,
account: ethermintAccount,
balance: balance,
address: ethcmn.BytesToAddress(ethermintAccount.GetAddress().Bytes()),
address: ethermintAccount.EthAddress(),
originStorage: Storage{},
dirtyStorage: Storage{},
keyToOriginStorageIndex: make(map[ethcmn.Hash]int),
@@ -177,7 +176,8 @@ func (so *stateObject) AddBalance(amount *big.Int) {
return
}
newBalance := so.balance.Add(amt)
// newBalance := so.balance.Add(amt)
newBalance := so.account.GetCoins().AmountOf(types.DenomDefault).Add(amt)
so.SetBalance(newBalance.BigInt())
}
@@ -188,7 +188,7 @@ func (so *stateObject) SubBalance(amount *big.Int) {
if amt.IsZero() {
return
}
newBalance := so.balance.Sub(amt)
newBalance := so.account.GetCoins().AmountOf(types.DenomDefault).Sub(amt)
so.SetBalance(newBalance.BigInt())
}
@@ -198,14 +198,14 @@ func (so *stateObject) SetBalance(amount *big.Int) {
so.stateDB.journal.append(balanceChange{
account: &so.address,
prev: so.balance,
prev: so.account.GetCoins().AmountOf(types.DenomDefault),
})
so.setBalance(amt)
}
func (so *stateObject) setBalance(amount sdk.Int) {
so.balance = amount
so.account.SetBalance(amount)
}
// SetNonce sets the state object's nonce (i.e sequence number of the account).
@@ -236,7 +236,8 @@ func (so *stateObject) markSuicided() {
so.suicided = true
}
// commitState commits all dirty storage to a KVStore.
// commitState commits all dirty storage to a KVStore and resets
// the dirty storage slice to the empty state.
func (so *stateObject) commitState() {
ctx := so.stateDB.ctx
store := prefix.NewStore(ctx.KVStore(so.stateDB.storeKey), AddressStoragePrefix(so.Address()))
@@ -291,7 +292,7 @@ func (so stateObject) Address() ethcmn.Address {
// Balance returns the state object's current balance.
func (so *stateObject) Balance() *big.Int {
balance := so.balance.BigInt()
balance := so.account.Balance().BigInt()
if balance == nil {
return zeroBalance
}
@@ -388,7 +389,7 @@ func (so *stateObject) GetCommittedState(_ ethstate.Database, key ethcmn.Hash) e
func (so *stateObject) ReturnGas(gas *big.Int) {}
func (so *stateObject) deepCopy(db *CommitStateDB) *stateObject {
newStateObj := newStateObject(db, so.account, so.balance)
newStateObj := newStateObject(db, so.account)
newStateObj.code = so.code
newStateObj.dirtyStorage = so.dirtyStorage.Copy()
@@ -402,10 +403,11 @@ func (so *stateObject) deepCopy(db *CommitStateDB) *stateObject {
// empty returns whether the account is considered empty.
func (so *stateObject) empty() bool {
balace := so.account.Balance()
return so.account == nil ||
(so.account != nil &&
so.account.Sequence == 0 &&
(so.balance.BigInt() == nil || so.balance.IsZero()) &&
(balace.BigInt() == nil || balace.IsZero()) &&
bytes.Equal(so.account.CodeHash, emptyCodeHash))
}
+1 -1
View File
@@ -108,7 +108,7 @@ func (st StateTransition) TransitionDb(ctx sdk.Context) (*ExecutionResult, error
return nil, errors.New("gas price cannot be nil")
}
evm := st.newEVM(ctx, csdb, gasLimit, gasPrice.BigInt())
evm := st.newEVM(ctx, csdb, gasLimit, gasPrice.Int)
var (
ret []byte
+4 -20
View File
@@ -18,7 +18,9 @@ func (suite *StateDBTestSuite) TestTransitionDb() {
addr := sdk.AccAddress(suite.address.Bytes())
balance := sdk.NewCoin(ethermint.DenomDefault, sdk.NewInt(5000))
suite.app.BankKeeper.SetBalance(suite.ctx, addr, balance)
acc := suite.app.AccountKeeper.GetAccount(suite.ctx, addr)
_ = acc.SetCoins(sdk.NewCoins(balance))
suite.app.AccountKeeper.SetAccount(suite.ctx, acc)
priv, err := crypto.GenerateKey()
suite.Require().NoError(err)
@@ -92,7 +94,7 @@ func (suite *StateDBTestSuite) TestTransitionDb() {
Price: big.NewInt(10),
GasLimit: 11,
Recipient: &recipient,
Amount: big.NewInt(4951),
Amount: big.NewInt(500000),
Payload: []byte("data"),
ChainID: big.NewInt(1),
Csdb: suite.stateDB,
@@ -102,24 +104,6 @@ func (suite *StateDBTestSuite) TestTransitionDb() {
},
false,
},
{
"failed to Finalize",
func() {},
types.StateTransition{
AccountNonce: 123,
Price: big.NewInt(10),
GasLimit: 11,
Recipient: &recipient,
Amount: big.NewInt(-5000),
Payload: []byte("data"),
ChainID: big.NewInt(1),
Csdb: suite.stateDB,
TxHash: &ethcmn.Hash{},
Sender: suite.address,
Simulate: false,
},
false,
},
{
"nil gas price",
func() {
+22 -14
View File
@@ -43,7 +43,6 @@ type CommitStateDB struct {
storeKey sdk.StoreKey
accountKeeper AccountKeeper
bankKeeper BankKeeper
// array that hold 'live' objects, which will get modified while processing a
// state transition
@@ -87,13 +86,12 @@ type CommitStateDB struct {
// CONTRACT: Stores used for state must be cache-wrapped as the ordering of the
// key/value space matters in determining the merkle root.
func NewCommitStateDB(
ctx sdk.Context, storeKey sdk.StoreKey, ak AccountKeeper, bk BankKeeper,
ctx sdk.Context, storeKey sdk.StoreKey, ak AccountKeeper,
) *CommitStateDB {
return &CommitStateDB{
ctx: ctx,
storeKey: storeKey,
accountKeeper: ak,
bankKeeper: bk,
stateObjects: []stateEntry{},
addressToObjectIndex: make(map[ethcmn.Address]int),
stateObjectsDirty: make(map[ethcmn.Address]struct{}),
@@ -484,13 +482,25 @@ func (csdb *CommitStateDB) IntermediateRoot(deleteEmptyObjects bool) (ethcmn.Has
// updateStateObject writes the given state object to the store.
func (csdb *CommitStateDB) updateStateObject(so *stateObject) error {
csdb.accountKeeper.SetAccount(csdb.ctx, so.account)
// NOTE: we don't use sdk.NewCoin here to avoid panic on test importer's genesis
newBalance := sdk.Coin{Denom: emint.DenomDefault, Amount: sdk.NewIntFromBigInt(so.Balance())}
if !newBalance.IsValid() {
return fmt.Errorf("invalid balance %s", newBalance)
}
return csdb.bankKeeper.SetBalance(csdb.ctx, so.account.Address, newBalance)
coins := so.account.GetCoins()
balance := coins.AmountOf(newBalance.Denom)
if balance.IsZero() || !balance.Equal(newBalance.Amount) {
coins = coins.Add(newBalance)
}
if err := so.account.SetCoins(coins); err != nil {
return err
}
csdb.accountKeeper.SetAccount(csdb.ctx, so.account)
// return csdb.bankKeeper.SetBalance(csdb.ctx, so.account.Address, newBalance)
return nil
}
// deleteStateObject removes the given state object from the state store.
@@ -613,12 +623,13 @@ func (csdb *CommitStateDB) UpdateAccounts() {
continue
}
balance := csdb.bankKeeper.GetBalance(csdb.ctx, emintAcc.GetAddress(), emint.DenomDefault)
if stateEntry.stateObject.Balance() != balance.Amount.BigInt() && balance.IsValid() {
stateEntry.stateObject.balance = balance.Amount
balance := sdk.Coin{
Denom: emint.DenomDefault,
Amount: emintAcc.GetCoins().AmountOf(emint.DenomDefault),
}
if stateEntry.stateObject.Nonce() != emintAcc.GetSequence() {
if stateEntry.stateObject.Balance() != balance.Amount.BigInt() && balance.IsValid() ||
stateEntry.stateObject.Nonce() != emintAcc.GetSequence() {
stateEntry.stateObject.account = emintAcc
}
}
@@ -674,7 +685,6 @@ func (csdb *CommitStateDB) Copy() *CommitStateDB {
ctx: csdb.ctx,
storeKey: csdb.storeKey,
accountKeeper: csdb.accountKeeper,
bankKeeper: csdb.bankKeeper,
stateObjects: make([]stateEntry, len(csdb.journal.dirties)),
addressToObjectIndex: make(map[ethcmn.Address]int, len(csdb.journal.dirties)),
stateObjectsDirty: make(map[ethcmn.Address]struct{}, len(csdb.journal.dirties)),
@@ -771,7 +781,7 @@ func (csdb *CommitStateDB) createObject(addr ethcmn.Address) (newObj, prevObj *s
acc := csdb.accountKeeper.NewAccountWithAddress(csdb.ctx, sdk.AccAddress(addr.Bytes()))
newObj = newStateObject(csdb, acc, sdk.ZeroInt())
newObj = newStateObject(csdb, acc)
newObj.setNonce(0) // sets the object to dirty
if prevObj == nil {
@@ -813,10 +823,8 @@ func (csdb *CommitStateDB) getStateObject(addr ethcmn.Address) (stateObject *sta
return nil
}
balance := csdb.bankKeeper.GetBalance(csdb.ctx, acc.GetAddress(), emint.DenomDefault)
// insert the state object into the live set
so := newStateObject(csdb, acc, balance.Amount)
so := newStateObject(csdb, acc)
csdb.setStateObject(so)
return so
+3 -25
View File
@@ -17,7 +17,6 @@ import (
"github.com/cosmos/ethermint/app"
"github.com/cosmos/ethermint/crypto"
ethermint "github.com/cosmos/ethermint/types"
"github.com/cosmos/ethermint/x/evm/keeper"
"github.com/cosmos/ethermint/x/evm/types"
abci "github.com/tendermint/tendermint/abci/types"
@@ -27,7 +26,6 @@ type StateDBTestSuite struct {
suite.Suite
ctx sdk.Context
querier sdk.Querier
app *app.EthermintApp
stateDB *types.CommitStateDB
address ethcmn.Address
@@ -43,15 +41,16 @@ func (suite *StateDBTestSuite) SetupTest() {
suite.app = app.Setup(checkTx)
suite.ctx = suite.app.BaseApp.NewContext(checkTx, abci.Header{Height: 1})
suite.querier = keeper.NewQuerier(suite.app.EvmKeeper)
suite.stateDB = suite.app.EvmKeeper.CommitStateDB.WithContext(suite.ctx)
privkey, err := crypto.GenerateKey()
suite.Require().NoError(err)
suite.address = ethcmn.BytesToAddress(privkey.PubKey().Address().Bytes())
balance := sdk.NewCoins(sdk.NewCoin(ethermint.DenomDefault, sdk.NewInt(0)))
acc := &ethermint.EthAccount{
BaseAccount: auth.NewBaseAccount(sdk.AccAddress(suite.address.Bytes()), nil, 0, 0),
BaseAccount: auth.NewBaseAccount(sdk.AccAddress(suite.address.Bytes()), balance, nil, 0, 0),
CodeHash: ethcrypto.Keccak256(nil),
}
@@ -139,13 +138,6 @@ func (suite *StateDBTestSuite) TestStateDB_Balance() {
},
big.NewInt(200),
},
{
"sub more than balance",
func() {
suite.stateDB.SubBalance(suite.address, big.NewInt(300))
},
big.NewInt(-100),
},
}
for _, tc := range testCase {
@@ -528,13 +520,6 @@ func (suite *StateDBTestSuite) TestCommitStateDB_Commit() {
},
false, true,
},
{
"faled to update state object",
func() {
suite.stateDB.SubBalance(suite.address, big.NewInt(10))
},
false, false,
},
}
for _, tc := range testCase {
@@ -592,13 +577,6 @@ func (suite *StateDBTestSuite) TestCommitStateDB_Finalize() {
},
false, true,
},
{
"faled to update state object",
func() {
suite.stateDB.SubBalance(suite.address, big.NewInt(10))
},
false, false,
},
}
for _, tc := range testCase {
+2 -1
View File
@@ -105,7 +105,8 @@ func TxDecoder(cdc *codec.Codec) sdk.TxDecoder {
// sdk.Tx is an interface. The concrete message types
// are registered by MakeTxCodec
err := cdc.UnmarshalBinaryBare(txBytes, &tx)
// TODO: switch to UnmarshalBinaryBare on SDK v0.40.0
err := cdc.UnmarshalBinaryLengthPrefixed(txBytes, &tx)
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrTxDecode, err.Error())
}