Skip to content

Commit

Permalink
chore: off-chain review improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
red-0ne authored and bryanchriswhite committed Feb 21, 2024
1 parent d008f57 commit d20affb
Show file tree
Hide file tree
Showing 34 changed files with 165 additions and 193 deletions.
44 changes: 22 additions & 22 deletions pkg/appgateserver/config/appgate_configs_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func Test_ParseAppGateConfigs(t *testing.T) {

inputConfigYAML string

expectedError *sdkerrors.Error
expectedErr *sdkerrors.Error
expectedConfig *config.AppGateServerConfig
}{
// Valid Configs
Expand All @@ -33,7 +33,7 @@ func Test_ParseAppGateConfigs(t *testing.T) {
listening_endpoint: http://localhost:42069
`,

expectedError: nil,
expectedErr: nil,
expectedConfig: &config.AppGateServerConfig{
QueryNodeRPCUrl: &url.URL{Scheme: "tcp", Host: "127.0.0.1:36657"},
QueryNodeGRPCUrl: &url.URL{Scheme: "tcp", Host: "127.0.0.1:36658"},
Expand All @@ -52,7 +52,7 @@ func Test_ParseAppGateConfigs(t *testing.T) {
listening_endpoint: http://localhost:42069
`,

expectedError: nil,
expectedErr: nil,
expectedConfig: &config.AppGateServerConfig{
QueryNodeRPCUrl: &url.URL{Scheme: "tcp", Host: "127.0.0.1:36657"},
QueryNodeGRPCUrl: &url.URL{Scheme: "tcp", Host: "127.0.0.1:36658"},
Expand All @@ -67,7 +67,7 @@ func Test_ParseAppGateConfigs(t *testing.T) {

inputConfigYAML: ``,

expectedError: config.ErrAppGateConfigEmpty,
expectedErr: config.ErrAppGateConfigEmpty,
},
{
desc: "invalid: no signing key",
Expand All @@ -80,7 +80,7 @@ func Test_ParseAppGateConfigs(t *testing.T) {
listening_endpoint: http://localhost:42069
`,

expectedError: config.ErrAppGateConfigEmptySigningKey,
expectedErr: config.ErrAppGateConfigEmptySigningKey,
},
{
desc: "invalid: invalid listening endpoint",
Expand All @@ -93,7 +93,7 @@ func Test_ParseAppGateConfigs(t *testing.T) {
listening_endpoint: l&ocalhost:42069
`,

expectedError: config.ErrAppGateConfigInvalidListeningEndpoint,
expectedErr: config.ErrAppGateConfigInvalidListeningEndpoint,
},
{
desc: "invalid: invalid query node grpc url",
Expand All @@ -106,7 +106,7 @@ func Test_ParseAppGateConfigs(t *testing.T) {
listening_endpoint: http://localhost:42069
`,

expectedError: config.ErrAppGateConfigInvalidQueryNodeGRPCUrl,
expectedErr: config.ErrAppGateConfigInvalidQueryNodeGRPCUrl,
},
{
desc: "invalid: missing query node grpc url",
Expand All @@ -119,7 +119,7 @@ func Test_ParseAppGateConfigs(t *testing.T) {
listening_endpoint: http://localhost:42069
`,

expectedError: config.ErrAppGateConfigInvalidQueryNodeGRPCUrl,
expectedErr: config.ErrAppGateConfigInvalidQueryNodeGRPCUrl,
},
{
desc: "invalid: invalid query node rpc url",
Expand All @@ -132,7 +132,7 @@ func Test_ParseAppGateConfigs(t *testing.T) {
listening_endpoint: http://localhost:42069
`,

expectedError: config.ErrAppGateConfigInvalidQueryNodeRPCUrl,
expectedErr: config.ErrAppGateConfigInvalidQueryNodeRPCUrl,
},
{
desc: "invalid: missing query node rpc url",
Expand All @@ -145,32 +145,32 @@ func Test_ParseAppGateConfigs(t *testing.T) {
listening_endpoint: http://localhost:42069
`,

expectedError: config.ErrAppGateConfigInvalidQueryNodeRPCUrl,
expectedErr: config.ErrAppGateConfigInvalidQueryNodeRPCUrl,
},
}

for _, tt := range tests {
t.Run(tt.desc, func(t *testing.T) {
normalizedConfig := yaml.NormalizeYAMLIndentation(tt.inputConfigYAML)
for _, test := range tests {
t.Run(test.desc, func(t *testing.T) {
normalizedConfig := yaml.NormalizeYAMLIndentation(test.inputConfigYAML)
config, err := config.ParseAppGateServerConfigs([]byte(normalizedConfig))

if tt.expectedError != nil {
require.ErrorIs(t, err, tt.expectedError)
if test.expectedErr != nil {
require.ErrorIs(t, err, test.expectedErr)
require.Nil(t, config)
stat, ok := status.FromError(tt.expectedError)
stat, ok := status.FromError(test.expectedErr)
require.True(t, ok)
require.Contains(t, stat.Message(), tt.expectedError.Error())
require.Contains(t, stat.Message(), test.expectedErr.Error())
require.Nil(t, config)
return
}

require.NoError(t, err)

require.Equal(t, tt.expectedConfig.SelfSigning, config.SelfSigning)
require.Equal(t, tt.expectedConfig.SigningKey, config.SigningKey)
require.Equal(t, tt.expectedConfig.ListeningEndpoint.String(), config.ListeningEndpoint.String())
require.Equal(t, tt.expectedConfig.QueryNodeGRPCUrl.String(), config.QueryNodeGRPCUrl.String())
require.Equal(t, tt.expectedConfig.QueryNodeGRPCUrl.String(), config.QueryNodeGRPCUrl.String())
require.Equal(t, test.expectedConfig.SelfSigning, config.SelfSigning)
require.Equal(t, test.expectedConfig.SigningKey, config.SigningKey)
require.Equal(t, test.expectedConfig.ListeningEndpoint.String(), config.ListeningEndpoint.String())
require.Equal(t, test.expectedConfig.QueryNodeGRPCUrl.String(), config.QueryNodeGRPCUrl.String())
require.Equal(t, test.expectedConfig.QueryNodeGRPCUrl.String(), config.QueryNodeGRPCUrl.String())
})
}
}
12 changes: 6 additions & 6 deletions pkg/appgateserver/config/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import sdkerrors "cosmossdk.io/errors"

var (
codespace = "appgate_config"
ErrAppGateConfigUnmarshalYAML = sdkerrors.Register(codespace, 1, "config reader cannot unmarshal yaml content")
ErrAppGateConfigEmptySigningKey = sdkerrors.Register(codespace, 2, "empty signing key in AppGateServer config")
ErrAppGateConfigInvalidListeningEndpoint = sdkerrors.Register(codespace, 3, "invalid listening endpoint in AppGateServer config")
ErrAppGateConfigInvalidQueryNodeGRPCUrl = sdkerrors.Register(codespace, 4, "invalid query node grpc url in AppGateServer config")
ErrAppGateConfigInvalidQueryNodeRPCUrl = sdkerrors.Register(codespace, 5, "invalid query node rpc url in AppGateServer config")
ErrAppGateConfigEmpty = sdkerrors.Register(codespace, 6, "empty AppGateServer config")
ErrAppGateConfigUnmarshalYAML = sdkerrors.Register(codespace, 2100, "config reader cannot unmarshal yaml content")
ErrAppGateConfigEmptySigningKey = sdkerrors.Register(codespace, 2101, "empty signing key in AppGateServer config")
ErrAppGateConfigInvalidListeningEndpoint = sdkerrors.Register(codespace, 2102, "invalid listening endpoint in AppGateServer config")
ErrAppGateConfigInvalidQueryNodeGRPCUrl = sdkerrors.Register(codespace, 2103, "invalid query node grpc url in AppGateServer config")
ErrAppGateConfigInvalidQueryNodeRPCUrl = sdkerrors.Register(codespace, 2104, "invalid query node rpc url in AppGateServer config")
ErrAppGateConfigEmpty = sdkerrors.Register(codespace, 2105, "empty AppGateServer config")
)
4 changes: 1 addition & 3 deletions pkg/appgateserver/options.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package appgateserver

import (
"net/url"
)
import "net/url"

// WithSigningInformation sets the signing information for the appgate server.
func WithSigningInformation(signingInfo *SigningInformation) appGateServerOption {
Expand Down
6 changes: 3 additions & 3 deletions pkg/client/block/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ func TestBlockClient(t *testing.T) {
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
actualBlockCh := make(chan client.Block, 10)

// Run test functions asynchronously because they can block, leading
Expand All @@ -102,7 +102,7 @@ func TestBlockClient(t *testing.T) {
go func(fn func() client.Block) {
actualBlockCh <- fn()
close(actualBlockCh)
}(tt.fn)
}(test.fn)

select {
case actualBlock := <-actualBlockCh:
Expand Down
6 changes: 3 additions & 3 deletions pkg/client/delegation/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ func TestDelegationClient(t *testing.T) {
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
actualRedelegationCh := make(chan client.Redelegation, 10)

// Run test functions asynchronously because they can block, leading
Expand All @@ -84,7 +84,7 @@ func TestDelegationClient(t *testing.T) {
go func(fn func() client.Redelegation) {
actualRedelegationCh <- fn()
close(actualRedelegationCh)
}(tt.fn)
}(test.fn)

select {
case actualRedelegation := <-actualRedelegationCh:
Expand Down
4 changes: 1 addition & 3 deletions pkg/client/events/errors.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package events

import (
sdkerrors "cosmossdk.io/errors"
)
import sdkerrors "cosmossdk.io/errors"

var (
codespace = "events"
Expand Down
4 changes: 1 addition & 3 deletions pkg/client/events/websocket/errors.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package websocket

import (
sdkerrors "cosmossdk.io/errors"
)
import sdkerrors "cosmossdk.io/errors"

var (
codespace = "events_query_client_websocket_connection"
Expand Down
6 changes: 3 additions & 3 deletions pkg/client/query/appquerier.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ func (aq *appQuerier) GetApplication(

// GetAllApplications returns all staked applications
func (aq *appQuerier) GetAllApplications(ctx context.Context) ([]apptypes.Application, error) {
req := apptypes.QueryAllApplicationRequest{}
res, err := aq.applicationQuerier.ApplicationAll(ctx, &req)
req := apptypes.QueryAllApplicationsRequest{}
res, err := aq.applicationQuerier.AllApplications(ctx, &req)
if err != nil {
return []apptypes.Application{}, err
}
return res.Application, nil
return res.Applications, nil
}
4 changes: 1 addition & 3 deletions pkg/client/query/errors.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package query

import (
sdkerrors "cosmossdk.io/errors"
)
import sdkerrors "cosmossdk.io/errors"

var (
codespace = "query"
Expand Down
4 changes: 1 addition & 3 deletions pkg/client/query/types/context.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package types

import (
cosmosclient "github.com/cosmos/cosmos-sdk/client"
)
import cosmosclient "github.com/cosmos/cosmos-sdk/client"

// Context is used to distinguish a cosmosclient.Context intended for use in
// queries from others. This is because the same cosmosclient.Context can be
Expand Down
10 changes: 5 additions & 5 deletions pkg/client/supplier/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ func TestNewSupplierClient(t *testing.T) {
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
signingKeyOpt := supplier.WithSigningKeyName(tt.signingKeyName)
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
signingKeyOpt := supplier.WithSigningKeyName(test.signingKeyName)

supplierClient, err := supplier.NewSupplierClient(deps, signingKeyOpt)
if tt.expectedErr != nil {
require.ErrorIs(t, err, tt.expectedErr)
if test.expectedErr != nil {
require.ErrorIs(t, err, test.expectedErr)
require.Nil(t, supplierClient)
} else {
require.NoError(t, err)
Expand Down
4 changes: 1 addition & 3 deletions pkg/client/supplier/options.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package supplier

import (
"github.com/pokt-network/poktroll/pkg/client"
)
import "github.com/pokt-network/poktroll/pkg/client"

// WithSigningKeyName sets the name of the key which the supplier client should
// retrieve from the keyring to use for authoring and signing CreateClaim and
Expand Down
8 changes: 4 additions & 4 deletions pkg/client/tx/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ func TestTxClient_NewTxClient_Error(t *testing.T) {
// },
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
var (
ctrl = gomock.NewController(t)
ctx = context.Background()
Expand All @@ -192,11 +192,11 @@ func TestTxClient_NewTxClient_Error(t *testing.T) {
)

// Construct a signing key option using the test signing key name.
signingKeyOpt := tx.WithSigningKeyName(tt.signingKeyName)
signingKeyOpt := tx.WithSigningKeyName(test.signingKeyName)

// Attempt to create the transactions client.
txClient, err := tx.NewTxClient(ctx, txClientDeps, signingKeyOpt)
require.ErrorIs(t, err, tt.expectedErr)
require.ErrorIs(t, err, test.expectedErr)
require.Nil(t, txClient)
})
}
Expand Down
4 changes: 1 addition & 3 deletions pkg/client/tx/options.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package tx

import (
"github.com/pokt-network/poktroll/pkg/client"
)
import "github.com/pokt-network/poktroll/pkg/client"

// WithCommitTimeoutBlocks sets the timeout duration in terms of number of blocks
// for the client to wait for broadcast transactions to be committed before
Expand Down
4 changes: 1 addition & 3 deletions pkg/client/tx/types/context.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package types

import (
cosmosclient "github.com/cosmos/cosmos-sdk/client"
)
import cosmosclient "github.com/cosmos/cosmos-sdk/client"

// Context is used to distinguish a cosmosclient.Context intended for use in
// transactions from others. This is because the same cosmosclient.Context can
Expand Down
4 changes: 1 addition & 3 deletions pkg/crypto/rings/errors.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package rings

import (
sdkerrors "cosmossdk.io/errors"
)
import sdkerrors "cosmossdk.io/errors"

var (
codespace = "rings"
Expand Down
14 changes: 7 additions & 7 deletions pkg/observable/channel/map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ func TestMap_Word_BytesToPalindrome(t *testing.T) {
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
var (
wordCounter int32
ctx, cancel = context.WithCancel(context.Background())
Expand All @@ -45,21 +45,21 @@ func TestMap_Word_BytesToPalindrome(t *testing.T) {
palindromeObserver := palindromeObservable.Subscribe(ctx)

// publish a word in bytes
bzPublishCh <- tt.wordBz
bzPublishCh <- test.wordBz

// concurrently consume the palindrome observer's channel
go func() {
for word := range palindromeObserver.Ch() {
atomic.AddInt32(&wordCounter, 1)

// word.forwards should always match the original word
require.Equal(t, string(tt.wordBz), word.forwards)
require.Equal(t, string(test.wordBz), word.forwards)

if tt.isValid {
require.Equal(t, string(tt.wordBz), word.backwards)
if test.isValid {
require.Equal(t, string(test.wordBz), word.backwards)
require.Truef(t, word.IsValid(), "palindrome should be valid")
} else {
require.NotEmptyf(t, string(tt.wordBz), word.backwards)
require.NotEmptyf(t, string(test.wordBz), word.backwards)
require.Falsef(t, word.IsValid(), "palindrome should be invalid")
}
}
Expand Down
Loading

0 comments on commit d20affb

Please sign in to comment.