forked from cobinhood/moneroutil
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbase58_test.go
44 lines (35 loc) · 1.02 KB
/
base58_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
package moneroutil
import (
"math/rand"
"testing"
"github.com/stretchr/testify/assert"
)
func TestDecodeThenEncode(t *testing.T) {
addrs := []string{
"9xttFdWis9x5BbDj24X2YLHVYB4DTsdic25SHpRFGSvKeLS2tZ1xL3eAgZYLYMqnr213b4jVy7huzQhM7gL7YGG67cTddJg",
"4AdUndXHHZ6cfufTMvppY6JwXNouMBzSkbLYfpAV5Usx3skxNgYeYTRj5UzqtReoS44qo9mtmXCqY45DJ852K5Jv2684Rge",
}
for _, addr := range addrs {
raw := DecodeMoneroBase58(addr)
enc := EncodeMoneroBase58(raw)
assert.Equal(t, addr, enc)
}
}
func TestByFuzzing(t *testing.T) {
for i := 0; i < 20000; i++ {
ln := rand.Intn(300) + 1
arr := make([]byte, ln)
rand.Read(arr)
encoded := EncodeMoneroBase58(arr)
raw := DecodeMoneroBase58(encoded)
reproduced := EncodeMoneroBase58(raw)
assert.Equal(t, encoded, reproduced)
}
}
func TestIllegalChar(t *testing.T) {
assert.Nil(t, DecodeMoneroBase58(""))
assert.Nil(t, DecodeMoneroBase58("abcd#"))
assert.Nil(t, DecodeMoneroBase58("@abcd"))
assert.Nil(t, DecodeMoneroBase58("!AAAA"))
assert.Nil(t, DecodeMoneroBase58("01234O"))
}