-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:
bytes
to base64 encoding in VM (#6785)
* Base64 cheatcode * Removed `toBase64(string calldata data)` * Typo fix * Changed version of base64 * Fix failed tests * Replaced `string::parse` with `abi_encode()`
- Loading branch information
1 parent
c3b6555
commit bb35926
Showing
11 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use crate::{Cheatcode, Cheatcodes, Result, Vm::*}; | ||
use alloy_sol_types::SolValue; | ||
use base64::prelude::*; | ||
|
||
impl Cheatcode for toBase64Call { | ||
fn apply(&self, _state: &mut Cheatcodes) -> Result { | ||
let Self { data } = self; | ||
Ok(BASE64_STANDARD.encode(data).abi_encode()) | ||
} | ||
} | ||
|
||
impl Cheatcode for toBase64URLCall { | ||
fn apply(&self, _state: &mut Cheatcodes) -> Result { | ||
let Self { data } = self; | ||
Ok(BASE64_URL_SAFE.encode(data).abi_encode()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
pragma solidity 0.8.18; | ||
|
||
import "ds-test/test.sol"; | ||
import "./Vm.sol"; | ||
import "../logs/console.sol"; | ||
|
||
contract Base64Test is DSTest { | ||
Vm constant vm = Vm(HEVM_ADDRESS); | ||
|
||
function test_toBase64() public { | ||
bytes memory input = hex"00112233445566778899aabbccddeeff"; | ||
string memory expected = "ABEiM0RVZneImaq7zN3u/w=="; | ||
string memory actual = vm.toBase64(input); | ||
assertEq(actual, expected); | ||
} | ||
|
||
function test_toBase64URL() public { | ||
bytes memory input = hex"00112233445566778899aabbccddeeff"; | ||
string memory expected = "ABEiM0RVZneImaq7zN3u_w=="; | ||
string memory actual = vm.toBase64URL(input); | ||
assertEq(actual, expected); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.