Skip to content

Commit

Permalink
allow eip 7702 delegation prefix in is-contract check (fix #308)
Browse files Browse the repository at this point in the history
  • Loading branch information
pk910 committed Nov 5, 2024
1 parent 40736e2 commit dbe2f71
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/eth/EthWalletManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ export class EthWalletManager {
}

public checkIsContract(addr: string): Promise<boolean> {
return this.web3.eth.getCode(addr).then((res) => res && !!res.match(/^0x[0-9a-f]{2,}$/));
return this.web3.eth.getCode(addr).then((res) => res && !!res.match(/^0x[0-9a-f]{2,}$/) && !res.match(/^0xef0100/));
}

public getFaucetBalance(native?: boolean): bigint | null {
Expand Down
22 changes: 22 additions & 0 deletions tests/modules/EthInfoModule.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,26 @@ describe("Faucet module: ethinfo", () => {
expect(error?.getCode()).to.equal("CONTRACT_ADDR", "unexpected error code");
});

it("Start session for wallet with eip7702 delegation", async () => {
faucetConfig.modules["ethinfo"] = {
enabled: true,
maxBalance: 1000,
denyContract: true,
} as IEthInfoConfig;
fakeProvider.injectResponse("eth_getBalance", "1000");
fakeProvider.injectResponse("eth_getCode", "0xef010012345678");
await ServiceManager.GetService(ModuleManager).initialize();
let sessionManager = ServiceManager.GetService(SessionManager);
let testSession = await sessionManager.createSession("::ffff:8.8.8.8", {
addr: "0x0000000000000000000000000000000000001337",
});
expect(testSession.getSessionStatus()).to.equal("claimable", "unexpected session status");
let balanceReq = fakeProvider.getLastRequest("eth_getBalance");
expect(balanceReq).to.not.equal(null, "no eth_getBalance request");
expect(balanceReq.params[0]).to.equal("0x0000000000000000000000000000000000001337", "unexpected target address in eth_getBalance request");
let codeReq = fakeProvider.getLastRequest("eth_getCode");
expect(codeReq).to.not.equal(null, "no eth_getCode request");
expect(codeReq.params[0]).to.equal("0x0000000000000000000000000000000000001337", "unexpected target address in eth_getCode request");
});

});

0 comments on commit dbe2f71

Please sign in to comment.