Skip to content

Commit 5394518

Browse files
Claim Functionality enhancement
1 parent bcf4ce9 commit 5394518

File tree

3 files changed

+70
-3
lines changed

3 files changed

+70
-3
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,14 @@ Includes SingularityNET platform contracts, migrations, tests
4444
npm install
4545
```
4646

47+
### Compile
48+
```bash
49+
truffle compile
50+
```
51+
4752
### Test
4853
```bash
49-
npm run test
54+
truffle test
5055
```
5156

5257
## Package

contracts/MultiPartyEscrow.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ contract MultiPartyEscrow {
199199
bytes32 message = prefixed(keccak256(abi.encodePacked("__MPE_claim_message", this, channelId, channel.nonce, plannedAmount)));
200200
// check that the signature is from the signer
201201
address signAddress = ecrecover(message, v, r, s);
202-
require(signAddress == channel.signer, "Invalid signature");
202+
require(signAddress == channel.signer || signAddress == channel.sender, "Invalid signature");
203203

204204
//transfer amount from the channel to the sender
205205
channel.value = channel.value.sub(actualAmount);

test/MultiPartyEscrow_test1.js

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,69 @@ contract('MultiPartyEscrow', function(accounts) {
282282

283283
// Test for a replay attack
284284
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+
});
286348

287349
it ("Check validity of the signatures with js-server part (claim)", async function()
288350
{

0 commit comments

Comments
 (0)