From edb4897d97d83a72b81cb6d2af8e90af2d4229d1 Mon Sep 17 00:00:00 2001 From: Arya Tabaie <15056835+Tabaie@users.noreply.github.com> Date: Wed, 11 Sep 2024 13:50:21 -0500 Subject: [PATCH] gopter test --- .../pi-interconnection/circuit_test.go | 48 ++++++++++++------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/prover/circuits/pi-interconnection/circuit_test.go b/prover/circuits/pi-interconnection/circuit_test.go index 57c231cf3..e024fc9c5 100644 --- a/prover/circuits/pi-interconnection/circuit_test.go +++ b/prover/circuits/pi-interconnection/circuit_test.go @@ -3,6 +3,10 @@ package pi_interconnection_test import ( "errors" "fmt" + "github.com/consensys/zkevm-monorepo/prover/config" + "github.com/leanovate/gopter" + "github.com/leanovate/gopter/gen" + "github.com/leanovate/gopter/prop" "testing" "github.com/consensys/gnark-crypto/ecc" @@ -14,9 +18,7 @@ import ( "github.com/consensys/zkevm-monorepo/prover/circuits/internal" pi_interconnection "github.com/consensys/zkevm-monorepo/prover/circuits/pi-interconnection" "github.com/consensys/zkevm-monorepo/prover/circuits/pi-interconnection/keccak" - "github.com/consensys/zkevm-monorepo/prover/config" "github.com/consensys/zkevm-monorepo/prover/utils" - "github.com/consensys/zkevm-monorepo/prover/utils/test_utils" "github.com/stretchr/testify/assert" "golang.org/x/crypto/sha3" ) @@ -103,22 +105,32 @@ func (c *testMerkleCircuit) Define(api frontend.API) error { } func TestMaxNbCircuitsSum(t *testing.T) { - cfg := config.PublicInput{ - MaxNbDecompression: test_utils.RandIntN(10), - MaxNbExecution: test_utils.RandIntN(10), - MaxNbCircuits: 20, - MaxNbKeccakF: 200, - ExecutionMaxNbMsg: 2, - L2MsgMerkleDepth: 5, - L2MsgMaxNbMerkle: 2, - MockKeccakWizard: true, - } - - c, err := pi_interconnection.Compile(cfg) - assert.NoError(t, err) + parameters := gopter.DefaultTestParameters() + parameters.MinSuccessfulTests = 5 + parameters.Rng.Seed(0x123456789abcdef0) + + properties := gopter.NewProperties(parameters) + + properties.Property("provides the correct number of public inputs", prop.ForAll( + func(maxNbDecompression, maxNbExecution int) bool { + cfg := config.PublicInput{ + MaxNbDecompression: maxNbDecompression, + MaxNbExecution: maxNbExecution, + MaxNbCircuits: 20, + MaxNbKeccakF: 200, + ExecutionMaxNbMsg: 2, + L2MsgMerkleDepth: 5, + L2MsgMaxNbMerkle: 2, + MockKeccakWizard: true, + } - cs, err := frontend.Compile(ecc.BLS12_377.ScalarField(), scs.NewBuilder, c.Circuit) - assert.NoError(t, err) + c, err := pi_interconnection.Compile(cfg) + assert.NoError(t, err) + cs, err := frontend.Compile(ecc.BLS12_377.ScalarField(), scs.NewBuilder, c.Circuit) + assert.NoError(t, err) + return cfg.MaxNbDecompression+cfg.MaxNbExecution == pi_interconnection.GetMaxNbCircuitsSum(cs) + }, gen.IntRange(1, 10), gen.IntRange(1, 10), + )) - assert.Equal(t, cfg.MaxNbDecompression+cfg.MaxNbExecution, pi_interconnection.GetMaxNbCircuitsSum(cs)) + properties.TestingRun(t) }