Skip to content

Commit

Permalink
proxies: Add more tests, capture revert exception more generally
Browse files Browse the repository at this point in the history
  • Loading branch information
shazow committed Sep 11, 2023
1 parent c481851 commit 3c40b49
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
45 changes: 43 additions & 2 deletions src/__tests__/proxies.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test, describe, expect } from '@jest/globals';

import {online_test } from './env';
import { cached_test, online_test } from './env';

import { disasm } from '../disasm';
import * as proxies from '../proxies';
Expand Down Expand Up @@ -64,7 +64,7 @@ describe('proxy detection', () => {
});
});

describe('proxy resolving', () => {
describe('known proxy resolving', () => {
online_test('Safe: Proxy Factory 1.1.1', async ({ provider }) => {
const address = "0x655a9e6b044d6b62f393f9990ec3ea877e966e18";
// Need to call masterCopy() or getStorageAt for 0th slot
Expand Down Expand Up @@ -105,3 +105,44 @@ describe('proxy resolving', () => {
//online_test('SequenceWallet Proxy', async() => {
//});
});


describe('contract proxy resolving', () => {
cached_test('Create2Beacon Proxy', async ({ provider, withCache }) => {
const address = "0x581acd618ba7ef6d3585242423867adc09e8ed60";
const code = await withCache(
`${address}_code`,
async () => {
return await provider.getCode(address)
},
)

const program = disasm(code);
expect(program.proxies.length).toEqual(1);

const resolver = program.proxies[0];
const got = await resolver.resolve(provider, address);

const wantImplementation = "0xaddc3e67a500f7037cd622b11df291a6351bfb64";
expect(got).toEqual(wantImplementation);
});

cached_test('Vyper Minimal Proxy', async ({ provider, withCache }) => {
const address = "0x2d5d4869381c4fce34789bc1d38acce747e295ae";
const code = await withCache(
`${address}_code`,
async () => {
return await provider.getCode(address)
},
)

const program = disasm(code);
expect(program.proxies.length).toEqual(1);

const resolver = program.proxies[0];
const got = await resolver.resolve(provider, address);

const wantImplementation = "0x9c13e225ae007731caa49fd17a41379ab1a489f4";
expect(got).toEqual(wantImplementation);
});
});
4 changes: 2 additions & 2 deletions src/proxies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class EIP1967ProxyResolver extends BaseProxyResolver implements ProxyReso
}));
if (addr !== _zeroAddress) return addr;
} catch (e: any) {
if (e.toString().includes("reverted")) continue;
if (e.toString().includes("revert")) continue;
throw e;
}
}
Expand Down Expand Up @@ -125,7 +125,7 @@ export class DiamondProxyResolver extends BaseProxyResolver implements ProxyReso
}));
if (addr !== _zeroAddress) return addr;
} catch (e: any) {
if (e.toString().includes("reverted")) continue;
if (e.toString().includes("revert")) continue;
throw e;
}
}
Expand Down

0 comments on commit 3c40b49

Please sign in to comment.