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.

67 lines
1.8 KiB

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