Skip to content

Commit

Permalink
test: separate hash test contract, micro changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tabaktoni committed Apr 14, 2023
1 parent 52fed30 commit e0d75c1
Show file tree
Hide file tree
Showing 11 changed files with 18,211 additions and 5,152 deletions.
57 changes: 57 additions & 0 deletions __mocks__/cairo/helloSierra/hello.cairo
Original file line number Diff line number Diff line change
@@ -1,9 +1,36 @@
use array::ArrayTrait;
use array::SpanTrait;
use option::OptionTrait;
use traits::TryInto;
use serde::Serde;

#[derive(Drop)]
struct Foo {
val: felt252
}

impl FooSerde of Serde::<Foo> {
fn serialize(ref serialized: Array<felt252>, input: Foo) {
Serde::<felt252>::serialize(ref serialized, input.val);
}

fn deserialize(ref serialized: Span<felt252>) -> Option<Foo> {
let val: felt252 = *serialized.pop_front()?;
Option::Some(Foo { val } )
}
}

#[contract]
mod HelloStarknet {
// libs
use starknet::ContractAddress;
use super::Foo;

struct Storage {
balance: felt252,
balance_u8: u8,
status: bool,
ca: ContractAddress,
}

// Felt252 test.
Expand All @@ -28,6 +55,17 @@ mod HelloStarknet {
status::read()
}

// ContractAddress
#[external]
fn set_ca(address: ContractAddress) {
ca::write(address);
}

#[view]
fn get_ca() -> ContractAddress {
ca::read()
}

// u8 Test.
#[external]
fn increase_balance_u8(amount: u8) {
Expand All @@ -38,4 +76,23 @@ mod HelloStarknet {
fn get_balance_u8() -> u8 {
balance_u8::read()
}

// echo Array
#[view]
fn echo_array(data: Array<u8>) -> Array<u8> {
data
}

// unamed Tuple
#[view]
fn echo_un_tuple(a:(felt252, u16)) -> (felt252, u16) {
a
}

// echo Struct
#[view]
fn echo_struct(tt: Foo) -> Foo {
tt
}

}
Loading

0 comments on commit e0d75c1

Please sign in to comment.