Skip to content

Commit

Permalink
prepare tests
Browse files Browse the repository at this point in the history
  • Loading branch information
0xChqrles committed Oct 8, 2024
1 parent b3881b8 commit 490c572
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 9 deletions.
12 changes: 8 additions & 4 deletions contracts/src/contracts/ramps/revolut/revolut.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ pub mod RevolutRamp {
#[storage]
struct Storage {
#[substorage(v0)]
ownable: OwnableComponent::Storage,
pub ownable: OwnableComponent::Storage,
#[substorage(v0)]
registry: RegistryComponent::Storage,
pub registry: RegistryComponent::Storage,
#[substorage(v0)]
escrow: EscrowComponent::Storage,
pub escrow: EscrowComponent::Storage,
token: ContractAddress,
// liquidity_key -> amount
liquidity: Map::<LiquidityKey, u256>,
Expand Down Expand Up @@ -150,7 +150,7 @@ pub mod RevolutRamp {
// initialize owner
self.ownable.initializer(:owner);

self.token.write(token);
self.initializer(:token);
}

//
Expand Down Expand Up @@ -348,6 +348,10 @@ pub mod RevolutRamp {

#[generate_trait]
pub impl InternalImpl of InternalTrait {
fn initializer(ref self: ContractState, token: ContractAddress) {
self.token.write(token);
}

fn _get_available_liquidity(self: @ContractState, liquidity_key: LiquidityKey) -> u256 {
let mut amount = self.liquidity.read(liquidity_key);
let current_timestamp = get_block_timestamp();
Expand Down
39 changes: 34 additions & 5 deletions contracts/src/contracts/ramps/revolut/revolut_test.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use snforge_std::{
stop_cheat_caller_address, test_address, start_cheat_block_timestamp_global
};
use zkramp::contracts::ramps::revolut::interface::{
ZKRampABIDispatcher, ZKRampABIDispatcherTrait, LiquidityKey, LiquidityShareRequest
ZKRampABIDispatcher, ZKRampABIDispatcherTrait, LiquidityKey, LiquidityShareRequest, IZKRampLiquidity
};
use zkramp::contracts::ramps::revolut::revolut::RevolutRamp::{
Event, LiquidityAdded, LiquidityRetrieved, LiquidityLocked, LiquidityShareRequested, LiquidityShareWithdrawn,
Expand All @@ -16,6 +16,7 @@ use zkramp::contracts::ramps::revolut::revolut::RevolutRamp::{
use zkramp::contracts::ramps::revolut::revolut::RevolutRamp;
use zkramp::tests::constants;
use zkramp::tests::utils;
use zkramp::components::registry::interface::IRegistry;

fn setup_revolut_ramp(erc20_contract_address: ContractAddress) -> ZKRampABIDispatcher {
// declare Revolut Ramp contract
Expand Down Expand Up @@ -1402,14 +1403,42 @@ fn test_available_liquidity_with_withdrawn_requests() {
assert_eq!(revolut_ramp.available_liquidity(:liquidity_key), amount - requested_amount);
}

// #[test]
#[test]
fn test__get_available_liquidity_empty() {
panic!("Not implemented yet");
let state = RevolutRamp::contract_state_for_testing();
let liquidity_owner = constants::CALLER();
let offchain_id = constants::REVOLUT_ID();
let liquidity_key = LiquidityKey { owner: liquidity_owner, offchain_id };

// assert no liquidity available
assert_eq!(state._get_available_liquidity(:liquidity_key), 0);
}

// #[test]
#[test]
fn test__get_available_liquidity_without_requests() {
panic!("Not implemented yet");
let (_, erc20) = setup();
let mut state = RevolutRamp::contract_state_for_testing();
let liquidity_owner = constants::CALLER();
let offchain_id = constants::REVOLUT_ID();
let amount = 42;
let liquidity_key = LiquidityKey { owner: liquidity_owner, offchain_id };
let contract_address = test_address();

// initialize ramp state
state.initializer(token: erc20.contract_address);

// fund the account
fund_and_approve(token: erc20, recipient: liquidity_owner, spender: contract_address, :amount);

// register offchain ID
start_cheat_caller_address(contract_address, liquidity_owner);
state.registry.register(:offchain_id);

// add liquidity
state.add_liquidity(:amount, :offchain_id);

// assert liquidity is available
assert_eq!(state.available_liquidity(:liquidity_key), amount);
}

// #[test]
Expand Down

0 comments on commit 490c572

Please sign in to comment.