Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cheatcodes): add repro test for once reported issues around empty JSON arrays #7348

Merged
merged 2 commits into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions crates/forge/tests/it/repros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ test_repro!(3753);
// https://github.com/foundry-rs/foundry/issues/3792
test_repro!(3792);

// https://github.com/foundry-rs/foundry/issues/4402
test_repro!(4402);

// https://github.com/foundry-rs/foundry/issues/4586
test_repro!(4586);

Expand Down
4 changes: 4 additions & 0 deletions testdata/fixtures/Json/Issue4402.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"tokens": ["0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"],
"empty": []
}
2 changes: 2 additions & 0 deletions testdata/fixtures/Toml/Issue4402.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
tokens = ["0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"]
empty = []
64 changes: 64 additions & 0 deletions testdata/repros/Issue4402.t.sol
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);
}
}
Loading