-
Notifications
You must be signed in to change notification settings - Fork 92
/
forwardCompatible_test.go
66 lines (55 loc) · 1.63 KB
/
forwardCompatible_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
61
62
63
64
65
66
package adminBlock_test
import (
"encoding/hex"
"math/rand"
"testing"
"time"
. "github.com/FactomProject/factomd/common/adminBlock"
"github.com/FactomProject/factomd/common/factoid"
"github.com/FactomProject/factomd/common/interfaces"
"github.com/FactomProject/factomd/common/primitives"
"github.com/FactomProject/factomd/testHelper"
)
func TestNewForwardCompatibleEntry(t *testing.T) {
rand.Seed(time.Now().UnixNano())
// Coinbase Descriptor
for i := 0; i < 100; i++ {
var outputs []interfaces.ITransAddress
for c := 0; c < rand.Intn(64); c++ {
outputs = append(outputs, factoid.RandomTransAddress())
}
a := NewCoinbaseDescriptor(outputs)
// Coinbase Descriptor is forward compatible
b := NewForwardCompatibleEntry(0)
testHelper.TestMarshaling(a, b, rand.Intn(100), t)
}
// Coinbase Address
for i := 0; i < 100; i++ {
a := NewAddFactoidAddress(primitives.RandomHash(), factoid.RandomAddress())
b := NewForwardCompatibleEntry(0)
testHelper.TestMarshaling(a, b, rand.Intn(100), t)
}
// Efficiency
for i := 0; i < 100; i++ {
a := NewAddEfficiency(primitives.RandomHash(), uint16(rand.Intn(10000)))
b := NewForwardCompatibleEntry(0)
testHelper.TestMarshaling(a, b, rand.Intn(100), t)
}
}
func TestAddBadForwardCompatibleEntry(t *testing.T) {
// create bad ForwardCompatibleEntry binary
// AdminIDType = 0a
// Size = ff
// Data = deadbeef
p, err := hex.DecodeString("0affdeadbeef")
if err != nil {
t.Error(err)
}
f := new(ForwardCompatibleEntry)
err = f.UnmarshalBinary(p)
if err == nil {
t.Error("ForwardCompatibleEntry should have errored on unmarshal", f)
} else {
t.Log(err)
}
}