Skip to content

Commit

Permalink
chore: fix cargo fmt (#772)
Browse files Browse the repository at this point in the history
Description
---
Fix the cargo fmt failing on the repo.

Motivation and Context
---

How Has This Been Tested?
---

What process can a PR reviewer use to test or verify this change?
---


Breaking Changes
---

- [x] None
- [ ] Requires data directory to be deleted
- [ ] Other - Please specify
  • Loading branch information
Cifko authored Nov 16, 2023
1 parent 9c2f369 commit 9d06a84
Showing 1 changed file with 36 additions and 131 deletions.
167 changes: 36 additions & 131 deletions dan_layer/engine/tests/confidential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,14 @@ use tari_template_lib::{
prelude::ConfidentialOutputProof,
};
use tari_template_test_tooling::{
confidential::{
generate_confidential_proof, generate_withdraw_proof, generate_withdraw_proof_with_inputs,
},
SubstateType, TemplateTest,
confidential::{generate_confidential_proof, generate_withdraw_proof, generate_withdraw_proof_with_inputs},
SubstateType,
TemplateTest,
};
use tari_transaction::Transaction;
use tari_transaction_manifest::ManifestValue;

fn setup(
initial_supply: ConfidentialOutputProof,
) -> (TemplateTest, ComponentAddress, SubstateAddress) {
fn setup(initial_supply: ConfidentialOutputProof) -> (TemplateTest, ComponentAddress, SubstateAddress) {
let mut template_test = TemplateTest::new(vec![
"tests/templates/confidential/faucet",
"tests/templates/confidential/utilities",
Expand Down Expand Up @@ -69,17 +66,15 @@ fn mint_more_later() {
#[allow(clippy::too_many_lines)]
#[test]
fn transfer_confidential_amounts_between_accounts() {
let (confidential_proof, faucet_mask, _change) =
generate_confidential_proof(Amount(100_000), None);
let (confidential_proof, faucet_mask, _change) = generate_confidential_proof(Amount(100_000), None);
let (mut template_test, faucet, faucet_resx) = setup(confidential_proof);

// Create an account
let (account1, owner1, _k) = template_test.create_owned_account();
let (account2, _owner2, _k) = template_test.create_owned_account();

// Create proof for transfer
let proof =
generate_withdraw_proof(&faucet_mask, Amount(1000), Some(Amount(99_000)), Amount(0));
let proof = generate_withdraw_proof(&faucet_mask, Amount(1000), Some(Amount(99_000)), Amount(0));

// Transfer faucet funds into account 1
let vars = [
Expand All @@ -102,39 +97,15 @@ fn transfer_confidential_amounts_between_accounts() {
.unwrap();

let diff = result.finalize.result.expect("Failed to execute manifest");
assert_eq!(
diff.up_iter().filter(|(addr, _)| *addr == account1).count(),
1
);
assert_eq!(
diff.down_iter()
.filter(|(addr, _)| *addr == account1)
.count(),
1
);
assert_eq!(
diff.up_iter().filter(|(addr, _)| *addr == faucet).count(),
1
);
assert_eq!(
diff.down_iter().filter(|(addr, _)| *addr == faucet).count(),
1
);
assert_eq!(diff.up_iter().filter(|(addr, _)| *addr == account1).count(), 1);
assert_eq!(diff.down_iter().filter(|(addr, _)| *addr == account1).count(), 1);
assert_eq!(diff.up_iter().filter(|(addr, _)| *addr == faucet).count(), 1);
assert_eq!(diff.down_iter().filter(|(addr, _)| *addr == faucet).count(), 1);
assert_eq!(diff.up_iter().count(), 5);
assert_eq!(diff.down_iter().count(), 3);

let withdraw_proof = generate_withdraw_proof(
&proof.output_mask,
Amount(100),
Some(Amount(900)),
Amount(0),
);
let split_proof = generate_withdraw_proof(
&withdraw_proof.output_mask,
Amount(20),
Some(Amount(80)),
Amount(0),
);
let withdraw_proof = generate_withdraw_proof(&proof.output_mask, Amount(100), Some(Amount(900)), Amount(0));
let split_proof = generate_withdraw_proof(&withdraw_proof.output_mask, Amount(20), Some(Amount(80)), Amount(0));

let vars = [
("faucet_resx", faucet_resx.into()),
Expand All @@ -144,10 +115,7 @@ fn transfer_confidential_amounts_between_accounts() {
"withdraw_proof",
ManifestValue::new_value(&withdraw_proof.proof).unwrap(),
),
(
"split_proof",
ManifestValue::new_value(&split_proof.proof).unwrap(),
),
("split_proof", ManifestValue::new_value(&split_proof.proof).unwrap()),
];
let result = template_test
.execute_and_commit_manifest(
Expand All @@ -170,42 +138,24 @@ fn transfer_confidential_amounts_between_accounts() {
)
.unwrap();
let diff = result.finalize.result.expect("Failed to execute manifest");
assert_eq!(
diff.up_iter().filter(|(addr, _)| *addr == account1).count(),
1
);
assert_eq!(
diff.down_iter()
.filter(|(addr, _)| *addr == account1)
.count(),
1
);
assert_eq!(
diff.up_iter().filter(|(addr, _)| *addr == account2).count(),
1
);
assert_eq!(
diff.down_iter()
.filter(|(addr, _)| *addr == account2)
.count(),
1
);
assert_eq!(diff.up_iter().filter(|(addr, _)| *addr == account1).count(), 1);
assert_eq!(diff.down_iter().filter(|(addr, _)| *addr == account1).count(), 1);
assert_eq!(diff.up_iter().filter(|(addr, _)| *addr == account2).count(), 1);
assert_eq!(diff.down_iter().filter(|(addr, _)| *addr == account2).count(), 1);
assert_eq!(diff.up_iter().count(), 5);
assert_eq!(diff.down_iter().count(), 3);
}

#[test]
fn transfer_confidential_fails_with_invalid_balance() {
let (confidential_proof, faucet_mask, _change) =
generate_confidential_proof(Amount(100_000), None);
let (confidential_proof, faucet_mask, _change) = generate_confidential_proof(Amount(100_000), None);
let (mut template_test, faucet, _faucet_resx) = setup(confidential_proof);

// Create an account
let (account1, _owner1, _k) = template_test.create_owned_account();

// Create proof for transfer
let proof =
generate_withdraw_proof(&faucet_mask, Amount(1001), Some(Amount(99_000)), Amount(0));
let proof = generate_withdraw_proof(&faucet_mask, Amount(1001), Some(Amount(99_000)), Amount(0));

// Transfer faucet funds into account 1
let vars = [
Expand All @@ -230,8 +180,7 @@ fn transfer_confidential_fails_with_invalid_balance() {

#[test]
fn reveal_confidential_and_transfer() {
let (confidential_proof, faucet_mask, _change) =
generate_confidential_proof(Amount(100_000), None);
let (confidential_proof, faucet_mask, _change) = generate_confidential_proof(Amount(100_000), None);
let (mut template_test, faucet, faucet_resx) = setup(confidential_proof);

// Create an account
Expand All @@ -240,18 +189,11 @@ fn reveal_confidential_and_transfer() {

// Create proof for transfer

let proof =
generate_withdraw_proof(&faucet_mask, Amount(1000), Some(Amount(99_000)), Amount(0));
let proof = generate_withdraw_proof(&faucet_mask, Amount(1000), Some(Amount(99_000)), Amount(0));
// Reveal 90 tokens and 10 confidentially
let reveal_proof = generate_withdraw_proof(
&proof.output_mask,
Amount(10),
Some(Amount(900)),
Amount(90),
);
let reveal_proof = generate_withdraw_proof(&proof.output_mask, Amount(10), Some(Amount(900)), Amount(90));
// Then reveal the rest
let reveal_bucket_proof =
generate_withdraw_proof(&reveal_proof.output_mask, Amount(0), None, Amount(10));
let reveal_bucket_proof = generate_withdraw_proof(&reveal_proof.output_mask, Amount(0), None, Amount(10));

// Transfer faucet funds into account 1
let vars = [
Expand All @@ -260,10 +202,7 @@ fn reveal_confidential_and_transfer() {
("account1", account1.into()),
("account2", account2.into()),
("proof", ManifestValue::new_value(&proof.proof).unwrap()),
(
"reveal_proof",
ManifestValue::new_value(&reveal_proof.proof).unwrap(),
),
("reveal_proof", ManifestValue::new_value(&reveal_proof.proof).unwrap()),
(
"reveal_bucket_proof",
ManifestValue::new_value(&reveal_bucket_proof.proof).unwrap(),
Expand Down Expand Up @@ -303,23 +242,18 @@ fn reveal_confidential_and_transfer() {
.unwrap();

assert_eq!(
result.finalize.execution_results[12]
.decode::<Amount>()
.unwrap(),
result.finalize.execution_results[12].decode::<Amount>().unwrap(),
Amount(10)
);
assert_eq!(
result.finalize.execution_results[13]
.decode::<Amount>()
.unwrap(),
result.finalize.execution_results[13].decode::<Amount>().unwrap(),
Amount(90)
);
}

#[test]
fn attempt_to_reveal_with_unbalanced_proof() {
let (confidential_proof, faucet_mask, _change) =
generate_confidential_proof(Amount(100_000), None);
let (confidential_proof, faucet_mask, _change) = generate_confidential_proof(Amount(100_000), None);
let (mut template_test, faucet, faucet_resx) = setup(confidential_proof);

// Create an account
Expand All @@ -328,15 +262,9 @@ fn attempt_to_reveal_with_unbalanced_proof() {

// Create proof for transfer

let proof =
generate_withdraw_proof(&faucet_mask, Amount(1000), Some(Amount(99_000)), Amount(0));
let proof = generate_withdraw_proof(&faucet_mask, Amount(1000), Some(Amount(99_000)), Amount(0));
// Attempt to reveal more than input - change
let reveal_proof = generate_withdraw_proof(
&proof.output_mask,
Amount(0),
Some(Amount(900)),
Amount(110),
);
let reveal_proof = generate_withdraw_proof(&proof.output_mask, Amount(0), Some(Amount(900)), Amount(110));

// Transfer faucet funds into account 1
let vars = [
Expand All @@ -345,10 +273,7 @@ fn attempt_to_reveal_with_unbalanced_proof() {
("account1", account1.into()),
("account2", account2.into()),
("proof", ManifestValue::new_value(&proof.proof).unwrap()),
(
"reveal_proof",
ManifestValue::new_value(&reveal_proof.proof).unwrap(),
),
("reveal_proof", ManifestValue::new_value(&reveal_proof.proof).unwrap()),
];

// TODO: Propagate error messages from runtime
Expand Down Expand Up @@ -381,17 +306,15 @@ fn attempt_to_reveal_with_unbalanced_proof() {

#[test]
fn multi_commitment_join() {
let (confidential_proof, faucet_mask, _change) =
generate_confidential_proof(Amount(100_000), None);
let (confidential_proof, faucet_mask, _change) = generate_confidential_proof(Amount(100_000), None);
let (mut template_test, faucet, faucet_resx) = setup(confidential_proof);

// Create an account
let (account1, owner1, _k) = template_test.create_owned_account();

// Create proof for transfer

let withdraw_proof1 =
generate_withdraw_proof(&faucet_mask, Amount(1000), Some(Amount(99_000)), Amount(0));
let withdraw_proof1 = generate_withdraw_proof(&faucet_mask, Amount(1000), Some(Amount(99_000)), Amount(0));
let withdraw_proof2 = generate_withdraw_proof(
withdraw_proof1.change_mask.as_ref().unwrap(),
Amount(1000),
Expand Down Expand Up @@ -421,10 +344,7 @@ fn multi_commitment_join() {
"withdraw_proof2",
ManifestValue::new_value(&withdraw_proof2.proof).unwrap(),
),
(
"join_proof",
ManifestValue::new_value(&join_proof.proof).unwrap(),
),
("join_proof", ManifestValue::new_value(&join_proof.proof).unwrap()),
];
let result = template_test
.execute_and_commit_manifest(
Expand Down Expand Up @@ -458,22 +378,7 @@ fn multi_commitment_join() {
)
.unwrap();

assert_eq!(
result.finalize.execution_results[3]
.decode::<u32>()
.unwrap(),
1
);
assert_eq!(
result.finalize.execution_results[7]
.decode::<u32>()
.unwrap(),
2
);
assert_eq!(
result.finalize.execution_results[9]
.decode::<u32>()
.unwrap(),
1
);
assert_eq!(result.finalize.execution_results[3].decode::<u32>().unwrap(), 1);
assert_eq!(result.finalize.execution_results[7].decode::<u32>().unwrap(), 2);
assert_eq!(result.finalize.execution_results[9].decode::<u32>().unwrap(), 1);
}

0 comments on commit 9d06a84

Please sign in to comment.