integration.rs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /* This file is part of DarkFi (https://dark.fi)
  2. *
  3. * Copyright (C) 2020-2022 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::{tx::Transaction, Result};
  19. use darkfi_sdk::{
  20. crypto::{constants::MERKLE_DEPTH, MerkleNode, TokenId},
  21. incrementalmerkletree::{bridgetree::BridgeTree, Tree},
  22. pasta::{group::ff::Field, pallas},
  23. tx::ContractCall,
  24. };
  25. use darkfi_serial::Encodable;
  26. use log::{debug, info};
  27. use rand::rngs::OsRng;
  28. use darkfi_dao_contract::{
  29. client::{build_dao_mint_tx, MerkleTree},
  30. DaoFunction,
  31. };
  32. mod harness;
  33. use harness::{init_logger, DaoTestHarness};
  34. // TODO: Anonymity leaks in this proof of concept:
  35. //
  36. // * Vote updates are linked to the proposal_bulla
  37. // * Nullifier of vote will link vote with the coin when it's spent
  38. // TODO: strategize and cleanup Result/Error usage
  39. // TODO: fix up code doc
  40. // TODO: Commenting this test until it works properly
  41. //#[async_std::test]
  42. async fn integration_test() -> Result<()> {
  43. init_logger()?;
  44. let mut th = DaoTestHarness::new().await?;
  45. // Money parameters
  46. //let xdrk_supply = 1_000_000;
  47. //let xrdk_token_id = TokenId::from(pallas::Base::random(&mut OsRng));
  48. // Governance token parameters
  49. //let gdrk_supply = 1_000_000;
  50. let gdrk_token_id = TokenId::from(pallas::Base::random(&mut OsRng));
  51. // DAO parameters
  52. let dao_proposer_limit = 110;
  53. let dao_quorum = 110;
  54. let dao_approval_ratio_quot = 1;
  55. let dao_approval_ratio_base = 2;
  56. // =======================================================
  57. // Dao::Mint
  58. //
  59. // Create the DAO bulla
  60. // =======================================================
  61. debug!(target: "demo", "Stage 1. Creating DAO bulla");
  62. let dao_bulla_blind = pallas::Base::random(&mut OsRng);
  63. info!("[Alice] =========================");
  64. info!("[Alice] Building Dao::Mint params");
  65. info!("[Alice] =========================");
  66. let (params, proofs) = build_dao_mint_tx(
  67. dao_proposer_limit,
  68. dao_quorum,
  69. dao_approval_ratio_quot,
  70. dao_approval_ratio_base,
  71. gdrk_token_id,
  72. &th.dao_kp.public,
  73. dao_bulla_blind,
  74. &th.dao_kp.secret,
  75. &th.dao_mint_zkbin,
  76. &th.dao_mint_pk,
  77. )?;
  78. info!("[Alice] ==========================================");
  79. info!("[Alice] Building Dao::Mint transaction with params");
  80. info!("[Alice] ==========================================");
  81. let mut data = vec![DaoFunction::Mint as u8];
  82. params.encode(&mut data)?;
  83. let calls = vec![ContractCall { contract_id: th.dao_contract_id, data }];
  84. let proofs = vec![proofs];
  85. let mut tx = Transaction { calls, proofs, signatures: vec![] };
  86. let sigs = tx.create_sigs(&mut OsRng, &[])?;
  87. tx.signatures = vec![sigs];
  88. info!("[Alice] ===============================");
  89. info!("[Alice] Executing Dao::Mint transaction");
  90. info!("[Alice] ===============================");
  91. th.alice_state.read().await.verify_transactions(&[tx.clone()], true).await?;
  92. // TODO: Witness and add to wallet merkle tree?
  93. let mut dao_tree = MerkleTree::new(100);
  94. let dao_leaf_position = {
  95. let node = MerkleNode::from(params.dao_bulla.inner());
  96. dao_tree.append(&node);
  97. dao_tree.witness().unwrap()
  98. };
  99. debug!(target: "demo", "Created DAO bulla: {:?}", params.dao_bulla.inner());
  100. // =======================================================
  101. // Money::Transfer
  102. //
  103. // Mint the initial supply of treasury token
  104. // and send it all to the DAO directly
  105. // =======================================================
  106. debug!(target: "demo", "Stage 2. Minting treasury token");
  107. Ok(())
  108. }