-
Notifications
You must be signed in to change notification settings - Fork 86
/
common_test.go
43 lines (38 loc) · 999 Bytes
/
common_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package tradingstate
import (
"reflect"
"testing"
)
// Testing scenario:
// encode originalTxMatchesBatch -> byteData
// decode byteData -> txMatchesBatch
// compare originalTxMatchesBatch and txMatchesBatch
func TestTxMatchesBatch(t *testing.T) {
originalTxMatchesBatch := []TxDataMatch{
{
Order: []byte("order1"),
},
{
Order: []byte("order2"),
},
{
Order: []byte("order3"),
},
}
encodedData, err := EncodeTxMatchesBatch(TxMatchBatch{
Data: originalTxMatchesBatch,
})
if err != nil {
t.Error("Failed to encode", err.Error())
}
txMatchesBatch, err := DecodeTxMatchesBatch(encodedData)
if err != nil {
t.Error("Failed to decode", err.Error())
}
eq := reflect.DeepEqual(originalTxMatchesBatch, txMatchesBatch.Data)
if eq {
t.Log("Awesome, encode and decode txMatchesBatch are correct")
} else {
t.Error("txMatchesBatch is different from originalTxMatchesBatch", "txMatchesBatch", txMatchesBatch, "originalTxMatchesBatch", originalTxMatchesBatch)
}
}