Skip to content

Commit e3d7a30

Browse files
authored
Merge pull request #151 from cloudstruct/test/localstatequery-message-unit-tests
test: encode/decode unit tests for localstatequery messages
2 parents 8d6eb7a + 8cfbddf commit e3d7a30

File tree

1 file changed

+59
-3
lines changed

1 file changed

+59
-3
lines changed

protocol/localstatequery/messages_test.go

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package localstatequery
33
import (
44
"encoding/hex"
55
"github.com/cloudstruct/go-ouroboros-network/protocol"
6+
"github.com/cloudstruct/go-ouroboros-network/protocol/common"
67
"github.com/cloudstruct/go-ouroboros-network/utils"
78
"reflect"
89
"testing"
@@ -14,13 +15,68 @@ type testDefinition struct {
1415
MessageType uint
1516
}
1617

17-
// TODO: implement tests for more messages
1818
var tests = []testDefinition{
19+
{
20+
CborHex: "820080",
21+
Message: NewMsgAcquire(common.Point{}),
22+
MessageType: MESSAGE_TYPE_ACQUIRE,
23+
},
24+
{
25+
CborHex: "8101",
26+
Message: NewMsgAcquired(),
27+
MessageType: MESSAGE_TYPE_ACQUIRED,
28+
},
29+
{
30+
CborHex: "820201",
31+
Message: NewMsgFailure(ACQUIRE_FAILURE_POINT_NOT_ON_CHAIN),
32+
MessageType: MESSAGE_TYPE_FAILURE,
33+
},
34+
{
35+
CborHex: "8203820082028101",
36+
Message: NewMsgQuery(
37+
// Current era hard-fork query
38+
[]interface{}{
39+
uint64(0),
40+
[]interface{}{
41+
uint64(2),
42+
[]interface{}{
43+
uint64(1),
44+
},
45+
},
46+
},
47+
),
48+
MessageType: MESSAGE_TYPE_QUERY,
49+
},
50+
{
51+
CborHex: "820405",
52+
Message: NewMsgResult([]byte{5}),
53+
MessageType: MESSAGE_TYPE_RESULT,
54+
},
55+
{
56+
CborHex: "8105",
57+
Message: NewMsgRelease(),
58+
MessageType: MESSAGE_TYPE_RELEASE,
59+
},
60+
{
61+
CborHex: "820680",
62+
Message: NewMsgReAcquire(common.Point{}),
63+
MessageType: MESSAGE_TYPE_REACQUIRE,
64+
},
1965
{
2066
CborHex: "8107",
2167
Message: NewMsgDone(),
2268
MessageType: MESSAGE_TYPE_DONE,
2369
},
70+
{
71+
CborHex: "8108",
72+
Message: NewMsgAcquireNoPoint(),
73+
MessageType: MESSAGE_TYPE_ACQUIRE_NO_POINT,
74+
},
75+
{
76+
CborHex: "8109",
77+
Message: NewMsgReAcquireNoPoint(),
78+
MessageType: MESSAGE_TYPE_REACQUIRE_NO_POINT,
79+
},
2480
}
2581

2682
func TestDecode(t *testing.T) {
@@ -36,7 +92,7 @@ func TestDecode(t *testing.T) {
3692
// Set the raw CBOR so the comparison should succeed
3793
test.Message.SetCbor(cborData)
3894
if !reflect.DeepEqual(msg, test.Message) {
39-
t.Fatalf("CBOR did not decode to expected message object\n got: %#v\n wanted: %#v", msg, test.Message)
95+
t.Fatalf("CBOR did not decode to expected message object\n got: %#v\n wanted: %#v", msg, test.Message)
4096
}
4197
}
4298
}
@@ -49,7 +105,7 @@ func TestEncode(t *testing.T) {
49105
}
50106
cborHex := hex.EncodeToString(cborData)
51107
if cborHex != test.CborHex {
52-
t.Fatalf("message did not encode to expected CBOR\n got: %s\n wanted: %s", cborHex, test.CborHex)
108+
t.Fatalf("message did not encode to expected CBOR\n got: %s\n wanted: %s", cborHex, test.CborHex)
53109
}
54110
}
55111
}

0 commit comments

Comments
 (0)