Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test liquidity_share_request #103

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions contracts/src/contracts/ramps/revolut/interface.cairo
Original file line number Diff line number Diff line change
@@ -10,13 +10,13 @@ pub struct Proof {
pub foo: felt252
}

#[derive(Drop, Copy, Hash, Serde, starknet::Store)]
#[derive(Drop, Copy, Hash, Serde, starknet::Store, Debug, PartialEq)]
pub struct LiquidityKey {
pub owner: ContractAddress,
pub offchain_id: OffchainId,
}

#[derive(Drop, Copy, Serde, starknet::Store)]
#[derive(Drop, Copy, Serde, starknet::Store, Debug, PartialEq)]
pub struct LiquidityShareRequest {
pub requestor: ContractAddress,
pub liquidity_key: LiquidityKey,
150 changes: 141 additions & 9 deletions contracts/src/contracts/ramps/revolut/revolut_test.cairo
Original file line number Diff line number Diff line change
@@ -6,7 +6,9 @@ use snforge_std::{
EventSpyAssertionsTrait, spy_events, declare, DeclareResultTrait, ContractClassTrait, start_cheat_caller_address,
stop_cheat_caller_address, test_address, start_cheat_block_timestamp_global
};
use zkramp::contracts::ramps::revolut::interface::{ZKRampABIDispatcher, ZKRampABIDispatcherTrait, LiquidityKey};
use zkramp::contracts::ramps::revolut::interface::{
ZKRampABIDispatcher, ZKRampABIDispatcherTrait, LiquidityKey, LiquidityShareRequest
};
use zkramp::contracts::ramps::revolut::revolut::RevolutRamp::{
Event, LiquidityAdded, LiquidityRetrieved, LiquidityLocked, LiquidityShareRequested, LiquidityShareWithdrawn,
InternalImpl as RevolutRampInternalImpl, MINIMUM_LOCK_DURATION, LOCK_DURATION_STEP
@@ -1453,24 +1455,154 @@ fn test_all_liquidity_with_requests() {
// liquidity_share_request
//

// #[test]
#[test]
fn test_liquidity_share_request_empty() {
panic!("Not implemented yet");
let (revolut_ramp, erc20) = setup();

// off-ramper
let liquidity_owner = constants::CALLER();
let offchain_id = constants::REVOLUT_ID();
let amount = 42;

// on-ramper
let withdrawer = constants::OTHER();
let withdrawer_offchain_id = constants::REVOLUT_ID2();

// fund the account
fund_and_approve(token: erc20, recipient: liquidity_owner, spender: revolut_ramp.contract_address, amount: 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, :offchain_id);

// withdrawer initiates withdrawal
start_cheat_caller_address(revolut_ramp.contract_address, withdrawer);
revolut_ramp.register(offchain_id: withdrawer_offchain_id);

// assert empty liquidity_share_request is None
let maybe_liquidity_share_request = revolut_ramp.liquidity_share_request(offchain_id: withdrawer_offchain_id);
assert!(maybe_liquidity_share_request.is_none());
}

// #[test]
#[test]
fn test_liquidity_share_request_expired() {
panic!("Not implemented yet");
let (revolut_ramp, erc20) = setup();

// off-ramper
let liquidity_owner = constants::CALLER();
let offchain_id = constants::REVOLUT_ID();
let amount = 42;

// on-ramper
let withdrawer = constants::OTHER();
let withdrawer_offchain_id = constants::REVOLUT_ID2();

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: 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, :offchain_id);

// withdrawer initiates withdrawal
start_cheat_caller_address(revolut_ramp.contract_address, withdrawer);
revolut_ramp.register(offchain_id: withdrawer_offchain_id);
revolut_ramp.initiate_liquidity_withdrawal(:liquidity_key, :amount, offchain_id: withdrawer_offchain_id);

// offer expires
start_cheat_block_timestamp_global(MINIMUM_LOCK_DURATION);

// assert expired liquidity_share_request is None
let maybe_liquidity_share_request = revolut_ramp.liquidity_share_request(offchain_id: withdrawer_offchain_id);
assert!(maybe_liquidity_share_request.is_none());
}

// #[test]
#[test]
fn test_liquidity_share_request_valid() {
panic!("Not implemented yet");
let (revolut_ramp, erc20) = setup();

// off-ramper
let liquidity_owner = constants::CALLER();
let offchain_id = constants::REVOLUT_ID();
let amount = 42;

// on-ramper
let withdrawer = constants::OTHER();
let withdrawer_offchain_id = constants::REVOLUT_ID2();

let liquidity_key = LiquidityKey { owner: liquidity_owner, offchain_id };
let expected_liquidity_share_request = LiquidityShareRequest {
requestor: withdrawer, amount, liquidity_key, expiration_date: MINIMUM_LOCK_DURATION,
};

// fund the account
fund_and_approve(token: erc20, recipient: liquidity_owner, spender: revolut_ramp.contract_address, amount: 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, :offchain_id);

// withdrawer initiates withdrawal
start_cheat_caller_address(revolut_ramp.contract_address, withdrawer);
revolut_ramp.register(offchain_id: withdrawer_offchain_id);
revolut_ramp.initiate_liquidity_withdrawal(:liquidity_key, :amount, offchain_id: withdrawer_offchain_id);

// assert liquidity_share_request
let liquidity_share_request = revolut_ramp
.liquidity_share_request(withdrawer_offchain_id)
.expect('liquidity_share_req expected');

assert_eq!(liquidity_share_request, expected_liquidity_share_request);
}

// #[test]
#[test]
fn test_liquidity_share_request_withdrawn() {
panic!("Not implemented yet");
let (revolut_ramp, erc20) = setup();

// off-ramper
let liquidity_owner = constants::CALLER();
let offchain_id = constants::REVOLUT_ID();
let amount = 42;

// on-ramper
let withdrawer = constants::OTHER();
let withdrawer_offchain_id = constants::REVOLUT_ID2();

let liquidity_key = LiquidityKey { owner: liquidity_owner, offchain_id };
let proof = constants::PROOF();

// fund the account
fund_and_approve(token: erc20, recipient: liquidity_owner, spender: revolut_ramp.contract_address, amount: 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, :offchain_id);

// withdrawer initiates withdrawal
start_cheat_caller_address(revolut_ramp.contract_address, withdrawer);
revolut_ramp.register(offchain_id: withdrawer_offchain_id);
revolut_ramp.initiate_liquidity_withdrawal(:liquidity_key, :amount, offchain_id: withdrawer_offchain_id);

// withdrawer withdraws
revolut_ramp.withdraw_liquidity(:liquidity_key, offchain_id: withdrawer_offchain_id, :proof);

// assert withdrawned liquidity_share_request is None
let maybe_liquidity_share_request = revolut_ramp.liquidity_share_request(withdrawer_offchain_id);
assert!(maybe_liquidity_share_request.is_none());
}

//

Unchanged files with check annotations Beta

`
export default function SwapPage() {
const [rampMode, setRampMode] = useState<'on' | 'off'>('on')

Check warning on line 77 in client/src/pages/Swap.tsx

GitHub Actions / lint

'rampMode' is assigned a value but never used

Check warning on line 77 in client/src/pages/Swap.tsx

GitHub Actions / lint

'setRampMode' is assigned a value but never used
const [fiatCurrency, setFiatCurrency] = useState(FIAT_CURRENCIES['EUR'])

Check warning on line 78 in client/src/pages/Swap.tsx

GitHub Actions / lint

'setFiatCurrency' is assigned a value but never used
const [tokenCurrency, setTokenCurrency] = useState(TOKEN_CURRENCIES['USDC'])

Check warning on line 79 in client/src/pages/Swap.tsx

GitHub Actions / lint

'setTokenCurrency' is assigned a value but never used
const [inputSendValue, setInputSendValue] = useState('')
const [inputReceiveValue, setInputReceiveValue] = useState('')

Check warning on line 82 in client/src/pages/Swap.tsx

GitHub Actions / lint

'inputReceiveValue' is assigned a value but never used
const [, toggleSelectAccountModal] = useSelectAccountModal()
const handleReceiveChange = (event: ChangeEvent<HTMLInputElement>) => {

Check warning on line 86 in client/src/pages/Swap.tsx

GitHub Actions / lint

'handleReceiveChange' is assigned a value but never used
const inputValue = event.target.value
const numericValue = inputValue.replace(/[^0-9]/g, '')
setInputReceiveValue(numericValue)