Skip to content
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

feat: emergency group ugov proto #2129

Merged
merged 11 commits into from
Jul 10, 2023
4 changes: 4 additions & 0 deletions proto/umee/ugov/v1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ package umee.ugov.v1;

import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";
import "cosmos_proto/cosmos.proto";

option go_package = "github.com/umee-network/umee/v5/x/ugov";
option (gogoproto.goproto_getters_all) = false;

// GenesisState of the ugov module.
message GenesisState {
cosmos.base.v1beta1.DecCoin min_gas_price = 1 [(gogoproto.nullable) = false];

// Emergency Group address
string emergency_group = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];
}
18 changes: 16 additions & 2 deletions proto/umee/ugov/v1/query.proto
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
syntax = "proto3";
package umee.ugov.v1;

import "google/api/annotations.proto";
import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";
import "cosmos_proto/cosmos.proto";
import "gogoproto/gogo.proto";
import "google/api/annotations.proto";

option go_package = "github.com/umee-network/umee/v5/x/ugov";

Expand All @@ -15,6 +16,11 @@ service Query {
rpc MinGasPrice(QueryMinGasPrice) returns (QueryMinGasPriceResponse) {
option (google.api.http).get = "/umee/ugov/v1/min-gas-price";
}

// EmergencyGroup returns emergency group address
rpc EmergencyGroup(QueryEmergencyGroup) returns (QueryEmergencyGroupResponse) {
option (google.api.http).get = "/umee/ugov/v1/emergency-group";
}
}

// QueryMinGasPrice is a request type.
Expand All @@ -24,3 +30,11 @@ message QueryMinGasPrice {}
message QueryMinGasPriceResponse {
cosmos.base.v1beta1.DecCoin min_gas_price = 1 [(gogoproto.nullable) = false];
}

// QueryEmergencyGroup request type.
message QueryEmergencyGroup {}

// QueryEmergencyGroupResponse response type.
message QueryEmergencyGroupResponse {
string emergency_group = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
}
19 changes: 17 additions & 2 deletions proto/umee/ugov/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ option (gogoproto.goproto_getters_all) = false;
service Msg {
// GovUpdateMinGasPrice sets protocol controlled tx min fees.
rpc GovUpdateMinGasPrice(MsgGovUpdateMinGasPrice) returns (MsgGovUpdateMinGasPriceResponse);

// GovSetEmergencyGroup sets protocol controlled tx min fees.
robert-zaremba marked this conversation as resolved.
Show resolved Hide resolved
rpc GovSetEmergencyGroup(MsgGovSetEmergencyGroup) returns (MsgGovSetEmergencyGroupResponse);
}

// MsgGovUpdateMinGasPrice is a request type for the Msg/GovUpdateMinGasPrice.
// MsgGovUpdateMinGasPrice request type.
message MsgGovUpdateMinGasPrice {
option (gogoproto.goproto_stringer) = false;
option (cosmos.msg.v1.signer) = "authority";
Expand All @@ -26,5 +29,17 @@ message MsgGovUpdateMinGasPrice {
cosmos.base.v1beta1.DecCoin min_gas_price = 2 [(gogoproto.nullable) = false];
}

// MsgGovUpdateMinGasPriceResponse is a response type for the Msg/GovUpdateMinGasPrice.
// MsgGovUpdateMinGasPriceResponse response type.
message MsgGovUpdateMinGasPriceResponse {};

// MsgGovSetEmergencyGroup request type.
message MsgGovSetEmergencyGroup {
option (cosmos.msg.v1.signer) = "authority";

// authority must be the address of the governance account.
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
string emergency_group = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];
}

// MsgGovSetEmergencyGroupResponse response type.
message MsgGovSetEmergencyGroupResponse {};
6 changes: 6 additions & 0 deletions tests/accs/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package accs
import (
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/tendermint/tendermint/crypto"
)

// Test user accounts
Expand All @@ -21,3 +22,8 @@ var (
var (
FooModule = authtypes.NewModuleAddress("foomodule")
)

// MkAddress creats an address from the give seed string
robert-zaremba marked this conversation as resolved.
Show resolved Hide resolved
func MkAddress(seed string) sdk.AccAddress {
robert-zaremba marked this conversation as resolved.
Show resolved Hide resolved
return sdk.AccAddress(crypto.AddressHash([]byte(seed)))
}
2 changes: 2 additions & 0 deletions x/ugov/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ func init() {
// Amino JSON serialization.
func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
cdc.RegisterConcrete(&MsgGovUpdateMinGasPrice{}, proto.MessageName(&MsgGovUpdateMinGasPrice{}), nil)
cdc.RegisterConcrete(&MsgGovSetEmergencyGroup{}, "umee/ugov/MsgGovSetEmergencyGroup", nil)
}

func RegisterInterfaces(registry cdctypes.InterfaceRegistry) {
registry.RegisterImplementations(
(*sdk.Msg)(nil),
&MsgGovUpdateMinGasPrice{},
&MsgGovSetEmergencyGroup{},
)

msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
Expand Down
82 changes: 66 additions & 16 deletions x/ugov/genesis.pb.go

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

5 changes: 5 additions & 0 deletions x/ugov/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,8 @@ func (m msgServer) GovUpdateMinGasPrice(ctx context.Context, msg *ugov.MsgGovUpd

return &ugov.MsgGovUpdateMinGasPriceResponse{}, nil
}

func (m msgServer) GovSetEmergencyGroup(_ context.Context, _ *ugov.MsgGovSetEmergencyGroup,
) (*ugov.MsgGovSetEmergencyGroupResponse, error) {
panic("not implemented")
}
5 changes: 5 additions & 0 deletions x/ugov/keeper/query_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,8 @@ func (q Querier) MinGasPrice(ctx context.Context, _ *ugov.QueryMinGasPrice) (*ug
return &ugov.QueryMinGasPriceResponse{MinGasPrice: q.Keeper(&sdkCtx).MinGasPrice()},
nil
}

func (q Querier) EmergencyGroup(_ context.Context, _ *ugov.QueryEmergencyGroup,
) (*ugov.QueryEmergencyGroupResponse, error) {
panic("not implemented")
}
40 changes: 32 additions & 8 deletions x/ugov/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,19 @@ import (
)

var (
_ sdk.Msg = &MsgGovUpdateMinGasPrice{}
_, _ sdk.Msg = &MsgGovUpdateMinGasPrice{},
&MsgGovSetEmergencyGroup{}

// amino
_ legacytx.LegacyMsg = &MsgGovUpdateMinGasPrice{}
_, _ legacytx.LegacyMsg = &MsgGovUpdateMinGasPrice{},
&MsgGovSetEmergencyGroup{}
)

// ValidateBasic implements Msg
func (msg *MsgGovUpdateMinGasPrice) ValidateBasic() error {
if err := checkers.IsGovAuthority(msg.Authority); err != nil {
return err
}

return msg.MinGasPrice.Validate()
}

Expand All @@ -35,13 +36,36 @@ func (msg *MsgGovUpdateMinGasPrice) String() string {
return fmt.Sprintf("<authority: %s, min_gas_price: %s>", msg.Authority, msg.MinGasPrice.String())
}

// Route implements LegacyMsg.Route
func (msg MsgGovUpdateMinGasPrice) Route() string { return "" }
// LegacyMsg.Type implementations

// GetSignBytes implements the LegacyMsg.GetSignBytes
func (msg MsgGovUpdateMinGasPrice) Route() string { return "" }
func (msg MsgGovUpdateMinGasPrice) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg))
}

// GetSignBytes implements the LegacyMsg.Type
func (msg MsgGovUpdateMinGasPrice) Type() string { return sdk.MsgTypeURL(&msg) }

//
// MsgGovSetEmergencyGroup
//

// Msg interface implementation

func (msg *MsgGovSetEmergencyGroup) ValidateBasic() error {
if err := checkers.IsGovAuthority(msg.Authority); err != nil {
return err
}
_, err := sdk.AccAddressFromBech32(msg.EmergencyGroup)
return err
}

// GetSignBytes implements Msg
func (msg *MsgGovSetEmergencyGroup) GetSigners() []sdk.AccAddress {
return checkers.Signers(msg.Authority)
}

// LegacyMsg.Type implementations
func (msg MsgGovSetEmergencyGroup) Route() string { return "" }
func (msg MsgGovSetEmergencyGroup) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg))
}
func (msg MsgGovSetEmergencyGroup) Type() string { return sdk.MsgTypeURL(&msg) }
30 changes: 30 additions & 0 deletions x/ugov/msg_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ugov

import (
fmt "fmt"
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -48,3 +49,32 @@ func TestMsgGovUpdateMinGasPrice(t *testing.T) {
msg.Authority = accs.Alice.String()
require.ErrorIs(msg.ValidateBasic(), govtypes.ErrInvalidSigner, "must fail on a non gov account")
}

func validMsgGovSetEmergencyGroup() MsgGovSetEmergencyGroup {
return MsgGovSetEmergencyGroup{
Authority: authtypes.NewModuleAddress("gov").String(),
EmergencyGroup: accs.Alice.String(),
}
}

func TestMsgGovSetEmergencyGroup(t *testing.T) {
t.Parallel()
require := require.New(t)

msg := validMsgGovSetEmergencyGroup()
require.Equal(fmt.Sprintf("authority:%q emergency_group:%q ", msg.Authority, msg.EmergencyGroup),
msg.String())
require.Contains("MsgGovSetEmergencyGroup", msg.Route())
require.NoError(msg.ValidateBasic())

signers := msg.GetSigners()
require.Len(signers, 1)
require.Equal(msg.Authority, signers[0].String())

msg.Authority = accs.Bob.String()
require.ErrorIs(msg.ValidateBasic(), govtypes.ErrInvalidSigner, "must fail on a non gov account")

msg = validMsgGovSetEmergencyGroup()
msg.EmergencyGroup = "umee1yesmdu06f7strl67kjvg2w7t5kacc"
require.ErrorContains(msg.ValidateBasic(), "bech32 failed", "must fail with bad emergency_group address")
}
Loading