Skip to content

Commit

Permalink
fix: ibc status default value (#1912)
Browse files Browse the repository at this point in the history
* chore: update IBC_TRANFER_STATUS proto

* update tests

* proto: update messages

* tests update

* update event
  • Loading branch information
robert-zaremba authored Mar 14, 2023
1 parent efd48f9 commit 5724cd8
Show file tree
Hide file tree
Showing 15 changed files with 280 additions and 283 deletions.
4 changes: 2 additions & 2 deletions proto/umee/uibc/v1/events.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ message EventBadRevert {
string packet = 2;
}

// EventQuotaPause is emitted on quota tracking pause status change.
message EventQuotaPause {
// EventIBCTransferStatus is emitted on quota tracking pause status change.
message EventIBCTransferStatus {
IBCTransferStatus status = 1;
}
14 changes: 7 additions & 7 deletions proto/umee/uibc/v1/quota.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ option go_package = "github.com/umee-network/umee/v4/x/uibc";
// Params of x/uibc module
message Params {
// ibc_status defines the wethever ibc-transfer enabled, disbaled or paused
IBCTransferStatus ibc_pause = 1;
IBCTransferStatus ibc_status = 1;
// total_quota defines the total outflow limit of ibc-transfer in USD
string total_quota = 2 [
(cosmos_proto.scalar) = "cosmos.Dec",
Expand All @@ -36,10 +36,10 @@ message Params {
enum IBCTransferStatus {
// UNSPECIFIED defines a no-op status.
IBC_TRANSFER_STATUS_UNSPECIFIED = 0;
// DISABLED defines the quota checking diabled for ibc-transfer.
IBC_TRANSFER_STATUS_DISABLED = 1;
// ENABLED defines the enable quota checking for ibc-transfer.
IBC_TRANSFER_STATUS_ENABLED = 2;
// PAUSED defines pause the ibc-transfer from app.
IBC_TRANSFER_STATUS_PAUSED = 3;
// DISABLED: quota checks are disabled.
IBC_TRANSFER_STATUS_QUOTA_DISABLED = 1;
// ENABLED: quota checks are enabled.
IBC_TRANSFER_STATUS_QUOTA_ENABLED = 2;
// PAUSED: all IBC transfers are paused.
IBC_TRANSFER_STATUS_TRANSFERS_PAUSED = 3;
}
16 changes: 8 additions & 8 deletions proto/umee/uibc/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ service Msg {
// updates the quota for existed ibc denoms.
rpc GovUpdateQuota(MsgGovUpdateQuota) returns (MsgGovUpdateQuotaResponse);

// GovSetIBCPause update the status of ibc-transfer
rpc GovSetIBCPause(MsgGovSetIBCPause) returns (MsgGovSetIBCPauseResponse);
// GovSetIBCStatus update the status of ibc-transfer
rpc GovSetIBCStatus(MsgGovSetIBCStatus) returns (MsgGovSetIBCStatusResponse);
}

// MsgGovUpdateQuota defines the Msg/GovUpdateQuota request type.
Expand Down Expand Up @@ -56,18 +56,18 @@ message MsgGovUpdateQuota {
// MsgGovUpdateQuotaResponse defines response type for the Msg/GovUpdateQuota for with x/gov proposals.
message MsgGovUpdateQuotaResponse {};

// MsgGovSetIBCPause defines request type for UpdateIBCTransferStatus
message MsgGovSetIBCPause {
// MsgGovSetIbcstatus defines request type for UpdateIBCTransferStatus
message MsgGovSetIBCStatus {
option (gogoproto.goproto_getters) = false;
option (gogoproto.goproto_stringer) = false;
option (cosmos.msg.v1.signer) = "authority";
// authority is the address of the governance account.
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
string title = 2;
string description = 3;
// ibc_pause_status defines ibc transfer pause status
IBCTransferStatus ibc_pause_status = 4;
// ibc_status defines ibc transfer pause status
IBCTransferStatus ibc_status = 4;
}

// MsgGovSetIBCPauseResponse definesresponse type for Msg/MsgGovSetIBCPause for with x/gov proposals.
message MsgGovSetIBCPauseResponse {}
// MsgGovSetIbcstatusResponse definesresponse type for Msg/MsgGovSetIbcstatus for with x/gov proposals.
message MsgGovSetIBCStatusResponse {}
4 changes: 2 additions & 2 deletions x/uibc/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ func init() {
// Amino JSON serialization.
func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
cdc.RegisterConcrete(&MsgGovUpdateQuota{}, "umee/uibc/MsgGovUpdateQuota", nil)
cdc.RegisterConcrete(&MsgGovSetIBCPause{}, "umee/uibc/MsgGovSetIBCPause", nil)
cdc.RegisterConcrete(&MsgGovSetIBCStatus{}, "umee/uibc/MsgGovSetIBCStatus", nil)
}

func RegisterInterfaces(registry cdctypes.InterfaceRegistry) {
registry.RegisterImplementations(
(*sdk.Msg)(nil),
&MsgGovUpdateQuota{},
&MsgGovSetIBCPause{},
&MsgGovSetIBCStatus{},
)

msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
Expand Down
66 changes: 33 additions & 33 deletions x/uibc/events.pb.go

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

20 changes: 10 additions & 10 deletions x/uibc/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

var (
_ sdk.Msg = &MsgGovUpdateQuota{}
_ sdk.Msg = &MsgGovSetIBCPause{}
_ sdk.Msg = &MsgGovSetIBCStatus{}
)

// GetTitle returns the title of the proposal.
Expand Down Expand Up @@ -64,43 +64,43 @@ func (msg *MsgGovUpdateQuota) GetSigners() []sdk.AccAddress {
}

// GetTitle implements govv1b1.Content interface.
func (msg *MsgGovSetIBCPause) GetTitle() string { return msg.Title }
func (msg *MsgGovSetIBCStatus) GetTitle() string { return msg.Title }

// GetDescription implements govv1b1.Content interface.
func (msg *MsgGovSetIBCPause) GetDescription() string { return msg.Description }
func (msg *MsgGovSetIBCStatus) GetDescription() string { return msg.Description }

// Route implements Msg
func (msg MsgGovSetIBCPause) Route() string { return RouterKey }
func (msg MsgGovSetIBCStatus) Route() string { return RouterKey }

// Type implements Msg
func (msg MsgGovSetIBCPause) Type() string { return sdk.MsgTypeURL(&msg) }
func (msg MsgGovSetIBCStatus) Type() string { return sdk.MsgTypeURL(&msg) }

// String implements the Stringer interface.
func (msg *MsgGovSetIBCPause) String() string {
func (msg *MsgGovSetIBCStatus) String() string {
out, _ := json.Marshal(msg)
return string(out)
}

// ValidateBasic implements Msg
func (msg *MsgGovSetIBCPause) ValidateBasic() error {
func (msg *MsgGovSetIBCStatus) ValidateBasic() error {
if err := checkers.ValidateAddr(msg.Authority, "authority"); err != nil {
return err
}

if err := validateIBCTransferStatus(msg.IbcPauseStatus); err != nil {
if err := validateIBCTransferStatus(msg.IbcStatus); err != nil {
return err
}

return checkers.ValidateProposal(msg.Title, msg.Description, msg.Authority)
}

// GetSignBytes implements Msg
func (msg *MsgGovSetIBCPause) GetSignBytes() []byte {
func (msg *MsgGovSetIBCStatus) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
}

// GetSigners implements Msg
func (msg *MsgGovSetIBCPause) GetSigners() []sdk.AccAddress {
func (msg *MsgGovSetIBCStatus) GetSigners() []sdk.AccAddress {
return checkers.Signers(msg.Authority)
}
24 changes: 12 additions & 12 deletions x/uibc/msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,27 +62,27 @@ func TestMsgGovUpdateQuota(t *testing.T) {
}
}

func validMsgGovSetIBCPause() MsgGovSetIBCPause {
return MsgGovSetIBCPause{
Title: "title",
Authority: authtypes.NewModuleAddress("gov").String(),
Description: "desc",
IbcPauseStatus: 1,
func validMsgGovSetIBCStatus() MsgGovSetIBCStatus {
return MsgGovSetIBCStatus{
Title: "title",
Authority: authtypes.NewModuleAddress("gov").String(),
Description: "desc",
IbcStatus: 1,
}
}

func TestMsgGovSetIBCPause(t *testing.T) {
func TestMsgGovSetIBCStatus(t *testing.T) {
t.Parallel()
validMsg := validMsgGovSetIBCPause()
validMsg := validMsgGovSetIBCStatus()

invalidAuthority := validMsg
invalidAuthority.Authority = authtypes.NewModuleAddress("govv").String()

invalidIBCPauseStatus := validMsg
invalidIBCPauseStatus.IbcPauseStatus = 10
invalidIBCStatus := validMsg
invalidIBCStatus.IbcStatus = 10

tests := []struct {
msg MsgGovSetIBCPause
msg MsgGovSetIBCStatus
name string
errMsg string
}{
Expand All @@ -96,7 +96,7 @@ func TestMsgGovSetIBCPause(t *testing.T) {
errMsg: "invalid authority",
}, {
name: "invalid ibc pause status in msg",
msg: invalidIBCPauseStatus,
msg: invalidIBCStatus,
errMsg: "invalid ibc-transfer status",
},
}
Expand Down
14 changes: 5 additions & 9 deletions x/uibc/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,26 @@ import (
// DefaultParams returns default genesis params
func DefaultParams() Params {
return Params{
IbcPause: IBCTransferStatus_IBC_TRANSFER_STATUS_DISABLED,
IbcStatus: IBCTransferStatus_IBC_TRANSFER_STATUS_QUOTA_ENABLED,
TotalQuota: sdk.NewDec(1_000_000),
TokenQuota: sdk.NewDec(600_000),
QuotaDuration: time.Second * 60 * 60 * 24, // 24h
}
}

func (p Params) Validate() error {
if err := validateIBCTransferStatus(p.IbcPause); err != nil {
if err := validateIBCTransferStatus(p.IbcStatus); err != nil {
return err
}

if err := validateQuotaDuration(p.QuotaDuration); err != nil {
return err
}

if err := validateQuota(p.TotalQuota, "total quota"); err != nil {
return err
}

if err := validateQuota(p.TokenQuota, "quota per token"); err != nil {
return err
}

if p.TotalQuota.LT(p.TokenQuota) {
return fmt.Errorf("token quota shouldn't be less than quota per denom")
}
Expand All @@ -42,9 +38,9 @@ func (p Params) Validate() error {
}

func validateIBCTransferStatus(status IBCTransferStatus) error {
if status == IBCTransferStatus_IBC_TRANSFER_STATUS_DISABLED ||
status == IBCTransferStatus_IBC_TRANSFER_STATUS_ENABLED ||
status == IBCTransferStatus_IBC_TRANSFER_STATUS_PAUSED {
if status == IBCTransferStatus_IBC_TRANSFER_STATUS_QUOTA_DISABLED ||
status == IBCTransferStatus_IBC_TRANSFER_STATUS_QUOTA_ENABLED ||
status == IBCTransferStatus_IBC_TRANSFER_STATUS_TRANSFERS_PAUSED {
return nil
}

Expand Down
Loading

0 comments on commit 5724cd8

Please sign in to comment.