@@ -65,9 +65,9 @@ public ICodexNodeGroup StartHosts()
65
65
var config = GetContracts ( ) . Deployment . Config ;
66
66
foreach ( var host in hosts )
67
67
{
68
- Assert . That ( GetTstBalance ( host ) . TstWei , Is . EqualTo ( StartingBalanceTST . Tst ( ) . TstWei ) ) ;
69
- Assert . That ( GetEthBalance ( host ) . Wei , Is . EqualTo ( StartingBalanceEth . Eth ( ) . Wei ) ) ;
70
-
68
+ AssertTstBalance ( host , StartingBalanceTST . Tst ( ) , nameof ( StartHosts ) ) ;
69
+ AssertEthBalance ( host , StartingBalanceEth . Eth ( ) , nameof ( StartHosts ) ) ;
70
+
71
71
host . Marketplace . MakeStorageAvailable ( new StorageAvailability (
72
72
totalSpace : HostAvailabilitySize ,
73
73
maxDuration : HostAvailabilityMaxDuration ,
@@ -78,22 +78,63 @@ public ICodexNodeGroup StartHosts()
78
78
return hosts ;
79
79
}
80
80
81
- public TestToken GetTstBalance ( ICodexNode node )
81
+ public void AssertTstBalance ( EthAddress address , TestToken expectedBalance , string message )
82
+ {
83
+ var retry = GetBalanceAssertRetry ( ) ;
84
+ retry . Run ( ( ) =>
85
+ {
86
+ var balance = GetTstBalance ( address ) ;
87
+
88
+ Assert . That ( balance , Is . EqualTo ( expectedBalance ) , message ) ;
89
+ } ) ;
90
+ }
91
+
92
+ public void AssertTstBalance ( ICodexNode node , TestToken expectedBalance , string message )
93
+ {
94
+ var retry = GetBalanceAssertRetry ( ) ;
95
+ retry . Run ( ( ) =>
96
+ {
97
+ var balance = GetTstBalance ( node ) ;
98
+
99
+ Assert . That ( balance , Is . EqualTo ( expectedBalance ) , message ) ;
100
+ } ) ;
101
+ }
102
+
103
+ public void AssertEthBalance ( ICodexNode node , Ether expectedBalance , string message )
104
+ {
105
+ var retry = GetBalanceAssertRetry ( ) ;
106
+ retry . Run ( ( ) =>
107
+ {
108
+ var balance = GetEthBalance ( node ) ;
109
+
110
+ Assert . That ( balance , Is . EqualTo ( expectedBalance ) , message ) ;
111
+ } ) ;
112
+ }
113
+
114
+ private Retry GetBalanceAssertRetry ( )
115
+ {
116
+ return new Retry ( "AssertBalance" ,
117
+ maxTimeout : TimeSpan . FromMinutes ( 30.0 ) ,
118
+ sleepAfterFail : TimeSpan . FromSeconds ( 10.0 ) ,
119
+ onFail : f => { } ) ;
120
+ }
121
+
122
+ private TestToken GetTstBalance ( ICodexNode node )
82
123
{
83
124
return GetContracts ( ) . GetTestTokenBalance ( node ) ;
84
125
}
85
126
86
- public TestToken GetTstBalance ( EthAddress address )
127
+ private TestToken GetTstBalance ( EthAddress address )
87
128
{
88
129
return GetContracts ( ) . GetTestTokenBalance ( address ) ;
89
130
}
90
131
91
- public Ether GetEthBalance ( ICodexNode node )
132
+ private Ether GetEthBalance ( ICodexNode node )
92
133
{
93
134
return GetGeth ( ) . GetEthBalance ( node ) ;
94
135
}
95
136
96
- public Ether GetEthBalance ( EthAddress address )
137
+ private Ether GetEthBalance ( EthAddress address )
97
138
{
98
139
return GetGeth ( ) . GetEthBalance ( address ) ;
99
140
}
@@ -141,10 +182,9 @@ public SlotFill[] GetOnChainSlotFills(ICodexNodeGroup possibleHosts)
141
182
142
183
protected void AssertClientHasPaidForContract ( TestToken pricePerBytePerSecond , ICodexNode client , IStoragePurchaseContract contract , ICodexNodeGroup hosts )
143
184
{
144
- var balance = GetTstBalance ( client ) ;
145
185
var expectedBalance = StartingBalanceTST . Tst ( ) - GetContractFinalCost ( pricePerBytePerSecond , contract , hosts ) ;
146
186
147
- Assert . That ( balance , Is . EqualTo ( expectedBalance ) , "Client balance incorrect." ) ;
187
+ AssertTstBalance ( client , expectedBalance , "Client balance incorrect." ) ;
148
188
}
149
189
150
190
protected void AssertHostsWerePaidForContract ( TestToken pricePerBytePerSecond , IStoragePurchaseContract contract , ICodexNodeGroup hosts )
@@ -162,20 +202,10 @@ protected void AssertHostsWerePaidForContract(TestToken pricePerBytePerSecond, I
162
202
expectedBalances [ fill . Host . EthAddress ] += GetContractCostPerSlot ( pricePerBytePerSecond , slotSize , slotDuration ) ;
163
203
}
164
204
165
- var retry = new Retry ( nameof ( AssertHostsWerePaidForContract ) ,
166
- maxTimeout : TimeSpan . FromMinutes ( 30 ) ,
167
- sleepAfterFail : TimeSpan . FromSeconds ( 10 ) ,
168
- onFail : f => { }
169
- ) ;
170
-
171
- retry . Run ( ( ) =>
205
+ foreach ( var pair in expectedBalances )
172
206
{
173
- foreach ( var pair in expectedBalances )
174
- {
175
- var balance = GetTstBalance ( pair . Key ) ;
176
- Assert . That ( balance , Is . EqualTo ( pair . Value ) , "Host was not paid for storage." ) ;
177
- }
178
- } ) ;
207
+ AssertTstBalance ( pair . Key , pair . Value , "Host was not paid for storage." ) ;
208
+ }
179
209
}
180
210
181
211
protected void AssertHostsCollateralsAreUnchanged ( ICodexNodeGroup hosts )
@@ -184,7 +214,11 @@ protected void AssertHostsCollateralsAreUnchanged(ICodexNodeGroup hosts)
184
214
// All host balances should be equal to or greater than the starting balance.
185
215
foreach ( var host in hosts )
186
216
{
187
- Assert . That ( GetTstBalance ( host ) , Is . GreaterThanOrEqualTo ( StartingBalanceTST . Tst ( ) ) ) ;
217
+ var retry = GetBalanceAssertRetry ( ) ;
218
+ retry . Run ( ( ) =>
219
+ {
220
+ Assert . That ( GetTstBalance ( host ) , Is . GreaterThanOrEqualTo ( StartingBalanceTST . Tst ( ) ) ) ;
221
+ } ) ;
188
222
}
189
223
}
190
224
0 commit comments