Skip to content

Commit

Permalink
Replace hardhat integration tests with lower-level test
Browse files Browse the repository at this point in the history
  • Loading branch information
fvictorio committed May 10, 2024
1 parent 6d3f571 commit c718a68
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 54 deletions.
10 changes: 10 additions & 0 deletions crates/edr_napi/test/helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { TracingMessage, TracingMessageResult, TracingStep } from "..";

/**
* Given a trace, return only its steps.
*/
export function collectSteps(
trace: Array<TracingMessage | TracingStep | TracingMessageResult>
): TracingStep[] {
return trace.filter((traceItem) => "pc" in traceItem) as TracingStep[];
}
105 changes: 104 additions & 1 deletion crates/edr_napi/test/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
SpecId,
SubscriptionEvent,
} from "..";
import { collectSteps } from "./helpers";

chai.use(chaiAsPromised);

Expand Down Expand Up @@ -36,7 +37,13 @@ describe("Provider", () => {
chainId: 123n,
chains: [],
coinbase: Buffer.from("0000000000000000000000000000000000000000", "hex"),
genesisAccounts: [],
genesisAccounts: [
{
secretKey:
"0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80",
balance: 1000n * 10n ** 18n,
},
],
hardfork: SpecId.Latest,
initialBlobGas: {
gasUsed: 0n,
Expand Down Expand Up @@ -102,4 +109,100 @@ describe("Provider", () => {

await assert.isFulfilled(provider);
});

describe("verbose mode", function () {
it("should only include the top of the stack by default", async function () {
const provider = await Provider.withConfig(
context,
providerConfig,
loggerConfig,
(_event: SubscriptionEvent) => {}
);

const responseObject = await provider.handleRequest(
JSON.stringify({
id: 1,
jsonrpc: "2.0",
method: "eth_sendTransaction",
params: [
{
from: "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
// PUSH1 1
// PUSH1 2
// PUSH1 3
// STOP
data: "60016002600300",
},
],
})
);

const rawTraces = responseObject.traces;
assert.lengthOf(rawTraces, 1);

const trace = rawTraces[0].trace();
const steps = collectSteps(trace);

assert.lengthOf(steps, 4);

// verbose tracing is disabled, so none of the steps should have a stack
assert.isTrue(steps.every((step) => step.stack === undefined));

assert.isUndefined(steps[0].stackTop);
assert.equal(steps[1].stackTop, 1n);
assert.equal(steps[2].stackTop, 2n);
assert.equal(steps[3].stackTop, 3n);
});

it("should only include the whole stack if verbose mode is enabled", async function () {
const provider = await Provider.withConfig(
context,
providerConfig,
loggerConfig,
(_event: SubscriptionEvent) => {}
);

provider.setVerboseTracing(true);

const responseObject = await provider.handleRequest(
JSON.stringify({
id: 1,
jsonrpc: "2.0",
method: "eth_sendTransaction",
params: [
{
from: "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
// PUSH1 1
// PUSH1 2
// PUSH1 3
// STOP
data: "60016002600300",
},
],
})
);

const rawTraces = responseObject.traces;
assert.lengthOf(rawTraces, 1);

const trace = rawTraces[0].trace();
const steps = collectSteps(trace);

assert.lengthOf(steps, 4);

// verbose tracing is enabled, so all steps should have a stack
assert.isTrue(steps.every((step) => step.stack !== undefined));

// same assertions as when verbose tracing is disabled
assert.isUndefined(steps[0].stackTop);
assert.equal(steps[1].stackTop, 1n);
assert.equal(steps[2].stackTop, 2n);
assert.equal(steps[3].stackTop, 3n);

assert.deepEqual(steps[0].stack, []);
assert.deepEqual(steps[1].stack, [1n]);
assert.deepEqual(steps[2].stack, [1n, 2n]);
assert.deepEqual(steps[3].stack, [1n, 2n, 3n]);
});
});
});
12 changes: 0 additions & 12 deletions hardhat-tests/integration/smock/contracts/FooBar.sol

This file was deleted.

6 changes: 0 additions & 6 deletions hardhat-tests/integration/smock/hardhat.config.js

This file was deleted.

17 changes: 0 additions & 17 deletions hardhat-tests/integration/smock/package.json

This file was deleted.

18 changes: 0 additions & 18 deletions hardhat-tests/integration/smock/test/test.js

This file was deleted.

0 comments on commit c718a68

Please sign in to comment.