Skip to content

Commit

Permalink
version numbered, tests on current version
Browse files Browse the repository at this point in the history
  • Loading branch information
polus-arcticus committed Jan 9, 2024
1 parent 337c4e5 commit fb1b7b3
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 19 deletions.
4 changes: 3 additions & 1 deletion src/IPToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { OwnableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/O
import { Strings } from "@openzeppelin/contracts/utils/Strings.sol";
import { Base64 } from "@openzeppelin/contracts/utils/Base64.sol";

import "forge-std/console.sol";
struct Metadata {
uint256 ipnftId;
address originalOwner;
Expand Down Expand Up @@ -60,7 +61,8 @@ contract IPToken is ERC20BurnableUpgradeable, OwnableUpgradeable {
*/

function hash() external view returns (uint256) {
return uint256(keccak256(abi.encodePacked(_metadata.originalOwner, _metadata.ipnftId)));
uint256 keccak = uint256(keccak256(abi.encodePacked(_metadata.originalOwner, _metadata.ipnftId)));
return keccak;
}

/**
Expand Down
18 changes: 15 additions & 3 deletions src/Tokenizer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ contract Tokenizer is UUPSUpgradeable, OwnableUpgradeable {
string symbol
);

event IPTokenUpgraded(
address indexed oldAddress,
address indexed newAddress
);

IPNFT internal ipnft;

//this is the old term to keep the storage layout intact
Expand Down Expand Up @@ -58,13 +63,20 @@ contract Tokenizer is UUPSUpgradeable, OwnableUpgradeable {
/**
*
* @notice sets the new implementation address of the IPToken
* @param impl the new implementation
* @param _tokenImplementation address pointing to the new implementation
*/
function setTokenImpl(address impl) public onlyOwner {
function setIPTokenImplementation(
address _tokenImplementation
) public onlyOwner {
/*
could call some functions on old contract to make sure its tokenizer not another contract behind a proxy for safety
*/
tokenImplementation = impl;
address oldImplementation = tokenImplementation;
tokenImplementation = _tokenImplementation;
emit IPTokenUpgraded(
oldImplementation,
_tokenImplementation
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ error AlreadyTokenized();
/// @title Tokenizer 1.1
/// @author molecule.to
/// @notice tokenizes an IPNFT to an ERC20 token (called IPT) and controls its supply.
contract Tokenizer is UUPSUpgradeable, OwnableUpgradeable {
contract Tokenizer11 is UUPSUpgradeable, OwnableUpgradeable {
event TokensCreated(
uint256 indexed moleculesId,
uint256 indexed ipnftId,
Expand Down
32 changes: 18 additions & 14 deletions test/Tokenizer.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { AcceptAllAuthorizer } from "./helpers/AcceptAllAuthorizer.sol";

import { FakeERC20 } from "../src/helpers/FakeERC20.sol";
import { MustOwnIpnft, AlreadyTokenized, Tokenizer } from "../src/Tokenizer.sol";
import { Tokenizer as OldTokenizer } from "../src/helpers/test-upgrades/TokenizerOld.sol";
import { Tokenizer11 } from "../src/helpers/test-upgrades/Tokenizer11.sol";

import { IPToken, OnlyIssuerOrOwner, TokenCapped } from "../src/IPToken.sol";
import { Molecules } from "../src/helpers/test-upgrades/Molecules.sol";
Expand Down Expand Up @@ -52,11 +52,11 @@ contract TokenizerTest is Test {
address escrow = makeAddr("escrow");

IPNFT internal ipnft;
OldTokenizer internal oldTokenizer;
Tokenizer11 internal tokenizer11;
Tokenizer internal tokenizer;
SchmackoSwap internal schmackoSwap;
IPermissioner internal blindPermissioner;

IPToken internal ipToken;
FakeERC20 internal erc20;

function setUp() public {
Expand All @@ -78,8 +78,11 @@ contract TokenizerTest is Test {

blindPermissioner = new BlindPermissioner();

oldTokenizer = OldTokenizer(address(new ERC1967Proxy(address(new OldTokenizer()), "")));
oldTokenizer.initialize(ipnft, blindPermissioner);
ipToken = new IPToken();

tokenizer = Tokenizer(address(new ERC1967Proxy(address(new Tokenizer()), "")));
tokenizer.initialize(ipnft, blindPermissioner);
tokenizer.setIPTokenImplementation(address(ipToken));

vm.stopPrank();

Expand All @@ -92,7 +95,7 @@ contract TokenizerTest is Test {

function testUrl() public {
vm.startPrank(originalOwner);
IPToken tokenContract = oldTokenizer.tokenizeIpnft(1, 100_000, "IPT", agreementCid, "");
IPToken tokenContract = tokenizer.tokenizeIpnft(1, 100_000, "IPT", agreementCid, "");
string memory uri = tokenContract.uri();
assertGt(bytes(uri).length, 200);
vm.stopPrank();
Expand All @@ -101,7 +104,7 @@ contract TokenizerTest is Test {
function testIssueIPToken() public {
vm.startPrank(originalOwner);
//ipnft.setApprovalForAll(address(tokenizer), true);
IPToken tokenContract = oldTokenizer.tokenizeIpnft(1, 100_000, "IPT", agreementCid, "");
IPToken tokenContract = tokenizer.tokenizeIpnft(1, 100_000, "IPT", agreementCid, "");
vm.stopPrank();

assertEq(tokenContract.balanceOf(originalOwner), 100_000);
Expand All @@ -122,7 +125,7 @@ contract TokenizerTest is Test {

function testIncreaseIPToken() public {
vm.startPrank(originalOwner);
IPToken tokenContract = oldTokenizer.tokenizeIpnft(1, 100_000, "IPT", agreementCid, "");
IPToken tokenContract = tokenizer.tokenizeIpnft(1, 100_000, "IPT", agreementCid, "");

tokenContract.transfer(alice, 25_000);
tokenContract.transfer(bob, 25_000);
Expand Down Expand Up @@ -155,18 +158,18 @@ contract TokenizerTest is Test {

function testCanBeTokenizedOnlyOnce() public {
vm.startPrank(originalOwner);
oldTokenizer.tokenizeIpnft(1, 100_000, "IPT", agreementCid, "");
tokenizer.tokenizeIpnft(1, 100_000, "IPT", agreementCid, "");

vm.expectRevert(AlreadyTokenized.selector);
oldTokenizer.tokenizeIpnft(1, 100_000, "IPT", agreementCid, "");
tokenizer.tokenizeIpnft(1, 100_000, "IPT", agreementCid, "");
vm.stopPrank();
}

function testCannotTokenizeIfNotOwner() public {
vm.startPrank(alice);

vm.expectRevert(MustOwnIpnft.selector);
oldTokenizer.tokenizeIpnft(1, 100_000, "IPT", agreementCid, "");
tokenizer.tokenizeIpnft(1, 100_000, "IPT", agreementCid, "");
vm.stopPrank();
}

Expand All @@ -182,7 +185,7 @@ contract TokenizerTest is Test {
vm.stopPrank();

vm.startPrank(originalOwner);
IPToken tokenContract = oldTokenizer.tokenizeIpnft(1, 100_000, "IPT", agreementCid, "");
IPToken tokenContract = tokenizer.tokenizeIpnft(1, 100_000, "IPT", agreementCid, "");
tokenContract.safeTransfer(address(wallet), 100_000);
vm.stopPrank();

Expand All @@ -209,8 +212,9 @@ contract TokenizerTest is Test {
function testCanUpgradeErc20TokenImplementation() public {
vm.selectFork(mainnetFork);
vm.startPrank(0xCfA0F84660fB33bFd07C369E5491Ab02C449f71B); // Owner address on mainnet
tokenizer = new Tokenizer();
oldTokenizer.upgradeTo(address(tokenizer));
tokenizer11 = Tokenizer11(0x58EB89C69CB389DBef0c130C6296ee271b82f436);
tokenizer11.upgradeTo(address(new Tokenizer()));
vm.stopPrank();

// vm.startPrank(deployer);
// vm.stopPrank();
Expand Down

0 comments on commit fb1b7b3

Please sign in to comment.