From 38cdcf6381481a037e0e2e8c030c884ad3b1a662 Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Fri, 12 Apr 2024 12:23:57 -0600 Subject: [PATCH 01/22] [1760]: Use ReadPageRequestWithPageKeyDecoded everywhere we used to. --- x/attribute/client/cli/query.go | 8 ++++---- x/exchange/client/cli/query_setup.go | 10 +++++----- x/hold/client/cli/query.go | 2 +- x/marker/client/cli/query.go | 4 ++-- x/metadata/client/cli/query.go | 20 ++++++++++---------- x/msgfees/client/cli/query.go | 2 +- x/name/client/cli/query.go | 2 +- x/trigger/client/cli/query.go | 2 +- 8 files changed, 25 insertions(+), 25 deletions(-) diff --git a/x/attribute/client/cli/query.go b/x/attribute/client/cli/query.go index 8b9c5b5577..236a156fcb 100644 --- a/x/attribute/client/cli/query.go +++ b/x/attribute/client/cli/query.go @@ -84,7 +84,7 @@ func GetAccountAttributeCmd() *cobra.Command { } queryClient := types.NewQueryClient(clientCtx) - pageReq, err := client.ReadPageRequest(cmd.Flags()) // TODO[1760]: cli: ReadPageRequestWithPageKeyDecoded + pageReq, err := client.ReadPageRequestWithPageKeyDecoded(cmd.Flags()) if err != nil { return err } @@ -130,7 +130,7 @@ func ListAccountAttributesCmd() *cobra.Command { } queryClient := types.NewQueryClient(clientCtx) - pageReq, err := client.ReadPageRequest(cmd.Flags()) // TODO[1760]: cli: ReadPageRequestWithPageKeyDecoded + pageReq, err := client.ReadPageRequestWithPageKeyDecoded(cmd.Flags()) if err != nil { return err } @@ -174,7 +174,7 @@ func ScanAccountAttributesCmd() *cobra.Command { } queryClient := types.NewQueryClient(clientCtx) - pageReq, err := client.ReadPageRequest(cmd.Flags()) // TODO[1760]: cli: ReadPageRequestWithPageKeyDecoded + pageReq, err := client.ReadPageRequestWithPageKeyDecoded(cmd.Flags()) if err != nil { return err } @@ -219,7 +219,7 @@ func GetAttributeAccountsCmd() *cobra.Command { } queryClient := types.NewQueryClient(clientCtx) - pageReq, err := client.ReadPageRequest(cmd.Flags()) // TODO[1760]: cli: ReadPageRequestWithPageKeyDecoded + pageReq, err := client.ReadPageRequestWithPageKeyDecoded(cmd.Flags()) if err != nil { return err } diff --git a/x/exchange/client/cli/query_setup.go b/x/exchange/client/cli/query_setup.go index 886b5bf02f..a16e5ec4d1 100644 --- a/x/exchange/client/cli/query_setup.go +++ b/x/exchange/client/cli/query_setup.go @@ -185,7 +185,7 @@ func MakeQueryGetMarketOrders(_ client.Context, flagSet *pflag.FlagSet, args []s req.MarketId, errs[0] = ReadFlagMarketOrArg(flagSet, args) req.OrderType, errs[1] = ReadFlagsAsksBidsOpt(flagSet) req.AfterOrderId, errs[2] = flagSet.GetUint64(FlagAfter) - req.Pagination, errs[3] = client.ReadPageRequest(flagSet) // TODO[1760]: cli: ReadPageRequestWithPageKeyDecoded + req.Pagination, errs[3] = client.ReadPageRequestWithPageKeyDecoded(flagSet) return req, errors.Join(errs...) } @@ -223,7 +223,7 @@ func MakeQueryGetOwnerOrders(_ client.Context, flagSet *pflag.FlagSet, args []st req.Owner, errs[0] = ReadStringFlagOrArg(flagSet, args, FlagOwner, "owner") req.OrderType, errs[1] = ReadFlagsAsksBidsOpt(flagSet) req.AfterOrderId, errs[2] = flagSet.GetUint64(FlagAfter) - req.Pagination, errs[3] = client.ReadPageRequest(flagSet) // TODO[1760]: cli: ReadPageRequestWithPageKeyDecoded + req.Pagination, errs[3] = client.ReadPageRequestWithPageKeyDecoded(flagSet) return req, errors.Join(errs...) } @@ -261,7 +261,7 @@ func MakeQueryGetAssetOrders(_ client.Context, flagSet *pflag.FlagSet, args []st req.Asset, errs[0] = ReadStringFlagOrArg(flagSet, args, FlagDenom, "asset") req.OrderType, errs[1] = ReadFlagsAsksBidsOpt(flagSet) req.AfterOrderId, errs[2] = flagSet.GetUint64(FlagAfter) - req.Pagination, errs[3] = client.ReadPageRequest(flagSet) // TODO[1760]: cli: ReadPageRequestWithPageKeyDecoded + req.Pagination, errs[3] = client.ReadPageRequestWithPageKeyDecoded(flagSet) return req, errors.Join(errs...) } @@ -284,7 +284,7 @@ func MakeQueryGetAllOrders(_ client.Context, flagSet *pflag.FlagSet, _ []string) req := &exchange.QueryGetAllOrdersRequest{} var err error - req.Pagination, err = client.ReadPageRequest(flagSet) // TODO[1760]: cli: ReadPageRequestWithPageKeyDecoded + req.Pagination, err = client.ReadPageRequestWithPageKeyDecoded(flagSet) return req, err } @@ -439,7 +439,7 @@ func MakeQueryGetAllMarkets(_ client.Context, flagSet *pflag.FlagSet, _ []string req := &exchange.QueryGetAllMarketsRequest{} var err error - req.Pagination, err = client.ReadPageRequest(flagSet) // TODO[1760]: cli: ReadPageRequestWithPageKeyDecoded + req.Pagination, err = client.ReadPageRequestWithPageKeyDecoded(flagSet) return req, err } diff --git a/x/hold/client/cli/query.go b/x/hold/client/cli/query.go index 49deb2e113..ee83b97c28 100644 --- a/x/hold/client/cli/query.go +++ b/x/hold/client/cli/query.go @@ -87,7 +87,7 @@ func QueryCmdGetAllHolds() *cobra.Command { } req := hold.GetAllHoldsRequest{} - req.Pagination, err = client.ReadPageRequest(cmd.Flags()) // TODO[1760]: cli: ReadPageRequestWithPageKeyDecoded + req.Pagination, err = client.ReadPageRequestWithPageKeyDecoded(cmd.Flags()) if err != nil { return err } diff --git a/x/marker/client/cli/query.go b/x/marker/client/cli/query.go index 84d0527656..6baa36df59 100644 --- a/x/marker/client/cli/query.go +++ b/x/marker/client/cli/query.go @@ -81,7 +81,7 @@ func AllMarkersCmd() *cobra.Command { } queryClient := types.NewQueryClient(clientCtx) - pageReq, err := client.ReadPageRequest(cmd.Flags()) // TODO[1760]: cli: ReadPageRequestWithPageKeyDecoded + pageReq, err := client.ReadPageRequestWithPageKeyDecoded(cmd.Flags()) if err != nil { return err } @@ -128,7 +128,7 @@ func AllHoldersCmd() *cobra.Command { } id := strings.ToLower(strings.TrimSpace(args[0])) queryClient := types.NewQueryClient(clientCtx) - pageReq, err := client.ReadPageRequest(cmd.Flags()) // TODO[1760]: cli: ReadPageRequestWithPageKeyDecoded + pageReq, err := client.ReadPageRequestWithPageKeyDecoded(cmd.Flags()) if err != nil { return err } diff --git a/x/metadata/client/cli/query.go b/x/metadata/client/cli/query.go index 774c5f7ba3..5816eac6ba 100644 --- a/x/metadata/client/cli/query.go +++ b/x/metadata/client/cli/query.go @@ -670,7 +670,7 @@ func outputScopesAll(cmd *cobra.Command) error { if err != nil { return err } - pageReq, e := client.ReadPageRequest(cmd.Flags()) // TODO[1760]: cli: ReadPageRequestWithPageKeyDecoded + pageReq, e := client.ReadPageRequestWithPageKeyDecoded(cmd.Flags()) if e != nil { return e } @@ -726,7 +726,7 @@ func outputSessionsAll(cmd *cobra.Command) error { if err != nil { return err } - pageReq, e := client.ReadPageRequest(cmd.Flags()) // TODO[1760]: cli: ReadPageRequestWithPageKeyDecoded + pageReq, e := client.ReadPageRequestWithPageKeyDecoded(cmd.Flags()) if e != nil { return e } @@ -779,7 +779,7 @@ func outputRecordsAll(cmd *cobra.Command) error { if err != nil { return err } - pageReq, e := client.ReadPageRequest(cmd.Flags()) // TODO[1760]: cli: ReadPageRequestWithPageKeyDecoded + pageReq, e := client.ReadPageRequestWithPageKeyDecoded(cmd.Flags()) if e != nil { return e } @@ -805,7 +805,7 @@ func outputOwnership(cmd *cobra.Command, address string) error { if err != nil { return err } - pageReq, e := client.ReadPageRequest(cmd.Flags()) // TODO[1760]: cli: ReadPageRequestWithPageKeyDecoded + pageReq, e := client.ReadPageRequestWithPageKeyDecoded(cmd.Flags()) if e != nil { return e } @@ -827,7 +827,7 @@ func outputValueOwnership(cmd *cobra.Command, address string) error { if err != nil { return err } - pageReq, e := client.ReadPageRequest(cmd.Flags()) // TODO[1760]: cli: ReadPageRequestWithPageKeyDecoded + pageReq, e := client.ReadPageRequestWithPageKeyDecoded(cmd.Flags()) if e != nil { return e } @@ -873,7 +873,7 @@ func outputScopeSpecsAll(cmd *cobra.Command) error { if err != nil { return err } - pageReq, e := client.ReadPageRequest(cmd.Flags()) // TODO[1760]: cli: ReadPageRequestWithPageKeyDecoded + pageReq, e := client.ReadPageRequestWithPageKeyDecoded(cmd.Flags()) if e != nil { return e } @@ -922,7 +922,7 @@ func outputContractSpecsAll(cmd *cobra.Command) error { if err != nil { return err } - pageReq, e := client.ReadPageRequest(cmd.Flags()) // TODO[1760]: cli: ReadPageRequestWithPageKeyDecoded + pageReq, e := client.ReadPageRequestWithPageKeyDecoded(cmd.Flags()) if e != nil { return e } @@ -993,7 +993,7 @@ func outputRecordSpecsAll(cmd *cobra.Command) error { if err != nil { return err } - pageReq, e := client.ReadPageRequest(cmd.Flags()) // TODO[1760]: cli: ReadPageRequestWithPageKeyDecoded + pageReq, e := client.ReadPageRequestWithPageKeyDecoded(cmd.Flags()) if e != nil { return e } @@ -1055,7 +1055,7 @@ func outputOSLocatorsByURI(cmd *cobra.Command, uri string) error { if err != nil { return err } - pageReq, e := client.ReadPageRequest(cmd.Flags()) // TODO[1760]: cli: ReadPageRequestWithPageKeyDecoded + pageReq, e := client.ReadPageRequestWithPageKeyDecoded(cmd.Flags()) if e != nil { return e } @@ -1095,7 +1095,7 @@ func outputOSLocatorsAll(cmd *cobra.Command) error { if err != nil { return err } - pageReq, e := client.ReadPageRequest(cmd.Flags()) // TODO[1760]: cli: ReadPageRequestWithPageKeyDecoded + pageReq, e := client.ReadPageRequestWithPageKeyDecoded(cmd.Flags()) if e != nil { return e } diff --git a/x/msgfees/client/cli/query.go b/x/msgfees/client/cli/query.go index 109570c330..7a4f2c7486 100644 --- a/x/msgfees/client/cli/query.go +++ b/x/msgfees/client/cli/query.go @@ -42,7 +42,7 @@ func AllMsgFeesCmd() *cobra.Command { } queryClient := types.NewQueryClient(clientCtx) - pageReq, err := client.ReadPageRequest(cmd.Flags()) // TODO[1760]: cli: ReadPageRequestWithPageKeyDecoded + pageReq, err := client.ReadPageRequestWithPageKeyDecoded(cmd.Flags()) if err != nil { return err } diff --git a/x/name/client/cli/query.go b/x/name/client/cli/query.go index 41374a1823..c4a6a537ba 100644 --- a/x/name/client/cli/query.go +++ b/x/name/client/cli/query.go @@ -111,7 +111,7 @@ $ %[1]s query name lookup pb1skjwj5whet0lpe65qaq4rpq03hjxlwd9nf39lk --page=2 --l } queryClient := types.NewQueryClient(clientCtx) - pageReq, err := client.ReadPageRequest(cmd.Flags()) // TODO[1760]: cli: ReadPageRequestWithPageKeyDecoded + pageReq, err := client.ReadPageRequestWithPageKeyDecoded(cmd.Flags()) if err != nil { return err } diff --git a/x/trigger/client/cli/query.go b/x/trigger/client/cli/query.go index b0dd7e2bf4..aba2fcb487 100644 --- a/x/trigger/client/cli/query.go +++ b/x/trigger/client/cli/query.go @@ -57,7 +57,7 @@ func GetTriggersCmd() *cobra.Command { } var request types.QueryTriggersRequest - request.Pagination, err = client.ReadPageRequest(cmd.Flags()) // TODO[1760]: cli: ReadPageRequestWithPageKeyDecoded + request.Pagination, err = client.ReadPageRequestWithPageKeyDecoded(cmd.Flags()) if err != nil { return err } From 508a3286ea6dee0b44c9b756ea966b45a6a15a42 Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Fri, 12 Apr 2024 12:40:54 -0600 Subject: [PATCH 02/22] [1760]: Clean up uses of cosmossdk.io/simapp --- app/app_test.go | 3 +-- app/sim_test.go | 13 ++++++------- go.mod | 2 -- go.sum | 2 -- 4 files changed, 7 insertions(+), 13 deletions(-) diff --git a/app/app_test.go b/app/app_test.go index bd3769afdf..62abf5c52f 100644 --- a/app/app_test.go +++ b/app/app_test.go @@ -11,7 +11,6 @@ import ( "cosmossdk.io/log" sdkmath "cosmossdk.io/math" - sdksim "cosmossdk.io/simapp" dbm "github.com/cosmos/cosmos-db" sdktypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -159,7 +158,7 @@ func TestExportAppStateAndValidators(t *testing.T) { exported, err := app.ExportAppStateAndValidators(false, nil, nil) require.NoError(t, err, "ExportAppStateAndValidators") - var genState sdksim.GenesisState + var genState map[string]json.RawMessage err = json.Unmarshal(exported.AppState, &genState) require.NoError(t, err, "unmarshalling exported app state") diff --git a/app/sim_test.go b/app/sim_test.go index 16101e613f..755dec69ef 100644 --- a/app/sim_test.go +++ b/app/sim_test.go @@ -19,7 +19,6 @@ import ( cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" "cosmossdk.io/log" - sdksim "cosmossdk.io/simapp" "cosmossdk.io/store" storetypes "cosmossdk.io/store/types" evidencetypes "cosmossdk.io/x/evidence/types" @@ -71,7 +70,7 @@ type StoreKeysPrefixes struct { Prefixes [][]byte } -// ProvAppStateFn wraps the sdksim.AppStateFn and sets the ICA GenesisState if isn't yet defined in the appState. +// ProvAppStateFn wraps the simtypes.AppStateFn and sets the ICA GenesisState if isn't yet defined in the appState. func ProvAppStateFn(cdc codec.JSONCodec, simManager *module.SimulationManager, genesisState map[string]json.RawMessage) simtypes.AppStateFn { return func(r *rand.Rand, accs []simtypes.Account, config simtypes.Config) (json.RawMessage, []simtypes.Account, string, time.Time) { appState, simAccs, chainID, genesisTimestamp := simtestutil.AppStateFn(cdc, simManager, genesisState)(r, accs, config) @@ -201,7 +200,7 @@ func TestSimple(t *testing.T) { // /usr/local/go/bin/go test -benchmem -run=^$ github.com/provenance-io/provenance -bench ^BenchmarkFullAppSimulation$ -Commit=true -cpuprofile cpu.out func TestAppImportExport(t *testing.T) { // uncomment to run in ide without flags. - //sdksim.FlagEnabledValue = true + //simcli.FlagEnabledValue = true config, db, dir, logger, skip, err := setupSimulation("leveldb-app-sim", "Simulation") if skip { @@ -257,7 +256,7 @@ func TestAppImportExport(t *testing.T) { newApp := New(log.NewNopLogger(), newDB, nil, true, map[int64]bool{}, home, simcli.FlagPeriodValue, simtestutil.EmptyAppOptions{}, fauxMerkleModeOpt) - var genesisState sdksim.GenesisState + var genesisState map[string]json.RawMessage err = json.Unmarshal(exported.AppState, &genesisState) require.NoError(t, err) @@ -402,9 +401,9 @@ func TestAppSimulationAfterImport(t *testing.T) { // and doesn't depend on the application. func TestAppStateDeterminism(t *testing.T) { // uncomment these to run in ide without flags. - //sdksim.FlagEnabledValue = true - //sdksim.FlagBlockSizeValue = 100 - //sdksim.FlagNumBlocksValue = 50 + //simcli.FlagEnabledValue = true + //simcli.FlagBlockSizeValue = 100 + //simcli.FlagNumBlocksValue = 50 if !simcli.FlagEnabledValue { t.Skip("skipping application simulation") diff --git a/go.mod b/go.mod index f4acc75093..4726687726 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,6 @@ require ( cosmossdk.io/errors v1.0.1 cosmossdk.io/log v1.3.1 cosmossdk.io/math v1.3.0 - cosmossdk.io/simapp v0.0.0-20231107193120-9814f684b9dd // TODO[1760]: Copy needed stuff out of simapp and remove this require. cosmossdk.io/store v1.0.2 cosmossdk.io/x/evidence v0.1.0 cosmossdk.io/x/feegrant v0.1.0 @@ -58,7 +57,6 @@ require ( cosmossdk.io/client/v2 v2.0.0-beta.1 // indirect cosmossdk.io/depinject v1.0.0-alpha.4 // indirect cosmossdk.io/x/circuit v0.1.0 // indirect - cosmossdk.io/x/nft v0.1.0 // indirect filippo.io/edwards25519 v1.0.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect github.com/99designs/keyring v1.2.2 // indirect diff --git a/go.sum b/go.sum index 8d8557c281..f531abb3f0 100644 --- a/go.sum +++ b/go.sum @@ -200,8 +200,6 @@ cosmossdk.io/log v1.3.1 h1:UZx8nWIkfbbNEWusZqzAx3ZGvu54TZacWib3EzUYmGI= cosmossdk.io/log v1.3.1/go.mod h1:2/dIomt8mKdk6vl3OWJcPk2be3pGOS8OQaLUM/3/tCM= cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE= cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k= -cosmossdk.io/simapp v0.0.0-20231107193120-9814f684b9dd h1:KwV+LjYFc4N+KwUrPtCfKW6m+zIdCI0kz1Zr+RrDW/Y= -cosmossdk.io/simapp v0.0.0-20231107193120-9814f684b9dd/go.mod h1:qnOJ7OPtF1kNzces9lnB3vpeMhQu4uQE9i+h0+vb+RA= cosmossdk.io/store v1.0.2 h1:lSg5BTvJBHUDwswNNyeh4K/CbqiHER73VU4nDNb8uk0= cosmossdk.io/store v1.0.2/go.mod h1:EFtENTqVTuWwitGW1VwaBct+yDagk7oG/axBMPH+FXs= cosmossdk.io/x/circuit v0.1.0 h1:IAej8aRYeuOMritczqTlljbUVHq1E85CpBqaCTwYgXs= From d6f7db6cfd8371063ebb44bb5279aee3a5f3538b Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Fri, 12 Apr 2024 12:59:25 -0600 Subject: [PATCH 03/22] [1760]: Handle some of the count-authz TODOs, but I forgot to update the grant command, so there's a couple things that are still needed in the SDK. --- x/metadata/keeper/signers_test.go | 141 +++++++++++------------- x/metadata/keeper/signers_utils_test.go | 89 +++++++-------- 2 files changed, 103 insertions(+), 127 deletions(-) diff --git a/x/metadata/keeper/signers_test.go b/x/metadata/keeper/signers_test.go index abebcdce2c..859027f97e 100644 --- a/x/metadata/keeper/signers_test.go +++ b/x/metadata/keeper/signers_test.go @@ -756,36 +756,32 @@ func (s *AuthzTestSuite) TestValidateAllRequiredPartiesSigned_CountAuthorization }.Real(), } - // TODO[1760]: count-authz: Uncomment the rest of this test once we have that back in the SDK. - _, _, _, _ = reqParties, availableParties, reqRoles, expDetails - /* - msg := &types.MsgDeleteScopeRequest{Signers: []string{accStr(signer)}} - msgTypeURL := types.TypeURLMsgDeleteScopeRequest + msg := &types.MsgDeleteScopeRequest{Signers: []string{accStr(signer)}} + msgTypeURL := types.TypeURLMsgDeleteScopeRequest - ctx := s.FreshCtx() + ctx := s.FreshCtx() - // first grant: signer can sign for party1 one time. - auth1 := authz.NewCountAuthorization(msgTypeURL, 1) - err := s.app.AuthzKeeper.SaveGrant(ctx, acc(signer), acc(party1), auth1, nil) - s.Require().NoError(err, "SaveGrant signer can sign for party1: 1 use") + // first grant: signer can sign for party1 one time. + auth1 := authz.NewCountAuthorization(msgTypeURL, 1) + err := s.app.AuthzKeeper.SaveGrant(ctx, acc(signer), acc(party1), auth1, nil) + s.Require().NoError(err, "SaveGrant signer can sign for party1: 1 use") - // second grant: signer can sign for party2 two times. - auth2 := authz.NewCountAuthorization(msgTypeURL, 2) - err = s.app.AuthzKeeper.SaveGrant(ctx, acc(signer), acc(party2), auth2, nil) - s.Require().NoError(err, "SaveGrant signer can sign for party2: 2 uses") + // second grant: signer can sign for party2 two times. + auth2 := authz.NewCountAuthorization(msgTypeURL, 2) + err = s.app.AuthzKeeper.SaveGrant(ctx, acc(signer), acc(party2), auth2, nil) + s.Require().NoError(err, "SaveGrant signer can sign for party2: 2 uses") - details, err := s.app.MetadataKeeper.ValidateAllRequiredPartiesSigned(ctx, reqParties, availableParties, reqRoles, msg) - s.Require().NoError(err, "ValidateSignersWithParties error") - s.Assert().Equal(expDetails, details, "ValidateSignersWithParties party details") + details, err := s.app.MetadataKeeper.ValidateAllRequiredPartiesSigned(ctx, reqParties, availableParties, reqRoles, msg) + s.Require().NoError(err, "ValidateSignersWithParties error") + s.Assert().Equal(expDetails, details, "ValidateSignersWithParties party details") - auth1Final, _ := s.app.AuthzKeeper.GetAuthorization(ctx, acc(signer), acc(party1), msgTypeURL) - s.Assert().Nil(auth1Final, "GetAuthorization after only allowed use") + auth1Final, _ := s.app.AuthzKeeper.GetAuthorization(ctx, acc(signer), acc(party1), msgTypeURL) + s.Assert().Nil(auth1Final, "GetAuthorization after only allowed use") - auth2Final, _ := s.app.AuthzKeeper.GetAuthorization(ctx, acc(signer), acc(party2), msgTypeURL) - s.Assert().NotNil(auth2Final, "GetAuthorization after first of two uses") - actual := auth2Final.(*authz.CountAuthorization).AllowedAuthorizations - s.Assert().Equal(1, int(actual), "number of uses left after first of two uses") - */ + auth2Final, _ := s.app.AuthzKeeper.GetAuthorization(ctx, acc(signer), acc(party2), msgTypeURL) + s.Assert().NotNil(auth2Final, "GetAuthorization after first of two uses") + actual := auth2Final.(*authz.CountAuthorization).AllowedAuthorizations + s.Assert().Equal(1, int(actual), "number of uses left after first of two uses") } func TestAssociateSigners(t *testing.T) { @@ -6357,12 +6353,9 @@ func (s *AuthzTestSuite) TestValidateAllRequiredSigned_CountAuthorizations() { ctx := s.FreshCtx() msgTypeURL := sdk.MsgTypeURL(tc.msg) if tc.grantee != nil && tc.granter != nil { - // TODO[1760]: count-authz: Uncomment the rest of this test once we have that back in the SDK. - /* - a := authz.NewCountAuthorization(msgTypeURL, tc.count) - err := s.app.AuthzKeeper.SaveGrant(ctx, tc.grantee, tc.granter, a, nil) - s.Require().NoError(err, "SaveGrant") - */ + a := authz.NewCountAuthorization(msgTypeURL, tc.count) + err := s.app.AuthzKeeper.SaveGrant(ctx, tc.grantee, tc.granter, a, nil) + s.Require().NoError(err, "SaveGrant") } _, err := s.app.MetadataKeeper.ValidateAllRequiredSigned(ctx, tc.owners, tc.msg) @@ -6375,59 +6368,53 @@ func (s *AuthzTestSuite) TestValidateAllRequiredSigned_CountAuthorizations() { // authorization is deleted after one use s.Assert().Nil(auth, "GetAuthorization after only allowed use") } else { - // TODO[1760]: count-authz: Uncomment the rest of this test once we have that back in the SDK. - /* - actual := auth.(*authz.CountAuthorization).AllowedAuthorizations - s.Assert().Equal(tc.count-1, actual, "uses left on authorization") - */ + actual := auth.(*authz.CountAuthorization).AllowedAuthorizations + s.Assert().Equal(tc.count-1, actual, "uses left on authorization") } } }) } s.Run("ensure authorizations are updated", func() { - // TODO[1760]: count-authz: Uncomment the rest of this test once we have that back in the SDK. - /* - ctx := s.FreshCtx() - // Two owners (1 & 2), and one signer (3), - // Two authz count authorization - // - count grants: - // granter: 1, grantee: 3, count: 1 - // granter: 2, grantee: 3, count: 2 - // Require signatures from 1 and 2, but sign with 3. - // Ensure both authorizations are applied and updated. - - msg := &types.MsgDeleteScopeRequest{} - msgTypeUrl := sdk.MsgTypeURL(msg) - - // first grant: 3 can sign for 1 one time. - a := authz.NewCountAuthorization(msgTypeUrl, 1) - err := s.app.AuthzKeeper.SaveGrant(ctx, s.user3Addr, s.user1Addr, a, nil) - s.Assert().NoError(err, "SaveGrant 1 -> 3, 1 use") - - // second grant: 3 can sign for 2 two times. - a = authz.NewCountAuthorization(msgTypeUrl, 2) - err = s.app.AuthzKeeper.SaveGrant(ctx, s.user3Addr, s.user2Addr, a, nil) - s.Assert().NoError(err, "SaveGrant 2 -> 3, 2 uses") - - // two owners (1 & 2), and one signer (3) - owners := []string{s.user1, s.user2} - msg.Signers = []string{s.user3} - - // Validate signatures. This should also use both count authorizations. - _, err = s.app.MetadataKeeper.ValidateAllRequiredSigned(ctx, owners, msg) - s.Assert().NoError(err, "ValidateSignersWithoutParties") - - // first grant should be deleted because it used its last use. - auth, _ := s.app.AuthzKeeper.GetAuthorization(ctx, s.user3Addr, s.user1Addr, msgTypeUrl) - s.Assert().Nil(auth, "GetAuthorization 1 -> 3 after only allowed use") - - // second grant should still exist, but only have one use left. - auth, _ = s.app.AuthzKeeper.GetAuthorization(ctx, s.user3Addr, s.user2Addr, msgTypeUrl) - s.Assert().NotNil(auth, "GetAuthorization 2 -> 3 after one use") - actual := auth.(*authz.CountAuthorization).AllowedAuthorizations - s.Assert().Equal(1, int(actual), "number of uses left on 2 -> 3 authorization") - */ + ctx := s.FreshCtx() + // Two owners (1 & 2), and one signer (3), + // Two authz count authorization + // - count grants: + // granter: 1, grantee: 3, count: 1 + // granter: 2, grantee: 3, count: 2 + // Require signatures from 1 and 2, but sign with 3. + // Ensure both authorizations are applied and updated. + + msg := &types.MsgDeleteScopeRequest{} + msgTypeUrl := sdk.MsgTypeURL(msg) + + // first grant: 3 can sign for 1 one time. + a := authz.NewCountAuthorization(msgTypeUrl, 1) + err := s.app.AuthzKeeper.SaveGrant(ctx, s.user3Addr, s.user1Addr, a, nil) + s.Assert().NoError(err, "SaveGrant 1 -> 3, 1 use") + + // second grant: 3 can sign for 2 two times. + a = authz.NewCountAuthorization(msgTypeUrl, 2) + err = s.app.AuthzKeeper.SaveGrant(ctx, s.user3Addr, s.user2Addr, a, nil) + s.Assert().NoError(err, "SaveGrant 2 -> 3, 2 uses") + + // two owners (1 & 2), and one signer (3) + owners := []string{s.user1, s.user2} + msg.Signers = []string{s.user3} + + // Validate signatures. This should also use both count authorizations. + _, err = s.app.MetadataKeeper.ValidateAllRequiredSigned(ctx, owners, msg) + s.Assert().NoError(err, "ValidateSignersWithoutParties") + + // first grant should be deleted because it used its last use. + auth, _ := s.app.AuthzKeeper.GetAuthorization(ctx, s.user3Addr, s.user1Addr, msgTypeUrl) + s.Assert().Nil(auth, "GetAuthorization 1 -> 3 after only allowed use") + + // second grant should still exist, but only have one use left. + auth, _ = s.app.AuthzKeeper.GetAuthorization(ctx, s.user3Addr, s.user2Addr, msgTypeUrl) + s.Assert().NotNil(auth, "GetAuthorization 2 -> 3 after one use") + actual := auth.(*authz.CountAuthorization).AllowedAuthorizations + s.Assert().Equal(1, int(actual), "number of uses left on 2 -> 3 authorization") }) } diff --git a/x/metadata/keeper/signers_utils_test.go b/x/metadata/keeper/signers_utils_test.go index 84d9411d35..6fd6f461b8 100644 --- a/x/metadata/keeper/signers_utils_test.go +++ b/x/metadata/keeper/signers_utils_test.go @@ -1960,7 +1960,7 @@ func TestNewAuthzCache(t *testing.T) { func TestAuthzCache_Clear(t *testing.T) { c := keeper.NewAuthzCache() - // c.AcceptableMap()["key1"] = &authz.CountAuthorization{} // TODO[1760]: count-authz + c.AcceptableMap()["key1"] = &authz.CountAuthorization{} c.AcceptableMap()["key2"] = &authz.GenericAuthorization{} c.IsWasmMap()["key3"] = true c.IsWasmMap()["key4"] = false @@ -1972,21 +1972,18 @@ func TestAuthzCache_Clear(t *testing.T) { } func TestAuthzCache_SetAcceptable(t *testing.T) { - // TODO[1760]: count-authz: Uncomment the rest of this test once we have that back in the SDK. - /* - c := keeper.NewAuthzCache() - grantee := sdk.AccAddress("grantee") - granter := sdk.AccAddress("granter") - msgTypeURL := "msgTypeURL" - authorization := &authz.CountAuthorization{ - Msg: msgTypeURL, - AllowedAuthorizations: 77, - } + c := keeper.NewAuthzCache() + grantee := sdk.AccAddress("grantee") + granter := sdk.AccAddress("granter") + msgTypeURL := "msgTypeURL" + authorization := &authz.CountAuthorization{ + Msg: msgTypeURL, + AllowedAuthorizations: 77, + } - c.SetAcceptable(grantee, granter, msgTypeURL, authorization) - actual := c.AcceptableMap()[keeper.AuthzCacheAcceptableKey(grantee, granter, msgTypeURL)] - assert.Equal(t, authorization, actual, "the authorization stored by SetAcceptable") - */ + c.SetAcceptable(grantee, granter, msgTypeURL, authorization) + actual := c.AcceptableMap()[keeper.AuthzCacheAcceptableKey(grantee, granter, msgTypeURL)] + assert.Equal(t, authorization, actual, "the authorization stored by SetAcceptable") } func TestAuthzCache_GetAcceptable(t *testing.T) { @@ -1996,21 +1993,17 @@ func TestAuthzCache_GetAcceptable(t *testing.T) { msgTypeURL := "msgTypeURL" key := keeper.AuthzCacheAcceptableKey(grantee, granter, msgTypeURL) - // TODO[1760]: count-authz: Uncomment the rest of this test once we have that back in the SDK. - _, _ = c, key - /* - authorization := &authz.CountAuthorization{ - Msg: msgTypeURL, - AllowedAuthorizations: 8, - } - c.AcceptableMap()[key] = authorization + authorization := &authz.CountAuthorization{ + Msg: msgTypeURL, + AllowedAuthorizations: 8, + } + c.AcceptableMap()[key] = authorization - actual := c.GetAcceptable(grantee, granter, msgTypeURL) - assert.Equal(t, authorization, actual, "GetAcceptable result") + actual := c.GetAcceptable(grantee, granter, msgTypeURL) + assert.Equal(t, authorization, actual, "GetAcceptable result") - notThere := c.GetAcceptable(granter, grantee, msgTypeURL) - assert.Nil(t, notThere, "GetAcceptable on an entry that should not exist") - */ + notThere := c.GetAcceptable(granter, grantee, msgTypeURL) + assert.Nil(t, notThere, "GetAcceptable on an entry that should not exist") } func TestAuthzCache_SetIsWasm(t *testing.T) { @@ -2135,30 +2128,26 @@ func TestAddAuthzCacheToContext(t *testing.T) { }) t.Run("context already has an AuthzCache", func(t *testing.T) { - // TODO[1760]: count-authz: Uncomment the rest of this test once we have that back in the SDK. - /* - grantee := sdk.AccAddress("grantee") - granter := sdk.AccAddress("granter") - msgTypeURL := "msgTypeURL" - authorization := &authz.CountAuthorization{ - Msg: msgTypeURL, - AllowedAuthorizations: 8, - } - origCache := keeper.NewAuthzCache() - origCache.SetAcceptable(grantee, granter, msgTypeURL, authorization) - - origCtx := emptySdkContext().WithValue(keeper.AuthzCacheContextKey, origCache) - newCtx := keeper.AddAuthzCacheToContext(origCtx) + grantee := sdk.AccAddress("grantee") + granter := sdk.AccAddress("granter") + msgTypeURL := "msgTypeURL" + authorization := &authz.CountAuthorization{ + Msg: msgTypeURL, + AllowedAuthorizations: 8, + } + origCache := keeper.NewAuthzCache() + origCache.SetAcceptable(grantee, granter, msgTypeURL, authorization) - var newCache *keeper.AuthzCache - testFunc := func() { - newCache = keeper.GetAuthzCache(newCtx) - } - require.NotPanics(t, testFunc, "GetAuthzCache") - assert.Same(t, origCache, newCache, "cache from new context") - assert.Empty(t, newCache.AcceptableMap(), "cache acceptable map") + origCtx := emptySdkContext().WithValue(keeper.AuthzCacheContextKey, origCache) + newCtx := keeper.AddAuthzCacheToContext(origCtx) - */ + var newCache *keeper.AuthzCache + testFunc := func() { + newCache = keeper.GetAuthzCache(newCtx) + } + require.NotPanics(t, testFunc, "GetAuthzCache") + assert.Same(t, origCache, newCache, "cache from new context") + assert.Empty(t, newCache.AcceptableMap(), "cache acceptable map") }) t.Run("context has something else", func(t *testing.T) { From 7d681a7bfeb79738db2f851942ce9bd444e0944a Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Fri, 12 Apr 2024 13:10:12 -0600 Subject: [PATCH 04/22] [1760]: Switch to a local version of the SDK that has the count authz cmd fix. --- go.mod | 3 ++- go.sum | 2 -- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 4726687726..7a4c3d03c4 100644 --- a/go.mod +++ b/go.mod @@ -215,7 +215,8 @@ replace ( // TODO[1760]: wasm: Put this CosmWasm/wasmd replace back with an updated version (or delete it). // github.com/CosmWasm/wasmd => github.com/provenance-io/wasmd v0.30.0-pio-5 // TODO[1760]: sdk: Put this replace back with an updated version of the sdk from our fork. - github.com/cosmos/cosmos-sdk => github.com/provenance-io/cosmos-sdk v0.50.5-pio-2 + // github.com/cosmos/cosmos-sdk => github.com/provenance-io/cosmos-sdk v0.50.5-pio-2 + github.com/cosmos/cosmos-sdk => ../prov-cosmos-sdk // TODO[1760]: Update once async-icq creates tag with our changes https://github.com/cosmos/ibc-apps/pull/168 github.com/cosmos/ibc-apps/modules/async-icq/v8 => github.com/provenance-io/ibc-apps/modules/async-icq/v8 v8.0.0-prov-1 diff --git a/go.sum b/go.sum index f531abb3f0..6a4f2becdc 100644 --- a/go.sum +++ b/go.sum @@ -914,8 +914,6 @@ github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4O github.com/prometheus/procfs v0.3.0/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo= github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo= -github.com/provenance-io/cosmos-sdk v0.50.5-pio-2 h1:qK+ZN2jBBFEOZZOpefAMBrU5mWj+znU87Gvxbsl8feA= -github.com/provenance-io/cosmos-sdk v0.50.5-pio-2/go.mod h1:oV/k6GJgXV9QPoM2fsYDPPsyPBgQbdotv532O6Mz1OQ= github.com/provenance-io/ibc-apps/modules/async-icq/v8 v8.0.0-prov-1 h1:p+7pxHB0ukO2aow+M6uW9gHgeQl7YJyYGyMSKHZ5My8= github.com/provenance-io/ibc-apps/modules/async-icq/v8 v8.0.0-prov-1/go.mod h1:tObW9uxibh5Z22CtOaHVeTDotCSMyc/2B4MrYdaViBo= github.com/rakyll/statik v0.1.7 h1:OF3QCZUuyPxuGEP7B4ypUa7sB/iHtqOTDYZXGM8KOdQ= From 53646f9b7f5c7448f6464e6bfb9a39e4e37cd304 Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Fri, 12 Apr 2024 13:10:57 -0600 Subject: [PATCH 05/22] [1760]: Fix the rest of the count-authz TODOs. --- x/metadata/client/cli/cli_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/metadata/client/cli/cli_test.go b/x/metadata/client/cli/cli_test.go index 4e0e16d1c7..d232ab6b1b 100644 --- a/x/metadata/client/cli/cli_test.go +++ b/x/metadata/client/cli/cli_test.go @@ -3809,7 +3809,7 @@ func (s *IntegrationCLITestSuite) TestCountAuthorizationIntactTxCommands() { args: []string{ s.user3AddrStr, "count", - // fmt.Sprintf("--%s=%d", authzcli.FlagAllowedAuthorizations, 1), // TODO[1760]: count-authz + fmt.Sprintf("--%s=%d", authzcli.FlagAllowedAuthorizations, 1), fmt.Sprintf("--%s=%s", authzcli.FlagMsgType, metadatatypes.TypeURLMsgDeleteScopeRequest), fmt.Sprintf("--%s=%s", flags.FlagFrom, s.user1AddrStr), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), @@ -3836,7 +3836,7 @@ func (s *IntegrationCLITestSuite) TestCountAuthorizationIntactTxCommands() { args: []string{ s.user3AddrStr, "count", - // fmt.Sprintf("--%s=%d", authzcli.FlagAllowedAuthorizations, 2), // TODO[1760]: count-authz + fmt.Sprintf("--%s=%d", authzcli.FlagAllowedAuthorizations, 2), fmt.Sprintf("--%s=%s", authzcli.FlagMsgType, metadatatypes.TypeURLMsgDeleteScopeRequest), fmt.Sprintf("--%s=%s", flags.FlagFrom, s.user2AddrStr), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), From 55128bfa2e67c4a866a935b7984962c2db124a21 Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Fri, 12 Apr 2024 13:45:30 -0600 Subject: [PATCH 06/22] [1760]: Use GenerateOrBroadcastTxCLIAsGovProp now that it's back. --- internal/provcli/cli_helpers.go | 17 ++++------- x/exchange/client/cli/helpers.go | 9 ++---- x/exchange/client/cli/tx.go | 10 +++---- x/ibcratelimit/client/cli/tx.go | 35 ++++++----------------- x/marker/client/cli/tx.go | 16 ++++------- x/name/client/cli/tx.go | 48 ++++++++------------------------ x/oracle/client/cli/tx.go | 34 ++++++---------------- 7 files changed, 47 insertions(+), 122 deletions(-) diff --git a/internal/provcli/cli_helpers.go b/internal/provcli/cli_helpers.go index 4872465f9b..b4a38ceac3 100644 --- a/internal/provcli/cli_helpers.go +++ b/internal/provcli/cli_helpers.go @@ -8,7 +8,6 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/tx" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" govcli "github.com/cosmos/cosmos-sdk/x/gov/client/cli" @@ -43,8 +42,8 @@ func GetAuthority(flagSet *pflag.FlagSet) string { } // GenerateOrBroadcastTxCLIAsGovProp wraps the provided msgs in a governance proposal -// and calls GenerateOrBroadcastTxCLI for that proposal. -// At least one msg is required. +// and calls GenerateOrBroadcastTxCLI for that proposal. At least one msg is required. +// // This uses flags added by govcli.AddGovPropFlagsToCmd to fill in the rest of the proposal. func GenerateOrBroadcastTxCLIAsGovProp(clientCtx client.Context, flagSet *pflag.FlagSet, msgs ...sdk.Msg) error { if len(msgs) == 0 { @@ -56,15 +55,9 @@ func GenerateOrBroadcastTxCLIAsGovProp(clientCtx client.Context, flagSet *pflag. return err } - prop.Messages = make([]*codectypes.Any, len(msgs)) - for i, msg := range msgs { - prop.Messages[i], err = codectypes.NewAnyWithValue(msg) - if err != nil { - if len(msgs) == 1 { - return fmt.Errorf("could not wrap %T message as Any: %w", msg, err) - } - return fmt.Errorf("could not wrap message %d (%T) as Any: %w", i, msg, err) - } + err = prop.SetMsgs(msgs) + if err != nil { + return fmt.Errorf("error wrapping msg(s) as Any: %w", err) } return tx.GenerateOrBroadcastTxCLI(clientCtx, flagSet, prop) diff --git a/x/exchange/client/cli/helpers.go b/x/exchange/client/cli/helpers.go index a04252beab..e7c0aa3c39 100644 --- a/x/exchange/client/cli/helpers.go +++ b/x/exchange/client/cli/helpers.go @@ -5,7 +5,6 @@ import ( "fmt" "strings" - "github.com/cosmos/gogoproto/proto" "github.com/spf13/cobra" "github.com/spf13/pflag" "google.golang.org/grpc" @@ -16,11 +15,11 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/version" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - - // govcli "github.com/cosmos/cosmos-sdk/x/gov/client/cli" // TODO[1760]: gov-cli govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" + "github.com/cosmos/gogoproto/proto" + "github.com/provenance-io/provenance/internal/provcli" "github.com/provenance-io/provenance/x/exchange" ) @@ -79,9 +78,7 @@ func govTxRunE[R sdk.Msg](maker msgMaker[R]) func(cmd *cobra.Command, args []str } cmd.SilenceUsage = true - // return govcli.GenerateOrBroadcastTxCLIAsGovProp(clientCtx, flagSet, msg) // TODO[1760]: gov-cli - _ = msg - return fmt.Errorf("not yet updated") + return provcli.GenerateOrBroadcastTxCLIAsGovProp(clientCtx, flagSet, msg) } } diff --git a/x/exchange/client/cli/tx.go b/x/exchange/client/cli/tx.go index ef9c3e4b27..e3fb6fc1c3 100644 --- a/x/exchange/client/cli/tx.go +++ b/x/exchange/client/cli/tx.go @@ -7,7 +7,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" - // govcli "github.com/cosmos/cosmos-sdk/x/gov/client/cli" // TODO[1760]: gov-cli + govcli "github.com/cosmos/cosmos-sdk/x/gov/client/cli" "github.com/provenance-io/provenance/x/exchange" ) @@ -402,7 +402,7 @@ func CmdTxGovCreateMarket() *cobra.Command { } flags.AddTxFlagsToCmd(cmd) - // govcli.AddGovPropFlagsToCmd(cmd) // TODO[1760]: gov-cli + govcli.AddGovPropFlagsToCmd(cmd) SetupCmdTxGovCreateMarket(cmd) return cmd } @@ -417,7 +417,7 @@ func CmdTxGovManageFees() *cobra.Command { } flags.AddTxFlagsToCmd(cmd) - // govcli.AddGovPropFlagsToCmd(cmd) // TODO[1760]: gov-cli + govcli.AddGovPropFlagsToCmd(cmd) SetupCmdTxGovManageFees(cmd) return cmd } @@ -432,7 +432,7 @@ func CmdTxGovCloseMarket() *cobra.Command { } flags.AddTxFlagsToCmd(cmd) - // govcli.AddGovPropFlagsToCmd(cmd) // TODO[1760]: gov-cli + govcli.AddGovPropFlagsToCmd(cmd) SetupCmdTxGovCloseMarket(cmd) return cmd } @@ -447,7 +447,7 @@ func CmdTxGovUpdateParams() *cobra.Command { } flags.AddTxFlagsToCmd(cmd) - // govcli.AddGovPropFlagsToCmd(cmd) // TODO[1760]: gov-cli + govcli.AddGovPropFlagsToCmd(cmd) SetupCmdTxGovUpdateParams(cmd) return cmd } diff --git a/x/ibcratelimit/client/cli/tx.go b/x/ibcratelimit/client/cli/tx.go index 0d34550b25..a8e08011b0 100644 --- a/x/ibcratelimit/client/cli/tx.go +++ b/x/ibcratelimit/client/cli/tx.go @@ -8,11 +8,9 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/version" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - - // govcli "github.com/cosmos/cosmos-sdk/x/gov/client/cli" // TODO[1760]: gov-cli - govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + govcli "github.com/cosmos/cosmos-sdk/x/gov/client/cli" + "github.com/provenance-io/provenance/internal/provcli" "github.com/provenance-io/provenance/x/ibcratelimit" ) @@ -49,32 +47,15 @@ func GetCmdParamsUpdate() *cobra.Command { return err } - authority := authtypes.NewModuleAddress(govtypes.ModuleName) - - msg := ibcratelimit.NewMsgGovUpdateParamsRequest( - authority.String(), - args[0], - ) - - // TODO[1760]: gov-cli: Replace this with GenerateOrBroadcastTxCLIAsGovProp once its back. - _, _ = msg, clientCtx - /* - proposal, govErr := govcli.ReadGovPropFlags(clientCtx, cmd.Flags()) - if govErr != nil { - return govErr - } - proposal.Messages, govErr = sdktx.SetMsgs([]sdk.Msg{msg}) - if govErr != nil { - return govErr - } - - return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), proposal) - */ - return fmt.Errorf("not yet updated") + flagSet := cmd.Flags() + authority := provcli.GetAuthority(flagSet) + msg := ibcratelimit.NewMsgGovUpdateParamsRequest(authority, args[0]) + return provcli.GenerateOrBroadcastTxCLIAsGovProp(clientCtx, flagSet, msg) }, } - // govcli.AddGovPropFlagsToCmd(cmd) // TODO[1760]: gov-cli + govcli.AddGovPropFlagsToCmd(cmd) + provcli.AddAuthorityFlagToCmd(cmd) flags.AddTxFlagsToCmd(cmd) return cmd diff --git a/x/marker/client/cli/tx.go b/x/marker/client/cli/tx.go index 866b25e363..3b0ce7e4e7 100644 --- a/x/marker/client/cli/tx.go +++ b/x/marker/client/cli/tx.go @@ -21,12 +21,12 @@ import ( "github.com/cosmos/cosmos-sdk/version" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/authz" - - // govcli "github.com/cosmos/cosmos-sdk/x/gov/client/cli" // TODO[1760]: gov-cli + govcli "github.com/cosmos/cosmos-sdk/x/gov/client/cli" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" channelutils "github.com/cosmos/ibc-go/v8/modules/core/04-channel/client/utils" + "github.com/provenance-io/provenance/internal/provcli" attrcli "github.com/provenance-io/provenance/x/attribute/client/cli" "github.com/provenance-io/provenance/x/marker/types" ) @@ -461,7 +461,6 @@ func GetNewTransferCmd() *cobra.Command { // GetIbcTransferTxCmd returns the command to create a GetIbcTransferTxCmd transaction func GetIbcTransferTxCmd() *cobra.Command { - // TODO: refactor ibc-transfer usage comments to be provenance specific cmd := &cobra.Command{ Use: "ibc-transfer [src-port] [src-channel] [sender] [receiver] [amount]", Short: "Transfer a restricted marker token through IBC", @@ -949,13 +948,11 @@ func GetCmdUpdateForcedTransfer() *cobra.Command { return err } - // return govcli.GenerateOrBroadcastTxCLIAsGovProp(clientCtx, cmd.Flags(), msg) // TODO[1760]: gov-cli - _, _ = msg, clientCtx - return fmt.Errorf("not yet updated") + return provcli.GenerateOrBroadcastTxCLIAsGovProp(clientCtx, cmd.Flags(), msg) }, } - // govcli.AddGovPropFlagsToCmd(cmd) // TODO[1760]: gov-cli + govcli.AddGovPropFlagsToCmd(cmd) flags.AddTxFlagsToCmd(cmd) return cmd } @@ -1224,7 +1221,7 @@ func ParseBoolStrict(input string) (bool, error) { // See also: generateOrBroadcastOptGovProp func addOptGovPropFlags(cmd *cobra.Command) { cmd.Flags().Bool(FlagGovProposal, false, "submit message as a gov proposal") - // govcli.AddGovPropFlagsToCmd(cmd) // TODO[1760]: gov-cli + govcli.AddGovPropFlagsToCmd(cmd) } // generateOrBroadcastOptGovProp either calls GenerateOrBroadcastTxCLIAsGovProp or GenerateOrBroadcastTxCLI @@ -1245,8 +1242,7 @@ func generateOrBroadcastOptGovProp(clientCtx client.Context, flagSet *pflag.Flag } if isGov { - // return govcli.GenerateOrBroadcastTxCLIAsGovProp(clientCtx, flagSet, msg) // TODO[1760]: gov-cli - return fmt.Errorf("not yet updated") + return provcli.GenerateOrBroadcastTxCLIAsGovProp(clientCtx, flagSet, msg) } return tx.GenerateOrBroadcastTxCLI(clientCtx, flagSet, msg) } diff --git a/x/name/client/cli/tx.go b/x/name/client/cli/tx.go index 322543391d..25eb92f9ce 100644 --- a/x/name/client/cli/tx.go +++ b/x/name/client/cli/tx.go @@ -12,18 +12,16 @@ import ( "github.com/cosmos/cosmos-sdk/client/tx" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/version" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - - // govcli "github.com/cosmos/cosmos-sdk/x/gov/client/cli" // TODO[1760]: gov-cli - govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + govcli "github.com/cosmos/cosmos-sdk/x/gov/client/cli" + "github.com/provenance-io/provenance/internal/provcli" "github.com/provenance-io/provenance/x/name/types" ) -// The flag for creating unrestricted names +// FlagUnrestricted is the flag for creating unrestricted names const FlagUnrestricted = "unrestrict" -// The flag to specify that the command should be ran as a gov proposal +// FlagGovProposal is the flag to specify that the command should be run as a gov proposal const FlagGovProposal = "gov-proposal" // NewTxCmd is the top-level command for name CLI transactions. @@ -140,46 +138,24 @@ $ %s tx name modify-name \ return err } - var authority sdk.AccAddress - if !isGov { - authority = clientCtx.GetFromAddress() - } else { - authority = authtypes.NewModuleAddress(govtypes.ModuleName) - } - - modifyMsg := types.MsgModifyNameRequest{ - Authority: authority.String(), - Record: types.NewNameRecord(strings.ToLower(args[0]), owner, !viper.GetBool(FlagUnrestricted)), + modifyMsg := &types.MsgModifyNameRequest{ + Record: types.NewNameRecord(strings.ToLower(args[0]), owner, !viper.GetBool(FlagUnrestricted)), } - var req sdk.Msg if isGov { - // TODO[1760]: gov-cli: Replace this with GenerateOrBroadcastTxCLIAsGovProp once its back. - /* - var govErr error - proposal, govErr := govcli.ReadGovPropFlags(clientCtx, cmd.Flags()) - if govErr != nil { - return govErr - } - anys, govErr := sdktx.SetMsgs([]sdk.Msg{&modifyMsg}) - if govErr != nil { - return govErr - } - proposal.Messages = anys - req = proposal - */ - return fmt.Errorf("not yet updated") - } else { - req = &modifyMsg + modifyMsg.Authority = provcli.GetAuthority(cmd.Flags()) + return provcli.GenerateOrBroadcastTxCLIAsGovProp(clientCtx, cmd.Flags(), modifyMsg) } - return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), req) + modifyMsg.Authority = clientCtx.GetFromAddress().String() + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), modifyMsg) }, } cmd.Flags().BoolP(FlagUnrestricted, "u", false, "Allow child name creation by everyone") cmd.Flags().Bool(FlagGovProposal, false, "Run transaction as gov proposal") - // govcli.AddGovPropFlagsToCmd(cmd) // TODO[1760]: gov-cli + govcli.AddGovPropFlagsToCmd(cmd) + provcli.AddAuthorityFlagToCmd(cmd) flags.AddTxFlagsToCmd(cmd) return cmd } diff --git a/x/oracle/client/cli/tx.go b/x/oracle/client/cli/tx.go index bb20ae7cfd..ae60b0ad12 100644 --- a/x/oracle/client/cli/tx.go +++ b/x/oracle/client/cli/tx.go @@ -11,11 +11,9 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" "github.com/cosmos/cosmos-sdk/version" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - - // govcli "github.com/cosmos/cosmos-sdk/x/gov/client/cli" // TODO[1760]: gov-cli - govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + govcli "github.com/cosmos/cosmos-sdk/x/gov/client/cli" + "github.com/provenance-io/provenance/internal/provcli" "github.com/provenance-io/provenance/x/oracle/types" ) @@ -53,32 +51,16 @@ func GetCmdOracleUpdate() *cobra.Command { return err } - authority := authtypes.NewModuleAddress(govtypes.ModuleName) - - msg := types.NewMsgUpdateOracle( - authority.String(), - args[0], - ) + flagSet := cmd.Flags() + authority := provcli.GetAuthority(flagSet) - // TODO[1760]: gov-cli: Replace this with GenerateOrBroadcastTxCLIAsGovProp once its back. - _, _ = msg, clientCtx - /* - proposal, govErr := govcli.ReadGovPropFlags(clientCtx, cmd.Flags()) - if govErr != nil { - return govErr - } - proposal.Messages, govErr = sdktx.SetMsgs([]sdk.Msg{msg}) - if govErr != nil { - return govErr - } - - return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), proposal) - */ - return fmt.Errorf("not yet updated") + msg := types.NewMsgUpdateOracle(authority, args[0]) + return provcli.GenerateOrBroadcastTxCLIAsGovProp(clientCtx, flagSet, msg) }, } - // govcli.AddGovPropFlagsToCmd(cmd) // TODO[1760]: gov-cli + govcli.AddGovPropFlagsToCmd(cmd) + provcli.AddAuthorityFlagToCmd(cmd) flags.AddTxFlagsToCmd(cmd) return cmd From 8f26735138a5e5273c474bc1d18c46d20e96c06f Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Fri, 12 Apr 2024 14:03:44 -0600 Subject: [PATCH 07/22] [1760]: Put the locked coins stuff back in. --- x/hold/expected_keepers.go | 4 ++-- x/hold/keeper/invariants.go | 3 ++- x/hold/keeper/keeper.go | 2 +- x/hold/keeper/keeper_test.go | 14 +++++++------- x/hold/keeper/locked_coins.go | 10 ++++++---- x/hold/keeper/mock_keepers_test.go | 9 ++++----- x/hold/locked_coins.go | 23 ++++++++++++++++------- 7 files changed, 38 insertions(+), 27 deletions(-) diff --git a/x/hold/expected_keepers.go b/x/hold/expected_keepers.go index c2dac5ea89..bea77f2886 100644 --- a/x/hold/expected_keepers.go +++ b/x/hold/expected_keepers.go @@ -4,10 +4,10 @@ import ( "context" sdk "github.com/cosmos/cosmos-sdk/types" - // banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" // TODO[1760]: locked-coins + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" ) type BankKeeper interface { - // AppendLockedCoinsGetter(getter banktypes.GetLockedCoinsFn) // TODO[1760]: locked-coins + AppendLockedCoinsGetter(getter banktypes.GetLockedCoinsFn) SpendableCoins(ctx context.Context, addr sdk.AccAddress) sdk.Coins } diff --git a/x/hold/keeper/invariants.go b/x/hold/keeper/invariants.go index c167a58a6f..1919f541b7 100644 --- a/x/hold/keeper/invariants.go +++ b/x/hold/keeper/invariants.go @@ -5,6 +5,7 @@ import ( "strings" sdk "github.com/cosmos/cosmos-sdk/types" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/provenance-io/provenance/x/hold" ) @@ -44,7 +45,7 @@ func holdAccountBalancesInvariantHelper(ctx sdk.Context, keeper Keeper) (string, // So, long story short (too late), if the block time is zero, also bypass the vesting locked funds getter. blockTime := ctx.BlockTime() if blockTime.IsZero() { - ctx = ctx // banktypes.WithVestingLockedBypass(ctx) // TODO[1760]: locked-coins + ctx = banktypes.WithVestingLockedBypass(ctx) } var addr sdk.AccAddress var total sdk.Coins diff --git a/x/hold/keeper/keeper.go b/x/hold/keeper/keeper.go index e7dd89d263..a6a2c93aae 100644 --- a/x/hold/keeper/keeper.go +++ b/x/hold/keeper/keeper.go @@ -27,7 +27,7 @@ func NewKeeper(cdc codec.BinaryCodec, storeKey storetypes.StoreKey, bankKeeper h storeKey: storeKey, bankKeeper: bankKeeper, } - // bankKeeper.AppendLockedCoinsGetter(rv.GetLockedCoins) // TODO[1760]: locked-coins + bankKeeper.AppendLockedCoinsGetter(rv.GetLockedCoins) return rv } diff --git a/x/hold/keeper/keeper_test.go b/x/hold/keeper/keeper_test.go index 08e21baf0f..cb18fd1e9f 100644 --- a/x/hold/keeper/keeper_test.go +++ b/x/hold/keeper/keeper_test.go @@ -1599,13 +1599,13 @@ func (s *TestSuite) TestVestingAndHoldOverTime() { }, "casting addr account to %T", acc) stepResults[i] = &stepResult{ - step: step, - balance: s.app.BankKeeper.GetAllBalances(ctx, addr), - delegated: s.app.BankKeeper.GetAllBalances(ctx, modAddr), - spendable: s.app.BankKeeper.SpendableCoins(ctx, addr), - locked: s.app.BankKeeper.LockedCoins(ctx, addr), - lockedHold: s.keeper.GetLockedCoins(ctx, addr), - // lockedVest: s.app.BankKeeper.UnvestedCoins(ctx, addr), TODO[1760]: locked-coins + step: step, + balance: s.app.BankKeeper.GetAllBalances(ctx, addr), + delegated: s.app.BankKeeper.GetAllBalances(ctx, modAddr), + spendable: s.app.BankKeeper.SpendableCoins(ctx, addr), + locked: s.app.BankKeeper.LockedCoins(ctx, addr), + lockedHold: s.keeper.GetLockedCoins(ctx, addr), + lockedVest: s.app.BankKeeper.UnvestedCoins(ctx, addr), accVesting: acc.GetVestingCoins(blockTime), accVested: acc.GetVestedCoins(blockTime), accDelegatedVesting: acc.GetDelegatedVesting(), diff --git a/x/hold/keeper/locked_coins.go b/x/hold/keeper/locked_coins.go index ea84dd56a7..30a833e9a5 100644 --- a/x/hold/keeper/locked_coins.go +++ b/x/hold/keeper/locked_coins.go @@ -1,20 +1,22 @@ package keeper import ( + "context" + sdk "github.com/cosmos/cosmos-sdk/types" - // banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" // TODO[1760]: locked-coins + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/provenance-io/provenance/x/hold" ) -// var _ banktypes.GetLockedCoinsFn = Keeper{}.GetLockedCoins // TODO[1760]: locked-coins +var _ banktypes.GetLockedCoinsFn = Keeper{}.GetLockedCoins // GetLockedCoins gets all the coins that are on hold for the given address. -func (k Keeper) GetLockedCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins { +func (k Keeper) GetLockedCoins(ctx context.Context, addr sdk.AccAddress) sdk.Coins { if hold.HasBypass(ctx) { return nil } - rv, err := k.GetHoldCoins(ctx, addr) + rv, err := k.GetHoldCoins(sdk.UnwrapSDKContext(ctx), addr) if err != nil { panic(err) } diff --git a/x/hold/keeper/mock_keepers_test.go b/x/hold/keeper/mock_keepers_test.go index 497fad6cc5..a0efa5310f 100644 --- a/x/hold/keeper/mock_keepers_test.go +++ b/x/hold/keeper/mock_keepers_test.go @@ -4,7 +4,7 @@ import ( "context" sdk "github.com/cosmos/cosmos-sdk/types" - // banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" // TODO[1760]: locked-coins + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/provenance-io/provenance/x/hold" ) @@ -28,10 +28,9 @@ func (k *MockBankKeeper) WithSpendable(addr sdk.AccAddress, amount sdk.Coins) *M return k } -// TODO[1760]: locked-coins -// func (k *MockBankKeeper) AppendLockedCoinsGetter(_ banktypes.GetLockedCoinsFn) { -// // Do nothing. -// } +func (k *MockBankKeeper) AppendLockedCoinsGetter(_ banktypes.GetLockedCoinsFn) { + // Do nothing. +} func (k *MockBankKeeper) SpendableCoins(_ context.Context, addr sdk.AccAddress) sdk.Coins { return k.Spendable[string(addr)] diff --git a/x/hold/locked_coins.go b/x/hold/locked_coins.go index ef852c2b79..34b66b29ff 100644 --- a/x/hold/locked_coins.go +++ b/x/hold/locked_coins.go @@ -1,22 +1,31 @@ package hold -import sdk "github.com/cosmos/cosmos-sdk/types" +import ( + "context" + + sdk "github.com/cosmos/cosmos-sdk/types" +) const bypassKey = "bypass-" + ModuleName + "-locked-coins" // WithBypass returns a new context that will cause the hold locked coins lookup to be skipped. -func WithBypass(ctx sdk.Context) sdk.Context { - return ctx.WithValue(bypassKey, true) +func WithBypass[C context.Context](ctx C) C { + sdkCtx := sdk.UnwrapSDKContext(ctx) + sdkCtx = sdkCtx.WithValue(bypassKey, true) + return context.Context(sdkCtx).(C) } // WithoutBypass returns a new context that will cause the hold locked coins lookup to not be skipped. -func WithoutBypass(ctx sdk.Context) sdk.Context { - return ctx.WithValue(bypassKey, false) +func WithoutBypass[C context.Context](ctx C) C { + sdkCtx := sdk.UnwrapSDKContext(ctx) + sdkCtx = sdkCtx.WithValue(bypassKey, false) + return context.Context(sdkCtx).(C) } // HasBypass checks the context to see if the hold locked coins lookup should be skipped. -func HasBypass(ctx sdk.Context) bool { - bypassValue := ctx.Value(bypassKey) +func HasBypass[C context.Context](ctx C) bool { + sdkCtx := sdk.UnwrapSDKContext(ctx) + bypassValue := sdkCtx.Value(bypassKey) if bypassValue == nil { return false } From 909645b9facb20e594b6b8c7386f32b0b1b476fa Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Fri, 12 Apr 2024 14:08:28 -0600 Subject: [PATCH 08/22] [1760]: Put back uses of InputOutputCoins and InputOutputCoinsProv. --- x/exchange/expected_keepers.go | 4 ++-- x/exchange/keeper/keeper.go | 12 ++++-------- x/marker/keeper/send_restrictions_test.go | 2 +- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/x/exchange/expected_keepers.go b/x/exchange/expected_keepers.go index e615eed334..28ba2115da 100644 --- a/x/exchange/expected_keepers.go +++ b/x/exchange/expected_keepers.go @@ -4,6 +4,7 @@ import ( "context" sdk "github.com/cosmos/cosmos-sdk/types" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" attrtypes "github.com/provenance-io/provenance/x/attribute/types" markertypes "github.com/provenance-io/provenance/x/marker/types" ) @@ -22,8 +23,7 @@ type AttributeKeeper interface { type BankKeeper interface { SendCoins(ctx context.Context, fromAddr, toAddr sdk.AccAddress, amt sdk.Coins) error SendCoinsFromAccountToModule(ctx context.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error - // TODO[1760]: exchange: Put InputOutputCoins back in this expected keeper once our fork is back in place. - // InputOutputCoins(ctx context.Context, inputs []banktypes.Input, outputs []banktypes.Output) error + InputOutputCoinsProv(ctx context.Context, inputs []banktypes.Input, outputs []banktypes.Output) error BlockedAddr(addr sdk.AccAddress) bool } diff --git a/x/exchange/keeper/keeper.go b/x/exchange/keeper/keeper.go index 56cdbff00a..b3bdad08a5 100644 --- a/x/exchange/keeper/keeper.go +++ b/x/exchange/keeper/keeper.go @@ -222,9 +222,7 @@ func (k Keeper) DoTransfer(ctxIn sdk.Context, inputs []banktypes.Input, outputs } } - // TODO[1760]: exchange: Put this back once we have InputOutputCoins again. - // return k.bankKeeper.InputOutputCoins(ctx, inputs, outputs) - return nil + return k.bankKeeper.InputOutputCoinsProv(ctx, inputs, outputs) } // CalculateExchangeSplit calculates the amount that the exchange will keep of the provided fee. @@ -302,11 +300,9 @@ func (k Keeper) CollectFees(ctx sdk.Context, marketID uint32, inputs []banktypes marketAddr := exchange.GetMarketAddress(marketID) outputs := []banktypes.Output{{Address: marketAddr.String(), Coins: feeAmt}} - // TODO[1760]: exchange: Put this back once we have InputOutputCoins again. - _ = outputs - // if err := k.bankKeeper.InputOutputCoins(ctx, inputs, outputs); err != nil { - // return fmt.Errorf("error collecting fees for market %d: %w", marketID, err) - // } + if err := k.bankKeeper.InputOutputCoinsProv(ctx, inputs, outputs); err != nil { + return fmt.Errorf("error collecting fees for market %d: %w", marketID, err) + } if !exchangeAmt.IsZero() { if err := k.bankKeeper.SendCoinsFromAccountToModule(ctx, marketAddr, k.feeCollectorName, exchangeAmt); err != nil { return fmt.Errorf("error collecting exchange fee %s (based off %s) from market %d: %w", exchangeAmt, feeAmt, marketID, err) diff --git a/x/marker/keeper/send_restrictions_test.go b/x/marker/keeper/send_restrictions_test.go index 9d558c62ca..12797774f6 100644 --- a/x/marker/keeper/send_restrictions_test.go +++ b/x/marker/keeper/send_restrictions_test.go @@ -878,7 +878,7 @@ func TestBankInputOutputCoinsUsesSendRestrictionFn(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { - // err = app.BankKeeper.InputOutputCoins(ctx, []banktypes.Input{tc.input}, tc.outputs) // TODO[1760]: bank + err = app.BankKeeper.InputOutputCoins(ctx, tc.input, tc.outputs) if len(tc.expErr) != 0 { assert.EqualError(t, err, tc.expErr, "InputOutputCoins") } else { From 7c0fee5c1f279c3d85ff0ba630f7fcc02f37d164 Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Fri, 12 Apr 2024 14:17:45 -0600 Subject: [PATCH 09/22] [1760]: Get rid of the test_amino build tag and the make targets for it. Remove the check-test stuff since we've also got build-tests which is easier for me to remember. --- Makefile | 13 ++----------- app/params/amino.go | 27 --------------------------- app/params/proto.go | 4 +--- 3 files changed, 3 insertions(+), 41 deletions(-) delete mode 100644 app/params/amino.go diff --git a/Makefile b/Makefile index 001783950a..29121ff748 100644 --- a/Makefile +++ b/Makefile @@ -331,13 +331,12 @@ PACKAGES_NOSIMULATION := $(filter-out %/simulation%,$(PACKAGES)) PACKAGES_SIMULATION := $(filter %/simulation%,$(PACKAGES)) TEST_PACKAGES=./... -TEST_TARGETS := test-unit test-unit-amino test-unit-proto test-ledger-mock test-race test-ledger test-race +TEST_TARGETS := test-unit test-unit-proto test-ledger-mock test-race test-ledger # Test runs-specific rules. To add a new test target, just add # a new rule, customise TAGS, ARGS and/or TEST_PACKAGES ad libitum, and # append the new rule to the TEST_TARGETS list. test-unit: TAGS+=cgo ledger test_ledger_mock norace -test-unit-amino: TAGS+=ledger test_ledger_mock test_amino norace test-ledger: TAGS+=cgo ledger norace test-ledger-mock: TAGS+=ledger test_ledger_mock norace test-race: ARGS+=-race @@ -345,14 +344,6 @@ test-race: TAGS+=cgo ledger test_ledger_mock test-race: TEST_PACKAGES=$(PACKAGES_NOSIMULATION) $(TEST_TARGETS): run-tests -# check-* compiles and collects tests without running them -# note: go test -c doesn't support multiple packages yet (https://github.com/golang/go/issues/15513) -CHECK_TEST_TARGETS := check-test-unit check-test-unit-amino -check-test-unit: TAGS+=cgo ledger test_ledger_mock norace -check-test-unit-amino: TAGS+=ledger test_ledger_mock test_amino norace -$(CHECK_TEST_TARGETS): ARGS+=-run=none -$(CHECK_TEST_TARGETS): run-tests - run-tests: go.sum ifneq (,$(shell which tparse 2>/dev/null)) $(GO) test -mod=readonly -json $(ARGS) -tags='$(TAGS)' $(TEST_PACKAGES) | tparse @@ -373,7 +364,7 @@ test-cover: benchmark: $(GO) test -mod=readonly -bench=. $(PACKAGES_NOSIMULATION) -.PHONY: test test-all test-unit test-race test-cover benchmark run-tests build-tests $(TEST_TARGETS) +.PHONY: test test-all test-cover benchmark run-tests build-tests $(TEST_TARGETS) ############################## # Test Network Targets diff --git a/app/params/amino.go b/app/params/amino.go deleted file mode 100644 index c7d8ba0045..0000000000 --- a/app/params/amino.go +++ /dev/null @@ -1,27 +0,0 @@ -//go:build test_amino -// +build test_amino - -package params - -import ( - "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" -) - -// MakeTestEncodingConfig creates an EncodingConfig for an amino based test configuration. -// This function should be used only internally (in the SDK). -// App user shouldn't create new codecs - use the app.AppCodec instead. -// [DEPRECATED] -func MakeTestEncodingConfig() EncodingConfig { - cdc := codec.NewLegacyAmino() - interfaceRegistry := types.NewInterfaceRegistry() - marshaler := codec.NewAminoCodec(cdc) - - return EncodingConfig{ - InterfaceRegistry: interfaceRegistry, - Marshaler: marshaler, - TxConfig: legacytx.StdTxConfig{Cdc: cdc}, - Amino: cdc, - } -} diff --git a/app/params/proto.go b/app/params/proto.go index e046afbd7b..5384fc046b 100644 --- a/app/params/proto.go +++ b/app/params/proto.go @@ -1,10 +1,8 @@ -//go:build !test_amino -// +build !test_amino - package params import ( "cosmossdk.io/x/tx/signing" + "github.com/cosmos/cosmos-sdk/codec" amino "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/address" From 79eb6094204f947ea0ea5520bd50fbf446a00f9e Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Fri, 12 Apr 2024 14:19:18 -0600 Subject: [PATCH 10/22] [1760]: Untab the make build comment about removing the delay so that it's actually a comment rather than a command that's printed. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 29121ff748..24f7eb6c6f 100644 --- a/Makefile +++ b/Makefile @@ -132,7 +132,7 @@ install: go.sum CGO_LDFLAGS="$(CGO_LDFLAGS)" CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) install $(BUILD_FLAGS) ./cmd/provenanced build: validate-go-version go.sum - # TODO[1760]: Remove this delay once we're stable again. +# TODO[1760]: Remove this delay once we're stable again. @if [ -z "${ACK_50}" ]; then printf '\033[93mWARNING:\033[0m This branch is currently unstable and should not be built for use.\n To bypass this 10 second delay: ACK_50=1 make build\n'; sleep 10; fi mkdir -p $(BUILDDIR) CGO_LDFLAGS="$(CGO_LDFLAGS)" CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) build -o $(BUILDDIR)/ $(BUILD_FLAGS) ./cmd/provenanced From 9e32e69fbb17fd510821d8df29bfc4018c30ce32 Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Fri, 12 Apr 2024 14:30:29 -0600 Subject: [PATCH 11/22] [1760]: Refactor the make build-tests target to behave just use the same flow as make test, and also give it the same tags. --- Makefile | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 24f7eb6c6f..e231de08ec 100644 --- a/Makefile +++ b/Makefile @@ -331,12 +331,14 @@ PACKAGES_NOSIMULATION := $(filter-out %/simulation%,$(PACKAGES)) PACKAGES_SIMULATION := $(filter %/simulation%,$(PACKAGES)) TEST_PACKAGES=./... -TEST_TARGETS := test-unit test-unit-proto test-ledger-mock test-race test-ledger +TEST_TARGETS := test-unit test-unit-proto test-ledger-mock test-race test-ledger build-tests # Test runs-specific rules. To add a new test target, just add # a new rule, customise TAGS, ARGS and/or TEST_PACKAGES ad libitum, and # append the new rule to the TEST_TARGETS list. test-unit: TAGS+=cgo ledger test_ledger_mock norace +build-tests: TAGS+=cgo ledger test_ledger_mock norace +build-tests: ARGS+=-run='ZYX_NOPE_NOPE_XYZ' test-ledger: TAGS+=cgo ledger norace test-ledger-mock: TAGS+=ledger test_ledger_mock norace test-race: ARGS+=-race @@ -351,13 +353,6 @@ else $(GO) test -mod=readonly $(ARGS) -tags='$(TAGS)' $(TEST_PACKAGES) endif -build-tests: go.sum -ifneq (,$(shell which tparse 2>/dev/null)) - $(GO) test -mod=readonly -json $(ARGS) -tags='$(TAGS)' -run='ZYX_NOPE_NOPE_XYZ' $(TEST_PACKAGES) | tparse -else - $(GO) test -mod=readonly $(ARGS) -tags='$(TAGS)' -run='ZYX_NOPE_NOPE_XYZ' $(TEST_PACKAGES) -endif - test-cover: export VERSION=$(VERSION); bash -x contrib/test_cover.sh From 8dd3b4943b82577dc088195c7b6aebb2beed6218 Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Fri, 12 Apr 2024 14:35:08 -0600 Subject: [PATCH 12/22] [1760]: Update a TODO comment that is now half done. --- app/params/proto.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/params/proto.go b/app/params/proto.go index 5384fc046b..983cf7159f 100644 --- a/app/params/proto.go +++ b/app/params/proto.go @@ -17,8 +17,7 @@ import ( // App user shouldn't create new codecs - use the app.AppCodec instead. // // TODO[1760]: Update all the simulation stuff that uses this to instead get what's needed from the SimState. -// That will involve passing the SimSate into many places where we used to provide a codec. -// Then delete this file and amino.go, and clean up stuff in the Makefile that uses the test_amino tag. +// That will involve passing the SimSate into many places where we used to provide a codec. Then, delete this file. // // Deprecated: Either get this from the app (app.GetEncodingConfig()) or use MakeTestEncodingConfig (from the app package), // or get what's needed from the SimSate. From fbc6e55af9baedc469347c156c980fe41f3a1cb7 Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Fri, 12 Apr 2024 14:36:20 -0600 Subject: [PATCH 13/22] [1760]: Use a BaseKeeper for the bank keeper instead of the Keeper interface since that interface doesn't have InputOutputCoinsProv. --- app/app.go | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/app/app.go b/app/app.go index 28b34dbb5e..786c93615f 100644 --- a/app/app.go +++ b/app/app.go @@ -8,21 +8,20 @@ import ( "path/filepath" "strings" - "github.com/CosmWasm/wasmd/x/wasm" - wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" - wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" "github.com/gorilla/mux" "github.com/rakyll/statik/fs" "github.com/spf13/cast" "github.com/spf13/viper" + "github.com/CosmWasm/wasmd/x/wasm" + wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" + wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" + abci "github.com/cometbft/cometbft/abci/types" cmtos "github.com/cometbft/cometbft/libs/os" "cosmossdk.io/log" sdkmath "cosmossdk.io/math" - "cosmossdk.io/x/tx/signing" - storetypes "cosmossdk.io/store/types" "cosmossdk.io/x/evidence" evidencekeeper "cosmossdk.io/x/evidence/keeper" @@ -30,12 +29,10 @@ import ( "cosmossdk.io/x/feegrant" feegrantkeeper "cosmossdk.io/x/feegrant/keeper" feegrantmodule "cosmossdk.io/x/feegrant/module" + "cosmossdk.io/x/tx/signing" "cosmossdk.io/x/upgrade" upgradekeeper "cosmossdk.io/x/upgrade/keeper" upgradetypes "cosmossdk.io/x/upgrade/types" - "github.com/cosmos/cosmos-sdk/codec/address" - "github.com/cosmos/cosmos-sdk/std" - "github.com/cosmos/gogoproto/proto" icq "github.com/cosmos/ibc-apps/modules/async-icq/v8" icqkeeper "github.com/cosmos/ibc-apps/modules/async-icq/v8/keeper" @@ -45,6 +42,10 @@ import ( // quarantinekeeper "github.com/cosmos/cosmos-sdk/x/quarantine/keeper" // TODO[1760]: quarantine // quarantinemodule "github.com/cosmos/cosmos-sdk/x/quarantine/module" // TODO[1760]: quarantine + "github.com/cosmos/cosmos-sdk/codec/address" + "github.com/cosmos/cosmos-sdk/std" + "github.com/cosmos/gogoproto/proto" + dbm "github.com/cosmos/cosmos-db" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" @@ -250,7 +251,7 @@ type App struct { // keepers AccountKeeper authkeeper.AccountKeeper - BankKeeper bankkeeper.Keeper + BankKeeper *bankkeeper.BaseKeeper CapabilityKeeper *capabilitykeeper.Keeper StakingKeeper *stakingkeeper.Keeper SlashingKeeper slashingkeeper.Keeper @@ -443,7 +444,7 @@ func New( // add keepers app.AccountKeeper = authkeeper.NewAccountKeeper(appCodec, runtime.NewKVStoreService(keys[authtypes.StoreKey]), authtypes.ProtoBaseAccount, maccPerms, authcodec.NewBech32Codec(addrPrefix), addrPrefix, govAuthority) - app.BankKeeper = bankkeeper.NewBaseKeeper( + bankKeeper := bankkeeper.NewBaseKeeper( appCodec, runtime.NewKVStoreService(keys[banktypes.StoreKey]), app.AccountKeeper, @@ -451,6 +452,7 @@ func New( govAuthority, logger, ) + app.BankKeeper = &bankKeeper // optional: enable sign mode textual by overwriting the default tx config (after setting the bank keeper) enabledSignModes := append(tx.DefaultSignModes, sigtypes.SignMode_SIGN_MODE_TEXTUAL) From 6755def46e93080eb2e76204314ae7ff8903986c Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Fri, 12 Apr 2024 14:37:52 -0600 Subject: [PATCH 14/22] [1760]: Fix the exchange mock bank keeper to have InputOutputCoinsProv instead of the old one. --- x/exchange/keeper/mocks_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/exchange/keeper/mocks_test.go b/x/exchange/keeper/mocks_test.go index b6f5c12b52..bd8ff6e11f 100644 --- a/x/exchange/keeper/mocks_test.go +++ b/x/exchange/keeper/mocks_test.go @@ -354,7 +354,7 @@ func (k *MockBankKeeper) SendCoinsFromAccountToModule(ctx context.Context, sende return err } -func (k *MockBankKeeper) InputOutputCoins(ctx context.Context, inputs []banktypes.Input, outputs []banktypes.Output) error { +func (k *MockBankKeeper) InputOutputCoinsProv(ctx context.Context, inputs []banktypes.Input, outputs []banktypes.Output) error { k.Calls.InputOutputCoins = append(k.Calls.InputOutputCoins, NewInputOutputCoinsArgs(ctx, inputs, outputs)) var err error if len(k.InputOutputCoinsResultsQueue) > 0 { From 802e6f9abbea98701798cfd5a6333dcddc3898ab Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Fri, 12 Apr 2024 14:52:47 -0600 Subject: [PATCH 15/22] [1760]: Use a concrete bank BaseKeeper in the app instead of a reference to one because there's some deep down-stream wiring stuff that assumes it's concrete. --- app/app.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/app.go b/app/app.go index 786c93615f..6fa42142ce 100644 --- a/app/app.go +++ b/app/app.go @@ -251,7 +251,7 @@ type App struct { // keepers AccountKeeper authkeeper.AccountKeeper - BankKeeper *bankkeeper.BaseKeeper + BankKeeper bankkeeper.BaseKeeper CapabilityKeeper *capabilitykeeper.Keeper StakingKeeper *stakingkeeper.Keeper SlashingKeeper slashingkeeper.Keeper @@ -444,7 +444,7 @@ func New( // add keepers app.AccountKeeper = authkeeper.NewAccountKeeper(appCodec, runtime.NewKVStoreService(keys[authtypes.StoreKey]), authtypes.ProtoBaseAccount, maccPerms, authcodec.NewBech32Codec(addrPrefix), addrPrefix, govAuthority) - bankKeeper := bankkeeper.NewBaseKeeper( + app.BankKeeper = bankkeeper.NewBaseKeeper( appCodec, runtime.NewKVStoreService(keys[banktypes.StoreKey]), app.AccountKeeper, @@ -452,7 +452,6 @@ func New( govAuthority, logger, ) - app.BankKeeper = &bankKeeper // optional: enable sign mode textual by overwriting the default tx config (after setting the bank keeper) enabledSignModes := append(tx.DefaultSignModes, sigtypes.SignMode_SIGN_MODE_TEXTUAL) From abaed0a0442787115586dbcfc058aa1d29aeb16e Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Fri, 12 Apr 2024 15:11:59 -0600 Subject: [PATCH 16/22] [1760]: Update the hold tests that check spendable balances. The actual test is commented out right now until the quarantine PR merges that has the needed query helper. --- x/hold/client/cli/cli_test.go | 63 +++++++++++++++-------------------- 1 file changed, 27 insertions(+), 36 deletions(-) diff --git a/x/hold/client/cli/cli_test.go b/x/hold/client/cli/cli_test.go index 1ced76734f..83349227b2 100644 --- a/x/hold/client/cli/cli_test.go +++ b/x/hold/client/cli/cli_test.go @@ -6,11 +6,12 @@ import ( "testing" "time" - "github.com/cosmos/gogoproto/proto" "github.com/ghodss/yaml" "github.com/spf13/cobra" "github.com/stretchr/testify/suite" + "github.com/cosmos/gogoproto/proto" + cmtcli "github.com/cometbft/cometbft/libs/cli" "github.com/cosmos/cosmos-sdk/client/flags" @@ -130,8 +131,8 @@ func (s *IntegrationCLITestSuite) SetupSuite() { // - One denom fully on hold. s.addr1Desc = "addr with large amounts" addr1Plus := "15banana,5000000000000000000000hugecoin,1xenon" - addr1Esrow := "5banana,2000000000000000000000hugecoin,1xenon" - s.addr1Bal, s.addr1Hold, s.addr1Spendable = newAmounts("addr1", addr1Plus, addr1Esrow) + addr1Escrow := "5banana,2000000000000000000000hugecoin,1xenon" + s.addr1Bal, s.addr1Hold, s.addr1Spendable = newAmounts("addr1", addr1Plus, addr1Escrow) // addr2 characteristics: // - One extra denom. @@ -505,53 +506,43 @@ func (s *IntegrationCLITestSuite) TestQueryCmdGetAllHolds() { func (s *IntegrationCLITestSuite) TestHoldsNotInFromSpendable() { // The purpose of these tests is to make sure that the bank module is // being properly informed of the locked hold funds. - cmdGen := func() *cobra.Command { - // TODO[1760]: bank: Put this back once we know how to query spendable balances again. - return nil - // return bankcli.GetSpendableBalancesCmd() - } - resp := func(balances sdk.Coins) *banktypes.QuerySpendableBalancesResponse { - return &banktypes.QuerySpendableBalancesResponse{ - Balances: balances, - Pagination: &query.PageResponse{ - NextKey: nil, - Total: 0, - }, - } - } - - tests := []queryCmdTestCase{ + tests := []struct { + name string + addr sdk.AccAddress + exp sdk.Coins + }{ { - name: s.addr1Desc + ": get spendable", - args: []string{s.addr1.String(), s.flagAsJSON}, - expOut: s.asJSON(resp(s.addr1Spendable)), + name: s.addr1Desc + ": get spendable", + addr: s.addr1, + exp: s.addr1Spendable, }, { - name: s.addr2Desc + ": get spendable", - args: []string{s.addr2.String(), s.flagAsJSON}, - expOut: s.asJSON(resp(s.addr2Spendable)), + name: s.addr2Desc + ": get spendable", + addr: s.addr2, + exp: s.addr2Spendable, }, { - name: s.addr3Desc + ": get spendable", - args: []string{s.addr3.String(), s.flagAsJSON}, - expOut: s.asJSON(resp(s.addr3Spendable)), + name: s.addr3Desc + ": get spendable", + addr: s.addr3, + exp: s.addr3Spendable, }, { - name: s.addr4Desc + ": get spendable", - args: []string{s.addr4.String(), s.flagAsJSON}, - expOut: s.asJSON(resp(s.addr4Spendable)), + name: s.addr4Desc + ": get spendable", + addr: s.addr4, + exp: s.addr4Spendable, }, { - name: s.addr5Desc + ": get spendable", - args: []string{s.addr5.String(), s.flagAsJSON}, - expOut: s.asJSON(resp(s.addr5Spendable)), + name: s.addr5Desc + ": get spendable", + addr: s.addr5, + exp: s.addr5Spendable, }, } for _, tc := range tests { s.Run(tc.name, func() { - tc.cmd = cmdGen() - s.assertQueryCmdTestCase(tc) + // TODO[1760]: Uncomment this once the quarantine PR has merged. + //actual := queries.GetSpendableBalances(s.T(), s.testnet, tc.addr.String()) + //s.Assert().Equal(tc.exp, actual, "spendable balances") }) } } From 9acb147caf457b1497e28b5430e09fc17b25d219 Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Mon, 15 Apr 2024 11:12:31 -0600 Subject: [PATCH 17/22] [1760]: Bump the sdk to v0.50.5-pio-3 (from v0.50.5-pio-2). --- go.mod | 4 +--- go.sum | 2 ++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 7a4c3d03c4..c5599e5824 100644 --- a/go.mod +++ b/go.mod @@ -214,9 +214,7 @@ replace ( // This is required for https://github.com/provenance-io/provenance/issues/1414 // TODO[1760]: wasm: Put this CosmWasm/wasmd replace back with an updated version (or delete it). // github.com/CosmWasm/wasmd => github.com/provenance-io/wasmd v0.30.0-pio-5 - // TODO[1760]: sdk: Put this replace back with an updated version of the sdk from our fork. - // github.com/cosmos/cosmos-sdk => github.com/provenance-io/cosmos-sdk v0.50.5-pio-2 - github.com/cosmos/cosmos-sdk => ../prov-cosmos-sdk + github.com/cosmos/cosmos-sdk => github.com/provenance-io/cosmos-sdk v0.50.5-pio-3 // TODO[1760]: Update once async-icq creates tag with our changes https://github.com/cosmos/ibc-apps/pull/168 github.com/cosmos/ibc-apps/modules/async-icq/v8 => github.com/provenance-io/ibc-apps/modules/async-icq/v8 v8.0.0-prov-1 diff --git a/go.sum b/go.sum index 6a4f2becdc..c7a3c42cc4 100644 --- a/go.sum +++ b/go.sum @@ -914,6 +914,8 @@ github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4O github.com/prometheus/procfs v0.3.0/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo= github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo= +github.com/provenance-io/cosmos-sdk v0.50.5-pio-3 h1:QwJ4feMM43a9fu2YZ1oSHd1wqEIsANDdqXKsoOin85Q= +github.com/provenance-io/cosmos-sdk v0.50.5-pio-3/go.mod h1:oV/k6GJgXV9QPoM2fsYDPPsyPBgQbdotv532O6Mz1OQ= github.com/provenance-io/ibc-apps/modules/async-icq/v8 v8.0.0-prov-1 h1:p+7pxHB0ukO2aow+M6uW9gHgeQl7YJyYGyMSKHZ5My8= github.com/provenance-io/ibc-apps/modules/async-icq/v8 v8.0.0-prov-1/go.mod h1:tObW9uxibh5Z22CtOaHVeTDotCSMyc/2B4MrYdaViBo= github.com/rakyll/statik v0.1.7 h1:OF3QCZUuyPxuGEP7B4ypUa7sB/iHtqOTDYZXGM8KOdQ= From a586f05709ada640be2539f24ad190b7c2afb9f6 Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Mon, 15 Apr 2024 11:33:12 -0600 Subject: [PATCH 18/22] [1760]: Allow defining the TEST_PACKAGES used in the make test target. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index e231de08ec..b7a34cd5c7 100644 --- a/Makefile +++ b/Makefile @@ -330,7 +330,7 @@ PACKAGES := $(shell $(GO) list ./... 2>/dev/null || true) PACKAGES_NOSIMULATION := $(filter-out %/simulation%,$(PACKAGES)) PACKAGES_SIMULATION := $(filter %/simulation%,$(PACKAGES)) -TEST_PACKAGES=./... +TEST_PACKAGES ?= ./... TEST_TARGETS := test-unit test-unit-proto test-ledger-mock test-race test-ledger build-tests # Test runs-specific rules. To add a new test target, just add From 445ee34ac4fcc6d38be940e11605010752f15246 Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Mon, 15 Apr 2024 11:59:30 -0600 Subject: [PATCH 19/22] [1760]: Add the migration of bank params to the umber upgrade. --- app/upgrades.go | 42 +++++++++++++++++++++++++++++++++++++----- app/upgrades_test.go | 4 ++++ 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/app/upgrades.go b/app/upgrades.go index 01e34518db..378fa082a7 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -6,9 +6,11 @@ import ( storetypes "cosmossdk.io/store/types" upgradetypes "cosmossdk.io/x/upgrade/types" + "github.com/cosmos/cosmos-sdk/baseapp" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types" paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" "github.com/cosmos/ibc-go/v8/modules/core/exported" @@ -46,7 +48,7 @@ var upgrades = map[string]appUpgrade{ Handler: func(ctx sdk.Context, app *App, vm module.VersionMap) (module.VersionMap, error) { var err error - if err := pruneIBCExpiredConsensusStates(ctx, app); err != nil { + if err = pruneIBCExpiredConsensusStates(ctx, app); err != nil { return nil, err } @@ -55,6 +57,11 @@ var upgrades = map[string]appUpgrade{ return nil, err } + err = migrateBankParams(ctx, app) + if err != nil { + return nil, err + } + vm, err = runModuleMigrations(ctx, app, vm) if err != nil { return nil, err @@ -76,7 +83,7 @@ var upgrades = map[string]appUpgrade{ Handler: func(ctx sdk.Context, app *App, vm module.VersionMap) (module.VersionMap, error) { var err error - if err := pruneIBCExpiredConsensusStates(ctx, app); err != nil { + if err = pruneIBCExpiredConsensusStates(ctx, app); err != nil { return nil, err } @@ -85,6 +92,10 @@ var upgrades = map[string]appUpgrade{ return nil, err } + err = migrateBankParams(ctx, app) + if err != nil { + return nil, err + } vm, err = runModuleMigrations(ctx, app, vm) if err != nil { return nil, err @@ -188,7 +199,7 @@ var _ = runModuleMigrations // removeInactiveValidatorDelegations unbonds all delegations from inactive validators, triggering their removal from the validator set. // This should be applied in most upgrades. func removeInactiveValidatorDelegations(ctx sdk.Context, app *App) { - ctx.Logger().Info(fmt.Sprintf("Removing inactive validator delegations.")) + ctx.Logger().Info("Removing inactive validator delegations.") sParams, perr := app.StakingKeeper.GetParams(ctx) if perr != nil { @@ -251,7 +262,7 @@ func pruneIBCExpiredConsensusStates(ctx sdk.Context, app *App) error { ctx.Logger().Info("Pruning expired consensus states for IBC.") _, err := ibctmmigrations.PruneExpiredConsensusStates(ctx, app.appCodec, app.IBCKeeper.ClientKeeper) if err != nil { - ctx.Logger().Error(fmt.Sprintf("unable to prune expired consensus states, error: %s.", err)) + ctx.Logger().Error(fmt.Sprintf("Unable to prune expired consensus states, error: %s.", err)) return err } ctx.Logger().Info("Done pruning expired consensus states for IBC.") @@ -276,9 +287,30 @@ func migrateBaseappParams(ctx sdk.Context, app *App) error { legacyBaseAppSubspace := app.ParamsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramstypes.ConsensusParamsKeyTable()) err := baseapp.MigrateParams(ctx, legacyBaseAppSubspace, app.ConsensusParamsKeeper.ParamsStore) if err != nil { - ctx.Logger().Error(fmt.Sprintf("unable to migrate legacy params to ConsensusParamsKeeper, error: %s.", err)) + ctx.Logger().Error(fmt.Sprintf("Unable to migrate legacy params to ConsensusParamsKeeper, error: %s.", err)) return err } ctx.Logger().Info("Done migrating legacy params.") return nil } + +// migrateBankParams migrates the bank params from the params module to the bank module's state. +// The SDK has this as part of their bank v4 migration, but we're already on v4, so that one +// won't run on its own. This is the only part of that migration that we still need to have +// done, and this brings us in-line with format the bank state on v4. +// TODO: delete with the umber handlers. +func migrateBankParams(ctx sdk.Context, app *App) (err error) { + ctx.Logger().Info("Migrating bank params.") + defer func() { + if err != nil { + ctx.Logger().Error(fmt.Sprintf("Unable to migrate bank params, error: %s.", err)) + } + ctx.Logger().Info("Done migrating bank params.") + }() + + bankParamsSpace, ok := app.ParamsKeeper.GetSubspace(banktypes.ModuleName) + if !ok { + return fmt.Errorf("params subspace not found: %q", banktypes.ModuleName) + } + return app.BankKeeper.MigrateParamsProv(ctx, bankParamsSpace) +} diff --git a/app/upgrades_test.go b/app/upgrades_test.go index 96495d8e2a..18b6f7888b 100644 --- a/app/upgrades_test.go +++ b/app/upgrades_test.go @@ -379,6 +379,8 @@ func (s *UpgradeTestSuite) TestUmberRC1() { "INF Done pruning expired consensus states for IBC.", "INF Migrating legacy params.", "INF Done migrating legacy params.", + "INF Migrating bank params.", + "INF Done migrating bank params.", "INF Updating IBC AllowedClients.", "INF Done updating IBC AllowedClients.", "INF Starting module migrations. This may take a significant amount of time to complete. Do not restart node.", @@ -394,6 +396,8 @@ func (s *UpgradeTestSuite) TestUmber() { "INF Done pruning expired consensus states for IBC.", "INF Migrating legacy params.", "INF Done migrating legacy params.", + "INF Migrating bank params.", + "INF Done migrating bank params.", "INF Updating IBC AllowedClients.", "INF Done updating IBC AllowedClients.", "INF Starting module migrations. This may take a significant amount of time to complete. Do not restart node.", From 4b1883c29a32cc167f13a935cc9d305ee6c42f68 Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Mon, 15 Apr 2024 12:02:57 -0600 Subject: [PATCH 20/22] [1760]: Add changelog entry. --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 76b52304f7..6b8a06d8b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -54,6 +54,9 @@ Ref: https://keepachangelog.com/en/1.0.0/ * Bump the SDK to `v0.50.5-pio-1` (from an earlier ephemeral version) [#1897](https://github.com/provenance-io/provenance/pull/1897). * Removed `rewards` module [#1905](https://github.com/provenance-io/provenance/pull/1905). * Remove unused navs [#1920](https://github.com/provenance-io/provenance/issues/1920). +* 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). ### Dependencies From 01fab974d63bc5e14d17418290d11a43cdc10831 Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Mon, 15 Apr 2024 12:26:37 -0600 Subject: [PATCH 21/22] [1760]: Uncomment the hold cli unit test that gets spendable balances so that once the quarantine PR is merged, this will be ready too. --- x/hold/client/cli/cli_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/x/hold/client/cli/cli_test.go b/x/hold/client/cli/cli_test.go index 83349227b2..a0e8cd6ca6 100644 --- a/x/hold/client/cli/cli_test.go +++ b/x/hold/client/cli/cli_test.go @@ -25,6 +25,7 @@ import ( "github.com/provenance-io/provenance/internal/antewrapper" "github.com/provenance-io/provenance/internal/pioconfig" "github.com/provenance-io/provenance/testutil" + "github.com/provenance-io/provenance/testutil/queries" "github.com/provenance-io/provenance/x/hold" "github.com/provenance-io/provenance/x/hold/client/cli" holdkeeper "github.com/provenance-io/provenance/x/hold/keeper" @@ -540,9 +541,8 @@ func (s *IntegrationCLITestSuite) TestHoldsNotInFromSpendable() { for _, tc := range tests { s.Run(tc.name, func() { - // TODO[1760]: Uncomment this once the quarantine PR has merged. - //actual := queries.GetSpendableBalances(s.T(), s.testnet, tc.addr.String()) - //s.Assert().Equal(tc.exp, actual, "spendable balances") + actual := queries.GetSpendableBalances(s.T(), s.testnet, tc.addr.String()) + s.Assert().Equal(tc.exp, actual, "spendable balances") }) } } From 007046be42db9fe5e3bc24736d612271b7495803 Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Mon, 15 Apr 2024 12:27:52 -0600 Subject: [PATCH 22/22] [1760]: Do a string comparison of the coins in TestHoldsNotInFromSpendable. --- x/hold/client/cli/cli_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/hold/client/cli/cli_test.go b/x/hold/client/cli/cli_test.go index a0e8cd6ca6..f6fdd85566 100644 --- a/x/hold/client/cli/cli_test.go +++ b/x/hold/client/cli/cli_test.go @@ -542,7 +542,7 @@ func (s *IntegrationCLITestSuite) TestHoldsNotInFromSpendable() { for _, tc := range tests { s.Run(tc.name, func() { actual := queries.GetSpendableBalances(s.T(), s.testnet, tc.addr.String()) - s.Assert().Equal(tc.exp, actual, "spendable balances") + s.Assert().Equal(tc.exp.String(), actual.String(), "spendable balances") }) } }