Skip to content

Commit

Permalink
tests: Add benchmark for sevm
Browse files Browse the repository at this point in the history
  • Loading branch information
shazow committed Oct 18, 2023
1 parent eaf22e2 commit b722519
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
7 changes: 7 additions & 0 deletions src/__tests__/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,10 @@ export const cached_test = testerWithContext(!process.env["SKIP_CACHED"] ? test
if (process.env["ONLINE"] === undefined) {
console.log("Skipping online tests. Set ONLINE env to run them.");
}

export const KNOWN_ADDRESSES = [
{address: "0x7a250d5630b4cf539739df2c5dacb4c659f2488d", label: "Uniswap v2"},
{address: "0x00000000006c3852cbEf3e08E8dF289169EdE581", label: "Seaport v1.1"},
{address: "0x4A137FD5e7a256eF08A7De531A17D0BE0cc7B6b6", label: "Random unverified"},
{address: "0x000000000000Df8c944e775BDe7Af50300999283", label: "Has 0x0 selector"},
];
20 changes: 20 additions & 0 deletions src/__tests__/sevm.bench.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { describe, bench } from 'vitest';

import { describe_cached, KNOWN_ADDRESSES } from "./env";

import { Contract } from "sevm";
import { disasm } from "../disasm.js";

describe_cached("bench: whatsabi vs sevm", async ({ provider, withCache}) => {
describe.each(KNOWN_ADDRESSES)("decompile $address ($label)", async ({address}) => {
const code = await withCache(`${address}_code`, provider.getCode.bind(provider, address))

bench('disassemble with whatsabi', () => {
disasm(code);
})

bench('disassemble with sevm', () => {
new Contract(code);
})
});
});
12 changes: 3 additions & 9 deletions src/__tests__/sevm.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { expect, test, describe, bench } from 'vitest';
import { expect, test, describe } from 'vitest';

// @ts-ignore
import { Contract } from "sevm";

import type { ABI, ABIFunction, ABIEvent } from "../abi.js";

import { whatsabi } from "../index.js";
import { describe_cached } from "./env";
import { describe_cached, KNOWN_ADDRESSES } from "./env";

type sevmPublicFunction = {
readonly payable: boolean;
Expand Down Expand Up @@ -44,12 +44,7 @@ function abiFromBytecode(bytecode: string): ABI {

describe_cached("whatsabi vs sevm: abiFromBytecode", async ({ provider, withCache}) => {

describe.each([
{address: "0x7a250d5630b4cf539739df2c5dacb4c659f2488d"}, // Uniswap v2
{address: "0x00000000006c3852cbEf3e08E8dF289169EdE581"}, // Seaport v1.1
{address: "0x4A137FD5e7a256eF08A7De531A17D0BE0cc7B6b6"}, // Random unverified
{address: "0x000000000000Df8c944e775BDe7Af50300999283"}, // Has 0x0 selector
])("decompile $address", async ({address}) => {
describe.each(KNOWN_ADDRESSES)("decompile $address ($label)", async ({address}) => {

const code = await withCache(`${address}_code`, provider.getCode.bind(provider, address))

Expand All @@ -64,6 +59,5 @@ describe_cached("whatsabi vs sevm: abiFromBytecode", async ({ provider, withCach

expect(a).toStrictEqual(b);
});

});
});

0 comments on commit b722519

Please sign in to comment.