Skip to content

Commit

Permalink
use eth_secp256k1 keyring
Browse files Browse the repository at this point in the history
  • Loading branch information
gartnera committed Jun 18, 2024
1 parent 9dddbdd commit 50acbd1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 25 deletions.
2 changes: 1 addition & 1 deletion cmd/zetae2e/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func RunnerFromConfig(
zetaTxServer, err := txserver.NewZetaTxServer(
conf.RPCs.ZetaCoreRPC,
[]string{zetaUserName},
[]string{account.RawPrivateKey.String()},
[]string{conf.AdditionalAccounts.UserAdmin.RawPrivateKey.String()},
conf.ZetaChainID,
)
if err != nil {
Expand Down
11 changes: 0 additions & 11 deletions cmd/zetae2e/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ package config
import (
"testing"

"github.com/cosmos/cosmos-sdk/crypto/hd"
sdktypes "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"

"github.com/zeta-chain/zetacore/e2e/config"
Expand Down Expand Up @@ -38,14 +35,6 @@ func TestReadConfig(t *testing.T) {
require.NoError(t, err)
require.NotEmpty(t, conf.Accounts.Deployer.RawEVMAddress)
require.NotEmpty(t, conf.Accounts.Deployer.RawPrivateKey)

// this test is passing, but a different key is derived by the txserver at runtime
if conf.FungibleAdminMnemonic != "" {
derivedPriv, err := hd.Secp256k1.Derive()(conf.FungibleAdminMnemonic, "", sdktypes.FullFundraiserPath)
require.NoError(t, err)
privKey := hd.Secp256k1.Generate()(derivedPriv)
require.Equal(t, common.Bytes2Hex(privKey.Bytes()), conf.AdditionalAccounts.UserAdmin.RawPrivateKey.String())
}
})
}
}
11 changes: 5 additions & 6 deletions e2e/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,11 @@ func (s DoubleQuotedString) AsEVMAddress() (ethcommon.Address, error) {

// Config contains the configuration for the e2e test
type Config struct {
Accounts Accounts `yaml:"accounts"`
AdditionalAccounts AdditionalAccounts `yaml:"additional_accounts"`
RPCs RPCs `yaml:"rpcs"`
Contracts Contracts `yaml:"contracts"`
ZetaChainID string `yaml:"zeta_chain_id"`
FungibleAdminMnemonic string `yaml:"fungible_admin_mnemonic"`
Accounts Accounts `yaml:"accounts"`
AdditionalAccounts AdditionalAccounts `yaml:"additional_accounts"`
RPCs RPCs `yaml:"rpcs"`
Contracts Contracts `yaml:"contracts"`
ZetaChainID string `yaml:"zeta_chain_id"`
}

// Account contains configuration for an account
Expand Down
20 changes: 13 additions & 7 deletions e2e/txserver/zeta_tx_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ import (
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
ethcommon "github.com/ethereum/go-ethereum/common"
"github.com/evmos/ethermint/crypto/hd"
etherminttypes "github.com/evmos/ethermint/types"
evmtypes "github.com/evmos/ethermint/x/evm/types"

"github.com/zeta-chain/zetacore/app"
"github.com/zeta-chain/zetacore/cmd/zetacored/config"
"github.com/zeta-chain/zetacore/pkg/chains"
"github.com/zeta-chain/zetacore/pkg/coin"
Expand Down Expand Up @@ -85,20 +87,23 @@ func NewZetaTxServer(rpcAddr string, names []string, privateKeys []string, chain
cdc, reg := newCodec()

// initialize keyring
kr := keyring.NewInMemory(cdc)
kr := keyring.NewInMemory(cdc, hd.EthSecp256k1Option())

addresses := make([]string, 0, len(names))

// create accounts
for i := range names {
err = kr.ImportPrivKeyHex(names[i], privateKeys[i], "secp256k1")
err = kr.ImportPrivKeyHex(names[i], privateKeys[i], string(hd.EthSecp256k1Type))
if err != nil {
return ZetaTxServer{}, fmt.Errorf("failed to create account: %s", err.Error())
return ZetaTxServer{}, fmt.Errorf("failed to create account: %w", err)
}
r, err := kr.Key(names[i])
if err != nil {
return ZetaTxServer{}, fmt.Errorf("failed to get account key: %w", err)
}
accAddr, err := r.GetAddress()
if err != nil {
return ZetaTxServer{}, fmt.Errorf("failed to get account address: %s", err.Error())
return ZetaTxServer{}, fmt.Errorf("failed to get account address: %w", err)
}

addresses = append(addresses, accAddr.String())
Expand Down Expand Up @@ -245,11 +250,11 @@ func (zts ZetaTxServer) EnableHeaderVerification(account string, chainIDList []i
// retrieve account
acc, err := zts.clientCtx.Keyring.Key(account)
if err != nil {
return err
return fmt.Errorf("keyring: %w", err)
}
addr, err := acc.GetAddress()
if err != nil {
return err
return fmt.Errorf("get address: %w", err)
}

_, err = zts.BroadcastTx(account, lightclienttypes.NewMsgEnableHeaderVerification(
Expand Down Expand Up @@ -414,7 +419,8 @@ func (zts ZetaTxServer) FundEmissionsPool(account string, amount *big.Int) error

// newCodec returns the codec for msg server
func newCodec() (*codec.ProtoCodec, codectypes.InterfaceRegistry) {
interfaceRegistry := codectypes.NewInterfaceRegistry()
encodingConfig := app.MakeEncodingConfig()
interfaceRegistry := encodingConfig.InterfaceRegistry
cdc := codec.NewProtoCodec(interfaceRegistry)

sdktypes.RegisterInterfaces(interfaceRegistry)
Expand Down

0 comments on commit 50acbd1

Please sign in to comment.