Skip to content

Commit

Permalink
test: stakeholder address validation (#44)
Browse files Browse the repository at this point in the history
* chore: lint

* test: validate stakeholder address
  • Loading branch information
fmorency authored Apr 16, 2024
1 parent 63282a0 commit 39214eb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
11 changes: 11 additions & 0 deletions interchaintest/mainfest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
Expand Down
11 changes: 8 additions & 3 deletions x/manifest/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]",
Expand Down Expand Up @@ -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]",
Expand Down Expand Up @@ -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),
Expand Down
3 changes: 2 additions & 1 deletion x/manifest/keeper/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit 39214eb

Please sign in to comment.