diff --git a/apiclient/vote.go b/apiclient/vote.go index c532092ff..23b06dfd8 100644 --- a/apiclient/vote.go +++ b/apiclient/vote.go @@ -37,7 +37,7 @@ import ( // (deprecated). type VoteData struct { Choices []int - ElectionID types.HexBytes + Election *api.Election VoteWeight *big.Int ProofMkTree *CensusProof @@ -60,27 +60,25 @@ func (cl *HTTPclient) Vote(v *VoteData) (types.HexBytes, error) { if v.VoterAccount != nil { c = cl.Clone(hex.EncodeToString(v.VoterAccount.PrivateKey())) } - election, err := c.Election(v.ElectionID) - if err != nil { - return nil, err - } var vote *models.VoteEnvelope + var err error + if v.Keys != nil { - vote, err = c.voteEnvelopeWithKeys(v.Choices, v.Keys, election) + vote, err = c.voteEnvelopeWithKeys(v.Choices, v.Keys, v.Election) } else { - vote, err = c.prepareVoteEnvelope(v.Choices, election) + vote, err = c.prepareVoteEnvelope(v.Choices, v.Election) } if err != nil { return nil, err } - log.Debugw("generating a new vote", "electionId", v.ElectionID, "voter", c.account.AddressString()) + log.Debugw("generating a new vote", "electionId", v.Election.ElectionID, "voter", c.account.AddressString()) voteAPI := &api.Vote{} censusOriginCSP := models.CensusOrigin_name[int32(models.CensusOrigin_OFF_CHAIN_CA)] censusOriginWeighted := models.CensusOrigin_name[int32(models.CensusOrigin_OFF_CHAIN_TREE_WEIGHTED)] switch { - case election.VoteMode.Anonymous: + case v.Election.VoteMode.Anonymous: // support no vote weight provided if v.VoteWeight == nil { v.VoteWeight = v.ProofMkTree.LeafWeight @@ -89,8 +87,8 @@ func (cl *HTTPclient) Vote(v *VoteData) (types.HexBytes, error) { // information and encode it into a json rawInputs, err := circuit.GenerateCircuitInput(circuit.CircuitInputsParameters{ Account: c.account, - ElectionId: election.ElectionID, - CensusRoot: election.Census.CensusRoot, + ElectionId: v.Election.ElectionID, + CensusRoot: v.Election.Census.CensusRoot, SIKRoot: v.ProofSIKTree.Root, CensusSiblings: v.ProofMkTree.Siblings, SIKSiblings: v.ProofSIKTree.Siblings, @@ -136,7 +134,7 @@ func (cl *HTTPclient) Vote(v *VoteData) (types.HexBytes, error) { if err != nil { return nil, fmt.Errorf("could not prepare vote transaction: %w", err) } - case election.Census.CensusOrigin == censusOriginWeighted: + case v.Election.Census.CensusOrigin == censusOriginWeighted: // support custom vote weight var voteWeight []byte if v.VoteWeight != nil { @@ -160,7 +158,7 @@ func (cl *HTTPclient) Vote(v *VoteData) (types.HexBytes, error) { if err != nil { return nil, err } - case election.Census.CensusOrigin == censusOriginCSP: + case v.Election.Census.CensusOrigin == censusOriginCSP: // decode the CSP proof and include in a VoteEnvelope p := models.ProofCA{} if err := proto.Unmarshal(v.ProofCSP, &p); err != nil { diff --git a/cmd/end2endtest/ballot.go b/cmd/end2endtest/ballot.go index 4dd364b32..68bab6bbb 100644 --- a/cmd/end2endtest/ballot.go +++ b/cmd/end2endtest/ballot.go @@ -228,7 +228,7 @@ func sendAndValidateVotes(e e2eElection, choices [][]int, expectedResults [][]*t e.voters.Range(func(key, value any) bool { if acctp, ok := value.(acctProof); ok { votes = append(votes, &apiclient.VoteData{ - ElectionID: e.election.ElectionID, + Election: e.election, ProofMkTree: acctp.proof, Choices: choices[vcount], VoterAccount: acctp.account, diff --git a/cmd/end2endtest/censusize.go b/cmd/end2endtest/censusize.go index 160fa9bc6..ea89411f1 100644 --- a/cmd/end2endtest/censusize.go +++ b/cmd/end2endtest/censusize.go @@ -67,7 +67,7 @@ func (t *E2EMaxCensusSizeElection) Run() error { t.voters.Range(func(key, value any) bool { if acctp, ok := value.(acctProof); ok { votes = append(votes, &apiclient.VoteData{ - ElectionID: t.election.ElectionID, + Election: t.election, ProofMkTree: acctp.proof, Choices: []int{0}, VoterAccount: acctp.account, diff --git a/cmd/end2endtest/csp.go b/cmd/end2endtest/csp.go index c4741c6d5..3f7da8a21 100644 --- a/cmd/end2endtest/csp.go +++ b/cmd/end2endtest/csp.go @@ -58,7 +58,7 @@ func (t *E2ECSPElection) Run() error { t.voters.Range(func(key, value any) bool { if acctp, ok := value.(acctProof); ok { votes = append(votes, &apiclient.VoteData{ - ElectionID: t.election.ElectionID, + Election: t.election, ProofCSP: acctp.proof.Proof, Choices: []int{0}, VoterAccount: acctp.account, diff --git a/cmd/end2endtest/dynamicensus.go b/cmd/end2endtest/dynamicensus.go index ca689884c..878da8e29 100644 --- a/cmd/end2endtest/dynamicensus.go +++ b/cmd/end2endtest/dynamicensus.go @@ -85,7 +85,7 @@ func (t *E2EDynamicensusElection) Run() error { } v := apiclient.VoteData{ - ElectionID: election.election.ElectionID, + Election: election.election, ProofMkTree: proof, VoterAccount: vAccts[0], Choices: []int{1}, @@ -116,7 +116,7 @@ func (t *E2EDynamicensusElection) Run() error { t.elections[0].voters.Range(func(key, value any) bool { if acctp, ok := value.(acctProof); ok { votes = append(votes, &apiclient.VoteData{ - ElectionID: t.elections[0].election.ElectionID, + Election: t.elections[0].election, ProofMkTree: acctp.proof, Choices: []int{0}, VoterAccount: acctp.account, @@ -225,7 +225,7 @@ func (t *E2EDynamicensusElection) Run() error { defer wg.Done() api := t.elections[1].api - electionID := t.elections[1].election.ElectionID + election := t.elections[1].election // Send the votes (parallelized) startTime := time.Now() @@ -236,7 +236,7 @@ func (t *E2EDynamicensusElection) Run() error { t.elections[1].voters.Range(func(key, value any) bool { if acctp, ok := value.(acctProof); ok { votes = append(votes, &apiclient.VoteData{ - ElectionID: electionID, + Election: election, ProofMkTree: acctp.proof, Choices: []int{0}, VoterAccount: acctp.account, @@ -247,7 +247,7 @@ func (t *E2EDynamicensusElection) Run() error { errs := t.elections[1].sendVotes(votes[1:]) if len(errs) > 0 { - errCh <- fmt.Errorf("error from electionID: %s, %+v", electionID, errs) + errCh <- fmt.Errorf("error from electionID: %s, %+v", election.ElectionID, errs) return } @@ -259,13 +259,13 @@ func (t *E2EDynamicensusElection) Run() error { var err error if censusRoot2, _, err = setupNewCensusAndVote(t.elections[1]); err != nil { - errCh <- fmt.Errorf("unexpected error from electionID: %s, error: %s", electionID, err) + errCh <- fmt.Errorf("unexpected error from electionID: %s, error: %s", election.ElectionID, err) return } log.Debugf("election details before: %s %s %x", t.elections[1].election.Census.CensusOrigin, t.elections[1].election.Census.CensusURL, t.elections[1].election.Census.CensusRoot) - if _, err := api.TransactionSetCensus(electionID, vapi.ElectionCensus{ + if _, err := api.TransactionSetCensus(election.ElectionID, vapi.ElectionCensus{ CensusOrigin: "OFF_CHAIN_TREE_WEIGHTED", CensusRoot: censusRoot2, CensusURL: "http://test/census", diff --git a/cmd/end2endtest/encrypted.go b/cmd/end2endtest/encrypted.go index e4e7c321c..7597bcc8f 100644 --- a/cmd/end2endtest/encrypted.go +++ b/cmd/end2endtest/encrypted.go @@ -69,7 +69,7 @@ func (t *E2EEncryptedElection) Run() error { t.voters.Range(func(key, value any) bool { if acctp, ok := value.(acctProof); ok { votes = append(votes, &apiclient.VoteData{ - ElectionID: t.election.ElectionID, + Election: t.election, ProofMkTree: acctp.proof, Choices: []int{vcount % 2}, VoterAccount: acctp.account, diff --git a/cmd/end2endtest/helpers.go b/cmd/end2endtest/helpers.go index d97ca225b..64a2cf80f 100644 --- a/cmd/end2endtest/helpers.go +++ b/cmd/end2endtest/helpers.go @@ -504,8 +504,8 @@ func (t *e2eElection) sendVotes(votes []*apiclient.VoteData) map[int]error { queues = append(queues, make(map[int]*apiclient.VoteData, len(votes))) } for i, v := range votes { - if v.ElectionID == nil { - v.ElectionID = t.election.ElectionID + if v.Election == nil { + v.Election = t.election } queues[i%t.config.parallelCount][i] = v } diff --git a/cmd/end2endtest/overwrite.go b/cmd/end2endtest/overwrite.go index 2e8d002ae..eecd579a7 100644 --- a/cmd/end2endtest/overwrite.go +++ b/cmd/end2endtest/overwrite.go @@ -63,7 +63,7 @@ func (t *E2EOverwriteElection) Run() error { t.voters.Range(func(key, value any) bool { if acctp, ok := value.(acctProof); ok { votes = append(votes, &apiclient.VoteData{ - ElectionID: t.election.ElectionID, + Election: t.election, ProofMkTree: acctp.proof, Choices: []int{0}, VoterAccount: acctp.account, diff --git a/cmd/end2endtest/plaintext.go b/cmd/end2endtest/plaintext.go index a197904ea..df0d1053c 100644 --- a/cmd/end2endtest/plaintext.go +++ b/cmd/end2endtest/plaintext.go @@ -62,7 +62,7 @@ func (t *E2EPlaintextElection) Run() error { t.voters.Range(func(key, value any) bool { if acctp, ok := value.(acctProof); ok { votes = append(votes, &apiclient.VoteData{ - ElectionID: t.election.ElectionID, + Election: t.election, ProofMkTree: acctp.proof, Choices: []int{vcount % 2}, VoterAccount: acctp.account, diff --git a/cmd/end2endtest/race.go b/cmd/end2endtest/race.go index 1e9a9d198..b9820e1e6 100644 --- a/cmd/end2endtest/race.go +++ b/cmd/end2endtest/race.go @@ -64,7 +64,7 @@ func (t *E2ERaceDuringCommit) Run() error { t.voters.Range(func(key, value any) bool { if acctp, ok := value.(acctProof); ok { votes = append(votes, &apiclient.VoteData{ - ElectionID: t.election.ElectionID, + Election: t.election, ProofMkTree: acctp.proof, Choices: []int{vcount % 2}, VoterAccount: acctp.account, diff --git a/cmd/end2endtest/zkweighted.go b/cmd/end2endtest/zkweighted.go index 8ad95bdb6..355fc482e 100644 --- a/cmd/end2endtest/zkweighted.go +++ b/cmd/end2endtest/zkweighted.go @@ -65,7 +65,7 @@ func (t *E2EAnonElection) Run() error { t.voters.Range(func(key, value any) bool { if acctp, ok := value.(acctProof); ok { votes = append(votes, &apiclient.VoteData{ - ElectionID: t.election.ElectionID, + Election: t.election, ProofMkTree: acctp.proof, ProofSIKTree: acctp.proofSIK, Choices: []int{vcount % 2}, @@ -137,7 +137,7 @@ func (t *E2EAnonElectionTempSIKs) Run() error { t.voters.Range(func(key, value any) bool { if acctp, ok := value.(acctProof); ok { votes = append(votes, &apiclient.VoteData{ - ElectionID: t.election.ElectionID, + Election: t.election, ProofMkTree: acctp.proof, ProofSIKTree: acctp.proofSIK, Choices: []int{vcount % 2}, diff --git a/vocone/vocone_test.go b/vocone/vocone_test.go index 326ff91ea..420c48dcf 100644 --- a/vocone/vocone_test.go +++ b/vocone/vocone_test.go @@ -115,19 +115,20 @@ func testCSPvote(cli *apiclient.HTTPclient) error { } // Wait until the process is ready - info, err := cli.ChainInfo() + ctx1, cancel1 := context.WithTimeout(context.Background(), time.Second*30) + defer cancel1() + election, err := cli.WaitUntilElectionStatus(ctx1, processID, "READY") if err != nil { return err } - cli.WaitUntilHeight(context.Background(), info.Height+2) // Send the votes for i, k := range voterKeys { c := cli.Clone(fmt.Sprintf("%x", k.PrivateKey())) c.Vote(&apiclient.VoteData{ - Choices: []int{1}, - ElectionID: processID, - ProofCSP: proofs[i], + Choices: []int{1}, + Election: election, + ProofCSP: proofs[i], }) } @@ -136,7 +137,7 @@ func testCSPvote(cli *apiclient.HTTPclient) error { } ctx, cancel := context.WithTimeout(context.Background(), time.Second*30) defer cancel() - election, err := cli.WaitUntilElectionStatus(ctx, processID, "RESULTS") + election, err = cli.WaitUntilElectionStatus(ctx, processID, "RESULTS") if err != nil { return err }