Skip to content

Commit

Permalink
fix: crerate/sign/resolve proposal shouldn't accept tez
Browse files Browse the repository at this point in the history
  • Loading branch information
rueshyna committed May 30, 2023
1 parent 43bd292 commit ef18593
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/internal/contract.mligo
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ let sign_proposal (type a)
* a storage_types)
: a result =
let () = Conditions.only_owner storage in
let () = Conditions.amount_must_be_zero_tez (Tezos.get_amount ()) in
let proposal = Storage.Op.retrieve_proposal(proposal_id, storage) in
let () = Conditions.unresolved proposal.state in
let () = Conditions.unsigned proposal in
Expand All @@ -89,6 +90,7 @@ let resolve_proposal (type a)
* a storage_types)
: a result =
let () = Conditions.only_owner storage in
let () = Conditions.amount_must_be_zero_tez (Tezos.get_amount ()) in
let proposal = Storage.Op.retrieve_proposal(proposal_id, storage) in
let () = Conditions.unresolved proposal.state in
let () = Conditions.check_proposals_content proposal_content proposal.contents in
Expand Down
21 changes: 15 additions & 6 deletions test/common/helper.mligo
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,20 @@ let originate (type a) (level: Breath.Logger.level) (main : a request -> a resul
init_storage
amount

let create_proposal (type a) (contract : (a parameter_types, a storage_types) originated) (proposal : (a proposal_content) list) () =
Breath.Contract.transfer_with_entrypoint_to contract "create_proposal" proposal 0tez
let create_proposal_with_amount (type a) (amount : tez) (contract : (a parameter_types, a storage_types) originated) (proposal : (a proposal_content) list) () =
Breath.Contract.transfer_with_entrypoint_to contract "create_proposal" proposal amount

let sign_proposal (type a) (contract : (a parameter_types, a storage_types) originated) (proposal_id : nat) (agreement : bool) (proposal : (a proposal_content) list) () =
Breath.Contract.transfer_with_entrypoint_to contract "sign_proposal" (proposal_id, proposal, agreement) 0tez
let sign_proposal_with_amount (type a) (amount : tez) (contract : (a parameter_types, a storage_types) originated) (proposal_id : nat) (agreement : bool) (proposal : (a proposal_content) list) () =
Breath.Contract.transfer_with_entrypoint_to contract "sign_proposal" (proposal_id, proposal, agreement) amount

let resolve_proposal (type a) (contract : (a parameter_types, a storage_types) originated) (proposal_id : nat) (proposal : (a proposal_content) list) () =
Breath.Contract.transfer_with_entrypoint_to contract "resolve_proposal" (proposal_id, proposal) 0tez
let resolve_proposal_with_amount (type a) (amount : tez) (contract : (a parameter_types, a storage_types) originated) (proposal_id : nat) (proposal : (a proposal_content) list) () =
Breath.Contract.transfer_with_entrypoint_to contract "resolve_proposal" (proposal_id, proposal) amount

let create_proposal =
create_proposal_with_amount 0tez

let sign_proposal =
sign_proposal_with_amount 0tez

let resolve_proposal =
resolve_proposal_with_amount 0tez
19 changes: 19 additions & 0 deletions test/test_basic_proposal.mligo
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,31 @@ let case_unauthorized_user_fail_to_create_proposal =
; Breath.Assert.is_equal "the counter of proposal" storage.proposal_counter 0n
])

let case_fail_to_create_proposal_with_nonzero_amount =
Breath.Model.case
"create proposal with nonzero amount"
"fail to create proposal"
(fun (level: Breath.Logger.level) ->
let (_, (alice, bob, carol)) = Breath.Context.init_default () in
let owners : address set = Set.literal [alice.address; bob.address;] in
let init_storage = Helper.init_storage (owners, 2n) in
let multisig_contract = Helper.originate level Mock_contract.multisig_main init_storage 0tez in

(* create proposal 1 *)
let param1 = [Transfer { target = alice.address; parameter=(); amount = 0tez;}] in
let action1 = Breath.Context.act_as alice (Helper.create_proposal_with_amount 1tez multisig_contract param1) in

Breath.Result.reduce [
Breath.Expect.fail_with_message "You must not send tez to the smart contract" action1
])

let test_suite =
Breath.Model.suite "Suite for create proposal" [
case_create_proposal
; case_unauthorized_user_fail_to_create_proposal
; case_fail_to_create_empty_proposal
; case_fail_to_create_transfer_0_amount_proposal
; case_fail_to_create_proposal_with_empty_owner_adjustment
; case_fail_to_create_proposal_with_nonzero_amount
]

26 changes: 26 additions & 0 deletions test/test_resolve_proposal_entrypoint.mligo
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,31 @@ let case_resolve_proposal =
})
])

let case_fail_to_resolve_proposal_with_nonzero_amount =
Breath.Model.case
"test resolve proposal with nonzero amount"
"fail resolve proposal"
(fun (level: Breath.Logger.level) ->
let (_, (alice, bob, carol)) = Breath.Context.init_default () in
let owners : address set = Set.literal [alice.address; bob.address; carol.address] in
let init_storage = Helper.init_storage (owners, 1n) in
let multisig_contract = Helper.originate level Mock_contract.multisig_main init_storage 100tez in
let param = ([] : (nat proposal_content) list) in

(* create proposal 1 *)
let param1 = (Transfer { target = alice.address; parameter = (); amount = 10tez;} :: param) in
let create_action1 = Breath.Context.act_as alice (Helper.create_proposal multisig_contract param1) in
let sign_action1 = Breath.Context.act_as bob (Helper.sign_proposal multisig_contract 1n true param1) in
let exe_action1 = Breath.Context.act_as bob (Helper.resolve_proposal_with_amount 1tez multisig_contract 1n param1) in


Breath.Result.reduce [
create_action1
; sign_action1
; Breath.Expect.fail_with_message "You must not send tez to the smart contract" exe_action1
])


let case_fail_to_resolve_proposal_twice =
Breath.Model.case
"test execute proposal twice"
Expand Down Expand Up @@ -377,6 +402,7 @@ let case_execute_transaction_3_of_3 =
let test_suite =
Breath.Model.suite "Suite for resolving proposal" [
case_resolve_proposal
; case_fail_to_resolve_proposal_with_nonzero_amount
; case_fail_to_resolve_proposal_twice
; case_not_owner
; case_no_enough_signature
Expand Down
21 changes: 21 additions & 0 deletions test/test_sign_only_entrypoint.mligo
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,26 @@ let case_gathering_signatures =
})
])

let case_fail_to_sign_proposal_with_nonzero_amount =
Breath.Model.case
"sign the proposal with nonzero amount"
"fail to sign"
(fun (level: Breath.Logger.level) ->
let (_, (alice, bob, _carol)) = Breath.Context.init_default () in
let owners : address set = Set.literal [alice.address; bob.address;] in
let init_storage = Helper.init_storage (owners, 2n) in
let multisig_contract = Helper.originate level Mock_contract.multisig_main init_storage 0tez in
let param = ([] : (nat proposal_content) list) in

let param1 = (Transfer { target = alice.address; parameter=(); amount = 10tez;} :: param) in
let action1 = Breath.Context.act_as alice (Helper.create_proposal multisig_contract param1) in
let sign_action1 = Breath.Context.act_as bob (Helper.sign_proposal_with_amount 1tez multisig_contract 1n true param1) in

Breath.Result.reduce [
action1
; Breath.Expect.fail_with_message "You must not send tez to the smart contract" sign_action1
])

let case_fail_double_sign =
Breath.Model.case
"sign the same proposal twice"
Expand Down Expand Up @@ -224,6 +244,7 @@ let case_wrong_content_bytes =
let test_suite =
Breath.Model.suite "Suite for sign proposal only" [
case_gathering_signatures
; case_fail_to_sign_proposal_with_nonzero_amount
; case_fail_double_sign
; case_unauthorized_user_fail_to_sign
; case_sign_nonexisted_proposal
Expand Down

0 comments on commit ef18593

Please sign in to comment.