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

Add test task for ligo plugin #1255

Merged
merged 6 commits into from
Sep 20, 2022
Merged

Add test task for ligo plugin #1255

merged 6 commits into from
Sep 20, 2022

Conversation

jchenche
Copy link
Contributor

@jchenche jchenche commented Sep 19, 2022

🏗️ PR ➾

Fixes #1166

🪂 Pre-Merge Checklist

  • 🐬 I have commented my code, particularly in hard-to-understand areas
  • 🦀 Automated tests have been written and added to this PR
  • 🤿 Corresponding changes have been made to all documentation
  • 🏖️ New and existing unit tests pass locally and in CI
  • 🔱 The test plan has been implemented and verified by an SDET
  • 🏄‍♂️ Myself and others have built this branch and done manual testing on the change
  • ⛵ A summary describing the change has been written for release notes

🪁 Description

This PR adds a new task from the LIGO plugin called test, which allows LIGO devs to test their LIGO code natively. This facilitate unit tests and e2e tests for contracts.

Command syntax: taq test <sourceFile>

Variable names that are prefixed with test will be included in the tests (this comes from LIGO).

Normally, you would have a counter.mligo contract and testCounter.mligo file that tests counter.mligo where at the beginning of testCounter.mligo, you have the line #include "counter.mligo".

For example (first is counter.mligo and second is testCounter.mligo):

type storage = int

type parameter =
  Increment of int
| Decrement of int
| Reset

let param: parameter = Increment 15

type return = operation list * storage

// Two entrypoints

let add (store, delta : storage * int) : storage = store + delta
let sub (store, delta : storage * int) : storage = store - delta

(* Main access point that dispatches to the entrypoints according to
   the smart contract parameter. *)
   
let main (action, store : parameter * storage) : return =
 ([] : operation list),    // No operations
 (match action with
   Increment (n) -> add (store, n)
 | Decrement (n) -> sub (store, n)
 | Reset         -> 0)
#include "counter.mligo"

let initial_storage = 42

let test_initial_storage =
 let (taddr, _, _) = Test.originate main initial_storage 0tez in
 assert (Test.get_storage taddr = initial_storage)

let test_increment =
 let (taddr, _, _) = Test.originate main initial_storage 0tez in
 let contr = Test.to_contract taddr in
 let _ = Test.transfer_to_contract_exn contr (Increment 1) 1mutez in
 assert (Test.get_storage taddr = initial_storage + 1)

🎢 Test Plan

Please describe the testing strategy for this change


🛸 Type of Change

  • 🐟 Minor change (non-breaking change of very limited scope)
  • 🦑 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 🌊 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 🐳 Major refactor (breaking changes and significant impact to the codebase)

@jchenche jchenche self-assigned this Sep 19, 2022
@jchenche jchenche requested a review from a team September 19, 2022 19:42
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Sep 19, 2022

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: c22e6d0
Status: ✅  Deploy successful!
Preview URL: https://d3eb4cd2.taqueria.pages.dev
Branch Preview URL: https://1166-ligo-native-test-jcc.taqueria.pages.dev

View logs

@github-actions
Copy link
Contributor

github-actions bot commented Sep 19, 2022

Latest Commit 6da61e6
Taq Binaries

Linux
MacOS
Windows

VSCode Extension VSIX Build skipped

Copy link
Contributor

@sinapsist sinapsist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jchenche jchenche merged commit f85126c into main Sep 20, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Sep 20, 2022
@jchenche jchenche deleted the 1166-ligo-native-test-JCC branch September 20, 2022 19:34
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🚧 Dev Epic ➾ Ligo Dev WF Improvements (user requests)
3 participants