-
Notifications
You must be signed in to change notification settings - Fork 87
market actor tests p8 #328
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
266 changes: 266 additions & 0 deletions
266
actors/market/tests/verify_deals_for_activation_test.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,266 @@ | ||
| // Copyright 2019-2022 ChainSafe Systems | ||
| // SPDX-License-Identifier: Apache-2.0, MIT | ||
|
|
||
| mod harness; | ||
| use fil_actor_market::policy::detail::deal_weight; | ||
| use fil_actor_market::{Actor as MarketActor, Method, SectorDeals, VerifyDealsForActivationParams}; | ||
| use fil_actors_runtime::test_utils::{ | ||
| expect_abort, expect_abort_contains_message, ACCOUNT_ACTOR_CODE_ID, MINER_ACTOR_CODE_ID, | ||
| }; | ||
| use fil_actors_runtime::EPOCHS_IN_DAY; | ||
| use fvm_ipld_encoding::RawBytes; | ||
| use fvm_shared::address::Address; | ||
| use fvm_shared::bigint::BigInt; | ||
| use fvm_shared::clock::ChainEpoch; | ||
| use fvm_shared::error::ExitCode; | ||
| use harness::*; | ||
| use num_traits::Zero; | ||
|
|
||
| const START_EPOCH: ChainEpoch = 10; | ||
| const END_EPOCH: ChainEpoch = 200 * EPOCHS_IN_DAY; | ||
| const SECTOR_EXPIRY: ChainEpoch = END_EPOCH + 200; | ||
| const MINER_ADDRESSES: MinerAddresses = MinerAddresses { | ||
| owner: OWNER_ADDR, | ||
| worker: WORKER_ADDR, | ||
| provider: PROVIDER_ADDR, | ||
| control: vec![], | ||
| }; | ||
|
|
||
| #[test] | ||
| fn verify_deal_and_get_deal_weight_for_unverified_deal_proposal() { | ||
| let mut rt = setup(); | ||
| let deal_id = | ||
| generate_and_publish_deal(&mut rt, CLIENT_ADDR, &MINER_ADDRESSES, START_EPOCH, END_EPOCH); | ||
| let deal_proposal = get_deal_proposal(&mut rt, deal_id); | ||
|
|
||
| let response = verify_deals_for_activation( | ||
| &mut rt, | ||
| PROVIDER_ADDR, | ||
| vec![SectorDeals { sector_expiry: SECTOR_EXPIRY, deal_ids: vec![deal_id] }], | ||
| ); | ||
|
|
||
| assert_eq!(1, response.sectors.len()); | ||
| assert_eq!(BigInt::zero(), response.sectors[0].verified_deal_weight); | ||
| assert_eq!(deal_weight(&deal_proposal), response.sectors[0].deal_weight); | ||
|
|
||
| check_state(&rt); | ||
| } | ||
|
|
||
| #[test] | ||
| fn verify_deal_and_get_deal_weight_for_verified_deal_proposal() { | ||
| let mut rt = setup(); | ||
| let deal_id = generate_and_publish_verified_deal( | ||
| &mut rt, | ||
| CLIENT_ADDR, | ||
| &MINER_ADDRESSES, | ||
| START_EPOCH, | ||
| END_EPOCH, | ||
| ); | ||
| let deal_proposal = get_deal_proposal(&mut rt, deal_id); | ||
|
|
||
| let response = verify_deals_for_activation( | ||
| &mut rt, | ||
| PROVIDER_ADDR, | ||
| vec![SectorDeals { sector_expiry: SECTOR_EXPIRY, deal_ids: vec![deal_id] }], | ||
| ); | ||
|
|
||
| assert_eq!(1, response.sectors.len()); | ||
| assert_eq!(deal_weight(&deal_proposal), response.sectors[0].verified_deal_weight); | ||
| assert_eq!(BigInt::zero(), response.sectors[0].deal_weight); | ||
|
|
||
| check_state(&rt); | ||
| } | ||
|
|
||
| #[test] | ||
| fn verification_and_weights_for_verified_and_unverified_deals() { | ||
| let mut rt = setup(); | ||
| let mut create_deal = |end_epoch, verified| { | ||
| let mut deal = generate_deal_and_add_funds( | ||
| &mut rt, | ||
| CLIENT_ADDR, | ||
| &MINER_ADDRESSES, | ||
| START_EPOCH, | ||
| end_epoch, | ||
| ); | ||
| deal.verified_deal = verified; | ||
| deal | ||
| }; | ||
|
|
||
| let verified_deal_1 = create_deal(END_EPOCH, true); | ||
| let verified_deal_2 = create_deal(END_EPOCH + 1, true); | ||
| let unverified_deal_1 = create_deal(END_EPOCH + 2, false); | ||
| let unverified_deal_2 = create_deal(END_EPOCH + 3, false); | ||
|
|
||
| rt.set_caller(*ACCOUNT_ACTOR_CODE_ID, WORKER_ADDR); | ||
| let deal_ids = publish_deals( | ||
| &mut rt, | ||
| &MINER_ADDRESSES, | ||
| &[ | ||
| verified_deal_1.clone(), | ||
| verified_deal_2.clone(), | ||
| unverified_deal_1.clone(), | ||
| unverified_deal_2.clone(), | ||
| ], | ||
| ); | ||
|
|
||
| let response = verify_deals_for_activation( | ||
| &mut rt, | ||
| PROVIDER_ADDR, | ||
| vec![SectorDeals { sector_expiry: SECTOR_EXPIRY, deal_ids }], | ||
| ); | ||
|
|
||
| let verified_weight = deal_weight(&verified_deal_1) + deal_weight(&verified_deal_2); | ||
| let unverified_weight = deal_weight(&unverified_deal_1) + deal_weight(&unverified_deal_2); | ||
|
|
||
| assert_eq!(1, response.sectors.len()); | ||
| assert_eq!(verified_weight, response.sectors[0].verified_deal_weight); | ||
| assert_eq!(unverified_weight, response.sectors[0].deal_weight); | ||
|
|
||
| check_state(&rt); | ||
| } | ||
|
|
||
| #[test] | ||
| fn fail_when_caller_is_not_a_storage_miner_actor() { | ||
| let mut rt = setup(); | ||
| let deal_id = | ||
| generate_and_publish_deal(&mut rt, CLIENT_ADDR, &MINER_ADDRESSES, START_EPOCH, END_EPOCH); | ||
|
|
||
| rt.set_caller(*ACCOUNT_ACTOR_CODE_ID, WORKER_ADDR); | ||
| rt.expect_validate_caller_type(vec![*MINER_ACTOR_CODE_ID]); | ||
|
|
||
| let params = VerifyDealsForActivationParams { | ||
| sectors: vec![SectorDeals { sector_expiry: SECTOR_EXPIRY, deal_ids: vec![deal_id] }], | ||
| }; | ||
| expect_abort( | ||
| ExitCode::USR_FORBIDDEN, | ||
| rt.call::<MarketActor>( | ||
| Method::VerifyDealsForActivation as u64, | ||
| &RawBytes::serialize(params).unwrap(), | ||
| ), | ||
| ); | ||
|
|
||
| rt.verify(); | ||
| check_state(&rt); | ||
| } | ||
|
|
||
| #[test] | ||
| fn fail_when_deal_proposal_is_not_found() { | ||
| let mut rt = setup(); | ||
|
|
||
| let params = VerifyDealsForActivationParams { | ||
| sectors: vec![SectorDeals { sector_expiry: SECTOR_EXPIRY, deal_ids: vec![1] }], | ||
| }; | ||
| rt.set_caller(*MINER_ACTOR_CODE_ID, PROVIDER_ADDR); | ||
| rt.expect_validate_caller_type(vec![*MINER_ACTOR_CODE_ID]); | ||
| expect_abort( | ||
| ExitCode::USR_NOT_FOUND, | ||
| rt.call::<MarketActor>( | ||
| Method::VerifyDealsForActivation as u64, | ||
| &RawBytes::serialize(params).unwrap(), | ||
| ), | ||
| ); | ||
|
|
||
| rt.verify(); | ||
| check_state(&rt); | ||
| } | ||
|
|
||
| #[test] | ||
| fn fail_when_caller_is_not_the_provider() { | ||
| let mut rt = setup(); | ||
| let deal_id = | ||
| generate_and_publish_deal(&mut rt, CLIENT_ADDR, &MINER_ADDRESSES, START_EPOCH, END_EPOCH); | ||
|
|
||
| rt.set_caller(*MINER_ACTOR_CODE_ID, Address::new_id(205)); | ||
| rt.expect_validate_caller_type(vec![*MINER_ACTOR_CODE_ID]); | ||
|
|
||
| let params = VerifyDealsForActivationParams { | ||
| sectors: vec![SectorDeals { sector_expiry: SECTOR_EXPIRY, deal_ids: vec![deal_id] }], | ||
| }; | ||
| expect_abort( | ||
| ExitCode::USR_FORBIDDEN, | ||
| rt.call::<MarketActor>( | ||
| Method::VerifyDealsForActivation as u64, | ||
| &RawBytes::serialize(params).unwrap(), | ||
| ), | ||
| ); | ||
|
|
||
| rt.verify(); | ||
| check_state(&rt); | ||
| } | ||
|
|
||
| #[test] | ||
| fn fail_when_current_epoch_is_greater_than_proposal_start_epoch() { | ||
| let mut rt = setup(); | ||
| let deal_id = | ||
| generate_and_publish_deal(&mut rt, CLIENT_ADDR, &MINER_ADDRESSES, START_EPOCH, END_EPOCH); | ||
| rt.set_epoch(START_EPOCH + 1); | ||
|
|
||
| rt.set_caller(*MINER_ACTOR_CODE_ID, PROVIDER_ADDR); | ||
| rt.expect_validate_caller_type(vec![*MINER_ACTOR_CODE_ID]); | ||
|
|
||
| let params = VerifyDealsForActivationParams { | ||
| sectors: vec![SectorDeals { sector_expiry: SECTOR_EXPIRY, deal_ids: vec![deal_id] }], | ||
| }; | ||
| expect_abort( | ||
| ExitCode::USR_ILLEGAL_ARGUMENT, | ||
| rt.call::<MarketActor>( | ||
| Method::VerifyDealsForActivation as u64, | ||
| &RawBytes::serialize(params).unwrap(), | ||
| ), | ||
| ); | ||
|
|
||
| rt.verify(); | ||
| check_state(&rt); | ||
| } | ||
|
|
||
| #[test] | ||
| fn fail_when_deal_end_epoch_is_greater_than_sector_expiration() { | ||
| let mut rt = setup(); | ||
| let deal_id = | ||
| generate_and_publish_deal(&mut rt, CLIENT_ADDR, &MINER_ADDRESSES, START_EPOCH, END_EPOCH); | ||
|
|
||
| rt.set_caller(*MINER_ACTOR_CODE_ID, PROVIDER_ADDR); | ||
| rt.expect_validate_caller_type(vec![*MINER_ACTOR_CODE_ID]); | ||
|
|
||
| let params = VerifyDealsForActivationParams { | ||
| sectors: vec![SectorDeals { sector_expiry: END_EPOCH - 1, deal_ids: vec![deal_id] }], | ||
| }; | ||
| expect_abort( | ||
| ExitCode::USR_ILLEGAL_ARGUMENT, | ||
| rt.call::<MarketActor>( | ||
| Method::VerifyDealsForActivation as u64, | ||
| &RawBytes::serialize(params).unwrap(), | ||
| ), | ||
| ); | ||
|
|
||
| rt.verify(); | ||
| check_state(&rt); | ||
| } | ||
|
|
||
| #[test] | ||
| fn fail_when_the_same_deal_id_is_passed_multiple_times() { | ||
| let mut rt = setup(); | ||
| let deal_id = | ||
| generate_and_publish_deal(&mut rt, CLIENT_ADDR, &MINER_ADDRESSES, START_EPOCH, END_EPOCH); | ||
|
|
||
| rt.set_caller(*MINER_ACTOR_CODE_ID, PROVIDER_ADDR); | ||
| rt.expect_validate_caller_type(vec![*MINER_ACTOR_CODE_ID]); | ||
|
|
||
| let params = VerifyDealsForActivationParams { | ||
| sectors: vec![SectorDeals { | ||
| sector_expiry: SECTOR_EXPIRY, | ||
| deal_ids: vec![deal_id, deal_id], | ||
| }], | ||
| }; | ||
| expect_abort_contains_message( | ||
| ExitCode::USR_ILLEGAL_ARGUMENT, | ||
| "multiple times", | ||
| rt.call::<MarketActor>( | ||
| Method::VerifyDealsForActivation as u64, | ||
| &RawBytes::serialize(params).unwrap(), | ||
| ), | ||
| ); | ||
|
|
||
| rt.verify(); | ||
| check_state(&rt); | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
name should include the fact that we are adding funds.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's basically a copy of the function above with the
verified_dealsetting. I'd say we should keep the name or rename the one above as well. What do you think @ZenGround0 ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah my bad, keeping it this way is ok