Skip to content

Commit eac7ad3

Browse files
committed
Move tests for CI
1 parent 609b415 commit eac7ad3

File tree

1 file changed

+89
-87
lines changed

1 file changed

+89
-87
lines changed

ledger/src/tests.rs

Lines changed: 89 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -2515,93 +2515,6 @@ function foo:
25152515
}
25162516
}
25172517

2518-
#[cfg(feature = "test")]
2519-
#[test]
2520-
fn test_no_rewards_after_limit_height() {
2521-
let rng = &mut TestRng::default();
2522-
2523-
// Initialize the test environment.
2524-
let crate::test_helpers::TestEnv { ledger, private_key, address, .. } = crate::test_helpers::sample_test_env(rng);
2525-
2526-
// Advance the ledger to the reward limit height.
2527-
let supply_limit_height = CurrentNetwork::MAX_SUPPLY_LIMIT_HEIGHT;
2528-
2529-
// Advance until before the supply limit height.
2530-
while ledger.latest_height() + 1 < supply_limit_height {
2531-
let block = ledger.prepare_advance_to_next_beacon_block(&private_key, vec![], vec![], vec![], rng).unwrap();
2532-
ledger.advance_to_next_block(&block).unwrap();
2533-
2534-
// Check that there exists rewards in the block.
2535-
assert!(!block.ratifications().is_empty());
2536-
let ratifications: Vec<_> = block.ratifications().iter().collect();
2537-
match ratifications[0] {
2538-
Ratify::BlockReward(block_reward) => {
2539-
assert!(*block_reward > 0);
2540-
}
2541-
_ => panic!("Expected a block reward ratification"),
2542-
}
2543-
}
2544-
2545-
// Create one additional block at the supply limit height.
2546-
let next_block = ledger.prepare_advance_to_next_beacon_block(&private_key, vec![], vec![], vec![], rng).unwrap();
2547-
ledger.advance_to_next_block(&next_block).unwrap();
2548-
2549-
// Check that the block and puzzle rewards are 0.
2550-
assert!(!next_block.ratifications().is_empty());
2551-
let ratifications: Vec<_> = next_block.ratifications().iter().collect();
2552-
match ratifications[0] {
2553-
Ratify::BlockReward(block_reward) => {
2554-
assert_eq!(*block_reward, 0);
2555-
}
2556-
_ => panic!("Expected a block reward ratification"),
2557-
}
2558-
match ratifications[1] {
2559-
Ratify::PuzzleReward(puzzle_reward) => {
2560-
assert_eq!(*puzzle_reward, 0);
2561-
}
2562-
_ => panic!("Expected a puzzle reward ratification"),
2563-
}
2564-
2565-
// Create another block with a valid solution that does not give any rewards.
2566-
2567-
// Retrieve the puzzle parameters.
2568-
let puzzle = ledger.puzzle();
2569-
let latest_epoch_hash = ledger.latest_epoch_hash().unwrap();
2570-
let minimum_proof_target = ledger.latest_proof_target();
2571-
2572-
// Create solutions that are greater than the minimum proof target.
2573-
let valid_solution = loop {
2574-
let solution = puzzle.prove(latest_epoch_hash, address, rng.r#gen(), None).unwrap();
2575-
if puzzle.get_proof_target(&solution).unwrap() >= minimum_proof_target {
2576-
break solution;
2577-
}
2578-
};
2579-
2580-
// Create a block with the valid solution.
2581-
let next_block_with_solution =
2582-
ledger.prepare_advance_to_next_beacon_block(&private_key, vec![], vec![valid_solution], vec![], rng).unwrap();
2583-
ledger.advance_to_next_block(&next_block_with_solution).unwrap();
2584-
2585-
// Check that the block and puzzle rewards are 0.
2586-
assert!(!next_block.ratifications().is_empty());
2587-
let ratifications: Vec<_> = next_block.ratifications().iter().collect();
2588-
match ratifications[0] {
2589-
Ratify::BlockReward(block_reward) => {
2590-
assert_eq!(*block_reward, 0);
2591-
}
2592-
_ => panic!("Expected a block reward ratification"),
2593-
}
2594-
match ratifications[1] {
2595-
Ratify::PuzzleReward(puzzle_reward) => {
2596-
assert_eq!(*puzzle_reward, 0);
2597-
}
2598-
_ => panic!("Expected a puzzle reward ratification"),
2599-
}
2600-
2601-
// Check that the solution was accepted.
2602-
assert_eq!(next_block_with_solution.solutions().len(), 1);
2603-
}
2604-
26052518
// These tests require the proof targets to be low enough to be able to generate **valid** solutions.
26062519
// This requires the 'test' feature to be enabled for the `console` dependency.
26072520
#[cfg(feature = "test")]
@@ -3322,6 +3235,95 @@ mod valid_solutions {
33223235
let block_aborted_solution_id = block.aborted_solution_ids().first().unwrap();
33233236
assert_eq!(*block_aborted_solution_id, invalid_solution.id(), "Aborted solutions do not match");
33243237
}
3238+
3239+
#[test]
3240+
fn test_no_rewards_after_limit_height() {
3241+
let rng = &mut TestRng::default();
3242+
3243+
// Initialize the test environment.
3244+
let crate::test_helpers::TestEnv { ledger, private_key, address, .. } =
3245+
crate::test_helpers::sample_test_env(rng);
3246+
3247+
// Advance the ledger to the reward limit height.
3248+
let supply_limit_height = CurrentNetwork::MAX_SUPPLY_LIMIT_HEIGHT;
3249+
3250+
// Advance until before the supply limit height.
3251+
while ledger.latest_height() + 1 < supply_limit_height {
3252+
let block = ledger.prepare_advance_to_next_beacon_block(&private_key, vec![], vec![], vec![], rng).unwrap();
3253+
ledger.advance_to_next_block(&block).unwrap();
3254+
3255+
// Check that there exists rewards in the block.
3256+
assert!(!block.ratifications().is_empty());
3257+
let ratifications: Vec<_> = block.ratifications().iter().collect();
3258+
match ratifications[0] {
3259+
Ratify::BlockReward(block_reward) => {
3260+
assert!(*block_reward > 0);
3261+
}
3262+
_ => panic!("Expected a block reward ratification"),
3263+
}
3264+
}
3265+
3266+
// Create one additional block at the supply limit height.
3267+
let next_block =
3268+
ledger.prepare_advance_to_next_beacon_block(&private_key, vec![], vec![], vec![], rng).unwrap();
3269+
ledger.advance_to_next_block(&next_block).unwrap();
3270+
3271+
// Check that the block and puzzle rewards are 0.
3272+
assert!(!next_block.ratifications().is_empty());
3273+
let ratifications: Vec<_> = next_block.ratifications().iter().collect();
3274+
match ratifications[0] {
3275+
Ratify::BlockReward(block_reward) => {
3276+
assert_eq!(*block_reward, 0);
3277+
}
3278+
_ => panic!("Expected a block reward ratification"),
3279+
}
3280+
match ratifications[1] {
3281+
Ratify::PuzzleReward(puzzle_reward) => {
3282+
assert_eq!(*puzzle_reward, 0);
3283+
}
3284+
_ => panic!("Expected a puzzle reward ratification"),
3285+
}
3286+
3287+
// Create another block with a valid solution that does not give any rewards.
3288+
3289+
// Retrieve the puzzle parameters.
3290+
let puzzle = ledger.puzzle();
3291+
let latest_epoch_hash = ledger.latest_epoch_hash().unwrap();
3292+
let minimum_proof_target = ledger.latest_proof_target();
3293+
3294+
// Create solutions that are greater than the minimum proof target.
3295+
let valid_solution = loop {
3296+
let solution = puzzle.prove(latest_epoch_hash, address, rng.r#gen(), None).unwrap();
3297+
if puzzle.get_proof_target(&solution).unwrap() >= minimum_proof_target {
3298+
break solution;
3299+
}
3300+
};
3301+
3302+
// Create a block with the valid solution.
3303+
let next_block_with_solution = ledger
3304+
.prepare_advance_to_next_beacon_block(&private_key, vec![], vec![valid_solution], vec![], rng)
3305+
.unwrap();
3306+
ledger.advance_to_next_block(&next_block_with_solution).unwrap();
3307+
3308+
// Check that the block and puzzle rewards are 0.
3309+
assert!(!next_block.ratifications().is_empty());
3310+
let ratifications: Vec<_> = next_block.ratifications().iter().collect();
3311+
match ratifications[0] {
3312+
Ratify::BlockReward(block_reward) => {
3313+
assert_eq!(*block_reward, 0);
3314+
}
3315+
_ => panic!("Expected a block reward ratification"),
3316+
}
3317+
match ratifications[1] {
3318+
Ratify::PuzzleReward(puzzle_reward) => {
3319+
assert_eq!(*puzzle_reward, 0);
3320+
}
3321+
_ => panic!("Expected a puzzle reward ratification"),
3322+
}
3323+
3324+
// Check that the solution was accepted.
3325+
assert_eq!(next_block_with_solution.solutions().len(), 1);
3326+
}
33253327
}
33263328

33273329
/// Tests multiple attacks where the subDAG of a block is invalid

0 commit comments

Comments
 (0)