-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathappend_test.go
60 lines (48 loc) · 2.22 KB
/
append_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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package gotrax
import (
"math/big"
"testing"
"time"
. "gopkg.in/check.v1"
)
func Test(t *testing.T) { TestingT(t) }
type GotraxSuite struct{}
var _ = Suite(&GotraxSuite{})
func (s *GotraxSuite) Test_AppendLong_serializesTimeCorrectly(c *C) {
tt := time.Date(2028, 11, 5, 13, 46, 00, 13, time.UTC)
num := tt.Unix()
c.Assert(num, Equals, int64(0x6EB04118))
c.Assert(AppendLong(nil, uint64(num)), DeepEquals, []byte{0x00, 0x00, 0x00, 0x00, 0x6e, 0xb0, 0x41, 0x18})
tt2 := time.Date(1968, 11, 5, 13, 46, 00, 13, time.UTC)
num2 := tt2.Unix()
c.Assert(num2, Equals, int64(-0x022B9768))
c.Assert(AppendLong(nil, uint64(num2)), DeepEquals, []byte{0xFF, 0xFF, 0xFF, 0xFF, 0xFD, 0xD4, 0x68, 0x98})
}
func (s *GotraxSuite) Test_AppendShort_willAppendTheShort(c *C) {
before := []byte{0x12, 0x14}
result := AppendShort(before, 0x4215)
c.Assert(result, DeepEquals, []byte{0x12, 0x14, 0x42, 0x15})
}
func (s *GotraxSuite) Test_AppendWord_WillAppendTheWord(c *C) {
before := []byte{0x12, 0x14}
result := AppendWord(before, 0x334D1215)
c.Assert(result, DeepEquals, []byte{0x12, 0x14, 0x33, 0x4D, 0x12, 0x15})
}
func (s *GotraxSuite) Test_AppendData_WillAppendBytes(c *C) {
before := []byte{0x13, 0x54}
result := AppendData(before, []byte{0x55, 0x12, 0x04, 0x8A, 0x00})
c.Assert(result, DeepEquals, []byte{0x13, 0x54, 0x00, 0x00, 0x00, 0x05, 0x55, 0x12, 0x04, 0x8A, 0x00})
}
func (s *GotraxSuite) Test_AppendMPI_WillAppendTheMPI(c *C) {
before := []byte{0x13, 0x54}
result := AppendMPI(before, new(big.Int).SetBytes([]byte{0x55, 0x12, 0x04, 0x8A, 0x00}))
c.Assert(result, DeepEquals, []byte{0x13, 0x54, 0x00, 0x00, 0x00, 0x05, 0x55, 0x12, 0x04, 0x8A, 0x00})
}
func (s *GotraxSuite) Test_AppendMPIs_WillAppendTheMPIs(c *C) {
before := []byte{0x13, 0x54}
one := new(big.Int).SetBytes([]byte{0x55, 0x12, 0x04, 0x8A, 0x00})
two := new(big.Int).SetBytes([]byte{0x01, 0x53, 0xCC})
three := new(big.Int).SetBytes([]byte{0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01})
result := AppendMPIs(before, one, two, three)
c.Assert(result, DeepEquals, []byte{0x13, 0x54, 0x00, 0x00, 0x00, 0x05, 0x55, 0x12, 0x04, 0x8A, 0x00, 0x00, 0x00, 0x00, 0x03, 0x01, 0x53, 0xCC, 0x00, 0x00, 0x00, 0x0A, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01})
}