Skip to content

Commit

Permalink
final fixesss
Browse files Browse the repository at this point in the history
  • Loading branch information
eugenPtr committed Jan 21, 2025
1 parent 38999dc commit 7c3ea75
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ fn test_tokenizing_options_events() {
let (mut current_round, mut option_bidders) = test_helper(ref vault);

// Check options tokenized event emits correctly
clear_event_logs(array![current_round.contract_address()]);
clear_event_logs(array![vault.contract_address()]);
loop {
match option_bidders.pop_front() {
Option::Some(bidder) => {
// User's option erc20 balance before tokenizing
// Tokenize options
let options_minted = current_round.mint_options(*bidder);
assert_event_options_tokenized(
current_round.contract_address(),
vault.contract_address(),
*bidder,
options_minted,
current_round.get_round_id(),
Expand Down
7 changes: 5 additions & 2 deletions src/tests/option_round/option_buyers/update_bids_tests.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,20 @@ fn test_update_bid_event() {
let option_buyer = option_bidder_buyer_1();
let bid_price = reserve_price;
let mut bid_amount = options_available / 2;
let bid_tree_nonce_before = current_round.get_bid_tree_nonce();
let bid = current_round.place_bid(bid_amount, bid_price, option_buyer);
let bid_tree_nonce_after = current_round.get_bid_tree_nonce();
clear_event_logs(array![vault_facade.contract_address()]);

let updated_bid = current_round.update_bid(bid.bid_id, 5);
assert_eq!(bid_tree_nonce_after, bid_tree_nonce_before+1);
assert_event_auction_bid_updated(
vault_facade.contract_address(),
option_buyer,
bid.bid_id,
5, //Updated amount
bid.tree_nonce,
current_round.get_bid_tree_nonce(),
bid_tree_nonce_before,
bid_tree_nonce_after,
current_round.get_round_id(),
current_round.contract_address()
);
Expand Down
26 changes: 10 additions & 16 deletions src/tests/utils/helpers/event_helpers.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -249,23 +249,19 @@ fn assert_event_options_tokenized(
round_id: u64,
round_address: ContractAddress
) {
// We pop here twice since the method fires a ERC20 transfer event before the OptionsTokenized
// event
match pop_log::<ERC20Component::Transfer>(contract) {
Option::Some(_) => {
match pop_log::<Vault::Event>(contract) {
Option::Some(e) => {
let expected = Vault::Event::OptionsMinted(
Vault::OptionsMinted { account, minted_amount, round_id, round_address }
);
assert_events_equal(e, expected);
},
Option::None => { panic(array!['No events found']); },
}
match pop_log::<Vault::Event>(contract) {
Option::Some(e) => {
let expected = Vault::Event::OptionsMinted(
Vault::OptionsMinted { account, minted_amount, round_id, round_address }
);
println!("OptionsMinted actual event: {:?}", e);
println!("OptionsMinted expected event: {:?}", expected);
assert_events_equal(e, expected);
},
Option::None => { panic!("ERC20 event not found") }
Option::None => { panic(array!['No events found']); },
}
}

// Check OptionsExercised emits correctly
fn assert_event_options_exercised(
contract: ContractAddress,
Expand Down Expand Up @@ -346,8 +342,6 @@ fn assert_event_option_round_deployed_single(
option_settlement_date: u64,
pricing_data: PricingData,
) {
// Remove the RoundSettled event
let x = pop_log::<Vault::Event>(contract);
// Get the event we're interested in
match pop_log::<Vault::Event>(contract) {
Option::Some(e) => {
Expand Down
2 changes: 1 addition & 1 deletion src/tests/vault/state_transition/option_settle_tests.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ fn test_next_round_deployed_events() {
};

assert(pricing_data != Default::default(), 'Pricing data not set correctly');
assert_event_option_round_deployed_single(
assert_event_option_round_deployed(
vault.contract_address(),
i + 1,
round_i_plus_1.contract_address(),
Expand Down
7 changes: 4 additions & 3 deletions src/vault/contract.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -899,15 +899,16 @@ mod Vault {
let current_round_id = self.current_round_id.read();
let current_round_address = self.round_addresses.read(current_round_id);
let current_round = self.get_round_dispatcher(current_round_id);


let current_bid = current_round.get_bid_details(bid_id);
let updated_bid = current_round.update_bid(account, bid_id, price_increase);

self.emit(Event::BidUpdated(BidUpdated {
account,
bid_id,
price_increase,
bid_tree_nonce_before: updated_bid.tree_nonce,
bid_tree_nonce_now: updated_bid.tree_nonce + 1,
bid_tree_nonce_before: current_bid.tree_nonce,
bid_tree_nonce_now: updated_bid.tree_nonce,
round_id: current_round_id,
round_address: current_round_address,
}));
Expand Down

0 comments on commit 7c3ea75

Please sign in to comment.