Skip to content

Commit

Permalink
chore: Add param update support for uint64
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanchriswhite committed Oct 7, 2024
1 parent 50ea8ed commit 0cda3f7
Show file tree
Hide file tree
Showing 15 changed files with 417 additions and 418 deletions.
227 changes: 114 additions & 113 deletions api/poktroll/application/tx.pulsar.go

Large diffs are not rendered by default.

152 changes: 76 additions & 76 deletions api/poktroll/shared/tx.pulsar.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions proto/poktroll/application/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ message MsgUpdateParam {

string name = 2;
oneof asType {
int64 as_int64 = 3;
cosmos.base.v1beta1.Coin as_coin = 4;
uint64 as_uint64 = 3 [(gogoproto.jsontag) = "as_uint64"];
cosmos.base.v1beta1.Coin as_coin = 4 [(gogoproto.jsontag) = "as_coin"];
};
}

Expand Down
2 changes: 1 addition & 1 deletion proto/poktroll/shared/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ message MsgUpdateParam {
string name = 2;
oneof as_type {
string as_string = 3 [(gogoproto.jsontag) = "as_string"];
int64 as_int64 = 6 [(gogoproto.jsontag) = "as_int64"];
uint64 as_uint64 = 6 [(gogoproto.jsontag) = "as_uint64"];
bytes as_bytes = 7 [(gogoproto.jsontag) = "as_bytes"];
}
}
Expand Down
7 changes: 2 additions & 5 deletions testutil/integration/suites/param_configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ var (
QueryParamsResponse: sharedtypes.QueryParamsResponse{},
},
ParamTypes: map[ParamType]any{
// TODO_IMPROVE: Add a Uint64 asType instead of using int64 for uint64 params.
ParamTypeUint64: sharedtypes.MsgUpdateParam_AsInt64{},
ParamTypeInt64: sharedtypes.MsgUpdateParam_AsInt64{},
ParamTypeUint64: sharedtypes.MsgUpdateParam_AsUint64{},
ParamTypeString: sharedtypes.MsgUpdateParam_AsString{},
ParamTypeBytes: sharedtypes.MsgUpdateParam_AsBytes{},
},
Expand Down Expand Up @@ -147,8 +145,7 @@ var (
MinStake: &ValidActorMinStake,
},
ParamTypes: map[ParamType]any{
// TODO_IMPROVE: Add a Uint64 asType instead of using int64 for uint64 params.
ParamTypeUint64: apptypes.MsgUpdateParam_AsInt64{},
ParamTypeUint64: apptypes.MsgUpdateParam_AsUint64{},
ParamTypeCoin: apptypes.MsgUpdateParam_AsCoin{},
},
DefaultParams: apptypes.DefaultParams(),
Expand Down
2 changes: 1 addition & 1 deletion testutil/integration/suites/update_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ func (s *ParamsSuite) RunUpdateParamAsSigner(
switch paramType {
case ParamTypeUint64:
// NB: MsgUpdateParam doesn't currently support uint64 param type.
msgAsTypeValue.Elem().FieldByName("AsInt64").SetInt(int64(paramReflectValue.Interface().(uint64)))
msgAsTypeValue.Elem().FieldByName("AsUint64").Set(paramReflectValue)
case ParamTypeInt64:
msgAsTypeValue.Elem().FieldByName("AsInt64").Set(paramReflectValue)
case ParamTypeFloat32:
Expand Down
4 changes: 2 additions & 2 deletions x/application/keeper/msg_server_update_param.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ func (k msgServer) UpdateParam(ctx context.Context, msg *apptypes.MsgUpdateParam
switch msg.Name {
// TODO_IMPROVE: Add a Uint64 asType instead of using int64 for uint64 params.
case apptypes.ParamMaxDelegatedGateways:
if _, ok := msg.AsType.(*apptypes.MsgUpdateParam_AsInt64); !ok {
if _, ok := msg.AsType.(*apptypes.MsgUpdateParam_AsUint64); !ok {
return nil, apptypes.ErrAppParamInvalid.Wrapf("unsupported value type for %s param: %T", msg.Name, msg.AsType)
}
maxDelegatedGateways := uint64(msg.GetAsInt64())
maxDelegatedGateways := msg.GetAsUint64()

if err := apptypes.ValidateMaxDelegatedGateways(maxDelegatedGateways); err != nil {
return nil, apptypes.ErrAppParamInvalid.Wrapf("maxdelegegated_gateways (%d): %v", maxDelegatedGateways, err)
Expand Down
2 changes: 1 addition & 1 deletion x/application/keeper/msg_server_update_param_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestMsgUpdateParam_UpdateMaxDelegatedGatewaysOnly(t *testing.T) {
updateParamMsg := &apptypes.MsgUpdateParam{
Authority: authtypes.NewModuleAddress(govtypes.ModuleName).String(),
Name: apptypes.ParamMaxDelegatedGateways,
AsType: &apptypes.MsgUpdateParam_AsInt64{AsInt64: int64(expectedMaxDelegatedGateways)},
AsType: &apptypes.MsgUpdateParam_AsUint64{AsUint64: expectedMaxDelegatedGateways},
}
res, err := msgSrv.UpdateParam(ctx, updateParamMsg)
require.NoError(t, err)
Expand Down
6 changes: 3 additions & 3 deletions x/application/types/message_update_param.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func NewMsgUpdateParam(authority string, name string, asType any) *MsgUpdatePara

switch t := asType.(type) {
case uint64:
asTypeIface = &MsgUpdateParam_AsInt64{AsInt64: int64(t)}
asTypeIface = &MsgUpdateParam_AsUint64{AsUint64: t}
case *cosmostypes.Coin:
asTypeIface = &MsgUpdateParam_AsCoin{AsCoin: t}
default:
Expand Down Expand Up @@ -52,10 +52,10 @@ func (msg *MsgUpdateParam) ValidateBasic() error {
}

func (msg *MsgUpdateParam) paramTypeIsUint64() error {
if _, ok := msg.AsType.(*MsgUpdateParam_AsInt64); !ok {
if _, ok := msg.AsType.(*MsgUpdateParam_AsUint64); !ok {
return ErrAppParamInvalid.Wrapf(""+
"invalid type for param %q; expected %T, got %T",
msg.Name, &MsgUpdateParam_AsInt64{}, msg.AsType,
msg.Name, &MsgUpdateParam_AsUint64{}, msg.AsType,
)
}
return nil
Expand Down
149 changes: 75 additions & 74 deletions x/application/types/tx.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0cda3f7

Please sign in to comment.