Skip to content

Commit

Permalink
handling missing errors
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmenendez committed Nov 14, 2024
1 parent e0f0cf7 commit 1bc882b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 22 deletions.
7 changes: 3 additions & 4 deletions helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package arbo
import (
"bytes"
"io"
"io/ioutil"
"os"
"testing"
"time"
Expand Down Expand Up @@ -41,13 +40,13 @@ func checkRoots(c *qt.C, tree1, tree2 *Tree) {
func storeTree(c *qt.C, tree *Tree, path string) {
dump, err := tree.Dump(nil)
c.Assert(err, qt.IsNil)
err = ioutil.WriteFile(path+"-"+time.Now().String()+".debug", dump, 0600)
err = os.WriteFile(path+"-"+time.Now().String()+".debug", dump, 0600)
c.Assert(err, qt.IsNil)
}

// nolint:unused
func readTree(c *qt.C, tree *Tree, path string) {
b, err := ioutil.ReadFile(path) //nolint:gosec
b, err := os.ReadFile(path) //nolint:gosec
c.Assert(err, qt.IsNil)
err = tree.ImportDump(b)
c.Assert(err, qt.IsNil)
Expand Down Expand Up @@ -102,7 +101,7 @@ func TestReadTreeDBG(t *testing.T) {

// tree1 is generated by a loop of .Add
path := "err-dump/tree1-2021-06-03 16:45:54.104449306 +0200 CEST m=+0.073874545.debug"
b, err := ioutil.ReadFile(path)
b, err := os.ReadFile(path)
c.Assert(err, qt.IsNil)
err = importDumpLoopAdd(tree1, b)
c.Assert(err, qt.IsNil)
Expand Down
6 changes: 3 additions & 3 deletions testvectors/circom/go-data-generator/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package main

import (
"encoding/json"
"io/ioutil"
"math/big"
"os"
"testing"

qt "github.com/frankban/quicktest"
Expand Down Expand Up @@ -42,7 +42,7 @@ func TestGenerator(t *testing.T) {
jCvp, err := json.Marshal(cvp)
c.Assert(err, qt.IsNil)
// store the data into a file that will be used at the circom test
err = ioutil.WriteFile("go-smt-verifier-inputs.json", jCvp, 0600)
err = os.WriteFile("go-smt-verifier-inputs.json", jCvp, 0600)
c.Assert(err, qt.IsNil)

// proof of non-existence
Expand All @@ -52,6 +52,6 @@ func TestGenerator(t *testing.T) {
jCvp, err = json.Marshal(cvp)
c.Assert(err, qt.IsNil)
// store the data into a file that will be used at the circom test
err = ioutil.WriteFile("go-smt-verifier-non-existence-inputs.json", jCvp, 0600)
err = os.WriteFile("go-smt-verifier-non-existence-inputs.json", jCvp, 0600)
c.Assert(err, qt.IsNil)
}
50 changes: 35 additions & 15 deletions vt.go
Original file line number Diff line number Diff line change
Expand Up @@ -627,13 +627,17 @@ func (n *node) computeHashes(currLvl, maxLvl int, p *params, pairs [][2][]byte)

//nolint:all
func (t *vt) graphviz(w io.Writer) error {
fmt.Fprintf(w, `digraph hierarchy {
if _, err := fmt.Fprintf(w, `digraph hierarchy {
node [fontname=Monospace,fontsize=10,shape=box]
`)
`); err != nil {
return err
}
if _, err := t.root.graphviz(w, t.params, 0); err != nil {
return err
}
fmt.Fprintf(w, "}\n")
if _, err := fmt.Fprintf(w, "}\n"); err != nil {
return err
}
return nil
}

Expand All @@ -650,7 +654,9 @@ func (n *node) graphviz(w io.Writer, p *params, nEmpties int) (int, error) {
if err != nil {
return nEmpties, err
}
fmt.Fprintf(w, "\"%p\" [style=filled,label=\"%v\"];\n", n, hex.EncodeToString(leafKey[:nChars]))
if _, err := fmt.Fprintf(w, "\"%p\" [style=filled,label=\"%v\"];\n", n, hex.EncodeToString(leafKey[:nChars])); err != nil {
return nEmpties, err
}

k := n.k
v := n.v
Expand All @@ -661,14 +667,20 @@ func (n *node) graphviz(w io.Writer, p *params, nEmpties int) (int, error) {
v = n.v[:nChars]
}

fmt.Fprintf(w, "\"%p\" -> {\"k:%v\\nv:%v\"}\n", n,
if _, err := fmt.Fprintf(w, "\"%p\" -> {\"k:%v\\nv:%v\"}\n", n,
hex.EncodeToString(k),
hex.EncodeToString(v))
fmt.Fprintf(w, "\"k:%v\\nv:%v\" [style=dashed]\n",
hex.EncodeToString(v)); err != nil {
return nEmpties, err
}
if _, err := fmt.Fprintf(w, "\"k:%v\\nv:%v\" [style=dashed]\n",
hex.EncodeToString(k),
hex.EncodeToString(v))
hex.EncodeToString(v)); err != nil {
return nEmpties, err
}
case vtMid:
fmt.Fprintf(w, "\"%p\" [label=\"\"];\n", n)
if _, err := fmt.Fprintf(w, "\"%p\" [label=\"\"];\n", n); err != nil {
return nEmpties, err
}

lStr := fmt.Sprintf("%p", n.l)
rStr := fmt.Sprintf("%p", n.r)
Expand All @@ -685,8 +697,12 @@ func (n *node) graphviz(w io.Writer, p *params, nEmpties int) (int, error) {
rStr)
nEmpties++
}
fmt.Fprintf(w, "\"%p\" -> {\"%v\" \"%v\"}\n", n, lStr, rStr)
fmt.Fprint(w, eStr)
if _, err := fmt.Fprintf(w, "\"%p\" -> {\"%v\" \"%v\"}\n", n, lStr, rStr); err != nil {
return nEmpties, err
}
if _, err := fmt.Fprint(w, eStr); err != nil {
return nEmpties, err
}
nEmpties, err := n.l.graphviz(w, p, nEmpties)
if err != nil {
return nEmpties, err
Expand All @@ -707,15 +723,19 @@ func (n *node) graphviz(w io.Writer, p *params, nEmpties int) (int, error) {
//nolint:all
func (t *vt) printGraphviz() error {
w := bytes.NewBufferString("")
fmt.Fprintf(w,
"--------\nGraphviz:\n")
if _, err := fmt.Fprintf(w,
"--------\nGraphviz:\n"); err != nil {
return err
}
err := t.graphviz(w)
if err != nil {
fmt.Println(w)
return err
}
fmt.Fprintf(w,
"End of Graphviz --------\n")
if _, err := fmt.Fprintf(w,
"End of Graphviz --------\n"); err != nil {
return err
}
fmt.Println(w)
return nil
}

0 comments on commit 1bc882b

Please sign in to comment.