Skip to content

Commit

Permalink
Merge branch 'tomas/fix-test-unjail' (#2585)
Browse files Browse the repository at this point in the history
* tomas/fix-test-unjail:
  test/pos: fix unjail test expected state
  • Loading branch information
tzemanovic committed Feb 9, 2024
2 parents fa75107 + 94be28f commit 7303b79
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
# It is recommended to check this file in to source control so that
# everyone who runs the test benefits from these saved cases.
cc 1046b561e07b35ab0acb2a14c048fd046494e8206f777a7f48c69e85c757517e # shrinks to genesis_validators = [GenesisValidator { address: Established: tnam1q9ns2rhtt726hat5f8vjv2wu760cpsnzgucmcltv, tokens: Amount { raw: 9457277 }, consensus_key: Ed25519(PublicKey(VerificationKey("ee1aa49a4459dfe813a3cf6eb882041230c7b2558469de81f87c9bf23bf10a03"))), protocol_key: Ed25519(PublicKey(VerificationKey("ee1aa49a4459dfe813a3cf6eb882041230c7b2558469de81f87c9bf23bf10a03"))), eth_cold_key: Secp256k1(PublicKey(PublicKey { point: AffinePoint { x: FieldElement(FieldElementImpl { value: FieldElement5x52([3687714098484844, 1725416969128219, 3594408049036174, 782872391161192, 80569310785291]), magnitude: 1, normalized: true }), y: FieldElement(FieldElementImpl { value: FieldElement5x52([1283555534803791, 4252032876348851, 1737243046858658, 667882566711281, 179730537769997]), magnitude: 1, normalized: true }), infinity: 0 } })), eth_hot_key: Secp256k1(PublicKey(PublicKey { point: AffinePoint { x: FieldElement(FieldElementImpl { value: FieldElement5x52([3952144861987407, 3192798110705048, 1432977887623307, 4343775242733102, 199596577679384]), magnitude: 1, normalized: true }), y: FieldElement(FieldElementImpl { value: FieldElement5x52([1551259714849962, 3777943015799511, 173947271087726, 3219386088850087, 119053612396808]), magnitude: 1, normalized: true }), infinity: 0 } })), commission_rate: 0.05, max_commission_rate_change: 0.01, metadata: ValidatorMetaData { email: "[email protected]", description: None, website: None, discord_handle: None, avatar: None } }, GenesisValidator { address: Established: tnam1qxwzunv0a97cs9psme882j6zqkuuyl8fvu0m4jlt, tokens: Amount { raw: 999999 }, consensus_key: Ed25519(PublicKey(VerificationKey("ff87a0b0a3c7c0ce827e9cada5ff79e75a44a0633bfcb5b50f99307ddb26b337"))), protocol_key: Ed25519(PublicKey(VerificationKey("ff87a0b0a3c7c0ce827e9cada5ff79e75a44a0633bfcb5b50f99307ddb26b337"))), eth_cold_key: Secp256k1(PublicKey(PublicKey { point: AffinePoint { x: FieldElement(FieldElementImpl { value: FieldElement5x52([3775997171064665, 402623202571169, 3517018742227290, 1979726550188643, 56489437017912]), magnitude: 1, normalized: true }), y: FieldElement(FieldElementImpl { value: FieldElement5x52([161541205874067, 2738570855055442, 2149230077785297, 1004004386946763, 9685310603477]), magnitude: 1, normalized: true }), infinity: 0 } })), eth_hot_key: Secp256k1(PublicKey(PublicKey { point: AffinePoint { x: FieldElement(FieldElementImpl { value: FieldElement5x52([63823977226473, 1780180951128778, 3880337533243508, 3477660780649868, 234759233176937]), magnitude: 1, normalized: true }), y: FieldElement(FieldElementImpl { value: FieldElement5x52([3967261296363354, 365489114047076, 865944663573361, 4215749262364770, 206416784899311]), magnitude: 1, normalized: true }), infinity: 0 } })), commission_rate: 0.05, max_commission_rate_change: 0.01, metadata: ValidatorMetaData { email: "[email protected]", description: None, website: None, discord_handle: None, avatar: None } }, GenesisValidator { address: Established: tnam1qyxqs9ec9pvrl3hv6mkdhn98k6fecjwzgg9j72dh, tokens: Amount { raw: 1000000 }, consensus_key: Ed25519(PublicKey(VerificationKey("191fc38f134aaf1b7fdb1f86330b9d03e94bd4ba884f490389de964448e89b3f"))), protocol_key: Ed25519(PublicKey(VerificationKey("191fc38f134aaf1b7fdb1f86330b9d03e94bd4ba884f490389de964448e89b3f"))), eth_cold_key: Secp256k1(PublicKey(PublicKey { point: AffinePoint { x: FieldElement(FieldElementImpl { value: FieldElement5x52([34511288854536, 510545718737219, 2130958320243070, 1981191820513176, 12537204833916]), magnitude: 1, normalized: true }), y: FieldElement(FieldElementImpl { value: FieldElement5x52([4195052699047722, 2500352379968226, 1587685438679340, 3119337455291951, 40440979274508]), magnitude: 1, normalized: true }), infinity: 0 } })), eth_hot_key: Secp256k1(PublicKey(PublicKey { point: AffinePoint { x: FieldElement(FieldElementImpl { value: FieldElement5x52([1656936550894586, 4006091246126320, 1652449362890341, 879420910110485, 112142529162408]), magnitude: 1, normalized: true }), y: FieldElement(FieldElementImpl { value: FieldElement5x52([4237986578828224, 1920811154974052, 738044507867020, 1062682166273987, 250213651523767]), magnitude: 1, normalized: true }), infinity: 0 } })), commission_rate: 0.05, max_commission_rate_change: 0.01, metadata: ValidatorMetaData { email: "[email protected]", description: None, website: None, discord_handle: None, avatar: None } }, GenesisValidator { address: Established: tnam1qxqfq0dyu6aal9hglahu89ntpn7n2hr7sccxudtq, tokens: Amount { raw: 4840217 }, consensus_key: Ed25519(PublicKey(VerificationKey("c5bbbb60e412879bbec7bb769804fa8e36e68af10d5477280b63deeaca931bed"))), protocol_key: Ed25519(PublicKey(VerificationKey("c5bbbb60e412879bbec7bb769804fa8e36e68af10d5477280b63deeaca931bed"))), eth_cold_key: Secp256k1(PublicKey(PublicKey { point: AffinePoint { x: FieldElement(FieldElementImpl { value: FieldElement5x52([3929052570932551, 422004460987956, 4110169997196645, 3546064018542959, 32528841793783]), magnitude: 1, normalized: true }), y: FieldElement(FieldElementImpl { value: FieldElement5x52([2876349252775808, 3328760537421833, 4044365321910424, 2186355755914359, 97214763693622]), magnitude: 1, normalized: true }), infinity: 0 } })), eth_hot_key: Secp256k1(PublicKey(PublicKey { point: AffinePoint { x: FieldElement(FieldElementImpl { value: FieldElement5x52([265328789488434, 63501740001796, 4150751128072978, 2614791001570599, 10878371620358]), magnitude: 1, normalized: true }), y: FieldElement(FieldElementImpl { value: FieldElement5x52([2188683297757430, 3484510095370921, 2983320355092166, 1938087775906649, 175615473130604]), magnitude: 1, normalized: true }), infinity: 0 } })), commission_rate: 0.05, max_commission_rate_change: 0.01, metadata: ValidatorMetaData { email: "[email protected]", description: None, website: None, discord_handle: None, avatar: None } }, GenesisValidator { address: Established: tnam1q9dfa2u3fquf89007pgdmuqzyrtjyy3u4q85hyxa, tokens: Amount { raw: 999999 }, consensus_key: Ed25519(PublicKey(VerificationKey("4f44e6c7bdfed3d9f48d86149ee3d29382cae8c83ca253e06a70be54a301828b"))), protocol_key: Ed25519(PublicKey(VerificationKey("4f44e6c7bdfed3d9f48d86149ee3d29382cae8c83ca253e06a70be54a301828b"))), eth_cold_key: Secp256k1(PublicKey(PublicKey { point: AffinePoint { x: FieldElement(FieldElementImpl { value: FieldElement5x52([1392748982455935, 3712056313690441, 3274215285211553, 275188245477517, 136910978276484]), magnitude: 1, normalized: true }), y: FieldElement(FieldElementImpl { value: FieldElement5x52([1417672179000226, 2067755564930961, 1709432283273046, 3106306522815366, 49421911403938]), magnitude: 1, normalized: true }), infinity: 0 } })), eth_hot_key: Secp256k1(PublicKey(PublicKey { point: AffinePoint { x: FieldElement(FieldElementImpl { value: FieldElement5x52([713981036146970, 2665399680475299, 1154426434978859, 4321127254681898, 146874239398056]), magnitude: 1, normalized: true }), y: FieldElement(FieldElementImpl { value: FieldElement5x52([3738123281003012, 2697437139896166, 1570515695454620, 3484105755605412, 222168649168427]), magnitude: 1, normalized: true }), infinity: 0 } })), commission_rate: 0.05, max_commission_rate_change: 0.01, metadata: ValidatorMetaData { email: "[email protected]", description: None, website: None, discord_handle: None, avatar: None } }, GenesisValidator { address: Established: tnam1qxef9qu3lzj80gnhfxj4ddecdax6gwg7nqn6m5n6, tokens: Amount { raw: 999999 }, consensus_key: Ed25519(PublicKey(VerificationKey("e2e8aa145e1ec5cb01ebfaa40e10e12f0230c832fd8135470c001cb86d77de00"))), protocol_key: Ed25519(PublicKey(VerificationKey("e2e8aa145e1ec5cb01ebfaa40e10e12f0230c832fd8135470c001cb86d77de00"))), eth_cold_key: Secp256k1(PublicKey(PublicKey { point: AffinePoint { x: FieldElement(FieldElementImpl { value: FieldElement5x52([2508121429912600, 4283049723885885, 2546168669420037, 2739723525368207, 154291485951333]), magnitude: 1, normalized: true }), y: FieldElement(FieldElementImpl { value: FieldElement5x52([4213072049696356, 3528798040209205, 3305954542051068, 3804621601998074, 123484600806497]), magnitude: 1, normalized: true }), infinity: 0 } })), eth_hot_key: Secp256k1(PublicKey(PublicKey { point: AffinePoint { x: FieldElement(FieldElementImpl { value: FieldElement5x52([2888154564342746, 2086322583450370, 513383920331760, 2277486538342599, 190139471523307]), magnitude: 1, normalized: true }), y: FieldElement(FieldElementImpl { value: FieldElement5x52([3815979585446158, 426537182641646, 2679715397722213, 2931802451234958, 184475860714145]), magnitude: 1, normalized: true }), infinity: 0 } })), commission_rate: 0.05, max_commission_rate_change: 0.01, metadata: ValidatorMetaData { email: "[email protected]", description: None, website: None, discord_handle: None, avatar: None } }]
cc f1342b2661fa64accea7ff3ff3772f87a9797f4692ce6e7d3620e5204b5789a3
62 changes: 42 additions & 20 deletions crates/proof_of_stake/src/tests/test_pos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
use std::collections::{BTreeMap, HashSet};

use assert_matches::assert_matches;
use namada_core::types::address::Address;
use namada_core::types::dec::Dec;
use namada_core::types::key::testing::{
Expand Down Expand Up @@ -866,12 +867,21 @@ fn test_unjail_validator_aux(
)
.unwrap();

assert_eq!(
validator_state_handle(val_addr)
.get(&s, current_epoch, &params)
.unwrap(),
Some(ValidatorState::Consensus)
);
let val_stake =
crate::read_validator_stake(&s, &params, val_addr, current_epoch)
.unwrap();
let state = validator_state_handle(val_addr)
.get(&s, current_epoch, &params)
.unwrap()
.unwrap();
if val_stake >= params.validator_stake_threshold {
assert_matches!(
state,
ValidatorState::Consensus | ValidatorState::BelowCapacity
);
} else {
assert_eq!(state, ValidatorState::BelowThreshold);
};

for epoch in Epoch::iter_bounds_inclusive(
current_epoch.next(),
Expand Down Expand Up @@ -916,20 +926,32 @@ fn test_unjail_validator_aux(
Some(ValidatorState::Jailed)
);
}

assert_eq!(
validator_state_handle(val_addr)
.get(&s, current_epoch + params.pipeline_len, &params)
.unwrap(),
Some(ValidatorState::Consensus)
);
assert!(
validator_set_positions_handle()
.at(&(current_epoch + params.pipeline_len))
.get(&s, val_addr)
.unwrap()
.is_some(),
);
let val_stake = crate::read_validator_stake(
&s,
&params,
val_addr,
current_epoch + params.pipeline_len,
)
.unwrap();
let state = validator_state_handle(val_addr)
.get(&s, current_epoch + params.pipeline_len, &params)
.unwrap()
.unwrap();
if val_stake >= params.validator_stake_threshold {
assert_matches!(
state,
ValidatorState::Consensus | ValidatorState::BelowCapacity
);
assert!(
validator_set_positions_handle()
.at(&(current_epoch + params.pipeline_len))
.get(&s, val_addr)
.unwrap()
.is_some(),
);
} else {
assert_eq!(state, ValidatorState::BelowThreshold);
};

// Advance another epoch
current_epoch = advance_epoch(&mut s, &params);
Expand Down

0 comments on commit 7303b79

Please sign in to comment.