-
Notifications
You must be signed in to change notification settings - Fork 12
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/553/fix/relayer-…
…session-manager * pokt/main: [Observables] chore: add `ReplayObservable#SubscribeFromLatestBufferedOffset()` (#647) [Observability] Add claim relays counter (#644) [Code Health] chore: log unused error when updating relay mining difficulty (#683) [Testing] chore: uncomment proof CLI query tests (#668)
- Loading branch information
Showing
10 changed files
with
545 additions
and
295 deletions.
There are no files selected for viewing
311 changes: 240 additions & 71 deletions
311
localnet/grafana-dashboards/stress-test-dashboard.json
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,150 +1,173 @@ | ||
package proof_test | ||
|
||
// TODO_BLOCKER(@Olshansk): Add these tests back in after merging on-chain Proof persistence. | ||
// Prevent strconv unused error | ||
// var _ = strconv.IntSize | ||
// | ||
// func networkWithProofObjects(t *testing.T, n int) (*network.Network, []types.Proof) { | ||
// t.Helper() | ||
// cfg := network.DefaultConfig() | ||
// state := types.GenesisState{} | ||
// for i := 0; i < n; i++ { | ||
// proof := types.Proof{ | ||
// Index: strconv.Itoa(i), | ||
// | ||
// } | ||
// nullify.Fill(&proof) | ||
// state.ProofList = append(state.ProofList, proof) | ||
// } | ||
// buf, err := cfg.Codec.MarshalJSON(&state) | ||
// require.NoError(t, err) | ||
// cfg.GenesisState[types.ModuleName] = buf | ||
// return network.New(t, cfg), state.ProofList | ||
// } | ||
// | ||
// func TestShowProof(t *testing.T) { | ||
// net, proofs := networkWithProofObjects(t, 2) | ||
// | ||
// ctx := net.Validators[0].ClientCtx | ||
// common := []string{ | ||
// fmt.Sprintf("--%s=json", tmcli.OutputFlag), | ||
// } | ||
// tests := []struct { | ||
// desc string | ||
// idIndex string | ||
// | ||
// args []string | ||
// expectedErr error | ||
// proof types.Proof | ||
// }{ | ||
// { | ||
// desc: "found", | ||
// idIndex: proofs[0].Index, | ||
// | ||
// args: common, | ||
// proof: proofs[0], | ||
// }, | ||
// { | ||
// desc: "not found", | ||
// idIndex: strconv.Itoa(100000), | ||
// | ||
// args: common, | ||
// expectedErr: status.Error(codes.NotFound, "not found"), | ||
// }, | ||
// } | ||
// for _, test := range tests { | ||
// t.Run(test.desc, func(t *testing.T) { | ||
// args := []string{ | ||
// test.idIndex, | ||
// | ||
// } | ||
// args = append(args, test.args...) | ||
// out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdShowProof(), args) | ||
// if test.expectedErr != nil { | ||
// stat, ok := status.FromError(test.expectedErr) | ||
// require.True(t, ok) | ||
// require.ErrorIs(t, stat.Err(), test.expectedErr) | ||
// } else { | ||
// require.NoError(t, err) | ||
// var resp types.QueryGetProofResponse | ||
// require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) | ||
// require.NotNil(t, resp.Proof) | ||
// require.Equal(t, | ||
// nullify.Fill(&test.proof), | ||
// nullify.Fill(&resp.Proof), | ||
// ) | ||
// } | ||
// }) | ||
// } | ||
// } | ||
// | ||
// func TestListProof(t *testing.T) { | ||
// net, proofs := networkWithProofObjects(t, 5) | ||
// | ||
// ctx := net.Validators[0].ClientCtx | ||
// request := func(next []byte, offset, limit uint64, total bool) []string { | ||
// args := []string{ | ||
// fmt.Sprintf("--%s=json", tmcli.OutputFlag), | ||
// } | ||
// if next == nil { | ||
// args = append(args, fmt.Sprintf("--%s=%d", flags.FlagOffset, offset)) | ||
// } else { | ||
// args = append(args, fmt.Sprintf("--%s=%s", flags.FlagPageKey, next)) | ||
// } | ||
// args = append(args, fmt.Sprintf("--%s=%d", flags.FlagLimit, limit)) | ||
// if total { | ||
// args = append(args, fmt.Sprintf("--%s", flags.FlagCountTotal)) | ||
// } | ||
// return args | ||
// } | ||
// | ||
// t.Run("ByOffset", func(t *testing.T) { | ||
// step := 2 | ||
// for i := 0; i < len(proofs); i += step { | ||
// args := request(nil, uint64(i), uint64(step), false) | ||
// out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdListProof(), args) | ||
// require.NoError(t, err) | ||
// var resp types.QueryAllProofsResponse | ||
// require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) | ||
// require.LessOrEqual(t, len(resp.Proof), step) | ||
// require.Subset(t, | ||
// nullify.Fill(proofs), | ||
// nullify.Fill(resp.Proof), | ||
// ) | ||
// } | ||
// }) | ||
// | ||
// t.Run("ByKey", func(t *testing.T) { | ||
// step := 2 | ||
// var next []byte | ||
// for i := 0; i < len(proofs); i += step { | ||
// args := request(next, 0, uint64(step), false) | ||
// out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdListProof(), args) | ||
// require.NoError(t, err) | ||
// var resp types.QueryAllProofsResponse | ||
// require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) | ||
// require.LessOrEqual(t, len(resp.Proof), step) | ||
// require.Subset(t, | ||
// nullify.Fill(proofs), | ||
// nullify.Fill(resp.Proof), | ||
// ) | ||
// next = resp.Pagination.NextKey | ||
// } | ||
// }) | ||
// | ||
// TODO_TEST: add "BySupplierAddress", "BySession", "ByHeight" tests. | ||
// | ||
// t.Run("Total", func(t *testing.T) { | ||
// args := request(nil, 0, uint64(len(proofs)), true) | ||
// out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdListProof(), args) | ||
// require.NoError(t, err) | ||
// var resp types.QueryAllProofsResponse | ||
// require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) | ||
// require.NoError(t, err) | ||
// require.Equal(t, len(proofs), int(resp.Pagination.Total)) | ||
// require.ElementsMatch(t, | ||
// nullify.Fill(proofs), | ||
// nullify.Fill(resp.Proof), | ||
// ) | ||
// }) | ||
// } | ||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
cometcli "github.com/cometbft/cometbft/libs/cli" | ||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" | ||
"github.com/stretchr/testify/require" | ||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/status" | ||
|
||
"github.com/pokt-network/poktroll/testutil/network" | ||
"github.com/pokt-network/poktroll/testutil/nullify" | ||
"github.com/pokt-network/poktroll/testutil/sample" | ||
proof "github.com/pokt-network/poktroll/x/proof/module" | ||
"github.com/pokt-network/poktroll/x/proof/types" | ||
sessiontypes "github.com/pokt-network/poktroll/x/session/types" | ||
) | ||
|
||
func networkWithProofObjects(t *testing.T, n int) (*network.Network, []types.Proof) { | ||
t.Helper() | ||
cfg := network.DefaultConfig() | ||
state := types.GenesisState{} | ||
for i := 0; i < n; i++ { | ||
proof := types.Proof{ | ||
SupplierAddress: sample.AccAddress(), | ||
SessionHeader: &sessiontypes.SessionHeader{ | ||
SessionId: "mock_session_id", | ||
// Other fields omitted and unused for these tests. | ||
}, | ||
// CloseseMerkleProof not required for these tests. | ||
ClosestMerkleProof: nil, | ||
} | ||
nullify.Fill(&proof) | ||
state.ProofList = append(state.ProofList, proof) | ||
} | ||
buf, err := cfg.Codec.MarshalJSON(&state) | ||
require.NoError(t, err) | ||
cfg.GenesisState[types.ModuleName] = buf | ||
return network.New(t, cfg), state.ProofList | ||
} | ||
|
||
func TestShowProof(t *testing.T) { | ||
net, proofs := networkWithProofObjects(t, 2) | ||
|
||
ctx := net.Validators[0].ClientCtx | ||
common := []string{ | ||
fmt.Sprintf("--%s=json", cometcli.OutputFlag), | ||
} | ||
tests := []struct { | ||
desc string | ||
sessionId string | ||
supplierAddr string | ||
|
||
args []string | ||
expectedErr error | ||
proof types.Proof | ||
}{ | ||
{ | ||
desc: "found", | ||
supplierAddr: proofs[0].SupplierAddress, | ||
sessionId: proofs[0].SessionHeader.SessionId, | ||
|
||
args: common, | ||
proof: proofs[0], | ||
}, | ||
{ | ||
desc: "not found", | ||
supplierAddr: sample.AccAddress(), | ||
sessionId: proofs[0].SessionHeader.SessionId, | ||
|
||
args: common, | ||
expectedErr: status.Error(codes.NotFound, "not found"), | ||
}, | ||
} | ||
for _, test := range tests { | ||
t.Run(test.desc, func(t *testing.T) { | ||
args := []string{ | ||
test.sessionId, | ||
test.supplierAddr, | ||
} | ||
args = append(args, test.args...) | ||
out, err := clitestutil.ExecTestCLICmd(ctx, proof.CmdShowProof(), args) | ||
if test.expectedErr != nil { | ||
stat, ok := status.FromError(test.expectedErr) | ||
require.True(t, ok) | ||
require.ErrorIs(t, stat.Err(), test.expectedErr) | ||
} else { | ||
require.NoError(t, err) | ||
var resp types.QueryGetProofResponse | ||
require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) | ||
require.NotNil(t, resp.Proof) | ||
require.Equal(t, | ||
nullify.Fill(&test.proof), | ||
nullify.Fill(&resp.Proof), | ||
) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestListProof(t *testing.T) { | ||
net, proofs := networkWithProofObjects(t, 5) | ||
|
||
ctx := net.Validators[0].ClientCtx | ||
request := func(next []byte, offset, limit uint64, total bool) []string { | ||
args := []string{ | ||
fmt.Sprintf("--%s=json", cometcli.OutputFlag), | ||
} | ||
if next == nil { | ||
args = append(args, fmt.Sprintf("--%s=%d", flags.FlagOffset, offset)) | ||
} else { | ||
args = append(args, fmt.Sprintf("--%s=%s", flags.FlagPageKey, next)) | ||
} | ||
args = append(args, fmt.Sprintf("--%s=%d", flags.FlagLimit, limit)) | ||
if total { | ||
args = append(args, fmt.Sprintf("--%s", flags.FlagCountTotal)) | ||
} | ||
return args | ||
} | ||
|
||
t.Run("ByOffset", func(t *testing.T) { | ||
step := 2 | ||
for i := 0; i < len(proofs); i += step { | ||
args := request(nil, uint64(i), uint64(step), false) | ||
out, err := clitestutil.ExecTestCLICmd(ctx, proof.CmdListProof(), args) | ||
require.NoError(t, err) | ||
var resp types.QueryAllProofsResponse | ||
require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) | ||
require.LessOrEqual(t, len(resp.Proofs), step) | ||
require.Subset(t, | ||
nullify.Fill(proofs), | ||
nullify.Fill(resp.Proofs), | ||
) | ||
} | ||
}) | ||
|
||
t.Run("ByKey", func(t *testing.T) { | ||
step := 2 | ||
var next []byte | ||
for i := 0; i < len(proofs); i += step { | ||
args := request(next, 0, uint64(step), false) | ||
out, err := clitestutil.ExecTestCLICmd(ctx, proof.CmdListProof(), args) | ||
require.NoError(t, err) | ||
var resp types.QueryAllProofsResponse | ||
require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) | ||
require.LessOrEqual(t, len(resp.Proofs), step) | ||
require.Subset(t, | ||
nullify.Fill(proofs), | ||
nullify.Fill(resp.Proofs), | ||
) | ||
next = resp.Pagination.NextKey | ||
} | ||
}) | ||
|
||
//TODO_TEST: add "ByHeight" test. | ||
|
||
t.Run("Total", func(t *testing.T) { | ||
args := request(nil, 0, uint64(len(proofs)), true) | ||
out, err := clitestutil.ExecTestCLICmd(ctx, proof.CmdListProof(), args) | ||
require.NoError(t, err) | ||
var resp types.QueryAllProofsResponse | ||
require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) | ||
require.NoError(t, err) | ||
require.Equal(t, len(proofs), int(resp.Pagination.Total)) | ||
require.ElementsMatch(t, | ||
nullify.Fill(proofs), | ||
nullify.Fill(resp.Proofs), | ||
) | ||
}) | ||
} |
Oops, something went wrong.