-
Notifications
You must be signed in to change notification settings - Fork 38
fix: wait for valid blockhash #992
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
+134
−4
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
113 changes: 113 additions & 0 deletions
113
test-integration/test-ledger-restore/tests/16_cranks_persists.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,113 @@ | ||
| use std::{path::Path, process::Child}; | ||
|
|
||
| use cleanass::assert; | ||
| use integration_test_tools::{ | ||
| expect, loaded_accounts::LoadedAccounts, tmpdir::resolve_tmp_dir, | ||
| validator::cleanup, | ||
| }; | ||
| use program_flexi_counter::instruction::create_schedule_task_ix; | ||
| use solana_sdk::{signature::Keypair, signer::Signer}; | ||
| use test_kit::init_logger; | ||
| use test_ledger_restore::{ | ||
| confirm_tx_with_payer_ephem, fetch_counter_ephem, | ||
| init_and_delegate_counter_and_payer, setup_validator_with_local_remote, | ||
| setup_validator_with_local_remote_and_resume_strategy, | ||
| wait_for_ledger_persist, TMP_DIR_LEDGER, | ||
| }; | ||
| use tracing::*; | ||
|
|
||
| #[test] | ||
| fn test_crank_persistence() { | ||
| init_logger!(); | ||
| let (_tmpdir, ledger_path) = resolve_tmp_dir(TMP_DIR_LEDGER); | ||
|
|
||
| let (mut validator, payer, count) = write(&ledger_path); | ||
| validator.kill().unwrap(); | ||
|
|
||
| let mut validator = read(&ledger_path, &payer, count); | ||
| validator.kill().unwrap(); | ||
| } | ||
|
|
||
| fn write(ledger_path: &Path) -> (Child, Keypair, u64) { | ||
| let (_, mut validator, ctx) = setup_validator_with_local_remote( | ||
| ledger_path, | ||
| None, | ||
| true, | ||
| false, | ||
| &LoadedAccounts::with_delegation_program_test_authority(), | ||
| ); | ||
|
|
||
| let (payer, _) = | ||
| init_and_delegate_counter_and_payer(&ctx, &mut validator, "COUNTER"); | ||
|
|
||
| // Schedule a task | ||
| let task_id = 1; | ||
| let execution_interval_millis = 50; | ||
| let iterations = 1000; | ||
| let ix = create_schedule_task_ix( | ||
| payer.pubkey(), | ||
| task_id, | ||
| execution_interval_millis, | ||
| iterations, | ||
| false, | ||
| false, | ||
| ); | ||
| confirm_tx_with_payer_ephem(ix, &payer, &ctx, &mut validator); | ||
|
|
||
| // Wait for the task to be scheduled and executed | ||
| expect!(ctx.wait_for_delta_slot_ephem(3), validator); | ||
|
|
||
| // Check that the counter was incremented | ||
| let counter_account = | ||
| fetch_counter_ephem(&ctx, &payer.pubkey(), &mut validator); | ||
| assert!( | ||
| counter_account.count > 0, | ||
| cleanup(&mut validator), | ||
| "counter.count: {}", | ||
| counter_account.count | ||
| ); | ||
|
|
||
| // Wait more to be sure the ledger is persisted | ||
| wait_for_ledger_persist(&ctx, &mut validator); | ||
| debug!("✅ Ledger persisted"); | ||
|
|
||
| (validator, payer, counter_account.count) | ||
| } | ||
|
|
||
| fn read(ledger_path: &Path, kp: &Keypair, count: u64) -> Child { | ||
| let (_, mut validator, ctx) = | ||
| setup_validator_with_local_remote_and_resume_strategy( | ||
| ledger_path, | ||
| None, | ||
| false, | ||
| false, | ||
| &LoadedAccounts::with_delegation_program_test_authority(), | ||
| ); | ||
|
|
||
| // Check that the counter persisted its value | ||
| let current_count = | ||
| fetch_counter_ephem(&ctx, &kp.pubkey(), &mut validator).count; | ||
| assert!( | ||
| current_count >= count, | ||
| cleanup(&mut validator), | ||
| "counter.count: {} < {}", | ||
| current_count, | ||
| count | ||
| ); | ||
|
|
||
| // Wait for the crank to execute | ||
| expect!(ctx.wait_for_delta_slot_ephem(10), validator); | ||
|
|
||
| // Check that the count increased | ||
| let new_count = | ||
| fetch_counter_ephem(&ctx, &kp.pubkey(), &mut validator).count; | ||
| assert!( | ||
| new_count > current_count, | ||
| cleanup(&mut validator), | ||
| "counter.count: {} <= {}", | ||
| new_count, | ||
| current_count | ||
| ); | ||
|
|
||
| validator | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.