-
Notifications
You must be signed in to change notification settings - Fork 25
Add transactions related scenarios #790
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
7797a64
added ledger status validation after transaction scenario
nicopado dce688f
removed useless validation
nicopado f76ab98
added scenario for invalid transaction
nicopado 179fadb
Merge branch 'master' into transactions_scenarios
nicopado 6427f8b
Merge branch 'master' into transactions_scenarios
nicopado d74dea5
added scenarios for correct fees when casting & tallying votes
nicopado 55a5f9c
Merge branch 'master' into transactions_scenarios
nicopado 4ec63c4
Merge branch 'master' into transactions_scenarios
nicopado 6de7793
Merge branch 'master' into transactions_scenarios
nicopado d32350e
Merge branch 'master' into transactions_scenarios
nicopado 8061288
partial PR correction
nicopado e853e8b
Merge branch 'master' into transactions_scenarios
nicopado 639ab20
PR corrections
nicopado eb136c0
Merge branch 'master' into transactions_scenarios
nicopado 49648d5
deleted comment
nicopado 039c14b
PR corrections
nicopado File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
use quickcheck::{Arbitrary, Gen}; | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct Random1to10(pub u64); | ||
|
||
impl Arbitrary for Random1to10 { | ||
fn arbitrary<G: Gen>(g: &mut G) -> Self { | ||
Self(u64::arbitrary(g) % 10 + 1) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
use crate::{ | ||
fee::{FeeAlgorithm, LinearFee}, | ||
testing::{ | ||
arbitrary::Random1to10, | ||
ledger::ConfigBuilder, | ||
scenario::{prepare_scenario, wallet}, | ||
verifiers::LedgerStateVerifier, | ||
}, | ||
value::Value, | ||
}; | ||
|
||
use quickcheck_macros::quickcheck; | ||
|
||
const BASIC_BALANCE: u64 = 1000; | ||
|
||
#[quickcheck] | ||
pub fn validate_ledger_state_after_transaction(amount: Random1to10, linear_fee: LinearFee) { | ||
let total_fees = linear_fee.calculate(None, 1, 1); | ||
let valid_transaction_amount = total_fees.0 + amount.0; | ||
let alice_initial_balance = BASIC_BALANCE + valid_transaction_amount + total_fees.0; | ||
let bob_initial_balance = BASIC_BALANCE; | ||
|
||
let (mut ledger, controller) = prepare_scenario() | ||
.with_config(ConfigBuilder::new().with_fee(linear_fee)) | ||
.with_initials(vec![ | ||
wallet("Alice").with(alice_initial_balance), | ||
wallet("Bob").with(bob_initial_balance), | ||
]) | ||
.build() | ||
.unwrap(); | ||
|
||
let mut alice = controller.wallet("Alice").unwrap(); | ||
let bob = controller.wallet("Bob").unwrap(); | ||
|
||
controller | ||
.transfer_funds( | ||
&alice, | ||
&bob, | ||
&mut ledger, | ||
valid_transaction_amount + total_fees.0, | ||
) | ||
.unwrap(); | ||
alice.confirm_transaction(); | ||
|
||
LedgerStateVerifier::new(ledger.into()).address_has_expected_balance( | ||
bob.as_account_data(), | ||
Value(bob_initial_balance + valid_transaction_amount), | ||
); | ||
} | ||
|
||
#[quickcheck] | ||
pub fn validate_ledger_state_after_invalid_transaction(amount: Random1to10, linear_fee: LinearFee) { | ||
let total_fees = linear_fee.calculate(None, 1, 1); | ||
let valid_transaction_amount = total_fees.0 + amount.0; | ||
let alice_initial_balance = amount.0 + valid_transaction_amount + total_fees.0; | ||
let bob_initial_balance = BASIC_BALANCE; | ||
|
||
let (mut ledger, controller) = prepare_scenario() | ||
.with_config(ConfigBuilder::new().with_fee(linear_fee)) | ||
.with_initials(vec![ | ||
wallet("Alice").with(alice_initial_balance), | ||
wallet("Bob").with(bob_initial_balance), | ||
]) | ||
.build() | ||
.unwrap(); | ||
|
||
let mut alice = controller.wallet("Alice").unwrap(); | ||
let bob = controller.wallet("Bob").unwrap(); | ||
|
||
controller | ||
.transfer_funds( | ||
&alice, | ||
&bob, | ||
&mut ledger, | ||
valid_transaction_amount + total_fees.0, | ||
) | ||
.unwrap(); | ||
|
||
alice.confirm_transaction(); | ||
|
||
// this second transaction should fail as alice does not have the balance to cover for it | ||
let _ = controller.transfer_funds( | ||
&alice, | ||
&bob, | ||
&mut ledger, | ||
valid_transaction_amount + total_fees.0, | ||
); | ||
|
||
alice.confirm_transaction(); | ||
|
||
LedgerStateVerifier::new(ledger.into()).address_has_expected_balance( | ||
alice.as_account_data(), | ||
Value(alice_initial_balance - (valid_transaction_amount + total_fees.0)), | ||
); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think we got
TestGen::token_name()
static method for this purposeThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not working for this purpose as TestGen::token_name() returns an incompatible type of token.
As discussed I created a ticket to track this desiderata: https://input-output.atlassian.net/browse/NPG-1217