Skip to content

Commit

Permalink
fix more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SWvheerden committed Jan 23, 2025
1 parent 3d70ea3 commit 8ff0186
Show file tree
Hide file tree
Showing 22 changed files with 149 additions and 138 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ mod tests {
let entry = ValidatorNodeEntry {
shard_key: make_hash(p1.as_bytes()),
public_key: p1,
commitment: Commitment::from_public_key(&new_public_key()),
commitment: Commitment::from_compressed_key(new_public_key()),
..Default::default()
};
store.insert(1, &entry).unwrap();
Expand All @@ -311,7 +311,7 @@ mod tests {
.insert(4, &ValidatorNodeEntry {
public_key: nodes[0].0.clone(),
shard_key: s0,
commitment: Commitment::from_compressed_key(&new_public_key()),
commitment: Commitment::from_compressed_key(new_public_key().clone()),
..Default::default()
})
.unwrap();
Expand All @@ -321,8 +321,8 @@ mod tests {
// We insert them in reverse order to demonstrate that insert order does not necessarily match the vn set
// order.
let mut ordered_commitments = vec![
Commitment::from_compressed_key(&new_public_key()),
Commitment::from_compressed_key(&new_public_key()),
Commitment::from_compressed_key(new_public_key().clone()),
Commitment::from_compressed_key(new_public_key().clone()),
];
ordered_commitments.sort();
store
Expand Down Expand Up @@ -364,7 +364,7 @@ mod tests {
.insert(4, &ValidatorNodeEntry {
public_key: nodes[0].0.clone(),
shard_key: new_shard_key,
commitment: Commitment::from_compressed_key(&new_public_key()),
commitment: Commitment::from_compressed_key(new_public_key()),

..Default::default()
})
Expand Down
33 changes: 18 additions & 15 deletions base_layer/core/src/transactions/coinbase_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,8 @@ pub async fn generate_coinbase_with_wallet_output(
mod test {
use tari_common::configuration::Network;
use tari_common_types::{key_branches::TransactionKeyManagerBranch, tari_address::TariAddress, types::Commitment};

use tari_common_types::types::PublicKey;
use tari_comms::types::CompressedSignature;
use crate::{
consensus::{emission::Emission, ConsensusManager, ConsensusManagerBuilder},
transactions::{
Expand All @@ -520,6 +521,8 @@ mod test {
},
validation::aggregate_body::AggregateBodyInternalConsistencyValidator,
};
use tari_common_types::types::Signature;


fn get_builder() -> (
CoinbaseBuilder<MemoryDbKeyManager>,
Expand Down Expand Up @@ -879,11 +882,11 @@ mod test {
&excess,
&kernel_message,
);
assert!(sig.verify_raw_uniform(&excess, &sig_challenge));
assert!(sig.to_schnorr_signature().unwrap().verify_raw_uniform(&excess.to_public_key().unwrap(), &sig_challenge));

// we fix the signature and the excess with the now included offset.
coinbase_kernel2.excess_sig = sig;
coinbase_kernel2.excess = Commitment::from_public_key(&excess);
coinbase_kernel2.excess = Commitment::from_compressed_key(excess);

tx.body.add_output(coinbase2);
tx.body.add_kernel(coinbase_kernel2);
Expand Down Expand Up @@ -977,9 +980,9 @@ mod test {
let coinbase2 = tx2.body.outputs()[0].clone();
let mut kernel_1 = tx1.body.kernels()[0].clone();
let kernel_2 = tx2.body.kernels()[0].clone();
let excess = &kernel_1.excess + &kernel_2.excess;
kernel_1.excess = &kernel_1.excess + &kernel_2.excess;
kernel_1.excess_sig = &kernel_1.excess_sig + &kernel_2.excess_sig;
let excess = &kernel_1.excess.to_commitment().unwrap() + &kernel_2.excess.to_commitment().unwrap();
kernel_1.excess = Commitment::from_commitment(&kernel_1.excess.to_commitment().unwrap() + &kernel_2.excess.to_commitment().unwrap());
kernel_1.excess_sig = CompressedSignature::new_from_schnorr(&kernel_1.excess_sig.to_schnorr_signature().unwrap() + &kernel_2.excess_sig.to_schnorr_signature().unwrap());
let mut body1 = AggregateBody::new(Vec::new(), vec![coinbase1, coinbase2], vec![kernel_1.clone()]);
body1.sort();

Expand All @@ -1002,7 +1005,7 @@ mod test {
.get_next_key(TransactionKeyManagerBranch::KernelNonce.get_branch_key())
.await
.unwrap();
let nonce = &new_nonce1.pub_key + &new_nonce2.pub_key;
let nonce = &new_nonce1.pub_key.to_public_key().unwrap() + &new_nonce2.pub_key.to_public_key().unwrap();
let kernel_message = TransactionKernel::build_kernel_signature_message(
&TransactionKernelVersion::get_current_version(),
kernel_1.fee,
Expand All @@ -1015,35 +1018,35 @@ mod test {
.get_partial_txo_kernel_signature(
&wo1.spending_key_id,
&new_nonce1.key_id,
&nonce,
excess.as_public_key(),
&PublicKey::new_from_pk(&nonce),
&PublicKey::new_from_pk(excess.as_public_key()),
&TransactionKernelVersion::get_current_version(),
&kernel_message,
&kernel_1.features,
TxoStage::Output,
)
.await
.unwrap();
.unwrap().to_schnorr_signature().unwrap();
kernel_signature = &kernel_signature +
&key_manager
.get_partial_txo_kernel_signature(
&wo2.spending_key_id,
&new_nonce2.key_id,
&nonce,
excess.as_public_key(),
&PublicKey::new_from_pk(&nonce),
&PublicKey::new_from_pk(excess.as_public_key()),
&TransactionKernelVersion::get_current_version(),
&kernel_message,
&kernel_1.features,
TxoStage::Output,
)
.await
.unwrap();
.unwrap().to_schnorr_signature().unwrap();
let kernel_new = KernelBuilder::new()
.with_fee(0.into())
.with_features(kernel_1.features)
.with_lock_height(kernel_1.lock_height)
.with_excess(&excess)
.with_signature(kernel_signature)
.with_excess(&Commitment::from_commitment(excess))
.with_signature(Signature::new_from_schnorr(kernel_signature))
.build()
.unwrap();

Expand Down
4 changes: 2 additions & 2 deletions base_layer/core/src/transactions/fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl From<TransactionWeight> for Fee {
#[cfg(test)]
mod test {
use std::convert::TryInto;

use tari_common_types::types::ComAndPubSignature;
use tari_crypto::ristretto::RistrettoComAndPubSig;
use tari_script::ExecutionStack;

Expand Down Expand Up @@ -108,7 +108,7 @@ mod test {
let input = TransactionInput::new_current_version(
spent_output,
ExecutionStack::new(vec![]),
RistrettoComAndPubSig::default(),
ComAndPubSignature::new_from_capk_signature(RistrettoComAndPubSig::default()),
);
let aggregate_body = AggregateBody::new(vec![input], vec![], vec![]);
let fee = Fee::new(TransactionWeight::latest());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,7 @@ mod test {
(654321, PrivateKey::random(&mut OsRng)),
(u64::MAX, PrivateKey::random(&mut OsRng)),
] {
let commitment = CommitmentFactory::default().commit(&mask, &PrivateKey::from(value));
let commitment = Commitment::from_commitment(CommitmentFactory::default().commit(&mask, &PrivateKey::from(value)));
let encryption_key = PrivateKey::random(&mut OsRng);
let amount = MicroMinotari::from(value);
let encrypted_data =
Expand Down Expand Up @@ -1022,7 +1022,7 @@ mod test {
(654321, PrivateKey::random(&mut OsRng)),
(u64::MAX, PrivateKey::random(&mut OsRng)),
] {
let commitment = CommitmentFactory::default().commit(&mask, &PrivateKey::from(value));
let commitment = Commitment::from_commitment(CommitmentFactory::default().commit(&mask, &PrivateKey::from(value)));
let encryption_key = PrivateKey::random(&mut OsRng);
let amount = MicroMinotari::from(value);
let encrypted_data =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ fn check_timelocks() {
let factories = CryptoFactories::new(32);
let k = PrivateKey::random(&mut OsRng);
let v = PrivateKey::from(2u64.pow(32) + 1);
let c = factories.commitment.commit(&k, &v);
let c = Commitment::from_commitment(factories.commitment.commit(&k, &v));

let script = TariScript::default();
let input_data = ExecutionStack::default();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ mod test {
.await
.unwrap();

let metadata_signature_from_partials = &receiver_metadata_signature + &sender_metadata_signature;
let metadata_signature_from_partials = ComAndPubSignature::new_from_capk_signature(&receiver_metadata_signature.to_capk_signature().unwrap() + &sender_metadata_signature.to_capk_signature().unwrap());
assert_ne!(output.metadata_signature, metadata_signature_from_partials);
output.metadata_signature = metadata_signature_from_partials;
assert!(output.verify_metadata_signature().is_ok());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ mod test {
.unwrap();
let offset = data.offset.clone();
let public_offset = PublicKey::from_secret_key(&offset);
let signing_pubkey = &pubkey - &public_offset;
let signing_pubkey = PublicKey::new_from_pk(&(&pubkey.to_public_key().unwrap() - &public_offset.to_public_key().unwrap()));
assert_eq!(data.tx_id.as_u64(), 15);
assert_eq!(data.public_spend_key, signing_pubkey);
let commitment = key_manager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@ mod test {
use tari_key_manager::key_manager_service::KeyManagerInterface;
use tari_script::{inputs, script, ExecutionStack, TariScript};
use tari_utilities::hex::Hex;

use tari_common_types::types::ComAndPubSignature;
use super::SenderState;
use crate::{
covenants::Covenant,
Expand Down Expand Up @@ -1068,7 +1068,7 @@ mod test {
)
.await
.unwrap();
output.metadata_signature = &partial_metadata_signature + &partial_sender_metadata_signature;
output.metadata_signature = ComAndPubSignature::new_from_capk_signature(&partial_metadata_signature.to_capk_signature().unwrap() + &partial_sender_metadata_signature.to_capk_signature().unwrap());
assert!(output.verify_metadata_signature().is_ok());
}

Expand Down
3 changes: 1 addition & 2 deletions base_layer/core/src/validation/block_body/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use std::sync::Arc;

use tari_common::configuration::Network;
use tari_common_types::{key_branches::TransactionKeyManagerBranch, tari_address::TariAddress};
use tari_key_manager::key_manager_service::KeyId;
use tari_script::{push_pubkey_script, script};
use tari_test_utils::unpack_enum;
use tokio::time::Instant;
Expand Down Expand Up @@ -242,7 +241,7 @@ async fn it_allows_multiple_coinbases() {
let (blockchain, validator) = setup(true).await;

let (mut block, coinbase) = blockchain.create_unmined_block(block_spec!("A1", parent: "GB")).await;
let commitment_mask_key = KeyId::Managed {
let commitment_mask_key = TariKeyId::Managed {
branch: TransactionKeyManagerBranch::CommitmentMask.get_branch_key(),
index: 42,
};
Expand Down
Loading

0 comments on commit 8ff0186

Please sign in to comment.