Skip to content

Commit

Permalink
Just events
Browse files Browse the repository at this point in the history
  • Loading branch information
pmikolajczyk41 committed Aug 28, 2023
1 parent 70299d7 commit 2f211f6
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 169 deletions.
37 changes: 0 additions & 37 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ parity-scale-codec = { version = "3.6.0" }
ratatui = { version = "0.21.0" }
scale-info = { version = "2.5.0" }
thiserror = { version = "1.0.40" }
wat = { version = "1.0.71" }

# Substrate dependencies

Expand Down
3 changes: 0 additions & 3 deletions drink/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,5 @@ parity-scale-codec = { workspace = true }
scale-info = { workspace = true }
thiserror = { workspace = true }

[dev-dependencies]
wat = { workspace = true }

[features]
session = ["contract-transcode"]
91 changes: 0 additions & 91 deletions drink/src/contract_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,94 +140,3 @@ pub fn decode_debug_buffer(buffer: &[u8]) -> Vec<String> {
let decoded = buffer.iter().map(|b| *b as char).collect::<String>();
decoded.split('\n').map(|s| s.to_string()).collect()
}

#[cfg(test)]
mod tests {
use frame_support::sp_runtime::traits::Hash;

use super::*;
use crate::{chain_api::ChainApi, MinimalRuntime, DEFAULT_ACTOR, DEFAULT_GAS_LIMIT};

fn compile_module(contract_name: &str) -> Vec<u8> {
let path = [
std::env::var("CARGO_MANIFEST_DIR")
.as_deref()
.unwrap_or("drink"),
"/test-resources/",
contract_name,
".wat",
]
.concat();
wat::parse_file(path).expect("Failed to parse wat file")
}

#[test]
fn can_upload_code() {
let mut sandbox = Sandbox::<MinimalRuntime>::new().unwrap();
let wasm_binary = compile_module("transfer");
let hash = <<MinimalRuntime as frame_system::Config>::Hashing>::hash(&wasm_binary);

let result = sandbox.upload_contract(wasm_binary, DEFAULT_ACTOR, None);

assert!(result.is_ok());
assert_eq!(hash, result.unwrap().code_hash);
}

#[test]
fn can_deploy_contract() {
let mut sandbox = Sandbox::<MinimalRuntime>::new().unwrap();
let wasm_binary = compile_module("transfer");

let events_before = sandbox.get_current_events();
assert!(events_before.is_empty());

let result = sandbox.deploy_contract(
wasm_binary,
0,
vec![],
vec![],
DEFAULT_ACTOR,
DEFAULT_GAS_LIMIT,
None,
);
assert!(result.result.is_ok());
assert!(!result.result.unwrap().result.did_revert());

let events = result.events.expect("Drink should collect events");
assert!(!events.is_empty());
}

#[test]
fn can_call_contract() {
let mut sandbox = Sandbox::<MinimalRuntime>::new().unwrap();
let wasm_binary = compile_module("transfer");

let result = sandbox.deploy_contract(
wasm_binary,
0,
vec![],
vec![],
DEFAULT_ACTOR,
DEFAULT_GAS_LIMIT,
None,
);

let contract_address = result
.result
.expect("Contract should be deployed")
.account_id;

let result = sandbox.call_contract(
contract_address,
0,
vec![],
DEFAULT_ACTOR,
DEFAULT_GAS_LIMIT,
None,
);
assert!(result.result.is_ok());
assert!(!result.result.unwrap().did_revert());

let events = result.events.expect("Drink should collect events");
}
}
36 changes: 0 additions & 36 deletions drink/test-resources/transfer.wat

This file was deleted.

2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[toolchain]
channel = "nightly-2023-03-20"
channel = "1.70"

0 comments on commit 2f211f6

Please sign in to comment.