-
Notifications
You must be signed in to change notification settings - Fork 12.4k
test: add decodeBatch error case coverage for ERC7579Utils #6251
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?
Conversation
🦋 Changeset detectedLatest commit: f6c1d8d The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
WalkthroughA new test suite "decodeBatch error cases" has been added to validate error handling in the Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Actionable comments posted: 1
📜 Review details
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
test/account/utils/draft-ERC7579Utils.test.js
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
- GitHub Check: Redirect rules - solidity-contracts
- GitHub Check: Header rules - solidity-contracts
- GitHub Check: Pages changed - solidity-contracts
- GitHub Check: tests
- GitHub Check: tests-foundry
- GitHub Check: slither
- GitHub Check: coverage
- GitHub Check: tests-upgradeable
- GitHub Check: halmos
| describe('decodeBatch error cases', function () { | ||
| it('reverts when executionCalldata is empty', async function () { | ||
| const emptyData = '0x'; | ||
| await expect(this.utils.$decodeBatch(emptyData)).to.be.revertedWithCustomError(this.utils, 'ERC7579DecodingError'); | ||
| }); | ||
|
|
||
| it('reverts when executionCalldata is too short', async function () { | ||
| const shortData = '0x' + '00'.repeat(16); | ||
| await expect(this.utils.$decodeBatch(shortData)).to.be.revertedWithCustomError(this.utils, 'ERC7579DecodingError'); | ||
| }); | ||
|
|
||
| it('reverts when array offset points outside buffer', async function () { | ||
| const malformedData = ethers.toBeHex(0x100, 32); | ||
| await expect(this.utils.$decodeBatch(malformedData)).to.be.revertedWithCustomError( | ||
| this.utils, | ||
| 'ERC7579DecodingError', | ||
| ); | ||
| }); | ||
|
|
||
| it('reverts when array length exceeds uint64 max', async function () { | ||
| const offsetData = ethers.toBeHex(32, 32); | ||
| const tooLargeLength = ethers.toBeHex(ethers.toBigInt('0xFFFFFFFFFFFFFFFF') + 1n, 32); | ||
| const malformedData = offsetData + tooLargeLength.slice(2); | ||
| await expect(this.utils.$decodeBatch(malformedData)).to.be.revertedWithCustomError( | ||
| this.utils, | ||
| 'ERC7579DecodingError', | ||
| ); | ||
| }); | ||
|
|
||
| it('reverts when buffer too small for array element pointers', async function () { | ||
| const offsetData = ethers.toBeHex(32, 32); | ||
| const arrayLength = ethers.toBeHex(10, 32); | ||
| const malformedData = offsetData + arrayLength.slice(2); | ||
| await expect(this.utils.$decodeBatch(malformedData)).to.be.revertedWithCustomError( | ||
| this.utils, | ||
| 'ERC7579DecodingError', | ||
| ); | ||
| }); | ||
| }); |
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.
Critical: Test suite missing fixture setup.
This test suite is defined outside the main 'ERC7579Utils' describe block (which ends at line 399), so it doesn't have access to the beforeEach fixture that initializes this.utils (lines 29-31). All five tests will fail because this.utils is undefined.
🔎 Proposed fix
Option 1 (Recommended): Nest the test suite inside the main describe block
Move this test suite inside the main 'ERC7579Utils' describe block before line 399:
});
});
+
+ describe('decodeBatch error cases', function () {
+ it('reverts when executionCalldata is empty', async function () {
+ const emptyData = '0x';
+ await expect(this.utils.$decodeBatch(emptyData)).to.be.revertedWithCustomError(this.utils, 'ERC7579DecodingError');
+ });
+
+ it('reverts when executionCalldata is too short', async function () {
+ const shortData = '0x' + '00'.repeat(16);
+ await expect(this.utils.$decodeBatch(shortData)).to.be.revertedWithCustomError(this.utils, 'ERC7579DecodingError');
+ });
+
+ it('reverts when array offset points outside buffer', async function () {
+ const malformedData = ethers.toBeHex(0x100, 32);
+ await expect(this.utils.$decodeBatch(malformedData)).to.be.revertedWithCustomError(
+ this.utils,
+ 'ERC7579DecodingError',
+ );
+ });
+
+ it('reverts when array length exceeds uint64 max', async function () {
+ const offsetData = ethers.toBeHex(32, 32);
+ const tooLargeLength = ethers.toBeHex(ethers.toBigInt('0xFFFFFFFFFFFFFFFF') + 1n, 32);
+ const malformedData = offsetData + tooLargeLength.slice(2);
+ await expect(this.utils.$decodeBatch(malformedData)).to.be.revertedWithCustomError(
+ this.utils,
+ 'ERC7579DecodingError',
+ );
+ });
+
+ it('reverts when buffer too small for array element pointers', async function () {
+ const offsetData = ethers.toBeHex(32, 32);
+ const arrayLength = ethers.toBeHex(10, 32);
+ const malformedData = offsetData + arrayLength.slice(2);
+ await expect(this.utils.$decodeBatch(malformedData)).to.be.revertedWithCustomError(
+ this.utils,
+ 'ERC7579DecodingError',
+ );
+ });
+ });
});
-
-describe('decodeBatch error cases', function () {
- it('reverts when executionCalldata is empty', async function () {
- const emptyData = '0x';
- await expect(this.utils.$decodeBatch(emptyData)).to.be.revertedWithCustomError(this.utils, 'ERC7579DecodingError');
- });
-
- it('reverts when executionCalldata is too short', async function () {
- const shortData = '0x' + '00'.repeat(16);
- await expect(this.utils.$decodeBatch(shortData)).to.be.revertedWithCustomError(this.utils, 'ERC7579DecodingError');
- });
-
- it('reverts when array offset points outside buffer', async function () {
- const malformedData = ethers.toBeHex(0x100, 32);
- await expect(this.utils.$decodeBatch(malformedData)).to.be.revertedWithCustomError(
- this.utils,
- 'ERC7579DecodingError',
- );
- });
-
- it('reverts when array length exceeds uint64 max', async function () {
- const offsetData = ethers.toBeHex(32, 32);
- const tooLargeLength = ethers.toBeHex(ethers.toBigInt('0xFFFFFFFFFFFFFFFF') + 1n, 32);
- const malformedData = offsetData + tooLargeLength.slice(2);
- await expect(this.utils.$decodeBatch(malformedData)).to.be.revertedWithCustomError(
- this.utils,
- 'ERC7579DecodingError',
- );
- });
-
- it('reverts when buffer too small for array element pointers', async function () {
- const offsetData = ethers.toBeHex(32, 32);
- const arrayLength = ethers.toBeHex(10, 32);
- const malformedData = offsetData + arrayLength.slice(2);
- await expect(this.utils.$decodeBatch(malformedData)).to.be.revertedWithCustomError(
- this.utils,
- 'ERC7579DecodingError',
- );
- });
-});Option 2: Add fixture setup to the new describe block
describe('decodeBatch error cases', function () {
+ beforeEach(async function () {
+ Object.assign(this, await loadFixture(fixture));
+ });
+
it('reverts when executionCalldata is empty', async function () {📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| describe('decodeBatch error cases', function () { | |
| it('reverts when executionCalldata is empty', async function () { | |
| const emptyData = '0x'; | |
| await expect(this.utils.$decodeBatch(emptyData)).to.be.revertedWithCustomError(this.utils, 'ERC7579DecodingError'); | |
| }); | |
| it('reverts when executionCalldata is too short', async function () { | |
| const shortData = '0x' + '00'.repeat(16); | |
| await expect(this.utils.$decodeBatch(shortData)).to.be.revertedWithCustomError(this.utils, 'ERC7579DecodingError'); | |
| }); | |
| it('reverts when array offset points outside buffer', async function () { | |
| const malformedData = ethers.toBeHex(0x100, 32); | |
| await expect(this.utils.$decodeBatch(malformedData)).to.be.revertedWithCustomError( | |
| this.utils, | |
| 'ERC7579DecodingError', | |
| ); | |
| }); | |
| it('reverts when array length exceeds uint64 max', async function () { | |
| const offsetData = ethers.toBeHex(32, 32); | |
| const tooLargeLength = ethers.toBeHex(ethers.toBigInt('0xFFFFFFFFFFFFFFFF') + 1n, 32); | |
| const malformedData = offsetData + tooLargeLength.slice(2); | |
| await expect(this.utils.$decodeBatch(malformedData)).to.be.revertedWithCustomError( | |
| this.utils, | |
| 'ERC7579DecodingError', | |
| ); | |
| }); | |
| it('reverts when buffer too small for array element pointers', async function () { | |
| const offsetData = ethers.toBeHex(32, 32); | |
| const arrayLength = ethers.toBeHex(10, 32); | |
| const malformedData = offsetData + arrayLength.slice(2); | |
| await expect(this.utils.$decodeBatch(malformedData)).to.be.revertedWithCustomError( | |
| this.utils, | |
| 'ERC7579DecodingError', | |
| ); | |
| }); | |
| }); | |
| describe('decodeBatch error cases', function () { | |
| it('reverts when executionCalldata is empty', async function () { | |
| const emptyData = '0x'; | |
| await expect(this.utils.$decodeBatch(emptyData)).to.be.revertedWithCustomError(this.utils, 'ERC7579DecodingError'); | |
| }); | |
| it('reverts when executionCalldata is too short', async function () { | |
| const shortData = '0x' + '00'.repeat(16); | |
| await expect(this.utils.$decodeBatch(shortData)).to.be.revertedWithCustomError(this.utils, 'ERC7579DecodingError'); | |
| }); | |
| it('reverts when array offset points outside buffer', async function () { | |
| const malformedData = ethers.toBeHex(0x100, 32); | |
| await expect(this.utils.$decodeBatch(malformedData)).to.be.revertedWithCustomError( | |
| this.utils, | |
| 'ERC7579DecodingError', | |
| ); | |
| }); | |
| it('reverts when array length exceeds uint64 max', async function () { | |
| const offsetData = ethers.toBeHex(32, 32); | |
| const tooLargeLength = ethers.toBeHex(ethers.toBigInt('0xFFFFFFFFFFFFFFFF') + 1n, 32); | |
| const malformedData = offsetData + tooLargeLength.slice(2); | |
| await expect(this.utils.$decodeBatch(malformedData)).to.be.revertedWithCustomError( | |
| this.utils, | |
| 'ERC7579DecodingError', | |
| ); | |
| }); | |
| it('reverts when buffer too small for array element pointers', async function () { | |
| const offsetData = ethers.toBeHex(32, 32); | |
| const arrayLength = ethers.toBeHex(10, 32); | |
| const malformedData = offsetData + arrayLength.slice(2); | |
| await expect(this.utils.$decodeBatch(malformedData)).to.be.revertedWithCustomError( | |
| this.utils, | |
| 'ERC7579DecodingError', | |
| ); | |
| }); | |
| }); |
🤖 Prompt for AI Agents
test/account/utils/draft-ERC7579Utils.test.js around lines 401-439: the
"decodeBatch error cases" describe is defined outside the main "ERC7579Utils"
describe (which ends at line 399) so this suite lacks the beforeEach fixture
that sets this.utils and will fail; fix by moving the entire describe block into
the main "ERC7579Utils" describe (i.e., place it before line 399 inside that
outer block) so it inherits the existing beforeEach, or alternatively add a
local beforeEach in this describe that initializes this.utils the same way as
the outer fixture.
|
The EIP-7702 test failures appear unrelated to this PR.
All Happy to help debug if these failures are somehow related to my changes. |
Description
This PR adds comprehensive test coverage for the
decodeBatcherror cases in ERC7579Utils, improving code coverage from 92.31% to 100%.Changes
Fixes
Fixes #5395 (improves coverage for the sanity checks added in PR #5400)
Testing