Skip to content

Commit

Permalink
Merge pull request #163 from dedis/updates-and-test-fixes
Browse files Browse the repository at this point in the history
Updates Dela+Go and fixes the tests
  • Loading branch information
nkcr authored Sep 8, 2022
2 parents 8a82240 + 0386cab commit b6a48be
Show file tree
Hide file tree
Showing 25 changed files with 537 additions and 395 deletions.
26 changes: 2 additions & 24 deletions .github/workflows/go_integration_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,9 @@ jobs:
uses: actions/setup-go@v2
with:
go-version: ^1.17

- name: Install crypto util from Dela
run: |
git clone https://github.com/dedis/dela.git
cd dela
go install ./cli/crypto

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Create a private key
run: crypto bls signer new --save private.key

- name: Install memcoin
run: make build

- name: Start 3 nodes
run: |
./memcoin --config /tmp/node1 start --postinstall --promaddr :9100 --proxyaddr :9080 --proxykey adbacd10fdb9822c71025d6d00092b8a4abb5ebcb673d28d863f7c7c5adaddf3 --listen tcp://0.0.0.0:2001 --public //localhost:2001 &
./memcoin --config /tmp/node2 start --postinstall --promaddr :9101 --proxyaddr :9081 --proxykey adbacd10fdb9822c71025d6d00092b8a4abb5ebcb673d28d863f7c7c5adaddf3 --listen tcp://0.0.0.0:2002 --public //localhost:2002 &
./memcoin --config /tmp/node3 start --postinstall --promaddr :9102 --proxyaddr :9082 --proxykey adbacd10fdb9822c71025d6d00092b8a4abb5ebcb673d28d863f7c7c5adaddf3 --listen tcp://0.0.0.0:2003 --public //localhost:2003 &
- name: Run the setup
run: ./setupnNode.sh -n 3 -d false


- name: Test integration & benchmark with coverage
run: go test -bench -cover -tags=integration ./integration/...
- name: Run the integration test
run: go test -timeout 7m -run TestIntegration ./integration/...
45 changes: 45 additions & 0 deletions .github/workflows/go_scenario_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Go Scenario Test (with proxy)

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:

test:
name: Tests
runs-on: ubuntu-latest
steps:
- name: Set up Go ^1.17
uses: actions/setup-go@v2
with:
go-version: ^1.17

- name: Install crypto util from Dela
run: |
git clone https://github.com/dedis/dela.git
cd dela
go install ./cli/crypto
- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Create a private key
run: crypto bls signer new --save private.key

- name: Install memcoin
run: make build

- name: Start 3 nodes
run: |
./memcoin --config /tmp/node1 start --postinstall --promaddr :9100 --proxyaddr :9080 --proxykey adbacd10fdb9822c71025d6d00092b8a4abb5ebcb673d28d863f7c7c5adaddf3 --listen tcp://0.0.0.0:2001 --public //localhost:2001 --routing tree &
./memcoin --config /tmp/node2 start --postinstall --promaddr :9101 --proxyaddr :9081 --proxykey adbacd10fdb9822c71025d6d00092b8a4abb5ebcb673d28d863f7c7c5adaddf3 --listen tcp://0.0.0.0:2002 --public //localhost:2002 --routing tree &
./memcoin --config /tmp/node3 start --postinstall --promaddr :9102 --proxyaddr :9082 --proxykey adbacd10fdb9822c71025d6d00092b8a4abb5ebcb673d28d863f7c7c5adaddf3 --listen tcp://0.0.0.0:2003 --public //localhost:2003 --routing tree &
- name: Run the setup
run: ./setupnNode.sh -n 3 -d false

- name: Run the scenario Test
run: go test -timeout 7m -run TestScenario ./integration/...
10 changes: 5 additions & 5 deletions .github/workflows/go_test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Go Test
name: Go Unit Tests

on:
push:
Expand All @@ -10,14 +10,14 @@ jobs:
name: Tests
runs-on: ubuntu-latest
steps:
- name: Set up Go ^1.17
uses: actions/setup-go@v2
- name: Use Go >= 1.19
uses: actions/setup-go@v3
with:
go-version: ^1.17
go-version: '>=1.19'
id: go

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

- name: Run lint
run: make lint
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
<a href="https://sonarcloud.io/summary/new_code?id=dedis_d-voting">
<img src="https://sonarcloud.io/api/project_badges/measure?project=dedis_d-voting&metric=alert_status">
</a>
<a href="https://github.com/dedis/d-voting/actions/workflows/go_release.yml">
<img src="https://github.com/dedis/d-voting/actions/workflows/go_release.yml/badge.svg">
</a><br/>
<a href="https://github.com/dedis/d-voting/graphs/contributors">
<img alt="GitHub contributors" src="https://img.shields.io/github/contributors/dedis/d-voting">
</a>
Expand All @@ -29,6 +32,9 @@
<a href="https://github.com/dedis/d-voting/actions/workflows/go_memcoin_test.yml">
<img src="https://github.com/dedis/d-voting/actions/workflows/go_memcoin_test.yml/badge.svg">
</a>
<a href="https://github.com/dedis/d-voting/actions/workflows/go_scenario_test.yml">
<img src="https://github.com/dedis/d-voting/actions/workflows/go_scenario_test.yml/badge.svg">
</a>
<a href="https://github.com/dedis/d-voting/actions/workflows/go_integration_tests.yml">
<img src="https://github.com/dedis/d-voting/actions/workflows/go_integration_tests.yml/badge.svg">
</a><br/>
Expand Down Expand Up @@ -354,7 +360,7 @@ results.

# ⚙️ Setup

First be sure to have Go installed (at least 1.17).
First be sure to have Go installed (at least 1.19).

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

Expand Down
4 changes: 2 additions & 2 deletions cli/cosipbftcontroller/action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package controller
import (
"bytes"
"context"
"io/ioutil"
"io"
"testing"
"time"

Expand Down Expand Up @@ -172,7 +172,7 @@ func prepContext(calls *fake.Call) node.Context {
ctx := node.Context{
Injector: node.NewInjector(),
Flags: make(node.FlagSet),
Out: ioutil.Discard,
Out: io.Discard,
}

events := []ordering.Event{
Expand Down
5 changes: 2 additions & 3 deletions cli/cosipbftcontroller/mod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package controller

import (
"encoding"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -105,7 +104,7 @@ func TestMinimal_MalformedKey_OnStart(t *testing.T) {
}

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

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

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

fset := make(node.FlagSet)
Expand Down
12 changes: 6 additions & 6 deletions cli/memcoin/mod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"net"
"os"
"path/filepath"
Expand All @@ -25,7 +25,7 @@ func TestMemcoin_Main(t *testing.T) {
// be able to communicate, but the chain should proceed because of the
// threshold.
func TestMemcoin_Scenario_SetupAndTransactions(t *testing.T) {
dir, err := ioutil.TempDir(os.TempDir(), "memcoin1")
dir, err := os.MkdirTemp(os.TempDir(), "memcoin1")
require.NoError(t, err)

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

cfg := config{Channel: sigs, Writer: ioutil.Discard}
cfg := config{Channel: sigs, Writer: io.Discard}

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

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

cfg := config{Channel: sigs, Writer: ioutil.Discard}
cfg := config{Channel: sigs, Writer: io.Discard}

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

cfg := config{Channel: sigs, Writer: ioutil.Discard}
cfg := config{Channel: sigs, Writer: io.Discard}

for i, node := range nodes {
runNode(t, node, cfg, ports[i], &wg)
Expand Down
13 changes: 6 additions & 7 deletions contracts/evoting/controller/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"strconv"
"strings"
Expand Down Expand Up @@ -267,7 +266,7 @@ func (a *scenarioTestAction) Execute(ctx node.Context) error {
}

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

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

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

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

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

Expand Down Expand Up @@ -721,7 +720,7 @@ func updateElection(secret kyber.Scalar, proxyAddr, electionIDHex, action string
}

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

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

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

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

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

Expand Down
2 changes: 0 additions & 2 deletions contracts/evoting/types/ballots.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,6 @@ func (b *Ballot) invalidate() {

// Equal performs a loose comparison of a ballot.
func (b *Ballot) Equal(other Ballot) bool {
fmt.Printf("b: %v\n", b)
fmt.Printf("other: %v\n", other)
if len(b.SelectResultIDs) != len(other.SelectResultIDs) {
return false
}
Expand Down
Loading

0 comments on commit b6a48be

Please sign in to comment.