Skip to content

Commit c421fab

Browse files
committed
Fixes proof-period message in chain-events. Fixes asserts in marketplace tests.
1 parent 25a7a30 commit c421fab

File tree

7 files changed

+163
-44
lines changed

7 files changed

+163
-44
lines changed

Framework/Utils/EthTokenExtensions.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,41 @@ public override string ToString()
3636

3737
return string.Join(" + ", tokens);
3838
}
39+
40+
public static Ether operator +(Ether a, Ether b)
41+
{
42+
return new Ether(a.Wei + b.Wei);
43+
}
44+
45+
public static Ether operator -(Ether a, Ether b)
46+
{
47+
return new Ether(a.Wei - b.Wei);
48+
}
49+
50+
public static Ether operator *(Ether a, int b)
51+
{
52+
return new Ether(a.Wei * b);
53+
}
54+
55+
public static bool operator <(Ether a, Ether b)
56+
{
57+
return a.Wei < b.Wei;
58+
}
59+
60+
public static bool operator >(Ether a, Ether b)
61+
{
62+
return a.Wei > b.Wei;
63+
}
64+
65+
public static bool operator ==(Ether a, Ether b)
66+
{
67+
return a.Wei == b.Wei;
68+
}
69+
70+
public static bool operator !=(Ether a, Ether b)
71+
{
72+
return a.Wei != b.Wei;
73+
}
3974
}
4075

4176
public static class TokensIntExtensions

ProjectPlugins/CodexContractsPlugin/ChainMonitor/PeriodMonitor.cs

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -86,24 +86,11 @@ public PeriodMonitorResult(PeriodReport[] reports)
8686

8787
private void CalcStats()
8888
{
89-
IsEmpty = true;
90-
PeriodLow = ulong.MaxValue;
91-
PeriodHigh = ulong.MinValue;
92-
AverageNumSlots = 0.0f;
93-
AverageNumProofsRequired = 0.0f;
94-
float count = Reports.Length;
95-
96-
foreach (var report in Reports)
97-
{
98-
if (report.TotalProofsRequired > 0) IsEmpty = false;
99-
PeriodLow = Math.Min(PeriodLow, report.PeriodNumber);
100-
PeriodHigh = Math.Min(PeriodHigh, report.PeriodNumber);
101-
AverageNumSlots += Convert.ToSingle(report.TotalNumSlots);
102-
AverageNumProofsRequired += Convert.ToSingle(report.TotalProofsRequired);
103-
}
104-
105-
AverageNumSlots = AverageNumSlots / count;
106-
AverageNumProofsRequired = AverageNumProofsRequired / count;
89+
IsEmpty = Reports.Any(r => r.TotalProofsRequired > 0);
90+
PeriodLow = Reports.Min(r => r.PeriodNumber);
91+
PeriodHigh = Reports.Max(r => r.PeriodNumber);
92+
AverageNumSlots = Reports.Average(r => Convert.ToSingle(r.TotalNumSlots));
93+
AverageNumProofsRequired = Reports.Average(r => Convert.ToSingle(r.TotalProofsRequired));
10794
}
10895
}
10996

ProjectPlugins/CodexContractsPlugin/CodexContractsAccess.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,6 @@ public ICodexContractsEvents GetEvents(BlockInterval blockInterval)
105105
return new CodexContractsEvents(log, gethNode, Deployment, blockInterval);
106106
}
107107

108-
public byte[] GetSlotId(Request request, decimal slotIndex)
109-
{
110-
var encoder = new ABIEncode();
111-
var encoded = encoder.GetABIEncoded(
112-
new ABIValue("bytes32", request.RequestId),
113-
new ABIValue("uint256", slotIndex.ToBig())
114-
);
115-
116-
return Sha3Keccack.Current.CalculateHash(encoded);
117-
}
118-
119108
public EthAddress? GetSlotHost(Request storageRequest, decimal slotIndex)
120109
{
121110
var slotId = GetSlotId(storageRequest, slotIndex);
@@ -166,6 +155,17 @@ public ProofState GetProofState(Request storageRequest, decimal slotIndex, ulong
166155
return new ProofState(required, missing);
167156
}
168157

158+
private byte[] GetSlotId(Request request, decimal slotIndex)
159+
{
160+
var encoder = new ABIEncode();
161+
var encoded = encoder.GetABIEncoded(
162+
new ABIValue("bytes32", request.RequestId),
163+
new ABIValue("uint256", slotIndex.ToBig())
164+
);
165+
166+
return Sha3Keccack.Current.CalculateHash(encoded);
167+
}
168+
169169
private bool IsProofRequired(byte[] slotId, ulong blockNumber)
170170
{
171171
var func = new IsProofRequiredFunction

Tests/CodexReleaseTests/MarketTests/MarketplaceAutoBootstrapDistTest.cs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,25 +78,23 @@ public ICodexNodeGroup StartHosts()
7878
return hosts;
7979
}
8080

81-
public void AssertTstBalance(EthAddress address, TestToken expectedBalance, string message)
81+
public void AssertTstBalance(ICodexNode node, TestToken expectedBalance, string message)
8282
{
83-
var retry = GetBalanceAssertRetry();
84-
retry.Run(() =>
85-
{
86-
var balance = GetTstBalance(address);
87-
88-
Assert.That(balance, Is.EqualTo(expectedBalance), message);
89-
});
83+
AssertTstBalance(node.EthAddress, expectedBalance, message);
9084
}
9185

92-
public void AssertTstBalance(ICodexNode node, TestToken expectedBalance, string message)
86+
public void AssertTstBalance(EthAddress address, TestToken expectedBalance, string message)
9387
{
9488
var retry = GetBalanceAssertRetry();
9589
retry.Run(() =>
9690
{
97-
var balance = GetTstBalance(node);
91+
var balance = GetTstBalance(address);
9892

99-
Assert.That(balance, Is.EqualTo(expectedBalance), message);
93+
if (balance != expectedBalance)
94+
{
95+
throw new Exception(nameof(AssertTstBalance) +
96+
$" expected: {expectedBalance} but was: {balance} - message: " + message);
97+
}
10098
});
10199
}
102100

@@ -107,14 +105,18 @@ public void AssertEthBalance(ICodexNode node, Ether expectedBalance, string mess
107105
{
108106
var balance = GetEthBalance(node);
109107

110-
Assert.That(balance, Is.EqualTo(expectedBalance), message);
108+
if (balance != expectedBalance)
109+
{
110+
throw new Exception(nameof(AssertEthBalance) +
111+
$" expected: {expectedBalance} but was: {balance} - message: " + message);
112+
}
111113
});
112114
}
113115

114116
private Retry GetBalanceAssertRetry()
115117
{
116118
return new Retry("AssertBalance",
117-
maxTimeout: TimeSpan.FromMinutes(30.0),
119+
maxTimeout: TimeSpan.FromMinutes(10.0),
118120
sleepAfterFail: TimeSpan.FromSeconds(10.0),
119121
onFail: f => { });
120122
}
@@ -217,7 +219,10 @@ protected void AssertHostsCollateralsAreUnchanged(ICodexNodeGroup hosts)
217219
var retry = GetBalanceAssertRetry();
218220
retry.Run(() =>
219221
{
220-
Assert.That(GetTstBalance(host), Is.GreaterThanOrEqualTo(StartingBalanceTST.Tst()));
222+
if (GetTstBalance(host) < StartingBalanceTST.Tst())
223+
{
224+
throw new Exception(nameof(AssertHostsCollateralsAreUnchanged));
225+
}
221226
});
222227
}
223228
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using NUnit.Framework;
2+
using Utils;
3+
4+
namespace FrameworkTests.CodexContractsPlugin
5+
{
6+
[TestFixture]
7+
public class TestTokenEqualityTests
8+
{
9+
[Test]
10+
[Combinatorial]
11+
public void Equal(
12+
[Values(1, 22, 333, 4444, 55555)] int amount,
13+
[Values(true, false)] bool isWei
14+
)
15+
{
16+
var amount1 = CreateTst(amount, isWei);
17+
var amount2 = CreateTst(amount, isWei);
18+
19+
Assert.That(amount1, Is.EqualTo(amount2));
20+
Assert.That(amount1 == amount2);
21+
Assert.That(!(amount1 != amount2));
22+
}
23+
24+
[Test]
25+
[Combinatorial]
26+
public void NotEqual(
27+
[Values(22, 333, 4444, 55555)] int amount,
28+
[Values(true, false)] bool isWei,
29+
[Values(1, 2, 10, -1, -2, -10)] int deltaWei
30+
)
31+
{
32+
var amount1 = CreateTst(amount, isWei);
33+
var amount2 = CreateTst(amount, isWei) + deltaWei.TstWei();
34+
35+
Assert.That(amount1, Is.Not.EqualTo(amount2));
36+
Assert.That(amount1 != amount2);
37+
Assert.That(!(amount1 == amount2));
38+
}
39+
40+
private TestToken CreateTst(int amount, bool isWei)
41+
{
42+
if (isWei) return amount.TstWei();
43+
return amount.Tst();
44+
}
45+
}
46+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using NUnit.Framework;
2+
using Utils;
3+
4+
namespace FrameworkTests.Utils
5+
{
6+
[TestFixture]
7+
public class EtherEqualityTests
8+
{
9+
[Test]
10+
[Combinatorial]
11+
public void Equal(
12+
[Values(1, 22, 333, 4444, 55555)] int amount,
13+
[Values(true, false)] bool isWei
14+
)
15+
{
16+
var amount1 = CreateEth(amount, isWei);
17+
var amount2 = CreateEth(amount, isWei);
18+
19+
Assert.That(amount1, Is.EqualTo(amount2));
20+
Assert.That(amount1 == amount2);
21+
Assert.That(!(amount1 != amount2));
22+
}
23+
24+
[Test]
25+
[Combinatorial]
26+
public void NotEqual(
27+
[Values(22, 333, 4444, 55555)] int amount,
28+
[Values(true, false)] bool isWei,
29+
[Values(1, 2, 10, -1, -2, -10)] int deltaWei
30+
)
31+
{
32+
var amount1 = CreateEth(amount, isWei);
33+
var amount2 = CreateEth(amount, isWei) + deltaWei.Wei();
34+
35+
Assert.That(amount1, Is.Not.EqualTo(amount2));
36+
Assert.That(amount1 != amount2);
37+
Assert.That(!(amount1 == amount2));
38+
}
39+
40+
private Ether CreateEth(int amount, bool isWei)
41+
{
42+
if (isWei) return amount.Wei();
43+
return amount.Eth();
44+
}
45+
}
46+
}

Tools/TestNetRewarder/EmojiMaps.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public class EmojiMaps
8585
public string Failed => "❌";
8686
public string ProofSubmitted => "🎵";
8787
public string ProofReport => "🔎";
88-
public string NoProofsMissed => "🏛";
88+
public string NoProofsMissed => "🎉";
8989
public string ManyProofsMissed => "😱";
9090

9191
public string StringToEmojis(string input, int outLength)

0 commit comments

Comments
 (0)