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
+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) {