Skip to content

Commit

Permalink
add basic functional solidity test case
Browse files Browse the repository at this point in the history
  • Loading branch information
sisyphusSmiling committed Oct 30, 2024
1 parent 1621927 commit ee05b06
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
15 changes: 15 additions & 0 deletions solidity/src/test/ExampleERC20.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol";

contract ExampleERC20 is ERC20, ERC20Burnable, Ownable, ERC20Permit {
constructor() ERC20("NAME", "SYMBOL") Ownable(msg.sender) ERC20Permit("NAME") {}

function mint(address to, uint256 amount) public onlyOwner {
_mint(to, amount);
}
}
42 changes: 42 additions & 0 deletions solidity/test/MaybeMintERC721.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
pragma solidity 0.8.24;

import {Test} from "forge-std/Test.sol";
import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {MaybeMintERC721} from "../src/MaybeMintERC721.sol";
import {ExampleERC20} from "../src/test/ExampleERC20.sol";

contract MaybeMintERC721Test is Test {
// Contracts
MaybeMintERC721 private erc721;
ExampleERC20 private erc20;

// MaybeMintERC721 parameters
address payable beneficiary = payable(address(100));
uint256 internal mintCost = 1 ether;
string internal name = "Maybe Mint ERC721 Test";
string internal symbol = "MAYBE";

// Test values
address payable internal user = payable(address(101));

function setUp() public virtual {
vm.deal(user, 10 ether);

erc20 = new ExampleERC20();
erc721 = new MaybeMintERC721(name, symbol, address(erc20), mintCost, beneficiary);
}

function test_mint() public {
erc20.mint(user, mintCost); // mint ERC20 to user

vm.prank(user);
erc20.approve(address(erc721), mintCost); // approve the ERC20 to be spent by MaybeMintERC721

vm.prank(user);
erc721.mint(); // mint ERC721 to user

assertEq(erc721.ownerOf(1), user); // user should own the ERC721 token
}
}

0 comments on commit ee05b06

Please sign in to comment.