token_mint.rs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* This file is part of DarkFi (https://dark.fi)
  2. *
  3. * Copyright (C) 2020-2024 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 token_mint() -> 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. // Some numbers we want to assert
  28. const BOB_SUPPLY: u64 = 2000000000; // 10 BOB
  29. // Block height to verify against
  30. let current_block_height = 0;
  31. // Initialize harness
  32. let mut th = TestHarness::new(&["money".to_string()], false).await?;
  33. info!("[Bob] Building BOB token mint tx");
  34. let (token_mint_tx, token_mint_params, token_auth_mint_params) =
  35. th.token_mint(BOB_SUPPLY, &Holder::Bob, &Holder::Bob, None, None)?;
  36. for holder in &HOLDERS {
  37. info!("[{holder:?}] Executing BOB token mint tx");
  38. th.execute_token_mint_tx(
  39. holder,
  40. &token_mint_tx,
  41. &token_mint_params,
  42. current_block_height,
  43. )
  44. .await?;
  45. }
  46. th.assert_trees(&HOLDERS);
  47. // Bob gathers his new coin
  48. th.gather_owncoin(
  49. &Holder::Bob,
  50. &token_mint_params.coin,
  51. &token_auth_mint_params.enc_note,
  52. None,
  53. )?;
  54. info!("[Bob] Building BOB token freeze tx");
  55. let (token_frz_tx, token_frz_params) = th.token_freeze(&Holder::Bob)?;
  56. for holder in &HOLDERS {
  57. info!("[{holder:?}] Executing BOB token freeze tx");
  58. th.execute_token_freeze_tx(
  59. holder,
  60. &token_frz_tx,
  61. &token_frz_params,
  62. current_block_height,
  63. )
  64. .await?;
  65. }
  66. th.assert_trees(&HOLDERS);
  67. // Statistics
  68. th.statistics();
  69. // Thanks for reading
  70. Ok(())
  71. })
  72. }