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

contract/money: Delete redundant tests

parazyd 2 лет назад
Родитель
Сommit
9c44bfb9ed

+ 2 - 14
src/contract/money/Makefile

@@ -56,12 +56,6 @@ test-mint-pay-swap: all
 		--features=no-entrypoint,client \
 		--test mint_pay_swap
 
-test-txs-verification: all
-	RUSTFLAGS="$(RUSTFLAGS)" $(CARGO) test --target=$(RUST_TARGET) \
-		--release --package $(PKGNAME) \
-		--features=no-entrypoint,client \
-		--test txs_verification
-
 test-genesis-mint: all
 	RUSTFLAGS="$(RUSTFLAGS)" $(CARGO) test --target=$(RUST_TARGET) \
 		--release --package $(PKGNAME) \
@@ -80,13 +74,7 @@ test-token-mint: all
 		--features=no-entrypoint,client \
 		--test token_mint
 
-bench:
-	RUSTFLAGS="$(RUSTFLAGS)" $(CARGO) test --target=$(RUST_TARGET) \
-		--release --package $(PKGNAME) \
-		--features=no-entrypoint,client \
-		--test verification_bench
-
-test: test-integration test-mint-pay-swap test-txs-verification test-genesis-mint test-pow-reward test-token-mint
+test: test-integration test-mint-pay-swap test-genesis-mint test-pow-reward test-token-mint
 
 clippy: all
 	RUSTFLAGS="$(RUSTFLAGS)" $(CARGO) clippy --target=$(WASM_TARGET) \
@@ -102,4 +90,4 @@ clean:
 		--release --package $(PKGNAME)
 	rm -f $(PROOFS_BIN) $(WASM_BIN)
 
-.PHONY: all test-integration test-mint-pay-swap test-txs-verification test-genesis-mint test-pow-reward bench test clippy clean
+.PHONY: all test-integration test-mint-pay-swap test-genesis-mint test-pow-reward test clippy clean

+ 0 - 170
src/contract/money/tests/txs_verification.rs

@@ -1,170 +0,0 @@
-/* This file is part of DarkFi (https://dark.fi)
- *
- * Copyright (C) 2020-2024 Dyne.org foundation
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <https://www.gnu.org/licenses/>.
- */
-
-//! Test for transaction verification correctness between Alice and Bob.
-//!
-//! We first mint Alice some tokens, and then she send some to Bob
-//! a couple of times, including some double spending transactions.
-//!
-//! With this test, we want to confirm the transactions execution works
-//! between multiple parties, with detection of erroneous transactions.
-
-use darkfi::Result;
-use darkfi_contract_test_harness::{init_logger, Holder, TestHarness, TxAction};
-use log::info;
-
-#[test]
-fn txs_verification() -> Result<()> {
-    smol::block_on(async {
-        init_logger();
-
-        // Holders this test will use
-        const HOLDERS: [Holder; 3] = [Holder::Faucet, Holder::Alice, Holder::Bob];
-
-        // Some numbers we want to assert
-        const ALICE_INITIAL: u64 = 100;
-
-        // Alice = 50 ALICE
-        // Bob = 50 ALICE
-        const ALICE_SEND: u64 = ALICE_INITIAL - 50;
-
-        // Block height to verify against
-        let current_block_height = 0;
-
-        // Initialize harness
-        let mut th = TestHarness::new(&["money".to_string()], false).await?;
-
-        let mut alice_owncoins = vec![];
-        let mut bob_owncoins = vec![];
-
-        info!(target: "money", "[Alice] ================================");
-        info!(target: "money", "[Alice] Building token mint tx for Alice");
-        info!(target: "money", "[Alice] ================================");
-        let (token_mint_tx, token_mint_params, token_auth_mint_params) =
-            th.token_mint(ALICE_INITIAL, &Holder::Alice, &Holder::Alice, None, None)?;
-
-        for holder in &HOLDERS {
-            info!(target: "money", "[{holder:?}] =============================");
-            info!(target: "money", "[{holder:?}] Executing Alice token mint tx");
-            info!(target: "money", "[{holder:?}] =============================");
-            th.execute_token_mint_tx(
-                holder,
-                &token_mint_tx,
-                &token_mint_params,
-                current_block_height,
-            )
-            .await?;
-        }
-
-        th.assert_trees(&HOLDERS);
-
-        // Alice gathers her new owncoin
-        let alice_oc = th.gather_owncoin(
-            &Holder::Alice,
-            &token_mint_params.coin,
-            &token_auth_mint_params.enc_note,
-            None,
-        )?;
-        let alice_token_id = alice_oc.note.token_id;
-        alice_owncoins.push(alice_oc);
-
-        // Now Alice can send a little bit of funds to Bob.
-        // We can duplicate this transaction to simulate double spending.
-        let duplicates = 3; // Change this number to >1 to double spend
-        let mut transactions = vec![];
-        let mut txs_params = vec![];
-        for i in 0..duplicates {
-            info!(target: "money", "[Alice] ======================================================");
-            info!(target: "money", "[Alice] Building Money::Transfer params for payment {i} to Bob");
-            info!(target: "money", "[Alice] ======================================================");
-            let (transfer_tx, transfer_params, spent_coins) = th.transfer(
-                ALICE_SEND,
-                &Holder::Alice,
-                &Holder::Bob,
-                &alice_owncoins,
-                alice_token_id,
-            )?;
-
-            // Validating transfer params
-            assert!(transfer_params.inputs.len() == 1);
-            assert!(transfer_params.outputs.len() == 2);
-            assert!(spent_coins.len() == 1);
-
-            // Now we simulate nodes verification, as transactions come one by one.
-            // Validation should pass, even when we are trying to double spent.
-            for holder in &HOLDERS {
-                info!(target: "money", "[{holder:?}] ==================================");
-                info!(target: "money", "[{holder:?}] Verifying Alice2Bob payment tx {i}");
-                info!(target: "money", "[{holder:?}] ==================================");
-                th.verify_transfer_tx(holder, &transfer_tx, current_block_height).await?;
-            }
-
-            transactions.push(transfer_tx);
-            txs_params.push(transfer_params);
-        }
-        alice_owncoins = vec![];
-        assert_eq!(transactions.len(), duplicates);
-        assert_eq!(txs_params.len(), duplicates);
-
-        // Now we can try to execute the transactions sequentialy.
-        // Each node will detect the duplicate txs and filter them out,
-        // then only apply the first txs from the set.
-        for holder in &HOLDERS {
-            info!(target: "money", "[{holder:?}] ==============================");
-            info!(target: "money", "[{holder:?}] Executing Alice2Bob payment tx");
-            info!(target: "money", "[{holder:?}] ==============================");
-            th.execute_erroneous_txs(
-                TxAction::MoneyTransfer,
-                holder,
-                &transactions,
-                current_block_height,
-                duplicates - 1,
-            )
-            .await?;
-            th.execute_transfer_tx(
-                holder,
-                &transactions[0],
-                &txs_params[0],
-                current_block_height,
-                true,
-            )
-            .await?;
-        }
-
-        th.assert_trees(&HOLDERS);
-
-        // Bob should now have the new OwnCoin.
-        let bob_oc =
-            th.gather_owncoin_from_output(&Holder::Bob, &txs_params[0].outputs[0], None)?;
-        bob_owncoins.push(bob_oc);
-
-        // Alice should now have one OwnCoin with the change from the above transaction.
-        let alice_oc =
-            th.gather_owncoin_from_output(&Holder::Alice, &txs_params[0].outputs[1], None)?;
-        alice_owncoins.push(alice_oc);
-
-        assert!(alice_owncoins.len() == 1);
-        assert!(bob_owncoins.len() == 1);
-
-        // Statistics
-        th.statistics();
-
-        // Thanks for reading
-        Ok(())
-    })
-}

+ 0 - 269
src/contract/money/tests/verification_bench.rs

@@ -1,269 +0,0 @@
-/* This file is part of DarkFi (https://dark.fi)
- *
- * Copyright (C) 2020-2024 Dyne.org foundation
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <https://www.gnu.org/licenses/>.
- */
-
-use std::{env, str::FromStr};
-
-use darkfi::Result;
-use darkfi_contract_test_harness::{init_logger, Holder, TestHarness};
-use log::info;
-use rand::{prelude::IteratorRandom, Rng};
-
-#[test]
-#[ignore]
-fn alice2alice_random_amounts() -> Result<()> {
-    smol::block_on(async {
-        init_logger();
-
-        // Holders this test will use
-        const HOLDERS: [Holder; 2] = [Holder::Faucet, Holder::Alice];
-
-        const ALICE_AIRDROP: u64 = 1000;
-
-        // Block height to verify against
-        let current_block_height = 0;
-
-        // n transactions to loop
-        let mut n = 3;
-        for arg in env::args() {
-            match usize::from_str(&arg) {
-                Ok(v) => {
-                    n = v;
-                    break
-                }
-                Err(_) => continue,
-            };
-        }
-
-        // Initialize harness
-        let mut th = TestHarness::new(&["money".to_string()], false).await?;
-
-        info!(target: "money", "[Faucet] ========================");
-        info!(target: "money", "[Faucet] Building Alice's airdrop");
-        info!(target: "money", "[Faucet] ========================");
-        let (airdrop_tx, airdrop_params) =
-            th.airdrop_native(ALICE_AIRDROP, &Holder::Alice, None, None)?;
-
-        for holder in &HOLDERS {
-            info!(target: "money", "[{holder:?}] ==========================");
-            info!(target: "money", "[{holder:?}] Executing Alice airdrop tx");
-            info!(target: "money", "[{holder:?}] ==========================");
-            th.execute_airdrop_native_tx(
-                holder,
-                &airdrop_tx,
-                &airdrop_params,
-                current_block_height,
-            )
-            .await?;
-        }
-
-        th.assert_trees(&HOLDERS);
-
-        // Gather new owncoins
-        let mut owncoins = vec![];
-        let owncoin =
-            th.gather_owncoin_from_output(&Holder::Alice, &airdrop_params.outputs[0], None)?;
-        let token_id = owncoin.note.token_id;
-        owncoins.push(owncoin);
-
-        // Execute transactions loop
-        for i in 0..n {
-            info!(target: "money", "[Alice] ===============================================");
-            info!(target: "money", "[Alice] Building Money::Transfer params for transfer {}", i);
-            info!(target: "money", "[Alice] Alice coins: {}", owncoins.len());
-            for (i, c) in owncoins.iter().enumerate() {
-                info!(target: "money", "[Alice] \t coin {} value: {}", i, c.note.value);
-            }
-            let amount = rand::thread_rng().gen_range(1..ALICE_AIRDROP);
-            info!(target: "money", "[Alice] Sending: {}", amount);
-            info!(target: "money", "[Alice] ===============================================");
-            let (tx, params, spent_coins) =
-                th.transfer(amount, &Holder::Alice, &Holder::Alice, &owncoins, token_id)?;
-
-            // Remove the owncoins we've spent
-            for spent in spent_coins {
-                owncoins.retain(|x| x != &spent);
-            }
-
-            // Verify transaction
-            info!(target: "money", "[Faucet] ================================");
-            info!(target: "money", "[Faucet] Executing Alice2Alice payment tx");
-            info!(target: "money", "[Faucet] ================================");
-            th.execute_transfer_tx(&Holder::Faucet, &tx, &params, current_block_height, true)
-                .await?;
-
-            info!(target: "money", "[Alice] ================================");
-            info!(target: "money", "[Alice] Executing Alice2Alice payment tx");
-            info!(target: "money", "[Alice] ================================");
-            th.execute_transfer_tx(&Holder::Alice, &tx, &params, current_block_height, false)
-                .await?;
-
-            // Gather new owncoins
-            owncoins.append(&mut th.gather_multiple_owncoins(&Holder::Alice, &params.outputs)?);
-
-            th.assert_trees(&HOLDERS);
-        }
-
-        // Statistics
-        th.statistics();
-
-        // Thanks for reading
-        Ok(())
-    })
-}
-
-#[test]
-#[ignore]
-fn alice2alice_multiplecoins_random_amounts() -> Result<()> {
-    smol::block_on(async {
-        init_logger();
-
-        // Holders this test will use
-        const HOLDERS: [Holder; 2] = [Holder::Faucet, Holder::Alice];
-
-        // Block height to verify against
-        let current_block_height = 0;
-
-        // N blocks to simulate
-        let mut n = 3;
-        for arg in env::args() {
-            match usize::from_str(&arg) {
-                Ok(v) => {
-                    n = v;
-                    break
-                }
-                Err(_) => continue,
-            };
-        }
-
-        // Initialize harness
-        let mut th = TestHarness::new(&["money".to_string()], false).await?;
-
-        // Mint 10 coins
-        let mut token_ids = vec![];
-        let mut minted_amounts = vec![];
-        let mut owncoins = vec![];
-        for i in 0..10 {
-            let amount = rand::thread_rng().gen_range(2..1000);
-            info!(target: "money", "[Faucet] ===================================================");
-            info!(target: "money", "[Faucet] Building Money::Mint params for Alice's mint for token {} and amount {}", i, amount);
-            info!(target: "money", "[Faucet] ===================================================");
-            let (mint_tx, mint_params, mint_auth_params) =
-                th.token_mint(amount, &Holder::Alice, &Holder::Alice, None, None)?;
-
-            for holder in &HOLDERS {
-                info!(target: "money", "[{holder:?}] =======================");
-                info!(target: "money", "[{holder:?}] Executing Alice mint tx");
-                info!(target: "money", "[{holder:?}] =======================");
-                th.execute_token_mint_tx(holder, &mint_tx, &mint_params, current_block_height)
-                    .await?;
-            }
-
-            th.assert_trees(&HOLDERS);
-
-            // Gather new owncoins
-            let owncoin = th.gather_owncoin(
-                &Holder::Alice,
-                &mint_params.coin,
-                &mint_auth_params.enc_note,
-                None,
-            )?;
-            let token_id = owncoin.note.token_id;
-            owncoins.push(vec![owncoin]);
-            minted_amounts.push(amount);
-            token_ids.push(token_id);
-        }
-
-        // Simulating N blocks
-        for b in 0..n {
-            // Get a random sized sample of owncoins
-            let sample = (0..10)
-                .choose_multiple(&mut rand::thread_rng(), rand::thread_rng().gen_range(1..10));
-            info!(target: "money", "[Alice] =====================================");
-            info!(target: "money", "[Alice] Generating transactions for block: {}", b);
-            info!(target: "money", "[Alice] Coins to use: {:?}", sample);
-            info!(target: "money", "[Alice] =====================================");
-
-            // Generate a transaction for each coin
-            let mut txs = vec![];
-            let mut txs_params = vec![];
-            for index in sample {
-                info!(target: "money", "[Alice] ===============================================");
-                info!(target: "money", "[Alice] Building Money::Transfer params for coin {}", index);
-                let mut coins = owncoins[index].clone();
-                let token_id = token_ids[index];
-                let mint_amount = minted_amounts[index];
-                info!(target: "money", "[Alice] Alice coins: {}", coins.len());
-                for (i, c) in coins.iter().enumerate() {
-                    info!(target: "money", "[Alice] \t coin {} value: {}", i, c.note.value);
-                }
-                let amount = rand::thread_rng().gen_range(1..mint_amount);
-                info!(target: "money", "[Alice] Sending: {}", amount);
-                info!(target: "money", "[Alice] ===============================================");
-                let (tx, params, spent_coins) =
-                    th.transfer(amount, &Holder::Alice, &Holder::Alice, &coins, token_id)?;
-
-                // Remove the owncoins we've spent
-                for spent in spent_coins {
-                    coins.retain(|x| x != &spent);
-                }
-
-                // Gather new owncoins
-                coins.append(&mut th.gather_multiple_owncoins(&Holder::Alice, &params.outputs)?);
-
-                // Store transaction and its params
-                txs.push(tx);
-                txs_params.push(params);
-
-                // Replace coins
-                owncoins[index] = coins;
-            }
-
-            info!(target: "money", "[Faucet] =================================");
-            info!(target: "money", "[Faucet] Executing Alice2Alice payment txs");
-            info!(target: "money", "[Faucet] =================================");
-            th.execute_multiple_transfer_txs(
-                &Holder::Faucet,
-                &txs,
-                &txs_params,
-                current_block_height,
-                true,
-            )
-            .await?;
-
-            info!(target: "money", "[Alice] =================================");
-            info!(target: "money", "[Alice] Executing Alice2Alice payment txs");
-            info!(target: "money", "[Alice] =================================");
-            th.execute_multiple_transfer_txs(
-                &Holder::Alice,
-                &txs,
-                &txs_params,
-                current_block_height,
-                false,
-            )
-            .await?;
-
-            th.assert_trees(&HOLDERS);
-        }
-
-        // Statistics
-        th.statistics();
-
-        // Thanks for reading
-        Ok(())
-    })
-}