Skip to content

Commit 057cf21

Browse files
Merge pull request #5394 from darthsiroftardis/tally-delegator-stake
[BUGFIX] Tally delegator stake at genesis
2 parents 6655545 + c98853c commit 057cf21

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

execution_engine_testing/tests/src/test/system_contracts/genesis.rs

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ const ACCOUNT_2_BONDED_AMOUNT: u64 = 2_000_000;
2020
const ACCOUNT_1_BALANCE: u64 = 1_000_000_000;
2121
const ACCOUNT_2_BALANCE: u64 = 2_000_000_000;
2222

23+
const ACCOUNT_3_BONDED_AMOUNT: u64 = 3_000_000;
24+
25+
const ACCOUNT_3_BALANCE: u64 = 3_000_000_000;
26+
2327
static ACCOUNT_1_PUBLIC_KEY: Lazy<PublicKey> = Lazy::new(|| {
2428
let secret_key = SecretKey::ed25519_from_bytes([42; SecretKey::ED25519_LENGTH]).unwrap();
2529
PublicKey::from(&secret_key)
@@ -31,6 +35,11 @@ static ACCOUNT_2_PUBLIC_KEY: Lazy<PublicKey> = Lazy::new(|| {
3135
});
3236
static ACCOUNT_2_ADDR: Lazy<AccountHash> = Lazy::new(|| AccountHash::from(&*ACCOUNT_2_PUBLIC_KEY));
3337

38+
static ACCOUNT_3_PUBLIC_KEY: Lazy<PublicKey> = Lazy::new(|| {
39+
let secret_key = SecretKey::ed25519_from_bytes([45; SecretKey::ED25519_LENGTH]).unwrap();
40+
PublicKey::from(&secret_key)
41+
});
42+
3443
static GENESIS_CUSTOM_ACCOUNTS: Lazy<Vec<GenesisAccount>> = Lazy::new(|| {
3544
let account_1 = {
3645
let account_1_balance = Motes::new(ACCOUNT_1_BALANCE);
@@ -56,7 +65,18 @@ static GENESIS_CUSTOM_ACCOUNTS: Lazy<Vec<GenesisAccount>> = Lazy::new(|| {
5665
)),
5766
)
5867
};
59-
vec![account_1, account_2]
68+
let account_3 = {
69+
let account_3_balance = Motes::new(ACCOUNT_3_BALANCE);
70+
let account_3_bonded_amount = Motes::new(ACCOUNT_3_BONDED_AMOUNT);
71+
GenesisAccount::Delegator {
72+
validator_public_key: ACCOUNT_1_PUBLIC_KEY.clone(),
73+
delegator_public_key: ACCOUNT_3_PUBLIC_KEY.clone(),
74+
balance: account_3_balance,
75+
delegated_amount: account_3_bonded_amount,
76+
}
77+
};
78+
79+
vec![account_1, account_2, account_3]
6080
});
6181

6282
#[ignore]
@@ -118,6 +138,16 @@ fn should_run_genesis() {
118138
#[ignore]
119139
#[test]
120140
fn should_track_total_token_supply_in_mint() {
141+
should_track_total_token(false)
142+
}
143+
144+
#[ignore]
145+
#[test]
146+
fn should_track_total_token_supply_in_mint_with_enable_addressable_entity() {
147+
should_track_total_token(true)
148+
}
149+
150+
fn should_track_total_token(enable_ae: bool) {
121151
let accounts = GENESIS_CUSTOM_ACCOUNTS.clone();
122152
let wasm_config = *DEFAULT_WASM_CONFIG;
123153
let system_config = *DEFAULT_SYSTEM_CONFIG;
@@ -139,6 +169,7 @@ fn should_track_total_token_supply_in_mint() {
139169
.with_unbonding_delay(unbonding_delay)
140170
.with_genesis_timestamp_millis(genesis_timestamp)
141171
.with_storage_costs(*DEFAULT_STORAGE_COSTS)
172+
.with_enable_addressable_entity(enable_ae)
142173
.build();
143174

144175
let genesis_request = GenesisRequest::new(
@@ -148,7 +179,9 @@ fn should_track_total_token_supply_in_mint() {
148179
DEFAULT_CHAINSPEC_REGISTRY.clone(),
149180
);
150181

151-
let mut builder = LmdbWasmTestBuilder::default();
182+
let chainspec_config = ChainspecConfig::default().with_enable_addressable_entity(enable_ae);
183+
184+
let mut builder = LmdbWasmTestBuilder::new_temporary_with_config(chainspec_config);
152185

153186
builder.run_genesis(genesis_request);
154187

storage/src/system/genesis/account_contract_installer.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,8 @@ where
357357
) in genesis_delegators.iter()
358358
{
359359
if (*validator_public_key).clone() == public_key.clone() {
360+
total_staked_amount += delegator_delegated_amount.value();
361+
360362
let purse_uref =
361363
self.create_purse(delegator_delegated_amount.value())?;
362364

storage/src/system/genesis/entity_installer.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ where
356356
) in genesis_delegators.iter()
357357
{
358358
if (*validator_public_key).clone() == public_key.clone() {
359+
total_staked_amount += delegator_delegated_amount.value();
359360
let purse_uref =
360361
self.create_purse(delegator_delegated_amount.value())?;
361362

0 commit comments

Comments
 (0)