crypto: updates from reviews (#535)

This commit is contained in:
Federico Kunze Küllmer
2021-09-07 17:29:24 +00:00
committed by GitHub
parent c3f70aeaf7
commit 2e45a0665e
12 changed files with 71 additions and 70 deletions
+3 -8
View File
@@ -5,16 +5,13 @@ import (
"github.com/stretchr/testify/require"
"github.com/tharsis/ethermint/crypto/ethsecp256k1"
"github.com/tharsis/ethermint/tests"
"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 := crypto.PubkeyToAddress(priv.ToECDSA().PublicKey).String()
addr := tests.GenerateAddress().String()
testCases := []struct {
name string
@@ -90,9 +87,7 @@ func TestTransactionLogsValidate(t *testing.T) {
}
func TestValidateLog(t *testing.T) {
priv, err := ethsecp256k1.GenerateKey()
require.NoError(t, err)
addr := crypto.PubkeyToAddress(priv.ToECDSA().PublicKey).String()
addr := tests.GenerateAddress().String()
testCases := []struct {
name string
+3 -9
View File
@@ -8,12 +8,10 @@ import (
"github.com/cosmos/cosmos-sdk/crypto/keyring"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/tharsis/ethermint/crypto/ethsecp256k1"
"github.com/tharsis/ethermint/tests"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
)
const invalidFromAddress = "0x0000"
@@ -32,15 +30,11 @@ func TestMsgsTestSuite(t *testing.T) {
}
func (suite *MsgsTestSuite) SetupTest() {
privFrom, err := ethsecp256k1.GenerateKey()
suite.Require().NoError(err)
privTo, err := ethsecp256k1.GenerateKey()
suite.Require().NoError(err)
from, privFrom := tests.NewAddrKey()
suite.signer = tests.NewSigner(privFrom)
suite.from = crypto.PubkeyToAddress(privFrom.ToECDSA().PublicKey)
suite.to = crypto.PubkeyToAddress(privTo.ToECDSA().PublicKey)
suite.from = from
suite.to = tests.GenerateAddress()
suite.chainID = big.NewInt(1)
}
-12
View File
@@ -10,26 +10,14 @@ import (
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
proto "github.com/gogo/protobuf/proto"
"github.com/tharsis/ethermint/app"
"github.com/tharsis/ethermint/crypto/ethsecp256k1"
"github.com/tharsis/ethermint/encoding"
evmtypes "github.com/tharsis/ethermint/x/evm/types"
"github.com/stretchr/testify/require"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
)
// GenerateEthAddress generates an Ethereum address.
func GenerateEthAddress() common.Address {
priv, err := ethsecp256k1.GenerateKey()
if err != nil {
panic(err)
}
return crypto.PubkeyToAddress(priv.ToECDSA().PublicKey)
}
func TestEvmDataEncoding(t *testing.T) {
ret := []byte{0x5, 0x8}