|
| 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