From 93002e87bede76a2fc2b5433c46f6895851badfa Mon Sep 17 00:00:00 2001 From: Carlton Hanna Date: Thu, 16 May 2024 08:47:36 -0600 Subject: [PATCH] Remove legacy msgfees gov proposal handlers (#1953) * migrate UpdateConversionFeeDenom for msgfees * migrate HandleUpdateNhashPerUsdMilProposal, move add param methods * migrate removal of msg fee * migrate UpdateMsgFee * remove old v1beta proposal stuff from msg fees * remove proposal handler routes for msgfees from app.go * remove proposal encodings, add check for empty msg type * add change log entry * fix lints * add tests * Update msg validations, update tests * remove test that is covered in validate basic of msg --- CHANGELOG.md | 1 + app/app.go | 4 +- proto/provenance/ibchooks/v1/params.proto | 2 - proto/provenance/ibchooks/v1/tx.proto | 1 - proto/provenance/ibcratelimit/v1/params.proto | 2 - proto/provenance/msgfees/v1/proposals.proto | 25 +- x/ibchooks/types/params.pb.go | 24 +- x/ibchooks/types/tx.pb.go | 47 +- x/ibcratelimit/params.pb.go | 22 +- x/marker/client/cli/tx.go | 2 +- x/msgfees/client/cli/cli_test.go | 400 +++++++++--------- x/msgfees/client/cli/tx.go | 126 +++--- x/msgfees/handler.go | 32 -- x/msgfees/keeper/keeper.go | 76 ++++ x/msgfees/keeper/keeper_test.go | 171 ++++++++ x/msgfees/keeper/msg_server.go | 62 +-- x/msgfees/keeper/msg_server_test.go | 23 - x/msgfees/keeper/params.go | 20 +- x/msgfees/keeper/proposal_handler.go | 124 ------ x/msgfees/keeper/proposal_handler_test.go | 219 ---------- x/msgfees/module/module.go | 6 - x/msgfees/simulation/proposals.go | 86 ---- x/msgfees/simulation/proposals_test.go | 46 -- x/msgfees/types/msgs.go | 50 +-- x/msgfees/types/msgs_test.go | 84 ++-- x/msgfees/types/proposal.go | 157 +------ x/msgfees/types/proposals.pb.go | 255 +++-------- x/msgfees/types/proposals_test.go | 210 --------- 28 files changed, 734 insertions(+), 1543 deletions(-) delete mode 100644 x/msgfees/handler.go delete mode 100644 x/msgfees/keeper/proposal_handler.go delete mode 100644 x/msgfees/keeper/proposal_handler_test.go delete mode 100644 x/msgfees/simulation/proposals.go delete mode 100644 x/msgfees/simulation/proposals_test.go delete mode 100644 x/msgfees/types/proposals_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 9666e4e1a4..519db89618 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -66,6 +66,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * Name module param migration [#1937](https://github.com/provenance-io/provenance/pull/1937). * IbcHooks module param migration [#1939](https://github.com/provenance-io/provenance/pull/1939). * Bank module param migration [#1967](https://github.com/provenance-io/provenance/pull/1967). +* Remove `msgfees` legacy gov proposals [#1953](https://github.com/provenance-io/provenance/pull/1953). * Restore the hold module [#1930](https://github.com/provenance-io/provenance/pull/1930). * Restore gov-prop cli commands and fix next key decoding [#1930](https://github.com/provenance-io/provenance/pull/1930). * Switch to InputOutputCoinsProv for exchange transfers [#1930](https://github.com/provenance-io/provenance/pull/1930). diff --git a/app/app.go b/app/app.go index 359351cd7e..fe0a290edf 100644 --- a/app/app.go +++ b/app/app.go @@ -155,7 +155,6 @@ import ( metadatakeeper "github.com/provenance-io/provenance/x/metadata/keeper" metadatatypes "github.com/provenance-io/provenance/x/metadata/types" metadatawasm "github.com/provenance-io/provenance/x/metadata/wasm" - "github.com/provenance-io/provenance/x/msgfees" msgfeeskeeper "github.com/provenance-io/provenance/x/msgfees/keeper" msgfeesmodule "github.com/provenance-io/provenance/x/msgfees/module" msgfeestypes "github.com/provenance-io/provenance/x/msgfees/types" @@ -692,8 +691,7 @@ func New( govRouter := govtypesv1beta1.NewRouter() govRouter.AddRoute(govtypes.RouterKey, govtypesv1beta1.ProposalHandler). AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(app.ParamsKeeper)). - AddRoute(markertypes.ModuleName, marker.NewProposalHandler(app.MarkerKeeper)). - AddRoute(msgfeestypes.ModuleName, msgfees.NewProposalHandler(app.MsgFeesKeeper, app.InterfaceRegistry())) + AddRoute(markertypes.ModuleName, marker.NewProposalHandler(app.MarkerKeeper)) govKeeper := govkeeper.NewKeeper( appCodec, runtime.NewKVStoreService(keys[govtypes.StoreKey]), app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.DistrKeeper, app.BaseApp.MsgServiceRouter(), govtypes.Config{MaxMetadataLen: 10000}, govAuthority, diff --git a/proto/provenance/ibchooks/v1/params.proto b/proto/provenance/ibchooks/v1/params.proto index 0f499516c8..6a7e05d92b 100644 --- a/proto/provenance/ibchooks/v1/params.proto +++ b/proto/provenance/ibchooks/v1/params.proto @@ -1,8 +1,6 @@ syntax = "proto3"; package provenance.ibchooks.v1; -import "gogoproto/gogo.proto"; - option go_package = "github.com/provenance-io/provenance/x/ibchooks/types"; option java_package = "io.provenance.ibchooks.v1"; diff --git a/proto/provenance/ibchooks/v1/tx.proto b/proto/provenance/ibchooks/v1/tx.proto index 5be752c730..5f41d24d5d 100644 --- a/proto/provenance/ibchooks/v1/tx.proto +++ b/proto/provenance/ibchooks/v1/tx.proto @@ -2,7 +2,6 @@ syntax = "proto3"; package provenance.ibchooks.v1; import "cosmos/msg/v1/msg.proto"; -import "gogoproto/gogo.proto"; option go_package = "github.com/provenance-io/provenance/x/ibchooks/types"; diff --git a/proto/provenance/ibcratelimit/v1/params.proto b/proto/provenance/ibcratelimit/v1/params.proto index cb1b0d2c1b..f187ec4000 100644 --- a/proto/provenance/ibcratelimit/v1/params.proto +++ b/proto/provenance/ibcratelimit/v1/params.proto @@ -1,8 +1,6 @@ syntax = "proto3"; package provenance.ibcratelimit.v1; -import "gogoproto/gogo.proto"; - option go_package = "github.com/provenance-io/provenance/x/ibcratelimit"; option java_package = "io.provenance.ibcratelimit.v1"; option java_multiple_files = true; diff --git a/proto/provenance/msgfees/v1/proposals.proto b/proto/provenance/msgfees/v1/proposals.proto index d34615dc25..b00e8dcc40 100644 --- a/proto/provenance/msgfees/v1/proposals.proto +++ b/proto/provenance/msgfees/v1/proposals.proto @@ -11,8 +11,11 @@ option java_package = "io.provenance.msgfees.v1"; option java_multiple_files = true; // AddMsgFeeProposal defines a governance proposal to add additional msg based fee +// Deprecated: This message is no longer usable. It is only still included for +// backwards compatibility (e.g. looking up old governance proposals). +// It is replaced by providing a MsgAddMsgFeeProposalRequest in a governance proposal. message AddMsgFeeProposal { - option (gogoproto.equal) = true; + option deprecated = true; // propsal title string title = 1; @@ -32,8 +35,11 @@ message AddMsgFeeProposal { } // UpdateMsgFeeProposal defines a governance proposal to update a current msg based fee +// Deprecated: This message is no longer usable. It is only still included for +// backwards compatibility (e.g. looking up old governance proposals). +// It is replaced by providing a MsgUpdateMsgFeeProposalRequest in a governance proposal. message UpdateMsgFeeProposal { - option (gogoproto.equal) = true; + option deprecated = true; // propsal title string title = 1; @@ -51,8 +57,11 @@ message UpdateMsgFeeProposal { } // RemoveMsgFeeProposal defines a governance proposal to delete a current msg based fee +// Deprecated: This message is no longer usable. It is only still included for +// backwards compatibility (e.g. looking up old governance proposals). +// It is replaced by providing a MsgRemoveMsgFeeProposalRequest in a governance proposal. message RemoveMsgFeeProposal { - option (gogoproto.equal) = true; + option deprecated = true; // propsal title string title = 1; @@ -63,8 +72,11 @@ message RemoveMsgFeeProposal { } // UpdateNhashPerUsdMilProposal defines a governance proposal to update the nhash per usd mil param +// Deprecated: This message is no longer usable. It is only still included for +// backwards compatibility (e.g. looking up old governance proposals). +// It is replaced by providing a MsgUpdateNhashPerUsdMilProposalRequest in a governance proposal. message UpdateNhashPerUsdMilProposal { - option (gogoproto.equal) = true; + option deprecated = true; string title = 1; // proposal title string description = 2; // proposal description @@ -73,8 +85,11 @@ message UpdateNhashPerUsdMilProposal { } // UpdateConversionFeeDenomProposal defines a governance proposal to update the msg fee conversion denom +// Deprecated: This message is no longer usable. It is only still included for +// backwards compatibility (e.g. looking up old governance proposals). +// It is replaced by providing a MsgUpdateConversionFeeDenomProposalRequest in a governance proposal. message UpdateConversionFeeDenomProposal { - option (gogoproto.equal) = true; + option deprecated = true; string title = 1; // proposal title string description = 2; // proposal description diff --git a/x/ibchooks/types/params.pb.go b/x/ibchooks/types/params.pb.go index 5e3a90f913..3b0e193597 100644 --- a/x/ibchooks/types/params.pb.go +++ b/x/ibchooks/types/params.pb.go @@ -5,7 +5,6 @@ package types import ( fmt "fmt" - _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/cosmos/gogoproto/proto" io "io" math "math" @@ -77,21 +76,20 @@ func init() { } var fileDescriptor_61d9bd623dd1e2fd = []byte{ - // 212 bytes of a gzipped FileDescriptorProto + // 199 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x2e, 0x28, 0xca, 0x2f, 0x4b, 0xcd, 0x4b, 0xcc, 0x4b, 0x4e, 0xd5, 0xcf, 0x4c, 0x4a, 0xce, 0xc8, 0xcf, 0xcf, 0x2e, 0xd6, 0x2f, 0x33, 0xd4, 0x2f, 0x48, 0x2c, 0x4a, 0xcc, 0x2d, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, - 0x12, 0x43, 0x28, 0xd2, 0x83, 0x29, 0xd2, 0x2b, 0x33, 0x94, 0x12, 0x49, 0xcf, 0x4f, 0xcf, 0x07, - 0x2b, 0xd1, 0x07, 0xb1, 0x20, 0xaa, 0x95, 0xdc, 0xb9, 0xd8, 0x02, 0xc0, 0xba, 0x85, 0x6c, 0xb9, - 0xa4, 0x13, 0x73, 0x72, 0xf2, 0xcb, 0x53, 0x53, 0xe2, 0x13, 0x8b, 0x2b, 0xf3, 0x92, 0xe3, 0x13, - 0x93, 0xb3, 0xe3, 0x93, 0xf3, 0xf3, 0x4a, 0x8a, 0x12, 0x93, 0x4b, 0x8a, 0x25, 0x18, 0x15, 0x98, - 0x35, 0x38, 0x83, 0x24, 0xa0, 0x4a, 0x1c, 0x41, 0x2a, 0x1c, 0x93, 0xb3, 0x9d, 0x61, 0xf2, 0x4e, - 0xd9, 0x27, 0x1e, 0xc9, 0x31, 0x5e, 0x78, 0x24, 0xc7, 0xf8, 0xe0, 0x91, 0x1c, 0xe3, 0x84, 0xc7, - 0x72, 0x0c, 0x17, 0x1e, 0xcb, 0x31, 0xdc, 0x78, 0x2c, 0xc7, 0xc0, 0x25, 0x99, 0x09, 0xb6, 0x0c, - 0x8b, 0x9b, 0x02, 0x18, 0xa3, 0x4c, 0xd2, 0x33, 0x4b, 0x32, 0x4a, 0x93, 0xf4, 0x92, 0xf3, 0x73, - 0xf5, 0x11, 0x8a, 0x74, 0x33, 0xf3, 0x91, 0x78, 0xfa, 0x15, 0x08, 0xdf, 0x96, 0x54, 0x16, 0xa4, - 0x16, 0x27, 0xb1, 0x81, 0x1d, 0x6f, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0xa8, 0xc0, 0x21, 0xe7, - 0x11, 0x01, 0x00, 0x00, + 0x12, 0x43, 0x28, 0xd2, 0x83, 0x29, 0xd2, 0x2b, 0x33, 0x54, 0x72, 0xe7, 0x62, 0x0b, 0x00, 0xab, + 0x13, 0xb2, 0xe5, 0x92, 0x4e, 0xcc, 0xc9, 0xc9, 0x2f, 0x4f, 0x4d, 0x89, 0x4f, 0x2c, 0xae, 0xcc, + 0x4b, 0x8e, 0x4f, 0x4c, 0xce, 0x8e, 0x4f, 0xce, 0xcf, 0x2b, 0x29, 0x4a, 0x4c, 0x2e, 0x29, 0x96, + 0x60, 0x54, 0x60, 0xd6, 0xe0, 0x0c, 0x92, 0x80, 0x2a, 0x71, 0x04, 0xa9, 0x70, 0x4c, 0xce, 0x76, + 0x86, 0xc9, 0x3b, 0x65, 0x9f, 0x78, 0x24, 0xc7, 0x78, 0xe1, 0x91, 0x1c, 0xe3, 0x83, 0x47, 0x72, + 0x8c, 0x13, 0x1e, 0xcb, 0x31, 0x5c, 0x78, 0x2c, 0xc7, 0x70, 0xe3, 0xb1, 0x1c, 0x03, 0x97, 0x64, + 0x66, 0xbe, 0x1e, 0x76, 0xdb, 0x03, 0x18, 0xa3, 0x4c, 0xd2, 0x33, 0x4b, 0x32, 0x4a, 0x93, 0xf4, + 0x92, 0xf3, 0x73, 0xf5, 0x11, 0x8a, 0x74, 0x33, 0xf3, 0x91, 0x78, 0xfa, 0x15, 0x08, 0x7f, 0x95, + 0x54, 0x16, 0xa4, 0x16, 0x27, 0xb1, 0x81, 0x3d, 0x65, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0x2b, + 0x3f, 0xf1, 0x7a, 0xfb, 0x00, 0x00, 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { diff --git a/x/ibchooks/types/tx.pb.go b/x/ibchooks/types/tx.pb.go index 98a312754a..d698a6c87e 100644 --- a/x/ibchooks/types/tx.pb.go +++ b/x/ibchooks/types/tx.pb.go @@ -7,7 +7,6 @@ import ( context "context" fmt "fmt" _ "github.com/cosmos/cosmos-sdk/types/msgservice" - _ "github.com/cosmos/gogoproto/gogoproto" grpc1 "github.com/cosmos/gogoproto/grpc" proto "github.com/cosmos/gogoproto/proto" grpc "google.golang.org/grpc" @@ -151,29 +150,29 @@ func init() { func init() { proto.RegisterFile("provenance/ibchooks/v1/tx.proto", fileDescriptor_f2b3b50a1b9e4ff4) } var fileDescriptor_f2b3b50a1b9e4ff4 = []byte{ - // 346 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x91, 0xc1, 0x4e, 0xc2, 0x40, - 0x10, 0x86, 0xa9, 0x18, 0x08, 0x6b, 0xc4, 0xa4, 0x51, 0xa8, 0x1c, 0x2a, 0x21, 0x31, 0x12, 0x13, - 0xba, 0x41, 0x3d, 0x79, 0x03, 0xe3, 0xc1, 0x03, 0x89, 0xa9, 0x27, 0xbd, 0x90, 0x76, 0xdc, 0x2c, - 0x9b, 0xd2, 0x9d, 0xda, 0x5d, 0x10, 0xaf, 0x3e, 0x81, 0x8f, 0xe2, 0x63, 0x78, 0xe4, 0xe8, 0xd1, - 0xc0, 0xc1, 0xd7, 0x30, 0x94, 0x36, 0x40, 0xa2, 0x89, 0xb7, 0xf9, 0xff, 0x7c, 0xfd, 0xe7, 0xef, - 0x0e, 0x39, 0x8a, 0x62, 0x1c, 0x33, 0xe9, 0x49, 0x60, 0x54, 0xf8, 0x30, 0x40, 0x0c, 0x14, 0x1d, - 0xb7, 0xa9, 0x9e, 0x38, 0x51, 0x8c, 0x1a, 0xcd, 0xca, 0x0a, 0x70, 0x32, 0xc0, 0x19, 0xb7, 0x6b, - 0x55, 0x40, 0x15, 0xa2, 0xa2, 0xa1, 0xe2, 0x0b, 0x3e, 0x54, 0x7c, 0xf9, 0x41, 0x6d, 0x9f, 0x23, - 0xc7, 0x64, 0xa4, 0x8b, 0x69, 0xe9, 0x36, 0x9e, 0xc9, 0x6e, 0x4f, 0xf1, 0xeb, 0x50, 0xe8, 0x9b, - 0xee, 0x55, 0x07, 0x02, 0xb3, 0x42, 0x0a, 0x8a, 0xc9, 0x47, 0x16, 0x5b, 0x46, 0xdd, 0x68, 0x96, - 0xdc, 0x54, 0x99, 0x27, 0x64, 0x2f, 0xf2, 0x20, 0x60, 0xba, 0xaf, 0xd8, 0xd3, 0x88, 0x49, 0x60, - 0xd6, 0x56, 0xdd, 0x68, 0x6e, 0xbb, 0xe5, 0xa5, 0x7d, 0x97, 0xba, 0xa6, 0x45, 0x8a, 0x30, 0xf0, - 0xa4, 0x64, 0x43, 0x2b, 0x9f, 0x24, 0x64, 0xf2, 0x72, 0xe7, 0xf5, 0xfb, 0xfd, 0x34, 0xcd, 0x6b, - 0xdc, 0x93, 0x83, 0x8d, 0xc5, 0x2e, 0x53, 0x11, 0x4a, 0xc5, 0x16, 0x8b, 0x00, 0xa5, 0x8e, 0x3d, - 0xd0, 0xfd, 0x98, 0xa9, 0xd1, 0x50, 0xa7, 0x4d, 0xca, 0x99, 0xed, 0x26, 0xae, 0x59, 0x25, 0x45, - 0xe1, 0x43, 0xdf, 0x83, 0x20, 0x69, 0x52, 0x72, 0x0b, 0xc2, 0x87, 0x0e, 0x04, 0x67, 0x82, 0xe4, - 0x7b, 0x8a, 0x9b, 0x3e, 0x21, 0x6b, 0xff, 0x75, 0xec, 0xfc, 0xfe, 0x60, 0xce, 0x46, 0x8b, 0x5a, - 0xeb, 0x5f, 0x58, 0x56, 0xb6, 0x1b, 0x7c, 0xcc, 0x6c, 0x63, 0x3a, 0xb3, 0x8d, 0xaf, 0x99, 0x6d, - 0xbc, 0xcd, 0xed, 0xdc, 0x74, 0x6e, 0xe7, 0x3e, 0xe7, 0x76, 0x8e, 0x1c, 0x0a, 0xfc, 0x23, 0xea, - 0xd6, 0x78, 0xb8, 0xe0, 0x42, 0x0f, 0x46, 0xbe, 0x03, 0x18, 0xd2, 0x15, 0xd4, 0x12, 0xb8, 0xa6, - 0xe8, 0x64, 0x75, 0x78, 0xfd, 0x12, 0x31, 0xe5, 0x17, 0x92, 0x93, 0x9d, 0xff, 0x04, 0x00, 0x00, - 0xff, 0xff, 0x87, 0x63, 0x76, 0x3b, 0x1c, 0x02, 0x00, 0x00, + // 338 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x91, 0xc1, 0x4e, 0xea, 0x40, + 0x14, 0x86, 0x99, 0xcb, 0x0d, 0x84, 0xb9, 0xb9, 0xdc, 0xa4, 0xc9, 0x85, 0xca, 0xa2, 0x12, 0x12, + 0x23, 0x31, 0xa1, 0x0d, 0xea, 0xca, 0x1d, 0x18, 0x17, 0x2e, 0x48, 0x4c, 0x5d, 0xe9, 0x86, 0xb4, + 0xc7, 0x93, 0x32, 0x29, 0x9d, 0xa9, 0x3d, 0x03, 0xe2, 0xd6, 0x27, 0xf0, 0x51, 0x7c, 0x0c, 0x97, + 0x2c, 0x5d, 0x1a, 0x58, 0xf8, 0x1a, 0x86, 0xd2, 0x06, 0x48, 0x34, 0x71, 0xf9, 0xff, 0xf9, 0xe6, + 0x3f, 0xff, 0x9c, 0xc3, 0xf7, 0xe3, 0x44, 0x4d, 0x51, 0x7a, 0x12, 0xd0, 0x11, 0x3e, 0x8c, 0x94, + 0x0a, 0xc9, 0x99, 0x76, 0x1d, 0x3d, 0xb3, 0xe3, 0x44, 0x69, 0x65, 0xd4, 0x36, 0x80, 0x9d, 0x03, + 0xf6, 0xb4, 0xdb, 0xa8, 0x83, 0xa2, 0x48, 0x91, 0x13, 0x51, 0xb0, 0xe2, 0x23, 0x0a, 0xd6, 0x0f, + 0x5a, 0x0f, 0xfc, 0xef, 0x80, 0x82, 0x8b, 0x48, 0xe8, 0xcb, 0xfe, 0x79, 0x0f, 0x42, 0xa3, 0xc6, + 0x4b, 0x84, 0xf2, 0x0e, 0x13, 0x93, 0x35, 0x59, 0xbb, 0xe2, 0x66, 0xca, 0x38, 0xe4, 0xff, 0x62, + 0x0f, 0x42, 0xd4, 0x43, 0xc2, 0xfb, 0x09, 0x4a, 0x40, 0xf3, 0x57, 0x93, 0xb5, 0x7f, 0xbb, 0xd5, + 0xb5, 0x7d, 0x9d, 0xb9, 0x86, 0xc9, 0xcb, 0x30, 0xf2, 0xa4, 0xc4, 0xb1, 0x59, 0x4c, 0x13, 0x72, + 0x79, 0xf6, 0xe7, 0xe9, 0xe3, 0xe5, 0x28, 0xcb, 0x6b, 0xdd, 0xf0, 0xff, 0x3b, 0x83, 0x5d, 0xa4, + 0x58, 0x49, 0xc2, 0xd5, 0x20, 0x50, 0x52, 0x27, 0x1e, 0xe8, 0x61, 0x82, 0x34, 0x19, 0xeb, 0xac, + 0x49, 0x35, 0xb7, 0xdd, 0xd4, 0x35, 0xea, 0xbc, 0x2c, 0x7c, 0x18, 0x7a, 0x10, 0xa6, 0x4d, 0x2a, + 0x6e, 0x49, 0xf8, 0xd0, 0x83, 0xf0, 0x58, 0xf0, 0xe2, 0x80, 0x02, 0xc3, 0xe7, 0x7c, 0xeb, 0x5f, + 0x07, 0xf6, 0xd7, 0xab, 0xb1, 0x77, 0x5a, 0x34, 0x3a, 0x3f, 0xc2, 0xf2, 0xb2, 0xfd, 0xf0, 0x75, + 0x61, 0xb1, 0xf9, 0xc2, 0x62, 0xef, 0x0b, 0x8b, 0x3d, 0x2f, 0xad, 0xc2, 0x7c, 0x69, 0x15, 0xde, + 0x96, 0x56, 0x81, 0xef, 0x09, 0xf5, 0x4d, 0xd4, 0x15, 0xbb, 0x3d, 0x0d, 0x84, 0x1e, 0x4d, 0x7c, + 0x1b, 0x54, 0xe4, 0x6c, 0xa0, 0x8e, 0x50, 0x5b, 0xca, 0x99, 0x6d, 0x4e, 0xac, 0x1f, 0x63, 0x24, + 0xbf, 0x94, 0x9e, 0xec, 0xe4, 0x33, 0x00, 0x00, 0xff, 0xff, 0x08, 0xa6, 0xff, 0xb8, 0x06, 0x02, + 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. diff --git a/x/ibcratelimit/params.pb.go b/x/ibcratelimit/params.pb.go index c838536739..57d491bb4a 100644 --- a/x/ibcratelimit/params.pb.go +++ b/x/ibcratelimit/params.pb.go @@ -5,7 +5,6 @@ package ibcratelimit import ( fmt "fmt" - _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/cosmos/gogoproto/proto" io "io" math "math" @@ -78,20 +77,19 @@ func init() { } var fileDescriptor_ee0cbe8442d3fe43 = []byte{ - // 194 bytes of a gzipped FileDescriptorProto + // 181 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x2f, 0x28, 0xca, 0x2f, 0x4b, 0xcd, 0x4b, 0xcc, 0x4b, 0x4e, 0xd5, 0xcf, 0x4c, 0x4a, 0x2e, 0x4a, 0x2c, 0x49, 0xcd, 0xc9, 0xcc, 0xcd, 0x2c, 0xd1, 0x2f, 0x33, 0xd4, 0x2f, 0x48, 0x2c, 0x4a, 0xcc, 0x2d, 0xd6, 0x2b, 0x28, - 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x42, 0x28, 0xd4, 0x43, 0x56, 0xa8, 0x57, 0x66, 0x28, 0x25, 0x92, - 0x9e, 0x9f, 0x9e, 0x0f, 0x56, 0xa6, 0x0f, 0x62, 0x41, 0x74, 0x28, 0x19, 0x73, 0xb1, 0x05, 0x80, - 0x4d, 0x10, 0xd2, 0xe4, 0x12, 0x48, 0xce, 0xcf, 0x2b, 0x29, 0x4a, 0x4c, 0x2e, 0x89, 0x4f, 0x4c, - 0x49, 0x29, 0x4a, 0x2d, 0x2e, 0x96, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x0c, 0xe2, 0x87, 0x89, 0x3b, - 0x42, 0x84, 0x9d, 0x72, 0x4f, 0x3c, 0x92, 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, 0x39, - 0xc6, 0x09, 0x8f, 0xe5, 0x18, 0x2e, 0x3c, 0x96, 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x81, 0x4b, 0x36, - 0x13, 0x6c, 0x30, 0x0e, 0x37, 0x04, 0x30, 0x46, 0x19, 0xa5, 0x67, 0x96, 0x64, 0x94, 0x26, 0xe9, - 0x25, 0xe7, 0xe7, 0xea, 0x23, 0x14, 0xea, 0x66, 0xe6, 0x23, 0xf1, 0xf4, 0x2b, 0x50, 0x7c, 0x99, - 0xc4, 0x06, 0x76, 0xaa, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0xc3, 0xfd, 0xab, 0x14, 0x07, 0x01, - 0x00, 0x00, + 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x42, 0x28, 0xd4, 0x43, 0x56, 0xa8, 0x57, 0x66, 0xa8, 0x64, 0xcc, + 0xc5, 0x16, 0x00, 0x56, 0x2b, 0xa4, 0xc9, 0x25, 0x90, 0x9c, 0x9f, 0x57, 0x52, 0x94, 0x98, 0x5c, + 0x12, 0x9f, 0x98, 0x92, 0x52, 0x94, 0x5a, 0x5c, 0x2c, 0xc1, 0xa8, 0xc0, 0xa8, 0xc1, 0x19, 0xc4, + 0x0f, 0x13, 0x77, 0x84, 0x08, 0x3b, 0xe5, 0x9e, 0x78, 0x24, 0xc7, 0x78, 0xe1, 0x91, 0x1c, 0xe3, + 0x83, 0x47, 0x72, 0x8c, 0x13, 0x1e, 0xcb, 0x31, 0x5c, 0x78, 0x2c, 0xc7, 0x70, 0xe3, 0xb1, 0x1c, + 0x03, 0x97, 0x6c, 0x66, 0xbe, 0x1e, 0x6e, 0xdb, 0x02, 0x18, 0xa3, 0x8c, 0xd2, 0x33, 0x4b, 0x32, + 0x4a, 0x93, 0xf4, 0x92, 0xf3, 0x73, 0xf5, 0x11, 0x0a, 0x75, 0x33, 0xf3, 0x91, 0x78, 0xfa, 0x15, + 0x28, 0xfe, 0x49, 0x62, 0x03, 0x7b, 0xc3, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0x9e, 0xc8, 0x67, + 0xbb, 0xf1, 0x00, 0x00, 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { diff --git a/x/marker/client/cli/tx.go b/x/marker/client/cli/tx.go index 122a829ef1..ce7a631696 100644 --- a/x/marker/client/cli/tx.go +++ b/x/marker/client/cli/tx.go @@ -102,7 +102,7 @@ Please use 'gov proposal submit-proposal instead. `, ), RunE: func(_ *cobra.Command, _ []string) error { - return fmt.Errorf("this command has been deprecated, and is no longer functional. Please use 'gov proposal submit-proposal' instead") + return fmt.Errorf("this command has been deprecated, and is no longer functional. Please use 'gov submit-proposal' instead") }, } flags.AddTxFlagsToCmd(cmd) diff --git a/x/msgfees/client/cli/cli_test.go b/x/msgfees/client/cli/cli_test.go index 840f877083..04165cd650 100644 --- a/x/msgfees/client/cli/cli_test.go +++ b/x/msgfees/client/cli/cli_test.go @@ -9,16 +9,22 @@ import ( sdkmath "cosmossdk.io/math" + cmtcli "github.com/cometbft/cometbft/libs/cli" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/crypto/hd" + "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" testnet "github.com/cosmos/cosmos-sdk/testutil/network" sdk "github.com/cosmos/cosmos-sdk/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" "github.com/provenance-io/provenance/internal/pioconfig" "github.com/provenance-io/provenance/testutil" testcli "github.com/provenance-io/provenance/testutil/cli" - msgfeescli "github.com/provenance-io/provenance/x/msgfees/client/cli" + "github.com/provenance-io/provenance/x/msgfees/client/cli" "github.com/provenance-io/provenance/x/msgfees/types" ) @@ -34,6 +40,11 @@ type IntegrationTestSuite struct { account2Addr sdk.AccAddress account2Key *secp256k1.PrivKey acc2NameCount int + + accountAddresses []sdk.AccAddress + + keyring keyring.Keyring + keyringDir string } func TestIntegrationTestSuite(t *testing.T) { @@ -59,183 +70,197 @@ func (s *IntegrationTestSuite) SetupSuite() { s.cfg = testutil.DefaultTestNetworkConfig() s.cfg.TimeoutCommit = 500 * time.Millisecond s.cfg.NumValidators = 1 + s.GenerateAccountsWithKeyrings(1) + + testutil.MutateGenesisState(s.T(), &s.cfg, banktypes.ModuleName, &banktypes.GenesisState{}, func(bankGenState *banktypes.GenesisState) *banktypes.GenesisState { + var genBalances []banktypes.Balance + for i := range s.accountAddresses { + genBalances = append(genBalances, banktypes.Balance{Address: s.accountAddresses[i].String(), Coins: sdk.NewCoins( + sdk.NewInt64Coin("nhash", 100_000_000), sdk.NewInt64Coin(s.cfg.BondDenom, 100_000_000), + ).Sort()}) + } + bankGenState.Params = banktypes.DefaultParams() + bankGenState.Balances = genBalances + return bankGenState + }) + + testutil.MutateGenesisState(s.T(), &s.cfg, authtypes.ModuleName, &authtypes.GenesisState{}, func(authData *authtypes.GenesisState) *authtypes.GenesisState { + var genAccounts []authtypes.GenesisAccount + authData.Params = authtypes.DefaultParams() + genAccounts = append(genAccounts, authtypes.NewBaseAccount(s.accountAddresses[0], nil, 3, 0)) + accounts, err := authtypes.PackAccounts(genAccounts) + s.Require().NoError(err, "should be able to pack accounts for genesis state when setting up suite") + authData.Accounts = accounts + return authData + }) - var msgfeeGen types.GenesisState - err = s.cfg.Codec.UnmarshalJSON(s.cfg.GenesisState[types.ModuleName], &msgfeeGen) - s.Require().NoError(err, "UnmarshalJSON msgfee gen state") - msgfeeGen.MsgFees = append(msgfeeGen.MsgFees, types.MsgFee{ - MsgTypeUrl: "/provenance.metadata.v1.MsgAddContractSpecToScopeSpecRequest", - AdditionalFee: sdk.NewInt64Coin(s.cfg.BondDenom, 3), + testutil.MutateGenesisState(s.T(), &s.cfg, types.ModuleName, &types.GenesisState{}, func(msgfeeGen *types.GenesisState) *types.GenesisState { + err = s.cfg.Codec.UnmarshalJSON(s.cfg.GenesisState[types.ModuleName], msgfeeGen) + s.Require().NoError(err, "UnmarshalJSON msgfee gen state") + msgfeeGen.MsgFees = append(msgfeeGen.MsgFees, types.MsgFee{ + MsgTypeUrl: "/provenance.metadata.v1.MsgAddContractSpecToScopeSpecRequest", + AdditionalFee: sdk.NewInt64Coin(s.cfg.BondDenom, 3), + }) + return msgfeeGen }) - s.cfg.GenesisState[types.ModuleName], err = s.cfg.Codec.MarshalJSON(&msgfeeGen) - s.Require().NoError(err, "MarshalJSON msgfee gen state") s.testnet, err = testnet.New(s.T(), s.T().TempDir(), s.cfg) s.Require().NoError(err, "creating testnet") + s.testnet.Validators[0].ClientCtx = s.testnet.Validators[0].ClientCtx.WithKeyringDir(s.keyringDir).WithKeyring(s.keyring) _, err = testutil.WaitForHeight(s.testnet, 1) s.Require().NoError(err, "waiting for height 1") } +func (s *IntegrationTestSuite) GenerateAccountsWithKeyrings(number int) { + path := hd.CreateHDPath(118, 0, 0).String() + s.keyringDir = s.T().TempDir() + kr, err := keyring.New(s.T().Name(), "test", s.keyringDir, nil, s.cfg.Codec) + s.Require().NoError(err, "Keyring.New") + s.keyring = kr + for i := 0; i < number; i++ { + keyId := fmt.Sprintf("test_key%v", i) + info, _, err := kr.NewMnemonic(keyId, keyring.English, path, keyring.DefaultBIP39Passphrase, hd.Secp256k1) + s.Require().NoError(err, "Keyring.NewMnemonic") + addr, err := info.GetAddress() + s.Require().NoError(err, "GetAddress") + s.accountAddresses = append(s.accountAddresses, addr) + } +} + func (s *IntegrationTestSuite) TearDownSuite() { testutil.Cleanup(s.testnet, s.T()) } -func (s *IntegrationTestSuite) TestMsgFeesTxGovProposals() { +func (s *IntegrationTestSuite) TestMsgFeesProposal() { testCases := []struct { - name string - typeArg string - title string - description string - deposit string - msgType string - additionalFee string - recipient string - bips string - expectErrMsg string - expectedCode uint32 + name string + args []string + expectErrMsg string + expectedCode uint32 + signer string }{ { - name: "add msg based fee proposal - valid", - typeArg: "add", - title: "test add msg based fee", - description: "description", - deposit: sdk.NewCoins(sdk.NewInt64Coin(s.cfg.BondDenom, 10)).String(), - msgType: "--msg-type=/provenance.metadata.v1.MsgWriteRecordRequest", - additionalFee: fmt.Sprintf("--additional-fee=%s", sdk.NewCoins(sdk.NewInt64Coin(s.cfg.BondDenom, 12)).String()), - recipient: "", - bips: "", - expectErrMsg: "", - expectedCode: 0, + name: "success - add msg fee", + args: []string{ + "add", + "--msg-type=/provenance.metadata.v1.MsgWriteRecordRequest", + "--additional-fee=612nhash", + }, + expectedCode: 0, + signer: s.accountAddresses[0].String(), }, { - name: "add msg based fee proposal with recipient - valid", - typeArg: "add", - title: "test update msg based fee", - description: "description", - deposit: sdk.NewCoins(sdk.NewInt64Coin(s.cfg.BondDenom, 10)).String(), - msgType: "--msg-type=/provenance.metadata.v1.MsgWriteRecordRequest", - additionalFee: fmt.Sprintf("--additional-fee=%s", sdk.NewCoins(sdk.NewInt64Coin(s.cfg.BondDenom, 12)).String()), - recipient: "", - bips: "", - expectErrMsg: "", - expectedCode: 0, + name: "success - update msg fee", + args: []string{ + "update", + "--msg-type=/provenance.metadata.v1.MsgWriteRecordRequest", + "--additional-fee=612000nhash", + }, + expectedCode: 0, + signer: s.accountAddresses[0].String(), }, { - name: "add msg based fee proposal with recipient and default basis points - valid", - typeArg: "add", - title: "test update msg based fee", - description: "description", - deposit: sdk.NewCoins(sdk.NewInt64Coin(s.cfg.BondDenom, 10)).String(), - msgType: "--msg-type=/provenance.metadata.v1.MsgWriteRecordRequest", - additionalFee: fmt.Sprintf("--additional-fee=%s", sdk.NewCoins(sdk.NewInt64Coin(s.cfg.BondDenom, 12)).String()), - recipient: fmt.Sprintf("--recipient=%s", s.testnet.Validators[0].Address.String()), - bips: "", - expectErrMsg: "", - expectedCode: 0, + name: "success - remove msg fee", + args: []string{ + "remove", + "--msg-type=/provenance.metadata.v1.MsgWriteRecordRequest", + }, + expectedCode: 0, + signer: s.accountAddresses[0].String(), }, { - name: "add msg based fee proposal - invalid msg type url", - typeArg: "add", - title: "test add msg based fee", - description: "description", - deposit: sdk.NewCoins(sdk.NewInt64Coin(s.cfg.BondDenom, 10)).String(), - msgType: "--msg-type=invalid", - additionalFee: fmt.Sprintf("--additional-fee=%s", sdk.NewCoins(sdk.NewInt64Coin(s.cfg.BondDenom, 12)).String()), - recipient: "", - bips: "", - expectErrMsg: "unable to resolve type URL invalid", - expectedCode: 0, + name: "failure - invalid number of args", + args: []string{"add", "extra-arg"}, + expectErrMsg: "accepts 1 arg(s), received 2", + signer: s.accountAddresses[0].String(), }, { - name: "add msg based fee proposal - invalid additional fee", - typeArg: "add", - title: "test add msg based fee", - description: "description", - deposit: sdk.NewCoins(sdk.NewInt64Coin(s.cfg.BondDenom, 10)).String(), - msgType: "--msg-type=/provenance.metadata.v1.MsgWriteRecordRequest", - additionalFee: fmt.Sprintf("--additional-fee=%s", "blah"), - recipient: "", - bips: "", - expectErrMsg: "invalid decimal coin expression: blah", - expectedCode: 0, + name: "failure - invalid proposal type", + args: []string{ + "invalid-type", + "--msg-type=/provenance.metadata.v1.MsgWriteRecordRequest", + }, + expectErrMsg: `unknown proposal type "invalid-type"`, + signer: s.accountAddresses[0].String(), }, { - name: "update msg based fee proposal with recipient - valid", - typeArg: "update", - title: "test update msg based fee", - description: "description", - deposit: sdk.NewCoins(sdk.NewInt64Coin(s.cfg.BondDenom, 10)).String(), - msgType: "--msg-type=/provenance.metadata.v1.MsgAddContractSpecToScopeSpecRequest", - additionalFee: fmt.Sprintf("--additional-fee=%s", sdk.NewCoins(sdk.NewInt64Coin(s.cfg.BondDenom, 12)).String()), - recipient: "", - bips: "", - expectErrMsg: "", - expectedCode: 0, + name: "success - add msg fee with recipient and bips", + args: []string{ + "add", + "--msg-type=/provenance.metadata.v1.MsgWriteRecordRequest", + "--additional-fee=612nhash", + fmt.Sprintf("--recipient=%v", s.account2Addr.String()), + "--bips=100", + "--deposit=1000000stake", + }, + expectedCode: 0, + signer: s.accountAddresses[0].String(), }, { - name: "update msg based fee proposal with recipient and default basis points - valid", - typeArg: "update", - title: "test update msg based fee", - description: "description", - deposit: sdk.NewCoins(sdk.NewInt64Coin(s.cfg.BondDenom, 10)).String(), - msgType: "--msg-type=/provenance.metadata.v1.MsgAddContractSpecToScopeSpecRequest", - additionalFee: fmt.Sprintf("--additional-fee=%s", sdk.NewCoins(sdk.NewInt64Coin(s.cfg.BondDenom, 12)).String()), - recipient: fmt.Sprintf("--recipient=%s", s.testnet.Validators[0].Address.String()), - bips: "", - expectErrMsg: "", - expectedCode: 0, + name: "failure - invalid fee format", + args: []string{ + "add", + "--msg-type=/provenance.metadata.v1.MsgWriteRecordRequest", + "--additional-fee=invalid-fee", + }, + expectErrMsg: "invalid decimal coin expression: invalid-fee", + signer: s.accountAddresses[0].String(), }, { - name: "update msg based fee proposal with recipient and modified basis points - valid", - typeArg: "update", - title: "test update msg based fee", - description: "description", - deposit: sdk.NewCoins(sdk.NewInt64Coin(s.cfg.BondDenom, 10)).String(), - msgType: "--msg-type=/provenance.metadata.v1.MsgAddContractSpecToScopeSpecRequest", - additionalFee: fmt.Sprintf("--additional-fee=%s", sdk.NewCoins(sdk.NewInt64Coin(s.cfg.BondDenom, 12)).String()), - recipient: fmt.Sprintf("--recipient=%s", s.testnet.Validators[0].Address.String()), - bips: fmt.Sprintf("--bips=%s", "5001"), - expectErrMsg: "", - expectedCode: 0, + name: "success - update msg fee with recipient and bips", + args: []string{ + "update", + "--msg-type=/provenance.metadata.v1.MsgWriteRecordRequest", + "--additional-fee=612000nhash", + fmt.Sprintf("--recipient=%v", s.account2Addr.String()), + "--bips=100", + "--deposit=1000000stake", + }, + expectedCode: 0, + signer: s.accountAddresses[0].String(), }, { - name: "remove msg based fee proposal - valid", - typeArg: "remove", - title: "test update msg based fee", - description: "description", - deposit: sdk.NewCoins(sdk.NewInt64Coin(s.cfg.BondDenom, 10)).String(), - msgType: "--msg-type=/provenance.metadata.v1.MsgAddContractSpecToScopeSpecRequest", - additionalFee: "", - recipient: "", - bips: "", - expectErrMsg: "", - expectedCode: 0, + name: "failure - invalid recipient format", + args: []string{ + "add", + "--msg-type=/provenance.metadata.v1.MsgWriteRecordRequest", + "--additional-fee=612nhash", + "--recipient=invalid-recipient", + "--bips=100", + "--deposit=1000000stake", + }, + expectErrMsg: "error validating basis points args: decoding bech32 failed: invalid separator index -1", + signer: s.accountAddresses[0].String(), + }, + { + name: "failure - bips out of range", + args: []string{ + "add", + "--msg-type=/provenance.metadata.v1.MsgWriteRecordRequest", + "--additional-fee=612nhash", + fmt.Sprintf("--recipient=%v", s.account2Addr.String()), + "--bips=10001", + "--deposit=1000000stake", + }, + expectErrMsg: "error validating basis points args: recipient basis points can only be between 0 and 10,000 : 10001", + signer: s.accountAddresses[0].String(), }, } for _, tc := range testCases { s.Run(tc.name, func() { - cmd := msgfeescli.GetCmdMsgFeesProposal() - args := []string{ - fmt.Sprintf("--%s=%s", flags.FlagFrom, s.testnet.Validators[0].Address.String()), + cmd := cli.GetCmdMsgFeesProposal() + tc.args = append(tc.args, + "--title", "Update nhash per usd mil proposal", "--summary", "Updates the nhash per usd mil rate.", + fmt.Sprintf("--%s=%s", flags.FlagFrom, tc.signer), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewInt64Coin(s.cfg.BondDenom, 10)).String()), - } - - args = append(args, tc.typeArg, tc.title, tc.description, tc.deposit, tc.msgType) - if len(tc.additionalFee) != 0 { - args = append(args, tc.additionalFee) - } - if len(tc.recipient) != 0 { - args = append(args, tc.recipient) - } - if len(tc.bips) != 0 { - args = append(args, tc.bips) - } - - testcli.NewCLITxExecutor(cmd, args). + fmt.Sprintf("--%s=json", cmtcli.OutputFlag), + ) + + testcli.NewCLITxExecutor(cmd, tc.args). WithExpErrMsg(tc.expectErrMsg). WithExpCode(tc.expectedCode). Execute(s.T(), s.testnet) @@ -243,57 +268,47 @@ func (s *IntegrationTestSuite) TestMsgFeesTxGovProposals() { } } -func (s *IntegrationTestSuite) TestUpdateUsdConversionRateProposal() { +func (s *IntegrationTestSuite) TestUpdateNhashPerUsdMilProposal() { testCases := []struct { name string - title string - description string - rate string - deposit string + args []string expectErrMsg string expectedCode uint32 + signer string }{ { - name: "update nhash to usd mil proposal - valid", - title: "title", - description: "description", - rate: "10", - deposit: sdk.NewCoins(sdk.NewInt64Coin(s.cfg.BondDenom, 10)).String(), - expectErrMsg: "", + name: "success - valid update", + args: []string{"1234"}, expectedCode: 0, + signer: s.accountAddresses[0].String(), }, { - name: "update nhash to usd mil proposal - invalid - rate param error", - title: "title", - description: "description", - rate: "invalid-rate", - deposit: sdk.NewCoins(sdk.NewInt64Coin(s.cfg.BondDenom, 10)).String(), - expectErrMsg: "unable to parse nhash value: invalid-rate", - expectedCode: 0, + name: "failure - invalid nhash value", + args: []string{"invalid-nhash-value"}, + expectErrMsg: "unable to parse nhash value: invalid-nhash-value", + signer: s.accountAddresses[0].String(), }, { - name: "update nhash to usd mil proposal - invalid - deposit param", - title: "title", - description: "description", - rate: "10", - deposit: "invalid-deposit", - expectErrMsg: "invalid decimal coin expression: invalid-deposit", - expectedCode: 0, + name: "failure - no nhash value", + args: []string{}, + expectErrMsg: "accepts 1 arg(s), received 0", + signer: s.accountAddresses[0].String(), }, } for _, tc := range testCases { s.Run(tc.name, func() { - cmd := msgfeescli.GetUpdateNhashPerUsdMilProposal() - args := []string{ - fmt.Sprintf("--%s=%s", flags.FlagFrom, s.testnet.Validators[0].Address.String()), + cmd := cli.GetUpdateNhashPerUsdMilProposal() + tc.args = append(tc.args, + "--title", "Update nhash per usd mil proposal", "--summary", "Updates the nhash per usd mil rate.", + fmt.Sprintf("--%s=%s", flags.FlagFrom, tc.signer), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewInt64Coin(s.cfg.BondDenom, 10)).String()), - } - args = append(args, tc.name, tc.description, tc.rate, tc.deposit) + fmt.Sprintf("--%s=json", cmtcli.OutputFlag), + ) - testcli.NewCLITxExecutor(cmd, args). + testcli.NewCLITxExecutor(cmd, tc.args). WithExpErrMsg(tc.expectErrMsg). WithExpCode(tc.expectedCode). Execute(s.T(), s.testnet) @@ -303,49 +318,44 @@ func (s *IntegrationTestSuite) TestUpdateUsdConversionRateProposal() { func (s *IntegrationTestSuite) TestUpdateConversionFeeDenomProposal() { testCases := []struct { - name string - title string - description string - conversionFeeDenom string - deposit string - expectErrMsg string - expectedCode uint32 + name string + args []string + expectErrMsg string + expectedCode uint32 + signer string }{ { - name: "update nhash to usd mil proposal - valid", - title: "title", - description: "description", - conversionFeeDenom: "jackthecat", - deposit: sdk.NewCoins(sdk.NewInt64Coin(s.cfg.BondDenom, 10)).String(), - expectErrMsg: "", - expectedCode: 0, + name: "success - valid denom update", + args: []string{"customcoin"}, + expectedCode: 0, + signer: s.accountAddresses[0].String(), }, { - name: "update nhash to usd mil proposal - invalid - deposit param", - title: "title", - description: "description", - conversionFeeDenom: "jackthecat", - deposit: "invalid-deposit", - expectErrMsg: "invalid decimal coin expression: invalid-deposit", - expectedCode: 0, + name: "failure - too many arguments", + args: []string{"customcoin", "unexpected"}, + expectErrMsg: "accepts 1 arg(s), received 2", + signer: s.accountAddresses[0].String(), }, } for _, tc := range testCases { s.Run(tc.name, func() { - cmd := msgfeescli.GetUpdateConversionFeeDenomProposal() - args := []string{ - fmt.Sprintf("--%s=%s", flags.FlagFrom, s.testnet.Validators[0].Address.String()), + cmd := cli.GetUpdateConversionFeeDenomProposal() + tc.args = append(tc.args, + "--title", "Update conversion fee denom proposal", "--summary", "Updates the conversion fee denom.", + fmt.Sprintf("--%s=%s", flags.FlagFrom, tc.signer), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewInt64Coin(s.cfg.BondDenom, 10)).String()), - } - args = append(args, tc.name, tc.description, tc.conversionFeeDenom, tc.deposit) + fmt.Sprintf("--%s=json", cmtcli.OutputFlag), + ) - testcli.NewCLITxExecutor(cmd, args). + testcli.NewCLITxExecutor(cmd, tc.args). WithExpErrMsg(tc.expectErrMsg). WithExpCode(tc.expectedCode). Execute(s.T(), s.testnet) }) } } + +// TODO: Add query tests diff --git a/x/msgfees/client/cli/tx.go b/x/msgfees/client/cli/tx.go index a02b89af09..7cd95a3088 100644 --- a/x/msgfees/client/cli/tx.go +++ b/x/msgfees/client/cli/tx.go @@ -9,11 +9,11 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/client/tx" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/version" - govtypesv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" + govcli "github.com/cosmos/cosmos-sdk/x/gov/client/cli" + "github.com/provenance-io/provenance/internal/provcli" "github.com/provenance-io/provenance/x/msgfees/types" ) @@ -46,16 +46,16 @@ func NewTxCmd() *cobra.Command { func GetCmdMsgFeesProposal() *cobra.Command { cmd := &cobra.Command{ - Use: "proposal {add|update|remove} <description> <deposit>", - Args: cobra.ExactArgs(4), + Use: "proposal {add|update|remove}", + Args: cobra.ExactArgs(1), Aliases: []string{"p"}, Short: "Submit a msg based fee proposal along with an initial deposit", Long: strings.TrimSpace(`Submit a msg fees proposal along with an initial deposit. For add, update, and removal of msg fees amount and min fee and/or rate fee must be set. `), - Example: fmt.Sprintf(`$ %[1]s tx msgfees add "adding" "adding MsgWriterRecordRequest fee" 10nhash --msg-type=/provenance.metadata.v1.MsgWriteRecordRequest --additional-fee=612nhash --recipient=pb... --bips=5000 -$ %[1]s tx msgfees update "updating" "updating MsgWriterRecordRequest fee" 10nhash --msg-type=/provenance.metadata.v1.MsgWriteRecordRequest --additional-fee=612000nhash --recipient=pb... --bips=5000 -$ %[1]s tx msgfees remove "removing" "removing MsgWriterRecordRequest fee" 10nhash --msg-type=/provenance.metadata.v1.MsgWriteRecordRequest + Example: fmt.Sprintf(`$ %[1]s tx msgfees add --msg-type=/provenance.metadata.v1.MsgWriteRecordRequest --additional-fee=612nhash --recipient=pb... --bips=5000 --deposit 1000000000nhash +$ %[1]s tx msgfees update --msg-type=/provenance.metadata.v1.MsgWriteRecordRequest --additional-fee=612000nhash --recipient=pb... --bips=5000 --deposit 1000000000nhash +$ %[1]s tx msgfees remove --msg-type=/provenance.metadata.v1.MsgWriteRecordRequest --deposit 1000000000nhash `, version.AppName), RunE: func(cmd *cobra.Command, args []string) error { clientCtx, err := client.GetClientTxContext(cmd) @@ -63,6 +63,8 @@ $ %[1]s tx msgfees remove "removing" "removing MsgWriterRecordRequest fee" 10nha return err } + flagSet := cmd.Flags() + authority := provcli.GetAuthority(flagSet) proposalType := args[0] msgType, err := cmd.Flags().GetString(FlagMsgType) @@ -75,19 +77,26 @@ $ %[1]s tx msgfees remove "removing" "removing MsgWriterRecordRequest fee" 10nha return err } - recipient, err := cmd.Flags().GetString(FlagRecipient) + recipient, err := flagSet.GetString(FlagRecipient) if err != nil { return err } - bips, err := cmd.Flags().GetString(FlagBips) + bips, err := flagSet.GetString(FlagBips) if err != nil { return err } + if len(recipient) > 0 || len(bips) > 0 { + if err := types.ValidateBips(recipient, bips); err != nil { + return fmt.Errorf("error validating basis points args: %w", err) + } + + } + var addFee sdk.Coin if proposalType != "remove" { - additionalFee, errMinFee := cmd.Flags().GetString(FlagMinFee) + additionalFee, errMinFee := flagSet.GetString(FlagMinFee) if errMinFee != nil { return err } @@ -99,51 +108,23 @@ $ %[1]s tx msgfees remove "removing" "removing MsgWriterRecordRequest fee" 10nha } } - var proposal govtypesv1beta1.Content - + var msg sdk.Msg switch args[0] { case "add": - proposal = &types.AddMsgFeeProposal{ - Title: args[1], - Description: args[2], - MsgTypeUrl: msgType, - AdditionalFee: addFee, - Recipient: recipient, - RecipientBasisPoints: bips, - } + msg = types.NewMsgAddMsgFeeProposalRequest(msgType, addFee, recipient, bips, authority) case "update": - proposal = &types.UpdateMsgFeeProposal{ - Title: args[1], - Description: args[2], - MsgTypeUrl: msgType, - AdditionalFee: addFee, - Recipient: recipient, - RecipientBasisPoints: bips, - } + msg = types.NewMsgUpdateMsgFeeProposalRequest(msgType, addFee, recipient, bips, authority) case "remove": - proposal = &types.RemoveMsgFeeProposal{ - Title: args[1], - Description: args[2], - MsgTypeUrl: msgType, - } + msg = types.NewMsgRemoveMsgFeeProposalRequest(msgType, authority) default: return fmt.Errorf("unknown proposal type %q", args[0]) } - - deposit, err := sdk.ParseCoinsNormalized(args[3]) - if err != nil { - return err - } - - callerAddr := clientCtx.GetFromAddress() - msg, err := govtypesv1beta1.NewMsgSubmitProposal(proposal, deposit, callerAddr) - if err != nil { - return fmt.Errorf("invalid governance proposal. Error: %w", err) - } - return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + return provcli.GenerateOrBroadcastTxCLIAsGovProp(clientCtx, flagSet, msg) }, } flags.AddTxFlagsToCmd(cmd) + govcli.AddGovPropFlagsToCmd(cmd) + provcli.AddAuthorityFlagToCmd(cmd) cmd.Flags().String(FlagMsgType, "", "proto type url for msg type") cmd.Flags().String(FlagMinFee, "", "additional fee for msg based fee") cmd.Flags().String(FlagRecipient, "", "optional recipient address for receiving partial fee based on basis points") @@ -153,73 +134,64 @@ $ %[1]s tx msgfees remove "removing" "removing MsgWriterRecordRequest fee" 10nha func GetUpdateNhashPerUsdMilProposal() *cobra.Command { cmd := &cobra.Command{ - Use: "nhash-per-usd-mil <title> <description> <nhash-per-usd-mil> <deposit>", + Use: "nhash-per-usd-mil <nhash-per-usd-mil>", Aliases: []string{"npum", "n-p-u-m"}, - Args: cobra.ExactArgs(4), + Args: cobra.ExactArgs(1), Short: "Submit a nhash per usd mil update proposal along with an initial deposit", Long: strings.TrimSpace(`Submit a nhash per usd mil update proposal along with an initial deposit. The nhash per usd mil is the number of nhash that will be multiplied by the usd mil amount. Example: $1.000 usd where 1 mil equals 2000nhash will equate to 1000 * 2000 = 2000000nhash `), - Example: fmt.Sprintf(`$ %[1]s tx msgfees nhash-per-usd-mil "updating nhash to usd mil" "changes the nhash per mil to 1234nhash" 1234 1000000000nhash -$ %[1]s tx msgfees npum "updating nhash to usd mil" "changes the nhash per mil to 1234nhash" 1234 1000000000nhash + Example: fmt.Sprintf(`$ %[1]s tx msgfees nhash-per-usd-mil 1234 --deposit 1000000000nhash +$ %[1]s tx msgfees npum 1234 --deposit 1000000000nhash `, version.AppName), RunE: func(cmd *cobra.Command, args []string) error { clientCtx, err := client.GetClientTxContext(cmd) + flagSet := cmd.Flags() + authority := provcli.GetAuthority(flagSet) if err != nil { return err } - title, description, nhash, depositArg := args[0], args[1], args[2], args[3] + nhash := args[0] rate, err := strconv.ParseUint(nhash, 0, 64) if err != nil { return fmt.Errorf("unable to parse nhash value: %s", nhash) } - proposal := types.NewUpdateNhashPerUsdMilProposal(title, description, rate) - deposit, err := sdk.ParseCoinsNormalized(depositArg) - if err != nil { - return err - } - callerAddr := clientCtx.GetFromAddress() - msg, err := govtypesv1beta1.NewMsgSubmitProposal(proposal, deposit, callerAddr) - if err != nil { - return fmt.Errorf("invalid governance proposal. Error: %w", err) - } - return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + msg := types.NewMsgUpdateNhashPerUsdMilProposalRequest(rate, authority) + return provcli.GenerateOrBroadcastTxCLIAsGovProp(clientCtx, flagSet, msg) }, } + govcli.AddGovPropFlagsToCmd(cmd) + provcli.AddAuthorityFlagToCmd(cmd) flags.AddTxFlagsToCmd(cmd) return cmd } func GetUpdateConversionFeeDenomProposal() *cobra.Command { cmd := &cobra.Command{ - Use: "conversion-fee-denom <title> <description> <conversion-fee-denom> <deposit>", + Use: "conversion-fee-denom <conversion-fee-denom>", Aliases: []string{"cfd", "c-f-d"}, - Args: cobra.ExactArgs(4), + Args: cobra.ExactArgs(1), Short: "Submit a conversion fee denom update proposal along with an initial deposit", Long: strings.TrimSpace(`Submit a conversion fee denom update proposal along with an initial deposit. The custom fee denom is the denom that usd will be converted to for fees with usd as denom type.`), - Example: fmt.Sprintf(`$ %[1]s tx msgfees conversion-fee-denom "updating conversion fee denom" "changes the conversion fee denom to customcoin" customcoin 1000000000nhash -$ %[1]s tx msgfees cfd "updating conversion fee denom" "changes the conversion fee denom to customcoin" customcoin 1000000000nhash + Example: fmt.Sprintf(`$ %[1]s tx msgfees conversion-fee-denom customcoin --deposit 1000000000nhash +$ %[1]s tx msgfees cfd customcoin --deposit 1000000000nhash `, version.AppName), RunE: func(cmd *cobra.Command, args []string) error { clientCtx, err := client.GetClientTxContext(cmd) + flagSet := cmd.Flags() + authority := provcli.GetAuthority(flagSet) + if err != nil { return err } - title, description, customCoin, depositArg := args[0], args[1], args[2], args[3] - proposal := types.NewUpdateConversionFeeDenomProposal(title, description, customCoin) - deposit, err := sdk.ParseCoinsNormalized(depositArg) - if err != nil { - return err - } - callerAddr := clientCtx.GetFromAddress() - msg, err := govtypesv1beta1.NewMsgSubmitProposal(proposal, deposit, callerAddr) - if err != nil { - return fmt.Errorf("invalid governance proposal. Error: %w", err) - } - return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + customCoin := args[0] + msg := types.NewMsgUpdateConversionFeeDenomProposalRequest(customCoin, authority) + return provcli.GenerateOrBroadcastTxCLIAsGovProp(clientCtx, flagSet, msg) }, } flags.AddTxFlagsToCmd(cmd) + govcli.AddGovPropFlagsToCmd(cmd) + provcli.AddAuthorityFlagToCmd(cmd) return cmd } diff --git a/x/msgfees/handler.go b/x/msgfees/handler.go deleted file mode 100644 index 30c008926a..0000000000 --- a/x/msgfees/handler.go +++ /dev/null @@ -1,32 +0,0 @@ -package msgfees - -import ( - cdctypes "github.com/cosmos/cosmos-sdk/codec/types" - sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - govtypesv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" - - "github.com/provenance-io/provenance/x/msgfees/keeper" - "github.com/provenance-io/provenance/x/msgfees/types" -) - -// TODO[1760]: marker: Migrate the legacy gov proposals. - -func NewProposalHandler(k keeper.Keeper, registry cdctypes.InterfaceRegistry) govtypesv1beta1.Handler { - return func(ctx sdk.Context, content govtypesv1beta1.Content) error { - switch c := content.(type) { - case *types.AddMsgFeeProposal: - return keeper.HandleAddMsgFeeProposal(ctx, k, c, registry) - case *types.UpdateMsgFeeProposal: - return keeper.HandleUpdateMsgFeeProposal(ctx, k, c, registry) - case *types.RemoveMsgFeeProposal: - return keeper.HandleRemoveMsgFeeProposal(ctx, k, c, registry) - case *types.UpdateNhashPerUsdMilProposal: - return keeper.HandleUpdateNhashPerUsdMilProposal(ctx, k, c) - case *types.UpdateConversionFeeDenomProposal: - return keeper.HandleUpdateConversionFeeDenomProposal(ctx, k, c) - default: - return sdkerrors.ErrUnknownRequest.Wrapf("unrecognized marker proposal content type: %T", c) - } - } -} diff --git a/x/msgfees/keeper/keeper.go b/x/msgfees/keeper/keeper.go index 64510369a1..b9eb9bb702 100644 --- a/x/msgfees/keeper/keeper.go +++ b/x/msgfees/keeper/keeper.go @@ -1,7 +1,9 @@ package keeper import ( + "fmt" "sort" + "strconv" "golang.org/x/exp/constraints" @@ -242,3 +244,77 @@ func sortedKeys[K constraints.Ordered, V any](m map[K]V) []K { }) return keys } + +// AddMsgFee adds a new msg fees +func (k Keeper) AddMsgFee(ctx sdk.Context, msgTypeURL, recipient, basisPoints string, additionalFee sdk.Coin) error { + if msgTypeURL == "" { + return types.ErrEmptyMsgType + } + + existing, err := k.GetMsgFee(ctx, msgTypeURL) + if err != nil { + return err + } + if existing != nil { + return types.ErrMsgFeeAlreadyExists + } + bips, err := DetermineBips(recipient, basisPoints) + if err != nil { + return err + } + + msgFees := types.NewMsgFee(msgTypeURL, additionalFee, recipient, bips) + + err = k.SetMsgFee(ctx, msgFees) + if err != nil { + return types.ErrInvalidFeeProposal + } + + return nil +} + +// UpdateMsgFee updates an existing msg fees +func (k Keeper) UpdateMsgFee(ctx sdk.Context, msgTypeURL, recipient, basisPoints string, additionalFee sdk.Coin) error { + if msgTypeURL == "" { + return types.ErrEmptyMsgType + } + + existing, err := k.GetMsgFee(ctx, msgTypeURL) + if err != nil { + return err + } + if existing == nil { + return types.ErrMsgFeeDoesNotExist + } + bips, err := DetermineBips(recipient, basisPoints) + if err != nil { + return err + } + + msgFees := types.NewMsgFee(msgTypeURL, additionalFee, recipient, bips) + + err = k.SetMsgFee(ctx, msgFees) + if err != nil { + return types.ErrInvalidFeeProposal + } + + return nil +} + +// DetermineBips converts basis point string to uint32 +func DetermineBips(recipient string, recipientBasisPoints string) (uint32, error) { + var bips uint32 + if len(recipientBasisPoints) > 0 && len(recipient) > 0 { + bips64, err := strconv.ParseUint(recipientBasisPoints, 10, 32) + if err != nil { + return bips, types.ErrInvalidBipsValue.Wrap(err.Error()) + } + bips = uint32(bips64) + if bips > 10_000 { + return 0, types.ErrInvalidBipsValue.Wrap(fmt.Errorf("recipient basis points can only be between 0 and 10,000 : %v", recipientBasisPoints).Error()) + } + } else if len(recipientBasisPoints) == 0 && len(recipient) > 0 { + bips = types.DefaultMsgFeeBips + } + return bips, nil +} diff --git a/x/msgfees/keeper/keeper_test.go b/x/msgfees/keeper/keeper_test.go index 9c4127b865..38f38189a0 100644 --- a/x/msgfees/keeper/keeper_test.go +++ b/x/msgfees/keeper/keeper_test.go @@ -20,6 +20,7 @@ import ( simapp "github.com/provenance-io/provenance/app" "github.com/provenance-io/provenance/internal/pioconfig" + msgfeeskeeper "github.com/provenance-io/provenance/x/msgfees/keeper" "github.com/provenance-io/provenance/x/msgfees/types" ) @@ -385,3 +386,173 @@ func (s *TestSuite) TestCalculateAdditionalFeesToBePaid() { assertEqualDist(s.T(), expected, actual) }) } + +func (s *TestSuite) TestAddMsgFee() { + testCases := []struct { + name string + msgTypeURL string + recipient string + basisPoints string + additionalFee sdk.Coin + expectError bool + errorMsg string + }{ + { + name: "successful addition", + msgTypeURL: "testTypeURL", + recipient: "testRecipient", + basisPoints: "100", + additionalFee: sdk.NewInt64Coin("nhash", 1000), + expectError: false, + }, + { + name: "duplicate msgTypeURL", + msgTypeURL: "testTypeURL", + recipient: "testRecipient", + basisPoints: "100", + additionalFee: sdk.NewInt64Coin("nhash", 1000), + expectError: true, + errorMsg: "fee for type already exists", + }, + { + name: "empty msgTypeURL", + msgTypeURL: "", + recipient: "testRecipient", + basisPoints: "100", + additionalFee: sdk.NewInt64Coin("nhash", 1000), + expectError: true, + errorMsg: "msg type is empty", + }, + } + + for _, tc := range testCases { + s.Run(tc.name, func() { + err := s.app.MsgFeesKeeper.AddMsgFee(s.ctx, tc.msgTypeURL, tc.recipient, tc.basisPoints, tc.additionalFee) + if tc.expectError { + s.Require().Error(err, "test was expected to fail") + s.Require().Contains(err.Error(), tc.errorMsg) + } else { + s.Require().NoError(err, "test was expected succeed") + msgFee, err := s.app.MsgFeesKeeper.GetMsgFee(s.ctx, tc.msgTypeURL) + s.Require().NoError(err, "GetMsgFee() should not error") + s.Require().NotNil(msgFee, "GetMsgFee() should have result") + s.Require().Equal(msgFee.MsgTypeUrl, tc.msgTypeURL, "msg type mis-match") + s.Require().Equal(msgFee.AdditionalFee, tc.additionalFee, "additional fee mis-match") + s.Require().Equal(msgFee.Recipient, tc.recipient, "recipient mis-match") + } + }) + } +} + +func (s *TestSuite) TestUpdateMsgFee() { + s.Require().NoError(s.app.MsgFeesKeeper.AddMsgFee(s.ctx, "updateTypeURL", "initialRecipient", "500", sdk.NewInt64Coin("nhash", 2000)), "AddMsgFee() failed test setup") + + testCases := []struct { + name string + msgTypeURL string + recipient string + basisPoints string + additionalFee sdk.Coin + expectError bool + errorMsg string + }{ + { + name: "successful update", + msgTypeURL: "updateTypeURL", + recipient: "updatedRecipient", + basisPoints: "1000", + additionalFee: sdk.NewInt64Coin("nhash", 3000), + expectError: false, + }, + { + name: "non-existing msgTypeURL", + msgTypeURL: "nonExistingTypeURL", + recipient: "anyRecipient", + basisPoints: "100", + additionalFee: sdk.NewInt64Coin("nhash", 1000), + expectError: true, + errorMsg: "fee for type does not exist", + }, + { + name: "empty msgTypeURL", + msgTypeURL: "", + recipient: "anyRecipient", + basisPoints: "100", + additionalFee: sdk.NewInt64Coin("nhash", 1000), + expectError: true, + errorMsg: "msg type is empty", + }, + } + + for _, tc := range testCases { + s.Run(tc.name, func() { + err := s.app.MsgFeesKeeper.UpdateMsgFee(s.ctx, tc.msgTypeURL, tc.recipient, tc.basisPoints, tc.additionalFee) + if tc.expectError { + s.Require().Error(err, "test was expected to fail") + s.Require().Contains(err.Error(), tc.errorMsg) + } else { + s.Require().NoError(err, "test was expected succeed") + msgFee, err := s.app.MsgFeesKeeper.GetMsgFee(s.ctx, tc.msgTypeURL) + s.Require().NoError(err, "GetMsgFee() should not error") + s.Require().NotNil(msgFee, "GetMsgFee() should have result") + s.Require().Equal(msgFee.MsgTypeUrl, tc.msgTypeURL, "msg type mis-match") + s.Require().Equal(msgFee.AdditionalFee, tc.additionalFee, "additional fee mis-match") + s.Require().Equal(msgFee.Recipient, tc.recipient, "recipient mis-match") + s.Require().Equal(msgFee.RecipientBasisPoints, uint32(1000), "basis points incorrect") + } + }) + } +} + +func (s *TestSuite) TestDetermineBips() { + testCases := []struct { + name string + recipient string + recipientBasisPoints string + expectedBips uint32 + expectError bool + errorMsg string + }{ + { + name: "valid basis points", + recipient: "testRecipient", + recipientBasisPoints: "2500", + expectedBips: 2500, + expectError: false, + }, + { + name: "default basis points when empty", + recipient: "testRecipient", + recipientBasisPoints: "", + expectedBips: types.DefaultMsgFeeBips, + expectError: false, + }, + { + name: "error on invalid numeric value", + recipient: "testRecipient", + recipientBasisPoints: "invalid", + expectError: true, + errorMsg: "invalid syntax", + }, + { + name: "error on excessive basis points", + recipient: "testRecipient", + recipientBasisPoints: "15000", + expectError: true, + errorMsg: "basis points can only be between 0 and 10,000", + }, + } + + for _, tc := range testCases { + s.Run(tc.name, func() { + bips, err := msgfeeskeeper.DetermineBips(tc.recipient, tc.recipientBasisPoints) + if tc.expectError { + s.Require().Error(err) + s.Require().Contains(err.Error(), tc.errorMsg) + } else { + s.Require().NoError(err) + s.Require().Equal(tc.expectedBips, bips) + } + }) + } +} diff --git a/x/msgfees/keeper/msg_server.go b/x/msgfees/keeper/msg_server.go index 1bb88cb17e..54c06614b6 100644 --- a/x/msgfees/keeper/msg_server.go +++ b/x/msgfees/keeper/msg_server.go @@ -50,18 +50,7 @@ func (m msgServer) AddMsgFeeProposal(goCtx context.Context, req *types.MsgAddMsg return nil, errors.Wrapf(govtypes.ErrInvalidSigner, "expected %s got %s", m.GetAuthority(), req.Authority) } - ctx := sdk.UnwrapSDKContext(goCtx) - - prop := types.AddMsgFeeProposal{ - Title: "AddMsgFeeProposal", - Description: "AddMsgFeeProposal", - MsgTypeUrl: req.MsgTypeUrl, - AdditionalFee: req.AdditionalFee, - Recipient: req.Recipient, - RecipientBasisPoints: req.RecipientBasisPoints, - } - - err := HandleAddMsgFeeProposal(ctx, m.Keeper, &prop, m.registry) + err := m.Keeper.AddMsgFee(sdk.UnwrapSDKContext(goCtx), req.MsgTypeUrl, req.Recipient, req.RecipientBasisPoints, req.AdditionalFee) if err != nil { return nil, err } @@ -74,18 +63,7 @@ func (m msgServer) UpdateMsgFeeProposal(goCtx context.Context, req *types.MsgUpd return nil, errors.Wrapf(govtypes.ErrInvalidSigner, "expected %s got %s", m.GetAuthority(), req.Authority) } - ctx := sdk.UnwrapSDKContext(goCtx) - - prop := types.UpdateMsgFeeProposal{ - Title: "UpdateMsgFeeProposal", - Description: "UpdateMsgFeeProposal", - MsgTypeUrl: req.MsgTypeUrl, - AdditionalFee: req.AdditionalFee, - Recipient: req.Recipient, - RecipientBasisPoints: req.RecipientBasisPoints, - } - - err := HandleUpdateMsgFeeProposal(ctx, m.Keeper, &prop, m.registry) + err := m.Keeper.UpdateMsgFee(sdk.UnwrapSDKContext(goCtx), req.MsgTypeUrl, req.Recipient, req.RecipientBasisPoints, req.AdditionalFee) if err != nil { return nil, err } @@ -98,15 +76,7 @@ func (m msgServer) RemoveMsgFeeProposal(goCtx context.Context, req *types.MsgRem return nil, errors.Wrapf(govtypes.ErrInvalidSigner, "expected %s got %s", m.GetAuthority(), req.Authority) } - ctx := sdk.UnwrapSDKContext(goCtx) - - prop := types.RemoveMsgFeeProposal{ - Title: "RemoveMsgFeeProposal", - Description: "RemoveMsgFeeProposal", - MsgTypeUrl: req.MsgTypeUrl, - } - - err := HandleRemoveMsgFeeProposal(ctx, m.Keeper, &prop, m.registry) + err := m.Keeper.RemoveMsgFee(sdk.UnwrapSDKContext(goCtx), req.MsgTypeUrl) if err != nil { return nil, err } @@ -119,18 +89,7 @@ func (m msgServer) UpdateNhashPerUsdMilProposal(goCtx context.Context, req *type return nil, errors.Wrapf(govtypes.ErrInvalidSigner, "expected %s got %s", m.GetAuthority(), req.Authority) } - ctx := sdk.UnwrapSDKContext(goCtx) - - prop := types.UpdateNhashPerUsdMilProposal{ - Title: "UpdateNhashPerUsdMilProposal", - Description: "UpdateNhashPerUsdMilProposal", - NhashPerUsdMil: req.NhashPerUsdMil, - } - - err := HandleUpdateNhashPerUsdMilProposal(ctx, m.Keeper, &prop) - if err != nil { - return nil, err - } + m.Keeper.UpdateNhashPerUsdMilParam(sdk.UnwrapSDKContext(goCtx), req.NhashPerUsdMil) return &types.MsgUpdateNhashPerUsdMilProposalResponse{}, nil } @@ -140,18 +99,7 @@ func (m msgServer) UpdateConversionFeeDenomProposal(goCtx context.Context, req * return nil, errors.Wrapf(govtypes.ErrInvalidSigner, "expected %s got %s", m.GetAuthority(), req.Authority) } - ctx := sdk.UnwrapSDKContext(goCtx) - - prop := types.UpdateConversionFeeDenomProposal{ - Title: "UpdateConversionFeeDenomProposal", - Description: "UpdateConversionFeeDenomProposal", - ConversionFeeDenom: req.ConversionFeeDenom, - } - - err := HandleUpdateConversionFeeDenomProposal(ctx, m.Keeper, &prop) - if err != nil { - return nil, err - } + m.Keeper.UpdateConversionFeeDenomParam(sdk.UnwrapSDKContext(goCtx), req.ConversionFeeDenom) return &types.MsgUpdateConversionFeeDenomProposalResponse{}, nil } diff --git a/x/msgfees/keeper/msg_server_test.go b/x/msgfees/keeper/msg_server_test.go index 065e33dfc9..4ebbdc92fb 100644 --- a/x/msgfees/keeper/msg_server_test.go +++ b/x/msgfees/keeper/msg_server_test.go @@ -176,14 +176,6 @@ func (s *MsgServerTestSuite) TestRemoveMsgFeeProposal() { }, errorMsg: `expected cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn got : expected gov account as only signer for proposal message`, }, - { - name: "msg type is empty", - msg: types.MsgRemoveMsgFeeProposalRequest{ - MsgTypeUrl: "", - Authority: "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn", - }, - errorMsg: `msg type is empty`, - }, { name: "successful", msg: types.MsgRemoveMsgFeeProposalRequest{ @@ -220,14 +212,6 @@ func (s *MsgServerTestSuite) TestUpdateNhashPerUsdMilProposal() { }, errorMsg: `expected cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn got : expected gov account as only signer for proposal message`, }, - { - name: "invalid NhashPerUsdMil amount", - msg: types.MsgUpdateNhashPerUsdMilProposalRequest{ - NhashPerUsdMil: 0, - Authority: "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn", - }, - errorMsg: `nhash per usd mil must be greater than 0`, - }, { name: "successful", msg: types.MsgUpdateNhashPerUsdMilProposalRequest{ @@ -264,13 +248,6 @@ func (s *MsgServerTestSuite) TestUpdateConversionFeeDenomProposal() { }, errorMsg: `expected cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn got : expected gov account as only signer for proposal message`, }, - { - name: "invalid denom", - msg: types.MsgUpdateConversionFeeDenomProposalRequest{ - Authority: "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn", - }, - errorMsg: `invalid denom: `, - }, { name: "successful", msg: types.MsgUpdateConversionFeeDenomProposalRequest{ diff --git a/x/msgfees/keeper/params.go b/x/msgfees/keeper/params.go index e462ade6e0..eba0e785b3 100644 --- a/x/msgfees/keeper/params.go +++ b/x/msgfees/keeper/params.go @@ -9,11 +9,11 @@ import ( // GetParams returns the total set of distribution parameters. func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) { store := ctx.KVStore(k.storeKey) - params = types.DefaultParams() // Initialize with defaults + params = types.DefaultParams() bz := store.Get(types.MsgFeesParamStoreKey) if bz != nil { - k.cdc.MustUnmarshal(bz, ¶ms) // Deserialize parameters + k.cdc.MustUnmarshal(bz, ¶ms) } return params } @@ -21,7 +21,7 @@ func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) { // SetParams sets the account parameters to the store. func (k Keeper) SetParams(ctx sdk.Context, params types.Params) { store := ctx.KVStore(k.storeKey) - bz := k.cdc.MustMarshal(¶ms) // Serialize parameters + bz := k.cdc.MustMarshal(¶ms) store.Set(types.MsgFeesParamStoreKey, bz) } @@ -50,3 +50,17 @@ func (k Keeper) GetConversionFeeDenom(ctx sdk.Context) string { params := k.GetParams(ctx) return params.ConversionFeeDenom } + +// UpdateConversionFeeDenomParam updates the conversion fee denom param +func (k Keeper) UpdateConversionFeeDenomParam(ctx sdk.Context, conversionFeeDenom string) { + params := k.GetParams(ctx) + params.ConversionFeeDenom = conversionFeeDenom + k.SetParams(ctx, params) +} + +// UpdateNhashPerUsdMilParam updates nhash per usd mil param +func (k Keeper) UpdateNhashPerUsdMilParam(ctx sdk.Context, nhashPerUsdMil uint64) { + params := k.GetParams(ctx) + params.NhashPerUsdMil = nhashPerUsdMil + k.SetParams(ctx, params) +} diff --git a/x/msgfees/keeper/proposal_handler.go b/x/msgfees/keeper/proposal_handler.go deleted file mode 100644 index fed81e6582..0000000000 --- a/x/msgfees/keeper/proposal_handler.go +++ /dev/null @@ -1,124 +0,0 @@ -package keeper - -import ( - "fmt" - "strconv" - - codectypes "github.com/cosmos/cosmos-sdk/codec/types" - sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/provenance-io/provenance/x/msgfees/types" -) - -// TODO[1760]: marker: Migrate the legacy gov proposals. - -// HandleAddMsgFeeProposal handles an Add msg fees governance proposal request -func HandleAddMsgFeeProposal(ctx sdk.Context, k Keeper, proposal *types.AddMsgFeeProposal, _ codectypes.InterfaceRegistry) error { - if err := proposal.ValidateBasic(); err != nil { - return err - } - - existing, err := k.GetMsgFee(ctx, proposal.MsgTypeUrl) - if err != nil { - return err - } - if existing != nil { - return types.ErrMsgFeeAlreadyExists - } - bips, err := DetermineBips(proposal.Recipient, proposal.RecipientBasisPoints) - if err != nil { - return err - } - - msgFees := types.NewMsgFee(proposal.MsgTypeUrl, proposal.AdditionalFee, proposal.Recipient, bips) - - err = k.SetMsgFee(ctx, msgFees) - if err != nil { - return types.ErrInvalidFeeProposal - } - - return nil -} - -// DetermineBips converts basis point string to uint32 -func DetermineBips(recipient string, recipientBasisPoints string) (uint32, error) { - var bips uint32 - if len(recipientBasisPoints) > 0 && len(recipient) > 0 { - bips64, err := strconv.ParseUint(recipientBasisPoints, 10, 32) - if err != nil { - return bips, types.ErrInvalidBipsValue.Wrap(err.Error()) - } - bips = uint32(bips64) - if bips > 10_000 { - return 0, types.ErrInvalidBipsValue.Wrap(fmt.Errorf("recipient basis points can only be between 0 and 10,000 : %v", recipientBasisPoints).Error()) - } - } else if len(recipientBasisPoints) == 0 && len(recipient) > 0 { - bips = types.DefaultMsgFeeBips - } - return bips, nil -} - -// HandleUpdateMsgFeeProposal handles an Update of an existing msg fees governance proposal request -func HandleUpdateMsgFeeProposal(ctx sdk.Context, k Keeper, proposal *types.UpdateMsgFeeProposal, _ codectypes.InterfaceRegistry) error { - if err := proposal.ValidateBasic(); err != nil { - return err - } - existing, err := k.GetMsgFee(ctx, proposal.MsgTypeUrl) - if err != nil { - return err - } - if existing == nil { - return types.ErrMsgFeeDoesNotExist - } - bips, err := DetermineBips(proposal.Recipient, proposal.RecipientBasisPoints) - if err != nil { - return err - } - - msgFees := types.NewMsgFee(proposal.MsgTypeUrl, proposal.AdditionalFee, proposal.Recipient, bips) - - err = k.SetMsgFee(ctx, msgFees) - if err != nil { - return types.ErrInvalidFeeProposal - } - - return nil -} - -// HandleRemoveMsgFeeProposal handles a Remove of an existing msg fees governance proposal request -func HandleRemoveMsgFeeProposal(ctx sdk.Context, k Keeper, proposal *types.RemoveMsgFeeProposal, _ codectypes.InterfaceRegistry) error { - if err := proposal.ValidateBasic(); err != nil { - return err - } - existing, err := k.GetMsgFee(ctx, proposal.MsgTypeUrl) - if err != nil { - return err - } - if existing == nil { - return types.ErrMsgFeeDoesNotExist - } - - return k.RemoveMsgFee(ctx, proposal.MsgTypeUrl) -} - -// HandleUpdateNhashPerUsdMilProposal handles update of nhash per usd mil governance proposal request -func HandleUpdateNhashPerUsdMilProposal(ctx sdk.Context, k Keeper, proposal *types.UpdateNhashPerUsdMilProposal) error { - if err := proposal.ValidateBasic(); err != nil { - return err - } - params := k.GetParams(ctx) - params.NhashPerUsdMil = proposal.NhashPerUsdMil - k.SetParams(ctx, params) - return nil -} - -// HandleUpdateConversionFeeDenomProposal handles update of conversion fee denom -func HandleUpdateConversionFeeDenomProposal(ctx sdk.Context, k Keeper, proposal *types.UpdateConversionFeeDenomProposal) error { - if err := proposal.ValidateBasic(); err != nil { - return err - } - params := k.GetParams(ctx) - params.ConversionFeeDenom = proposal.ConversionFeeDenom - k.SetParams(ctx, params) - return nil -} diff --git a/x/msgfees/keeper/proposal_handler_test.go b/x/msgfees/keeper/proposal_handler_test.go deleted file mode 100644 index 770480d3b1..0000000000 --- a/x/msgfees/keeper/proposal_handler_test.go +++ /dev/null @@ -1,219 +0,0 @@ -package keeper_test - -import ( - "errors" - "testing" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "github.com/stretchr/testify/suite" - - "github.com/cometbft/cometbft/crypto/secp256k1" - - sdk "github.com/cosmos/cosmos-sdk/types" - govtypesv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" - - provenance "github.com/provenance-io/provenance/app" - "github.com/provenance-io/provenance/internal/pioconfig" - metadatatypes "github.com/provenance-io/provenance/x/metadata/types" - msgfeeskeeper "github.com/provenance-io/provenance/x/msgfees/keeper" - msgfeestypes "github.com/provenance-io/provenance/x/msgfees/types" -) - -type IntegrationTestSuite struct { - suite.Suite - - app *provenance.App - ctx sdk.Context - k msgfeeskeeper.Keeper - - accountAddr sdk.AccAddress -} - -func (s *IntegrationTestSuite) SetupSuite() { - s.app = provenance.Setup(s.T()) - s.ctx = s.app.BaseApp.NewContext(false) - s.k = msgfeeskeeper.NewKeeper(s.app.AppCodec(), s.app.GetKey(msgfeestypes.ModuleName), "", pioconfig.GetProvenanceConfig().FeeDenom, nil, nil, s.app.InterfaceRegistry()) - s.accountAddr = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) -} - -func (s *IntegrationTestSuite) TearDownSuite() { - s.T().Log("tearing down integration test suite") -} - -func (s *IntegrationTestSuite) TestMsgFeeProposals() { - writeRecordRequest := &metadatatypes.MsgWriteRecordRequest{} - writeScopeRequest := &metadatatypes.MsgWriteScopeRequest{} - - testCases := []struct { - name string - prop govtypesv1beta1.Content - err error - }{ - { - "add msgfees - valid", - msgfeestypes.NewAddMsgFeeProposal("title add", "description", sdk.MsgTypeURL(writeRecordRequest), sdk.NewInt64Coin("hotdog", 10), "", ""), - nil, - }, - { - "add msgfees - invalid - cannot add when the same msgfee exists", - msgfeestypes.NewAddMsgFeeProposal("title add", "description", sdk.MsgTypeURL(writeRecordRequest), sdk.NewInt64Coin("hotdog", 10), "", ""), - msgfeestypes.ErrMsgFeeAlreadyExists, - }, - { - "add msgfees - invalid - validate basic fail", - msgfeestypes.NewAddMsgFeeProposal("title add", "description", sdk.MsgTypeURL(writeScopeRequest), sdk.NewInt64Coin("hotdog", 0), "", ""), - msgfeestypes.ErrInvalidFee, - }, - { - "update msgfees - valid", - msgfeestypes.NewUpdateMsgFeeProposal("title update", "description", sdk.MsgTypeURL(writeRecordRequest), sdk.NewInt64Coin("hotdog", 10), "", ""), - nil, - }, - { - "update msgfees - invalid - cannot update a non-existing msgfee", - msgfeestypes.NewUpdateMsgFeeProposal("title update", "description", sdk.MsgTypeURL(writeScopeRequest), sdk.NewInt64Coin("hotdog", 10), "", ""), - msgfeestypes.ErrMsgFeeDoesNotExist, - }, - { - "update msgfees - invalid - validate basic fail", - msgfeestypes.NewUpdateMsgFeeProposal("title update", "description", sdk.MsgTypeURL(writeRecordRequest), sdk.NewInt64Coin("hotdog", 0), "", ""), - msgfeestypes.ErrInvalidFee, - }, - { - "remove msgfees - valid", - msgfeestypes.NewRemoveMsgFeeProposal("title remove", "description", sdk.MsgTypeURL(writeRecordRequest)), - nil, - }, - { - "remove msgfees - invalid - cannot remove a non-existing msgfee", - msgfeestypes.NewRemoveMsgFeeProposal("title remove", "description", sdk.MsgTypeURL(writeRecordRequest)), - msgfeestypes.ErrMsgFeeDoesNotExist, - }, - { - "remove msgfees - invalid - validate basic fail", - msgfeestypes.NewRemoveMsgFeeProposal("title remove", "description", ""), - msgfeestypes.ErrEmptyMsgType, - }, - { - "update nhash to usd mil - invalid - validate basic fail", - msgfeestypes.NewUpdateNhashPerUsdMilProposal("title update conversion", "", 10), - errors.New("proposal description cannot be blank: invalid proposal content"), - }, - { - "update nhash to usd mil - valid", - msgfeestypes.NewUpdateNhashPerUsdMilProposal("title update conversion", "description", 1), - nil, - }, - { - "update conversion fee denom - invalid - validate basic fail", - msgfeestypes.NewUpdateConversionFeeDenomProposal("title update conversion fee denom", "description", ""), - errors.New("invalid denom: "), - }, - { - "update conversion fee denom - invalid - validate basic fail regex failure on denom", - msgfeestypes.NewUpdateConversionFeeDenomProposal("title update conversion fee denom", "description", "??"), - errors.New("invalid denom: ??"), - }, - { - "update conversion fee denom - valid", - msgfeestypes.NewUpdateConversionFeeDenomProposal("title update conversion", "description", "hotdog"), - nil, - }, - } - - for _, tc := range testCases { - tc := tc - - s.T().Run(tc.name, func(t *testing.T) { - var err error - switch c := tc.prop.(type) { - case *msgfeestypes.AddMsgFeeProposal: - err = msgfeeskeeper.HandleAddMsgFeeProposal(s.ctx, s.k, c, s.app.InterfaceRegistry()) - case *msgfeestypes.UpdateMsgFeeProposal: - err = msgfeeskeeper.HandleUpdateMsgFeeProposal(s.ctx, s.k, c, s.app.InterfaceRegistry()) - case *msgfeestypes.RemoveMsgFeeProposal: - err = msgfeeskeeper.HandleRemoveMsgFeeProposal(s.ctx, s.k, c, s.app.InterfaceRegistry()) - case *msgfeestypes.UpdateNhashPerUsdMilProposal: - err = msgfeeskeeper.HandleUpdateNhashPerUsdMilProposal(s.ctx, s.k, c) - case *msgfeestypes.UpdateConversionFeeDenomProposal: - err = msgfeeskeeper.HandleUpdateConversionFeeDenomProposal(s.ctx, s.k, c) - default: - panic("invalid proposal type") - } - - if tc.err != nil { - require.Error(t, err) - require.Equal(t, tc.err.Error(), err.Error()) - } else { - require.NoError(t, err) - } - }) - } - -} - -func (s *IntegrationTestSuite) TestDetermineBipsProposals() { - testCases := []struct { - name string - recipient string - bips string - expectedBips uint32 - expectedErrMsg string - }{ - { - "valid - has recipient empty bips string, should return default bips", - "recipient", - "", - msgfeestypes.DefaultMsgFeeBips, - "", - }, - { - "valid - has recipient and bips string, should return bips as uint32", - "recipient", - "100", - 100, - "", - }, - { - "valid - has no recipient and a bips string, should return 0 bips", - "", - "10", - 0, - "", - }, - { - "invalid - has recipient and bips string too high, should error", - "recipient", - "10001", - 0, - "recipient basis points can only be between 0 and 10,000 : 10001: invalid bips amount", - }, - { - "invalid - has recipient and bips string not a number, should error", - "recipient", - "error", - 0, - "strconv.ParseUint: parsing \"error\": invalid syntax: invalid bips amount", - }, - } - - for _, tc := range testCases { - s.T().Run(tc.name, func(t *testing.T) { - bips, err := msgfeeskeeper.DetermineBips(tc.recipient, tc.bips) - if len(tc.expectedErrMsg) != 0 { - assert.Equal(t, uint32(0), bips, "should return 0 bips on error") - assert.Equal(t, tc.expectedErrMsg, err.Error()) - } else { - assert.NoError(t, err) - assert.Equal(t, tc.expectedBips, bips, "expected bips should match") - } - }) - } - -} - -func TestIntegrationTestSuite(t *testing.T) { - pioconfig.SetProvenanceConfig("", 0) - suite.Run(t, new(IntegrationTestSuite)) -} diff --git a/x/msgfees/module/module.go b/x/msgfees/module/module.go index 8b680268eb..6408c2f998 100644 --- a/x/msgfees/module/module.go +++ b/x/msgfees/module/module.go @@ -149,12 +149,6 @@ func (AppModule) GenerateGenesisState(simState *module.SimulationState) { simulation.RandomizedGenState(simState) } -// ProposalContents returns all the msgfees content functions used to -// simulate governance proposals. -func (am AppModule) ProposalContents(_ module.SimulationState) []simtypes.WeightedProposalContent { - return simulation.ProposalContents(am.keeper) -} - // RandomizedParams creates randomized msgfees param changes for the simulator. func (AppModule) RandomizedParams(r *rand.Rand) []simtypes.LegacyParamChange { return simulation.ParamChanges(r) diff --git a/x/msgfees/simulation/proposals.go b/x/msgfees/simulation/proposals.go deleted file mode 100644 index 3897cc05b3..0000000000 --- a/x/msgfees/simulation/proposals.go +++ /dev/null @@ -1,86 +0,0 @@ -package simulation - -import ( - "math/rand" - - sdk "github.com/cosmos/cosmos-sdk/types" - simtypes "github.com/cosmos/cosmos-sdk/types/simulation" - "github.com/cosmos/cosmos-sdk/x/simulation" - - simappparams "github.com/provenance-io/provenance/app/params" - attributetypes "github.com/provenance-io/provenance/x/attribute/types" - "github.com/provenance-io/provenance/x/msgfees/keeper" - "github.com/provenance-io/provenance/x/msgfees/types" -) - -const ( - // OpWeightAddMsgFeesProposal add msg fees proposal - //nolint:gosec // not credentials - OpWeightAddMsgFeesProposal = "op_weight_add_msg_based_fees_proposal" - OpWeightRemoveMsgFeesProposal = "op_weight_remove_msg_based_fees_proposal" -) - -// ProposalContents defines the module weighted proposals' contents -func ProposalContents(k keeper.Keeper) []simtypes.WeightedProposalContent { - return []simtypes.WeightedProposalContent{ - simulation.NewWeightedProposalContent( - OpWeightAddMsgFeesProposal, - simappparams.DefaultWeightAddMsgFeeProposalContent, - SimulateCreateAddMsgFeesProposal(k), - ), - simulation.NewWeightedProposalContent( - OpWeightRemoveMsgFeesProposal, - simappparams.DefaultWeightRemoveMsgFeeProposalContent, - SimulateCreateRemoveMsgFeesProposal(k), - ), - } -} - -// SimulateCreateAddMsgFeesProposal generates random additional fee with AddMsgFeesProposal -func SimulateCreateAddMsgFeesProposal(k keeper.Keeper) simtypes.ContentSimulatorFn { - return func(r *rand.Rand, ctx sdk.Context, _ []simtypes.Account) simtypes.Content { - msgFeeExists, err := k.GetMsgFee(ctx, sdk.MsgTypeURL(&attributetypes.MsgAddAttributeRequest{})) - check(err) - if msgFeeExists == nil { - return types.NewAddMsgFeeProposal( - simtypes.RandStringOfLength(r, 10), - simtypes.RandStringOfLength(r, 100), - sdk.MsgTypeURL(&attributetypes.MsgAddAttributeRequest{}), - sdk.NewInt64Coin("hotdog", r.Int63n(100_000_000)), - "", - "", - ) - } - return types.NewUpdateMsgFeeProposal( - simtypes.RandStringOfLength(r, 10), - simtypes.RandStringOfLength(r, 100), - sdk.MsgTypeURL(&attributetypes.MsgAddAttributeRequest{}), - sdk.NewInt64Coin("hotdog", r.Int63n(100_000_000)), - "", - "", - ) - } -} - -// SimulateCreateRemoveMsgFeesProposal generates random removal of additional fee with RemoveMsgFeesProposal -func SimulateCreateRemoveMsgFeesProposal(k keeper.Keeper) simtypes.ContentSimulatorFn { - return func(r *rand.Rand, ctx sdk.Context, _ []simtypes.Account) simtypes.Content { - msgFeeExists, err := k.GetMsgFee(ctx, sdk.MsgTypeURL(&attributetypes.MsgAddAttributeRequest{})) - check(err) - if msgFeeExists != nil { - return types.NewRemoveMsgFeeProposal( - simtypes.RandStringOfLength(r, 10), - simtypes.RandStringOfLength(r, 100), - sdk.MsgTypeURL(&attributetypes.MsgAddAttributeRequest{}), - ) - } - - return nil - } -} - -func check(err error) { - if err != nil { - panic(err) - } -} diff --git a/x/msgfees/simulation/proposals_test.go b/x/msgfees/simulation/proposals_test.go deleted file mode 100644 index 73814e237c..0000000000 --- a/x/msgfees/simulation/proposals_test.go +++ /dev/null @@ -1,46 +0,0 @@ -package simulation_test - -import ( - "math/rand" - "testing" - - "github.com/stretchr/testify/require" - - simtypes "github.com/cosmos/cosmos-sdk/types/simulation" - - simapp "github.com/provenance-io/provenance/app" - simappparams "github.com/provenance-io/provenance/app/params" - "github.com/provenance-io/provenance/internal/pioconfig" - "github.com/provenance-io/provenance/x/msgfees/keeper" - "github.com/provenance-io/provenance/x/msgfees/simulation" - "github.com/provenance-io/provenance/x/msgfees/types" -) - -func TestProposalContents(t *testing.T) { - app := simapp.Setup(t) - ctx := app.BaseApp.NewContext(false) - - // initialize parameters - s := rand.NewSource(1) - r := rand.New(s) - - accounts := simtypes.RandomAccounts(r, 3) - - // execute ProposalContents function - weightedProposalContent := simulation.ProposalContents(keeper.NewKeeper(app.AppCodec(), app.GetKey(types.ModuleName), "", pioconfig.GetProvenanceConfig().FeeDenom, nil, nil, app.InterfaceRegistry())) - require.Len(t, weightedProposalContent, 2) - - w0 := weightedProposalContent[0] - - // tests w0 interface: - require.Equal(t, simulation.OpWeightAddMsgFeesProposal, w0.AppParamsKey()) - require.Equal(t, simappparams.DefaultWeightAddMsgFeeProposalContent, w0.DefaultWeight()) - - content := w0.ContentSimulatorFn()(r, ctx, accounts) - - require.Equal(t, "fyzeOcbWwNbeHVIkPZBSpYuLyYggwexjxusrBqDOTtGTOWeLrQKjLxzIivHSlcxgdXhhuTSkuxKGLwQvuyNhYFmBZHeAerqyNEUz", content.GetDescription()) - require.Equal(t, "GqiQWIXnku", content.GetTitle()) - - require.Equal(t, "msgfees", content.ProposalRoute()) - require.Equal(t, "AddMsgFee", content.ProposalType()) -} diff --git a/x/msgfees/types/msgs.go b/x/msgfees/types/msgs.go index 10032c7904..4794b05b09 100644 --- a/x/msgfees/types/msgs.go +++ b/x/msgfees/types/msgs.go @@ -100,30 +100,37 @@ func (msg *MsgAddMsgFeeProposalRequest) ValidateBasic() error { return err } - if len(msg.Recipient) != 0 { - _, err := sdk.AccAddressFromBech32(msg.Recipient) + if err := ValidateBips(msg.Recipient, msg.RecipientBasisPoints); err != nil { + return err + } + + _, err := sdk.AccAddressFromBech32(msg.Authority) + if err != nil { + return err + } + + return nil +} + +func ValidateBips(recipient, recipientBasisPoints string) error { + if len(recipient) != 0 { + _, err := sdk.AccAddressFromBech32(recipient) if err != nil { return err } } - if len(msg.RecipientBasisPoints) > 0 && len(msg.Recipient) > 0 { - bips, err := strconv.ParseUint(msg.RecipientBasisPoints, 0, 64) + if len(recipientBasisPoints) > 0 && len(recipient) > 0 { + bips, err := strconv.ParseUint(recipientBasisPoints, 0, 64) if err != nil { return err } if bips > 10_000 { - return fmt.Errorf("recipient basis points can only be between 0 and 10,000 : %v", msg.RecipientBasisPoints) + return fmt.Errorf("recipient basis points can only be between 0 and 10,000 : %v", recipientBasisPoints) } - } else if len(msg.RecipientBasisPoints) > 0 && len(msg.Recipient) == 0 { - return fmt.Errorf("") - } - - _, err := sdk.AccAddressFromBech32(msg.Authority) - if err != nil { - return err + } else if len(recipientBasisPoints) > 0 && len(recipient) == 0 { + return fmt.Errorf("recipient basis points provided without a recipient") } - return nil } @@ -146,21 +153,10 @@ func (msg *MsgUpdateMsgFeeProposalRequest) ValidateBasic() error { return ErrInvalidFee } - if len(msg.Recipient) != 0 { - _, err := sdk.AccAddressFromBech32(msg.Recipient) - if err != nil { - return err - } - } - if len(msg.RecipientBasisPoints) > 0 { - bips, err := strconv.ParseUint(msg.RecipientBasisPoints, 0, 64) - if err != nil { - return err - } - if bips > 10_000 { - return fmt.Errorf("recipient basis points can only be between 0 and 10,000 : %v", msg.RecipientBasisPoints) - } + if err := ValidateBips(msg.Recipient, msg.RecipientBasisPoints); err != nil { + return err } + _, err := sdk.AccAddressFromBech32(msg.Authority) if err != nil { return err diff --git a/x/msgfees/types/msgs_test.go b/x/msgfees/types/msgs_test.go index 809af8ad61..61dbec84f5 100644 --- a/x/msgfees/types/msgs_test.go +++ b/x/msgfees/types/msgs_test.go @@ -189,18 +189,7 @@ func TestMsgAddMsgFeeProposalRequestValidateBasic(t *testing.T) { errorMsg: "invalid fee amount", }, { - name: "Invalid proposal recipient address", - msg: MsgAddMsgFeeProposalRequest{ - MsgTypeUrl: "msgType", - AdditionalFee: sdk.NewInt64Coin("hotdog", 10), - Recipient: "invalid", - RecipientBasisPoints: "", - Authority: authority, - }, - errorMsg: "decoding bech32 failed: invalid bech32 string length 7", - }, - { - name: "Invalid proposal invalid basis points for address", + name: "Invalid proposal invalid basis points for address failed ValidateBips", msg: MsgAddMsgFeeProposalRequest{ MsgTypeUrl: "msgType", AdditionalFee: sdk.NewInt64Coin("hotdog", 10), @@ -313,7 +302,7 @@ func TestMsgUpdateMsgFeeProposalRequestValidateBasic(t *testing.T) { errorMsg: "invalid fee amount", }, { - name: "Invalid proposal recipient address", + name: "Invalid proposal recipient address fail ValidateBips", msg: MsgUpdateMsgFeeProposalRequest{ MsgTypeUrl: msgType, AdditionalFee: sdk.NewInt64Coin("hotdog", 10), @@ -323,17 +312,6 @@ func TestMsgUpdateMsgFeeProposalRequestValidateBasic(t *testing.T) { }, errorMsg: "decoding bech32 failed: invalid bech32 string length 7", }, - { - name: "Invalid proposal invalid basis points for address", - msg: MsgUpdateMsgFeeProposalRequest{ - MsgTypeUrl: msgType, - AdditionalFee: sdk.NewInt64Coin("hotdog", 10), - Recipient: "cosmos1depk54cuajgkzea6zpgkq36tnjwdzv4afc3d27", - RecipientBasisPoints: "10001", - Authority: authority, - }, - errorMsg: "recipient basis points can only be between 0 and 10,000 : 10001", - }, { name: "Valid proposal without recipient", msg: MsgUpdateMsgFeeProposalRequest{ @@ -541,3 +519,61 @@ func TestUpdateConversionFeeDenomProposalRequestValidateBasic(t *testing.T) { } } + +func TestValidateBips(t *testing.T) { + cases := []struct { + name string + recipient string + recipientBasisPoints string + expectedError string + }{ + { + name: "valid recipient and basis points", + recipient: "cosmos1sh49f6ze3vn7cdl2amh2gnc70z5mten3y08xck", + recipientBasisPoints: "5000", + expectedError: "", + }, + { + name: "valid recipient without basis points", + recipient: "cosmos1sh49f6ze3vn7cdl2amh2gnc70z5mten3y08xck", + recipientBasisPoints: "", + expectedError: "", + }, + { + name: "invalid recipient with basis points", + recipient: "invalid", + recipientBasisPoints: "1000", + expectedError: "decoding bech32 failed: invalid bech32 string length 7", + }, + { + name: "valid recipient with basis points too high", + recipient: "cosmos1sh49f6ze3vn7cdl2amh2gnc70z5mten3y08xck", + recipientBasisPoints: "10001", + expectedError: "recipient basis points can only be between 0 and 10,000 : 10001", + }, + { + name: "valid recipient with invalid basis points format", + recipient: "cosmos1sh49f6ze3vn7cdl2amh2gnc70z5mten3y08xck", + recipientBasisPoints: "invalid_bips", + expectedError: `strconv.ParseUint: parsing "invalid_bips": invalid syntax`, + }, + { + name: "basis points without recipient", + recipient: "", + recipientBasisPoints: "1000", + expectedError: "recipient basis points provided without a recipient", + }, + } + + for _, tc := range cases { + tc := tc + t.Run(tc.name, func(t *testing.T) { + err := ValidateBips(tc.recipient, tc.recipientBasisPoints) + if tc.expectedError != "" { + require.EqualError(t, err, tc.expectedError) + } else { + require.NoError(t, err) + } + }) + } +} diff --git a/x/msgfees/types/proposal.go b/x/msgfees/types/proposal.go index f159db5a81..47bb7c474b 100644 --- a/x/msgfees/types/proposal.go +++ b/x/msgfees/types/proposal.go @@ -2,10 +2,7 @@ package types import ( "errors" - "fmt" - "strconv" - sdk "github.com/cosmos/cosmos-sdk/types" govtypesv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" ) @@ -30,85 +27,10 @@ var ( _ govtypesv1beta1.Content = &UpdateConversionFeeDenomProposal{} ) -func init() { - govtypesv1beta1.RegisterProposalType(ProposalTypeAddMsgFee) - govtypesv1beta1.RegisterProposalType(ProposalTypeUpdateMsgFee) - govtypesv1beta1.RegisterProposalType(ProposalTypeRemoveMsgFee) - govtypesv1beta1.RegisterProposalType(ProposalTypeUpdateUsdConversionRate) - govtypesv1beta1.RegisterProposalType(ProposalTypeUpdateConversionFeeDenom) -} - -func NewAddMsgFeeProposal( - title string, - description string, - msg string, - additionalFee sdk.Coin, - recipient string, - recipientBasisPoints string, -) *AddMsgFeeProposal { - return &AddMsgFeeProposal{ - Title: title, - Description: description, - MsgTypeUrl: msg, - AdditionalFee: additionalFee, - Recipient: recipient, - RecipientBasisPoints: recipientBasisPoints, - } -} - func (p AddMsgFeeProposal) ProposalRoute() string { return RouterKey } func (p AddMsgFeeProposal) ProposalType() string { return ProposalTypeAddMsgFee } func (p AddMsgFeeProposal) ValidateBasic() error { - if len(p.MsgTypeUrl) == 0 { - return ErrEmptyMsgType - } - - if !p.AdditionalFee.IsPositive() { - return ErrInvalidFee - } - - if err := p.AdditionalFee.Validate(); err != nil { - return err - } - - if len(p.Recipient) != 0 { - _, err := sdk.AccAddressFromBech32(p.Recipient) - if err != nil { - return err - } - } - - if len(p.RecipientBasisPoints) > 0 && len(p.Recipient) > 0 { - bips, err := strconv.ParseUint(p.RecipientBasisPoints, 0, 64) - if err != nil { - return err - } - if bips > 10_000 { - return fmt.Errorf("recipient basis points can only be between 0 and 10,000 : %v", p.RecipientBasisPoints) - } - } else if len(p.RecipientBasisPoints) > 0 && len(p.Recipient) == 0 { - return fmt.Errorf("") - } - - return govtypesv1beta1.ValidateAbstract(&p) -} - -func NewUpdateMsgFeeProposal( - title string, - description string, - msg string, - additionalFee sdk.Coin, - recipient string, - recipientBasisPoints string, -) *UpdateMsgFeeProposal { - return &UpdateMsgFeeProposal{ - Title: title, - Description: description, - MsgTypeUrl: msg, - AdditionalFee: additionalFee, - Recipient: recipient, - RecipientBasisPoints: recipientBasisPoints, - } + return errors.New("proposal msg no longer supported") } func (p UpdateMsgFeeProposal) ProposalRoute() string { return RouterKey } @@ -116,43 +38,7 @@ func (p UpdateMsgFeeProposal) ProposalRoute() string { return RouterKey } func (p UpdateMsgFeeProposal) ProposalType() string { return ProposalTypeUpdateMsgFee } func (p UpdateMsgFeeProposal) ValidateBasic() error { - if len(p.MsgTypeUrl) == 0 { - return ErrEmptyMsgType - } - - if !p.AdditionalFee.IsPositive() { - return ErrInvalidFee - } - - if len(p.Recipient) != 0 { - _, err := sdk.AccAddressFromBech32(p.Recipient) - if err != nil { - return err - } - } - if len(p.RecipientBasisPoints) > 0 { - bips, err := strconv.ParseUint(p.RecipientBasisPoints, 0, 64) - if err != nil { - return err - } - if bips > 10_000 { - return fmt.Errorf("recipient basis points can only be between 0 and 10,000 : %v", p.RecipientBasisPoints) - } - } - - return govtypesv1beta1.ValidateAbstract(&p) -} - -func NewRemoveMsgFeeProposal( - title string, - description string, - msgTypeURL string, -) *RemoveMsgFeeProposal { - return &RemoveMsgFeeProposal{ - Title: title, - Description: description, - MsgTypeUrl: msgTypeURL, - } + return errors.New("proposal msg no longer supported") } func (p RemoveMsgFeeProposal) ProposalRoute() string { return RouterKey } @@ -160,22 +46,7 @@ func (p RemoveMsgFeeProposal) ProposalRoute() string { return RouterKey } func (p RemoveMsgFeeProposal) ProposalType() string { return ProposalTypeRemoveMsgFee } func (p RemoveMsgFeeProposal) ValidateBasic() error { - if len(p.MsgTypeUrl) == 0 { - return ErrEmptyMsgType - } - return govtypesv1beta1.ValidateAbstract(&p) -} - -func NewUpdateNhashPerUsdMilProposal( - title string, - description string, - nhashPerUsdMil uint64, -) *UpdateNhashPerUsdMilProposal { - return &UpdateNhashPerUsdMilProposal{ - Title: title, - Description: description, - NhashPerUsdMil: nhashPerUsdMil, - } + return errors.New("proposal msg no longer supported") } func (p UpdateNhashPerUsdMilProposal) ProposalRoute() string { return RouterKey } @@ -185,22 +56,7 @@ func (p UpdateNhashPerUsdMilProposal) ProposalType() string { } func (p UpdateNhashPerUsdMilProposal) ValidateBasic() error { - if p.NhashPerUsdMil < 1 { - return errors.New("nhash per usd mil must be greater than 0") - } - return govtypesv1beta1.ValidateAbstract(&p) -} - -func NewUpdateConversionFeeDenomProposal( - title string, - description string, - converstionFeeDenom string, -) *UpdateConversionFeeDenomProposal { - return &UpdateConversionFeeDenomProposal{ - Title: title, - Description: description, - ConversionFeeDenom: converstionFeeDenom, - } + return errors.New("proposal msg no longer supported") } func (p UpdateConversionFeeDenomProposal) ProposalRoute() string { return RouterKey } @@ -210,8 +66,5 @@ func (p UpdateConversionFeeDenomProposal) ProposalType() string { } func (p UpdateConversionFeeDenomProposal) ValidateBasic() error { - if err := sdk.ValidateDenom(p.ConversionFeeDenom); err != nil { - return err - } - return govtypesv1beta1.ValidateAbstract(&p) + return errors.New("proposal msg no longer supported") } diff --git a/x/msgfees/types/proposals.pb.go b/x/msgfees/types/proposals.pb.go index a80dc34d26..17d3060f4e 100644 --- a/x/msgfees/types/proposals.pb.go +++ b/x/msgfees/types/proposals.pb.go @@ -25,6 +25,11 @@ var _ = math.Inf const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // AddMsgFeeProposal defines a governance proposal to add additional msg based fee +// Deprecated: This message is no longer usable. It is only still included for +// backwards compatibility (e.g. looking up old governance proposals). +// It is replaced by providing a MsgAddMsgFeeProposalRequest in a governance proposal. +// +// Deprecated: Do not use. type AddMsgFeeProposal struct { // propsal title Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"` @@ -116,6 +121,11 @@ func (m *AddMsgFeeProposal) GetRecipientBasisPoints() string { } // UpdateMsgFeeProposal defines a governance proposal to update a current msg based fee +// Deprecated: This message is no longer usable. It is only still included for +// backwards compatibility (e.g. looking up old governance proposals). +// It is replaced by providing a MsgUpdateMsgFeeProposalRequest in a governance proposal. +// +// Deprecated: Do not use. type UpdateMsgFeeProposal struct { // propsal title Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"` @@ -207,6 +217,11 @@ func (m *UpdateMsgFeeProposal) GetRecipientBasisPoints() string { } // RemoveMsgFeeProposal defines a governance proposal to delete a current msg based fee +// Deprecated: This message is no longer usable. It is only still included for +// backwards compatibility (e.g. looking up old governance proposals). +// It is replaced by providing a MsgRemoveMsgFeeProposalRequest in a governance proposal. +// +// Deprecated: Do not use. type RemoveMsgFeeProposal struct { // propsal title Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"` @@ -271,6 +286,11 @@ func (m *RemoveMsgFeeProposal) GetMsgTypeUrl() string { } // UpdateNhashPerUsdMilProposal defines a governance proposal to update the nhash per usd mil param +// Deprecated: This message is no longer usable. It is only still included for +// backwards compatibility (e.g. looking up old governance proposals). +// It is replaced by providing a MsgUpdateNhashPerUsdMilProposalRequest in a governance proposal. +// +// Deprecated: Do not use. type UpdateNhashPerUsdMilProposal struct { Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"` Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"` @@ -333,6 +353,11 @@ func (m *UpdateNhashPerUsdMilProposal) GetNhashPerUsdMil() uint64 { } // UpdateConversionFeeDenomProposal defines a governance proposal to update the msg fee conversion denom +// Deprecated: This message is no longer usable. It is only still included for +// backwards compatibility (e.g. looking up old governance proposals). +// It is replaced by providing a MsgUpdateConversionFeeDenomProposalRequest in a governance proposal. +// +// Deprecated: Do not use. type UpdateConversionFeeDenomProposal struct { Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"` Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"` @@ -407,207 +432,39 @@ func init() { } var fileDescriptor_a2e168825d6c34a4 = []byte{ - // 478 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xec, 0x54, 0x4d, 0x6f, 0xd3, 0x40, - 0x10, 0xcd, 0x86, 0xb4, 0x52, 0xb6, 0x50, 0xa9, 0x96, 0x41, 0xa6, 0xaa, 0x5c, 0xab, 0x12, 0x52, - 0x39, 0x60, 0x13, 0xca, 0x89, 0x1b, 0x29, 0xca, 0xad, 0x28, 0xb2, 0xc8, 0x85, 0x8b, 0xe5, 0x8f, - 0xa9, 0xb3, 0x92, 0xbd, 0xb3, 0xda, 0xd9, 0x58, 0xf4, 0x17, 0x70, 0x04, 0xf1, 0x0b, 0xf8, 0x39, - 0x3d, 0xf6, 0xc8, 0x09, 0xa1, 0xe4, 0xc2, 0xcf, 0x40, 0xb6, 0x83, 0x53, 0xd4, 0x63, 0x24, 0x4e, - 0xbd, 0x79, 0xf6, 0x3d, 0xcf, 0x7b, 0x9a, 0x19, 0x3d, 0xfe, 0x4c, 0x69, 0xac, 0x40, 0xc6, 0x32, - 0x85, 0xa0, 0xa4, 0xfc, 0x12, 0x80, 0x82, 0x6a, 0x14, 0x28, 0x8d, 0x0a, 0x29, 0x2e, 0xc8, 0x57, - 0x1a, 0x0d, 0x5a, 0x8f, 0x37, 0x34, 0x7f, 0x4d, 0xf3, 0xab, 0xd1, 0xa1, 0x9d, 0x63, 0x8e, 0x0d, - 0x23, 0xa8, 0xbf, 0x5a, 0xf2, 0xa1, 0x9b, 0x22, 0x95, 0x48, 0x41, 0x12, 0x13, 0x04, 0xd5, 0x28, - 0x01, 0x13, 0x8f, 0x82, 0x14, 0x85, 0x6c, 0xf1, 0x93, 0x2f, 0x7d, 0x7e, 0xf0, 0x36, 0xcb, 0x2e, - 0x28, 0x9f, 0x00, 0x4c, 0xd7, 0x4a, 0x96, 0xcd, 0x77, 0x8c, 0x30, 0x05, 0x38, 0xcc, 0x63, 0xa7, - 0xc3, 0xb0, 0x2d, 0x2c, 0x8f, 0xef, 0x65, 0x40, 0xa9, 0x16, 0xca, 0x08, 0x94, 0x4e, 0xbf, 0xc1, - 0x6e, 0x3f, 0x59, 0x1e, 0x7f, 0x58, 0x52, 0x1e, 0x99, 0x2b, 0x05, 0xd1, 0x42, 0x17, 0xce, 0x83, - 0x86, 0xc2, 0x4b, 0xca, 0x3f, 0x5c, 0x29, 0x98, 0xe9, 0xc2, 0x9a, 0xf0, 0xfd, 0x38, 0xcb, 0x44, - 0xcd, 0x8e, 0x8b, 0xe8, 0x12, 0xc0, 0x19, 0x78, 0xec, 0x74, 0xef, 0xd5, 0x53, 0xbf, 0x35, 0xea, - 0xd7, 0x46, 0xfd, 0xb5, 0x51, 0xff, 0x1c, 0x85, 0x1c, 0x0f, 0xae, 0x7f, 0x1e, 0xf7, 0xc2, 0x47, - 0x9b, 0xdf, 0x26, 0x00, 0xd6, 0x11, 0x1f, 0x6a, 0x48, 0x85, 0x12, 0x20, 0x8d, 0xb3, 0xd3, 0xc8, - 0x6c, 0x1e, 0xac, 0xd7, 0xfc, 0x49, 0x57, 0x44, 0x49, 0x4c, 0x82, 0x22, 0x85, 0x42, 0x1a, 0x72, - 0x76, 0x1b, 0xaa, 0xdd, 0xa1, 0xe3, 0x1a, 0x9c, 0x36, 0xd8, 0x9b, 0xc1, 0xef, 0xef, 0xc7, 0xec, - 0xe4, 0x5b, 0x9f, 0xdb, 0x33, 0x95, 0xc5, 0x06, 0xee, 0x87, 0xd2, 0x0d, 0xa5, 0xe2, 0x76, 0x08, - 0x25, 0x56, 0xff, 0x6d, 0x26, 0x6b, 0xdd, 0xcf, 0x8c, 0x1f, 0xb5, 0xcb, 0x78, 0x3f, 0x8f, 0x69, - 0x3e, 0x05, 0x3d, 0xa3, 0xec, 0x42, 0x14, 0x5b, 0x1b, 0x78, 0xce, 0x0f, 0x64, 0xdd, 0x31, 0x52, - 0xa0, 0xa3, 0x05, 0x65, 0x51, 0x29, 0x5a, 0x17, 0x83, 0x70, 0x5f, 0xfe, 0x23, 0xf5, 0xf7, 0x2c, - 0x18, 0xf7, 0x5a, 0x27, 0xe7, 0x28, 0x2b, 0xd0, 0x24, 0x50, 0x4e, 0x00, 0xde, 0x81, 0xc4, 0x72, - 0x6b, 0x37, 0x2f, 0xb9, 0x9d, 0x76, 0x5d, 0xeb, 0x03, 0x88, 0xb2, 0xba, 0x6f, 0x73, 0x06, 0xc3, - 0xd0, 0x4a, 0xef, 0x28, 0xb6, 0xa6, 0xc6, 0xe2, 0x7a, 0xe9, 0xb2, 0x9b, 0xa5, 0xcb, 0x7e, 0x2d, - 0x5d, 0xf6, 0x75, 0xe5, 0xf6, 0x6e, 0x56, 0x6e, 0xef, 0xc7, 0xca, 0xed, 0x71, 0x47, 0x34, 0x09, - 0x70, 0x37, 0x27, 0xa6, 0xec, 0xe3, 0x59, 0x2e, 0xcc, 0x7c, 0x91, 0xf8, 0x29, 0x96, 0xc1, 0x86, - 0xf3, 0x42, 0xe0, 0xad, 0x2a, 0xf8, 0xd4, 0x45, 0x50, 0xbd, 0x24, 0x4a, 0x76, 0x9b, 0xbc, 0x38, - 0xfb, 0x13, 0x00, 0x00, 0xff, 0xff, 0x25, 0xa7, 0x25, 0xea, 0xa5, 0x04, 0x00, 0x00, -} - -func (this *AddMsgFeeProposal) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*AddMsgFeeProposal) - if !ok { - that2, ok := that.(AddMsgFeeProposal) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if this.Title != that1.Title { - return false - } - if this.Description != that1.Description { - return false - } - if this.MsgTypeUrl != that1.MsgTypeUrl { - return false - } - if !this.AdditionalFee.Equal(&that1.AdditionalFee) { - return false - } - if this.Recipient != that1.Recipient { - return false - } - if this.RecipientBasisPoints != that1.RecipientBasisPoints { - return false - } - return true -} -func (this *UpdateMsgFeeProposal) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*UpdateMsgFeeProposal) - if !ok { - that2, ok := that.(UpdateMsgFeeProposal) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if this.Title != that1.Title { - return false - } - if this.Description != that1.Description { - return false - } - if this.MsgTypeUrl != that1.MsgTypeUrl { - return false - } - if !this.AdditionalFee.Equal(&that1.AdditionalFee) { - return false - } - if this.Recipient != that1.Recipient { - return false - } - if this.RecipientBasisPoints != that1.RecipientBasisPoints { - return false - } - return true + // 471 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xec, 0x54, 0x4d, 0x6b, 0xdb, 0x40, + 0x10, 0xf5, 0xba, 0x4e, 0xc0, 0x9b, 0x36, 0x10, 0xa1, 0x16, 0x35, 0x04, 0x55, 0x04, 0x0a, 0xe9, + 0xa1, 0x52, 0xdd, 0xf4, 0xd4, 0x5b, 0x9d, 0xe2, 0x5b, 0x8a, 0x11, 0xf5, 0xa5, 0x17, 0xa1, 0x8f, + 0x89, 0xbc, 0x20, 0xed, 0x2c, 0x3b, 0x6b, 0xd1, 0xfc, 0x80, 0x1e, 0x0b, 0xf9, 0x59, 0x39, 0xe6, + 0xd8, 0x53, 0x29, 0xf6, 0x1f, 0x29, 0x5a, 0x19, 0x3b, 0x25, 0x47, 0x43, 0x4f, 0xb9, 0x69, 0xe6, + 0x3d, 0xcd, 0x7b, 0xcc, 0xcc, 0x0e, 0x7f, 0xad, 0x34, 0x36, 0x20, 0x53, 0x99, 0x43, 0x54, 0x53, + 0x79, 0x05, 0x40, 0x51, 0x33, 0x8a, 0x94, 0x46, 0x85, 0x94, 0x56, 0x14, 0x2a, 0x8d, 0x06, 0x9d, + 0xe7, 0x5b, 0x5a, 0xb8, 0xa6, 0x85, 0xcd, 0xe8, 0xd8, 0x2d, 0xb1, 0x44, 0xcb, 0x88, 0xda, 0xaf, + 0x8e, 0x7c, 0xec, 0xe7, 0x48, 0x35, 0x52, 0x94, 0xa5, 0x04, 0x51, 0x33, 0xca, 0xc0, 0xa4, 0xa3, + 0x28, 0x47, 0x21, 0x3b, 0xfc, 0xf4, 0x67, 0x9f, 0x1f, 0x7d, 0x2a, 0x8a, 0x4b, 0x2a, 0x27, 0x00, + 0xd3, 0xb5, 0x92, 0xe3, 0xf2, 0x3d, 0x23, 0x4c, 0x05, 0x1e, 0x0b, 0xd8, 0xd9, 0x30, 0xee, 0x02, + 0x27, 0xe0, 0x07, 0x05, 0x50, 0xae, 0x85, 0x32, 0x02, 0xa5, 0xd7, 0xb7, 0xd8, 0xfd, 0x94, 0x13, + 0xf0, 0xa7, 0x35, 0x95, 0x89, 0xb9, 0x56, 0x90, 0x2c, 0x74, 0xe5, 0x3d, 0xb1, 0x14, 0x5e, 0x53, + 0xf9, 0xf5, 0x5a, 0xc1, 0x4c, 0x57, 0xce, 0x84, 0x1f, 0xa6, 0x45, 0x21, 0x5a, 0x76, 0x5a, 0x25, + 0x57, 0x00, 0xde, 0x20, 0x60, 0x67, 0x07, 0xef, 0x5f, 0x86, 0x9d, 0xd1, 0xb0, 0x35, 0x1a, 0xae, + 0x8d, 0x86, 0x17, 0x28, 0xe4, 0x78, 0x70, 0xfb, 0xfb, 0x55, 0x2f, 0x7e, 0xb6, 0xfd, 0x6d, 0x02, + 0xe0, 0x9c, 0xf0, 0xa1, 0x86, 0x5c, 0x28, 0x01, 0xd2, 0x78, 0x7b, 0x56, 0x66, 0x9b, 0x70, 0x3e, + 0xf0, 0x17, 0x9b, 0x20, 0xc9, 0x52, 0x12, 0x94, 0x28, 0x14, 0xd2, 0x90, 0xb7, 0x6f, 0xa9, 0xee, + 0x06, 0x1d, 0xb7, 0xe0, 0xd4, 0x62, 0x1f, 0xfb, 0x1e, 0x3b, 0xbd, 0xe9, 0x73, 0x77, 0xa6, 0x8a, + 0xd4, 0xc0, 0x63, 0x4b, 0xd6, 0x2d, 0x31, 0xdc, 0x8d, 0xa1, 0xc6, 0xe6, 0xbf, 0x75, 0xc4, 0xaa, + 0xfe, 0x60, 0xfc, 0xa4, 0x1b, 0xc4, 0x97, 0x79, 0x4a, 0xf3, 0x29, 0xe8, 0x19, 0x15, 0x97, 0xa2, + 0xda, 0x59, 0xfe, 0x0d, 0x3f, 0x92, 0x6d, 0xc5, 0x44, 0x81, 0x4e, 0x16, 0x54, 0x24, 0xb5, 0xe8, + 0x3c, 0x0c, 0xe2, 0x43, 0xf9, 0x8f, 0x54, 0xb7, 0x10, 0x8c, 0x07, 0x9d, 0x8f, 0x0b, 0x94, 0x0d, + 0x68, 0x12, 0x28, 0x27, 0x00, 0x9f, 0x41, 0x62, 0xbd, 0xb3, 0x97, 0x77, 0xdc, 0xcd, 0x37, 0x55, + 0xdb, 0xd1, 0x27, 0x45, 0x5b, 0xd7, 0x2e, 0xc0, 0x30, 0x76, 0xf2, 0x07, 0x8a, 0xad, 0xa5, 0xb1, + 0xb8, 0x5d, 0xfa, 0xec, 0x6e, 0xe9, 0xb3, 0x3f, 0x4b, 0x9f, 0xdd, 0xac, 0xfc, 0xde, 0xdd, 0xca, + 0xef, 0xfd, 0x5a, 0xf9, 0x3d, 0xee, 0x09, 0xfb, 0xee, 0x1f, 0x5e, 0x87, 0x29, 0xfb, 0x76, 0x5e, + 0x0a, 0x33, 0x5f, 0x64, 0x61, 0x8e, 0x75, 0xb4, 0xe5, 0xbc, 0x15, 0x78, 0x2f, 0x8a, 0xbe, 0x6f, + 0x0e, 0x4f, 0x3b, 0x1e, 0xca, 0xf6, 0xed, 0x95, 0x38, 0xff, 0x1b, 0x00, 0x00, 0xff, 0xff, 0x73, + 0x6b, 0x32, 0xbc, 0x9b, 0x04, 0x00, 0x00, } -func (this *RemoveMsgFeeProposal) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - that1, ok := that.(*RemoveMsgFeeProposal) - if !ok { - that2, ok := that.(RemoveMsgFeeProposal) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if this.Title != that1.Title { - return false - } - if this.Description != that1.Description { - return false - } - if this.MsgTypeUrl != that1.MsgTypeUrl { - return false - } - return true -} -func (this *UpdateNhashPerUsdMilProposal) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*UpdateNhashPerUsdMilProposal) - if !ok { - that2, ok := that.(UpdateNhashPerUsdMilProposal) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if this.Title != that1.Title { - return false - } - if this.Description != that1.Description { - return false - } - if this.NhashPerUsdMil != that1.NhashPerUsdMil { - return false - } - return true -} -func (this *UpdateConversionFeeDenomProposal) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*UpdateConversionFeeDenomProposal) - if !ok { - that2, ok := that.(UpdateConversionFeeDenomProposal) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if this.Title != that1.Title { - return false - } - if this.Description != that1.Description { - return false - } - if this.ConversionFeeDenom != that1.ConversionFeeDenom { - return false - } - return true -} func (m *AddMsgFeeProposal) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) diff --git a/x/msgfees/types/proposals_test.go b/x/msgfees/types/proposals_test.go deleted file mode 100644 index 7fcb8940b6..0000000000 --- a/x/msgfees/types/proposals_test.go +++ /dev/null @@ -1,210 +0,0 @@ -package types - -import ( - "testing" - - sdk "github.com/cosmos/cosmos-sdk/types" - - metadatatypes "github.com/provenance-io/provenance/x/metadata/types" - - "github.com/stretchr/testify/suite" -) - -type MsgFeesProposalTestSuite struct { - suite.Suite -} - -func (s *MsgFeesProposalTestSuite) SetupSuite() { -} - -func TestMsgFeesProposalTestSuite(t *testing.T) { - suite.Run(t, new(MsgFeesProposalTestSuite)) -} - -func (s *MsgFeesProposalTestSuite) TearDownSuite() { - s.T().Log("tearing down integration test suite") -} - -func (s *MsgFeesProposalTestSuite) TestAddMsgFeeProposalType() { - msgType := sdk.MsgTypeURL(&metadatatypes.MsgWriteRecordRequest{}) - - tests := []struct { - name string - proposal *AddMsgFeeProposal - expectedErr string - }{ - { - "Empty type error", - NewAddMsgFeeProposal("title", "description", "", sdk.NewInt64Coin("hotdog", 10), "", ""), - ErrEmptyMsgType.Error(), - }, - { - "Invalid fee amounts", - NewAddMsgFeeProposal("title", "description", msgType, sdk.NewInt64Coin("hotdog", 0), "", ""), - ErrInvalidFee.Error(), - }, - { - "Invalid proposal details", - NewAddMsgFeeProposal("title", "", msgType, sdk.NewInt64Coin("hotdog", 10), "", ""), - "proposal description cannot be blank: invalid proposal content", - }, - { - "Invalid proposal recipient address", - NewAddMsgFeeProposal("title", "", msgType, sdk.NewInt64Coin("hotdog", 10), "invalid", ""), - "decoding bech32 failed: invalid bech32 string length 7", - }, - { - "Invalid proposal invalid basis points for address", - NewAddMsgFeeProposal("title", "description", msgType, sdk.NewInt64Coin("hotdog", 10), "cosmos1depk54cuajgkzea6zpgkq36tnjwdzv4afc3d27", "10001"), - "recipient basis points can only be between 0 and 10,000 : 10001", - }, - { - "Valid proposal without recipient", - NewAddMsgFeeProposal("title", "description", msgType, sdk.NewInt64Coin("hotdog", 10), "", ""), - "", - }, - { - "Valid proposal with recipient", - NewAddMsgFeeProposal("title", "description", msgType, sdk.NewInt64Coin("hotdog", 10), "cosmos1depk54cuajgkzea6zpgkq36tnjwdzv4afc3d27", "10000"), - "", - }, - { - "Valid proposal with recipient without defined bips", - NewAddMsgFeeProposal("title", "description", msgType, sdk.NewInt64Coin("hotdog", 10), "cosmos1depk54cuajgkzea6zpgkq36tnjwdzv4afc3d27", ""), - "", - }, - { - "Valid proposal with recipient with defined bips", - NewAddMsgFeeProposal("title", "description", msgType, sdk.NewInt64Coin("hotdog", 10), "cosmos1depk54cuajgkzea6zpgkq36tnjwdzv4afc3d27", "10"), - "", - }, - } - - for _, tc := range tests { - s.T().Run(tc.name, func(t *testing.T) { - err := tc.proposal.ValidateBasic() - if len(tc.expectedErr) != 0 { - s.Require().NotNil(err, "Error should not be nil for test %s", tc.name) - s.Assert().Equal(tc.expectedErr, err.Error(), "Error messages do not match for test %s", tc.name) - } else { - s.Require().Nil(err, "Error should be nil for test %s", tc.name) - } - }) - } -} - -func (s *MsgFeesProposalTestSuite) TestUpdateMsgFeeProposalType() { - msgType := sdk.MsgTypeURL(&metadatatypes.MsgWriteRecordRequest{}) - tests := []struct { - name string - proposal *UpdateMsgFeeProposal - expectedErr string - }{ - { - "Empty type error", - NewUpdateMsgFeeProposal("title", "description", "", sdk.NewInt64Coin("hotdog", 10), "", ""), - ErrEmptyMsgType.Error(), - }, - { - "Invalid fee amounts", - NewUpdateMsgFeeProposal("title", "description", msgType, sdk.NewInt64Coin("hotdog", 0), "", ""), - ErrInvalidFee.Error(), - }, - { - "Invalid proposal details", - NewUpdateMsgFeeProposal("title", "", msgType, sdk.NewInt64Coin("hotdog", 10), "", ""), - "proposal description cannot be blank: invalid proposal content", - }, - { - "Invalid proposal recipient address", - NewUpdateMsgFeeProposal("title", "", msgType, sdk.NewInt64Coin("hotdog", 10), "invalid", "50"), - "decoding bech32 failed: invalid bech32 string length 7", - }, - { - "Invalid proposal invalid basis points for address", - NewUpdateMsgFeeProposal("title", "description", msgType, sdk.NewInt64Coin("hotdog", 10), "cosmos1depk54cuajgkzea6zpgkq36tnjwdzv4afc3d27", "10001"), - "recipient basis points can only be between 0 and 10,000 : 10001", - }, - { - "Valid proposal without recipient", - NewUpdateMsgFeeProposal("title", "description", msgType, sdk.NewInt64Coin("hotdog", 10), "", ""), - "", - }, - { - "Valid proposal with recipient without defined bips", - NewUpdateMsgFeeProposal("title", "description", msgType, sdk.NewInt64Coin("hotdog", 10), "cosmos1depk54cuajgkzea6zpgkq36tnjwdzv4afc3d27", ""), - "", - }, - { - "Valid proposal with recipient with defined bips", - NewUpdateMsgFeeProposal("title", "description", msgType, sdk.NewInt64Coin("hotdog", 10), "cosmos1depk54cuajgkzea6zpgkq36tnjwdzv4afc3d27", "10"), - "", - }, - } - - for _, tc := range tests { - s.T().Run(tc.name, func(t *testing.T) { - err := tc.proposal.ValidateBasic() - if len(tc.expectedErr) != 0 { - s.Require().NotNil(err, "Error should not be nil for test %s", tc.name) - s.Assert().Equal(tc.expectedErr, err.Error(), "Error messages do not match for test %s", tc.name) - } else { - s.Require().Nil(err, "Error should be nil for test %s", tc.name) - } - }) - } - -} - -func (s *MsgFeesProposalTestSuite) TestRemoveMsgFeeProposalType() { - msgType := sdk.MsgTypeURL(&metadatatypes.MsgWriteRecordRequest{}) - - m := NewRemoveMsgFeeProposal("title", "description", msgType) - err := m.ValidateBasic() - s.Assert().NoError(err) - - m.MsgTypeUrl = "" - err = m.ValidateBasic() - s.Assert().ErrorIs(err, ErrEmptyMsgType) - - m.MsgTypeUrl = msgType - m.Description = "" - err = m.ValidateBasic() - s.Assert().Equal("proposal description cannot be blank: invalid proposal content", err.Error()) -} - -func (s *MsgFeesProposalTestSuite) TestUpdateUsdConversionRateProposalValidateBasic() { - tests := []struct { - name string - proposal *UpdateNhashPerUsdMilProposal - expectedErr string - }{ - { - "Empty type error", - NewUpdateNhashPerUsdMilProposal("title", "description", 0), - "nhash per usd mil must be greater than 0", - }, - { - "Invalid proposal details", - NewUpdateNhashPerUsdMilProposal("title", "", 70), - "proposal description cannot be blank: invalid proposal content", - }, - { - "Valid proposal", - NewUpdateNhashPerUsdMilProposal("title", "description", 70), - "", - }, - } - - for _, tc := range tests { - s.T().Run(tc.name, func(t *testing.T) { - err := tc.proposal.ValidateBasic() - if len(tc.expectedErr) == 0 { - s.Assert().NoError(err) - } else { - s.Assert().Equal(tc.expectedErr, err.Error()) - } - }) - } - -}