Skip to content

Commit

Permalink
#1751 case where no contract is called
Browse files Browse the repository at this point in the history
  • Loading branch information
kladkogex committed Jan 22, 2024
1 parent da9bf68 commit 36a18b3
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions test/historicstate/hardhat/scripts/trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const CALL_ADDRESS: string = "0xCe5c7ca85F8cB94FA284a303348ef42ADD23f5e7";
const ZERO_ADDRESS: string = '0x0000000000000000000000000000000000000000';
const INITIAL_MINT: bigint = 10000000000000000000000000000000000000000n;
const TEST_CONTRACT_NAME = "Tracer";
const RUN_FUNCTION_NAME = "mint";
const EXECUTE_FUNCTION_NAME = "mint";
const CALL_FUNCTION_NAME = "getBalance";

const SKALE_TRACES_DIR = "/tmp/skale_traces/"
Expand All @@ -28,20 +28,12 @@ let FOURBYTE_TRACER = "4byteTracer";
let REPLAY_TRACER = "replayTracer"


async function getTraceJsonOptions(_tracer: string): Promise<object> {
if (_tracer == DEFAULT_TRACER) {
return {};
}
const TEST_CONTRACT_DEPLOY_FILE_NAME = TEST_CONTRACT_NAME + ".deploy.defaultTracer.json";

if (_tracer == PRESTATEDIFF_TRACER) {
return {"tracer": PRESTATE_TRACER, "tracerConfig": {diffMode: true}};
}

return {"tracer": _tracer}
}
const TEST_CONTRACT_EXECUTE_DEFAULTTRACER_FILE_NAME = TEST_CONTRACT_NAME + "." + EXECUTE_FUNCTION_NAME + ".defaultTracer.json";


const TEST_CONTRACT_DEPLOY_FILE_NAME = TEST_CONTRACT_NAME + ".deploy.defaultTracer.json";
const TEST_CONTRACT_RUN_FILE_NAME = TEST_CONTRACT_NAME + "." + RUN_FUNCTION_NAME + ".defaultTracer.json";
const TEST_TRANSFER_DEFAULTTRACER_FILE_NAME = TEST_CONTRACT_NAME + ".transfer.defaultTracer.json";
const TEST_TRANSFER_CALLTRACER_FILE_NAME = TEST_CONTRACT_NAME + ".transfer.callTracer.json";
const TEST_TRANSFER_PRESTATETRACER_FILE_NAME = TEST_CONTRACT_NAME + ".transfer.prestateTracer.json";
Expand All @@ -56,6 +48,21 @@ const TEST_CONTRACT_CALL_PRESTATEDIFFTRACER_FILE_NAME = TEST_CONTRACT_NAME + "."
const TEST_CONTRACT_CALL_FOURBYTETRACER_FILE_NAME = TEST_CONTRACT_NAME + "." + CALL_FUNCTION_NAME + ".4byteTracer.json";
const TEST_CONTRACT_CALL_REPLAYTRACER_FILE_NAME = TEST_CONTRACT_NAME + "." + CALL_FUNCTION_NAME + ".replayTracer.json";


async function getTraceJsonOptions(_tracer: string): Promise<object> {
if (_tracer == DEFAULT_TRACER) {
return {};
}

if (_tracer == PRESTATEDIFF_TRACER) {
return {"tracer": PRESTATE_TRACER, "tracerConfig": {diffMode: true}};
}

return {"tracer": _tracer}
}



async function deleteAndRecreateDirectory(dirPath: string): Promise<void> {
try {
// Remove the directory and its contents
Expand Down Expand Up @@ -250,15 +257,15 @@ async function callTestContractRun(deployedContract: any): Promise<string> {

let currentNonce: int = await sendMoneyWithoutConfirmation();

const transferReceipt = await deployedContract[RUN_FUNCTION_NAME](1000, {
const transferReceipt = await deployedContract[EXECUTE_FUNCTION_NAME](1000, {
gasLimit: 2100000, // this is just an example value; you'll need to set an appropriate gas limit for your specific function call
nonce: currentNonce + 1,
});

expect(transferReceipt.blockNumber).not.to.be.null;


await getAndPrintCommittedTransactionTrace(transferReceipt.hash, DEFAULT_TRACER, TEST_CONTRACT_RUN_FILE_NAME);
await getAndPrintCommittedTransactionTrace(transferReceipt.hash, DEFAULT_TRACER, TEST_CONTRACT_EXECUTE_DEFAULTTRACER_FILE_NAME);
await getBlockTrace(transferReceipt.blockNumber);

const transferHash: string = await sendMoneyWithConfirmation();
Expand Down Expand Up @@ -657,7 +664,7 @@ async function verifyGasCalculations(_actualResult: any): Promise<void> {
async function main(): Promise<void> {

expect(existsSync(GETH_TRACES_DIR + TEST_CONTRACT_DEPLOY_FILE_NAME));
expect(existsSync(GETH_TRACES_DIR + TEST_CONTRACT_RUN_FILE_NAME));
expect(existsSync(GETH_TRACES_DIR + TEST_CONTRACT_EXECUTE_DEFAULTTRACER_FILE_NAME));
expect(existsSync(GETH_TRACES_DIR + TEST_CONTRACT_CALL_DEFAULTTRACER_FILE_NAME));

await deleteAndRecreateDirectory(SKALE_TRACES_DIR);
Expand Down Expand Up @@ -691,7 +698,7 @@ async function main(): Promise<void> {
await verifyTransferTraceAgainstGethTrace(TEST_TRANSFER_FOURBYTETRACER_FILE_NAME);

await verifyDefaultTraceAgainstGethTrace(TEST_CONTRACT_DEPLOY_FILE_NAME);
await verifyDefaultTraceAgainstGethTrace(TEST_CONTRACT_RUN_FILE_NAME);
await verifyDefaultTraceAgainstGethTrace(TEST_CONTRACT_EXECUTE_DEFAULTTRACER_FILE_NAME);
await verifyDefaultTraceAgainstGethTrace(TEST_CONTRACT_CALL_DEFAULTTRACER_FILE_NAME);
await verifyCallTraceAgainstGethTrace(TEST_CONTRACT_CALL_CALLTRACER_FILE_NAME);
await verifyFourByteTraceAgainstGethTrace(TEST_CONTRACT_CALL_FOURBYTETRACER_FILE_NAME);
Expand Down

0 comments on commit 36a18b3

Please sign in to comment.