-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
16426aa
commit 20b2b38
Showing
4 changed files
with
55 additions
and
2 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
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,3 @@ | ||
pub mod ocr2; | ||
pub mod storage; | ||
|
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,27 @@ | ||
#[starknet::interface] | ||
pub trait IStorage<TContractState> { | ||
fn store(ref self: TContractState, value: u256); | ||
fn retrieve(self: @TContractState) -> u256; | ||
} | ||
|
||
#[starknet::contract] | ||
mod Storage { | ||
#[storage] | ||
struct Storage { | ||
value: u256 | ||
} | ||
|
||
#[constructor] | ||
fn constructor(ref self: ContractState) {} | ||
|
||
#[abi(embed_v0)] | ||
impl StorageImpl of super::IStorage<ContractState> { | ||
fn store(ref self: ContractState, value: u256) { | ||
self.value.write(value) | ||
} | ||
|
||
fn retrieve(self: @ContractState) -> u256 { | ||
self.value.read() | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
examples/contracts/aggregator_consumer/tests/test_storage.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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use starknet::contract_address_const; | ||
use starknet::get_caller_address; | ||
use starknet::ContractAddress; | ||
|
||
use aggregator_consumer::storage::{IStorageDispatcherTrait, IStorageDispatcher}; | ||
|
||
use snforge_std::{declare, ContractClassTrait}; | ||
|
||
fn deploy_storage() -> (ContractAddress, IStorageDispatcher) { | ||
let mut calldata = ArrayTrait::new(); | ||
let (contract_address, _) = declare("Storage").unwrap().deploy(@calldata).unwrap(); | ||
(contract_address, IStorageDispatcher { contract_address: contract_address }) | ||
} | ||
|
||
#[test] | ||
fn test_store_and_retrieve() { | ||
let (_, storage) = deploy_storage(); | ||
let desired_value: u256 = 145; | ||
storage.store(desired_value); | ||
|
||
let actual_value = storage.retrieve(); | ||
|
||
assert(actual_value == desired_value, 'values should equal'); | ||
} | ||
|