Skip to content

Commit

Permalink
Merge pull request #51 from c4dt/316
Browse files Browse the repository at this point in the history
fix: repair JSON export
  • Loading branch information
PascalinDe authored Nov 24, 2023
2 parents ea49694 + 97b98be commit 7f8c477
Show file tree
Hide file tree
Showing 35 changed files with 468 additions and 471 deletions.
6 changes: 3 additions & 3 deletions contracts/evoting/controller/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ func (a *scenarioTestAction) Execute(ctx node.Context) error {
return xerrors.Errorf(getFormErr, err)
}

dela.Logger.Info().Msg("Title of the form: " + form.Configuration.MainTitle)
dela.Logger.Info().Msg("Title of the form: " + form.Configuration.Title.En)
dela.Logger.Info().Msg("Status of the form: " + strconv.Itoa(int(form.Status)))

// ###################################### SHUFFLE BALLOTS ##################
Expand Down Expand Up @@ -642,15 +642,15 @@ func setupSimpleForm(ctx node.Context, secret kyber.Scalar, proxyAddr1 string,
return "", types.Form{}, nil, xerrors.Errorf("formID mismatch: %s != %s", form.FormID, formID)
}

fmt.Fprintf(ctx.Out, "Title of the form: "+form.Configuration.MainTitle)
fmt.Fprintf(ctx.Out, "Title of the form: "+form.Configuration.Title.En)
fmt.Fprintf(ctx.Out, "ID of the form: "+form.FormID)
fmt.Fprintf(ctx.Out, "Status of the form: "+strconv.Itoa(int(form.Status)))

return formID, form, formIDBuf, nil
}

func logFormStatus(form types.Form) {
dela.Logger.Info().Msg("Title of the form : " + form.Configuration.MainTitle)
dela.Logger.Info().Msg("Title of the form : " + form.Configuration.Title.En)
dela.Logger.Info().Msg("ID of the form : " + form.FormID)
dela.Logger.Info().Msg("Status of the form : " + strconv.Itoa(int(form.Status)))
}
Expand Down
28 changes: 21 additions & 7 deletions contracts/evoting/types/ballots.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,26 @@ func (b *Ballot) Equal(other Ballot) bool {
return true
}

// Title contains the titles in different languages.
type Title struct {
En string
Fr string
De string
}

// Hint contains explanations in different languages.
type Hint struct {
En string
Fr string
De string
}

// Subject is a wrapper around multiple questions that can be of type "select",
// "rank", or "text".
type Subject struct {
ID ID

Title string
Title Title

// Order defines the order of the different question, which all have a unique
// identifier. This is purely for display purpose.
Expand Down Expand Up @@ -414,11 +428,11 @@ func isValid(q Question) bool {
type Select struct {
ID ID

Title string
Title Title
MaxN uint
MinN uint
Choices []string
Hint string
Hint Hint
}

// GetID implements Question
Expand Down Expand Up @@ -480,11 +494,11 @@ func (s Select) unmarshalAnswers(sforms []string) ([]bool, error) {
type Rank struct {
ID ID

Title string
Title Title
MaxN uint
MinN uint
Choices []string
Hint string
Hint Hint
}

func (r Rank) GetID() string {
Expand Down Expand Up @@ -553,13 +567,13 @@ func (r Rank) unmarshalAnswers(ranks []string) ([]int8, error) {
type Text struct {
ID ID

Title string
Title Title
MaxN uint
MinN uint
MaxLength uint
Regex string
Choices []string
Hint string
Hint Hint
}

func (t Text) GetID() string {
Expand Down
42 changes: 21 additions & 21 deletions contracts/evoting/types/ballots_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,29 +56,29 @@ func TestBallot_Unmarshal(t *testing.T) {

Selects: []Select{{
ID: decodedQuestionID(1),
Title: "",
Title: Title{En: "", Fr: "", De: ""},
MaxN: 2,
MinN: 2,
Choices: make([]string, 3),
}, {
ID: decodedQuestionID(2),
Title: "",
Title: Title{En: "", Fr: "", De: ""},
MaxN: 3,
MinN: 3,
Choices: make([]string, 5),
}},

Ranks: []Rank{{
ID: decodedQuestionID(3),
Title: "",
Title: Title{En: "", Fr: "", De: ""},
MaxN: 4,
MinN: 0,
Choices: make([]string, 4),
}},

Texts: []Text{{
ID: decodedQuestionID(4),
Title: "",
Title: Title{En: "", Fr: "", De: ""},
MaxN: 2,
MinN: 2,
MaxLength: 10,
Expand Down Expand Up @@ -305,7 +305,7 @@ func TestSubject_MaxEncodedSize(t *testing.T) {
subject := Subject{
Subjects: []Subject{{
ID: "",
Title: "",
Title: Title{En: "", Fr: "", De: ""},
Order: nil,
Subjects: []Subject{},
Selects: []Select{},
Expand All @@ -315,37 +315,37 @@ func TestSubject_MaxEncodedSize(t *testing.T) {

Selects: []Select{{
ID: encodedQuestionID(1),
Title: "",
Title: Title{En: "", Fr: "", De: ""},
MaxN: 3,
MinN: 0,
Choices: make([]string, 3),
}, {
ID: encodedQuestionID(2),
Title: "",
Title: Title{En: "", Fr: "", De: ""},
MaxN: 5,
MinN: 0,
Choices: make([]string, 5),
}},

Ranks: []Rank{{
ID: encodedQuestionID(3),
Title: "",
Title: Title{En: "", Fr: "", De: ""},
MaxN: 4,
MinN: 0,
Choices: make([]string, 4),
}},

Texts: []Text{{
ID: encodedQuestionID(4),
Title: "",
Title: Title{En: "", Fr: "", De: ""},
MaxN: 2,
MinN: 0,
MaxLength: 10,
Regex: "",
Choices: make([]string, 2),
}, {
ID: encodedQuestionID(5),
Title: "",
Title: Title{En: "", Fr: "", De: ""},
MaxN: 1,
MinN: 0,
MaxLength: 10,
Expand All @@ -355,8 +355,8 @@ func TestSubject_MaxEncodedSize(t *testing.T) {
}

conf := Configuration{
MainTitle: "",
Scaffold: []Subject{subject},
Title: Title{En: "", Fr: "", De: ""},
Scaffold: []Subject{subject},
}

size := conf.MaxBallotSize()
Expand All @@ -368,7 +368,7 @@ func TestSubject_MaxEncodedSize(t *testing.T) {
func TestSubject_IsValid(t *testing.T) {
mainSubject := &Subject{
ID: ID(base64.StdEncoding.EncodeToString([]byte("S1"))),
Title: "",
Title: Title{En: "", Fr: "", De: ""},
Order: []ID{},
Subjects: []Subject{},
Selects: []Select{},
Expand All @@ -378,7 +378,7 @@ func TestSubject_IsValid(t *testing.T) {

subSubject := &Subject{
ID: ID(base64.StdEncoding.EncodeToString([]byte("S2"))),
Title: "",
Title: Title{En: "", Fr: "", De: ""},
Order: []ID{},
Subjects: []Subject{},
Selects: []Select{},
Expand All @@ -387,8 +387,8 @@ func TestSubject_IsValid(t *testing.T) {
}

configuration := Configuration{
MainTitle: "",
Scaffold: []Subject{*mainSubject, *subSubject},
Title: Title{En: "", Fr: "", De: ""},
Scaffold: []Subject{*mainSubject, *subSubject},
}

valid := configuration.IsValid()
Expand All @@ -400,15 +400,15 @@ func TestSubject_IsValid(t *testing.T) {

mainSubject.Selects = []Select{{
ID: encodedQuestionID(1),
Title: "",
Title: Title{En: "", Fr: "", De: ""},
MaxN: 0,
MinN: 0,
Choices: make([]string, 0),
}}

mainSubject.Ranks = []Rank{{
ID: encodedQuestionID(1),
Title: "",
Title: Title{En: "", Fr: "", De: ""},
MaxN: 0,
MinN: 0,
Choices: make([]string, 0),
Expand All @@ -423,7 +423,7 @@ func TestSubject_IsValid(t *testing.T) {

mainSubject.Ranks[0] = Rank{
ID: encodedQuestionID(2),
Title: "",
Title: Title{En: "", Fr: "", De: ""},
MaxN: 0,
MinN: 2,
Choices: make([]string, 0),
Expand All @@ -439,7 +439,7 @@ func TestSubject_IsValid(t *testing.T) {
mainSubject.Ranks = []Rank{}
mainSubject.Selects[0] = Select{
ID: encodedQuestionID(1),
Title: "",
Title: Title{En: "", Fr: "", De: ""},
MaxN: 1,
MinN: 0,
Choices: make([]string, 0),
Expand All @@ -455,7 +455,7 @@ func TestSubject_IsValid(t *testing.T) {
mainSubject.Selects = []Select{}
mainSubject.Texts = []Text{{
ID: encodedQuestionID(3),
Title: "",
Title: Title{En: "", Fr: "", De: ""},
MaxN: 2,
MinN: 4,
MaxLength: 0,
Expand Down
4 changes: 2 additions & 2 deletions contracts/evoting/types/election.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ type ShuffleInstance struct {

// Configuration contains the configuration of a new poll.
type Configuration struct {
MainTitle string
Scaffold []Subject
Title Title
Scaffold []Subject
}

// MaxBallotSize returns the maximum number of bytes required to store a ballot
Expand Down
6 changes: 3 additions & 3 deletions integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func getIntegrationTest(numNodes, numVotes int) func(*testing.T) {
form, err = getForm(formFac, formID, nodes[0].GetOrdering())
require.NoError(t, err)

fmt.Println("Title of the form : " + form.Configuration.MainTitle)
fmt.Println("Title of the form : " + form.Configuration.Title.En)
fmt.Println("ID of the form : " + string(form.FormID))
fmt.Println("Status of the form : " + strconv.Itoa(int(form.Status)))
fmt.Println("Number of decrypted ballots : " + strconv.Itoa(len(form.DecryptedBallots)))
Expand Down Expand Up @@ -304,7 +304,7 @@ func getIntegrationTestCrash(numNodes, numVotes, failingNodes int) func(*testing
form, err = getForm(formFac, formID, nodes[0].GetOrdering())
require.NoError(t, err)

fmt.Println("Title of the form : " + form.Configuration.MainTitle)
fmt.Println("Title of the form : " + form.Configuration.Title.En)
fmt.Println("ID of the form : " + string(form.FormID))
fmt.Println("Status of the form : " + strconv.Itoa(int(form.Status)))
fmt.Println("Number of decrypted ballots : " + strconv.Itoa(len(form.DecryptedBallots)))
Expand Down Expand Up @@ -425,7 +425,7 @@ func getIntegrationBenchmark(numNodes, numVotes int) func(*testing.B) {
form, err = getForm(formFac, formID, nodes[0].GetOrdering())
require.NoError(b, err)

fmt.Println("Title of the form : " + form.Configuration.MainTitle)
fmt.Println("Title of the form : " + form.Configuration.Title.En)
fmt.Println("ID of the form : " + string(form.FormID))
fmt.Println("Status of the form : " + strconv.Itoa(int(form.Status)))
fmt.Println("Number of decrypted ballots : " + strconv.Itoa(len(form.DecryptedBallots)))
Expand Down
12 changes: 6 additions & 6 deletions integration/performance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func BenchmarkIntegration_CustomVotesScenario(b *testing.B) {
}

// ##### CREATE FORM #####
formID, err := createFormNChunks(m, "Three votes form", adminID, numChunksPerBallot)
formID, err := createFormNChunks(m, types.Title{En: "Three votes form", Fr: "", De: ""}, adminID, numChunksPerBallot)
require.NoError(b, err)

time.Sleep(time.Millisecond * 1000)
Expand Down Expand Up @@ -124,7 +124,7 @@ func BenchmarkIntegration_CustomVotesScenario(b *testing.B) {
form, err = getForm(formFac, formID, nodes[0].GetOrdering())
require.NoError(b, err)

fmt.Println("Title of the form : " + form.Configuration.MainTitle)
fmt.Println("Title of the form : " + form.Configuration.Title.En)
fmt.Println("ID of the form : " + string(form.FormID))
fmt.Println("Status of the form : " + strconv.Itoa(int(form.Status)))
fmt.Println("Number of decrypted ballots : " + strconv.Itoa(len(form.DecryptedBallots)))
Expand All @@ -146,25 +146,25 @@ func BenchmarkIntegration_CustomVotesScenario(b *testing.B) {
closeNodesBench(b, nodes)
}

func createFormNChunks(m txManager, title string, admin string, numChunks int) ([]byte, error) {
func createFormNChunks(m txManager, title types.Title, admin string, numChunks int) ([]byte, error) {

defaultBallotContent := "text:" + encodeID("bb") + ":\n\n"
textSize := 29*numChunks - len(defaultBallotContent)

// Define the configuration :
configuration := types.Configuration{
MainTitle: title,
Title: title,
Scaffold: []types.Subject{
{
ID: "aa",
Title: "subject1",
Title: types.Title{En: "subject1", Fr: "", De: ""},
Order: nil,
Subjects: nil,
Selects: nil,
Ranks: []types.Rank{},
Texts: []types.Text{{
ID: "bb",
Title: "Enter favorite snack",
Title: types.Title{En: "Enter favorite snack", Fr: "", De: ""},
MaxN: 1,
MinN: 0,
MaxLength: uint(base64.StdEncoding.DecodedLen(textSize)),
Expand Down
4 changes: 2 additions & 2 deletions integration/votes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func getIntegrationTestBadVote(numNodes, numVotes, numBadVotes int) func(*testin
form, err = getForm(formFac, formID, nodes[0].GetOrdering())
require.NoError(t, err)

fmt.Println("Title of the form : " + form.Configuration.MainTitle)
fmt.Println("Title of the form : " + form.Configuration.Title.En)
fmt.Println("ID of the form : " + string(form.FormID))
fmt.Println("Status of the form : " + strconv.Itoa(int(form.Status)))
fmt.Println("Number of decrypted ballots : " + strconv.Itoa(len(form.DecryptedBallots)))
Expand Down Expand Up @@ -281,7 +281,7 @@ func getIntegrationTestRevote(numNodes, numVotes, numRevotes int) func(*testing.
form, err = getForm(formFac, formID, nodes[0].GetOrdering())
require.NoError(t, err)

fmt.Println("Title of the form : " + form.Configuration.MainTitle)
fmt.Println("Title of the form : " + form.Configuration.Title.En)
fmt.Println("ID of the form : " + string(form.FormID))
fmt.Println("Status of the form : " + strconv.Itoa(int(form.Status)))
fmt.Println("Number of decrypted ballots : " + strconv.Itoa(len(form.DecryptedBallots)))
Expand Down
Loading

0 comments on commit 7f8c477

Please sign in to comment.