-
Notifications
You must be signed in to change notification settings - Fork 129
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-839] add query for unconditional revshare #2380
Changes from 1 commit
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 |
---|---|---|
@@ -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 | ||
} |
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{}, | ||
}, | ||
} | ||
Comment on lines
+13
to
+43
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. 🛠️ Refactor suggestion Consider adding edge cases and invalid configurations. The current test cases cover the main scenarios well. To enhance the robustness of the tests, consider adding the following cases:
These additional cases would help ensure proper error handling and validation in the |
||
|
||
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) | ||
}) | ||
} | ||
Comment on lines
+45
to
+57
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. 🛠️ Refactor suggestion Enhance error checking and add more assertions. The test execution logic is generally correct, but consider the following improvements:
These changes will provide more detailed error messages if a test fails, making it easier to identify the exact point of failure. |
||
} |
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.
Replace empty interfaces with type aliases
The interfaces
QueryUnconditionalRevShareConfig
andQueryUnconditionalRevShareConfigSDKType
are empty. Since empty interfaces are equivalent to{}
, consider using type aliases instead for clarity.Apply this diff to fix the issue:
Also applies to: 48-48
🧰 Tools
🪛 Biome