Skip to content

Commit 936b265

Browse files
committed
test: use assert.CheckCircuit directly
Until #1422 is resolved
1 parent 9d0d806 commit 936b265

File tree

2 files changed

+24
-62
lines changed

2 files changed

+24
-62
lines changed

std/hash/poseidon2/poseidon2_test.go

+24-12
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,41 @@
11
package poseidon2
22

33
import (
4-
"github.com/consensys/gnark-crypto/ecc"
54
"testing"
65

6+
"github.com/consensys/gnark-crypto/ecc"
77
"github.com/consensys/gnark-crypto/ecc/bls12-377/fr/poseidon2"
88
"github.com/consensys/gnark/frontend"
99
"github.com/consensys/gnark/test"
10-
"github.com/stretchr/testify/require"
1110
)
1211

12+
type Poseidon2Circuit struct {
13+
Input []frontend.Variable
14+
Expected frontend.Variable `gnark:",public"`
15+
}
16+
17+
func (c *Poseidon2Circuit) Define(api frontend.API) error {
18+
hsh, err := NewMerkleDamgardHasher(api)
19+
if err != nil {
20+
return err
21+
}
22+
hsh.Write(c.Input...)
23+
api.AssertIsEqual(hsh.Sum(), c.Expected)
24+
return nil
25+
}
26+
1327
func TestPoseidon2Hash(t *testing.T) {
28+
assert := test.NewAssert(t)
29+
30+
const nbInputs = 5
1431
// prepare expected output
1532
h := poseidon2.NewMerkleDamgardHasher()
16-
for i := range 5 {
33+
circInput := make([]frontend.Variable, nbInputs)
34+
for i := range nbInputs {
1735
_, err := h.Write([]byte{byte(i)})
18-
require.NoError(t, err)
36+
assert.NoError(err)
37+
circInput[i] = i
1938
}
2039
res := h.Sum(nil)
21-
22-
test.Function(func(api frontend.API) error {
23-
hsh, err := NewMerkleDamgardHasher(api)
24-
require.NoError(t, err)
25-
hsh.Write(0, 1, 2, 3, 4)
26-
api.AssertIsEqual(hsh.Sum(), res)
27-
return nil
28-
}, test.WithCurves(ecc.BLS12_377))(t)
40+
assert.CheckCircuit(&Poseidon2Circuit{Input: make([]frontend.Variable, nbInputs)}, test.WithValidAssignment(&Poseidon2Circuit{Input: circInput, Expected: res}), test.WithCurves(ecc.BLS12_377)) // we have parametrized currently only for BLS12-377
2941
}

test/quick.go

-50
This file was deleted.

0 commit comments

Comments
 (0)