Skip to content

Commit

Permalink
Merge pull request #1 from reown-com/chore/tests
Browse files Browse the repository at this point in the history
chore: improve tests
  • Loading branch information
skibitsky authored Sep 18, 2024
2 parents 3108e74 + f39f1a3 commit 94f28dc
Show file tree
Hide file tree
Showing 18 changed files with 267 additions and 17 deletions.
30 changes: 30 additions & 0 deletions .github/actions/test-dotnet/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: 'test-dotnet'
description: 'Runs unit and integration tests with dotnet cli'

inputs:
type:
description: 'The type of CI step to run'
required: true
relay-endpoint:
description: 'The endpoint of the relay e.g. wss://relay.walletconnect.org'
required: false
default: 'wss://relay.walletconnect.org'
project-id:
description: 'Reown project id'
required: true

runs:
using: "composite"
steps:
- name: Run tests
if: inputs.type == 'unit-tests'
shell: bash
run: dotnet test Reown.NoUnity.slnf --verbosity minimal --filter Category=unit

- name: Run integration tests
if: inputs.type == 'integration-tests'
shell: bash
env:
RELAY_ENDPOINT: ${{ inputs.relay-endpoint }}
PROJECT_ID: ${{ inputs.project-id }}
run: dotnet test Reown.NoUnity.slnf --verbosity minimal --filter Category=integration
50 changes: 50 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: .NET Build & Test

on:
push:
branches: [ main ]
pull_request:
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
8.0.x
- name: Restore dependencies
run: dotnet restore
working-directory: ./

- name: Build
run: dotnet build Reown.NoUnity.slnf --no-restore
working-directory: ./

test:
needs: build
runs-on: ubuntu-latest
strategy:
matrix:
test-type: [unit-tests, integration-tests]

steps:
- uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
8.0.x
- name: Run tests
uses: ./.github/actions/test-dotnet
with:
type: ${{ matrix.test-type }}
project-id: ${{ secrets.PROJECT_ID }}
13 changes: 13 additions & 0 deletions .idea/.idea.Reown.NoUnity/.idea/.gitignore

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

1 change: 1 addition & 0 deletions .idea/.idea.Reown.NoUnity/.idea/.name

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

4 changes: 4 additions & 0 deletions .idea/.idea.Reown.NoUnity/.idea/encodings.xml

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

8 changes: 8 additions & 0 deletions .idea/.idea.Reown.NoUnity/.idea/indexLayout.xml

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

6 changes: 6 additions & 0 deletions .idea/.idea.Reown.NoUnity/.idea/vcs.xml

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

8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
Reown is the onchain UX platform that provides toolkits built on top of the WalletConnect Network that enable builders to create onchain user experiences
that make digital ownership effortless, intuitive, and secure.

This is a monorepo of Unity and NuGet packages for AppKit, WalletKit, and other Reown libraries.
This is a monorepo of Unity and NuGet packages for [AppKit](https://reown.com/appkit), [WalletKit](https://reown.com/walletkit), and other Reown libraries.

| | <img width="36px" src="https://raw.githubusercontent.com/reown-com/reown-dotnet/main/media/appkit-icon.png"> <br/>AppKit | <img width="36px" src="https://raw.githubusercontent.com/reown-com/reown-dotnet/main/media/walletkit-icon.png"> <br/>WalletKit |
|----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------|
| Package | [![openupm](https://img.shields.io/npm/v/com.reown.appkit.unity?label=openupm&registry_uri=https://package.openupm.com&logo=unity)](https://openupm.com/packages/com.reown.appkit.unity/) | ![NuGet Version](https://img.shields.io/nuget/v/Reown.WalletKit?logo=nuget) |
| Platform | ![Unity](https://img.shields.io/badge/unity-≥_2022.3-grey?logo=unity&labelColor=black) | ![Static Badge](https://img.shields.io/badge/7.0_%7C_8.0_%7C_standard_2.1-blue?logo=.net&labelColor=%235027d5&color=gray) |


## License

Expand Down
22 changes: 22 additions & 0 deletions Reown.NoUnity.slnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"solution": {
"path": "Reown.sln",
"projects": [
"src\\Reown.Core.Common\\Reown.Core.Common.csproj",
"src\\Reown.Core.Crypto\\Reown.Core.Crypto.csproj",
"src\\Reown.Core.Network.WebSocket\\Reown.Core.Network.WebSocket.csproj",
"src\\Reown.Core.Network\\Reown.Core.Network.csproj",
"src\\Reown.Core.Storage\\Reown.Core.Storage.csproj",
"src\\Reown.Core\\Reown.Core.csproj",
"src\\Reown.Sign.Nethereum\\Reown.Sign.Nethereum.csproj",
"src\\Reown.Sign\\Reown.Sign.csproj",
"src\\Reown.WalletKit\\Reown.WalletKit.csproj",
"test\\Reown.Core.Crypto.Test\\Reown.Core.Crypto.Test.csproj",
"test\\Reown.Core.Network.Test\\Reown.Core.Network.Test.csproj",
"test\\Reown.Core.Storage.Test\\Reown.Core.Storage.Test.csproj",
"test\\Reown.Sign.Test\\Reown.Sign.Test.csproj",
"test\\Reown.WalletKit.Test\\Reown.WalletKit.Test.csproj",
"test\\Rown.TestUtils\\Rown.TestUtils.csproj"
]
}
}
6 changes: 6 additions & 0 deletions Reown.sln
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Reown.WalletKit", "src\Reow
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Reown.WalletKit.Test", "test\Reown.WalletKit.Test\Reown.WalletKit.Test.csproj", "{D27B8D54-3BB7-4A1F-B8DA-7D00ADE730A7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Reown.Core.Storage.Test", "test\Reown.Core.Storage.Test\Reown.Core.Storage.Test.csproj", "{F13FA074-D00C-46B9-A7AC-78FCF940165D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -108,5 +110,9 @@ Global
{D27B8D54-3BB7-4A1F-B8DA-7D00ADE730A7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D27B8D54-3BB7-4A1F-B8DA-7D00ADE730A7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D27B8D54-3BB7-4A1F-B8DA-7D00ADE730A7}.Release|Any CPU.Build.0 = Release|Any CPU
{F13FA074-D00C-46B9-A7AC-78FCF940165D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F13FA074-D00C-46B9-A7AC-78FCF940165D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F13FA074-D00C-46B9-A7AC-78FCF940165D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F13FA074-D00C-46B9-A7AC-78FCF940165D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
Binary file added media/appkit-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/Reown.AppKit.Unity/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Reown - AppKit Unity

<img src="https://reown-docs.vercel.app/reown/appkit-logo.svg">
<img width="60px" src="https://raw.githubusercontent.com/reown-com/reown-dotnet/main/media/appkit-icon.png">

The all-in-one stack to build apps for the new internet.

Expand Down
2 changes: 1 addition & 1 deletion src/Reown.WalletKit/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Reown - WalletKit .NET

<img src="https://reown-docs.vercel.app/reown/walletkit-logo.svg">
<img width="60px" src="https://raw.githubusercontent.com/reown-com/reown-dotnet/main/media/walletkit-icon.png">

The ultimate toolkit for building and connecting wallets.

Expand Down
63 changes: 63 additions & 0 deletions test/Reown.Core.Storage.Test/FileSystemStorageTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using Reown.TestUtils;
using Xunit;

namespace Reown.Core.Storage.Test;

public class FileSystemStorageTest
{
[Fact] [Trait("Category", "unit")]
public async Task GetSetRemoveTest()
{
using var tempFolder = new TempFolder();
var testDictStorage = new FileSystemStorage(Path.Combine(tempFolder.Folder.FullName, ".wctestdata"));
await testDictStorage.Init();
await testDictStorage.SetItem("somekey", "somevalue");
Assert.Equal("somevalue", await testDictStorage.GetItem<string>("somekey"));
await testDictStorage.RemoveItem("somekey");
await Assert.ThrowsAsync<KeyNotFoundException>(() => testDictStorage.GetItem<string>("somekey"));
}

private static readonly string[] expected = new string[]
{
"addkey"
};

[Fact] [Trait("Category", "unit")]
public async Task GetKeysTest()
{
using var tempFolder = new TempFolder();
var testDictStorage = new FileSystemStorage(Path.Combine(tempFolder.Folder.FullName, ".wctestdata"));
await testDictStorage.Init();
await testDictStorage.Clear(); //Clear any persistant state
await testDictStorage.SetItem("addkey", "testingvalue");
Assert.Equal(expected, await testDictStorage.GetKeys());
}

[Fact] [Trait("Category", "unit")]
public async Task GetEntriesTests()
{
using var tempFolder = new TempFolder();
var testDictStorage = new FileSystemStorage(Path.Combine(tempFolder.Folder.FullName, ".wctestdata"));
await testDictStorage.Init();
await testDictStorage.Clear();
await testDictStorage.SetItem("addkey", "testingvalue");
Assert.Equal([
"testingvalue"
], await testDictStorage.GetEntries());
await testDictStorage.SetItem("newkey", 5);
Assert.Equal(new int[]
{
5
}, await testDictStorage.GetEntriesOfType<int>());
}

[Fact] [Trait("Category", "unit")]
public async Task HasItemTest()
{
using var tempFolder = new TempFolder();
var testDictStorage = new FileSystemStorage(Path.Combine(tempFolder.Folder.FullName, ".wctestdata"));
await testDictStorage.Init();
await testDictStorage.SetItem("checkedkey", "testingvalue");
Assert.True(await testDictStorage.HasItem("checkedkey"));
}
}
26 changes: 26 additions & 0 deletions test/Reown.Core.Storage.Test/Reown.Core.Storage.Test.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<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"/>
<PackageReference Include="xunit"/>
<PackageReference Include="xunit.runner.visualstudio">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Reown.Core.Storage\Reown.Core.Storage.csproj" />
<ProjectReference Include="..\Rown.TestUtils\Rown.TestUtils.csproj" />
</ItemGroup>

</Project>
21 changes: 13 additions & 8 deletions test/Reown.Sign.Test/SignClientFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ public override async Task Init()
RelayUrl = TestValues.TestRelayUrl,
Metadata = new Metadata()
{
Description = "An example dapp to showcase WalletConnectSharpv2",
Description = "Dapp Test",
Icons = new[]
{
"https://walletconnect.com/meta/favicon.ico"
"https://raw.githubusercontent.com/reown-com/reown-dotnet/main/media/reown-avatar-positive.png"
},
Name = $"WalletConnectSharpv2 Dapp Example",
Url = "https://walletconnect.com"
Name = "Dapp Test",
Url = "https://reown.com"
},
// Omit if you want persistant storage
Storage = StorageOverrideA ?? new InMemoryStorage()
Expand All @@ -50,13 +50,13 @@ public override async Task Init()
RelayUrl = TestValues.TestRelayUrl,
Metadata = new Metadata()
{
Description = "An example wallet to showcase WalletConnectSharpv2",
Description = "Wallet Test",
Icons = new[]
{
"https://walletconnect.com/meta/favicon.ico"
"https://raw.githubusercontent.com/reown-com/reown-dotnet/main/media/reown-avatar-positive.png"
},
Name = $"WalletConnectSharpv2 Wallet Example",
Url = "https://walletconnect.com"
Name = "Wallet Test",
Url = "https://reown.com"
},
// Omit if you want persistant storage
Storage = StorageOverrideB ?? new InMemoryStorage()
Expand All @@ -71,6 +71,11 @@ public override async Task DisposeAndReset()
await WaitForNoPendingRequests(ClientA);
await WaitForNoPendingRequests(ClientB);

await Task.WhenAll(
ClientA.CoreClient.Storage.Clear(),
ClientB.CoreClient.Storage.Clear()
);

await base.DisposeAndReset();
}

Expand Down
20 changes: 15 additions & 5 deletions test/Reown.Sign.Test/SignTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -651,10 +651,18 @@ public async Task TestTwoUniqueComplexSessionRequestResponse()
}

[Fact] [Trait("Category", "integration")]
public async Task TestTwoUniqueSessionRequestResponseUsingAddressProviderDefaults()
public async Task TestTwoUniqueSessionRequestUsingAddressProviderDefaults()
{
await _cryptoFixture.WaitForClientsReady();

await _cryptoFixture.DisposeAndReset();

await TwoUniqueSessionRequestUsingAddressProviderDefaults();
}

private async Task TwoUniqueSessionRequestUsingAddressProviderDefaults()
{
await _cryptoFixture.WaitForClientsReady();

var dappClient = ClientA;
var walletClient = ClientB;

Expand Down Expand Up @@ -860,7 +868,7 @@ public async Task TestAddressProviderDefaultsSaving()
{
await _cryptoFixture.WaitForClientsReady();

await TestTwoUniqueSessionRequestResponseUsingAddressProviderDefaults();
await TwoUniqueSessionRequestUsingAddressProviderDefaults();

var defaultSessionTopic = _cryptoFixture.ClientA.AddressProvider.DefaultSession.Topic;

Expand All @@ -871,7 +879,9 @@ public async Task TestAddressProviderDefaultsSaving()

await Task.Delay(500);

await _cryptoFixture.DisposeAndReset();
_cryptoFixture.ClientA.Dispose();
_cryptoFixture.ClientB.Dispose();
await _cryptoFixture.Init();

await Task.Delay(500);

Expand All @@ -880,7 +890,7 @@ public async Task TestAddressProviderDefaultsSaving()

Assert.Equal(defaultSessionTopic, reloadedDefaultSessionTopic);

await TestTwoUniqueSessionRequestResponseUsingAddressProviderDefaults();
await TwoUniqueSessionRequestUsingAddressProviderDefaults();
}

[Fact] [Trait("Category", "integration")]
Expand Down
2 changes: 1 addition & 1 deletion test/Rown.TestUtils/TwoClientsFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public TwoClientsFixture(bool initNow = true)

public async Task WaitForClientsReady()
{
while (Equals(ClientA, default(TClient)) && Equals(ClientB, default(TClient)))
while (Equals(ClientA, default(TClient)) || Equals(ClientB, default(TClient)))
await Task.Delay(10);
}

Expand Down

0 comments on commit 94f28dc

Please sign in to comment.