forked from foundry-rs/foundry
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cheatcodes): add repro test for once reported issues around empty…
… JSON arrays (foundry-rs#7348) * add repro case, fortunately issue has been resolved over time * revert debug line
- Loading branch information
1 parent
9ec42d6
commit 9f6bb3b
Showing
4 changed files
with
73 additions
and
0 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,4 @@ | ||
{ | ||
"tokens": ["0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"], | ||
"empty": [] | ||
} |
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,2 @@ | ||
tokens = ["0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"] | ||
empty = [] |
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,64 @@ | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
pragma solidity 0.8.18; | ||
|
||
import "ds-test/test.sol"; | ||
import "../cheats/Vm.sol"; | ||
|
||
// https://github.com/foundry-rs/foundry/issues/4402 | ||
contract Issue4402Test is DSTest { | ||
Vm constant vm = Vm(HEVM_ADDRESS); | ||
|
||
function testReadNonEmptyArray() public { | ||
string memory path = "fixtures/Json/Issue4402.json"; | ||
string memory json = vm.readFile(path); | ||
address[] memory tokens = vm.parseJsonAddressArray(json, ".tokens"); | ||
assertEq(tokens.length, 1); | ||
|
||
path = "fixtures/Toml/Issue4402.toml"; | ||
string memory toml = vm.readFile(path); | ||
tokens = vm.parseTomlAddressArray(toml, ".tokens"); | ||
assertEq(tokens.length, 1); | ||
} | ||
|
||
function testReadEmptyArray() public { | ||
string memory path = "fixtures/Json/Issue4402.json"; | ||
string memory json = vm.readFile(path); | ||
|
||
// Every one of these used to causes panic | ||
address[] memory emptyAddressArray = vm.parseJsonAddressArray(json, ".empty"); | ||
bool[] memory emptyBoolArray = vm.parseJsonBoolArray(json, ".empty"); | ||
bytes[] memory emptyBytesArray = vm.parseJsonBytesArray(json, ".empty"); | ||
bytes32[] memory emptyBytes32Array = vm.parseJsonBytes32Array(json, ".empty"); | ||
string[] memory emptyStringArray = vm.parseJsonStringArray(json, ".empty"); | ||
int256[] memory emptyIntArray = vm.parseJsonIntArray(json, ".empty"); | ||
uint256[] memory emptyUintArray = vm.parseJsonUintArray(json, ".empty"); | ||
|
||
assertEq(emptyAddressArray.length, 0); | ||
assertEq(emptyBoolArray.length, 0); | ||
assertEq(emptyBytesArray.length, 0); | ||
assertEq(emptyBytes32Array.length, 0); | ||
assertEq(emptyStringArray.length, 0); | ||
assertEq(emptyIntArray.length, 0); | ||
assertEq(emptyUintArray.length, 0); | ||
|
||
path = "fixtures/Toml/Issue4402.toml"; | ||
string memory toml = vm.readFile(path); | ||
|
||
// Every one of these used to causes panic | ||
emptyAddressArray = vm.parseTomlAddressArray(toml, ".empty"); | ||
emptyBoolArray = vm.parseTomlBoolArray(toml, ".empty"); | ||
emptyBytesArray = vm.parseTomlBytesArray(toml, ".empty"); | ||
emptyBytes32Array = vm.parseTomlBytes32Array(toml, ".empty"); | ||
emptyStringArray = vm.parseTomlStringArray(toml, ".empty"); | ||
emptyIntArray = vm.parseTomlIntArray(toml, ".empty"); | ||
emptyUintArray = vm.parseTomlUintArray(toml, ".empty"); | ||
|
||
assertEq(emptyAddressArray.length, 0); | ||
assertEq(emptyBoolArray.length, 0); | ||
assertEq(emptyBytesArray.length, 0); | ||
assertEq(emptyBytes32Array.length, 0); | ||
assertEq(emptyStringArray.length, 0); | ||
assertEq(emptyIntArray.length, 0); | ||
assertEq(emptyUintArray.length, 0); | ||
} | ||
} |