diff --git a/contracts/evoting/types/ballots.go b/contracts/evoting/types/ballots.go index e8f8eb14..770af369 100644 --- a/contracts/evoting/types/ballots.go +++ b/contracts/evoting/types/ballots.go @@ -334,7 +334,9 @@ func (s *Subject) MaxEncodedSize() int { //TODO : optimise by computing max size according to number of choices and maxN for _, rank := range s.Ranks { size += len(rank.GetID()) - size += len(rank.ID) + // the ID arrives Base64-encoded, but rank.ID is decoded + // we need the size of the Base64-encoded string + size += len(base64.StdEncoding.EncodeToString([]byte(rank.ID))) // ':' separators ('id:id:choice') size += 2 @@ -345,7 +347,9 @@ func (s *Subject) MaxEncodedSize() int { for _, selection := range s.Selects { size += len(selection.GetID()) - size += len(selection.ID) + // the ID arrives Base64-encoded, but selection.ID is decoded + // we need the size of the Base64-encoded string + size += len(base64.StdEncoding.EncodeToString([]byte(selection.ID))) // ':' separators ('id:id:choice') size += 2 @@ -356,7 +360,9 @@ func (s *Subject) MaxEncodedSize() int { for _, text := range s.Texts { size += len(text.GetID()) - size += len(text.ID) + // the ID arrives Base64-encoded, but text.ID is decoded + // we need the size of the Base64-encoded string + size += len(base64.StdEncoding.EncodeToString([]byte(text.ID))) // ':' separators ('id:id:choice') size += 2 diff --git a/contracts/evoting/types/ballots_test.go b/contracts/evoting/types/ballots_test.go index 9b292f73..f47bddfd 100644 --- a/contracts/evoting/types/ballots_test.go +++ b/contracts/evoting/types/ballots_test.go @@ -314,13 +314,13 @@ func TestSubject_MaxEncodedSize(t *testing.T) { }}, Selects: []Select{{ - ID: encodedQuestionID(1), + ID: decodedQuestionID(1), Title: Title{En: "", Fr: "", De: "", URL: ""}, MaxN: 3, MinN: 0, Choices: make([]Choice, 3), }, { - ID: encodedQuestionID(2), + ID: decodedQuestionID(2), Title: Title{En: "", Fr: "", De: "", URL: ""}, MaxN: 5, MinN: 0, @@ -328,7 +328,7 @@ func TestSubject_MaxEncodedSize(t *testing.T) { }}, Ranks: []Rank{{ - ID: encodedQuestionID(3), + ID: decodedQuestionID(3), Title: Title{En: "", Fr: "", De: "", URL: ""}, MaxN: 4, MinN: 0, @@ -336,7 +336,7 @@ func TestSubject_MaxEncodedSize(t *testing.T) { }}, Texts: []Text{{ - ID: encodedQuestionID(4), + ID: decodedQuestionID(4), Title: Title{En: "", Fr: "", De: "", URL: ""}, MaxN: 2, MinN: 0, @@ -344,7 +344,7 @@ func TestSubject_MaxEncodedSize(t *testing.T) { Regex: "", Choices: make([]Choice, 2), }, { - ID: encodedQuestionID(5), + ID: decodedQuestionID(5), Title: Title{En: "", Fr: "", De: "", URL: ""}, MaxN: 1, MinN: 0,