-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(zk): Add proxy and NFT script to Cargo test (#527)
* add proxy and NFT script * generalize run script test function * add list of deps, extra args and expose rich wallets * Multiple installs in one command --------- Co-authored-by: Jrigada <[email protected]>
- Loading branch information
Showing
9 changed files
with
290 additions
and
53 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
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,84 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity >=0.8.10; | ||
|
||
import "forge-std/Script.sol"; | ||
import "solmate/tokens/ERC721.sol"; | ||
|
||
error MintPriceNotPaid(); | ||
error MaxSupply(); | ||
error NonExistentTokenURI(); | ||
error WithdrawTransfer(); | ||
|
||
contract NFT is ERC721 { | ||
string public baseURI; | ||
uint256 public currentTokenId; | ||
uint256 public constant TOTAL_SUPPLY = 10_000; | ||
uint256 public constant MINT_PRICE = 0.08 ether; | ||
address public owner; | ||
|
||
constructor(string memory _name, string memory _symbol, string memory _baseURI) ERC721(_name, _symbol) { | ||
baseURI = _baseURI; | ||
owner = msg.sender; | ||
} | ||
|
||
modifier onlyOwner() { | ||
require(msg.sender == owner, "Not the owner"); | ||
_; | ||
} | ||
|
||
function mintTo(address recipient) public payable returns (uint256) { | ||
if (msg.value != MINT_PRICE) { | ||
revert MintPriceNotPaid(); | ||
} | ||
uint256 newTokenId = ++currentTokenId; | ||
if (newTokenId > TOTAL_SUPPLY) { | ||
revert MaxSupply(); | ||
} | ||
_safeMint(recipient, newTokenId); | ||
return newTokenId; | ||
} | ||
|
||
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { | ||
if (ownerOf(tokenId) == address(0)) { | ||
revert NonExistentTokenURI(); | ||
} | ||
return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, _toString(tokenId))) : ""; | ||
} | ||
|
||
function withdrawPayments(address payable payee) external onlyOwner { | ||
uint256 balance = address(this).balance; | ||
(bool transferTx,) = payee.call{value: balance}(""); | ||
if (!transferTx) { | ||
revert WithdrawTransfer(); | ||
} | ||
} | ||
|
||
function _toString(uint256 value) internal pure returns (string memory) { | ||
if (value == 0) { | ||
return "0"; | ||
} | ||
uint256 temp = value; | ||
uint256 digits; | ||
while (temp != 0) { | ||
digits++; | ||
temp /= 10; | ||
} | ||
bytes memory buffer = new bytes(digits); | ||
while (value != 0) { | ||
digits -= 1; | ||
buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); | ||
value /= 10; | ||
} | ||
return string(buffer); | ||
} | ||
} | ||
|
||
contract MyScript is Script { | ||
function run() external { | ||
vm.startBroadcast(0x7becc4a46e0c3b512d380ca73a4c868f790d1055a7698f38fb3ca2b2ac97efbb); | ||
|
||
new NFT("NFT_tutorial", "TUT", "baseUri"); | ||
|
||
vm.stopBroadcast(); | ||
} | ||
} |
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,32 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity >=0.8.7 <0.9.0; | ||
|
||
import "forge-std/Script.sol"; | ||
import "openzeppelin-contracts/contracts/proxy/ERC1967/ERC1967Proxy.sol"; | ||
|
||
contract ProxyScript is Script { | ||
function run() public { | ||
vm.startBroadcast(0x7becc4a46e0c3b512d380ca73a4c868f790d1055a7698f38fb3ca2b2ac97efbb); | ||
//deploy Foo | ||
ERC1967Proxy proxy = new ERC1967Proxy(address(new Foo()), ""); | ||
|
||
Foo foo = Foo(payable(proxy)); | ||
foo.initialize(msg.sender); | ||
|
||
console.log("Foo deployed at: ", address(foo)); | ||
console.log("Bar: ", foo.getAddress()); | ||
vm.stopBroadcast(); | ||
} | ||
} | ||
|
||
contract Foo { | ||
address bar; | ||
|
||
function initialize(address _bar) public { | ||
bar = _bar; | ||
} | ||
|
||
function getAddress() public returns (address) { | ||
return bar; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -8,5 +8,7 @@ mod fork; | |
mod fuzz; | ||
mod invariant; | ||
mod logs; | ||
mod nft; | ||
mod ownership; | ||
mod proxy; | ||
mod repros; |
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,21 @@ | ||
use foundry_test_utils::{forgetest_async, util, TestProject}; | ||
|
||
use crate::test_helpers::run_zk_script_test; | ||
|
||
forgetest_async!(script_zk_can_deploy_nft, |prj, cmd| { | ||
setup_nft_prj(&mut prj); | ||
run_zk_script_test( | ||
prj.root(), | ||
&mut cmd, | ||
"./script/NFT.s.sol", | ||
"MyScript", | ||
Some("transmissions11/solmate@v7 OpenZeppelin/openzeppelin-contracts"), | ||
1, | ||
Some(&["-vvvvv"]), | ||
); | ||
}); | ||
|
||
fn setup_nft_prj(prj: &mut TestProject) { | ||
util::initialize(prj.root()); | ||
prj.add_script("NFT.s.sol", include_str!("../../fixtures/zk/NFT.s.sol")).unwrap(); | ||
} |
Oops, something went wrong.