Skip to content

Commit

Permalink
support tzip27
Browse files Browse the repository at this point in the history
  • Loading branch information
rueshyna committed Jan 19, 2024
1 parent cee65a3 commit 3b31eae
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/internal/conditions.mligo
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ let check_proposal (content: proposal_content) : unit =
assert_with_error (p > 0) Errors.invalid_effective_period
| Add_or_update_metadata _ -> ()
| Remove_metadata _ -> ()
| Proof_of_event _ -> ()

let not_empty_content (proposals_content: proposal_content list) : unit =
let () = assert_with_error ((List.length proposals_content) > 0n) Errors.no_proposal in
Expand Down
6 changes: 6 additions & 0 deletions src/internal/contract.mligo
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

type parameter_types = Parameter.Types.t
type proposal_id = Parameter.Types.proposal_id
type payload = Parameter.Types.payload
type storage_types = Storage.Types.t
type storage_types_proposal = Storage.Types.proposal
type storage_types_proposal_state = Storage.Types.proposal_state
Expand Down Expand Up @@ -104,6 +105,9 @@ let resolve_proposal
let archive = Tezos.emit "%archive_proposal" ({ proposal_id ; proposal = Bytes.pack proposal }: Event.Types.archive_proposal ) in
(event::archive::ops, storage)

let proof_of_event_challenge (payload, storage : payload * storage_types) : result =
create_proposal ([Proof_of_event {payload}], storage)

let contract (action, storage : request) : result =
let ops, storage =
match action with
Expand All @@ -114,6 +118,8 @@ let contract (action, storage : request) : result =
sign_proposal (proposal_id, proposal_contents, agreement, storage)
| Resolve_proposal { proposal_id; proposal_contents } ->
resolve_proposal (proposal_id, proposal_contents, storage)
| Proof_of_event_challenge { payload } ->
proof_of_event_challenge (payload, storage)
in
let () = Conditions.check_setting storage in
(ops, storage)
2 changes: 2 additions & 0 deletions src/internal/event.mligo
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ module Types = struct
type proposal_id = Parameter.Types.proposal_id
type agreement = Parameter.Types.agreement
type proposal_state = Storage.Types.proposal_state
type payload = Parameter.Types.payload

type create_proposal = { proposal_id: proposal_id;}
type sign_proposal = { proposal_id: proposal_id; signer: address; agreement: agreement}
type resolve_proposal = { proposal_id: proposal_id; proposal_state: proposal_state}
type archive_proposal = { proposal_id: proposal_id; proposal: bytes }
type receiving_tez = { from :address ; amount : tez}
type proof_of_event = { payload: payload}
end
3 changes: 3 additions & 0 deletions src/internal/execution.mligo
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ let send (content : proposal_content) (storage : storage_types)
| Adjust_effective_period i -> ([], Storage.Op.adjust_effective_period i storage)
| Add_or_update_metadata { key; value } -> ([], Storage.Op.update_metadata (key, (Some value), storage))
| Remove_metadata { key } -> ([], Storage.Op.update_metadata (key, None, storage))
| Proof_of_event { payload } ->
let event = Tezos.emit "%proof_of_event" ({ payload } : Event.Types.proof_of_event) in
([event], storage)

let perform_operations
(proposal_id: storage_types_proposal_id)
Expand Down
2 changes: 2 additions & 0 deletions src/internal/parameter.mligo
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ module Types = struct
type proposal_id = nat
type agreement = bool
type expiration_time = timestamp
type payload = bytes

type t =
| Default of unit
| Create_proposal of { proposal_contents: proposal_content list }
| Sign_proposal of { proposal_id: proposal_id; proposal_contents: proposal_content list; agreement: agreement }
| Resolve_proposal of { proposal_id: proposal_id; proposal_contents: proposal_content list }
| Proof_of_event_challenge of { payload: payload }
end
1 change: 1 addition & 0 deletions src/internal/proposal_content.mligo
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ module Types = struct
| Adjust_effective_period of int
| Add_or_update_metadata of { key: string; value: bytes; }
| Remove_metadata of { key: string }
| Proof_of_event of { payload: bytes}
end
3 changes: 3 additions & 0 deletions test/common/helper.mligo
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ let originate (level: Breath.Logger.level) (main : request -> result) (init_stor
init_storage
amount

let proof_of_event_challenge (amount: tez) (contract : (parameter_types, storage_types) originated) (payload : payload) () =
Breath.Contract.transfer_with_entrypoint_to contract "proof_of_event_challenge" payload amount

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

Expand Down
2 changes: 2 additions & 0 deletions test/test.mligo
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#import "./test_disapproval.mligo" "Disapproval"
#import "./test_expiration_time.mligo" "Exp_date"
#import "./test_update_metadata.mligo" "Update_metadata"
#import "./test_tzip27.mligo" "Tzip27"

let () =
Breath.Model.run_suites Void
Expand All @@ -45,4 +46,5 @@ let () =
; Disapproval.test_suite
; Exp_date.test_suite
; Update_metadata.test_suite
; Tzip27.test_suite
]
81 changes: 81 additions & 0 deletions test/test_tzip27.mligo
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
(* MIT License
Copyright (c) 2022 Marigold <[email protected]>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. *)

#import "ligo-breathalyzer/lib/lib.mligo" "Breath"
#import "./common/helper.mligo" "Helper"
#import "./common/assert.mligo" "Assert"
#import "./common/util.mligo" "Util"
#import "./common/mock_contract.mligo" "Mock_contract"
#import "../src/internal/proposal_content.mligo" "Proposal_content"
#import "../src/internal/event.mligo" "Event"
#import "../app/main.mligo" "App"

type proposal_content = Proposal_content.Types.t

let case_emit_poe =
Breath.Model.case
"test emit poe"
"successuful emit poe"
(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, 1n) in
let multisig_contract = Helper.originate level App.main init_storage 0tez in

let payload = 0x01 in
let param = ([Proof_of_event {payload}] : proposal_content list) in

let action = Breath.Context.act_as alice (Helper.proof_of_event_challenge 0tez multisig_contract payload) in
let sign_action = Breath.Context.act_as bob (Helper.sign_proposal multisig_contract 1n true param) in
let resolve_action = Breath.Context.act_as bob (Helper.resolve_proposal multisig_contract 1n param) in
let multisig_address = multisig_contract.originated_address in

let events = (Util.get_last_events_from multisig_address "proof_of_event" : Event.Types.proof_of_event list) in

let { payload = expected_payload }
= Option.unopt (List.head_opt events) in

Breath.Result.reduce [
action
; sign_action
; resolve_action
; Breath.Assert.is_equal "payload of poe" expected_payload payload
])

let case_process_poe_challenge_with_non_zero_amount =
Breath.Model.case
"test process poe challange with 1tez"
"fail to process proof_of_event_challenge"
(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, 1n) in
let multisig_contract = Helper.originate level App.main init_storage 0tez in

let payload = 0x01 in

let action = Breath.Context.act_as alice (Helper.proof_of_event_challenge 1tez multisig_contract payload) in
Breath.Result.reduce [
Breath.Expect.fail_with_message "You must not send tez to the smart contract" action
])

let test_suite =
Breath.Model.suite "Suite for tzip17" [
case_emit_poe
; case_process_poe_challenge_with_non_zero_amount
]

0 comments on commit 3b31eae

Please sign in to comment.