Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore ExpenditureCancelled event on CancelAndReclaim #1167

Merged
merged 1 commit into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions contracts/extensions/StakedExpenditure.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ contract StakedExpenditure is ColonyExtensionMeta {
// Events

event ExpenditureMadeViaStake(address indexed creator, uint256 expenditureId, uint256 stake);
event ExpenditureCancelled(uint256 expenditureId, bool punished);
event ExpenditureCancelled(address agent, uint256 expenditureId);
event StakeReclaimed(uint256 expenditureId);
event StakeFractionSet(uint256 stakeFraction);
event StakeFractionSet(address agent, uint256 stakeFraction);
event ExpenditureStakerPunished(address agent, uint256 expenditureId, bool punished);

// Datatypes

Expand Down Expand Up @@ -108,7 +109,7 @@ contract StakedExpenditure is ColonyExtensionMeta {
require(_stakeFraction <= WAD, "staked-expenditure-value-too-large");
stakeFraction = _stakeFraction;

emit StakeFractionSet(_stakeFraction);
emit StakeFractionSet(msgSender(), _stakeFraction);
}

/// @notice Make an expenditure by putting up a stake
Expand Down Expand Up @@ -265,7 +266,7 @@ contract StakedExpenditure is ColonyExtensionMeta {

cancelExpenditure(_permissionDomainId, _childSkillIndex, _expenditureId, expenditure.owner);

emit ExpenditureCancelled(_expenditureId, _punish);
emit ExpenditureStakerPunished(msgSender(), _expenditureId, _punish);
}

// View
Expand Down Expand Up @@ -317,5 +318,7 @@ contract StakedExpenditure is ColonyExtensionMeta {
keys,
value
);

emit ExpenditureCancelled(msgSender(), _expenditureId);
}
}
21 changes: 14 additions & 7 deletions test/extensions/staked-expenditure.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ contract("StakedExpenditure", (accounts) => {

const USER0 = accounts[0];
const USER1 = accounts[1];
const USER2 = accounts[2];
const MINER = accounts[5];

const CANCELLED = 1;
Expand All @@ -75,6 +76,8 @@ contract("StakedExpenditure", (accounts) => {
await colony.setArbitrationRole(1, UINT256_MAX, stakedExpenditure.address, 1, true);
await colony.setAdministrationRole(1, UINT256_MAX, stakedExpenditure.address, 1, true);

await colony.setArbitrationRole(1, UINT256_MAX, USER1, 1, true);

const domain1 = await colony.getDomain(1);

reputationTree = new PatriciaTree();
Expand Down Expand Up @@ -270,9 +273,10 @@ contract("StakedExpenditure", (accounts) => {
const expenditureId = await colony.getExpenditureCount();
await colony.lockExpenditure(expenditureId);

const tx = await stakedExpenditure.cancelAndPunish(1, UINT256_MAX, 1, UINT256_MAX, expenditureId, true);
const tx = await stakedExpenditure.cancelAndPunish(1, UINT256_MAX, 1, UINT256_MAX, expenditureId, true, { from: USER1 });

await expectEvent(tx, "ExpenditureCancelled", [expenditureId, true]);
await expectEvent(tx, "ExpenditureCancelled", [USER1, expenditureId]);
await expectEvent(tx, "ExpenditureStakerPunished", [USER1, expenditureId, true]);

const obligation = await tokenLocking.getObligation(USER0, token.address, colony.address);
expect(obligation).to.be.zero;
Expand Down Expand Up @@ -302,7 +306,7 @@ contract("StakedExpenditure", (accounts) => {
await colony.lockExpenditure(expenditureId);

await checkErrorRevert(
stakedExpenditure.cancelAndPunish(1, UINT256_MAX, 1, UINT256_MAX, expenditureId, true, { from: USER1 }),
stakedExpenditure.cancelAndPunish(1, UINT256_MAX, 1, UINT256_MAX, expenditureId, true, { from: USER2 }),
"staked-expenditure-caller-not-arbitration"
);
});
Expand All @@ -312,9 +316,10 @@ contract("StakedExpenditure", (accounts) => {
const expenditureId = await colony.getExpenditureCount();
await colony.lockExpenditure(expenditureId);

const tx = await stakedExpenditure.cancelAndPunish(1, UINT256_MAX, 1, UINT256_MAX, expenditureId, false);
const tx = await stakedExpenditure.cancelAndPunish(1, UINT256_MAX, 1, UINT256_MAX, expenditureId, false, { from: USER1 });

await expectEvent(tx, "ExpenditureCancelled", [expenditureId, false]);
await expectEvent(tx, "ExpenditureCancelled", [USER1, expenditureId]);
await expectEvent(tx, "ExpenditureStakerPunished", [USER1, expenditureId, false]);

let obligation;
let userLock;
Expand Down Expand Up @@ -358,7 +363,8 @@ contract("StakedExpenditure", (accounts) => {
await stakedExpenditure.makeExpenditureWithStake(1, UINT256_MAX, 1, domain1Key, domain1Value, domain1Mask, domain1Siblings, { from: USER0 });
const expenditureId = await colony.getExpenditureCount();

await colony.cancelExpenditure(expenditureId);
const tx = await colony.cancelExpenditure(expenditureId);
await expectEvent(tx, "ExpenditureCancelled", [USER0, expenditureId]);

await stakedExpenditure.reclaimStake(expenditureId);

Expand All @@ -373,7 +379,8 @@ contract("StakedExpenditure", (accounts) => {
await stakedExpenditure.makeExpenditureWithStake(1, UINT256_MAX, 1, domain1Key, domain1Value, domain1Mask, domain1Siblings, { from: USER0 });
const expenditureId = await colony.getExpenditureCount();

await stakedExpenditure.cancelAndReclaimStake(1, UINT256_MAX, expenditureId);
const tx = await stakedExpenditure.cancelAndReclaimStake(1, UINT256_MAX, expenditureId);
await expectEvent(tx, "ExpenditureCancelled", [USER0, expenditureId]);

const obligation = await tokenLocking.getObligation(USER0, token.address, colony.address);
expect(obligation).to.be.zero;
Expand Down