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
Prev Previous commit
Next Next commit
Add unique ID to prevent overwrite for solana and starknet
  • Loading branch information
george-dorin committed Mar 17, 2023
commit ce3d81b7c79d69969f3b7d428db5f50f986a0087
5 changes: 5 additions & 0 deletions core/chains/solana/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

solcfg "github.com/smartcontractkit/chainlink-solana/pkg/solana/config"
soldb "github.com/smartcontractkit/chainlink-solana/pkg/solana/db"

v2 "github.com/smartcontractkit/chainlink/core/config/v2"
)

Expand Down Expand Up @@ -105,6 +106,10 @@ func (cs SolanaConfigs) Nodes() (ns []soldb.Node) {
ns = append(ns, legacySolNode(n, *cs[i].ChainID))
}
}
//Add unique ID to prevent overwriting nodes during unmarshalling since this will be transformed into JAID
for i := range ns {
ns[i].ID = int32(i)
}
return
}

Expand Down
4 changes: 4 additions & 0 deletions core/chains/starknet/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ func (cs StarknetConfigs) Nodes() (ns []db.Node) {
ns = append(ns, legacyNode(n, *cs[i].ChainID))
}
}
//Add unique ID to prevent overwriting nodes during unmarshalling since this will be transformed into JAID
for i := range ns {
ns[i].ID = int32(i)
}
return
}

Expand Down
32 changes: 0 additions & 32 deletions core/cmd/evm_node_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,38 +26,6 @@ func assertTableRenders(t *testing.T, r *cltest.RendererMock) {
func TestClient_IndexEVMNodes(t *testing.T) {
t.Parallel()

chainID := newRandChainID()
node := evmcfg.Node{
Name: ptr("Test node"),
WSURL: models.MustParseURL("ws://localhost:8546"),
HTTPURL: models.MustParseURL("http://localhost:8546"),
SendOnly: ptr(false),
}
chain := evmcfg.EVMConfig{
ChainID: chainID,
Chain: evmcfg.Defaults(chainID),
Nodes: evmcfg.EVMNodes{&node},
}
app := startNewApplicationV2(t, func(c *chainlink.Config, s *chainlink.Secrets) {
c.EVM = evmcfg.EVMConfigs{&chain}
})
client, r := app.NewClientAndRenderer()

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)
assertTableRenders(t, r)
}

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

chainID := newRandChainID()
node1 := evmcfg.Node{
Name: ptr("Test node 1"),
Expand Down
23 changes: 16 additions & 7 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://solana.example"),
}
node2 := solcfg.Node{
Name: ptr("second"),
URL: utils.MustParseURL("https://solana.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, "0", n1.ID)
assert.Equal(t, *node1.Name, n1.Name)
assert.Equal(t, (*url.URL)(node1.URL).String(), n1.SolanaURL)
assert.Equal(t, "1", 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://starknet.example"),
}
node2 := config.Node{
Name: ptr("second"),
URL: utils.MustParseURL("https://starknet.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, "0", n1.ID)
assert.Equal(t, *node1.Name, n1.Name)
assert.Equal(t, (*url.URL)(node1.URL).String(), n1.URL)
assert.Equal(t, "1", n2.ID)
assert.Equal(t, *node2.Name, n2.Name)
assert.Equal(t, (*url.URL)(node2.URL).String(), n2.URL)
assertTableRenders(t, r)
}