-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: karmacoma <[email protected]> Co-authored-by: Daejun Park <[email protected]>
- Loading branch information
1 parent
6be83f7
commit 8eb41ba
Showing
10 changed files
with
240 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
name: Test FFI | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
pull_request: | ||
branches: [main] | ||
|
||
jobs: | ||
test: | ||
runs-on: macos-latest | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
include: | ||
- testname: "ffi:tests" | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
submodules: recursive | ||
|
||
- name: Install Foundry | ||
uses: foundry-rs/foundry-toolchain@v1 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: "3.11" | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install pytest | ||
- name: Install Halmos | ||
run: pip install -e . | ||
|
||
- name: Run pytest | ||
run: pytest -v tests/test_halmos.py -k ${{ matrix.testname }} --halmos-options="--ffi -v -st --error-unknown --test-parallel --solver-parallel --solver-timeout-assertion 0" |
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
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,43 @@ | ||
{ | ||
"exitcode": 1, | ||
"test_results": { | ||
"test/Ffi.t.sol:FfiTest": [ | ||
{ | ||
"name": "testFFI_Failure()", | ||
"exitcode": 2, | ||
"num_models": null, | ||
"models": null, | ||
"num_paths": null, | ||
"time": null, | ||
"num_bounded_loops": null | ||
}, | ||
{ | ||
"name": "testFFI_HexOutput()", | ||
"exitcode": 0, | ||
"num_models": 0, | ||
"models": null, | ||
"num_paths": null, | ||
"time": null, | ||
"num_bounded_loops": null | ||
}, | ||
{ | ||
"name": "testFFI_Stderr()", | ||
"exitcode": 0, | ||
"num_models": 0, | ||
"models": null, | ||
"num_paths": null, | ||
"time": null, | ||
"num_bounded_loops": null | ||
}, | ||
{ | ||
"name": "testFFI_StringOutput()", | ||
"exitcode": 0, | ||
"num_models": 0, | ||
"models": null, | ||
"num_paths": null, | ||
"time": null, | ||
"num_bounded_loops": null | ||
} | ||
] | ||
} | ||
} |
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,62 @@ | ||
// SPDX-License-Identifier: AGPL-3.0 | ||
pragma solidity >=0.8.0 <0.9.0; | ||
|
||
import "forge-std/Test.sol"; | ||
|
||
contract FfiTest is Test { | ||
|
||
function testFFI_HexOutput() public { | ||
string[] memory inputs = new string[](3); | ||
inputs[0] = "echo"; | ||
inputs[1] = "-n"; | ||
inputs[2] = /* "arbitrary string" abi.encoded hex representation */"0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001061726269747261727920737472696e6700000000000000000000000000000000"; | ||
|
||
bytes memory res = vm.ffi(inputs); | ||
|
||
bytes32 expected = keccak256(abi.encodePacked("arbitrary string")); | ||
bytes32 output = keccak256(abi.encodePacked(abi.decode(res, (string)))); | ||
|
||
assert(expected == output); | ||
} | ||
|
||
function testFFI_StringOutput() public { | ||
string memory str = "arbitrary string"; | ||
|
||
string[] memory inputs = new string[](3); | ||
inputs[0] = "echo"; | ||
inputs[1] = "-n"; | ||
inputs[2] = str; | ||
|
||
bytes32 expected = keccak256(abi.encodePacked(str)); | ||
bytes32 output = keccak256( | ||
vm.ffi(inputs) /* Perform ffi */ | ||
); | ||
|
||
assert(expected == output); | ||
} | ||
|
||
function testFFI_Stderr() public { | ||
string[] memory inputs = new string[](3); | ||
inputs[0] = "logger"; | ||
inputs[1] = "-s"; | ||
inputs[2] = "Error!"; | ||
|
||
bytes32 output = keccak256( | ||
vm.ffi(inputs) /* Perform ffi that generates non empty stderr */ | ||
); | ||
|
||
/* TODO: fix bug in sha3 of empty bytes | ||
bytes32 expected = keccak256(abi.encodePacked("")); | ||
assert(expected == output); | ||
*/ | ||
} | ||
|
||
function testFFI_Failure() public { | ||
string[] memory inputs = new string[](1); | ||
inputs[0] = "must_fail"; | ||
|
||
bytes32 output = keccak256( | ||
vm.ffi(inputs) /* Perform ffi that must fail */ | ||
); | ||
} | ||
} |
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