Skip to content

Commit

Permalink
fix: clippy warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
nakul1010 committed Aug 15, 2023
1 parent 4901c81 commit 1ab5cbd
Showing 1 changed file with 7 additions and 75 deletions.
82 changes: 7 additions & 75 deletions parachain/runtime/runtime-tests/src/parachain/replace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,27 +100,6 @@ mod request_replace_tests {
issue: &IssueRequest<AccountId32, BlockNumber, Balance, CurrencyId>,
amount: Amount<Runtime>,
) {
let result = ParachainTwoVaultState::get(&old_vault_id, &new_vault_id);
println!("--- result: {:#?} ---", result);
let result = ParachainTwoVaultState::get_default(&old_vault_id, &new_vault_id);
println!("--- result: {:#?} ---", result);

// let result = ParachainTwoVaultState::get_default(&old_vault_id, &new_vault_id).with_changes(
// |old_vault, new_vault, _| {
// *old_vault
// .free_balance
// .get_mut(&new_vault_id.collateral_currency())
// .unwrap() -= Amount::new(issue.griefing_collateral, new_vault_id.collateral_currency());
// // let issue_amount = issue.amount();
// println!("---- issue_amount: {:?} ----",amount);
//
// old_vault.to_be_redeemed += amount;
// new_vault.to_be_issued += amount;
// }
// );
// println!("--- to_be_redeemed: {:#?} ---",result.vault1.to_be_redeemed);
// println!("--- to_be_issued: {:#?} ---",result.vault2.to_be_issued);

assert_eq!(
ParachainTwoVaultState::get(&old_vault_id, &new_vault_id),
ParachainTwoVaultState::get_default(&old_vault_id, &new_vault_id).with_changes(
Expand All @@ -139,7 +118,6 @@ mod request_replace_tests {
fn integration_test_replace_accept_replace_at_capacity_succeeds() {
test_with(|old_vault_id, new_vault_id| {
let accept_amount = new_vault_id.wrapped(DEFAULT_VAULT_TO_BE_REPLACED.amount());
println!("accept_amount: {:?},", accept_amount.amount());
assert_ok!(RuntimeCall::Redeem(RedeemCall::request_replace {
currency_pair: old_vault_id.currencies.clone(),
amount: accept_amount.amount(),
Expand All @@ -157,9 +135,6 @@ mod request_replace_tests {
let issue_id = assert_issue_request_event();
let issue = IssuePallet::get_issue_request_from_id(&issue_id).unwrap();

println!("---- issue event: {:#?} -----", issue);
// println!("---- redeem event: {:#?} ----",redeem);

assert_eq!(issue.griefing_collateral(), griefing(2));
assert_state_after_accept_replace_correct(&old_vault_id, &new_vault_id, &issue, accept_amount);
});
Expand All @@ -172,7 +147,6 @@ mod request_replace_tests {

let accept_amount = DEFAULT_VAULT_TO_BE_REPLACED / 4;
let accept_amount = old_vault_id.wrapped(accept_amount.amount());
println!("accept_amount: {:?}", accept_amount.amount());

assert_ok!(RuntimeCall::Redeem(RedeemCall::request_replace {
currency_pair: old_vault_id.currencies.clone(),
Expand All @@ -191,9 +165,6 @@ mod request_replace_tests {
let issue_id = assert_issue_request_event();
let issue = IssuePallet::get_issue_request_from_id(&issue_id).unwrap();

println!("---- issue event: {:#?} -----", issue);
// println!("---- redeem event: {:#?} ----",redeem);

assert_eq!(issue.griefing_collateral(), griefing(1));
assert_state_after_accept_replace_correct(&old_vault_id, &new_vault_id, &issue, accept_amount);
});
Expand All @@ -206,7 +177,6 @@ mod request_replace_tests {

let accept_amount = DEFAULT_VAULT_TO_BE_REPLACED * 4;
let accept_amount = old_vault_id.wrapped(accept_amount.amount());
println!("accept_amount: {:?}", accept_amount.amount());

assert_ok!(RuntimeCall::Redeem(RedeemCall::request_replace {
currency_pair: old_vault_id.currencies.clone(),
Expand All @@ -218,14 +188,12 @@ mod request_replace_tests {

let redeem_id = assert_redeem_request_event();
let redeem = RedeemPallet::get_open_redeem_request_from_id(&redeem_id).unwrap();
println!("---- redeem event: {:#?} ----", redeem);

assert_eq!(redeem.amount_btc, accept_amount.amount() / 2);
assert_eq!(redeem.issue_id.is_some(), true);

let issue_id = assert_issue_request_event();
let issue = IssuePallet::get_issue_request_from_id(&issue_id).unwrap();
println!("---- issue event: {:#?} -----", issue);

assert_eq!(issue.griefing_collateral(), griefing(4));
assert_state_after_accept_replace_correct(
Expand Down Expand Up @@ -332,7 +300,6 @@ mod expiry_test {
/// test replace created by accept
fn test_with(initial_period: u32, execute: impl Fn((H256, H256))) {
let amount_btc = wrapped(5_000);
let griefing_collateral = griefing(1000);
super::test_with(|old_vault_id, new_vault_id| {
set_replace_period(initial_period);
assert_ok!(RuntimeCall::Redeem(RedeemCall::request_replace {
Expand Down Expand Up @@ -610,11 +577,6 @@ fn integration_test_replace_execute_replace_success() {
let pre_execute_state = ParachainTwoVaultState::get(&old_vault_id, &new_vault_id);

assert_ok!(execute_replace(redeem_id));

let new_state = ParachainTwoVaultState::get(&old_vault_id, &new_vault_id);

println!("---- old_state: {:#?} ----", pre_execute_state);
println!("---- new_state: {:#?} ----", new_state);
assert_eq!(
ParachainTwoVaultState::get(&old_vault_id, &new_vault_id),
pre_execute_state.with_changes(|old_vault, new_vault, _| {
Expand Down Expand Up @@ -659,11 +621,6 @@ fn integration_test_replace_execute_replace_old_vault_liquidated() {
let collateral_for_replace =
calculate_replace_collateral(&old, redeem.amount_btc(), old_vault_id.collateral_currency());

let new_state = ParachainTwoVaultState::get(&old_vault_id, &new_vault_id);

println!("---- old_state: {:#?} ----", pre_execution_state);
println!("---- new_state: {:#?} ----", new_state);

assert_eq!(
ParachainTwoVaultState::get(&old_vault_id, &new_vault_id),
pre_execution_state.with_changes(|old_vault, new_vault, liquidation_vault| {
Expand Down Expand Up @@ -692,23 +649,14 @@ fn integration_test_replace_execute_replace_new_vault_liquidated() {
test_with(|old_vault_id, new_vault_id| {
let accept_amount = new_vault_id.wrapped(10000);

let (redeem_id, redeem, _issue_id, issue) = setup_replace(accept_amount, &old_vault_id, &new_vault_id);

let old = CoreVaultData::vault(old_vault_id.clone());
let (redeem_id, _redeem, _issue_id, issue) = setup_replace(accept_amount, &old_vault_id, &new_vault_id);

liquidate_vault(&new_vault_id);

let pre_execution_state = ParachainTwoVaultState::get(&old_vault_id, &new_vault_id);

assert_ok!(execute_replace(redeem_id));

let collateral_for_replace =
calculate_replace_collateral(&old, redeem.amount_btc(), old_vault_id.collateral_currency());

let new_state = ParachainTwoVaultState::get(&old_vault_id, &new_vault_id);
println!("---- old_state: {:#?} ----", pre_execution_state);
println!("---- new_state: {:#?} ----", new_state);

assert_eq!(
ParachainTwoVaultState::get(&old_vault_id, &new_vault_id),
pre_execution_state.with_changes(|old_vault, _new_vault, liquidation_vault| {
Expand Down Expand Up @@ -771,7 +719,7 @@ fn integration_test_replace_execute_replace_both_vaults_liquidated() {
fn integration_test_replace_execute_replace_with_cancelled() {
test_with(|old_vault_id, new_vault_id| {
let accept_amount = new_vault_id.wrapped(10000);
let (redeem_id, redeem, _issue_id, issue) = setup_replace(accept_amount, &old_vault_id, &new_vault_id);
let (redeem_id, _redeem, _issue_id, _issue) = setup_replace(accept_amount, &old_vault_id, &new_vault_id);
cancel_replace(redeem_id);
assert_err!(execute_replace(redeem_id), RedeemError::RedeemCancelled);
});
Expand All @@ -781,12 +729,9 @@ fn integration_test_replace_execute_replace_with_cancelled() {
fn integration_test_replace_cancel_replace_success() {
test_with(|old_vault_id, new_vault_id| {
let accept_amount = new_vault_id.wrapped(10000);
let (redeem_id, redeem, _issue_id, issue) = setup_replace(accept_amount, &old_vault_id, &new_vault_id);
let (redeem_id, _redeem, _issue_id, issue) = setup_replace(accept_amount, &old_vault_id, &new_vault_id);
let pre_cancellation_state = ParachainTwoVaultState::get(&old_vault_id, &new_vault_id);
cancel_replace(redeem_id);
let new_state = ParachainTwoVaultState::get(&old_vault_id, &new_vault_id);
println!("---- pre_cancellation_state: {:#?} ----", pre_cancellation_state);
println!("---- new_state: {:#?} ----", new_state);

assert_eq!(
ParachainTwoVaultState::get(&old_vault_id, &new_vault_id),
Expand Down Expand Up @@ -816,9 +761,6 @@ fn integration_test_replace_cancel_replace_old_vault_liquidated() {

let collateral_for_replace =
calculate_replace_collateral(&old, redeem.amount_btc(), old_vault_id.collateral_currency());
let new_state = ParachainTwoVaultState::get(&old_vault_id, &new_vault_id);
println!("---- pre_cancellation_state: {:#?} ----", pre_cancellation_state);
println!("---- new_state: {:#?} ----", new_state);

assert_eq!(
ParachainTwoVaultState::get(&old_vault_id, &new_vault_id),
Expand All @@ -842,16 +784,13 @@ fn integration_test_replace_cancel_replace_old_vault_liquidated() {
fn integration_test_replace_cancel_replace_new_vault_liquidated() {
test_with(|old_vault_id, new_vault_id| {
let accept_amount = new_vault_id.wrapped(10000);
let (redeem_id, redeem, _issue_id, issue) = setup_replace(accept_amount, &old_vault_id, &new_vault_id);
let (redeem_id, _redeem, _issue_id, issue) = setup_replace(accept_amount, &old_vault_id, &new_vault_id);

liquidate_vault(&new_vault_id);

let pre_cancellation_state = ParachainTwoVaultState::get(&old_vault_id, &new_vault_id);

cancel_replace(redeem_id);
let new_state = ParachainTwoVaultState::get(&old_vault_id, &new_vault_id);
println!("---- pre_cancellation_state: {:#?} ----", pre_cancellation_state);
println!("---- new_state: {:#?} ----", new_state);

assert_eq!(
ParachainTwoVaultState::get(&old_vault_id, &new_vault_id),
Expand Down Expand Up @@ -881,9 +820,6 @@ fn integration_test_replace_cancel_replace_both_vaults_liquidated() {
let pre_cancellation_state = ParachainTwoVaultState::get(&old_vault_id, &new_vault_id);

cancel_replace(redeem_id);
let new_state = ParachainTwoVaultState::get(&old_vault_id, &new_vault_id);
println!("---- pre_cancellation_state: {:#?} ----", pre_cancellation_state);
println!("---- new_state: {:#?} ----", new_state);

let collateral_for_replace =
calculate_replace_collateral(&old, redeem.amount_btc(), old_vault_id.collateral_currency());
Expand Down Expand Up @@ -931,15 +867,11 @@ fn integration_test_replace_vault_with_different_currency_succeeds() {
CoreVaultData::force_to(&new_vault_id, default_vault_state(&new_vault_id));

let accept_amount = new_vault_id.wrapped(10000);
let (redeem_id, redeem, _issue_id, issue) = setup_replace(accept_amount, &old_vault_id, &new_vault_id);
let (redeem_id, _redeem, _issue_id, issue) = setup_replace(accept_amount, &old_vault_id, &new_vault_id);

let pre_execute_state = ParachainTwoVaultState::get(&old_vault_id, &new_vault_id);

assert_ok!(execute_replace(redeem_id));
let new_state = ParachainTwoVaultState::get(&old_vault_id, &new_vault_id);

println!("---- pre_execute_state: {:#?} ----", pre_execute_state);
println!("---- new_state: {:#?} ----", new_state);

assert_eq!(
ParachainTwoVaultState::get(&old_vault_id, &new_vault_id),
Expand Down Expand Up @@ -993,7 +925,7 @@ mod oracle_down {
fn no_oracle_cancel_replace_succeeds() {
test_with(|old_vault_id, new_vault_id| {
let accept_amount = new_vault_id.wrapped(10000);
let (redeem_id, redeem, _issue_id, issue) = setup_replace(accept_amount, &old_vault_id, &new_vault_id);
let (redeem_id, _redeem, _issue_id, _issue) = setup_replace(accept_amount, &old_vault_id, &new_vault_id);

OraclePallet::expire_all();

Expand All @@ -1012,7 +944,7 @@ mod oracle_down {
fn no_oracle_execute_cancelled_replace_succeeds() {
test_with(|old_vault_id, new_vault_id| {
let accept_amount = new_vault_id.wrapped(10000);
let (redeem_id, redeem, _issue_id, issue) = setup_replace(accept_amount, &old_vault_id, &new_vault_id);
let (redeem_id, _redeem, _issue_id, _issue) = setup_replace(accept_amount, &old_vault_id, &new_vault_id);

OraclePallet::expire_all();
assert_ok!(execute_replace(redeem_id));
Expand Down

0 comments on commit 1ab5cbd

Please sign in to comment.