diff --git a/README.md b/README.md index 49fd55c..0f41f54 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ If you haven't already, install Golang by following the [official docs](https:// Requirement | Notes ----------- | ----------------- Go version | Go1.16 or higher -Cosmos SDK | v0.44.2 or higher +Cosmos SDK | v0.44.3 or higher ### Installation diff --git a/x/budget/client/cli/flags.go b/x/budget/client/cli/flags.go index 034ace4..e09d199 100644 --- a/x/budget/client/cli/flags.go +++ b/x/budget/client/cli/flags.go @@ -29,7 +29,6 @@ func flagSetAddress() *flag.FlagSet { fs.String(FlagType, "", "The Address Type, default 0 for ADDRESS_TYPE_32_BYTES or 1 for ADDRESS_TYPE_20_BYTES") fs.String(FlagModuleName, "", "The module name to be used for address derivation, default is budget when type 0") - //fs.String(FlagName, "", "The name to be used for address derivation") return fs } diff --git a/x/budget/client/cli/query.go b/x/budget/client/cli/query.go index 3d90583..3f9e1d3 100644 --- a/x/budget/client/cli/query.go +++ b/x/budget/client/cli/query.go @@ -130,11 +130,11 @@ $ %s query %s budgets --destination-address %s1zaavvzxez0elundtn32qnk9lkm8kmcszz // GetCmdQueryAddress implements the query an address that can be used as source and destination is derived according to the given type, module name, and name command. func GetCmdQueryAddress() *cobra.Command { cmd := &cobra.Command{ - Use: "address", + Use: "address [name]", Args: cobra.ExactArgs(1), - Short: "Query an address that derived can be used as source and destination", + Short: "Query an address that can be used as source or destination address", Long: strings.TrimSpace( - fmt.Sprintf(`Query an address that can be used as source and destination is derived according to the given name, module name, and type. + fmt.Sprintf(`Query an address that can be used as source or destination address. It is derived with address derivation name, module name, and address type. Example: $ %s query %s address testSourceAddr @@ -143,7 +143,7 @@ $ %s query %s address GravityDEXFarmingBudget --module-name farming Default flag: $ [--type 0] - ADDRESS_TYPE_32_BYTES of ADR 028 -$ [--module-name %s] - When B, the default module name is %s +$ [--module-name %s] - When type is 0, the default module name is %s `, version.AppName, types.ModuleName, version.AppName, types.ModuleName, diff --git a/x/budget/keeper/budget_test.go b/x/budget/keeper/budget_test.go index 100457c..2587bab 100644 --- a/x/budget/keeper/budget_test.go +++ b/x/budget/keeper/budget_test.go @@ -3,6 +3,7 @@ package keeper_test import ( "time" + "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" paramscutils "github.com/cosmos/cosmos-sdk/x/params/client/utils" "github.com/cosmos/cosmos-sdk/x/params/types/proposal" @@ -183,6 +184,10 @@ func (suite *KeeperTestSuite) TestBudgetChangeSituation() { suite.ctx = suite.ctx.WithBlockTime(types.MustParseRFC3339("2021-08-01T00:00:00Z")) suite.ctx = suite.ctx.WithBlockHeight(int64(height)) + // cosmos10wy60v3zuks7rkwnqxs3e878zqfhus6m98l77q6rppz40kxwgllsruc0az + // inflation occurs by 1000000000denom1,1000000000denom2,1000000000denom3,1000000000stake every blocks + budgetSource := types.DeriveAddress(types.AddressType32Bytes, types.ModuleName, "InflationPool") + for _, tc := range []struct { name string proposal *proposal.ParameterChangeProposal @@ -191,6 +196,8 @@ func (suite *KeeperTestSuite) TestBudgetChangeSituation() { govTime time.Time nextBlockTime time.Time expErr error + accAsserts []sdk.AccAddress + balanceAsserts []sdk.Coins }{ { "add budget 1", @@ -199,10 +206,10 @@ func (suite *KeeperTestSuite) TestBudgetChangeSituation() { Key: string(types.KeyBudgets), Value: `[ { - "name": "gravity-dex-farming-20213Q-20313Q", + "name": "gravity-dex-farming-1", "rate": "0.500000000000000000", - "source_address": "cosmos17xpfvakm2amg962yls6f84z3kell8c5lserqta", - "destination_address": "cosmos1228ryjucdpdv3t87rxle0ew76a56ulvnfst0hq0sscd3nafgjpqqkcxcky", + "source_address": "cosmos10wy60v3zuks7rkwnqxs3e878zqfhus6m98l77q6rppz40kxwgllsruc0az", + "destination_address": "cosmos1qceyjmnrl6hapntjq3z25vn38nh68u7yxvufs2thptxvqm7huxeqj7zyrq", "start_time": "2021-09-01T00:00:00Z", "end_time": "2031-09-30T00:00:00Z" } @@ -213,6 +220,13 @@ func (suite *KeeperTestSuite) TestBudgetChangeSituation() { types.MustParseRFC3339("2021-08-01T00:00:00Z"), types.MustParseRFC3339("2021-08-01T00:00:00Z"), nil, + []sdk.AccAddress{budgetSource, suite.destinationAddrs[0], suite.destinationAddrs[1], suite.destinationAddrs[2]}, + []sdk.Coins{ + mustParseCoinsNormalized("1000000000denom1,1000000000denom2,1000000000denom3,1000000000stake"), + {}, + {}, + {}, + }, }, { "add budget 2", @@ -221,18 +235,18 @@ func (suite *KeeperTestSuite) TestBudgetChangeSituation() { Key: string(types.KeyBudgets), Value: `[ { - "name": "gravity-dex-farming-20213Q-20313Q", + "name": "gravity-dex-farming-1", "rate": "0.500000000000000000", - "source_address": "cosmos17xpfvakm2amg962yls6f84z3kell8c5lserqta", - "destination_address": "cosmos1228ryjucdpdv3t87rxle0ew76a56ulvnfst0hq0sscd3nafgjpqqkcxcky", + "source_address": "cosmos10wy60v3zuks7rkwnqxs3e878zqfhus6m98l77q6rppz40kxwgllsruc0az", + "destination_address": "cosmos1qceyjmnrl6hapntjq3z25vn38nh68u7yxvufs2thptxvqm7huxeqj7zyrq", "start_time": "2021-09-01T00:00:00Z", "end_time": "2031-09-30T00:00:00Z" }, { "name": "gravity-dex-farming-2", "rate": "0.500000000000000000", - "source_address": "cosmos17xpfvakm2amg962yls6f84z3kell8c5lserqta", - "destination_address": "cosmos1m63436cdxnu9ymyj02e7k3xljkn8klyf5ahqa75degq748xxkmksvtlp8n", + "source_address": "cosmos10wy60v3zuks7rkwnqxs3e878zqfhus6m98l77q6rppz40kxwgllsruc0az", + "destination_address": "cosmos1czyx0dj2yd26gv3stpxzv23ddy8pld4j6p90a683mdcg8vzy72jqa8tm6p", "start_time": "2021-09-01T00:00:00Z", "end_time": "2021-09-30T00:00:00Z" } @@ -243,6 +257,13 @@ func (suite *KeeperTestSuite) TestBudgetChangeSituation() { types.MustParseRFC3339("2021-09-03T00:00:00Z"), types.MustParseRFC3339("2021-09-03T00:00:00Z"), nil, + []sdk.AccAddress{budgetSource, suite.destinationAddrs[0], suite.destinationAddrs[1], suite.destinationAddrs[2]}, + []sdk.Coins{ + {}, + mustParseCoinsNormalized("1000000000denom1,1000000000denom2,1000000000denom3,1000000000stake"), + mustParseCoinsNormalized("1000000000denom1,1000000000denom2,1000000000denom3,1000000000stake"), + {}, + }, }, { "add budget 3 with invalid total rate case 1", @@ -251,36 +272,43 @@ func (suite *KeeperTestSuite) TestBudgetChangeSituation() { Key: string(types.KeyBudgets), Value: `[ { - "name": "gravity-dex-farming-20213Q-20313Q", + "name": "gravity-dex-farming-1", "rate": "0.500000000000000000", - "source_address": "cosmos17xpfvakm2amg962yls6f84z3kell8c5lserqta", - "destination_address": "cosmos1228ryjucdpdv3t87rxle0ew76a56ulvnfst0hq0sscd3nafgjpqqkcxcky", + "source_address": "cosmos10wy60v3zuks7rkwnqxs3e878zqfhus6m98l77q6rppz40kxwgllsruc0az", + "destination_address": "cosmos1qceyjmnrl6hapntjq3z25vn38nh68u7yxvufs2thptxvqm7huxeqj7zyrq", "start_time": "2021-09-01T00:00:00Z", "end_time": "2031-09-30T00:00:00Z" }, { "name": "gravity-dex-farming-2", "rate": "0.500000000000000000", - "source_address": "cosmos17xpfvakm2amg962yls6f84z3kell8c5lserqta", - "destination_address": "cosmos1m63436cdxnu9ymyj02e7k3xljkn8klyf5ahqa75degq748xxkmksvtlp8n", + "source_address": "cosmos10wy60v3zuks7rkwnqxs3e878zqfhus6m98l77q6rppz40kxwgllsruc0az", + "destination_address": "cosmos1czyx0dj2yd26gv3stpxzv23ddy8pld4j6p90a683mdcg8vzy72jqa8tm6p", "start_time": "2021-09-01T00:00:00Z", "end_time": "2021-09-30T00:00:00Z" }, { "name": "gravity-dex-farming-3", "rate": "0.500000000000000000", - "source_address": "cosmos17xpfvakm2amg962yls6f84z3kell8c5lserqta", - "destination_address": "cosmos17avp6xs5c8ycqzy20yv99ccxwunu32e507kpm8ql5nfg47pzj9qqxhujxr", + "source_address": "cosmos10wy60v3zuks7rkwnqxs3e878zqfhus6m98l77q6rppz40kxwgllsruc0az", + "destination_address": "cosmos1e0n8jmeg4u8q3es2tmhz5zlte8a4q8687ndns8pj4q8grdl74a0sw3045s", "start_time": "2021-09-30T00:00:00Z", "end_time": "2021-10-10T00:00:00Z" } ]`, }), - 0, - 0, + 2, // left last budgets of 2nd tc + 1, // left last budgets of 2nd tc types.MustParseRFC3339("2021-09-29T00:00:00Z"), types.MustParseRFC3339("2021-09-30T00:00:00Z"), types.ErrInvalidTotalBudgetRate, + []sdk.AccAddress{budgetSource, suite.destinationAddrs[0], suite.destinationAddrs[1], suite.destinationAddrs[2]}, + []sdk.Coins{ + mustParseCoinsNormalized("500000000denom1,500000000denom2,500000000denom3,500000000stake"), + mustParseCoinsNormalized("1500000000denom1,1500000000denom2,1500000000denom3,1500000000stake"), + mustParseCoinsNormalized("1000000000denom1,1000000000denom2,1000000000denom3,1000000000stake"), + {}, + }, }, { "add budget 3 with invalid total rate case 2", @@ -289,36 +317,43 @@ func (suite *KeeperTestSuite) TestBudgetChangeSituation() { Key: string(types.KeyBudgets), Value: `[ { - "name": "gravity-dex-farming-20213Q-20313Q", + "name": "gravity-dex-farming-1", "rate": "0.500000000000000000", - "source_address": "cosmos17xpfvakm2amg962yls6f84z3kell8c5lserqta", - "destination_address": "cosmos1228ryjucdpdv3t87rxle0ew76a56ulvnfst0hq0sscd3nafgjpqqkcxcky", + "source_address": "cosmos10wy60v3zuks7rkwnqxs3e878zqfhus6m98l77q6rppz40kxwgllsruc0az", + "destination_address": "cosmos1qceyjmnrl6hapntjq3z25vn38nh68u7yxvufs2thptxvqm7huxeqj7zyrq", "start_time": "2021-09-01T00:00:00Z", "end_time": "2031-09-30T00:00:00Z" }, { "name": "gravity-dex-farming-2", "rate": "0.500000000000000000", - "source_address": "cosmos17xpfvakm2amg962yls6f84z3kell8c5lserqta", - "destination_address": "cosmos1m63436cdxnu9ymyj02e7k3xljkn8klyf5ahqa75degq748xxkmksvtlp8n", + "source_address": "cosmos10wy60v3zuks7rkwnqxs3e878zqfhus6m98l77q6rppz40kxwgllsruc0az", + "destination_address": "cosmos1czyx0dj2yd26gv3stpxzv23ddy8pld4j6p90a683mdcg8vzy72jqa8tm6p", "start_time": "2021-09-01T00:00:00Z", "end_time": "2021-09-30T00:00:00Z" }, { "name": "gravity-dex-farming-3", "rate": "0.500000000000000000", - "source_address": "cosmos17xpfvakm2amg962yls6f84z3kell8c5lserqta", - "destination_address": "cosmos17avp6xs5c8ycqzy20yv99ccxwunu32e507kpm8ql5nfg47pzj9qqxhujxr", + "source_address": "cosmos10wy60v3zuks7rkwnqxs3e878zqfhus6m98l77q6rppz40kxwgllsruc0az", + "destination_address": "cosmos1e0n8jmeg4u8q3es2tmhz5zlte8a4q8687ndns8pj4q8grdl74a0sw3045s", "start_time": "2021-09-30T00:00:00Z", "end_time": "2021-10-10T00:00:00Z" } ]`, }), - 0, - 0, + 2, // left last budgets of 2nd tc + 1, // left last budgets of 2nd tc types.MustParseRFC3339("2021-10-01T00:00:00Z"), types.MustParseRFC3339("2021-10-01T00:00:00Z"), types.ErrInvalidTotalBudgetRate, + []sdk.AccAddress{budgetSource, suite.destinationAddrs[0], suite.destinationAddrs[1], suite.destinationAddrs[2]}, + []sdk.Coins{ + mustParseCoinsNormalized("750000000denom1,750000000denom2,750000000denom3,750000000stake"), + mustParseCoinsNormalized("2250000000denom1,2250000000denom2,2250000000denom3,2250000000stake"), + mustParseCoinsNormalized("1000000000denom1,1000000000denom2,1000000000denom3,1000000000stake"), + {}, + }, }, { "add budget 3", @@ -327,18 +362,18 @@ func (suite *KeeperTestSuite) TestBudgetChangeSituation() { Key: string(types.KeyBudgets), Value: `[ { - "name": "gravity-dex-farming-20213Q-20313Q", + "name": "gravity-dex-farming-1", "rate": "0.500000000000000000", - "source_address": "cosmos17xpfvakm2amg962yls6f84z3kell8c5lserqta", - "destination_address": "cosmos1228ryjucdpdv3t87rxle0ew76a56ulvnfst0hq0sscd3nafgjpqqkcxcky", + "source_address": "cosmos10wy60v3zuks7rkwnqxs3e878zqfhus6m98l77q6rppz40kxwgllsruc0az", + "destination_address": "cosmos1qceyjmnrl6hapntjq3z25vn38nh68u7yxvufs2thptxvqm7huxeqj7zyrq", "start_time": "2021-09-01T00:00:00Z", "end_time": "2031-09-30T00:00:00Z" }, { "name": "gravity-dex-farming-3", "rate": "0.500000000000000000", - "source_address": "cosmos17xpfvakm2amg962yls6f84z3kell8c5lserqta", - "destination_address": "cosmos17avp6xs5c8ycqzy20yv99ccxwunu32e507kpm8ql5nfg47pzj9qqxhujxr", + "source_address": "cosmos10wy60v3zuks7rkwnqxs3e878zqfhus6m98l77q6rppz40kxwgllsruc0az", + "destination_address": "cosmos1e0n8jmeg4u8q3es2tmhz5zlte8a4q8687ndns8pj4q8grdl74a0sw3045s", "start_time": "2021-09-30T00:00:00Z", "end_time": "2021-10-10T00:00:00Z" } @@ -349,6 +384,13 @@ func (suite *KeeperTestSuite) TestBudgetChangeSituation() { types.MustParseRFC3339("2021-10-01T00:00:00Z"), types.MustParseRFC3339("2021-10-01T00:00:00Z"), nil, + []sdk.AccAddress{budgetSource, suite.destinationAddrs[0], suite.destinationAddrs[1], suite.destinationAddrs[2]}, + []sdk.Coins{ + {}, + mustParseCoinsNormalized("3125000000denom1,3125000000denom2,3125000000denom3,3125000000stake"), + mustParseCoinsNormalized("1000000000denom1,1000000000denom2,1000000000denom3,1000000000stake"), + mustParseCoinsNormalized("875000000denom1,875000000denom2,875000000denom3,875000000stake"), + }, }, { "add budget 4 without date range overlap", @@ -357,18 +399,18 @@ func (suite *KeeperTestSuite) TestBudgetChangeSituation() { Key: string(types.KeyBudgets), Value: `[ { - "name": "gravity-dex-farming-20213Q-20313Q", + "name": "gravity-dex-farming-1", "rate": "0.500000000000000000", - "source_address": "cosmos17xpfvakm2amg962yls6f84z3kell8c5lserqta", - "destination_address": "cosmos1228ryjucdpdv3t87rxle0ew76a56ulvnfst0hq0sscd3nafgjpqqkcxcky", + "source_address": "cosmos10wy60v3zuks7rkwnqxs3e878zqfhus6m98l77q6rppz40kxwgllsruc0az", + "destination_address": "cosmos1qceyjmnrl6hapntjq3z25vn38nh68u7yxvufs2thptxvqm7huxeqj7zyrq", "start_time": "2021-09-01T00:00:00Z", "end_time": "2031-09-30T00:00:00Z" }, { "name": "gravity-dex-farming-4", "rate": "1.000000000000000000", - "source_address": "cosmos17xpfvakm2amg962yls6f84z3kell8c5lserqta", - "destination_address": "cosmos17avp6xs5c8ycqzy20yv99ccxwunu32e507kpm8ql5nfg47pzj9qqxhujxr", + "source_address": "cosmos10wy60v3zuks7rkwnqxs3e878zqfhus6m98l77q6rppz40kxwgllsruc0az", + "destination_address": "cosmos1e0n8jmeg4u8q3es2tmhz5zlte8a4q8687ndns8pj4q8grdl74a0sw3045s", "start_time": "2031-09-30T00:00:01Z", "end_time": "2031-12-10T00:00:00Z" } @@ -379,6 +421,33 @@ func (suite *KeeperTestSuite) TestBudgetChangeSituation() { types.MustParseRFC3339("2021-09-29T00:00:00Z"), types.MustParseRFC3339("2021-09-30T00:00:00Z"), nil, + []sdk.AccAddress{budgetSource, suite.destinationAddrs[0], suite.destinationAddrs[1], suite.destinationAddrs[2]}, + []sdk.Coins{ + mustParseCoinsNormalized("500000000denom1,500000000denom2,500000000denom3,500000000stake"), + mustParseCoinsNormalized("3625000000denom1,3625000000denom2,3625000000denom3,3625000000stake"), + mustParseCoinsNormalized("1000000000denom1,1000000000denom2,1000000000denom3,1000000000stake"), + mustParseCoinsNormalized("875000000denom1,875000000denom2,875000000denom3,875000000stake"), + }, + }, + { + "remove all budgets", + testProposal(proposal.ParamChange{ + Subspace: types.ModuleName, + Key: string(types.KeyBudgets), + Value: `[]`, + }), + 0, + 0, + types.MustParseRFC3339("2021-10-25T00:00:00Z"), + types.MustParseRFC3339("2021-10-26T00:00:00Z"), + nil, + []sdk.AccAddress{budgetSource, suite.destinationAddrs[0], suite.destinationAddrs[1], suite.destinationAddrs[2]}, + []sdk.Coins{ + mustParseCoinsNormalized("1500000000denom1,1500000000denom2,1500000000denom3,1500000000stake"), + mustParseCoinsNormalized("3625000000denom1,3625000000denom2,3625000000denom3,3625000000stake"), + mustParseCoinsNormalized("1000000000denom1,1000000000denom2,1000000000denom3,1000000000stake"), + mustParseCoinsNormalized("875000000denom1,875000000denom2,875000000denom3,875000000stake"), + }, }, } { suite.Run(tc.name, func() { @@ -399,23 +468,37 @@ func (suite *KeeperTestSuite) TestBudgetChangeSituation() { suite.Require().Error(err) } else { suite.Require().NoError(err) - params := suite.keeper.GetParams(suite.ctx) - suite.Require().Len(params.Budgets, tc.budgetCount) - for _, budget := range params.Budgets { - err := budget.Validate() - suite.Require().NoError(err) - } - // (new block) - height += 1 - suite.ctx = suite.ctx.WithBlockHeight(int64(height)) - suite.ctx = suite.ctx.WithBlockTime(tc.nextBlockTime) - budgets := types.CollectibleBudgets(params.Budgets, suite.ctx.BlockTime()) - suite.Require().Len(budgets, tc.collectibleBudgetCount) + } + + // (new block) + height += 1 + suite.ctx = suite.ctx.WithBlockHeight(int64(height)) + suite.ctx = suite.ctx.WithBlockTime(tc.nextBlockTime) - // BeginBlocker - err := suite.keeper.CollectBudgets(suite.ctx) + params := suite.keeper.GetParams(suite.ctx) + suite.Require().Len(params.Budgets, tc.budgetCount) + for _, budget := range params.Budgets { + err := budget.Validate() suite.Require().NoError(err) } + + budgets := types.CollectibleBudgets(params.Budgets, suite.ctx.BlockTime()) + suite.Require().Len(budgets, tc.collectibleBudgetCount) + + // BeginBlocker - inflation or mint on budgetSource + // inflation occurs by 1000000000denom1,1000000000denom2,1000000000denom3,1000000000stake every blocks + err = simapp.FundAccount(suite.app.BankKeeper, suite.ctx, budgetSource, initialBalances) + suite.Require().NoError(err) + + // BeginBlocker - Collect budgets + err = suite.keeper.CollectBudgets(suite.ctx) + suite.Require().NoError(err) + + // Assert budget collections + for i, acc := range tc.accAsserts { + balances := suite.app.BankKeeper.GetAllBalances(suite.ctx, acc) + suite.Require().Equal(tc.balanceAsserts[i], balances) + } }) } } diff --git a/x/budget/keeper/grpc_query.go b/x/budget/keeper/grpc_query.go index a446b2a..931520d 100644 --- a/x/budget/keeper/grpc_query.go +++ b/x/budget/keeper/grpc_query.go @@ -2,7 +2,6 @@ package keeper import ( "context" - "fmt" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -74,7 +73,7 @@ func (k Querier) Addresses(_ context.Context, req *types.QueryAddressesRequest) } if req.Name == "" && req.ModuleName == "" { - return nil, fmt.Errorf("at least one input of name or module name is required") + return nil, status.Error(codes.InvalidArgument,"at least one input of name or module name is required") } if req.ModuleName == "" && req.Type == types.AddressType32Bytes { @@ -83,7 +82,7 @@ func (k Querier) Addresses(_ context.Context, req *types.QueryAddressesRequest) addr := types.DeriveAddress(req.Type, req.ModuleName, req.Name) if addr.Empty() { - return nil, fmt.Errorf("invalid names with address type") + return nil, status.Error(codes.InvalidArgument, "invalid names with address type") } return &types.QueryAddressesResponse{Address: addr.String()}, nil diff --git a/x/budget/keeper/keeper_test.go b/x/budget/keeper/keeper_test.go index 2a77149..217a1c0 100644 --- a/x/budget/keeper/keeper_test.go +++ b/x/budget/keeper/keeper_test.go @@ -10,7 +10,6 @@ import ( "github.com/stretchr/testify/suite" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/address" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" simapp "github.com/tendermint/budget/app" @@ -63,18 +62,18 @@ func (suite *KeeperTestSuite) SetupTest() { suite.keeper = suite.app.BudgetKeeper suite.querier = keeper.Querier{Keeper: suite.keeper} suite.addrs = simapp.AddTestAddrs(suite.app, suite.ctx, 10, sdk.ZeroInt()) - dAddr1 := sdk.AccAddress(address.Module(types.ModuleName, []byte("destinationAddr1"))) - dAddr2 := sdk.AccAddress(address.Module(types.ModuleName, []byte("destinationAddr2"))) - dAddr3 := sdk.AccAddress(address.Module(types.ModuleName, []byte("destinationAddr3"))) - dAddr4 := sdk.AccAddress(address.Module(types.ModuleName, []byte("destinationAddr4"))) - dAddr5 := sdk.AccAddress(address.Module(types.ModuleName, []byte("destinationAddr5"))) - dAddr6 := suite.app.AccountKeeper.GetModuleAccount(suite.ctx, authtypes.FeeCollectorName).GetAddress() - sAddr1 := sdk.AccAddress(address.Module(types.ModuleName, []byte("sourceAddr1"))) - sAddr2 := sdk.AccAddress(address.Module(types.ModuleName, []byte("sourceAddr2"))) - sAddr3 := sdk.AccAddress(address.Module(types.ModuleName, []byte("sourceAddr3"))) - sAddr4 := sdk.AccAddress(address.Module(types.ModuleName, []byte("sourceAddr4"))) - sAddr5 := sdk.AccAddress(address.Module(types.ModuleName, []byte("sourceAddr5"))) - sAddr6 := sdk.AccAddress(address.Module("farming", []byte("GravityDEXFarmingBudget"))) + dAddr1 := types.DeriveAddress(types.AddressType32Bytes, types.ModuleName, "destinationAddr1") + dAddr2 := types.DeriveAddress(types.AddressType32Bytes, types.ModuleName, "destinationAddr2") + dAddr3 := types.DeriveAddress(types.AddressType32Bytes, types.ModuleName, "destinationAddr3") + dAddr4 := types.DeriveAddress(types.AddressType32Bytes, types.ModuleName, "destinationAddr4") + dAddr5 := types.DeriveAddress(types.AddressType32Bytes, types.ModuleName, "destinationAddr5") + dAddr6 := types.DeriveAddress(types.AddressType32Bytes, "farming", "GravityDEXFarmingBudget") + sAddr1 := types.DeriveAddress(types.AddressType32Bytes, types.ModuleName, "sourceAddr1") + sAddr2 := types.DeriveAddress(types.AddressType32Bytes, types.ModuleName, "sourceAddr2") + sAddr3 := types.DeriveAddress(types.AddressType32Bytes, types.ModuleName, "sourceAddr3") + sAddr4 := types.DeriveAddress(types.AddressType32Bytes, types.ModuleName, "sourceAddr4") + sAddr5 := types.DeriveAddress(types.AddressType32Bytes, types.ModuleName, "sourceAddr5") + sAddr6 := suite.app.AccountKeeper.GetModuleAccount(suite.ctx, authtypes.FeeCollectorName).GetAddress() suite.destinationAddrs = []sdk.AccAddress{dAddr1, dAddr2, dAddr3, dAddr4, dAddr5, dAddr6} suite.sourceAddrs = []sdk.AccAddress{sAddr1, sAddr2, sAddr3, sAddr4, sAddr5, sAddr6} for _, addr := range append(suite.addrs, suite.sourceAddrs[:3]...) { diff --git a/x/budget/types/utils.go b/x/budget/types/utils.go index 79da776..40ae989 100644 --- a/x/budget/types/utils.go +++ b/x/budget/types/utils.go @@ -23,6 +23,8 @@ func DateRangesOverlap(startTimeA, endTimeA, startTimeB, endTimeB time.Time) boo return startTimeA.Before(endTimeB) && endTimeA.After(startTimeB) } +// DeriveAddress derives an address with the given address length type, module name, and +// address derivation name. It is used to derive source or destination address. func DeriveAddress(addressType AddressType, moduleName, name string) sdk.AccAddress { switch addressType { case AddressType32Bytes: