Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set node name as JAID to prevent overwrite #8737

Merged
merged 10 commits into from
Mar 20, 2023
29 changes: 20 additions & 9 deletions core/cmd/evm_node_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,22 @@ func TestClient_IndexEVMNodes(t *testing.T) {
t.Parallel()

chainID := newRandChainID()
node := evmcfg.Node{
Name: ptr("Test node"),
node1 := evmcfg.Node{
Name: ptr("Test node 1"),
WSURL: models.MustParseURL("ws://localhost:8546"),
HTTPURL: models.MustParseURL("http://localhost:8546"),
SendOnly: ptr(false),
}
node2 := evmcfg.Node{
Name: ptr("Test node 2"),
WSURL: models.MustParseURL("ws://localhost:8547"),
HTTPURL: models.MustParseURL("http://localhost:8547"),
SendOnly: ptr(false),
}
chain := evmcfg.EVMConfig{
ChainID: chainID,
Chain: evmcfg.Defaults(chainID),
Nodes: evmcfg.EVMNodes{&node},
Nodes: evmcfg.EVMNodes{&node1, &node2},
}
app := startNewApplicationV2(t, func(c *chainlink.Config, s *chainlink.Secrets) {
c.EVM = evmcfg.EVMConfigs{&chain}
Expand All @@ -46,11 +52,16 @@ func TestClient_IndexEVMNodes(t *testing.T) {
require.Nil(t, cmd.NewEVMNodeClient(client).IndexNodes(cltest.EmptyCLIContext()))
require.NotEmpty(t, r.Renders)
nodes := *r.Renders[0].(*cmd.EVMNodePresenters)
require.Len(t, nodes, 1)
n := nodes[0]
assert.Equal(t, "0", n.ID)
assert.Equal(t, *node.Name, n.Name)
assert.Equal(t, node.WSURL.String(), n.WSURL.String)
assert.Equal(t, node.HTTPURL.String(), n.HTTPURL.String)
require.Len(t, nodes, 2)
n1 := nodes[0]
n2 := nodes[1]
assert.Equal(t, "Test node 1", n1.ID)
assert.Equal(t, *node1.Name, n1.Name)
assert.Equal(t, node1.WSURL.String(), n1.WSURL.String)
assert.Equal(t, node1.HTTPURL.String(), n1.HTTPURL.String)
assert.Equal(t, "Test node 2", n2.ID)
assert.Equal(t, *node2.Name, n2.Name)
assert.Equal(t, node2.WSURL.String(), n2.WSURL.String)
assert.Equal(t, node2.HTTPURL.String(), n2.HTTPURL.String)
assertTableRenders(t, r)
}
25 changes: 17 additions & 8 deletions core/cmd/solana_node_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/smartcontractkit/chainlink-relay/pkg/utils"
solcfg "github.com/smartcontractkit/chainlink-solana/pkg/solana/config"

"github.com/smartcontractkit/chainlink/core/chains/solana"
"github.com/smartcontractkit/chainlink/core/cmd"
"github.com/smartcontractkit/chainlink/core/internal/cltest"
Expand All @@ -30,24 +31,32 @@ func TestClient_IndexSolanaNodes(t *testing.T) {
t.Parallel()

id := solanatest.RandomChainID()
node := solcfg.Node{
node1 := solcfg.Node{
Name: ptr("first"),
URL: utils.MustParseURL("https://solana1.example"),
}
node2 := solcfg.Node{
Name: ptr("second"),
URL: utils.MustParseURL("https://solana.example"),
URL: utils.MustParseURL("https://solana2.example"),
}
chain := solana.SolanaConfig{
ChainID: &id,
Nodes: solana.SolanaNodes{&node},
Nodes: solana.SolanaNodes{&node1, &node2},
}
app := solanaStartNewApplication(t, &chain)
client, r := app.NewClientAndRenderer()

require.Nil(t, cmd.NewSolanaNodeClient(client).IndexNodes(cltest.EmptyCLIContext()))
require.NotEmpty(t, r.Renders)
nodes := *r.Renders[0].(*cmd.SolanaNodePresenters)
require.Len(t, nodes, 1)
n := nodes[0]
assert.Equal(t, "0", n.ID)
assert.Equal(t, *node.Name, n.Name)
assert.Equal(t, (*url.URL)(node.URL).String(), n.SolanaURL)
require.Len(t, nodes, 2)
n1 := nodes[0]
n2 := nodes[1]
assert.Equal(t, "first", n1.ID)
assert.Equal(t, *node1.Name, n1.Name)
assert.Equal(t, (*url.URL)(node1.URL).String(), n1.SolanaURL)
assert.Equal(t, "second", n2.ID)
assert.Equal(t, *node2.Name, n2.Name)
assert.Equal(t, (*url.URL)(node2.URL).String(), n2.SolanaURL)
assertTableRenders(t, r)
}
61 changes: 61 additions & 0 deletions core/cmd/starknet_node_commands_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package cmd_test

import (
"net/url"
"testing"

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

"github.com/smartcontractkit/chainlink/core/chains/starknet"
"github.com/smartcontractkit/chainlink/core/cmd"
"github.com/smartcontractkit/chainlink/core/internal/cltest"
"github.com/smartcontractkit/chainlink/core/services/chainlink"
)

func starknetStartNewApplication(t *testing.T, cfgs ...*starknet.StarknetConfig) *cltest.TestApplication {
for i := range cfgs {
cfgs[i].SetDefaults()
}
return startNewApplicationV2(t, func(c *chainlink.Config, s *chainlink.Secrets) {
c.Starknet = cfgs
c.EVM = nil
c.Solana = nil
})
}

func TestClient_IndexStarkNetNodes(t *testing.T) {
t.Parallel()

id := "starknet chain ID"
node1 := config.Node{
Name: ptr("first"),
URL: utils.MustParseURL("https://starknet1.example"),
}
node2 := config.Node{
Name: ptr("second"),
URL: utils.MustParseURL("https://starknet2.example"),
}
chain := starknet.StarknetConfig{
ChainID: &id,
Nodes: starknet.StarknetNodes{&node1, &node2},
}
app := starknetStartNewApplication(t, &chain)
client, r := app.NewClientAndRenderer()

require.Nil(t, cmd.NewStarkNetNodeClient(client).IndexNodes(cltest.EmptyCLIContext()))
require.NotEmpty(t, r.Renders)
nodes := *r.Renders[0].(*cmd.StarkNetNodePresenters)
require.Len(t, nodes, 2)
n1 := nodes[0]
n2 := nodes[1]
assert.Equal(t, "first", n1.ID)
assert.Equal(t, *node1.Name, n1.Name)
assert.Equal(t, (*url.URL)(node1.URL).String(), n1.URL)
assert.Equal(t, "second", n2.ID)
assert.Equal(t, *node2.Name, n2.Name)
assert.Equal(t, (*url.URL)(node2.URL).String(), n2.URL)
assertTableRenders(t, r)
}
2 changes: 1 addition & 1 deletion core/web/presenters/evm_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (r EVMNodeResource) GetName() string {
// NewEVMNodeResource returns a new EVMNodeResource for node.
func NewEVMNodeResource(node evmtypes.Node) EVMNodeResource {
return EVMNodeResource{
JAID: NewJAIDInt32(node.ID),
JAID: NewJAID(node.Name),
Name: node.Name,
EVMChainID: node.EVMChainID,
WSURL: node.WSURL,
Expand Down
2 changes: 1 addition & 1 deletion core/web/presenters/solana_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (r SolanaNodeResource) GetName() string {
// NewSolanaNodeResource returns a new SolanaNodeResource for node.
func NewSolanaNodeResource(node db.Node) SolanaNodeResource {
return SolanaNodeResource{
JAID: NewJAIDInt32(node.ID),
JAID: NewJAID(node.Name),
Name: node.Name,
SolanaChainID: node.SolanaChainID,
SolanaURL: node.SolanaURL,
Expand Down
2 changes: 1 addition & 1 deletion core/web/presenters/starknet_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (r StarkNetNodeResource) GetName() string {
// NewStarkNetNodeResource returns a new StarkNetNodeResource for node.
func NewStarkNetNodeResource(node db.Node) StarkNetNodeResource {
return StarkNetNodeResource{
JAID: NewJAIDInt32(node.ID),
JAID: NewJAID(node.Name),
Name: node.Name,
ChainID: node.ChainID,
URL: node.URL,
Expand Down