forked from cerc-io/laconicd-deprecated
bump Cosmos SDK version to v0.38.2 (#183)
* evm: move Keeper and Querier to /keeper package * keeper: update keeper_test.go * fix format * evm: use aliased types * bump SDK version to v0.38.1 * app: updates from new version * errors: switch sdk.Error -> error * errors: switch sdk.Error -> error. Continuation * more fixes * update app/ * update keys and client pkgs * build * fix tests * lint * minor changes * changelog * address @austinbell comments * Fix keyring usage in rpc API and CLI * fix keyring * break line * Misc cleanup (#188) * evm: move Begin and EndBlock to abci.go * evm: use expected keeper interfaces * app: use EthermintApp for integration and unit test setup * evm: remove count type; update codec * go mod verify * evm: rename msgs for consistency * evm: events * minor cleanup * lint * ante: update tests * changelog * nolint * evm: update statedb to create ethermint Account instead of BaseAccount * fix importer test * address @austinabell comments * update README * changelog * evm: update codec * fix event sender * store logs in keeper after transition (#210) * add some comments * begin log handler test * update TransitionCSDB to return ReturnData * use rlp for result data encode/decode * update tests * implement SetBlockLogs * implement GetBlockLogs * test log set/get * update keeper get/set logs to use hash as key * fix test * move logsKey to csdb * attempt to fix test * attempt to fix test * attempt to fix test * lint * lint * lint * save logs after handling msg * update k.Logs * cleanup * remove unused * fix issues * comment out handler test * address comments * lint * fix handler test * address comments * use amino * lint * address comments * merge * fix encoding bug * minor fix * rpc: error handling * rpc: simulate only returns gasConsumed * rpc: error ineffassign * go: bump version to 1.14 and SDK version to latest master * rpc: fix simulation return value * breaking changes from SDK * sdk: breaking changes; build * tests: fixes * minor fix * proto: ethermint types attempt * proto: define EthAccount proto type and extend sdk std.Codec * evm: fix panic on handler test * evm: minor state object changes * cleanup * tests: update test-importer * fix pubkey registration * lint * cleanup * more test checks for importer * minor change * codec fixes * rm init func * fix importer test build * fix marshaling for TxDecoder * use amino codec for evm * fix marshaling for SimulationResponse * use jsonpb for unmarshaling * fix method handler crashed * return err on VerifySig * switch stateObject balance to sdk.Int * fixes to codec and encoding * cleanup * set tmhash -> ethhash in state transition * add tmhash->ethereumhash to csdb.GetLogs * attempt to fix tests * update GetLogs to switch with Has * ante panic * diff changes * update SetLogs * evm/cli: use ethermint codec * use LengthPrefixed for encoding * add check for nil *big.Int * add balance to UpdateAccounts * fix previous balance * fix balance bug * prevent panic on make test-import Co-authored-by: austinabell <austinabell8@gmail.com> Co-authored-by: noot <36753753+noot@users.noreply.github.com> Co-authored-by: noot <elizabethjbinks@gmail.com>
This commit is contained in:
co-authored by
austinabell
noot
noot
parent
2693718662
commit
4d609b2a22
+45
-23
@@ -13,14 +13,17 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdkcodec "github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/store"
|
||||
sdkstore "github.com/cosmos/cosmos-sdk/store/types"
|
||||
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"
|
||||
|
||||
"github.com/cosmos/ethermint/codec"
|
||||
"github.com/cosmos/ethermint/core"
|
||||
emintcrypto "github.com/cosmos/ethermint/crypto"
|
||||
"github.com/cosmos/ethermint/types"
|
||||
evmtypes "github.com/cosmos/ethermint/x/evm/types"
|
||||
|
||||
@@ -46,9 +49,9 @@ var (
|
||||
|
||||
genInvestor = ethcmn.HexToAddress("0x756F45E3FA69347A9A973A725E3C98bC4db0b5a0")
|
||||
|
||||
accKey = sdk.NewKVStoreKey("acc")
|
||||
storageKey = sdk.NewKVStoreKey(evmtypes.StoreKey)
|
||||
codeKey = sdk.NewKVStoreKey(evmtypes.CodeKey)
|
||||
accKey = sdk.NewKVStoreKey(auth.StoreKey)
|
||||
storeKey = sdk.NewKVStoreKey(evmtypes.StoreKey)
|
||||
codeKey = sdk.NewKVStoreKey(evmtypes.CodeKey)
|
||||
|
||||
logger = tmlog.NewNopLogger()
|
||||
|
||||
@@ -64,14 +67,16 @@ func init() {
|
||||
flag.Parse()
|
||||
}
|
||||
|
||||
func newTestCodec() *codec.Codec {
|
||||
cdc := codec.New()
|
||||
func newTestCodec() *sdkcodec.Codec {
|
||||
cdc := sdkcodec.New()
|
||||
|
||||
evmtypes.RegisterCodec(cdc)
|
||||
types.RegisterCodec(cdc)
|
||||
auth.RegisterCodec(cdc)
|
||||
bank.RegisterCodec(cdc)
|
||||
sdk.RegisterCodec(cdc)
|
||||
codec.RegisterCrypto(cdc)
|
||||
emintcrypto.RegisterCodec(cdc)
|
||||
sdkcodec.RegisterCrypto(cdc)
|
||||
|
||||
return cdc
|
||||
}
|
||||
@@ -96,12 +101,13 @@ func trapSignals() {
|
||||
}()
|
||||
}
|
||||
|
||||
func createAndTestGenesis(t *testing.T, cms sdk.CommitMultiStore, ak auth.AccountKeeper) {
|
||||
// nolint: interfacer
|
||||
func createAndTestGenesis(t *testing.T, cms sdk.CommitMultiStore, ak auth.AccountKeeper, bk bank.Keeper) {
|
||||
genBlock := ethcore.DefaultGenesisBlock()
|
||||
ms := cms.CacheMultiStore()
|
||||
ctx := sdk.NewContext(ms, abci.Header{}, false, logger)
|
||||
|
||||
stateDB := evmtypes.NewCommitStateDB(ctx, codeKey, storageKey, ak)
|
||||
stateDB := evmtypes.NewCommitStateDB(ctx, codeKey, storeKey, ak, bk)
|
||||
|
||||
// sort the addresses and insertion of key/value pairs matters
|
||||
genAddrs := make([]string, len(genBlock.Alloc))
|
||||
@@ -145,7 +151,8 @@ func createAndTestGenesis(t *testing.T, cms sdk.CommitMultiStore, ak auth.Accoun
|
||||
// verify account mapper state
|
||||
genAcc := ak.GetAccount(ctx, sdk.AccAddress(genInvestor.Bytes()))
|
||||
require.NotNil(t, genAcc)
|
||||
require.Equal(t, sdk.NewIntFromBigInt(b), genAcc.GetCoins().AmountOf(types.DenomDefault))
|
||||
balance := bk.GetBalance(ctx, genAcc.GetAddress(), types.DenomDefault)
|
||||
require.Equal(t, sdk.NewIntFromBigInt(b), balance.Amount)
|
||||
}
|
||||
|
||||
func TestImportBlocks(t *testing.T) {
|
||||
@@ -165,20 +172,24 @@ func TestImportBlocks(t *testing.T) {
|
||||
defer cleanup()
|
||||
trapSignals()
|
||||
|
||||
// create logger, codec and root multi-store
|
||||
cdc := newTestCodec()
|
||||
appCodec := codec.NewAppCodec(cdc)
|
||||
|
||||
cms := store.NewCommitMultiStore(db)
|
||||
|
||||
// The ParamsKeeper handles parameter storage for the application
|
||||
bankKey := sdk.NewKVStoreKey(bank.StoreKey)
|
||||
keyParams := sdk.NewKVStoreKey(params.StoreKey)
|
||||
tkeyParams := sdk.NewTransientStoreKey(params.TStoreKey)
|
||||
paramsKeeper := params.NewKeeper(cdc, keyParams, tkeyParams, params.DefaultCodespace)
|
||||
paramsKeeper := params.NewKeeper(appCodec, keyParams, tkeyParams)
|
||||
// Set specific supspaces
|
||||
authSubspace := paramsKeeper.Subspace(auth.DefaultParamspace)
|
||||
ak := auth.NewAccountKeeper(cdc, accKey, authSubspace, types.ProtoBaseAccount)
|
||||
bankSubspace := paramsKeeper.Subspace(bank.DefaultParamspace)
|
||||
ak := auth.NewAccountKeeper(appCodec, accKey, authSubspace, types.ProtoAccount)
|
||||
bk := bank.NewBaseKeeper(appCodec, bankKey, ak, bankSubspace, nil)
|
||||
|
||||
// mount stores
|
||||
keys := []*sdk.KVStoreKey{accKey, storageKey, codeKey}
|
||||
keys := []*sdk.KVStoreKey{accKey, bankKey, storeKey, codeKey}
|
||||
for _, key := range keys {
|
||||
cms.MountStoreWithDB(key, sdk.StoreTypeIAVL, nil)
|
||||
}
|
||||
@@ -190,7 +201,7 @@ func TestImportBlocks(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// set and test genesis block
|
||||
createAndTestGenesis(t, cms, ak)
|
||||
createAndTestGenesis(t, cms, ak, bk)
|
||||
|
||||
// open blockchain export file
|
||||
blockchainInput, err := os.Open(flagBlockchain)
|
||||
@@ -233,7 +244,7 @@ func TestImportBlocks(t *testing.T) {
|
||||
ctx := sdk.NewContext(ms, abci.Header{}, false, logger)
|
||||
ctx = ctx.WithBlockHeight(int64(block.NumberU64()))
|
||||
|
||||
stateDB := createStateDB(ctx, ak)
|
||||
stateDB := createStateDB(ctx, ak, bk)
|
||||
|
||||
if chainConfig.DAOForkSupport && chainConfig.DAOForkBlock != nil && chainConfig.DAOForkBlock.Cmp(block.Number()) == 0 {
|
||||
applyDAOHardFork(stateDB)
|
||||
@@ -242,10 +253,11 @@ func TestImportBlocks(t *testing.T) {
|
||||
for i, tx := range block.Transactions() {
|
||||
stateDB.Prepare(tx.Hash(), block.Hash(), i)
|
||||
|
||||
_, _, err = applyTransaction(
|
||||
receipt, gas, err := applyTransaction(
|
||||
chainConfig, chainContext, nil, gp, stateDB, header, tx, usedGas, vmConfig,
|
||||
)
|
||||
require.NoError(t, err, "failed to apply tx at block %d; tx: %X", block.NumberU64(), tx.Hash())
|
||||
require.NoError(t, err, "failed to apply tx at block %d; tx: %X; gas %d; receipt:%v", block.NumberU64(), tx.Hash(), gas, receipt)
|
||||
require.NotNil(t, receipt)
|
||||
}
|
||||
|
||||
// apply mining rewards
|
||||
@@ -266,9 +278,9 @@ func TestImportBlocks(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func createStateDB(ctx sdk.Context, ak auth.AccountKeeper) *evmtypes.CommitStateDB {
|
||||
stateDB := evmtypes.NewCommitStateDB(ctx, codeKey, storageKey, ak)
|
||||
return stateDB
|
||||
// nolint: interfacer
|
||||
func createStateDB(ctx sdk.Context, ak auth.AccountKeeper, bk bank.Keeper) *evmtypes.CommitStateDB {
|
||||
return evmtypes.NewCommitStateDB(ctx, codeKey, storeKey, ak, bk)
|
||||
}
|
||||
|
||||
// accumulateRewards credits the coinbase of the given block with the mining
|
||||
@@ -327,21 +339,29 @@ func applyDAOHardFork(statedb *evmtypes.CommitStateDB) {
|
||||
// indicating the block was invalid.
|
||||
// Function is also pulled from go-ethereum 1.9 because of the incompatible usage
|
||||
// Ref: https://github.com/ethereum/go-ethereum/blob/52f2461774bcb8cdd310f86b4bc501df5b783852/core/state_processor.go#L88
|
||||
func applyTransaction(config *ethparams.ChainConfig, bc ethcore.ChainContext, author *ethcmn.Address, gp *ethcore.GasPool, statedb *evmtypes.CommitStateDB, header *ethtypes.Header, tx *ethtypes.Transaction, usedGas *uint64, cfg ethvm.Config) (*ethtypes.Receipt, uint64, error) {
|
||||
func applyTransaction(
|
||||
config *ethparams.ChainConfig, bc ethcore.ChainContext, author *ethcmn.Address,
|
||||
gp *ethcore.GasPool, statedb *evmtypes.CommitStateDB, header *ethtypes.Header,
|
||||
tx *ethtypes.Transaction, usedGas *uint64, cfg ethvm.Config,
|
||||
) (*ethtypes.Receipt, uint64, error) {
|
||||
msg, err := tx.AsMessage(ethtypes.MakeSigner(config, header.Number))
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
// Create a new context to be used in the EVM environment
|
||||
context := ethcore.NewEVMContext(msg, header, bc, author)
|
||||
|
||||
// Create a new environment which holds all relevant information
|
||||
// about the transaction and calling mechanisms.
|
||||
vmenv := ethvm.NewEVM(context, statedb, config, cfg)
|
||||
|
||||
// Apply the transaction to the current state (included in the env)
|
||||
_, gas, failed, err := ethcore.ApplyMessage(vmenv, msg, gp)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
return nil, gas, err
|
||||
}
|
||||
|
||||
// Update the state with pending changes
|
||||
var intRoot ethcmn.Hash
|
||||
if config.IsByzantium(header.Number) {
|
||||
@@ -362,10 +382,12 @@ func applyTransaction(config *ethparams.ChainConfig, bc ethcore.ChainContext, au
|
||||
receipt := ethtypes.NewReceipt(root, failed, *usedGas)
|
||||
receipt.TxHash = tx.Hash()
|
||||
receipt.GasUsed = gas
|
||||
|
||||
// if the transaction created a contract, store the creation address in the receipt.
|
||||
if msg.To() == nil {
|
||||
receipt.ContractAddress = ethcrypto.CreateAddress(vmenv.Context.Origin, tx.Nonce())
|
||||
}
|
||||
|
||||
// Set the receipt logs and create a bloom for filtering
|
||||
receipt.Logs, err = statedb.GetLogs(tx.Hash())
|
||||
receipt.Bloom = ethtypes.CreateBloom(ethtypes.Receipts{receipt})
|
||||
|
||||
Reference in New Issue
Block a user