Skip to content

Commit

Permalink
Task/ev testing (#372)
Browse files Browse the repository at this point in the history
* ev testing changes

* Rollback version update

* removed .net 7 building for the ui.
removed the ui.test project
fix issue with loading tally

* tally fixes

* version number change

* removing testing of the UI

---------

Co-authored-by: John Morgan <70619927+john-s-morgan@users.noreply.github.com>
  • Loading branch information
SteveMaier-IRT and john-s-morgan committed Jul 13, 2023
1 parent 5144ab2 commit 8b5d308
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 43 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ test-cli: build-cli

test-ui: build-ui
@echo 🧪 TEST UI $(OPERATING_SYSTEM) $(PROCESSOR) $(TARGET)
dotnet test -a $(PROCESSOR) -c $(TARGET) ./src/electionguard-ui/ElectionGuard.UI.Test/ElectionGuard.UI.Test.csproj
# dotnet test -a $(PROCESSOR) -c $(TARGET) ./src/electionguard-ui/ElectionGuard.UI.Test/ElectionGuard.UI.Test.csproj

test-wasm: build-wasm
@echo 🧪 TEST WASM $(PROCESSOR) $(TARGET)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,11 @@ List<CiphertextBallot> ballots
)
{
SubmitShare(shares.TallyShare);
SubmitShares(shares.BallotShares.Values
.Select(i => new BallotShare(i)).ToList(),
ballots.Select(i => new CiphertextBallot(i)).ToList());
if (ballots.Count > 0)
{
SubmitShares(shares.BallotShares.Values.Select(i => new BallotShare(i)).ToList(),
ballots.Select(i => new CiphertextBallot(i)).ToList());
}
}

/// <summary>
Expand Down Expand Up @@ -284,7 +286,7 @@ public DecryptionResult Decrypt(string tallyId, bool skipValidation = false)
}

var tallyDecryption = TallyDecryptions[tallyId];
return tallyDecryption.Decrypt(skipValidation);
return tallyDecryption.Decrypt(false, skipValidation);
}

#endregion
Expand Down
15 changes: 0 additions & 15 deletions src/electionguard-ui/ElectionGuard.UI.sln
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ElectionGuard.Encryption.Ut
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ElectionGuard.Decryption", "..\..\bindings\netstandard\ElectionGuard\ElectionGuard.Decryption\ElectionGuard.Decryption.csproj", "{DF0CA84A-EC01-48A6-9140-EF546FD781C5}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ElectionGuard.UI.Test", "ElectionGuard.UI.Test\ElectionGuard.UI.Test.csproj", "{108ACA29-BCC3-421E-9DF5-B87182CF5710}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ElectionGuard.Decryption.Tests", "..\..\bindings\netstandard\ElectionGuard\ElectionGuard.Decryption.Tests\ElectionGuard.Decryption.Tests.csproj", "{72F8C1CA-FDD7-4B7B-A08A-C16589EEA187}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ElectionGuard.ElectionSetup.Tests", "..\..\bindings\netstandard\ElectionGuard\ElectionGuard.ElectionSetup.Tests\ElectionGuard.ElectionSetup.Tests.csproj", "{123DF2EF-5EB9-4974-B834-F996D777CFAB}"
Expand Down Expand Up @@ -114,18 +112,6 @@ Global
{DF0CA84A-EC01-48A6-9140-EF546FD781C5}.Release|x64.Build.0 = Release|x64
{DF0CA84A-EC01-48A6-9140-EF546FD781C5}.Release|x86.ActiveCfg = Release|x86
{DF0CA84A-EC01-48A6-9140-EF546FD781C5}.Release|x86.Build.0 = Release|x86
{108ACA29-BCC3-421E-9DF5-B87182CF5710}.Debug|arm64.ActiveCfg = Debug|arm64
{108ACA29-BCC3-421E-9DF5-B87182CF5710}.Debug|arm64.Build.0 = Debug|arm64
{108ACA29-BCC3-421E-9DF5-B87182CF5710}.Debug|x64.ActiveCfg = Debug|x64
{108ACA29-BCC3-421E-9DF5-B87182CF5710}.Debug|x64.Build.0 = Debug|x64
{108ACA29-BCC3-421E-9DF5-B87182CF5710}.Debug|x86.ActiveCfg = Debug|x86
{108ACA29-BCC3-421E-9DF5-B87182CF5710}.Debug|x86.Build.0 = Debug|x86
{108ACA29-BCC3-421E-9DF5-B87182CF5710}.Release|arm64.ActiveCfg = Release|arm64
{108ACA29-BCC3-421E-9DF5-B87182CF5710}.Release|arm64.Build.0 = Release|arm64
{108ACA29-BCC3-421E-9DF5-B87182CF5710}.Release|x64.ActiveCfg = Release|x64
{108ACA29-BCC3-421E-9DF5-B87182CF5710}.Release|x64.Build.0 = Release|x64
{108ACA29-BCC3-421E-9DF5-B87182CF5710}.Release|x86.ActiveCfg = Release|x86
{108ACA29-BCC3-421E-9DF5-B87182CF5710}.Release|x86.Build.0 = Release|x86
{72F8C1CA-FDD7-4B7B-A08A-C16589EEA187}.Debug|arm64.ActiveCfg = Debug|arm64
{72F8C1CA-FDD7-4B7B-A08A-C16589EEA187}.Debug|arm64.Build.0 = Debug|arm64
{72F8C1CA-FDD7-4B7B-A08A-C16589EEA187}.Debug|x64.ActiveCfg = Debug|x64
Expand Down Expand Up @@ -155,7 +141,6 @@ Global
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{108ACA29-BCC3-421E-9DF5-B87182CF5710} = {42BB40E3-87DD-44E6-A2B8-AE36B2B98AA1}
{72F8C1CA-FDD7-4B7B-A08A-C16589EEA187} = {42BB40E3-87DD-44E6-A2B8-AE36B2B98AA1}
{123DF2EF-5EB9-4974-B834-F996D777CFAB} = {42BB40E3-87DD-44E6-A2B8-AE36B2B98AA1}
EndGlobalSection
Expand Down
8 changes: 4 additions & 4 deletions src/electionguard-ui/ElectionGuard.UI/ElectionGuard.UI.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('OSX'))">net7.0-maccatalyst;net7.0</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">net7.0-windows10.0.19041.0;net7.0</TargetFrameworks>
<OutputType Condition="'$(TargetFramework)' != 'net7.0'">Exe</OutputType>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('OSX'))">net7.0-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">net7.0-windows10.0.19041.0</TargetFrameworks>
<OutputType>Exe</OutputType>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
Expand All @@ -19,7 +19,7 @@

<!-- Versions -->
<ApplicationDisplayVersion>1.90.0</ApplicationDisplayVersion>
<ApplicationVersion>1</ApplicationVersion>
<ApplicationVersion>2</ApplicationVersion>

<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">15.3</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.19041.0</SupportedOSPlatformVersion>
Expand Down
15 changes: 6 additions & 9 deletions src/electionguard-ui/ElectionGuard.UI/Services/TallyManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,7 @@ public async Task DecryptShare(string guardianId, TallyRecord tally)
var challengeBallots = (await GetBallotsByState(tally.ElectionId, BallotBoxState.Challenged)).ToList();
using var decryptionShares = guardian.ComputeDecryptionShares(mediator.Tallies[tally.TallyId], challengeBallots);

if (challengeBallots.Count > 0)
{
mediator.SubmitShares(decryptionShares, challengeBallots);
}
mediator.SubmitShares(decryptionShares, challengeBallots);

await SaveShare(guardianId, tally, decryptionShares);
}
Expand Down Expand Up @@ -325,11 +322,11 @@ private async Task LoadAllShares(DecryptionMediator mediator, TallyRecord tally)
var challengeBallots = await GetBallotsByState(tally.ElectionId, BallotBoxState.Challenged);
var shares = await _decryptionShareService.GetAllByTallyIdAsync(tally.TallyId);

foreach (var share in shares)
{
var shareData = JsonConvert.DeserializeObject<DecryptionShare>(share.ShareData)!;
mediator.SubmitShares(shareData, challengeBallots.ToList());
}
foreach (var share in shares)
{
var shareData = JsonConvert.DeserializeObject<DecryptionShare>(share.ShareData)!;
mediator.SubmitShares(shareData, challengeBallots.ToList());
}
}

private async Task AddSpoiledBallots(DecryptionMediator mediator, TallyRecord tally)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ namespace ElectionGuard.UI.Services;
public class TallyStateMachine : ITallyStateMachine
{
private Dictionary<bool, List<StateMachineStep<TallyState, TallyRecord>>> _steps = new();
private object mutex = new();

private IAuthenticationService _authenticationService;
private readonly ChallengeResponseService _challengeResponseService;
Expand Down Expand Up @@ -40,15 +39,16 @@ public async Task<bool> Run(TallyRecord tally)
bool ran = false;
string label = $"Electionguard.UI.TallyStateMachine-{_authenticationService.UserName}";

var mutex = new Mutex(true, label, out var owned);

using var mutex = new Mutex(true, label, out var owned);
if (owned)
{
try
{
mutex.WaitOne();
Task.WaitAll(RunAsync(tally));
ran = true;
if (mutex.WaitOne(10))
{
Task.WaitAll(RunAsync(tally));
ran = true;
}
}
catch (AbandonedMutexException)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Text.Json;
using CommunityToolkit.Maui.Storage;
using CommunityToolkit.Mvvm.Input;
using ElectionGuard.Ballot;
using ElectionGuard.Decryption;
using ElectionGuard.Decryption.Tally;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,15 +421,31 @@ private void CeremonyPollingTimer_Tick(object? sender, EventArgs e)

_ = Task.Run(async () =>
{
Tally = await _tallyService.GetByTallyIdAsync(TallyId);
if (Tally != null)
var localTally = await _tallyService.GetByTallyIdAsync(TallyId);
if (localTally != null)
{
await UpdateTallyData();
try
{
if (await _tallyRunner.Run(Tally))
_ = Shell.Current.CurrentPage.Dispatcher.DispatchAsync(async () =>
{
Tally = localTally;
});
await UpdateTallyData();
#if DEBUG
ErrorMessage = Tally.State.ToString();
#endif
if (await _tallyRunner.Run(localTally))
{
ErrorMessage = string.Empty;
#if DEBUG
ErrorMessage = $"{Tally.State.ToString()} ran";
#endif
}
else
{
#if DEBUG
ErrorMessage = $"{Tally.State.ToString()} waiting";
#endif
}
}
catch (Exception ex)
Expand Down

0 comments on commit 8b5d308

Please sign in to comment.