Skip to content

Commit

Permalink
Tests and updates from API
Browse files Browse the repository at this point in the history
  • Loading branch information
xactant committed Sep 16, 2022
1 parent 5497fce commit 96164da
Show file tree
Hide file tree
Showing 29 changed files with 394 additions and 134 deletions.
Binary file modified .vs/MoralisDotNetSdk/DesignTimeBuild/.dtbcache.v2
Binary file not shown.
Binary file modified .vs/MoralisDotNetSdk/v17/.futdcache.v1
Binary file not shown.
3 changes: 1 addition & 2 deletions Moralis.Sdk.UnitTests/SettingsRequestTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ internal class SettingsRequestTests
[Test]
public void Json_DeserializesToSettingsRequest()
{
string json = "{\"secretKey\":\"0xdeadbeef\", \"region\": \"eu-central-1\"}";
string json = "{\"region\": \"eu-central-1\"}";
SettingsDetail sr = JsonConvert.DeserializeObject<SettingsDetail>(json);

Assert.IsNotNull(sr);
Assert.AreEqual("0xdeadbeef", sr.SecretKey);
Assert.AreEqual("eu-central-1", sr.Region);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,35 @@

namespace Moralis.StreamsApi.Integrated.Tests
{
internal class LoggerTests : IIntegratedTest
internal class HistoryTests : IIntegratedTest
{

private IntegratedTestResult testResults;
public async Task<IntegratedTestResult> RunTests(IStreamsApiClient streamsApi, string address)
{
testResults = new IntegratedTestResult();

Console.WriteLine("Running test GetLogs");
if (await GetLogs(streamsApi))
Console.WriteLine("Running test GetHistory");
if (await GetHistory(streamsApi))
{
testResults.PassedTests.Add("GetLogs", "PASSED");
testResults.PassedTests.Add("GetHistory", "PASSED");
}
else
{
testResults.FailedTests.Add("GetLogs", "FAILED");
testResults.FailedTests.Add("GetHistory", "FAILED");
Console.WriteLine("\tFAILED");
}

return testResults;
}

private async Task<bool> GetLogs(IStreamsApiClient streamsApi)
private async Task<bool> GetHistory(IStreamsApiClient streamsApi)
{
bool result = true;

try
{
LogResponse resp = await streamsApi.LoggerEndpoint.GetLogs(10, "debug", null);
HistoryResponse resp = await streamsApi.HistoryEndpoint.GetHistory(10, null);

result = resp is { };
}
Expand Down
4 changes: 2 additions & 2 deletions Moralis.StreamsApi.Integrated.Tests/ProgramTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ static List<IIntegratedTest> TestGroups()
{
List<IIntegratedTest> groups = new List<IIntegratedTest>();

//groups.Add(new LoggerTests());
//groups.Add(new SettingsTests());
groups.Add(new HistoryTests());
groups.Add(new SettingsTests());
groups.Add(new StreamsTests());

return groups;
Expand Down
4 changes: 1 addition & 3 deletions Moralis.StreamsApi.Integrated.Tests/SettingsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ private async Task<bool> GetSettings(IStreamsApiClient streamsApi)
{
SettingsDetail resp = await streamsApi.SettingsEndpoint.GetSettings();
result = (resp is { } &&
resp.SecretKey.Equals(MoralisClient.ConnectionData.MasterKey) &&
resp.Region.Equals("eu-central-1"));
}
catch (Exception exp)
Expand All @@ -65,8 +64,7 @@ private async Task<bool> PostSettings(IStreamsApiClient streamsApi)
{
SettingsDetail settings = new SettingsDetail()
{
Region = "eu-central-1",
SecretKey = MoralisClient.ConnectionData.MasterKey
Region = "eu-central-1"
};

result = await streamsApi.SettingsEndpoint.PostSettings(settings);
Expand Down
6 changes: 3 additions & 3 deletions Moralis.StreamsApi.Integrated.Tests/StreamsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ private async Task<bool> GetStream(IStreamsApiClient streamsApi, string streamId

try
{
StreamBindingDto[] resp = await streamsApi.StreamsEndpoint.GetStream(streamId);
StreamBindingDto resp = await streamsApi.StreamsEndpoint.GetStream(streamId);

result = (resp != null && resp.Length > 0 &&
!String.IsNullOrEmpty(resp[0].StreamId));
result = (resp != null &&
!String.IsNullOrEmpty(resp.StreamId));
}
catch (Exception exp)
{
Expand Down
12 changes: 6 additions & 6 deletions Moralis.Web3Api.Integrated.Tests/ProgramTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ static List<IIntegratedTest> TestGroups()
List<IIntegratedTest> groups = new List<IIntegratedTest>();

groups.Add(new AccountTests());
//groups.Add(new InfoTests());
//groups.Add(new DefiTests());
//groups.Add(new NativeTests());
//groups.Add(new ResolveTests());
//groups.Add(new StorageTests());
//groups.Add(new TokenTests());
groups.Add(new InfoTests());
groups.Add(new DefiTests());
groups.Add(new NativeTests());
groups.Add(new ResolveTests());
groups.Add(new StorageTests());
groups.Add(new TokenTests());

return groups;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@

namespace Moralis.StreamsApi.Api
{
public class LoggerApi : ILoggerApi
{
public class HistoryApi : IHistoryApi
{
/// <summary>
/// Initializes a new instance of the <see cref="AuthenticationApi"/> class.
/// Initializes a new instance of the <see cref="HistoryApi"/> class.
/// </summary>
/// <param name="apiClient"> an instance of ApiClient (optional)</param>
public LoggerApi(ApiClient apiClient = null)
public HistoryApi(ApiClient apiClient = null)
{
if (apiClient == null) // use the default one in Configuration
this.ApiClient = Configuration.DefaultApiClient;
Expand All @@ -25,9 +25,9 @@ public LoggerApi(ApiClient apiClient = null)
}

/// <summary>
/// Initializes a new instance of the <see cref="AuthenticationApi"/> class.
/// Initializes a new instance of the <see cref="HistoryApi"/> class.
/// </summary>
public LoggerApi(String basePath)
public HistoryApi(String basePath)
{
this.ApiClient = new ApiClient(basePath);
}
Expand Down Expand Up @@ -59,22 +59,20 @@ public String GetBasePath(String basePath)
public ApiClient ApiClient { get; set; }

/// <summary>
/// Retrieves stream logs.
/// Retrieves history.
/// </summary>
/// <param name="limit">double</param>
/// <param name="logType">string</param>
/// <param name="cursor">string</param>
/// <returns>LogResponse</returns>
/// <exception cref="ApiException"></exception>
public async Task<LogResponse> GetLogs(double limit, string logType, string cursor)
public async Task<HistoryResponse> GetHistory(long limit, string cursor)
{
var headerParams = new Dictionary<String, String>();

var path = "/logger";
var path = "/history";
var queryParams = new Dictionary<String, String>();

queryParams.Add("limit", ApiClient.ParameterToString(limit));
if (logType != null) queryParams.Add("logType", ApiClient.ParameterToString(logType));
if (cursor != null) queryParams.Add("cursor", ApiClient.ParameterToString(cursor));

// Authentication setting, if any
Expand All @@ -88,11 +86,11 @@ public async Task<LogResponse> GetLogs(double limit, string logType, string curs
string data = await response.Content.ReadAsStringAsync();
List<Parameter> headers = ApiClient.ResponHeadersToParameterList(response.Headers);

return (LogResponse)ApiClient.Deserialize(data, typeof(LogResponse), headers);
return (HistoryResponse)ApiClient.Deserialize(data, typeof(HistoryResponse), headers);
}
else
{
throw new ApiException((int)response.StatusCode, $"Error calling Authentication Health Check: {response.ReasonPhrase}");
throw new ApiException((int)response.StatusCode, $"Error calling GetHistory: {response.ReasonPhrase}");
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions MoralisDotNet/Moralis.StreamsApi/Api/SettingsApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public async Task<SettingsDetail> GetSettings()
}
else
{
throw new ApiException((int)response.StatusCode, $"Error calling Authentication Health Check: {response.ReasonPhrase}");
throw new ApiException((int)response.StatusCode, $"Error calling GetSettings: {response.ReasonPhrase}");
}
}

Expand Down Expand Up @@ -121,7 +121,7 @@ public async Task<bool> PostSettings(SettingsDetail req)
}
else
{
throw new ApiException((int)response.StatusCode, $"Error calling GetPairAddress: {response.ReasonPhrase}");
throw new ApiException((int)response.StatusCode, $"Error calling PostSettings: {response.ReasonPhrase}");
}

return result;
Expand Down
14 changes: 7 additions & 7 deletions MoralisDotNet/Moralis.StreamsApi/Api/StreamsApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public async Task<StreamBindingDto> BindStream(StreamBindingDto req)
}
else
{
throw new ApiException((int)response.StatusCode, $"Error calling GetPairAddress: {response.ReasonPhrase}");
throw new ApiException((int)response.StatusCode, $"Error calling BindStream: {response.ReasonPhrase}");
}
}

Expand Down Expand Up @@ -140,7 +140,7 @@ public async Task<StreamBindingDto> DeleteStream(string streamId)
/// <param name="streamId"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public async Task<StreamBindingDto[]> GetStream(string streamId)
public async Task<StreamBindingDto> GetStream(string streamId)
{
// Verify stream Id is set.
if (string.IsNullOrEmpty(streamId)) throw new ApiException(400, "Missing required parameter 'streamId' when calling GetStream");
Expand All @@ -163,11 +163,11 @@ public async Task<StreamBindingDto[]> GetStream(string streamId)
string data = await response.Content.ReadAsStringAsync();
List<Parameter> headers = ApiClient.ResponHeadersToParameterList(response.Headers);

return (StreamBindingDto[])ApiClient.Deserialize(data, typeof(StreamBindingDto[]), headers);
return (StreamBindingDto)ApiClient.Deserialize(data, typeof(StreamBindingDto), headers);
}
else
{
throw new ApiException((int)response.StatusCode, $"Error calling Authentication Health Check: {response.ReasonPhrase}");
throw new ApiException((int)response.StatusCode, $"Error calling DeleteStream: {response.ReasonPhrase}");
}
}

Expand All @@ -176,7 +176,7 @@ public async Task<StreamBindingDto[]> GetStream(string streamId)
/// </summary>
/// <returns>StreamBindingDto List</returns>
/// <exception cref="NotImplementedException"></exception>
public async Task<StreamsResponse> GetStreams(int limit, string cursor = "")
public async Task<StreamsResponse> GetStreams(long limit, string cursor = "")
{
var headerParams = new Dictionary<String, String>();
var queryParams = new Dictionary<String, String>();
Expand All @@ -201,7 +201,7 @@ public async Task<StreamsResponse> GetStreams(int limit, string cursor = "")
}
else
{
throw new ApiException((int)response.StatusCode, $"Error calling Authentication Health Check: {response.ReasonPhrase}");
throw new ApiException((int)response.StatusCode, $"Error calling GetStreams: {response.ReasonPhrase}");
}
}

Expand Down Expand Up @@ -246,7 +246,7 @@ public async Task<StreamBindingDto> UpdateStream(StreamBindingDto req)
}
else
{
throw new ApiException((int)response.StatusCode, $"Error calling GetPairAddress: {response.ReasonPhrase}");
throw new ApiException((int)response.StatusCode, $"Error calling UpdateStream: {response.ReasonPhrase}");
}
}

Expand Down
19 changes: 16 additions & 3 deletions MoralisDotNet/Moralis.StreamsApi/Client/StreamsApiClient.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Moralis.Network;
using Moralis.StreamsApi.Api;
using Moralis.StreamsApi.Interfaces;
using System.Security.Cryptography;


namespace Moralis.StreamsApi.Client
{
Expand All @@ -12,9 +14,9 @@ public class StreamsApiClient : IStreamsApiClient
private static string defaultServerUrl = "https://auth-api.do-prod-1.moralis.io/";

/// <summary>
/// Target Logger Endpoint.
///
/// </summary>
public ILoggerApi LoggerEndpoint { get; private set; }
public IHistoryApi HistoryEndpoint { get; private set; }

/// <summary>
/// Target Settings Endpoint
Expand Down Expand Up @@ -55,12 +57,23 @@ public void Initialize(string serverUrl = null)
// Initialize client
ApiClient client = new ApiClient(serverUrl is { } ? serverUrl : defaultServerUrl);

LoggerEndpoint = new LoggerApi(client);
HistoryEndpoint = new HistoryApi(client);
SettingsEndpoint = new SettingsApi(client);
StreamsEndpoint = new Api.StreamsApi(client);

// Indicate that the client is initialized.
this.IsInitialized = true;
}

/// <summary>
/// Verifies that a WebHook message was sent by Moralis using sha3(REQUEST_BODY + WEB3_API_KEY);
/// </summary>
/// <param name="signature"></param>
/// <param name="requestBody"></param>
/// <returns>bool</returns>
public bool VerifySignature(string signature, string requestBody)
{
return true; // SHA512 sha512 = new SHA512();
}
}
}
16 changes: 16 additions & 0 deletions MoralisDotNet/Moralis.StreamsApi/Interfaces/IHistoryApi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Moralis.StreamsApi.Models;
using System.Threading.Tasks;

namespace Moralis.StreamsApi.Interfaces
{
public interface IHistoryApi
{
/// <summary>
/// Returns Webhook information - currently only Failed webhook information returned.
/// </summary>
/// <param name="limit"></param>
/// <param name="cursor"></param>
/// <returns></returns>
Task<HistoryResponse> GetHistory(long limit, string cursor = "");
}
}
17 changes: 0 additions & 17 deletions MoralisDotNet/Moralis.StreamsApi/Interfaces/ILoggerApi.cs

This file was deleted.

4 changes: 2 additions & 2 deletions MoralisDotNet/Moralis.StreamsApi/Interfaces/IStreamsApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ public interface IStreamsApi
/// </summary>
/// <param name="id"></param>
/// <returns>StreamBindingDto[]</returns>
public Task<StreamBindingDto[]> GetStream(string id);
public Task<StreamBindingDto> GetStream(string id);

/// <summary>
/// Get all the streams for the current project based on the project api-key.
/// </summary>
/// <returns>List<StreamBindingDto></returns>
public Task<StreamsResponse> GetStreams(int limit, string cursor);
public Task<StreamsResponse> GetStreams(long limit, string cursor);

/// <summary>
/// Updates a specific stream.
Expand Down
12 changes: 10 additions & 2 deletions MoralisDotNet/Moralis.StreamsApi/Interfaces/IStreamsApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ namespace Moralis.StreamsApi.Interfaces
public interface IStreamsApiClient
{
/// <summary>
/// Target Logger Endpoint.
///
/// </summary>
public ILoggerApi LoggerEndpoint { get; }
public IHistoryApi HistoryEndpoint { get; }

/// <summary>
/// Target Settings Endpoint
Expand All @@ -29,5 +29,13 @@ public interface IStreamsApiClient
/// </summary>
/// <param name="serverUrl"></param>
void Initialize(string serverUrl = null);

/// <summary>
/// Verifies that a WebHook message was sent by Moralis using sha3(REQUEST_BODY + WEB3_API_KEY);
/// </summary>
/// <param name="signature"></param>
/// <param name="requestBody"></param>
/// <returns>bool</returns>
bool VerifySignature(string signature, string requestBody);
}
}
8 changes: 8 additions & 0 deletions MoralisDotNet/Moralis.StreamsApi/Models/HistoryDetail.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@


namespace Moralis.StreamsApi.Models
{
public class HistoryDetail
{
}
}
Loading

0 comments on commit 96164da

Please sign in to comment.