Skip to content

Commit

Permalink
removed more code
Browse files Browse the repository at this point in the history
  • Loading branch information
Zachary Frederick committed Jan 5, 2024
1 parent 97d0a1d commit d3bcedc
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 342 deletions.
112 changes: 0 additions & 112 deletions integration-tests/src/test/burn.test.ts

This file was deleted.

13 changes: 0 additions & 13 deletions pallets/creditcoin/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,19 +373,6 @@ benchmarks! {

let contract = BurnDetails::GCRE(address.value, tx_id);
}: _( RawOrigin::Signed(collector), contract)

burn_all {
let collector: T::AccountId = lender_account::<T>(true);
let who = collector.clone();
}: _(RawOrigin::Signed(who), collector)

burn {
let collector: T::AccountId = lender_account::<T>(true);
let who = collector.clone();
let min = <Balances<T> as Currency<T::AccountId>>::minimum_balance();
<Balances<T> as Currency<T::AccountId>>::make_free_balance_be(&collector, min * 1_000_000u32.into());
let balance = min * 100u32.into();
}: _(RawOrigin::Signed(who), balance, collector)
}

//impl_benchmark_test_suite!(Creditcoin, crate::mock::new_test_ext(), crate::mock::Test);
Expand Down
24 changes: 0 additions & 24 deletions pallets/creditcoin/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,27 +257,3 @@ pub fn blockchain_is_supported(blockchain: &Blockchain) -> bool {
Blockchain::Other(_) => false,
}
}

pub fn burn_and_settle<T: Config>(
who: T::AccountId,
amount: T::Balance,
) -> Result<(), PositiveImbalance<T>> {
let imbalance: pallet_balances::PositiveImbalance<T> =
<pallet_balances::Pallet<T>>::burn(amount);

<pallet_balances::Pallet<T> as CurrencyT<T::AccountId>>::settle(
&who,
imbalance,
WithdrawReasons::TRANSFER,
AllowDeath,
)
}

pub fn can_burn_amount<T: Config>(who: T::AccountId, amount: T::Balance) -> bool {
let balance = <pallet_balances::Pallet<T> as CurrencyT<T::AccountId>>::free_balance(&who);

let res = balance.saturated_into::<u128>();
let amount_128 = amount.saturated_into::<u128>();

res >= amount_128
}
3 changes: 0 additions & 3 deletions pallets/creditcoin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ mod types;
pub mod test_utils;

use crate::types::{BurnId, BurnInfo};
use helpers::{burn_and_settle, can_burn_amount};
use ocw::tasks::collect_coins::DeployedContract;
pub use types::{
loan_terms, Address, AddressId, AskOrder, AskOrderId, AskTerms, BidOrder, BidOrderId, BidTerms,
Expand Down Expand Up @@ -157,8 +156,6 @@ pub mod pallet {
fn set_gate_contract() -> Weight;
fn set_gate_faucet() -> Weight;
fn request_collect_coins_v2() -> Weight;
fn burn_all() -> Weight;
fn burn() -> Weight;
}

#[pallet::pallet]
Expand Down
182 changes: 0 additions & 182 deletions pallets/creditcoin/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2949,12 +2949,6 @@ fn exercise_weightinfo_functions() {

let result = super::weights::WeightInfo::<Test>::request_collect_coins_v2();
assert!(result.ref_time() > 0);

let result = super::weights::WeightInfo::<Test>::burn();
assert!(result.ref_time() > 0);

let result = super::weights::WeightInfo::<Test>::burn_all();
assert!(result.ref_time() > 0);
}

#[test]
Expand Down Expand Up @@ -3329,179 +3323,3 @@ fn gate_faucet_account_storage_should_return_none_when_not_set() {
assert!(gate_faucet.is_none());
});
}

#[test]
fn burn_all_should_error_when_not_signed() {
ExtBuilder::default().build_and_execute(|| {
System::set_block_number(1);

let account_on_cc3: AccountId = AccountId::new([0; 32]);

assert_noop!(Creditcoin::burn_all(Origin::none(), account_on_cc3), BadOrigin);
});
}

#[test]
fn burn_all_should_emit_event_and_update_storage_when_ok() {
let account_on_cc2: AccountId = AccountId::new([0; 32]);
let all_funds = 999_999_999;

let mut ext = ExtBuilder::default();
ext.fund(account_on_cc2.clone(), all_funds);

ext.build_and_execute(|| {
System::set_block_number(1);

let account_on_cc3: AccountId = AccountId::new([1; 32]);

// no funds have been burned
assert_eq!(crate::BurnedFunds::<Test>::count(), 0);

assert_ok!(Creditcoin::burn_all(
Origin::signed(account_on_cc2.clone()),
account_on_cc3.clone()
));
assert_eq!(crate::BurnedFunds::<Test>::count(), 1); // burn has been registered

let event = <frame_system::Pallet<Test>>::events().pop().expect("expected an event").event;
assert_matches!(event, crate::mock::RuntimeEvent::Creditcoin(crate::Event::Burned(burn_id))=>{
let burn_info = crate::BurnedFunds::<Test>::try_get(burn_id).unwrap();
assert_eq!(burn_info.account, account_on_cc2);
assert_eq!(burn_info.amount, all_funds);
assert_eq!(burn_info.collector, account_on_cc3);
});
});
}

#[test]
fn burn_should_error_when_not_signed() {
ExtBuilder::default().build_and_execute(|| {
System::set_block_number(1);

let account_on_cc3: AccountId = AccountId::new([1; 32]);

assert_noop!(Creditcoin::burn(Origin::none(), 1_000_000, account_on_cc3), BadOrigin);
});
}

#[test]
fn burn_should_error_when_balance_is_less_than_requested_amount() {
let account_on_cc2: AccountId = AccountId::new([0; 32]);
let all_funds = 9_999;

let mut ext = ExtBuilder::default();
ext.fund(account_on_cc2.clone(), all_funds);

ext.build_and_execute(|| {
System::set_block_number(1);
let account_on_cc3: AccountId = AccountId::new([1; 32]);

// doesn't have enough funds on CC2 to burn that much
assert_noop!(
Creditcoin::burn(Origin::signed(account_on_cc2), 99_000_000, account_on_cc3),
crate::Error::<Test>::BurnInsufficientFunds
);
});
}

#[test]
fn burn_should_error_when_requested_second_time_with_insufficient_amount() {
let account_on_cc2: AccountId = AccountId::new([0; 32]);
let all_funds = 999_999_999;
let some_funds = 899_999_999;

let mut ext = ExtBuilder::default();
ext.fund(account_on_cc2.clone(), all_funds);

ext.build_offchain_and_execute_with_state(|_, _| {
System::set_block_number(1);

let account_on_cc3: AccountId = AccountId::new([1; 32]);

assert_ok!(Creditcoin::burn(
Origin::signed(account_on_cc2.clone()),
some_funds,
account_on_cc3.clone()
));

roll_by_with_ocw(10);

// call again, some_funds > remaining balance
assert_noop!(
Creditcoin::burn(Origin::signed(account_on_cc2), some_funds, account_on_cc3),
crate::Error::<Test>::BurnInsufficientFunds
);
});
}

#[test]
fn burn_should_work_when_requested_second_time_with_smaller_amount() {
let account_on_cc2: AccountId = AccountId::new([0; 32]);
let all_funds = 1_000_000;
let some_funds = 500_000;

let mut ext = ExtBuilder::default();
ext.fund(account_on_cc2.clone(), all_funds);

ext.build_offchain_and_execute_with_state(|_, _| {
System::set_block_number(1);

let account_on_cc3: AccountId = AccountId::new([1; 32]);

assert_ok!(Creditcoin::burn(
Origin::signed(account_on_cc2.clone()),
some_funds,
account_on_cc3.clone()
));

roll_by_with_ocw(10);

// call aagain, some_funds <= remaining balance
// actually some_funds == remaining balance in this example
assert_ok!(Creditcoin::burn(
Origin::signed(account_on_cc2.clone()),
some_funds,
account_on_cc3
));
});
}

#[test]
fn burn_should_emit_event_and_update_storage_when_ok() {
let account_on_cc2: AccountId = AccountId::new([0; 32]);
let all_funds = 999_999_999;
let some_funds = 899_999_999;

let mut ext = ExtBuilder::default();
ext.fund(account_on_cc2.clone(), all_funds);

ext.build_and_execute(|| {
System::set_block_number(1);

let account_on_cc3: AccountId = AccountId::new([1; 32]);

// no funds have been burned
assert_eq!(crate::BurnedFunds::<Test>::count(), 0);

assert_ok!(Creditcoin::burn(
Origin::signed(account_on_cc2.clone()),
some_funds,
account_on_cc3.clone()
));
assert_eq!(crate::BurnedFunds::<Test>::count(), 1); // burn has been registered

let event = <frame_system::Pallet<Test>>::events().pop().expect("expected an event").event;
assert_matches!(event, crate::mock::RuntimeEvent::Creditcoin(crate::Event::Burned(burn_id))=>{
let burn_info = crate::BurnedFunds::<Test>::try_get(burn_id).unwrap();
assert_eq!(burn_info.account, account_on_cc2);
assert_eq!(burn_info.amount, some_funds);
assert_eq!(burn_info.collector, account_on_cc3);
});

// remaining balance is exactly the difference between the 2 amounts
let remaining_balance =
<pallet_balances::Pallet<Test> as Currency<AccountId>>::free_balance(&account_on_cc2);
let remaining_balance = remaining_balance.saturated_into::<u128>();
assert_eq!(remaining_balance, all_funds - some_funds);
});
}
8 changes: 0 additions & 8 deletions pallets/creditcoin/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,12 +491,4 @@ impl<T: frame_system::Config> crate::WeightInfo for WeightInfo<T> {
.saturating_add(T::DbWeight::get().reads(4))
.saturating_add(T::DbWeight::get().writes(1))
}

fn burn_all() -> Weight {
Weight::from_parts(1, 1)
}

fn burn() -> Weight {
Weight::from_parts(1, 1)
}
}

0 comments on commit d3bcedc

Please sign in to comment.