Skip to content

Commit d5465e0

Browse files
committed
Read primary ETH key based on chain id
1 parent ea4ffd8 commit d5465e0

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

framework/clclient/client.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,15 +557,20 @@ func (c *ChainlinkClient) UpdateEthKeyMaxGasPriceGWei(keyId string, gWei int) (*
557557
}
558558

559559
// ReadPrimaryETHKey reads updated information about the Chainlink's primary ETH key
560-
func (c *ChainlinkClient) ReadPrimaryETHKey() (*ETHKeyData, error) {
560+
func (c *ChainlinkClient) ReadPrimaryETHKey(chainId string) (*ETHKeyData, error) {
561561
ethKeys, err := c.MustReadETHKeys()
562562
if err != nil {
563563
return nil, err
564564
}
565565
if len(ethKeys.Data) == 0 {
566566
return nil, fmt.Errorf("Error retrieving primary eth key on node %s: No ETH keys present", c.URL())
567567
}
568-
return &ethKeys.Data[0], nil
568+
for _, data := range ethKeys.Data {
569+
if data.Attributes.ChainID == chainId {
570+
return &data, nil
571+
}
572+
}
573+
return nil, fmt.Errorf("error retrieving primary eth key on node %s: No ETH keys present for chain %s", c.URL(), chainId)
569574
}
570575

571576
// ReadETHKeyAtIndex reads updated information about the Chainlink's ETH key at given index

framework/components/simple_node_set/fund.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/ethereum/go-ethereum/core/types"
1111
"github.com/ethereum/go-ethereum/crypto"
1212
"github.com/ethereum/go-ethereum/ethclient"
13+
er "github.com/pkg/errors"
1314
"github.com/smartcontractkit/chainlink-testing-framework/framework"
1415
"github.com/smartcontractkit/chainlink-testing-framework/framework/clclient"
1516
"math/big"
@@ -18,7 +19,7 @@ import (
1819
func SendETH(client *ethclient.Client, privateKeyHex string, toAddress string, amount *big.Float) error {
1920
privateKey, err := crypto.HexToECDSA(privateKeyHex)
2021
if err != nil {
21-
return fmt.Errorf("failed to parse private key: %v", err)
22+
return er.Wrap(err, "failed to parse private key")
2223
}
2324
wei := new(big.Int)
2425
amountWei := new(big.Float).Mul(amount, big.NewFloat(1e18))
@@ -33,29 +34,29 @@ func SendETH(client *ethclient.Client, privateKeyHex string, toAddress string, a
3334

3435
nonce, err := client.PendingNonceAt(context.Background(), fromAddress)
3536
if err != nil {
36-
return fmt.Errorf("failed to fetch nonce: %v", err)
37+
return er.Wrap(err, "failed to fetch nonce")
3738
}
3839

3940
gasPrice, err := client.SuggestGasPrice(context.Background())
4041
if err != nil {
41-
return fmt.Errorf("failed to fetch gas price: %v", err)
42+
return er.Wrap(err, "failed to fetch gas price")
4243
}
4344
gasLimit := uint64(21000) // Standard gas limit for ETH transfer
4445

4546
tx := types.NewTransaction(nonce, common.HexToAddress(toAddress), wei, gasLimit, gasPrice, nil)
4647

4748
chainID, err := client.NetworkID(context.Background())
4849
if err != nil {
49-
return fmt.Errorf("failed to fetch chain ID: %v", err)
50+
return er.Wrap(err, "failed to fetch chain ID")
5051
}
5152
signedTx, err := types.SignTx(tx, types.NewEIP155Signer(chainID), privateKey)
5253
if err != nil {
53-
return fmt.Errorf("failed to sign transaction: %v", err)
54+
return er.Wrap(err, "failed to sign transaction")
5455
}
5556

5657
err = client.SendTransaction(context.Background(), signedTx)
5758
if err != nil {
58-
return fmt.Errorf("failed to send transaction: %v", err)
59+
return er.Wrap(err, "failed to send transaction")
5960
}
6061
framework.L.Info().Msgf("Transaction sent: %s", signedTx.Hash().Hex())
6162
_, err = bind.WaitMined(context.Background(), client, signedTx)
@@ -67,13 +68,17 @@ func FundNodes(c *ethclient.Client, nodes []*clclient.ChainlinkClient, pkey stri
6768
if ethAmount == 0 {
6869
return errors.New("funds_eth is 0, set some value in config, ex.: funds_eth = 30.0")
6970
}
71+
chainID, err := c.ChainID(context.Background())
72+
if err != nil {
73+
return er.Wrap(err, "failed to fetch chain ID")
74+
}
7075
for _, cl := range nodes {
71-
ek, err := cl.ReadPrimaryETHKey()
76+
ek, err := cl.ReadPrimaryETHKey(chainID.String())
7277
if err != nil {
7378
return err
7479
}
7580
if err := SendETH(c, pkey, ek.Attributes.Address, big.NewFloat(ethAmount)); err != nil {
76-
return fmt.Errorf("failed to fund CL node %s: %w", ek.Attributes.Address, err)
81+
return er.Wrapf(err, "failed to fund CL node %s", ek.Attributes.Address)
7782
}
7883
}
7984
return nil

0 commit comments

Comments
 (0)