mirror of
https://github.com/logos-storage/logos-storage-nim-cs-dist-tests.git
synced 2026-01-10 09:23:11 +00:00
Fixes proof-period message in chain-events. Fixes asserts in marketplace tests.
This commit is contained in:
parent
25a7a30793
commit
c421fabb7b
@ -36,6 +36,41 @@
|
||||
|
||||
return string.Join(" + ", tokens);
|
||||
}
|
||||
|
||||
public static Ether operator +(Ether a, Ether b)
|
||||
{
|
||||
return new Ether(a.Wei + b.Wei);
|
||||
}
|
||||
|
||||
public static Ether operator -(Ether a, Ether b)
|
||||
{
|
||||
return new Ether(a.Wei - b.Wei);
|
||||
}
|
||||
|
||||
public static Ether operator *(Ether a, int b)
|
||||
{
|
||||
return new Ether(a.Wei * b);
|
||||
}
|
||||
|
||||
public static bool operator <(Ether a, Ether b)
|
||||
{
|
||||
return a.Wei < b.Wei;
|
||||
}
|
||||
|
||||
public static bool operator >(Ether a, Ether b)
|
||||
{
|
||||
return a.Wei > b.Wei;
|
||||
}
|
||||
|
||||
public static bool operator ==(Ether a, Ether b)
|
||||
{
|
||||
return a.Wei == b.Wei;
|
||||
}
|
||||
|
||||
public static bool operator !=(Ether a, Ether b)
|
||||
{
|
||||
return a.Wei != b.Wei;
|
||||
}
|
||||
}
|
||||
|
||||
public static class TokensIntExtensions
|
||||
|
||||
@ -86,24 +86,11 @@ namespace CodexContractsPlugin.ChainMonitor
|
||||
|
||||
private void CalcStats()
|
||||
{
|
||||
IsEmpty = true;
|
||||
PeriodLow = ulong.MaxValue;
|
||||
PeriodHigh = ulong.MinValue;
|
||||
AverageNumSlots = 0.0f;
|
||||
AverageNumProofsRequired = 0.0f;
|
||||
float count = Reports.Length;
|
||||
|
||||
foreach (var report in Reports)
|
||||
{
|
||||
if (report.TotalProofsRequired > 0) IsEmpty = false;
|
||||
PeriodLow = Math.Min(PeriodLow, report.PeriodNumber);
|
||||
PeriodHigh = Math.Min(PeriodHigh, report.PeriodNumber);
|
||||
AverageNumSlots += Convert.ToSingle(report.TotalNumSlots);
|
||||
AverageNumProofsRequired += Convert.ToSingle(report.TotalProofsRequired);
|
||||
}
|
||||
|
||||
AverageNumSlots = AverageNumSlots / count;
|
||||
AverageNumProofsRequired = AverageNumProofsRequired / count;
|
||||
IsEmpty = Reports.Any(r => r.TotalProofsRequired > 0);
|
||||
PeriodLow = Reports.Min(r => r.PeriodNumber);
|
||||
PeriodHigh = Reports.Max(r => r.PeriodNumber);
|
||||
AverageNumSlots = Reports.Average(r => Convert.ToSingle(r.TotalNumSlots));
|
||||
AverageNumProofsRequired = Reports.Average(r => Convert.ToSingle(r.TotalProofsRequired));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -105,17 +105,6 @@ namespace CodexContractsPlugin
|
||||
return new CodexContractsEvents(log, gethNode, Deployment, blockInterval);
|
||||
}
|
||||
|
||||
public byte[] GetSlotId(Request request, decimal slotIndex)
|
||||
{
|
||||
var encoder = new ABIEncode();
|
||||
var encoded = encoder.GetABIEncoded(
|
||||
new ABIValue("bytes32", request.RequestId),
|
||||
new ABIValue("uint256", slotIndex.ToBig())
|
||||
);
|
||||
|
||||
return Sha3Keccack.Current.CalculateHash(encoded);
|
||||
}
|
||||
|
||||
public EthAddress? GetSlotHost(Request storageRequest, decimal slotIndex)
|
||||
{
|
||||
var slotId = GetSlotId(storageRequest, slotIndex);
|
||||
@ -166,6 +155,17 @@ namespace CodexContractsPlugin
|
||||
return new ProofState(required, missing);
|
||||
}
|
||||
|
||||
private byte[] GetSlotId(Request request, decimal slotIndex)
|
||||
{
|
||||
var encoder = new ABIEncode();
|
||||
var encoded = encoder.GetABIEncoded(
|
||||
new ABIValue("bytes32", request.RequestId),
|
||||
new ABIValue("uint256", slotIndex.ToBig())
|
||||
);
|
||||
|
||||
return Sha3Keccack.Current.CalculateHash(encoded);
|
||||
}
|
||||
|
||||
private bool IsProofRequired(byte[] slotId, ulong blockNumber)
|
||||
{
|
||||
var func = new IsProofRequiredFunction
|
||||
|
||||
@ -78,6 +78,11 @@ namespace CodexReleaseTests.MarketTests
|
||||
return hosts;
|
||||
}
|
||||
|
||||
public void AssertTstBalance(ICodexNode node, TestToken expectedBalance, string message)
|
||||
{
|
||||
AssertTstBalance(node.EthAddress, expectedBalance, message);
|
||||
}
|
||||
|
||||
public void AssertTstBalance(EthAddress address, TestToken expectedBalance, string message)
|
||||
{
|
||||
var retry = GetBalanceAssertRetry();
|
||||
@ -85,18 +90,11 @@ namespace CodexReleaseTests.MarketTests
|
||||
{
|
||||
var balance = GetTstBalance(address);
|
||||
|
||||
Assert.That(balance, Is.EqualTo(expectedBalance), message);
|
||||
});
|
||||
}
|
||||
|
||||
public void AssertTstBalance(ICodexNode node, TestToken expectedBalance, string message)
|
||||
{
|
||||
var retry = GetBalanceAssertRetry();
|
||||
retry.Run(() =>
|
||||
{
|
||||
var balance = GetTstBalance(node);
|
||||
|
||||
Assert.That(balance, Is.EqualTo(expectedBalance), message);
|
||||
if (balance != expectedBalance)
|
||||
{
|
||||
throw new Exception(nameof(AssertTstBalance) +
|
||||
$" expected: {expectedBalance} but was: {balance} - message: " + message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -107,14 +105,18 @@ namespace CodexReleaseTests.MarketTests
|
||||
{
|
||||
var balance = GetEthBalance(node);
|
||||
|
||||
Assert.That(balance, Is.EqualTo(expectedBalance), message);
|
||||
if (balance != expectedBalance)
|
||||
{
|
||||
throw new Exception(nameof(AssertEthBalance) +
|
||||
$" expected: {expectedBalance} but was: {balance} - message: " + message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private Retry GetBalanceAssertRetry()
|
||||
{
|
||||
return new Retry("AssertBalance",
|
||||
maxTimeout: TimeSpan.FromMinutes(30.0),
|
||||
maxTimeout: TimeSpan.FromMinutes(10.0),
|
||||
sleepAfterFail: TimeSpan.FromSeconds(10.0),
|
||||
onFail: f => { });
|
||||
}
|
||||
@ -217,7 +219,10 @@ namespace CodexReleaseTests.MarketTests
|
||||
var retry = GetBalanceAssertRetry();
|
||||
retry.Run(() =>
|
||||
{
|
||||
Assert.That(GetTstBalance(host), Is.GreaterThanOrEqualTo(StartingBalanceTST.Tst()));
|
||||
if (GetTstBalance(host) < StartingBalanceTST.Tst())
|
||||
{
|
||||
throw new Exception(nameof(AssertHostsCollateralsAreUnchanged));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,46 @@
|
||||
using NUnit.Framework;
|
||||
using Utils;
|
||||
|
||||
namespace FrameworkTests.CodexContractsPlugin
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestTokenEqualityTests
|
||||
{
|
||||
[Test]
|
||||
[Combinatorial]
|
||||
public void Equal(
|
||||
[Values(1, 22, 333, 4444, 55555)] int amount,
|
||||
[Values(true, false)] bool isWei
|
||||
)
|
||||
{
|
||||
var amount1 = CreateTst(amount, isWei);
|
||||
var amount2 = CreateTst(amount, isWei);
|
||||
|
||||
Assert.That(amount1, Is.EqualTo(amount2));
|
||||
Assert.That(amount1 == amount2);
|
||||
Assert.That(!(amount1 != amount2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Combinatorial]
|
||||
public void NotEqual(
|
||||
[Values(22, 333, 4444, 55555)] int amount,
|
||||
[Values(true, false)] bool isWei,
|
||||
[Values(1, 2, 10, -1, -2, -10)] int deltaWei
|
||||
)
|
||||
{
|
||||
var amount1 = CreateTst(amount, isWei);
|
||||
var amount2 = CreateTst(amount, isWei) + deltaWei.TstWei();
|
||||
|
||||
Assert.That(amount1, Is.Not.EqualTo(amount2));
|
||||
Assert.That(amount1 != amount2);
|
||||
Assert.That(!(amount1 == amount2));
|
||||
}
|
||||
|
||||
private TestToken CreateTst(int amount, bool isWei)
|
||||
{
|
||||
if (isWei) return amount.TstWei();
|
||||
return amount.Tst();
|
||||
}
|
||||
}
|
||||
}
|
||||
46
Tests/FrameworkTests/Utils/EtherEqualityTests.cs
Normal file
46
Tests/FrameworkTests/Utils/EtherEqualityTests.cs
Normal file
@ -0,0 +1,46 @@
|
||||
using NUnit.Framework;
|
||||
using Utils;
|
||||
|
||||
namespace FrameworkTests.Utils
|
||||
{
|
||||
[TestFixture]
|
||||
public class EtherEqualityTests
|
||||
{
|
||||
[Test]
|
||||
[Combinatorial]
|
||||
public void Equal(
|
||||
[Values(1, 22, 333, 4444, 55555)] int amount,
|
||||
[Values(true, false)] bool isWei
|
||||
)
|
||||
{
|
||||
var amount1 = CreateEth(amount, isWei);
|
||||
var amount2 = CreateEth(amount, isWei);
|
||||
|
||||
Assert.That(amount1, Is.EqualTo(amount2));
|
||||
Assert.That(amount1 == amount2);
|
||||
Assert.That(!(amount1 != amount2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Combinatorial]
|
||||
public void NotEqual(
|
||||
[Values(22, 333, 4444, 55555)] int amount,
|
||||
[Values(true, false)] bool isWei,
|
||||
[Values(1, 2, 10, -1, -2, -10)] int deltaWei
|
||||
)
|
||||
{
|
||||
var amount1 = CreateEth(amount, isWei);
|
||||
var amount2 = CreateEth(amount, isWei) + deltaWei.Wei();
|
||||
|
||||
Assert.That(amount1, Is.Not.EqualTo(amount2));
|
||||
Assert.That(amount1 != amount2);
|
||||
Assert.That(!(amount1 == amount2));
|
||||
}
|
||||
|
||||
private Ether CreateEth(int amount, bool isWei)
|
||||
{
|
||||
if (isWei) return amount.Wei();
|
||||
return amount.Eth();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -85,7 +85,7 @@
|
||||
public string Failed => "❌";
|
||||
public string ProofSubmitted => "🎵";
|
||||
public string ProofReport => "🔎";
|
||||
public string NoProofsMissed => "🏛";
|
||||
public string NoProofsMissed => "🎉";
|
||||
public string ManyProofsMissed => "😱";
|
||||
|
||||
public string StringToEmojis(string input, int outLength)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user