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

Vs code extension testing #569

Merged
merged 25 commits into from
May 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
c9baeaa
Added initial set up for VS Code Plugin testing. Also added dependenc…
ivan-romanov Mar 15, 2022
90e6f18
Merge branch 'main' of https://github.com/ecadlabs/taqueria into vs-c…
ivan-romanov Mar 21, 2022
1bcc86d
Merge branch 'main' of https://github.com/ecadlabs/taqueria into vs-c…
ivan-romanov Apr 4, 2022
2dad5f9
Merge branch 'main' of https://github.com/ecadlabs/taqueria into vs-c…
ivan-romanov Apr 8, 2022
8e955a5
Merge branch 'main' of https://github.com/ecadlabs/taqueria into vs-c…
ivan-romanov Apr 12, 2022
ef3a5da
Updated runner to fix an issue with sleep
ivan-romanov Apr 14, 2022
dc1658e
Merge branch 'main' of https://github.com/ecadlabs/taqueria into vs-c…
ivan-romanov Apr 21, 2022
d2157eb
Merge branch 'main' of https://github.com/ecadlabs/taqueria into vs-c…
ivan-romanov Apr 28, 2022
f7b18f3
Merge branch 'main' of https://github.com/ecadlabs/taqueria into vs-c…
sinapsist May 4, 2022
2c3a5e1
Merge branch 'main' of https://github.com/ecadlabs/taqueria into vs-c…
sinapsist May 5, 2022
93362df
Polished runner and added set up and tear down parts. Also linked eac…
sinapsist May 5, 2022
39585d5
Updated package-lock.json with new packages added to package.json
sinapsist May 5, 2022
44e0936
Enable back clean up for test project folder
sinapsist May 5, 2022
83d8662
Update package.json files to remove index.ts
sinapsist May 12, 2022
6519879
Merge branch 'main' of https://github.com/ecadlabs/taqueria into vs-c…
sinapsist May 12, 2022
4c1038b
Update package.json files to remove index.ts
sinapsist May 12, 2022
9707082
Fixing tsconfig.json
sinapsist May 12, 2022
3e03956
Updating package-lock
sinapsist May 13, 2022
f2aa712
Updated test
sinapsist May 13, 2022
4ae24da
Fixing pipeline.
sinapsist May 13, 2022
200cb44
Fixing pipeline.
sinapsist May 13, 2022
02059ab
Fixing pipeline.
sinapsist May 13, 2022
dd5072d
Merge branch 'main' of https://github.com/ecadlabs/taqueria into vs-c…
sinapsist May 13, 2022
9462dcd
rollback test
sinapsist May 13, 2022
d79d09d
update package-lock.json
sinapsist May 13, 2022
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
7,130 changes: 2,502 additions & 4,628 deletions package-lock.json

Large diffs are not rendered by default.

28 changes: 26 additions & 2 deletions taqueria-vscode-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@
"includeNodeModules": {
"vscode": false
}
},
"test": {
"source": [
"./src/test/runTest.ts",
"./src/test/suite/index.ts",
"./src/test/suite/extension.test.ts"
],
"distDir": "./out/test",
"context": "node",
"engines": {
"node": ">= 12"
},
"includeNodeModules": {
"vscode": false
}
}
},
"author": "ECAD Labs",
Expand Down Expand Up @@ -122,16 +137,25 @@
"watch": "parcel watch --no-cache --detailed-report",
"pretest": "npm run compile && npm run lint",
"lint": "eslint src --ext ts",
"test": "echo 'No tests to run for VSCode yet'"
"test": "node ./out/test/runTest.js"
},
"devDependencies": {
"@taquito/taquito": "^12.1.0",
"@types/fs-extra": "^9.0.13",
"@types/glob": "^7.2.0",
"@types/mocha": "^5.2.6",
"@types/node": "^17.0.17",
"@types/promise-memoize": "^1.2.1",
"@types/vscode": "1.63.0",
"@typescript-eslint/eslint-plugin": "^5.9.1",
"@typescript-eslint/parser": "^5.9.1",
"@vscode/test-electron": "^2.1.2",
"esbuild": "^0.14.15",
"eslint": "^8.6.0",
"parcel": "^2.4.0",
"fs-extra": "^10.1.0",
"glob": "^7.2.0",
"mocha": "^9.2.1",
"parcel": "^2.3.1",
"typescript": "4.5.4",
"vsce": "^2.6.4"
},
Expand Down
23 changes: 23 additions & 0 deletions taqueria-vscode-extension/src/test/runTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as path from 'path';

import { runTests } from '@vscode/test-electron';

async function main() {
try {
// The folder containing the Extension Manifest package.json
// Passed to `--extensionDevelopmentPath`
const extensionDevelopmentPath = path.resolve(__dirname, '../../out');

// The path to the extension test script
// Passed to --extensionTestsPath
const extensionTestsPath = path.resolve(__dirname, '../../out/test/suite/index');

// Download VS Code, unzip it and run the integration test
await runTests({ extensionDevelopmentPath, extensionTestsPath });
} catch (err) {
console.error('Failed to run tests');
process.exit(1);
}
}

main();
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"language": "en",
"plugins": [],
"contractsDir": "contracts",
"testsDir": "tests",
"artifactsDir": "artifacts",
"environment": {
"default": "development",
"development": {
"networks": [],
"sandboxes": [
"local"
],
"storage": {}
}
},
"sandbox": {
"local": {
"accounts": {
"default": "bob",
"bob": {
"initialBalance": "3000000000"
},
"alice": {
"initialBalance": "2000000000"
},
"john": {
"initialBalance": "4000000000"
},
"jane": {
"initialBalance": "5000000000"
},
"joe": {
"initialBalance": "1000000000"
}
},
"label": "Local Tezos Sandbox",
"protocol": "PtHangz2aRngywmSRGGvrcTyMbbdpWdpFKuS4uMWxg2RaH9i1qx",
"rpcUrl": "http://localhost:20000"
}
},
"network": {}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "vscode-taq-test-project",
"version": "1.0.0",
"description": "",
"main": "index.js",
"directories": {
"test": "tests"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
## Overview
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this file be removed?


This quickstart guide will teach you the fundamentals of using Taqueria in 10 minutes by going through the process of running some basic tasks in Taqueria from the CLI

What you will accomplish:
- Initialize a new Taqueria project
- Install plugins for LIGO, Flextesa, and Taquito
- Compile a LIGO smart contract
- Start a local Flextesa sandbox
- Originate the compiled smart contract to the sandbox

## Requirements

To successfully use Taqueria, you must ensure that:
- The Taqueria CLI has been [installed](./installation.mdx) and is available in your `$PATH`
- Docker v0.8 or later is installed and currently running
- Node.js v16.x or later

## Starting a Taqueria Project

There are two things required to start using Taqueria on a project

1. The project must be initialized by Taqueria. This process creates a hidden directory `./.taq` inside the project directory that contains the configuration and state files required by Taqueria, and ensures the required directories `/contracts`, `/artifacts`, and `/tests` have been created

Taqueria provides the command `init` which will create a new directory with the correct structure and configuration. To create a new Taqueria project called `my-first-project`, run the command:
```shell
taq init my-first-project
```
:::caution
If a project has already been initialized, Taqueria will not re-initialize the project, but will still return a success message. This will be fixed in an upcoming release
:::

2. The project directory must be initialized as an NPM project as all current plugins implemented as NPM packages. To do this, run:
```shell
npm init -y
```

## Working with Plugins

Now that the project has been properly initialized, plugins can be installed to provide support for specific functionality such as compilation, smart contract origination, or sandbox environments

Plugins are installed using the `taq install [pluginName]` command (requires the project to be initialized). Once a plugin has been installed, it's tasks will become available in Taqueria

You can view the list of commands available in the current project context by running `taq` from the command line

### Available Plugins

| name | pluginName | description |
|----------------|------------------------------ |---------------------------------------------------------------------|
| LIGO | `@taqueria/plugin-ligo` | A compiler for the LIGO smart contract language |
| SmartPy | `@taqueria/plugin-smartpy` | A compiler for the SmartPy contract language |
| Flextesa | `@taqueria/plugin-flextesa` | A sandbox test network running Tezos Flextesa |
| Taquito | `@taqueria/plugin-taquito` | A front-end Tezos framework used to originate |
| Contract Types | `@taqueria/plugin-contract-types` | A type generator that produces TS types from Michelson code |
| Tezos Client | `@taqueria/plugin-tezos-client` | Interacts with a Tezos node, providing simulation and type checking |

## Compiling a LIGO Smart Contract

To add support for the LIGO smart contract language, install the LIGO plugin by running:
```shell
taq install @taqueria/plugin-ligo
```

Once installed, the plugin provides the command `taq compile` which when run, will look for any LIGO files in the `/contracts` directory and compile them to Michelson `.tz` files in the `/artifacts` directory

To demonstrate this, create a file called `counter.jsligo` in the `/contracts` directory and insert the following JSLigo code:
```ligo title="/contracts/counter.jsligo"
type storage = int;

type parameter =
| ["Increment", int]
| ["Decrement", int]
| ["Reset"];

type return_ = [list <operation>, 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_ => {
return [
(list([]) as list <operation>), // No operations
(match (action, {
Increment: (n: int) => add ([store, n]),
Decrement: (n: int) => sub ([store, n]),
Reset: () => 0}))
]
}
```

You can now compile this contract by running the following command from the project directory:
```shell
taq compile
```

Taqueria will then output a list of contracts compiled, and the artifacts created:
```shell
❯ taq compile
┌────────────────┬──────────────────────┐
│ Contract │ Artifact │
├────────────────┼──────────────────────┤
│ counter.jsligo │ artifacts/counter.tz │
└────────────────┴──────────────────────┘
```

If you open this file (`/artifacts/counter.tz`), you can view the raw Michelson code which will later be originated to the sandbox:
```
{ parameter (or (or (int %decrement) (int %increment)) (unit %reset)) ;
storage int ;
code { UNPAIR ;
IF_LEFT { IF_LEFT { SWAP ; SUB } { ADD } } { DROP 2 ; PUSH int 0 } ;
NIL operation ;
PAIR } }
```

### Starting a Flextesa Sandbox

The next step is to install the Flextesa plugin which provides a local Tezos sandbox network:
```shell
taq install @taqueria/plugin-flextesa
```

Once installed, the plugin provides three commands to start, stop, and query a sandbox:
- `taq start sandbox [sandboxName]`
- `taq stop sandbox [sandboxName]`
- `taq list accounts [sandboxName]`

:::note
Sandboxes are configured in the project's Taqueria configuration file (`./.taq/config.json`). Each named sandbox configuration can then be called from the CLI.
By default, every Taqueria project comes pre-configured with a sandbox named `local`
:::

Start up the sandbox named `local` by running:
```shell
taq start sandbox local
```

To confirm the sandbox is running, query the sandbox for the account information:
```shell
taq list accounts local
```

If successful, you will see a list of the accounts and balances specified in the `config.json` file that have been created on the Tezos blockchain in the sandbox:
```
❯ taq list accounts local
┌─────────┬─────────┬──────────────────────────────────────┐
│ Account │ Balance │ Address │
├─────────┼─────────┼──────────────────────────────────────┤
│ bob │ 3000 ꜩ │ tz1aSkwEot3L2kmUvcoxzjMomb9mvBNuzFK6 │
├─────────┼─────────┼──────────────────────────────────────┤
│ alice │ 2000 ꜩ │ tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb │
├─────────┼─────────┼──────────────────────────────────────┤
│ john │ 4000 ꜩ │ tz1Zwoh1QCVAvJ4sVTojMp9pLYp6Ji4NoZy6 │
├─────────┼─────────┼──────────────────────────────────────┤
│ jane │ 5000 ꜩ │ tz1aHUAC4oviwJuZF1EvVSvFz7cu9KMNYBph │
├─────────┼─────────┼──────────────────────────────────────┤
│ joe │ 1000 ꜩ │ tz1MVGjgD1YtAPwohsSfk8i3ZiT1yEGM2YXB │
└─────────┴─────────┴──────────────────────────────────────┘
```

### Originating a Contract with Taquito

With a sandbox now running, the next step is to originate the `counter.tz` file to the sandbox network using the Taquito plugin

First, install the plugin:
```shell
taq install @taqueria/plugin-taquito
```

Next, you need to configure some values for origination:
- The initial storage for the smart contract
- The name of the sandbox to target (by default it is pre-configured to the sandbox named `local`)
:::note
As the default configuration comes with the sandbox named `local` preconfigured, simply provide a value for the initial storage in the `"storage"` property
:::

To set these values in Taqueria, navigate to the file `./.taq/config.json` and locate the `"environment"` property. For the `counter.tz` contract, simply need to provide an integer value for the `counter.tz` file which looks like this:
```
"environment": {
"default": "development",
"development": {
"networks": [],
"sandboxes": [
"local"
],
"storage": {
"counter.tz": 42
}
}
},
```

Now you can originate the contract by running:
```shell
taq originate
```

This will originate all contracts in the `/artifacts` directory to the sandbox and return the address of the deployed contract and destination sandbox. The output for this command will display which contracts were originated, what the destination was, and what the on-chain address for the deployed address is. This will look something like this:
```
┌────────────┬──────────────────────────────────────┬─────────────┐
│ Contract │ Address │ Destination │
├────────────┼──────────────────────────────────────┼─────────────┤
│ counter.tz │ KT1Ayz8qos7G4U3Jucp6QWoM7ayhbShNXcat │ local │
└────────────┴──────────────────────────────────────┴─────────────┘
```

## Finishing Up

Congratulations! At this point, you have run through the basic usage of Taqueria

For more details on the usage of specific Taqueria tasks, you can refer to the plugin documentation which contains additional context, configuration, and usage of the many Taqueria tasks; or continue on with the getting started guides
Loading