Przeglądaj źródła

example: Add integration test for contract.

parazyd 4 lat temu
rodzic
commit
2505f9ebf6

+ 3 - 0
example/smart-contract/Cargo.toml

@@ -17,6 +17,9 @@ git = "https://github.com/darkrenaissance/pasta_curves"
 branch = "serialization-support"
 features = ["borsh"]
 
+[dev-dependencies]
+darkfi = { path = "../../", features = ["wasm-runtime"] }
+
 [profile.release]
 lto = true
 codegen-units = 1

+ 21 - 0
example/smart-contract/tests/runtime.rs

@@ -0,0 +1,21 @@
+use borsh::BorshSerialize;
+use darkfi::{
+    runtime::{util::serialize_payload, vm_runtime::Runtime},
+    Result,
+};
+use pasta_curves::pallas;
+
+use smart_contract::Args;
+
+#[test]
+fn run_contract() -> Result<()> {
+    let wasm_bytes = std::fs::read("smart_contract.wasm")?;
+    let mut runtime = Runtime::new(&wasm_bytes)?;
+
+    let args = Args { a: pallas::Base::from(777), b: pallas::Base::from(666) };
+    let payload = args.try_to_vec()?;
+
+    let input = serialize_payload(&payload);
+
+    runtime.run(&input)
+}