runtime.rs 821 B

1234567891011121314151617181920212223242526272829303132
  1. use borsh::BorshSerialize;
  2. use darkfi::{
  3. runtime::{util::serialize_payload, vm_runtime::Runtime},
  4. serial::serialize,
  5. Result,
  6. };
  7. use pasta_curves::pallas;
  8. use smart_contract::{Args, Foo};
  9. #[test]
  10. fn run_contract() -> Result<()> {
  11. simplelog::TermLogger::init(
  12. simplelog::LevelFilter::Debug,
  13. simplelog::Config::default(),
  14. simplelog::TerminalMode::Mixed,
  15. simplelog::ColorChoice::Auto,
  16. )?;
  17. let wasm_bytes = std::fs::read("smart_contract.wasm")?;
  18. let mut runtime = Runtime::new(&wasm_bytes)?;
  19. let _args = Args { a: pallas::Base::from(777), b: pallas::Base::from(666) };
  20. let _payload = _args.try_to_vec()?;
  21. let args = Foo { a: 777, b: 666 };
  22. let payload = serialize(&args);
  23. let input = serialize_payload(&payload);
  24. runtime.run(&input)
  25. }