@@ -138,32 +138,43 @@ public SlotFill[] GetOnChainSlotFills(ICodexNodeGroup possibleHosts)
138
138
} ) . ToArray ( ) ;
139
139
}
140
140
141
- protected void AssertClientHasPaidForContract ( TestToken pricePerSlotPerSecond , ICodexNode client , IStoragePurchaseContract contract , ICodexNodeGroup hosts )
141
+ protected void AssertClientHasPaidForContract ( TestToken pricePerBytePerSecond , ICodexNode client , IStoragePurchaseContract contract , ICodexNodeGroup hosts )
142
142
{
143
143
var balance = GetTstBalance ( client ) ;
144
- var expectedBalance = StartingBalanceTST . Tst ( ) - GetContractFinalCost ( pricePerSlotPerSecond , contract , hosts ) ;
144
+ var expectedBalance = StartingBalanceTST . Tst ( ) - GetContractFinalCost ( pricePerBytePerSecond , contract , hosts ) ;
145
145
146
146
Assert . That ( balance , Is . EqualTo ( expectedBalance ) , "Client balance incorrect." ) ;
147
147
}
148
148
149
- protected void AssertHostsWerePaidForContract ( TestToken pricePerSlotPerSecond , IStoragePurchaseContract contract , ICodexNodeGroup hosts )
149
+ protected void AssertHostsWerePaidForContract ( TestToken pricePerBytePerSecond , IStoragePurchaseContract contract , ICodexNodeGroup hosts )
150
150
{
151
151
var fills = GetOnChainSlotFills ( hosts ) ;
152
152
var submitUtc = GetContractOnChainSubmittedUtc ( contract ) ;
153
153
var finishUtc = submitUtc + contract . Purchase . Duration ;
154
+ var slotSize = Convert . ToInt64 ( contract . GetStatus ( ) . Request . Ask . SlotSize ) . Bytes ( ) ;
154
155
var expectedBalances = new Dictionary < EthAddress , TestToken > ( ) ;
156
+
155
157
foreach ( var host in hosts ) expectedBalances . Add ( host . EthAddress , StartingBalanceTST . Tst ( ) ) ;
156
158
foreach ( var fill in fills )
157
159
{
158
160
var slotDuration = finishUtc - fill . SlotFilledEvent . Block . Utc ;
159
- expectedBalances [ fill . Host . EthAddress ] += GetContractCostPerSlot ( pricePerSlotPerSecond , slotDuration ) ;
161
+ expectedBalances [ fill . Host . EthAddress ] += GetContractCostPerSlot ( pricePerBytePerSecond , slotSize , slotDuration ) ;
160
162
}
161
163
162
- foreach ( var pair in expectedBalances )
164
+ var retry = new Retry ( nameof ( AssertHostsWerePaidForContract ) ,
165
+ maxTimeout : TimeSpan . FromMinutes ( 30 ) ,
166
+ sleepAfterFail : TimeSpan . FromSeconds ( 10 ) ,
167
+ onFail : f => { }
168
+ ) ;
169
+
170
+ retry . Run ( ( ) =>
163
171
{
164
- var balance = GetTstBalance ( pair . Key ) ;
165
- Assert . That ( balance , Is . EqualTo ( pair . Value ) , "Host was not paid for storage." ) ;
166
- }
172
+ foreach ( var pair in expectedBalances )
173
+ {
174
+ var balance = GetTstBalance ( pair . Key ) ;
175
+ Assert . That ( balance , Is . EqualTo ( pair . Value ) , "Host was not paid for storage." ) ;
176
+ }
177
+ } ) ;
167
178
}
168
179
169
180
protected void AssertHostsCollateralsAreUnchanged ( ICodexNodeGroup hosts )
@@ -176,17 +187,18 @@ protected void AssertHostsCollateralsAreUnchanged(ICodexNodeGroup hosts)
176
187
}
177
188
}
178
189
179
- private TestToken GetContractFinalCost ( TestToken pricePerSlotPerSecond , IStoragePurchaseContract contract , ICodexNodeGroup hosts )
190
+ private TestToken GetContractFinalCost ( TestToken pricePerBytePerSecond , IStoragePurchaseContract contract , ICodexNodeGroup hosts )
180
191
{
181
192
var fills = GetOnChainSlotFills ( hosts ) ;
182
193
var result = 0 . Tst ( ) ;
183
194
var submitUtc = GetContractOnChainSubmittedUtc ( contract ) ;
184
195
var finishUtc = submitUtc + contract . Purchase . Duration ;
196
+ var slotSize = Convert . ToInt64 ( contract . GetStatus ( ) . Request . Ask . SlotSize ) . Bytes ( ) ;
185
197
186
198
foreach ( var fill in fills )
187
199
{
188
200
var slotDuration = finishUtc - fill . SlotFilledEvent . Block . Utc ;
189
- result += GetContractCostPerSlot ( pricePerSlotPerSecond , slotDuration ) ;
201
+ result += GetContractCostPerSlot ( pricePerBytePerSecond , slotSize , slotDuration ) ;
190
202
}
191
203
192
204
return result ;
@@ -207,9 +219,10 @@ private DateTime GetContractOnChainSubmittedUtc(IStoragePurchaseContract contrac
207
219
} , nameof ( GetContractOnChainSubmittedUtc ) ) ;
208
220
}
209
221
210
- private TestToken GetContractCostPerSlot ( TestToken pricePerSlotPerSecond , TimeSpan slotDuration )
222
+ private TestToken GetContractCostPerSlot ( TestToken pricePerBytePerSecond , ByteSize slotSize , TimeSpan slotDuration )
211
223
{
212
- return pricePerSlotPerSecond * ( int ) slotDuration . TotalSeconds ;
224
+ var cost = pricePerBytePerSecond . TstWei * slotSize . SizeInBytes * ( int ) slotDuration . TotalSeconds ;
225
+ return cost . TstWei ( ) ;
213
226
}
214
227
215
228
protected void AssertContractSlotsAreFilledByHosts ( IStoragePurchaseContract contract , ICodexNodeGroup hosts )
0 commit comments