Skip to content

Commit 44ca798

Browse files
committed
test(app): checks for unlocked+locked stake
1 parent 3957134 commit 44ca798

File tree

1 file changed

+101
-1
lines changed

1 file changed

+101
-1
lines changed

core/application/src/tests/epoch_change.rs

+101-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use fleek_crypto::{AccountOwnerSecretKey, NodeSecretKey, SecretKey};
55
use hp_fixed::unsigned::HpUfixed;
66
use lightning_committee_beacon::{CommitteeBeaconConfig, CommitteeBeaconTimerConfig};
77
use lightning_interfaces::types::{
8+
CommitteeSelectionBeaconPhase,
89
DeliveryAcknowledgmentProof,
910
ExecuteTransactionError,
1011
ExecutionData,
@@ -23,8 +24,18 @@ use lightning_test_utils::e2e::{
2324
use lightning_utils::application::QueryRunnerExt;
2425
use lightning_utils::poll::{poll_until, PollUntilError};
2526
use tempfile::tempdir;
27+
use utils::{
28+
create_genesis_committee,
29+
deposit_and_stake,
30+
expect_tx_revert,
31+
expect_tx_success,
32+
prepare_update_request_account,
33+
prepare_update_request_node,
34+
test_init_app,
35+
test_reputation_measurements,
36+
};
2637

27-
use super::utils::*;
38+
use super::*;
2839

2940
#[tokio::test]
3041
async fn test_epoch_change_with_all_committee_nodes() {
@@ -319,6 +330,95 @@ async fn test_epoch_change_with_some_non_committee_nodes() {
319330
network.shutdown().await;
320331
}
321332

333+
#[tokio::test]
334+
async fn test_change_epoch_with_only_locked_stake() {
335+
let network = utils::TestNetwork::builder()
336+
.with_committee_nodes(2)
337+
.with_genesis_mutator(|genesis| {
338+
genesis.min_stake = 1000;
339+
340+
// First node has only locked stake.
341+
genesis.node_info[0].stake.staked = 0u32.into();
342+
genesis.node_info[0].stake.locked = 1000u32.into();
343+
344+
// Second node has unlocked stake.
345+
genesis.node_info[1].stake.staked = 1000u32.into();
346+
genesis.node_info[1].stake.locked = 0u32.into();
347+
})
348+
.build()
349+
.await
350+
.unwrap();
351+
let query = network.query();
352+
let epoch = query.get_current_epoch();
353+
354+
// Execute epoch change transaction from the node with only locked stake.
355+
let resp = network
356+
.execute(vec![
357+
network
358+
.node(0)
359+
.build_transaction(UpdateMethod::ChangeEpoch { epoch }),
360+
])
361+
.await
362+
.unwrap();
363+
assert_eq!(resp.block_number, 1);
364+
assert!(!resp.change_epoch);
365+
366+
// Execute epoch change transaction from the node with unlocked stake.
367+
let resp = network
368+
.execute(vec![
369+
network
370+
.node(1)
371+
.build_transaction(UpdateMethod::ChangeEpoch { epoch }),
372+
])
373+
.await
374+
.unwrap();
375+
assert_eq!(resp.block_number, 2);
376+
assert!(!resp.change_epoch);
377+
378+
// Check that we have transitioned to the committee beacon commit phase.
379+
assert_eq!(
380+
query.get_committee_selection_beacon_phase(),
381+
Some(CommitteeSelectionBeaconPhase::Commit((2, 4)))
382+
);
383+
assert_eq!(query.get_committee_selection_beacon_round(), Some(0));
384+
}
385+
386+
#[tokio::test]
387+
async fn test_change_epoch_reverts_if_node_opted_out() {
388+
let network = utils::TestNetwork::builder()
389+
.with_committee_nodes(2)
390+
.build()
391+
.await
392+
.unwrap();
393+
let query = network.query();
394+
let epoch = query.get_current_epoch();
395+
396+
// Execute opt-out transaction from the first node.
397+
let resp = network
398+
.execute(vec![
399+
network.node(0).build_transaction(UpdateMethod::OptOut {}),
400+
])
401+
.await
402+
.unwrap();
403+
assert_eq!(resp.block_number, 1);
404+
405+
// Execute epoch change transaction from the node and check that it reverts.
406+
let resp = network
407+
.maybe_execute(vec![
408+
network
409+
.node(0)
410+
.build_transaction(UpdateMethod::ChangeEpoch { epoch }),
411+
])
412+
.await
413+
.unwrap();
414+
assert_eq!(resp.block_number, 2);
415+
assert!(!resp.change_epoch);
416+
assert_eq!(
417+
resp.txn_receipts[0].response,
418+
TransactionResponse::Revert(ExecutionError::NodeNotParticipating)
419+
);
420+
}
421+
322422
#[tokio::test]
323423
async fn test_change_epoch_reverts_account_key() {
324424
let temp_dir = tempdir().unwrap();

0 commit comments

Comments
 (0)