Skip to content

Commit

Permalink
Ensure that MsgWirePayForData and MsgPayForData contain at least …
Browse files Browse the repository at this point in the history
…one MessageShareCommitment (#654)

* implement failing test

* make test pass

* implement failing test

* make test pass
  • Loading branch information
rootulp authored Aug 28, 2022
1 parent 301f9df commit de5cd1d
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions x/payment/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ var (
ErrTailPaddingNamespace = sdkerrors.Register(ModuleName, 11118, "cannot use tail padding namespace ID")
ErrTxNamespace = sdkerrors.Register(ModuleName, 11119, "cannot use transaction namespace ID")
ErrEvidenceNamespace = sdkerrors.Register(ModuleName, 11120, "cannot use evidence namespace ID")
ErrNoMessageShareCommitments = sdkerrors.Register(ModuleName, 11121, "no message share commitments")
)
4 changes: 4 additions & 0 deletions x/payment/types/payfordata.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ func (msg *MsgPayForData) ValidateBasic() error {
return err
}

if len(msg.MessageShareCommitment) == 0 {
return ErrNoMessageShareCommitments
}

return nil
}

Expand Down
9 changes: 9 additions & 0 deletions x/payment/types/payfordata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,10 @@ func TestValidateBasic(t *testing.T) {
maxReservedNamespaceMsg := validMsgPayForData(t)
maxReservedNamespaceMsg.MessageNamespaceId = namespace.ID{0, 0, 0, 0, 0, 0, 0, 255}

// MsgPayForData that has no message share commitments
noMessageShareCommitments := validMsgPayForData(t)
noMessageShareCommitments.MessageShareCommitment = []byte{}

tests := []test{
{
name: "valid msg",
Expand Down Expand Up @@ -393,6 +397,11 @@ func TestValidateBasic(t *testing.T) {
msg: maxReservedNamespaceMsg,
wantErr: ErrReservedNamespace,
},
{
name: "no message share commitments",
msg: noMessageShareCommitments,
wantErr: ErrNoMessageShareCommitments,
},
}

for _, tt := range tests {
Expand Down
4 changes: 4 additions & 0 deletions x/payment/types/wirepayfordata.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ func (msg *MsgWirePayForData) ValidateBasic() error {
}
}

if len(msg.MessageShareCommitment) == 0 {
return ErrNoMessageShareCommitments
}

return nil
}

Expand Down
9 changes: 9 additions & 0 deletions x/payment/types/wirepayfordata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ func TestWirePayForData_ValidateBasic(t *testing.T) {
badSquareSizeMsg := validWirePayForData(t)
badSquareSizeMsg.MessageShareCommitment[0].K = 4

// pfd that signed over no squares
noMessageShareCommitments := validWirePayForData(t)
noMessageShareCommitments.MessageShareCommitment = []ShareCommitAndSignature{}

tests := []test{
{
name: "valid msg",
Expand Down Expand Up @@ -95,6 +99,11 @@ func TestWirePayForData_ValidateBasic(t *testing.T) {
msg: tailPaddingMsg,
wantErr: ErrTailPaddingNamespace,
},
{
name: "no message share commitments",
msg: noMessageShareCommitments,
wantErr: ErrNoMessageShareCommitments,
},
}

for _, tt := range tests {
Expand Down

0 comments on commit de5cd1d

Please sign in to comment.