Skip to content

Commit

Permalink
Add test for ConstructionPayloads
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-ogrady committed Jul 10, 2020
1 parent c1a714a commit 0a6291a
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
4 changes: 4 additions & 0 deletions asserter/construction.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ func ConstructionPayloads(
return errors.New("unsigned transaction cannot be empty")
}

if len(response.Payloads) == 0 {
return errors.New("signing payloads cannot be empty")
}

for i, payload := range response.Payloads {
if err := SigningPayload(payload); err != nil {
return fmt.Errorf("%w: signing payload %d is invalid", err, i)
Expand Down
63 changes: 63 additions & 0 deletions asserter/construction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,69 @@ func TestConstructionParse(t *testing.T) {
}
}

func TestConstructionPayloads(t *testing.T) {
var tests = map[string]struct {
response *types.ConstructionPayloadsResponse
err error
}{
"valid response": {
response: &types.ConstructionPayloadsResponse{
UnsignedTransaction: "tx blob",
Payloads: []*types.SigningPayload{
{
Address: "hello",
HexBytes: "48656c6c6f20476f7068657221",
},
},
},
err: nil,
},
"nil response": {
err: errors.New("construction payloads response cannot be nil"),
},
"empty unsigned transaction": {
response: &types.ConstructionPayloadsResponse{
Payloads: []*types.SigningPayload{
{
Address: "hello",
HexBytes: "48656c6c6f20476f7068657221",
},
},
},
err: errors.New("unsigned transaction cannot be empty"),
},
"empty signing payloads": {
response: &types.ConstructionPayloadsResponse{
UnsignedTransaction: "tx blob",
},
err: errors.New("signing payloads cannot be empty"),
},
"invalid signing payload": {
response: &types.ConstructionPayloadsResponse{
UnsignedTransaction: "tx blob",
Payloads: []*types.SigningPayload{
{
HexBytes: "48656c6c6f20476f7068657221",
},
},
},
err: errors.New("signing payload address cannot be empty"),
},
}

for name, test := range tests {
t.Run(name, func(t *testing.T) {
err := ConstructionPayloads(test.response)
if test.err != nil {
assert.Error(t, err)
assert.Contains(t, err.Error(), test.err.Error())
} else {
assert.NoError(t, err)
}
})
}
}

func TestPublicKey(t *testing.T) {
var tests = map[string]struct {
publicKey *types.PublicKey
Expand Down

0 comments on commit 0a6291a

Please sign in to comment.