-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[OTE-839] add query for unconditional revshare (#2380)
(cherry picked from commit 60cc7aa)
- Loading branch information
1 parent
d0d22fa
commit 80968f6
Showing
13 changed files
with
673 additions
and
36 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
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
21 changes: 21 additions & 0 deletions
21
protocol/x/revshare/keeper/grpc_query_unconditional_revshare.go
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,21 @@ | ||
package keeper | ||
|
||
import ( | ||
"context" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/dydxprotocol/v4-chain/protocol/x/revshare/types" | ||
) | ||
|
||
func (k Keeper) UnconditionalRevShareConfig( | ||
ctx context.Context, | ||
req *types.QueryUnconditionalRevShareConfig, | ||
) (*types.QueryUnconditionalRevShareConfigResponse, error) { | ||
config, err := k.GetUnconditionalRevShareConfigParams(sdk.UnwrapSDKContext(ctx)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &types.QueryUnconditionalRevShareConfigResponse{ | ||
Config: config, | ||
}, nil | ||
} |
58 changes: 58 additions & 0 deletions
58
protocol/x/revshare/keeper/grpc_query_unconditional_revshare_test.go
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 keeper_test | ||
|
||
import ( | ||
"testing" | ||
|
||
testapp "github.com/dydxprotocol/v4-chain/protocol/testutil/app" | ||
"github.com/dydxprotocol/v4-chain/protocol/testutil/constants" | ||
"github.com/dydxprotocol/v4-chain/protocol/x/revshare/types" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestQueryUnconditionalRevShare(t *testing.T) { | ||
testCases := map[string]struct { | ||
config types.UnconditionalRevShareConfig | ||
}{ | ||
"Single recipient": { | ||
config: types.UnconditionalRevShareConfig{ | ||
Configs: []types.UnconditionalRevShareConfig_RecipientConfig{ | ||
{ | ||
Address: constants.AliceAccAddress.String(), | ||
SharePpm: 100_000, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"Multiple recipients": { | ||
config: types.UnconditionalRevShareConfig{ | ||
Configs: []types.UnconditionalRevShareConfig_RecipientConfig{ | ||
{ | ||
Address: constants.AliceAccAddress.String(), | ||
SharePpm: 50_000, | ||
}, | ||
{ | ||
Address: constants.BobAccAddress.String(), | ||
SharePpm: 30_000, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"Empty config": { | ||
config: types.UnconditionalRevShareConfig{}, | ||
}, | ||
} | ||
|
||
for name, tc := range testCases { | ||
t.Run(name, func(t *testing.T) { | ||
tApp := testapp.NewTestAppBuilder(t).Build() | ||
ctx := tApp.InitChain() | ||
k := tApp.App.RevShareKeeper | ||
|
||
k.SetUnconditionalRevShareConfigParams(ctx, tc.config) | ||
|
||
resp, err := k.UnconditionalRevShareConfig(ctx, &types.QueryUnconditionalRevShareConfig{}) | ||
require.NoError(t, err) | ||
require.Equal(t, tc.config, resp.Config) | ||
}) | ||
} | ||
} |
Oops, something went wrong.