Skip to content

Commit

Permalink
update test to include rewards distribution
Browse files Browse the repository at this point in the history
  • Loading branch information
Maciej Wójcik committed Mar 6, 2024
1 parent 2317c21 commit 2ce7d6c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::{collections::BTreeSet, iter::FromIterator};
use std::collections::BTreeMap;

use assert_matches::assert_matches;
use num_traits::{One, Zero};
Expand Down Expand Up @@ -31,13 +32,15 @@ use casper_types::{
self,
auction::{
self, BidsExt, DelegationRate, EraValidators, Error as AuctionError, UnbondingPurses,
ValidatorWeights, ARG_AMOUNT, ARG_DELEGATION_RATE, ARG_DELEGATOR, ARG_NEW_PUBLIC_KEY,
ARG_NEW_VALIDATOR, ARG_PUBLIC_KEY, ARG_VALIDATOR, ERA_ID_KEY, INITIAL_ERA_ID,
ValidatorWeights, ARG_AMOUNT, ARG_DELEGATION_RATE, ARG_DELEGATOR, ARG_ENTRY_POINT,
ARG_NEW_PUBLIC_KEY, ARG_NEW_VALIDATOR, ARG_PUBLIC_KEY, ARG_VALIDATOR, ERA_ID_KEY,
INITIAL_ERA_ID, METHOD_DISTRIBUTE,
},
},
EntityAddr, EraId, GenesisAccount, GenesisConfigBuilder, GenesisValidator, Key, Motes,
ProtocolVersion, PublicKey, SecretKey, U256, U512,
};
use casper_types::system::auction::ARG_REWARDS_MAP;

const ARG_TARGET: &str = "target";

Expand Down Expand Up @@ -4632,4 +4635,21 @@ fn should_change_validator_bid_public_key() {
.delegator_by_public_keys(&NON_FOUNDER_VALIDATOR_2_PK, &BID_ACCOUNT_2_PK)
.expect("should have account2 delegation");
assert_eq!(delegator.staked_amount(), U512::from(DELEGATE_AMOUNT_2));

// distribute rewards
let total_payout = builder.base_round_reward(None);
let mut rewards = BTreeMap::new();
rewards.insert(NON_FOUNDER_VALIDATOR_1_PK.clone(), total_payout);
let distribute_request = ExecuteRequestBuilder::contract_call_by_hash(
*SYSTEM_ADDR,
builder.get_auction_contract_hash(),
METHOD_DISTRIBUTE,
runtime_args! {
ARG_ENTRY_POINT => METHOD_DISTRIBUTE,
ARG_REWARDS_MAP => rewards
},
)
.build();

builder.exec(distribute_request).commit().expect_success();
}
2 changes: 2 additions & 0 deletions types/src/system/auction/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ pub const ARG_ERA_END_TIMESTAMP_MILLIS: &str = "era_end_timestamp_millis";
pub const ARG_EVICTED_VALIDATORS: &str = "evicted_validators";
/// Named constant for `rewards_map`;
pub const ARG_REWARDS_MAP: &str = "rewards_map";
/// Named constant for `entry_point`;
pub const ARG_ENTRY_POINT: &str = "entry_point";

/// Named constant for method `get_era_validators`.
pub const METHOD_GET_ERA_VALIDATORS: &str = "get_era_validators";
Expand Down

0 comments on commit 2ce7d6c

Please sign in to comment.