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 15, 2024
1 parent 7f92009 commit 238fe85
Showing 1 changed file with 20 additions and 25 deletions.
45 changes: 20 additions & 25 deletions test/historicstate/hardhat/scripts/trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ async function getTraceJsonOptions(_tracer: string): Promise<object> {

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_FILE_NAME = TEST_CONTRACT_NAME + ".transfer.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_CONTRACT_CALL_DEFAULTTRACER_FILE_NAME = TEST_CONTRACT_NAME + "." + CALL_FUNCTION_NAME + ".defaultTracer.json";
const TEST_CONTRACT_CALL_CALLTRACER_FILE_NAME = TEST_CONTRACT_NAME + "." + CALL_FUNCTION_NAME + ".callTracer.json";
const TEST_CONTRACT_CALL_PRESTATETRACER_FILE_NAME = TEST_CONTRACT_NAME + "." + CALL_FUNCTION_NAME + ".prestateTracer.json";
Expand Down Expand Up @@ -144,13 +145,13 @@ async function getBlockTrace(blockNumber: number): Promise<String> {
const blockStr = "0x" + blockNumber.toString(16);
const trace = await ethers.provider.send('debug_traceBlockByNumber', [blockStr, {}]);

0// console.log(JSON.stringify(trace, null, 4));
0// console.log(JSON.stringify(trace, null, 4));
return trace;
}

async function getAndPrintTransactionTrace(hash: string, _skaleFileName: string): Promise<String> {
async function getAndPrintTransactionTrace(hash: string, _tracer: string, _skaleFileName: string): Promise<String> {

console.log("Calling debug_traceTransaction to generate " + _skaleFileName + " for tx " + hash);
console.log("Calling debug_traceTransaction to generate " + _skaleFileName);

const trace = await ethers.provider.send('debug_traceTransaction', [hash, {}]);

Expand All @@ -175,7 +176,7 @@ async function deployTestContract(): Promise<object> {
const hash = deployedTestContract.deployTransaction.hash;
console.log(`Contract deployed to ${deployedTestContract.address} at block ${deployBlockNumber.toString(16)} tx hash ${hash}`);

await getAndPrintTransactionTrace(hash, TEST_CONTRACT_DEPLOY_FILE_NAME);
await getAndPrintTransactionTrace(hash, DEFAULT_TRACER, TEST_CONTRACT_DEPLOY_FILE_NAME);

return deployedTestContract;

Expand All @@ -194,8 +195,6 @@ function sleep(ms: number) {
}




async function sendMoneyWithoutConfirmation(): Promise<int> {
// Generate a new wallet
const newWallet = generateNewWallet();
Expand All @@ -217,7 +216,7 @@ async function sendMoneyWithoutConfirmation(): Promise<int> {
// Send the transaction and wait until it is submitted ot the queue
const txResponse = signer.sendTransaction(tx);

if (hre.network.name == "geth") {
if (hre.network.name == "geth") {
await txResponse;
}

Expand All @@ -226,7 +225,7 @@ async function sendMoneyWithoutConfirmation(): Promise<int> {
return currentNonce;
}

async function sendMoneyWithConfirmation() : Promise<string> {
async function sendMoneyWithConfirmation(): Promise<string> {
// Generate a new wallet
const newWallet = generateNewWallet();

Expand All @@ -253,10 +252,9 @@ async function sendMoneyWithConfirmation() : Promise<string> {
}



async function callTestContractRun(deployedContract: any): Promise<void> {

let currentNonce : int = await sendMoneyWithoutConfirmation();
let currentNonce: int = await sendMoneyWithoutConfirmation();

const transferReceipt = await deployedContract[RUN_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
Expand All @@ -266,11 +264,11 @@ async function callTestContractRun(deployedContract: any): Promise<void> {
expect(transferReceipt.blockNumber).not.to.be.null;


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

const transferHash : string = await sendMoneyWithConfirmation();
await getAndPrintTransactionTrace(transferHash, TEST_TRANSFER_FILE_NAME);
const transferHash: string = await sendMoneyWithConfirmation();
await getAndPrintTransactionTrace(transferHash, DEFAULT_TRACER, TEST_TRANSFER_DEFAULTTRACER_FILE_NAME);


}
Expand Down Expand Up @@ -341,7 +339,7 @@ async function readJSONFile(fileName: string): Promise<object> {

async function verifyDefaultTraceAgainstGethTrace(_fileName: string) {

console.log("Verifying " + _fileName);
console.log("Verifying " + _fileName);

const _expectedResultFileName = GETH_TRACES_DIR + _fileName;
const _actualResultFileName = SKALE_TRACES_DIR + _fileName;
Expand Down Expand Up @@ -391,7 +389,7 @@ async function verifyDefaultTraceAgainstGethTrace(_fileName: string) {

async function verifyDefaultTransferTraceAgainstGethTrace(_fileName: string) {

console.log("Verifying " + _fileName);
console.log("Verifying " + _fileName);

const _expectedResultFileName = GETH_TRACES_DIR + _fileName;
const _actualResultFileName = SKALE_TRACES_DIR + _fileName;
Expand All @@ -417,7 +415,7 @@ async function verifyDefaultTransferTraceAgainstGethTrace(_fileName: string) {

async function verifyCallTraceAgainstGethTrace(_fileName: string) {

console.log("Verifying " + _fileName);
console.log("Verifying " + _fileName);

const _expectedResultFileName = GETH_TRACES_DIR + _fileName;
const _actualResultFileName = SKALE_TRACES_DIR + _fileName;
Expand Down Expand Up @@ -453,7 +451,7 @@ async function verifyCallTraceAgainstGethTrace(_fileName: string) {

async function verifyFourByteTraceAgainstGethTrace(_fileName: string) {

console.log("Verifying " + _fileName);
console.log("Verifying " + _fileName);

const _expectedResultFileName = GETH_TRACES_DIR + _fileName;
const _actualResultFileName = SKALE_TRACES_DIR + _fileName;
Expand Down Expand Up @@ -484,7 +482,7 @@ async function verifyFourByteTraceAgainstGethTrace(_fileName: string) {

async function verifyPrestateTraceAgainstGethTrace(_fileName: string) {

console.log("Verifying " + _fileName);
console.log("Verifying " + _fileName);

const _expectedResultFileName = GETH_TRACES_DIR + _fileName;
const _actualResultFileName = SKALE_TRACES_DIR + _fileName;
Expand Down Expand Up @@ -518,7 +516,7 @@ async function verifyPrestateTraceAgainstGethTrace(_fileName: string) {

async function verifyPrestateDiffTraceAgainstGethTrace(_fileName: string) {

console.log("Verifying " + _fileName);
console.log("Verifying " + _fileName);

const _expectedResultFileName = GETH_TRACES_DIR + _fileName;
const _actualResultFileName = SKALE_TRACES_DIR + _fileName;
Expand Down Expand Up @@ -546,9 +544,6 @@ async function verifyPrestateDiffTraceAgainstGethTrace(_fileName: string) {
}





async function verifyGasCalculations(_actualResult: any): Promise<void> {
let structLogs: object[] = _actualResult.structLogs;
expect(structLogs.length > 0)
Expand Down Expand Up @@ -586,12 +581,12 @@ async function main(): Promise<void> {


// geth does not have replay trace
if ( hre.network.name != "geth") {
if (hre.network.name != "geth") {
await callDebugTraceCall(deployedContract, REPLAY_TRACER, TEST_CONTRACT_CALL_REPLAYTRACER_FILE_NAME);
}


await verifyDefaultTransferTraceAgainstGethTrace(TEST_TRANSFER_FILE_NAME)
await verifyDefaultTransferTraceAgainstGethTrace(TEST_TRANSFER_DEFAULTTRACER_FILE_NAME)

await verifyDefaultTraceAgainstGethTrace(TEST_CONTRACT_DEPLOY_FILE_NAME)
await verifyDefaultTraceAgainstGethTrace(TEST_CONTRACT_RUN_FILE_NAME)
Expand Down

0 comments on commit 238fe85

Please sign in to comment.