Skip to content

Commit

Permalink
refactor: Update deploy function to deployERC20Upgradeable in TokenFa…
Browse files Browse the repository at this point in the history
…ctory (#6)
  • Loading branch information
gnkz authored Oct 20, 2024
1 parent 3c775d5 commit 56158ac
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/TokenFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ contract TokenFactory {
tokenImplementation = _tokenImplementation;
}

function deploy(
function deployERC20Upgradeable(
string memory _name,
string memory _symbol,
uint256 _initialSupply,
Expand Down
15 changes: 8 additions & 7 deletions test/TokenFactory.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ contract TokenFactoryTest is Test {
uint256 initialSupply = 1_000_000 ether;

ERC20TokenUpgradeable token =
ERC20TokenUpgradeable(factory.deploy(tokenName, tokenSymbol, initialSupply, owner, owner));
ERC20TokenUpgradeable(factory.deployERC20Upgradeable(tokenName, tokenSymbol, initialSupply, owner, owner));

vm.assertEq(token.name(), tokenName);
vm.assertEq(token.symbol(), tokenSymbol);
Expand All @@ -45,7 +45,7 @@ contract TokenFactoryTest is Test {
string memory tokenSymbol = "uToken";
uint256 initialSupply = 1_000_000 ether;

address tokenProxy = factory.deploy(tokenName, tokenSymbol, initialSupply, owner, owner);
address tokenProxy = factory.deployERC20Upgradeable(tokenName, tokenSymbol, initialSupply, owner, owner);

vm.expectRevert(Initializable.InvalidInitialization.selector);
ERC20TokenUpgradeableProxy(payable(tokenProxy)).initialize(
Expand All @@ -62,7 +62,7 @@ contract TokenFactoryTest is Test {
uint256 initialSupply = 1_000_000 ether;

ERC20TokenUpgradeable token =
ERC20TokenUpgradeable(factory.deploy(tokenName, tokenSymbol, initialSupply, owner, owner));
ERC20TokenUpgradeable(factory.deployERC20Upgradeable(tokenName, tokenSymbol, initialSupply, owner, owner));

vm.expectRevert(Initializable.NotInitializing.selector);
token.initialize(tokenName, tokenSymbol, initialSupply, owner, owner);
Expand All @@ -74,7 +74,7 @@ contract TokenFactoryTest is Test {
uint256 initialSupply = 1_000_000 ether;

ERC20TokenUpgradeable tokenProxy =
ERC20TokenUpgradeable(factory.deploy(tokenName, tokenSymbol, initialSupply, owner, owner));
ERC20TokenUpgradeable(factory.deployERC20Upgradeable(tokenName, tokenSymbol, initialSupply, owner, owner));

ERC20TokenUpgradeable newToken = new ERC20TokenUpgradeable();

Expand All @@ -90,13 +90,14 @@ contract TokenFactoryTest is Test {
address predictedTokenAddress = factory.predictNextTokenAddress(address(this));

ERC20TokenUpgradeable token =
ERC20TokenUpgradeable(factory.deploy(tokenName, tokenSymbol, initialSupply, owner, owner));
ERC20TokenUpgradeable(factory.deployERC20Upgradeable(tokenName, tokenSymbol, initialSupply, owner, owner));

vm.assertEq(address(token), predictedTokenAddress);

predictedTokenAddress = factory.predictNextTokenAddress(address(this));

token = ERC20TokenUpgradeable(factory.deploy(tokenName, tokenSymbol, initialSupply, owner, owner));
token =
ERC20TokenUpgradeable(factory.deployERC20Upgradeable(tokenName, tokenSymbol, initialSupply, owner, owner));

vm.assertEq(address(token), predictedTokenAddress);
}
Expand All @@ -111,7 +112,7 @@ contract TokenFactoryTest is Test {
address predictedTokenAddress = factory.predictNextTokenAddress(address(this));

ERC20TokenUpgradeable token =
ERC20TokenUpgradeable(factory.deploy(tokenName, tokenSymbol, initialSupply, owner, owner));
ERC20TokenUpgradeable(factory.deployERC20Upgradeable(tokenName, tokenSymbol, initialSupply, owner, owner));

vm.assertEq(address(token), predictedTokenAddress);
vm.assertEq(factory.nonce(address(this)), initialNonce + 1);
Expand Down

0 comments on commit 56158ac

Please sign in to comment.