Skip to content

Commit

Permalink
Implement facade classes throughout test suite (#20)
Browse files Browse the repository at this point in the history
* remove old comment

* updated crash course fossil section

* refined eth.cairo

* fixed eth deployment to match refinement

* uncommented constructor deployment of r0 & r1

* made round state after vault deployment test pass

* simplified logic

* added vault address sets in deployment

* added setup function specific for testing

* Finished updating tests in vault_option_round_tests

* fixed missing text from docs

* fixed docs link

* typos in docs

* updated round params tests

* removed old tests from vault option round tests

* update comment for clarity, added back in old params

* updated and added tests, updated an interface function

* Formatting/comments

* stripped some (old) interface functions

* added total unallocated liquidity back to OR

* remove old test docs

* updated option_auction_bid_test.cairo

* add comment about round initialized state

* stripped more old entry points from vault interface

* updated round interface and tests

* finished re writing vault_liquidity_deposit_test.cairo

* added notes for later tests

* added notes for premium tests

* added collateral/unallocated getters in vault/option round

* commented out warnings

* initial finish of migrated files

* stripped old interface out

* making helpers

* change readme link to crash course

* Facade

* setup_facade function in utils

* Option round facade, Rewrite vault_liquidity_deposit_test file

* Add read functions to facade

* Remove unused imports

* Formatting

* Rewrite tests using vault facade

* Rewrite all tests

---------

Co-authored-by: Matt Carter <[email protected]>
  • Loading branch information
dhruv035 and 0xDegenDeveloper authored Apr 23, 2024
1 parent e54456a commit 11ee811
Show file tree
Hide file tree
Showing 12 changed files with 660 additions and 829 deletions.
7 changes: 4 additions & 3 deletions src/option_round.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ trait IOptionRound<TContractState> {
// @return the amount of the transfer
fn exercise_options(ref self: TContractState, option_buyer: ContractAddress) -> u256;

fn get_market_aggregator(self: @TContractState) -> IMarketAggregatorDispatcher;
fn get_market_aggregator(self: @TContractState) -> ContractAddress;

}

#[starknet::contract]
Expand Down Expand Up @@ -315,8 +316,8 @@ mod OptionRound {
100
}

fn get_market_aggregator(self: @ContractState) -> IMarketAggregatorDispatcher {
IMarketAggregatorDispatcher { contract_address: self.market_aggregator.read() }
fn get_market_aggregator(self: @ContractState) -> ContractAddress{
self.market_aggregator.read()
}
}
}
Expand Down
562 changes: 233 additions & 329 deletions src/tests/option_auction_bid_test.cairo

Large diffs are not rendered by default.

73 changes: 59 additions & 14 deletions src/tests/option_round_facade.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ use pitch_lake_starknet::vault::{
};

use starknet::{ContractAddress, testing::{set_contract_address}};
use pitch_lake_starknet::option_round::{IOptionRoundDispatcher, IOptionRoundDispatcherTrait};
use pitch_lake_starknet::option_round::{
IOptionRoundDispatcher, IOptionRoundDispatcherTrait, OptionRoundParams, OptionRoundState
};

use pitch_lake_starknet::tests::utils::{vault_manager};

//@note: confirm start/end auction flow in relation to vault function and set_contract_address accordingly
//fn start_auction(ref option_round_dispatcher: IOptionRoundDispatcher) -> bool {
Expand All @@ -27,30 +30,72 @@ struct OptionRoundFacade {
impl OptionRoundFacadeImpl of OptionRoundFacadeTrait {
fn place_bid(
ref self: OptionRoundFacade,
ref option_round_dispatcher: IOptionRoundDispatcher,
option_bidder_buyer: ContractAddress,
amount: u256,
price: u256
price: u256,
option_bidder_buyer: ContractAddress,
) -> bool {
set_contract_address(option_bidder_buyer);
let result: bool = option_round_dispatcher.place_bid(amount, price);
return result;
let result: bool = self.option_round_dispatcher.place_bid(amount, price);
result
}

fn refund_bid(
ref option_round_dispatcher: IOptionRoundDispatcher, option_bidder_buyer: ContractAddress
) -> u256 {

fn end_auction(ref self: OptionRoundFacade) {
set_contract_address(vault_manager());
self.option_round_dispatcher.end_auction();
}

fn refund_bid(ref self: OptionRoundFacade, option_bidder_buyer: ContractAddress) -> u256 {
set_contract_address(option_bidder_buyer);
let result: u256 = option_round_dispatcher.refund_unused_bids(option_bidder_buyer);
return result;
let result: u256 = self.option_round_dispatcher.refund_unused_bids(option_bidder_buyer);
result
}

fn exercise_options(ref self: OptionRoundFacade, option_bidder_buyer: ContractAddress) -> u256 {
self.option_round_dispatcher.exercise_options(option_bidder_buyer)
}
fn get_state(ref self: OptionRoundFacade) -> OptionRoundState {
self.option_round_dispatcher.get_state()
}

fn vault_address(ref self:OptionRoundFacade)->ContractAddress{
self.vault_address()
}
fn total_liquidity(ref self: OptionRoundFacade) -> u256 {
return self.option_round_dispatcher.total_liquidity();
self.option_round_dispatcher.total_liquidity()
}
fn total_unallocated_liquidity(ref self: OptionRoundFacade) -> u256 {
return self.option_round_dispatcher.total_unallocated_liquidity();
self.option_round_dispatcher.total_unallocated_liquidity()
}
fn contract_address(ref self: OptionRoundFacade) -> ContractAddress {
return self.option_round_dispatcher.contract_address;
self.option_round_dispatcher.contract_address
}

fn get_params(ref self: OptionRoundFacade) -> OptionRoundParams {
self.option_round_dispatcher.get_params()
}

fn total_options_sold(ref self: OptionRoundFacade) -> u256 {
self.option_round_dispatcher.total_options_sold()
}

fn get_auction_clearing_price(ref self: OptionRoundFacade) -> u256 {
self.option_round_dispatcher.get_auction_clearing_price()
}

fn total_collateral(ref self: OptionRoundFacade) -> u256 {
self.option_round_dispatcher.total_collateral()
}

fn get_payout_balance_for(
ref self: OptionRoundFacade, option_bidder_buyer: ContractAddress
) -> u256 {
self.option_round_dispatcher.get_payout_balance_for(option_bidder_buyer)
}
fn get_unused_bids_for(ref self:OptionRoundFacade, option_bidder_buyer:ContractAddress)->u256{
self.option_round_dispatcher.get_unused_bids_for(option_bidder_buyer)
}
fn get_market_aggregator(ref self: OptionRoundFacade) -> ContractAddress {
self.option_round_dispatcher.get_market_aggregator()
}
}
Loading

0 comments on commit 11ee811

Please sign in to comment.