Skip to content

Commit 9fd34e9

Browse files
authored
Merge pull request #16 from kirilradkov14/fix/test-depricated-testFail
Fix/test depricated test fail
2 parents 17d7505 + bbb6f1c commit 9fd34e9

File tree

8 files changed

+52
-35
lines changed

8 files changed

+52
-35
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# 🚀 EVM Launchpad - Gas Efficient Token Launchpad Smart Contract
1+
# 🚀 EVM Launchpad Contract - Gas Efficient Token Launchpad Smart Contract
22

3-
**EVM-compatible Launchpad System** inspired by [pump.fun](https://pump.fun) featuring **zero-liquidity launches** and **automated price discovery** through an exponential bonding curve. Designed for secure, transparent, and efficient token distribution.
3+
**EVM-compatible Launchpad System** inspired by **pump.fun** featuring **zero-liquidity launches** and **automated price discovery** through an exponential bonding curve. Designed for secure, transparent, and efficient token distribution.
44

55
![Solidity Version](https://img.shields.io/badge/Solidity-^0.8.28-informational)
66
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

src/LaunchpadFactory.sol

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ contract LaunchpadFactory is Ownable(msg.sender), Pausable, ILaunchpadFactory {
4848
*/
4949
function createLaunchpad(string memory _name, string memory _symbol)
5050
external
51-
payable
5251
whenNotPaused
5352
returns (address launchpad)
5453
{

src/interfaces/launchpad/ILaunchpadFactory.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
pragma solidity ^0.8.28;
33

44
interface ILaunchpadFactory {
5-
function createLaunchpad(string memory _name, string memory _symbol) external payable returns (address launchpad);
5+
function createLaunchpad(string memory _name, string memory _symbol) external returns (address launchpad);
66
}

test/BondingCurve.t.sol

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ contract BondingCurveTest is Test {
1212

1313
function setUp() public {}
1414

15-
function testPurchaseBaseCases() public pure {
15+
function test_PurchaseBaseCases() public pure {
1616
// Test purchase with 0 ETH supply and 1 ETH input
1717
// Should return some tokens
1818
uint256 tokensOut = BondingCurve.calculatePurchaseReturn(0, 1 ether);
@@ -24,7 +24,7 @@ contract BondingCurveTest is Test {
2424
assert(zeroOut == 0);
2525
}
2626

27-
function testPurchasePriceIncrease() public {
27+
function test_PurchasePriceIncrease() public {
2828
// Test that token price increases with ETH supply
2929
uint256 ethIn = 1 ether;
3030
uint256 supply1 = 10 ether;
@@ -41,13 +41,13 @@ contract BondingCurveTest is Test {
4141
assertTrue(priceDiff > 0 && priceDiff < 50, "Price increase should be reasonable");
4242
}
4343

44-
function testSellBaseCases() public {
44+
function test_SellBaseCases() public {
4545
// Test sell with 0 token input
4646
uint256 ethOut = BondingCurve.calculateSellReturn(1 ether, 0);
4747
assertEq(ethOut, 0, "Should return 0 ETH for 0 tokens");
4848
}
4949

50-
function testSellPriceDecrease() public {
50+
function test_SellPriceDecrease() public {
5151
// Setup initial state
5252
uint256 initialEthSupply = 50 ether;
5353

@@ -60,7 +60,7 @@ contract BondingCurveTest is Test {
6060
assertTrue(ethOut2 < ethOut1, "Price should decrease after selling");
6161
}
6262

63-
function testCurveSymmetry() public {
63+
function test_CurveSymmetry() public {
6464
uint256 ethSupply = 10 ether;
6565
uint256 ethIn = 1 ether;
6666

@@ -75,7 +75,7 @@ contract BondingCurveTest is Test {
7575
assertTrue(ethOut > ethIn * 99 / 100, "Slippage should be reasonable");
7676
}
7777

78-
function testExtremeValues() public {
78+
function test_ExtremeValues() public {
7979
// Test with very small amounts
8080
uint256 tinyEth = 1 wei;
8181
uint256 tokensForTiny = BondingCurve.calculatePurchaseReturn(0, tinyEth);
@@ -96,16 +96,31 @@ contract BondingCurveTest is Test {
9696
assertTrue(tokensForSmall < tokensForLarge, "Larger ETH input should yield more tokens");
9797
}
9898

99-
function testSellRevertOnInvalidAmount() public {
99+
function test_CannotSellOnInvalidAmount() public {
100100
uint256 ethSupply = 10 ether;
101101

102102
// Try to sell more tokens than possible
103103
uint256 maxTokens = BondingCurve.calculatePurchaseReturn(0, ethSupply);
104-
vm.expectRevert();
105-
BondingCurve.calculateSellReturn(ethSupply, maxTokens * 2);
104+
try this.callCalculateSellReturn(ethSupply, maxTokens * 2) {
105+
fail();
106+
} catch Error(string memory) {
107+
fail();
108+
} catch (bytes memory returnData) {
109+
bytes4 expectedSelector = BondingCurve.FormulaInvalidTokenAmount.selector;
110+
bytes4 actualSelector;
111+
assembly {
112+
actualSelector := mload(add(returnData, 0x20))
113+
}
114+
assertEq(actualSelector, expectedSelector, "Wrong error selector");
115+
}
116+
}
117+
118+
// Helper function to call the library function externally
119+
function callCalculateSellReturn(uint256 ethSupply, uint256 tokenAmount) external pure returns (uint256) {
120+
return BondingCurve.calculateSellReturn(ethSupply, tokenAmount);
106121
}
107122

108-
function testPriceProgression() public {
123+
function test_PriceProgression() public {
109124
uint256 ethSupply = 0;
110125
uint256 ethIncrement = 1 ether;
111126
uint256 lastTokenAmount = type(uint256).max;
@@ -121,7 +136,7 @@ contract BondingCurveTest is Test {
121136
}
122137
}
123138

124-
function testCurveParameters() public {
139+
function test_CurveParameters() public {
125140
// Test that the curve parameters produce expected behavior
126141
uint256 initialPurchase = BondingCurve.calculatePurchaseReturn(0, 1 ether);
127142

test/Launchpad.t.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ contract LaunchpadTest is Test, ArtifactStorage {
4444
require(address(launchpadFactory) != address(0), "LaunchpadFactory deployment failed");
4545
}
4646

47-
function testProxyCreation() public {
47+
function test_ProxyCreation() public {
4848
string memory tokenName = "Test Token";
4949
string memory tokenSymbol = "TTKN";
5050

51-
address launchpad = launchpadFactory.createLaunchpad{value: 1 ether}(tokenName, tokenSymbol);
51+
address launchpad = launchpadFactory.createLaunchpad(tokenName, tokenSymbol);
5252

5353
assertTrue(launchpad != address(0), "Launchpad creation failed");
5454

@@ -85,11 +85,11 @@ contract LaunchpadTest is Test, ArtifactStorage {
8585
assertTrue(userEthBalance >= ethReceived, "User ETH balance mismatch after token sale");
8686
}
8787

88-
function testLiquidityMigration() public {
88+
function test_LiquidityMigration() public {
8989
string memory tokenName = "Test Token";
9090
string memory tokenSymbol = "TTKN";
9191

92-
address launchpad = launchpadFactory.createLaunchpad{value: 1 ether}(tokenName, tokenSymbol);
92+
address launchpad = launchpadFactory.createLaunchpad(tokenName, tokenSymbol);
9393

9494
assertTrue(launchpad != address(0), "Launchpad creation failed");
9595

test/LaunchpadFuzz.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ contract LaunchpadFuzzTest is Test, ArtifactStorage {
4444
require(address(launchpadFactory) != address(0), "LaunchpadFactory deployment failed");
4545

4646
// Create a proxy instance for testing
47-
address launchpad = launchpadFactory.createLaunchpad{value: 1 ether}("Test Token", "TTKN");
47+
address launchpad = launchpadFactory.createLaunchpad("Test Token", "TTKN");
4848
proxy = Launchpad(payable(launchpad));
4949
}
5050

test/Proxy.t.sol

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,14 @@ contract ProxyTest is Test, ArtifactStorage {
6666
vm.deal(bob, INITIAL_ETH_BALANCE);
6767
}
6868

69-
function testInitialState() public view {
69+
function test_InitialState() public view {
7070
assertEq(proxy.ethSupply(), 0, "Initial ETH supply should be 0");
7171
assertEq(proxy.tokenSupply(), INITIAL_TOKEN_SUPPLY, "Initial token supply mismatch");
7272
assertEq(proxy.tokensLiquidity(), INITIAL_LIQUIDITY_TOKENS, "Initial liquidity tokens mismatch");
7373
assertFalse(proxy.isMigrated(), "Should not be migrated initially");
7474
}
7575

76-
function testSingleBuyTokens() public {
76+
function test_SingleBuyTokens() public {
7777
uint256 buyAmount = 1 ether;
7878
uint256 initialTokenBalance = proxy.token().balanceOf(alice);
7979
uint256 initialEthSupply = proxy.ethSupply();
@@ -90,7 +90,7 @@ contract ProxyTest is Test, ArtifactStorage {
9090
assertEq(IERC20(address(proxy.weth())).balanceOf(address(proxy)), buyAmount, "WETH balance incorrect");
9191
}
9292

93-
function testMultipleBuysIncreasePrices() public {
93+
function test_MultipleBuysIncreasePrices() public {
9494
uint256 buyAmount = 1 ether;
9595

9696
// First buy
@@ -108,7 +108,7 @@ contract ProxyTest is Test, ArtifactStorage {
108108
assertTrue(secondBuyTokens < firstBuyTokens, "Price should increase after buys");
109109
}
110110

111-
function testSellTokens() public {
111+
function test_SellTokens() public {
112112
// First buy tokens
113113
uint256 buyAmount = 1 ether;
114114
vm.startPrank(alice);
@@ -136,7 +136,7 @@ contract ProxyTest is Test, ArtifactStorage {
136136
assertEq(proxy.token().balanceOf(alice), 0, "Should have no tokens left");
137137
}
138138

139-
function testPriceDecreasesAfterSell() public {
139+
function test_PriceDecreasesAfterSell() public {
140140
// Initial buy
141141
uint256 buyAmount = 2 ether;
142142
vm.startPrank(alice);
@@ -156,7 +156,7 @@ contract ProxyTest is Test, ArtifactStorage {
156156
assertTrue(priceAfterSell < priceBeforeSell, "Price should decrease after sell");
157157
}
158158

159-
function testThresholdMigration() public {
159+
function test_ThresholdMigration() public {
160160
vm.startPrank(alice);
161161
uint256 thresholdAmount = proxy.THRESHOLD();
162162

@@ -170,18 +170,20 @@ contract ProxyTest is Test, ArtifactStorage {
170170
vm.stopPrank();
171171
}
172172

173-
function testFailBuyAfterMigration() public {
174-
// First reach threshold
173+
function test_CannotBuyAfterMigration() public {
174+
// First reach threshold and verify migration
175175
vm.startPrank(alice);
176-
proxy.buyTokens{value: proxy.THRESHOLD()}(0);
176+
uint256 exceedingAmount = proxy.THRESHOLD() + 1 ether;
177+
proxy.buyTokens{value: exceedingAmount}(0);
178+
assertTrue(proxy.isMigrated(), "Should be migrated after threshold");
177179

178-
// Try to buy after migration
180+
// Should revert when trying to buy after migration
179181
vm.expectRevert(abi.encodeWithSignature("LaunchpadInvalidState()"));
180182
proxy.buyTokens{value: 1 ether}(0);
181183
vm.stopPrank();
182184
}
183185

184-
function testMinimumOutputAmount() public {
186+
function test_MinimumOutputAmount() public {
185187
uint256 buyAmount = 1 ether;
186188
uint256 expectedTokens = proxy.getTokensOutAtCurrentSupply(buyAmount);
187189

@@ -192,7 +194,7 @@ contract ProxyTest is Test, ArtifactStorage {
192194
vm.stopPrank();
193195
}
194196

195-
function testFailSellMinimumOutputTooHigh() public {
197+
function test_CannotBuyWithHighMinimumOutput() public {
196198
uint256 buyAmount = 1 ether;
197199
uint256 expectedTokens = proxy.getTokensOutAtCurrentSupply(buyAmount);
198200

@@ -203,6 +205,7 @@ contract ProxyTest is Test, ArtifactStorage {
203205

204206
// Try to buy with minimum output higher than possible
205207
vm.startPrank(alice);
208+
vm.expectRevert(abi.encodeWithSignature("LaunchpadInsufficientOutputAmount()"));
206209
proxy.buyTokens{value: buyAmount}(expectedTokens + 1);
207210
vm.stopPrank();
208211

test/UniswapV2.t.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ contract UniswapV2 is Test, ArtifactStorage {
3232

3333
function setUp() public {}
3434

35-
function testWethDeployment() public {
35+
function test_WethDeployment() public {
3636
weth = _deployBytecode(ArtifactStorage.wethBytecode);
3737

3838
// Assert deployment succeeded
@@ -53,7 +53,7 @@ contract UniswapV2 is Test, ArtifactStorage {
5353
assertEq(newBalance, 0.5 ether, "Balance should be 0.5 Ether");
5454
}
5555

56-
function testFactoryDeployment() public {
56+
function test_FactoryDeployment() public {
5757
address feeToSetter = vm.addr(1);
5858
bytes memory constructorArgs = abi.encode(feeToSetter);
5959
bytes memory bytecodeWithArgs = abi.encodePacked(ArtifactStorage.uniswapV2Factory, constructorArgs);
@@ -82,7 +82,7 @@ contract UniswapV2 is Test, ArtifactStorage {
8282
assertEq(pair, retrievedPair, "Retrieved pair address does not match created pair");
8383
}
8484

85-
function testRouterDeployment() public {
85+
function test_RouterDeployment() public {
8686
// Deploy WETH
8787
weth = _deployBytecode(ArtifactStorage.wethBytecode);
8888
assertTrue(weth != address(0), "WETH deployment failed");

0 commit comments

Comments
 (0)