Skip to content

Commit

Permalink
Extend authentication service and add API Tests (baking-bad#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmirgaleev authored Apr 18, 2022
1 parent a30dff8 commit 2c2e8c2
Show file tree
Hide file tree
Showing 25 changed files with 1,428 additions and 135 deletions.
41 changes: 41 additions & 0 deletions Tzkt.Api.Tests/Api/SettingsFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Net.Http;
using Dynamic.Json;

namespace Tzkt.Api.Tests.Api
{
public class SettingsFixture : IDisposable
{
static readonly object Crit = new();

public HttpClient Client { get; }
public string Baker { get; }
public string Delegator { get; }
public string Originator { get; }
public int Cycle { get; }

public SettingsFixture()
{
lock (Crit)
{
var settings = DJson.Read("../../../Api/settings.json");

Client = new HttpClient()
{
BaseAddress = new Uri(settings.Url)
};

Baker = settings.Baker;
Delegator = settings.Delegator;
Originator = settings.Originator;
Cycle = settings.Cycle;
}
}

public void Dispose()
{
Client.Dispose();
GC.SuppressFinalize(this);
}
}
}
132 changes: 132 additions & 0 deletions Tzkt.Api.Tests/Api/TestAccountsQueries.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
using System.Net.Http;
using System.Threading.Tasks;
using Dynamic.Json;
using Dynamic.Json.Extensions;
using Xunit;

namespace Tzkt.Api.Tests.Api
{
public class TestAccountsQueries : IClassFixture<SettingsFixture>
{
readonly SettingsFixture Settings;
readonly HttpClient Client;

public TestAccountsQueries(SettingsFixture settings)
{
Settings = settings;
Client = settings.Client;
}

[Fact]
public async Task TestAccountsCount()
{
var res = await Client.GetJsonAsync("/v1/accounts/count");

Assert.True(res is DJsonValue);
}

[Fact]
public async Task TestAccounts()
{
var res = await Client.GetJsonAsync("/v1/accounts");

Assert.True(res is DJsonArray);
}

[Fact]
public async Task TestUsers()
{
var res = await Client.GetJsonAsync("/v1/accounts?type=user");

Assert.True(res is DJsonArray);
}

[Fact]
public async Task TestDelegates()
{
var res = await Client.GetJsonAsync("/v1/accounts?type=delegate");

Assert.True(res is DJsonArray);
}

[Fact]
public async Task TestContracts()
{
var res = await Client.GetJsonAsync("/v1/accounts?type=contract");

Assert.True(res is DJsonArray);
}

[Fact]
public async Task TestGhosts()
{
var res = await Client.GetJsonAsync("/v1/accounts?type=ghost");

Assert.True(res is DJsonArray);
}

[Fact]
public async Task TestAccountByAddress()
{
var res = await Client.GetJsonAsync($"/v1/accounts/{Settings.Baker}");

Assert.True(res is DJsonObject);
}

[Fact]
public async Task TestAccountContracts()
{
var res = await Client.GetJsonAsync($"/v1/accounts/{Settings.Originator}/contracts");

Assert.True(res is DJsonArray);
}

[Fact]
public async Task TestAccountDelegators()
{
var res = await Client.GetJsonAsync($"/v1/accounts/{Settings.Baker}/delegators");

Assert.True(res is DJsonArray);
}

[Fact]
public async Task TestAccountOperations()
{
var res = await Client.GetJsonAsync($"/v1/accounts/{Settings.Baker}/operations");

Assert.True(res is DJsonArray);
}

[Fact]
public async Task TestCounter()
{
var res = await Client.GetJsonAsync($"/v1/accounts/{Settings.Baker}/counter");

Assert.True(res is DJsonValue);
}

[Fact]
public async Task TestBalance()
{
var res = await Client.GetJsonAsync($"/v1/accounts/{Settings.Baker}/balance");

Assert.True(res is DJsonValue);
}

[Fact]
public async Task TestBalanceAtLevel()
{
var res = await Client.GetJsonAsync($"/v1/accounts/{Settings.Baker}/balance_history/10");

Assert.True(res is DJsonValue);
}

[Fact]
public async Task TestBalanceHistory()
{
var res = await Client.GetJsonAsync($"/v1/accounts/{Settings.Baker}/balance_history");

Assert.True(res is DJsonArray);
}
}
}
58 changes: 58 additions & 0 deletions Tzkt.Api.Tests/Api/TestBlocksQueries.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System.Net.Http;
using System.Threading.Tasks;
using Dynamic.Json;
using Dynamic.Json.Extensions;
using Xunit;

namespace Tzkt.Api.Tests.Api
{
public class TestBlocksQueries : IClassFixture<SettingsFixture>
{
readonly HttpClient Client;

public TestBlocksQueries(SettingsFixture settings)
{
Client = settings.Client;
}

[Fact]
public async Task TestBlocksCount()
{
var res = await Client.GetJsonAsync("/v1/blocks/count");

Assert.True(res is DJsonValue);
}

[Fact]
public async Task TestBlocks()
{
var res = await Client.GetJsonAsync("/v1/blocks");

Assert.True(res is DJsonArray);
}

[Fact]
public async Task TestBlockByLevel()
{
var res = await Client.GetJsonAsync("/v1/blocks/10");

Assert.True(res is DJsonObject);
}

[Fact]
public async Task TestBlockOperations()
{
var res = await Client.GetJsonAsync("/v1/blocks/10?operations=true");

Assert.True(res is DJsonObject);
}

[Fact]
public async Task TestBlockQuotes()
{
var res = await Client.GetJsonAsync("/v1/blocks/10?quote=usd");

Assert.True(res is DJsonObject);
}
}
}
Loading

0 comments on commit 2c2e8c2

Please sign in to comment.