|
@@ -2,13 +2,13 @@ const { ethers } = require('hardhat');
|
|
|
const { expect } = require('chai');
|
|
|
const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers');
|
|
|
|
|
|
-const { packValidationData, packPaymasterData, UserOperation } = require('../../helpers/erc4337');
|
|
|
+const { packValidationData, UserOperation } = require('../../helpers/erc4337');
|
|
|
const { MAX_UINT48 } = require('../../helpers/constants');
|
|
|
|
|
|
const fixture = async () => {
|
|
|
- const [authorizer, sender, entrypoint, paymaster] = await ethers.getSigners();
|
|
|
+ const [authorizer, sender, entrypoint, factory, paymaster] = await ethers.getSigners();
|
|
|
const utils = await ethers.deployContract('$ERC4337Utils');
|
|
|
- return { utils, authorizer, sender, entrypoint, paymaster };
|
|
|
+ return { utils, authorizer, sender, entrypoint, factory, paymaster };
|
|
|
};
|
|
|
|
|
|
describe('ERC4337Utils', function () {
|
|
@@ -144,6 +144,33 @@ describe('ERC4337Utils', function () {
|
|
|
});
|
|
|
|
|
|
describe('userOp values', function () {
|
|
|
+ describe('intiCode', function () {
|
|
|
+ beforeEach(async function () {
|
|
|
+ this.userOp = new UserOperation({
|
|
|
+ sender: this.sender,
|
|
|
+ nonce: 1,
|
|
|
+ verificationGas: 0x12345678n,
|
|
|
+ factory: this.factory,
|
|
|
+ factoryData: '0x123456',
|
|
|
+ });
|
|
|
+
|
|
|
+ this.emptyUserOp = new UserOperation({
|
|
|
+ sender: this.sender,
|
|
|
+ nonce: 1,
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ it('returns factory', async function () {
|
|
|
+ expect(this.utils.$factory(this.userOp.packed)).to.eventually.equal(this.factory);
|
|
|
+ expect(this.utils.$factory(this.emptyUserOp.packed)).to.eventually.equal(ethers.ZeroAddress);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('returns factoryData', async function () {
|
|
|
+ expect(this.utils.$factoryData(this.userOp.packed)).to.eventually.equal('0x123456');
|
|
|
+ expect(this.utils.$factoryData(this.emptyUserOp.packed)).to.eventually.equal('0x');
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
it('returns verificationGasLimit', async function () {
|
|
|
const userOp = new UserOperation({ sender: this.sender, nonce: 1, verificationGas: 0x12345678n });
|
|
|
expect(this.utils.$verificationGasLimit(userOp.packed)).to.eventually.equal(userOp.verificationGas);
|
|
@@ -176,28 +203,43 @@ describe('ERC4337Utils', function () {
|
|
|
|
|
|
describe('paymasterAndData', function () {
|
|
|
beforeEach(async function () {
|
|
|
- this.verificationGasLimit = 0x12345678n;
|
|
|
- this.postOpGasLimit = 0x87654321n;
|
|
|
- this.paymasterAndData = packPaymasterData(this.paymaster, this.verificationGasLimit, this.postOpGasLimit);
|
|
|
this.userOp = new UserOperation({
|
|
|
sender: this.sender,
|
|
|
nonce: 1,
|
|
|
- paymasterAndData: this.paymasterAndData,
|
|
|
+ paymaster: this.paymaster,
|
|
|
+ paymasterVerificationGasLimit: 0x12345678n,
|
|
|
+ paymasterPostOpGasLimit: 0x87654321n,
|
|
|
+ paymasterData: '0xbeefcafe',
|
|
|
+ });
|
|
|
+
|
|
|
+ this.emptyUserOp = new UserOperation({
|
|
|
+ sender: this.sender,
|
|
|
+ nonce: 1,
|
|
|
});
|
|
|
});
|
|
|
|
|
|
it('returns paymaster', async function () {
|
|
|
- expect(this.utils.$paymaster(this.userOp.packed)).to.eventually.equal(this.paymaster);
|
|
|
+ expect(this.utils.$paymaster(this.userOp.packed)).to.eventually.equal(this.userOp.paymaster);
|
|
|
+ expect(this.utils.$paymaster(this.emptyUserOp.packed)).to.eventually.equal(ethers.ZeroAddress);
|
|
|
});
|
|
|
|
|
|
it('returns verificationGasLimit', async function () {
|
|
|
expect(this.utils.$paymasterVerificationGasLimit(this.userOp.packed)).to.eventually.equal(
|
|
|
- this.verificationGasLimit,
|
|
|
+ this.userOp.paymasterVerificationGasLimit,
|
|
|
);
|
|
|
+ expect(this.utils.$paymasterVerificationGasLimit(this.emptyUserOp.packed)).to.eventually.equal(0n);
|
|
|
});
|
|
|
|
|
|
it('returns postOpGasLimit', async function () {
|
|
|
- expect(this.utils.$paymasterPostOpGasLimit(this.userOp.packed)).to.eventually.equal(this.postOpGasLimit);
|
|
|
+ expect(this.utils.$paymasterPostOpGasLimit(this.userOp.packed)).to.eventually.equal(
|
|
|
+ this.userOp.paymasterPostOpGasLimit,
|
|
|
+ );
|
|
|
+ expect(this.utils.$paymasterPostOpGasLimit(this.emptyUserOp.packed)).to.eventually.equal(0n);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('returns data', async function () {
|
|
|
+ expect(this.utils.$paymasterData(this.userOp.packed)).to.eventually.equal(this.userOp.paymasterData);
|
|
|
+ expect(this.utils.$paymasterData(this.emptyUserOp.packed)).to.eventually.equal('0x');
|
|
|
});
|
|
|
});
|
|
|
});
|