integration.rs 3.2 KB

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