Skip to content
This repository was archived by the owner on Feb 18, 2025. It is now read-only.

Commit

Permalink
Merge pull request #17 from NilFoundation/fix-hardhat-test-deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
dmtrskv authored Jul 15, 2024
2 parents 17df997 + 58aa05a commit dc3b5e6
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 30 additions & 3 deletions src/handlers/blockNumber.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,40 @@
import type { HandlerContext } from "../context";
import { executeOriginalFunction } from "../interceptors";
import { shardNumber } from "../utils/conversion";

export async function blockNumber(
method: string,
params: any[],
context: HandlerContext,
) {
const preparedMethod = "eth_getBlockByNumber";
if (context.debug) {
console.log(`Method ${method} params ${JSON.stringify(params)}`);
console.log("Response 0x0");
console.log("Method", preparedMethod);
}
return "0x0";
const result = await executeOriginalFunction(
preparedMethod,
prepareInput(context),
context,
);
const adaptResponse = adaptResult(result);
if (context.debug) {
console.log("Response", JSON.stringify(adaptResponse));
}
return adaptResponse;
}

function prepareInput(context: HandlerContext): any[] {
return [
context.hre.config.shardId ?? shardNumber(context.wallet.getAddressHex()),
"latest",
false,
];
}

function adaptResult(result: any): any {
if (!result) {
return "0x0";
}

return result.number;
}
7 changes: 6 additions & 1 deletion src/handlers/getTransactionByHash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export async function getTransactionByHash(
);
const adaptResponse = adaptResult(result);
if (context.debug) {
console.log(`Response ${adaptResponse}`);
console.log(`Response ${JSON.stringify(adaptResponse)}`);
}
return adaptResponse;
}
Expand Down Expand Up @@ -76,6 +76,11 @@ function adaptResult(result: any): any {
}
}

if (result.signature === "0x") {
// Hardhat wants a signature, so we'll give it a fake one.
result.signature = `0x${"00".repeat(64)}`;
}

result.nonce = result.seqno;
return result;
}

0 comments on commit dc3b5e6

Please sign in to comment.