-
Notifications
You must be signed in to change notification settings - Fork 124
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
[OTE-780] Add client code for affiliates #2252
Changes from 1 commit
7fdb5c9
2e5732c
8cc99a3
24bd618
5c95dd7
d93ae49
4e5599b
54e8d55
05c4163
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,13 @@ | ||
syntax = "proto3"; | ||
package dydxprotocol.affiliates; | ||
import "gogoproto/gogo.proto"; | ||
import "cosmos_proto/cosmos.proto"; | ||
import "dydxprotocol/affiliates/affiliates.proto"; | ||
|
||
option go_package = "github.com/dydxprotocol/v4-chain/protocol/x/affiliates/types"; | ||
|
||
// GenesisState defines generis state of `x/affiliates` | ||
message GenesisState {} | ||
message GenesisState { | ||
// The list of affiliate tiers | ||
AffiliateTiers affiliate_tiers = 1 [ (gogoproto.nullable) = false ]; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package cli_test | ||
|
||
import ( | ||
"strconv" | ||
"testing" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/dydxprotocol/v4-chain/protocol/testutil/constants" | ||
"github.com/dydxprotocol/v4-chain/protocol/testutil/network" | ||
"github.com/dydxprotocol/v4-chain/protocol/x/affiliates/client/cli" | ||
"github.com/dydxprotocol/v4-chain/protocol/x/affiliates/types" | ||
) | ||
|
||
// Prevent strconv unused error | ||
var _ = strconv.IntSize | ||
|
||
func setupNetwork(t *testing.T) (*network.Network, client.Context) { | ||
t.Helper() | ||
cfg := network.DefaultConfig(nil) | ||
|
||
// Init state. | ||
state := types.GenesisState{} | ||
require.NoError(t, cfg.Codec.UnmarshalJSON(cfg.GenesisState[types.ModuleName], &state)) | ||
|
||
// Modify default genesis state | ||
state = *types.DefaultGenesis() | ||
|
||
// Add test affiliate tiers | ||
state.AffiliateTiers = types.DefaultAffiliateTiers | ||
|
||
buf, err := cfg.Codec.MarshalJSON(&state) | ||
require.NoError(t, err) | ||
cfg.GenesisState[types.ModuleName] = buf | ||
net := network.New(t, cfg) | ||
ctx := net.Validators[0].ClientCtx | ||
|
||
return net, ctx | ||
} | ||
|
||
func TestQueryAffiliateTiers(t *testing.T) { | ||
net, ctx := setupNetwork(t) | ||
|
||
out, err := clitestutil.ExecTestCLICmd(ctx, cli.GetCmdQueryAffiliateTiers(), []string{}) | ||
require.NoError(t, err) | ||
|
||
var resp types.AllAffiliateTiersResponse | ||
require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) | ||
require.Equal(t, types.DefaultAffiliateTiers, resp.Tiers) | ||
} | ||
|
||
func TestQueryAffiliateInfo(t *testing.T) { | ||
net, ctx := setupNetwork(t) | ||
|
||
testAddress := constants.AliceAccAddress.String() | ||
out, err := clitestutil.ExecTestCLICmd(ctx, cli.GetCmdQueryAffiliateInfo(), []string{testAddress}) | ||
require.NoError(t, err) | ||
|
||
var resp types.AffiliateInfoResponse | ||
require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) | ||
} | ||
Comment on lines
+54
to
+63
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add assertions for the returned affiliate info. The However, it does not assert anything about the returned affiliate info. Consider adding assertions to check that the returned affiliate info matches the expected values for the test address. |
||
|
||
func TestQueryReferredBy(t *testing.T) { | ||
net, ctx := setupNetwork(t) | ||
|
||
testAddress := constants.AliceAccAddress.String() | ||
out, err := clitestutil.ExecTestCLICmd(ctx, cli.GetCmdQueryReferredBy(), []string{testAddress}) | ||
require.NoError(t, err) | ||
|
||
var resp types.ReferredByResponse | ||
require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) | ||
} | ||
Comment on lines
+65
to
+74
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add assertions for the returned referred-by info. The However, it does not assert anything about the returned referred-by info. Consider adding assertions to check that the returned referred-by info matches the expected values for the test address. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,11 +49,7 @@ func (k Keeper) ReferredBy(ctx context.Context, | |
|
||
affiliateAddr, exists := k.GetReferredBy(sdkCtx, req.GetAddress()) | ||
if !exists { | ||
return &types.ReferredByResponse{}, errorsmod.Wrapf( | ||
types.ErrAffiliateNotFound, | ||
"affiliate not found for address: %s", | ||
req.GetAddress(), | ||
) | ||
return &types.ReferredByResponse{}, nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tip Codebase Verification Based on the analysis of the test cases, it appears that the tests for the ReferredBy function have not been updated to reflect the new behavior of returning an empty response instead of an error when no affiliate is found. This inconsistency could lead to potential issues and false negative test results. To address this, we should recommend updating the test cases to align with the new implementation. Here's the final response: Update test cases for ReferredBy function to expect empty response The test cases for the ReferredBy function in
This update will ensure that the tests accurately reflect the new implementation and prevent potential false negative results. Analysis chainVerify the impact of returning an empty response on the calling code. The change simplifies the control flow by removing the error handling when an affiliate is not found and returns an empty Please verify that the calling code and the broader application can handle the empty response correctly. You can use the following script to search for the usage of the To complete the verification process, we need to check if the test cases for the ReferredBy function have been updated to expect an empty response instead of an error when no affiliate is found. Let's examine the relevant test file. Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Verify the impact of returning an empty response on the calling code.
# Test: Search for the function usage. Expect: Analyze how the response is handled.
rg --type go -A 10 $'ReferredBy\('
Length of output: 18042 Script: #!/bin/bash
# Description: Check if test cases for ReferredBy have been updated
# Test: Examine the test cases for ReferredBy function
cat protocol/x/affiliates/keeper/grpc_query_test.go
Length of output: 5723 |
||
} | ||
|
||
return &types.ReferredByResponse{ | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix the missing import for "gogoproto/gogo.proto".
The static analysis tool
buf
reports a missing import for "gogoproto/gogo.proto". This issue needs to be resolved to ensure successful compilation of the code.Please check the following:
gogoproto
library is properly installed and configured in your project's build system.If you need further assistance, I'd be happy to help you resolve this issue. Let me know if you'd like me to investigate further or provide more specific guidance.
Tools
buf