Skip to content

Commit

Permalink
revert logic for addTickets endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
psorinionut committed Nov 13, 2024
1 parent 9fc07c1 commit 88cf10a
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 95 deletions.
16 changes: 3 additions & 13 deletions launchpad-guaranteed-tickets-v2/src/guaranteed_tickets_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub trait GuaranteedTicketsInitModule:
fn add_tickets_with_guaranteed_winners(
&self,
address_number_pairs: MultiValueEncoded<
MultiValue3<ManagedAddress, usize, MultiValueEncoded<MultiValue2<usize, usize>>>,
MultiValue3<ManagedAddress, usize, ManagedVec<GuaranteedTicketInfo>>,
>,
) -> AddTicketsResult {
self.require_add_tickets_period();
Expand All @@ -52,9 +52,9 @@ pub trait GuaranteedTicketsInitModule:
let mut total_guaranteed_tickets_added = 0;

for multi_arg in address_number_pairs {
let (buyer, total_tickets_allowance, guaranteed_ticket_array) = multi_arg.into_tuple();
let (buyer, total_tickets_allowance, guaranteed_ticket_infos) = multi_arg.into_tuple();
require!(
guaranteed_ticket_array.len() <= MAX_GUARANTEED_TICKETS_ENTRIES,
guaranteed_ticket_infos.len() <= MAX_GUARANTEED_TICKETS_ENTRIES,
"Number of guaranteed tickets entries exceeds maximum allowed"
);

Expand All @@ -64,16 +64,6 @@ pub trait GuaranteedTicketsInitModule:

let mut user_guaranteed_tickets = 0;

let mut guaranteed_ticket_infos = ManagedVec::new();
for element in guaranteed_ticket_array {
let (guaranteed_tickets, min_confirmed_tickets) = element.into_tuple();
let guaranteed_ticket_info = GuaranteedTicketInfo {
guaranteed_tickets,
min_confirmed_tickets,
};
guaranteed_ticket_infos.push(guaranteed_ticket_info);
}

for info in guaranteed_ticket_infos.iter() {
require!(
info.guaranteed_tickets <= info.min_confirmed_tickets,
Expand Down
2 changes: 1 addition & 1 deletion launchpad-guaranteed-tickets-v2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub trait LaunchpadGuaranteedTickets:
fn add_tickets_endpoint(
&self,
address_number_pairs: MultiValueEncoded<
MultiValue3<ManagedAddress, usize, MultiValueEncoded<MultiValue2<usize, usize>>>,
MultiValue3<ManagedAddress, usize, ManagedVec<GuaranteedTicketInfo>>,
>,
) {
let total_users_count = address_number_pairs.len();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ use launchpad_common::{
winner_selection::WinnerSelectionModule,
};
use launchpad_guaranteed_tickets_v2::{
guaranteed_tickets_init::GuaranteedTicketInfo,
token_release::{TokenReleaseModule, UnlockMilestone},
guaranteed_tickets_init::GuaranteedTicketInfo, token_release::TokenReleaseModule,
};
use launchpad_guaranteed_tickets_v2::{
guaranteed_tickets_init::GuaranteedTicketsInitModule, LaunchpadGuaranteedTickets,
Expand Down Expand Up @@ -136,8 +135,6 @@ where
)
.assert_ok();

b_mock.set_block_nonce(CONFIRM_START_BLOCK);

Self {
b_mock,
owner_address,
Expand Down Expand Up @@ -235,14 +232,18 @@ where
)
}

pub fn set_unlock_schedule(&mut self, unlock_milestones: Vec<UnlockMilestone>) {
pub fn set_unlock_schedule(&mut self, unlock_milestones: Vec<(u64, u64)>) {
let _ = self.b_mock.execute_tx(
&self.owner_address,
&self.lp_wrapper,
&rust_biguint!(0),
|sc| {
let milestones = ManagedVec::from(unlock_milestones);
sc.set_unlock_schedule(MultiValueEncoded::from(milestones));
let mut milestones = MultiValueEncoded::new();
for milestone in unlock_milestones {
milestones.push(milestone.into());
}

sc.set_unlock_schedule(milestones);
},
);
}
Expand Down
117 changes: 43 additions & 74 deletions launchpad-guaranteed-tickets-v2/tests/guaranteed_tickets_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use launchpad_guaranteed_tickets_v2::{
GuaranteedTicketWinnersModule, GuaranteedTicketsSelectionOperation,
},
guaranteed_tickets_init::{GuaranteedTicketInfo, GuaranteedTicketsInitModule},
token_release::{TokenReleaseModule, UnlockMilestone},
token_release::TokenReleaseModule,
LaunchpadGuaranteedTickets,
};
use multiversx_sc::types::{EgldOrEsdtTokenIdentifier, ManagedVec, MultiValueEncoded};
Expand All @@ -39,11 +39,9 @@ fn confirm_all_test() {
NR_WINNING_TICKETS,
launchpad_guaranteed_tickets_v2::contract_obj,
);
let unlock_milestones = vec![UnlockMilestone {
release_epoch: 0,
percentage: 10000,
}];
let unlock_milestones = vec![(0, 10000).into()];

Check warning on line 42 in launchpad-guaranteed-tickets-v2/tests/guaranteed_tickets_test.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] launchpad-guaranteed-tickets-v2/tests/guaranteed_tickets_test.rs#L42

warning: useless conversion to the same type: `(u64, u64)` --> launchpad-guaranteed-tickets-v2/tests/guaranteed_tickets_test.rs:42:34 | 42 | let unlock_milestones = vec![(0, 10000).into()]; | ^^^^^^^^^^^^^^^^^ help: consider removing `.into()`: `(0, 10000)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion = note: `#[warn(clippy::useless_conversion)]` on by default
Raw output
launchpad-guaranteed-tickets-v2/tests/guaranteed_tickets_test.rs:42:34:w:warning: useless conversion to the same type: `(u64, u64)`
  --> launchpad-guaranteed-tickets-v2/tests/guaranteed_tickets_test.rs:42:34
   |
42 |     let unlock_milestones = vec![(0, 10000).into()];
   |                                  ^^^^^^^^^^^^^^^^^ help: consider removing `.into()`: `(0, 10000)`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion
   = note: `#[warn(clippy::useless_conversion)]` on by default


__END__
lp_setup.set_unlock_schedule(unlock_milestones);
lp_setup.b_mock.set_block_nonce(CONFIRM_START_BLOCK);
let participants = lp_setup.participants.clone();

for (i, p) in participants.iter().enumerate() {
Expand Down Expand Up @@ -160,6 +158,8 @@ fn redistribute_test() {
NR_WINNING_TICKETS,
launchpad_guaranteed_tickets_v2::contract_obj,
);
lp_setup.b_mock.set_block_nonce(CONFIRM_START_BLOCK);

let participants = lp_setup.participants.clone();

lp_setup.confirm(&participants[0], 1).assert_ok();
Expand Down Expand Up @@ -373,10 +373,7 @@ fn add_migration_guaranteed_tickets_distribution_isolated_steps_scenario_test()
nr_winning_tickets,
launchpad_guaranteed_tickets_v2::contract_obj,
);
let unlock_milestones = vec![UnlockMilestone {
release_epoch: 0,
percentage: 10000,
}];
let unlock_milestones = vec![(0, 10000)];
lp_setup.set_unlock_schedule(unlock_milestones);
let mut participants = lp_setup.participants.clone();

Expand Down Expand Up @@ -553,10 +550,7 @@ fn add_migration_guaranteed_tickets_distribution_and_claim_scenario_test() {
nr_winning_tickets,
launchpad_guaranteed_tickets_v2::contract_obj,
);
let unlock_milestones = vec![UnlockMilestone {
release_epoch: 0,
percentage: 10000,
}];
let unlock_milestones = vec![(0, 10000)];
lp_setup.set_unlock_schedule(unlock_milestones);
let mut participants = lp_setup.participants.clone();

Expand Down Expand Up @@ -753,10 +747,7 @@ fn condition_checks_test() {
nr_winning_tickets,
launchpad_guaranteed_tickets_v2::contract_obj,
);
let unlock_milestones = vec![UnlockMilestone {
release_epoch: 0,
percentage: 10000,
}];
let unlock_milestones = vec![(0, 10000)];
lp_setup.set_unlock_schedule(unlock_milestones);
let mut participants = lp_setup.participants.clone();

Expand Down Expand Up @@ -926,10 +917,7 @@ fn blacklist_scenario_test() {
nr_winning_tickets,
launchpad_guaranteed_tickets_v2::contract_obj,
);
let unlock_milestones = vec![UnlockMilestone {
release_epoch: 0,
percentage: 10000,
}];
let unlock_milestones = vec![(0, 10000)];
lp_setup.set_unlock_schedule(unlock_milestones);
let mut participants = lp_setup.participants.clone();

Expand Down Expand Up @@ -1206,17 +1194,11 @@ fn confirm_less_tickets_than_total_available_with_vesting_scenario_test() {
nr_winning_tickets,
launchpad_guaranteed_tickets_v2::contract_obj,
);
let unlock_milestones = vec![
UnlockMilestone {
release_epoch: 0,
percentage: 5_000,
},
UnlockMilestone {
release_epoch: 1,
percentage: 5_000,
},
];
let unlock_milestones = vec![(0, 5000), (1, 5000)];
lp_setup.set_unlock_schedule(unlock_milestones);

lp_setup.b_mock.set_block_nonce(CONFIRM_START_BLOCK);

let mut participants = lp_setup.participants.clone();

let new_participant = lp_setup
Expand Down Expand Up @@ -1361,24 +1343,8 @@ fn vesting_with_four_milestones_test() {
nr_winning_tickets,
launchpad_guaranteed_tickets_v2::contract_obj,
);
let unlock_milestones = vec![
UnlockMilestone {
release_epoch: 0,
percentage: 2_500, // 25%
},
UnlockMilestone {
release_epoch: 1,
percentage: 2_500, // 25%
},
UnlockMilestone {
release_epoch: 2,
percentage: 2_500, // 25%
},
UnlockMilestone {
release_epoch: 3,
percentage: 2_500, // 25%
},
];

let unlock_milestones = vec![(0, 2500), (1, 2500), (2, 2500), (3, 2500)];
lp_setup.set_unlock_schedule(unlock_milestones);
let participant = &lp_setup.participants[0].clone();

Expand Down Expand Up @@ -1444,26 +1410,13 @@ fn vesting_with_four_milestones_test() {
}

#[test]
fn unlock_milestones_wrong_order_test() {
fn unlock_milestones_wrong_step_and_order_test() {
let mut lp_setup = LaunchpadSetup::new(
NR_WINNING_TICKETS,
launchpad_guaranteed_tickets_v2::contract_obj,
);

let unlock_milestones = vec![
UnlockMilestone {
release_epoch: 10,
percentage: 3000,
},
UnlockMilestone {
release_epoch: 30,
percentage: 3000,
},
UnlockMilestone {
release_epoch: 20,
percentage: 4000,
},
];
let unlock_milestones = vec![(10, 3000), (30, 3000), (20, 4000)];

lp_setup
.b_mock
Expand All @@ -1472,11 +1425,33 @@ fn unlock_milestones_wrong_order_test() {
&lp_setup.lp_wrapper,
&rust_biguint!(0),
|sc| {
let unlock_schedule = ManagedVec::from(unlock_milestones);
sc.set_unlock_schedule(MultiValueEncoded::from(unlock_schedule));
let mut unlock_schedule = MultiValueEncoded::new();
for milestone in unlock_milestones.clone() {
unlock_schedule.push(milestone.into());
}
sc.set_unlock_schedule(unlock_schedule);
},
)
.assert_user_error("Invalid unlock schedule");

// Retry after setup period has passed
lp_setup.b_mock.set_block_nonce(CONFIRM_START_BLOCK);

lp_setup
.b_mock
.execute_tx(
&lp_setup.owner_address,
&lp_setup.lp_wrapper,
&rust_biguint!(0),
|sc| {
let mut unlock_schedule = MultiValueEncoded::new();
for milestone in unlock_milestones {
unlock_schedule.push(milestone.into());
}
sc.set_unlock_schedule(unlock_schedule);
},
)
.assert_user_error("Add tickets period has passed");
}

#[test]
Expand All @@ -1488,10 +1463,7 @@ fn multiple_guaranteed_tickets_test() {
);

// Set unlock schedule: 100% release immediately
let unlock_milestones = vec![UnlockMilestone {
release_epoch: 0,
percentage: 10000,
}];
let unlock_milestones = vec![(0, 10000)];
lp_setup.set_unlock_schedule(unlock_milestones);

let mut participants = lp_setup.participants.clone();
Expand Down Expand Up @@ -1679,10 +1651,7 @@ fn contract_pause_test() {
nr_winning_tickets,
launchpad_guaranteed_tickets_v2::contract_obj,
);
let unlock_milestones = vec![UnlockMilestone {
release_epoch: 0,
percentage: 10_000,
}];
let unlock_milestones = vec![(0, 10000)];
lp_setup.set_unlock_schedule(unlock_milestones);
let participant = &lp_setup.participants[0].clone();

Expand Down

0 comments on commit 88cf10a

Please sign in to comment.