Skip to content
Snippets Groups Projects
Commit 03d64046 authored by Éloïs's avatar Éloïs
Browse files

tests: add test scenario monetary_mass

parent 912f5b55
No related branches found
No related tags found
1 merge request!14tests: add test scenario monetary_mass
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
## cucumber functionnal tests ## 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 Cucumber is a specification for running tests in a [BDD] (behavior-driven development) style
workflow. workflow.
...@@ -22,7 +22,7 @@ Feature: Balance transfer ...@@ -22,7 +22,7 @@ Feature: Balance transfer
### create a new functional test ### 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`. folder and give it the extension `.feature`.
Read in the sections below which users are available and which operations you can write. Read in the sections below which users are available and which operations you can write.
...@@ -92,6 +92,13 @@ List of possible actions: ...@@ -92,6 +92,13 @@ List of possible actions:
Example: `Current UD amount should be 10.00 ĞD` 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 ### 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 Cucumber is not magic, we have to write code that interprets the Gherkin text and performs the right
......
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
...@@ -82,7 +82,7 @@ pub async fn spawn_node() -> (Api, Client, Process) { ...@@ -82,7 +82,7 @@ pub async fn spawn_node() -> (Api, Client, Process) {
(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 // Create an empty block
let _: Value = client let _: Value = client
.rpc() .rpc()
...@@ -94,7 +94,7 @@ pub async fn spawn_node() -> (Api, Client, Process) { ...@@ -94,7 +94,7 @@ pub async fn spawn_node() -> (Api, Client, Process) {
.await?; .await?;
Ok(()) Ok(())
}*/ }
pub async fn create_block_with_extrinsic( pub async fn create_block_with_extrinsic(
client: &Client, client: &Client,
......
...@@ -83,6 +83,14 @@ async fn who_have(world: &mut DuniterWorld, who: String, amount: u64, unit: Stri ...@@ -83,6 +83,14 @@ async fn who_have(world: &mut DuniterWorld, who: String, amount: u64, unit: Stri
Ok(()) 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]+)")] #[when(regex = r"([a-zA-Z]+) send (\d+) (ĞD|cĞD|UD|mUD) to ([a-zA-Z]+)")]
async fn transfer( async fn transfer(
world: &mut DuniterWorld, world: &mut DuniterWorld,
...@@ -125,22 +133,33 @@ async fn should_have(world: &mut DuniterWorld, who: String, amount: u64) -> Resu ...@@ -125,22 +133,33 @@ async fn should_have(world: &mut DuniterWorld, who: String, amount: u64) -> Resu
Ok(()) 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( async fn current_ud_amount_should_be(
world: &mut DuniterWorld, world: &mut DuniterWorld,
amount: u64, amount: u64,
cents: u64, cents: u64,
) -> Result<()> { ) -> Result<()> {
// Parse inputs let expected = (amount * 100) + cents;
let expected_amount = amount + (cents * 100); let actual = world
let current_ud_amount = world
.api .api
.storage() .storage()
.universal_dividend() .universal_dividend()
.current_ud_storage(None) .current_ud_storage(None)
.await?; .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(()) Ok(())
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment