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

Tests WithdrawalQueueERC721 #657

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
50 changes: 50 additions & 0 deletions contracts/0.8.9/test_helpers/NFTDescriptorMock.sol
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;
}
}
14 changes: 12 additions & 2 deletions test/0.8.9/withdrawal-queue-deploy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ const { assert } = require('../helpers/assert')
const StETHMock = artifacts.require('StETHPermitMock.sol')
const WstETH = artifacts.require('WstETHMock.sol')
const EIP712StETH = artifacts.require('EIP712StETH')
const NFTDescriptorMock = artifacts.require('NFTDescriptorMock.sol')

const QUEUE_NAME = 'Unsteth nft'
const QUEUE_SYMBOL = 'UNSTETH'
const NFT_DESCRIPTOR_BASE_URI = 'https://exampleDescriptor.com/'

async function deployWithdrawalQueue({
stethOwner,
Expand All @@ -16,10 +21,11 @@ async function deployWithdrawalQueue({
queueResumer,
queueFinalizer,
queueBunkerReporter,
queueName = 'Unsteth nft',
symbol = 'UNSTETH',
queueName = QUEUE_NAME,
symbol = QUEUE_SYMBOL,
doResume = true,
}) {
const nftDescriptor = await NFTDescriptorMock.new(NFT_DESCRIPTOR_BASE_URI)
const steth = await StETHMock.new({ value: ETH(1), from: stethOwner })
const wsteth = await WstETH.new(steth.address, { from: stethOwner })
const eip712StETH = await EIP712StETH.new(steth.address, { from: stethOwner })
Expand All @@ -44,11 +50,15 @@ async function deployWithdrawalQueue({
steth,
wsteth,
withdrawalQueue,
nftDescriptor,
}
}

module.exports = {
deployWithdrawalQueue,
QUEUE_NAME,
QUEUE_SYMBOL,
NFT_DESCRIPTOR_BASE_URI,
}

contract(
Expand Down
Loading