-
Notifications
You must be signed in to change notification settings - Fork 5
/
utils_test.go
51 lines (40 loc) · 1.39 KB
/
utils_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
package witness
import (
"math/big"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestFlatSlice(t *testing.T) {
one := new(big.Int).SetInt64(1)
two := new(big.Int).SetInt64(2)
three := new(big.Int).SetInt64(3)
four := new(big.Int).SetInt64(4)
a := one
fa := flatSlice(a)
assert.Equal(t, []*big.Int{one}, fa)
b := []*big.Int{one, two}
fb := flatSlice(b)
assert.Equal(t, []*big.Int{one, two}, fb)
c := []interface{}{one, []*big.Int{two, three}}
fc := flatSlice(c)
assert.Equal(t, []*big.Int{one, two, three}, fc)
d := []interface{}{[]*big.Int{one, two}, []*big.Int{three, four}}
fd := flatSlice(d)
assert.Equal(t, []*big.Int{one, two, three, four}, fd)
}
func TestParseInputs(t *testing.T) {
one := new(big.Int).SetInt64(1)
two := new(big.Int).SetInt64(2)
three := new(big.Int).SetInt64(3)
four := new(big.Int).SetInt64(4)
a, err := ParseInputs([]byte(`{"a": 1, "b": "2"}`))
require.Nil(t, err)
assert.Equal(t, map[string]interface{}{"a": one, "b": two}, a)
b, err := ParseInputs([]byte(`{"a": 1, "b": [2, 3]}`))
require.Nil(t, err)
assert.Equal(t, map[string]interface{}{"a": one, "b": []interface{}{two, three}}, b)
c, err := ParseInputs([]byte(`{"a": 1, "b": [[1, 2], [3, 4]]}`))
require.Nil(t, err)
assert.Equal(t, map[string]interface{}{"a": one, "b": []interface{}{[]interface{}{one, two}, []interface{}{three, four}}}, c)
}