Skip to content

Commit

Permalink
fixup! test/shell/finalize_block: add some txs to DB commit test
Browse files Browse the repository at this point in the history
  • Loading branch information
tzemanovic committed Jul 13, 2023
1 parent 1335e25 commit 7207fa9
Showing 1 changed file with 79 additions and 79 deletions.
158 changes: 79 additions & 79 deletions apps/src/lib/node/ledger/shell/finalize_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,85 @@ mod test_finalize_block {
FinalizeBlock, ProcessedTx,
};

/// Make a wrapper tx and a processed tx from the wrapped tx that can be
/// added to `FinalizeBlock` request.
fn mk_wrapper_tx(
shell: &TestShell,
keypair: &common::SecretKey,
) -> (Tx, ProcessedTx) {
let mut wrapper_tx =
Tx::new(TxType::Wrapper(Box::new(WrapperTx::new(
Fee {
amount: MIN_FEE_AMOUNT,
token: shell.wl_storage.storage.native_token.clone(),
},
keypair.ref_to(),
Epoch(0),
Default::default(),
#[cfg(not(feature = "mainnet"))]
None,
))));
wrapper_tx.header.chain_id = shell.chain_id.clone();
wrapper_tx.set_code(Code::new("wasm_code".as_bytes().to_owned()));
wrapper_tx.set_data(Data::new(
"Encrypted transaction data".as_bytes().to_owned(),
));
wrapper_tx.add_section(Section::Signature(Signature::new(
wrapper_tx.sechashes(),
keypair,
)));
let tx = wrapper_tx.to_bytes();
(
wrapper_tx,
ProcessedTx {
tx,
result: TxResult {
code: ErrorCodes::Ok.into(),
info: "".into(),
},
},
)
}

/// Make a wrapper tx and a processed tx from the wrapped tx that can be
/// added to `FinalizeBlock` request.
fn mk_decrypted_tx(
shell: &mut TestShell,
keypair: &common::SecretKey,
) -> ProcessedTx {
let tx_code = TestWasms::TxNoOp.read_bytes();
let mut outer_tx = Tx::new(TxType::Wrapper(Box::new(WrapperTx::new(
Fee {
amount: MIN_FEE_AMOUNT,
token: shell.wl_storage.storage.native_token.clone(),
},
keypair.ref_to(),
Epoch(0),
Default::default(),
#[cfg(not(feature = "mainnet"))]
None,
))));
outer_tx.header.chain_id = shell.chain_id.clone();
outer_tx.set_code(Code::new(tx_code));
outer_tx.set_data(Data::new(
"Decrypted transaction data".as_bytes().to_owned(),
));
shell.enqueue_tx(outer_tx.clone());
outer_tx.update_header(TxType::Decrypted(DecryptedTx::Decrypted {
#[cfg(not(feature = "mainnet"))]
has_valid_pow: false,
}));
outer_tx.decrypt(<EllipticCurve as PairingEngine>::G2Affine::prime_subgroup_generator())
.expect("Test failed");
ProcessedTx {
tx: outer_tx.to_bytes(),
result: TxResult {
code: ErrorCodes::Ok.into(),
info: "".into(),
},
}
}

/// Check that if a wrapper tx was rejected by [`process_proposal`],
/// check that the correct event is returned. Check that it does
/// not appear in the queue of txs to be decrypted
Expand Down Expand Up @@ -3490,83 +3569,4 @@ mod test_finalize_block {
control_receiver.recv().await.expect("Test failed");
assert_eq!(u64::from(cmd.min_confirmations), 42);
}

/// Make a wrapper tx and a processed tx from the wrapped tx that can be
/// added to `FinalizeBlock` request.
fn mk_wrapper_tx(
shell: &TestShell,
keypair: &common::SecretKey,
) -> (Tx, ProcessedTx) {
let mut wrapper_tx =
Tx::new(TxType::Wrapper(Box::new(WrapperTx::new(
Fee {
amount: MIN_FEE_AMOUNT,
token: shell.wl_storage.storage.native_token.clone(),
},
keypair.ref_to(),
Epoch(0),
Default::default(),
#[cfg(not(feature = "mainnet"))]
None,
))));
wrapper_tx.header.chain_id = shell.chain_id.clone();
wrapper_tx.set_code(Code::new("wasm_code".as_bytes().to_owned()));
wrapper_tx.set_data(Data::new(
"Encrypted transaction data".as_bytes().to_owned(),
));
wrapper_tx.add_section(Section::Signature(Signature::new(
wrapper_tx.sechashes(),
keypair,
)));
let tx = wrapper_tx.to_bytes();
(
wrapper_tx,
ProcessedTx {
tx,
result: TxResult {
code: ErrorCodes::Ok.into(),
info: "".into(),
},
},
)
}

/// Make a wrapper tx and a processed tx from the wrapped tx that can be
/// added to `FinalizeBlock` request.
fn mk_decrypted_tx(
shell: &mut TestShell,
keypair: &common::SecretKey,
) -> ProcessedTx {
let tx_code = TestWasms::TxNoOp.read_bytes();
let mut outer_tx = Tx::new(TxType::Wrapper(Box::new(WrapperTx::new(
Fee {
amount: MIN_FEE_AMOUNT,
token: shell.wl_storage.storage.native_token.clone(),
},
keypair.ref_to(),
Epoch(0),
Default::default(),
#[cfg(not(feature = "mainnet"))]
None,
))));
outer_tx.header.chain_id = shell.chain_id.clone();
outer_tx.set_code(Code::new(tx_code));
outer_tx.set_data(Data::new(
"Decrypted transaction data".as_bytes().to_owned(),
));
shell.enqueue_tx(outer_tx.clone());
outer_tx.update_header(TxType::Decrypted(DecryptedTx::Decrypted {
#[cfg(not(feature = "mainnet"))]
has_valid_pow: false,
}));
outer_tx.decrypt(<EllipticCurve as PairingEngine>::G2Affine::prime_subgroup_generator())
.expect("Test failed");
ProcessedTx {
tx: outer_tx.to_bytes(),
result: TxResult {
code: ErrorCodes::Ok.into(),
info: "".into(),
},
}
}
}

0 comments on commit 7207fa9

Please sign in to comment.