-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into nish-move-smoke-tests
- Loading branch information
Showing
12 changed files
with
494 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.13; | ||
|
||
import {Test, console2 as console} from "../../lib/forge-std/src/Test.sol"; | ||
import {Constants} from "./Constants.sol"; | ||
import {Utils} from "./Utils.sol"; | ||
|
||
contract FfiTest is Test { | ||
function testFfi() public { | ||
string[] memory inputs = new string[](3); | ||
inputs[0] = "bash"; | ||
inputs[1] = "-c"; | ||
inputs[ | ||
2 | ||
] = "echo -n 0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000966666920776f726b730000000000000000000000000000000000000000000000"; | ||
|
||
(bool success, bytes memory rawData) = Constants.CHEATCODE_ADDRESS.call( | ||
abi.encodeWithSignature("ffi(string[])", inputs) | ||
); | ||
require(success, "ffi failed"); | ||
|
||
bytes memory data = Utils.trimReturnBytes(rawData); | ||
string memory output = abi.decode(data, (string)); | ||
require( | ||
keccak256(bytes(output)) == keccak256(bytes("ffi works")), | ||
"ffi failed" | ||
); | ||
|
||
console.log("failed?", failed()); | ||
} | ||
|
||
function testFfiString() public { | ||
string[] memory inputs = new string[](3); | ||
inputs[0] = "echo"; | ||
inputs[1] = "-n"; | ||
inputs[2] = "gm"; | ||
|
||
(bool success, bytes memory rawData) = Constants.CHEATCODE_ADDRESS.call( | ||
abi.encodeWithSignature("ffi(string[])", inputs) | ||
); | ||
require(success, "ffi failed"); | ||
bytes memory data = Utils.trimReturnBytes(rawData); | ||
require(keccak256(data) == keccak256(bytes("gm")), "ffi failed"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.13; | ||
|
||
import {Test, console2 as console} from "../../lib/forge-std/src/Test.sol"; | ||
import {Constants} from "./Constants.sol"; | ||
import {Utils} from "./Utils.sol"; | ||
|
||
contract FsTest is Test { | ||
function testReadFile() public { | ||
string memory path = "src/fixtures/File/read.txt"; | ||
|
||
(bool success, bytes memory rawData) = Constants.CHEATCODE_ADDRESS.call( | ||
abi.encodeWithSignature("readFile(string)", path) | ||
); | ||
require(success, "readFile failed"); | ||
|
||
bytes memory data = Utils.trimReturnBytes(rawData); | ||
|
||
require( | ||
keccak256(data) == | ||
keccak256("hello readable world\nthis is the second line!\n"), | ||
"read data did not match expected data" | ||
); | ||
console.log("failed?", failed()); | ||
} | ||
|
||
function testWriteFile() public { | ||
string memory path = "src/fixtures/File/write_file.txt"; | ||
string memory writeData = "hello writable world"; | ||
|
||
(bool success, ) = Constants.CHEATCODE_ADDRESS.call( | ||
abi.encodeWithSignature("writeFile(string,string)", path, writeData) | ||
); | ||
require(success, "writeFile failed"); | ||
|
||
bytes memory readRawData; | ||
(success, readRawData) = Constants.CHEATCODE_ADDRESS.call( | ||
abi.encodeWithSignature("readFile(string)", path) | ||
); | ||
require(success, "readFile failed"); | ||
|
||
bytes memory readData = Utils.trimReturnBytes(readRawData); | ||
|
||
require( | ||
keccak256(readData) == keccak256(bytes(writeData)), | ||
"read data did not match write data" | ||
); | ||
console.log("failed?", failed()); | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
crates/era-cheatcodes/tests/src/cheatcodes/ReadCallers.t.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.13; | ||
|
||
import {Test, console2 as console} from "../../lib/forge-std/src/Test.sol"; | ||
import {Constants} from "./Constants.sol"; | ||
|
||
contract CheatcodeReadCallers is Test { | ||
address constant TEST_ADDRESS = 0x6Eb28604685b1F182dAB800A1Bfa4BaFdBA8a79a; | ||
address constant TEST_ORIGIN = 0xdEBe90b7BFD87Af696B1966082F6515a6E72F3d8; | ||
|
||
// enum CallerMode { | ||
// None, | ||
// Broadcast, | ||
// RecurrentBroadcast, | ||
// Prank, | ||
// RecurrentPrank | ||
// } | ||
|
||
function testNormalReadCallers() public { | ||
(bool success, bytes memory data) = Constants.CHEATCODE_ADDRESS.call( | ||
abi.encodeWithSignature("readCallers()")); | ||
require(success, "readCallers failed"); | ||
|
||
(uint8 mode, address sender, address origin) = abi.decode(data, (uint8, address, address)); | ||
require(mode == 0, "normal call mode"); | ||
require(sender == msg.sender, "sender not overridden"); | ||
require(origin == tx.origin, "origin not overridden"); | ||
} | ||
|
||
function testPrankedReadCallers() public { | ||
(bool success1, ) = Constants.CHEATCODE_ADDRESS.call( | ||
abi.encodeWithSignature("startPrank(address)", TEST_ADDRESS) | ||
); | ||
require(success1, "startPrank failed"); | ||
|
||
(bool success, bytes memory data) = Constants.CHEATCODE_ADDRESS.call( | ||
abi.encodeWithSignature("readCallers()")); | ||
require(success, "readCallers failed"); | ||
|
||
(uint8 mode, address sender, address origin) = abi.decode(data, (uint8, address, address)); | ||
require(mode == 4, "recurrent prank call mode"); | ||
require(sender == TEST_ADDRESS, "sender overridden"); | ||
require(origin == tx.origin, "origin not overridden"); | ||
|
||
console.log("failed?", failed()); | ||
} | ||
|
||
function testFullyPrankedReadCallers() public { | ||
(bool success1, ) = Constants.CHEATCODE_ADDRESS.call( | ||
abi.encodeWithSignature("startPrank(address,address)", TEST_ADDRESS, TEST_ORIGIN) | ||
); | ||
require(success1, "startPrank failed"); | ||
|
||
(bool success, bytes memory data) = Constants.CHEATCODE_ADDRESS.call( | ||
abi.encodeWithSignature("readCallers()")); | ||
require(success, "readCallers failed"); | ||
|
||
(uint8 mode, address sender, address origin) = abi.decode(data, (uint8, address, address)); | ||
|
||
require(mode == 4, "recurrent prank call mode"); | ||
require(sender == TEST_ADDRESS, "sender overridden"); | ||
require(origin == TEST_ORIGIN, "origin overridden"); | ||
|
||
console.log("failed?", failed()); | ||
} | ||
} |
Oops, something went wrong.