Sets up test for downloading content by contract CID
This commit is contained in:
parent
22527a5d93
commit
74ca512f92
|
@ -63,14 +63,47 @@ namespace CodexPlugin
|
|||
};
|
||||
}
|
||||
|
||||
public StoragePurchase Map(CodexOpenApi.Purchase purchase)
|
||||
{
|
||||
return new StoragePurchase
|
||||
{
|
||||
State = purchase.State,
|
||||
Error = purchase.Error
|
||||
};
|
||||
}
|
||||
// TODO: Fix openapi spec for this call.
|
||||
//public StoragePurchase Map(CodexOpenApi.Purchase purchase)
|
||||
//{
|
||||
// return new StoragePurchase(Map(purchase.Request))
|
||||
// {
|
||||
// State = purchase.State,
|
||||
// Error = purchase.Error
|
||||
// };
|
||||
//}
|
||||
|
||||
//public StorageRequest Map(CodexOpenApi.StorageRequest request)
|
||||
//{
|
||||
// return new StorageRequest(Map(request.Ask), Map(request.Content))
|
||||
// {
|
||||
// Id = request.Id,
|
||||
// Client = request.Client,
|
||||
// Expiry = TimeSpan.FromSeconds(Convert.ToInt64(request.Expiry)),
|
||||
// Nonce = request.Nonce
|
||||
// };
|
||||
//}
|
||||
|
||||
//public StorageAsk Map(CodexOpenApi.StorageAsk ask)
|
||||
//{
|
||||
// return new StorageAsk
|
||||
// {
|
||||
// Duration = TimeSpan.FromSeconds(Convert.ToInt64(ask.Duration)),
|
||||
// MaxSlotLoss = ask.MaxSlotLoss,
|
||||
// ProofProbability = ask.ProofProbability,
|
||||
// Reward = Convert.ToDecimal(ask.Reward).TstWei(),
|
||||
// Slots = ask.Slots,
|
||||
// SlotSize = new ByteSize(Convert.ToInt64(ask.SlotSize))
|
||||
// };
|
||||
//}
|
||||
|
||||
//public StorageContent Map(CodexOpenApi.Content content)
|
||||
//{
|
||||
// return new StorageContent
|
||||
// {
|
||||
// Cid = content.Cid
|
||||
// };
|
||||
//}
|
||||
|
||||
public StorageAvailability Map(CodexOpenApi.SalesAvailabilityREAD read)
|
||||
{
|
||||
|
|
|
@ -97,10 +97,13 @@ namespace CodexPlugin
|
|||
this.codexAccess = codexAccess;
|
||||
PurchaseId = purchaseId;
|
||||
Purchase = purchase;
|
||||
|
||||
ContentId = new ContentId(codexAccess.GetPurchaseStatus(purchaseId).Request.Content.Cid);
|
||||
}
|
||||
|
||||
public string PurchaseId { get; }
|
||||
public StoragePurchaseRequest Purchase { get; }
|
||||
public ContentId ContentId { get; }
|
||||
|
||||
public TimeSpan? PendingToSubmitted => contractSubmittedUtc - contractPendingUtc;
|
||||
public TimeSpan? SubmittedToStarted => contractStartedUtc - contractSubmittedUtc;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
using CodexContractsPlugin;
|
||||
using CodexOpenApi;
|
||||
using Logging;
|
||||
using System.Data;
|
||||
using Utils;
|
||||
|
||||
namespace CodexPlugin
|
||||
|
@ -37,6 +39,34 @@ namespace CodexPlugin
|
|||
{
|
||||
public string State { get; set; } = string.Empty;
|
||||
public string Error { get; set; } = string.Empty;
|
||||
public StorageRequest Request { get; set; } = null!;
|
||||
}
|
||||
|
||||
public class StorageRequest
|
||||
{
|
||||
public string Id { get; set; } = string.Empty;
|
||||
public string Client { get; set; } = string.Empty;
|
||||
public StorageAsk Ask { get; set; } = null!;
|
||||
public StorageContent Content { get; set; } = null!;
|
||||
public string Expiry { get; set; } = string.Empty;
|
||||
public string Nonce { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
public class StorageAsk
|
||||
{
|
||||
public int Slots { get; set; }
|
||||
public string SlotSize { get; set; } = string.Empty;
|
||||
public string Duration { get; set; } = string.Empty;
|
||||
public string ProofProbability { get; set; } = string.Empty;
|
||||
public string Reward { get; set; } = string.Empty;
|
||||
public int MaxSlotLoss { get; set; }
|
||||
}
|
||||
|
||||
public class StorageContent
|
||||
{
|
||||
public string Cid { get; set; } = string.Empty;
|
||||
//public ErasureParameters Erasure { get; set; }
|
||||
//public PoRParameters Por { get; set; }
|
||||
}
|
||||
|
||||
public class StorageAvailability
|
||||
|
|
|
@ -85,6 +85,47 @@ namespace CodexTests.BasicTests
|
|||
Assert.That(contracts.GetRequestState(request), Is.EqualTo(RequestState.Finished));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CanDownloadContentFromContractCid()
|
||||
{
|
||||
var fileSize = 10.MB();
|
||||
var geth = Ci.StartGethNode(s => s.IsMiner().WithName("disttest-geth"));
|
||||
var contracts = Ci.StartCodexContracts(geth);
|
||||
var testFile = GenerateTestFile(fileSize);
|
||||
|
||||
var client = StartCodex(s => s
|
||||
.WithName("Client")
|
||||
.EnableMarketplace(geth, contracts, m => m
|
||||
.WithInitial(10.Eth(), 10.Tst())));
|
||||
|
||||
var uploadCid = client.UploadFile(testFile);
|
||||
|
||||
var purchase = new StoragePurchaseRequest(uploadCid)
|
||||
{
|
||||
PricePerSlotPerSecond = 2.TstWei(),
|
||||
RequiredCollateral = 10.TstWei(),
|
||||
MinRequiredNumberOfNodes = 5,
|
||||
NodeFailureTolerance = 2,
|
||||
ProofProbability = 5,
|
||||
Duration = TimeSpan.FromMinutes(5),
|
||||
Expiry = TimeSpan.FromMinutes(4)
|
||||
};
|
||||
|
||||
var purchaseContract = client.Marketplace.RequestStorage(purchase);
|
||||
|
||||
var contractCid = purchaseContract.ContentId;
|
||||
|
||||
Assert.That(uploadCid.Id, Is.Not.EqualTo(contractCid.Id));
|
||||
|
||||
var downloader = StartCodex(s => s.WithName("Downloader"));
|
||||
|
||||
var uploadedFile = downloader.DownloadContent(uploadCid);
|
||||
testFile.AssertIsEqual(uploadedFile);
|
||||
|
||||
var contractFile = downloader.DownloadContent(contractCid);
|
||||
testFile.AssertIsEqual(contractFile);
|
||||
}
|
||||
|
||||
private void WaitForAllSlotFilledEvents(ICodexContracts contracts, StoragePurchaseRequest purchase, IGethNode geth)
|
||||
{
|
||||
Time.Retry(() =>
|
||||
|
|
Loading…
Reference in New Issue