Skip to content

Commit

Permalink
Merge pull request #527 from NexusMutual/feature/assessment-data-ipfs…
Browse files Browse the repository at this point in the history
…-hash

Feature: assessment data ipfs hash
  • Loading branch information
danoctavian committed Nov 29, 2022
2 parents 17bf405 + 09775aa commit 1171cec
Show file tree
Hide file tree
Showing 14 changed files with 211 additions and 150 deletions.
3 changes: 2 additions & 1 deletion contracts/interfaces/IAssessment.sol
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ interface IAssessment {
function castVotes(
uint[] calldata assessmentIds,
bool[] calldata votes,
string[] calldata ipfsAssessmentDataHashes,
uint96 stakeIncrease
) external;

Expand All @@ -170,7 +171,7 @@ interface IAssessment {

event StakeDeposited(address user, uint104 amount);
event StakeWithdrawn(address indexed user, address to, uint96 amount);
event VoteCast(address indexed user, uint256 assessmentId, uint96 stakedAmount, bool accepted);
event VoteCast(address indexed user, uint256 assessmentId, uint96 stakedAmount, bool accepted, string ipfsAssessmentDataHash);
event RewardWithdrawn(address user, address to, uint256 amount);
event FraudProcessed(uint assessmentId, address assessor, Poll poll);
event FraudSubmitted(bytes32 root);
Expand Down
12 changes: 8 additions & 4 deletions contracts/modules/assessment/Assessment.sol
Original file line number Diff line number Diff line change
Expand Up @@ -291,19 +291,24 @@ contract Assessment is IAssessment, MasterAwareV2 {
function castVotes(
uint[] calldata assessmentIds,
bool[] calldata votes,
string[] calldata ipfsAssessmentDataHashes,
uint96 stakeIncrease
) external override onlyMember whenNotPaused {
require(
assessmentIds.length == votes.length,
"The lengths of the assessment ids and votes arrays mismatch"
);
require(
assessmentIds.length == ipfsAssessmentDataHashes.length,
"The lengths of the assessment ids and ipfs assessment data hashes arrays mismatch"
);

if (stakeIncrease > 0) {
stake(stakeIncrease);
}

for (uint i = 0; i < assessmentIds.length; i++) {
castVote(assessmentIds[i], votes[i]);
castVote(assessmentIds[i], votes[i], ipfsAssessmentDataHashes[i]);
}
}

Expand All @@ -318,7 +323,7 @@ contract Assessment is IAssessment, MasterAwareV2 {
///
/// @param assessmentId The index of the assessment for which the vote is cast
/// @param isAcceptVote True to accept, false to deny
function castVote(uint assessmentId, bool isAcceptVote) internal {
function castVote(uint assessmentId, bool isAcceptVote, string memory ipfsAssessmentDataHash) internal {
{
require(!hasAlreadyVotedOn[msg.sender][assessmentId], "Already voted");
hasAlreadyVotedOn[msg.sender][assessmentId] = true;
Expand Down Expand Up @@ -365,8 +370,7 @@ contract Assessment is IAssessment, MasterAwareV2 {
uint32(block.timestamp),
stakeAmount
));

emit VoteCast(msg.sender, assessmentId, stakeAmount, isAcceptVote);
emit VoteCast(msg.sender, assessmentId, stakeAmount, isAcceptVote, ipfsAssessmentDataHash);
}

/// Allows governance to submit a merkle tree root hash representing fraudulent stakers
Expand Down
18 changes: 9 additions & 9 deletions test/integration/Cover/expireCover.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ describe.skip('expireCover', function () {
await submitIncident({ yc, productId, period, signer: this.accounts.defaultSender });

// accept incident
await as.connect(staker1).castVotes([assessmentId], [true], parseEther('100'));
await as.connect(staker1).castVotes([assessmentId], [true], ['Assessment data hash'], parseEther('100'));

{
// advance past payout cooldown
Expand Down Expand Up @@ -210,7 +210,7 @@ describe.skip('expireCover', function () {
await submitIncident({ yc, productId, period, signer: this.accounts.defaultSender });

// accept incident
await as.connect(staker1).castVotes([assessmentId], [true], parseEther('100'));
await as.connect(staker1).castVotes([assessmentId], [true], ['Assessment data hash'], parseEther('100'));

{
// advance past payout cooldown
Expand Down Expand Up @@ -280,7 +280,7 @@ describe.skip('expireCover', function () {
await submitIncident({ yc, productId, period, signer: this.accounts.defaultSender });

// accept incident
await as.connect(staker1).castVotes([assessmentId], [true], parseEther('100'));
await as.connect(staker1).castVotes([assessmentId], [true], ['Assessment data hash'], parseEther('100'));

{
// advance past payout cooldown
Expand Down Expand Up @@ -355,7 +355,7 @@ describe.skip('expireCover', function () {
await submitIncident({ yc, productId, period, signer: this.accounts.defaultSender });

// accept incident
await as.connect(staker1).castVotes([assessmentId], [true], parseEther('100'));
await as.connect(staker1).castVotes([assessmentId], [true], ['Assessment data hash'], parseEther('100'));

{
// advance past payout cooldown
Expand Down Expand Up @@ -424,7 +424,7 @@ describe.skip('expireCover', function () {
await submitIncident({ yc, productId, period, signer: this.accounts.defaultSender });

// accept incident
await as.connect(staker1).castVotes([assessmentId], [true], parseEther('100'));
await as.connect(staker1).castVotes([assessmentId], [true], ['Assessment data hash'], parseEther('100'));

{
// advance past payout cooldown
Expand Down Expand Up @@ -503,8 +503,8 @@ describe.skip('expireCover', function () {
await submitIncident({ yc, productId, period, signer: this.accounts.defaultSender });

// reject incident (requires at least 1 positive vote)
await as.connect(staker1).castVotes([assessmentId], [true], parseEther('100'));
await as.connect(staker2).castVotes([assessmentId], [false], parseEther('100'));
await as.connect(staker1).castVotes([assessmentId], [true], ['Assessment data hash'], parseEther('100'));
await as.connect(staker2).castVotes([assessmentId], [false], ['Assessment data hash'], parseEther('100'));

{
// advance past payout cooldown
Expand Down Expand Up @@ -579,8 +579,8 @@ describe.skip('expireCover', function () {
await submitIncident({ yc, productId, period, signer: this.accounts.defaultSender });

// reject incident (requires at least 1 positive vote)
await as.connect(staker1).castVotes([assessmentId], [true], parseEther('100'));
await as.connect(staker2).castVotes([assessmentId], [false], parseEther('100'));
await as.connect(staker1).castVotes([assessmentId], [true], ['Assessment data hash'], parseEther('100'));
await as.connect(staker2).castVotes([assessmentId], [false], ['Assessment data hash'], parseEther('100'));

{
// advance past payout cooldown
Expand Down
6 changes: 3 additions & 3 deletions test/integration/IndividualClaims/submitClaim.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe.skip('submitClaim', function () {
const { payoutCooldownInDays } = await as.config();
await as.connect(staker).stake(assessmentStakingAmount);

await as.connect(staker).castVotes([0], [true], 0);
await as.connect(staker).castVotes([0], [true], ['Assessment data hash'], 0);

const { poll } = await as.assessments(0);
const futureTime = poll.end + daysToSeconds(payoutCooldownInDays);
Expand All @@ -48,10 +48,10 @@ describe.skip('submitClaim', function () {
const { payoutCooldownInDays } = await as.config();
await as.connect(approvingStaker).stake(assessmentStakingAmountForApproval);

await as.connect(approvingStaker).castVotes([0], [true], 0);
await as.connect(approvingStaker).castVotes([0], [true], ['Assessment data hash'], 0);

await as.connect(rejectingStaker).stake(assessmentStakingAmountForRejection);
await as.connect(rejectingStaker).castVotes([0], [false], 0);
await as.connect(rejectingStaker).castVotes([0], [false], ['Assessment data hash'], 0);

const { poll } = await as.assessments(0);
const futureTime = poll.end + daysToSeconds(payoutCooldownInDays);
Expand Down
8 changes: 4 additions & 4 deletions test/integration/YieldTokenIncidents/submitClaim.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ describe.skip('submitClaim', function () {
}

// accept incident
await as.connect(staker1).castVotes([0], [true], parseEther('100'));
await as.connect(staker1).castVotes([0], [true], ['Assessment data hash'], parseEther('100'));

{
// advance past payout cooldown
Expand Down Expand Up @@ -186,7 +186,7 @@ describe.skip('submitClaim', function () {
}

// accept incident
await as.connect(staker1).castVotes([0], [true], parseEther('100'));
await as.connect(staker1).castVotes([0], [true], ['Assessment data hash'], parseEther('100'));

{
// advance past payout cooldown
Expand Down Expand Up @@ -271,8 +271,8 @@ describe.skip('submitClaim', function () {
}

// reject incident (requires at least 1 positive vote)
await as.connect(staker1).castVotes([0], [true], parseEther('100'));
await as.connect(staker2).castVotes([0], [false], parseEther('100'));
await as.connect(staker1).castVotes([0], [true], ['Assessment data hash'], parseEther('100'));
await as.connect(staker2).castVotes([0], [false], ['Assessment data hash'], parseEther('100'));

{
// advance past payout cooldown
Expand Down
Loading

0 comments on commit 1171cec

Please sign in to comment.