Skip to content

Commit

Permalink
Fix broken tests. Wrap WaaSWalletTests in try catches to catch any ex…
Browse files Browse the repository at this point in the history
…ceptions thrown throughout and fail the test - otherwise, the tests fail silently and the WaaSTestHarness never outputs the results (as it doesn't receive all the expected pass/fail events
  • Loading branch information
BellringerQuinn committed Nov 30, 2023
1 parent cef8aec commit 36f35f6
Show file tree
Hide file tree
Showing 3 changed files with 215 additions and 153 deletions.
14 changes: 7 additions & 7 deletions Assets/SequenceSDK/WaaS/Tests/CustomAssert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,31 @@ namespace Sequence.WaaS.Tests
{
public static class CustomAssert
{
public static Exception TestFailedException;
public static Exception TestFailedException(string reason)
{
return new Exception(reason);
}
public static void NotNull(object obj, string name, params object[] args)
{
if (obj == null)
{
WaaSTestHarness.TestFailed?.Invoke(new WaaSTestFailed(name, args));
throw TestFailedException;
throw TestFailedException($"{obj} was null");
}
}

public static void IsTrue(bool condition, string name, params object[] args)
{
if (!condition)
{
WaaSTestHarness.TestFailed?.Invoke(new WaaSTestFailed(name, args));
throw TestFailedException;
throw TestFailedException($"Condition was not true");
}
}

public static void IsEqual(object expected, object actual, string name, params object[] args)
{
if (!expected.Equals(actual))
{
WaaSTestHarness.TestFailed?.Invoke(new WaaSTestFailed(name, args));
throw TestFailedException;
throw TestFailedException($"Expected {expected} is not equal to Actual {actual}");
}
}
}
Expand Down
9 changes: 8 additions & 1 deletion Assets/SequenceSDK/WaaS/Tests/WaaSTestHarness.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,15 @@ private void InitiateTests(WaaSWallet wallet)
TestPassed += () => _passedTests++;
TestStarted += () => _testsStarted++;
WaaSWalletTests walletTests = new WaaSWalletTests(wallet);
wallet.OnSendTransactionFailed += OnFailedTransaction;
RunTests(walletTests);
}

private void OnFailedTransaction(FailedTransactionReturn result)
{
Debug.LogError("Transaction failed: " + result.error);
}

private async Task RunTests(WaaSWalletTests walletTests)
{
walletTests.TestMessageSigning("Hello world", Chain.Polygon);
Expand All @@ -82,9 +88,10 @@ private async Task RunTests(WaaSWalletTests walletTests)
public class WaaSTestFailed
{
public string Name;
public string Reason;
public object[] Args;

public WaaSTestFailed(string name, params object[] args)
public WaaSTestFailed(string name, string reason, params object[] args)
{
Name = name;
Args = args;
Expand Down
Loading

0 comments on commit 36f35f6

Please sign in to comment.