From 39214eb8274074983bf3fc8b1890d149e79b168f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20C=2E=20Morency?= <1102868+fmorency@users.noreply.github.com> Date: Tue, 16 Apr 2024 10:33:31 -0400 Subject: [PATCH] test: stakeholder address validation (#44) * chore: lint * test: validate stakeholder address --- interchaintest/mainfest_test.go | 11 +++++++++++ x/manifest/client/cli/tx.go | 11 ++++++++--- x/manifest/keeper/abci_test.go | 3 ++- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/interchaintest/mainfest_test.go b/interchaintest/mainfest_test.go index c0e6b0b..3f09faa 100644 --- a/interchaintest/mainfest_test.go +++ b/interchaintest/mainfest_test.go @@ -138,6 +138,17 @@ func TestManifestModule(t *testing.T) { }) + t.Run("fail: invalid stakeholder addr", func(t *testing.T) { + _, err := helpers.ManifestUpdateParams( + t, ctx, appChain, poaAdmin, + fmt.Sprintf("%s:1_000_000,%s:99_000_000", uaddr, "foobar"), + false, + sdk.NewCoin(Denom, sdkmath.NewIntFromUint64(p.Inflation.YearlyAmount)), // it's off, this just matches genesis + ) + require.Error(t, err) + require.ErrorContains(t, err, "invalid address") + }) + t.Cleanup(func() { _ = ic.Close() }) diff --git a/x/manifest/client/cli/tx.go b/x/manifest/client/cli/tx.go index 97597aa..0134eeb 100644 --- a/x/manifest/client/cli/tx.go +++ b/x/manifest/client/cli/tx.go @@ -33,7 +33,7 @@ func NewTxCmd() *cobra.Command { return txCmd } -// Returns a CLI command handler for updating the params. +// MsgUpdateParams returns a CLI command handler for updating the params. func MsgUpdateParams() *cobra.Command { cmd := &cobra.Command{ Use: "update-params [address_pairs] [automatic_inflation_enabled] [inflation_per_year]", @@ -80,7 +80,7 @@ func MsgUpdateParams() *cobra.Command { return cmd } -// Returns a CLI command handler for deploying a stakeholder payout (where stakeholders are set in the current params). +// MsgDeployStakeholderPayout returns a CLI command handler for deploying a stakeholder payout (where stakeholders are set in the current params). func MsgDeployStakeholderPayout() *cobra.Command { cmd := &cobra.Command{ Use: "stakeholder-payout [coin_amount]", @@ -130,11 +130,16 @@ func fromStrToStakeholders(s string) ([]*types.StakeHolders, error) { return nil, fmt.Errorf("invalid stakeholder: %s", stakeholder) } - percentage, err := strconv.ParseInt(parts[1], 10, 64) + percentage, err := strconv.ParseInt(parts[1], 10, 32) if err != nil { return nil, fmt.Errorf("invalid percentage: %s", parts[1]) } + _, err = sdk.AccAddressFromBech32(parts[0]) + if err != nil { + return nil, fmt.Errorf("invalid address: %s", parts[0]) + } + sh := &types.StakeHolders{ Address: parts[0], Percentage: int32(percentage), diff --git a/x/manifest/keeper/abci_test.go b/x/manifest/keeper/abci_test.go index 0fe81b1..21d2cd0 100644 --- a/x/manifest/keeper/abci_test.go +++ b/x/manifest/keeper/abci_test.go @@ -4,9 +4,10 @@ import ( "fmt" "testing" - sdkmath "cosmossdk.io/math" "github.com/stretchr/testify/require" + sdkmath "cosmossdk.io/math" + "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types"