-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #657 from lidofinance/feature/shapella-upgrade-tes…
…ts-withdrawal-queue-nft Tests WithdrawalQueueERC721
- Loading branch information
Showing
3 changed files
with
453 additions
and
2 deletions.
There are no files selected for viewing
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,50 @@ | ||
// SPDX-FileCopyrightText: 2023 Lido <[email protected]> | ||
// SPDX-License-Identifier: GPL-3.0 | ||
|
||
/* See contracts/COMPILERS.md */ | ||
pragma solidity 0.8.9; | ||
|
||
import { Strings } from "@openzeppelin/contracts-v4.4/utils/Strings.sol"; | ||
import { INFTDescriptor } from "../WithdrawalQueueERC721.sol"; | ||
|
||
contract NFTDescriptorMock is INFTDescriptor { | ||
using Strings for uint256; | ||
|
||
bytes32 private BASE_TOKEN_URI; | ||
|
||
constructor(string memory _baseURI) INFTDescriptor() { | ||
BASE_TOKEN_URI = _toBytes32(_baseURI); | ||
} | ||
|
||
function constructTokenURI( | ||
uint256 _requestId | ||
) external view returns (string memory) { | ||
string memory baseURI = _toString(BASE_TOKEN_URI); | ||
return string(abi.encodePacked(baseURI, _requestId.toString())); | ||
} | ||
|
||
function baseTokenURI() external view returns (string memory) { | ||
return _toString(BASE_TOKEN_URI); | ||
} | ||
|
||
function setBaseTokenURI(string memory _baseURI) external { | ||
BASE_TOKEN_URI = _toBytes32(_baseURI); | ||
} | ||
|
||
function _toBytes32(string memory _str) internal pure returns (bytes32) { | ||
bytes memory bstr = bytes(_str); | ||
require(bstr.length <= 32, "NFTDescriptor: string too long"); | ||
return bytes32(uint256(bytes32(bstr)) | bstr.length); | ||
} | ||
|
||
function _toString(bytes32 _sstr) internal pure returns (string memory) { | ||
uint256 len = uint256(_sstr) & 0xFF; | ||
string memory str = new string(32); | ||
/// @solidity memory-safe-assembly | ||
assembly { | ||
mstore(str, len) | ||
mstore(add(str, 0x20), _sstr) | ||
} | ||
return str; | ||
} | ||
} |
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
Oops, something went wrong.