Skip to content

Commit 5777176

Browse files
committed
Updates Dela+Go and fixes the tests
- Uses the latest version of Dela - Fixes the tests (encoding of ballot ID, warnings instead of errors) - Uses Go 1.19 - Cleans some parts (removes prints, formats lines)
1 parent 8a82240 commit 5777176

File tree

17 files changed

+112
-66
lines changed

17 files changed

+112
-66
lines changed

cli/cosipbftcontroller/action_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package controller
33
import (
44
"bytes"
55
"context"
6-
"io/ioutil"
6+
"io"
77
"testing"
88
"time"
99

@@ -172,7 +172,7 @@ func prepContext(calls *fake.Call) node.Context {
172172
ctx := node.Context{
173173
Injector: node.NewInjector(),
174174
Flags: make(node.FlagSet),
175-
Out: ioutil.Discard,
175+
Out: io.Discard,
176176
}
177177

178178
events := []ordering.Event{

cli/cosipbftcontroller/mod_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package controller
22

33
import (
44
"encoding"
5-
"io/ioutil"
65
"os"
76
"path/filepath"
87
"testing"
@@ -105,7 +104,7 @@ func TestMinimal_MalformedKey_OnStart(t *testing.T) {
105104
}
106105

107106
func TestMinimal_OnStop(t *testing.T) {
108-
dir, err := ioutil.TempDir(os.TempDir(), "dela-test-")
107+
dir, err := os.MkdirTemp(os.TempDir(), "dela-test-")
109108
require.NoError(t, err)
110109

111110
db, err := kv.New(filepath.Join(dir, "test.db"))
@@ -152,7 +151,7 @@ func TestMinimal_OnStop(t *testing.T) {
152151
// Utility functions
153152

154153
func makeFlags(t *testing.T) (cli.Flags, string, func()) {
155-
dir, err := ioutil.TempDir(os.TempDir(), "dela-")
154+
dir, err := os.MkdirTemp(os.TempDir(), "dela-")
156155
require.NoError(t, err)
157156

158157
fset := make(node.FlagSet)

cli/memcoin/mod_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package main
33
import (
44
"bytes"
55
"fmt"
6-
"io/ioutil"
6+
"io"
77
"net"
88
"os"
99
"path/filepath"
@@ -25,7 +25,7 @@ func TestMemcoin_Main(t *testing.T) {
2525
// be able to communicate, but the chain should proceed because of the
2626
// threshold.
2727
func TestMemcoin_Scenario_SetupAndTransactions(t *testing.T) {
28-
dir, err := ioutil.TempDir(os.TempDir(), "memcoin1")
28+
dir, err := os.MkdirTemp(os.TempDir(), "memcoin1")
2929
require.NoError(t, err)
3030

3131
defer os.RemoveAll(dir)
@@ -40,7 +40,7 @@ func TestMemcoin_Scenario_SetupAndTransactions(t *testing.T) {
4040
node4 := filepath.Join(dir, "node4")
4141
node5 := filepath.Join(dir, "node5")
4242

43-
cfg := config{Channel: sigs, Writer: ioutil.Discard}
43+
cfg := config{Channel: sigs, Writer: io.Discard}
4444

4545
runNode(t, node1, cfg, 2111, &wg)
4646
runNode(t, node2, cfg, 2112, &wg)
@@ -117,7 +117,7 @@ func TestMemcoin_Scenario_SetupAndTransactions(t *testing.T) {
117117
// restart. It basically tests if the components are correctly loaded from the
118118
// persisten storage.
119119
func TestMemcoin_Scenario_RestartNode(t *testing.T) {
120-
dir, err := ioutil.TempDir(os.TempDir(), "memcoin2")
120+
dir, err := os.MkdirTemp(os.TempDir(), "memcoin2")
121121
require.NoError(t, err)
122122

123123
defer os.RemoveAll(dir)
@@ -132,7 +132,7 @@ func TestMemcoin_Scenario_RestartNode(t *testing.T) {
132132
wg := sync.WaitGroup{}
133133
wg.Add(2)
134134

135-
cfg := config{Channel: sigs, Writer: ioutil.Discard}
135+
cfg := config{Channel: sigs, Writer: io.Discard}
136136

137137
// Now the node are restarted. It should correctly follow the existing chain
138138
// and then participate to new blocks.
@@ -177,7 +177,7 @@ func setupChain(t *testing.T, nodes []string, ports []uint16) {
177177
wg := sync.WaitGroup{}
178178
wg.Add(len(nodes))
179179

180-
cfg := config{Channel: sigs, Writer: ioutil.Discard}
180+
cfg := config{Channel: sigs, Writer: io.Discard}
181181

182182
for i, node := range nodes {
183183
runNode(t, node, cfg, ports[i], &wg)

contracts/evoting/controller/action.go

+6-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"encoding/json"
99
"fmt"
1010
"io"
11-
"io/ioutil"
1211
"net/http"
1312
"strconv"
1413
"strings"
@@ -267,7 +266,7 @@ func (a *scenarioTestAction) Execute(ctx node.Context) error {
267266
}
268267

269268
if resp.StatusCode != http.StatusOK {
270-
buf, _ := ioutil.ReadAll(resp.Body)
269+
buf, _ := io.ReadAll(resp.Body)
271270
return xerrors.Errorf("unexpected status: %s - %s", resp.Status, buf)
272271
}
273272

@@ -525,7 +524,7 @@ func (a *scenarioTestAction) Execute(ctx node.Context) error {
525524
}
526525

527526
if resp.StatusCode != http.StatusOK {
528-
buf, _ := ioutil.ReadAll(resp.Body)
527+
buf, _ := io.ReadAll(resp.Body)
529528
return xerrors.Errorf("unexpected shuffle status: %s - %s", resp.Status, buf)
530529
}
531530

@@ -686,7 +685,7 @@ func castVote(electionID string, signed []byte, proxyAddr string) (string, error
686685
}
687686

688687
if resp.StatusCode != http.StatusOK {
689-
buf, _ := ioutil.ReadAll(resp.Body)
688+
buf, _ := io.ReadAll(resp.Body)
690689
return "", xerrors.Errorf("unexpected status: %s - %s", resp.Status, buf)
691690
}
692691

@@ -721,7 +720,7 @@ func updateElection(secret kyber.Scalar, proxyAddr, electionIDHex, action string
721720
}
722721

723722
if resp.StatusCode != http.StatusOK {
724-
buf, _ := ioutil.ReadAll(resp.Body)
723+
buf, _ := io.ReadAll(resp.Body)
725724
return resp.StatusCode, xerrors.Errorf("unexpected status: %s - %s", resp.Status, buf)
726725
}
727726

@@ -744,7 +743,7 @@ func initDKG(secret kyber.Scalar, proxyAddr, electionIDHex string) error {
744743
}
745744

746745
if resp.StatusCode != http.StatusOK {
747-
buf, _ := ioutil.ReadAll(resp.Body)
746+
buf, _ := io.ReadAll(resp.Body)
748747
return xerrors.Errorf("unexpected status: %s - %s", resp.Status, buf)
749748
}
750749

@@ -772,7 +771,7 @@ func updateDKG(secret kyber.Scalar, proxyAddr, electionIDHex, action string) (in
772771
}
773772

774773
if resp.StatusCode != http.StatusOK {
775-
buf, _ := ioutil.ReadAll(resp.Body)
774+
buf, _ := io.ReadAll(resp.Body)
776775
return resp.StatusCode, xerrors.Errorf("unexpected status: %s - %s", resp.Status, buf)
777776
}
778777

contracts/evoting/types/ballots.go

-2
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,6 @@ func (b *Ballot) invalidate() {
171171

172172
// Equal performs a loose comparison of a ballot.
173173
func (b *Ballot) Equal(other Ballot) bool {
174-
fmt.Printf("b: %v\n", b)
175-
fmt.Printf("other: %v\n", other)
176174
if len(b.SelectResultIDs) != len(other.SelectResultIDs) {
177175
return false
178176
}

contracts/evoting/types/ballots_test.go

+10-17
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ func TestBallot_Unmarshal(t *testing.T) {
158158

159159
err = b.Unmarshal(ballotWrongSelect, election)
160160
require.EqualError(t, err, "could not unmarshal select answers: "+
161-
"question Q1 has too many selected answers")
161+
"failed to check number of answers: question Q1 has too many selected answers")
162162

163163
// with not enough selected answers in select question
164164
ballotWrongSelect = string("select:" + encodedQuestionID(1) + ":1,0,0\n" +
@@ -170,7 +170,7 @@ func TestBallot_Unmarshal(t *testing.T) {
170170

171171
err = b.Unmarshal(ballotWrongSelect, election)
172172
require.EqualError(t, err, "could not unmarshal select answers: "+
173-
"question Q1 has not enough selected answers")
173+
"failed to check number of answers: question Q1 has not enough selected answers")
174174

175175
// with not enough answers in rank question
176176
ballotWrongRank := string("select:" + encodedQuestionID(1) + ":1,0,1\n" +
@@ -192,7 +192,7 @@ func TestBallot_Unmarshal(t *testing.T) {
192192

193193
err = b.Unmarshal(ballotWrongRank, election)
194194
require.EqualError(t, err, "could not unmarshal rank answers: "+
195-
"could not parse rank value for Q.Q2 : strconv.ParseInt: parsing \"x\": invalid syntax")
195+
"could not parse rank value for Q.Q2: strconv.ParseInt: parsing \"x\": invalid syntax")
196196

197197
// with too many selected answers in rank question
198198
ballotWrongRank = string("select:" + encodedQuestionID(1) + ":1,0,1\n" +
@@ -204,7 +204,7 @@ func TestBallot_Unmarshal(t *testing.T) {
204204

205205
err = b.Unmarshal(ballotWrongRank, election)
206206
require.EqualError(t, err, "could not unmarshal rank answers: "+
207-
"invalid rank not in range [0, MaxN[")
207+
"invalid rank not in range [0, MaxN[: 3")
208208

209209
// with valid ranks but one is selected twice
210210
ballotWrongRank = string("select:" + encodedQuestionID(1) + ":1,0,1\n" +
@@ -216,7 +216,7 @@ func TestBallot_Unmarshal(t *testing.T) {
216216

217217
err = b.Unmarshal(ballotWrongRank, election)
218218
require.EqualError(t, err, "could not unmarshal rank answers: "+
219-
"question Q2 has too many selected answers")
219+
"failed to check number of answers: question Q2 has too many selected answers")
220220

221221
// with not enough selected answers in rank question
222222
ballotWrongRank = string("select:" + encodedQuestionID(1) + ":1,0,1\n" +
@@ -227,7 +227,8 @@ func TestBallot_Unmarshal(t *testing.T) {
227227
election.BallotSize = len(ballotWrongRank)
228228

229229
err = b.Unmarshal(ballotWrongRank, election)
230-
require.EqualError(t, err, "could not unmarshal rank answers: question"+
230+
require.EqualError(t, err, "could not unmarshal rank answers: "+
231+
"failed to check number of answers: question"+
231232
" Q2 has not enough selected answers")
232233

233234
// with not enough answers in text question
@@ -252,7 +253,7 @@ func TestBallot_Unmarshal(t *testing.T) {
252253

253254
err = b.Unmarshal(ballotWrongText, election)
254255
require.EqualError(t, err, "could not unmarshal text answers: "+
255-
"could not decode text for Q. Q4: illegal base64 data at input byte 12")
256+
"could not decode text for Q.Q4: illegal base64 data at input byte 12")
256257

257258
// with too many selected answers in text question
258259
election.Configuration.Scaffold[0].Texts[0].MaxN = 1
@@ -266,7 +267,7 @@ func TestBallot_Unmarshal(t *testing.T) {
266267

267268
err = b.Unmarshal(ballotWrongText, election)
268269
require.EqualError(t, err, "could not unmarshal text answers: "+
269-
"question Q4 has too many selected answers")
270+
"failed to check number of answers: question Q4 has too many selected answers")
270271

271272
election.Configuration.Scaffold[0].Texts[0].MaxN = 2
272273

@@ -280,7 +281,7 @@ func TestBallot_Unmarshal(t *testing.T) {
280281

281282
err = b.Unmarshal(ballotWrongText, election)
282283
require.EqualError(t, err, "could not unmarshal text answers: "+
283-
"question Q4 has not enough selected answers")
284+
"failed to check number of answers: question Q4 has not enough selected answers")
284285

285286
// with unknown question type
286287
ballotWrongType := string("wrong:" + encodedQuestionID(1) + ":")
@@ -382,14 +383,6 @@ func TestSubject_IsValid(t *testing.T) {
382383
valid := configuration.IsValid()
383384
require.True(t, valid)
384385

385-
// with wrongly ID not in base64
386-
mainSubject.ID = "zzz"
387-
388-
configuration.Scaffold = []Subject{*mainSubject}
389-
390-
valid = configuration.IsValid()
391-
require.False(t, valid)
392-
393386
// with double IDs
394387

395388
mainSubject.ID = ID(base64.StdEncoding.EncodeToString([]byte("S1")))

go.mod

+34-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/dedis/d-voting
22

3-
go 1.16
3+
go 1.19
44

55
require (
66
github.com/gorilla/mux v1.8.0
@@ -9,10 +9,42 @@ require (
99
github.com/rs/zerolog v1.19.0
1010
github.com/stretchr/testify v1.7.0
1111
github.com/uber/jaeger-client-go v2.25.0+incompatible
12-
go.dedis.ch/dela v0.0.0-20220705073643-0b58fb2e471f
12+
go.dedis.ch/dela v0.0.0-20220727144418-4a9466c2c294
1313
go.dedis.ch/dela-apps v0.0.0-20211019120455-a0db752a0ba0
1414
go.dedis.ch/kyber/v3 v3.1.0-alpha
1515
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f
1616
golang.org/x/tools v0.1.11-0.20220316014157-77aa08bb151a
1717
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1
1818
)
19+
20+
require (
21+
github.com/beorn7/perks v1.0.1 // indirect
22+
github.com/cespare/xxhash/v2 v2.1.2 // indirect
23+
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
24+
github.com/davecgh/go-spew v1.1.1 // indirect
25+
github.com/golang/protobuf v1.5.2 // indirect
26+
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
27+
github.com/opentracing-contrib/go-grpc v0.0.0-20200813121455-4a6760c71486 // indirect
28+
github.com/pkg/errors v0.9.1 // indirect
29+
github.com/pmezard/go-difflib v1.0.0 // indirect
30+
github.com/prometheus/client_model v0.2.0 // indirect
31+
github.com/prometheus/common v0.32.1 // indirect
32+
github.com/prometheus/procfs v0.7.3 // indirect
33+
github.com/rs/xid v1.2.1 // indirect
34+
github.com/russross/blackfriday/v2 v2.0.1 // indirect
35+
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
36+
github.com/uber/jaeger-lib v2.4.0+incompatible // indirect
37+
github.com/urfave/cli/v2 v2.2.0 // indirect
38+
go.dedis.ch/fixbuf v1.0.3 // indirect
39+
go.dedis.ch/protobuf v1.0.11 // indirect
40+
go.etcd.io/bbolt v1.3.5 // indirect
41+
go.uber.org/atomic v1.7.0 // indirect
42+
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect
43+
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect
44+
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 // indirect
45+
golang.org/x/text v0.3.7 // indirect
46+
google.golang.org/genproto v0.0.0-20200825200019-8632dd797987 // indirect
47+
google.golang.org/grpc v1.45.0 // indirect
48+
google.golang.org/protobuf v1.26.0 // indirect
49+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
50+
)

go.sum

+2-4
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,8 @@ github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de
244244
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
245245
github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
246246
go.dedis.ch/dela v0.0.0-20211018150429-1fdbe35cd189/go.mod h1:GVQ2MumgCcAkor2MmfRCoqTBsFjaaqt7HfJpQLhMGok=
247-
go.dedis.ch/dela v0.0.0-20220428080424-2348afb6228a h1:Ahci1dtYYj9MIVOUjsA2kavD6oAEmnLZrwBctzHOYYA=
248-
go.dedis.ch/dela v0.0.0-20220428080424-2348afb6228a/go.mod h1:IIIV0aR0f1c9z4jRB2HVYYeLK7XbQ6pfqv6RufaXmUg=
249-
go.dedis.ch/dela v0.0.0-20220705073643-0b58fb2e471f h1:BbrlaRV3rFMTlKUQ+o2PJJQUlmyINIqB4FPmMlsSLjU=
250-
go.dedis.ch/dela v0.0.0-20220705073643-0b58fb2e471f/go.mod h1:IIIV0aR0f1c9z4jRB2HVYYeLK7XbQ6pfqv6RufaXmUg=
247+
go.dedis.ch/dela v0.0.0-20220727144418-4a9466c2c294 h1:q+kgJ4Cso4daxyR1owhz5jmFNxTG/O0xI4O/ppHaPdQ=
248+
go.dedis.ch/dela v0.0.0-20220727144418-4a9466c2c294/go.mod h1:IIIV0aR0f1c9z4jRB2HVYYeLK7XbQ6pfqv6RufaXmUg=
251249
go.dedis.ch/dela-apps v0.0.0-20211019120455-a0db752a0ba0 h1:gPrJd+7QUuADpfToMKr80maGnjGPeB7ft7iNrkAtwGY=
252250
go.dedis.ch/dela-apps v0.0.0-20211019120455-a0db752a0ba0/go.mod h1:MoJSdm3LXkNtiKEK3eiBKgqFhory4v8sBr7ldFP/vFc=
253251
go.dedis.ch/fixbuf v1.0.3 h1:hGcV9Cd/znUxlusJ64eAlExS+5cJDIyTyEG+otu5wQs=

integration/dvotingdela.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ func (c dVotingNode) Setup(nodes ...dela) {
315315

316316
token := joinable.GenerateToken(time.Hour)
317317

318-
certHash, err := joinable.GetCertificateStore().Hash(joinable.GetCertificate())
318+
certHash, err := joinable.GetCertificateStore().Hash(joinable.GetCertificateChain())
319319
require.NoError(c.t, err)
320320

321321
for _, n := range nodes {

integration/integration_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"encoding/hex"
99
"fmt"
1010
"io"
11-
"io/ioutil"
1211
"math/rand"
1312
"os"
1413
"strconv"
@@ -60,7 +59,7 @@ func getIntegrationTest(numNodes, numVotes int) func(*testing.T) {
6059

6160
delaPkg.Logger = delaPkg.Logger.Level(zerolog.WarnLevel)
6261

63-
dirPath, err := ioutil.TempDir(os.TempDir(), "d-voting-three-votes")
62+
dirPath, err := os.MkdirTemp(os.TempDir(), "d-voting-three-votes")
6463
require.NoError(t, err)
6564

6665
defer os.RemoveAll(dirPath)

integration/performance_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"crypto/sha256"
55
"encoding/base64"
66
"fmt"
7-
"io/ioutil"
87
"math/rand"
98
"os"
109
"strconv"
@@ -39,7 +38,7 @@ func BenchmarkIntegration_CustomVotesScenario(b *testing.B) {
3938

4039
delaPkg.Logger = delaPkg.Logger.Level(zerolog.WarnLevel)
4140

42-
dirPath, err := ioutil.TempDir(os.TempDir(), "d-voting-three-votes")
41+
dirPath, err := os.MkdirTemp(os.TempDir(), "d-voting-three-votes")
4342
require.NoError(b, err)
4443

4544
defer os.RemoveAll(dirPath)

internal/testing/fake/ordering.go

-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package fake
33
import (
44
"context"
55
"encoding/hex"
6-
"fmt"
76

87
electionTypes "github.com/dedis/d-voting/contracts/evoting/types"
98
"go.dedis.ch/dela/core/ordering"
@@ -112,7 +111,6 @@ func (f *Service) AddTx(tx Transaction) {
112111

113112
f.Status = true
114113

115-
fmt.Println("watch", results[0])
116114
f.Channel <- ordering.Event{
117115
Index: 0,
118116
Transactions: results,

0 commit comments

Comments
 (0)