Skip to content

Commit

Permalink
revert all changes to the core/cmd dir
Browse files Browse the repository at this point in the history
  • Loading branch information
poopoothegorilla committed Feb 27, 2024
1 parent 5850634 commit 88e2236
Show file tree
Hide file tree
Showing 24 changed files with 269 additions and 271 deletions.
8 changes: 4 additions & 4 deletions core/cmd/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"path/filepath"
"regexp"

pkgerrors "github.com/pkg/errors"
"github.com/pkg/errors"
"github.com/urfave/cli"

"github.com/smartcontractkit/chainlink/v2/core/build"
Expand Down Expand Up @@ -98,7 +98,7 @@ func NewApp(s *Shell) *cli.App {
urlStr := c.String("remote-node-url")
remoteNodeURL, err := url.Parse(urlStr)
if err != nil {
return pkgerrors.Wrapf(err, "%s is not a valid URL", urlStr)
return errors.Wrapf(err, "%s is not a valid URL", urlStr)
}

insecureSkipVerify := c.Bool("insecure-skip-verify")
Expand All @@ -108,8 +108,8 @@ func NewApp(s *Shell) *cli.App {

credentialsFile := c.String("admin-credentials-file")
sr, err := sessionRequestBuilder.Build(credentialsFile)
if err != nil && !pkgerrors.Is(pkgerrors.Cause(err), ErrNoCredentialFile) && !os.IsNotExist(err) {
return pkgerrors.Wrapf(err, "failed to load API credentials from file %s", credentialsFile)
if err != nil && !errors.Is(errors.Cause(err), ErrNoCredentialFile) && !os.IsNotExist(err) {
return errors.Wrapf(err, "failed to load API credentials from file %s", credentialsFile)
}

s.HTTP = NewAuthenticatedHTTPClient(s.Logger, clientOpts, cookieAuth, sr)
Expand Down
4 changes: 2 additions & 2 deletions core/cmd/blocks_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"net/url"
"strconv"

pkgerrors "github.com/pkg/errors"
"github.com/pkg/errors"
"github.com/urfave/cli"
"go.uber.org/multierr"
)
Expand Down Expand Up @@ -41,7 +41,7 @@ func initBlocksSubCmds(s *Shell) []cli.Command {
func (s *Shell) ReplayFromBlock(c *cli.Context) (err error) {
blockNumber := c.Int64("block-number")
if blockNumber <= 0 {
return s.errorOut(pkgerrors.New("Must pass a positive value in '--block-number' parameter"))
return s.errorOut(errors.New("Must pass a positive value in '--block-number' parameter"))
}

v := url.Values{}
Expand Down
2 changes: 1 addition & 1 deletion core/cmd/cosmos_node_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ func TestShell_IndexCosmosNodes(t *testing.T) {
nodes := *r.Renders[0].(*cmd.CosmosNodePresenters)
require.Len(t, nodes, 1)
n := nodes[0]
assert.Equal(t, cltest.FormatWithPrefixedChainID(chainID, *node.Name), n.ID)
assert.Equal(t, chainID, n.ChainID)
assert.Equal(t, *node.Name, n.ID)
assert.Equal(t, *node.Name, n.Name)
wantConfig, err := toml.Marshal(node)
require.NoError(t, err)
Expand Down
22 changes: 11 additions & 11 deletions core/cmd/csa_keys_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"net/url"
"os"

pkgerrors "github.com/pkg/errors"
"github.com/pkg/errors"
"github.com/urfave/cli"
"go.uber.org/multierr"

Expand Down Expand Up @@ -139,16 +139,16 @@ func (s *Shell) CreateCSAKey(_ *cli.Context) (err error) {
// ImportCSAKey imports and stores a CSA key. Path to key must be passed.
func (s *Shell) ImportCSAKey(c *cli.Context) (err error) {
if !c.Args().Present() {
return s.errorOut(pkgerrors.New("Must pass the filepath of the key to be imported"))
return s.errorOut(errors.New("Must pass the filepath of the key to be imported"))
}

oldPasswordFile := c.String("old-password")
if len(oldPasswordFile) == 0 {
return s.errorOut(pkgerrors.New("Must specify --old-password/-p flag"))
return s.errorOut(errors.New("Must specify --old-password/-p flag"))
}
oldPassword, err := os.ReadFile(oldPasswordFile)
if err != nil {
return s.errorOut(pkgerrors.Wrap(err, "Could not read password file"))
return s.errorOut(errors.Wrap(err, "Could not read password file"))
}

filepath := c.Args().Get(0)
Expand Down Expand Up @@ -181,22 +181,22 @@ func (s *Shell) ImportCSAKey(c *cli.Context) (err error) {
// ExportCSAKey exports a CSA key. Key ID must be passed.
func (s *Shell) ExportCSAKey(c *cli.Context) (err error) {
if !c.Args().Present() {
return s.errorOut(pkgerrors.New("Must pass the ID of the key to export"))
return s.errorOut(errors.New("Must pass the ID of the key to export"))
}

newPasswordFile := c.String("new-password")
if len(newPasswordFile) == 0 {
return s.errorOut(pkgerrors.New("Must specify --new-password/-p flag"))
return s.errorOut(errors.New("Must specify --new-password/-p flag"))
}

newPassword, err := os.ReadFile(newPasswordFile)
if err != nil {
return s.errorOut(pkgerrors.Wrap(err, "Could not read password file"))
return s.errorOut(errors.Wrap(err, "Could not read password file"))
}

filepath := c.String("output")
if len(filepath) == 0 {
return s.errorOut(pkgerrors.New("Must specify --output/-o flag"))
return s.errorOut(errors.New("Must specify --output/-o flag"))
}

ID := c.Args().Get(0)
Expand All @@ -210,7 +210,7 @@ func (s *Shell) ExportCSAKey(c *cli.Context) (err error) {
exportUrl.RawQuery = query.Encode()
resp, err := s.HTTP.Post(s.ctx(), exportUrl.String(), nil)
if err != nil {
return s.errorOut(pkgerrors.Wrap(err, "Could not make HTTP request"))
return s.errorOut(errors.Wrap(err, "Could not make HTTP request"))
}
defer func() {
if cerr := resp.Body.Close(); cerr != nil {
Expand All @@ -224,12 +224,12 @@ func (s *Shell) ExportCSAKey(c *cli.Context) (err error) {

keyJSON, err := io.ReadAll(resp.Body)
if err != nil {
return s.errorOut(pkgerrors.Wrap(err, "Could not read response body"))
return s.errorOut(errors.Wrap(err, "Could not read response body"))
}

err = utils.WriteFileWithMaxPerms(filepath, keyJSON, 0o600)
if err != nil {
return s.errorOut(pkgerrors.Wrapf(err, "Could not write %v", filepath))
return s.errorOut(errors.Wrapf(err, "Could not write %v", filepath))
}

_, err = os.Stderr.WriteString(fmt.Sprintf("🔑 Exported P2P key %s to %s\n", ID, filepath))
Expand Down
34 changes: 17 additions & 17 deletions core/cmd/eth_keys_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"os"
"strings"

pkgerrors "github.com/pkg/errors"
"github.com/pkg/errors"
"github.com/urfave/cli"
"go.uber.org/multierr"

Expand Down Expand Up @@ -223,7 +223,7 @@ func (s *Shell) CreateETHKey(c *cli.Context) (err error) {
// address of key must be passed
func (s *Shell) DeleteETHKey(c *cli.Context) (err error) {
if !c.Args().Present() {
return s.errorOut(pkgerrors.New("Must pass the address of the key to be deleted"))
return s.errorOut(errors.New("Must pass the address of the key to be deleted"))
}
address := c.Args().Get(0)

Expand All @@ -244,14 +244,14 @@ func (s *Shell) DeleteETHKey(c *cli.Context) (err error) {
if resp.StatusCode != http.StatusOK {
body, err := io.ReadAll(resp.Body)
if err != nil {
return s.errorOut(pkgerrors.Wrap(err, "Failed to read request response"))
return s.errorOut(errors.Wrap(err, "Failed to read request response"))
}
var result *models.JSONAPIErrors
err = json.Unmarshal(body, &result)
if err != nil {
return s.errorOut(pkgerrors.Wrapf(err, "Unable to unmarshal json from body '%s'", string(body)))
return s.errorOut(errors.Wrapf(err, "Unable to unmarshal json from body '%s'", string(body)))
}
return s.errorOut(pkgerrors.Errorf("Delete ETH key failed: %s", result.Error()))
return s.errorOut(errors.Errorf("Delete ETH key failed: %s", result.Error()))
}
return s.renderAPIResponse(resp, &EthKeyPresenter{}, fmt.Sprintf("🔑 Deleted ETH key: %s\n", address))
}
Expand All @@ -260,16 +260,16 @@ func (s *Shell) DeleteETHKey(c *cli.Context) (err error) {
// file path must be passed
func (s *Shell) ImportETHKey(c *cli.Context) (err error) {
if !c.Args().Present() {
return s.errorOut(pkgerrors.New("Must pass the filepath of the key to be imported"))
return s.errorOut(errors.New("Must pass the filepath of the key to be imported"))
}

oldPasswordFile := c.String("old-password")
if len(oldPasswordFile) == 0 {
return s.errorOut(pkgerrors.New("Must specify --old-password/-p flag"))
return s.errorOut(errors.New("Must specify --old-password/-p flag"))
}
oldPassword, err := os.ReadFile(oldPasswordFile)
if err != nil {
return s.errorOut(pkgerrors.Wrap(err, "Could not read password file"))
return s.errorOut(errors.Wrap(err, "Could not read password file"))
}

filepath := c.Args().Get(0)
Expand Down Expand Up @@ -307,21 +307,21 @@ func (s *Shell) ImportETHKey(c *cli.Context) (err error) {
// address must be passed
func (s *Shell) ExportETHKey(c *cli.Context) (err error) {
if !c.Args().Present() {
return s.errorOut(pkgerrors.New("Must pass the address of the key to export"))
return s.errorOut(errors.New("Must pass the address of the key to export"))
}

newPasswordFile := c.String("new-password")
if len(newPasswordFile) == 0 {
return s.errorOut(pkgerrors.New("Must specify --new-password/-p flag"))
return s.errorOut(errors.New("Must specify --new-password/-p flag"))
}
newPassword, err := os.ReadFile(newPasswordFile)
if err != nil {
return s.errorOut(pkgerrors.Wrap(err, "Could not read password file"))
return s.errorOut(errors.Wrap(err, "Could not read password file"))
}

filepath := c.String("output")
if len(newPassword) == 0 {
return s.errorOut(pkgerrors.New("Must specify --output/-o flag"))
return s.errorOut(errors.New("Must specify --output/-o flag"))
}

address := c.Args().Get(0)
Expand All @@ -334,7 +334,7 @@ func (s *Shell) ExportETHKey(c *cli.Context) (err error) {
exportUrl.RawQuery = query.Encode()
resp, err := s.HTTP.Post(s.ctx(), exportUrl.String(), nil)
if err != nil {
return s.errorOut(pkgerrors.Wrap(err, "Could not make HTTP request"))
return s.errorOut(errors.Wrap(err, "Could not make HTTP request"))
}
defer func() {
if cerr := resp.Body.Close(); cerr != nil {
Expand All @@ -348,12 +348,12 @@ func (s *Shell) ExportETHKey(c *cli.Context) (err error) {

keyJSON, err := io.ReadAll(resp.Body)
if err != nil {
return s.errorOut(pkgerrors.Wrap(err, "Could not read response body"))
return s.errorOut(errors.Wrap(err, "Could not read response body"))
}

err = utils.WriteFileWithMaxPerms(filepath, keyJSON, 0o600)
if err != nil {
return s.errorOut(pkgerrors.Wrapf(err, "Could not write %v", filepath))
return s.errorOut(errors.Wrapf(err, "Could not write %v", filepath))
}

_, err = os.Stderr.WriteString("🔑 Exported ETH key " + address + " to " + filepath + "\n")
Expand All @@ -377,7 +377,7 @@ func (s *Shell) UpdateChainEVMKey(c *cli.Context) (err error) {
query.Set("abandon", abandon)

if c.IsSet("enable") && c.IsSet("disable") {
return s.errorOut(pkgerrors.New("cannot set both --enable and --disable simultaneously"))
return s.errorOut(errors.New("cannot set both --enable and --disable simultaneously"))
} else if c.Bool("enable") {
query.Set("enabled", "true")
} else if c.Bool("disable") {
Expand All @@ -387,7 +387,7 @@ func (s *Shell) UpdateChainEVMKey(c *cli.Context) (err error) {
chainURL.RawQuery = query.Encode()
resp, err := s.HTTP.Post(s.ctx(), chainURL.String(), nil)
if err != nil {
return s.errorOut(pkgerrors.Wrap(err, "Could not make HTTP request"))
return s.errorOut(errors.Wrap(err, "Could not make HTTP request"))
}
defer func() {
if cerr := resp.Body.Close(); cerr != nil {
Expand Down
24 changes: 12 additions & 12 deletions core/cmd/eth_keys_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"testing"
"time"

pkgerrors "github.com/pkg/errors"
"github.com/pkg/errors"

commonassets "github.com/smartcontractkit/chainlink-common/pkg/assets"
"github.com/smartcontractkit/chainlink-common/pkg/utils"
Expand Down Expand Up @@ -116,8 +116,8 @@ func TestShell_ListETHKeys_Error(t *testing.T) {
t.Parallel()

ethClient := newEthMock(t)
ethClient.On("BalanceAt", mock.Anything, mock.Anything, mock.Anything).Return(nil, pkgerrors.New("fake error"))
ethClient.On("LINKBalance", mock.Anything, mock.Anything, mock.Anything).Return(nil, pkgerrors.New("fake error"))
ethClient.On("BalanceAt", mock.Anything, mock.Anything, mock.Anything).Return(nil, errors.New("fake error"))
ethClient.On("LINKBalance", mock.Anything, mock.Anything, mock.Anything).Return(nil, errors.New("fake error"))
ethClient.On("PendingNonceAt", mock.Anything, mock.Anything).Return(uint64(0), nil)
app := startNewApplicationV2(t, func(c *chainlink.Config, s *chainlink.Secrets) {
c.EVM[0].Enabled = ptr(true)
Expand Down Expand Up @@ -148,7 +148,7 @@ func TestShell_ListETHKeys_Disabled(t *testing.T) {
withMocks(ethClient),
)
client, r := app.NewShellAndRenderer()
keys, err := app.KeyStore.Eth().GetAll()
keys, err := app.KeyStore.Eth().GetAll(testutils.Context(t))
require.NoError(t, err)
require.Equal(t, 1, len(keys))
k := keys[0]
Expand Down Expand Up @@ -186,7 +186,7 @@ func TestShell_CreateETHKey(t *testing.T) {
client, _ := app.NewShellAndRenderer()

cltest.AssertCount(t, db, "evm.key_states", 1) // The initial funding key
keys, err := app.KeyStore.Eth().GetAll()
keys, err := app.KeyStore.Eth().GetAll(testutils.Context(t))
require.NoError(t, err)
require.Equal(t, 1, len(keys))

Expand All @@ -202,7 +202,7 @@ func TestShell_CreateETHKey(t *testing.T) {
assert.NoError(t, client.CreateETHKey(c))

cltest.AssertCount(t, db, "evm.key_states", 2)
keys, err = app.KeyStore.Eth().GetAll()
keys, err = app.KeyStore.Eth().GetAll(testutils.Context(t))
require.NoError(t, err)
require.Equal(t, 2, len(keys))
}
Expand All @@ -221,7 +221,7 @@ func TestShell_DeleteETHKey(t *testing.T) {
client, _ := app.NewShellAndRenderer()

// Create the key
key, err := ethKeyStore.Create(&cltest.FixtureChainID)
key, err := ethKeyStore.Create(testutils.Context(t), &cltest.FixtureChainID)
require.NoError(t, err)

// Delete the key
Expand All @@ -235,7 +235,7 @@ func TestShell_DeleteETHKey(t *testing.T) {
err = client.DeleteETHKey(c)
require.NoError(t, err)

_, err = ethKeyStore.Get(key.Address.Hex())
_, err = ethKeyStore.Get(testutils.Context(t), key.Address.Hex())
assert.Error(t, err)
}

Expand Down Expand Up @@ -303,7 +303,7 @@ func TestShell_ImportExportETHKey_NoChains(t *testing.T) {
c = cli.NewContext(nil, set, nil)
err = client.DeleteETHKey(c)
require.NoError(t, err)
_, err = ethKeyStore.Get(address)
_, err = ethKeyStore.Get(testutils.Context(t), address)
require.Error(t, err)

cltest.AssertCount(t, app.GetSqlxDB(), "evm.key_states", 0)
Expand All @@ -328,7 +328,7 @@ func TestShell_ImportExportETHKey_NoChains(t *testing.T) {
err = client.ListETHKeys(c)
require.NoError(t, err)
require.Len(t, *r.Renders[0].(*cmd.EthKeyPresenters), 1)
_, err = ethKeyStore.Get(address)
_, err = ethKeyStore.Get(testutils.Context(t), address)
require.NoError(t, err)

// Export test invalid id
Expand Down Expand Up @@ -411,7 +411,7 @@ func TestShell_ImportExportETHKey_WithChains(t *testing.T) {
c = cli.NewContext(nil, set, nil)
err = client.DeleteETHKey(c)
require.NoError(t, err)
_, err = ethKeyStore.Get(address)
_, err = ethKeyStore.Get(testutils.Context(t), address)
require.Error(t, err)

// Import the key
Expand All @@ -435,7 +435,7 @@ func TestShell_ImportExportETHKey_WithChains(t *testing.T) {
err = client.ListETHKeys(c)
require.NoError(t, err)
require.Len(t, *r.Renders[0].(*cmd.EthKeyPresenters), 1)
_, err = ethKeyStore.Get(address)
_, err = ethKeyStore.Get(testutils.Context(t), address)
require.NoError(t, err)

// Export test invalid id
Expand Down
4 changes: 2 additions & 2 deletions core/cmd/evm_node_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ func TestShell_IndexEVMNodes(t *testing.T) {
n1 := nodes[0]
n2 := nodes[1]
assert.Equal(t, chainID.String(), n1.ChainID)
assert.Equal(t, *node1.Name, n1.ID)
assert.Equal(t, cltest.FormatWithPrefixedChainID(chainID.String(), *node1.Name), n1.ID)
assert.Equal(t, *node1.Name, n1.Name)
wantConfig, err := toml.Marshal(node1)
require.NoError(t, err)
assert.Equal(t, string(wantConfig), n1.Config)
assert.Equal(t, chainID.String(), n2.ChainID)
assert.Equal(t, *node2.Name, n2.ID)
assert.Equal(t, cltest.FormatWithPrefixedChainID(chainID.String(), *node2.Name), n2.ID)
assert.Equal(t, *node2.Name, n2.Name)
wantConfig2, err := toml.Marshal(node2)
require.NoError(t, err)
Expand Down
Loading

0 comments on commit 88e2236

Please sign in to comment.