Skip to content

Commit

Permalink
chore(cheatcodes): remove base64 group, add string overloads (#6830)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes authored Jan 17, 2024
1 parent 9e2830d commit 03f5a95
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 41 deletions.
66 changes: 53 additions & 13 deletions crates/cheatcodes/assets/cheatcodes.json

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

7 changes: 0 additions & 7 deletions crates/cheatcodes/assets/cheatcodes.schema.json

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

8 changes: 0 additions & 8 deletions crates/cheatcodes/spec/src/cheatcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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*`.
Expand All @@ -131,7 +125,6 @@ impl Group {
Self::Environment |
Self::String |
Self::Json |
Self::Base64 |
Self::Utilities => Some(Safety::Safe),
}
}
Expand All @@ -147,7 +140,6 @@ impl Group {
Self::Environment => "environment",
Self::String => "string",
Self::Json => "json",
Self::Base64 => "base64",
Self::Utilities => "utilities",
}
}
Expand Down
26 changes: 16 additions & 10 deletions crates/cheatcodes/spec/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1236,16 +1236,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.
Expand Down Expand Up @@ -1319,5 +1309,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);
}
}
18 changes: 16 additions & 2 deletions crates/cheatcodes/src/base64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
4 changes: 3 additions & 1 deletion 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 03f5a95

Please sign in to comment.