@@ -273,7 +273,7 @@ describe("Marketplace", function () {
273273 } )
274274 } )
275275
276- describe ( "filling a slot with collateral " , function ( ) {
276+ describe ( "filling a slot" , function ( ) {
277277 beforeEach ( async function ( ) {
278278 switchAccount ( client )
279279 await token . approve ( marketplace . address , maxPrice ( request ) )
@@ -296,6 +296,15 @@ describe("Marketplace", function () {
296296 expect ( await marketplace . getHost ( slotId ( slot ) ) ) . to . equal ( host . address )
297297 } )
298298
299+ it ( "collects only requested collateral and not more" , async function ( ) {
300+ await token . approve ( marketplace . address , collateralPerSlot ( request ) * 2 )
301+ const startBalance = await token . balanceOf ( host . address )
302+ await marketplace . reserveSlot ( slot . request , slot . index )
303+ await marketplace . fillSlot ( slot . request , slot . index , proof )
304+ const endBalance = await token . balanceOf ( host . address )
305+ expect ( startBalance - endBalance ) . to . eq ( collateralPerSlot ( request ) )
306+ } )
307+
299308 describe ( "when repairing a slot" , function ( ) {
300309 beforeEach ( async function ( ) {
301310 await marketplace . reserveSlot ( slot . request , slot . index )
@@ -411,33 +420,15 @@ describe("Marketplace", function () {
411420 marketplace . fillSlot ( slot . request , slot . index , proof )
412421 ) . to . be . revertedWith ( "Marketplace_ReservationRequired" )
413422 } )
414- } )
415-
416- describe ( "filling slot without collateral" , function ( ) {
417- beforeEach ( async function ( ) {
418- switchAccount ( client )
419- await token . approve ( marketplace . address , maxPrice ( request ) )
420- await marketplace . requestStorage ( request )
421- switchAccount ( host )
422- } )
423423
424- it ( "is rejected when approved collateral is insufficient" , async function ( ) {
424+ it ( "fails when approved collateral is insufficient" , async function ( ) {
425425 let insufficient = collateralPerSlot ( request ) - 1
426426 await token . approve ( marketplace . address , insufficient )
427427 await marketplace . reserveSlot ( slot . request , slot . index )
428428 await expect (
429429 marketplace . fillSlot ( slot . request , slot . index , proof )
430430 ) . to . be . revertedWith ( "ERC20InsufficientAllowance" )
431431 } )
432-
433- it ( "collects only requested collateral and not more" , async function ( ) {
434- await token . approve ( marketplace . address , collateralPerSlot ( request ) * 2 )
435- const startBalance = await token . balanceOf ( host . address )
436- await marketplace . reserveSlot ( slot . request , slot . index )
437- await marketplace . fillSlot ( slot . request , slot . index , proof )
438- const endBalance = await token . balanceOf ( host . address )
439- expect ( startBalance - endBalance ) . to . eq ( collateralPerSlot ( request ) )
440- } )
441432 } )
442433
443434 describe ( "submitting proofs when slot is filled" , function ( ) {
@@ -1177,50 +1168,43 @@ describe("Marketplace", function () {
11771168 } )
11781169
11791170 describe ( "slashing when missing proofs" , function ( ) {
1180- it ( "reduces collateral when a proof is missing" , async function ( ) {
1181- const id = slotId ( slot )
1182- const { slashPercentage } = config . collateral
1171+ const { slashPercentage, validatorRewardPercentage } = config . collateral
1172+ let id
1173+ let missedPeriod
1174+ let collateral
1175+ let slashAmount
1176+
1177+ beforeEach ( async function ( ) {
1178+ collateral = collateralPerSlot ( request )
1179+ slashAmount = Math . round ( ( collateral * slashPercentage ) / 100 )
1180+ id = slotId ( slot )
11831181 await marketplace . reserveSlot ( slot . request , slot . index )
11841182 await marketplace . fillSlot ( slot . request , slot . index , proof )
1185-
11861183 await waitUntilProofIsRequired ( id )
1187- let missedPeriod = periodOf ( await currentTime ( ) )
1184+ missedPeriod = periodOf ( await currentTime ( ) )
11881185 await advanceTime ( period + 1 )
1186+ } )
11891187
1188+ it ( "reduces balance when a proof is missing" , async function ( ) {
11901189 const startBalance = await marketplace . getSlotBalance ( id )
11911190 await setNextBlockTimestamp ( await currentTime ( ) )
11921191 await marketplace . markProofAsMissing ( id , missedPeriod )
11931192 const endBalance = await marketplace . getSlotBalance ( id )
1193+ expect ( endBalance ) . to . equal ( startBalance - slashAmount )
11941194
1195- const collateral = collateralPerSlot ( request )
1196- const expectedSlash = Math . round ( ( collateral * slashPercentage ) / 100 )
1197-
1198- expect ( endBalance ) . to . equal ( startBalance - expectedSlash )
11991195 } )
12001196
12011197 it ( "rewards validator when marking proof as missing" , async function ( ) {
1202- const id = slotId ( slot )
1203- const { slashPercentage, validatorRewardPercentage } = config . collateral
1204- await marketplace . reserveSlot ( slot . request , slot . index )
1205- await marketplace . fillSlot ( slot . request , slot . index , proof )
1206-
12071198 switchAccount ( validator )
1208-
1209- await waitUntilProofIsRequired ( id )
1210- let missedPeriod = periodOf ( await currentTime ( ) )
1211- await advanceTime ( period + 1 )
12121199 await marketplace . markProofAsMissing ( id , missedPeriod )
12131200
12141201 const startBalance = await token . balanceOf ( validator . address )
12151202 await waitUntilFinished ( marketplace , slot . request )
12161203 await marketplace . withdrawByValidator ( slot . request )
12171204 const endBalance = await token . balanceOf ( validator . address )
12181205
1219- const collateral = collateralPerSlot ( request )
1220- const slashedAmount = ( collateral * slashPercentage ) / 100
1221-
12221206 const expectedReward = Math . round (
1223- ( slashedAmount * validatorRewardPercentage ) / 100
1207+ ( slashAmount * validatorRewardPercentage ) / 100
12241208 )
12251209
12261210 expect ( endBalance . toNumber ( ) ) . to . equal (
0 commit comments