Skip to content

Commit d4ed699

Browse files
test(multi-collateral): add withdraw n transfer flow test utils (#168)
1 parent 592d540 commit d4ed699

File tree

7 files changed

+311
-101
lines changed

7 files changed

+311
-101
lines changed

workspace/apps/perpetuals/contracts/src/tests/constants.cairo

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ pub const PREMIUM_COST: u64 = 100;
6868
pub const COLLATERAL_DECIMALS: u8 = 6;
6969
pub const COLLATERAL_QUORUM: u8 = 0;
7070
pub const COLLATERAL_QUANTUM: u64 = 1;
71+
pub const COLLATERAL_RESOLUTION_FACTOR: u64 = 1_000_000_000;
7172
pub const SYNTHETIC_QUORUM: u8 = 1;
7273
pub const SYNTHETIC_RESOLUTION_FACTOR: u64 = 1_000_000_000;
7374
pub const VAULT_DECIMALS: u8 = 6;

workspace/apps/perpetuals/contracts/src/tests/flow_tests/flow_tests.cairo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -935,8 +935,8 @@ fn test_multi_trade_with_price_and_funding_ticks() {
935935
test.validate_total_value(user_b, 1_903_437);
936936
test.validate_total_risk(user_b, 44_172);
937937

938-
test.withdraw(test.withdraw_request(user_a, 1_000_000));
939-
test.withdraw(test.withdraw_request(user_b, 1_000_000));
938+
test.withdraw(test.withdraw_request(user: user_a, amount: 1_000_000));
939+
test.withdraw(test.withdraw_request(user: user_b, amount: 1_000_000));
940940

941941
test.transfer(test.transfer_request(sender: user_a, recipient: user_b, amount: 1_000_000));
942942

workspace/apps/perpetuals/contracts/src/tests/flow_tests/infra.cairo

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use perpetuals::core::components::positions::interface::{
55
IPositionsDispatcher, IPositionsDispatcherTrait,
66
};
77
use perpetuals::core::interface::Settlement;
8+
use perpetuals::core::types::asset::AssetId;
89
use perpetuals::core::types::balance::Balance;
910
use perpetuals::core::types::funding::FundingTick;
1011
use perpetuals::core::types::position::{PositionData, PositionId};
@@ -101,7 +102,7 @@ pub struct OrderRequest {
101102

102103
pub struct FlowTestExtended {
103104
pub flow_test_base: FlowTestBase,
104-
pub synthetics: Felt252Dict<Nullable<SyntheticInfo>>,
105+
pub synthetics: Felt252Dict<Nullable<AssetInfo>>,
105106
pub fee_percentage: u8,
106107
}
107108

@@ -137,7 +138,7 @@ pub impl FlowTestImpl of FlowTestExtendedTrait {
137138
BTC_ASSET, ETH_ASSET, STRK_ASSET, SOL_ASSET, DOGE_ASSET, PEPE_ASSET, ETC_ASSET,
138139
TAO_ASSET, XRP_ASSET, ADA_ASSET,
139140
] {
140-
let synthetic_info = SyntheticInfoTrait::new(
141+
let synthetic_info = AssetInfoTrait::new(
141142
:asset_name, risk_factor_data: risk_factor_tiers, oracles_len: 1,
142143
);
143144
flow_test_base.facade.add_active_synthetic(@synthetic_info, :initial_price);
@@ -160,6 +161,19 @@ pub impl FlowTestImpl of FlowTestExtendedTrait {
160161
depositor: user.account, position_id: user.position_id, quantized_amount: amount,
161162
)
162163
}
164+
fn deposit_spot(
165+
ref self: FlowTestExtended, user: User, asset_id: AssetId, amount: u64,
166+
) -> DepositInfo {
167+
self
168+
.flow_test_base
169+
.facade
170+
.deposit_spot(
171+
depositor: user.account,
172+
:asset_id,
173+
position_id: user.position_id,
174+
quantized_amount: amount,
175+
)
176+
}
163177
fn process_deposit(ref self: FlowTestExtended, deposit_info: DepositInfo) {
164178
self.flow_test_base.facade.process_deposit(:deposit_info)
165179
}
@@ -169,6 +183,11 @@ pub impl FlowTestImpl of FlowTestExtendedTrait {
169183
fn withdraw_request(ref self: FlowTestExtended, user: User, amount: u64) -> RequestInfo {
170184
self.flow_test_base.facade.withdraw_request(:user, :amount)
171185
}
186+
fn withdraw_spot_request(
187+
ref self: FlowTestExtended, user: User, asset_id: AssetId, amount: u64,
188+
) -> RequestInfo {
189+
self.flow_test_base.facade.withdraw_spot_request(:user, :asset_id, :amount)
190+
}
172191
fn withdraw(ref self: FlowTestExtended, withdraw_info: RequestInfo) {
173192
self.flow_test_base.facade.withdraw(:withdraw_info)
174193
}

0 commit comments

Comments
 (0)