all: cleanup imports (#524)

This commit is contained in:
Federico Kunze Küllmer
2021-09-03 18:06:36 +00:00
committed by GitHub
parent 945fa64853
commit c73ce0f812
30 changed files with 238 additions and 247 deletions
+1 -1
View File
@@ -130,7 +130,7 @@ type GenesisAccount struct {
type TransactionLogs struct {
Hash ethcmn.Hash `json:"hash"`
Hash common.Hash `json:"hash"`
Logs []*ethtypes.Log `json:"logs"`
}
+6 -6
View File
@@ -5,7 +5,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/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"
ethermint "github.com/tharsis/ethermint/types"
@@ -31,7 +31,7 @@ func InitGenesis(
}
for _, account := range data.Accounts {
address := ethcmn.HexToAddress(account.Address)
address := common.HexToAddress(account.Address)
accAddress := sdk.AccAddress(address.Bytes())
// check that the EVM balance the matches the account balance
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 {
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 {
k.SetLogs(ethcmn.HexToHash(txLog.Hash), txLog.EthLogs())
k.SetLogs(common.HexToHash(txLog.Hash), txLog.EthLogs())
}
return []abci.ValidatorUpdate{}
@@ -83,7 +83,7 @@ func ExportGenesis(ctx sdk.Context, k *keeper.Keeper, ak types.AccountKeeper) *t
genAccount := types.GenesisAccount{
Address: addr.String(),
Code: ethcmn.Bytes2Hex(k.GetCode(addr)),
Code: common.Bytes2Hex(k.GetCode(addr)),
Storage: storage,
}
+7 -7
View File
@@ -7,7 +7,7 @@ import (
"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"
"github.com/cosmos/cosmos-sdk/codec"
@@ -33,7 +33,7 @@ type EvmTestSuite struct {
signer keyring.Signer
ethSigner ethtypes.Signer
from ethcmn.Address
from common.Address
to sdk.AccAddress
}
@@ -57,7 +57,7 @@ func (suite *EvmTestSuite) SetupTest() {
suite.signer = tests.NewSigner(privKey)
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",
// 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.From = suite.from.String()
@@ -181,10 +181,10 @@ func TestEvmTestSuite(t *testing.T) {
// suite.Require().Equal(len(txResponse.Logs[0].Topics), 2)
// 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)
// logs := suite.app.EvmKeeper.GetTxLogs(ethcmn.BytesToHash(hash))
// logs := suite.app.EvmKeeper.GetTxLogs(common.BytesToHash(hash))
// suite.Require().Equal(logs, txResponse.Logs)
// }
@@ -302,7 +302,7 @@ func TestEvmTestSuite(t *testing.T) {
// gasPrice := big.NewInt(0x55ae82600)
// // 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()
// err := tx.Sign(suite.ethSigner, suite.signer)
// suite.Require().NoError(err)
+8 -8
View File
@@ -15,7 +15,7 @@ import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"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/core"
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)
k.WithContext(ctx)
@@ -66,7 +66,7 @@ func (k Keeper) CosmosAccount(c context.Context, req *types.QueryCosmosAccountRe
ctx := sdk.UnwrapSDKContext(c)
k.WithContext(ctx)
ethAddr := ethcmn.HexToAddress(req.Address)
ethAddr := common.HexToAddress(req.Address)
cosmosAddr := sdk.AccAddress(ethAddr.Bytes())
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)
k.WithContext(ctx)
balanceInt := k.GetBalance(ethcmn.HexToAddress(req.Address))
balanceInt := k.GetBalance(common.HexToAddress(req.Address))
return &types.QueryBalanceResponse{
Balance: balanceInt.String(),
@@ -157,8 +157,8 @@ func (k Keeper) Storage(c context.Context, req *types.QueryStorageRequest) (*typ
ctx := sdk.UnwrapSDKContext(c)
k.WithContext(ctx)
address := ethcmn.HexToAddress(req.Address)
key := ethcmn.HexToHash(req.Key)
address := common.HexToAddress(req.Address)
key := common.HexToHash(req.Key)
state := k.GetState(address, key)
stateHex := state.Hex()
@@ -184,7 +184,7 @@ func (k Keeper) Code(c context.Context, req *types.QueryCodeRequest) (*types.Que
ctx := sdk.UnwrapSDKContext(c)
k.WithContext(ctx)
address := ethcmn.HexToAddress(req.Address)
address := common.HexToAddress(req.Address)
code := k.GetCode(address)
return &types.QueryCodeResponse{
@@ -208,7 +208,7 @@ func (k Keeper) TxLogs(c context.Context, req *types.QueryTxLogsRequest) (*types
ctx := sdk.UnwrapSDKContext(c)
k.WithContext(ctx)
hash := ethcmn.HexToHash(req.Hash)
hash := common.HexToHash(req.Hash)
logs := k.GetTxLogs(hash)
return &types.QueryTxLogsResponse{
+28 -29
View File
@@ -8,10 +8,9 @@ import (
"google.golang.org/grpc/metadata"
"github.com/ethereum/go-ethereum/common"
ethcmn "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
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"
@@ -40,7 +39,7 @@ func (suite *KeeperTestSuite) TestQueryAccount() {
func() {
expAccount = &types.QueryAccountResponse{
Balance: "0",
CodeHash: common.BytesToHash(ethcrypto.Keccak256(nil)).Hex(),
CodeHash: common.BytesToHash(crypto.Keccak256(nil)).Hex(),
Nonce: 0,
}
req = &types.QueryAccountRequest{
@@ -60,7 +59,7 @@ func (suite *KeeperTestSuite) TestQueryAccount() {
expAccount = &types.QueryAccountResponse{
Balance: "100",
CodeHash: common.BytesToHash(ethcrypto.Keccak256(nil)).Hex(),
CodeHash: common.BytesToHash(crypto.Keccak256(nil)).Hex(),
Nonce: 0,
}
req = &types.QueryAccountRequest{
@@ -105,7 +104,7 @@ func (suite *KeeperTestSuite) TestQueryCosmosAccount() {
{"invalid address",
func() {
expAccount = &types.QueryCosmosAccountResponse{
CosmosAddress: sdk.AccAddress(ethcmn.Address{}.Bytes()).String(),
CosmosAddress: sdk.AccAddress(common.Address{}.Bytes()).String(),
}
req = &types.QueryCosmosAccountRequest{
Address: invalidAddress,
@@ -248,8 +247,8 @@ func (suite *KeeperTestSuite) TestQueryStorage() {
{
"success",
func() {
key := ethcmn.BytesToHash([]byte("key"))
value := ethcmn.BytesToHash([]byte("value"))
key := common.BytesToHash([]byte("key"))
value := common.BytesToHash([]byte("value"))
expValue = value.String()
suite.app.EvmKeeper.SetState(suite.address, key, value)
req = &types.QueryStorageRequest{
@@ -350,14 +349,14 @@ func (suite *KeeperTestSuite) TestQueryTxLogs() {
{"empty hash",
func() {
req = &types.QueryTxLogsRequest{
Hash: ethcmn.Hash{}.String(),
Hash: common.Hash{}.String(),
}
},
false,
},
{"logs not found",
func() {
hash := ethcmn.BytesToHash([]byte("hash"))
hash := common.BytesToHash([]byte("hash"))
req = &types.QueryTxLogsRequest{
Hash: hash.String(),
}
@@ -367,17 +366,17 @@ func (suite *KeeperTestSuite) TestQueryTxLogs() {
{
"success",
func() {
hash := ethcmn.BytesToHash([]byte("tx_hash"))
hash := common.BytesToHash([]byte("tx_hash"))
expLogs = []*types.Log{
{
Address: suite.address.String(),
Topics: []string{ethcmn.BytesToHash([]byte("topic")).String()},
Topics: []string{common.BytesToHash([]byte("topic")).String()},
Data: []byte("data"),
BlockNumber: 1,
TxHash: hash.String(),
TxIndex: 1,
BlockHash: ethcmn.BytesToHash([]byte("block_hash")).String(),
BlockHash: common.BytesToHash([]byte("block_hash")).String(),
Index: 0,
Removed: false,
},
@@ -427,14 +426,14 @@ func (suite *KeeperTestSuite) TestQueryBlockLogs() {
{"empty hash",
func() {
req = &types.QueryBlockLogsRequest{
Hash: ethcmn.Hash{}.String(),
Hash: common.Hash{}.String(),
}
},
false,
},
{"logs not found",
func() {
hash := ethcmn.BytesToHash([]byte("hash"))
hash := common.BytesToHash([]byte("hash"))
req = &types.QueryBlockLogsRequest{
Hash: hash.String(),
}
@@ -445,46 +444,46 @@ func (suite *KeeperTestSuite) TestQueryBlockLogs() {
"success",
func() {
hash := ethcmn.BytesToHash([]byte("block_hash"))
hash := common.BytesToHash([]byte("block_hash"))
expLogs = []types.TransactionLogs{
{
Hash: ethcmn.BytesToHash([]byte("tx_hash_0")).String(),
Hash: common.BytesToHash([]byte("tx_hash_0")).String(),
Logs: []*types.Log{
{
Address: suite.address.String(),
Topics: []string{ethcmn.BytesToHash([]byte("topic")).String()},
Topics: []string{common.BytesToHash([]byte("topic")).String()},
Data: []byte("data"),
BlockNumber: 1,
TxHash: ethcmn.BytesToHash([]byte("tx_hash_0")).String(),
TxHash: common.BytesToHash([]byte("tx_hash_0")).String(),
TxIndex: 1,
BlockHash: ethcmn.BytesToHash([]byte("block_hash")).String(),
BlockHash: common.BytesToHash([]byte("block_hash")).String(),
Index: 0,
Removed: false,
},
},
},
{
Hash: ethcmn.BytesToHash([]byte("tx_hash_1")).String(),
Hash: common.BytesToHash([]byte("tx_hash_1")).String(),
Logs: []*types.Log{
{
Address: suite.address.String(),
Topics: []string{ethcmn.BytesToHash([]byte("topic")).String()},
Topics: []string{common.BytesToHash([]byte("topic")).String()},
Data: []byte("data"),
BlockNumber: 1,
TxHash: ethcmn.BytesToHash([]byte("tx_hash_1")).String(),
TxHash: common.BytesToHash([]byte("tx_hash_1")).String(),
TxIndex: 1,
BlockHash: ethcmn.BytesToHash([]byte("block_hash")).String(),
BlockHash: common.BytesToHash([]byte("block_hash")).String(),
Index: 1,
Removed: false,
},
{
Address: suite.address.String(),
Topics: []string{ethcmn.BytesToHash([]byte("topic_1")).String()},
Topics: []string{common.BytesToHash([]byte("topic_1")).String()},
Data: []byte("data_1"),
BlockNumber: 1,
TxHash: ethcmn.BytesToHash([]byte("tx_hash_1")).String(),
TxHash: common.BytesToHash([]byte("tx_hash_1")).String(),
TxIndex: 1,
BlockHash: ethcmn.BytesToHash([]byte("block_hash")).String(),
BlockHash: common.BytesToHash([]byte("block_hash")).String(),
Index: 2,
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(ethcmn.BytesToHash([]byte("tx_hash_1")), types.LogsToEthereum(expLogs[1].Logs))
suite.app.EvmKeeper.SetLogs(common.BytesToHash([]byte("tx_hash_0")), types.LogsToEthereum(expLogs[0].Logs))
suite.app.EvmKeeper.SetLogs(common.BytesToHash([]byte("tx_hash_1")), types.LogsToEthereum(expLogs[1].Logs))
req = &types.QueryBlockLogsRequest{
Hash: hash.String(),
@@ -618,7 +617,7 @@ func (suite *KeeperTestSuite) TestQueryValidatorAccount() {
{"invalid address",
func() {
expAccount = &types.QueryValidatorAccountResponse{
AccountAddress: sdk.AccAddress(ethcmn.Address{}.Bytes()).String(),
AccountAddress: sdk.AccAddress(common.Address{}.Bytes()).String(),
}
req = &types.QueryValidatorAccountRequest{
ConsAddress: "",
+2 -2
View File
@@ -3,7 +3,7 @@ package keeper
import (
sdk "github.com/cosmos/cosmos-sdk/types"
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"
"github.com/tharsis/ethermint/x/evm/types"
)
@@ -21,7 +21,7 @@ func NewMultiEvmHooks(hooks ...types.EvmHooks) MultiEvmHooks {
}
// 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 {
if err := mh[i].PostTxProcessing(ctx, txHash, logs); err != nil {
return sdkerrors.Wrapf(err, "EVM hook %T failed", mh[i])
+3 -5
View File
@@ -28,11 +28,9 @@ import (
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
ethcmn "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
ethcrypto "github.com/ethereum/go-ethereum/crypto"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto/tmhash"
@@ -72,7 +70,7 @@ type KeeperTestSuite struct {
ctx sdk.Context
app *app.EthermintApp
queryClient types.QueryClient
address ethcmn.Address
address common.Address
consAddress sdk.ConsAddress
// for generate test tx
@@ -90,7 +88,7 @@ func (suite *KeeperTestSuite) DoSetupTest(t require.TestingT) {
// account key
priv, err := ethsecp256k1.GenerateKey()
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)
// consensus key
@@ -130,7 +128,7 @@ func (suite *KeeperTestSuite) DoSetupTest(t require.TestingT) {
acc := &ethermint.EthAccount{
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)
+4 -5
View File
@@ -16,7 +16,6 @@ import (
"github.com/ethereum/go-ethereum/crypto"
"github.com/tharsis/ethermint/tests"
"github.com/tharsis/ethermint/x/evm/types"
evmtypes "github.com/tharsis/ethermint/x/evm/types"
)
func (suite *KeeperTestSuite) TestCreateAccount() {
@@ -533,8 +532,8 @@ func (suite *KeeperTestSuite) TestSnapshot() {
}
}
func (suite *KeeperTestSuite) CreateTestTx(msg *evmtypes.MsgEthereumTx, priv cryptotypes.PrivKey) authsigning.Tx {
option, err := codectypes.NewAnyWithValue(&evmtypes.ExtensionOptionsEthereumTx{})
func (suite *KeeperTestSuite) CreateTestTx(msg *types.MsgEthereumTx, priv cryptotypes.PrivKey) authsigning.Tx {
option, err := codectypes.NewAnyWithValue(&types.ExtensionOptionsEthereumTx{})
suite.Require().NoError(err)
txBuilder := suite.clientCtx.TxConfig.NewTxBuilder()
@@ -558,14 +557,14 @@ func (suite *KeeperTestSuite) TestAddLog() {
msg.From = addr.Hex()
tx := suite.CreateTestTx(msg, privKey)
msg, _ = tx.GetMsgs()[0].(*evmtypes.MsgEthereumTx)
msg, _ = tx.GetMsgs()[0].(*types.MsgEthereumTx)
txHash := msg.AsTransaction().Hash()
msg2 := types.NewTx(big.NewInt(1), 1, &suite.address, big.NewInt(1), 100000, big.NewInt(1), []byte("test"), nil)
msg2.From = addr.Hex()
tx2 := suite.CreateTestTx(msg2, privKey)
msg2, _ = tx2.GetMsgs()[0].(*evmtypes.MsgEthereumTx)
msg2, _ = tx2.GetMsgs()[0].(*types.MsgEthereumTx)
txHash2 := msg2.AsTransaction().Hash()
testCases := []struct {
+4 -4
View File
@@ -1,7 +1,7 @@
package types
import (
ethcmn "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
ethtypes "github.com/ethereum/go-ethereum/core/types"
)
@@ -39,14 +39,14 @@ func (al AccessList) ToEthAccessList() *ethtypes.AccessList {
var ethAccessList ethtypes.AccessList
for _, tuple := range al {
storageKeys := make([]ethcmn.Hash, len(tuple.StorageKeys))
storageKeys := make([]common.Hash, len(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{
Address: ethcmn.HexToAddress(tuple.Address),
Address: common.HexToAddress(tuple.Address),
StorageKeys: storageKeys,
})
}
+7 -8
View File
@@ -3,10 +3,9 @@ package types
import (
"testing"
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/suite"
ethcmn "github.com/ethereum/go-ethereum/common"
"github.com/tharsis/ethermint/crypto/ethsecp256k1"
)
@@ -14,7 +13,7 @@ type GenesisTestSuite struct {
suite.Suite
address string
hash ethcmn.Hash
hash common.Hash
code string
}
@@ -22,9 +21,9 @@ func (suite *GenesisTestSuite) SetupTest() {
priv, err := ethsecp256k1.GenerateKey()
suite.Require().NoError(err)
suite.address = ethcmn.BytesToAddress(priv.PubKey().Address().Bytes()).String()
suite.hash = ethcmn.BytesToHash([]byte("hash"))
suite.code = ethcmn.Bytes2Hex([]byte{1, 2, 3})
suite.address = common.BytesToAddress(priv.PubKey().Address().Bytes()).String()
suite.hash = common.BytesToHash([]byte("hash"))
suite.code = common.Bytes2Hex([]byte{1, 2, 3})
}
func TestGenesisTestSuite(t *testing.T) {
@@ -141,7 +140,7 @@ func (suite *GenesisTestSuite) TestValidateGenesis() {
genState: &GenesisState{
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,
},
+2 -2
View File
@@ -4,7 +4,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/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"
)
@@ -43,5 +43,5 @@ type StakingKeeper interface {
// EvmHooks event hooks for evm tx processing
type EvmHooks interface {
// 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
}
+6 -6
View File
@@ -3,8 +3,8 @@ package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
ethcmn "github.com/ethereum/go-ethereum/common"
ethcrypto "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
)
const (
@@ -73,18 +73,18 @@ func BloomKey(height int64) []byte {
}
// 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()...)
}
// 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...)
}
// KeyAddressStorage returns the key hash to access a given account state. The composite key
// (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()
key := hash.Bytes()
@@ -93,5 +93,5 @@ func KeyAddressStorage(address ethcmn.Address, hash ethcmn.Hash) ethcmn.Hash {
copy(compositeKey, prefix)
copy(compositeKey[len(prefix):], key)
return ethcrypto.Keccak256Hash(compositeKey)
return crypto.Keccak256Hash(compositeKey)
}
+8 -8
View File
@@ -4,14 +4,14 @@ import (
"errors"
"fmt"
ethcmn "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
ethtypes "github.com/ethereum/go-ethereum/core/types"
ethermint "github.com/tharsis/ethermint/types"
)
// 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{
Hash: hash.String(),
Logs: logs,
@@ -19,7 +19,7 @@ func NewTransactionLogs(hash ethcmn.Hash, logs []*Log) TransactionLogs { // noli
}
// 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{
Hash: hash.String(),
Logs: NewLogsFromEth(ethlogs),
@@ -70,20 +70,20 @@ func (log *Log) Validate() error {
// ToEthereum returns the Ethereum type Log from a Ethermint proto compatible Log.
func (log *Log) ToEthereum() *ethtypes.Log {
var topics []ethcmn.Hash // nolint: prealloc
var topics []common.Hash // nolint: prealloc
for i := range log.Topics {
topics = append(topics, ethcmn.HexToHash(log.Topics[i]))
topics = append(topics, common.HexToHash(log.Topics[i]))
}
return &ethtypes.Log{
Address: ethcmn.HexToAddress(log.Address),
Address: common.HexToAddress(log.Address),
Topics: topics,
Data: log.Data,
BlockNumber: log.BlockNumber,
TxHash: ethcmn.HexToHash(log.TxHash),
TxHash: common.HexToHash(log.TxHash),
TxIndex: uint(log.TxIndex),
Index: uint(log.Index),
BlockHash: ethcmn.HexToHash(log.BlockHash),
BlockHash: common.HexToHash(log.BlockHash),
Removed: log.Removed,
}
}
+22 -22
View File
@@ -7,14 +7,14 @@ import (
"github.com/tharsis/ethermint/crypto/ethsecp256k1"
ethcmn "github.com/ethereum/go-ethereum/common"
ethcrypto "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
)
func TestTransactionLogsValidate(t *testing.T) {
priv, err := ethsecp256k1.GenerateKey()
require.NoError(t, err)
addr := ethcrypto.PubkeyToAddress(priv.ToECDSA().PublicKey).String()
addr := crypto.PubkeyToAddress(priv.ToECDSA().PublicKey).String()
testCases := []struct {
name string
@@ -24,16 +24,16 @@ func TestTransactionLogsValidate(t *testing.T) {
{
"valid log",
TransactionLogs{
Hash: ethcmn.BytesToHash([]byte("tx_hash")).String(),
Hash: common.BytesToHash([]byte("tx_hash")).String(),
Logs: []*Log{
{
Address: addr,
Topics: []string{ethcmn.BytesToHash([]byte("topic")).String()},
Topics: []string{common.BytesToHash([]byte("topic")).String()},
Data: []byte("data"),
BlockNumber: 1,
TxHash: ethcmn.BytesToHash([]byte("tx_hash")).String(),
TxHash: common.BytesToHash([]byte("tx_hash")).String(),
TxIndex: 1,
BlockHash: ethcmn.BytesToHash([]byte("block_hash")).String(),
BlockHash: common.BytesToHash([]byte("block_hash")).String(),
Index: 1,
Removed: false,
},
@@ -44,14 +44,14 @@ func TestTransactionLogsValidate(t *testing.T) {
{
"empty hash",
TransactionLogs{
Hash: ethcmn.Hash{}.String(),
Hash: common.Hash{}.String(),
},
false,
},
{
"invalid log",
TransactionLogs{
Hash: ethcmn.BytesToHash([]byte("tx_hash")).String(),
Hash: common.BytesToHash([]byte("tx_hash")).String(),
Logs: []*Log{{}},
},
false,
@@ -59,16 +59,16 @@ func TestTransactionLogsValidate(t *testing.T) {
{
"hash mismatch log",
TransactionLogs{
Hash: ethcmn.BytesToHash([]byte("tx_hash")).String(),
Hash: common.BytesToHash([]byte("tx_hash")).String(),
Logs: []*Log{
{
Address: addr,
Topics: []string{ethcmn.BytesToHash([]byte("topic")).String()},
Topics: []string{common.BytesToHash([]byte("topic")).String()},
Data: []byte("data"),
BlockNumber: 1,
TxHash: ethcmn.BytesToHash([]byte("other_hash")).String(),
TxHash: common.BytesToHash([]byte("other_hash")).String(),
TxIndex: 1,
BlockHash: ethcmn.BytesToHash([]byte("block_hash")).String(),
BlockHash: common.BytesToHash([]byte("block_hash")).String(),
Index: 1,
Removed: false,
},
@@ -92,7 +92,7 @@ func TestTransactionLogsValidate(t *testing.T) {
func TestValidateLog(t *testing.T) {
priv, err := ethsecp256k1.GenerateKey()
require.NoError(t, err)
addr := ethcrypto.PubkeyToAddress(priv.ToECDSA().PublicKey).String()
addr := crypto.PubkeyToAddress(priv.ToECDSA().PublicKey).String()
testCases := []struct {
name string
@@ -103,12 +103,12 @@ func TestValidateLog(t *testing.T) {
"valid log",
&Log{
Address: addr,
Topics: []string{ethcmn.BytesToHash([]byte("topic")).String()},
Topics: []string{common.BytesToHash([]byte("topic")).String()},
Data: []byte("data"),
BlockNumber: 1,
TxHash: ethcmn.BytesToHash([]byte("tx_hash")).String(),
TxHash: common.BytesToHash([]byte("tx_hash")).String(),
TxIndex: 1,
BlockHash: ethcmn.BytesToHash([]byte("block_hash")).String(),
BlockHash: common.BytesToHash([]byte("block_hash")).String(),
Index: 1,
Removed: false,
},
@@ -120,7 +120,7 @@ func TestValidateLog(t *testing.T) {
{
"zero address",
&Log{
Address: ethcmn.Address{}.String(),
Address: common.Address{}.String(),
},
false,
},
@@ -128,7 +128,7 @@ func TestValidateLog(t *testing.T) {
"empty block hash",
&Log{
Address: addr,
BlockHash: ethcmn.Hash{}.String(),
BlockHash: common.Hash{}.String(),
},
false,
},
@@ -136,7 +136,7 @@ func TestValidateLog(t *testing.T) {
"zero block number",
&Log{
Address: addr,
BlockHash: ethcmn.BytesToHash([]byte("block_hash")).String(),
BlockHash: common.BytesToHash([]byte("block_hash")).String(),
BlockNumber: 0,
},
false,
@@ -145,9 +145,9 @@ func TestValidateLog(t *testing.T) {
"empty tx hash",
&Log{
Address: addr,
BlockHash: ethcmn.BytesToHash([]byte("block_hash")).String(),
BlockHash: common.BytesToHash([]byte("block_hash")).String(),
BlockNumber: 1,
TxHash: ethcmn.Hash{}.String(),
TxHash: common.Hash{}.String(),
},
false,
},
+18 -20
View File
@@ -12,9 +12,7 @@ import (
"github.com/tharsis/ethermint/tests"
"github.com/ethereum/go-ethereum/common"
ethcmn "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
)
@@ -24,8 +22,8 @@ type MsgsTestSuite struct {
suite.Suite
signer keyring.Signer
from ethcmn.Address
to ethcmn.Address
from common.Address
to common.Address
chainID *big.Int
}
@@ -74,12 +72,12 @@ func (suite *MsgsTestSuite) TestMsgEthereumTx_ValidateBasic() {
amount *sdk.Int
gasPrice *sdk.Int
from string
accessList *ethtypes.AccessList
accessList *types.AccessList
chainID *sdk.Int
expectPass bool
}{
{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: "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},
@@ -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: "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: "nil amount - AccessListTx", to: suite.to.Hex(), amount: nil, gasPrice: &hundredInt, accessList: &ethtypes.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: "nil gas price - AccessListTx", to: suite.to.Hex(), amount: &hundredInt, gasPrice: nil, accessList: &ethtypes.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: "zero gas price - AccessListTx", to: suite.to.Hex(), amount: &hundredInt, gasPrice: &zeroInt, accessList: &ethtypes.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: "chain ID not set on AccessListTx", to: suite.to.Hex(), amount: &hundredInt, gasPrice: &zeroInt, accessList: &ethtypes.AccessList{}, chainID: nil, expectPass: false},
{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: &types.AccessList{}, chainID: nil, 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: &types.AccessList{}, chainID: nil, expectPass: false},
{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: &types.AccessList{}, chainID: &hundredInt, 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 {
@@ -128,49 +126,49 @@ func (suite *MsgsTestSuite) TestMsgEthereumTx_Sign() {
testCases := []struct {
msg string
tx *MsgEthereumTx
ethSigner ethtypes.Signer
ethSigner types.Signer
malleate func(tx *MsgEthereumTx)
expectPass bool
}{
{
"pass - EIP2930 signer",
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() },
true,
},
{
"pass - EIP155 signer",
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() },
true,
},
{
"pass - Homestead signer",
NewTx(suite.chainID, 0, &suite.to, nil, 100000, nil, []byte("test"), nil),
ethtypes.HomesteadSigner{},
types.HomesteadSigner{},
func(tx *MsgEthereumTx) { tx.From = suite.from.Hex() },
true,
},
{
"pass - Frontier signer",
NewTx(suite.chainID, 0, &suite.to, nil, 100000, nil, []byte("test"), nil),
ethtypes.FrontierSigner{},
types.FrontierSigner{},
func(tx *MsgEthereumTx) { tx.From = suite.from.Hex() },
true,
},
{
"no from address ",
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 = "" },
false,
},
{
"from address ≠ signer address",
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() },
false,
},
+2 -3
View File
@@ -4,10 +4,9 @@ import (
"fmt"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/ethereum/go-ethereum/common"
"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
@@ -59,7 +58,7 @@ func (s State) Validate() error {
}
// 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{
Key: key.String(),
Value: value.String(),
+8 -9
View File
@@ -3,9 +3,8 @@ package types
import (
"testing"
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"
ethcmn "github.com/ethereum/go-ethereum/common"
)
func TestStorageValidate(t *testing.T) {
@@ -17,22 +16,22 @@ func TestStorageValidate(t *testing.T) {
{
"valid 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,
},
{
"empty storage key bytes",
Storage{
{Key: ethcmn.Hash{}.String()},
{Key: common.Hash{}.String()},
},
false,
},
{
"duplicated storage key",
Storage{
{Key: ethcmn.BytesToHash([]byte{1, 2, 3}).String()},
{Key: ethcmn.BytesToHash([]byte{1, 2, 3}).String()},
{Key: common.BytesToHash([]byte{1, 2, 3}).String()},
{Key: common.BytesToHash([]byte{1, 2, 3}).String()},
},
false,
},
@@ -57,13 +56,13 @@ func TestStorageCopy(t *testing.T) {
{
"single 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",
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) {
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"
require.Equal(t, str, storage.String())
}
+3 -4
View File
@@ -17,18 +17,17 @@ import (
"github.com/stretchr/testify/require"
"github.com/ethereum/go-ethereum/common"
ethcmn "github.com/ethereum/go-ethereum/common"
ethcrypto "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto"
)
// GenerateEthAddress generates an Ethereum address.
func GenerateEthAddress() ethcmn.Address {
func GenerateEthAddress() common.Address {
priv, err := ethsecp256k1.GenerateKey()
if err != nil {
panic(err)
}
return ethcrypto.PubkeyToAddress(priv.ToECDSA().PublicKey)
return crypto.PubkeyToAddress(priv.ToECDSA().PublicKey)
}
func TestEvmDataEncoding(t *testing.T) {