Skip to content

Commit 3de78fd

Browse files
committed
add test
1 parent af953c3 commit 3de78fd

File tree

5 files changed

+72
-0
lines changed

5 files changed

+72
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# build artifacts
2+
asset/*.boc
3+
asset/*.dbg.json
4+
15
# Generated by Cargo
26
# will have compiled files and executables
37
target/

asset/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
setup:
2+
cargo install --git https://github.com/tonlabs/ever-assembler.git
3+
build:
4+
asm simple.code

asset/simple.code

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
SETCP0
2+
PUSHINT 40
3+
PUSHINT 2
4+
ADD

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@ pub mod smart_contract_info;
2424
pub use self::smart_contract_info::SmartContractInfo;
2525
pub mod error;
2626
pub mod utils;
27+
mod test;
2728

2829
include!("../common/src/info.rs");

src/test.rs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
use ton_types::{SliceData, Cell};
2+
use crate::executor::Engine;
3+
use crate::stack::{savelist::SaveList, StackItem};
4+
5+
static DEFAULT_CAPABILITIES: u64 = 0x572e;
6+
7+
fn read_boc(filename: &str) -> Vec<u8> {
8+
let mut bytes = Vec::new();
9+
let mut file = std::fs::File::open(filename).unwrap();
10+
std::io::Read::read_to_end(&mut file, &mut bytes).unwrap();
11+
bytes
12+
}
13+
14+
fn load_boc(filename: &str) -> Cell {
15+
let bytes = read_boc(filename);
16+
ton_types::read_single_root_boc(bytes).unwrap()
17+
}
18+
19+
#[test]
20+
fn test_simple() {
21+
let code = load_boc("asset/simple.boc");
22+
let mut ctrls = SaveList::default();
23+
let params = vec!(
24+
StackItem::int(0x76ef1ea), // magic - should be changed because of structure change
25+
StackItem::int(0), // actions
26+
StackItem::int(0), // msgs
27+
StackItem::int(0), // unix time
28+
StackItem::int(0), // logical time
29+
StackItem::int(0), // transaction time
30+
StackItem::int(0), // rand seed
31+
StackItem::tuple(vec!(
32+
StackItem::int(1000000000), // balance
33+
StackItem::None // balance other
34+
)),
35+
StackItem::default(), // myself
36+
StackItem::None, // global config params
37+
StackItem::None,
38+
StackItem::int(0),
39+
);
40+
ctrls.put(7, &mut StackItem::tuple(vec!(StackItem::tuple(params)))).unwrap();
41+
42+
let mut engine = Engine::with_capabilities(DEFAULT_CAPABILITIES).setup_with_libraries(
43+
SliceData::load_cell_ref(&code).unwrap(),
44+
Some(ctrls),
45+
None,
46+
None,
47+
vec!());
48+
engine.dump_ctrls(false);
49+
engine.execute().unwrap();
50+
let stack = engine.stack().get(0).as_integer().unwrap();
51+
println!("stack {:?}", stack);
52+
println!("C3 {:?}", engine.ctrl(3));
53+
let output = engine.ctrl(4).unwrap().as_cell().unwrap();
54+
println!("C4 {:?}", output);
55+
let actions = engine.ctrl(5).unwrap().as_cell().unwrap();
56+
println!("C5 {:?}", actions);
57+
println!("{:?}", engine.gas_used());
58+
assert_eq!(engine.gas_used(), 93);
59+
}

0 commit comments

Comments
 (0)