Skip to content

Commit

Permalink
Amended tests to work with new split contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
glottologist committed Sep 8, 2023
1 parent 7d5f7c3 commit 3480734
Show file tree
Hide file tree
Showing 19 changed files with 194 additions and 97 deletions.
6 changes: 4 additions & 2 deletions batcher/batcher.mligo
Original file line number Diff line number Diff line change
Expand Up @@ -1214,9 +1214,11 @@ let enforce_correct_side
(order:external_swap_order)
(valid_swap:valid_swap_reduced) : unit =
let swap = order.swap in
if order.side = 0n then
let side = Utils.nat_to_side order.side in
match side with
| Buy ->
if swap.from.token.name = valid_swap.swap.from then () else failwith Errors.incorrect_side_specified
else
| Sell ->
if swap.from.token.name = valid_swap.swap.to then () else failwith Errors.incorrect_side_specified

(* Register a deposit during a valid (Open) deposit time; fails otherwise.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#import "ligo-breathalyzer/lib/lib.mligo" "Breath"
#import "./../../../common/helpers.mligo" "Helpers"
#import "../../../../batcher.mligo" "Batcher"
#import "../../../../errors.mligo" "Errors"

let get_tzbtc_eurl_swap_pair
(disabled: bool)
Expand Down Expand Up @@ -76,7 +77,7 @@ let add_swap_pair_should_fail_if_user_is_non_admin =

Breath.Result.reduce [
Breath.Assert.is_equal "swap pair should not already exist" None swap_pair_does_not_already_exist
; Breath.Expect.fail_with_value Batcher.sender_not_administrator act_add_swap_pair
; Breath.Expect.fail_with_value Errors.sender_not_administrator act_add_swap_pair
; Breath.Assert.is_equal "swap pair still does not exist" None added_swap_pair_reduced
])

Expand All @@ -97,7 +98,7 @@ let add_swap_pair_should_fail_if_tez_is_supplied =

Breath.Result.reduce [
Breath.Assert.is_equal "swap pair should not already exist" None swap_pair_does_not_already_exist
; Breath.Expect.fail_with_value Batcher.endpoint_does_not_accept_tez act_add_swap_pair
; Breath.Expect.fail_with_value Errors.endpoint_does_not_accept_tez act_add_swap_pair
; Breath.Assert.is_equal "swap pair still does not exist" None added_swap_pair_reduced
])

Expand Down Expand Up @@ -152,7 +153,7 @@ let remove_swap_pair_should_fail_if_user_is_non_admin =
Breath.Assert.is_equal "swap pair should not already exist" None swap_pair_does_not_already_exist
; act_add_swap_pair
; Breath.Assert.is_equal "swap pair should have been added" swap_pair_reduced added_swap_pair_reduced
; Breath.Expect.fail_with_value Batcher.sender_not_administrator act_remove_swap_pair
; Breath.Expect.fail_with_value Errors.sender_not_administrator act_remove_swap_pair
; Breath.Assert.is_equal "swap pair should still exist" swap_pair_reduced removed_swap_pair_reduced
])

Expand Down Expand Up @@ -180,7 +181,7 @@ let remove_swap_pair_should_fail_if_tez_is_supplied =
Breath.Assert.is_equal "swap pair should not already exist" None swap_pair_does_not_already_exist
; act_add_swap_pair
; Breath.Assert.is_equal "swap pair should have been added" swap_pair_reduced added_swap_pair_reduced
; Breath.Expect.fail_with_value Batcher.endpoint_does_not_accept_tez act_remove_swap_pair
; Breath.Expect.fail_with_value Errors.endpoint_does_not_accept_tez act_remove_swap_pair
; Breath.Assert.is_equal "swap pair should still exist" swap_pair_reduced removed_swap_pair_reduced
])

Expand All @@ -201,7 +202,7 @@ let remove_swap_pair_should_fail_if_swap_does_not_exist =
let removed_swap_pair_reduced = Map.find_opt "tzBTC/EURL" r_storage.valid_swaps in
Breath.Result.reduce [
Breath.Assert.is_equal "swap pair should not already exist" None swap_pair_does_not_already_exist
; Breath.Expect.fail_with_value Batcher.swap_does_not_exist act_remove_swap_pair
; Breath.Expect.fail_with_value Errors.swap_does_not_exist act_remove_swap_pair
; Breath.Assert.is_equal "swap pair should have been removed" None removed_swap_pair_reduced
])

Expand All @@ -222,7 +223,7 @@ let remove_swap_pair_should_fail_if_swap_is_not_disabled =
let removed_swap_pair_reduced = Map.find_opt "tzBTC/EURL" r_storage.valid_swaps in
Breath.Result.reduce [
Breath.Assert.is_equal "swap pair should not already exist" None swap_pair_does_not_already_exist
; Breath.Expect.fail_with_value Batcher.cannot_remove_swap_pair_that_is_not_disabled act_remove_swap_pair
; Breath.Expect.fail_with_value Errors.cannot_remove_swap_pair_that_is_not_disabled act_remove_swap_pair
; Breath.Assert.is_equal "swap pair should have been removed" None removed_swap_pair_reduced
])

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#import "ligo-breathalyzer/lib/lib.mligo" "Breath"
#import "./../../../common/helpers.mligo" "Helpers"
#import "../../../../batcher.mligo" "Batcher"
#import "../../../../errors.mligo" "Errors"

let test_metadata = ("546573742044617461" : bytes)
let updated_test_metadata = ("5570646174656420546573742044617461" : bytes)
Expand Down Expand Up @@ -67,11 +68,11 @@ let change_metadata_should_fail_if_user_is_not_admin =

Breath.Result.reduce [
Breath.Assert.is_equal "metadata should be empty" None initial_metadata
; Breath.Expect.fail_with_value Batcher.sender_not_administrator act_add_metadata
; Breath.Expect.fail_with_value Errors.sender_not_administrator act_add_metadata
; Breath.Assert.is_equal "metadata should be empty" None added_meta
; Breath.Expect.fail_with_value Batcher.sender_not_administrator act_update_metadata
; Breath.Expect.fail_with_value Errors.sender_not_administrator act_update_metadata
; Breath.Assert.is_equal "metadata should be empty" None updated_meta
; Breath.Expect.fail_with_value Batcher.sender_not_administrator act_remove_metadata
; Breath.Expect.fail_with_value Errors.sender_not_administrator act_remove_metadata
; Breath.Assert.is_equal "metadata should be empty" None removed_meta
])

Expand All @@ -97,11 +98,11 @@ let change_metadata_should_fail_if_tez_is_supplied =

Breath.Result.reduce [
Breath.Assert.is_equal "metadata should be empty" None initial_metadata
; Breath.Expect.fail_with_value Batcher.endpoint_does_not_accept_tez act_add_metadata
; Breath.Expect.fail_with_value Errors.endpoint_does_not_accept_tez act_add_metadata
; Breath.Assert.is_equal "metadata should be empty" None added_meta
; Breath.Expect.fail_with_value Batcher.endpoint_does_not_accept_tez act_update_metadata
; Breath.Expect.fail_with_value Errors.endpoint_does_not_accept_tez act_update_metadata
; Breath.Assert.is_equal "metadata should be empty" None updated_meta
; Breath.Expect.fail_with_value Batcher.endpoint_does_not_accept_tez act_remove_metadata
; Breath.Expect.fail_with_value Errors.endpoint_does_not_accept_tez act_remove_metadata
; Breath.Assert.is_equal "metadata should be empty" None removed_meta
])

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#import "ligo-breathalyzer/lib/lib.mligo" "Breath"
#import "./../../../common/helpers.mligo" "Helpers"
#import "../../../../batcher.mligo" "Batcher"
#import "../../../../errors.mligo" "Errors"


let amend_token_pair_limit_should_succeed_if_user_is_admin =
Expand Down Expand Up @@ -35,7 +36,7 @@ let amend_token_pair_limit_should_fail_if_user_is_not_admin =

Breath.Result.reduce [
Breath.Assert.is_equal "old limit" 10n old_storage.limit_on_tokens_or_pairs
; Breath.Expect.fail_with_value Batcher.sender_not_administrator act_amend_token_pair_limit
; Breath.Expect.fail_with_value Errors.sender_not_administrator act_amend_token_pair_limit
; Breath.Assert.is_equal "limit unchanged" 10n new_storage.limit_on_tokens_or_pairs
])

Expand All @@ -53,7 +54,7 @@ let amend_token_pair_limit_should_fail_if_tez_is_sent =

Breath.Result.reduce [
Breath.Assert.is_equal "old limit" 10n old_storage.limit_on_tokens_or_pairs
; Breath.Expect.fail_with_value Batcher.endpoint_does_not_accept_tez act_amend_token_pair_limit
; Breath.Expect.fail_with_value Errors.endpoint_does_not_accept_tez act_amend_token_pair_limit
; Breath.Assert.is_equal "limit unchanged" 10n new_storage.limit_on_tokens_or_pairs
])

Expand All @@ -71,7 +72,7 @@ let amend_token_pair_limit_should_fail_if_limit_is_less_than_current_tokens =

Breath.Result.reduce [
Breath.Assert.is_equal "old limit" 10n old_storage.limit_on_tokens_or_pairs
; Breath.Expect.fail_with_value Batcher.cannot_reduce_limit_on_tokens_to_less_than_already_exists act_amend_token_pair_limit
; Breath.Expect.fail_with_value Errors.cannot_reduce_limit_on_tokens_to_less_than_already_exists act_amend_token_pair_limit
; Breath.Assert.is_equal "limit unchanged" 10n new_storage.limit_on_tokens_or_pairs
])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#import "ligo-breathalyzer/lib/lib.mligo" "Breath"
#import "./../../../common/helpers.mligo" "Helpers"
#import "../../../../batcher.mligo" "Batcher"
#import "../../../../errors.mligo" "Errors"


let change_admin_address_should_succeed_if_user_is_admin =
Expand Down Expand Up @@ -36,7 +37,7 @@ let change_admin_address_should_fail_if_user_is_not_admin =

Breath.Result.reduce [
Breath.Assert.is_equal "old address" context.admin.address old_storage.administrator
; Breath.Expect.fail_with_value Batcher.sender_not_administrator act_change_admin_address
; Breath.Expect.fail_with_value Errors.sender_not_administrator act_change_admin_address
; Breath.Assert.is_equal "address unchanged" context.admin.address new_storage.administrator
])

Expand All @@ -54,7 +55,7 @@ let change_admin_address_should_fail_if_tez_is_sent =

Breath.Result.reduce [
Breath.Assert.is_equal "old address" context.admin.address old_storage.administrator
; Breath.Expect.fail_with_value Batcher.endpoint_does_not_accept_tez act_change_admin_address
; Breath.Expect.fail_with_value Errors.endpoint_does_not_accept_tez act_change_admin_address
; Breath.Assert.is_equal "address unchanged" context.admin.address new_storage.administrator
])

Expand All @@ -72,7 +73,7 @@ let change_admin_address_should_fail_if_new_address_is_the_same_as_fee_recipient

Breath.Result.reduce [
Breath.Assert.is_equal "old address" context.admin.address old_storage.administrator
; Breath.Expect.fail_with_value Batcher.admin_and_fee_recipient_address_cannot_be_the_same act_change_admin_address
; Breath.Expect.fail_with_value Errors.admin_and_fee_recipient_address_cannot_be_the_same act_change_admin_address
; Breath.Assert.is_equal "address unchanged" context.admin.address new_storage.administrator
])

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#import "ligo-breathalyzer/lib/lib.mligo" "Breath"
#import "./../../../common/helpers.mligo" "Helpers"
#import "../../../../batcher.mligo" "Batcher"
#import "../../../../errors.mligo" "Errors"


let change_deposit_time_window_should_succeed_if_user_is_admin =
Expand Down Expand Up @@ -35,7 +36,7 @@ let change_deposit_time_window_should_fail_if_user_is_not_admin =

Breath.Result.reduce [
Breath.Assert.is_equal "time window" 600n old_storage.deposit_time_window_in_seconds
; Breath.Expect.fail_with_value Batcher.sender_not_administrator act_change_deposit_time_window
; Breath.Expect.fail_with_value Errors.sender_not_administrator act_change_deposit_time_window
; Breath.Assert.is_equal "time window unchanged" 600n new_storage.deposit_time_window_in_seconds
])

Expand All @@ -53,7 +54,7 @@ let change_deposit_time_window_should_fail_if_tez_is_sent =

Breath.Result.reduce [
Breath.Assert.is_equal "time window" 600n old_storage.deposit_time_window_in_seconds
; Breath.Expect.fail_with_value Batcher.endpoint_does_not_accept_tez act_change_deposit_time_window
; Breath.Expect.fail_with_value Errors.endpoint_does_not_accept_tez act_change_deposit_time_window
; Breath.Assert.is_equal "time window unchanged" 600n new_storage.deposit_time_window_in_seconds
])

Expand All @@ -71,7 +72,7 @@ let change_deposit_time_window_should_fail_if_below_minimum_window =

Breath.Result.reduce [
Breath.Assert.is_equal "time window" 600n old_storage.deposit_time_window_in_seconds
; Breath.Expect.fail_with_value Batcher.cannot_update_deposit_window_to_less_than_the_minimum act_change_deposit_time_window
; Breath.Expect.fail_with_value Errors.cannot_update_deposit_window_to_less_than_the_minimum act_change_deposit_time_window
; Breath.Assert.is_equal "time window unchanged" 600n new_storage.deposit_time_window_in_seconds
])

Expand All @@ -89,7 +90,7 @@ let change_deposit_time_window_should_fail_if_above_maximum_window =

Breath.Result.reduce [
Breath.Assert.is_equal "time window" 600n old_storage.deposit_time_window_in_seconds
; Breath.Expect.fail_with_value Batcher.cannot_update_deposit_window_to_more_than_the_maximum act_change_deposit_time_window
; Breath.Expect.fail_with_value Errors.cannot_update_deposit_window_to_more_than_the_maximum act_change_deposit_time_window
; Breath.Assert.is_equal "time window unchanged" 600n new_storage.deposit_time_window_in_seconds
])

Expand Down
5 changes: 3 additions & 2 deletions batcher/test/batcher/endpoints/admin/test_change_fee.mligo
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#import "ligo-breathalyzer/lib/lib.mligo" "Breath"
#import "./../../../common/helpers.mligo" "Helpers"
#import "../../../../batcher.mligo" "Batcher"
#import "../../../../errors.mligo" "Errors"


let change_fee_should_succeed_if_user_is_admin =
Expand Down Expand Up @@ -41,7 +42,7 @@ let change_fee_should_fail_if_user_is_not_admin =

Breath.Result.reduce [
Breath.Assert.is_equal "old fee" old_fee old_storage.fee_in_mutez
; Breath.Expect.fail_with_value Batcher.sender_not_administrator act_change_fee
; Breath.Expect.fail_with_value Errors.sender_not_administrator act_change_fee
; Breath.Assert.is_equal "old fee is unchanged" old_fee new_storage.fee_in_mutez
])

Expand All @@ -60,7 +61,7 @@ let change_fee_should_fail_if_tez_is_sent =

Breath.Result.reduce [
Breath.Assert.is_equal "old fee" old_fee old_storage.fee_in_mutez
; Breath.Expect.fail_with_value Batcher.endpoint_does_not_accept_tez act_change_fee
; Breath.Expect.fail_with_value Errors.endpoint_does_not_accept_tez act_change_fee
; Breath.Assert.is_equal "old fee is unchanged" old_fee new_storage.fee_in_mutez
])
let test_suite =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#import "ligo-breathalyzer/lib/lib.mligo" "Breath"
#import "./../../../common/helpers.mligo" "Helpers"
#import "../../../../batcher.mligo" "Batcher"
#import "../../../../errors.mligo" "Errors"


let change_fee_recipient_address_should_succeed_if_user_is_admin =
Expand Down Expand Up @@ -36,7 +37,7 @@ let change_fee_recipient_address_should_fail_if_user_is_not_admin =

Breath.Result.reduce [
Breath.Assert.is_equal "old address" context.admin.address old_storage.administrator
; Breath.Expect.fail_with_value Batcher.sender_not_administrator act_change_fee_recipient_address
; Breath.Expect.fail_with_value Errors.sender_not_administrator act_change_fee_recipient_address
; Breath.Assert.is_equal "address unchanged" context.admin.address new_storage.administrator
])

Expand All @@ -54,7 +55,7 @@ let change_fee_recipient_address_should_fail_if_tez_is_sent =

Breath.Result.reduce [
Breath.Assert.is_equal "old address" context.admin.address old_storage.administrator
; Breath.Expect.fail_with_value Batcher.endpoint_does_not_accept_tez act_change_fee_recipient_address
; Breath.Expect.fail_with_value Errors.endpoint_does_not_accept_tez act_change_fee_recipient_address
; Breath.Assert.is_equal "address unchanged" context.admin.address new_storage.administrator
])

Expand All @@ -72,7 +73,7 @@ let change_fee_recipient_address_should_fail_if_new_address_is_the_same_as_admin

Breath.Result.reduce [
Breath.Assert.is_equal "old address" context.fee_recipient old_storage.fee_recipient
; Breath.Expect.fail_with_value Batcher.admin_and_fee_recipient_address_cannot_be_the_same act_change_fee_recipient_address
; Breath.Expect.fail_with_value Errors.admin_and_fee_recipient_address_cannot_be_the_same act_change_fee_recipient_address
; Breath.Assert.is_equal "address unchanged" context.fee_recipient new_storage.fee_recipient
])

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#import "ligo-breathalyzer/lib/lib.mligo" "Breath"
#import "./../../../common/helpers.mligo" "Helpers"
#import "../../../../batcher.mligo" "Batcher"
#import "../../../../errors.mligo" "Errors"

let pair = "tzBTC/USDT"
let oraclepair = "BTC-USDT"
Expand Down Expand Up @@ -48,7 +49,7 @@ let change_oracle_source_should_fail_if_the_user_is_non_admin =
Breath.Result.reduce [
Breath.Assert.is_equal "new price" new_oracle_price old_price
; Breath.Assert.is_equal "old address" oracle.originated_address test_swap.oracle_address
; Breath.Expect.fail_with_value Batcher.sender_not_administrator act_change_oracle_source
; Breath.Expect.fail_with_value Errors.sender_not_administrator act_change_oracle_source
; Breath.Assert.is_equal "old address unchanged" oracle.originated_address new_test_swap.oracle_address
])

Expand All @@ -71,7 +72,7 @@ let change_oracle_source_should_fail_if_tez_is_sent =
Breath.Result.reduce [
Breath.Assert.is_equal "new price" new_oracle_price old_price
; Breath.Assert.is_equal "old address" oracle.originated_address test_swap.oracle_address
; Breath.Expect.fail_with_value Batcher.endpoint_does_not_accept_tez act_change_oracle_source
; Breath.Expect.fail_with_value Errors.endpoint_does_not_accept_tez act_change_oracle_source
; Breath.Assert.is_equal "old address unchanged" oracle.originated_address new_test_swap.oracle_address
])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#import "ligo-breathalyzer/lib/lib.mligo" "Breath"
#import "./../../../common/helpers.mligo" "Helpers"
#import "../../../../batcher.mligo" "Batcher"
#import "../../../../errors.mligo" "Errors"


let enable_disable_swap_pair_should_succeed_if_user_is_admin =
Expand Down Expand Up @@ -42,9 +43,9 @@ let enable_disable_swap_pair_should_fail_if_user_is_not_admin =

Breath.Result.reduce [
Breath.Assert.is_equal "pair should be enabled" false initial_pair.is_disabled_for_deposits
; Breath.Expect.fail_with_value Batcher.sender_not_administrator act_disable_swap_pair
; Breath.Expect.fail_with_value Errors.sender_not_administrator act_disable_swap_pair
; Breath.Assert.is_equal "pair should still be enabled" false disabled_pair.is_disabled_for_deposits
; Breath.Expect.fail_with_value Batcher.sender_not_administrator act_enable_swap_pair
; Breath.Expect.fail_with_value Errors.sender_not_administrator act_enable_swap_pair
; Breath.Assert.is_equal "pair should still be enabled" false enabled_pair.is_disabled_for_deposits
])

Expand All @@ -64,9 +65,9 @@ let enable_disable_swap_pair_should_fail_if_tez_is_supplied =

Breath.Result.reduce [
Breath.Assert.is_equal "pair should be enabled" false initial_pair.is_disabled_for_deposits
; Breath.Expect.fail_with_value Batcher.endpoint_does_not_accept_tez act_disable_swap_pair
; Breath.Expect.fail_with_value Errors.endpoint_does_not_accept_tez act_disable_swap_pair
; Breath.Assert.is_equal "pair should still be enabled" false disabled_pair.is_disabled_for_deposits
; Breath.Expect.fail_with_value Batcher.endpoint_does_not_accept_tez act_enable_swap_pair
; Breath.Expect.fail_with_value Errors.endpoint_does_not_accept_tez act_enable_swap_pair
; Breath.Assert.is_equal "pair should still be enabled" false enabled_pair.is_disabled_for_deposits
])

Expand Down
3 changes: 2 additions & 1 deletion batcher/test/batcher/endpoints/user/test_cancellations.mligo
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#import "./../../../common/helpers.mligo" "Helpers"
#import "./../../../common/batch.mligo" "Batch"
#import "../../../../batcher.mligo" "Batcher"
#import "../../../../errors.mligo" "Errors"

type skew = Batch.skew
type pressure = Batch.pressure
Expand All @@ -21,7 +22,7 @@ let cancellation_fail_if_batch_is_closed =
let act_cancel = Breath.Context.act_as btc_trader (fun (_u:unit) -> (Breath.Contract.transfer_to batcher (Cancel pair) 0tez)) in

Breath.Result.reduce [
Breath.Expect.fail_with_value Batcher.cannot_cancel_orders_for_a_batch_that_is_not_open act_cancel
Breath.Expect.fail_with_value Errors.cannot_cancel_orders_for_a_batch_that_is_not_open act_cancel
])

let cancellation_should_succeed =
Expand Down
Loading

0 comments on commit 3480734

Please sign in to comment.