From 03d64046d1480d4a693bae22022a4e41ea52baa0 Mon Sep 17 00:00:00 2001 From: librelois <c@elo.tf> Date: Thu, 13 Jan 2022 00:21:02 +0100 Subject: [PATCH] tests: add test scenario monetary_mass --- integration-tests/README.md | 11 +++++-- .../features/monetary_mass.feature | 10 ++++++ integration-tests/tests/common/mod.rs | 4 +-- integration-tests/tests/cucumber_tests.rs | 31 +++++++++++++++---- 4 files changed, 46 insertions(+), 10 deletions(-) create mode 100644 integration-tests/features/monetary_mass.feature diff --git a/integration-tests/README.md b/integration-tests/README.md index b16954b05..81f37678f 100644 --- a/integration-tests/README.md +++ b/integration-tests/README.md @@ -2,7 +2,7 @@ ## cucumber functionnal tests -We use [cucumber] to be able to describe test cases in human language. +We use [cucumber] to be able to describe test scenarios in human language. Cucumber is a specification for running tests in a [BDD] (behavior-driven development) style workflow. @@ -22,7 +22,7 @@ Feature: Balance transfer ### create a new functional test -To create a new test case, simply create a new file with a name of your choice in the `/features` +To create a new test scenario, simply create a new file with a name of your choice in the `/features` folder and give it the extension `.feature`. Read in the sections below which users are available and which operations you can write. @@ -92,6 +92,13 @@ List of possible actions: Example: `Current UD amount should be 10.00 ÄžD` + +- Check the monetary mass + + Usage: `Monetary mass should be {amount}.{cents} ÄžD` + + Example: `Monetary mass should be 30.00 ÄžD` + ### Contribute to the code that runs the tests Cucumber is not magic, we have to write code that interprets the Gherkin text and performs the right diff --git a/integration-tests/features/monetary_mass.feature b/integration-tests/features/monetary_mass.feature new file mode 100644 index 000000000..674f34398 --- /dev/null +++ b/integration-tests/features/monetary_mass.feature @@ -0,0 +1,10 @@ +Feature: Balance transfer + + Scenario: After 10 blocks, the monetary mass should be 30 ÄžD + Then Monetary mass should be 0.00 ÄžD + Then Current UD amount should be 10.00 ÄžD + When 10 blocks later + Then Monetary mass should be 30.00 ÄžD + When 10 blocks later + Then Monetary mass should be 60.00 ÄžD + Then Current UD amount should be 10.00 ÄžD diff --git a/integration-tests/tests/common/mod.rs b/integration-tests/tests/common/mod.rs index 09a31a929..ebb179f90 100644 --- a/integration-tests/tests/common/mod.rs +++ b/integration-tests/tests/common/mod.rs @@ -82,7 +82,7 @@ pub async fn spawn_node() -> (Api, Client, Process) { (api, client, process) } -/*pub async fn create_empty_block(client: &Client) -> Result<(), subxt::Error> { +pub async fn create_empty_block(client: &Client) -> Result<()> { // Create an empty block let _: Value = client .rpc() @@ -94,7 +94,7 @@ pub async fn spawn_node() -> (Api, Client, Process) { .await?; Ok(()) -}*/ +} pub async fn create_block_with_extrinsic( client: &Client, diff --git a/integration-tests/tests/cucumber_tests.rs b/integration-tests/tests/cucumber_tests.rs index cd327e76e..ea229bbd6 100644 --- a/integration-tests/tests/cucumber_tests.rs +++ b/integration-tests/tests/cucumber_tests.rs @@ -83,6 +83,14 @@ async fn who_have(world: &mut DuniterWorld, who: String, amount: u64, unit: Stri Ok(()) } +#[when(regex = r"(\d+) blocks? later")] +async fn n_blocks_later(world: &mut DuniterWorld, n: usize) -> Result<()> { + for _ in 0..n { + common::create_empty_block(&world.client).await?; + } + Ok(()) +} + #[when(regex = r"([a-zA-Z]+) send (\d+) (ÄžD|cÄžD|UD|mUD) to ([a-zA-Z]+)")] async fn transfer( world: &mut DuniterWorld, @@ -125,22 +133,33 @@ async fn should_have(world: &mut DuniterWorld, who: String, amount: u64) -> Resu Ok(()) } -#[then(regex = r"current UD amount should be (\d+).(\d+)")] +#[then(regex = r"Current UD amount should be (\d+).(\d+)")] async fn current_ud_amount_should_be( world: &mut DuniterWorld, amount: u64, cents: u64, ) -> Result<()> { - // Parse inputs - let expected_amount = amount + (cents * 100); - - let current_ud_amount = world + let expected = (amount * 100) + cents; + let actual = world .api .storage() .universal_dividend() .current_ud_storage(None) .await?; - assert_eq!(current_ud_amount, expected_amount); + assert_eq!(actual, expected); + Ok(()) +} + +#[then(regex = r"Monetary mass should be (\d+).(\d+)")] +async fn monetary_mass_should_be(world: &mut DuniterWorld, amount: u64, cents: u64) -> Result<()> { + let expected = (amount * 100) + cents; + let actual = world + .api + .storage() + .universal_dividend() + .monetary_mass_storage(None) + .await?; + assert_eq!(actual, expected); Ok(()) } -- GitLab