diff --git a/end2end-tests/README.md b/end2end-tests/README.md index c15fc019df0c420eb01b9306143f20885a764947..6bea5535161d2e486fc8cae70415ae783728139b 100644 --- a/end2end-tests/README.md +++ b/end2end-tests/README.md @@ -1,6 +1,6 @@ # Duniter-v2s end2end tests -## cucumber functionnal tests +## Cucumber functionnal tests We use [cucumber] to be able to describe test scenarios in human language. @@ -20,7 +20,7 @@ Feature: Balance transfer Then dave should have 5 ÄžD ``` -### create a new functional test +### Create a new functional test To create a new test scenario, simply create a new file with a name of your choice in the `/cucumber-features` folder and give it the extension `.feature`. @@ -55,8 +55,8 @@ Each scenario is a list of steps. In our context (blockchain), only the `When` a List of possible actions: -- transfer: `alice send 5 ÄžD to bob` -- transfer_ud: `alice send 3 UD to bob` +- transfer: `alice sends 5 ÄžD to bob` +- transfer_ud: `alice sends 3 UD to bob` - transfer_all: `alice sends all her ÄžDs to bob` #### Then @@ -96,7 +96,7 @@ Amounts must be expressed as an integer of `ÄžD` or `UD`, decimal numbers are no If you need more precision, you can express amounts in cents of ÄžD (write `cÄžD`), or in thousandths of UD (write `mUD`). -### genesis state +### Genesis state Each scenario bootstraps its own blockchain with its own genesis state. @@ -117,17 +117,22 @@ For some scenarios, you may need to perform an action (When) that fails voluntar ### Run cucumber functional tests +The cucumber tests use the last debug binary in your `target` folder. Make sure this binary corresponds to the executable you want to test by running `cargo build` before. + To run the cucumber tests, you will need to have the rust toolchain installed locally. To run all the scenarios (there are many) use the command: `cargo cucumber` -You can filter the `.feature` files to run with the option `i`, for instante: +You can filter the `.feature` files to run with the option `i`, for instance: ``` cargo cucumber -i monetary* ``` -Will only run `.feature` files that start with `"monetary"`. +will only run `.feature` files that start with `"monetary"`. + +The features will be tested in parallel and logs files will be written in the `end2end-tests` folder. +If you get an `Error: Timeout`, look at the logs to understand why Duniter did not launch successfully. You can also set the environment variable `DUNITER_END2END_TESTS_SPAWN_NODE_TIMEOUT` to increase the timeout for node spawn. ### Contribute to the code that runs the tests diff --git a/end2end-tests/cucumber-features/account_creation.feature b/end2end-tests/cucumber-features/account_creation.feature index e3df0d149011a0c8575eb49cc0f6c25284a0d9a6..dd39150d7d2d47d43ff041c65f0bba14cca978fa 100644 --- a/end2end-tests/cucumber-features/account_creation.feature +++ b/end2end-tests/cucumber-features/account_creation.feature @@ -1,7 +1,7 @@ Feature: Balance transfer - Scenario: Create a new account with enough founds - When alice send 5 ÄžD to dave + Scenario: Create a new account with enough funds + When alice sends 5 ÄžD to dave Then dave should have 5 ÄžD When 1 block later """ @@ -9,13 +9,13 @@ Feature: Balance transfer """ Then dave should have 2 ÄžD - Scenario: Create a new account without enough founds then retry with enough founds - When alice send 2 ÄžD to eve + Scenario: Create a new account without enough funds then retry with enough funds + When alice sends 2 ÄžD to eve Then eve should have 2 ÄžD When 1 block later """ - The blockchain should automatically destroy Evec account - because Eve not have enough founds to pay the new account tax + The blockchain should automatically destroy Eve account + because Eve does not have enough funds to pay the new account tax """ Then eve should have 0 ÄžD When alice send 5 ÄžD to eve @@ -27,7 +27,7 @@ Feature: Balance transfer Then eve should have 2 ÄžD @ignoreErrors - Scenario: Create a new account without any founds + Scenario: Create a new account without any funds Then eve should have 0 ÄžD When eve send 0 ÄžD to alice Then alice should have 10 ÄžD diff --git a/end2end-tests/tests/cucumber_tests.rs b/end2end-tests/tests/cucumber_tests.rs index a039bc2b73908db6ac9665f1069a96d7b1ba4a05..09913a11efd306b71f9059b21bd90be46c3face5 100644 --- a/end2end-tests/tests/cucumber_tests.rs +++ b/end2end-tests/tests/cucumber_tests.rs @@ -119,7 +119,7 @@ fn parse_amount(amount: u64, unit: &str) -> (u64, bool) { } } -#[given(regex = r"([a-zA-Z]+) have (\d+) (ÄžD|cÄžD|UD|mUD)")] +#[given(regex = r"([a-zA-Z]+) ha(?:ve|s) (\d+) (ÄžD|cÄžD|UD|mUD)")] async fn who_have(world: &mut DuniterWorld, who: String, amount: u64, unit: String) -> Result<()> { // Parse inputs let who = AccountKeyring::from_str(&who).expect("unknown to"); @@ -149,7 +149,7 @@ async fn n_blocks_later(world: &mut DuniterWorld, n: usize) -> Result<()> { Ok(()) } -#[when(regex = r"([a-zA-Z]+) send (\d+) (ÄžD|cÄžD|UD|mUD) to ([a-zA-Z]+)")] +#[when(regex = r"([a-zA-Z]+) sends? (\d+) (ÄžD|cÄžD|UD|mUD) to ([a-zA-Z]+)")] async fn transfer( world: &mut DuniterWorld, from: String,