dexorder
This commit is contained in:
34
lib_openzeppelin_contracts/test/utils/Base64.t.sol
Normal file
34
lib_openzeppelin_contracts/test/utils/Base64.t.sol
Normal file
@@ -0,0 +1,34 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity ^0.8.20;
|
||||
|
||||
import {Test} from "@forge-std/Test.sol";
|
||||
import {Base64} from "@openzeppelin/contracts/utils/Base64.sol";
|
||||
|
||||
contract Base64Test is Test {
|
||||
function testEncode(bytes memory input) external {
|
||||
assertEq(Base64.encode(input), vm.toBase64(input));
|
||||
}
|
||||
|
||||
function testEncodeURL(bytes memory input) external {
|
||||
assertEq(Base64.encodeURL(input), _removePadding(vm.toBase64URL(input)));
|
||||
}
|
||||
|
||||
function _removePadding(string memory inputStr) internal pure returns (string memory) {
|
||||
bytes memory input = bytes(inputStr);
|
||||
bytes memory output;
|
||||
|
||||
for (uint256 i = 0; i < input.length; ++i) {
|
||||
if (input[input.length - i - 1] != 0x3d) {
|
||||
output = new bytes(input.length - i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (uint256 i = 0; i < output.length; ++i) {
|
||||
output[i] = input[i];
|
||||
}
|
||||
|
||||
return string(output);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user