Skip to content

Commit e30881e

Browse files
Seongjae ChoiSeongjae Choi
authored andcommitted
Fix tests
1 parent 5a639ee commit e30881e

File tree

3 files changed

+40
-18
lines changed

3 files changed

+40
-18
lines changed

primitives/bignumber_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ func TestBigNumber(t *testing.T) {
1313
t.Fatal("bignumber creation Error")
1414
}
1515

16-
if b.ToEncodeObject() != "0x05" {
16+
if bytes.Compare(b.ToEncodeObject(), []byte{5}) != 0 {
1717
t.Fatal("ToEncodeObject Error")
1818
}
19-
if c.ToEncodeObject() != uint(0) {
19+
if bytes.Compare(c.ToEncodeObject(), []byte{}) != 0 {
2020
t.Fatal("ToEncodeObject Error")
2121
}
2222
}

primitives/hexstring.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ func (h H128) Cmp(g H128) bool {
6262
}
6363

6464
func (h H128) ToString() string {
65-
return string(h[:])
65+
var test = make([]byte, 32)
66+
innerArrOfH := [16]byte(h)
67+
hex.Encode(test, innerArrOfH[:])
68+
return string(test)
6669
}
6770

6871
func (h H128) ToHexString() string {
@@ -137,7 +140,10 @@ func (h H160) Cmp(g H160) bool {
137140
}
138141

139142
func (h H160) ToString() string {
140-
return string(h[:])
143+
var test = make([]byte, 40)
144+
innerArrOfH := [20]byte(h)
145+
hex.Encode(test, innerArrOfH[:])
146+
return string(test)
141147
}
142148

143149
func (h H160) ToHexString() string {
@@ -203,7 +209,10 @@ func (h H256) Cmp(g H256) bool {
203209
}
204210

205211
func (h H256) ToString() string {
206-
return string(h[:])
212+
var test = make([]byte, 64)
213+
innerArrOfH := [32]byte(h)
214+
hex.Encode(test, innerArrOfH[:])
215+
return string(test)
207216
}
208217

209218
func (h H256) ToHexString() string {
@@ -269,7 +278,10 @@ func (h H512) Cmp(g H512) bool {
269278
}
270279

271280
func (h H512) ToString() string {
272-
return string(h[:])
281+
var test = make([]byte, 128)
282+
innerArrOfH := [64]byte(h)
283+
hex.Encode(test, innerArrOfH[:])
284+
return string(test)
273285
}
274286

275287
func (h H512) ToHexString() string {

primitives/hexstring_test.go

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,35 @@
11
package primitives
22

33
import (
4-
"fmt"
4+
"bytes"
55
"testing"
66
)
77

8-
func TestH128(t *testing.T) {
8+
func TestHexstring(t *testing.T) {
99
a := NewH128Zero()
1010
b := NewH128Zero()
1111
c := H128([16]byte{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0})
12-
d := NewH512Zero()
13-
fmt.Println(d)
14-
fmt.Println(d.ToJSON())
15-
fmt.Println(a.Cmp(b))
16-
fmt.Println(c.Cmp(b))
17-
fmt.Println(a.ToString())
18-
fmt.Println(a.RlpBytes())
19-
fmt.Println(a.ToJSON())
12+
if a.Cmp(b) != true {
13+
t.Fatal("Hexstring Error")
14+
}
15+
if c.Cmp(b) != false {
16+
t.Fatal("Hexstring Error")
17+
}
18+
if c.ToString() != "01000000000000000000000000000000" {
19+
t.Fatal("Hexstring ToString() Error")
20+
}
21+
22+
if bytes.Compare(a.RlpBytes(), []byte{144, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 00}) != 0 {
23+
t.Fatal("Hexstring RlpBytes() Error")
24+
}
25+
if c.ToJSON() != "0x01000000000000000000000000000000" {
26+
t.Fatal("Hexstring ToJSON() Error")
27+
}
2028

2129
z := "0x1010101010101010101010101010101010101010"
2230
x, y := StringToH160(z)
23-
fmt.Println(len(z))
24-
fmt.Println(x, y)
31+
32+
if y != nil || bytes.Compare(x.Bytes(), []byte{16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16}) != 0 {
33+
t.Fatal("StringToH160 Error")
34+
}
2535
}

0 commit comments

Comments
 (0)