-
Notifications
You must be signed in to change notification settings - Fork 12.2k
test: fix execution delay edge cases in AccessManaged tests #5972
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -65,7 +65,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
describe('when role is granted with execution delay', function () { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
beforeEach(async function () { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const executionDelay = 911n; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const executionDelay = time.duration.hours(1); // 1 hour - standard test value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
await this.authority.$_grantRole(this.role, this.roleMember, 0, executionDelay); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -97,6 +97,42 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Shouldn't revert | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
await this.managed.connect(this.roleMember)[this.selector](); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
it('succeeds when role is granted with zero execution delay', async function () { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Grant role with zero execution delay | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
await this.authority.$_grantRole(this.role, this.roleMember, 0, 0n); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Should work without scheduling | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
await this.managed.connect(this.roleMember)[this.selector](); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
it('handles maximum execution delay correctly', async function () { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const maxExecutionDelay = 2n**32n - 1n; // uint32 max | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
await this.authority.$_grantRole(this.role, this.roleMember, 0, maxExecutionDelay); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Should require scheduling | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
await expect(this.managed.connect(this.roleMember)[this.selector]()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
.to.be.revertedWithCustomError(this.authority, 'AccessManagerNotScheduled'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
it('adjusts when time to minimum required time if too early', async function () { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const executionDelay = time.duration.hours(1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
await this.authority.$_grantRole(this.role, this.roleMember, 0, executionDelay); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const fn = this.managed.interface.getFunction(this.selector); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const calldata = this.managed.interface.encodeFunctionData(fn, []); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Try to schedule in the past | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const pastTime = (await time.clock.timestamp()) - time.duration.hours(1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Should automatically adjust time to minimum required | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const { operationId } = await this.authority.connect(this.roleMember).schedule(this.managed, calldata, pastTime); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const scheduledTime = await this.authority.getSchedule(operationId); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Verify time was adjusted to minimum required | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const minTime = (await time.clock.timestamp()) + executionDelay; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
expect(scheduledTime).to.be.at.least(minTime); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+118
to
+135
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix timing inconsistency in minTime calculation. The test calculates Apply this diff to fix the timing issue: it('adjusts when time to minimum required time if too early', async function () {
const executionDelay = time.duration.hours(1);
await this.authority.$_grantRole(this.role, this.roleMember, 0, executionDelay);
const fn = this.managed.interface.getFunction(this.selector);
const calldata = this.managed.interface.encodeFunctionData(fn, []);
// Try to schedule in the past
- const pastTime = (await time.clock.timestamp()) - time.duration.hours(1);
+ const currentTime = await time.clock.timestamp();
+ const pastTime = currentTime - time.duration.hours(1);
// Should automatically adjust time to minimum required
const { operationId } = await this.authority.connect(this.roleMember).schedule(this.managed, calldata, pastTime);
const scheduledTime = await this.authority.getSchedule(operationId);
// Verify time was adjusted to minimum required
- const minTime = (await time.clock.timestamp()) + executionDelay;
+ const minTime = currentTime + executionDelay;
expect(scheduledTime).to.be.at.least(minTime);
}); 📝 Committable suggestion
Suggested change
🧰 Tools🪛 GitHub Check: codespell[failure] 129-129: [failure] 126-126: 🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add opId to error assertion for consistency.
The test should calculate the
opId
and include it in.withArgs(opId)
for a more precise assertion, consistent with the similar test at lines 72-79.Apply this diff to add the missing opId:
📝 Committable suggestion
🤖 Prompt for AI Agents