Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
chachaleo committed Sep 27, 2024
1 parent 74c8e3b commit 9b46940
Show file tree
Hide file tree
Showing 3 changed files with 160 additions and 16 deletions.
1 change: 1 addition & 0 deletions contracts/.snfoundry_cache/.prev_tests_failed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
zkramp::contracts::ramps::revolut::revolut_test::test_initiate_liquidity_withdraw_without_enough_liquidity
169 changes: 153 additions & 16 deletions contracts/src/contracts/ramps/revolut/revolut_test.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -277,40 +277,177 @@ fn test_retrieve_liquidity_with_expired_requests() {
// initiate_liquidity_withdraw & withdraw_liquidity
//

// #[test]
// #[should_panic(expected: 'Caller is the owner')]
#[test]
#[should_panic(expected: 'Caller is the owner')]
fn test_initiate_liquidity_withdraw_from_owner() {
panic!("Not implemented yet");
let (revolut_ramp, erc20) = setup();
let liquidity_owner = constants::OTHER();
let offchain_id = constants::REVOLUT_ID();
let amount = 42;
let liquidity_key = LiquidityKey { owner: liquidity_owner, offchain_id };

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

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

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

// initiate liquidity withdraw
revolut_ramp.initiate_liquidity_withdrawal(:liquidity_key, :amount, :offchain_id);
}

// #[test]
// #[should_panic(expected: 'Amount cannot be null')]
#[test]
#[should_panic(expected: 'Amount cannot be null')]
fn test_initiate_liquidity_withdraw_zero_amount() {
panic!("Not implemented yet");
let (revolut_ramp, erc20) = setup();
let liquidity_owner = constants::OTHER();
let liquidity_withdrawer = constants::CALLER();
let offchain_id = constants::REVOLUT_ID();
let offchain_id_withdrawer = constants::OTHER_REVOLUT_ID();
let amount = 42;
let liquidity_key = LiquidityKey { owner: liquidity_owner, offchain_id };

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

// register offchain ID owner
start_cheat_caller_address(revolut_ramp.contract_address, liquidity_owner);
revolut_ramp.register(:offchain_id);

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

// register offchain ID withdrawer
start_cheat_caller_address(revolut_ramp.contract_address, liquidity_withdrawer);
revolut_ramp.register(offchain_id: offchain_id_withdrawer);

// initiate liquidity withdraw
revolut_ramp.initiate_liquidity_withdrawal(:liquidity_key, amount: 0, offchain_id: offchain_id_withdrawer);
}

// #[test]
// #[should_panic(expected: 'Liquidity is not available')]
#[test]
#[should_panic(expected: 'Liquidity is not available')]
fn test_initiate_liquidity_withdraw_locked() {
panic!("Not implemented yet");
let (revolut_ramp, erc20) = setup();
let liquidity_owner = constants::OTHER();
let liquidity_withdrawer = constants::CALLER();
let offchain_id = constants::REVOLUT_ID();
let offchain_id_withdrawer = constants::OTHER_REVOLUT_ID();
let amount = 42;
let liquidity_key = LiquidityKey { owner: liquidity_owner, offchain_id };

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

// register offchain ID owner
start_cheat_caller_address(revolut_ramp.contract_address, liquidity_owner);
revolut_ramp.register(:offchain_id);

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

// locks liquidity
revolut_ramp.initiate_liquidity_retrieval(:liquidity_key);

// register offchain ID withdrawer
start_cheat_caller_address(revolut_ramp.contract_address, liquidity_withdrawer);
revolut_ramp.register(offchain_id: offchain_id_withdrawer);

// initiate liquidity withdraw
revolut_ramp.initiate_liquidity_withdrawal(:liquidity_key, :amount, offchain_id: offchain_id_withdrawer);
}

// #[test]
// #[should_panic(expected: 'Caller is not registered')]
#[test]
#[should_panic(expected: 'Caller is not registered')]
fn test_initiate_liquidity_withdraw_with_unregistered_offchain_id() {
panic!("Not implemented yet");
let (revolut_ramp, erc20) = setup();
let liquidity_owner = constants::OTHER();
let liquidity_withdrawer = constants::CALLER();
let offchain_id = constants::REVOLUT_ID();
let offchain_id_withdrawer = constants::OTHER_REVOLUT_ID();
let amount = 42;
let liquidity_key = LiquidityKey { owner: liquidity_owner, offchain_id };

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

// register offchain ID owner
start_cheat_caller_address(revolut_ramp.contract_address, liquidity_owner);
revolut_ramp.register(:offchain_id);

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

// initiate liquidity withdraw
start_cheat_caller_address(revolut_ramp.contract_address, liquidity_withdrawer);
revolut_ramp.initiate_liquidity_withdrawal(:liquidity_key, :amount, offchain_id: offchain_id_withdrawer);
}

// #[test]
// #[should_panic(expected: 'Not enough liquidity')]
#[test]
#[should_panic(expected: 'Not enough liquidity')]
fn test_initiate_liquidity_withdraw_without_enough_liquidity() {
panic!("Not implemented yet");
let (revolut_ramp, erc20) = setup();
let liquidity_owner = constants::OTHER();
let liquidity_withdrawer = constants::CALLER();
let offchain_id = constants::REVOLUT_ID();
let offchain_id_withdrawer = constants::OTHER_REVOLUT_ID();
let amount1 = 42;
let amount2 = 75;
let liquidity_key = LiquidityKey { owner: liquidity_owner, offchain_id };

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

// register offchain ID owner
start_cheat_caller_address(revolut_ramp.contract_address, liquidity_owner);
revolut_ramp.register(:offchain_id);

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

// register offchain ID withdrawer
start_cheat_caller_address(revolut_ramp.contract_address, liquidity_withdrawer);
revolut_ramp.register(offchain_id: offchain_id_withdrawer);

// initiate liquidity withdraw
revolut_ramp.initiate_liquidity_withdrawal(:liquidity_key, amount: amount2, offchain_id: offchain_id_withdrawer);
}

// #[test]
// #[should_panic(expected: 'Not enough liquidity')]
fn test_initiate_liquidity_withdraw_without_enough_available_liquidity() {
panic!("Not implemented yet");
let (revolut_ramp, erc20) = setup();
let liquidity_owner = constants::OTHER();
let liquidity_withdrawer = constants::CALLER();
let offchain_id = constants::REVOLUT_ID();
let offchain_id_withdrawer = constants::OTHER_REVOLUT_ID();
let amount1 = 42;
let amount2 = 75;
let liquidity_key = LiquidityKey { owner: liquidity_owner, offchain_id };

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

// register offchain ID owner
start_cheat_caller_address(revolut_ramp.contract_address, liquidity_owner);
revolut_ramp.register(:offchain_id);

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

// register offchain ID withdrawer
start_cheat_caller_address(revolut_ramp.contract_address, liquidity_withdrawer);
revolut_ramp.register(offchain_id: offchain_id_withdrawer);

// initiate liquidity withdraw
revolut_ramp.initiate_liquidity_withdrawal(:liquidity_key, amount: amount1, offchain_id: offchain_id_withdrawer);

// initiate liquidity withdraw
revolut_ramp.initiate_liquidity_withdrawal(:liquidity_key, amount: amount1, offchain_id: offchain_id_withdrawer);
}

// #[test]
Expand Down
6 changes: 6 additions & 0 deletions contracts/src/tests/constants.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@ use zkramp::components::registry::interface::OffchainId;

const REVTAG: felt252 = 'just a random revtag hash';

const REVTAG2: felt252 = 'just another random revtag hash';

pub fn REVOLUT_ID() -> OffchainId {
OffchainId::Revolut(REVTAG)
}

pub fn OTHER_REVOLUT_ID() -> OffchainId {
OffchainId::Revolut(REVTAG2)
}

pub fn CALLER() -> ContractAddress {
contract_address_const::<'caller'>()
}
Expand Down

0 comments on commit 9b46940

Please sign in to comment.