Skip to content

Commit

Permalink
Merge d6f5374 into 39a4524
Browse files Browse the repository at this point in the history
  • Loading branch information
rueshyna authored Nov 1, 2023
2 parents 39a4524 + d6f5374 commit 4e119c4
Show file tree
Hide file tree
Showing 10 changed files with 126 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "TzSafe",
"version": "0.3.1",
"version": "0.3.2",
"author": "Marigold <contact@marigold.dev>",
"description": "TzSafe is a multisig wallet aiming at providing better assurance of security and management of ownership than a traditional single-signed wallet. The implementation adheres to the guidelines specified in TZIP-27.",
"scripts": {
Expand Down
2 changes: 2 additions & 0 deletions src/internal/conditions.mligo
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ let check_proposal (content: proposal_content) : unit =
assert_with_error (Set.cardinal s > 0n) Errors.no_owners
| Adjust_effective_period p ->
assert_with_error (p > 0) Errors.invalid_effective_period
| Add_or_update_metadata _ -> ()
| Remove_metadata _ -> ()

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
9 changes: 0 additions & 9 deletions src/internal/contract.mligo
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,6 @@ let resolve_proposal
let event = Tezos.emit "%resolve_proposal" ({ challenge_id = challenge_id; proposal_state = proposal.state } : Event.Types.resolve_proposal) in
(event::ops, storage)

(**
* Update Metadata
*)
let update_metadata (key, value, storage : string * bytes * storage_types) : result =
let s = Storage.Op.update_metadata (key, value, storage) in
([], s)

let contract (action, storage : request) : result =
let ops, storage =
match action with
Expand All @@ -122,8 +115,6 @@ let contract (action, storage : request) : result =
sign_proposal (challenge_id, payload, agreement, storage)
| Proof_of_event_challenge { challenge_id; payload } ->
resolve_proposal (challenge_id, payload, storage)
| Update_metadata { key; value } ->
update_metadata(key, value, storage)
in
let _ = Conditions.check_setting storage in
(ops, storage)
2 changes: 2 additions & 0 deletions src/internal/execution.mligo
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ let send (content : proposal_content) (storage : storage_types)
| Add_owners s -> ([], Storage.Op.add_owners s storage)
| Remove_owners s -> ([], Storage.Op.remove_owners s storage)
| 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))

let perform_operations
(challenge_id: storage_types_challenge_id)
Expand Down
1 change: 0 additions & 1 deletion src/internal/parameter.mligo
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,4 @@ module Types = struct
| Create_proposal of { proposal_contents: proposal_content list }
| Sign_proposal of { challenge_id: challenge_id ; payload: payload; agreement: agreement }
| Proof_of_event_challenge of { challenge_id: challenge_id; payload: payload }
| Update_metadata of { key: string; value: bytes; }
end
2 changes: 2 additions & 0 deletions src/internal/proposal_content.mligo
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ module Types = struct
| Add_owners of address set
| Remove_owners of address set
| Adjust_effective_period of int
| Add_or_update_metadata of { key: string; value: bytes; }
| Remove_metadata of { key: string }
end
4 changes: 2 additions & 2 deletions src/internal/storage.mligo
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ module Op = struct
archives = archives
}

let update_metadata (key, value, storage: string * bytes * types) : types =
let metadata = Big_map.update key (Some value) storage.metadata in
let update_metadata (key, value, storage: string * bytes option * types) : types =
let metadata = Big_map.update key value storage.metadata in
{
storage with
metadata = metadata
Expand Down
2 changes: 1 addition & 1 deletion test/common/helper.mligo
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ let init_storage (owners, threshold: address set * nat) : storage_types =
owners = owners;
threshold = threshold;
effective_period = 172800;
metadata = (Big_map.empty: (string, bytes) big_map);
metadata = Big_map.literal [("", 0x01)];
}

type originated = Breath.Contract.originated
Expand Down
2 changes: 2 additions & 0 deletions test/test.mligo
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#import "./test_resolve_proposal_entrypoint.mligo" "Exe"
#import "./test_disapproval.mligo" "Disapproval"
#import "./test_expiration_time.mligo" "Exp_date"
#import "./test_update_metadata.mligo" "Update_metadata"

let () =
Breath.Model.run_suites Void
Expand All @@ -43,4 +44,5 @@ let () =
; Exe.test_suite
; Disapproval.test_suite
; Exp_date.test_suite
; Update_metadata.test_suite
]
114 changes: 114 additions & 0 deletions test/test_update_metadata.mligo
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
(* MIT License
Copyright (c) 2022 Marigold <contact@marigold.dev>
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 "../app/main.mligo" "App"

type proposal_content = Proposal_content.Types.t

let case_update_metadata =
Breath.Model.case
"test update element metadata"
"successuful update element metadata"
(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 param = ([] : proposal_content list) in

let param = Add_or_update_metadata {key=""; value=0x12} :: param in
let action = Breath.Context.act_as alice (Helper.create_proposal multisig_contract param) 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 storage = Breath.Contract.storage_of multisig_contract in

Breath.Result.reduce [
action
; sign_action
; resolve_action
; Breath.Assert.is_equal "metadata with key \"\"" (Big_map.find_opt "" storage.metadata) (Some 0x12)
])

let case_add_metadata =
Breath.Model.case
"test add more element to metadata"
"successuful add more element to metadata"
(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 param = ([] : proposal_content list) in

let param = Add_or_update_metadata {key="1"; value=0x12} :: param in
let action = Breath.Context.act_as alice (Helper.create_proposal multisig_contract param) 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 storage = Breath.Contract.storage_of multisig_contract in

Breath.Result.reduce [
action
; sign_action
; resolve_action
; Breath.Assert.is_equal "metadata with key \"\"" (Big_map.find_opt "" storage.metadata) (Some 0x01)
; Breath.Assert.is_equal "metadata with key \"1\"" (Big_map.find_opt "1" storage.metadata) (Some 0x12)
])

let case_remove_metadata =
Breath.Model.case
"test remove element from metadata"
"successuful remove element from metadata"
(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 param = ([] : proposal_content list) in

let param = Remove_metadata {key=""} :: param in
let action = Breath.Context.act_as alice (Helper.create_proposal multisig_contract param) 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 storage = Breath.Contract.storage_of multisig_contract in

Breath.Result.reduce [
action
; sign_action
; resolve_action
; Breath.Assert.is_equal "metadata with key \"\"" (Big_map.find_opt "" storage.metadata) None
])

let test_suite =
Breath.Model.suite "Suite for update metadata" [
case_update_metadata
; case_add_metadata
; case_remove_metadata
]

0 comments on commit 4e119c4

Please sign in to comment.