Skip to content

Commit

Permalink
more test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Filipp Makarov authored and Filipp Makarov committed Oct 10, 2023
1 parent 62f483f commit 58cd767
Show file tree
Hide file tree
Showing 2 changed files with 172 additions and 3 deletions.
150 changes: 147 additions & 3 deletions test/module/BatchedSessionRouter.Module.specs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@ import {
getMockToken,
getEcdsaOwnershipRegistryModule,
getSmartAccountWithModule,
getVerifyingPaymaster,
} from "../utils/setupHelper";
import { computeAddress } from "ethers/lib/utils";
import { computeAddress, defaultAbiCoder } from "ethers/lib/utils";

describe("SessionKey: Batched Session Router", async () => {
const [

Check failure on line 20 in test/module/BatchedSessionRouter.Module.specs.ts

View workflow job for this annotation

GitHub Actions / Lint sources (18.x)

Replace `⏎····deployer,⏎····smartAccountOwner,⏎····alice,⏎····sessionKey,⏎····nonAuthSessionKey,` with `deployer,·smartAccountOwner,·alice,·sessionKey,·nonAuthSessionKey]·=`
deployer,
smartAccountOwner,
alice,
verifiedSigner,
sessionKey,
nonAuthSessionKey,
] = waffle.provider.getWallets();

Check failure on line 26 in test/module/BatchedSessionRouter.Module.specs.ts

View workflow job for this annotation

GitHub Actions / Lint sources (18.x)

Replace `]·=` with `·`
Expand Down Expand Up @@ -1107,5 +1105,151 @@ describe("SessionKey: Batched Session Router", async () => {
);
expect(validationData).to.equal(SIG_VALIDATION_FAILED);
});

it("Should return SIG_VALIDATION_FAILED if the userOp.signature length is less than 65", async () => {
const {
entryPoint,
userSA,
sessionKeyManager,
erc20SessionModule,
sessionKeyData,
leafData,
merkleTree,
sessionRouter,
mockProtocol,
mockProtocolSVM,
mockToken,
sessionKeyData2,
leafData2,
validUntilForMockProtocol,
} = await setupTests();

const SIG_VALIDATION_FAILED = 1;
const tokenAmountToTransfer = ethers.utils.parseEther("1.7534");

const MockProtocol = await ethers.getContractFactory("MockProtocol");
const IERC20 = await ethers.getContractFactory("ERC20");

const approveCallData = IERC20.interface.encodeFunctionData("approve", [
mockProtocol.address,
tokenAmountToTransfer,
]);
const interactCallData = MockProtocol.interface.encodeFunctionData(
"interact",
[mockToken.address, tokenAmountToTransfer]
);


Check failure on line 1142 in test/module/BatchedSessionRouter.Module.specs.ts

View workflow job for this annotation

GitHub Actions / Lint sources (18.x)

Delete `⏎······`
/*
const userOp = await makeEcdsaSessionKeySignedBatchUserOp(
"executeBatch_y6U",
[
[mockToken.address, mockProtocol.address],
[0, 0],
[approveCallData, interactCallData],
],
userSA.address,
sessionKey,
entryPoint,
sessionKeyManager.address,
[
[
0,
0,
erc20SessionModule.address,
sessionKeyData,
merkleTree.getHexProof(ethers.utils.keccak256(leafData)),
"0x",
],
[
validUntilForMockProtocol,
0,
mockProtocolSVM.address,
sessionKeyData2,
merkleTree.getHexProof(ethers.utils.keccak256(leafData2)),
"0x",
],
],
sessionRouter.address
);
*/

const SmartAccount = await ethers.getContractFactory("SmartAccount");

const txnDataAA1 = SmartAccount.interface.encodeFunctionData(
"executeBatch_y6U",
[
[mockToken.address, mockProtocol.address],
[0, 0],
[approveCallData, interactCallData],
]
);

const userOp = await fillAndSign(
{
sender: userSA.address,
callData: txnDataAA1,
},
sessionKey,
entryPoint,
"nonce"
);

const userOpHash = await entryPoint.getUserOpHash(userOp);
const userOpHashAndModuleAddress = ethers.utils.hexConcat([
ethers.utils.hexZeroPad(userOpHash, 32),
ethers.utils.hexZeroPad(sessionKeyManager.address, 20),
]);
const resultingHash = ethers.utils.keccak256(userOpHashAndModuleAddress);
const signatureOverUserOpHashAndModuleAddress = (await sessionKey.signMessage(

Check failure on line 1204 in test/module/BatchedSessionRouter.Module.specs.ts

View workflow job for this annotation

GitHub Actions / Lint sources (18.x)

Replace `await·sessionKey.signMessage(⏎········ethers.utils.arrayify(resultingHash)` with `⏎········await·sessionKey.signMessage(ethers.utils.arrayify(resultingHash))`
ethers.utils.arrayify(resultingHash)
)).slice(0, -2);

Check failure on line 1206 in test/module/BatchedSessionRouter.Module.specs.ts

View workflow job for this annotation

GitHub Actions / Lint sources (18.x)

Delete `)`

const sessionData = [
[
0,
0,
erc20SessionModule.address,
sessionKeyData,
merkleTree.getHexProof(ethers.utils.keccak256(leafData)),
"0x",
],
[
validUntilForMockProtocol,
0,
mockProtocolSVM.address,
sessionKeyData2,
merkleTree.getHexProof(ethers.utils.keccak256(leafData2)),
"0x",
],
]

Check failure on line 1225 in test/module/BatchedSessionRouter.Module.specs.ts

View workflow job for this annotation

GitHub Actions / Lint sources (18.x)

Insert `;`

const paddedSig = defaultAbiCoder.encode(
[
"address",
"tuple(uint48,uint48,address,bytes,bytes32[],bytes)[]",
"bytes",
],
[
sessionKeyManager.address,
sessionData,
signatureOverUserOpHashAndModuleAddress,
]
);

const signatureWithModuleAddress = ethers.utils.defaultAbiCoder.encode(
["bytes", "address"],
[paddedSig, sessionRouter.address]
);
userOp.signature = signatureWithModuleAddress;

await expect(
sessionRouter.validateUserOp(

Check failure on line 1247 in test/module/BatchedSessionRouter.Module.specs.ts

View workflow job for this annotation

GitHub Actions / Lint sources (18.x)

Replace `⏎··········userOp,⏎··········userOpHash⏎········` with `userOp,·userOpHash`
userOp,
userOpHash
)
).to.be.revertedWith("ECDSA: invalid signature length");
});

Check failure on line 1252 in test/module/BatchedSessionRouter.Module.specs.ts

View workflow job for this annotation

GitHub Actions / Lint sources (18.x)

Delete `⏎`

});
});
25 changes: 25 additions & 0 deletions test/module/SessionKeyManager.Module.specs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,31 @@ describe("SessionKey: SessionKey Manager Module", async () => {
);
});

it("should revert if the module has not been set up for the smart account", async () => {
const {
userSA,
sessionKeyManager,
mockSessionValidationModule,
sessionKeyData,
leafData,
merkleTree,
} = await setupTests();

const validateSesionKeyTxn =
sessionKeyManager.callStatic.validateSessionKey(
alice.address,
0,
0,
mockSessionValidationModule.address,
sessionKeyData,
merkleTree.getHexProof(ethers.utils.keccak256(leafData))
);

await expect(validateSesionKeyTxn).to.be.revertedWith(
"SessionNotApproved"
);
});

it("should not revert otherwise", async () => {
const {
userSA,
Expand Down

0 comments on commit 58cd767

Please sign in to comment.