Skip to content

Commit

Permalink
prepare contracts tests (keep-starknet-strange#82)
Browse files Browse the repository at this point in the history
* prepare revolut ramp tests

* add more tests definitions for revolut ramp

* improve escrow testing

* create last tests

* comment empty tests

* fmt
  • Loading branch information
0xChqrles authored Sep 23, 2024
1 parent 7fb866e commit b66caff
Show file tree
Hide file tree
Showing 8 changed files with 700 additions and 127 deletions.
15 changes: 5 additions & 10 deletions contracts/src/components/escrow/escrow.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ pub mod EscrowComponent {
//

pub mod Errors {
pub const PROOF_OF_DEPOSIT_FAILED: felt252 = 'Proof of deposit failed';
pub const INSUFFICIENT_BALANCE: felt252 = 'Insufficient deposit balance';
}

Expand All @@ -33,13 +32,13 @@ pub mod EscrowComponent {
TContractState, +HasComponent<TContractState>, +Drop<TContractState>,
> of interface::IEscrow<ComponentState<TContractState>> {
fn lock(ref self: ComponentState<TContractState>, from: ContractAddress, token: ContractAddress, amount: u256) {
let locked_amount = self.deposits.read((from, token));

// transfers funds to escrow
let erc20_dispatcher = IERC20Dispatcher { contract_address: token };

erc20_dispatcher.transfer_from(from, get_contract_address(), amount);
// transfers funds to escrow
erc20_dispatcher.transfer_from(sender: from, recipient: get_contract_address(), :amount);

// update locked amount
let locked_amount = self.deposits.read((from, token));
self.deposits.write((from, token), amount + locked_amount);
}

Expand All @@ -52,17 +51,13 @@ pub mod EscrowComponent {
) {
let locked_amount = self.deposits.read((from, token));

// TODO
// check for proof of deposit
assert(true, Errors::PROOF_OF_DEPOSIT_FAILED);

// check deposit balance
assert(locked_amount >= amount, Errors::INSUFFICIENT_BALANCE);

// transfert of the amount to `to`
let erc20_dispatcher = IERC20Dispatcher { contract_address: token };

erc20_dispatcher.transfer_from(get_contract_address(), to, amount);
erc20_dispatcher.transfer(recipient: to, :amount);

// update locked amount
self.deposits.write((from, token), locked_amount - amount);
Expand Down
Loading

0 comments on commit b66caff

Please sign in to comment.