Skip to content

Commit

Permalink
Test changes (#191)
Browse files Browse the repository at this point in the history
Test changes and some new assertions for ekubo fork tests.
  • Loading branch information
ermvrs authored Feb 5, 2024
1 parent ea4f694 commit 95e51c8
Show file tree
Hide file tree
Showing 3 changed files with 276 additions and 97 deletions.
184 changes: 146 additions & 38 deletions contracts/src/tests/fork_tests/test_ekubo.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,9 @@ fn test_launch_meme() {
let owner = snforge_std::test_address();
let (quote, quote_address) = deploy_eth_with_owner(owner);
let starting_price = i129 { sign: true, mag: 4600158 }; // 0.01ETH/MEME
let quote_to_deposit = 215_000
* pow_256(10, 18); // 10% of the total supply at a price of 0.01ETH/MEME
let quote_to_deposit = PercentageMath::percent_mul(
2_100_000 * pow_256(10, 16), 10_120
); // 10% of the total supply at a price of 0.01ETH/MEME
let mut spy = spy_events(SpyOn::One(MEMEFACTORY_ADDRESS()));
let (memecoin_address, id, position) = launch_memecoin_on_ekubo(
quote_address,
Expand All @@ -234,8 +235,9 @@ fn test_launch_meme() {
let reserve_memecoin = memecoin.balance_of(core.contract_address);
let reserve_quote = ERC20ABIDispatcher { contract_address: quote_address }
.balance_of(core.contract_address);
//TODO: fix the reserve quote must be the amount bought by the team
// assert(reserve_quote == 0, 'reserve quote not 0');

assert(reserve_quote >= PercentageMath::percent_mul(quote_to_deposit, 9980), 'reserve too low');
// No need to check +2% percent

// Verify that the reserve of memecoin is within 0.5% of the (total supply minus the team allocation)
// When providing liquidity, if the liquidity provided doesn't exactly match the repartition between
Expand Down Expand Up @@ -282,8 +284,9 @@ fn test_transfer_ekuboLP_position() {
let owner = snforge_std::test_address();
let (quote, quote_address) = deploy_eth_with_owner(owner);
let starting_price = i129 { sign: true, mag: 4600158 }; // 0.01ETH/MEME
let quote_to_deposit = 215_000
* pow_256(10, 18); // 10% of the total supply at a price of 0.01ETH/MEME
let quote_to_deposit = PercentageMath::percent_mul(
2_100_000 * pow_256(10, 16), 10_120
); // 10% of the total supply at a price of 0.01ETH/MEME
let (memecoin_address, id, position) = launch_memecoin_on_ekubo(
quote_address,
0xc49ba5e353f7d00000000000000000,
Expand Down Expand Up @@ -370,11 +373,6 @@ fn test_launch_meme_token0_price_below_1() {
let post_balance_quote = quote.balance_of(recipient);
let balance_quote_diff = post_balance_quote - pre_balance_quote;
assert(balance_of_memecoin == 0, 'memecoin shouldnt collect fees');
//TODO: restore this check
// assert(
// balance_quote_diff == PercentageMath::percent_mul(amount_in, 0030),
// 'should collect 0.3% of eth'
//);
}

#[test]
Expand All @@ -383,9 +381,9 @@ fn test_launch_meme_token1_price_below_1() {
let owner = snforge_std::test_address();
let (quote, quote_address) = deploy_token0_with_owner(owner);
let starting_price = i129 { sign: true, mag: 4600158 }; // 0.01ETH/MEME
//TODO investigate with the correct amount
let quote_to_deposit = 2_500_000
* pow_256(10, 16); // 10% of the total supply at a price of 0.01ETH/MEME
let quote_to_deposit = PercentageMath::percent_mul(
2_100_000 * pow_256(10, 16), 10_120
); // 10% of the total supply at a price of 0.01ETH/MEME
let (memecoin_address, id, position) = launch_memecoin_on_ekubo(
quote_address,
0xc49ba5e353f7d00000000000000000,
Expand Down Expand Up @@ -423,8 +421,10 @@ fn test_launch_meme_token1_price_below_1() {
let reserve_memecoin = memecoin.balance_of(core.contract_address);
let reserve_quote = ERC20ABIDispatcher { contract_address: quote_address }
.balance_of(core.contract_address);
//TODO: fix now reserves have the initial eth of the team.
// assert(reserve_quote == 0, 'reserve quote not 0');

assert(
reserve_quote >= PercentageMath::percent_mul(quote_to_deposit, 9980), 'quote reserve low'
);

// Verify that the reserve of memecoin is within 0.5% of the (total supply minus the team allocation)
let team_allocation = memecoin.get_team_allocation();
Expand Down Expand Up @@ -455,11 +455,6 @@ fn test_launch_meme_token1_price_below_1() {
let post_balance_quote = quote.balance_of(recipient);
let balance_quote_diff = post_balance_quote - pre_balance_quote;
assert(balance_of_memecoin == 0, 'memecoin shouldnt collect fees');
//TODO: restore this check
// assert(
// balance_quote_diff == PercentageMath::percent_mul(amount_in, 0030),
// 'should collect 0.3% of eth'
//);
}

#[test]
Expand Down Expand Up @@ -507,8 +502,10 @@ fn test_launch_meme_token0_price_above_1() {
let reserve_quote = ERC20ABIDispatcher { contract_address: quote_address }
.balance_of(core.contract_address);

//TODO: now reserves have the initial eth of the team.
// assert(reserve_quote == 0, 'reserve quote not 0');
assert(
reserve_quote >= PercentageMath::percent_mul(quote_to_deposit, 9900), 'quote reserve low'
);
// Changed percent range to %1 here, it was reverting lower.

// Verify that the reserve of memecoin is within 0.5% of the (total supply minus the team allocation)
let team_allocation = memecoin.get_team_allocation();
Expand Down Expand Up @@ -541,12 +538,6 @@ fn test_launch_meme_token0_price_above_1() {
let post_balance_quote = quote.balance_of(recipient);
let balance_quote_diff = post_balance_quote - pre_balance_quote;
assert(balance_of_memecoin == 0, 'memecoin shouldnt collect fees');
//TODO: restore this check
//TODO: restore this check
// assert(
// balance_quote_diff == PercentageMath::percent_mul(amount_in, 0030),
// 'should collect 0.3% of eth'
//);
}

#[test]
Expand Down Expand Up @@ -594,8 +585,11 @@ fn test_launch_meme_token1_price_above_1() {
let reserve_memecoin = memecoin.balance_of(core.contract_address);
let reserve_token0 = ERC20ABIDispatcher { contract_address: quote_address }
.balance_of(core.contract_address);
//TODO: fix now reserves have the balance of the team
// assert(reserve_token0 == 0, 'reserve quote not 0');

assert(
reserve_token0 >= PercentageMath::percent_mul(quote_to_deposit, 9900), 'quote reserve low'
);
// Changed percent range to %1 here, it was reverting lower.

// Verify that the reserve of memecoin is within 0.5% of the (total supply minus the team allocation)
let team_allocation = memecoin.get_team_allocation();
Expand Down Expand Up @@ -627,12 +621,6 @@ fn test_launch_meme_token1_price_above_1() {
let post_balance_quote = quote.balance_of(recipient);
let balance_quote_diff = post_balance_quote - pre_balance_quote;
assert(balance_of_memecoin == 0, 'memecoin shouldnt collect fees');
//TODO: restore this check
//TODO: restore this check
// assert(
// balance_quote_diff == PercentageMath::percent_mul(amount_in, 0030),
// 'should collect 0.3% of eth'
//);
}

#[test]
Expand Down Expand Up @@ -667,7 +655,7 @@ fn test_launch_meme_with_pool_1percent() {
let reserve_memecoin = memecoin.balance_of(core.contract_address);
let reserve_token0 = ERC20ABIDispatcher { contract_address: quote_address }
.balance_of(core.contract_address);
//TODO:Fix because its too low it should be 0.5%
//TODO:This assertion should be correctified.
// assert(reserve_token0 == 0, 'reserve quote not 0');

// Verify that the reserve of memecoin is within 0.5% of the (total supply minus the team allocation)
Expand Down Expand Up @@ -839,3 +827,123 @@ fn test_launch_memecoin_quote_memecoin_ekubo() {
DEFAULT_MIN_LOCKTIME,
);
}

#[test]
#[fork("Mainnet")]
#[should_panic(expected: ('Holders len dont match amounts',))]
fn test_launch_memecoin_ekubo_initial_holders_len_mismatch() {
let owner = snforge_std::test_address();
let (memecoin, memecoin_address) = deploy_memecoin_through_factory_with_owner(owner);
let factory = IFactoryDispatcher { contract_address: MEMEFACTORY_ADDRESS() };

let (quote, quote_address) = deploy_token0_with_owner(owner);
// approve spending of eth by factory
let quote_amount: u256 = 1 * pow_256(10, 18); // 1 ETHER
let factory_balance_quote = quote.balanceOf(factory.contract_address);
start_prank(CheatTarget::One(quote.contract_address), owner);
quote.approve(factory.contract_address, quote_amount);
stop_prank(CheatTarget::One(quote.contract_address));

start_prank(CheatTarget::One(factory.contract_address), owner);
let pair_address = factory
.launch_on_jediswap(
LaunchParameters {
memecoin_address,
transfer_restriction_delay: TRANSFER_RESTRICTION_DELAY,
max_percentage_buy_launch: MAX_PERCENTAGE_BUY_LAUNCH,
quote_address: quote.contract_address,
initial_holders: array![
'initial_holder_1'.try_into().unwrap(), 'initial_holder_2'.try_into().unwrap()
]
.span(),
initial_holders_amounts: array![50_u256, 20_u256, 10_u256].span(),
},
quote_amount,
DEFAULT_MIN_LOCKTIME,
);
}

#[test]
#[fork("Mainnet")]
#[should_panic(expected: ('Max number of holders reached',))]
fn test_launch_memecoin_ekubo_max_holders_reached() {
let owner = snforge_std::test_address();
let (memecoin, memecoin_address) = deploy_memecoin_through_factory_with_owner(owner);
let factory = IFactoryDispatcher { contract_address: MEMEFACTORY_ADDRESS() };

let initial_holders: Array<ContractAddress> = array![
'initial_holder_1'.try_into().unwrap(),
'initial_holder_2'.try_into().unwrap(),
'initial_holder_3'.try_into().unwrap(),
'initial_holder_4'.try_into().unwrap(),
'initial_holder_5'.try_into().unwrap(),
'initial_holder_6'.try_into().unwrap(),
'initial_holder_7'.try_into().unwrap(),
'initial_holder_8'.try_into().unwrap(),
'initial_holder_9'.try_into().unwrap(),
'initial_holder_10'.try_into().unwrap(),
'initial_holder_11'.try_into().unwrap()
];
let initial_holders_amounts: Array<u256> = array![1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1];

let (quote, quote_address) = deploy_token0_with_owner(owner);
// approve spending of eth by factory
let quote_amount: u256 = 1 * pow_256(10, 18); // 1 ETHER
let factory_balance_quote = quote.balanceOf(factory.contract_address);
start_prank(CheatTarget::One(quote.contract_address), owner);
quote.approve(factory.contract_address, quote_amount);
stop_prank(CheatTarget::One(quote.contract_address));

start_prank(CheatTarget::One(factory.contract_address), owner);
let pair_address = factory
.launch_on_jediswap(
LaunchParameters {
memecoin_address,
transfer_restriction_delay: TRANSFER_RESTRICTION_DELAY,
max_percentage_buy_launch: MAX_PERCENTAGE_BUY_LAUNCH,
quote_address: quote.contract_address,
initial_holders: initial_holders.span(),
initial_holders_amounts: initial_holders_amounts.span(),
},
quote_amount,
DEFAULT_MIN_LOCKTIME,
);
}

#[test]
#[fork("Mainnet")]
#[should_panic(expected: ('Max team allocation reached',))]
fn test_launch_memecoin_ekubo_too_much_team_alloc() {
let owner = snforge_std::test_address();
let (memecoin, memecoin_address) = deploy_memecoin_through_factory_with_owner(owner);
let factory = IFactoryDispatcher { contract_address: MEMEFACTORY_ADDRESS() };

let alloc_holder_1 = 1_050_000 * pow_256(10, 18);
let alloc_holder_2 = 1_050_001 * pow_256(10, 18);

let (quote, quote_address) = deploy_token0_with_owner(owner);
// approve spending of eth by factory
let quote_amount: u256 = 1 * pow_256(10, 18); // 1 ETHER
let factory_balance_quote = quote.balanceOf(factory.contract_address);
start_prank(CheatTarget::One(quote.contract_address), owner);
quote.approve(factory.contract_address, quote_amount);
stop_prank(CheatTarget::One(quote.contract_address));

start_prank(CheatTarget::One(factory.contract_address), owner);
let pair_address = factory
.launch_on_jediswap(
LaunchParameters {
memecoin_address,
transfer_restriction_delay: TRANSFER_RESTRICTION_DELAY,
max_percentage_buy_launch: MAX_PERCENTAGE_BUY_LAUNCH,
quote_address: quote.contract_address,
initial_holders: array![
'initial_holder_1'.try_into().unwrap(), 'initial_holder_2'.try_into().unwrap()
]
.span(),
initial_holders_amounts: array![alloc_holder_1, alloc_holder_2].span(),
},
quote_amount,
DEFAULT_MIN_LOCKTIME,
);
}
Loading

0 comments on commit 95e51c8

Please sign in to comment.