From 4eb18ef2ac95991450d533301a5c5e49ec5276f4 Mon Sep 17 00:00:00 2001 From: joe petrowski <25483142+joepetrowski@users.noreply.github.com> Date: Wed, 15 May 2019 18:13:37 +0200 Subject: [PATCH] add quantization test for on_dilution (#2595) --- substrate/srml/treasury/src/lib.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/substrate/srml/treasury/src/lib.rs b/substrate/srml/treasury/src/lib.rs index 0afb8ba5e0..39253ac4d9 100644 --- a/substrate/srml/treasury/src/lib.rs +++ b/substrate/srml/treasury/src/lib.rs @@ -507,6 +507,35 @@ mod tests { }); } + #[test] + // Note: This test demonstrates that `on_dilution` does not increase the pot with good resolution + // with large amounts of the network staked. https://github.com/paritytech/substrate/issues/2579 + // A fix to 2579 should include a change of this test. + fn on_dilution_quantization_effects() { + with_externalities(&mut new_test_ext(), || { + // minted = 1% of total issuance for all cases + let _ = Treasury::set_pot(0); + assert_eq!(Balances::total_issuance(), 200); + + Treasury::on_dilution(2, 66); // portion = 33% of total issuance + assert_eq!(Treasury::pot(), 4); // should increase by 4 (200 - 66) / 66 * 2 + + Treasury::on_dilution(2, 67); // portion = 33+eps% of total issuance + assert_eq!(Treasury::pot(), 6); // should increase by 2 (200 - 67) / 67 * 2 + + Treasury::on_dilution(2, 100); // portion = 50% of total issuance + assert_eq!(Treasury::pot(), 8); // should increase by 2 (200 - 100) / 100 * 2 + + // If any more than 50% of the network is staked (i.e. (2 * portion) > total_issuance) + // then the pot will not increase. + Treasury::on_dilution(2, 101); // portion = 50+eps% of total issuance + assert_eq!(Treasury::pot(), 8); // should increase by 0 (200 - 101) / 101 * 2 + + Treasury::on_dilution(2, 134); // portion = 67% of total issuance + assert_eq!(Treasury::pot(), 8); // should increase by 0 (200 - 134) / 134 * 2 + }); + } + #[test] fn pot_underflow_should_not_diminish() { with_externalities(&mut new_test_ext(), || {