Skip to content

Commit

Permalink
fix: run scarb fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
glihm committed Feb 8, 2024
1 parent fd2a503 commit ccbfea0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
8 changes: 5 additions & 3 deletions src/appchain.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ mod appchain {
use piltover::config::{config_cpt, config_cpt::InternalTrait as ConfigInternal, IConfig};
use piltover::messaging::{
messaging_cpt, messaging_cpt::InternalTrait as MessagingInternal, IMessaging,
output_process,
output_process::{MessageToStarknet, MessageToAppchain},
output_process, output_process::{MessageToStarknet, MessageToAppchain},
};
use starknet::ContractAddress;
use super::errors;
Expand Down Expand Up @@ -92,7 +91,10 @@ mod appchain {

let mut messages_segments = program_output.slice(offset, program_output.len() - offset);

let (messages_to_starknet, messages_to_appchain) = output_process::gather_messages_from_output(messages_segments);
let (messages_to_starknet, messages_to_appchain) =
output_process::gather_messages_from_output(
messages_segments
);

self.messaging.process_messages_to_starknet(messages_to_starknet);
self.messaging.process_messages_to_appchain(messages_to_appchain);
Expand Down
16 changes: 11 additions & 5 deletions src/messaging/output_process.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ const MESSAGE_TO_APPCHAIN_HEADER_SIZE: usize = 5;
///
/// A tuple with the messages to Starknet and messages to Appchain
/// deserialized.
fn gather_messages_from_output(output_messages: Span<felt252>) -> (Span<MessageToStarknet>, Span<MessageToAppchain>) {
fn gather_messages_from_output(
output_messages: Span<felt252>
) -> (Span<MessageToStarknet>, Span<MessageToAppchain>) {
let mut messages_to_starknet = array![];
let mut messages_to_appchain = array![];

Expand All @@ -68,15 +70,17 @@ fn gather_messages_from_output(output_messages: Span<felt252>) -> (Span<MessageT

loop {
if offset >= segment_end {
break;
break;
}

if offset + MESSAGE_TO_STARKNET_HEADER_SIZE > segment_end {
core::panic_with_felt252('invalid message sn');
}

// +2 due to fields arrangement.
let payload_size: usize = (*output_messages[offset + 2]).try_into().expect('invalid size sn');
let payload_size: usize = (*output_messages[offset + 2])
.try_into()
.expect('invalid size sn');

// +1 for payload size and +2 for remaining fields.
let mut slice = output_messages.slice(offset, payload_size + 1 + 2);
Expand All @@ -101,15 +105,17 @@ fn gather_messages_from_output(output_messages: Span<felt252>) -> (Span<MessageT

loop {
if offset >= segment_end {
break;
break;
}

if offset + MESSAGE_TO_APPCHAIN_HEADER_SIZE > segment_end {
core::panic_with_felt252('invalid message appc');
}

// +4 due to fields arrangement.
let payload_size: usize = (*output_messages[offset + 4]).try_into().expect('invalid size appc');
let payload_size: usize = (*output_messages[offset + 4])
.try_into()
.expect('invalid size appc');

// +1 for payload size and +4 for remaining fields.
let mut slice = output_messages.slice(offset, payload_size + 1 + 4);
Expand Down
13 changes: 5 additions & 8 deletions tests/test_messaging.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ fn get_messages_segments() -> Span<felt252> {
917360325178274450223200079540424150242461675748,
300000000000000,
0,

// message to l2 (appchain in this context).
8,
993696174272377493693496825928908586134624850969,
Expand All @@ -104,7 +103,6 @@ fn get_messages_segments() -> Span<felt252> {
1905350129216923298156817020930524704572804705313566176282348575247442538663,
100000000000000000,
0,

]
.span()
}
Expand Down Expand Up @@ -339,7 +337,9 @@ fn cancel_message_cancellation_not_allowed_yet() {
#[test]
fn gather_messages_from_output_ok() {
let felts = get_messages_segments();
let (messages_to_starknet, messages_to_appchain) = output_process::gather_messages_from_output(felts);
let (messages_to_starknet, messages_to_appchain) = output_process::gather_messages_from_output(
felts
);

assert(messages_to_starknet.len() == 1, 'missing msgs to sn');
assert(messages_to_appchain.len() == 1, 'missing msgs to appc');
Expand Down Expand Up @@ -411,11 +411,8 @@ fn consume_message_from_appchain_ok() {

let message_hash = hash::compute_message_hash_appc_to_sn(from, to, payload);

let messages = array![MessageToStarknet {
from_address: from,
to_address: to,
payload,
}].span();
let messages = array![MessageToStarknet { from_address: from, to_address: to, payload, }]
.span();

mock.process_messages_to_starknet(messages);

Expand Down

0 comments on commit ccbfea0

Please sign in to comment.