Skip to content

Commit

Permalink
Merge pull request #657 from lidofinance/feature/shapella-upgrade-tes…
Browse files Browse the repository at this point in the history
…ts-withdrawal-queue-nft

Tests WithdrawalQueueERC721
  • Loading branch information
Jeday authored Feb 27, 2023
2 parents cf72059 + b3a59ec commit 6f9616f
Show file tree
Hide file tree
Showing 3 changed files with 453 additions and 2 deletions.
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

0 comments on commit 6f9616f

Please sign in to comment.