Skip to content

Commit 88fe985

Browse files
committed
test: add test for proving full data request lifecycle
1 parent cdbd32e commit 88fe985

File tree

1 file changed

+47
-0
lines changed
  • data_structures/src/chain

1 file changed

+47
-0
lines changed

data_structures/src/chain/mod.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7344,4 +7344,51 @@ mod tests {
73447344
.reveal_contains(&dr_pointer, &pkh, &r.hash())
73457345
.unwrap());
73467346
}
7347+
7348+
#[test]
7349+
fn data_request_lifecycle() {
7350+
let extra_rounds = 3;
7351+
// Initial state
7352+
let mut state = DataRequestState::default();
7353+
state.data_request.witnesses = 1;
7354+
assert_eq!(state.stage, DataRequestStage::COMMIT);
7355+
assert_eq!(state.info.current_commit_round, 0);
7356+
// First commitment round
7357+
state.update_stage(extra_rounds, false);
7358+
assert_eq!(state.stage, DataRequestStage::COMMIT);
7359+
assert_eq!(state.info.current_commit_round, 1);
7360+
// Second commitment round
7361+
state.update_stage(extra_rounds, false);
7362+
assert_eq!(state.stage, DataRequestStage::COMMIT);
7363+
assert_eq!(state.info.current_commit_round, 2);
7364+
// Third commitment round
7365+
state.update_stage(extra_rounds, false);
7366+
assert_eq!(state.stage, DataRequestStage::COMMIT);
7367+
assert_eq!(state.info.current_commit_round, 3);
7368+
// Fourth and last commitment round
7369+
state.update_stage(extra_rounds, false);
7370+
assert_eq!(state.stage, DataRequestStage::COMMIT);
7371+
assert_eq!(state.info.current_commit_round, 4);
7372+
// We introduce at least 1 commit to force the stage to move to reveal
7373+
let _ = state.add_commit(Default::default(), Default::default());
7374+
// First reveal round
7375+
state.update_stage(extra_rounds, false);
7376+
assert_eq!(state.stage, DataRequestStage::REVEAL);
7377+
assert_eq!(state.info.current_reveal_round, 1);
7378+
// Second reveal round
7379+
state.update_stage(extra_rounds, false);
7380+
assert_eq!(state.stage, DataRequestStage::REVEAL);
7381+
assert_eq!(state.info.current_reveal_round, 2);
7382+
// Third reveal round
7383+
state.update_stage(extra_rounds, false);
7384+
assert_eq!(state.stage, DataRequestStage::REVEAL);
7385+
assert_eq!(state.info.current_reveal_round, 3);
7386+
// Fourth reveal round
7387+
state.update_stage(extra_rounds, false);
7388+
assert_eq!(state.stage, DataRequestStage::REVEAL);
7389+
assert_eq!(state.info.current_reveal_round, 4);
7390+
// Jumped to tally stage
7391+
state.update_stage(extra_rounds, false);
7392+
assert_eq!(state.stage, DataRequestStage::TALLY);
7393+
}
73477394
}

0 commit comments

Comments
 (0)