Skip to content

Commit

Permalink
Fix nodes list command display (smartcontractkit#9558)
Browse files Browse the repository at this point in the history
  • Loading branch information
george-dorin authored Jun 13, 2023
1 parent 5c0ac38 commit 8814c69
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 8 deletions.
2 changes: 1 addition & 1 deletion core/cmd/cosmos_node_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type CosmosNodePresenter struct {

// ToRow presents the CosmosNodeResource as a slice of strings.
func (p *CosmosNodePresenter) ToRow() []string {
return []string{p.GetID(), p.Name, p.ChainID, p.State, p.Config}
return []string{p.Name, p.ChainID, p.State, p.Config}
}

// RenderTable implements TableRenderer
Expand Down
21 changes: 17 additions & 4 deletions core/cmd/cosmos_node_commands_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package cmd_test

import (
"bytes"
"strings"
"testing"

"github.com/pelletier/go-toml/v2"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

coscfg "github.com/smartcontractkit/chainlink-cosmos/pkg/cosmos/config"
"github.com/smartcontractkit/chainlink-relay/pkg/utils"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink/v2/core/services/chainlink"

Expand Down Expand Up @@ -43,7 +44,6 @@ func TestShell_IndexCosmosNodes(t *testing.T) {
}
app := cosmosStartNewApplication(t, &chain)
client, r := app.NewShellAndRenderer()

require.Nil(t, cmd.NewCosmosNodeClient(client).IndexNodes(cltest.EmptyCLIContext()))
require.NotEmpty(t, r.Renders)
nodes := *r.Renders[0].(*cmd.CosmosNodePresenters)
Expand All @@ -56,4 +56,17 @@ func TestShell_IndexCosmosNodes(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, string(wantConfig), n.Config)
assertTableRenders(t, r)

//Render table and check the fields order
b := new(bytes.Buffer)
rt := cmd.RendererTable{b}
nodes.RenderTable(rt)
renderLines := strings.Split(b.String(), "\n")
assert.Equal(t, 7, len(renderLines))
assert.Contains(t, renderLines[1], "Name")
assert.Contains(t, renderLines[1], n.Name)
assert.Contains(t, renderLines[2], "Chain ID")
assert.Contains(t, renderLines[2], n.ChainID)
assert.Contains(t, renderLines[3], "State")
assert.Contains(t, renderLines[3], n.State)
}
2 changes: 1 addition & 1 deletion core/cmd/evm_node_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type EVMNodePresenter struct {

// ToRow presents the EVMNodeResource as a slice of strings.
func (p *EVMNodePresenter) ToRow() []string {
return []string{p.GetID(), p.Name, p.ChainID, p.State, p.Config}
return []string{p.Name, p.ChainID, p.State, p.Config}
}

// RenderTable implements TableRenderer
Expand Down
22 changes: 22 additions & 0 deletions core/cmd/evm_node_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd_test

import (
"bytes"
"strings"
"testing"

"github.com/pelletier/go-toml/v2"
Expand Down Expand Up @@ -33,12 +34,14 @@ func TestShell_IndexEVMNodes(t *testing.T) {
WSURL: models.MustParseURL("ws://localhost:8546"),
HTTPURL: models.MustParseURL("http://localhost:8546"),
SendOnly: ptr(false),
Order: ptr(int32(15)),
}
node2 := evmcfg.Node{
Name: ptr("Test node 2"),
WSURL: models.MustParseURL("ws://localhost:8547"),
HTTPURL: models.MustParseURL("http://localhost:8547"),
SendOnly: ptr(false),
Order: ptr(int32(36)),
}
chain := evmcfg.EVMConfig{
ChainID: chainID,
Expand Down Expand Up @@ -69,4 +72,23 @@ func TestShell_IndexEVMNodes(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, string(wantConfig2), n2.Config)
assertTableRenders(t, r)

//Render table and check the fields order
b := new(bytes.Buffer)
rt := cmd.RendererTable{b}
nodes.RenderTable(rt)
renderLines := strings.Split(b.String(), "\n")
assert.Equal(t, 20, len(renderLines))
assert.Contains(t, renderLines[1], "Name")
assert.Contains(t, renderLines[1], n1.Name)
assert.Contains(t, renderLines[2], "Chain ID")
assert.Contains(t, renderLines[2], n1.ChainID)
assert.Contains(t, renderLines[3], "State")
assert.Contains(t, renderLines[3], n1.State)
assert.Contains(t, renderLines[11], "Name")
assert.Contains(t, renderLines[11], n2.Name)
assert.Contains(t, renderLines[12], "Chain ID")
assert.Contains(t, renderLines[12], n2.ChainID)
assert.Contains(t, renderLines[13], "State")
assert.Contains(t, renderLines[13], n2.State)
}
2 changes: 1 addition & 1 deletion core/cmd/solana_node_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type SolanaNodePresenter struct {

// ToRow presents the SolanaNodeResource as a slice of strings.
func (p *SolanaNodePresenter) ToRow() []string {
return []string{p.GetID(), p.Name, p.ChainID, p.State, p.Config}
return []string{p.Name, p.ChainID, p.State, p.Config}
}

// RenderTable implements TableRenderer
Expand Down
21 changes: 21 additions & 0 deletions core/cmd/solana_node_commands_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package cmd_test

import (
"bytes"
"strings"
"testing"

"github.com/pelletier/go-toml/v2"
Expand Down Expand Up @@ -66,4 +68,23 @@ func TestShell_IndexSolanaNodes(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, string(wantConfig2), n2.Config)
assertTableRenders(t, r)

//Render table and check the fields order
b := new(bytes.Buffer)
rt := cmd.RendererTable{b}
nodes.RenderTable(rt)
renderLines := strings.Split(b.String(), "\n")
assert.Equal(t, 14, len(renderLines))
assert.Contains(t, renderLines[1], "Name")
assert.Contains(t, renderLines[1], n1.Name)
assert.Contains(t, renderLines[2], "Chain ID")
assert.Contains(t, renderLines[2], n1.ChainID)
assert.Contains(t, renderLines[3], "State")
assert.Contains(t, renderLines[3], n1.State)
assert.Contains(t, renderLines[8], "Name")
assert.Contains(t, renderLines[8], n2.Name)
assert.Contains(t, renderLines[9], "Chain ID")
assert.Contains(t, renderLines[9], n2.ChainID)
assert.Contains(t, renderLines[10], "State")
assert.Contains(t, renderLines[10], n2.State)
}
2 changes: 1 addition & 1 deletion core/cmd/starknet_node_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type StarkNetNodePresenter struct {

// ToRow presents the StarkNetNodeResource as a slice of strings.
func (p *StarkNetNodePresenter) ToRow() []string {
return []string{p.GetID(), p.Name, p.ChainID, p.State, p.Config}
return []string{p.Name, p.ChainID, p.State, p.Config}
}

// RenderTable implements TableRenderer
Expand Down
21 changes: 21 additions & 0 deletions core/cmd/starknet_node_commands_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package cmd_test

import (
"bytes"
"strings"
"testing"

"github.com/pelletier/go-toml/v2"
Expand Down Expand Up @@ -64,4 +66,23 @@ func TestShell_IndexStarkNetNodes(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, string(wantConfig2), n2.Config)
assertTableRenders(t, r)

//Render table and check the fields order
b := new(bytes.Buffer)
rt := cmd.RendererTable{b}
nodes.RenderTable(rt)
renderLines := strings.Split(b.String(), "\n")
assert.Equal(t, 14, len(renderLines))
assert.Contains(t, renderLines[1], "Name")
assert.Contains(t, renderLines[1], n1.Name)
assert.Contains(t, renderLines[2], "Chain ID")
assert.Contains(t, renderLines[2], n1.ChainID)
assert.Contains(t, renderLines[3], "State")
assert.Contains(t, renderLines[3], n1.State)
assert.Contains(t, renderLines[8], "Name")
assert.Contains(t, renderLines[8], n2.Name)
assert.Contains(t, renderLines[9], "Chain ID")
assert.Contains(t, renderLines[9], n2.ChainID)
assert.Contains(t, renderLines[10], "State")
assert.Contains(t, renderLines[10], n2.State)
}
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Order = 5
state instead of relying on an unreliable round-trip to the Mercury server.

### Fixed
- Fixed a bug in the `nodes xxx list` command that caused results to not be displayed correctly

### Changed
- Assumption violations for MaxFeePerGas >= BaseFeePerGas and MaxFeePerGas >= MaxPriorityFeePerGas in EIP-1559 effective gas price calculation will now use a gas price if specified
Expand Down

0 comments on commit 8814c69

Please sign in to comment.