Skip to content

Commit

Permalink
Merge pull request #82 from magmo/guarantor-consensus
Browse files Browse the repository at this point in the history
Guarantor channels can use consensus app.
  • Loading branch information
andrewgordstewart authored Jun 27, 2019
2 parents 2982de8 + 9fb1db2 commit 3519d69
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 26 deletions.
37 changes: 19 additions & 18 deletions packages/fmg-nitro-adjudicator/contracts/ConsensusApp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ contract ConsensusApp {
require(
encodeAndHashAllocation(oldCommitment.currentAllocation) == encodeAndHashAllocation(newCommitment.currentAllocation),
"ConsensusApp: 'allocation' must be the same between commitments."
);
);
require(
encodeAndHashDestination(oldCommitment.currentDestination) == encodeAndHashDestination(newCommitment.currentDestination),
"ConsensusApp: 'destination' must be the same between commitments."
Expand All @@ -146,7 +146,7 @@ contract ConsensusApp {
require(
encodeAndHashAllocation(oldCommitment.proposedAllocation) == encodeAndHashAllocation(newCommitment.proposedAllocation),
"ConsensusApp: 'proposedAllocation' must be the same between commitments."
);
);
require(
encodeAndHashDestination(oldCommitment.proposedDestination) == encodeAndHashDestination(newCommitment.proposedDestination),
"ConsensusApp: 'proposedDestination' must be the same between commitments."
Expand All @@ -159,33 +159,34 @@ contract ConsensusApp {
require(
commitment.furtherVotesRequired == 0,
"ConsensusApp: 'furtherVotesRequired' must be 0 during consensus."
);
);
require(
commitment.proposedAllocation.length == 0,
"ConsensusApp: 'proposedAllocation' must be reset during consensus."
);
);
require(
commitment.proposedDestination.length == 0,
"ConsensusApp: 'proposedDestination' must be reset during consensus."
);
}
);
}

function validateProposeCommitment(
ConsensusCommitment.ConsensusCommitmentStruct memory commitment
) internal pure {
require(
commitment.furtherVotesRequired != 0,
"ConsensusApp: 'furtherVotesRequired' must not be 0 during propose."
);
);
require(
commitment.proposedAllocation.length > 0,
"ConsensusApp: 'proposedAllocation' must not be reset during propose."
);
commitment.proposedDestination.length > 0,
"ConsensusApp: 'proposedDestination' must not be reset during propose."
);
require(
commitment.proposedDestination.length == commitment.proposedAllocation.length,
"ConsensusApp: 'proposedDestination' and 'proposedAllocation' must be the same length during propose."
);
}
commitment.proposedAllocation.length == 0 || // in case it's a guarantor channel
commitment.proposedAllocation.length == commitment.proposedDestination.length,
"ConsensusApp: Outcome must be valid during propose"
);
}

// Booleans

Expand All @@ -195,17 +196,17 @@ contract ConsensusApp {
) private pure returns (bool) {
return(
commitment.furtherVotesRequired == numParticipants - 1
);
}
);
}

function furtherVotesRequiredDecremented(
ConsensusCommitment.ConsensusCommitmentStruct memory oldCommitment,
ConsensusCommitment.ConsensusCommitmentStruct memory newCommitment
) private pure returns (bool) {
return(
newCommitment.furtherVotesRequired == oldCommitment.furtherVotesRequired - 1
);
}
);
}

function balancesUpdated(
ConsensusCommitment.ConsensusCommitmentStruct memory oldCommitment,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('ConsensusApp', () => {
channelType: participantB.address,
nonce: 0,
participants,
}; // just use any valid address
};
const defaults = {
channel,
allocation,
Expand Down Expand Up @@ -96,7 +96,7 @@ describe('ConsensusApp', () => {
proposedDestination: participants,
});
const proposeCommitmentAllocation = appCommitment(threeVotesComplete, {
proposedAllocation: [],
proposedAllocation: allocation.slice(1),
});
const proposeCommitmentDestination = appCommitment(threeVotesComplete, {
proposedDestination: [],
Expand All @@ -119,14 +119,14 @@ describe('ConsensusApp', () => {
it('calls the propose commitment validator on the new commitment', async () => {
await invalidTransition(
fromCommitment,
proposeCommitmentAllocation,
"ConsensusApp: 'proposedAllocation' must not be reset during propose.",
proposeCommitmentDestination,
"ConsensusApp: 'proposedDestination' must not be reset during propose.",
);

await invalidTransition(
fromCommitment,
proposeCommitmentDestination,
"ConsensusApp: 'proposedDestination' and 'proposedAllocation' must be the same length during propose.",
proposeCommitmentAllocation,
'ConsensusApp: Outcome must be valid during propose',
);
});

Expand All @@ -138,9 +138,9 @@ describe('ConsensusApp', () => {
);

await invalidTransition(
proposeCommitmentAllocation,
proposeCommitmentDestination,
toCommitment,
"ConsensusApp: 'proposedAllocation' must not be reset during propose.",
"ConsensusApp: 'proposedDestination' must not be reset during propose.",
);
});
});
Expand Down

0 comments on commit 3519d69

Please sign in to comment.