Skip to content

Commit

Permalink
core/cmd: keys eth list: print Unknown/None instead of <nil> (#11724)
Browse files Browse the repository at this point in the history
Co-authored-by: Vyzaldy Sanchez <[email protected]>
  • Loading branch information
jmank88 and vyzaldysanchez authored Jan 10, 2024
1 parent 2a20248 commit 1567a11
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 5 deletions.
18 changes: 15 additions & 3 deletions core/cmd/eth_keys_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,27 @@ type EthKeyPresenter struct {
}

func (p *EthKeyPresenter) ToRow() []string {
eth := "Unknown"
if p.EthBalance != nil {
eth = p.EthBalance.String()
}
link := "Unknown"
if p.LinkBalance != nil {
link = p.LinkBalance.String()
}
gas := "None"
if p.MaxGasPriceWei != nil {
gas = p.MaxGasPriceWei.String()
}
return []string{
p.Address,
p.EVMChainID.String(),
p.EthBalance.String(),
p.LinkBalance.String(),
eth,
link,
fmt.Sprintf("%v", p.Disabled),
p.CreatedAt.String(),
p.UpdatedAt.String(),
p.MaxGasPriceWei.String(),
gas,
}
}

Expand Down
4 changes: 2 additions & 2 deletions core/cmd/eth_keys_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ func TestShell_ListETHKeys_Disabled(t *testing.T) {
assert.Nil(t, balances[0].LinkBalance)
assert.Nil(t, balances[0].MaxGasPriceWei)
assert.Equal(t, []string{
k.Address.String(), "0", "<nil>", "0", "false",
balances[0].UpdatedAt.String(), balances[0].CreatedAt.String(), "<nil>",
k.Address.String(), "0", "Unknown", "Unknown", "false",
balances[0].UpdatedAt.String(), balances[0].CreatedAt.String(), "None",
}, balances[0].ToRow())
}

Expand Down
14 changes: 14 additions & 0 deletions testdata/scripts/keys/eth/create/help.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
exec chainlink keys eth create --help
cmp stdout out.txt

-- out.txt --
NAME:
chainlink keys eth create - Create a key in the node's keystore alongside the existing key; to create an original key, just run the node

USAGE:
chainlink keys eth create [command options] [arguments...]

OPTIONS:
--evm-chain-id value, --evmChainID value Chain ID for the key. If left blank, default chain will be used.
--max-gas-price-gwei value, --maxGasPriceGWei value Optional maximum gas price (GWei) for the creating key. (default: 0)

9 changes: 9 additions & 0 deletions testdata/scripts/keys/eth/list/help.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
exec chainlink keys eth list --help
cmp stdout out.txt

-- out.txt --
NAME:
chainlink keys eth list - List available Ethereum accounts with their ETH & LINK balances and other metadata

USAGE:
chainlink keys eth list [arguments...]
38 changes: 38 additions & 0 deletions testdata/scripts/keys/eth/list/unavailable.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# start node
exec sh -c 'eval "echo \"$(cat config.toml.tmpl)\" > config.toml"'
exec chainlink node -c config.toml start -p password -a creds &

# initialize client
env NODEURL=http://localhost:$PORT
exec curl --retry 10 --retry-max-time 60 --retry-connrefused $NODEURL
exec chainlink --remote-node-url $NODEURL admin login -file creds --bypass-version-check

exec chainlink --remote-node-url $NODEURL keys eth list
! stdout 'ETH: <nil>'
! stdout 'LINK: <nil>'
! stdout '<nil>'
stdout 'ETH: Unknown'
stdout 'LINK: Unknown'

-- testdb.txt --
CL_DATABASE_URL
-- testport.txt --
PORT

-- password --
T.tLHkcmwePT/p,]sYuntjwHKAsrhm#4eRs4LuKHwvHejWYAC2JP4M8HimwgmbaZ
-- creds --
[email protected]
fj293fbBnlQ!f9vNs

-- config.toml.tmpl --
[Webserver]
HTTPPort = $PORT

[[EVM]]
ChainID = '99'

[[EVM.Nodes]]
Name = 'fake'
WSURL = 'wss://foo.bar/ws'
HTTPURL = 'https://foo.bar'

0 comments on commit 1567a11

Please sign in to comment.