Skip to content

Commit

Permalink
v0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
remollemo committed Dec 11, 2023
1 parent 1cb7308 commit a4caa78
Show file tree
Hide file tree
Showing 8 changed files with 172 additions and 83 deletions.
2 changes: 2 additions & 0 deletions src/cairo/test_utils.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,7 @@ mod test_utils {
token_bridge_address: ContractAddress,
l1_bridge_address: EthAddress,
l1_token: EthAddress,
depositor: EthAddress,
l2_recipient: ContractAddress,
amount_to_deposit: u256
) {
Expand All @@ -556,6 +557,7 @@ mod test_utils {
ref token_bridge_state,
from_address: l1_bridge_address.into(),
:l1_token,
:depositor,
:l2_recipient,
amount: amount_to_deposit
);
Expand Down
3 changes: 2 additions & 1 deletion src/cairo/token_bridge.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,7 @@ mod TokenBridge {
ref self: ContractState,
from_address: felt252,
l1_token: EthAddress,
depositor: EthAddress,
l2_recipient: ContractAddress,
amount: u256,
) {
Expand All @@ -1029,9 +1030,9 @@ mod TokenBridge {
ref self: ContractState,
from_address: felt252,
l1_token: EthAddress,
depositor: EthAddress,
l2_recipient: ContractAddress,
amount: u256,
depositor: EthAddress,
message: Span<felt252>,
) {
// Verify deposit originating from the l1 bridge.
Expand Down
82 changes: 64 additions & 18 deletions src/cairo/token_bridge_admin_test.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ mod token_bridge_admin_test {
ITokenBridgeAdminDispatcher, ITokenBridgeAdminDispatcherTrait
};

const DEFAULT_DEPOSITOR_ETH_ADDRESS: felt252 = 7;
// TODO change the name of deploy_and_prepare.

// Deploys the token bridge and sets the caller as the App Governer (and as App Role Admin).
Expand Down Expand Up @@ -189,14 +190,19 @@ mod token_bridge_admin_test {
#[available_gas(30000000)]
fn test_successful_initiate_token_withdraw_with_limits_one_withdrawal() {
let (l1_bridge_address, l1_token, l1_recipient) = get_default_l1_addresses();

let depositor = EthAddress { address: DEFAULT_DEPOSITOR_ETH_ADDRESS };
let token_bridge_address = deploy_token_bridge();

// Deploy a new token and deposit funds to this token.
let l2_recipient = initial_owner();
let amount_to_deposit = default_amount();
deploy_new_token_and_deposit(
:token_bridge_address, :l1_bridge_address, :l1_token, :l2_recipient, :amount_to_deposit
:token_bridge_address,
:l1_bridge_address,
:l1_token,
:depositor,
:l2_recipient,
:amount_to_deposit
);

enable_withdrawal_limit(:token_bridge_address, :l1_token);
Expand All @@ -218,14 +224,19 @@ mod token_bridge_admin_test {
#[available_gas(30000000)]
fn test_successful_initiate_token_withdraw_with_limits_two_withdrawals() {
let (l1_bridge_address, l1_token, l1_recipient) = get_default_l1_addresses();

let depositor = EthAddress { address: DEFAULT_DEPOSITOR_ETH_ADDRESS };
let token_bridge_address = deploy_token_bridge();

// Deploy a new token and deposit funds to this token.
let l2_recipient = initial_owner();
let amount_to_deposit = default_amount();
deploy_new_token_and_deposit(
:token_bridge_address, :l1_bridge_address, :l1_token, :l2_recipient, :amount_to_deposit
:token_bridge_address,
:l1_bridge_address,
:l1_token,
:depositor,
:l2_recipient,
:amount_to_deposit
);

enable_withdrawal_limit(:token_bridge_address, :l1_token);
Expand Down Expand Up @@ -258,14 +269,19 @@ mod token_bridge_admin_test {
#[available_gas(30000000)]
fn test_successful_initiate_token_withdraw_with_and_without_limits() {
let (l1_bridge_address, l1_token, l1_recipient) = get_default_l1_addresses();

let depositor = EthAddress { address: DEFAULT_DEPOSITOR_ETH_ADDRESS };
let token_bridge_address = deploy_token_bridge();

// Deploy a new token and deposit funds to this token.
let l2_recipient = initial_owner();
let amount_to_deposit = default_amount();
deploy_new_token_and_deposit(
:token_bridge_address, :l1_bridge_address, :l1_token, :l2_recipient, :amount_to_deposit
:token_bridge_address,
:l1_bridge_address,
:l1_token,
:depositor,
:l2_recipient,
:amount_to_deposit
);

enable_withdrawal_limit(:token_bridge_address, :l1_token);
Expand Down Expand Up @@ -312,14 +328,19 @@ mod token_bridge_admin_test {
#[should_panic(expected: ('LIMIT_EXCEEDED', 'ENTRYPOINT_FAILED',))]
fn test_failed_initiate_token_withdraw_with_and_without_limits() {
let (l1_bridge_address, l1_token, l1_recipient) = get_default_l1_addresses();

let depositor = EthAddress { address: DEFAULT_DEPOSITOR_ETH_ADDRESS };
let token_bridge_address = deploy_token_bridge();

// Deploy a new token and deposit funds to this token.
let l2_recipient = initial_owner();
let amount_to_deposit = default_amount();
deploy_new_token_and_deposit(
:token_bridge_address, :l1_bridge_address, :l1_token, :l2_recipient, :amount_to_deposit
:token_bridge_address,
:l1_bridge_address,
:l1_token,
:depositor,
:l2_recipient,
:amount_to_deposit
);

enable_withdrawal_limit(:token_bridge_address, :l1_token);
Expand Down Expand Up @@ -357,7 +378,7 @@ mod token_bridge_admin_test {
#[available_gas(30000000)]
fn test_successful_initiate_token_withdraw_with_limits_different_days() {
let (l1_bridge_address, l1_token, l1_recipient) = get_default_l1_addresses();

let depositor = EthAddress { address: DEFAULT_DEPOSITOR_ETH_ADDRESS };
let token_bridge_address = deploy_token_bridge();
set_caller_as_app_role_admin_app_governor(:token_bridge_address);
let token_bridge_admin = get_token_bridge_admin(:token_bridge_address);
Expand All @@ -367,7 +388,12 @@ mod token_bridge_admin_test {
let l2_recipient = initial_owner();
let amount_to_deposit = default_amount();
deploy_new_token_and_deposit(
:token_bridge_address, :l1_bridge_address, :l1_token, :l2_recipient, :amount_to_deposit
:token_bridge_address,
:l1_bridge_address,
:l1_token,
:depositor,
:l2_recipient,
:amount_to_deposit
);

enable_withdrawal_limit(:token_bridge_address, :l1_token);
Expand Down Expand Up @@ -406,14 +432,19 @@ mod token_bridge_admin_test {
#[available_gas(30000000)]
fn test_successful_initiate_token_withdraw_with_limits_same_day_differnet_time() {
let (l1_bridge_address, l1_token, l1_recipient) = get_default_l1_addresses();

let depositor = EthAddress { address: DEFAULT_DEPOSITOR_ETH_ADDRESS };
let token_bridge_address = deploy_token_bridge();

// Deploy a new token and deposit funds to this token.
let l2_recipient = initial_owner();
let amount_to_deposit = default_amount();
deploy_new_token_and_deposit(
:token_bridge_address, :l1_bridge_address, :l1_token, :l2_recipient, :amount_to_deposit
:token_bridge_address,
:l1_bridge_address,
:l1_token,
:depositor,
:l2_recipient,
:amount_to_deposit
);

enable_withdrawal_limit(:token_bridge_address, :l1_token);
Expand Down Expand Up @@ -453,14 +484,19 @@ mod token_bridge_admin_test {
#[should_panic(expected: ('LIMIT_EXCEEDED', 'ENTRYPOINT_FAILED',))]
fn test_failed_initiate_token_withdraw_limit_exceeded_one_withdrawal() {
let (l1_bridge_address, l1_token, l1_recipient) = get_default_l1_addresses();

let depositor = EthAddress { address: DEFAULT_DEPOSITOR_ETH_ADDRESS };
let token_bridge_address = deploy_token_bridge();

// Deploy a new token and deposit funds to this token.
let l2_recipient = initial_owner();
let amount_to_deposit = default_amount();
deploy_new_token_and_deposit(
:token_bridge_address, :l1_bridge_address, :l1_token, :l2_recipient, :amount_to_deposit
:token_bridge_address,
:l1_bridge_address,
:l1_token,
:depositor,
:l2_recipient,
:amount_to_deposit
);

enable_withdrawal_limit(:token_bridge_address, :l1_token);
Expand All @@ -481,14 +517,19 @@ mod token_bridge_admin_test {
#[should_panic(expected: ('LIMIT_EXCEEDED', 'ENTRYPOINT_FAILED',))]
fn test_failed_initiate_token_withdraw_limit_exceeded_two_withdrawals() {
let (l1_bridge_address, l1_token, l1_recipient) = get_default_l1_addresses();

let depositor = EthAddress { address: DEFAULT_DEPOSITOR_ETH_ADDRESS };
let token_bridge_address = deploy_token_bridge();

// Deploy a new token and deposit funds to this token.
let l2_recipient = initial_owner();
let amount_to_deposit = default_amount();
deploy_new_token_and_deposit(
:token_bridge_address, :l1_bridge_address, :l1_token, :l2_recipient, :amount_to_deposit
:token_bridge_address,
:l1_bridge_address,
:l1_token,
:depositor,
:l2_recipient,
:amount_to_deposit
);

enable_withdrawal_limit(:token_bridge_address, :l1_token);
Expand Down Expand Up @@ -517,14 +558,19 @@ mod token_bridge_admin_test {
#[should_panic(expected: ('LIMIT_EXCEEDED', 'ENTRYPOINT_FAILED',))]
fn test_failed_initiate_token_withdraw_limit_exceeded_same_day_different_time() {
let (l1_bridge_address, l1_token, l1_recipient) = get_default_l1_addresses();

let depositor = EthAddress { address: DEFAULT_DEPOSITOR_ETH_ADDRESS };
let token_bridge_address = deploy_token_bridge();

// Deploy a new token and deposit funds to this token.
let l2_recipient = initial_owner();
let amount_to_deposit = default_amount();
deploy_new_token_and_deposit(
:token_bridge_address, :l1_bridge_address, :l1_token, :l2_recipient, :amount_to_deposit
:token_bridge_address,
:l1_bridge_address,
:l1_token,
:depositor,
:l2_recipient,
:amount_to_deposit
);

// Limit the withdrawal amount.
Expand Down
Loading

0 comments on commit a4caa78

Please sign in to comment.