Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(pallet-market): add failure tests and code coverage #105

Merged
merged 22 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
be93172
test(pallet-market): add code coverage tools
th7nder Jul 1, 2024
d39c00b
docs: add recommended vs code extensions to make developers' life easier
th7nder Jul 1, 2024
1d7c80c
test(pallet-market): publish_storage_deals failure tests
th7nder Jul 2, 2024
a191127
test(pallet-market): refactor and simplify tests to use DealProposalB…
th7nder Jul 3, 2024
a075552
test(pallet-market): verify_deals_for_activation failures
th7nder Jul 3, 2024
9a481dd
Merge branch 'feat/11/market-pallet-cron' into feat/11/market-pallet-…
th7nder Jul 3, 2024
4eabf2f
test(pallet-market): test activate_deals even more
th7nder Jul 4, 2024
2ce0881
test(pallet-market): reorganize builders to be at the end of the file
th7nder Jul 4, 2024
922dbfc
style(pallet-market): format rust-toolchain
th7nder Jul 4, 2024
4e16eb8
Merge branch 'feat/11/market-pallet-cron' into feat/11/market-pallet-…
th7nder Jul 4, 2024
fc32814
Merge branch 'feat/11/market-pallet-cron' into feat/11/market-pallet-…
th7nder Jul 5, 2024
17b4c12
test(pallet-market): simplify tests
th7nder Jul 5, 2024
86a3569
Merge branch 'develop' into feat/11/market-pallet-tests
th7nder Jul 5, 2024
ccdd271
style(pallet-market): reformat
th7nder Jul 5, 2024
a3e338d
build: remove crates from .vscode/extensions
th7nder Jul 6, 2024
e69ba5b
tests(pallet-market): simplify and make more maintainable
th7nder Jul 6, 2024
4c50400
build: remove rust bundle
th7nder Jul 6, 2024
364945e
Merge branch 'develop' into feat/11/market-pallet-tests
th7nder Jul 8, 2024
0c1d0b3
test(pallet-market): make fails min duration more readable
th7nder Jul 8, 2024
4ee45f7
test(pallet-market): make em more readable
th7nder Jul 8, 2024
5a2f079
Merge branch 'develop' into feat/11/market-pallet-tests
th7nder Jul 8, 2024
f8643e9
test(pallet-market): deal from the past
th7nder Jul 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
.AppleDouble
.LSOverride
.idea
.vscode
.vscode/*
# For team-wide VS Code configuration, like code-coverage extensions and previews
!.vscode/settings.json
# Recommended extensions for VS Code
!.vscode/extensions.json

# Rust .gitignore
# https://github.com/github/gitignore/blob/main/Rust.gitignore
Expand All @@ -21,3 +25,6 @@ target/

# reproducible local environment
.direnv

# code coverage
coverage/
14 changes: 14 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"recommendations": [
// Rust language support
"rust-lang.rust-analyzer",
// Justfile
"nefrob.vscode-just-syntax",
// TOML support
"tamasfe.even-better-toml",
// Code Coverage display inline, next to the code
"ryanluker.vscode-coverage-gutters",
// direnv, to use tool binaries from `nix` profile and set environment variables automatically
"mkhl.direnv",
]
}
7 changes: 7 additions & 0 deletions .vscode/settings.json
th7nder marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"coverage-gutters.coverageBaseDir": "coverage",
"coverage-gutters.coverageFileNames": [
"pallet-market.lcov.info",
"mater.lcov.info"
]
}
8 changes: 6 additions & 2 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@
- [nix](https://nixos.org/download/) with [flakes](https://nixos.wiki/wiki/flakes) enabled (`echo 'experimental-features = nix-command flakes' >> ~/.config/nix/nix.conf`)
- reasoning: every developer has the same version of development tools (rust, protoc, zombienet), directed by [flake.nix](./flake.nix)`.
- how it works? fasterthanli.me has [a whole series on it](https://fasterthanli.me/series/building-a-rust-service-with-nix/part-10).
- optional: [vscode extension for Nix](https://marketplace.visualstudio.com/items?itemName=jnoortheen.nix-ide)
- [direnv](https://direnv.net/) with a [shell hook](https://direnv.net/docs/hook.html)
- *VS Code only* [direnv extension](https://marketplace.visualstudio.com/items?itemName=mkhl.direnv) (uses the same tooling as rust-toolchain.toml defined).
- reasoning: when you enter a directory it uses everything defined in [.envrc](./.envrc), e.g. environment variables, `nix`, secrets.
- [cargo-llvm-cov](llvm coverage generator), produces coverage in `coverage/` directory.

> [!NOTE]
> `.vscode/settings.json` is part of the git repo, please add only necessary and life-saving things there (like Code Coverage configuration).
>
> [Recommended extensions](https://code.visualstudio.com/docs/editor/extension-marketplace#_workspace-recommended-extensions) are also part of the repo in `.vscode/extensions.json`.

## How it works?
Nix is a package manager, which sneakily downloads all of the dependencies and updates PATH when you launch it with `nix develop`.
Expand Down
11 changes: 11 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,14 @@ release: lint
testnet: release
zombienet -p native spawn zombienet/local-testnet.toml

# Must be in sync with .vscode/settings.json and have extension Coverage Gutters to display it in VS Code.
market-coverage:
mkdir -p coverage
cargo llvm-cov -p pallet-market --ignore-filename-regex "(mock|test)"
cargo llvm-cov -p pallet-market report --ignore-filename-regex "(mock|test)" --html --output-dir coverage/pallet-market
cargo llvm-cov -p pallet-market report --ignore-filename-regex "(mock|test)" --lcov --output-path coverage/pallet-market.lcov.info

mater-coverage:
cargo llvm-cov -p mater --ignore-filename-regex "(mock|test)"
cargo llvm-cov -p mater report --ignore-filename-regex "(mock|test)" --html --output-dir coverage/mater
cargo llvm-cov -p mater report --ignore-filename-regex "(mock|test)" --lcov --output-path coverage/mater.lcov.info
jmg-duarte marked this conversation as resolved.
Show resolved Hide resolved
12 changes: 6 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
};
rustToolchain = pkgs.pkgsBuildHost.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
buildInputs = with pkgs; [
cargo-llvm-cov
clang
pkg-config
rustToolchain
Expand Down
9 changes: 6 additions & 3 deletions pallets/market/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ pub mod pallet {
ArithmeticError, BoundedBTreeMap, RuntimeDebug,
},
traits::{
tokens::WithdrawReasons,
Currency,
ExistenceRequirement::{AllowDeath, KeepAlive},
Hooks, ReservableCurrency,
Hooks, ReservableCurrency, WithdrawReasons,
},
PalletId,
};
Expand Down Expand Up @@ -1133,7 +1132,11 @@ pub mod pallet {

let mut pending_proposals = PendingProposals::<T>::get();
for sector in sector_deals {
let proposals = Self::proposals_for_deals(sector.deal_ids)?;
let Ok(proposals) = Self::proposals_for_deals(sector.deal_ids) else {
jmg-duarte marked this conversation as resolved.
Show resolved Hide resolved
log::error!("failed to find deals for sector: {}", sector.sector_number);
continue;
};

let sector_size = sector.sector_type.sector_size();
if let Err(e) = Self::validate_deals_for_sector(
&proposals,
Expand Down
5 changes: 3 additions & 2 deletions pallets/market/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl crate::Config for Test {
type OffchainPublic = AccountPublic;
type MaxDeals = ConstU32<32>;
type BlocksPerDay = ConstU64<1>;
type MinDealDuration = ConstU64<1>;
type MinDealDuration = ConstU64<2>;
type MaxDealDuration = ConstU64<30>;
type MaxDealsPerBlock = ConstU32<32>;
}
Expand Down Expand Up @@ -84,7 +84,7 @@ pub fn cid_of(data: &str) -> cid::Cid {
pub(crate) type DealProposalOf<T> =
DealProposal<<T as frame_system::Config>::AccountId, BalanceOf<T>, BlockNumberFor<T>>;

type ClientDealProposalOf<T> = ClientDealProposal<
pub(crate) type ClientDealProposalOf<T> = ClientDealProposal<
<T as frame_system::Config>::AccountId,
BalanceOf<T>,
BlockNumberFor<T>,
Expand All @@ -107,6 +107,7 @@ pub const INITIAL_FUNDS: u64 = 100;

/// Build genesis storage according to the mock runtime.
pub fn new_test_ext() -> sp_io::TestExternalities {
let _ = env_logger::try_init();
let mut t = system::GenesisConfig::<Test>::default()
.build_storage()
.unwrap()
Expand Down
Loading
Loading