Skip to content
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

[net]refactor(tests): refactor tests infrastructure and add Sails.DemoClient project #673

Merged
merged 7 commits into from
Nov 25, 2024
Merged
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
11 changes: 10 additions & 1 deletion .github/workflows/net-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ jobs:
build-test:
name: Build & Test
runs-on: ubuntu-latest
permissions:
packages: read
defaults:
run:
shell: bash
Expand All @@ -33,7 +35,14 @@ jobs:
dotnet-version: 8.0.x

- name: Restore Solution
run: >-
run: |
NUGET_SOURCE_URL="https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json"
dotnet nuget remove source ${{ github.repository_owner }}-github || true
dotnet nuget add source $NUGET_SOURCE_URL \
--name ${{ github.repository_owner }}-github \
--username "${{ github.workflow }}" \
--password ${{ secrets.GITHUB_TOKEN }} \
--store-password-in-clear-text
dotnet restore

- name: Build Solution
Expand Down
16 changes: 16 additions & 0 deletions Sails.Net.sln
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Substrate.Gear.Client.Tests
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sails.Client.Tests", "net\tests\Sails.Client.Tests\Sails.Client.Tests.csproj", "{BC248D44-14CD-4BB0-9AF9-4E0750574492}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "examples", "examples", "{4D457454-ED79-4BC3-8B6B-AC6934AAF048}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sails.DemoClient", "net\examples\Sails.DemoClient\Sails.DemoClient.csproj", "{C9D87AD3-612B-43A0-89BD-9211FE2FB310}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sails.DemoClient.Tests", "net\tests\Sails.DemoClient.Tests\Sails.DemoClient.Tests.csproj", "{5ED8CDB7-F896-4ACE-8B7B-A128CCBBCFA4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -83,6 +89,14 @@ Global
{BC248D44-14CD-4BB0-9AF9-4E0750574492}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BC248D44-14CD-4BB0-9AF9-4E0750574492}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BC248D44-14CD-4BB0-9AF9-4E0750574492}.Release|Any CPU.Build.0 = Release|Any CPU
{C9D87AD3-612B-43A0-89BD-9211FE2FB310}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C9D87AD3-612B-43A0-89BD-9211FE2FB310}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C9D87AD3-612B-43A0-89BD-9211FE2FB310}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C9D87AD3-612B-43A0-89BD-9211FE2FB310}.Release|Any CPU.Build.0 = Release|Any CPU
{5ED8CDB7-F896-4ACE-8B7B-A128CCBBCFA4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5ED8CDB7-F896-4ACE-8B7B-A128CCBBCFA4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5ED8CDB7-F896-4ACE-8B7B-A128CCBBCFA4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5ED8CDB7-F896-4ACE-8B7B-A128CCBBCFA4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -93,6 +107,8 @@ Global
{A6A2172B-8F8F-4BDC-B519-E7299FFCCA5F} = {19594BCA-94DB-44AD-ACBC-2ACFED242E9F}
{42B621CE-C2B4-4911-961C-5B087A514AF5} = {19594BCA-94DB-44AD-ACBC-2ACFED242E9F}
{BC248D44-14CD-4BB0-9AF9-4E0750574492} = {19594BCA-94DB-44AD-ACBC-2ACFED242E9F}
{C9D87AD3-612B-43A0-89BD-9211FE2FB310} = {4D457454-ED79-4BC3-8B6B-AC6934AAF048}
{5ED8CDB7-F896-4ACE-8B7B-A128CCBBCFA4} = {19594BCA-94DB-44AD-ACBC-2ACFED242E9F}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0894C08B-8BB9-401D-8471-26F5EB5A4EA2}
Expand Down
10 changes: 7 additions & 3 deletions net/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,29 @@
<PackageVersion Include="Substrate.NET.API" Version="0.9.23" />
<PackageVersion Include="System.Linq.Async" Version="6.0.1" />
<PackageVersion Include="System.Threading.Channels" Version="9.0.0" />
<!-- For Tests -->
<!-- Tests -->
<PackageVersion Include="coverlet.collector" Version="6.0.2" />
<PackageVersion Include="FluentAssertions" Version="6.12.2" />
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageVersion Include="Nito.AsyncEx" Version="5.1.2" />
<PackageVersion Include="NSubstitute" Version="5.3.0" />
<PackageVersion Include="Polly" Version="8.5.0" />
<PackageVersion Include="Testcontainers" Version="4.0.0" />
<PackageVersion Include="Verify.SourceGenerators" Version="2.5.0" />
<PackageVersion Include="Verify.Xunit" Version="28.3.2" />
<PackageVersion Include="xunit" Version="2.9.2" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" />
<!-- For Code Analysis -->
<!-- Code Analysis -->
<PackageVersion Include="NSubstitute.Analyzers.CSharp" Version="1.0.17" />
<PackageVersion Include="Roslynator.Analyzers" Version="4.12.9" />
<PackageVersion Include="Roslynator.Formatting.Analyzers" Version="4.12.9" />
<!-- Due to Vulnarabilties -->
<!-- Vulnarabilties -->
<PackageVersion Include="MessagePack" Version="2.5.192" />
<PackageVersion Include="System.Text.Json" Version="9.0.0" />
<!-- Examples -->
<PackageVersion Include="Sails.ClientGenerator" Version="0.0.1-beta.1" />
<PackageVersion Include="Sails.Net" Version="0.0.1-beta.1" />
</ItemGroup>
</Project>
16 changes: 16 additions & 0 deletions net/examples/Sails.DemoClient/Sails.DemoClient.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<AdditionalFiles Include="demo.idl" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Sails.ClientGenerator" />
<PackageReference Include="Sails.Net" />
</ItemGroup>

</Project>
91 changes: 91 additions & 0 deletions net/examples/Sails.DemoClient/demo.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
type ReferenceCount = struct {
u32,
};

type DoThatParam = struct {
p1: nat32,
p2: actor_id,
p3: ManyVariants,
};

type ManyVariants = enum {
One,
Two: u32,
Three: opt u256,
Four: struct { a: u32, b: opt u16 },
Five: struct { str, h256 },
Six: struct { u32 },
};

type TupleStruct = struct {
bool,
};

constructor {
/// Program constructor (called once at the very beginning of the program lifetime)
Default : ();
/// Another program constructor (called once at the very beginning of the program lifetime)
New : (counter: opt u32, dog_position: opt struct { i32, i32 });
};

service Counter {
/// Add a value to the counter
Add : (value: u32) -> u32;
/// Substract a value from the counter
Sub : (value: u32) -> u32;
/// Get the current value
query Value : () -> u32;

events {
/// Emitted when a new value is added to the counter
Added: u32;
/// Emitted when a value is subtracted from the counter
Subtracted: u32;
}
};

service Dog {
MakeSound : () -> str;
Walk : (dx: i32, dy: i32) -> null;
query AvgWeight : () -> u32;
query Position : () -> struct { i32, i32 };

events {
Barked;
Walked: struct { from: struct { i32, i32 }, to: struct { i32, i32 } };
}
};

service PingPong {
Ping : (input: str) -> result (str, str);
};

service References {
Add : (v: u32) -> u32;
AddByte : (byte: u8) -> vec u8;
GuessNum : (number: u8) -> result (str, str);
Incr : () -> ReferenceCount;
SetNum : (number: u8) -> result (null, str);
query Baked : () -> str;
query LastByte : () -> opt u8;
query Message : () -> opt str;
};

service ThisThat {
DoThat : (param: DoThatParam) -> result (struct { actor_id, nat32 }, struct { str });
DoThis : (p1: u32, p2: str, p3: struct { opt h160, nat8 }, p4: TupleStruct) -> struct { str, u32 };
Noop : () -> null;
query That : () -> result (str, str);
query This : () -> u32;
};

service ValueFee {
/// Return flag if fee taken and remain value,
/// using special type `CommandReply<T>`
DoSomethingAndTakeFee : () -> bool;

events {
Withheld: u128;
}
};

6 changes: 6 additions & 0 deletions net/tests/Sails.DemoClient.Tests/AssemblyAttributes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[assembly: TestFramework(
"Sails.Tests.Shared.XUnit.TestFramework",
"Sails.Tests.Shared")]

[assembly: AssemblyFixture(
typeof(Sails.DemoClient.Tests._Infra.XUnit.Fixtures.SailsFixture))]
21 changes: 21 additions & 0 deletions net/tests/Sails.DemoClient.Tests/DemoFactoryTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Sails.DemoClient.Tests._Infra.XUnit.Fixtures;

namespace Sails.DemoClient.Tests;

public sealed class DemoFactoryTests : IAssemblyFixture<SailsFixture>
{
public DemoFactoryTests(SailsFixture fixture)
{
this.sailsFixture = fixture;
// Assert that IDL file from the Sails.DemoClient project is the same as the one
// from the SailsFixture
}

private readonly SailsFixture sailsFixture;

[Fact]
public async Task Test1()
{
var demoContractCodeId = await this.sailsFixture.GetDemoContractCodeIdAsync();
}
}
3 changes: 3 additions & 0 deletions net/tests/Sails.DemoClient.Tests/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
global using System.Threading.Tasks;
global using Sails.Tests.Shared.XUnit;
global using Xunit;
22 changes: 22 additions & 0 deletions net/tests/Sails.DemoClient.Tests/Sails.DemoClient.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<NoWarn>$(NoWarn);xUnit1041</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\examples\Sails.DemoClient\Sails.DemoClient.csproj" />
<ProjectReference Include="..\Sails.Tests.Shared\Sails.Tests.Shared.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Sails.DemoClient.Tests._Infra.XUnit.Fixtures;

public sealed class SailsFixture : Sails.Tests.Shared.XUnit.Fixtures.SailsFixture
{
public SailsFixture()
: base("demo-client-tests")
{
}
}
6 changes: 6 additions & 0 deletions net/tests/Sails.Remoting.Tests/AssemblyAttributes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[assembly: TestFramework(
"Sails.Tests.Shared.XUnit.TestFramework",
"Sails.Tests.Shared")]

[assembly: AssemblyFixture(
typeof(Sails.Remoting.Tests._Infra.XUnit.Fixtures.SailsFixture))]
Loading