Skip to content

Commit c612681

Browse files
bertllllBert
andauthored
GH-671: base for PaymentAdjuster-checked payables (#233)
* GH-671: started with the reconstruction slowly; however, found weakness in an older test and designed a test tool, eventually bracing it up * GH-671: I stopped before I create another branch to fix some discrepancy in the test tree (adding tests + I wanna move my new test utility there too) * testing_area_fixes: one test counted on a premise that could not be matched with the test tooling we had; I created a new kind and fixed the test * GH-673: making three tests into more stronger ones; these will embrace also certain use of self.handle_scan() * GH-673: first phase of smooth use of stop conditions for recorder * GH-673: first moment hitting wall hard * GH-673: StopConditions considered implemented; might change some details * GH-673: added some tests... of test code... * GH-673: finishing tests and adding required PartialEq and Eq traits to some messages * GH-673: most of things from the review addressed; preparing for reducing the Single cond, experimenting * GH-673: review answered * GH-673: adding notify later 'facelift' * GH-673: simplifying default impl for NotifyLaterHandler * GH-671: merge from GH-673 finished * GH-671: interim commit * GH-671: blockchain bridge with implemented check for balances for payables * GH-671: enclosed the circle; functionality stable again; fully tested; next some reviewing * GH-671: last changes begun with auto review * GH-671: formatting * GH-671: removing www.failingFailing.com as non-http anymore for www.neverssl.com * GH-671: formatting * GH-671: first part of addressing the review * GH-671: problematic parts that required discussion resolved now * GH-671: refactoring my older code in setup_reporter.rs so that it makes more sense * GH-671: weis of gwei constant renamed * GH-671: making function clearer by using better names for variables etc * GH-671: added a comment to explain more about the fn * GH-671: little mistake in multinode tests --------- Co-authored-by: Bert <[email protected]>
1 parent 762dbe4 commit c612681

File tree

15 files changed

+626
-214
lines changed

15 files changed

+626
-214
lines changed

masq/src/commands/financials_command/parsing_and_value_dressing.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
pub(in crate::commands::financials_command) mod restricted {
44
use crate::commands::financials_command::data_structures::restricted::UserOriginalTypingOfRanges;
5-
use masq_lib::constants::{MASQ_TOTAL_SUPPLY, WEIS_OF_GWEI};
5+
use masq_lib::constants::{MASQ_TOTAL_SUPPLY, WEIS_IN_GWEI};
66
use masq_lib::utils::ExpectValue;
77
use num::CheckedMul;
88
use regex::{Captures, Regex};
@@ -15,8 +15,8 @@ pub(in crate::commands::financials_command) mod restricted {
1515

1616
pub fn convert_masq_from_gwei_and_dress_well(balance_gwei: i64) -> String {
1717
const MASK_FOR_NON_SIGNIFICANT_DIGITS: i64 = 10_000_000;
18-
let balance_masq_int = (balance_gwei / WEIS_OF_GWEI as i64).abs();
19-
let balance_masq_frac = (balance_gwei % WEIS_OF_GWEI as i64).abs();
18+
let balance_masq_int = (balance_gwei / WEIS_IN_GWEI as i64).abs();
19+
let balance_masq_frac = (balance_gwei % WEIS_IN_GWEI as i64).abs();
2020
let balance_masq_frac_trunc = balance_masq_frac / MASK_FOR_NON_SIGNIFICANT_DIGITS;
2121
match (
2222
(balance_masq_int == 0) && (balance_masq_frac_trunc == 0),
@@ -310,7 +310,7 @@ mod tests {
310310
process_optionally_fractional_number,
311311
};
312312
use crate::commands::financials_command::test_utils::transpose_inputs_to_nested_tuples;
313-
use masq_lib::constants::{MASQ_TOTAL_SUPPLY, WEIS_OF_GWEI};
313+
use masq_lib::constants::{MASQ_TOTAL_SUPPLY, WEIS_IN_GWEI};
314314
use regex::Regex;
315315

316316
#[test]
@@ -482,7 +482,7 @@ mod tests {
482482

483483
#[test]
484484
fn i64_interpretation_capabilities_are_good_enough_for_masq_total_supply_in_gwei() {
485-
let _: i64 = (MASQ_TOTAL_SUPPLY * WEIS_OF_GWEI as u64)
485+
let _: i64 = (MASQ_TOTAL_SUPPLY * WEIS_IN_GWEI as u64)
486486
.try_into()
487487
.unwrap();
488488
}

masq_lib/src/constants.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub const DEFAULT_GAS_PRICE: u64 = 1; //TODO ?? Really
2020

2121
pub const WALLET_ADDRESS_LENGTH: usize = 42;
2222
pub const MASQ_TOTAL_SUPPLY: u64 = 37_500_000;
23-
pub const WEIS_OF_GWEI: i128 = 1_000_000_000;
23+
pub const WEIS_IN_GWEI: i128 = 1_000_000_000;
2424

2525
pub const ETH_MAINNET_CONTRACT_CREATION_BLOCK: u64 = 11_170_708;
2626
pub const ROPSTEN_TESTNET_CONTRACT_CREATION_BLOCK: u64 = 8_688_171;
@@ -102,7 +102,7 @@ mod tests {
102102
assert_eq!(DEFAULT_GAS_PRICE, 1);
103103
assert_eq!(WALLET_ADDRESS_LENGTH, 42);
104104
assert_eq!(MASQ_TOTAL_SUPPLY, 37_500_000);
105-
assert_eq!(WEIS_OF_GWEI, 1_000_000_000);
105+
assert_eq!(WEIS_IN_GWEI, 1_000_000_000);
106106
assert_eq!(ETH_MAINNET_CONTRACT_CREATION_BLOCK, 11_170_708);
107107
assert_eq!(ROPSTEN_TESTNET_CONTRACT_CREATION_BLOCK, 8_688_171);
108108
assert_eq!(MULTINODE_TESTNET_CONTRACT_CREATION_BLOCK, 0);

multinode_integration_tests/tests/verify_bill_payment.rs

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
use bip39::{Language, Mnemonic, Seed};
33
use futures::Future;
44
use masq_lib::blockchains::chains::Chain;
5-
use masq_lib::constants::WEIS_OF_GWEI;
5+
use masq_lib::constants::WEIS_IN_GWEI;
66
use masq_lib::utils::{derivation_path, NeighborhoodModeLight};
77
use multinode_integration_tests_lib::blockchain::BlockchainServer;
88
use multinode_integration_tests_lib::masq_node::{MASQNode, MASQNodeUtils};
@@ -96,7 +96,7 @@ fn verify_bill_payment() {
9696
derivation_path(0, 3),
9797
);
9898

99-
let amount = 10 * payment_thresholds.permanent_debt_allowed_gwei as u128 * WEIS_OF_GWEI as u128;
99+
let amount = 10 * payment_thresholds.permanent_debt_allowed_gwei as u128 * WEIS_IN_GWEI as u128;
100100

101101
let project_root = MASQNodeUtils::find_project_root();
102102
let (consuming_node_name, consuming_node_index) = cluster.prepare_real_node(&consuming_config);
@@ -323,20 +323,26 @@ fn assert_balances(
323323
expected_eth_balance: &str,
324324
expected_token_balance: &str,
325325
) {
326-
if let (Ok(eth_balance), Ok(token_balance)) = blockchain_interface.get_balances(&wallet) {
327-
assert_eq!(
328-
format!("{}", eth_balance),
329-
String::from(expected_eth_balance),
330-
"EthBalance"
331-
);
332-
assert_eq!(
333-
token_balance,
334-
web3::types::U256::from_dec_str(expected_token_balance).unwrap(),
335-
"TokenBalance"
336-
);
337-
} else {
338-
assert!(false, "Failed to retrieve balances {}", wallet);
339-
}
326+
let eth_balance = blockchain_interface
327+
.get_gas_balance(&wallet)
328+
.unwrap_or_else(|_| panic!("Failed to retrieve gas balance for {}", wallet));
329+
assert_eq!(
330+
format!("{}", eth_balance),
331+
String::from(expected_eth_balance),
332+
"Actual EthBalance {} doesn't much with expected {}",
333+
eth_balance,
334+
expected_eth_balance
335+
);
336+
let token_balance = blockchain_interface
337+
.get_token_balance(&wallet)
338+
.unwrap_or_else(|_| panic!("Failed to retrieve token balance for {}", wallet));
339+
assert_eq!(
340+
token_balance,
341+
web3::types::U256::from_dec_str(expected_token_balance).unwrap(),
342+
"Actual TokenBalance {} doesn't match with expected {}",
343+
token_balance,
344+
expected_token_balance
345+
);
340346
}
341347

342348
fn deploy_smart_contract(wallet: &Wallet, web3: &Web3<Http>, chain: Chain) -> Address {

node/src/accountant/dao_utils.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::database::db_initializer::{
99
connection_or_panic, DbInitializationConfig, DbInitializerReal,
1010
};
1111
use crate::sub_lib::accountant::PaymentThresholds;
12-
use masq_lib::constants::WEIS_OF_GWEI;
12+
use masq_lib::constants::WEIS_IN_GWEI;
1313
use masq_lib::messages::{
1414
RangeQuery, TopRecordsConfig, TopRecordsOrdering, UiPayableAccount, UiReceivableAccount,
1515
};
@@ -211,7 +211,7 @@ impl<N: Copy + Display> CustomQuery<N> {
211211
.into_iter()
212212
.zip([min_amount, max_amount].into_iter())
213213
.flat_map(|(param_names, gwei_num)| {
214-
let wei_num = i128::from(gwei_num) * WEIS_OF_GWEI;
214+
let wei_num = i128::from(gwei_num) * WEIS_IN_GWEI;
215215
let big_int_divided = BigIntDivider::deconstruct(wei_num);
216216
Self::balance_constraint_as_integer_pair(param_names, big_int_divided)
217217
})
@@ -260,7 +260,7 @@ pub fn remap_payable_accounts(accounts: Vec<PayableAccount>) -> Vec<UiPayableAcc
260260
wallet: account.wallet.to_string(),
261261
age_s: to_age(account.last_paid_timestamp),
262262
balance_gwei: {
263-
let gwei = (account.balance_wei / (WEIS_OF_GWEI as u128)) as u64;
263+
let gwei = (account.balance_wei / (WEIS_IN_GWEI as u128)) as u64;
264264
if gwei > 0 {
265265
gwei
266266
} else {
@@ -285,7 +285,7 @@ pub fn remap_receivable_accounts(accounts: Vec<ReceivableAccount>) -> Vec<UiRece
285285
wallet: account.wallet.to_string(),
286286
age_s: to_age(account.last_received_timestamp),
287287
balance_gwei:{
288-
let gwei = (account.balance_wei / (WEIS_OF_GWEI as i128)) as i64;
288+
let gwei = (account.balance_wei / (WEIS_IN_GWEI as i128)) as i64;
289289
if gwei != 0 {gwei} else {panic!("Broken code: ReceivableAccount with balance \
290290
between {} and 0 gwei passed through db query constraints; wallet: {}, balance: {}",
291291
if account.balance_wei.is_positive() {"1"}else{"-1"},
@@ -759,7 +759,7 @@ mod tests {
759759
maturity_threshold_sec: 20,
760760
payment_grace_period_sec: 33,
761761
permanent_debt_allowed_gwei: 1,
762-
debt_threshold_gwei: MASQ_TOTAL_SUPPLY * WEIS_OF_GWEI as u64,
762+
debt_threshold_gwei: MASQ_TOTAL_SUPPLY * WEIS_IN_GWEI as u64,
763763
threshold_interval_sec: 1,
764764
unban_below_gwei: 0,
765765
};
@@ -775,7 +775,7 @@ mod tests {
775775
);
776776
slope * (payment_thresholds.maturity_threshold_sec + 1) as i128 + y_interception
777777
};
778-
assert_eq!(check, WEIS_OF_GWEI)
778+
assert_eq!(check, WEIS_IN_GWEI)
779779
}
780780

781781
#[test]

0 commit comments

Comments
 (0)