Skip to content

Commit

Permalink
core: cosmos & starknet LOOPP mode only
Browse files Browse the repository at this point in the history
  • Loading branch information
jmank88 committed Feb 3, 2025
1 parent ce0d4c1 commit 63472c0
Show file tree
Hide file tree
Showing 40 changed files with 412 additions and 1,637 deletions.
9 changes: 4 additions & 5 deletions core/cmd/chains_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

coscfg "github.com/smartcontractkit/chainlink-cosmos/pkg/cosmos/config"
solcfg "github.com/smartcontractkit/chainlink-solana/pkg/solana/config"

"github.com/smartcontractkit/chainlink/v2/core/cmd"
Expand All @@ -24,11 +23,11 @@ func TestShell_IndexCosmosChains(t *testing.T) {
t.Parallel()

chainID := cosmostest.RandomChainID()
chain := coscfg.TOMLConfig{
ChainID: ptr(chainID),
Enabled: ptr(true),
chain := chainlink.RawConfig{
"ChainID": ptr(chainID),
"Enabled": ptr(true),
}
app := cosmosStartNewApplication(t, &chain)
app := cosmosStartNewApplication(t, chain)
client, r := app.NewShellAndRenderer()

require.NoError(t, cmd.NewChainClient(client, "cosmos").IndexChains(cltest.EmptyCLIContext()))
Expand Down
36 changes: 15 additions & 21 deletions core/cmd/cosmos_transaction_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"encoding/json"
"errors"
"fmt"
"math/big"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/urfave/cli"
"go.uber.org/multierr"

Expand Down Expand Up @@ -67,31 +67,25 @@ func (s *Shell) CosmosSendNativeToken(c *cli.Context) (err error) {
return s.errorOut(errors.New("four arguments expected: token, amount, fromAddress and toAddress"))
}

err = sdk.ValidateDenom(c.Args().Get(0))
if err != nil {
return s.errorOut(fmt.Errorf("invalid native token: %w", err))
token := c.Args().Get(0)
if token == "" {
return s.errorOut(errors.New("missing token"))
}

amount, err := sdk.NewDecFromStr(c.Args().Get(1))
if err != nil {
return s.errorOut(multierr.Combine(
fmt.Errorf("invalid coin: %w", err)))
unparsedAmount := c.Args().Get(1)
amount, ok := new(big.Int).SetString(unparsedAmount, 10)
if !ok {
return s.errorOut(fmt.Errorf("invalid int: %s", unparsedAmount))
}

unparsedFromAddress := c.Args().Get(2)
fromAddress, err := sdk.AccAddressFromBech32(unparsedFromAddress)
if err != nil {
return s.errorOut(multierr.Combine(
fmt.Errorf("while parsing withdrawal source address %v",
unparsedFromAddress), err))
if unparsedFromAddress == "" {
return s.errorOut(errors.New("missing from address"))
}

unparsedDestinationAddress := c.Args().Get(3)
destinationAddress, err := sdk.AccAddressFromBech32(unparsedDestinationAddress)
if err != nil {
return s.errorOut(multierr.Combine(
fmt.Errorf("while parsing withdrawal destination address %v",
unparsedDestinationAddress), err))
if unparsedDestinationAddress == "" {
return s.errorOut(errors.New("missing destination address"))
}

chainID := c.String("id")
Expand All @@ -100,11 +94,11 @@ func (s *Shell) CosmosSendNativeToken(c *cli.Context) (err error) {
}

request := cosmos.SendRequest{
DestinationAddress: destinationAddress,
FromAddress: fromAddress,
DestinationAddress: unparsedDestinationAddress,
FromAddress: unparsedFromAddress,
Amount: amount,
CosmosChainID: chainID,
Token: c.Args().Get(0),
Token: token,
AllowHigherAmounts: c.IsSet("force"),
}

Expand Down
132 changes: 0 additions & 132 deletions core/cmd/cosmos_transaction_commands_test.go

This file was deleted.

139 changes: 139 additions & 0 deletions core/cmd/node_commands_integration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
package cmd_test

import (
"bytes"
"strings"
"testing"

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

"github.com/smartcontractkit/chainlink-common/pkg/config"
"github.com/smartcontractkit/chainlink/v2/core/cmd"
"github.com/smartcontractkit/chainlink/v2/core/internal/cltest"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils/cosmostest"
"github.com/smartcontractkit/chainlink/v2/core/services/chainlink"
)

func cosmosStartNewApplication(t *testing.T, cfgs ...chainlink.RawConfig) *cltest.TestApplication {
//for i := range cfgs {
// cfgs[i].SetDefaults() //TODO?
//}
return startNewApplicationV2(t, func(c *chainlink.Config, s *chainlink.Secrets) {
c.Cosmos = cfgs
c.EVM = nil
})
}

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

chainID := cosmostest.RandomChainID()
node := map[string]any{
"Name": ptr("second"),
"TendermintURL": config.MustParseURL("http://tender.mint.test/bombay-12"),
}
chain := chainlink.RawConfig{
"ChainID": chainID,
"Enabled": true,
"Nodes": []any{node},
}
app := cosmosStartNewApplication(t, chain)
client, r := app.NewShellAndRenderer()
require.NoError(t, cmd.NewNodeClient(client, "cosmos").IndexNodes(cltest.EmptyCLIContext()))
require.NotEmpty(t, r.Renders)
nodes := *r.Renders[0].(*cmd.NodePresenters)
require.Len(t, nodes, 1)
n := nodes[0]
assert.Equal(t, cltest.FormatWithPrefixedChainID(chainID, "second"), n.ID)
assert.Equal(t, chainID, n.ChainID)
assert.Equal(t, "second", n.Name)
wantConfig, err := toml.Marshal(node)
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}
require.NoError(t, nodes.RenderTable(rt))
renderLines := strings.Split(b.String(), "\n")
assert.Len(t, renderLines, 10)
assert.Contains(t, renderLines[2], "Name")
assert.Contains(t, renderLines[2], n.Name)
assert.Contains(t, renderLines[3], "Chain ID")
assert.Contains(t, renderLines[3], n.ChainID)
assert.Contains(t, renderLines[4], "State")
assert.Contains(t, renderLines[4], n.State)
}

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

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

id := "starknet chain ID"
node1 := map[string]any{
"Name": ptr("first"),
"URL": config.MustParseURL("https://starknet1.example"),
}
node2 := map[string]any{
"Name": ptr("second"),
"URL": config.MustParseURL("https://starknet2.example"),
}
chain := chainlink.RawConfig{
"ChainID": &id,
"Nodes": []any{&node1, &node2},
}
app := starknetStartNewApplication(t, chain)
client, r := app.NewShellAndRenderer()

require.NoError(t, cmd.NewNodeClient(client, "starknet").IndexNodes(cltest.EmptyCLIContext()))
require.NotEmpty(t, r.Renders)
nodes := *r.Renders[0].(*cmd.NodePresenters)
require.Len(t, nodes, 2)
n1 := nodes[0]
n2 := nodes[1]
assert.Equal(t, id, n1.ChainID)
assert.Equal(t, cltest.FormatWithPrefixedChainID(id, "first"), n1.ID)
assert.Equal(t, "first", n1.Name)
wantConfig, err := toml.Marshal(node1)
require.NoError(t, err)
assert.Equal(t, string(wantConfig), n1.Config)
assert.Equal(t, id, n2.ChainID)
assert.Equal(t, cltest.FormatWithPrefixedChainID(id, "second"), n2.ID)
assert.Equal(t, "second", n2.Name)
wantConfig2, err := toml.Marshal(node2)
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}
require.NoError(t, nodes.RenderTable(rt))
renderLines := strings.Split(b.String(), "\n")
assert.Len(t, renderLines, 17)
assert.Contains(t, renderLines[2], "Name")
assert.Contains(t, renderLines[2], n1.Name)
assert.Contains(t, renderLines[3], "Chain ID")
assert.Contains(t, renderLines[3], n1.ChainID)
assert.Contains(t, renderLines[4], "State")
assert.Contains(t, renderLines[4], n1.State)
assert.Contains(t, renderLines[9], "Name")
assert.Contains(t, renderLines[9], n2.Name)
assert.Contains(t, renderLines[10], "Chain ID")
assert.Contains(t, renderLines[10], n2.ChainID)
assert.Contains(t, renderLines[11], "State")
assert.Contains(t, renderLines[11], n2.State)
}
Loading

0 comments on commit 63472c0

Please sign in to comment.