Skip to content
Open
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
9 changes: 6 additions & 3 deletions contracts/DLCManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ contract DLCManager is
error DLCNotFunded();

error ThresholdMinimumReached(uint16 _minimumThreshold);
error ThresholdTooLow(uint16 _minimumThreshold);
error ThresholdTooLow(uint16 requestedThreshold, uint16 _minimumThreshold);
error ThresholdTooHigh(uint16 requestedThreshold, uint16 _maximumThreshold);
error Unauthorized();
error NotEnoughSignatures();
error InvalidSigner();
Expand Down Expand Up @@ -147,7 +148,7 @@ contract DLCManager is
_grantRole(DLC_ADMIN_ROLE, dlcAdminRole);
_minimumThreshold = 2;
if (threshold < _minimumThreshold)
revert ThresholdTooLow(_minimumThreshold);
revert ThresholdTooLow(_minimumThreshold, threshold);
_threshold = threshold;
_index = 0;
tssCommitment = 0x0;
Expand Down Expand Up @@ -675,7 +676,9 @@ contract DLCManager is

function setThreshold(uint16 newThreshold) external onlyAdmin {
if (newThreshold < _minimumThreshold)
revert ThresholdTooLow(_minimumThreshold);
revert ThresholdTooLow(newThreshold, _minimumThreshold);
if (newThreshold > _signerCount)
revert ThresholdTooHigh(newThreshold, _signerCount);
_threshold = newThreshold;
emit SetThreshold(newThreshold);
}
Expand Down
29 changes: 20 additions & 9 deletions test/DLCManager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,31 +120,42 @@ describe('DLCManager', () => {
});

describe('setThreshold', async () => {
beforeEach(async () => {
await setSigners(dlcManager, [attestor1, attestor2, attestor3]);
await dlcManager.connect(deployer).setThreshold(2);
});

it('reverts if called by a non-admin', async () => {
await expect(
dlcManager.connect(user).setThreshold(4)
dlcManager.connect(user).setThreshold(3)
).to.be.revertedWithCustomError(dlcManager, 'NotDLCAdmin');
});

it('reverts if threshold is set below minimum threshold', async () => {
await expect(
dlcManager.connect(deployer).setThreshold(0)
).to.be.revertedWithCustomError(dlcManager, 'ThresholdTooLow');
await expect(dlcManager.connect(deployer).setThreshold(1))
.to.be.revertedWithCustomError(dlcManager, 'ThresholdTooLow')
.withArgs(1, 2);
});

it('reverts if threshold is set greater than signer count', async () => {
await expect(dlcManager.connect(deployer).setThreshold(4))
.to.be.revertedWithCustomError(dlcManager, 'ThresholdTooHigh')
.withArgs(4, 3);
});

it('emits a SetThreshold event with the correct data', async () => {
const tx = await dlcManager.connect(deployer).setThreshold(4);
const tx = await dlcManager.connect(deployer).setThreshold(3);
const receipt = await tx.wait();
const event = receipt.events[0];

expect(event.event).to.equal('SetThreshold');
expect(event.args.newThreshold).to.equal(4);
expect(event.args.newThreshold).to.equal(3);
});

it('updates the threshold correctly', async () => {
await dlcManager.connect(deployer).setThreshold(4);
await dlcManager.connect(deployer).setThreshold(3);
const newThreshold = await dlcManager.getThreshold();
expect(newThreshold).to.equal(4);
expect(newThreshold).to.equal(3);
});
});

Expand Down Expand Up @@ -557,8 +568,8 @@ describe('DLCManager', () => {
attestors.push(maliciousSigner);

// Change threshold and add the new signer
await dlcManager.connect(deployer).setThreshold(4);
await setSigners(dlcManager, [maliciousAttestor]);
await dlcManager.connect(deployer).setThreshold(4);

// Sign pending status
const signatureBytesForPending =
Expand Down