github.com/iden3/go-circom-witnesscalc@v0.2.1-0.20230314155733-dd1f248a91b6/utils_test.go (about)

     1  package witnesscalc
     2  
     3  import (
     4  	"math/big"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  	"github.com/stretchr/testify/require"
     9  )
    10  
    11  func TestFlatSlice(t *testing.T) {
    12  	one := new(big.Int).SetInt64(1)
    13  	two := new(big.Int).SetInt64(2)
    14  	three := new(big.Int).SetInt64(3)
    15  	four := new(big.Int).SetInt64(4)
    16  
    17  	a := one
    18  	fa := flatSlice(a)
    19  	assert.Equal(t, []*big.Int{one}, fa)
    20  
    21  	b := []*big.Int{one, two}
    22  	fb := flatSlice(b)
    23  	assert.Equal(t, []*big.Int{one, two}, fb)
    24  
    25  	c := []interface{}{one, []*big.Int{two, three}}
    26  	fc := flatSlice(c)
    27  	assert.Equal(t, []*big.Int{one, two, three}, fc)
    28  
    29  	d := []interface{}{[]*big.Int{one, two}, []*big.Int{three, four}}
    30  	fd := flatSlice(d)
    31  	assert.Equal(t, []*big.Int{one, two, three, four}, fd)
    32  }
    33  
    34  func TestParseInputs(t *testing.T) {
    35  	one := new(big.Int).SetInt64(1)
    36  	two := new(big.Int).SetInt64(2)
    37  	three := new(big.Int).SetInt64(3)
    38  	four := new(big.Int).SetInt64(4)
    39  
    40  	a, err := ParseInputs([]byte(`{"a": 1, "b": "2"}`))
    41  	require.Nil(t, err)
    42  	assert.Equal(t, map[string]interface{}{"a": one, "b": two}, a)
    43  
    44  	b, err := ParseInputs([]byte(`{"a": 1, "b": [2, 3]}`))
    45  	require.Nil(t, err)
    46  	assert.Equal(t, map[string]interface{}{"a": one, "b": []interface{}{two, three}}, b)
    47  
    48  	c, err := ParseInputs([]byte(`{"a": 1, "b": [[1, 2], [3, 4]]}`))
    49  	require.Nil(t, err)
    50  	assert.Equal(t, map[string]interface{}{"a": one, "b": []interface{}{[]interface{}{one, two}, []interface{}{three, four}}}, c)
    51  }