-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Test the ThunderSwapPoolFactory
- Loading branch information
1 parent
bcee06b
commit 92cfa7d
Showing
3 changed files
with
80 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.20; | ||
|
||
import {PoolFactoryHelper} from "../../utils/helpers/PoolFactoryHelper.sol"; | ||
import {UniversalHelper} from "../../utils/helpers/UniversalHelper.sol"; | ||
import {Token} from "../../utils/mocks/Token.sol"; | ||
|
||
contract DeployPool is UniversalHelper, PoolFactoryHelper { | ||
function testDeployingThunderSwapPoolRevertsIfTokenNotSupported() public { | ||
address tokenAddress = makeAddr("unsupportedToken"); | ||
|
||
vm.expectRevert(abi.encodeWithSelector(TokenNotSupported.selector, tokenAddress)); | ||
thunderSwapPoolFactory.deployThunderSwapPool(tokenAddress, tokenAddress); | ||
} | ||
|
||
function testDeployingThunderSwapPoolRevertsIfBothTokensAreTheSame() public { | ||
address tokenAddress = makeAddr("unsupportedToken"); | ||
|
||
vm.prank(deployer); | ||
thunderSwapPoolFactory.setSupportedToken(tokenAddress); | ||
vm.expectRevert(PoolCannotHaveTwoTokensOfTheSameType.selector); | ||
thunderSwapPoolFactory.deployThunderSwapPool(tokenAddress, tokenAddress); | ||
} | ||
|
||
function testDeployingThunderSwapPoolRevertsIfPoolAlreadyExists() public distributeTokensToUsers(1e18, 2e18) addInitialLiquidity(1e18, 2e18) { | ||
vm.expectRevert(abi.encodeWithSelector(PoolAlreadyExists.selector, address(thunderSwapPool))); | ||
thunderSwapPoolFactory.deployThunderSwapPool(address(tokenB), address(tokenA)); | ||
} | ||
|
||
function testDeployingThunderSwapPoolEmitsEvent() public { | ||
Token tokenC = new Token("TokenC", "C"); | ||
Token tokenD = new Token("TokenD", "D"); | ||
|
||
vm.startPrank(deployer); | ||
thunderSwapPoolFactory.setSupportedToken(address(tokenC)); | ||
thunderSwapPoolFactory.setSupportedToken(address(tokenD)); | ||
|
||
vm.expectEmit(false, true, true, false); | ||
emit PoolCreated(address(0), address(tokenC), address(tokenD)); | ||
thunderSwapPoolFactory.deployThunderSwapPool(address(tokenC), address(tokenD)); | ||
vm.stopPrank(); | ||
} | ||
} |
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,11 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.20; | ||
|
||
contract PoolFactoryHelper { | ||
event PoolCreated(address newPool, address token1, address token2); | ||
event SupportedToken(address supportedToken); | ||
|
||
error PoolAlreadyExists(address pool); | ||
error PoolCannotHaveTwoTokensOfTheSameType(); | ||
error TokenNotSupported(address tokenAddress); | ||
} |