Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jmg-duarte committed Nov 20, 2024
1 parent 326d9d6 commit 4d62a78
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
- name: Setup mdBook
uses: peaceiris/actions-mdbook@v2
with:
mdbook-version: '0.4.40'
mdbook-version: "0.4.40"
- name: Build the book
run: mdbook build docs

Expand Down Expand Up @@ -90,4 +90,4 @@ jobs:
- name: Cargo clippy
run: RUSTFLAGS="-D warnings" cargo clippy --profile ci --locked
- name: Run tests
run: RUSTFLAGS="-D warnings" cargo tarpaulin --profile ci --locked --workspace --exclude maat
run: RUSTFLAGS="-D warnings" cargo tarpaulin --profile ci --locked --workspace --skip-clean --exclude maat
6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ members = [
resolver = "2"

[profile.ci]
build-override.inherits = "dev"
inherits = "dev" # required otherwise we get the "unknown profile" error

codegen-units = 256 # Increase parallel code generation units
debug = false # No debug information
incremental = false # Disable incremental compilation for consistent CI performance
inherits = "dev"
lto = false # Disable Link Time Optimization
lto = "off" # Disable Link Time Optimization
opt-level = 0 # No optimization
overflow-checks = false # Disable overflow checks
panic = 'abort' # Use abort on panic to reduce binary size
Expand Down
30 changes: 30 additions & 0 deletions pallets/faucet/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ fn drip() {
assert_eq!(
events(),
[
RuntimeEvent::Balances(BalanceEvent::Issued {
amount: <Test as crate::Config>::FaucetDripAmount::get()
}),
RuntimeEvent::Balances(BalanceEvent::Deposit {
who: account.clone(),
amount: <Test as crate::Config>::FaucetDripAmount::get()
Expand All @@ -36,12 +39,36 @@ fn drip() {
Balances::free_balance(account.clone()),
<Test as crate::Config>::FaucetDripAmount::get()
);
});
}

#[test]
fn early_drip_fails() {
new_test_ext().execute_with(|| {
let account = account::<Test>(ALICE);
Faucet::drip(RuntimeOrigin::none(), account.clone())
.expect("first drip should always succeed");

// Run to block_number + faucet_delay
run_to_block(System::block_number() + <Test as crate::Config>::FaucetDripDelay::get() - 1);

// Check that dripping at the same block is blocked
assert_err!(
Faucet::drip(RuntimeOrigin::none(), account.clone()),
Error::<Test>::FaucetUsedRecently
);
});
}

#[test]
fn drip_delay_succeeds() {
new_test_ext().execute_with(|| {
let account = account::<Test>(ALICE);
Faucet::drip(RuntimeOrigin::none(), account.clone())
.expect("first drip should always succeed");

// We've tested this scenario so we can reset the events
System::reset_events();

// Run to block_number + faucet_delay
run_to_block(System::block_number() + <Test as crate::Config>::FaucetDripDelay::get());
Expand All @@ -53,6 +80,9 @@ fn drip() {
assert_eq!(
events(),
[
RuntimeEvent::Balances(BalanceEvent::Issued {
amount: <Test as crate::Config>::FaucetDripAmount::get()
}),
RuntimeEvent::Balances(BalanceEvent::Deposit {
who: account.clone(),
amount: <Test as crate::Config>::FaucetDripAmount::get()
Expand Down
11 changes: 7 additions & 4 deletions pallets/market/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,7 @@ fn verifies_deals_on_block_finalization() {
assert_eq!(
events(),
[
RuntimeEvent::Balances(pallet_balances::Event::<Test>::Rescinded { amount: 15 }),
RuntimeEvent::Balances(pallet_balances::Event::<Test>::Withdraw {
who: Market::account_id(),
amount: 15
Expand Down Expand Up @@ -1503,12 +1504,13 @@ fn slash_and_burn_acc() {

assert_eq!(
events(),
[RuntimeEvent::Balances(
pallet_balances::Event::<Test>::Withdraw {
[
RuntimeEvent::Balances(pallet_balances::Event::<Test>::Rescinded { amount: 10 }),
RuntimeEvent::Balances(pallet_balances::Event::<Test>::Withdraw {
who: Market::account_id(),
amount: 10
}
),]
}),
]
);
assert_eq!(
<Test as crate::pallet::Config>::Currency::total_issuance(),
Expand Down Expand Up @@ -1689,6 +1691,7 @@ fn on_sector_terminate_active() {
assert_eq!(
events(),
[
RuntimeEvent::Balances(pallet_balances::Event::<Test>::Rescinded { amount: 15 }),
RuntimeEvent::Balances(pallet_balances::Event::<Test>::Withdraw {
who: Market::account_id(),
amount: 15
Expand Down
4 changes: 4 additions & 0 deletions pallets/storage-provider/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1455,6 +1455,10 @@ pub mod pallet {
// slash_reserved returns NegativeImbalance, we need to get a concrete value and burn it to level out the circulating currency
let imbalance = T::Currency::burn(imbalance.peek());

// TODO(@jmg-duarte,20/11/2024): we'll probably need to review this,
// we're slashing an account (makes sense)
// burning the imbalance (maybe we could stash it in an account for rewards)
// and settling it??? — this part makes less sense since it's similar to a withdraw
T::Currency::settle(account, imbalance, WithdrawReasons::RESERVE, KeepAlive)
.map_err(|_| Error::<T>::SlashingFailed)?;

Expand Down
9 changes: 9 additions & 0 deletions pallets/storage-provider/src/tests/pre_commit_sector_hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,23 @@ fn pre_commit_hook_slashed_deal() {
owner: account(storage_provider),
sector_number: 1,
}),
// the slash -> withdraw is related to the usage of slash_and_burn
// when slashing the SP for a failed pre_commit
// this usage may need review for a proper economic balance
RuntimeEvent::Balances(pallet_balances::Event::<Test>::Slashed {
who: account(storage_provider),
amount: deal_precommit_deposit,
}),
RuntimeEvent::Balances(pallet_balances::Event::<Test>::Rescinded {
amount: deal_precommit_deposit
}),
RuntimeEvent::Balances(pallet_balances::Event::<Test>::Withdraw {
who: account(storage_provider),
amount: deal_precommit_deposit,
}),
RuntimeEvent::Balances(pallet_balances::Event::<Test>::Rescinded {
amount: deal_precommit_deposit
}),
]
);
});
Expand Down

0 comments on commit 4d62a78

Please sign in to comment.