@@ -282,7 +282,69 @@ contract('MultiPartyEscrow', function(accounts) {
282
282
283
283
// Test for a replay attack
284
284
await testErrorRevert ( escrow . openChannelByThirdParty ( accounts [ 4 ] , accounts [ 4 ] , accounts [ 3 ] , groupId , channelDepositAmount , expiration , messageNonce , vrs . v , vrs . r , vrs . s , { from :accounts [ 7 ] } ) ) ;
285
- } ) ;
285
+ } ) ;
286
+
287
+ it ( "Open the seventh channel for Claim signed by sender" , async function ( )
288
+ {
289
+ //sign message by the privet key of accounts[0]
290
+
291
+ let channelDepositAmount = 100
292
+ let plannedAmount = 90
293
+ let actualAmount = 80
294
+
295
+ let expiration = web3 . eth . blockNumber + 10000000
296
+ let groupId = "group42"
297
+ let currentChannelId = ( await escrow . nextChannelId . call ( ) ) . toNumber ( )
298
+ let accountBal_4 = ( await escrow . balances . call ( accounts [ 4 ] ) ) . toNumber ( )
299
+ let accountBal_7 = ( await escrow . balances . call ( accounts [ 7 ] ) ) . toNumber ( )
300
+
301
+ // Signer is Different than the sender
302
+ await escrow . openChannel ( accounts [ 5 ] , accounts [ 7 ] , groupId , channelDepositAmount , expiration , { from :accounts [ 4 ] } )
303
+ assert . equal ( ( await escrow . balances . call ( accounts [ 4 ] ) ) . toNumber ( ) , accountBal_4 - channelDepositAmount )
304
+
305
+ // Message signed by the sender/channel owner or creater
306
+ let sgn = await signFuns . waitSignedClaimMessage ( accounts [ 4 ] , escrow . address , currentChannelId , 0 , plannedAmount ) ;
307
+ let vrs = signFuns . getVRSFromSignature ( sgn . toString ( "hex" ) ) ;
308
+
309
+ // Testing for Actual Amount > Planned Amount
310
+ testErrorRevert ( escrow . channelClaim ( currentChannelId , actualAmount + plannedAmount , plannedAmount , vrs . v , vrs . r , vrs . s , true , { from :accounts [ 7 ] } ) ) ;
311
+ // Claiming the lower amount and sending remaining channel value back to user
312
+ await escrow . channelClaim ( currentChannelId , actualAmount , plannedAmount , vrs . v , vrs . r , vrs . s , true , { from :accounts [ 7 ] } ) ;
313
+ assert . equal ( ( await escrow . balances . call ( accounts [ 7 ] ) ) . toNumber ( ) , accountBal_7 + actualAmount )
314
+ assert . equal ( ( await escrow . balances . call ( accounts [ 4 ] ) ) . toNumber ( ) , accountBal_4 - actualAmount )
315
+
316
+ } ) ;
317
+
318
+ it ( "Open the eight channel for Claim signed by signer" , async function ( )
319
+ {
320
+ //sign message by the privet key of accounts[0]
321
+
322
+ let channelDepositAmount = 100
323
+ let plannedAmount = 90
324
+ let actualAmount = 80
325
+
326
+ let expiration = web3 . eth . blockNumber + 10000000
327
+ let groupId = "group42"
328
+ let currentChannelId = ( await escrow . nextChannelId . call ( ) ) . toNumber ( )
329
+ let accountBal_4 = ( await escrow . balances . call ( accounts [ 4 ] ) ) . toNumber ( )
330
+ let accountBal_7 = ( await escrow . balances . call ( accounts [ 7 ] ) ) . toNumber ( )
331
+
332
+ // Signer is Different than the sender
333
+ await escrow . openChannel ( accounts [ 5 ] , accounts [ 7 ] , groupId , channelDepositAmount , expiration , { from :accounts [ 4 ] } )
334
+ assert . equal ( ( await escrow . balances . call ( accounts [ 4 ] ) ) . toNumber ( ) , accountBal_4 - channelDepositAmount )
335
+
336
+ // Message signed by the Signer
337
+ let sgn = await signFuns . waitSignedClaimMessage ( accounts [ 5 ] , escrow . address , currentChannelId , 0 , plannedAmount ) ;
338
+ let vrs = signFuns . getVRSFromSignature ( sgn . toString ( "hex" ) ) ;
339
+
340
+ // Testing for Actual Amount > Planned Amount
341
+ testErrorRevert ( escrow . channelClaim ( currentChannelId , actualAmount + plannedAmount , plannedAmount , vrs . v , vrs . r , vrs . s , true , { from :accounts [ 7 ] } ) ) ;
342
+ // Claiming the lower amount and sending remaining channel value back to user
343
+ await escrow . channelClaim ( currentChannelId , actualAmount , plannedAmount , vrs . v , vrs . r , vrs . s , true , { from :accounts [ 7 ] } ) ;
344
+ assert . equal ( ( await escrow . balances . call ( accounts [ 7 ] ) ) . toNumber ( ) , accountBal_7 + actualAmount )
345
+ assert . equal ( ( await escrow . balances . call ( accounts [ 4 ] ) ) . toNumber ( ) , accountBal_4 - actualAmount )
346
+
347
+ } ) ;
286
348
287
349
it ( "Check validity of the signatures with js-server part (claim)" , async function ( )
288
350
{
0 commit comments