validator.rs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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::{
  19. blockchain::BlockInfo,
  20. util::time::TimeKeeper,
  21. validator::{Validator, ValidatorConfig, ValidatorPtr},
  22. Result,
  23. };
  24. use darkfi_contract_test_harness::{init_logger, vks};
  25. struct Harness {
  26. pub _alice: ValidatorPtr,
  27. pub _bob: ValidatorPtr,
  28. }
  29. impl Harness {
  30. async fn new() -> Result<Self> {
  31. // Generate default genesis block
  32. let genesis_block = BlockInfo::default();
  33. // Generate validators configuration
  34. // NOTE: we are not using consensus constants here so we
  35. // don't get circular dependencies.
  36. let time_keeper = TimeKeeper::new(genesis_block.header.timestamp, 10, 90, 0);
  37. let config = ValidatorConfig::new(time_keeper, genesis_block, vec![]);
  38. // Generate validators using pregenerated vks
  39. let sled_db = sled::Config::new().temporary(true).open()?;
  40. vks::inject(&sled_db)?;
  41. let _alice = Validator::new(&sled_db, config.clone()).await?;
  42. let sled_db = sled::Config::new().temporary(true).open()?;
  43. vks::inject(&sled_db)?;
  44. let _bob = Validator::new(&sled_db, config).await?;
  45. Ok(Self { _alice, _bob })
  46. }
  47. }
  48. #[async_std::test]
  49. async fn add_blocks() -> Result<()> {
  50. init_logger();
  51. // Initialize harness
  52. let _th = Harness::new().await?;
  53. // Thanks for reading
  54. Ok(())
  55. }