integration.rs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* This file is part of DarkFi (https://dark.fi)
  2. *
  3. * Copyright (C) 2020-2023 Dyne.org foundation
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU Affero General Public License as
  7. * published by the Free Software Foundation, either version 3 of the
  8. * License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU Affero General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Affero General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. use darkfi::Result;
  19. use darkfi_contract_test_harness::{init_logger, Holder, TestHarness};
  20. use log::info;
  21. #[test]
  22. fn money_integration() -> Result<()> {
  23. smol::block_on(async {
  24. init_logger();
  25. // Holders this test will use
  26. const HOLDERS: [Holder; 2] = [Holder::Alice, Holder::Bob];
  27. // Initialize harness
  28. let mut th = TestHarness::new(&["money".to_string()]).await?;
  29. // Current verification slot
  30. let mut verification_slot = 1;
  31. th.generate_slot(verification_slot).await?;
  32. // Drop some money to Alice
  33. info!("[Alice] Building block proposal");
  34. let (alice_proposal_tx, alice_proposal_params) =
  35. th.pow_reward(&Holder::Alice, None, verification_slot, None)?;
  36. for holder in HOLDERS {
  37. info!("[{holder:?}] Executing Alice's block proposal");
  38. th.execute_pow_reward_tx(
  39. &holder,
  40. &alice_proposal_tx,
  41. &alice_proposal_params,
  42. verification_slot,
  43. )
  44. .await?;
  45. }
  46. th.assert_trees(&HOLDERS);
  47. verification_slot += 1;
  48. th.generate_slot(verification_slot).await?;
  49. // And some to Bob
  50. info!("[Bob] Building block proposal");
  51. let (bob_proposal_tx, bob_proposal_params) =
  52. th.pow_reward(&Holder::Bob, None, verification_slot, None)?;
  53. for holder in HOLDERS {
  54. info!("[{holder:?}] Executing Alice's block proposal");
  55. th.execute_pow_reward_tx(
  56. &holder,
  57. &bob_proposal_tx,
  58. &bob_proposal_params,
  59. verification_slot,
  60. )
  61. .await?;
  62. }
  63. th.assert_trees(&HOLDERS);
  64. verification_slot += 1;
  65. th.generate_slot(verification_slot).await?;
  66. // Statistics
  67. th.statistics();
  68. // Thanks for reading
  69. Ok(())
  70. })
  71. }