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.
* WIP: add get call trace api * Update * make the build pass
- Loading branch information
Showing
14 changed files
with
294 additions
and
70 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright © Aptos Foundation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use super::new_test_context; | ||
use aptos_api_test_context::current_function_name; | ||
use serde_json::json; | ||
|
||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)] | ||
async fn test_simple_call_trace() { | ||
let mut context = new_test_context(current_function_name!()); | ||
let creator = &mut context.gen_account(); | ||
let owner = &mut context.gen_account(); | ||
let txn1 = context.mint_user_account(creator).await; | ||
let txn2 = context.account_transfer(creator, owner, 100_000); | ||
|
||
context.commit_block(&vec![txn1, txn2]).await; | ||
|
||
let resp = context | ||
.post( | ||
"/view", | ||
json!({ | ||
"function":"0x1::coin::balance", | ||
"arguments": vec![owner.address().to_string()], | ||
"type_arguments": vec!["0x1::aptos_coin::AptosCoin"], | ||
}), | ||
) | ||
.await; | ||
|
||
context.check_golden_output_no_prune(resp); | ||
} |
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
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
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,33 @@ | ||
use poem_openapi_derive::Object; | ||
use serde::{Deserialize, Serialize}; | ||
use move_core_types::call_trace::InternalCallTrace; | ||
|
||
/// A call trace | ||
/// | ||
/// This is a representation of the debug call trace | ||
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize, Object)] | ||
pub struct CallTrace { | ||
pub pc: u16, | ||
pub module_id: String, | ||
pub func_name: String, | ||
pub inputs: Vec<String>, | ||
pub outputs: Vec<String>, | ||
pub type_args: Vec<String>, | ||
pub sub_traces: Vec<CallTrace>, | ||
} | ||
|
||
impl From<InternalCallTrace> for CallTrace { | ||
fn from(value: InternalCallTrace) -> Self { | ||
CallTrace { | ||
pc: value.pc, | ||
module_id: value.module_id, | ||
func_name: value.func_name, | ||
inputs: value.inputs, | ||
outputs: value.outputs, | ||
type_args: value.type_args, | ||
sub_traces: value.sub_traces.into_iter().enumerate().map(|(_, trace)| { | ||
CallTrace::from(trace) | ||
}).collect(), | ||
} | ||
} | ||
} |
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
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
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,57 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
const CALL_STACK_SIZE_LIMIT: usize = 1024; | ||
|
||
/// A call trace | ||
/// | ||
/// This is a representation of the debug call trace | ||
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] | ||
pub struct InternalCallTrace { | ||
pub pc: u16, | ||
pub module_id: String, | ||
pub func_name: String, | ||
pub inputs: Vec<String>, | ||
pub outputs: Vec<String>, | ||
pub type_args: Vec<String>, | ||
pub sub_traces: Vec<InternalCallTrace>, | ||
} | ||
|
||
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] | ||
pub struct CallTraces(Vec<InternalCallTrace>); | ||
|
||
impl CallTraces { | ||
pub fn new() -> Self { | ||
CallTraces(vec![]) | ||
} | ||
|
||
pub fn push(&mut self, trace: InternalCallTrace) -> Result<(), InternalCallTrace> { | ||
if self.0.len() < CALL_STACK_SIZE_LIMIT { | ||
self.0.push(trace); | ||
Ok(()) | ||
} else { | ||
Err(trace) | ||
} | ||
} | ||
|
||
pub fn pop(&mut self) -> Option<InternalCallTrace> { | ||
self.0.pop() | ||
} | ||
|
||
pub fn set_outputs(&mut self, outputs: Vec<String>) { | ||
let length = self.0.len(); | ||
self.0[length - 1].outputs = outputs | ||
} | ||
|
||
pub fn push_call_trace(&mut self, call_trace: InternalCallTrace) { | ||
let length = self.0.len(); | ||
self.0[length - 1].sub_traces.push(call_trace); | ||
} | ||
|
||
pub fn len(&self) -> usize { | ||
self.0.len() | ||
} | ||
|
||
pub fn root(&mut self) -> Option<InternalCallTrace> { | ||
self.0.pop() | ||
} | ||
} |
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 |
---|---|---|
|
@@ -25,3 +25,4 @@ pub mod u256; | |
mod unit_tests; | ||
pub mod value; | ||
pub mod vm_status; | ||
pub mod call_trace; |
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
Oops, something went wrong.