Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
Loading