forked from ac10n/tzkt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extend authentication service and add API Tests (baking-bad#90)
- Loading branch information
1 parent
a30dff8
commit 2c2e8c2
Showing
25 changed files
with
1,428 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
Oops, something went wrong.