Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated dependencies & improved debug mode #4

Merged
merged 1 commit into from
May 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ __tea/bin/*

# ligo
**/.ligo-work
.ligo

# build
build/*
Expand Down
4 changes: 3 additions & 1 deletion __tea/.cmd/setup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ local function _install_dependencies()
ami_assert(_ok, "Invalid package.json!")
if #table.keys(_parsed.dependencies) > 0 then
log_info("Installing ligo dependencies...")
ami_assert(os.execute(string.interpolate("${LIGO} install", { LIGO = _ligoDestination })),
local _cmd = string.interpolate("${LIGO} install", { LIGO = _ligoDestination })
log_debug(_cmd)
ami_assert(os.execute(_cmd),
"Failed to install ligo dependencies!")
else
log_info("No ligo dependencies found. Skipping dependecy setup...")
Expand Down
12 changes: 8 additions & 4 deletions __tea/tools/compile/contract.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,22 @@ local _cmd = _computed.LIGO_VARS.LIGO .. " compile contract ${FILE} --entry-poin

if _computed.COMPILE.TZ then
log_info("Compiling contract to ${ID}.tz...", _computed)
local _ok = os.execute(string.interpolate(_cmd, util.merge_tables(_computed.LIGO_VARS, {
local _cmd = string.interpolate(_cmd, util.merge_tables(_computed.LIGO_VARS, {
FORMAT = "text",
SUFFIX = ".tz"
})))
}))
log_debug(_cmd)
local _ok = os.execute(_cmd)
ami_assert(_ok, string.interpolate("Failed to compile contract ${ID}.tz", _computed))
end

if _computed.COMPILE.JSON then
log_info("Compiling contract to ${ID}.json...", _computed)
local _ok = os.execute(string.interpolate(_cmd, util.merge_tables(_computed.LIGO_VARS, {
local _cmd = string.interpolate(_cmd, util.merge_tables(_computed.LIGO_VARS, {
FORMAT = "json",
SUFFIX = ".json"
})))
}))
log_debug(_cmd)
local _ok = os.execute(_cmd)
ami_assert(_ok, string.interpolate("Failed to compile contract ${ID}.json", _computed))
end
8 changes: 6 additions & 2 deletions __tea/tools/compile/storage.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ for id, vars in pairs(_computed.DEPLOYS) do
SUFFIX = ".tz",
})
log_info("Compiling initial storage tz for ${DEPLOY}...", _vars)
local _ok = os.execute(string.interpolate(_preprocessedCmd, _vars))
local _cmd = string.interpolate(_preprocessedCmd, _vars)
log_info(_cmd)
local _ok = os.execute(_cmd)
ami_assert(_ok,
string.interpolate("Failed to compile contract ${BUILD_DIR}/${DEPLOY}-storage-${CONTRACT_ID}.tz", _vars))
end
Expand All @@ -37,7 +39,9 @@ for id, vars in pairs(_computed.DEPLOYS) do
SUFFIX = ".json",
})
log_info("Compiling initial storage json for ${DEPLOY}...", _vars)
local _ok = os.execute(string.interpolate(_preprocessedCmd, _vars))
local _cmd = string.interpolate(_preprocessedCmd, _vars)
log_info(_cmd)
local _ok = os.execute(_cmd)
ami_assert(_ok,
string.interpolate("Failed to compile contract ${BUILD_DIR}/${DEPLOY}-storage-${CONTRACT_ID}.tz", _computed))
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ local _checkCmd = "${ENGINE} exec -it ${NAME} ${TEZOS_CLIENT_PATH}" ..

return function(options)
local _vars = util.merge_tables(_computed.SANDBOX_VARS, {
TEZOS_CLIENT_PATH = options.path or "tezos-client",
TEZOS_CLIENT_PATH = options.path or "octez-client",
BURN_CAP = options["burn-cap"] or "10",
CONTRACT_ID = _computed.ID,
SOURCE = options.source,
CONTRACT_CODE = string.trim(fs.read_file(string.interpolate("build/${ID}.tz", options))),
INITIAL_STORAGE = string.trim(fs.read_file(string.interpolate("build/${DEPLOYMENT_ID}-storage-${ID}.tz", options)))
}, true)

local _ok, _, _code = os.execute(string.interpolate(_deployCmd, _vars))
local _cmd = string.interpolate(_deployCmd, _vars)
log_debug(_cmd)
local _ok, _, _code = os.execute(_cmd)
if not _ok then error("exit code " .. tostring(_code)) end

local _result = proc.exec(string.interpolate(_checkCmd, _vars), { stdout = "pipe" })
Expand Down
1 change: 1 addition & 0 deletions __tea/tools/deploy/plugin/taquito.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ return function(options)
env.set_env("ID", options.ID)
env.set_env("CREATOR_KEY", options.source)
env.set_env("RPC", options.rpc)
log_debug(_cmd)
local _ok, _, _exitcode = os.execute(_cmd)
os.chdir(_cwd)
ami_assert(_ok, "Failed to deploy contract with taquito!")
Expand Down
7 changes: 4 additions & 3 deletions __tea/tools/deploy/plugin/tezos-client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ local _checkCmd = "${TEZOS_CLIENT_PATH}" ..

return function(options)
local _vars = util.merge_tables(_computed.SANDBOX_VARS, {
TEZOS_CLIENT_PATH = options.path or "tezos-client",
TEZOS_CLIENT_PATH = options.path or "octez-client",
BURN_CAP = options["burn-cap"] or "10",
CONTRACT_ID = _computed.ID,
SOURCE = options.source,
CONTRACT_CODE = string.trim(fs.read_file(string.interpolate("build/${ID}.tz", options))),
INITIAL_STORAGE = string.trim(fs.read_file(string.interpolate("build/${DEPLOYMENT_ID}-storage-${ID}.tz", options)))
}, true)

local _ok, _, _code = os.execute(string.interpolate(_deployCmd, _vars))
local _cmd = string.interpolate(_deployCmd, _vars)
log_debug(_cmd)
local _ok, _, _code = os.execute(_cmd)
if not _ok then error("exit code " .. tostring(_code)) end

local _result = proc.exec(string.interpolate(_checkCmd, _vars), { stdout = "pipe" })
Expand Down
2 changes: 1 addition & 1 deletion __tea/tools/sandbox/remove.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
local _computed = require("__tea.common.computed")

local _cmd = string.interpolate("${ENGINE} rm ${NAME} --force", _computed.SANDBOX_VARS)

log_debug(_cmd)
ami_assert(os.execute(_cmd), "Failed to remove sandbox!")
2 changes: 1 addition & 1 deletion __tea/tools/sandbox/start.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ local _computed = require("__tea.common.computed")

local _cmd = string.interpolate("${ENGINE} run --rm --name ${NAME} --detach -p ${RPC_PORT}:20000 -e block_time=5" ..
" ${IMAGE} ${SCRIPT} start", _computed.SANDBOX_VARS)

log_debug(_cmd)
ami_assert(os.execute(_cmd), "Failed to start sandbox!")
2 changes: 1 addition & 1 deletion __tea/tools/sandbox/stop.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
local _computed = require("__tea.common.computed")

local _cmd = string.interpolate("${ENGINE} stop ${NAME}", _computed.SANDBOX_VARS)

log_debug(_cmd)
ami_assert(os.execute(_cmd), "Failed to stop sandbox!")
1 change: 1 addition & 0 deletions __tea/tools/tests/js.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ local _args = table.pack(...)

local _cmd = #_args == 0 and "npm run test" or "npm run test-selection"
os.chdir("web")
log_debug(_cmd)
os.execute(string.join(" ", _cmd, ...))
os.chdir("..")
1 change: 1 addition & 0 deletions __tea/tools/tests/ligo.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local _computed = require "__tea.common.computed"

local _cmd = _computed.LIGO_VARS.LIGO .. " run test ${ROOT}"
log_debug(_cmd)
os.execute(string.interpolate(_cmd, _computed.TEST_VARS))
-- ligo reports failure on its own
16 changes: 8 additions & 8 deletions app.hjson
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ configuration: {
sandbox: {
// alice key from sandbox
admin-addr: '"tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb"'
kind: sandbox-tezos-client
// path: tezos-client
kind: sandbox-octez-client
// path: octez-client
source: alice
burn-cap: 5

// requires installed tezos-client
// kind: tezos-client
// // path: tezos-client
// requires installed octez-client
// kind: octez-client
// // path: octez-client
// source: alice
// burn-cap: 5
}
Expand All @@ -32,14 +32,14 @@ configuration: {
// or container
// image: ligolang/ligo:0.49.0
// syntax: cameligo
protocol: kathmandu
protocol: mumbai
// initial-storage-args: (${admin-addr}: address), ${metadata}
}
sandbox: {
// name: tezos-sandbox
// defaults to `sandbox-${id}`
image: oxheadalpha/flextesa:20220715
script: kathmandubox
image: registry.hub.docker.com/oxheadalpha/flextesa:20230313
script: mumbaibox
// rpc_port: 20000
}
metadata: {
Expand Down
4 changes: 4 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ TEA provides bellow commands (see `--help` of each for details):
- `ami deploy sandbox` to deploy to sandbox with default `app.hjson`
5. Run `ami test-js` to test js-module

### Debug
You can examine all commands tea executes with log level debug:
- `ami -ll=debug <command>` e.g. `ami -ll=debug test`

## Development with VS Code

1. Install [Lua extension from sumneko](https://marketplace.visualstudio.com/items?itemName=sumneko.lua)
Expand Down
2 changes: 1 addition & 1 deletion src/contract.mligo
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "views/lock.mligo"
#include "views/state.mligo"

let main(action, store: action_type * storage_type): return_type =
let main(action: action_type) (store: storage_type): return_type =
match action with
Increment n -> add (n, store)
| Decrement n -> sub (n, store)
Expand Down
8 changes: 4 additions & 4 deletions tests/all.mligo
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#include "../src/contract.mligo"

let test_deploy =
let initial_storage: storage_type = generate_initial_storage ("tz1aSkwEot3L2kmUvcoxzjMomb9mvBNuzFK6": address) in
let initial_storage: storage_type = generate_initial_storage (("tz1aSkwEot3L2kmUvcoxzjMomb9mvBNuzFK6": address), 0x00) in
let taddr, _, _ = Test.originate main initial_storage 0tez in
let storage = Test.get_storage taddr in
assert (storage.admin = initial_storage.admin && storage.state = initial_storage.state && storage.locked = initial_storage.locked)

let test_add_locked_not_admin =
let initial_storage: storage_type = generate_initial_storage ("tz1aSkwEot3L2kmUvcoxzjMomb9mvBNuzFK6": address) in
let initial_storage: storage_type = generate_initial_storage (("tz1aSkwEot3L2kmUvcoxzjMomb9mvBNuzFK6": address), 0x00) in
let taddr, _, _ = Test.originate main initial_storage 0tez in
let contr = Test.to_contract taddr in
let result = Test.transfer_to_contract contr (Increment (1)) 0mutez in
Expand All @@ -24,7 +24,7 @@ let test_add_locked_not_admin =

let test_add_locked_admin =
let addr = Test.nth_bootstrap_account 0 in
let initial_storage: storage_type = generate_initial_storage addr in
let initial_storage: storage_type = generate_initial_storage (addr, 0x00) in
let _ = Test.set_source addr in
let taddr, _, _ = Test.originate main initial_storage 0tez in
let contr = Test.to_contract taddr in
Expand All @@ -34,7 +34,7 @@ let test_add_locked_admin =

let test_add_unlocked_admin =
let addr = Test.nth_bootstrap_account 0 in
let initial_storage: storage_type = generate_initial_storage addr in
let initial_storage: storage_type = generate_initial_storage (addr, 0x00) in
let _ = Test.set_source addr in
let taddr, _, _ = Test.originate main initial_storage 0tez in
let contr = Test.to_contract taddr in
Expand Down
Loading