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

chore(cheatcodes): remove base64 group, add string overloads #6830

Merged
merged 1 commit into from
Jan 17, 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
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 @@ -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.
Expand Down Expand Up @@ -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);
}
}
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.