Skip to content

Commit

Permalink
Merge pull request #166 from yohamta/add-hascode
Browse files Browse the repository at this point in the history
autoload: Add `hasCode` property to `AutoloadResult` type
  • Loading branch information
shazow authored Jan 7, 2025
2 parents 6294a53 + 8e6ad7c commit 3ab9a2d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/__tests__/auto.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ test('autoload throws typed error', async () => {
await expect(autoload("abc.eth", { provider: fakeProvider })).rejects.toThrow(/Failed to resolve ENS/);
});

test('autoload sets hasCode to false if code is empty', async () => {
const fakeProvider = (code: string) => ({
request: () => code,
});
const address = "0x00000000219ab540356cBB839Cbe05303d7705Fa"
await expect(autoload(address, { provider: fakeProvider("0x") })).resolves.toMatchObject({ hasCode: false });
await expect(autoload(address, { provider: fakeProvider("0x1234") })).resolves.toMatchObject({ hasCode: true });
});

online_test('autoload selectors', async ({ provider }) => {
const address = "0x4A137FD5e7a256eF08A7De531A17D0BE0cc7B6b6"; // Random unverified contract
const { abi } = await autoload(address, {
Expand Down
7 changes: 6 additions & 1 deletion src/auto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ export type AutoloadResult = {
* @experimental
*/
isFactory?: boolean;

/** Set to true if the address has deployed code */
hasCode: boolean;
}


Expand Down Expand Up @@ -157,6 +160,7 @@ export async function autoload(address: string, config: AutoloadConfig): Promise
address,
abi: [],
proxies: [],
hasCode: false,
};

let abiLoader = config.abiLoader;
Expand Down Expand Up @@ -191,7 +195,8 @@ export async function autoload(address: string, config: AutoloadConfig): Promise
},
);
}
if (!bytecode) return result; // Must be an EOA
if (!bytecode || bytecode === "0x") return result; // Must be an EOA
result.hasCode = true;

const program = disasm(bytecode);

Expand Down

0 comments on commit 3ab9a2d

Please sign in to comment.