From 4d62a78570254bf31c6a18664c8279833d68fc1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Duarte?= Date: Wed, 20 Nov 2024 16:59:54 +0000 Subject: [PATCH] fix tests --- .github/workflows/ci.yaml | 4 +-- Cargo.toml | 6 ++-- pallets/faucet/src/test.rs | 30 +++++++++++++++++++ pallets/market/src/test.rs | 11 ++++--- pallets/storage-provider/src/lib.rs | 4 +++ .../src/tests/pre_commit_sector_hook.rs | 9 ++++++ 6 files changed, 56 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 997e96411..67ac5bd69 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -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 @@ -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 diff --git a/Cargo.toml b/Cargo.toml index bd7ff4b3e..d178f58a7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 diff --git a/pallets/faucet/src/test.rs b/pallets/faucet/src/test.rs index 2bd710f26..14b3281b4 100644 --- a/pallets/faucet/src/test.rs +++ b/pallets/faucet/src/test.rs @@ -14,6 +14,9 @@ fn drip() { assert_eq!( events(), [ + RuntimeEvent::Balances(BalanceEvent::Issued { + amount: ::FaucetDripAmount::get() + }), RuntimeEvent::Balances(BalanceEvent::Deposit { who: account.clone(), amount: ::FaucetDripAmount::get() @@ -36,12 +39,36 @@ fn drip() { Balances::free_balance(account.clone()), ::FaucetDripAmount::get() ); + }); +} + +#[test] +fn early_drip_fails() { + new_test_ext().execute_with(|| { + let account = account::(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() + ::FaucetDripDelay::get() - 1); // Check that dripping at the same block is blocked assert_err!( Faucet::drip(RuntimeOrigin::none(), account.clone()), Error::::FaucetUsedRecently ); + }); +} + +#[test] +fn drip_delay_succeeds() { + new_test_ext().execute_with(|| { + let account = account::(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() + ::FaucetDripDelay::get()); @@ -53,6 +80,9 @@ fn drip() { assert_eq!( events(), [ + RuntimeEvent::Balances(BalanceEvent::Issued { + amount: ::FaucetDripAmount::get() + }), RuntimeEvent::Balances(BalanceEvent::Deposit { who: account.clone(), amount: ::FaucetDripAmount::get() diff --git a/pallets/market/src/test.rs b/pallets/market/src/test.rs index 822fd2892..b5590dff5 100644 --- a/pallets/market/src/test.rs +++ b/pallets/market/src/test.rs @@ -1006,6 +1006,7 @@ fn verifies_deals_on_block_finalization() { assert_eq!( events(), [ + RuntimeEvent::Balances(pallet_balances::Event::::Rescinded { amount: 15 }), RuntimeEvent::Balances(pallet_balances::Event::::Withdraw { who: Market::account_id(), amount: 15 @@ -1503,12 +1504,13 @@ fn slash_and_burn_acc() { assert_eq!( events(), - [RuntimeEvent::Balances( - pallet_balances::Event::::Withdraw { + [ + RuntimeEvent::Balances(pallet_balances::Event::::Rescinded { amount: 10 }), + RuntimeEvent::Balances(pallet_balances::Event::::Withdraw { who: Market::account_id(), amount: 10 - } - ),] + }), + ] ); assert_eq!( ::Currency::total_issuance(), @@ -1689,6 +1691,7 @@ fn on_sector_terminate_active() { assert_eq!( events(), [ + RuntimeEvent::Balances(pallet_balances::Event::::Rescinded { amount: 15 }), RuntimeEvent::Balances(pallet_balances::Event::::Withdraw { who: Market::account_id(), amount: 15 diff --git a/pallets/storage-provider/src/lib.rs b/pallets/storage-provider/src/lib.rs index 994c9f791..13834ff8c 100644 --- a/pallets/storage-provider/src/lib.rs +++ b/pallets/storage-provider/src/lib.rs @@ -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::::SlashingFailed)?; diff --git a/pallets/storage-provider/src/tests/pre_commit_sector_hook.rs b/pallets/storage-provider/src/tests/pre_commit_sector_hook.rs index 9a91fc0a3..041674edb 100644 --- a/pallets/storage-provider/src/tests/pre_commit_sector_hook.rs +++ b/pallets/storage-provider/src/tests/pre_commit_sector_hook.rs @@ -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::::Slashed { who: account(storage_provider), amount: deal_precommit_deposit, }), + RuntimeEvent::Balances(pallet_balances::Event::::Rescinded { + amount: deal_precommit_deposit + }), RuntimeEvent::Balances(pallet_balances::Event::::Withdraw { who: account(storage_provider), amount: deal_precommit_deposit, }), + RuntimeEvent::Balances(pallet_balances::Event::::Rescinded { + amount: deal_precommit_deposit + }), ] ); });