Skip to content
Open
Changes from 1 commit
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
40 changes: 40 additions & 0 deletions test/account/utils/draft-ERC7579Utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,3 +397,43 @@ describe('ERC7579Utils', function () {
});
});
});

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',
);
});
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

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.

Suggested change
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.

Loading