Sfoglia il codice sorgente

dao-test: create exec tx

x 3 anni fa
parent
commit
ffcbccf0bd

+ 12 - 20
src/contract/dao/src/dao_exec_client.rs

@@ -46,7 +46,10 @@ use darkfi::{
     Error, Result,
 };
 
-use crate::dao_propose_client::{DaoParams, Proposal};
+use crate::{
+    dao_propose_client::{DaoParams, Proposal},
+    state::DaoExecParams,
+};
 
 pub struct Builder {
     pub proposal: Proposal,
@@ -68,12 +71,11 @@ pub struct Builder {
 impl Builder {
     pub fn build(
         self,
-        // zk_bins: &ZkContractTable
-    )
-    //-> FuncCall
-    {
+        exec_zkbin: &ZkBinary,
+        exec_pk: &ProvingKey,
+    ) -> Result<(DaoExecParams, Vec<Proof>)> {
         debug!(target: "dao_contract::exec::wallet::Builder", "build()");
-        //let mut proofs = vec![];
+        let mut proofs = vec![];
 
         let (proposal_dest_x, proposal_dest_y) = self.proposal.dest.xy();
 
@@ -207,16 +209,12 @@ impl Builder {
             user_data,
         ];
 
-        /*
-        let circuit = ZkCircuit::new(prover_witnesses, zk_bin);
-        let proving_key = &zk_info.proving_key;
-        let input_proof = Proof::create(proving_key, &[circuit], &public_inputs, &mut OsRng)
+        let circuit = ZkCircuit::new(prover_witnesses, exec_zkbin.clone());
+        let input_proof = Proof::create(&exec_pk, &[circuit], &public_inputs, &mut OsRng)
             .expect("DAO::exec() proving error!)");
         proofs.push(input_proof);
-        */
 
-        /*
-        let call_data = CallData {
+        let params = DaoExecParams {
             proposal: proposal_bulla,
             coin_0,
             coin_1,
@@ -225,12 +223,6 @@ impl Builder {
             input_value_commit,
         };
 
-        FuncCall {
-            contract_id: *CONTRACT_ID,
-            func_id: *super::FUNC_ID,
-            call_data: Box::new(call_data),
-            proofs,
-        }
-        */
+        Ok((params, proofs))
     }
 }

+ 5 - 0
src/contract/dao/tests/dao_harness.rs

@@ -88,6 +88,9 @@ pub struct DaoTestHarness {
 
     pub dao_vote_main_zkbin: ZkBinary,
     pub dao_vote_main_pk: ProvingKey,
+
+    pub dao_exec_zkbin: ZkBinary,
+    pub dao_exec_pk: ProvingKey,
 }
 
 impl DaoTestHarness {
@@ -236,6 +239,8 @@ impl DaoTestHarness {
             dao_vote_burn_pk,
             dao_vote_main_zkbin,
             dao_vote_main_pk,
+            dao_exec_zkbin,
+            dao_exec_pk,
         })
     }
 }

+ 19 - 0
src/contract/dao/tests/integration.rs

@@ -860,6 +860,10 @@ async fn integration_test() -> Result<()> {
         &dao_th.money_burn_pk,
     )?;
 
+    let mut data = vec![MoneyFunction::Transfer as u8];
+    xfer_params.encode(&mut data)?;
+    let xfer_call = ContractCall { contract_id: *MONEY_CONTRACT_ID, data };
+
     let builder = dao_exec_client::Builder {
         proposal,
         dao: dao_params.clone(),
@@ -876,6 +880,21 @@ async fn integration_test() -> Result<()> {
         hook_dao_exec: spend_hook,
         signature_secret: exec_signature_secret,
     };
+    let (exec_params, mut exec_proofs) =
+        builder.build(&dao_th.dao_exec_zkbin, &dao_th.dao_exec_pk)?;
+
+    let mut data = vec![DaoFunction::Exec as u8];
+    exec_params.encode(&mut data)?;
+    let exec_call = ContractCall { contract_id: *DAO_CONTRACT_ID, data };
+
+    let calls = vec![xfer_call, exec_call];
+    let proofs = vec![xfer_proofs, exec_proofs];
+    let mut tx = Transaction { calls, proofs, signatures: vec![] };
+    let xfer_sigs = tx.create_sigs(&mut OsRng, &vec![tx_signature_secret])?;
+    let exec_sigs = tx.create_sigs(&mut OsRng, &vec![exec_signature_secret])?;
+    tx.signatures = vec![xfer_sigs, exec_sigs];
+
+    //dao_th.alice_state.read().await.verify_transactions(&[tx.clone()], true).await?;
 
     Ok(())
 }