Skip to content

Commit

Permalink
Merge pull request #5085 from brianp/feature-cucumber-rs-bug-fixes
Browse files Browse the repository at this point in the history
fix: a few cucumber bugs
  • Loading branch information
brianp authored Jan 5, 2023
2 parents c54e4a1 + 74a8c4b commit b3380c7
Show file tree
Hide file tree
Showing 13 changed files with 81 additions and 75 deletions.
40 changes: 18 additions & 22 deletions integration_tests/tests/cucumber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ use crate::utils::{
pub const LOG_TARGET: &str = "cucumber";
pub const LOG_TARGET_STDOUT: &str = "stdout";
const CONFIRMATION_PERIOD: u64 = 4;
const NUM_RETIRES: u64 = 240;
const RETRY_TIME_IN_MS: u64 = 250;

#[derive(Error, Debug)]
pub enum TariWorldError {
Expand Down Expand Up @@ -256,52 +258,46 @@ async fn run_miner(world: &mut TariWorld, miner_name: String, num_blocks: u64) {
#[then(expr = "all nodes are at height {int}")]
#[when(expr = "all nodes are at height {int}")]
async fn all_nodes_are_at_height(world: &mut TariWorld, height: u64) {
let num_retries = 24; // About 2 minutes
let mut nodes_at_height: IndexMap<&String, bool> = IndexMap::new();
let num_retries = NUM_RETIRES * height; // About 2 minutes per block
let mut nodes_at_height: IndexMap<&String, u64> = IndexMap::new();

let _ = world
.base_nodes
.iter()
.map(|(name, _)| nodes_at_height.insert(name, false));
for (name, _) in world.base_nodes.iter() {
nodes_at_height.insert(name, 0);
}

for _ in 0..num_retries {
for (name, _) in nodes_at_height
.clone()
.iter()
.filter(|(_, at_height)| at_height == &&false)
.filter(|(_, at_height)| at_height != &&height)
{
let mut client = world.get_node_client(name).await.unwrap();

let chain_tip = client.get_tip_info(Empty {}).await.unwrap().into_inner();
let chain_hgt = chain_tip.metadata.unwrap().height_of_longest_chain;

if chain_hgt < height {
nodes_at_height.insert(name, true);
}
nodes_at_height.insert(name, chain_hgt);
}

if nodes_at_height.values().all(|v| v == &true) {
if nodes_at_height.values().all(|h| h == &height) {
return;
}

tokio::time::sleep(Duration::from_secs(5)).await;
tokio::time::sleep(Duration::from_millis(RETRY_TIME_IN_MS)).await;
}

panic!("base nodes not successfully synchronized at height {}", height);
panic!(
"base nodes not successfully synchronized at height {}, {:?}",
height, nodes_at_height
);
}

#[when(expr = "node {word} is at height {int}")]
#[then(expr = "node {word} is at height {int}")]
async fn node_is_at_height(world: &mut TariWorld, base_node: String, height: u64) {
let num_retries = 24; // About two minutes
let num_retries = NUM_RETIRES; // About two minutes

let mut client = world
.base_nodes
.get(&base_node)
.unwrap()
.get_grpc_client()
.await
.unwrap();
let mut client = world.get_node_client(&base_node).await.unwrap();
let mut chain_hgt = 0;

for _ in 0..=num_retries {
Expand All @@ -312,7 +308,7 @@ async fn node_is_at_height(world: &mut TariWorld, base_node: String, height: u64
return;
}

tokio::time::sleep(Duration::from_secs(5)).await;
tokio::time::sleep(Duration::from_millis(RETRY_TIME_IN_MS)).await;
}

// base node didn't synchronize successfully at height, so we bail out
Expand Down
8 changes: 8 additions & 0 deletions integration_tests/tests/features/BaseNodeConnectivity.feature
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,20 @@ Feature: Base Node Connectivity
When I have wallet WALLET connected to all seed nodes
When I have mining node MINER connected to base node NODE and wallet WALLET
Given mining node MINER mines 1 blocks
Then node NODE is at height 1

Scenario: Basic mining with templates
Given I have a base node NODE
When I mine 2 blocks on NODE
Then node NODE is at height 2
Then all nodes are at height 2

Scenario: Base node lists heights
Given I have a seed node N1
When I mine 5 blocks on N1
Then node N1 lists heights 1 to 5


Scenario: Base node lists headers
Given I have a seed node BN1
When I mine 5 blocks on BN1
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/tests/features/BlockExplorerGRPC.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ Feature: Block Explorer GRPC
When I have wallet WALLET connected to all seed nodes
# And I have a merge mining proxy PROXY connected to NODE and WALLET with default config
# When I merge mine 2 blocks via PROXY
Then all nodes are at height 2
# Then all nodes are at height 2
# When I request the difficulties of a node NODE
# Then difficulties are available
8 changes: 4 additions & 4 deletions integration_tests/tests/features/Mempool.feature
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Feature: Mempool
# And I have 8 base nodes connected to all seed nodes
# When I mine a block on SENDER with coinbase CB1
When I mine 2 blocks on SENDER
Then all nodes are at height 3
# Then all nodes are at height 3
# When I create a transaction TX1 spending CB1 to UTX1
# When I submit transaction TX1 to SENDER
# Then SENDER has TX1 in MEMPOOL state
Expand All @@ -29,15 +29,15 @@ Feature: Mempool
# And I have 2 base nodes connected to all seed nodes
# When I mine a block on SENDER with coinbase CB1
When I mine 2 blocks on SENDER
Then all nodes are at height 3
# Then all nodes are at height 3
# When I create a transaction TX1 spending CB1 to UTX1
# When I submit transaction TX1 to SENDER
# Then SENDER has TX1 in MEMPOOL state
# Then TX1 is in the MEMPOOL of all nodes
When I have a base node NODE1 connected to all seed nodes
# Then NODE1 has TX1 in MEMPOOL state
When I mine 1 blocks on SENDER
Then all nodes are at height 4
# Then all nodes are at height 4
# Then SENDER has TX1 in MINED state
# Then TX1 is in the MINED of all nodes

Expand Down Expand Up @@ -114,7 +114,7 @@ Feature: Mempool
# Then node SEED_A is at height 5
# Then node SEED_B is at height 12
# And I connect node NODE_A to node NODE_B
Then all nodes are at height 12
# Then all nodes are at height 12
# Then NODE_A has TXA in NOT_STORED state
# Then NODE_A has TXB in MINED state

Expand Down
2 changes: 1 addition & 1 deletion integration_tests/tests/features/MergeMining.feature
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ Feature: Merge Mining
When I have wallet WALLET connected to all seed nodes
# And I have a merge mining proxy PROXY connected to NODE and WALLET with default config
# When I merge mine 2 blocks via PROXY
Then all nodes are at height 2
# Then all nodes are at height 2

20 changes: 10 additions & 10 deletions integration_tests/tests/features/Propagation.feature
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,21 @@ Feature: Block Propagation
# And I have a SHA3 miner MINER connected to all seed nodes
# And mining node MINER mines 5 blocks
# Then node MINER is at height 5
Then all nodes are at height 5
# Then all nodes are at height 5

Scenario: Duplicate block is rejected
Given I have 1 seed nodes
When I have a base node MINER connected to all seed nodes
# When I mine but do not submit a block BLOCKA on MINER
# When I submit block BLOCKA to MINER
Then all nodes are at height 1
# Then all nodes are at height 1
# When I submit block BLOCKA to MINER
# # TODO: this step is not implemented.
# Then I receive an error containing 'Block exists'
And all nodes are at height 1
# And all nodes are at height 1
# # Check that the base node continues to accept blocks
When I mine 1 blocks on MINER
Then all nodes are at height 2
# Then all nodes are at height 2

Scenario: Submit orphan
Given I have 1 seed nodes
Expand All @@ -53,11 +53,11 @@ Feature: Block Propagation
# # And I update the parent of block BLOCKA to be an orphan
# When I submit block BLOCKA to MINER
# Then I receive an error containing 'Orphan block'
Then all nodes are at height 1
# Then all nodes are at height 1
# # Do it twice to be sure
# When I submit block BLOCKA to MINER
# Then I receive an error containing 'Orphan block'
And all nodes are at height 1
# And all nodes are at height 1

@non-sync-propagation
Scenario: Nodes should never switch to block sync but stay synced via propagation
Expand All @@ -69,16 +69,16 @@ Feature: Block Propagation
# Then node LAG1 has reached initial sync
# Then node LAG2 has reached initial sync
# When mining node MINER mines 5 blocks
Then all nodes are at height 5
# Then all nodes are at height 5
# Given mining node MINER mines 15 blocks
Then all nodes are at height 20
# Then all nodes are at height 20

Scenario: Node should lag for while before syncing
Given I have 1 seed nodes
# Given I have a SHA3 miner MINER connected to all seed nodes
# And I have a lagging delayed node LAG1 connected to node MINER with blocks_behind_before_considered_lagging 6
# Given mining node MINER mines 1 blocks
Then all nodes are at height 1
# Then all nodes are at height 1
# When I stop node LAG1
# And mining node MINER mines 5 blocks
# Then node MINER is at height 6
Expand All @@ -89,7 +89,7 @@ Feature: Block Propagation
# Then node LAG1 is at height 1
# Given mining node MINER mines 1 blocks
# Then node MINER is at height 7
Then all nodes are at height 7
# Then all nodes are at height 7

@critical @pruned
Scenario: Pruned node should prune outputs
Expand Down
18 changes: 9 additions & 9 deletions integration_tests/tests/features/Reorgs.feature
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ Feature: Reorgs
When I have wallet WALLET1 connected to base node NODE1
When I have mining node MINING1 connected to base node NODE1 and wallet WALLET1
# When mining node MINING1 mines 5 blocks with min difficulty 1 and max difficulty 20
Then all nodes are at height 5
# Then all nodes are at height 5
# Given I have a pruned node PNODE2 connected to node NODE1 with pruning horizon set to 5
# When I have wallet WALLET2 connected to base node PNODE2
# And I have mining node MINING2 connected to base node PNODE2 and wallet WALLET2
# When mining node MINING1 mines 4 blocks with min difficulty 1 and max difficulty 20
Then all nodes are at height 9
# Then all nodes are at height 9
# When mining node MINING2 mines 5 blocks with min difficulty 1 and max difficulty 20
Then all nodes are at height 14
# Then all nodes are at height 14
# When I stop node PNODE2
# When mining node MINING1 mines 3 blocks with min difficulty 1 and max difficulty 20
# And node NODE1 is at height 17
Expand All @@ -93,7 +93,7 @@ Feature: Reorgs
# When mining node MINING2 mines 6 blocks with min difficulty 2 and max difficulty 1000000
# And node PNODE2 is at height 20
# When I start base node NODE1
Then all nodes are at height 20
# Then all nodes are at height 20

@reorg @flaky
Scenario: Pruned mode reorg past horizon
Expand All @@ -104,7 +104,7 @@ Feature: Reorgs
# When I have wallet WALLET2 connected to base node NODE2
# And I have mining node MINING2 connected to base node NODE2 and wallet WALLET2
# When I mine a block on NODE1 with coinbase CB1
Then all nodes are at height 1
# Then all nodes are at height 1
# And I stop node NODE1
# And mining node MINING2 mines 19 blocks with min difficulty 20 and max difficulty 1000000
# And node NODE2 is at height 20
Expand All @@ -120,7 +120,7 @@ Feature: Reorgs
# Given I have a pruned node PNODE1 connected to node NODE1 with pruning horizon set to 5
# Then node PNODE1 is at height 10
# When I start base node NODE2
Then all nodes are at height 20
# Then all nodes are at height 20
# # Because TX1 should have been re_orged out we should be able to spend CB1 again
# When I create a transaction TX2 spending CB1 to UTX2
# When I submit transaction TX2 to PNODE1
Expand All @@ -140,7 +140,7 @@ Feature: Reorgs
When I mine 1 blocks on NODE1
# Then NODE1 has TX1 in MINED state
# And NODE1 has TX11 in MINED state
And all nodes are at height 20
# And all nodes are at height 20
# And I stop node NODE1
# And node NODE2 is at height 20
# When I mine a block on NODE2 with coinbase CB2
Expand Down Expand Up @@ -262,7 +262,7 @@ Feature: Reorgs
# When I have wallet WALLET2 connected to base node NODE2
# And I have mining node MINER2 connected to base node NODE2 and wallet WALLET2
# And mining node MINER1 mines 5 blocks with min difficulty 1 and max difficulty 10
Then all nodes are at height 5
# Then all nodes are at height 5
# Given I stop node NODE2
# And mining node MINER1 mines 5 blocks with min difficulty 1 and max difficulty 1
# Then node NODE1 is at height 10
Expand All @@ -282,7 +282,7 @@ Feature: Reorgs
# When I have wallet WALLET2 connected to base node NODE2
# And I have mining node MINER2 connected to base node NODE2 and wallet WALLET2
# And mining node MINER1 mines 5 blocks with min difficulty 1 and max difficulty 10
Then all nodes are at height 5
# Then all nodes are at height 5
# Given I stop node NODE2
# And mining node MINER1 mines 1001 blocks with min difficulty 1 and max difficulty 10
# Then node NODE1 is at height 1006
Expand Down
28 changes: 14 additions & 14 deletions integration_tests/tests/features/Sync.feature
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Feature: Block Sync
# Given mining node MINER mines 20 blocks
# Given I have 2 base nodes connected to all seed nodes
# # All nodes should sync to tip
Then all nodes are at height 20
# Then all nodes are at height 20

@critical
Scenario: Sync burned output
Expand All @@ -42,24 +42,24 @@ Feature: Block Sync
When I have wallet WALLET_A connected to all seed nodes
When I have mining node MINER connected to base node NODE and wallet WALLET_A
# When mining node MINER mines 15 blocks
Then all nodes are at height 15
# Then all nodes are at height 15
# When I wait for wallet WALLET_A to have at least 55000000000 uT
# When I create a burn transaction of 1000000 uT from WALLET_A at fee 100
# When mining node MINER mines 10 blocks
Then all nodes are at height 25
# Then all nodes are at height 25
When I have a base node NODE2 connected to all seed nodes
Then all nodes are at height 25
# Then all nodes are at height 25

@critical @pruned
Scenario: Pruned mode simple sync
Given I have 1 seed nodes
# Given I have a SHA3 miner NODE1 connected to all seed nodes
# When I mine a block on NODE1 with coinbase CB1
And I mine 4 blocks on NODE1
# And I mine 4 blocks on NODE1
# When I spend outputs CB1 via NODE1
# Given mining node NODE1 mines 15 blocks
# Given I have a pruned node PNODE1 connected to node NODE1 with pruning horizon set to 5
Then all nodes are at height 20
# Then all nodes are at height 20

@critical @pruned
Scenario: Pruned node should handle burned output
Expand All @@ -69,13 +69,13 @@ Feature: Block Sync
When I have wallet WALLET_A connected to all seed nodes
When I have mining node MINER connected to base node NODE and wallet WALLET_A
# When mining node MINER mines 15 blocks
Then all nodes are at height 15
# Then all nodes are at height 15
# When I wait for wallet WALLET_A to have at least 55000000000 uT
# When I create a burn transaction of 1000000 uT from WALLET_A at fee 100
# When mining node MINER mines 10 blocks
Then all nodes are at height 25
# Then all nodes are at height 25
# Given I have a pruned node PNODE1 connected to node NODE1 with pruning horizon set to 5
Then all nodes are at height 25
# Then all nodes are at height 25

@critical
Scenario: When a new node joins the network, it receives all peers
Expand All @@ -92,13 +92,13 @@ Feature: Block Sync
When I have a base node NODE1 connected to all seed nodes
# When I mine a block on NODE1 with coinbase CB1
And I mine 4 blocks on NODE1
Then all nodes are at height 5
# Then all nodes are at height 5
# When I spend outputs CB1 via NODE1
And I mine 3 blocks on NODE1
# Given I have a pruned node PNODE2 connected to node NODE1 with pruning horizon set to 5
Then all nodes are at height 8
# Then all nodes are at height 8
# When I mine 15 blocks on PNODE2
Then all nodes are at height 23
# Then all nodes are at height 23

@long-running @flaky
Scenario: Node should not sync from pruned node
Expand All @@ -107,7 +107,7 @@ Feature: Block Sync
When I have mining node MINING1 connected to base node NODE1 and wallet WALLET1
# And I have a pruned node PNODE1 connected to node NODE1 with pruning horizon set to 6
# When mining node MINING1 mines 40 blocks with min difficulty 20 and max difficulty 9999999999
Then all nodes are at height 40
# Then all nodes are at height 40
# When I stop node NODE1
# Given I have a pruned node PNODE2 connected to node PNODE1 with pruning horizon set to 5
Given I have a base node NODE2
Expand All @@ -124,7 +124,7 @@ Feature: Block Sync
# # NODE2 may initially try to sync from PNODE1 and PNODE2, then eventually try to sync from NODE1; mining blocks
# # on NODE1 will make this test less flaky and force NODE2 to sync from NODE1 much quicker
# When I mine 10 blocks on NODE1
Then all nodes are at height 50
# Then all nodes are at height 50

Scenario Outline: Syncing node while also mining before tip sync
Given I have a seed node SEED
Expand Down
Loading

0 comments on commit b3380c7

Please sign in to comment.