Skip to content

Commit

Permalink
e2etest: make ops a map[string]operation
Browse files Browse the repository at this point in the history
  • Loading branch information
altergui committed Apr 5, 2023
1 parent 9eefbe2 commit 751c654
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 27 deletions.
5 changes: 2 additions & 3 deletions cmd/end2endtest/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ import (
)

func init() {
ops = append(ops, operation{
ops["tokentxs"] = operation{
test: &E2ETokenTxs{},
name: "tokentxs",
description: "Tests all token related transactions",
example: os.Args[0] + " --operation=tokentxs " +
"--host http://127.0.0.1:9090/v2",
})
}
}

var _ VochainTest = (*E2ETokenTxs)(nil)
Expand Down
5 changes: 2 additions & 3 deletions cmd/end2endtest/encrypted.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@ import (
)

func init() {
ops = append(ops, operation{
ops["encryptedelection"] = operation{
test: &E2EEncryptedElection{},
name: "encryptedelection",
description: "Publishes a census and a non-anonymous, secret-until-the-end election, emits N votes and verifies the results",
example: os.Args[0] + " --operation=encryptedelection --votes=1000",
})
}
}

var _ VochainTest = (*E2EEncryptedElection)(nil)
Expand Down
33 changes: 18 additions & 15 deletions cmd/end2endtest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,17 @@ type VochainTest interface {
type operation struct {
test VochainTest

name, description, example string
description, example string
}

var ops = []operation{}
var ops = map[string]operation{}

func init() {
ops = make(map[string]operation)
}
func opNames() (names []string) {
for _, op := range ops {
names = append(names, op.name)
for name, _ := range ops {
names = append(names, name)
}
return names
}
Expand Down Expand Up @@ -83,8 +86,8 @@ func main() {
fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
flag.PrintDefaults()
fmt.Fprintf(os.Stderr, "\nSome examples of different operation modes:\n")
for _, op := range ops {
fmt.Fprintf(os.Stderr, "### %s\n", op.name)
for name, op := range ops {
fmt.Fprintf(os.Stderr, "### %s\n", name)
fmt.Fprintf(os.Stderr, "\t"+op.description+"\n")
fmt.Fprintf(os.Stderr, op.example+"\n")
fmt.Fprintf(os.Stderr, "\n")
Expand Down Expand Up @@ -112,13 +115,8 @@ func main() {
log.Infof("privkey %x = account %s", ak.PrivateKey(), ak.AddressString())
}

var test VochainTest
for _, op := range ops {
if op.name == c.operation {
test = op.test
}
}
if test == nil {
op, found := ops[c.operation]
if !found {
log.Fatal("no valid operation mode specified")
}

Expand All @@ -127,16 +125,21 @@ func main() {
log.Fatal(err)
}

err = test.Setup(api, c)
err = op.test.Setup(api, c)
if err != nil {
log.Fatal(err)
}

duration, err := test.Run()
duration, err := op.test.Run()
if err != nil {
log.Fatal(err)
}
log.Infow("test finished", "duration", duration.String())

err = op.test.Teardown()
if err != nil {
log.Fatal(err)
}
}

// NewAPIclient connects to the API host and returns the handle
Expand Down
5 changes: 2 additions & 3 deletions cmd/end2endtest/plaintext.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@ import (
)

func init() {
ops = append(ops, operation{
ops["plaintextelection"] = operation{
test: &E2EPlaintextElection{},
name: "plaintextelection",
description: "Publishes a census and a non-anonymous, non-secret election, emits N votes and verifies the results",
example: os.Args[0] + " --operation=plaintextelection --votes=1000",
})
}
}

var _ VochainTest = (*E2EPlaintextElection)(nil)
Expand Down
5 changes: 2 additions & 3 deletions cmd/end2endtest/zkweighted.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ import (
)

func init() {
ops = append(ops, operation{
ops["anonelection"] = operation{
test: &E2EAnonElection{},
name: "anonelection",
description: "Performs a complete test of anonymous election, from creating a census to voting and validating votes",
example: os.Args[0] + " --operation=anonelection --votes=1000 " +
"--oracleKey=6aae1d165dd9776c580b8fdaf8622e39c5f943c715e20690080bbfce2c760223",
})
}
}

var _ VochainTest = (*E2EAnonElection)(nil)
Expand Down

0 comments on commit 751c654

Please sign in to comment.