Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add test #239

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# build artifacts
asset/*.boc
asset/*.dbg.json

# Generated by Cargo
# will have compiled files and executables
target/
Expand Down
4 changes: 4 additions & 0 deletions asset/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
setup:
cargo install --git https://github.com/tonlabs/ever-assembler.git
build:
asm simple.code
4 changes: 4 additions & 0 deletions asset/simple.code
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SETCP0
PUSHINT 40
PUSHINT 2
ADD
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ pub mod smart_contract_info;
pub use self::smart_contract_info::SmartContractInfo;
pub mod error;
pub mod utils;
mod test;

include!("../common/src/info.rs");
59 changes: 59 additions & 0 deletions src/test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
use ton_types::{SliceData, Cell};
use crate::executor::Engine;
use crate::stack::{savelist::SaveList, StackItem};

static DEFAULT_CAPABILITIES: u64 = 0x572e;

fn read_boc(filename: &str) -> Vec<u8> {
let mut bytes = Vec::new();
let mut file = std::fs::File::open(filename).unwrap();
std::io::Read::read_to_end(&mut file, &mut bytes).unwrap();
bytes
}

fn load_boc(filename: &str) -> Cell {
let bytes = read_boc(filename);
ton_types::read_single_root_boc(bytes).unwrap()
}

#[test]
fn test_simple() {
let code = load_boc("asset/simple.boc");
let mut ctrls = SaveList::default();
let params = vec!(
StackItem::int(0x76ef1ea), // magic - should be changed because of structure change
StackItem::int(0), // actions
StackItem::int(0), // msgs
StackItem::int(0), // unix time
StackItem::int(0), // logical time
StackItem::int(0), // transaction time
StackItem::int(0), // rand seed
StackItem::tuple(vec!(
StackItem::int(1000000000), // balance
StackItem::None // balance other
)),
StackItem::default(), // myself
StackItem::None, // global config params
StackItem::None,
StackItem::int(0),
);
ctrls.put(7, &mut StackItem::tuple(vec!(StackItem::tuple(params)))).unwrap();

let mut engine = Engine::with_capabilities(DEFAULT_CAPABILITIES).setup_with_libraries(
SliceData::load_cell_ref(&code).unwrap(),
Some(ctrls),
None,
None,
vec!());
engine.dump_ctrls(false);
engine.execute().unwrap();
let stack = engine.stack().get(0).as_integer().unwrap();
println!("stack {:?}", stack);
println!("C3 {:?}", engine.ctrl(3));
let output = engine.ctrl(4).unwrap().as_cell().unwrap();
println!("C4 {:?}", output);
let actions = engine.ctrl(5).unwrap().as_cell().unwrap();
println!("C5 {:?}", actions);
println!("{:?}", engine.gas_used());
assert_eq!(engine.gas_used(), 93);
}