-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add Tuples in cheatsheet * nit: trigger ci * feat: tests of custom type serde * appying improvement * nit: fix embed
- Loading branch information
Showing
2 changed files
with
57 additions
and
6 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
50 changes: 49 additions & 1 deletion
50
listings/ch00-getting-started/custom_type_serde/src/tests.cairo
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 |
---|---|---|
@@ -1,2 +1,50 @@ | ||
mod tests { // TODO | ||
// The purpose of these tests is to demonstrate the capability of using custom types as inputs and outputs in contract calls. | ||
// Therefore, we are not employing getters and setters for managing the contract's state. | ||
|
||
mod tests { | ||
use custom_type_serde::contract::{ | ||
SerdeCustomType, SerdeCustomType::Person, ISerdeCustomTypeDispatcher, | ||
ISerdeCustomTypeDispatcherTrait | ||
}; | ||
use core::result::ResultTrait; | ||
use debug::PrintTrait; | ||
use starknet::{deploy_syscall, ContractAddress}; | ||
use starknet::class_hash::Felt252TryIntoClassHash; | ||
|
||
fn deploy() -> ISerdeCustomTypeDispatcher { | ||
let calldata: Array<felt252> = array![]; | ||
let (address0, _) = deploy_syscall( | ||
SerdeCustomType::TEST_CLASS_HASH.try_into().unwrap(), 0, calldata.span(), false | ||
) | ||
.unwrap(); | ||
ISerdeCustomTypeDispatcher { contract_address: address0 } | ||
} | ||
|
||
#[test] | ||
#[available_gas(2000000000)] | ||
fn should_deploy() { | ||
let init_value = 10; | ||
let contract = deploy(); | ||
} | ||
|
||
#[test] | ||
#[available_gas(2000000000)] | ||
fn should_get_person_output() { | ||
let contract = deploy(); | ||
let expected_person = Person { age: 10, name: 'Joe' }; | ||
let received_person = contract.person_output(); | ||
let age_received = received_person.age; | ||
let name_received = received_person.name; | ||
|
||
assert(age_received == expected_person.age, 'Wrong age value'); | ||
assert(name_received == expected_person.name, 'Wrong name value'); | ||
} | ||
|
||
#[test] | ||
#[available_gas(2000000000)] | ||
fn should_call_person_input() { | ||
let contract = deploy(); | ||
let expected_person = Person { age: 10, name: 'Joe' }; | ||
let received_person = contract.person_input(expected_person); | ||
} | ||
} |