Skip to content

Commit

Permalink
test: fix integration tests (#3015)
Browse files Browse the repository at this point in the history
  • Loading branch information
stringhandler committed Jun 16, 2021
2 parents b174390 + 568788c commit 4b4af99
Show file tree
Hide file tree
Showing 7 changed files with 266 additions and 284 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ commands:
when: always
- run:
name: Run flaky/broken cucumber scenarios (Always pass)
command: node_modules/.bin/cucumber-js --tags "not @long-running and @broken" --format json:cucumber_output/broken-tests.cucumber || true
command: cd integration_tests && node_modules/.bin/cucumber-js --tags "not @long-running and (@broken or @flaky)" --format json:cucumber_output/broken-tests.cucumber || true
- store_test_results:
path: integration_tests/cucumber_output
- store_artifacts:
Expand Down
39 changes: 22 additions & 17 deletions applications/tari_console_wallet/src/wallet_modes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ pub fn command_mode(config: WalletModeConfig, wallet: WalletSqlite, command: Str
global_config, handle, ..
} = config.clone();
let commands = vec![parse_command(&command)?];
info!("Starting wallet command mode");
info!(target: LOG_TARGET, "Starting wallet command mode");
handle.block_on(command_runner(handle.clone(), commands, wallet.clone(), global_config))?;

info!("Shutting down wallet command mode");
info!(target: LOG_TARGET, "Completed wallet command mode");

wallet_or_exit(config, wallet)
}
Expand Down Expand Up @@ -171,22 +171,27 @@ pub fn script_mode(config: WalletModeConfig, wallet: WalletSqlite, path: PathBuf
}

fn wallet_or_exit(config: WalletModeConfig, wallet: WalletSqlite) -> Result<(), ExitCodes> {
debug!(target: LOG_TARGET, "Prompting for run or exit key.");
println!("\nPress Enter to continue to the wallet, or or type q (or quit) followed by Enter.");
let mut buf = String::new();
std::io::stdin()
.read_line(&mut buf)
.map_err(|e| ExitCodes::IOError(e.to_string()))?;

match buf.as_str().trim() {
"quit" | "q" | "exit" => Ok(()),
_ => {
if config.daemon_mode {
grpc_mode(config, wallet)
} else {
if config.daemon_mode {
info!(target: LOG_TARGET, "Daemon mode detected - auto exiting.");
Ok(())
} else {
debug!(target: LOG_TARGET, "Prompting for run or exit key.");
println!("\nPress Enter to continue to the wallet, or type q (or quit) followed by Enter.");
let mut buf = String::new();
std::io::stdin()
.read_line(&mut buf)
.map_err(|e| ExitCodes::IOError(e.to_string()))?;

match buf.as_str().trim() {
"quit" | "q" | "exit" => {
info!(target: LOG_TARGET, "Exiting.");
Ok(())
},
_ => {
info!(target: LOG_TARGET, "Starting TUI.");
tui_mode(config, wallet)
}
},
},
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,13 @@ use crate::output_manager_service::{
},
MasterKeyManager,
};
use blake2::Digest;
use log::*;
use std::sync::Arc;
use tari_core::transactions::{
transaction::{TransactionOutput, UnblindedOutput},
types::{CryptoFactories, PrivateKey, PublicKey},
};
use tari_crypto::{
common::Blake256,
inputs,
keys::PublicKey as PublicKeyTrait,
tari_utilities::{hex::Hex, ByteArray},
types::{CryptoFactories, PublicKey},
};
use tari_crypto::{inputs, keys::PublicKey as PublicKeyTrait, tari_utilities::hex::Hex};

const LOG_TARGET: &str = "wallet::output_manager_service::recovery";

Expand Down Expand Up @@ -85,17 +79,9 @@ where TBackend: OutputManagerBackend + 'static
.map(|v| (v, output.features, output.script, output.script_offset_public_key))
})
.map(|(output, features, script, script_offset_public_key)| {
let beta_hash = Blake256::new()
.chain(script.as_bytes())
.chain(features.to_bytes())
.chain(script_offset_public_key.as_bytes())
.result()
.to_vec();
let beta = PrivateKey::from_bytes(beta_hash.as_slice())
.expect("Should be able to construct a private key from a hash");
UnblindedOutput::new(
output.committed_value,
output.blinding_factor.clone() - beta,
output.blinding_factor.clone(),
Some(features),
script,
inputs!(PublicKey::from_secret_key(&output.blinding_factor)),
Expand Down
43 changes: 22 additions & 21 deletions integration_tests/features/Mempool.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
Feature: Mempool

Scenario: Transactions are propagated through a network
Given I have 10 seed nodes
Given I have 8 seed nodes
And I have a base node SENDER connected to all seed nodes
And I have 10 base nodes connected to all seed nodes
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
When I create a transaction TX1 spending CB1 to UTX1
Expand All @@ -25,11 +25,12 @@ Feature: Mempool
Then TX1 is in the MEMPOOL of all nodes
Given 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
When I mine 1 blocks on SENDER
Then SENDER has TX1 in MINED state
Then TX1 is in the MINED of all nodes

Scenario: Clear out mempool
@flaky
Scenario: Clear out mempool
Given I have 1 seed nodes
And I have a base node SENDER connected to all seed nodes
When I mine a block on SENDER with coinbase CB1
Expand Down Expand Up @@ -76,11 +77,11 @@ Feature: Mempool

@critical
Scenario: Mempool clearing out invalid transactions after a reorg
#
# Chain 1:
# Collects 7 coinbases into one wallet, send 7 transactions
# Stronger chain
#
#
# Chain 1:
# Collects 7 coinbases into one wallet, send 7 transactions
# Stronger chain
#
Given I have a seed node SEED_A
And I have a base node NODE_A1 connected to seed SEED_A
And I have wallet WALLET_A1 connected to seed node SEED_A
Expand All @@ -97,11 +98,11 @@ Feature: Mempool
And I multi-send 7 transactions of 1000000 uT from wallet WALLET_A1 to wallet WALLET_A2 at fee 100
Then wallet WALLET_A1 detects all transactions are at least Broadcast
When I wait 1 seconds
#
# Chain 2:
# Collects 7 coinbases into one wallet, send 7 transactions
# Weaker chain
#
#
# Chain 2:
# Collects 7 coinbases into one wallet, send 7 transactions
# Weaker chain
#
And I have a seed node SEED_B
And I have a base node NODE_B1 connected to seed SEED_B
And I have wallet WALLET_B1 connected to seed node SEED_B
Expand All @@ -118,15 +119,15 @@ Feature: Mempool
And I multi-send 7 transactions of 1000000 uT from wallet WALLET_B1 to wallet WALLET_B2 at fee 100
Then wallet WALLET_B1 detects all transactions are at least Broadcast
When I wait 1 seconds
#
# Connect Chain 1 and 2 in stages
# New node connects to weaker chain, receives all broadcast (not mined) transactions into mempool
# New node connects to stronger chain, then reorgs its complete chain
# New node mines blocks; no invalid inputs from the weaker chain should be used in the block template
#
#
# Connect Chain 1 and 2 in stages
# New node connects to weaker chain, receives all broadcast (not mined) transactions into mempool
# New node connects to stronger chain, then reorgs its complete chain
# New node mines blocks; no invalid inputs from the weaker chain should be used in the block template
#
And I have a base node NODE_C connected to seed SEED_B
Then node NODE_C is at height 12
# Wait for the reorg to filter through
# Wait for the reorg to filter through
And I connect node SEED_A to node NODE_C and wait 30 seconds
Then all nodes are at height 10
When I mine 6 blocks on NODE_C
Expand Down
93 changes: 47 additions & 46 deletions integration_tests/features/WalletRecovery.feature
Original file line number Diff line number Diff line change
@@ -1,50 +1,51 @@
@wallet-recovery
Feature: Wallet Recovery

@critical
Scenario: Wallet recovery with connected base node staying online
Given I have a seed node NODE
And I have 1 base nodes connected to all seed nodes
And I have wallet WALLET_A connected to all seed nodes
And I have a merge mining proxy PROXY connected to NODE and WALLET_A with default config
When I merge mine 10 blocks via PROXY
When I mine 5 blocks on NODE
When I wait for wallet WALLET_A to have at least 55000000000 uT
Then all nodes are at height 15
When I recover wallet WALLET_A into wallet WALLET_B connected to all seed nodes
Then wallet WALLET_A and wallet WALLET_B have the same balance
And I have wallet WALLET_C connected to all seed nodes
And I send 100000 uT from wallet WALLET_B to wallet WALLET_C at fee 100
Then wallet WALLET_B detects all transactions are at least Broadcast
When I mine 5 blocks on NODE
Then all nodes are at height 20
Then I wait for wallet WALLET_C to have at least 100000 uT
@critical
Scenario: Wallet recovery with connected base node staying online
Given I have a seed node NODE
And I have 1 base nodes connected to all seed nodes
And I have wallet WALLET_A connected to all seed nodes
And I have a merge mining proxy PROXY connected to NODE and WALLET_A with default config
When I merge mine 10 blocks via PROXY
When I mine 5 blocks on NODE
When I wait for wallet WALLET_A to have at least 55000000000 uT
Then all nodes are at height 15
When I recover wallet WALLET_A into wallet WALLET_B connected to all seed nodes
Then wallet WALLET_A and wallet WALLET_B have the same balance
And I have wallet WALLET_C connected to all seed nodes
And I send 100000 uT from wallet WALLET_B to wallet WALLET_C at fee 100
Then wallet WALLET_B detects all transactions are at least Broadcast
When I mine 5 blocks on NODE
Then all nodes are at height 20
Then I wait for wallet WALLET_C to have at least 100000 uT

@critical
Scenario: Recover one-sided payments
Given I have a seed node NODE
And I have 1 base nodes connected to all seed nodes
And I have wallet WALLET_A connected to all seed nodes
And I have a merge mining proxy PROXY connected to NODE and WALLET_A with default config
When I merge mine 10 blocks via PROXY
Then all nodes are at height 10
And I have wallet WALLET_B connected to all seed nodes
And I stop wallet WALLET_B
# Send 2 one-sided payments to WALLET_B so it can spend them in two cases
Then I send a one-sided transaction of 1000000 uT from WALLET_A to WALLET_B at fee 100
Then I send a one-sided transaction of 1000000 uT from WALLET_A to WALLET_B at fee 100
When I merge mine 5 blocks via PROXY
Then all nodes are at height 15
When I recover wallet WALLET_B into wallet WALLET_C connected to all seed nodes
Then I wait for wallet WALLET_C to have at least 2000000 uT
# Send one of the recovered outputs back to Wallet A as a one-sided transactions
Then I send a one-sided transaction of 900000 uT from WALLET_C to WALLET_A at fee 100
When I merge mine 5 blocks via PROXY
Then all nodes are at height 20
Then I wait for wallet WALLET_C to have less than 1100000 uT
# Send the remaining recovered UTXO to self in standard MW transaction
Then I send 1000000 uT from wallet WALLET_C to wallet WALLET_C at fee 100
Then I wait for wallet WALLET_C to have less than 100000 uT
When I merge mine 5 blocks via PROXY
Then all nodes are at height 25
Then I wait for wallet WALLET_C to have at least 1000000 uT
# fails often on circle CI
@critical @flaky
Scenario: Recover one-sided payments
Given I have a seed node NODE
And I have 1 base nodes connected to all seed nodes
And I have wallet WALLET_A connected to all seed nodes
And I have a merge mining proxy PROXY connected to NODE and WALLET_A with default config
When I merge mine 10 blocks via PROXY
Then all nodes are at height 10
And I have wallet WALLET_B connected to all seed nodes
And I stop wallet WALLET_B
# Send 2 one-sided payments to WALLET_B so it can spend them in two cases
Then I send a one-sided transaction of 1000000 uT from WALLET_A to WALLET_B at fee 100
Then I send a one-sided transaction of 1000000 uT from WALLET_A to WALLET_B at fee 100
When I merge mine 5 blocks via PROXY
Then all nodes are at height 15
When I recover wallet WALLET_B into wallet WALLET_C connected to all seed nodes
Then I wait for wallet WALLET_C to have at least 2000000 uT
# Send one of the recovered outputs back to Wallet A as a one-sided transactions
Then I send a one-sided transaction of 900000 uT from WALLET_C to WALLET_A at fee 100
When I merge mine 5 blocks via PROXY
Then all nodes are at height 20
Then I wait for wallet WALLET_C to have less than 1100000 uT
# Send the remaining recovered UTXO to self in standard MW transaction
Then I send 1000000 uT from wallet WALLET_C to wallet WALLET_C at fee 100
Then I wait for wallet WALLET_C to have less than 100000 uT
When I merge mine 5 blocks via PROXY
Then all nodes are at height 25
Then I wait for wallet WALLET_C to have at least 1000000 uT
4 changes: 3 additions & 1 deletion integration_tests/helpers/walletProcess.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ class WalletProcess {
"--init",
"--base-path",
".",
"--daemon",
"--password",
"kensentme",
"--command",
Expand All @@ -190,10 +191,11 @@ class WalletProcess {
"--init",
"--base-path",
".",
"--daemon",
"--password",
"kensentme",
"--command",
"export-utxos --csv-file exported_outputs.csv",
"export-utxos --csv-file exported_outputs.csv",
];
outputProcess = __dirname + "/../temp/out/tari_console_wallet";
await this.run(outputProcess, args, true);
Expand Down
Loading

0 comments on commit 4b4af99

Please sign in to comment.