Skip to content

Commit

Permalink
core: fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
cfal committed Dec 9, 2024
1 parent c5f1791 commit dc9b5a9
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 61 deletions.
2 changes: 1 addition & 1 deletion core/cmd/shell_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ func TestSetupTronRelayer(t *testing.T) {
require.NotNil(t, relayers)
require.Len(t, relayers, nEnabledChains)
// no using plugin, so registry should be empty
require.Len(t, reg.List(), 0)
require.Empty(t, reg.List())
})

t.Run("plugin", func(t *testing.T) {
Expand Down
9 changes: 4 additions & 5 deletions core/cmd/tron_keys_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"context"
"flag"
"fmt"
"os"
"testing"

Expand Down Expand Up @@ -76,10 +75,10 @@ func TestShell_TronKeys(t *testing.T) {
key, err := app.GetKeyStore().Tron().Create(ctx)
require.NoError(t, err)
requireTronKeyCount(t, app, 1)
assert.Nil(t, cmd.NewTronKeysClient(client).ListKeys(cltest.EmptyCLIContext()))
require.Equal(t, 1, len(r.Renders))
require.NoError(t, cmd.NewTronKeysClient(client).ListKeys(cltest.EmptyCLIContext()))
require.Len(t, r.Renders, 1)
keys := *r.Renders[0].(*cmd.TronKeyPresenters)
assert.True(t, key.PublicKeyStr() == keys[0].PubKey)
assert.Equal(t, key.PublicKeyStr(), keys[0].PubKey)
})

t.Run("CreateTronKey", func(tt *testing.T) {
Expand Down Expand Up @@ -142,7 +141,7 @@ func TestShell_TronKeys(t *testing.T) {
set = flag.NewFlagSet("test Tron export", 0)
flagSetApplyFromAction(cmd.NewTronKeysClient(client).ExportKey, set, "tron")

require.NoError(tt, set.Parse([]string{fmt.Sprint(key.ID())}))
require.NoError(tt, set.Parse([]string{key.ID()}))
require.NoError(tt, set.Set("new-password", "../internal/fixtures/incorrect_password.txt"))
require.NoError(tt, set.Set("output", keyName))

Expand Down
6 changes: 2 additions & 4 deletions core/cmd/tron_node_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ func (p *TronNodePresenter) ToRow() []string {

// RenderTable implements TableRenderer
func (p TronNodePresenter) RenderTable(rt RendererTable) error {
var rows [][]string
rows = append(rows, p.ToRow())
rows := [][]string{p.ToRow()}
renderList(nodeHeaders, rows, rt.Writer)

return nil
Expand All @@ -28,8 +27,7 @@ type TronNodePresenters []TronNodePresenter

// RenderTable implements TableRenderer
func (ps TronNodePresenters) RenderTable(rt RendererTable) error {
var rows [][]string

rows := [][]string{}
for _, p := range ps {
rows = append(rows, p.ToRow())
}
Expand Down
6 changes: 3 additions & 3 deletions core/services/chainlink/relayer_chain_interoperators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func TestCoreRelayerChainInteroperators(t *testing.T) {

expectedTronChainCnt int
expectedTronNodeCnt int
expectedTronRelayerIds []types.RelayID
expectedTronRelayerIDs []types.RelayID
}{

{name: "2 evm chains with 3 nodes",
Expand Down Expand Up @@ -304,7 +304,7 @@ func TestCoreRelayerChainInteroperators(t *testing.T) {
},
expectedTronChainCnt: 2,
expectedTronNodeCnt: 2,
expectedTronRelayerIds: []types.RelayID{
expectedTronRelayerIDs: []types.RelayID{
{Network: relay.NetworkTron, ChainID: tronChainID1},
{Network: relay.NetworkTron, ChainID: tronChainID2},
},
Expand Down Expand Up @@ -364,7 +364,7 @@ func TestCoreRelayerChainInteroperators(t *testing.T) {

expectedTronChainCnt: 2,
expectedTronNodeCnt: 2,
expectedTronRelayerIds: []types.RelayID{
expectedTronRelayerIDs: []types.RelayID{
{Network: relay.NetworkTron, ChainID: tronChainID1},
{Network: relay.NetworkTron, ChainID: tronChainID2},
},
Expand Down
7 changes: 4 additions & 3 deletions core/services/keystore/keys/tronkey/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"crypto/ecdsa"
"crypto/sha256"
"encoding/hex"
"errors"
"fmt"
"math/big"

Expand Down Expand Up @@ -136,7 +137,7 @@ func DecodeCheck(input string) ([]byte, error) {
}

if len(decodeCheck) < 4 {
return nil, fmt.Errorf("b58 check error")
return nil, errors.New("base58 check error")
}

// tron address should should have 20 bytes + 4 checksum + 1 Prefix
Expand All @@ -146,7 +147,7 @@ func DecodeCheck(input string) ([]byte, error) {

// check prefix
if decodeCheck[0] != prefixMainnet {
return nil, fmt.Errorf("invalid prefix")
return nil, errors.New("invalid prefix")
}

decodeData := decodeCheck[:len(decodeCheck)-4]
Expand All @@ -166,7 +167,7 @@ func DecodeCheck(input string) ([]byte, error) {
return decodeData, nil
}

return nil, fmt.Errorf("b58 check error")
return nil, errors.New("base58 check error")
}

func Decode(input string) ([]byte, error) {
Expand Down
33 changes: 17 additions & 16 deletions core/services/keystore/keys/tronkey/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"strings"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func Test_DecodeBase58(t *testing.T) {
Expand All @@ -24,12 +24,12 @@ func Test_DecodeBase58(t *testing.T) {

for _, addr := range invalidAddresses {
_, err := DecodeCheck(addr)
assert.NotNil(t, err)
require.Error(t, err)
}

for _, addr := range validAddresses {
_, err := DecodeCheck(addr)
assert.Nil(t, err)
require.NoError(t, err)
}
}

Expand All @@ -44,12 +44,12 @@ func TestAddress(t *testing.T) {
for _, addrStr := range validAddresses {
t.Run(addrStr, func(t *testing.T) {
addr, err := Base58ToAddress(addrStr)
assert.Nil(t, err)
assert.Equal(t, addrStr, addr.String())
require.NoError(t, err)
require.Equal(t, addrStr, addr.String())

decoded, err := DecodeCheck(addrStr)
assert.Nil(t, err)
assert.True(t, bytes.Equal(decoded, addr.Bytes()))
require.NoError(t, err)
require.True(t, bytes.Equal(decoded, addr.Bytes()))
})
}
})
Expand All @@ -64,40 +64,41 @@ func TestAddress(t *testing.T) {
for _, addrStr := range invalidAddresses {
t.Run(addrStr, func(t *testing.T) {
_, err := Base58ToAddress(addrStr)
assert.NotNil(t, err)
require.Error(t, err)

_, err = DecodeCheck(addrStr)
assert.NotNil(t, err)
require.Error(t, err)
})
}
})

t.Run("Address Conversion", func(t *testing.T) {
addrStr := "TSvT6Bg3siokv3dbdtt9o4oM1CTXmymGn1"
addr, err := Base58ToAddress(addrStr)
assert.Nil(t, err)
require.NoError(t, err)

t.Run("To Bytes", func(t *testing.T) {
bytes := addr.Bytes()
assert.Equal(t, 21, len(bytes))
require.Len(t, bytes, 21)
})

t.Run("To Hex", func(t *testing.T) {
hex := addr.Hex()
assert.True(t, hex[:2] == "0x")
assert.Equal(t, 44, len(hex)) // first 2 bytes are 0x
require.Equal(t, "0x", hex[:2])
require.Len(t, hex, 44)
})
})

t.Run("Address Validity", func(t *testing.T) {
t.Run("Valid Address", func(t *testing.T) {
addr, _ := Base58ToAddress("TSvT6Bg3siokv3dbdtt9o4oM1CTXmymGn1")
assert.True(t, isValid(addr))
addr, err := Base58ToAddress("TSvT6Bg3siokv3dbdtt9o4oM1CTXmymGn1")
require.NoError(t, err)
require.True(t, isValid(addr))
})

t.Run("Zero Address", func(t *testing.T) {
addr := Address{}
assert.False(t, isValid(addr))
require.False(t, isValid(addr))
})
})
}
Expand Down
2 changes: 1 addition & 1 deletion core/services/keystore/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func (kr *keyRing) logPubKeys(lggr logger.Logger) {
for _, aptosKey := range kr.Aptos {
aptosIDs = append(aptosIDs, aptosKey.ID())
}
var tronIDs []string
tronIDs := []string{}
for _, tronKey := range kr.Tron {
tronIDs = append(tronIDs, tronKey.ID())
}
Expand Down
2 changes: 1 addition & 1 deletion core/services/keystore/models_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func TestKeyRing_Encrypt_Decrypt(t *testing.T) {
require.Equal(t, originalKeyRing.Cosmos[tk1.ID()].PublicKey(), decryptedKeyRing.Cosmos[tk1.ID()].PublicKey())
require.Equal(t, originalKeyRing.Cosmos[tk2.ID()].PublicKey(), decryptedKeyRing.Cosmos[tk2.ID()].PublicKey())
// compare tron keys
require.Equal(t, 2, len(decryptedKeyRing.Tron))
require.Len(t, decryptedKeyRing.Tron, 2)
require.Equal(t, originalKeyRing.Tron[tk1.ID()].Base58Address(), decryptedKeyRing.Tron[tk1.ID()].Base58Address())
require.Equal(t, originalKeyRing.Tron[tk2.ID()].Base58Address(), decryptedKeyRing.Tron[tk2.ID()].Base58Address())
// compare csa keys
Expand Down
27 changes: 13 additions & 14 deletions core/services/keystore/tron_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink-common/pkg/utils"
Expand Down Expand Up @@ -35,7 +34,7 @@ func Test_TronKeyStore_E2E(t *testing.T) {
defer reset()
keys, err := ks.GetAll()
require.NoError(t, err)
require.Equal(t, 0, len(keys))
require.Empty(t, keys)
})

t.Run("errors when getting non-existent ID", func(t *testing.T) {
Expand All @@ -62,17 +61,17 @@ func Test_TronKeyStore_E2E(t *testing.T) {
exportJSON, err := ks.Export(key.ID(), cltest.Password)
require.NoError(t, err)
_, err = ks.Export("non-existent", cltest.Password)
assert.Error(t, err)
require.Error(t, err)
_, err = ks.Delete(ctx, key.ID())
require.NoError(t, err)
_, err = ks.Get(key.ID())
require.Error(t, err)
importedKey, err := ks.Import(ctx, exportJSON, cltest.Password)
require.NoError(t, err)
_, err = ks.Import(ctx, exportJSON, cltest.Password)
assert.Error(t, err)
require.Error(t, err)
_, err = ks.Import(ctx, []byte(""), cltest.Password)
assert.Error(t, err)
require.Error(t, err)
require.Equal(t, key.ID(), importedKey.ID())
retrievedKey, err := ks.Get(key.ID())
require.NoError(t, err)
Expand All @@ -87,17 +86,17 @@ func Test_TronKeyStore_E2E(t *testing.T) {
err = ks.Add(ctx, newKey)
require.NoError(t, err)
err = ks.Add(ctx, newKey)
assert.Error(t, err)
require.Error(t, err)
keys, err := ks.GetAll()
require.NoError(t, err)
require.Equal(t, 1, len(keys))
require.Len(t, keys, 1)
_, err = ks.Delete(ctx, newKey.ID())
require.NoError(t, err)
_, err = ks.Delete(ctx, newKey.ID())
assert.Error(t, err)
require.Error(t, err)
keys, err = ks.GetAll()
require.NoError(t, err)
require.Equal(t, 0, len(keys))
require.Empty(t, keys)
_, err = ks.Get(newKey.ID())
require.Error(t, err)
})
Expand All @@ -106,14 +105,14 @@ func Test_TronKeyStore_E2E(t *testing.T) {
defer reset()
ctx := testutils.Context(t)
err := ks.EnsureKey(ctx)
assert.NoError(t, err)
require.NoError(t, err)

err = ks.EnsureKey(ctx)
assert.NoError(t, err)
require.NoError(t, err)

keys, err := ks.GetAll()
require.NoError(t, err)
require.Equal(t, 1, len(keys))
require.Len(t, keys, 1)
})

t.Run("sign tx", func(t *testing.T) {
Expand All @@ -125,7 +124,7 @@ func Test_TronKeyStore_E2E(t *testing.T) {

// sign unknown ID
_, err = ks.Sign(testutils.Context(t), "not-real", nil)
assert.Error(t, err)
require.Error(t, err)

// sign known key

Expand All @@ -143,7 +142,7 @@ func Test_TronKeyStore_E2E(t *testing.T) {
require.NoError(t, err)

// signatures should match using keystore sign or key sign
assert.Equal(t, directSig, sig)
require.Equal(t, directSig, sig)
})
}

Expand Down
Loading

0 comments on commit dc9b5a9

Please sign in to comment.