Skip to content

Commit

Permalink
test(zk): check console.log passthru
Browse files Browse the repository at this point in the history
  • Loading branch information
Karrq committed Aug 26, 2024
1 parent 8cdea1e commit 4c366db
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions testdata/zk/Cheatcodes.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ contract Emitter {
function functionEmit() public {
emit EventFunction(FUNCTION_MESSAGE);
}

function emitConsole(string memory message) public view {
console.log(message);
}
}

contract ZkCheatcodesTest is DSTest {
Expand Down Expand Up @@ -235,6 +239,27 @@ contract ZkCheatcodesTest is DSTest {
assertEq(entries[10].data, abi.encode("function"));
// 11: EthToken
}

function testRecordConsoleLogsLikeEVM() public {
Emitter emitter = new Emitter();
vm.makePersistent(address(emitter));

// ensure we are in zkvm
(bool _success, bytes memory _ret) = address(vm).call(abi.encodeWithSignature("zkVm(bool)", true));

vm.recordLogs();
emitter.emitConsole("zkvm");
Vm.Log[] memory zkvmEntries = vm.getRecordedLogs();

// ensure we are NOT in zkvm
(_success, _ret) = address(vm).call(abi.encodeWithSignature("zkVm(bool)", false));

vm.recordLogs();
emitter.emitConsole("evm");
Vm.Log[] memory evmEntries = vm.getRecordedLogs();

assertEq(zkvmEntries.length, evmEntries.length);
}
}

contract UsesCheatcodes {
Expand Down

0 comments on commit 4c366db

Please sign in to comment.