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.

45 lines
1.0 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,
  12. []byte("1111111111111111111111111111111111111111111111111111111111111111"))
  13. c.Assert(err, qt.IsNil)
  14. c.Assert(Verify(srs_0, srs_1, proof_1), qt.IsTrue)
  15. srs_2, proof_2, err := Contribute(srs_1,
  16. []byte("2222222222222222222222222222222222222222222222222222222222222222"))
  17. c.Assert(err, qt.IsNil)
  18. c.Assert(Verify(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. }