Skip to content

Commit b6a48be

Browse files
authored
Merge pull request #163 from dedis/updates-and-test-fixes
Updates Dela+Go and fixes the tests
2 parents 8a82240 + 0386cab commit b6a48be

25 files changed

+537
-395
lines changed

.github/workflows/go_integration_tests.yml

+2-24
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,9 @@ jobs:
1616
uses: actions/setup-go@v2
1717
with:
1818
go-version: ^1.17
19-
20-
- name: Install crypto util from Dela
21-
run: |
22-
git clone https://github.com/dedis/dela.git
23-
cd dela
24-
go install ./cli/crypto
2519

2620
- name: Check out code into the Go module directory
2721
uses: actions/checkout@v2
28-
29-
- name: Create a private key
30-
run: crypto bls signer new --save private.key
31-
32-
- name: Install memcoin
33-
run: make build
34-
35-
- name: Start 3 nodes
36-
run: |
37-
./memcoin --config /tmp/node1 start --postinstall --promaddr :9100 --proxyaddr :9080 --proxykey adbacd10fdb9822c71025d6d00092b8a4abb5ebcb673d28d863f7c7c5adaddf3 --listen tcp://0.0.0.0:2001 --public //localhost:2001 &
38-
./memcoin --config /tmp/node2 start --postinstall --promaddr :9101 --proxyaddr :9081 --proxykey adbacd10fdb9822c71025d6d00092b8a4abb5ebcb673d28d863f7c7c5adaddf3 --listen tcp://0.0.0.0:2002 --public //localhost:2002 &
39-
./memcoin --config /tmp/node3 start --postinstall --promaddr :9102 --proxyaddr :9082 --proxykey adbacd10fdb9822c71025d6d00092b8a4abb5ebcb673d28d863f7c7c5adaddf3 --listen tcp://0.0.0.0:2003 --public //localhost:2003 &
40-
41-
- name: Run the setup
42-
run: ./setupnNode.sh -n 3 -d false
43-
4422

45-
- name: Test integration & benchmark with coverage
46-
run: go test -bench -cover -tags=integration ./integration/...
23+
- name: Run the integration test
24+
run: go test -timeout 7m -run TestIntegration ./integration/...
+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Go Scenario Test (with proxy)
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
11+
test:
12+
name: Tests
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Set up Go ^1.17
16+
uses: actions/setup-go@v2
17+
with:
18+
go-version: ^1.17
19+
20+
- name: Install crypto util from Dela
21+
run: |
22+
git clone https://github.com/dedis/dela.git
23+
cd dela
24+
go install ./cli/crypto
25+
26+
- name: Check out code into the Go module directory
27+
uses: actions/checkout@v2
28+
29+
- name: Create a private key
30+
run: crypto bls signer new --save private.key
31+
32+
- name: Install memcoin
33+
run: make build
34+
35+
- name: Start 3 nodes
36+
run: |
37+
./memcoin --config /tmp/node1 start --postinstall --promaddr :9100 --proxyaddr :9080 --proxykey adbacd10fdb9822c71025d6d00092b8a4abb5ebcb673d28d863f7c7c5adaddf3 --listen tcp://0.0.0.0:2001 --public //localhost:2001 --routing tree &
38+
./memcoin --config /tmp/node2 start --postinstall --promaddr :9101 --proxyaddr :9081 --proxykey adbacd10fdb9822c71025d6d00092b8a4abb5ebcb673d28d863f7c7c5adaddf3 --listen tcp://0.0.0.0:2002 --public //localhost:2002 --routing tree &
39+
./memcoin --config /tmp/node3 start --postinstall --promaddr :9102 --proxyaddr :9082 --proxykey adbacd10fdb9822c71025d6d00092b8a4abb5ebcb673d28d863f7c7c5adaddf3 --listen tcp://0.0.0.0:2003 --public //localhost:2003 --routing tree &
40+
41+
- name: Run the setup
42+
run: ./setupnNode.sh -n 3 -d false
43+
44+
- name: Run the scenario Test
45+
run: go test -timeout 7m -run TestScenario ./integration/...

.github/workflows/go_test.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Go Test
1+
name: Go Unit Tests
22

33
on:
44
push:
@@ -10,14 +10,14 @@ jobs:
1010
name: Tests
1111
runs-on: ubuntu-latest
1212
steps:
13-
- name: Set up Go ^1.17
14-
uses: actions/setup-go@v2
13+
- name: Use Go >= 1.19
14+
uses: actions/setup-go@v3
1515
with:
16-
go-version: ^1.17
16+
go-version: '>=1.19'
1717
id: go
1818

1919
- name: Check out code into the Go module directory
20-
uses: actions/checkout@v2
20+
uses: actions/checkout@v3
2121

2222
- name: Run lint
2323
run: make lint

README.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
<a href="https://sonarcloud.io/summary/new_code?id=dedis_d-voting">
1313
<img src="https://sonarcloud.io/api/project_badges/measure?project=dedis_d-voting&metric=alert_status">
1414
</a>
15+
<a href="https://github.com/dedis/d-voting/actions/workflows/go_release.yml">
16+
<img src="https://github.com/dedis/d-voting/actions/workflows/go_release.yml/badge.svg">
17+
</a><br/>
1518
<a href="https://github.com/dedis/d-voting/graphs/contributors">
1619
<img alt="GitHub contributors" src="https://img.shields.io/github/contributors/dedis/d-voting">
1720
</a>
@@ -29,6 +32,9 @@
2932
<a href="https://github.com/dedis/d-voting/actions/workflows/go_memcoin_test.yml">
3033
<img src="https://github.com/dedis/d-voting/actions/workflows/go_memcoin_test.yml/badge.svg">
3134
</a>
35+
<a href="https://github.com/dedis/d-voting/actions/workflows/go_scenario_test.yml">
36+
<img src="https://github.com/dedis/d-voting/actions/workflows/go_scenario_test.yml/badge.svg">
37+
</a>
3238
<a href="https://github.com/dedis/d-voting/actions/workflows/go_integration_tests.yml">
3339
<img src="https://github.com/dedis/d-voting/actions/workflows/go_integration_tests.yml/badge.svg">
3440
</a><br/>
@@ -354,7 +360,7 @@ results.
354360

355361
# ⚙️ Setup
356362

357-
First be sure to have Go installed (at least 1.17).
363+
First be sure to have Go installed (at least 1.19).
358364

359365
Be sure to have the `crypto` utility from Dela:
360366

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
}

0 commit comments

Comments
 (0)