mirror of
https://git.ghostchain.io/proxmio/ghost-node.git
synced 2025-12-27 11:19:57 +00:00
separate bridged imbalance and gatekeeper amount. requested by @st1nky for ghost-slow-clap
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
This commit is contained in:
@@ -656,8 +656,6 @@ fn gatekeeper_amount_changes_correctly() {
|
||||
let result = amount_in - 3 * amount_out;
|
||||
|
||||
assert_eq!(GatekeeperAmount::<Test>::get(&chain_id), 0);
|
||||
assert_eq!(BridgedImbalance::<Test>::get(),
|
||||
BridgeAdjustment::default());
|
||||
|
||||
assert_ok!(GhostNetworks::increase_gatekeeper_amount(&chain_id, &amount_in));
|
||||
assert_ok!(GhostNetworks::decrease_gatekeeper_amount(&chain_id, &amount_out));
|
||||
@@ -665,9 +663,26 @@ fn gatekeeper_amount_changes_correctly() {
|
||||
assert_ok!(GhostNetworks::decrease_gatekeeper_amount(&chain_id, &amount_out));
|
||||
|
||||
assert_eq!(GatekeeperAmount::<Test>::get(&chain_id), result);
|
||||
assert_eq!(BridgedImbalance::<Test>::get(), BridgeAdjustment {
|
||||
bridged_out: 3 * amount_out,
|
||||
bridged_in: amount_in });
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bridged_imbalance_accumulated_correctly() {
|
||||
ExtBuilder::build()
|
||||
.execute_with(|| {
|
||||
let amount_in: u128 = 420;
|
||||
let amount_out: u128 = 69;
|
||||
|
||||
let imbalance_before = BridgedImbalance::<Test>::get();
|
||||
assert_eq!(imbalance_before.bridged_in, 0);
|
||||
assert_eq!(imbalance_before.bridged_out, 0);
|
||||
|
||||
assert_ok!(GhostNetworks::accumulate_incoming_imbalance(&amount_in));
|
||||
assert_ok!(GhostNetworks::accumulate_outgoing_imbalance(&amount_out));
|
||||
|
||||
let imbalance_after = BridgedImbalance::<Test>::get();
|
||||
assert_eq!(imbalance_after.bridged_in, amount_in);
|
||||
assert_eq!(imbalance_after.bridged_out, amount_out);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -708,7 +723,7 @@ fn gatekeeper_amount_overflow_and_underflow_emits_error() {
|
||||
assert_ok!(GhostNetworks::increase_gatekeeper_amount(
|
||||
&chain_id,
|
||||
&commission,
|
||||
), (commission, commission));
|
||||
), commission);
|
||||
assert_err!(GhostNetworks::increase_gatekeeper_amount(
|
||||
&chain_id,
|
||||
&commission,
|
||||
@@ -717,16 +732,33 @@ fn gatekeeper_amount_overflow_and_underflow_emits_error() {
|
||||
assert_ok!(GhostNetworks::decrease_gatekeeper_amount(
|
||||
&chain_id,
|
||||
&commission,
|
||||
), (0, commission));
|
||||
), 0);
|
||||
assert_err!(GhostNetworks::decrease_gatekeeper_amount(
|
||||
&chain_id,
|
||||
&commission,
|
||||
), ());
|
||||
assert_eq!(GatekeeperAmount::<Test>::get(&chain_id), 0);
|
||||
assert_eq!(BridgedImbalance::<Test>::get(), BridgeAdjustment {
|
||||
bridged_out: commission,
|
||||
bridged_in: commission,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bridged_imbalance_overflow_emits_error() {
|
||||
ExtBuilder::build()
|
||||
.execute_with(|| {
|
||||
let chain_id: u32 = 1;
|
||||
let amount: u128 = u128::MAX - 69;
|
||||
assert_eq!(GatekeeperAmount::<Test>::get(&chain_id), 0);
|
||||
assert_ok!(GhostNetworks::accumulate_outgoing_imbalance(&amount), amount);
|
||||
assert_ok!(GhostNetworks::accumulate_incoming_imbalance(&amount), amount);
|
||||
|
||||
assert_err!(GhostNetworks::accumulate_outgoing_imbalance(&amount), ());
|
||||
assert_err!(GhostNetworks::accumulate_incoming_imbalance(&amount), ());
|
||||
assert_err!(GhostNetworks::accumulate_outgoing_imbalance(&u128::MAX), ());
|
||||
assert_err!(GhostNetworks::accumulate_incoming_imbalance(&u128::MAX), ());
|
||||
|
||||
let bridged_imbalance = BridgedImbalance::<Test>::get();
|
||||
assert_eq!(bridged_imbalance.bridged_out, amount);
|
||||
assert_eq!(bridged_imbalance.bridged_in, amount);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -737,18 +769,16 @@ fn bridged_amount_overflow_and_underflow_emits_error() {
|
||||
let chain_id_first: u32 = 1;
|
||||
let chain_id_second: u32 = 2;
|
||||
let commission: u128 = u128::MAX - 69;
|
||||
assert_eq!(BridgedImbalance::<Test>::get(), BridgeAdjustment {
|
||||
bridged_out: 0,
|
||||
bridged_in: 0,
|
||||
});
|
||||
|
||||
assert_ok!(GhostNetworks::increase_gatekeeper_amount(
|
||||
&chain_id_first,
|
||||
&commission,
|
||||
), (commission, commission));
|
||||
assert_err!(GhostNetworks::increase_gatekeeper_amount(
|
||||
), commission);
|
||||
assert_ok!(GhostNetworks::increase_gatekeeper_amount(
|
||||
&chain_id_second,
|
||||
&commission,
|
||||
), ());
|
||||
), commission);
|
||||
|
||||
assert_err!(GhostNetworks::increase_gatekeeper_amount(
|
||||
&chain_id_first,
|
||||
&u128::MAX,
|
||||
@@ -757,12 +787,18 @@ fn bridged_amount_overflow_and_underflow_emits_error() {
|
||||
&chain_id_first,
|
||||
&commission,
|
||||
), ());
|
||||
assert_eq!(GatekeeperAmount::<Test>::get(&chain_id_first), commission);
|
||||
assert_eq!(GatekeeperAmount::<Test>::get(&chain_id_second), 0);
|
||||
|
||||
assert_err!(GhostNetworks::decrease_gatekeeper_amount(
|
||||
&chain_id_second,
|
||||
&commission,
|
||||
&u128::MAX,
|
||||
), ());
|
||||
assert_ok!(GhostNetworks::decrease_gatekeeper_amount(
|
||||
&chain_id_second,
|
||||
&commission,
|
||||
), 0);
|
||||
|
||||
assert_eq!(GatekeeperAmount::<Test>::get(&chain_id_first), commission);
|
||||
assert_eq!(GatekeeperAmount::<Test>::get(&chain_id_second), 0);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -791,7 +827,6 @@ fn accumulated_commission_could_be_nullified() {
|
||||
fn bridged_inlation_reward_works() {
|
||||
ExtBuilder::build()
|
||||
.execute_with(|| {
|
||||
let chain_id: u32 = 1;
|
||||
let amount: u128 = 1337 * 1_000_000_000;
|
||||
let commission: u128 = amount / 100; // 1% commission
|
||||
let total_staked_ideal: u128 = 69;
|
||||
@@ -832,7 +867,7 @@ fn bridged_inlation_reward_works() {
|
||||
1, total_issuance * 1_000_000_000_000_000_000_000_000, 0), (0, 0));
|
||||
|
||||
assert_ok!(GhostNetworks::accumulate_commission(&commission));
|
||||
assert_ok!(GhostNetworks::increase_gatekeeper_amount(&chain_id, &amount));
|
||||
assert_ok!(GhostNetworks::accumulate_incoming_imbalance(&amount));
|
||||
|
||||
assert_eq!(BridgedInflationCurve::<RewardCurve, Test>::era_payout(
|
||||
total_staked_ideal * 1_000,
|
||||
@@ -917,14 +952,13 @@ fn bridged_inlation_reward_works() {
|
||||
fn bridged_inflation_era_payout_triggers_need_of_nullification() {
|
||||
ExtBuilder::build()
|
||||
.execute_with(|| {
|
||||
let chain_id: u32 = 1;
|
||||
let amount: u128 = 1337 * 1_000_000_000;
|
||||
let commission: u128 = amount / 100; // 1% commission
|
||||
let total_staked_ideal: u128 = 69;
|
||||
let total_issuance: u128 = 100;
|
||||
|
||||
assert_ok!(GhostNetworks::accumulate_commission(&commission));
|
||||
assert_ok!(GhostNetworks::increase_gatekeeper_amount(&chain_id, &amount));
|
||||
assert_ok!(GhostNetworks::accumulate_incoming_imbalance(&amount));
|
||||
assert_eq!(NullifyNeeded::<Test>::get(), false);
|
||||
assert_eq!(BridgedInflationCurve::<RewardCurve, Test>::era_payout(
|
||||
total_staked_ideal * 1_000,
|
||||
|
||||
Reference in New Issue
Block a user