Skip to content

Commit

Permalink
test(revolut_test): added tests for retrieve_liquidity (keep-starknet…
Browse files Browse the repository at this point in the history
…-strange#100)

* test(revolut_test): added tests for retrieve_liquidity

CI is not passing because of a bug in the retrieve_liquidity function, liquidity amount is never updated

 [CONTRACTS] implement retrieve_liquidity tests keep-starknet-strange#85

* fix tests

---------

Co-authored-by: 0xChqrles <[email protected]>
  • Loading branch information
leohscl and 0xChqrles authored Oct 1, 2024
1 parent fa01485 commit 9b4c4fd
Show file tree
Hide file tree
Showing 2 changed files with 315 additions and 44 deletions.
10 changes: 7 additions & 3 deletions contracts/src/contracts/ramps/revolut/revolut.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -232,19 +232,23 @@ pub mod RevolutRamp {
fn retrieve_liquidity(ref self: ContractState, liquidity_key: LiquidityKey) {
let caller = get_caller_address();

// asserts caller is the liquidity owner
// asserts liquidity is locked
assert(self.locked_liquidity.read(liquidity_key), Errors::UNLOCKED_LIQUIDITY);
// asserts caller is the liquidity owner
assert(liquidity_key.owner == caller, Errors::CALLER_IS_NOT_OWNER);

let token = self.token.read();
let available_amount = self._get_available_liquidity(:liquidity_key);

// update stored liquidity
let amount = self.liquidity.read(liquidity_key);
self.liquidity.write(liquidity_key, amount - available_amount);

// use the escrow to unlock the funds
self.escrow.unlock(from: caller, to: caller, :token, :amount);
self.escrow.unlock(from: caller, to: caller, :token, amount: available_amount);

// emits Liquidityretrieved event
self.emit(LiquidityRetrieved { liquidity_key, amount });
self.emit(LiquidityRetrieved { liquidity_key, amount: available_amount });
}

// If the requested amount is valid according to the available amount,
Expand Down
Loading

0 comments on commit 9b4c4fd

Please sign in to comment.