diff --git a/crates/cheatcodes/assets/cheatcodes.json b/crates/cheatcodes/assets/cheatcodes.json index 7819914cba8c..cb0ee2d6052b 100644 --- a/crates/cheatcodes/assets/cheatcodes.json +++ b/crates/cheatcodes/assets/cheatcodes.json @@ -4555,8 +4555,48 @@ }, { "func": { - "id": "toBase64", - "description": "Encodes a `bytes` value to base64 string", + "id": "toBase64URL_0", + "description": "Encodes a `bytes` value to a base64url string.", + "declaration": "function toBase64URL(bytes calldata data) external pure returns (string memory);", + "visibility": "external", + "mutability": "pure", + "signature": "toBase64URL(bytes)", + "selector": "0xc8bd0e4a", + "selectorBytes": [ + 200, + 189, + 14, + 74 + ] + }, + "group": "utilities", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "toBase64URL_1", + "description": "Encodes a `string` value to a base64url string.", + "declaration": "function toBase64URL(string calldata data) external pure returns (string memory);", + "visibility": "external", + "mutability": "pure", + "signature": "toBase64URL(string)", + "selector": "0xae3165b3", + "selectorBytes": [ + 174, + 49, + 101, + 179 + ] + }, + "group": "utilities", + "status": "stable", + "safety": "safe" + }, + { + "func": { + "id": "toBase64_0", + "description": "Encodes a `bytes` value to a base64 string.", "declaration": "function toBase64(bytes calldata data) external pure returns (string memory);", "visibility": "external", "mutability": "pure", @@ -4569,27 +4609,27 @@ 101 ] }, - "group": "base64", + "group": "utilities", "status": "stable", "safety": "safe" }, { "func": { - "id": "toBase64URL", - "description": "Encodes a `bytes` value to base64url string", - "declaration": "function toBase64URL(bytes calldata data) external pure returns (string memory);", + "id": "toBase64_1", + "description": "Encodes a `string` value to a base64 string.", + "declaration": "function toBase64(string calldata data) external pure returns (string memory);", "visibility": "external", "mutability": "pure", - "signature": "toBase64URL(bytes)", - "selector": "0xc8bd0e4a", + "signature": "toBase64(string)", + "selector": "0x3f8be2c8", "selectorBytes": [ - 200, - 189, - 14, - 74 + 63, + 139, + 226, + 200 ] }, - "group": "base64", + "group": "utilities", "status": "stable", "safety": "safe" }, diff --git a/crates/cheatcodes/assets/cheatcodes.schema.json b/crates/cheatcodes/assets/cheatcodes.schema.json index 1231ec0458e6..7b68420ad63b 100644 --- a/crates/cheatcodes/assets/cheatcodes.schema.json +++ b/crates/cheatcodes/assets/cheatcodes.schema.json @@ -298,13 +298,6 @@ "json" ] }, - { - "description": "Utility cheatcodes that deal with encoding and decoding Base64.\n\nExamples: `toBase64`, `toBase64URL`.\n\nSafety: safe.", - "type": "string", - "enum": [ - "base64" - ] - }, { "description": "Generic, uncategorized utilities.\n\nExamples: `toString`, `parse*`, `serialize*`.\n\nSafety: safe.", "type": "string", diff --git a/crates/cheatcodes/spec/src/cheatcode.rs b/crates/cheatcodes/spec/src/cheatcode.rs index e6ed724629fe..f7e0c87b306f 100644 --- a/crates/cheatcodes/spec/src/cheatcode.rs +++ b/crates/cheatcodes/spec/src/cheatcode.rs @@ -103,12 +103,6 @@ pub enum Group { /// /// Safety: safe. Json, - /// Utility cheatcodes that deal with encoding and decoding Base64. - /// - /// Examples: `toBase64`, `toBase64URL`. - /// - /// Safety: safe. - Base64, /// Generic, uncategorized utilities. /// /// Examples: `toString`, `parse*`, `serialize*`. @@ -131,7 +125,6 @@ impl Group { Self::Environment | Self::String | Self::Json | - Self::Base64 | Self::Utilities => Some(Safety::Safe), } } @@ -147,7 +140,6 @@ impl Group { Self::Environment => "environment", Self::String => "string", Self::Json => "json", - Self::Base64 => "base64", Self::Utilities => "utilities", } } diff --git a/crates/cheatcodes/spec/src/vm.rs b/crates/cheatcodes/spec/src/vm.rs index d1611222d54b..cf193663eead 100644 --- a/crates/cheatcodes/spec/src/vm.rs +++ b/crates/cheatcodes/spec/src/vm.rs @@ -1232,16 +1232,6 @@ interface Vm { #[cheatcode(group = Json)] function writeJson(string calldata json, string calldata path, string calldata valueKey) external; - // -------- Base64 -------- - - /// Encodes a `bytes` value to base64 string - #[cheatcode(group = Base64)] - function toBase64(bytes calldata data) external pure returns (string memory); - - /// Encodes a `bytes` value to base64url string - #[cheatcode(group = Base64)] - function toBase64URL(bytes calldata data) external pure returns (string memory); - // -------- Key Management -------- /// Derives a private key from the name, labels the account with that name, and returns the wallet. @@ -1315,5 +1305,21 @@ interface Vm { /// Compute the address of a contract created with CREATE2 using the default CREATE2 deployer. #[cheatcode(group = Utilities)] function computeCreate2Address(bytes32 salt, bytes32 initCodeHash) external pure returns (address); + + /// Encodes a `bytes` value to a base64 string. + #[cheatcode(group = Utilities)] + function toBase64(bytes calldata data) external pure returns (string memory); + + /// Encodes a `string` value to a base64 string. + #[cheatcode(group = Utilities)] + function toBase64(string calldata data) external pure returns (string memory); + + /// Encodes a `bytes` value to a base64url string. + #[cheatcode(group = Utilities)] + function toBase64URL(bytes calldata data) external pure returns (string memory); + + /// Encodes a `string` value to a base64url string. + #[cheatcode(group = Utilities)] + function toBase64URL(string calldata data) external pure returns (string memory); } } diff --git a/crates/cheatcodes/src/base64.rs b/crates/cheatcodes/src/base64.rs index d9d0bc86f76c..4aa4ba74a0e4 100644 --- a/crates/cheatcodes/src/base64.rs +++ b/crates/cheatcodes/src/base64.rs @@ -2,14 +2,28 @@ use crate::{Cheatcode, Cheatcodes, Result, Vm::*}; use alloy_sol_types::SolValue; use base64::prelude::*; -impl Cheatcode for toBase64Call { +impl Cheatcode for toBase64_0Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { data } = self; Ok(BASE64_STANDARD.encode(data).abi_encode()) } } -impl Cheatcode for toBase64URLCall { +impl Cheatcode for toBase64_1Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { data } = self; + Ok(BASE64_STANDARD.encode(data).abi_encode()) + } +} + +impl Cheatcode for toBase64URL_0Call { + fn apply(&self, _state: &mut Cheatcodes) -> Result { + let Self { data } = self; + Ok(BASE64_URL_SAFE.encode(data).abi_encode()) + } +} + +impl Cheatcode for toBase64URL_1Call { fn apply(&self, _state: &mut Cheatcodes) -> Result { let Self { data } = self; Ok(BASE64_URL_SAFE.encode(data).abi_encode()) diff --git a/testdata/cheats/Vm.sol b/testdata/cheats/Vm.sol index 78ca56eda835..ccc29b9abd2e 100644 --- a/testdata/cheats/Vm.sol +++ b/testdata/cheats/Vm.sol @@ -225,8 +225,10 @@ interface Vm { function stopMappingRecording() external; function stopPrank() external; function store(address target, bytes32 slot, bytes32 value) external; - function toBase64(bytes calldata data) external pure returns (string memory); function toBase64URL(bytes calldata data) external pure returns (string memory); + function toBase64URL(string calldata data) external pure returns (string memory); + function toBase64(bytes calldata data) external pure returns (string memory); + function toBase64(string calldata data) external pure returns (string memory); function toString(address value) external pure returns (string memory stringifiedValue); function toString(bytes calldata value) external pure returns (string memory stringifiedValue); function toString(bytes32 value) external pure returns (string memory stringifiedValue);