integration.rs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 std::time::Instant;
  19. use darkfi::Result;
  20. use darkfi_sdk::{
  21. crypto::{
  22. poseidon_hash,
  23. Keypair,
  24. MerkleNode,
  25. Nullifier,
  26. MAP_CONTRACT_ID
  27. },
  28. incrementalmerkletree::Tree,
  29. pasta::pallas,
  30. // db::{db_lookup, db_get} link error?
  31. };
  32. use log::{info, debug};
  33. use rand::rngs::OsRng;
  34. use darkfi_map_contract::MAP_CONTRACT_ENTRIES_TREE;
  35. use darkfi_serial::{deserialize, serialize};
  36. mod harness;
  37. use harness::{init_logger, MapTestHarness};
  38. #[async_std::test]
  39. async fn map_integration() -> Result<()> {
  40. let current_slot = 0;
  41. init_logger();
  42. let mut th = MapTestHarness::new().await?;
  43. let (alice_tx, alice_params) = th.set(
  44. th.alice.keypair.secret,
  45. pallas::Base::from(1), // lock
  46. pallas::Base::from(1), // car
  47. pallas::Base::from(2), // key
  48. pallas::Base::from(4), // value
  49. )?;
  50. info!(target: "map", "[Faucet] =============================");
  51. info!(target: "map", "[Faucet] Executing Alice set tx");
  52. info!(target: "map", "[Faucet] =============================");
  53. let timer = Instant::now();
  54. let erroneous_txs = th
  55. .faucet
  56. .state
  57. .read()
  58. .await
  59. .verify_transactions(&[alice_tx.clone()], current_slot, true)
  60. .await?;
  61. assert!(erroneous_txs.is_empty());
  62. info!(target: "map", "[Alice] =============================");
  63. info!(target: "map", "[Alice] Executing Alice set tx");
  64. info!(target: "map", "[Alice] =============================");
  65. let timer = Instant::now();
  66. let erroneous_txs = th
  67. .alice
  68. .state
  69. .read()
  70. .await
  71. .verify_transactions(&[alice_tx.clone()], current_slot, true)
  72. .await?;
  73. debug!("error_tx: {:?}", erroneous_txs);
  74. assert!(erroneous_txs.is_empty());
  75. // let slot = poseidon_hash([alice_params.account, alice_params.key]);
  76. // let db = db_lookup(*MAP_CONTRACT_ID, MAP_CONTRACT_ENTRIES_TREE)?;
  77. // db_get(db, &serialize(&slot))?;
  78. // match db_get(db, &serialize(&slot))? {
  79. // None => panic!("slot should be set"),
  80. // Some(locked) => {
  81. // let lock: pallas::Base = deserialize(&locked)?;
  82. // assert!(lock == pallas::Base::one());
  83. // }
  84. // };
  85. // match db_get(db, &serialize(&(slot.add(&pallas::Base::one()))))? {
  86. // None => panic!("slot + 1 should be set"),
  87. // Some(value) => {
  88. // let value: pallas::Base = deserialize(&value)?;
  89. // assert!(value == pallas::Base::from(4));
  90. // }
  91. // };
  92. Ok(())
  93. }