Skip to content

Commit

Permalink
Merge pull request #99 from ksridharbabuus/master
Browse files Browse the repository at this point in the history
Enhancements to Claim functionality
  • Loading branch information
ksridharbabuus authored Aug 14, 2019
2 parents 6070230 + 283cf7b commit 28bcf92
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 4 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,14 @@ Includes SingularityNET platform contracts, migrations, tests
npm install
```

### Compile
```bash
truffle compile
```

### Test
```bash
npm run test
truffle test
```

## Package
Expand Down
2 changes: 1 addition & 1 deletion contracts/MultiPartyEscrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ contract MultiPartyEscrow {
bytes32 message = prefixed(keccak256(abi.encodePacked("__MPE_claim_message", this, channelId, channel.nonce, plannedAmount)));
// check that the signature is from the signer
address signAddress = ecrecover(message, v, r, s);
require(signAddress == channel.signer, "Invalid signature");
require(signAddress == channel.signer || signAddress == channel.sender, "Invalid signature");

//transfer amount from the channel to the sender
channel.value = channel.value.sub(actualAmount);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "singularitynet-platform-contracts",
"version": "0.3.1-beta",
"version": "0.3.2-beta",
"private": true,
"description": "Includes SingularityNET platform contracts, migrations, tests",
"directories": {
Expand Down
64 changes: 63 additions & 1 deletion test/MultiPartyEscrow_test1.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,69 @@ contract('MultiPartyEscrow', function(accounts) {

// Test for a replay attack
await testErrorRevert(escrow.openChannelByThirdParty(accounts[4], accounts[4], accounts[3], groupId, channelDepositAmount, expiration, messageNonce, vrs.v, vrs.r, vrs.s, {from:accounts[7]}));
});
});

it ("Open the seventh channel for Claim signed by sender", async function()
{
//sign message by the privet key of accounts[0]

let channelDepositAmount = 100
let plannedAmount = 90
let actualAmount = 80

let expiration = web3.eth.blockNumber + 10000000
let groupId = "group42"
let currentChannelId = (await escrow.nextChannelId.call()).toNumber()
let accountBal_4 = (await escrow.balances.call(accounts[4])).toNumber()
let accountBal_7 = (await escrow.balances.call(accounts[7])).toNumber()

// Signer is Different than the sender
await escrow.openChannel(accounts[5], accounts[7], groupId, channelDepositAmount, expiration, {from:accounts[4]})
assert.equal((await escrow.balances.call(accounts[4])).toNumber(), accountBal_4 - channelDepositAmount)

// Message signed by the sender/channel owner or creater
let sgn = await signFuns.waitSignedClaimMessage(accounts[4], escrow.address, currentChannelId, 0, plannedAmount);
let vrs = signFuns.getVRSFromSignature(sgn.toString("hex"));

// Testing for Actual Amount > Planned Amount
testErrorRevert(escrow.channelClaim(currentChannelId, actualAmount+plannedAmount, plannedAmount, vrs.v, vrs.r, vrs.s, true, {from:accounts[7]}));
// Claiming the lower amount and sending remaining channel value back to user
await escrow.channelClaim(currentChannelId, actualAmount, plannedAmount, vrs.v, vrs.r, vrs.s, true, {from:accounts[7]});
assert.equal((await escrow.balances.call(accounts[7])).toNumber(), accountBal_7 + actualAmount)
assert.equal((await escrow.balances.call(accounts[4])).toNumber(), accountBal_4 - actualAmount)

});

it ("Open the eight channel for Claim signed by signer", async function()
{
//sign message by the privet key of accounts[0]

let channelDepositAmount = 100
let plannedAmount = 90
let actualAmount = 80

let expiration = web3.eth.blockNumber + 10000000
let groupId = "group42"
let currentChannelId = (await escrow.nextChannelId.call()).toNumber()
let accountBal_4 = (await escrow.balances.call(accounts[4])).toNumber()
let accountBal_7 = (await escrow.balances.call(accounts[7])).toNumber()

// Signer is Different than the sender
await escrow.openChannel(accounts[5], accounts[7], groupId, channelDepositAmount, expiration, {from:accounts[4]})
assert.equal((await escrow.balances.call(accounts[4])).toNumber(), accountBal_4 - channelDepositAmount)

// Message signed by the Signer
let sgn = await signFuns.waitSignedClaimMessage(accounts[5], escrow.address, currentChannelId, 0, plannedAmount);
let vrs = signFuns.getVRSFromSignature(sgn.toString("hex"));

// Testing for Actual Amount > Planned Amount
testErrorRevert(escrow.channelClaim(currentChannelId, actualAmount+plannedAmount, plannedAmount, vrs.v, vrs.r, vrs.s, true, {from:accounts[7]}));
// Claiming the lower amount and sending remaining channel value back to user
await escrow.channelClaim(currentChannelId, actualAmount, plannedAmount, vrs.v, vrs.r, vrs.s, true, {from:accounts[7]});
assert.equal((await escrow.balances.call(accounts[7])).toNumber(), accountBal_7 + actualAmount)
assert.equal((await escrow.balances.call(accounts[4])).toNumber(), accountBal_4 - actualAmount)

});

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

0 comments on commit 28bcf92

Please sign in to comment.