Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
qiaopengjun5162 committed Jul 29, 2024
1 parent 9da8820 commit 221bb9d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/ERC20Token.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ contract ERC20Token is

/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
// _disableInitializers();
}

/**
Expand Down
24 changes: 13 additions & 11 deletions src/TokenFactoryV1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,19 @@ contract TokenFactoryV1 is Initializable, OwnableUpgradeable, UUPSUpgradeable {
uint perMint
) public {
// 部署实现
ERC20Token implementation = new ERC20Token();
// Deploy the proxy and initialize the contract through the proxy
proxy = new ERC1967Proxy(
address(implementation),
abi.encodeCall(
implementation.initialize,
(msg.sender, symbol, totalSupply, perMint)
)
);
// 用代理关联 MyToken 接口
myToken = ERC20Token(address(proxy));
// ERC20Token implementation = new ERC20Token();
// // Deploy the proxy and initialize the contract through the proxy
// proxy = new ERC1967Proxy(
// address(implementation),
// abi.encodeCall(
// implementation.initialize,
// (msg.sender, symbol, totalSupply, perMint)
// )
// );
// // 用代理关联 MyToken 接口
// myToken = ERC20Token(address(proxy));
myToken = new ERC20Token();
myToken.initialize(msg.sender, symbol, totalSupply, perMint);
console.log("deployInscription newToken: ", address(myToken));

deployedTokens.push(address(myToken));
Expand Down
2 changes: 2 additions & 0 deletions test/TokenFactoryV1Test.sol
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,6 @@ contract TokenFactoryV1Test is Test {
owner.addr
);
}

function testV1Upgradeability() public {}
}
38 changes: 9 additions & 29 deletions test/TokenFactoryV2Test.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,9 @@ import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol";

contract MyToken is ERC20, Ownable, ERC20Permit {
constructor(
address initialOwner
) ERC20("MyToken", "MTK") Ownable(initialOwner) ERC20Permit("MyToken") {}

function mint(address to, uint256 amount) public onlyOwner {
_mint(to, amount);
}
}

contract CounterTest is Test {
TokenFactoryV2 public factoryv2;
MyToken public erc20Token;

ERC20Token public myToken;
ERC1967Proxy proxy;
ERC1967Proxy proxy2;
Expand All @@ -37,18 +27,8 @@ contract CounterTest is Test {
address public tokenAddr;

function setUp() public {
erc20Token = new MyToken(owner.addr);
// myToken.initialize(owner.addr, symbol, totalSupply, perMint);
// Deploy the proxy and initialize the contract through the proxy
// proxy = new ERC1967Proxy(
// address(implementation),
// abi.encodeCall(
// implementation.initialize,
// (owner.addr, symbol, totalSupply, perMint)
// )
// );
// 用代理关联 MyToken 接口
// myToken = ERC20Token(address(proxy));
myToken = new ERC20Token();
myToken.initialize(msg.sender, symbol, totalSupply, perMint);

TokenFactoryV2 implementationV2 = new TokenFactoryV2();
vm.prank(owner.addr);
Expand All @@ -58,18 +38,18 @@ contract CounterTest is Test {
);

// 用代理关联 TokenFactoryV2 接口
// factoryv2 = TokenFactoryV2(address(proxy));
factoryv2 = TokenFactoryV2(address(proxy));

vm.prank(owner.addr);
(bool _success, bytes memory returnData) = address(proxy).call(
(bool success, ) = address(proxy).call(
abi.encodeWithSelector(
factoryv2.setLibraryAddress.selector,
address(erc20Token)
address(myToken)
)
);
console.log(_success, "Success");
require(_success);
// tokenAddr = abi.decode(returnData, (address));

require(success);

// Emit the owner address for debugging purposes
emit log_address(owner.addr);
}
Expand Down

0 comments on commit 221bb9d

Please sign in to comment.