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.

64 lines
1.5 KiB

  1. package kzgceremony
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "io/ioutil"
  6. "testing"
  7. qt "github.com/frankban/quicktest"
  8. )
  9. func TestContribution(t *testing.T) {
  10. c := qt.New(t)
  11. srs_0 := newEmptySRS(10, 10)
  12. srs_1, proof_1, err := Contribute(srs_0,
  13. []byte("1111111111111111111111111111111111111111111111111111111111111111"))
  14. c.Assert(err, qt.IsNil)
  15. c.Assert(Verify(srs_0, srs_1, proof_1), qt.IsTrue)
  16. srs_2, proof_2, err := Contribute(srs_1,
  17. []byte("2222222222222222222222222222222222222222222222222222222222222222"))
  18. c.Assert(err, qt.IsNil)
  19. c.Assert(Verify(srs_1, srs_2, proof_2), qt.IsTrue)
  20. }
  21. func TestComputeNewState(t *testing.T) {
  22. c := qt.New(t)
  23. j, err := ioutil.ReadFile("current_state_10.json")
  24. c.Assert(err, qt.IsNil)
  25. cs := &State{}
  26. err = json.Unmarshal(j, cs)
  27. c.Assert(err, qt.IsNil)
  28. newState, err :=
  29. cs.Contribute([]byte("1111111111111111111111111111111111111111111111111111111111111111"))
  30. c.Assert(err, qt.IsNil)
  31. b, err := json.Marshal(newState)
  32. c.Assert(err, qt.IsNil)
  33. err = ioutil.WriteFile("new_state.json", b, 0600)
  34. c.Assert(err, qt.IsNil)
  35. }
  36. func TestBatchContribution(t *testing.T) {
  37. c := qt.New(t)
  38. j, err := ioutil.ReadFile("batch_contribution_10.json")
  39. c.Assert(err, qt.IsNil)
  40. bc := &BatchContribution{}
  41. err = json.Unmarshal(j, bc)
  42. c.Assert(err, qt.IsNil)
  43. nb, err :=
  44. bc.Contribute([]byte("1111111111111111111111111111111111111111111111111111111111111111"))
  45. c.Assert(err, qt.IsNil)
  46. b, err := json.Marshal(nb)
  47. c.Assert(err, qt.IsNil)
  48. fmt.Println(string(b))
  49. }