Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates Dela+Go and fixes the tests #163

Merged
merged 10 commits into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
27 changes: 10 additions & 17 deletions contracts/evoting/types/ballots_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func TestBallot_Unmarshal(t *testing.T) {

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// with wrongly ID not in base64
mainSubject.ID = "zzz"

configuration.Scaffold = []Subject{*mainSubject}

valid = configuration.IsValid()
require.False(t, valid)

// with double IDs

mainSubject.ID = ID(base64.StdEncoding.EncodeToString([]byte("S1")))
Expand Down
36 changes: 34 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/dedis/d-voting

go 1.16
go 1.19

require (
github.com/gorilla/mux v1.8.0
Expand All @@ -9,10 +9,42 @@ require (
github.com/rs/zerolog v1.19.0
github.com/stretchr/testify v1.7.0
github.com/uber/jaeger-client-go v2.25.0+incompatible
go.dedis.ch/dela v0.0.0-20220705073643-0b58fb2e471f
go.dedis.ch/dela v0.0.0-20220727144418-4a9466c2c294
go.dedis.ch/dela-apps v0.0.0-20211019120455-a0db752a0ba0
go.dedis.ch/kyber/v3 v3.1.0-alpha
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f
golang.org/x/tools v0.1.11-0.20220316014157-77aa08bb151a
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/opentracing-contrib/go-grpc v0.0.0-20200813121455-4a6760c71486 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.32.1 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/rs/xid v1.2.1 // indirect
github.com/russross/blackfriday/v2 v2.0.1 // indirect
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
github.com/uber/jaeger-lib v2.4.0+incompatible // indirect
github.com/urfave/cli/v2 v2.2.0 // indirect
go.dedis.ch/fixbuf v1.0.3 // indirect
go.dedis.ch/protobuf v1.0.11 // indirect
go.etcd.io/bbolt v1.3.5 // indirect
go.uber.org/atomic v1.7.0 // indirect
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 // indirect
golang.org/x/text v0.3.7 // indirect
google.golang.org/genproto v0.0.0-20200825200019-8632dd797987 // indirect
google.golang.org/grpc v1.45.0 // indirect
google.golang.org/protobuf v1.26.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
)
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,8 @@ github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
go.dedis.ch/dela v0.0.0-20211018150429-1fdbe35cd189/go.mod h1:GVQ2MumgCcAkor2MmfRCoqTBsFjaaqt7HfJpQLhMGok=
go.dedis.ch/dela v0.0.0-20220428080424-2348afb6228a h1:Ahci1dtYYj9MIVOUjsA2kavD6oAEmnLZrwBctzHOYYA=
go.dedis.ch/dela v0.0.0-20220428080424-2348afb6228a/go.mod h1:IIIV0aR0f1c9z4jRB2HVYYeLK7XbQ6pfqv6RufaXmUg=
go.dedis.ch/dela v0.0.0-20220705073643-0b58fb2e471f h1:BbrlaRV3rFMTlKUQ+o2PJJQUlmyINIqB4FPmMlsSLjU=
go.dedis.ch/dela v0.0.0-20220705073643-0b58fb2e471f/go.mod h1:IIIV0aR0f1c9z4jRB2HVYYeLK7XbQ6pfqv6RufaXmUg=
go.dedis.ch/dela v0.0.0-20220727144418-4a9466c2c294 h1:q+kgJ4Cso4daxyR1owhz5jmFNxTG/O0xI4O/ppHaPdQ=
go.dedis.ch/dela v0.0.0-20220727144418-4a9466c2c294/go.mod h1:IIIV0aR0f1c9z4jRB2HVYYeLK7XbQ6pfqv6RufaXmUg=
go.dedis.ch/dela-apps v0.0.0-20211019120455-a0db752a0ba0 h1:gPrJd+7QUuADpfToMKr80maGnjGPeB7ft7iNrkAtwGY=
go.dedis.ch/dela-apps v0.0.0-20211019120455-a0db752a0ba0/go.mod h1:MoJSdm3LXkNtiKEK3eiBKgqFhory4v8sBr7ldFP/vFc=
go.dedis.ch/fixbuf v1.0.3 h1:hGcV9Cd/znUxlusJ64eAlExS+5cJDIyTyEG+otu5wQs=
Expand Down
2 changes: 1 addition & 1 deletion integration/dvotingdela.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ func (c dVotingNode) Setup(nodes ...dela) {

token := joinable.GenerateToken(time.Hour)

certHash, err := joinable.GetCertificateStore().Hash(joinable.GetCertificate())
certHash, err := joinable.GetCertificateStore().Hash(joinable.GetCertificateChain())
require.NoError(c.t, err)

for _, n := range nodes {
Expand Down
3 changes: 1 addition & 2 deletions integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"encoding/hex"
"fmt"
"io"
"io/ioutil"
"math/rand"
"os"
"strconv"
Expand Down Expand Up @@ -60,7 +59,7 @@ func getIntegrationTest(numNodes, numVotes int) func(*testing.T) {

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

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

defer os.RemoveAll(dirPath)
Expand Down
3 changes: 1 addition & 2 deletions integration/performance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"crypto/sha256"
"encoding/base64"
"fmt"
"io/ioutil"
"math/rand"
"os"
"strconv"
Expand Down Expand Up @@ -39,7 +38,7 @@ func BenchmarkIntegration_CustomVotesScenario(b *testing.B) {

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

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

defer os.RemoveAll(dirPath)
Expand Down
2 changes: 0 additions & 2 deletions internal/testing/fake/ordering.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package fake
import (
"context"
"encoding/hex"
"fmt"

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

f.Status = true

fmt.Println("watch", results[0])
f.Channel <- ordering.Event{
Index: 0,
Transactions: results,
Expand Down
Loading