Skip to content

Commit 4c773f9

Browse files
committed
Add todos
1 parent 7d27679 commit 4c773f9

File tree

3 files changed

+16
-120
lines changed

3 files changed

+16
-120
lines changed

crates/sncast/tests/e2e/script/call.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ async fn test_call_invalid_address() {
8686
}
8787

8888
#[tokio::test]
89-
#[ignore = "TODO(#3120)"]
9089
async fn test_call_invalid_calldata() {
9190
let tempdir =
9291
copy_script_directory_to_tempdir(SCRIPTS_DIR.to_owned() + "/call", Vec::<String>::new());
@@ -97,11 +96,12 @@ async fn test_call_invalid_calldata() {
9796
let snapbox = runner(&args).current_dir(tempdir.path());
9897
let output = snapbox.assert().success();
9998

99+
// TODO(#3120): Update asserted message once displaying is implemented
100100
assert_stdout_contains(
101101
output,
102102
indoc! {r#"
103-
ScriptCommandError::ProviderError(ProviderError::StarknetError(StarknetError::ContractError(ErrorData { msg: "Execution failed. Failure reason: 0x496e70757420746f6f206c6f6e6720666f7220617267756d656e7473 ('Input too long for arguments')." })))
104-
ScriptCommandError::ProviderError(ProviderError::StarknetError(StarknetError::ContractError(ErrorData { msg: "Execution failed. Failure reason: 0x4661696c656420746f20646573657269616c697a6520706172616d202332 ('Failed to deserialize param #2')." })))
103+
ScriptCommandError::ProviderError(ProviderError::StarknetError(StarknetError::ContractError(ErrorData { revert_error: ContractExecutionError::Nested(&ContractExecutionErrorInner { [..] error: ContractExecutionError::Message([2, 161019049007022372777416340987812303282620498837842361643383982666764674358, 97522975666756167445258504733288874551174906205732890712698934399253815901, 0, 0]) }) })))
104+
ScriptCommandError::ProviderError(ProviderError::StarknetError(StarknetError::ContractError(ErrorData { revert_error: ContractExecutionError::Nested(&ContractExecutionErrorInner { [..] error: ContractExecutionError::Message([2, 161019049007017550688154859146124165449376331526496475447250082491572630326, 94023844190060481618082450560698606437386733826467150857039051259452076595, 858923613, 4]) }) }))) command: script run
105105
command: script run
106106
status: success
107107
"#},

crates/sncast/tests/e2e/script/invoke.rs

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ async fn test_contract_does_not_exist() {
8181
}
8282

8383
#[test]
84-
#[ignore = "TODO(#3120)"]
8584
fn test_wrong_function_name() {
8685
let script_dir =
8786
copy_script_directory_to_tempdir(SCRIPTS_DIR.to_owned() + "/invoke", Vec::<String>::new());
@@ -103,26 +102,19 @@ fn test_wrong_function_name() {
103102
let snapbox = runner(&args).current_dir(script_dir.path());
104103
let output = snapbox.assert().success();
105104

105+
// TODO(#3120): Update asserted message once displaying is implemented
106106
assert_stdout_contains(
107107
output,
108108
indoc! {r#"
109109
[..]
110-
ScriptCommandError::ProviderError(ProviderError::StarknetError(StarknetError::TransactionExecutionError(TransactionExecutionErrorData { transaction_index: 0, execution_error: "Transaction execution has failed:
111-
[..]
112-
[..]: Error in the called contract ([..]):
113-
Execution failed. Failure reason:
114-
Error in contract (contract address: [..], class hash: [..], selector: [..]):
115-
Error in contract (contract address: [..], class hash: [..], selector: [..]):
116-
[..] ('ENTRYPOINT_NOT_FOUND').
117-
" })))
110+
ScriptCommandError::ProviderError(ProviderError::StarknetError(StarknetError::TransactionExecutionError(TransactionExecutionErrorData { transaction_index: 0, [..] error: ContractExecutionError::Message([1, 161019049007015932470845765948242586617553515362189813571442680017261454901, 271082501784130983606656111016682077, 15]) }) }) }) })))
118111
command: script run
119112
status: success
120113
"#},
121114
);
122115
}
123116

124117
#[test]
125-
#[ignore = "TODO(#3120)"]
126118
fn test_wrong_calldata() {
127119
let script_dir =
128120
copy_script_directory_to_tempdir(SCRIPTS_DIR.to_owned() + "/invoke", Vec::<String>::new());
@@ -144,18 +136,11 @@ fn test_wrong_calldata() {
144136
let snapbox = runner(&args).current_dir(script_dir.path());
145137
let output = snapbox.assert().success();
146138

139+
// TODO(#3120): Update asserted message once displaying is implemented
147140
assert_stdout_contains(
148141
output,
149142
indoc! {r#"
150-
[..]
151-
ScriptCommandError::ProviderError(ProviderError::StarknetError(StarknetError::TransactionExecutionError(TransactionExecutionErrorData { transaction_index: 0, execution_error: "Transaction execution has failed:
152-
[..]
153-
[..]: Error in the called contract ([..]):
154-
Execution failed. Failure reason:
155-
Error in contract (contract address: [..], class hash: [..], selector: [..]):
156-
Error in contract (contract address: [..], class hash: [..], selector: [..]):
157-
[..] ('Failed to deserialize param #2').
158-
" })))
143+
ScriptCommandError::ProviderError(ProviderError::StarknetError(StarknetError::TransactionExecutionError(TransactionExecutionErrorData { transaction_index: 0, [..], error: ContractExecutionError::Message([2, 161019049007017550688154859146124165449376331526496475447250082491572630326, 94023844190060481618082450560698606437386733826467150857039051259452076595, 858923613, 4]) }) }) }) })))
159144
command: script run
160145
status: success
161146
"#},

sncast_std/src/lib.cairo

Lines changed: 9 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ use core::fmt::{Debug, Display, Error, Formatter};
55

66
#[derive(Drop, PartialEq, Serde, Debug)]
77
pub struct ErrorData {
8-
msg: ByteArray
8+
revert_error: ContractExecutionError
99
}
1010

11-
#[derive(Drop, PartialEq)]
11+
#[derive(Drop, PartialEq, Debug)]
1212
pub struct TransactionExecutionErrorData {
1313
pub transaction_index: felt252,
1414
pub execution_error: ContractExecutionError,
@@ -27,13 +27,15 @@ impl TransactionExecutionErrorDataSerde of Serde<TransactionExecutionErrorData>
2727
}
2828

2929

30-
#[derive(Drop, PartialEq, Copy)]
30+
// TODO(#3120): We should implement displaying message variant as deserialized byte array.
31+
// ATM, it's dispplayed as a serialized one.
32+
#[derive(Drop, PartialEq, Copy, Debug)]
3133
pub enum ContractExecutionError {
3234
Nested: Box<ContractExecutionErrorInner>,
3335
Message: Span<felt252>,
3436
}
3537

36-
#[derive(Drop, Serde, Copy)]
38+
#[derive(Drop, Serde, Copy, Debug)]
3739
pub struct ContractExecutionErrorInner {
3840
contract_address: ContractAddress,
3941
class_hash: felt252,
@@ -62,7 +64,6 @@ impl ContractExecutionErrorSerde of Serde<ContractExecutionError> {
6264
},
6365
ContractExecutionError::Message(msg) => {
6466
output.append(1);
65-
// output.append_span(msg);
6667
msg.serialize(ref output);
6768
}
6869
}
@@ -85,15 +86,12 @@ impl BoxContractExecutionErrorSerde of Serde<Box<ContractExecutionError>> {
8586
match (*self).unbox() {
8687
ContractExecutionError::Nested(inner) => {
8788
let inner = inner.unbox();
88-
// output.append(0);
89-
// inner.serialize(ref output);
9089
inner.serialize(ref output);
9190
},
9291
ContractExecutionError::Message(msg) => {
93-
for each in msg {
94-
output.append(*each);
95-
} // output.append(1);
96-
// msg.serialize(ref output);
92+
for byte_array_element in msg {
93+
output.append(*byte_array_element);
94+
}
9795
}
9896
}
9997
}
@@ -102,77 +100,6 @@ impl BoxContractExecutionErrorSerde of Serde<Box<ContractExecutionError>> {
102100
}
103101
}
104102

105-
fn span_to_array(span: Span<felt252>) -> Array::<felt252> {
106-
let mut result = array![];
107-
for each in span {
108-
result.append(*each);
109-
};
110-
result
111-
}
112-
113-
pub impl DisplayTransactionExecutionErrorData of Display<TransactionExecutionErrorData> {
114-
fn fmt(self: @TransactionExecutionErrorData, ref f: Formatter) -> Result<(), Error> {
115-
write!(
116-
f,
117-
"Transaction execution has failed: transaction_index: {}, execution_error: {}",
118-
self.transaction_index,
119-
self.execution_error
120-
)
121-
}
122-
}
123-
124-
pub impl DisplayContractExecutionError of Display<ContractExecutionError> {
125-
fn fmt(self: @ContractExecutionError, ref f: Formatter) -> Result<(), Error> {
126-
match self {
127-
ContractExecutionError::Nested(inner) => {
128-
let inner = (*inner).unbox();
129-
write!(
130-
f,
131-
"Error in contract (contract address: {}, class hash: {}, selector:
132-
{}):\n{}",
133-
inner.contract_address,
134-
inner.class_hash,
135-
inner.selector,
136-
inner.error
137-
)
138-
},
139-
ContractExecutionError::Message(msg) => { write!(f, "Message({:?})", *msg) }
140-
}
141-
}
142-
}
143-
144-
pub impl DisplayContractExecutionErrorInner of Display<ContractExecutionErrorInner> {
145-
fn fmt(self: @ContractExecutionErrorInner, ref f: Formatter) -> Result<(), Error> {
146-
write!(
147-
f,
148-
"Error in contract (contract_address: {}, class_hash: {}, selector: {}, error:
149-
{}):\n",
150-
self.contract_address,
151-
self.class_hash,
152-
self.selector,
153-
self.error
154-
)
155-
}
156-
}
157-
158-
pub impl DebugTransactionExecutionErrorData of Debug<TransactionExecutionErrorData> {
159-
fn fmt(self: @TransactionExecutionErrorData, ref f: Formatter) -> Result<(), Error> {
160-
Display::fmt(self, ref f)
161-
}
162-
}
163-
164-
pub impl DebugContractExecutionError of Debug<ContractExecutionError> {
165-
fn fmt(self: @ContractExecutionError, ref f: Formatter) -> Result<(), Error> {
166-
Display::fmt(self, ref f)
167-
}
168-
}
169-
170-
pub impl DebugContractExecutionErrorInner of Debug<ContractExecutionErrorInner> {
171-
fn fmt(self: @ContractExecutionErrorInner, ref f: Formatter) -> Result<(), Error> {
172-
Display::fmt(self, ref f)
173-
}
174-
}
175-
176103
#[derive(Drop, Serde, PartialEq, Debug)]
177104
pub enum StarknetError {
178105
/// Failed to receive transaction
@@ -499,22 +426,6 @@ pub fn invoke(
499426
fee_settings: FeeSettings,
500427
nonce: Option<felt252>
501428
) -> Result<InvokeResult, ScriptCommandError> {
502-
// let mut raw = array![
503-
// 4660.into(),
504-
// 0.into(),
505-
// 291.into(),
506-
// 2271560481.into(),
507-
// 4660.into(),
508-
// 1.into(),
509-
// 1,
510-
// 184477651815859881857708426232370721322670788429034947509639899811272418401,
511-
// 3265566911520157363207237164170485900701757214916046435088312658391615,
512-
// 29
513-
// ];
514-
// let mut span = raw.span();
515-
// let deserialized = Serde::<TransactionExecutionErrorData>::deserialize(ref span).unwrap();
516-
// println!("deserialized: {:?}", deserialized);
517-
518429
let contract_address_felt: felt252 = contract_address.into();
519430
let mut inputs = array![contract_address_felt, entry_point_selector];
520431

0 commit comments

Comments
 (0)