Skip to content

Commit

Permalink
fix(webgl): fix webgl errors being caused in player test builds
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonboukheir committed Jun 19, 2022
1 parent 62b014b commit f7ee641
Show file tree
Hide file tree
Showing 13 changed files with 1,267 additions and 44 deletions.
1,169 changes: 1,160 additions & 9 deletions Runtime/CareBoo.AlgoSdk.Crypto/Plugins/WebGL/sha512.min.jspre

Large diffs are not rendered by default.

24 changes: 14 additions & 10 deletions Tests/Runtime/CareBoo.AlgoSdk.Tests/Abi/Types/TupleTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,20 @@ public void EncodeShouldPackUpTo8BitsIntoASingleByte()
{
using var references = new AbiReferences(Allocator.Persistent);
var expected = new byte[] { 0xff, 0x00 };
var bools = Args.Add(Boolean.True)
.Add(Boolean.True)
.Add(Boolean.True)
.Add(Boolean.True)
.Add(Boolean.True)
.Add(Boolean.True)
.Add(Boolean.True)
.Add(Boolean.True)
.Add(Boolean.False)
;
// var bools = Args.Add(Boolean.True)
// .Add(Boolean.True)
// .Add(Boolean.True)
// .Add(Boolean.True)
// .Add(Boolean.True)
// .Add(Boolean.True)
// .Add(Boolean.True)
// .Add(Boolean.True)
// .Add(Boolean.False)
// ;
var bools = new IAbiValue[9];
for (var i = 0; i < 8; i++)
bools[i] = Boolean.True;
bools[8] = Boolean.False;
var tuple = Tuple.Of(bools);
var typeStr = string.Join(",", Enumerable.Range(0, 9).Select(_ => "bool"));
typeStr = $"({typeStr})";
Expand Down
33 changes: 22 additions & 11 deletions Tests/Runtime/CareBoo.AlgoSdk.Tests/Abi/Types/UintNTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using AlgoSdk;
using AlgoSdk.Abi;
using NUnit.Framework;
using Unity.Collections;
Expand All @@ -20,20 +19,32 @@ public void Uint64EncodingShouldEqualUintNOf64Encoding()
}

[Test]
[TestCase(new object[] { ulong.MinValue, (ushort)8 })]
[TestCase(new object[] { ulong.MaxValue, (ushort)64 })]
public void Uint64NShouldAlwaysReturnMultipleOf8(ulong value, ushort expected)
public void Uint64NShouldAlwaysReturnMultipleOf8()
{
var actual = new UInt64(value).N;
Assert.AreEqual(expected, actual);
var testCases = new[]
{
(value: ulong.MinValue, expected: (ushort)8),
(value: ulong.MaxValue, expected: (ushort)64)
};
foreach (var (value, expected) in testCases)
{
var actual = new UInt64(value).N;
Assert.AreEqual(expected, actual);
}
}

[Test]
[TestCase(new object[] { uint.MinValue, (ushort)8 })]
[TestCase(new object[] { uint.MaxValue, (ushort)32 })]
public void Uint32NShouldAlwaysReturnMultipleOf8(uint value, ushort expected)
public void Uint32NShouldAlwaysReturnMultipleOf8()
{
var actual = new UInt32(value).N;
Assert.AreEqual(expected, actual);
var testCases = new[]
{
(value: uint.MinValue, expected: (ushort)8),
(value: uint.MaxValue, expected: (ushort)32)
};
foreach (var (value, expected) in testCases)
{
var actual = new UInt32(value).N;
Assert.AreEqual(expected, actual);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
using AlgoSdk.Abi;
using Cysharp.Threading.Tasks;
using NUnit.Framework;
using Unity.Mathematics;
using UnityEngine;
using UnityEngine.TestTools;

[TestFixture]
Expand Down Expand Up @@ -137,12 +135,13 @@ public void BuildingTransactionWithAbiCallsShouldValidateTxnTypes()
[Test]
public void BuildingAtomicTxnWithMoreThan15ArgsShouldEncodeTheLastOnesIntoATuple()
{
var length = 20;
var argType = AbiType.UIntN(32);
var methodAbi = new Method
{
Name = "test",
Description = "Blah blah blah",
Arguments = Enumerable.Range(0, 20).Select(i => new Method.Arg
Arguments = Enumerable.Range(0, length).Select(i => new Method.Arg
{
Type = argType,
Name = $"arg{i}",
Expand All @@ -158,9 +157,11 @@ public void BuildingAtomicTxnWithMoreThan15ArgsShouldEncodeTheLastOnesIntoATuple
var sender = Account.GenerateAccount();
var receiver = Account.GenerateAccount();

var args = Args.Add(1).Add(2).Add(3).Add(4).Add(5).Add(6).Add(7).Add(8).Add(9).Add(10).Add(11).Add(12).Add(13).Add(14).Add(15).Add(16).Add(17).Add(18).Add(19).Add(20);
var args = new IAbiValue[length];
for (var i = 0; i < length; i++)
args[i] = new UInt32((uint)i);

Assert.AreEqual(methodAbi.Arguments.Length, args.Count);
Assert.AreEqual(methodAbi.Arguments.Length, args.Length);
var group = Transaction.Atomic()
.AddTxn(Transaction.Payment(sender.Address, default, receiver.Address, 10000))
.AddMethodCall(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,19 @@ public void EnumeratorShouldEnumerateThroughGivenIndicesInOrder()
}

[Test]
[TestCase(1, true)]
[TestCase(2, false)]
public void ContainsIndexShouldReturnIfIndexInIndices(int index, bool expected)
public void ContainsIndexShouldReturnIfIndexInIndices()
{
var testCases = new[]
{
(index: 1, expected: true),
(index: 2, expected: false)
};
var indices = TxnIndices.Select(1, 3, 4, 5, 6, 7, 9);
var actual = indices.ContainsIndex(index);
Assert.AreEqual(expected, actual);

foreach (var (index, expected) in testCases)
{
var actual = indices.ContainsIndex(index);
Assert.AreEqual(expected, actual);
}
}
}
11 changes: 11 additions & 0 deletions Unity.AlgoSdk.AssetStore/Assets/Editor/WebglPreBuildProcessing.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using UnityEditor.Build;
using UnityEditor.Build.Reporting;

public class WebglPreBuildProcessing : IPreprocessBuildWithReport
{
public int callbackOrder => 1;
public void OnPreprocessBuild(BuildReport report)
{
System.Environment.SetEnvironmentVariable("EMSDK_PYTHON", "/Users/jason/.asdf/installs/python/3.9.11/bin/python3.9");
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Unity.AlgoSdk.AssetStore/Packages/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"dependencies": {
"com.unity.collections": "1.1.0",
"com.unity.ide.vscode": "1.2.5",
"com.unity.modules.ai": "1.0.0",
"com.unity.modules.androidjni": "1.0.0",
"com.unity.modules.animation": "1.0.0",
Expand Down
7 changes: 7 additions & 0 deletions Unity.AlgoSdk.AssetStore/Packages/packages-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@
"dependencies": {},
"url": "https://packages.unity.com"
},
"com.unity.ide.vscode": {
"version": "1.2.5",
"depth": 0,
"source": "registry",
"dependencies": {},
"url": "https://packages.unity.com"
},
"com.unity.mathematics": {
"version": "1.2.1",
"depth": 2,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"MonoBehaviour": {
"Version": 3,
"EnableBurstCompilation": true,
"EnableOptimisations": true,
"EnableSafetyChecks": false,
"EnableDebugInAllBuilds": false,
"CpuMinTargetX32": 0,
"CpuMaxTargetX32": 0,
"CpuMinTargetX64": 0,
"CpuMaxTargetX64": 0
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"MonoBehaviour": {
"Version": 3,
"DisabledWarnings": ""
}
}
Git LFS file not shown
4 changes: 2 additions & 2 deletions Unity.AlgoSdk.AssetStore/ProjectSettings/ProjectVersion.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
m_EditorVersion: 2020.3.31f1
m_EditorVersionWithRevision: 2020.3.31f1 (6b54b7616050)
m_EditorVersion: 2020.3.36f1
m_EditorVersionWithRevision: 2020.3.36f1 (71f96b79b9f0)

0 comments on commit f7ee641

Please sign in to comment.