arbo/testvectors/circom/go-data-generator/generator_test.go
testvectors/circom/go-data-generator/generator_test.goRaw
1package main
2
3import (
4 "encoding/json"
5 "math/big"
6 "os"
7 "testing"
8
9 "github.com/arnaucube/arbo"
10 "github.com/arnaucube/arbo/db"
11 "github.com/arnaucube/arbo/db/pebbledb"
12 qt "github.com/frankban/quicktest"
13)
14
15func TestGenerator(t *testing.T) {
16 c := qt.New(t)
17 database, err := pebbledb.New(db.Options{Path: c.TempDir()})
18 c.Assert(err, qt.IsNil)
19 tree, err := arbo.NewTree(arbo.Config{Database: database, MaxLevels: 4,
20 HashFunction: arbo.HashFunctionPoseidon})
21 c.Assert(err, qt.IsNil)
22
23 testVector := [][]int64{
24 {1, 11},
25 {2, 22},
26 {3, 33},
27 {4, 44},
28 }
29 bLen := 1
30 for i := 0; i < len(testVector); i++ {
31 k := arbo.BigIntToBytes(bLen, big.NewInt(testVector[i][0]))
32 v := arbo.BigIntToBytes(bLen, big.NewInt(testVector[i][1]))
33 if err := tree.Add(k, v); err != nil {
34 t.Fatal(err)
35 }
36 }
37
38 // proof of existence
39 k := arbo.BigIntToBytes(bLen, big.NewInt(int64(2)))
40 cvp, err := tree.GenerateCircomVerifierProof(k)
41 c.Assert(err, qt.IsNil)
42 jCvp, err := json.Marshal(cvp)
43 c.Assert(err, qt.IsNil)
44 // store the data into a file that will be used at the circom test
45 err = os.WriteFile("go-smt-verifier-inputs.json", jCvp, 0600)
46 c.Assert(err, qt.IsNil)
47
48 // proof of non-existence
49 k = arbo.BigIntToBytes(bLen, big.NewInt(int64(5)))
50 cvp, err = tree.GenerateCircomVerifierProof(k)
51 c.Assert(err, qt.IsNil)
52 jCvp, err = json.Marshal(cvp)
53 c.Assert(err, qt.IsNil)
54 // store the data into a file that will be used at the circom test
55 err = os.WriteFile("go-smt-verifier-non-existence-inputs.json", jCvp, 0600)
56 c.Assert(err, qt.IsNil)
57}