Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test-case invalid_undelegate_transaction_with_invalid_timestamp #546

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 53 additions & 3 deletions core/src/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2347,10 +2347,60 @@ mod test {
#[ignore]
#[test]
// Test the case where the `Undelegate` extra-agenda transaction is invalid because the timestamp is invalid.
/// This test case is ignored because the extra-agenda transaction is not implemented yet.
/// TODO: enable this test case when the extra-agenda transaction is implemented.
fn invalid_undelegate_transaction_with_invalid_timestamp() {
todo!("Implement this test")
let (validator_keypair, reserved_state, mut csv) = setup_test(4);
// Apply agenda commit
let agenda_transactions_hash = calculate_agenda_transactions_hash(csv.phase.clone());
let agenda: Agenda = Agenda {
author: reserved_state.query_name(&validator_keypair[0].0).unwrap(),
timestamp: 1,
transactions_hash: agenda_transactions_hash,
height: csv.header.height + 1,
previous_block_hash: csv.header.to_hash256(),
};
csv.apply_commit(&generate_agenda_commit(&agenda)).unwrap();
// Apply agenda-proof commit
csv.apply_commit(&generate_agenda_proof_commit(
&validator_keypair,
&agenda,
agenda.to_hash256(),
))
.unwrap();
// Apply extra-agenda transaction commit
// delegator: member-1, delegatee: member-2
let delegator = reserved_state.members[1].clone();
let delegator_private_key = validator_keypair[1].1.clone();
let delegatee = reserved_state.members[2].clone();
let delegation_transaction_data: DelegationTransactionData = DelegationTransactionData {
delegator: delegator.name.clone(),
delegatee: delegatee.name,
governance: true,
block_height: csv.header.height + 1,
timestamp: 2,
chain_name: reserved_state.genesis_info.chain_name.clone(),
};
let proof =
TypedSignature::sign(&delegation_transaction_data, &delegator_private_key).unwrap();
csv.apply_commit(&generate_delegation_transaction_commit(
&delegation_transaction_data,
proof,
))
.unwrap();
// Apply `Undelegate` extra-agenda transaction commit with invalid timestamp
let undelegation_transaction_data: UndelegationTransactionData =
UndelegationTransactionData {
delegator: delegator.name,
block_height: csv.header.height + 1,
timestamp: 1, // invalid timestamp
chain_name: reserved_state.genesis_info.chain_name,
};
let invalid_proof =
TypedSignature::sign(&undelegation_transaction_data, &delegator_private_key).unwrap();
csv.apply_commit(&generate_undelegation_transaction_commit(
&undelegation_transaction_data,
invalid_proof,
))
.unwrap_err();
}

// TODO: add test cases where the `Report` extra-agenda transactions are invalid.
Expand Down
Loading