Skip to content

Commit

Permalink
chore(cheatcodes): enforce calldata in declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes committed Nov 25, 2024
1 parent 672bdf6 commit 79504b8
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 27 deletions.
18 changes: 9 additions & 9 deletions crates/cheatcodes/assets/cheatcodes.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions crates/cheatcodes/spec/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ interface Vm {

/// Gets all the logs according to specified filter.
#[cheatcode(group = Evm, safety = Safe)]
function eth_getLogs(uint256 fromBlock, uint256 toBlock, address target, bytes32[] memory topics)
function eth_getLogs(uint256 fromBlock, uint256 toBlock, address target, bytes32[] calldata topics)
external
returns (EthGetLogs[] memory logs);

Expand Down Expand Up @@ -1764,35 +1764,35 @@ interface Vm {
///
/// The most recent call can be fetched by passing `txType` as `CALL`.
#[cheatcode(group = Filesystem)]
function getBroadcast(string memory contractName, uint64 chainId, BroadcastTxType txType) external view returns (BroadcastTxSummary memory);
function getBroadcast(string calldata contractName, uint64 chainId, BroadcastTxType txType) external view returns (BroadcastTxSummary memory);

/// Returns all broadcasts for the given contract on `chainId` with the specified `txType`.
///
/// Sorted such that the most recent broadcast is the first element, and the oldest is the last. i.e descending order of BroadcastTxSummary.blockNumber.
#[cheatcode(group = Filesystem)]
function getBroadcasts(string memory contractName, uint64 chainId, BroadcastTxType txType) external view returns (BroadcastTxSummary[] memory);
function getBroadcasts(string calldata contractName, uint64 chainId, BroadcastTxType txType) external view returns (BroadcastTxSummary[] memory);

/// Returns all broadcasts for the given contract on `chainId`.
///
/// Sorted such that the most recent broadcast is the first element, and the oldest is the last. i.e descending order of BroadcastTxSummary.blockNumber.
#[cheatcode(group = Filesystem)]
function getBroadcasts(string memory contractName, uint64 chainId) external view returns (BroadcastTxSummary[] memory);
function getBroadcasts(string calldata contractName, uint64 chainId) external view returns (BroadcastTxSummary[] memory);

/// Returns the most recent deployment for the current `chainId`.
#[cheatcode(group = Filesystem)]
function getDeployment(string memory contractName) external view returns (address deployedAddress);
function getDeployment(string calldata contractName) external view returns (address deployedAddress);

/// Returns the most recent deployment for the given contract on `chainId`
#[cheatcode(group = Filesystem)]
function getDeployment(string memory contractName, uint64 chainId) external view returns (address deployedAddress);
function getDeployment(string calldata contractName, uint64 chainId) external view returns (address deployedAddress);

/// Returns all deployments for the given contract on `chainId`
///
/// Sorted in descending order of deployment time i.e descending order of BroadcastTxSummary.blockNumber.
///
/// The most recent deployment is the first element, and the oldest is the last.
#[cheatcode(group = Filesystem)]
function getDeployments(string memory contractName, uint64 chainId) external view returns (address[] memory deployedAddresses);
function getDeployments(string calldata contractName, uint64 chainId) external view returns (address[] memory deployedAddresses);

// -------- Foreign Function Interface --------

Expand Down Expand Up @@ -2298,13 +2298,13 @@ interface Vm {
returns (string memory json);
/// See `serializeJson`.
#[cheatcode(group = Json)]
function serializeJsonType(string calldata typeDescription, bytes memory value)
function serializeJsonType(string calldata typeDescription, bytes calldata value)
external
pure
returns (string memory json);
/// See `serializeJson`.
#[cheatcode(group = Json)]
function serializeJsonType(string calldata objectKey, string calldata valueKey, string calldata typeDescription, bytes memory value)
function serializeJsonType(string calldata objectKey, string calldata valueKey, string calldata typeDescription, bytes calldata value)
external
returns (string memory json);

Expand Down
11 changes: 11 additions & 0 deletions crates/macros/src/cheatcodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ fn derive_call(name: &Ident, data: &DataStruct, attrs: &[Attribute]) -> Result<T
let doc = get_docstring(attrs);
let (signature, selector, declaration, description) = func_docstring(&doc);

let mut params = declaration;
if let Some(ret) = params.find(" returns ") {
params = &params[..ret];
}
if params.contains(" memory ") {
emit_warning!(
name.span(),
"parameter data locations must be `calldata` instead of `memory`"
);
}

let (visibility, mutability) = parse_function_attrs(declaration, name.span())?;
let visibility = Ident::new(visibility, Span::call_site());
let mutability = Ident::new(mutability, Span::call_site());
Expand Down
18 changes: 9 additions & 9 deletions testdata/cheats/Vm.sol

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 79504b8

Please sign in to comment.