-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[OTE-780] Add client code for affiliates (#2252)
- Loading branch information
Showing
13 changed files
with
298 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
syntax = "proto3"; | ||
package dydxprotocol.affiliates; | ||
import "gogoproto/gogo.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 ]; | ||
} |
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,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)) | ||
} | ||
|
||
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)) | ||
} |
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
Oops, something went wrong.