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