You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
2.1 KiB

  1. package zkproof
  2. import (
  3. "context"
  4. "encoding/json"
  5. "fmt"
  6. "io/ioutil"
  7. "os"
  8. "testing"
  9. "time"
  10. "github.com/hermeznetwork/hermez-node/db/statedb"
  11. "github.com/hermeznetwork/hermez-node/prover"
  12. "github.com/hermeznetwork/hermez-node/test/txsets"
  13. "github.com/hermeznetwork/hermez-node/txprocessor"
  14. "github.com/stretchr/testify/assert"
  15. "github.com/stretchr/testify/require"
  16. )
  17. var proofServerURL string
  18. const pollInterval = 200 * time.Millisecond
  19. func TestMain(m *testing.M) {
  20. exitVal := 0
  21. proofServerURL = os.Getenv("PROOF_SERVER_URL")
  22. if proofServerURL != "" {
  23. exitVal = m.Run()
  24. }
  25. os.Exit(exitVal)
  26. }
  27. const MaxTx = 376
  28. const NLevels = 32
  29. const MaxL1Tx = 256
  30. const MaxFeeTx = 64
  31. const ChainID uint16 = 1
  32. func TestZKInputs5(t *testing.T) {
  33. dir, err := ioutil.TempDir("", "tmpdb")
  34. require.NoError(t, err)
  35. defer assert.Nil(t, os.RemoveAll(dir))
  36. sdb, err := statedb.NewStateDB(dir, 128, statedb.TypeBatchBuilder, NLevels)
  37. require.NoError(t, err)
  38. _, coordIdxs, l1UserTxs, l1CoordTxs, l2Txs := txsets.GenerateTxsZKInputs5(t, ChainID)
  39. config := txprocessor.Config{
  40. NLevels: uint32(NLevels),
  41. MaxTx: MaxTx,
  42. MaxL1Tx: MaxL1Tx,
  43. MaxFeeTx: MaxFeeTx,
  44. ChainID: ChainID,
  45. }
  46. tp := txprocessor.NewTxProcessor(sdb, config)
  47. // skip first batch to do the test with BatchNum=1
  48. _, err = tp.ProcessTxs(nil, nil, nil, nil)
  49. require.NoError(t, err)
  50. ptOut, err := tp.ProcessTxs(coordIdxs, l1UserTxs, l1CoordTxs, l2Txs)
  51. require.NoError(t, err)
  52. // Store zkinputs json for debugging purposes
  53. zkInputsJSON, err := json.Marshal(ptOut.ZKInputs)
  54. require.NoError(t, err)
  55. err = ioutil.WriteFile("/tmp/dbgZKInputs.json", zkInputsJSON, 0640) //nolint:gosec
  56. require.NoError(t, err)
  57. proofServerClient := prover.NewProofServerClient(proofServerURL, pollInterval)
  58. err = proofServerClient.WaitReady(context.Background())
  59. require.NoError(t, err)
  60. err = proofServerClient.CalculateProof(context.Background(), ptOut.ZKInputs)
  61. require.NoError(t, err)
  62. proof, pubInputs, err := proofServerClient.GetProof(context.Background())
  63. require.NoError(t, err)
  64. fmt.Printf("proof: %#v\n", proof)
  65. fmt.Printf("pubInputs: %#v\n", pubInputs)
  66. }