Skip to content

Commit

Permalink
Merge pull request #17 from marigold-dev/fix-ligo-v1
Browse files Browse the repository at this point in the history
Breathalyzer 1.5.0: fix for Ligo v1
  • Loading branch information
aguillon authored Oct 26, 2023
2 parents 9831886 + 7667fcc commit 7c64e33
Show file tree
Hide file tree
Showing 14 changed files with 31 additions and 87 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ jobs:
- name: Ligo version
uses: marigold-dev/[email protected]
with:
ligo_version: 0.70.1
ligo_version: 1.0.0
command: version
working_directory: batcher
- name: Run test
uses: marigold-dev/[email protected]
with:
ligo_version: 0.70.1
ligo_version: 1.0.0
command: run test test.mligo
working_directory: test

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 Xavier Van de Woestyne
Copyright (c) 2022-2023 Marigold developers

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# breathalyzer
# Breathalyzer test framework

A simple test framework for Ligo Lang, the name `breathalyzer` is a wink to
[Alcotest](https://github.com/mirage/alcotest), a powerful test framework for
A simple test framework for the Ligo language. The name `Breathalyzer` is a wink
to [Alcotest](https://github.com/mirage/alcotest), a powerful test framework for
the OCaml language.

The best way to understand the design and use of **Breathalyzer** is to consult
Expand Down
6 changes: 3 additions & 3 deletions examples/auction/src/auction_sc.mligo
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,21 @@ let claim (storage: storage) (user_address: address) (time: timestamp) : operati
(op, new_storage)

[@entry]
let bid (_, storage: unit * storage) : operation list * storage =
let bid () (storage: storage) : operation list * storage =
let quantity = Tezos.get_amount () in
let user_address = Tezos.get_sender () in
let current_time = Tezos.get_now () in
([], bid storage quantity user_address current_time)

[@entry]
let claim (_, storage: unit * storage) : operation list * storage =
let claim () (storage: storage) : operation list * storage =
let user_address = Tezos.get_sender () in
let current_time = Tezos.get_now () in
let operation, storage = claim storage user_address current_time in
([operation], storage)

[@view]
let is_claimable (_, storage: unit * storage) : bool =
let is_claimable () (storage: storage) : bool =
match storage with
| None -> false
| Some current_leader ->
Expand Down
2 changes: 1 addition & 1 deletion examples/auction/test/util.mligo
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
type originated = Breath.Contract.originated

let originate (level: Breath.Logger.level) =
Breath.Contract.originate_module
Breath.Contract.originate
level
"auction_sc"
(contract_of Auction)
Expand Down
4 changes: 2 additions & 2 deletions examples/ticket_factory/src/oven_sc.mligo
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ let request_mint (mint_address: address) (qty: tez) : operation =
mint_address
"oven_sc: unable to find mint contract"
in
Tezos.transaction (Mint_process_mint callback) qty mint_sc
Tezos.transaction (Mint_process_mint callback: Mint parameter_of) qty mint_sc

let retrieve_ticket
(counter: nat)
Expand All @@ -66,7 +66,7 @@ let request_redeem (mint_address: address) (stored_ticket : bytes ticket option)
mint_address
"oven_sc: unable to find mint contract"
in
Tezos.transaction (Mint_process_redeem (ticket, callback)) 0tez mint_sc
Tezos.transaction ((Mint_process_redeem (ticket, callback)): Mint parameter_of) 0tez mint_sc

let retrieve_tez (owner_address : address) (retribution: tez) : operation =
let beneficiary : unit contract =
Expand Down
4 changes: 2 additions & 2 deletions examples/ticket_factory/test/util.mligo
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
type originated = Breath.Contract.originated

let originate_mint (level: Breath.Logger.level) (pl: bytes) (min_amount: tez) () =
Breath.Contract.originate_module
Breath.Contract.originate
level
"mint_sc"
(contract_of Mint)
Expand All @@ -46,7 +46,7 @@ let originate_oven_with
let (_, (_, qty)), fresh = Tezos.read_ticket t in
(Some fresh, qty)
in
Breath.Contract.originate_module
Breath.Contract.originate
level
("oven_sc_" ^ actor.name)
(contract_of Oven)
Expand Down
4 changes: 2 additions & 2 deletions lib/context.mligo
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ let rec wait_for_blocks (n_blocks: nat) : unit =
if n_blocks = 0n then ()
else
let source = Tezos.get_source () in
let dummy = Test.compile_value () in
let source : (unit, unit) typed_address = Test.cast_address source in
(* We transfer a valid amount from the source to itself to bake a block
and change the time *)
let _ = Test.transfer source dummy 1mutez in
let _ = Test.transfer source () 1mutez in
wait_for_blocks (abs (n_blocks - 1))

(** [wait_for_with_blocks_per_cycle seconds blocks_per_cycle] bakes enough
Expand Down
48 changes: 3 additions & 45 deletions lib/contract.mligo
Original file line number Diff line number Diff line change
Expand Up @@ -29,61 +29,19 @@ type ('a, 'b) originated = {
; originated_address : address
}

(** [originate level name f storage quantity] originates the smart-contract [f]
(which is a main entry point) and provisions it using [quantity] and with
[storage] as a default storage value. *)
let originate
(type a b)
(level: Logger.level)
(name: string)
(main: (a -> b -> (operation list * b)))
(storage: b)
(quantity: tez) : (a, b) originated =
let typed_address, _, _ = Test.originate main storage quantity in
let contract = Test.to_contract typed_address in
let address = Tezos.address contract in

let () =
Logger.log level ("originated smart contract", name, address, storage, quantity)
in
{ originated_typed_address = typed_address
; originated_contract = contract
; originated_address = address }

(** [originate_uncurried level name f storage quantity] originates the
smart-contract [f] (which is a main entry point) and provisions it using
[quantity] and with [storage] as a default storage value. *)
let originate_uncurried
(type a b)
(level: Logger.level)
(name: string)
(main: (a * b -> (operation list * b)))
(storage: b)
(quantity: tez) : (a, b) originated =
let typed_address, _, _ = Test.originate_uncurried main storage quantity in
let contract = Test.to_contract typed_address in
let address = Tezos.address contract in

let () =
Logger.log level ("originated smart contract", name, address, storage, quantity)
in
{ originated_typed_address = typed_address
; originated_contract = contract
; originated_address = address }

(** [originate_module level name module storage quantity] originates the
smart-contract from the module [module] and provisions it using [quantity]
and with [storage] as a default storage value. Use the [contract_of] keyword
to get a module_contract out of a module. Use this function to originate a
contract with views. *)
let originate_module
let originate
(type a b)
(level: Logger.level)
(name: string)
(contract: (a, b) module_contract)
(storage: b)
(quantity: tez) : (a, b) originated =
let typed_address, _, _ = Test.originate_module contract storage quantity in
let {addr=typed_address; code=_; size=_} = Test.originate contract storage quantity in
let contract = Test.to_contract typed_address in
let address = Tezos.address contract in

Expand Down Expand Up @@ -138,5 +96,5 @@ let storage_of
let balance_of
(type a b)
(originated: (a, b) originated) : tez =
let addr = originated.originated_address in
let addr = originated.originated_typed_address in
Test.get_balance addr
4 changes: 2 additions & 2 deletions package.json → ligo.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "ligo-breathalyzer",
"description": "A simple test framework for Ligo Lang",
"description": "A simple test framework for Ligo",
"keywords": [ "ligo", "tezos", "tezos-ligo", "cameligo", "jsligo" ],
"directories": { "lib": "lib", "test": "test" },
"repository": {
"type": "git",
"url": "git+https://github.com/marigold-dev/breathalyzer.git"
},
"version": "1.4.0",
"version": "1.5.0",
"main": "./lib/lib.mligo",
"author": "Marigold <[email protected]>",
"license": "MIT",
Expand Down
14 changes: 0 additions & 14 deletions package-lock.json

This file was deleted.

4 changes: 2 additions & 2 deletions test/simple_contract.jsligo
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ const decrement = (delta : int, store : s) : ret =>
[list([]), store - delta];

@entry
const reset = (_ : unit, _ : s) : ret =>
const reset = (_unit : unit, _storage : s) : ret =>
[list([]), 0];

@view
const get_value = (_ : unit, s : s) : s =>
const get_value = (_unit : unit, s : s) : s =>
s
8 changes: 4 additions & 4 deletions test/test_tezos.mligo
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ module Other = struct
}

[@entry]
let default (_, storage: unit * storage): operation list * storage =
let default () (storage: storage): operation list * storage =
match (Tezos.call_view "get_value" () storage.simple: int option) with
| None -> failwith "Should not happen"
| Some x -> [], { storage with x = x }

[@view]
let view (_, storage: unit * storage): int =
let view () (storage: storage): int =
storage.x
end

let (_, (alice, _, _)) = B.Context.init_default ()

let originated level =
B.Contract.originate_module level "Simple" (contract_of Simple) 0 0tez
B.Contract.originate level "Simple" (contract_of Simple) 0 0tez

let case_views_1 =
B.Model.case
Expand All @@ -70,7 +70,7 @@ let case_views_2 =
let contract = originated level in
let initial_storage = { simple = contract.originated_address; x = 0 } in
let other =
B.Contract.originate_module level "Other" (contract_of Other) initial_storage 0tez
B.Contract.originate level "Other" (contract_of Other) initial_storage 0tez
in
B.Result.reduce [
B.Context.call_as alice
Expand Down
8 changes: 4 additions & 4 deletions test/test_time.mligo
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module Ping = struct
type storage = timestamp

[@entry]
let ping (_, last: unit * storage) : operation list * storage =
let ping () (last: storage) : operation list * storage =
let now = Tezos.get_now () in
if now > last + 60 then
[], now
Expand All @@ -39,7 +39,7 @@ module Exact = struct
type storage = timestamp

[@entry]
let exact (_, last: unit * storage) : operation list * storage =
let exact () (last: storage) : operation list * storage =
let now = Tezos.get_now () in
if last > (0: timestamp) && now <> last + 30 then
failwith "wrong time"
Expand All @@ -50,10 +50,10 @@ end
let (_, (alice, _, _)) = B.Context.init_default ()

let ping_contract level initial_time =
B.Contract.originate_module level "ping" (contract_of Ping) initial_time 0tez
B.Contract.originate level "ping" (contract_of Ping) initial_time 0tez

let exact_contract level initial_time =
B.Contract.originate_module level "exact" (contract_of Exact) initial_time 0tez
B.Contract.originate level "exact" (contract_of Exact) initial_time 0tez

let suite =
B.Model.suite
Expand Down

0 comments on commit 7c64e33

Please sign in to comment.