Feat : Trimmed label to prevent white spaces (#1412)
* Merge pull request #1397 from CosmWasm/ext_wasmibctesting Decouple testing from app with an interface * Feat : Trimmed label to prevent white spaces * Fix: Made required nit changes * Added test files to validate untrimmed labels
This commit is contained in:
@@ -340,6 +340,12 @@ func TestValidateInstantiateContract2Proposal(t *testing.T) {
|
||||
}),
|
||||
expErr: true,
|
||||
},
|
||||
"untrimmed label ": {
|
||||
src: InstantiateContract2ProposalFixture(func(p *InstantiateContract2Proposal) {
|
||||
p.Label = " label "
|
||||
}),
|
||||
expErr: true,
|
||||
},
|
||||
"init funds negative": {
|
||||
src: InstantiateContract2ProposalFixture(func(p *InstantiateContract2Proposal) {
|
||||
p.Funds = sdk.Coins{{Denom: "foo", Amount: sdk.NewInt(-1)}}
|
||||
|
||||
@@ -3,6 +3,7 @@ package types
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
errorsmod "cosmossdk.io/errors"
|
||||
"github.com/docker/distribution/reference"
|
||||
@@ -40,6 +41,9 @@ func ValidateLabel(label string) error {
|
||||
if len(label) > MaxLabelSize {
|
||||
return ErrLimit.Wrapf("cannot be longer than %d characters", MaxLabelSize)
|
||||
}
|
||||
if label != strings.TrimSpace(label) {
|
||||
return ErrInvalid.Wrap("label must not start/end with whitespaces")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user