forked from aptos-labs/aptos-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from sentioxyz/dev/pc/add_call_trce
Add a multiple function test and call trace struct
- Loading branch information
Showing
3 changed files
with
139 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
third_party/move/move-vm/integration-tests/src/tests/multi_func_tests.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// Copyright (c) The Diem Core Contributors | ||
// Copyright (c) The Move Contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use crate::compiler::{as_module, compile_units}; | ||
use move_binary_format::errors::VMResult; | ||
use move_core_types::{ | ||
account_address::AccountAddress, | ||
identifier::Identifier, | ||
language_storage::{ModuleId, TypeTag}, | ||
value::{MoveTypeLayout, MoveValue}, | ||
}; | ||
use move_vm_runtime::{move_vm::MoveVM, session::SerializedReturnValues}; | ||
use move_vm_test_utils::InMemoryStorage; | ||
use move_vm_types::gas::UnmeteredGasMeter; | ||
|
||
const TEST_ADDR: AccountAddress = AccountAddress::new([42; AccountAddress::LENGTH]); | ||
|
||
fn run( | ||
ty_args: Vec<TypeTag>, | ||
args: Vec<MoveValue>, | ||
) -> VMResult<Vec<Vec<u8>>> { | ||
let code = r#" | ||
module {{ADDR}}::M { | ||
public fun foo(v1: u64): u64 { | ||
bar(v1) | ||
} | ||
public fun bar(v1: u64): u64 { | ||
1 + v1 | ||
} | ||
} | ||
"#; | ||
let code = code.replace("{{ADDR}}", &format!("0x{}", TEST_ADDR.to_hex())); | ||
|
||
let mut units = compile_units(&code).unwrap(); | ||
let m = as_module(units.pop().unwrap()); | ||
let mut blob = vec![]; | ||
m.serialize(&mut blob).unwrap(); | ||
|
||
let mut storage = InMemoryStorage::new(); | ||
let module_id = ModuleId::new(TEST_ADDR, Identifier::new("M").unwrap()); | ||
storage.publish_or_overwrite_module(module_id.clone(), blob); | ||
|
||
let vm = MoveVM::new(vec![]).unwrap(); | ||
let mut sess = vm.new_session(&storage); | ||
|
||
let fun_name = Identifier::new("foo").unwrap(); | ||
|
||
let args: Vec<_> = args | ||
.into_iter() | ||
.map(|val| val.simple_serialize().unwrap()) | ||
.collect(); | ||
|
||
let SerializedReturnValues { | ||
return_values, | ||
mutable_reference_outputs: _, | ||
} = sess.execute_function_bypass_visibility( | ||
&module_id, | ||
&fun_name, | ||
ty_args, | ||
args, | ||
&mut UnmeteredGasMeter, | ||
)?; | ||
|
||
Ok(return_values | ||
.into_iter() | ||
.map(|(bytes, _layout)| bytes) | ||
.collect()) | ||
} | ||
|
||
fn expect_success( | ||
ty_args: Vec<TypeTag>, | ||
args: Vec<MoveValue>, | ||
expected_layouts: &[MoveTypeLayout], | ||
) { | ||
let return_vals = run(ty_args, args).unwrap(); | ||
assert!(return_vals.len() == expected_layouts.len()); | ||
|
||
for (blob, layout) in return_vals.iter().zip(expected_layouts.iter()) { | ||
MoveValue::simple_deserialize(blob, layout).unwrap(); | ||
} | ||
} | ||
|
||
#[test] | ||
fn multi_func() { | ||
expect_success(vec![], vec![MoveValue::U64(6)], &[ | ||
MoveTypeLayout::U64, | ||
]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters