From 9370b7529a1dc7c8db99e99040e468bffcf7d711 Mon Sep 17 00:00:00 2001 From: Taylor Hulsmans Date: Wed, 17 Jan 2024 12:38:08 +0100 Subject: [PATCH] creating ipnfts through tokenizer in permissioner tests --- test/CrowdSalePermissioned.t.sol | 43 +++++++++++++++++++++++++++---- test/Permissioner.t.sol | 44 +++++++++++++++++++++++++++++--- 2 files changed, 78 insertions(+), 9 deletions(-) diff --git a/test/CrowdSalePermissioned.t.sol b/test/CrowdSalePermissioned.t.sol index df884f0a..534d76ef 100644 --- a/test/CrowdSalePermissioned.t.sol +++ b/test/CrowdSalePermissioned.t.sol @@ -7,29 +7,39 @@ import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import { IERC20Metadata } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; import { ECDSA } from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol"; +import { ERC1967Proxy } from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; import { IPToken, Metadata } from "../src/IPToken.sol"; import { CrowdSale, Sale, SaleInfo, SaleState, BadDecimals } from "../src/crowdsale/CrowdSale.sol"; import { StakedLockingCrowdSale, BadPrice } from "../src/crowdsale/StakedLockingCrowdSale.sol"; -import { IPermissioner, TermsAcceptedPermissioner, InvalidSignature } from "../src/Permissioner.sol"; - +import { IPermissioner, TermsAcceptedPermissioner, InvalidSignature, BlindPermissioner } from "../src/Permissioner.sol"; +import { MustOwnIpnft, AlreadyTokenized, Tokenizer, ZeroAddress } from "../src/Tokenizer.sol"; +import { IPNFT } from "../src/IPNFT.sol"; import { TokenVesting } from "@moleculeprotocol/token-vesting/TokenVesting.sol"; import { TimelockedToken } from "../src/TimelockedToken.sol"; import { FakeERC20 } from "../src/helpers/FakeERC20.sol"; //import { BioPriceFeed, IPriceFeedConsumer } from "../src/BioPriceFeed.sol"; import { CrowdSaleHelpers } from "./helpers/CrowdSaleHelpers.sol"; +import { AcceptAllAuthorizer } from "./helpers/AcceptAllAuthorizer.sol"; contract CrowdSalePermissionedTest is Test { address deployer = makeAddr("chucknorris"); address emitter = makeAddr("emitter"); + address anyone = makeAddr("anyone"); address bidder; uint256 bidderPk; - address anyone = makeAddr("anyone"); + uint256 MINTING_FEE = 0.001 ether; + string DEFAULT_SYMBOL = "IPT-0001"; + string ipfsUri = "ipfs://bafkreiankqd3jvpzso6khstnaoxovtyezyatxdy7t2qzjoolqhltmasqki"; + string agreementCid = "bafkreigk5dvqblnkdniges6ft5kmuly47ebw4vho6siikzmkaovq6sjstq"; + IPNFT internal ipnft; + Tokenizer internal tokenizer; IPToken internal auctionToken; FakeERC20 internal biddingToken; FakeERC20 internal daoToken; + IPermissioner internal blindPermissioner; //this typically is the DAO's general vesting contract TokenVesting internal vestedDao; @@ -43,13 +53,36 @@ contract CrowdSalePermissionedTest is Test { (bidder, bidderPk) = makeAddrAndKey("bidder"); vm.startPrank(deployer); - auctionToken = new IPToken(); - auctionToken.initialize("IPTOKENS", "IPT-0001", Metadata(42, msg.sender, "ipfs://abcde")); + ipnft = IPNFT(address(new ERC1967Proxy(address(new IPNFT()), ""))); + ipnft.initialize(); + ipnft.setAuthorizer(new AcceptAllAuthorizer()); + + tokenizer = Tokenizer(address(new ERC1967Proxy(address(new Tokenizer()), ""))); + blindPermissioner = new BlindPermissioner(); + tokenizer.initialize(ipnft, blindPermissioner); + tokenizer.setIPTokenImplementation(new IPToken()); + biddingToken = new FakeERC20("USD token", "USDC"); daoToken = new FakeERC20("DAO token", "DAO"); + vm.stopPrank(); + + vm.deal(emitter, MINTING_FEE); + + vm.startPrank(emitter); + crowdSale = new StakedLockingCrowdSale(); + + uint256 reservationId = ipnft.reserve(); + ipnft.mintReservation{ value: MINTING_FEE }(emitter, reservationId, ipfsUri, DEFAULT_SYMBOL, ""); + + + auctionToken = tokenizer.tokenizeIpnft(1, 100_000, "IPT", agreementCid, ""); + + //auctionToken = new IPToken(); + //auctionToken.initialize("IPTOKENS", "IPT-0001", Metadata(42, msg.sender, "ipfs://abcde")); + auctionToken.issue(emitter, 500_000 ether); vestedDao = new TokenVesting( diff --git a/test/Permissioner.t.sol b/test/Permissioner.t.sol index cd1b9d1c..d5ea0189 100644 --- a/test/Permissioner.t.sol +++ b/test/Permissioner.t.sol @@ -2,13 +2,17 @@ pragma solidity ^0.8.18; import "forge-std/Test.sol"; -import { InvalidSignature, IPermissioner, TermsAcceptedPermissioner } from "../src/Permissioner.sol"; +import { InvalidSignature, IPermissioner, TermsAcceptedPermissioner, BlindPermissioner } from "../src/Permissioner.sol"; import { IPToken, Metadata } from "../src/IPToken.sol"; import { ECDSA } from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol"; +import { AcceptAllAuthorizer } from "./helpers/AcceptAllAuthorizer.sol"; +import { ERC1967Proxy } from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; +import { IPNFT } from "../src/IPNFT.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 { MustOwnIpnft, AlreadyTokenized, Tokenizer, ZeroAddress } from "../src/Tokenizer.sol"; import "./helpers/MakeGnosisWallet.sol"; @@ -22,19 +26,51 @@ contract PermissionerTest is Test { address bob = makeAddr("bob"); uint256 bobPk; + string ipfsUri = "ipfs://bafkreiankqd3jvpzso6khstnaoxovtyezyatxdy7t2qzjoolqhltmasqki"; + string agreementCid = "bafkreigk5dvqblnkdniges6ft5kmuly47ebw4vho6siikzmkaovq6sjstq"; + uint256 MINTING_FEE = 0.001 ether; + string DEFAULT_SYMBOL = "IPT-0001"; + + IPNFT internal ipnft; + Tokenizer internal tokenizer; IPToken ipToken; TermsAcceptedPermissioner internal permissioner; function setUp() public { + (alice, alicePk) = makeAddrAndKey("alice"); (bob, bobPk) = makeAddrAndKey("bob"); vm.startPrank(deployer); + + ipnft = IPNFT(address(new ERC1967Proxy(address(new IPNFT()), ""))); + ipnft.initialize(); + ipnft.setAuthorizer(new AcceptAllAuthorizer()); + permissioner = new TermsAcceptedPermissioner(); - ipToken = new IPToken(); - Metadata memory md = Metadata(1, originalOwner, "abcde"); - ipToken.initialize("foo", "BAR", md); + tokenizer = Tokenizer(address(new ERC1967Proxy(address(new Tokenizer()), ""))); + + BlindPermissioner blindPermissioner = new BlindPermissioner(); + tokenizer.initialize(ipnft, blindPermissioner); + tokenizer.setIPTokenImplementation(new IPToken()); + + //ipToken = new IPToken(); + //Metadata memory md = Metadata(1, originalOwner, "abcde"); + //ipToken.initialize("foo", "BAR", md); + + vm.stopPrank(); + + vm.deal(originalOwner, MINTING_FEE); + + vm.startPrank(originalOwner); + uint256 reservationId = ipnft.reserve(); + ipnft.mintReservation{ value: MINTING_FEE }(originalOwner, reservationId, ipfsUri, DEFAULT_SYMBOL, ""); + + ipToken = tokenizer.tokenizeIpnft(1, 100_000, "IPT", agreementCid, ""); + vm.stopPrank(); + vm.startPrank(deployer); + tokenizer.reinit(permissioner); vm.stopPrank(); }