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

[Testing] Unit tests, E2E tests, logging and other Fixes / "Touchups" #253

Merged
merged 21 commits into from
Dec 13, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix unit tests and verify e2e tests again
Olshansk committed Dec 11, 2023
commit d2fe64e69e16714f7530db5c1406813c5beb044f
24 changes: 15 additions & 9 deletions pkg/client/supplier/client_test.go
Original file line number Diff line number Diff line change
@@ -8,16 +8,16 @@ import (

"cosmossdk.io/depinject"
"github.com/golang/mock/gomock"
"github.com/pokt-network/smt"
"github.com/stretchr/testify/require"

"github.com/pokt-network/poktroll/testutil/mockclient"

"github.com/pokt-network/poktroll/pkg/client/keyring"
"github.com/pokt-network/poktroll/pkg/client/supplier"
"github.com/pokt-network/poktroll/pkg/polylog/polyzero"
"github.com/pokt-network/poktroll/testutil/mockclient"
"github.com/pokt-network/poktroll/testutil/testclient/testkeyring"
"github.com/pokt-network/poktroll/testutil/testclient/testtx"
sessiontypes "github.com/pokt-network/poktroll/x/session/types"
sharedtypes "github.com/pokt-network/poktroll/x/shared/types"
"github.com/pokt-network/smt"
"github.com/stretchr/testify/require"
)

var testSigningKeyName = "test_signer"
@@ -76,7 +76,7 @@ func TestSupplierClient_CreateClaim(t *testing.T) {
var (
signAndBroadcastDelay = 50 * time.Millisecond
doneCh = make(chan struct{}, 1)
ctx = context.Background()
ctx = polyzero.NewLogger().WithContext(context.Background())
)

keyring, testAppKey := testkeyring.NewTestKeyringWithKey(t, testSigningKeyName)
@@ -85,7 +85,7 @@ func TestSupplierClient_CreateClaim(t *testing.T) {
require.NoError(t, err)

txCtxMock, _ := testtx.NewAnyTimesTxTxContext(t, keyring)
txClientMock := testtx.NewOneTimeDelayedSignAndBroadcastTxClient(t, signAndBroadcastDelay)
txClientMock := testtx.NewOneTimeDelayedSignAndBroadcastTxClient(t, ctx, signAndBroadcastDelay)

signingKeyOpt := supplier.WithSigningKeyName(testAppKey.Name)
deps := depinject.Supply(
@@ -102,6 +102,9 @@ func TestSupplierClient_CreateClaim(t *testing.T) {
ApplicationAddress: testAppAddr.String(),
SessionStartBlockHeight: 0,
SessionId: "",
Service: &sharedtypes.Service{
Id: "test_service",
},
}

go func() {
@@ -132,7 +135,7 @@ func TestSupplierClient_SubmitProof(t *testing.T) {
var (
signAndBroadcastDelay = 50 * time.Millisecond
doneCh = make(chan struct{}, 1)
ctx = context.Background()
ctx = polyzero.NewLogger().WithContext(context.Background())
)

keyring, testAppKey := testkeyring.NewTestKeyringWithKey(t, testSigningKeyName)
@@ -141,7 +144,7 @@ func TestSupplierClient_SubmitProof(t *testing.T) {
require.NoError(t, err)

txCtxMock, _ := testtx.NewAnyTimesTxTxContext(t, keyring)
txClientMock := testtx.NewOneTimeDelayedSignAndBroadcastTxClient(t, signAndBroadcastDelay)
txClientMock := testtx.NewOneTimeDelayedSignAndBroadcastTxClient(t, ctx, signAndBroadcastDelay)

signingKeyOpt := supplier.WithSigningKeyName(testAppKey.Name)
deps := depinject.Supply(
@@ -157,6 +160,9 @@ func TestSupplierClient_SubmitProof(t *testing.T) {
ApplicationAddress: testAppAddr.String(),
SessionStartBlockHeight: 0,
SessionId: "",
Service: &sharedtypes.Service{
Id: "test_service",
},
}

kvStore, err := smt.NewKVStore("")
3 changes: 1 addition & 2 deletions pkg/relayer/relayminer_test.go
Original file line number Diff line number Diff line change
@@ -6,13 +6,12 @@ import (
"time"

"cosmossdk.io/depinject"
"github.com/stretchr/testify/require"

"github.com/pokt-network/poktroll/pkg/observable/channel"
"github.com/pokt-network/poktroll/pkg/polylog/polyzero"
"github.com/pokt-network/poktroll/pkg/relayer"
"github.com/pokt-network/poktroll/testutil/testrelayer"
servicetypes "github.com/pokt-network/poktroll/x/service/types"
"github.com/stretchr/testify/require"
)

func TestRelayMiner_StartAndStop(t *testing.T) {
12 changes: 6 additions & 6 deletions testutil/testclient/testtx/client.go
Original file line number Diff line number Diff line change
@@ -8,15 +8,13 @@ import (
"cosmossdk.io/depinject"
cosmostypes "github.com/cosmos/cosmos-sdk/types"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/require"

"github.com/pokt-network/poktroll/testutil/mockclient"

"github.com/pokt-network/poktroll/pkg/client"
"github.com/pokt-network/poktroll/pkg/client/tx"
"github.com/pokt-network/poktroll/pkg/either"
"github.com/pokt-network/poktroll/testutil/mockclient"
"github.com/pokt-network/poktroll/testutil/testclient/testblock"
"github.com/pokt-network/poktroll/testutil/testclient/testeventsquery"
"github.com/stretchr/testify/require"
)

type signAndBroadcastFn func(context.Context, cosmostypes.Msg) either.AsyncError
@@ -50,19 +48,21 @@ func NewLocalnetClient(t *testing.T, opts ...client.TxClientOption) client.TxCli
// expectation to perform a SignAndBroadcast operation with a specified delay.
func NewOneTimeDelayedSignAndBroadcastTxClient(
t *testing.T,
ctx context.Context,
delay time.Duration,
) *mockclient.MockTxClient {
t.Helper()

signAndBroadcast := newSignAndBroadcastSucceedsDelayed(delay)
return NewOneTimeSignAndBroadcastTxClient(t, signAndBroadcast)
return NewOneTimeSignAndBroadcastTxClient(t, ctx, signAndBroadcast)
}

// NewOneTimeSignAndBroadcastTxClient constructs a mock TxClient with the
// expectation to perform a SignAndBroadcast operation, which will call and receive
// the return from the given signAndBroadcast function.
func NewOneTimeSignAndBroadcastTxClient(
t *testing.T,
ctx context.Context,
signAndBroadcast signAndBroadcastFn,
) *mockclient.MockTxClient {
t.Helper()
@@ -71,7 +71,7 @@ func NewOneTimeSignAndBroadcastTxClient(

txClient := mockclient.NewMockTxClient(ctrl)
txClient.EXPECT().SignAndBroadcast(
gomock.AssignableToTypeOf(context.Background()),
gomock.Eq(ctx),
gomock.Any(),
).DoAndReturn(signAndBroadcast).Times(1)

1 change: 0 additions & 1 deletion x/supplier/keeper/msg_server_submit_proof.go
Original file line number Diff line number Diff line change
@@ -4,7 +4,6 @@ import (
"context"

sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/pokt-network/poktroll/x/supplier/types"
)