wip: marketplace test is starting to work with annoying sleep and unused code in NethereumInteraction.cs

This commit is contained in:
benbierens 2023-04-24 16:07:32 +02:00
parent 9db35be2ec
commit 929fdb1157
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
6 changed files with 52 additions and 16 deletions

View File

@ -31,9 +31,9 @@ namespace DistTestCore.Codex
return Http().HttpPostJson<CodexSalesAvailabilityRequest, CodexSalesAvailabilityResponse>("sales/availability", request);
}
public CodexSalesRequestStorageResponse RequestStorage(CodexSalesRequestStorageRequest request, string contentId)
public string RequestStorage(CodexSalesRequestStorageRequest request, string contentId)
{
return Http().HttpPostJson<CodexSalesRequestStorageRequest, CodexSalesRequestStorageResponse>($"storage/request/{contentId}", request);
return Http().HttpPostJson($"storage/request/{contentId}", request);
}
private Http Http()
@ -91,9 +91,4 @@ namespace DistTestCore.Codex
public uint? nodes { get; set; }
public uint? tolerance { get; set;}
}
public class CodexSalesRequestStorageResponse
{
public string purchaseId { get; set; } = string.Empty;
}
}

View File

@ -41,7 +41,13 @@ namespace DistTestCore
public TResponse HttpPostJson<TRequest, TResponse>(string route, TRequest body)
{
var json = Retry(() =>
var json = HttpPostJson(route, body);
return TryJsonDeserialize<TResponse>(json);
}
public string HttpPostJson<TRequest>(string route, TRequest body)
{
return Retry(() =>
{
using var client = GetClient();
var url = GetUrl() + route;
@ -49,8 +55,6 @@ namespace DistTestCore
var result = Time.Wait(client.PostAsync(url, content));
return Time.Wait(result.Content.ReadAsStringAsync());
});
return TryJsonDeserialize<TResponse>(json);
}
public string HttpPostStream(string route, Stream stream)

View File

@ -41,8 +41,15 @@ namespace DistTestCore.Marketplace
private void EnsureCompanionNodeIsSynced(GethCompanionNodeInfo node, MarketplaceNetwork marketplace)
{
var interaction = node.StartInteraction(lifecycle.Log);
interaction.EnsureSynced(marketplace.Marketplace.Address, marketplace.Marketplace.Abi);
try
{
var interaction = node.StartInteraction(lifecycle.Log);
interaction.EnsureSynced(marketplace.Marketplace.Address, marketplace.Marketplace.Abi);
}
catch (Exception e)
{
throw new Exception("Geth companion node did not sync within timeout. Test infra failure.", e);
}
}
private StartupConfig CreateCompanionNodeStartupConfig(GethBootstrapNodeInfo bootstrapNode)

View File

@ -52,9 +52,14 @@ namespace DistTestCore.Marketplace
var response = codexAccess.RequestStorage(request, contentId.Id);
Log($"Storage requested successfully. PurchaseId: {response.purchaseId}");
if (response == "Purchasing not available")
{
throw new InvalidOperationException(response);
}
return response.purchaseId;
Log($"Storage requested successfully. PurchaseId: {response}");
return response;
}
public string MakeStorageAvailable(ByteSize size, TestToken minPricePerBytePerSecond, TestToken maxCollateral, TimeSpan maxDuration)

View File

@ -1,6 +1,6 @@
namespace DistTestCore
{
public class Ether
public class Ether : IComparable<Ether>
{
public Ether(decimal wei)
{
@ -9,6 +9,11 @@
public decimal Wei { get; }
public int CompareTo(Ether? other)
{
return Wei.CompareTo(other!.Wei);
}
public override bool Equals(object? obj)
{
return obj is Ether ether && Wei == ether.Wei;
@ -25,7 +30,7 @@
}
}
public class TestToken
public class TestToken : IComparable<TestToken>
{
public TestToken(decimal amount)
{
@ -34,6 +39,11 @@
public decimal Amount { get; }
public int CompareTo(TestToken? other)
{
return Amount.CompareTo(other!.Amount);
}
public override bool Equals(object? obj)
{
return obj is TestToken token && Amount == token.Amount;

View File

@ -85,6 +85,19 @@ namespace NethereumWorkflow
try
{
var contract = web3.Eth.GetContract(marketplaceAbi, marketplaceAddress);
if (contract != null)
{
var aaa = 0;
var func = contract.GetFunction("myRequests");
var input = func.CreateCallInput();
var result = Time.Wait(func.CallAsync(input));
var eeee = 0;
}
return contract != null;
}
catch
@ -92,6 +105,8 @@ namespace NethereumWorkflow
return false;
}
}, TimeSpan.FromMinutes(1), TimeSpan.FromSeconds(1));
Thread.Sleep(TimeSpan.FromMinutes(2));
}
private HexBigInteger ToHexBig(decimal amount)