genesis functions cleanup, testing (#318)

This commit is contained in:
noot 2020-05-29 11:50:22 -04:00 committed by GitHub
parent 915a9018d4
commit 4fd9ec3a26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 108 additions and 3 deletions

View File

@ -33,7 +33,7 @@ func ExportGenesis(ctx sdk.Context, k Keeper, ak types.AccountKeeper) GenesisSta
var err error var err error
for _, account := range accounts { for _, account := range accounts {
ethAccount, ok := account.(emint.EthAccount) ethAccount, ok := account.(*emint.EthAccount)
if !ok { if !ok {
continue continue
} }

File diff suppressed because one or more lines are too long

35
x/evm/module_test.go Normal file
View File

@ -0,0 +1,35 @@
package evm_test
import (
"encoding/json"
"github.com/cosmos/ethermint/x/evm"
"github.com/ethereum/go-ethereum/common"
)
var testJSON = `{
"accounts": [
{
"address": "0x00cabdd44664b73cfc3194b9d32eb6c351ef7652",
"balance": 34
},
{
"address": "0x2cc7fdf9fde6746731d7f11979609d455c2c197a",
"balance": 0,
"code": "0x60806040"
}
]
}`
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)
testAddr := common.HexToAddress("0x2cc7fdf9fde6746731d7f11979609d455c2c197a")
res := suite.app.EvmKeeper.CommitStateDB.WithContext(suite.ctx).GetCode(testAddr)
expectedCode := common.FromHex("0x60806040")
suite.Require().Equal(expectedCode, res)
}

View File

@ -7,6 +7,7 @@ import (
"math/big" "math/big"
ethcmn "github.com/ethereum/go-ethereum/common" ethcmn "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
) )
type ( type (
@ -29,7 +30,7 @@ type (
GenesisAccount struct { GenesisAccount struct {
Address ethcmn.Address `json:"address"` Address ethcmn.Address `json:"address"`
Balance *big.Int `json:"balance"` Balance *big.Int `json:"balance"`
Code []byte `json:"code,omitempty"` Code hexutil.Bytes `json:"code,omitempty"`
Storage []GenesisStorage `json:"storage,omitempty"` Storage []GenesisStorage `json:"storage,omitempty"`
} }
) )

View File

@ -63,6 +63,11 @@ func NewMsgEthermint(
} }
} }
func (msg MsgEthermint) String() string {
return fmt.Sprintf("nonce=%d gasPrice=%d gasLimit=%d recipient=%s amount=%d data=0x%x from=%s",
msg.AccountNonce, msg.Price, msg.GasLimit, msg.Recipient, msg.Amount, msg.Payload, msg.From)
}
// Route should return the name of the module // Route should return the name of the module
func (msg MsgEthermint) Route() string { return RouterKey } func (msg MsgEthermint) Route() string { return RouterKey }
@ -166,6 +171,10 @@ func newMsgEthereumTx(
return MsgEthereumTx{Data: txData} return MsgEthereumTx{Data: txData}
} }
func (msg MsgEthereumTx) String() string {
return msg.Data.String()
}
// Route returns the route value of an MsgEthereumTx. // Route returns the route value of an MsgEthereumTx.
func (msg MsgEthereumTx) Route() string { return RouterKey } func (msg MsgEthereumTx) Route() string { return RouterKey }

View File

@ -590,7 +590,7 @@ func (csdb *CommitStateDB) UpdateAccounts() {
currAcc := csdb.accountKeeper.GetAccount(csdb.ctx, sdk.AccAddress(addr.Bytes())) currAcc := csdb.accountKeeper.GetAccount(csdb.ctx, sdk.AccAddress(addr.Bytes()))
emintAcc, ok := currAcc.(*emint.EthAccount) emintAcc, ok := currAcc.(*emint.EthAccount)
if !ok { if !ok {
return continue
} }
balance := csdb.bankKeeper.GetBalance(csdb.ctx, emintAcc.GetAddress(), emint.DenomDefault) balance := csdb.bankKeeper.GetBalance(csdb.ctx, emintAcc.GetAddress(), emint.DenomDefault)

View File

@ -1,6 +1,7 @@
package types package types
import ( import (
"fmt"
"math/big" "math/big"
"github.com/cosmos/ethermint/utils" "github.com/cosmos/ethermint/utils"
@ -46,6 +47,16 @@ type encodableTxData struct {
Hash *ethcmn.Hash `json:"hash" rlp:"-"` Hash *ethcmn.Hash `json:"hash" rlp:"-"`
} }
func (td TxData) String() string {
if td.Recipient != nil {
return fmt.Sprintf("nonce=%d price=%s gasLimit=%d recipient=%s amount=%s data=0x%x v=%s r=%s s=%s",
td.AccountNonce, td.Price, td.GasLimit, td.Recipient.Hex(), td.Amount, td.Payload, td.V, td.R, td.S)
}
return fmt.Sprintf("nonce=%d price=%s gasLimit=%d recipient=nil amount=%s data=0x%x v=%s r=%s s=%s",
td.AccountNonce, td.Price, td.GasLimit, td.Amount, td.Payload, td.V, td.R, td.S)
}
// MarshalAmino defines custom encoding scheme for TxData // MarshalAmino defines custom encoding scheme for TxData
func (td TxData) MarshalAmino() ([]byte, error) { func (td TxData) MarshalAmino() ([]byte, error) {
gasPrice, err := utils.MarshalBigInt(td.Price) gasPrice, err := utils.MarshalBigInt(td.Price)