-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adding pocketic * Copy binaries to output * Fixing * Adding line test * Client * Update EdjCase.ICP.PocketIC.csproj * Update PocketIcClient.cs * Update PocketIcClient.cs * Removing lf enforcement * Rename folder * Fixing tests * a * Tests work * Fixing tests * Removing dead code * Adding missing doc * Adding PocketIC Tests and .net8 * Adding to solution and XUnit * Adding tests * Adding more methods * IPocketIcHttpClient * Adding tests * Adding routes * HttpGateway * Auto progress time * Documenting PocketIc.cs * IPocketIcHttpClient.cs docs * PocketIcHttpClient.cs docs * PocketIcServer + Request/Response models docs * Docs * Misc Candid/PocketIC tweaks and tests * Updating README for pocketic * Fixing Async
- Loading branch information
Showing
45 changed files
with
5,391 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
root = true | ||
|
||
[*] | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
samples/Sample.BlazorWebAssembly/Client/Sample.BlazorWebAssembly.Client.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
samples/Sample.BlazorWebAssembly/Server/Sample.BlazorWebAssembly.Server.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
using System.Net; | ||
using EdjCase.ICP.Agent.Agents; | ||
using EdjCase.ICP.Agent.Responses; | ||
using EdjCase.ICP.Candid.Models; | ||
using EdjCase.ICP.PocketIC; | ||
using EdjCase.ICP.PocketIC.Client; | ||
using EdjCase.ICP.PocketIC.Models; | ||
using Newtonsoft.Json; | ||
using Org.BouncyCastle.Asn1.Cms; | ||
using Xunit; | ||
|
||
namespace Sample.PocketIC | ||
{ | ||
public class PocketIcServerFixture : IDisposable | ||
{ | ||
public PocketIcServer Server { get; private set; } | ||
|
||
public PocketIcServerFixture() | ||
{ | ||
// Start the server for all tests | ||
this.Server = PocketIcServer.Start().GetAwaiter().GetResult(); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
// Stop the server after all tests | ||
if (this.Server != null) | ||
{ | ||
this.Server.StopAsync().GetAwaiter().GetResult(); | ||
this.Server.DisposeAsync().GetAwaiter().GetResult(); | ||
} | ||
} | ||
} | ||
|
||
public class PocketIcTests : IClassFixture<PocketIcServerFixture> | ||
{ | ||
private readonly PocketIcServerFixture fixture; | ||
private string url => this.fixture.Server.GetUrl(); | ||
|
||
public PocketIcTests(PocketIcServerFixture fixture) | ||
{ | ||
this.fixture = fixture; | ||
} | ||
|
||
[Fact] | ||
public async Task UpdateCallAsync_CounterWasm__Basic__Valid() | ||
{ | ||
byte[] wasmModule = File.ReadAllBytes("CanisterWasmModules/counter.wasm"); | ||
CandidArg arg = CandidArg.FromCandid(); | ||
|
||
// Create new pocketic instance for test, then dispose it | ||
await using (PocketIc pocketIc = await PocketIc.CreateAsync(this.url)) | ||
{ | ||
Principal canisterId = await pocketIc.CreateAndInstallCanisterAsync(wasmModule, arg); | ||
|
||
UnboundedUInt value = await pocketIc.QueryCallAsync<UnboundedUInt>( | ||
Principal.Anonymous(), | ||
canisterId, | ||
"get" | ||
); | ||
Assert.Equal((UnboundedUInt)0, value); | ||
|
||
|
||
await pocketIc.UpdateCallNoResponseAsync( | ||
Principal.Anonymous(), | ||
canisterId, | ||
"inc" | ||
); | ||
|
||
value = await pocketIc.QueryCallAsync<UnboundedUInt>( | ||
Principal.Anonymous(), | ||
canisterId, | ||
"get" | ||
); | ||
Assert.Equal((UnboundedUInt)1, value); | ||
|
||
await pocketIc.UpdateCallNoResponseAsync( | ||
Principal.Anonymous(), | ||
canisterId, | ||
"set", | ||
(UnboundedUInt)10 | ||
); | ||
|
||
value = await pocketIc.QueryCallAsync<UnboundedUInt>( | ||
Principal.Anonymous(), | ||
canisterId, | ||
"get" | ||
); | ||
|
||
Assert.Equal((UnboundedUInt)10, value); | ||
} | ||
} | ||
|
||
|
||
[Fact] | ||
public async Task HttpGateway_CounterWasm__Basic__Valid() | ||
{ | ||
byte[] wasmModule = File.ReadAllBytes("CanisterWasmModules/counter.wasm"); | ||
CandidArg arg = CandidArg.FromCandid(); | ||
|
||
|
||
SubnetConfig nnsSubnet = SubnetConfig.New(); // NNS subnet required for HttpGateway | ||
|
||
await using (PocketIc pocketIc = await PocketIc.CreateAsync(this.url, nnsSubnet: nnsSubnet)) | ||
{ | ||
Principal canisterId = await pocketIc.CreateAndInstallCanisterAsync(wasmModule, arg); | ||
|
||
await pocketIc.StartCanisterAsync(canisterId); | ||
|
||
// Let time progress so that update calls get processed | ||
await using (await pocketIc.AutoProgressTimeAsync()) | ||
{ | ||
await using (HttpGateway httpGateway = await pocketIc.RunHttpGatewayAsync()) | ||
{ | ||
HttpAgent agent = httpGateway.BuildHttpAgent(); | ||
QueryResponse getResponse = await agent.QueryAsync(canisterId, "get", CandidArg.Empty()); | ||
CandidArg getResponseArg = getResponse.ThrowOrGetReply(); | ||
UnboundedUInt getResponseValue = getResponseArg.ToObjects<UnboundedUInt>(); | ||
Assert.Equal((UnboundedUInt)0, getResponseValue); | ||
|
||
|
||
CancellationTokenSource cts = new(TimeSpan.FromSeconds(5)); | ||
CandidArg incResponseArg = await agent.CallAndWaitAsync(canisterId, "inc", CandidArg.Empty(), cancellationToken: cts.Token); | ||
Assert.Equal(CandidArg.Empty(), incResponseArg); | ||
|
||
// This alternative also doesnt work | ||
// RequestId requestId = await agent.CallAsync(canisterId, "inc", CandidArg.Empty()); | ||
// ICTimestamp currentTime = await pocketIc.GetTimeAsync(); | ||
// await pocketIc.SetTimeAsync(currentTime + TimeSpan.FromSeconds(5)); | ||
// await pocketIc.TickAsync(5); | ||
// CandidArg incResponseArg = await agent.WaitForRequestAsync(canisterId, requestId); | ||
// Assert.Equal(CandidArg.Empty(), incResponseArg); | ||
|
||
getResponse = await agent.QueryAsync(canisterId, "get", CandidArg.Empty()); | ||
getResponseArg = getResponse.ThrowOrGetReply(); | ||
getResponseValue = getResponseArg.ToObjects<UnboundedUInt>(); | ||
Assert.Equal((UnboundedUInt)1, getResponseValue); | ||
|
||
CandidArg setRequestArg = CandidArg.FromObjects((UnboundedUInt)10); | ||
CandidArg setResponseArg = await agent.CallAndWaitAsync(canisterId, "set", setRequestArg); | ||
Assert.Equal(CandidArg.Empty(), setResponseArg); | ||
|
||
getResponse = await agent.QueryAsync(canisterId, "get", CandidArg.Empty()); | ||
getResponseArg = getResponse.ThrowOrGetReply(); | ||
getResponseValue = getResponseArg.ToObjects<UnboundedUInt>(); | ||
Assert.Equal((UnboundedUInt)10, getResponseValue); | ||
|
||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" /> | ||
<PackageReference Include="xunit" Version="2.9.2" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="6.0.2"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Features" Version="4.11.0" /> | ||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Analyzer.Testing.XUnit" Version="1.1.2" /> | ||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeFix.Testing.XUnit" Version="1.1.2" /> | ||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeRefactoring.Testing.XUnit" Version="1.1.2" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Content Include="CanisterWasmModules/*.wasm"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</Content> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\PocketIC\EdjCase.ICP.PocketIC.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.