-
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.
[Service] Refresh service module params logic (#861)
## Summary The "adding_params.md" doc has (or will have) changed substantially (see #839) since the shared module's param logic was last updated. This PR aligns the service module's param logic with the snippets in the updated docs. Specifically, this refresh includes: - Moving validation logic from `msgServer#UpdateParam()` to `MsgUpdateParam#ValidateBasic()`. - Replacing magic strings of param names with their standard variable counterparts (i.e. `prooftypes.Param...`). - Improving some local variable names. - Replacing usages of `interface{}` with `any`. - Improving validation for all coin type params to be consistent with application, gateway, and supplier coin type validation. ## Dependencies - #809 - #843 - #844 - #845 - #847 - #848 - #849 - #850 - #857 - #852 - #851 ## Issue - #612 ## Type of change Select one or more from the following: - [ ] New feature, functionality or library - [ ] Consensus breaking; add the `consensus-breaking` label if so. See #791 for details - [ ] Bug fix - [x] Code health or cleanup - [ ] Documentation - [ ] Other (specify) ## Testing - [ ] **Documentation**: `make docusaurus_start`; only needed if you make doc changes - [ ] **Unit Tests**: `make go_develop_and_test` - [ ] **LocalNet E2E Tests**: `make test_e2e` - [ ] **DevNet E2E Tests**: Add the `devnet-test-e2e` label to the PR. ## Sanity Checklist - [ ] I have tested my changes using the available tooling - [ ] I have commented my code - [ ] I have performed a self-review of my own code; both comments & source code - [ ] I create and reference any new tickets, if applicable - [ ] I have left TODOs throughout the codebase, if applicable --------- Co-authored-by: Redouane Lakrache <[email protected]> Co-authored-by: Daniel Olshansky <[email protected]> Co-authored-by: red-0ne <[email protected]>
- Loading branch information
1 parent
1f75244
commit b002fb1
Showing
9 changed files
with
149 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package types | ||
|
||
import ( | ||
"testing" | ||
|
||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/pokt-network/poktroll/testutil/sample" | ||
) | ||
|
||
func TestMsgUpdateParam_ValidateBasic(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
desc string | ||
msg MsgUpdateParam | ||
expectedErr error | ||
}{ | ||
{ | ||
name: "invalid address", | ||
desc: "invalid: authority address invalid", | ||
msg: MsgUpdateParam{ | ||
Authority: "invalid_address", | ||
Name: "", // Doesn't matter for this test | ||
AsType: &MsgUpdateParam_AsCoin{AsCoin: nil}, | ||
}, | ||
expectedErr: sdkerrors.ErrInvalidAddress, | ||
}, { | ||
desc: "invalid: param name incorrect (non-existent)", | ||
msg: MsgUpdateParam{ | ||
Authority: sample.AccAddress(), | ||
Name: "non_existent", | ||
AsType: &MsgUpdateParam_AsCoin{AsCoin: &MinAddServiceFee}, | ||
}, | ||
expectedErr: ErrServiceParamInvalid, | ||
}, { | ||
name: "valid address", | ||
desc: "valid: correct address, param name, and type", | ||
msg: MsgUpdateParam{ | ||
Authority: sample.AccAddress(), | ||
Name: ParamAddServiceFee, | ||
AsType: &MsgUpdateParam_AsCoin{AsCoin: &MinAddServiceFee}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.desc, func(t *testing.T) { | ||
err := test.msg.ValidateBasic() | ||
if test.expectedErr != nil { | ||
require.ErrorContains(t, err, test.expectedErr.Error()) | ||
return | ||
} | ||
require.NoError(t, err) | ||
}) | ||
} | ||
} |
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