-
Notifications
You must be signed in to change notification settings - Fork 11
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
IPN-54 tokenizer adds function to reserve and tokenize at once #164
Open
elmariachi111
wants to merge
2
commits into
main
Choose a base branch
from
feature/ipn-54-tokenizer-page-action-to-clone-mint-ipts-from-a-reservation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,88 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.18; | ||
|
||
import "forge-std/Test.sol"; | ||
import { console } from "forge-std/console.sol"; | ||
|
||
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | ||
import { ERC1967Proxy } from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; | ||
import { ECDSA } from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol"; | ||
import { SafeERC20Upgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol"; | ||
|
||
import { Safe } from "safe-global/safe-contracts/Safe.sol"; | ||
import { SafeProxyFactory } from "safe-global/safe-contracts/proxies/SafeProxyFactory.sol"; | ||
import { Enum } from "safe-global/safe-contracts/common/Enum.sol"; | ||
import "./helpers/MakeGnosisWallet.sol"; | ||
import { IPNFT } from "../src/IPNFT.sol"; | ||
import { AcceptAllAuthorizer } from "./helpers/AcceptAllAuthorizer.sol"; | ||
|
||
import { FakeERC20 } from "../src/helpers/FakeERC20.sol"; | ||
import { MustControlIpnft, AlreadyTokenized, Tokenizer, ZeroAddress, IPTNotControlledByTokenizer } from "../src/Tokenizer.sol"; | ||
|
||
import { IPToken, TokenCapped, Metadata as TokenMetadata } from "../src/IPToken.sol"; | ||
import { IControlIPTs } from "../src/IControlIPTs.sol"; | ||
import { Molecules } from "../src/helpers/test-upgrades/Molecules.sol"; | ||
import { Synthesizer } from "../src/helpers/test-upgrades/Synthesizer.sol"; | ||
import { IPermissioner, BlindPermissioner } from "../src/Permissioner.sol"; | ||
|
||
contract PreliminaryIPTsTest is Test { | ||
using SafeERC20Upgradeable for IPToken; | ||
|
||
string ipfsUri = "ipfs://bafkreiankqd3jvpzso6khstnaoxovtyezyatxdy7t2qzjoolqhltmasqki"; | ||
string agreementCid = "bafkreigk5dvqblnkdniges6ft5kmuly47ebw4vho6siikzmkaovq6sjstq"; | ||
uint256 MINTING_FEE = 0.001 ether; | ||
string DEFAULT_SYMBOL = "IPT-0001"; | ||
|
||
address deployer = makeAddr("chucknorris"); | ||
address originalOwner = makeAddr("brucelee"); | ||
address bob = makeAddr("bob"); | ||
address alice = makeAddr("alice"); | ||
|
||
IPNFT internal ipnft; | ||
Tokenizer internal tokenizer; | ||
|
||
IPermissioner internal blindPermissioner; | ||
FakeERC20 internal erc20; | ||
|
||
function setUp() public { | ||
vm.startPrank(deployer); | ||
ipnft = IPNFT(address(new ERC1967Proxy(address(new IPNFT()), ""))); | ||
ipnft.initialize(); | ||
ipnft.setAuthorizer(new AcceptAllAuthorizer()); | ||
blindPermissioner = new BlindPermissioner(); | ||
|
||
tokenizer = Tokenizer(address(new ERC1967Proxy(address(new Tokenizer()), ""))); | ||
tokenizer.initialize(ipnft, blindPermissioner); | ||
tokenizer.setIPTokenImplementation(new IPToken()); | ||
} | ||
|
||
function testReserveAndIssue() public { | ||
vm.startPrank(originalOwner); | ||
(uint256 reservationId, IPToken ipToken) = tokenizer.reserveNewIpnftIdAndTokenize(1_000_000 ether, "IPT-SOL-FOO", "QmAgreeToThat", ""); | ||
|
||
vm.expectRevert("ERC721: invalid token ID"); | ||
ipnft.ownerOf(reservationId); | ||
|
||
assertEq(ipToken.balanceOf(originalOwner), 1_000_000 ether); | ||
|
||
//even direct minting works now ... //todo: check if this is intended or if we must prevent this | ||
ipToken.issue(bob, 42 ether); | ||
assertEq(ipToken.balanceOf(bob), 42 ether); | ||
|
||
// ... do anything with the ip token ... | ||
|
||
vm.startPrank(bob); //bob didn't reserve this. | ||
vm.expectRevert(abi.encodeWithSelector(IPNFT.NotOwningReservation.selector, 1)); | ||
ipnft.mintReservation(alice, reservationId, ipfsUri, "A-TOTALLY-DIFFERENT-SYMBOL", ""); | ||
|
||
vm.startPrank(originalOwner); | ||
vm.deal(originalOwner, 0.1 ether); | ||
ipnft.mintReservation{ value: 0.1 ether }(alice, reservationId, ipfsUri, "A-TOTALLY-DIFFERENT-SYMBOL", ""); | ||
|
||
assertEq(ipnft.ownerOf(reservationId), alice); | ||
|
||
vm.startPrank(alice); | ||
ipToken.issue(bob, 58 ether); | ||
assertEq(ipToken.balanceOf(bob), 100 ether); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this correct:
return ipnft.reservations(ipnftId) || ipnft.ownerOf(ipnftId)
if the ipnft is minted it will return
ipnft.ownerOf(ipnftId)
asipnft.reservations(ipnftId)
would beaddress(0)
abd vice versa.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would never assume by default whether a language besides Javascript would automatically cast an (address(0)) to a boolean (true). That code is pretty concise imo. If there's a reservation it returns its initiator, otherwise the holder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes yes the code is clear, I just wanted to know whether the other optiion is also correct or not