all: cleanup imports (#524)

This commit is contained in:
Federico Kunze Küllmer 2021-09-03 20:06:36 +02:00 committed by GitHub
parent 945fa64853
commit c73ce0f812
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
30 changed files with 238 additions and 247 deletions

View File

@ -6,11 +6,10 @@ import (
"crypto/subtle" "crypto/subtle"
"fmt" "fmt"
ethcrypto "github.com/ethereum/go-ethereum/crypto"
"github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/ethereum/go-ethereum/crypto"
tmcrypto "github.com/tendermint/tendermint/crypto" tmcrypto "github.com/tendermint/tendermint/crypto"
) )
@ -43,13 +42,13 @@ var (
// GenerateKey generates a new random private key. It returns an error upon // GenerateKey generates a new random private key. It returns an error upon
// failure. // failure.
func GenerateKey() (*PrivKey, error) { func GenerateKey() (*PrivKey, error) {
priv, err := ethcrypto.GenerateKey() priv, err := crypto.GenerateKey()
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &PrivKey{ return &PrivKey{
Key: ethcrypto.FromECDSA(priv), Key: crypto.FromECDSA(priv),
}, nil }, nil
} }
@ -62,7 +61,7 @@ func (privKey PrivKey) Bytes() []byte {
func (privKey PrivKey) PubKey() cryptotypes.PubKey { func (privKey PrivKey) PubKey() cryptotypes.PubKey {
ecdsaPrivKey := privKey.ToECDSA() ecdsaPrivKey := privKey.ToECDSA()
return &PubKey{ return &PubKey{
Key: ethcrypto.CompressPubkey(&ecdsaPrivKey.PublicKey), Key: crypto.CompressPubkey(&ecdsaPrivKey.PublicKey),
} }
} }
@ -107,17 +106,17 @@ func (privKey *PrivKey) UnmarshalAminoJSON(bz []byte) error {
// provided hash of the message. The produced signature is 65 bytes // provided hash of the message. The produced signature is 65 bytes
// where the last byte contains the recovery ID. // where the last byte contains the recovery ID.
func (privKey PrivKey) Sign(digestBz []byte) ([]byte, error) { func (privKey PrivKey) Sign(digestBz []byte) ([]byte, error) {
if len(digestBz) != ethcrypto.DigestLength { if len(digestBz) != crypto.DigestLength {
digestBz = ethcrypto.Keccak256Hash(digestBz).Bytes() digestBz = crypto.Keccak256Hash(digestBz).Bytes()
} }
return ethcrypto.Sign(digestBz, privKey.ToECDSA()) return crypto.Sign(digestBz, privKey.ToECDSA())
} }
// ToECDSA returns the ECDSA private key as a reference to ecdsa.PrivateKey type. // ToECDSA returns the ECDSA private key as a reference to ecdsa.PrivateKey type.
// The function will panic if the private key is invalid. // The function will panic if the private key is invalid.
func (privKey PrivKey) ToECDSA() *ecdsa.PrivateKey { func (privKey PrivKey) ToECDSA() *ecdsa.PrivateKey {
key, err := ethcrypto.ToECDSA(privKey.Bytes()) key, err := crypto.ToECDSA(privKey.Bytes())
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -135,12 +134,12 @@ var (
// Address returns the address of the ECDSA public key. // Address returns the address of the ECDSA public key.
// The function will panic if the public key is invalid. // The function will panic if the public key is invalid.
func (pubKey PubKey) Address() tmcrypto.Address { func (pubKey PubKey) Address() tmcrypto.Address {
pubk, err := ethcrypto.DecompressPubkey(pubKey.Key) pubk, err := crypto.DecompressPubkey(pubKey.Key)
if err != nil { if err != nil {
panic(err) panic(err)
} }
return tmcrypto.Address(ethcrypto.PubkeyToAddress(*pubk).Bytes()) return tmcrypto.Address(crypto.PubkeyToAddress(*pubk).Bytes())
} }
// Bytes returns the raw bytes of the ECDSA public key. // Bytes returns the raw bytes of the ECDSA public key.
@ -196,11 +195,11 @@ func (pubKey *PubKey) UnmarshalAminoJSON(bz []byte) error {
// //
// CONTRACT: The signature should be in [R || S] format. // CONTRACT: The signature should be in [R || S] format.
func (pubKey PubKey) VerifySignature(msg []byte, sig []byte) bool { func (pubKey PubKey) VerifySignature(msg []byte, sig []byte) bool {
if len(sig) == ethcrypto.SignatureLength { if len(sig) == crypto.SignatureLength {
// remove recovery ID (V) if contained in the signature // remove recovery ID (V) if contained in the signature
sig = sig[:len(sig)-1] sig = sig[:len(sig)-1]
} }
// the signature needs to be in [R || S] format when provided to VerifySignature // the signature needs to be in [R || S] format when provided to VerifySignature
return ethcrypto.VerifySignature(pubKey.Key, ethcrypto.Keccak256Hash(msg).Bytes(), sig) return crypto.VerifySignature(pubKey.Key, crypto.Keccak256Hash(msg).Bytes(), sig)
} }

View File

@ -8,7 +8,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec"
ethcrypto "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto/secp256k1" "github.com/ethereum/go-ethereum/crypto/secp256k1"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
@ -28,12 +28,12 @@ func TestPrivKey(t *testing.T) {
// validate Ethereum address equality // validate Ethereum address equality
addr := privKey.PubKey().Address() addr := privKey.PubKey().Address()
expectedAddr := ethcrypto.PubkeyToAddress(privKey.ToECDSA().PublicKey) expectedAddr := crypto.PubkeyToAddress(privKey.ToECDSA().PublicKey)
require.Equal(t, expectedAddr.Bytes(), addr.Bytes()) require.Equal(t, expectedAddr.Bytes(), addr.Bytes())
// validate we can sign some bytes // validate we can sign some bytes
msg := []byte("hello world") msg := []byte("hello world")
sigHash := ethcrypto.Keccak256Hash(msg) sigHash := crypto.Keccak256Hash(msg)
expectedSig, err := secp256k1.Sign(sigHash.Bytes(), privKey.Bytes()) expectedSig, err := secp256k1.Sign(sigHash.Bytes(), privKey.Bytes())
require.NoError(t, err) require.NoError(t, err)

View File

@ -5,8 +5,8 @@ import (
"github.com/btcsuite/btcutil/hdkeychain" "github.com/btcsuite/btcutil/hdkeychain"
bip39 "github.com/tyler-smith/go-bip39" bip39 "github.com/tyler-smith/go-bip39"
ethaccounts "github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/accounts"
ethcrypto "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/hd"
"github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/crypto/keyring"
@ -59,7 +59,7 @@ func (s ethSecp256k1Algo) Name() hd.PubKeyType {
// Derive derives and returns the eth_secp256k1 private key for the given mnemonic and HD path. // Derive derives and returns the eth_secp256k1 private key for the given mnemonic and HD path.
func (s ethSecp256k1Algo) Derive() hd.DeriveFn { func (s ethSecp256k1Algo) Derive() hd.DeriveFn {
return func(mnemonic string, bip39Passphrase, path string) ([]byte, error) { return func(mnemonic string, bip39Passphrase, path string) ([]byte, error) {
hdpath, err := ethaccounts.ParseDerivationPath(path) hdpath, err := accounts.ParseDerivationPath(path)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -88,7 +88,7 @@ func (s ethSecp256k1Algo) Derive() hd.DeriveFn {
} }
privateKeyECDSA := privateKey.ToECDSA() privateKeyECDSA := privateKey.ToECDSA()
derivedKey := ethcrypto.FromECDSA(privateKeyECDSA) derivedKey := crypto.FromECDSA(privateKeyECDSA)
return derivedKey, nil return derivedKey, nil
} }

View File

@ -29,9 +29,9 @@ add custom logic to process transaction logs.
This ADR proposes to add an `EvmHooks` interface and a method to register hooks in the `EvmKeeper`: This ADR proposes to add an `EvmHooks` interface and a method to register hooks in the `EvmKeeper`:
```golang ```go
type EvmHooks interface { type EvmHooks interface {
PostTxProcessing(ctx sdk.Context, txHash ethcmn.Hash, logs []*ethtypes.Log) error PostTxProcessing(ctx sdk.Context, txHash common.Hash, logs []*ethtypes.Log) error
} }
func (k *EvmKeeper) SetHooks(eh types.EvmHooks) *Keeper; func (k *EvmKeeper) SetHooks(eh types.EvmHooks) *Keeper;
@ -48,9 +48,13 @@ func (k *EvmKeeper) SetHooks(eh types.EvmHooks) *Keeper;
The EVM state transition method `ApplyTransaction` should be changed like this: The EVM state transition method `ApplyTransaction` should be changed like this:
```golang ```go
// Need to create a snapshot explicitly to cover both tx processing and post processing logic // Need to create a snapshot explicitly to cover both tx processing and post processing logic
revision := k.Snapshot() var revision int
if k.hooks != nil {
revision = k.Snapshot()
}
res, err := k.ApplyMessage(evm, msg, ethCfg, false) res, err := k.ApplyMessage(evm, msg, ethCfg, false)
if err != nil { if err != nil {
@ -96,50 +100,50 @@ function withdraw_to_native_token(amount uint256) public {
And the application registers a `BankSendHook` to `EvmKeeper`, it recognizes the log and converts it to a call to the bank And the application registers a `BankSendHook` to `EvmKeeper`, it recognizes the log and converts it to a call to the bank
module's `SendCoinsFromAccountToAccount` method: module's `SendCoinsFromAccountToAccount` method:
```golang ```go
var ( var (
// BankSendEvent represent the signature of // BankSendEvent represent the signature of
// `event __CosmosNativeBankSend(address recipient, uint256 amount, string denom)` // `event __CosmosNativeBankSend(address recipient, uint256 amount, string denom)`
BankSendEvent abi.Event BankSendEvent abi.Event
) )
func init() { func init() {
addressType, _ := abi.NewType("address", "", nil) addressType, _ := abi.NewType("address", "", nil)
uint256Type, _ := abi.NewType("uint256", "", nil) uint256Type, _ := abi.NewType("uint256", "", nil)
stringType, _ := abi.NewType("string", "", nil) stringType, _ := abi.NewType("string", "", nil)
BankSendEvent = abi.NewEvent( BankSendEvent = abi.NewEvent(
"__CosmosNativeBankSend", "__CosmosNativeBankSend",
"__CosmosNativeBankSend", "__CosmosNativeBankSend",
false, false,
abi.Arguments{abi.Argument{ abi.Arguments{abi.Argument{
Name: "recipient", Name: "recipient",
Type: addressType, Type: addressType,
Indexed: false, Indexed: false,
}, abi.Argument{ }, abi.Argument{
Name: "amount", Name: "amount",
Type: uint256Type, Type: uint256Type,
Indexed: false, Indexed: false,
}, abi.Argument{ }, abi.Argument{
Name: "denom", Name: "denom",
Type: stringType, Type: stringType,
Indexed: false, Indexed: false,
}}, }},
) )
} }
type BankSendHook struct { type BankSendHook struct {
bankKeeper bankkeeper.Keeper bankKeeper bankkeeper.Keeper
} }
func NewBankSendHook(bankKeeper bankkeeper.Keeper) *BankSendHook { func NewBankSendHook(bankKeeper bankkeeper.Keeper) *BankSendHook {
return &BankSendHook{ return &BankSendHook{
bankKeeper: bankKeeper, bankKeeper: bankKeeper,
} }
} }
func (h BankSendHook) PostTxProcessing(ctx sdk.Context, txHash ethcmn.Hash, logs []*ethtypes.Log) error { func (h BankSendHook) PostTxProcessing(ctx sdk.Context, txHash common.Hash, logs []*ethtypes.Log) error {
for _, log := range logs { for _, log := range logs {
if len(log.Topics) == 0 || log.Topics[0] != BankSendEvent.ID { if len(log.Topics) == 0 || log.Topics[0] != BankSendEvent.ID {
continue continue
} }
if !ContractAllowed(log.Address) { if !ContractAllowed(log.Address) {
@ -152,21 +156,21 @@ func (h BankSendHook) PostTxProcessing(ctx sdk.Context, txHash ethcmn.Hash, logs
continue continue
} }
contract := sdk.AccAddress(log.Address.Bytes()) contract := sdk.AccAddress(log.Address.Bytes())
recipient := sdk.AccAddress(unpacked[0].(ethcmn.Address).Bytes()) recipient := sdk.AccAddress(unpacked[0].(common.Address).Bytes())
coins := sdk.NewCoins(sdk.NewCoin(unpacked[2].(string), sdk.NewIntFromBigInt(unpacked[1].(*big.Int)))) coins := sdk.NewCoins(sdk.NewCoin(unpacked[2].(string), sdk.NewIntFromBigInt(unpacked[1].(*big.Int))))
err = h.bankKeeper.SendCoins(ctx, contract, recipient, coins) err = h.bankKeeper.SendCoins(ctx, contract, recipient, coins)
if err != nil { if err != nil {
return err return err
} }
} }
} }
return nil return nil
} }
``` ```
Register the hook in `app.go`: Register the hook in `app.go`:
```golang ```go
evmKeeper.SetHooks(NewBankSendHook(bankKeeper)); evmKeeper.SetHooks(NewBankSendHook(bankKeeper));
``` ```

View File

@ -3,7 +3,7 @@ package importer
import ( import (
"math/big" "math/big"
ethcmn "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
ethcons "github.com/ethereum/go-ethereum/consensus" ethcons "github.com/ethereum/go-ethereum/consensus"
ethstate "github.com/ethereum/go-ethereum/core/state" ethstate "github.com/ethereum/go-ethereum/core/state"
ethtypes "github.com/ethereum/go-ethereum/core/types" ethtypes "github.com/ethereum/go-ethereum/core/types"
@ -20,7 +20,7 @@ import (
// NOTE: Ethermint will distribute the fees out to validators, so the structure // NOTE: Ethermint will distribute the fees out to validators, so the structure
// and functionality of this is a WIP and subject to change. // and functionality of this is a WIP and subject to change.
type ChainContext struct { type ChainContext struct {
Coinbase ethcmn.Address Coinbase common.Address
headersByNumber map[uint64]*ethtypes.Header headersByNumber map[uint64]*ethtypes.Header
} }
@ -48,7 +48,7 @@ func (cc *ChainContext) SetHeader(number uint64, header *ethtypes.Header) {
// //
// TODO: The Cosmos SDK supports retreiving such information in contexts and // TODO: The Cosmos SDK supports retreiving such information in contexts and
// multi-store, so this will be need to be integrated. // multi-store, so this will be need to be integrated.
func (cc *ChainContext) GetHeader(_ ethcmn.Hash, number uint64) *ethtypes.Header { func (cc *ChainContext) GetHeader(_ common.Hash, number uint64) *ethtypes.Header {
if header, ok := cc.headersByNumber[number]; ok { if header, ok := cc.headersByNumber[number]; ok {
return header return header
} }
@ -62,7 +62,7 @@ func (cc *ChainContext) GetHeader(_ ethcmn.Hash, number uint64) *ethtypes.Header
// //
// NOTE: Ethermint will distribute the fees out to validators, so the structure // NOTE: Ethermint will distribute the fees out to validators, so the structure
// and functionality of this is a WIP and subject to change. // and functionality of this is a WIP and subject to change.
func (cc *ChainContext) Author(_ *ethtypes.Header) (ethcmn.Address, error) { func (cc *ChainContext) Author(_ *ethtypes.Header) (common.Address, error) {
return cc.Coinbase, nil return cc.Coinbase, nil
} }
@ -119,8 +119,8 @@ func (cc *ChainContext) Seal(_ ethcons.ChainHeaderReader, _ *ethtypes.Block, _ c
// SealHash implements Ethereum's consensus.Engine interface. It returns the // SealHash implements Ethereum's consensus.Engine interface. It returns the
// hash of a block prior to it being sealed. // hash of a block prior to it being sealed.
func (cc *ChainContext) SealHash(header *ethtypes.Header) ethcmn.Hash { func (cc *ChainContext) SealHash(header *ethtypes.Header) common.Hash {
return ethcmn.Hash{} return common.Hash{}
} }
// VerifyHeader implements Ethereum's consensus.Engine interface. It currently // VerifyHeader implements Ethereum's consensus.Engine interface. It currently

View File

@ -9,7 +9,7 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
ethcmn "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
ethcons "github.com/ethereum/go-ethereum/consensus" ethcons "github.com/ethereum/go-ethereum/consensus"
ethcore "github.com/ethereum/go-ethereum/core" ethcore "github.com/ethereum/go-ethereum/core"
ethtypes "github.com/ethereum/go-ethereum/core/types" ethtypes "github.com/ethereum/go-ethereum/core/types"
@ -47,8 +47,8 @@ func TestChainContextGetHeader(t *testing.T) {
} }
cc.SetHeader(uint64(header.Number.Int64()), header) cc.SetHeader(uint64(header.Number.Int64()), header)
require.Equal(t, header, cc.GetHeader(ethcmn.Hash{}, uint64(header.Number.Int64()))) require.Equal(t, header, cc.GetHeader(common.Hash{}, uint64(header.Number.Int64())))
require.Nil(t, cc.GetHeader(ethcmn.Hash{}, 0)) require.Nil(t, cc.GetHeader(common.Hash{}, 0))
} }
func TestChainContextAuthor(t *testing.T) { func TestChainContextAuthor(t *testing.T) {

View File

@ -35,12 +35,12 @@ package importer
// evmkeeper "github.com/tharsis/ethermint/x/evm/keeper" // evmkeeper "github.com/tharsis/ethermint/x/evm/keeper"
// evmtypes "github.com/tharsis/ethermint/x/evm/types" // evmtypes "github.com/tharsis/ethermint/x/evm/types"
// ethcmn "github.com/ethereum/go-ethereum/common" // "github.com/ethereum/go-ethereum/common"
// "github.com/ethereum/go-ethereum/consensus/ethash" // "github.com/ethereum/go-ethereum/consensus/ethash"
// ethcore "github.com/ethereum/go-ethereum/core" // ethcore "github.com/ethereum/go-ethereum/core"
// ethtypes "github.com/ethereum/go-ethereum/core/types" // ethtypes "github.com/ethereum/go-ethereum/core/types"
// ethvm "github.com/ethereum/go-ethereum/core/vm" // ethvm "github.com/ethereum/go-ethereum/core/vm"
// ethcrypto "github.com/ethereum/go-ethereum/crypto" // "github.com/ethereum/go-ethereum/crypto"
// ethparams "github.com/ethereum/go-ethereum/params" // ethparams "github.com/ethereum/go-ethereum/params"
// ethrlp "github.com/ethereum/go-ethereum/rlp" // ethrlp "github.com/ethereum/go-ethereum/rlp"
@ -56,7 +56,7 @@ package importer
// flagBlockchain string // flagBlockchain string
// flagCPUProfile string // flagCPUProfile string
// genInvestor = ethcmn.HexToAddress("0x756F45E3FA69347A9A973A725E3C98bC4db0b5a0") // genInvestor = common.HexToAddress("0x756F45E3FA69347A9A973A725E3C98bC4db0b5a0")
// logger = tmlog.NewNopLogger() // logger = tmlog.NewNopLogger()
@ -125,7 +125,7 @@ package importer
// sort.Strings(genAddrs) // sort.Strings(genAddrs)
// for _, addrStr := range genAddrs { // for _, addrStr := range genAddrs {
// addr := ethcmn.HexToAddress(addrStr) // addr := common.HexToAddress(addrStr)
// acc := genBlock.Alloc[addr] // acc := genBlock.Alloc[addr]
// evmKeeper.AddBalance(addr, acc.Balance) // evmKeeper.AddBalance(addr, acc.Balance)
@ -348,7 +348,7 @@ package importer
// // Function is also pulled from go-ethereum 1.9 because of the incompatible usage // // 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 // // Ref: https://github.com/ethereum/go-ethereum/blob/52f2461774bcb8cdd310f86b4bc501df5b783852/core/state_processor.go#L88
// func applyTransaction( // func applyTransaction(
// config *ethparams.ChainConfig, bc ethcore.ChainContext, author *ethcmn.Address, // config *ethparams.ChainConfig, bc ethcore.ChainContext, author *common.Address,
// gp *ethcore.GasPool, evmKeeper *evmkeeper.Keeper, header *ethtypes.Header, // gp *ethcore.GasPool, evmKeeper *evmkeeper.Keeper, header *ethtypes.Header,
// tx *ethtypes.Transaction, usedGas *uint64, cfg ethvm.Config, // tx *ethtypes.Transaction, usedGas *uint64, cfg ethvm.Config,
// ) (*ethtypes.Receipt, uint64, error) { // ) (*ethtypes.Receipt, uint64, error) {
@ -376,7 +376,7 @@ package importer
// return nil, execResult.UsedGas, err // return nil, execResult.UsedGas, err
// } // }
// root := ethcmn.Hash{}.Bytes() // root := common.Hash{}.Bytes()
// *usedGas += execResult.UsedGas // *usedGas += execResult.UsedGas
// // Create a new receipt for the transaction, storing the intermediate root and gas used by the tx // // Create a new receipt for the transaction, storing the intermediate root and gas used by the tx
@ -387,7 +387,7 @@ package importer
// // if the transaction created a contract, store the creation address in the receipt. // // if the transaction created a contract, store the creation address in the receipt.
// if msg.To() == nil { // if msg.To() == nil {
// receipt.ContractAddress = ethcrypto.CreateAddress(vmenv.TxContext.Origin, tx.Nonce()) // receipt.ContractAddress = crypto.CreateAddress(vmenv.TxContext.Origin, tx.Nonce())
// } // }
// // Set the receipt logs and create a bloom for filtering // // Set the receipt logs and create a bloom for filtering

View File

@ -8,7 +8,7 @@ import (
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/hexutil"
ethcrypto "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
) )
func TestPersonal_ListAccounts(t *testing.T) { func TestPersonal_ListAccounts(t *testing.T) {
@ -47,18 +47,18 @@ func TestPersonal_Sign(t *testing.T) {
} }
func TestPersonal_ImportRawKey(t *testing.T) { func TestPersonal_ImportRawKey(t *testing.T) {
privkey, err := ethcrypto.GenerateKey() privkey, err := crypto.GenerateKey()
require.NoError(t, err) require.NoError(t, err)
// parse priv key to hex // parse priv key to hex
hexPriv := common.Bytes2Hex(ethcrypto.FromECDSA(privkey)) hexPriv := common.Bytes2Hex(crypto.FromECDSA(privkey))
rpcRes := Call(t, "personal_importRawKey", []string{hexPriv, "password"}) rpcRes := Call(t, "personal_importRawKey", []string{hexPriv, "password"})
var res hexutil.Bytes var res hexutil.Bytes
err = json.Unmarshal(rpcRes.Result, &res) err = json.Unmarshal(rpcRes.Result, &res)
require.NoError(t, err) require.NoError(t, err)
addr := ethcrypto.PubkeyToAddress(privkey.PublicKey) addr := crypto.PubkeyToAddress(privkey.PublicKey)
resAddr := common.BytesToAddress(res) resAddr := common.BytesToAddress(res)
require.Equal(t, addr.String(), resAddr.String()) require.Equal(t, addr.String(), resAddr.String())

View File

@ -23,7 +23,7 @@ import (
ethermint "github.com/tharsis/ethermint/types" ethermint "github.com/tharsis/ethermint/types"
evmtypes "github.com/tharsis/ethermint/x/evm/types" evmtypes "github.com/tharsis/ethermint/x/evm/types"
ethcmn "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/hexutil"
ethtypes "github.com/ethereum/go-ethereum/core/types" ethtypes "github.com/ethereum/go-ethereum/core/types"
) )
@ -339,7 +339,7 @@ func TestEth_blockNumber(t *testing.T) {
} }
func TestEth_coinbase(t *testing.T) { func TestEth_coinbase(t *testing.T) {
zeroAddress := hexutil.Bytes(ethcmn.Address{}.Bytes()) zeroAddress := hexutil.Bytes(common.Address{}.Bytes())
rpcRes := call(t, "eth_coinbase", []string{}) rpcRes := call(t, "eth_coinbase", []string{})
var res hexutil.Bytes var res hexutil.Bytes
@ -470,7 +470,7 @@ func TestEth_GetFilterChanges_BlockFilter(t *testing.T) {
time.Sleep(5 * time.Second) time.Sleep(5 * time.Second)
changesRes := call(t, "eth_getFilterChanges", []string{ID}) changesRes := call(t, "eth_getFilterChanges", []string{ID})
var hashes []ethcmn.Hash var hashes []common.Hash
err = json.Unmarshal(changesRes.Result, &hashes) err = json.Unmarshal(changesRes.Result, &hashes)
require.NoError(t, err) require.NoError(t, err)
require.GreaterOrEqual(t, len(hashes), 1) require.GreaterOrEqual(t, len(hashes), 1)
@ -579,7 +579,7 @@ func TestEth_GetTransactionReceipt_ContractDeployment(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, "0x1", receipt["status"].(string)) require.Equal(t, "0x1", receipt["status"].(string))
require.NotEqual(t, ethcmn.Address{}.String(), receipt["contractAddress"].(string)) require.NotEqual(t, common.Address{}.String(), receipt["contractAddress"].(string))
require.NotNil(t, receipt["logs"]) require.NotNil(t, receipt["logs"])
} }

View File

@ -5,7 +5,7 @@ import (
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
ethcrypto "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
) )
var ( var (
@ -23,7 +23,7 @@ var (
func ProtoAccount() authtypes.AccountI { func ProtoAccount() authtypes.AccountI {
return &EthAccount{ return &EthAccount{
BaseAccount: &authtypes.BaseAccount{}, BaseAccount: &authtypes.BaseAccount{},
CodeHash: common.BytesToHash(ethcrypto.Keccak256(nil)).String(), CodeHash: common.BytesToHash(crypto.Keccak256(nil)).String(),
} }
} }

View File

@ -3,24 +3,23 @@ package types
import ( import (
"bytes" "bytes"
ethcmn "github.com/ethereum/go-ethereum/common"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/ethereum/go-ethereum/common"
) )
// IsEmptyHash returns true if the hash corresponds to an empty ethereum hex hash. // IsEmptyHash returns true if the hash corresponds to an empty ethereum hex hash.
func IsEmptyHash(hash string) bool { func IsEmptyHash(hash string) bool {
return bytes.Equal(ethcmn.HexToHash(hash).Bytes(), ethcmn.Hash{}.Bytes()) return bytes.Equal(common.HexToHash(hash).Bytes(), common.Hash{}.Bytes())
} }
// IsZeroAddress returns true if the address corresponds to an empty ethereum hex address. // IsZeroAddress returns true if the address corresponds to an empty ethereum hex address.
func IsZeroAddress(address string) bool { func IsZeroAddress(address string) bool {
return bytes.Equal(ethcmn.HexToAddress(address).Bytes(), ethcmn.Address{}.Bytes()) return bytes.Equal(common.HexToAddress(address).Bytes(), common.Address{}.Bytes())
} }
// ValidateAddress returns an error if the provided string is either not a hex formatted string address // ValidateAddress returns an error if the provided string is either not a hex formatted string address
func ValidateAddress(address string) error { func ValidateAddress(address string) error {
if !ethcmn.IsHexAddress(address) { if !common.IsHexAddress(address) {
return sdkerrors.Wrapf( return sdkerrors.Wrapf(
sdkerrors.ErrInvalidAddress, "address '%s' is not a valid ethereum hex address", sdkerrors.ErrInvalidAddress, "address '%s' is not a valid ethereum hex address",
address, address,

View File

@ -3,9 +3,8 @@ package types
import ( import (
"testing" "testing"
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
ethcmn "github.com/ethereum/go-ethereum/common"
) )
func TestIsEmptyHash(t *testing.T) { func TestIsEmptyHash(t *testing.T) {
@ -18,11 +17,11 @@ func TestIsEmptyHash(t *testing.T) {
"empty string", "", true, "empty string", "", true,
}, },
{ {
"zero hash", ethcmn.Hash{}.String(), true, "zero hash", common.Hash{}.String(), true,
}, },
{ {
"non-empty hash", ethcmn.BytesToHash([]byte{1, 2, 3, 4}).String(), false, "non-empty hash", common.BytesToHash([]byte{1, 2, 3, 4}).String(), false,
}, },
} }
@ -41,11 +40,11 @@ func TestIsZeroAddress(t *testing.T) {
"empty string", "", true, "empty string", "", true,
}, },
{ {
"zero address", ethcmn.Address{}.String(), true, "zero address", common.Address{}.String(), true,
}, },
{ {
"non-empty address", ethcmn.BytesToAddress([]byte{1, 2, 3, 4}).String(), false, "non-empty address", common.BytesToAddress([]byte{1, 2, 3, 4}).String(), false,
}, },
} }

View File

@ -130,7 +130,7 @@ type GenesisAccount struct {
type TransactionLogs struct { type TransactionLogs struct {
Hash ethcmn.Hash `json:"hash"` Hash common.Hash `json:"hash"`
Logs []*ethtypes.Log `json:"logs"` Logs []*ethtypes.Log `json:"logs"`
} }

View File

@ -5,7 +5,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
ethcmn "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
abci "github.com/tendermint/tendermint/abci/types" abci "github.com/tendermint/tendermint/abci/types"
ethermint "github.com/tharsis/ethermint/types" ethermint "github.com/tharsis/ethermint/types"
@ -31,7 +31,7 @@ func InitGenesis(
} }
for _, account := range data.Accounts { for _, account := range data.Accounts {
address := ethcmn.HexToAddress(account.Address) address := common.HexToAddress(account.Address)
accAddress := sdk.AccAddress(address.Bytes()) accAddress := sdk.AccAddress(address.Bytes())
// check that the EVM balance the matches the account balance // check that the EVM balance the matches the account balance
acc := accountKeeper.GetAccount(ctx, accAddress) acc := accountKeeper.GetAccount(ctx, accAddress)
@ -48,15 +48,15 @@ func InitGenesis(
) )
} }
k.SetCode(address, ethcmn.Hex2Bytes(account.Code)) k.SetCode(address, common.Hex2Bytes(account.Code))
for _, storage := range account.Storage { for _, storage := range account.Storage {
k.SetState(address, ethcmn.HexToHash(storage.Key), ethcmn.HexToHash(storage.Value)) k.SetState(address, common.HexToHash(storage.Key), common.HexToHash(storage.Value))
} }
} }
for _, txLog := range data.TxsLogs { for _, txLog := range data.TxsLogs {
k.SetLogs(ethcmn.HexToHash(txLog.Hash), txLog.EthLogs()) k.SetLogs(common.HexToHash(txLog.Hash), txLog.EthLogs())
} }
return []abci.ValidatorUpdate{} return []abci.ValidatorUpdate{}
@ -83,7 +83,7 @@ func ExportGenesis(ctx sdk.Context, k *keeper.Keeper, ak types.AccountKeeper) *t
genAccount := types.GenesisAccount{ genAccount := types.GenesisAccount{
Address: addr.String(), Address: addr.String(),
Code: ethcmn.Bytes2Hex(k.GetCode(addr)), Code: common.Bytes2Hex(k.GetCode(addr)),
Storage: storage, Storage: storage,
} }

View File

@ -7,7 +7,7 @@ import (
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
ethcmn "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
ethtypes "github.com/ethereum/go-ethereum/core/types" ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec"
@ -33,7 +33,7 @@ type EvmTestSuite struct {
signer keyring.Signer signer keyring.Signer
ethSigner ethtypes.Signer ethSigner ethtypes.Signer
from ethcmn.Address from common.Address
to sdk.AccAddress to sdk.AccAddress
} }
@ -57,7 +57,7 @@ func (suite *EvmTestSuite) SetupTest() {
suite.signer = tests.NewSigner(privKey) suite.signer = tests.NewSigner(privKey)
suite.ethSigner = ethtypes.LatestSignerForChainID(suite.chainID) suite.ethSigner = ethtypes.LatestSignerForChainID(suite.chainID)
suite.from = ethcmn.BytesToAddress(privKey.PubKey().Address().Bytes()) suite.from = common.BytesToAddress(privKey.PubKey().Address().Bytes())
} }
@ -77,7 +77,7 @@ func TestEvmTestSuite(t *testing.T) {
// { // {
// "passed", // "passed",
// func() { // func() {
// to := ethcmn.BytesToAddress(suite.to) // to := common.BytesToAddress(suite.to)
// tx = types.NewTx(suite.chainID, 0, &to, big.NewInt(100), 0, big.NewInt(10000), nil, nil) // tx = types.NewTx(suite.chainID, 0, &to, big.NewInt(100), 0, big.NewInt(10000), nil, nil)
// tx.From = suite.from.String() // tx.From = suite.from.String()
@ -181,10 +181,10 @@ func TestEvmTestSuite(t *testing.T) {
// suite.Require().Equal(len(txResponse.Logs[0].Topics), 2) // suite.Require().Equal(len(txResponse.Logs[0].Topics), 2)
// hash := []byte{1} // hash := []byte{1}
// suite.app.EvmKeeper.SetLogs(ethcmn.BytesToHash(hash), types.LogsToEthereum(txResponse.Logs)) // suite.app.EvmKeeper.SetLogs(common.BytesToHash(hash), types.LogsToEthereum(txResponse.Logs))
// suite.Require().NoError(err) // suite.Require().NoError(err)
// logs := suite.app.EvmKeeper.GetTxLogs(ethcmn.BytesToHash(hash)) // logs := suite.app.EvmKeeper.GetTxLogs(common.BytesToHash(hash))
// suite.Require().Equal(logs, txResponse.Logs) // suite.Require().Equal(logs, txResponse.Logs)
// } // }
@ -302,7 +302,7 @@ func TestEvmTestSuite(t *testing.T) {
// gasPrice := big.NewInt(0x55ae82600) // gasPrice := big.NewInt(0x55ae82600)
// // send simple value transfer with gasLimit=21000 // // send simple value transfer with gasLimit=21000
// tx := types.NewTx(suite.chainID, 1, &ethcmn.Address{0x1}, big.NewInt(1), gasLimit, gasPrice, nil, nil) // tx := types.NewTx(suite.chainID, 1, &common.Address{0x1}, big.NewInt(1), gasLimit, gasPrice, nil, nil)
// tx.From = suite.from.String() // tx.From = suite.from.String()
// err := tx.Sign(suite.ethSigner, suite.signer) // err := tx.Sign(suite.ethSigner, suite.signer)
// suite.Require().NoError(err) // suite.Require().NoError(err)

View File

@ -15,7 +15,7 @@ import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/query" "github.com/cosmos/cosmos-sdk/types/query"
ethcmn "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core"
ethtypes "github.com/ethereum/go-ethereum/core/types" ethtypes "github.com/ethereum/go-ethereum/core/types"
@ -40,7 +40,7 @@ func (k Keeper) Account(c context.Context, req *types.QueryAccountRequest) (*typ
) )
} }
addr := ethcmn.HexToAddress(req.Address) addr := common.HexToAddress(req.Address)
ctx := sdk.UnwrapSDKContext(c) ctx := sdk.UnwrapSDKContext(c)
k.WithContext(ctx) k.WithContext(ctx)
@ -66,7 +66,7 @@ func (k Keeper) CosmosAccount(c context.Context, req *types.QueryCosmosAccountRe
ctx := sdk.UnwrapSDKContext(c) ctx := sdk.UnwrapSDKContext(c)
k.WithContext(ctx) k.WithContext(ctx)
ethAddr := ethcmn.HexToAddress(req.Address) ethAddr := common.HexToAddress(req.Address)
cosmosAddr := sdk.AccAddress(ethAddr.Bytes()) cosmosAddr := sdk.AccAddress(ethAddr.Bytes())
account := k.accountKeeper.GetAccount(ctx, cosmosAddr) account := k.accountKeeper.GetAccount(ctx, cosmosAddr)
@ -134,7 +134,7 @@ func (k Keeper) Balance(c context.Context, req *types.QueryBalanceRequest) (*typ
ctx := sdk.UnwrapSDKContext(c) ctx := sdk.UnwrapSDKContext(c)
k.WithContext(ctx) k.WithContext(ctx)
balanceInt := k.GetBalance(ethcmn.HexToAddress(req.Address)) balanceInt := k.GetBalance(common.HexToAddress(req.Address))
return &types.QueryBalanceResponse{ return &types.QueryBalanceResponse{
Balance: balanceInt.String(), Balance: balanceInt.String(),
@ -157,8 +157,8 @@ func (k Keeper) Storage(c context.Context, req *types.QueryStorageRequest) (*typ
ctx := sdk.UnwrapSDKContext(c) ctx := sdk.UnwrapSDKContext(c)
k.WithContext(ctx) k.WithContext(ctx)
address := ethcmn.HexToAddress(req.Address) address := common.HexToAddress(req.Address)
key := ethcmn.HexToHash(req.Key) key := common.HexToHash(req.Key)
state := k.GetState(address, key) state := k.GetState(address, key)
stateHex := state.Hex() stateHex := state.Hex()
@ -184,7 +184,7 @@ func (k Keeper) Code(c context.Context, req *types.QueryCodeRequest) (*types.Que
ctx := sdk.UnwrapSDKContext(c) ctx := sdk.UnwrapSDKContext(c)
k.WithContext(ctx) k.WithContext(ctx)
address := ethcmn.HexToAddress(req.Address) address := common.HexToAddress(req.Address)
code := k.GetCode(address) code := k.GetCode(address)
return &types.QueryCodeResponse{ return &types.QueryCodeResponse{
@ -208,7 +208,7 @@ func (k Keeper) TxLogs(c context.Context, req *types.QueryTxLogsRequest) (*types
ctx := sdk.UnwrapSDKContext(c) ctx := sdk.UnwrapSDKContext(c)
k.WithContext(ctx) k.WithContext(ctx)
hash := ethcmn.HexToHash(req.Hash) hash := common.HexToHash(req.Hash)
logs := k.GetTxLogs(hash) logs := k.GetTxLogs(hash)
return &types.QueryTxLogsResponse{ return &types.QueryTxLogsResponse{

View File

@ -8,10 +8,9 @@ import (
"google.golang.org/grpc/metadata" "google.golang.org/grpc/metadata"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
ethcmn "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/hexutil"
ethtypes "github.com/ethereum/go-ethereum/core/types" ethtypes "github.com/ethereum/go-ethereum/core/types"
ethcrypto "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
@ -40,7 +39,7 @@ func (suite *KeeperTestSuite) TestQueryAccount() {
func() { func() {
expAccount = &types.QueryAccountResponse{ expAccount = &types.QueryAccountResponse{
Balance: "0", Balance: "0",
CodeHash: common.BytesToHash(ethcrypto.Keccak256(nil)).Hex(), CodeHash: common.BytesToHash(crypto.Keccak256(nil)).Hex(),
Nonce: 0, Nonce: 0,
} }
req = &types.QueryAccountRequest{ req = &types.QueryAccountRequest{
@ -60,7 +59,7 @@ func (suite *KeeperTestSuite) TestQueryAccount() {
expAccount = &types.QueryAccountResponse{ expAccount = &types.QueryAccountResponse{
Balance: "100", Balance: "100",
CodeHash: common.BytesToHash(ethcrypto.Keccak256(nil)).Hex(), CodeHash: common.BytesToHash(crypto.Keccak256(nil)).Hex(),
Nonce: 0, Nonce: 0,
} }
req = &types.QueryAccountRequest{ req = &types.QueryAccountRequest{
@ -105,7 +104,7 @@ func (suite *KeeperTestSuite) TestQueryCosmosAccount() {
{"invalid address", {"invalid address",
func() { func() {
expAccount = &types.QueryCosmosAccountResponse{ expAccount = &types.QueryCosmosAccountResponse{
CosmosAddress: sdk.AccAddress(ethcmn.Address{}.Bytes()).String(), CosmosAddress: sdk.AccAddress(common.Address{}.Bytes()).String(),
} }
req = &types.QueryCosmosAccountRequest{ req = &types.QueryCosmosAccountRequest{
Address: invalidAddress, Address: invalidAddress,
@ -248,8 +247,8 @@ func (suite *KeeperTestSuite) TestQueryStorage() {
{ {
"success", "success",
func() { func() {
key := ethcmn.BytesToHash([]byte("key")) key := common.BytesToHash([]byte("key"))
value := ethcmn.BytesToHash([]byte("value")) value := common.BytesToHash([]byte("value"))
expValue = value.String() expValue = value.String()
suite.app.EvmKeeper.SetState(suite.address, key, value) suite.app.EvmKeeper.SetState(suite.address, key, value)
req = &types.QueryStorageRequest{ req = &types.QueryStorageRequest{
@ -350,14 +349,14 @@ func (suite *KeeperTestSuite) TestQueryTxLogs() {
{"empty hash", {"empty hash",
func() { func() {
req = &types.QueryTxLogsRequest{ req = &types.QueryTxLogsRequest{
Hash: ethcmn.Hash{}.String(), Hash: common.Hash{}.String(),
} }
}, },
false, false,
}, },
{"logs not found", {"logs not found",
func() { func() {
hash := ethcmn.BytesToHash([]byte("hash")) hash := common.BytesToHash([]byte("hash"))
req = &types.QueryTxLogsRequest{ req = &types.QueryTxLogsRequest{
Hash: hash.String(), Hash: hash.String(),
} }
@ -367,17 +366,17 @@ func (suite *KeeperTestSuite) TestQueryTxLogs() {
{ {
"success", "success",
func() { func() {
hash := ethcmn.BytesToHash([]byte("tx_hash")) hash := common.BytesToHash([]byte("tx_hash"))
expLogs = []*types.Log{ expLogs = []*types.Log{
{ {
Address: suite.address.String(), Address: suite.address.String(),
Topics: []string{ethcmn.BytesToHash([]byte("topic")).String()}, Topics: []string{common.BytesToHash([]byte("topic")).String()},
Data: []byte("data"), Data: []byte("data"),
BlockNumber: 1, BlockNumber: 1,
TxHash: hash.String(), TxHash: hash.String(),
TxIndex: 1, TxIndex: 1,
BlockHash: ethcmn.BytesToHash([]byte("block_hash")).String(), BlockHash: common.BytesToHash([]byte("block_hash")).String(),
Index: 0, Index: 0,
Removed: false, Removed: false,
}, },
@ -427,14 +426,14 @@ func (suite *KeeperTestSuite) TestQueryBlockLogs() {
{"empty hash", {"empty hash",
func() { func() {
req = &types.QueryBlockLogsRequest{ req = &types.QueryBlockLogsRequest{
Hash: ethcmn.Hash{}.String(), Hash: common.Hash{}.String(),
} }
}, },
false, false,
}, },
{"logs not found", {"logs not found",
func() { func() {
hash := ethcmn.BytesToHash([]byte("hash")) hash := common.BytesToHash([]byte("hash"))
req = &types.QueryBlockLogsRequest{ req = &types.QueryBlockLogsRequest{
Hash: hash.String(), Hash: hash.String(),
} }
@ -445,46 +444,46 @@ func (suite *KeeperTestSuite) TestQueryBlockLogs() {
"success", "success",
func() { func() {
hash := ethcmn.BytesToHash([]byte("block_hash")) hash := common.BytesToHash([]byte("block_hash"))
expLogs = []types.TransactionLogs{ expLogs = []types.TransactionLogs{
{ {
Hash: ethcmn.BytesToHash([]byte("tx_hash_0")).String(), Hash: common.BytesToHash([]byte("tx_hash_0")).String(),
Logs: []*types.Log{ Logs: []*types.Log{
{ {
Address: suite.address.String(), Address: suite.address.String(),
Topics: []string{ethcmn.BytesToHash([]byte("topic")).String()}, Topics: []string{common.BytesToHash([]byte("topic")).String()},
Data: []byte("data"), Data: []byte("data"),
BlockNumber: 1, BlockNumber: 1,
TxHash: ethcmn.BytesToHash([]byte("tx_hash_0")).String(), TxHash: common.BytesToHash([]byte("tx_hash_0")).String(),
TxIndex: 1, TxIndex: 1,
BlockHash: ethcmn.BytesToHash([]byte("block_hash")).String(), BlockHash: common.BytesToHash([]byte("block_hash")).String(),
Index: 0, Index: 0,
Removed: false, Removed: false,
}, },
}, },
}, },
{ {
Hash: ethcmn.BytesToHash([]byte("tx_hash_1")).String(), Hash: common.BytesToHash([]byte("tx_hash_1")).String(),
Logs: []*types.Log{ Logs: []*types.Log{
{ {
Address: suite.address.String(), Address: suite.address.String(),
Topics: []string{ethcmn.BytesToHash([]byte("topic")).String()}, Topics: []string{common.BytesToHash([]byte("topic")).String()},
Data: []byte("data"), Data: []byte("data"),
BlockNumber: 1, BlockNumber: 1,
TxHash: ethcmn.BytesToHash([]byte("tx_hash_1")).String(), TxHash: common.BytesToHash([]byte("tx_hash_1")).String(),
TxIndex: 1, TxIndex: 1,
BlockHash: ethcmn.BytesToHash([]byte("block_hash")).String(), BlockHash: common.BytesToHash([]byte("block_hash")).String(),
Index: 1, Index: 1,
Removed: false, Removed: false,
}, },
{ {
Address: suite.address.String(), Address: suite.address.String(),
Topics: []string{ethcmn.BytesToHash([]byte("topic_1")).String()}, Topics: []string{common.BytesToHash([]byte("topic_1")).String()},
Data: []byte("data_1"), Data: []byte("data_1"),
BlockNumber: 1, BlockNumber: 1,
TxHash: ethcmn.BytesToHash([]byte("tx_hash_1")).String(), TxHash: common.BytesToHash([]byte("tx_hash_1")).String(),
TxIndex: 1, TxIndex: 1,
BlockHash: ethcmn.BytesToHash([]byte("block_hash")).String(), BlockHash: common.BytesToHash([]byte("block_hash")).String(),
Index: 2, Index: 2,
Removed: false, Removed: false,
}, },
@ -492,8 +491,8 @@ func (suite *KeeperTestSuite) TestQueryBlockLogs() {
}, },
} }
suite.app.EvmKeeper.SetLogs(ethcmn.BytesToHash([]byte("tx_hash_0")), types.LogsToEthereum(expLogs[0].Logs)) suite.app.EvmKeeper.SetLogs(common.BytesToHash([]byte("tx_hash_0")), types.LogsToEthereum(expLogs[0].Logs))
suite.app.EvmKeeper.SetLogs(ethcmn.BytesToHash([]byte("tx_hash_1")), types.LogsToEthereum(expLogs[1].Logs)) suite.app.EvmKeeper.SetLogs(common.BytesToHash([]byte("tx_hash_1")), types.LogsToEthereum(expLogs[1].Logs))
req = &types.QueryBlockLogsRequest{ req = &types.QueryBlockLogsRequest{
Hash: hash.String(), Hash: hash.String(),
@ -618,7 +617,7 @@ func (suite *KeeperTestSuite) TestQueryValidatorAccount() {
{"invalid address", {"invalid address",
func() { func() {
expAccount = &types.QueryValidatorAccountResponse{ expAccount = &types.QueryValidatorAccountResponse{
AccountAddress: sdk.AccAddress(ethcmn.Address{}.Bytes()).String(), AccountAddress: sdk.AccAddress(common.Address{}.Bytes()).String(),
} }
req = &types.QueryValidatorAccountRequest{ req = &types.QueryValidatorAccountRequest{
ConsAddress: "", ConsAddress: "",

View File

@ -3,7 +3,7 @@ package keeper
import ( import (
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
ethcmn "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
ethtypes "github.com/ethereum/go-ethereum/core/types" ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/tharsis/ethermint/x/evm/types" "github.com/tharsis/ethermint/x/evm/types"
) )
@ -21,7 +21,7 @@ func NewMultiEvmHooks(hooks ...types.EvmHooks) MultiEvmHooks {
} }
// PostTxProcessing delegate the call to underlying hooks // PostTxProcessing delegate the call to underlying hooks
func (mh MultiEvmHooks) PostTxProcessing(ctx sdk.Context, txHash ethcmn.Hash, logs []*ethtypes.Log) error { func (mh MultiEvmHooks) PostTxProcessing(ctx sdk.Context, txHash common.Hash, logs []*ethtypes.Log) error {
for i := range mh { for i := range mh {
if err := mh[i].PostTxProcessing(ctx, txHash, logs); err != nil { if err := mh[i].PostTxProcessing(ctx, txHash, logs); err != nil {
return sdkerrors.Wrapf(err, "EVM hook %T failed", mh[i]) return sdkerrors.Wrapf(err, "EVM hook %T failed", mh[i])

View File

@ -28,11 +28,9 @@ import (
"github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
ethcmn "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/hexutil"
ethtypes "github.com/ethereum/go-ethereum/core/types" ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
ethcrypto "github.com/ethereum/go-ethereum/crypto"
abci "github.com/tendermint/tendermint/abci/types" abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto/tmhash" "github.com/tendermint/tendermint/crypto/tmhash"
@ -72,7 +70,7 @@ type KeeperTestSuite struct {
ctx sdk.Context ctx sdk.Context
app *app.EthermintApp app *app.EthermintApp
queryClient types.QueryClient queryClient types.QueryClient
address ethcmn.Address address common.Address
consAddress sdk.ConsAddress consAddress sdk.ConsAddress
// for generate test tx // for generate test tx
@ -90,7 +88,7 @@ func (suite *KeeperTestSuite) DoSetupTest(t require.TestingT) {
// account key // account key
priv, err := ethsecp256k1.GenerateKey() priv, err := ethsecp256k1.GenerateKey()
require.NoError(t, err) require.NoError(t, err)
suite.address = ethcmn.BytesToAddress(priv.PubKey().Address().Bytes()) suite.address = common.BytesToAddress(priv.PubKey().Address().Bytes())
suite.signer = tests.NewSigner(priv) suite.signer = tests.NewSigner(priv)
// consensus key // consensus key
@ -130,7 +128,7 @@ func (suite *KeeperTestSuite) DoSetupTest(t require.TestingT) {
acc := &ethermint.EthAccount{ acc := &ethermint.EthAccount{
BaseAccount: authtypes.NewBaseAccount(sdk.AccAddress(suite.address.Bytes()), nil, 0, 0), BaseAccount: authtypes.NewBaseAccount(sdk.AccAddress(suite.address.Bytes()), nil, 0, 0),
CodeHash: common.BytesToHash(ethcrypto.Keccak256(nil)).String(), CodeHash: common.BytesToHash(crypto.Keccak256(nil)).String(),
} }
suite.app.AccountKeeper.SetAccount(suite.ctx, acc) suite.app.AccountKeeper.SetAccount(suite.ctx, acc)

View File

@ -16,7 +16,6 @@ import (
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/tharsis/ethermint/tests" "github.com/tharsis/ethermint/tests"
"github.com/tharsis/ethermint/x/evm/types" "github.com/tharsis/ethermint/x/evm/types"
evmtypes "github.com/tharsis/ethermint/x/evm/types"
) )
func (suite *KeeperTestSuite) TestCreateAccount() { func (suite *KeeperTestSuite) TestCreateAccount() {
@ -533,8 +532,8 @@ func (suite *KeeperTestSuite) TestSnapshot() {
} }
} }
func (suite *KeeperTestSuite) CreateTestTx(msg *evmtypes.MsgEthereumTx, priv cryptotypes.PrivKey) authsigning.Tx { func (suite *KeeperTestSuite) CreateTestTx(msg *types.MsgEthereumTx, priv cryptotypes.PrivKey) authsigning.Tx {
option, err := codectypes.NewAnyWithValue(&evmtypes.ExtensionOptionsEthereumTx{}) option, err := codectypes.NewAnyWithValue(&types.ExtensionOptionsEthereumTx{})
suite.Require().NoError(err) suite.Require().NoError(err)
txBuilder := suite.clientCtx.TxConfig.NewTxBuilder() txBuilder := suite.clientCtx.TxConfig.NewTxBuilder()
@ -558,14 +557,14 @@ func (suite *KeeperTestSuite) TestAddLog() {
msg.From = addr.Hex() msg.From = addr.Hex()
tx := suite.CreateTestTx(msg, privKey) tx := suite.CreateTestTx(msg, privKey)
msg, _ = tx.GetMsgs()[0].(*evmtypes.MsgEthereumTx) msg, _ = tx.GetMsgs()[0].(*types.MsgEthereumTx)
txHash := msg.AsTransaction().Hash() txHash := msg.AsTransaction().Hash()
msg2 := types.NewTx(big.NewInt(1), 1, &suite.address, big.NewInt(1), 100000, big.NewInt(1), []byte("test"), nil) msg2 := types.NewTx(big.NewInt(1), 1, &suite.address, big.NewInt(1), 100000, big.NewInt(1), []byte("test"), nil)
msg2.From = addr.Hex() msg2.From = addr.Hex()
tx2 := suite.CreateTestTx(msg2, privKey) tx2 := suite.CreateTestTx(msg2, privKey)
msg2, _ = tx2.GetMsgs()[0].(*evmtypes.MsgEthereumTx) msg2, _ = tx2.GetMsgs()[0].(*types.MsgEthereumTx)
txHash2 := msg2.AsTransaction().Hash() txHash2 := msg2.AsTransaction().Hash()
testCases := []struct { testCases := []struct {

View File

@ -1,7 +1,7 @@
package types package types
import ( import (
ethcmn "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
ethtypes "github.com/ethereum/go-ethereum/core/types" ethtypes "github.com/ethereum/go-ethereum/core/types"
) )
@ -39,14 +39,14 @@ func (al AccessList) ToEthAccessList() *ethtypes.AccessList {
var ethAccessList ethtypes.AccessList var ethAccessList ethtypes.AccessList
for _, tuple := range al { for _, tuple := range al {
storageKeys := make([]ethcmn.Hash, len(tuple.StorageKeys)) storageKeys := make([]common.Hash, len(tuple.StorageKeys))
for i := range tuple.StorageKeys { for i := range tuple.StorageKeys {
storageKeys[i] = ethcmn.HexToHash(tuple.StorageKeys[i]) storageKeys[i] = common.HexToHash(tuple.StorageKeys[i])
} }
ethAccessList = append(ethAccessList, ethtypes.AccessTuple{ ethAccessList = append(ethAccessList, ethtypes.AccessTuple{
Address: ethcmn.HexToAddress(tuple.Address), Address: common.HexToAddress(tuple.Address),
StorageKeys: storageKeys, StorageKeys: storageKeys,
}) })
} }

View File

@ -3,10 +3,9 @@ package types
import ( import (
"testing" "testing"
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
ethcmn "github.com/ethereum/go-ethereum/common"
"github.com/tharsis/ethermint/crypto/ethsecp256k1" "github.com/tharsis/ethermint/crypto/ethsecp256k1"
) )
@ -14,7 +13,7 @@ type GenesisTestSuite struct {
suite.Suite suite.Suite
address string address string
hash ethcmn.Hash hash common.Hash
code string code string
} }
@ -22,9 +21,9 @@ func (suite *GenesisTestSuite) SetupTest() {
priv, err := ethsecp256k1.GenerateKey() priv, err := ethsecp256k1.GenerateKey()
suite.Require().NoError(err) suite.Require().NoError(err)
suite.address = ethcmn.BytesToAddress(priv.PubKey().Address().Bytes()).String() suite.address = common.BytesToAddress(priv.PubKey().Address().Bytes()).String()
suite.hash = ethcmn.BytesToHash([]byte("hash")) suite.hash = common.BytesToHash([]byte("hash"))
suite.code = ethcmn.Bytes2Hex([]byte{1, 2, 3}) suite.code = common.Bytes2Hex([]byte{1, 2, 3})
} }
func TestGenesisTestSuite(t *testing.T) { func TestGenesisTestSuite(t *testing.T) {
@ -141,7 +140,7 @@ func (suite *GenesisTestSuite) TestValidateGenesis() {
genState: &GenesisState{ genState: &GenesisState{
Accounts: []GenesisAccount{ Accounts: []GenesisAccount{
{ {
Address: ethcmn.Address{}.String(), Address: common.Address{}.String(),
}, },
}, },
}, },
@ -234,7 +233,7 @@ func (suite *GenesisTestSuite) TestValidateGenesis() {
}, },
}, },
}, },
TxsLogs: []TransactionLogs{NewTransactionLogs(ethcmn.Hash{}, nil)}, TxsLogs: []TransactionLogs{NewTransactionLogs(common.Hash{}, nil)},
}, },
expPass: false, expPass: false,
}, },

View File

@ -4,7 +4,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
ethcmn "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
ethtypes "github.com/ethereum/go-ethereum/core/types" ethtypes "github.com/ethereum/go-ethereum/core/types"
) )
@ -43,5 +43,5 @@ type StakingKeeper interface {
// EvmHooks event hooks for evm tx processing // EvmHooks event hooks for evm tx processing
type EvmHooks interface { type EvmHooks interface {
// Must be called after tx is processed successfully, if return an error, the whole transaction is reverted. // Must be called after tx is processed successfully, if return an error, the whole transaction is reverted.
PostTxProcessing(ctx sdk.Context, txHash ethcmn.Hash, logs []*ethtypes.Log) error PostTxProcessing(ctx sdk.Context, txHash common.Hash, logs []*ethtypes.Log) error
} }

View File

@ -3,8 +3,8 @@ package types
import ( import (
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
ethcmn "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
ethcrypto "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
) )
const ( const (
@ -73,18 +73,18 @@ func BloomKey(height int64) []byte {
} }
// AddressStoragePrefix returns a prefix to iterate over a given account storage. // AddressStoragePrefix returns a prefix to iterate over a given account storage.
func AddressStoragePrefix(address ethcmn.Address) []byte { func AddressStoragePrefix(address common.Address) []byte {
return append(KeyPrefixStorage, address.Bytes()...) return append(KeyPrefixStorage, address.Bytes()...)
} }
// StateKey defines the full key under which an account state is stored. // StateKey defines the full key under which an account state is stored.
func StateKey(address ethcmn.Address, key []byte) []byte { func StateKey(address common.Address, key []byte) []byte {
return append(AddressStoragePrefix(address), key...) return append(AddressStoragePrefix(address), key...)
} }
// KeyAddressStorage returns the key hash to access a given account state. The composite key // KeyAddressStorage returns the key hash to access a given account state. The composite key
// (address + hash) is hashed using Keccak256. // (address + hash) is hashed using Keccak256.
func KeyAddressStorage(address ethcmn.Address, hash ethcmn.Hash) ethcmn.Hash { func KeyAddressStorage(address common.Address, hash common.Hash) common.Hash {
prefix := address.Bytes() prefix := address.Bytes()
key := hash.Bytes() key := hash.Bytes()
@ -93,5 +93,5 @@ func KeyAddressStorage(address ethcmn.Address, hash ethcmn.Hash) ethcmn.Hash {
copy(compositeKey, prefix) copy(compositeKey, prefix)
copy(compositeKey[len(prefix):], key) copy(compositeKey[len(prefix):], key)
return ethcrypto.Keccak256Hash(compositeKey) return crypto.Keccak256Hash(compositeKey)
} }

View File

@ -4,14 +4,14 @@ import (
"errors" "errors"
"fmt" "fmt"
ethcmn "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
ethtypes "github.com/ethereum/go-ethereum/core/types" ethtypes "github.com/ethereum/go-ethereum/core/types"
ethermint "github.com/tharsis/ethermint/types" ethermint "github.com/tharsis/ethermint/types"
) )
// NewTransactionLogs creates a new NewTransactionLogs instance. // NewTransactionLogs creates a new NewTransactionLogs instance.
func NewTransactionLogs(hash ethcmn.Hash, logs []*Log) TransactionLogs { // nolint: interfacer func NewTransactionLogs(hash common.Hash, logs []*Log) TransactionLogs { // nolint: interfacer
return TransactionLogs{ return TransactionLogs{
Hash: hash.String(), Hash: hash.String(),
Logs: logs, Logs: logs,
@ -19,7 +19,7 @@ func NewTransactionLogs(hash ethcmn.Hash, logs []*Log) TransactionLogs { // noli
} }
// NewTransactionLogsFromEth creates a new NewTransactionLogs instance using []*ethtypes.Log. // NewTransactionLogsFromEth creates a new NewTransactionLogs instance using []*ethtypes.Log.
func NewTransactionLogsFromEth(hash ethcmn.Hash, ethlogs []*ethtypes.Log) TransactionLogs { // nolint: interfacer func NewTransactionLogsFromEth(hash common.Hash, ethlogs []*ethtypes.Log) TransactionLogs { // nolint: interfacer
return TransactionLogs{ return TransactionLogs{
Hash: hash.String(), Hash: hash.String(),
Logs: NewLogsFromEth(ethlogs), Logs: NewLogsFromEth(ethlogs),
@ -70,20 +70,20 @@ func (log *Log) Validate() error {
// ToEthereum returns the Ethereum type Log from a Ethermint proto compatible Log. // ToEthereum returns the Ethereum type Log from a Ethermint proto compatible Log.
func (log *Log) ToEthereum() *ethtypes.Log { func (log *Log) ToEthereum() *ethtypes.Log {
var topics []ethcmn.Hash // nolint: prealloc var topics []common.Hash // nolint: prealloc
for i := range log.Topics { for i := range log.Topics {
topics = append(topics, ethcmn.HexToHash(log.Topics[i])) topics = append(topics, common.HexToHash(log.Topics[i]))
} }
return &ethtypes.Log{ return &ethtypes.Log{
Address: ethcmn.HexToAddress(log.Address), Address: common.HexToAddress(log.Address),
Topics: topics, Topics: topics,
Data: log.Data, Data: log.Data,
BlockNumber: log.BlockNumber, BlockNumber: log.BlockNumber,
TxHash: ethcmn.HexToHash(log.TxHash), TxHash: common.HexToHash(log.TxHash),
TxIndex: uint(log.TxIndex), TxIndex: uint(log.TxIndex),
Index: uint(log.Index), Index: uint(log.Index),
BlockHash: ethcmn.HexToHash(log.BlockHash), BlockHash: common.HexToHash(log.BlockHash),
Removed: log.Removed, Removed: log.Removed,
} }
} }

View File

@ -7,14 +7,14 @@ import (
"github.com/tharsis/ethermint/crypto/ethsecp256k1" "github.com/tharsis/ethermint/crypto/ethsecp256k1"
ethcmn "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
ethcrypto "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
) )
func TestTransactionLogsValidate(t *testing.T) { func TestTransactionLogsValidate(t *testing.T) {
priv, err := ethsecp256k1.GenerateKey() priv, err := ethsecp256k1.GenerateKey()
require.NoError(t, err) require.NoError(t, err)
addr := ethcrypto.PubkeyToAddress(priv.ToECDSA().PublicKey).String() addr := crypto.PubkeyToAddress(priv.ToECDSA().PublicKey).String()
testCases := []struct { testCases := []struct {
name string name string
@ -24,16 +24,16 @@ func TestTransactionLogsValidate(t *testing.T) {
{ {
"valid log", "valid log",
TransactionLogs{ TransactionLogs{
Hash: ethcmn.BytesToHash([]byte("tx_hash")).String(), Hash: common.BytesToHash([]byte("tx_hash")).String(),
Logs: []*Log{ Logs: []*Log{
{ {
Address: addr, Address: addr,
Topics: []string{ethcmn.BytesToHash([]byte("topic")).String()}, Topics: []string{common.BytesToHash([]byte("topic")).String()},
Data: []byte("data"), Data: []byte("data"),
BlockNumber: 1, BlockNumber: 1,
TxHash: ethcmn.BytesToHash([]byte("tx_hash")).String(), TxHash: common.BytesToHash([]byte("tx_hash")).String(),
TxIndex: 1, TxIndex: 1,
BlockHash: ethcmn.BytesToHash([]byte("block_hash")).String(), BlockHash: common.BytesToHash([]byte("block_hash")).String(),
Index: 1, Index: 1,
Removed: false, Removed: false,
}, },
@ -44,14 +44,14 @@ func TestTransactionLogsValidate(t *testing.T) {
{ {
"empty hash", "empty hash",
TransactionLogs{ TransactionLogs{
Hash: ethcmn.Hash{}.String(), Hash: common.Hash{}.String(),
}, },
false, false,
}, },
{ {
"invalid log", "invalid log",
TransactionLogs{ TransactionLogs{
Hash: ethcmn.BytesToHash([]byte("tx_hash")).String(), Hash: common.BytesToHash([]byte("tx_hash")).String(),
Logs: []*Log{{}}, Logs: []*Log{{}},
}, },
false, false,
@ -59,16 +59,16 @@ func TestTransactionLogsValidate(t *testing.T) {
{ {
"hash mismatch log", "hash mismatch log",
TransactionLogs{ TransactionLogs{
Hash: ethcmn.BytesToHash([]byte("tx_hash")).String(), Hash: common.BytesToHash([]byte("tx_hash")).String(),
Logs: []*Log{ Logs: []*Log{
{ {
Address: addr, Address: addr,
Topics: []string{ethcmn.BytesToHash([]byte("topic")).String()}, Topics: []string{common.BytesToHash([]byte("topic")).String()},
Data: []byte("data"), Data: []byte("data"),
BlockNumber: 1, BlockNumber: 1,
TxHash: ethcmn.BytesToHash([]byte("other_hash")).String(), TxHash: common.BytesToHash([]byte("other_hash")).String(),
TxIndex: 1, TxIndex: 1,
BlockHash: ethcmn.BytesToHash([]byte("block_hash")).String(), BlockHash: common.BytesToHash([]byte("block_hash")).String(),
Index: 1, Index: 1,
Removed: false, Removed: false,
}, },
@ -92,7 +92,7 @@ func TestTransactionLogsValidate(t *testing.T) {
func TestValidateLog(t *testing.T) { func TestValidateLog(t *testing.T) {
priv, err := ethsecp256k1.GenerateKey() priv, err := ethsecp256k1.GenerateKey()
require.NoError(t, err) require.NoError(t, err)
addr := ethcrypto.PubkeyToAddress(priv.ToECDSA().PublicKey).String() addr := crypto.PubkeyToAddress(priv.ToECDSA().PublicKey).String()
testCases := []struct { testCases := []struct {
name string name string
@ -103,12 +103,12 @@ func TestValidateLog(t *testing.T) {
"valid log", "valid log",
&Log{ &Log{
Address: addr, Address: addr,
Topics: []string{ethcmn.BytesToHash([]byte("topic")).String()}, Topics: []string{common.BytesToHash([]byte("topic")).String()},
Data: []byte("data"), Data: []byte("data"),
BlockNumber: 1, BlockNumber: 1,
TxHash: ethcmn.BytesToHash([]byte("tx_hash")).String(), TxHash: common.BytesToHash([]byte("tx_hash")).String(),
TxIndex: 1, TxIndex: 1,
BlockHash: ethcmn.BytesToHash([]byte("block_hash")).String(), BlockHash: common.BytesToHash([]byte("block_hash")).String(),
Index: 1, Index: 1,
Removed: false, Removed: false,
}, },
@ -120,7 +120,7 @@ func TestValidateLog(t *testing.T) {
{ {
"zero address", "zero address",
&Log{ &Log{
Address: ethcmn.Address{}.String(), Address: common.Address{}.String(),
}, },
false, false,
}, },
@ -128,7 +128,7 @@ func TestValidateLog(t *testing.T) {
"empty block hash", "empty block hash",
&Log{ &Log{
Address: addr, Address: addr,
BlockHash: ethcmn.Hash{}.String(), BlockHash: common.Hash{}.String(),
}, },
false, false,
}, },
@ -136,7 +136,7 @@ func TestValidateLog(t *testing.T) {
"zero block number", "zero block number",
&Log{ &Log{
Address: addr, Address: addr,
BlockHash: ethcmn.BytesToHash([]byte("block_hash")).String(), BlockHash: common.BytesToHash([]byte("block_hash")).String(),
BlockNumber: 0, BlockNumber: 0,
}, },
false, false,
@ -145,9 +145,9 @@ func TestValidateLog(t *testing.T) {
"empty tx hash", "empty tx hash",
&Log{ &Log{
Address: addr, Address: addr,
BlockHash: ethcmn.BytesToHash([]byte("block_hash")).String(), BlockHash: common.BytesToHash([]byte("block_hash")).String(),
BlockNumber: 1, BlockNumber: 1,
TxHash: ethcmn.Hash{}.String(), TxHash: common.Hash{}.String(),
}, },
false, false,
}, },

View File

@ -12,9 +12,7 @@ import (
"github.com/tharsis/ethermint/tests" "github.com/tharsis/ethermint/tests"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
ethcmn "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
) )
@ -24,8 +22,8 @@ type MsgsTestSuite struct {
suite.Suite suite.Suite
signer keyring.Signer signer keyring.Signer
from ethcmn.Address from common.Address
to ethcmn.Address to common.Address
chainID *big.Int chainID *big.Int
} }
@ -74,12 +72,12 @@ func (suite *MsgsTestSuite) TestMsgEthereumTx_ValidateBasic() {
amount *sdk.Int amount *sdk.Int
gasPrice *sdk.Int gasPrice *sdk.Int
from string from string
accessList *ethtypes.AccessList accessList *types.AccessList
chainID *sdk.Int chainID *sdk.Int
expectPass bool expectPass bool
}{ }{
{msg: "pass with recipient - Legacy Tx", to: suite.to.Hex(), amount: &hundredInt, gasPrice: &hundredInt, expectPass: true}, {msg: "pass with recipient - Legacy Tx", to: suite.to.Hex(), amount: &hundredInt, gasPrice: &hundredInt, expectPass: true},
{msg: "pass with recipient - AccessList Tx", to: suite.to.Hex(), amount: &hundredInt, gasPrice: &zeroInt, accessList: &ethtypes.AccessList{}, chainID: &hundredInt, expectPass: true}, {msg: "pass with recipient - AccessList Tx", to: suite.to.Hex(), amount: &hundredInt, gasPrice: &zeroInt, accessList: &types.AccessList{}, chainID: &hundredInt, expectPass: true},
{msg: "pass contract - Legacy Tx", to: "", amount: &hundredInt, gasPrice: &hundredInt, expectPass: true}, {msg: "pass contract - Legacy Tx", to: "", amount: &hundredInt, gasPrice: &hundredInt, expectPass: true},
// {msg: "invalid recipient", to: invalidFromAddress, amount: &minusOneInt, gasPrice: &hundredInt, expectPass: false}, // {msg: "invalid recipient", to: invalidFromAddress, amount: &minusOneInt, gasPrice: &hundredInt, expectPass: false},
{msg: "nil amount - Legacy Tx", to: suite.to.Hex(), amount: nil, gasPrice: &hundredInt, expectPass: true}, {msg: "nil amount - Legacy Tx", to: suite.to.Hex(), amount: nil, gasPrice: &hundredInt, expectPass: true},
@ -88,13 +86,13 @@ func (suite *MsgsTestSuite) TestMsgEthereumTx_ValidateBasic() {
{msg: "negative gas price - Legacy Tx", to: suite.to.Hex(), amount: &hundredInt, gasPrice: &minusOneInt, expectPass: false}, {msg: "negative gas price - Legacy Tx", to: suite.to.Hex(), amount: &hundredInt, gasPrice: &minusOneInt, expectPass: false},
{msg: "zero gas price - Legacy Tx", to: suite.to.Hex(), amount: &hundredInt, gasPrice: &zeroInt, expectPass: true}, {msg: "zero gas price - Legacy Tx", to: suite.to.Hex(), amount: &hundredInt, gasPrice: &zeroInt, expectPass: true},
{msg: "invalid from address - Legacy Tx", to: suite.to.Hex(), amount: &hundredInt, gasPrice: &zeroInt, from: invalidFromAddress, expectPass: false}, {msg: "invalid from address - Legacy Tx", to: suite.to.Hex(), amount: &hundredInt, gasPrice: &zeroInt, from: invalidFromAddress, expectPass: false},
{msg: "nil amount - AccessListTx", to: suite.to.Hex(), amount: nil, gasPrice: &hundredInt, accessList: &ethtypes.AccessList{}, chainID: &hundredInt, expectPass: true}, {msg: "nil amount - AccessListTx", to: suite.to.Hex(), amount: nil, gasPrice: &hundredInt, accessList: &types.AccessList{}, chainID: &hundredInt, expectPass: true},
{msg: "negative amount - AccessListTx", to: suite.to.Hex(), amount: &minusOneInt, gasPrice: &hundredInt, accessList: &ethtypes.AccessList{}, chainID: nil, expectPass: false}, {msg: "negative amount - AccessListTx", to: suite.to.Hex(), amount: &minusOneInt, gasPrice: &hundredInt, accessList: &types.AccessList{}, chainID: nil, expectPass: false},
{msg: "nil gas price - AccessListTx", to: suite.to.Hex(), amount: &hundredInt, gasPrice: nil, accessList: &ethtypes.AccessList{}, chainID: &hundredInt, expectPass: false}, {msg: "nil gas price - AccessListTx", to: suite.to.Hex(), amount: &hundredInt, gasPrice: nil, accessList: &types.AccessList{}, chainID: &hundredInt, expectPass: false},
{msg: "negative gas price - AccessListTx", to: suite.to.Hex(), amount: &hundredInt, gasPrice: &minusOneInt, accessList: &ethtypes.AccessList{}, chainID: nil, expectPass: false}, {msg: "negative gas price - AccessListTx", to: suite.to.Hex(), amount: &hundredInt, gasPrice: &minusOneInt, accessList: &types.AccessList{}, chainID: nil, expectPass: false},
{msg: "zero gas price - AccessListTx", to: suite.to.Hex(), amount: &hundredInt, gasPrice: &zeroInt, accessList: &ethtypes.AccessList{}, chainID: &hundredInt, expectPass: true}, {msg: "zero gas price - AccessListTx", to: suite.to.Hex(), amount: &hundredInt, gasPrice: &zeroInt, accessList: &types.AccessList{}, chainID: &hundredInt, expectPass: true},
{msg: "invalid from address - AccessListTx", to: suite.to.Hex(), amount: &hundredInt, gasPrice: &zeroInt, from: invalidFromAddress, accessList: &ethtypes.AccessList{}, chainID: &hundredInt, expectPass: false}, {msg: "invalid from address - AccessListTx", to: suite.to.Hex(), amount: &hundredInt, gasPrice: &zeroInt, from: invalidFromAddress, accessList: &types.AccessList{}, chainID: &hundredInt, expectPass: false},
{msg: "chain ID not set on AccessListTx", to: suite.to.Hex(), amount: &hundredInt, gasPrice: &zeroInt, accessList: &ethtypes.AccessList{}, chainID: nil, expectPass: false}, {msg: "chain ID not set on AccessListTx", to: suite.to.Hex(), amount: &hundredInt, gasPrice: &zeroInt, accessList: &types.AccessList{}, chainID: nil, expectPass: false},
} }
for i, tc := range testCases { for i, tc := range testCases {
@ -128,49 +126,49 @@ func (suite *MsgsTestSuite) TestMsgEthereumTx_Sign() {
testCases := []struct { testCases := []struct {
msg string msg string
tx *MsgEthereumTx tx *MsgEthereumTx
ethSigner ethtypes.Signer ethSigner types.Signer
malleate func(tx *MsgEthereumTx) malleate func(tx *MsgEthereumTx)
expectPass bool expectPass bool
}{ }{
{ {
"pass - EIP2930 signer", "pass - EIP2930 signer",
NewTx(suite.chainID, 0, &suite.to, nil, 100000, nil, []byte("test"), &types.AccessList{}), NewTx(suite.chainID, 0, &suite.to, nil, 100000, nil, []byte("test"), &types.AccessList{}),
ethtypes.NewEIP2930Signer(suite.chainID), types.NewEIP2930Signer(suite.chainID),
func(tx *MsgEthereumTx) { tx.From = suite.from.Hex() }, func(tx *MsgEthereumTx) { tx.From = suite.from.Hex() },
true, true,
}, },
{ {
"pass - EIP155 signer", "pass - EIP155 signer",
NewTx(suite.chainID, 0, &suite.to, nil, 100000, nil, []byte("test"), nil), NewTx(suite.chainID, 0, &suite.to, nil, 100000, nil, []byte("test"), nil),
ethtypes.NewEIP155Signer(suite.chainID), types.NewEIP155Signer(suite.chainID),
func(tx *MsgEthereumTx) { tx.From = suite.from.Hex() }, func(tx *MsgEthereumTx) { tx.From = suite.from.Hex() },
true, true,
}, },
{ {
"pass - Homestead signer", "pass - Homestead signer",
NewTx(suite.chainID, 0, &suite.to, nil, 100000, nil, []byte("test"), nil), NewTx(suite.chainID, 0, &suite.to, nil, 100000, nil, []byte("test"), nil),
ethtypes.HomesteadSigner{}, types.HomesteadSigner{},
func(tx *MsgEthereumTx) { tx.From = suite.from.Hex() }, func(tx *MsgEthereumTx) { tx.From = suite.from.Hex() },
true, true,
}, },
{ {
"pass - Frontier signer", "pass - Frontier signer",
NewTx(suite.chainID, 0, &suite.to, nil, 100000, nil, []byte("test"), nil), NewTx(suite.chainID, 0, &suite.to, nil, 100000, nil, []byte("test"), nil),
ethtypes.FrontierSigner{}, types.FrontierSigner{},
func(tx *MsgEthereumTx) { tx.From = suite.from.Hex() }, func(tx *MsgEthereumTx) { tx.From = suite.from.Hex() },
true, true,
}, },
{ {
"no from address ", "no from address ",
NewTx(suite.chainID, 0, &suite.to, nil, 100000, nil, []byte("test"), &types.AccessList{}), NewTx(suite.chainID, 0, &suite.to, nil, 100000, nil, []byte("test"), &types.AccessList{}),
ethtypes.NewEIP2930Signer(suite.chainID), types.NewEIP2930Signer(suite.chainID),
func(tx *MsgEthereumTx) { tx.From = "" }, func(tx *MsgEthereumTx) { tx.From = "" },
false, false,
}, },
{ {
"from address ≠ signer address", "from address ≠ signer address",
NewTx(suite.chainID, 0, &suite.to, nil, 100000, nil, []byte("test"), &types.AccessList{}), NewTx(suite.chainID, 0, &suite.to, nil, 100000, nil, []byte("test"), &types.AccessList{}),
ethtypes.NewEIP2930Signer(suite.chainID), types.NewEIP2930Signer(suite.chainID),
func(tx *MsgEthereumTx) { tx.From = suite.to.Hex() }, func(tx *MsgEthereumTx) { tx.From = suite.to.Hex() },
false, false,
}, },

View File

@ -4,10 +4,9 @@ import (
"fmt" "fmt"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/ethereum/go-ethereum/common"
"github.com/tharsis/ethermint/types" "github.com/tharsis/ethermint/types"
ethcmn "github.com/ethereum/go-ethereum/common"
) )
// Storage represents the account Storage map as a slice of single key value // Storage represents the account Storage map as a slice of single key value
@ -59,7 +58,7 @@ func (s State) Validate() error {
} }
// NewState creates a new State instance // NewState creates a new State instance
func NewState(key, value ethcmn.Hash) State { // nolint: interfacer func NewState(key, value common.Hash) State { // nolint: interfacer
return State{ return State{
Key: key.String(), Key: key.String(),
Value: value.String(), Value: value.String(),

View File

@ -3,9 +3,8 @@ package types
import ( import (
"testing" "testing"
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
ethcmn "github.com/ethereum/go-ethereum/common"
) )
func TestStorageValidate(t *testing.T) { func TestStorageValidate(t *testing.T) {
@ -17,22 +16,22 @@ func TestStorageValidate(t *testing.T) {
{ {
"valid storage", "valid storage",
Storage{ Storage{
NewState(ethcmn.BytesToHash([]byte{1, 2, 3}), ethcmn.BytesToHash([]byte{1, 2, 3})), NewState(common.BytesToHash([]byte{1, 2, 3}), common.BytesToHash([]byte{1, 2, 3})),
}, },
true, true,
}, },
{ {
"empty storage key bytes", "empty storage key bytes",
Storage{ Storage{
{Key: ethcmn.Hash{}.String()}, {Key: common.Hash{}.String()},
}, },
false, false,
}, },
{ {
"duplicated storage key", "duplicated storage key",
Storage{ Storage{
{Key: ethcmn.BytesToHash([]byte{1, 2, 3}).String()}, {Key: common.BytesToHash([]byte{1, 2, 3}).String()},
{Key: ethcmn.BytesToHash([]byte{1, 2, 3}).String()}, {Key: common.BytesToHash([]byte{1, 2, 3}).String()},
}, },
false, false,
}, },
@ -57,13 +56,13 @@ func TestStorageCopy(t *testing.T) {
{ {
"single storage", "single storage",
Storage{ Storage{
NewState(ethcmn.BytesToHash([]byte{1, 2, 3}), ethcmn.BytesToHash([]byte{1, 2, 3})), NewState(common.BytesToHash([]byte{1, 2, 3}), common.BytesToHash([]byte{1, 2, 3})),
}, },
}, },
{ {
"empty storage key value bytes", "empty storage key value bytes",
Storage{ Storage{
{Key: ethcmn.Hash{}.String(), Value: ethcmn.Hash{}.String()}, {Key: common.Hash{}.String(), Value: common.Hash{}.String()},
}, },
}, },
{ {
@ -79,7 +78,7 @@ func TestStorageCopy(t *testing.T) {
} }
func TestStorageString(t *testing.T) { func TestStorageString(t *testing.T) {
storage := Storage{NewState(ethcmn.BytesToHash([]byte("key")), ethcmn.BytesToHash([]byte("value")))} storage := Storage{NewState(common.BytesToHash([]byte("key")), common.BytesToHash([]byte("value")))}
str := "key:\"0x00000000000000000000000000000000000000000000000000000000006b6579\" value:\"0x00000000000000000000000000000000000000000000000000000076616c7565\" \n" str := "key:\"0x00000000000000000000000000000000000000000000000000000000006b6579\" value:\"0x00000000000000000000000000000000000000000000000000000076616c7565\" \n"
require.Equal(t, str, storage.String()) require.Equal(t, str, storage.String())
} }

View File

@ -17,18 +17,17 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
ethcmn "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto"
ethcrypto "github.com/ethereum/go-ethereum/crypto"
) )
// GenerateEthAddress generates an Ethereum address. // GenerateEthAddress generates an Ethereum address.
func GenerateEthAddress() ethcmn.Address { func GenerateEthAddress() common.Address {
priv, err := ethsecp256k1.GenerateKey() priv, err := ethsecp256k1.GenerateKey()
if err != nil { if err != nil {
panic(err) panic(err)
} }
return ethcrypto.PubkeyToAddress(priv.ToECDSA().PublicKey) return crypto.PubkeyToAddress(priv.ToECDSA().PublicKey)
} }
func TestEvmDataEncoding(t *testing.T) { func TestEvmDataEncoding(t *testing.T) {