forked from iotaledger/iota.go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kerl_test.go
64 lines (56 loc) · 1.96 KB
/
kerl_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
package giota
import (
"testing"
)
func TestNewKerl(t *testing.T) {
k := NewKerl()
if k == nil {
t.Error("could not initialize kerl instance")
}
}
func TestKerl(t *testing.T) {
tests := []struct {
name string
trytes Trytes
expectedTrytes Trytes
squeezeSize int
}{
{
name: "test squeeze HashSize",
trytes: Trytes("EMIDYNHBWMBCXVDEFOFWINXTERALUKYYPPHKP9JJFGJEIUY9MUDVNFZHMMWZUYUSWAIOWEVTHNWMHANBH"),
expectedTrytes: Trytes("EJEAOOZYSAWFPZQESYDHZCGYNSTWXUMVJOVDWUNZJXDGWCLUFGIMZRMGCAZGKNPLBRLGUNYWKLJTYEAQX"),
squeezeSize: HashSize,
},
{
name: "test squeeze HashSize * 2",
trytes: Trytes("9MIDYNHBWMBCXVDEFOFWINXTERALUKYYPPHKP9JJFGJEIUY9MUDVNFZHMMWZUYUSWAIOWEVTHNWMHANBH"),
expectedTrytes: Trytes("G9JYBOMPUXHYHKSNRNMMSSZCSHOFYOYNZRSZMAAYWDYEIMVVOGKPJBVBM9TDPULSFUNMTVXRKFIDOHUXXVYDLFSZYZTWQYTE9SPYYWYTXJYQ9IFGYOLZXWZBKWZN9QOOTBQMWMUBLEWUEEASRHRTNIQWJQNDWRYLCA"),
squeezeSize: HashSize * 2,
},
{
name: "test longer trytes with HashSize * 2",
trytes: Trytes("G9JYBOMPUXHYHKSNRNMMSSZCSHOFYOYNZRSZMAAYWDYEIMVVOGKPJBVBM9TDPULSFUNMTVXRKFIDOHUXXVYDLFSZYZTWQYTE9SPYYWYTXJYQ9IFGYOLZXWZBKWZN9QOOTBQMWMUBLEWUEEASRHRTNIQWJQNDWRYLCA"),
expectedTrytes: Trytes("LUCKQVACOGBFYSPPVSSOXJEKNSQQRQKPZC9NXFSMQNRQCGGUL9OHVVKBDSKEQEBKXRNUJSRXYVHJTXBPDWQGNSCDCBAIRHAQCOWZEBSNHIJIGPZQITIBJQ9LNTDIBTCQ9EUWKHFLGFUVGGUWJONK9GBCDUIMAYMMQX"),
squeezeSize: HashSize * 2,
},
}
for _, tt := range tests {
k := NewKerl()
if k == nil {
t.Errorf("could not initialize Kerl instance")
}
err := k.Absorb(tt.trytes.Trits())
if err != nil {
t.Errorf("Absorb(%q) failed: %s", tt.trytes, err)
}
ts, err := k.Squeeze(tt.squeezeSize)
if err != nil {
t.Errorf("Squeeze() failed: %s", err)
}
if ts.Trytes() != tt.expectedTrytes {
if err != nil {
t.Errorf("%s: tryte output: %s != expected output: %s", tt.name, ts.Trytes(), tt.expectedTrytes)
}
}
}
}