Skip to content

Initial Commit #296

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Assets/SequenceSDK/Sidekick.meta

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

37 changes: 37 additions & 0 deletions Assets/SequenceSDK/Sidekick/SideKickWalletTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.Threading.Tasks;
using NUnit.Framework;
using Newtonsoft.Json.Linq;
using Sequence;
using Sequence.EmbeddedWallet;
public class SequenceSidekickTests
{
SequenceSidekickClient sidekick;
string chainId;

[SetUp]
public void Setup()
{
sidekick = new SequenceSidekickClient(Chain.TestnetArbitrumSepolia);
chainId = sidekick.Chain.GetChainId();

}

[Test]
public async Task TestGetWalletAddress()
{
try
{
var sidekick = new SequenceSidekickClient();
string response = await sidekick.GetWalletAddress();
Assert.IsNotNull(response);
var json = JObject.Parse(response);
Assert.IsTrue(json.ContainsKey("walletAddress"));
}
catch (Exception e)
{
Assert.Fail("Expected no exception, but got: " + e.Message);
}
}

}
11 changes: 11 additions & 0 deletions Assets/SequenceSDK/Sidekick/SideKickWalletTests.cs.meta

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

81 changes: 81 additions & 0 deletions Assets/SequenceSDK/Sidekick/SidekickERC1155Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using System;
using System.Threading.Tasks;
using NUnit.Framework;
using UnityEngine;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Sequence.EmbeddedWallet;
using Sequence;
public class SidekickERC1155MintTest
{
private SequenceSidekickClient sidekick;
private string chainId;
private string walletAddress;

[SetUp]
public void Setup()
{
sidekick = new SequenceSidekickClient(Chain.TestnetArbitrumSepolia);
chainId = sidekick.Chain.GetChainId();
}


[Test]
public async Task DeployERC1155()
{
try
{
walletAddress = await sidekick.GetWalletAddress();
string recipientAddress = JObject.Parse(walletAddress)["address"]?.ToString();

var deployBody = new
{
defaultAdmin = recipientAddress,
minter = recipientAddress,
name = "MYTESTERC1155"
};


string deployJson = JsonConvert.SerializeObject(deployBody);

string deployResult = await sidekick.DeployERC1155(deployJson);

Debug.Log("Deploy result: " + deployResult);
Assert.IsNotNull(deployResult, "Deploy result must not be null");
}
catch (Exception e)
{
Assert.Fail("ERC1155 deploy flow failed: " + e.Message);
}
}


[Test]
public async Task MintERC1155()
{
try
{
walletAddress = await sidekick.GetWalletAddress();

string recipientAddress = JObject.Parse(walletAddress)["address"]?.ToString();

var mintBody = new
{
recipient = recipientAddress,
id = "0",
amount = "1",
data = "0x00"
};
string mintJson = JsonConvert.SerializeObject(mintBody);
string mintResult = await sidekick.MintERC1155("0x63c12baa017b2bcb6855d83506500edcac423c3c", mintJson);

Debug.Log("Mint result: " + mintResult);

Assert.IsNotNull(mintResult, "Mint result must not be null");
}
catch (Exception e)
{
Assert.Fail("ERC1155 flow failed: " + e.Message);
}
}
}
11 changes: 11 additions & 0 deletions Assets/SequenceSDK/Sidekick/SidekickERC1155Tests.cs.meta

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

23 changes: 23 additions & 0 deletions Assets/SequenceSDK/Sidekick/SidekickTests.asmdef
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "SidekickTests",
"rootNamespace": "",
"references": [
"GUID:4e0a798abbda240658187632ae443a67",
"GUID:f7fd4ba36aabd1d499450c174865e70b",
"GUID:0acc523941302664db1f4e527237feb3",
"GUID:27619889b8ba8c24980f49ee34dbb44a"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [
"UNITY_INCLUDE_TESTS"
],
"versionDefines": [],
"noEngineReferences": false
}
7 changes: 7 additions & 0 deletions Assets/SequenceSDK/Sidekick/SidekickTests.asmdef.meta

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

8 changes: 8 additions & 0 deletions Packages/Sequence-Unity/Editor/Sidekick.meta

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

200 changes: 200 additions & 0 deletions Packages/Sequence-Unity/Editor/Sidekick/SidekickDockerUtility.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
using UnityEditor;
using UnityEngine;
using System.Diagnostics;
using System.IO;
using System.Linq;
public static class SidekickDockerUtility
{
private static SidekickConfig config;

private static string SidekickPath
{
get
{
if (config == null)
{
config = Resources.Load<SidekickConfig>("SidekickConfig");
if (config == null)
{
UnityEngine.Debug.LogError("Could not load SidekickConfig from Resources.");
return string.Empty;
}
}
return config.sidekickPath;
}
}

private static string dockerDesktopPath
{
get
{
if (config == null)
{
config = Resources.Load<SidekickConfig>("SidekickConfig");
if (config == null)
{
UnityEngine.Debug.LogError("Could not load SidekickConfig from Resources.");
return string.Empty;
}
}
return config.dockerDesktopPath;
}
}


[MenuItem("Sequence Sidekick/Start", false, 0)]
private static void StartSidekick()
{
if (IsSidekickRunning()) return;

EnsureDockerDesktopRunning();

RunCommand("pnpm docker:restart", SidekickPath);
}

[MenuItem("Sequence Sidekick/Start", true)]
private static bool ValidateStart() => !IsSidekickRunning();

[MenuItem("Sequence Sidekick/Stop", false, 1)]
private static void StopSidekick()
{
if (!IsSidekickRunning()) return;

RunCommand("pnpm docker:stop", SidekickPath);
}

[MenuItem("Sequence Sidekick/Stop", true)]
private static bool ValidateStop() => IsSidekickRunning();

private static void RunCommand(string command, string workingDirectory)
{
if (string.IsNullOrEmpty(workingDirectory) || !Directory.Exists(workingDirectory))
{
UnityEngine.Debug.LogError($"Sidekick path not set or invalid: {workingDirectory}");
return;
}

ProcessStartInfo psi = new ProcessStartInfo
{
FileName = "cmd.exe",
Arguments = $"/c {command}",
WorkingDirectory = workingDirectory,
CreateNoWindow = true,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true
};

Process process = new Process { StartInfo = psi };

process.OutputDataReceived += (sender, e) =>
{
if (!string.IsNullOrEmpty(e.Data))
UnityEngine.Debug.Log($"[Docker] {e.Data}");
};

process.ErrorDataReceived += (sender, e) =>
{
if (!string.IsNullOrEmpty(e.Data))
UnityEngine.Debug.LogWarning($"[Docker] {e.Data}");
};

process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
}
private static void EnsureDockerDesktopRunning()
{
const int maxWaitTimeSeconds = 120;
const int pollIntervalMs = 2000;

System.Threading.Tasks.Task.Run(() =>
{
if (!Process.GetProcessesByName("Docker Desktop").Any())
{
if (File.Exists(config.dockerDesktopPath))
{
Process.Start(config.dockerDesktopPath);
}
else
{
UnityEngine.Debug.LogWarning("[Docker] Docker Desktop not found at Sidekick Config set path.");
return;
}
}

var stopwatch = new Stopwatch();
stopwatch.Start();

while (stopwatch.Elapsed.TotalSeconds < maxWaitTimeSeconds)
{
if (IsDockerDaemonReady())
{
UnityEngine.Debug.Log("[Docker] Docker is ready.");
return;
}

System.Threading.Thread.Sleep(pollIntervalMs);
}

UnityEngine.Debug.LogError("[Docker] Timed out waiting for Docker to become ready.");
});
}

private static bool IsDockerDaemonReady()
{
try
{
ProcessStartInfo psi = new ProcessStartInfo
{
FileName = "cmd.exe",
Arguments = "/c docker info",
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true,
UseShellExecute = false
};

using (Process process = Process.Start(psi))
{
process.WaitForExit(3000);

string output = process.StandardOutput.ReadToEnd();
string error = process.StandardError.ReadToEnd();

return process.ExitCode == 0 && output.Contains("Server Version");
}
}
catch
{
return false;
}
}

private static bool IsSidekickRunning()
{
try
{
var psi = new ProcessStartInfo
{
FileName = "cmd.exe",
Arguments = "/c docker ps --format \"{{.Names}}\"",
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true
};

using (var process = Process.Start(psi))
{
process.WaitForExit();
var output = process.StandardOutput.ReadToEnd();

return output.Contains("sidekick");
}
}
catch
{
return false;
}
}
}
Loading