Skip to content

Commit

Permalink
Check for keyname entry in keystore map
Browse files Browse the repository at this point in the history
  • Loading branch information
misko9 committed Aug 15, 2024
1 parent fb0d472 commit ab52723
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
25 changes: 21 additions & 4 deletions chain/ethereum/ethererum_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import (
"strconv"
"strings"

"github.com/ethereum/go-ethereum/common/hexutil"
sdkmath "cosmossdk.io/math"
dockertypes "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/mount"
"github.com/docker/docker/api/types/volume"
dockerclient "github.com/docker/docker/client"
"github.com/docker/go-connections/nat"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/strangelove-ventures/interchaintest/v8/dockerutil"
"github.com/strangelove-ventures/interchaintest/v8/ibc"
"github.com/strangelove-ventures/interchaintest/v8/testutil"
Expand Down Expand Up @@ -299,6 +299,11 @@ func (c *EthereumChain) CreateKey(ctx context.Context, keyName string) error {
return err
}

_, ok := c.keystoreMap[keyName]
if ok {
return fmt.Errorf("Keyname (%s) already used", keyName)
}

cmd := []string{"cast", "wallet", "new", c.KeystoreDir(), "--unsafe-password", "", "--json"}
stdout, _, err := c.Exec(ctx, cmd, nil)
if err != nil {
Expand All @@ -318,8 +323,12 @@ func (c *EthereumChain) CreateKey(ctx context.Context, keyName string) error {

// Get address of account, cast to a string to use
func (c *EthereumChain) GetAddress(ctx context.Context, keyName string) ([]byte, error) {
keystore, ok := c.keystoreMap[keyName]
if !ok {
return nil, fmt.Errorf("Keyname (%s) not found", keyName)
}

cmd := []string{"cast", "wallet", "address", "--keystore", c.keystoreMap[keyName], "--password", ""}
cmd := []string{"cast", "wallet", "address", "--keystore", keystore, "--password", ""}
stdout, _, err := c.Exec(ctx, cmd, nil)
if err != nil {
return nil, err
Expand All @@ -336,8 +345,12 @@ func (c *EthereumChain) SendFunds(ctx context.Context, keyName string, amount ib
)

} else {
keystore, ok := c.keystoreMap[keyName]
if !ok {
return fmt.Errorf("keyname (%s) not found", keyName)
}
cmd = append(cmd,
"--keystore", c.keystoreMap[keyName],
"--keystore", keystore,
"--password", "",
"--rpc-url", c.GetRPCAddress(),
)
Expand All @@ -359,8 +372,12 @@ func (c *EthereumChain) SendFundsWithNote(ctx context.Context, keyName string, a
)

} else {
keystore, ok := c.keystoreMap[keyName]
if !ok {
return "", fmt.Errorf("Keyname (%s) not found", keyName)
}
cmd = append(cmd,
"--keystore", c.keystoreMap[keyName],
"--keystore", keystore,
"--password", "",
"--rpc-url", c.GetRPCAddress(),
)
Expand Down
3 changes: 2 additions & 1 deletion examples/ethereum/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,12 @@ func TestEthereum(t *testing.T) {

// Fund user2 wallet using SendFunds() from user1 wallet
ethUser2InitialAmount := math.NewInt(ethereum.ETHER)
ethereumChain.SendFunds(ctx, ethUser.KeyName(), ibc.WalletAmount{
err = ethereumChain.SendFunds(ctx, ethUser.KeyName(), ibc.WalletAmount{
Address: ethUser2.FormattedAddress(),
Denom: ethereumChain.Config().Denom,
Amount: ethUser2InitialAmount,
})
require.NoError(t, err)

// Final check of balances
balance, err = ethereumChain.GetBalance(ctx, faucetAddr, "")
Expand Down

0 comments on commit ab52723

Please sign in to comment.