Просмотр исходного кода

dao::propose(): fix get_tx_location(), by making the test-harness write the txs and their locs to the DB inside wallet.add_transactions()

zero 2 лет назад
Родитель
Сommit
88c39e5861

+ 1 - 2
src/contract/dao/src/entrypoint/propose.rs

@@ -151,8 +151,7 @@ pub(crate) fn dao_propose_process_instruction(
         let tx_hash_data: [u8; 32] = coin_root_data[0..32].try_into().unwrap();
         let tx_hash = TransactionHash(tx_hash_data);
         // Get block_height where tx_hash was confirmed
-        //let (tx_height, _) = get_tx_location(&tx_hash)?;
-        let tx_height = 0;
+        let (tx_height, _) = get_tx_location(&tx_hash)?;
         let current_height = get_verifying_block_height();
         if current_height - tx_height > PROPOSAL_SNAPSHOT_CUTOFF_LIMIT {
             msg!("[Dao::Propose] Error: Snapshot is too old. Current height: {}, snapshot height: {}",

+ 39 - 27
src/contract/dao/tests/integration.rs

@@ -81,7 +81,7 @@ fn integration_test() -> Result<()> {
         const PROPOSAL_AMOUNT: u64 = 250_000_000;
 
         // Block height to verify against
-        let current_block_height = 0;
+        let mut current_block_height = 0;
 
         // DAO parameters
         let dao_keypair = th.holders.get(&Holder::Dao).unwrap().keypair;
@@ -95,35 +95,12 @@ fn integration_test() -> Result<()> {
             bulla_blind: Blind::random(&mut OsRng),
         };
 
-        // ====================
-        // Dao::Mint
-        // Create the DAO bulla
-        // ====================
-        info!("Stage 1. Creating DAO bulla");
-
-        info!("[Dao] Building DAO mint tx");
-        let (dao_mint_tx, dao_mint_params, fee_params) =
-            th.dao_mint(&Holder::Alice, &dao, &dao_keypair, current_block_height).await?;
-
-        for holder in &HOLDERS {
-            info!("[{holder:?}] Executing DAO Mint tx");
-            th.execute_dao_mint_tx(
-                holder,
-                dao_mint_tx.clone(),
-                &dao_mint_params,
-                &fee_params,
-                current_block_height,
-                true,
-            )
-            .await?;
-        }
-
-        th.assert_trees(&HOLDERS);
-
         // =======================================
         // Airdrop some treasury tokens to the DAO
         // =======================================
         info!("[Dao] Building DAO airdrop tx");
+        assert_eq!(current_block_height, 0);
+
         let spend_hook =
             FuncRef { contract_id: *DAO_CONTRACT_ID, func_code: DaoFunction::Exec as u8 }
                 .to_func_id();
@@ -133,7 +110,7 @@ fn integration_test() -> Result<()> {
                 &Holder::Dao,
                 DRK_TOKEN_SUPPLY,
                 Some(spend_hook),
-                Some(dao_mint_params.dao_bulla.inner()),
+                Some(dao.to_bulla().inner()),
             )
             .await?;
 
@@ -155,6 +132,35 @@ fn integration_test() -> Result<()> {
         assert!(_dao_tokens[0].note.token_id == *DARK_TOKEN_ID);
         assert!(_dao_tokens[0].note.value == DRK_TOKEN_SUPPLY);
 
+        current_block_height += 1;
+
+        // ====================
+        // Dao::Mint
+        // Create the DAO bulla
+        // ====================
+        info!("Stage 1. Creating DAO bulla");
+
+        info!("[Dao] Building DAO mint tx");
+        let (dao_mint_tx, dao_mint_params, fee_params) =
+            th.dao_mint(&Holder::Alice, &dao, &dao_keypair, current_block_height).await?;
+
+        for holder in &HOLDERS {
+            info!("[{holder:?}] Executing DAO Mint tx");
+            th.execute_dao_mint_tx(
+                holder,
+                dao_mint_tx.clone(),
+                &dao_mint_params,
+                &fee_params,
+                current_block_height,
+                true,
+            )
+            .await?;
+        }
+
+        th.assert_trees(&HOLDERS);
+
+        current_block_height += 1;
+
         // ======================================
         // Mint the governance token to 3 holders
         // ======================================
@@ -262,6 +268,8 @@ fn integration_test() -> Result<()> {
         assert!(_charlie_tokens[0].note.token_id == gov_token_id);
         assert!(_charlie_tokens[0].note.value == CHARLIE_GOV_SUPPLY);
 
+        current_block_height += 1;
+
         // ================
         // Dao::Propose
         // Propose the vote
@@ -312,6 +320,8 @@ fn integration_test() -> Result<()> {
 
         th.assert_trees(&HOLDERS);
 
+        current_block_height += 1;
+
         // =====================================
         // Dao::Vote
         // Proposal is accepted. Start the vote.
@@ -459,6 +469,8 @@ fn integration_test() -> Result<()> {
                 pedersen_commitment_u64(total_yes_vote_value, total_yes_vote_blind)
         );
 
+        current_block_height += 1;
+
         // ================
         // Dao::Exec
         // Execute the vote

+ 11 - 1
src/contract/test-harness/src/lib.rs

@@ -210,7 +210,17 @@ impl Wallet {
             benchmark_wasm_calls(callname, &self.validator, &tx, block_height);
         }
 
-        self.validator.add_transactions(&[tx], block_height, true, verify_fees).await?;
+        self.validator.add_transactions(&[tx.clone()], block_height, true, verify_fees).await?;
+
+        // Write the data
+        {
+            let blockchain = &self.validator.blockchain;
+            let txs = &blockchain.transactions;
+            txs.insert(&[tx.clone()]).expect("insert tx");
+            txs.insert_location(&[blake3::Hash::from_bytes(tx.hash().0)], block_height)
+                .expect("insert loc");
+        }
+
         Ok(())
     }
 }