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

Dev #4

Merged
merged 30 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
c15d920
Update models and stuff
Mister-Eth Jun 23, 2023
85b094d
Cache configuration provider values
Mister-Eth Jun 26, 2023
4211cc1
Add project
Mister-Eth Jun 30, 2023
b3ef832
Config check
Mister-Eth Jun 30, 2023
40f2987
Action definitions
Mister-Eth Jul 1, 2023
53565df
Formatting
Mister-Eth Jul 1, 2023
4d2382d
Schema dump
Mister-Eth Jul 4, 2023
b1934ed
Update
Mister-Eth Jul 7, 2023
60e8ff7
Update README.md
Mister-Eth Jul 9, 2023
cd33f32
Update README.md
Mister-Eth Jul 9, 2023
f211d3d
Nothing
Mister-Eth Aug 13, 2023
8ad061c
Merge branch 'dev' of https://github.com/ethtps/ethtps.backend into dev
Mister-Eth Aug 13, 2023
2cf05aa
Update dotnet.yml
Mister-Eth Aug 13, 2023
7962777
Update dotnet.yml
Mister-Eth Aug 13, 2023
d7b1d5f
FIle changes
Mister-Eth Aug 13, 2023
831ca84
Added diagram
Mister-Eth Aug 17, 2023
9d528c2
Docker files
Mister-Eth Aug 17, 2023
ad54400
Merge branch 'dev' into auto-setup
Mister-Eth Aug 17, 2023
d072fd5
More config updates
Mister-Eth Aug 18, 2023
5e2d1ca
Replace strings with enums
Mister-Eth Aug 29, 2023
0f423f7
Try use in-mem
Mister-Eth Aug 29, 2023
62fa63b
Run with in-memory storage
Mister-Eth Aug 30, 2023
d446dc5
Fix publisher
Mister-Eth Aug 30, 2023
5467492
Series get returned
Mister-Eth Aug 31, 2023
23d4610
Fix more errors
Mister-Eth Aug 31, 2023
0257f00
Up
Mister-Eth Sep 2, 2023
5a1d04b
Add RPC models
Mister-Eth Sep 3, 2023
d8a7c29
Update models
Mister-Eth Sep 6, 2023
34a4378
Update Provider.cs
Mister-Eth Sep 6, 2023
176b6c1
Auto discover and register EVM-compatible chains
Mister-Eth Sep 6, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ETHTPS_ENV=DEVELOPMENT
ETHTPS_ENV=RELEASE
4 changes: 3 additions & 1 deletion .env.development
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
ETHTPS_ENV=DEVELOPMENT
ETHTPS_ENV=DEVELOPMENT
ETHTPS_CONFIGURATION_PROVIDER_DB_CONN_STR=Server=localhost;Database=ETHTPS.Dev;Trust Server Certificate=True;MultipleActiveResultSets=True;Integrated Security=true;
ETHTPS_CONFIGURATION_PROVIDER_DB_CONN_STR2=Server=10.2.0.65;User Id=ethtps_dev;Password=6f2073f4b34f3bb7f6f23718c878a6b9;Database=ETHTPS.Dev;Trust Server Certificate=True;MultipleActiveResultSets=True;
1 change: 1 addition & 0 deletions .env.testing
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ETHTPS_ENV=TESTING
56 changes: 40 additions & 16 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,51 @@
# This workflow will build a .NET project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net

name: .NET

on:
push:
branches: [ "main", "dev" ]
branches: ["main", "dev"]
pull_request:
branches: [ "main", "dev" ]
branches: ["main", "dev"]

jobs:
build:

runs-on: self-hosted

steps:
- uses: actions/checkout@v3
# We assume .NET is already installed
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
# Extracting branch name for Windows
- name: Extract branch name (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
$branchName = $env:GITHUB_REF -replace "refs/heads/", ""
echo "BRANCH_NAME=$branchName" | Out-File -Append $env:GITHUB_ENV

# Extracting branch name for Linux/macOS
- name: Extract branch name (Linux/macOS)
if: runner.os != 'Windows'
shell: bash
run: echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_ENV

# Modifying paths to include branch name
- name: Set up .env
run: cp ../${BRANCH_NAME}/ethtps_files/.env ./.env

- name: Set up appsttings.json
run: cp ../${BRANCH_NAME}/ethtps_files/appsettings.json ./ETHTPS.API/appsettings.json

- name: Set up docker-compose.yml
run: cp ../${BRANCH_NAME}/ethtps_files/docker-compose.yml ./docker-compose.yml

- name: Set up StartupConfig.json
run: cp ../${BRANCH_NAME}/ethtps_files/StartupConfig.json ./ETHTPS.Configuration/StartupConfig.json

- uses: actions/checkout@v3

# Assuming .NET is already installed
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
1 change: 1 addition & 0 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# TODO
24 changes: 24 additions & 0 deletions ETHTPS.API.BIL.Tests/AutoSetup/AutoSetupTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using ETHTPS.Configuration.AutoSetup.Scripts;

namespace ETHTPS.Tests.AutoSetup;

[TestFixture]
public sealed class AutoSetupTests
{
private readonly ETHTPSAutoSetupScript _mainScript = new("Test");

[SetUp]
public void Setup()
{

}

[Test]
public void BasicRunTest()
{
Assert.DoesNotThrow(() =>
{
_mainScript.Run();
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,29 @@ public void TearDown()
[Test]
public void DependencyInjectionTest()
{
Assert.NotNull(ServiceProvider.GetRequiredService<IDBConfigurationProvider>());
Assert.NotNull(ServiceProvider.GetRequiredService<DBConfigurationProviderWithCache>());
Assert.Pass();
}

[Test]
public void ReturnsHangfireConnectionString()
{
var strings = ConfigurationProvider.GetConfigurationStringsForMicroservice("ETHTPS.TaskRunner");
if (strings == null)
{
Assert.That(strings, Is.Not.Null);
return;
}
strings = strings.ToList();
Assert.That(strings.Count(), Is.GreaterThan(0));
Assert.That(strings.Count(x => x.Name == "HangfireConnectionString"), Is.GreaterThan(1));
}

[Test]
public void AddEnvironments_WithNewEnvironment_AddsNewEnvironment()
{
// Arrange
var provider = ServiceProvider.GetRequiredService<IDBConfigurationProvider>();
var provider = ServiceProvider.GetRequiredService<DBConfigurationProviderWithCache>();
var environmentName = "TestEnvironment";

// Act
Expand All @@ -52,7 +66,7 @@ public void AddEnvironments_WithNewEnvironment_AddsNewEnvironment()
public void AddEnvironments_WithExistingEnvironment_DoesNotAddNewEnvironment()
{
// Arrange
var provider = ServiceProvider.GetRequiredService<IDBConfigurationProvider>();
var provider = ServiceProvider.GetRequiredService<DBConfigurationProviderWithCache>();
var environmentName = "Development";

// Act
Expand All @@ -67,7 +81,7 @@ public void AddEnvironments_WithExistingEnvironment_DoesNotAddNewEnvironment()
public void GetEnvironmentID_WithExistingEnvironment_ReturnsCorrectID()
{
// Arrange
var provider = ServiceProvider.GetRequiredService<IDBConfigurationProvider>();
var provider = ServiceProvider.GetRequiredService<DBConfigurationProviderWithCache>();
var environmentName = "Development";
var expectedEnvironmentID = ServiceProvider.GetRequiredService<ConfigurationContext>().Environments?.Single(x => x.Name == environmentName).Id;

Expand Down
23 changes: 23 additions & 0 deletions ETHTPS.API.BIL.Tests/Data/BasicTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using ETHTPS.Configuration;
using ETHTPS.Configuration.Database;
using ETHTPS.Configuration.Extensions;
using ETHTPS.Data.Core.Models.DataEntries;

namespace ETHTPS.Tests.Data
{
[TestFixture]
public class BasicTests
{
[Test]
public void IsIEnumerableWorks()
{
Assert.That(typeof(IEnumerable<Block>).IsIEnumerable());
Assert.That(typeof(IEnumerable<>).IsIEnumerable());
Assert.That(typeof(IEnumerable<int>).IsIEnumerable());
Assert.That(typeof(IEnumerable<ConfigurationString>).IsIEnumerable());
Assert.That(typeof(IEnumerable<IConfigurationString>).IsIEnumerable());
Assert.That(typeof(IEnumerable<IConfigurationString?>).IsIEnumerable());
Assert.That(typeof(IEnumerable<IConfigurationString>).IsIEnumerable());
}
}
}
2 changes: 1 addition & 1 deletion ETHTPS.API.BIL.Tests/Data/Database/StoredProcedureTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void DeleteAllJobs_DoesNotThrowError()
[Test]
public async Task InsertOrUpdateConfigurationStringAsync_InsertsOrUpdateConfigurationString()
{
var configurationProvider = ServiceProvider.GetRequiredService<IDBConfigurationProvider>();
var configurationProvider = ServiceProvider.GetRequiredService<DBConfigurationProviderWithCache>();
var configurationProviderContext = ServiceProvider.GetRequiredService<ConfigurationContext>();
string microserviceName = "ETHTPS.Tests";
string environmentName = "Development";
Expand Down
8 changes: 6 additions & 2 deletions ETHTPS.API.BIL.Tests/ETHTPS.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
<IsPackable>false</IsPackable>

<Platforms>AnyCPU;x64</Platforms>

<Configurations>Debug;Release;Testing</Configurations>
</PropertyGroup>

<ItemGroup>
Expand All @@ -22,8 +24,8 @@

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.0-preview.4.23259.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.2" />
<PackageReference Include="Moq" Version="4.18.4" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="Moq" Version="4.20.69" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="NUnit.Analyzers" Version="3.6.1">
Expand All @@ -38,11 +40,13 @@

<ItemGroup>
<ProjectReference Include="..\ETHTPS.BIL\ETHTPS.API.BIL.csproj" />
<ProjectReference Include="..\ETHTPS.Configuration.AutoSetup\ETHTPS.Configuration.AutoSetup.csproj" />
<ProjectReference Include="..\ETHTPS.DependencyInjection\ETHTPS.API.DependencyInjection.csproj" />
<ProjectReference Include="..\ETHTPS.Services.Ethereum\ETHTPS.Services.Ethereum.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="AutoSetup\" />
<Folder Include="WSTests\" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion ETHTPS.API.BIL.Tests/InfluxTests/BlockInfoTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public async Task OnlyRequestedProvidersAreReturnedTest()
Assert.Fail();
return;
}
var result = await _service.GetAsync(ProviderQueryModel.FromProviderName("Ethereum"), TimeInterval.OneYear);
var result = await _service.GetAsync(ProviderQueryModel.FromProviderName("Ethereum"), TimeInterval.OneDay);
Assert.That(result, Has.Count.AtMost(1));
Assert.That(result.ContainsKey("Ethereum"), Is.True, $"Keys returned: [{string.Join(',', result.Select((x => x.Key)))}]");
}
Expand Down
17 changes: 8 additions & 9 deletions ETHTPS.API.BIL.Tests/InfluxTests/InfluxValueTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,17 @@ public void GetDataAsync_ShouldReturnEmptyList_WhenNoDataExists()
Assert.Fail($"{nameof(_aggregatedDataservice)} is null");
return;
}

// Set a date range where no data is expected.
var noDataRequestModel = new L2DataRequestModel
{
StartDate = DateTime.Now.AddYears(-100), // Example: 100 years ago.
EndDate = DateTime.Now.AddYears(-99), // Example: 99 years ago.
Providers = _TEST_PROVIDERS.ToList()
StartDate = DateTime.Now.AddYears(-100),
EndDate = DateTime.Now.AddYears(-99),
Providers = _TEST_PROVIDERS.ToList(),
IncludeEmptyDatasets = false
};

var response = await _aggregatedDataservice.GetDataAsync(noDataRequestModel, _dataType);
Assert.That(response, Is.Not.Null, "Response is null");
Assert.That(response.Datasets, Is.Empty, "Response datasets is not empty"); // Assert that the response is an empty list.
Assert.That(response.Datasets?.Sum(x => x.DataPoints.Count()), Is.EqualTo(0));
});
}

Expand Down Expand Up @@ -180,7 +179,7 @@ public void GetDataAsync_ShouldApplyBucketOptionsCorrectlyAndShouldReturnDataInC
Assert.That(data?.Count, Is.GreaterThan(0));
foreach (var dataset in data ?? throw new Exception("Null datasets"))
{
var datedPoints = dataset.DataPoints.Select(x => x.ToDatedXYDataPoint());
var datedPoints = dataset.DataPoints.Select(x => x.ToDatedXYDataPoint()).ToList();
for (int i = 0, j = 1; i < datedPoints?.Count() - 1; i++, j++)
{
Assert.That(datedPoints?.ElementAt(j).X - datedPoints?.ElementAt(i).X, Is.GreaterThanOrEqualTo(expectedSize));
Expand Down Expand Up @@ -226,7 +225,7 @@ public async Task GetDataAsync_ShouldPerformSimpleAnalysisWhenRequested()
Assert.That(response, Is.Not.Null);
Assert.That(response.Datasets, Is.Not.Null);
#pragma warning disable CS8604 // Possible null reference argument.
Assert.That((bool)(response.Datasets.All(x => x.SimpleAnalysis != null)));
Assert.That(response.Datasets.All(x => x.SimpleAnalysis != null));
#pragma warning restore CS8604 // Possible null reference argument.
}

Expand All @@ -252,7 +251,7 @@ public async Task GetDataAsync_ShouldPerformComplexAnalysisWhenRequested()
// Check for presence of complex analysis data
// NOTE: Replace 'ComplexAnalysisProperty' with the actual property that indicates the result of complex analysis
#pragma warning disable CS8604 // Possible null reference argument.
Assert.That((bool)(response.Datasets.All(x => x.ComplexAnalysis != null)));
Assert.That(response.Datasets.All(x => x.ComplexAnalysis != null));
#pragma warning restore CS8604 // Possible null reference argument.
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ public class ThroughputTest : TestBase
private IConnection? _conn;
private IModel? _ch;
private EventingBasicConsumer? _consumer;

[SetUp]
public void Init()
{
ConnectionFactory? cf = new()
{
AutomaticRecoveryEnabled = false,
HostName = ServiceProvider.GetRequiredService<IDBConfigurationProvider>().GetFirstConfigurationString("RabbitMQ_Host_Dev") ?? "localhost"
HostName = ServiceProvider.GetRequiredService<DBConfigurationProviderWithCache>().GetFirstConfigurationString("RabbitMQ_Host_Dev") ?? "localhost"
};
_conn = cf.CreateConnection();
_ch = _conn.CreateModel();
Expand Down
2 changes: 1 addition & 1 deletion ETHTPS.API.BIL.Tests/ProviderTests/CustomProvidersTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public sealed class SorareTests : ProviderTestBase<SorareBlockInfoProvider>
[SetUp]
public override void SetUp()
{
_provider = new SorareBlockInfoProvider(ServiceProvider.GetRequiredService<EthtpsContext>(), ServiceProvider.GetRequiredService<IDBConfigurationProvider>());
_provider = new SorareBlockInfoProvider(ServiceProvider.GetRequiredService<EthtpsContext>(), ServiceProvider.GetRequiredService<DBConfigurationProviderWithCache>());
PartialSetup(_provider);
}
}
Expand Down
7 changes: 3 additions & 4 deletions ETHTPS.API.BIL.Tests/ServiceTests/CacheTests.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using ETHTPS.API.BIL.Infrastructure.Services.DataServices;
using ETHTPS.API.Core.Services;
using ETHTPS.API.Core.Services;
using ETHTPS.Configuration;
using ETHTPS.Configuration.Extensions;
using ETHTPS.Data.Core;
using ETHTPS.Core;

using Microsoft.Extensions.DependencyInjection;

Expand All @@ -24,7 +23,7 @@ public sealed class CacheTests : TestBase
public void Setup()
{
// Initialize the ICachedDataService implementation here.
_connectionMultiplexer = ConnectionMultiplexer.Connect(ServiceProvider.GetRequiredService<IDBConfigurationProvider>().GetFirstConfigurationString("RedisServer") ?? "localhost");
_connectionMultiplexer = ConnectionMultiplexer.Connect(ServiceProvider.GetRequiredService<DBConfigurationProviderWithCache>().GetFirstConfigurationString("RedisServer") ?? "localhost");
_database = _connectionMultiplexer.GetDatabase();
_cachedDataService = new RedisCachedDataService(_connectionMultiplexer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void NoExceptionThrownTest()
public void UniquenessTest()
{
var groups = _statusService?.GetAllStatuses().GroupBy(x => (x ?? ETHTPS.Data.Core.Models.DataUpdater.LiveDataUpdaterStatus.EMPTY).Updater + (x ?? ETHTPS.Data.Core.Models.DataUpdater.LiveDataUpdaterStatus.EMPTY).UpdaterType);
if ((bool)(groups?.Any(x => x.Count() > 1)).GetValueOrDefault())
if ((groups?.Any(x => x.Count() > 1)).GetValueOrDefault())
{
Assert.Fail("Multiple entries for the same updater found", groups?.Where(x => x.Count() > 1));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,19 @@ public sealed class RabbitMQMessagePublisherTests : TestBase
{
private static string _host = "localhost";
private static string _queue = "test_queue";
private static IDBConfigurationProvider? _configurationProvider;
private static DBConfigurationProviderWithCache? _configurationProvider;

[SetUp]
public void Setup()
{
_configurationProvider = ServiceProvider.GetRequiredService<IDBConfigurationProvider>();
_host = _configurationProvider.GetFirstConfigurationString("RabbitMQ_Host_Dev") ?? "localhost";
_configurationProvider = ServiceProvider.GetRequiredService<DBConfigurationProviderWithCache>();
_host = _configurationProvider.GetFirstConfigurationString(
#if DEBUG
"RabbitMQ_Host_Dev"
#else
"RabbitMQ_Host"
#endif
) ?? "localhost";
}

[Test]
Expand Down
Loading
Loading