Skip to content

Commit

Permalink
[ECO-1659] Test swap simulator/executor to 100% coverage (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
alnoki authored May 14, 2024
1 parent a677ae0 commit d31fbf1
Show file tree
Hide file tree
Showing 2 changed files with 792 additions and 84 deletions.
28 changes: 22 additions & 6 deletions src/move/emojicoin_dot_fun/sources/emojicoin_dot_fun.move
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,9 @@ module emojicoin_dot_fun::emojicoin_dot_fun {
assign_supply_minuend_reserves_ref(market_ref_mut, in_bonding_curve);
let circulating_supply = supply_minuend - reserves_ref.base;
let user_emojicoin_balance = if (!coin::is_account_registered<Emojicoin>(user_address)) {
if (!account::exists_at(user_address)) {
aptos_account::create_account(user_address);
};
coin::register<Emojicoin>(user);
0
} else {
Expand Down Expand Up @@ -757,12 +760,12 @@ module emojicoin_dot_fun::emojicoin_dot_fun {

inline fun assign_supply_minuend_reserves_ref(
market_ref: &Market,
starts_in_bonding_curve: bool
in_bonding_curve: bool
): (
u64,
&Reserves,
) {
if (starts_in_bonding_curve) {
if (in_bonding_curve) {
(BASE_VIRTUAL_CEILING, &market_ref.clamm_virtual_reserves)
} else {
(EMOJICOIN_SUPPLY, &market_ref.cpamm_real_reserves)
Expand Down Expand Up @@ -913,7 +916,7 @@ module emojicoin_dot_fun::emojicoin_dot_fun {
let reserves_start = *reserves_ref_mut;
let reserves_end = reserves_start;
reserves_end.base = reserves_end.base + event.input_amount;
reserves_end.quote = reserves_end.base - quote_leaving_market;
reserves_end.quote = reserves_end.quote - quote_leaving_market;
*reserves_ref_mut = reserves_end;

// Get FDV, market cap at start and end.
Expand Down Expand Up @@ -1005,7 +1008,7 @@ module emojicoin_dot_fun::emojicoin_dot_fun {
// Update cumulative pool fees.
let local_cumulative_pool_fees_base_ref_mut =
&mut local_cumulative_stats_ref_mut.pool_fees_base;
let pool_fees_base_as_u128 = (event.pool_fee as u128);
pool_fees_base_as_u128 = (event.pool_fee as u128);
*local_cumulative_pool_fees_base_ref_mut =
*local_cumulative_pool_fees_base_ref_mut + pool_fees_base_as_u128;
};
Expand Down Expand Up @@ -1071,11 +1074,11 @@ module emojicoin_dot_fun::emojicoin_dot_fun {
if (tracker_ref_mut.open_price_q64 == 0) {
tracker_ref_mut.open_price_q64 = avg_execution_price_q64;
};
if (tracker_ref_mut.high_price_q64 < avg_execution_price_q64) {
if (avg_execution_price_q64 > tracker_ref_mut.high_price_q64) {
tracker_ref_mut.high_price_q64 = avg_execution_price_q64;
};
if (tracker_ref_mut.low_price_q64 == 0 ||
tracker_ref_mut.low_price_q64 > avg_execution_price_q64) {
avg_execution_price_q64 < tracker_ref_mut.low_price_q64) {
tracker_ref_mut.low_price_q64 = avg_execution_price_q64;
};
tracker_ref_mut.close_price_q64 = avg_execution_price_q64;
Expand Down Expand Up @@ -2299,6 +2302,13 @@ module emojicoin_dot_fun::emojicoin_dot_fun {
exists<LPCoinCapabilities<Emojicoin, EmojicoinLP>>(market_address)
}

#[test_only] public fun fdv_market_cap_test_only(
real_reserves: Reserves,
emojicoin_supply: u64,
): (u128, u128) {
fdv_market_cap(real_reserves, emojicoin_supply)
}

#[test_only] public fun get_bps_fee_test_only(
principal: u64,
fee_rate_bps: u8,
Expand Down Expand Up @@ -2342,10 +2352,12 @@ module emojicoin_dot_fun::emojicoin_dot_fun {
#[test_only] public fun get_PERIOD_1H(): u64 { PERIOD_1H }
#[test_only] public fun get_PERIOD_4H(): u64 { PERIOD_4H }
#[test_only] public fun get_PERIOD_1D(): u64 { PERIOD_1D }
#[test_only] public fun get_POOL_FEE_RATE_BPS(): u8 { POOL_FEE_RATE_BPS }
#[test_only] public fun get_REGISTRY_NAME(): vector<u8> { REGISTRY_NAME }
#[test_only] public fun get_TRIGGER_MARKET_REGISTRATION(): u8 { TRIGGER_MARKET_REGISTRATION }
#[test_only] public fun get_TRIGGER_PACKAGE_PUBLICATION(): u8 { TRIGGER_PACKAGE_PUBLICATION }
#[test_only] public fun get_TRIGGER_SWAP_BUY(): u8 { TRIGGER_SWAP_BUY }
#[test_only] public fun get_TRIGGER_SWAP_SELL(): u8 { TRIGGER_SWAP_SELL }
#[test_only] public fun get_QUOTE_REAL_CEILING(): u64 { QUOTE_REAL_CEILING }
#[test_only] public fun get_QUOTE_VIRTUAL_CEILING(): u64 { QUOTE_VIRTUAL_CEILING }
#[test_only] public fun get_QUOTE_VIRTUAL_FLOOR(): u64 { QUOTE_VIRTUAL_FLOOR }
Expand All @@ -2364,6 +2376,10 @@ module emojicoin_dot_fun::emojicoin_dot_fun {
register_market_inner(registrant, emojis, integrator, false);
}

#[test_only] public fun tvl_clamm_test_only(virtual_reserves: Reserves): u128 {
tvl_clamm(virtual_reserves)
}

#[test_only] public fun unpack_chat(
chat: Chat,
): (
Expand Down
Loading

0 comments on commit d31fbf1

Please sign in to comment.