From a4e52b75aaccbfdc0b4a37ad644055b8d2859405 Mon Sep 17 00:00:00 2001 From: David Rusu Date: Mon, 19 Aug 2024 20:46:48 +0400 Subject: [PATCH] goas: add isolated test for zone fund constraint --- .../atomic_asset_transfer/executor/src/lib.rs | 21 ++++++++++++++++++- .../executor/tests/atomic_transfer.rs | 4 ++-- .../executor/tests/withdraw_ptx.rs | 2 +- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/goas/atomic_asset_transfer/executor/src/lib.rs b/goas/atomic_asset_transfer/executor/src/lib.rs index 7a299a9..d0f0779 100644 --- a/goas/atomic_asset_transfer/executor/src/lib.rs +++ b/goas/atomic_asset_transfer/executor/src/lib.rs @@ -157,7 +157,7 @@ pub fn prove_zone_stf( ledger::DeathProof::from_risc0(goas_risc0_proofs::ZONE_STATE_ID, receipt) } -pub fn prove_zone_fund_withdraw( +pub fn prove_zone_fund_constraint( in_zone_funds: cl::PartialTxInputWitness, zone_note: cl::PartialTxOutputWitness, out_zone_state: &StateWitness, @@ -289,4 +289,23 @@ mod tests { ptx_root: ptx.commit().root(), })) } + + #[test] + fn test_prove_zone_fund_constraint() { + let zone = + ZoneNotes::new_with_balances("ZONE", BTreeMap::from_iter([]), &mut rand::thread_rng()); + + let ptx = PartialTxWitness { + inputs: vec![zone.fund_input_witness()], + outputs: vec![zone.state_note], + }; + + let proof = + prove_zone_fund_constraint(ptx.input_witness(0), ptx.output_witness(0), &zone.state); + + assert!(proof.verify(DeathConstraintPublic { + nf: zone.fund_input_witness().nullifier(), + ptx_root: ptx.commit().root(), + })) + } } diff --git a/goas/atomic_asset_transfer/executor/tests/atomic_transfer.rs b/goas/atomic_asset_transfer/executor/tests/atomic_transfer.rs index ac66029..975831d 100644 --- a/goas/atomic_asset_transfer/executor/tests/atomic_transfer.rs +++ b/goas/atomic_asset_transfer/executor/tests/atomic_transfer.rs @@ -111,7 +111,7 @@ fn test_atomic_transfer() { ), ( zone_a_start.fund_input_witness().nullifier(), - executor::prove_zone_fund_withdraw( + executor::prove_zone_fund_constraint( atomic_transfer_ptx.input_witness(2), // input fund note atomic_transfer_ptx.output_witness(0), // output state note &zone_a_end.state, @@ -129,7 +129,7 @@ fn test_atomic_transfer() { ), ( zone_b_start.fund_input_witness().nullifier(), - executor::prove_zone_fund_withdraw( + executor::prove_zone_fund_constraint( atomic_transfer_ptx.input_witness(4), // input fund note (input #1) atomic_transfer_ptx.output_witness(2), // output state note (output #0) &zone_b_end.state, diff --git a/goas/atomic_asset_transfer/executor/tests/withdraw_ptx.rs b/goas/atomic_asset_transfer/executor/tests/withdraw_ptx.rs index ae189c4..5f099d1 100644 --- a/goas/atomic_asset_transfer/executor/tests/withdraw_ptx.rs +++ b/goas/atomic_asset_transfer/executor/tests/withdraw_ptx.rs @@ -73,7 +73,7 @@ fn test_withdrawal() { ), ( zone_start.fund_input_witness().nullifier(), - executor::prove_zone_fund_withdraw( + executor::prove_zone_fund_constraint( withdraw_ptx.input_witness(1), // input fund note (input #1) withdraw_ptx.output_witness(0), // output state note (output #0) &zone_end.state,