-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'pokt/main' into issues/126/test/miner
* pokt/main: [RelayMiner, Testing, Off-chain] test: `relayer` pkg (#193) [Relayminer] chore: cleanup after 177 (#190)
- Loading branch information
Showing
12 changed files
with
234 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package relayer_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"cosmossdk.io/depinject" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/pokt-network/poktroll/pkg/observable/channel" | ||
"github.com/pokt-network/poktroll/pkg/relayer" | ||
"github.com/pokt-network/poktroll/testutil/testrelayer" | ||
servicetypes "github.com/pokt-network/poktroll/x/service/types" | ||
) | ||
|
||
func TestRelayMiner_StartAndStop(t *testing.T) { | ||
srObs, _ := channel.NewObservable[*servicetypes.Relay]() | ||
servedRelaysObs := relayer.RelaysObservable(srObs) | ||
|
||
mrObs, _ := channel.NewObservable[*relayer.MinedRelay]() | ||
minedRelaysObs := relayer.MinedRelaysObservable(mrObs) | ||
|
||
ctx := context.Background() | ||
relayerProxyMock := testrelayer.NewMockOneTimeRelayerProxy( | ||
ctx, t, | ||
servedRelaysObs, | ||
) | ||
|
||
minerMock := testrelayer.NewMockOneTimeMiner( | ||
ctx, t, | ||
servedRelaysObs, | ||
minedRelaysObs, | ||
) | ||
|
||
relayerSessionsManagerMock := testrelayer.NewMockOneTimeRelayerSessionsManager( | ||
ctx, t, | ||
minedRelaysObs, | ||
) | ||
|
||
deps := depinject.Supply( | ||
relayerProxyMock, | ||
minerMock, | ||
relayerSessionsManagerMock, | ||
) | ||
|
||
relayminer, err := relayer.NewRelayMiner(ctx, deps) | ||
require.NoError(t, err) | ||
require.NotNil(t, relayminer) | ||
|
||
err = relayminer.Start(ctx) | ||
require.NoError(t, err) | ||
|
||
time.Sleep(time.Millisecond) | ||
|
||
err = relayminer.Stop(ctx) | ||
require.NoError(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package mockrelayer | ||
|
||
// This file is in place to declare the package for dynamically generated structs. | ||
// | ||
// Note that this does not follow the Cosmos SDK pattern of committing Mocks to main. | ||
// For example, they commit auto-generate code to main: https://github.com/cosmos/cosmos-sdk/blob/main/x/gov/testutil/expected_keepers_mocks.go | ||
// Documentation on how Cosmos uses mockgen can be found here: https://docs.cosmos.network/main/build/building-modules/testing#unit-tests | ||
// | ||
// IMPORTANT: We have attempted to use `.gitkeep` files instead, but it causes a circular dependency issue with protobuf and mock generation | ||
// since we are leveraging `ignite` to compile `.proto` files which runs `go mod tidy` before generating, requiring the entire dependency tree | ||
// to be valid before mock implementations have been generated. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package testrelayer | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/golang/mock/gomock" | ||
|
||
"github.com/pokt-network/poktroll/pkg/relayer" | ||
"github.com/pokt-network/poktroll/testutil/mockrelayer" | ||
) | ||
|
||
// NewMockOneTimeMiner creates a new mock Miner. This mock Miner will expect a | ||
// call to MinedRelays with the given context and expectedRelayObs args. When | ||
// that call is made, returnedMinedRelaysObs is returned. | ||
func NewMockOneTimeMiner( | ||
ctx context.Context, | ||
t *testing.T, | ||
expectedRelaysObs relayer.RelaysObservable, | ||
returnedMinedRelaysObs relayer.MinedRelaysObservable, | ||
) *mockrelayer.MockMiner { | ||
t.Helper() | ||
|
||
ctrl := gomock.NewController(t) | ||
minerMock := mockrelayer.NewMockMiner(ctrl) | ||
minerMock.EXPECT(). | ||
MinedRelays( | ||
gomock.Eq(ctx), | ||
gomock.Eq(expectedRelaysObs), | ||
). | ||
Return(returnedMinedRelaysObs). | ||
Times(1) | ||
return minerMock | ||
} |
Oops, something went wrong.