diff --git a/encoding/kzg/prover/decode_test.go b/encoding/kzg/prover/decode_test.go index cc6384c3a3..4e14301882 100644 --- a/encoding/kzg/prover/decode_test.go +++ b/encoding/kzg/prover/decode_test.go @@ -10,8 +10,6 @@ import ( ) func TestEncodeDecodeFrame_AreInverses(t *testing.T) { - teardownSuite := setupSuite(t) - defer teardownSuite(t) group, _ := prover.NewProver(kzgConfig, true) diff --git a/encoding/kzg/prover/parametrized_prover_test.go b/encoding/kzg/prover/parametrized_prover_test.go index b56f8ad8aa..8684bbf6fa 100644 --- a/encoding/kzg/prover/parametrized_prover_test.go +++ b/encoding/kzg/prover/parametrized_prover_test.go @@ -14,8 +14,6 @@ import ( ) func TestProveAllCosetThreads(t *testing.T) { - teardownSuite := setupSuite(t) - defer teardownSuite(t) group, _ := prover.NewProver(kzgConfig, true) diff --git a/encoding/kzg/prover/precompute_test.go b/encoding/kzg/prover/precompute_test.go index 035514bd28..9f2517f5ab 100644 --- a/encoding/kzg/prover/precompute_test.go +++ b/encoding/kzg/prover/precompute_test.go @@ -12,8 +12,6 @@ import ( ) func TestNewSRSTable_PreComputeWorks(t *testing.T) { - teardownSuite := setupSuite(t) - defer teardownSuite(t) kzgConfig.CacheDir = "./data/SRSTable" params := encoding.ParamsFromSysPar(numSys, numPar, uint64(len(gettysburgAddressBytes))) diff --git a/encoding/kzg/prover/prover_test.go b/encoding/kzg/prover/prover_test.go index ebf9ccd6ff..7526411981 100644 --- a/encoding/kzg/prover/prover_test.go +++ b/encoding/kzg/prover/prover_test.go @@ -16,10 +16,6 @@ import ( "github.com/stretchr/testify/assert" ) -const ( - BYTES_PER_COEFFICIENT = 31 -) - var ( gettysburgAddressBytes = []byte("Fourscore and seven years ago our fathers brought forth, on this continent, a new nation, conceived in liberty, and dedicated to the proposition that all men are created equal. Now we are engaged in a great civil war, testing whether that nation, or any nation so conceived, and so dedicated, can long endure. We are met on a great battle-field of that war. We have come to dedicate a portion of that field, as a final resting-place for those who here gave their lives, that that nation might live. It is altogether fitting and proper that we should do this. But, in a larger sense, we cannot dedicate, we cannot consecrate—we cannot hallow—this ground. The brave men, living and dead, who struggled here, have consecrated it far above our poor power to add or detract. The world will little note, nor long remember what we say here, but it can never forget what they did here. It is for us the living, rather, to be dedicated here to the unfinished work which they who fought here have thus far so nobly advanced. It is rather for us to be here dedicated to the great task remaining before us—that from these honored dead we take increased devotion to that cause for which they here gave the last full measure of devotion—that we here highly resolve that these dead shall not have died in vain—that this nation, under God, shall have a new birth of freedom, and that government of the people, by the people, for the people, shall not perish from the earth.") kzgConfig *kzg.KzgConfig @@ -28,7 +24,14 @@ var ( numPar uint64 ) -func setupSuite(t *testing.T) func(t *testing.T) { +func TestMain(m *testing.M) { + setup() + result := m.Run() + teardown() + os.Exit(result) +} + +func setup() { log.Println("Setting up suite") kzgConfig = &kzg.KzgConfig{ @@ -45,12 +48,13 @@ func setupSuite(t *testing.T) func(t *testing.T) { numSys = uint64(3) numPar = numNode - numSys - return func(t *testing.T) { - log.Println("Tearing down suite") +} - // Some test may want to create a new SRS table so this should clean it up. - os.RemoveAll("./data") - } +func teardown() { + log.Println("Tearing down suite") + + // Some test may want to create a new SRS table so this should clean it up. + os.RemoveAll("./data") } func sampleFrames(frames []encoding.Frame, num uint64) ([]encoding.Frame, []uint64) { diff --git a/encoding/kzg/verifier/batch_commit_equivalence_test.go b/encoding/kzg/verifier/batch_commit_equivalence_test.go index d1cebe1e88..daf94083a1 100644 --- a/encoding/kzg/verifier/batch_commit_equivalence_test.go +++ b/encoding/kzg/verifier/batch_commit_equivalence_test.go @@ -14,16 +14,14 @@ import ( ) func TestBatchEquivalence(t *testing.T) { - teardownSuite := setupSuite(t) - defer teardownSuite(t) group, _ := prover.NewProver(kzgConfig, true) v, _ := verifier.NewVerifier(kzgConfig, true) - params := encoding.ParamsFromSysPar(numSys, numPar, uint64(len(GETTYSBURG_ADDRESS_BYTES))) + params := encoding.ParamsFromSysPar(numSys, numPar, uint64(len(gettysburgAddressBytes))) enc, err := group.GetKzgEncoder(params) require.Nil(t, err) - inputFr := rs.ToFrArray(GETTYSBURG_ADDRESS_BYTES) + inputFr := rs.ToFrArray(gettysburgAddressBytes) commit, g2commit, _, _, _, err := enc.Encode(inputFr) require.Nil(t, err) diff --git a/encoding/kzg/verifier/degree_test.go b/encoding/kzg/verifier/degree_test.go index ff811b5cb7..de7ee1661a 100644 --- a/encoding/kzg/verifier/degree_test.go +++ b/encoding/kzg/verifier/degree_test.go @@ -12,19 +12,17 @@ import ( ) func TestLengthProof(t *testing.T) { - teardownSuite := setupSuite(t) - defer teardownSuite(t) group, _ := prover.NewProver(kzgConfig, true) v, _ := verifier.NewVerifier(kzgConfig, true) - params := encoding.ParamsFromSysPar(numSys, numPar, uint64(len(GETTYSBURG_ADDRESS_BYTES))) + params := encoding.ParamsFromSysPar(numSys, numPar, uint64(len(gettysburgAddressBytes))) enc, err := group.GetKzgEncoder(params) require.Nil(t, err) numBlob := 5 for z := 0; z < numBlob; z++ { extra := make([]byte, z*31*2) - inputBytes := append(GETTYSBURG_ADDRESS_BYTES, extra...) + inputBytes := append(gettysburgAddressBytes, extra...) inputFr := rs.ToFrArray(inputBytes) _, lowDegreeCommitment, lowDegreeProof, _, _, err := enc.Encode(inputFr) diff --git a/encoding/kzg/verifier/frame_test.go b/encoding/kzg/verifier/frame_test.go index d3353733de..707d52fee2 100644 --- a/encoding/kzg/verifier/frame_test.go +++ b/encoding/kzg/verifier/frame_test.go @@ -16,18 +16,16 @@ import ( ) func TestVerify(t *testing.T) { - teardownSuite := setupSuite(t) - defer teardownSuite(t) group, _ := prover.NewProver(kzgConfig, true) - params := encoding.ParamsFromSysPar(numSys, numPar, uint64(len(GETTYSBURG_ADDRESS_BYTES))) + params := encoding.ParamsFromSysPar(numSys, numPar, uint64(len(gettysburgAddressBytes))) enc, err := group.GetKzgEncoder(params) require.Nil(t, err) require.NotNil(t, enc) - commit, _, _, frames, _, err := enc.EncodeBytes(GETTYSBURG_ADDRESS_BYTES) + commit, _, _, frames, _, err := enc.EncodeBytes(gettysburgAddressBytes) require.Nil(t, err) require.NotNil(t, commit) require.NotNil(t, frames) diff --git a/encoding/kzg/verifier/multiframe_test.go b/encoding/kzg/verifier/multiframe_test.go index 64efa47d8b..60cbafdbaf 100644 --- a/encoding/kzg/verifier/multiframe_test.go +++ b/encoding/kzg/verifier/multiframe_test.go @@ -12,20 +12,18 @@ import ( ) func TestUniversalVerify(t *testing.T) { - teardownSuite := setupSuite(t) - defer teardownSuite(t) group, _ := prover.NewProver(kzgConfig, true) v, _ := verifier.NewVerifier(kzgConfig, true) - params := encoding.ParamsFromSysPar(numSys, numPar, uint64(len(GETTYSBURG_ADDRESS_BYTES))) + params := encoding.ParamsFromSysPar(numSys, numPar, uint64(len(gettysburgAddressBytes))) enc, err := group.GetKzgEncoder(params) require.Nil(t, err) numBlob := 5 samples := make([]verifier.Sample, 0) for z := 0; z < numBlob; z++ { - inputFr := rs.ToFrArray(GETTYSBURG_ADDRESS_BYTES) + inputFr := rs.ToFrArray(gettysburgAddressBytes) commit, _, _, frames, fIndices, err := enc.Encode(inputFr) require.Nil(t, err) @@ -55,8 +53,6 @@ func TestUniversalVerify(t *testing.T) { } func TestUniversalVerifyWithPowerOf2G2(t *testing.T) { - teardownSuite := setupSuite(t) - defer teardownSuite(t) kzgConfigCopy := *kzgConfig group, err := prover.NewProver(&kzgConfigCopy, true) @@ -66,14 +62,14 @@ func TestUniversalVerifyWithPowerOf2G2(t *testing.T) { v, err := verifier.NewVerifier(kzgConfig, true) assert.NoError(t, err) - params := encoding.ParamsFromSysPar(numSys, numPar, uint64(len(GETTYSBURG_ADDRESS_BYTES))) + params := encoding.ParamsFromSysPar(numSys, numPar, uint64(len(gettysburgAddressBytes))) enc, err := group.GetKzgEncoder(params) assert.NoError(t, err) numBlob := 5 samples := make([]verifier.Sample, 0) for z := 0; z < numBlob; z++ { - inputFr := rs.ToFrArray(GETTYSBURG_ADDRESS_BYTES) + inputFr := rs.ToFrArray(gettysburgAddressBytes) commit, _, _, frames, fIndices, err := enc.Encode(inputFr) require.Nil(t, err) diff --git a/encoding/kzg/verifier/verifier_test.go b/encoding/kzg/verifier/verifier_test.go index 8c82832058..04aee88104 100644 --- a/encoding/kzg/verifier/verifier_test.go +++ b/encoding/kzg/verifier/verifier_test.go @@ -15,19 +15,22 @@ import ( "github.com/stretchr/testify/assert" ) -const ( - BYTES_PER_COEFFICIENT = 31 -) - var ( - GETTYSBURG_ADDRESS_BYTES = []byte("Fourscore and seven years ago our fathers brought forth, on this continent, a new nation, conceived in liberty, and dedicated to the proposition that all men are created equal. Now we are engaged in a great civil war, testing whether that nation, or any nation so conceived, and so dedicated, can long endure. We are met on a great battle-field of that war. We have come to dedicate a portion of that field, as a final resting-place for those who here gave their lives, that that nation might live. It is altogether fitting and proper that we should do this. But, in a larger sense, we cannot dedicate, we cannot consecrate—we cannot hallow—this ground. The brave men, living and dead, who struggled here, have consecrated it far above our poor power to add or detract. The world will little note, nor long remember what we say here, but it can never forget what they did here. It is for us the living, rather, to be dedicated here to the unfinished work which they who fought here have thus far so nobly advanced. It is rather for us to be here dedicated to the great task remaining before us—that from these honored dead we take increased devotion to that cause for which they here gave the last full measure of devotion—that we here highly resolve that these dead shall not have died in vain—that this nation, under God, shall have a new birth of freedom, and that government of the people, by the people, for the people, shall not perish from the earth.") - kzgConfig *kzg.KzgConfig - numNode uint64 - numSys uint64 - numPar uint64 + gettysburgAddressBytes = []byte("Fourscore and seven years ago our fathers brought forth, on this continent, a new nation, conceived in liberty, and dedicated to the proposition that all men are created equal. Now we are engaged in a great civil war, testing whether that nation, or any nation so conceived, and so dedicated, can long endure. We are met on a great battle-field of that war. We have come to dedicate a portion of that field, as a final resting-place for those who here gave their lives, that that nation might live. It is altogether fitting and proper that we should do this. But, in a larger sense, we cannot dedicate, we cannot consecrate—we cannot hallow—this ground. The brave men, living and dead, who struggled here, have consecrated it far above our poor power to add or detract. The world will little note, nor long remember what we say here, but it can never forget what they did here. It is for us the living, rather, to be dedicated here to the unfinished work which they who fought here have thus far so nobly advanced. It is rather for us to be here dedicated to the great task remaining before us—that from these honored dead we take increased devotion to that cause for which they here gave the last full measure of devotion—that we here highly resolve that these dead shall not have died in vain—that this nation, under God, shall have a new birth of freedom, and that government of the people, by the people, for the people, shall not perish from the earth.") + kzgConfig *kzg.KzgConfig + numNode uint64 + numSys uint64 + numPar uint64 ) -func setupSuite(t *testing.T) func(t *testing.T) { +func TestMain(m *testing.M) { + setup() + result := m.Run() + teardown() + os.Exit(result) +} + +func setup() { log.Println("Setting up suite") kzgConfig = &kzg.KzgConfig{ @@ -44,12 +47,11 @@ func setupSuite(t *testing.T) func(t *testing.T) { numSys = uint64(3) numPar = numNode - numSys - return func(t *testing.T) { - log.Println("Tearing down suite") +} - // Some test may want to create a new SRS table so this should clean it up. - os.RemoveAll("./data") - } +func teardown() { + log.Println("Tearing down") + os.RemoveAll("./data") } // var control interface{ Stop() }