Skip to content

Commit

Permalink
Separate test cases, add 0-len test
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaptic committed Mar 23, 2022
1 parent 0498dc6 commit d37806d
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions xdr/decorated_signature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,43 @@ import (
"github.com/stretchr/testify/assert"
)

func TestDecoratedSignatures(t *testing.T) {
signature := []byte{0, 1, 2, 3, 4, 5, 6, 7, 8}
keyHint := [4]byte{9, 10, 11, 12}
var (
signature = []byte{0, 1, 2, 3, 4, 5, 6, 7, 8}
hint = [4]byte{9, 10, 11, 12}
)

func TestDecoratedSignature(t *testing.T) {
decoSig := xdr.NewDecoratedSignature(signature, hint)
assert.EqualValues(t, hint, decoSig.Hint)
assert.EqualValues(t, signature, decoSig.Signature)
}

func TestDecoratedSignatureForPayload(t *testing.T) {
testCases := []struct {
payload []byte
expectedHint [4]byte
expectedPayloadHint [4]byte
payload []byte
expectedHint [4]byte
}{
{
[]byte{13, 14, 15, 16, 17, 18, 19, 20, 21},
keyHint,
[4]byte{27, 25, 31, 25},
},
{
[]byte{18, 19, 20},
keyHint,
[4]byte{27, 25, 31, 12},
},
{
[]byte{},
hint,
},
}

for _, testCase := range testCases {
t.Run(
fmt.Sprintf("%d-byte decorated sig", len(testCase.payload)),
func(t *testing.T) {
decoSig := xdr.NewDecoratedSignature(signature, keyHint)
assert.EqualValues(t, testCase.expectedHint, decoSig.Hint)
assert.EqualValues(t, signature, decoSig.Signature)
})

t.Run(
fmt.Sprintf("%d-byte decorated sig for payload", len(testCase.payload)),
fmt.Sprintf("%d-byte payload", len(testCase.payload)),
func(t *testing.T) {
decoSig := xdr.NewDecoratedSignatureForPayload(
signature, keyHint, testCase.payload)
assert.EqualValues(t, testCase.expectedPayloadHint, decoSig.Hint)
signature, hint, testCase.payload)
assert.EqualValues(t, testCase.expectedHint, decoSig.Hint)
assert.EqualValues(t, signature, decoSig.Signature)
})
}
Expand Down

0 comments on commit d37806d

Please sign in to comment.