@taqueria/plugin-ligo 0.18.0 → 0.19.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -54,6 +54,73 @@ Lastly, `taq compile hello.mligo` will compile `hello.mligo` and emit `hello.tz`
54
54
 
55
55
  None for now.
56
56
 
57
+ ## The `taq test` Task
58
+
59
+ Basic usage is:
60
+
61
+ ```shell
62
+ taq test <filename>
63
+ ```
64
+
65
+ ### Basic description
66
+ This task tests the LIGO source code and ouputs a result suggesting a failure or success. Normally you'd have a contract file and a separate test file that includes the contract's code, both within the `/contracts` directory.
67
+
68
+ For example, refer to the following 2 code snippets:
69
+ ```ligo title="counter.mligo"
70
+ type storage = int
71
+
72
+ type parameter =
73
+ Increment of int
74
+ | Decrement of int
75
+ | Reset
76
+
77
+ type return = operation list * storage
78
+
79
+ // Two entrypoints
80
+
81
+ let add (store, delta : storage * int) : storage = store + delta
82
+ let sub (store, delta : storage * int) : storage = store - delta
83
+
84
+ (* Main access point that dispatches to the entrypoints according to
85
+ the smart contract parameter. *)
86
+
87
+ let main (action, store : parameter * storage) : return =
88
+ ([] : operation list), // No operations
89
+ (match action with
90
+ Increment (n) -> add (store, n)
91
+ | Decrement (n) -> sub (store, n)
92
+ | Reset -> 0)
93
+ ```
94
+
95
+ ```ligo title="testCounter.mligo"
96
+ #include "counter.mligo"
97
+
98
+ let initial_storage = 42
99
+
100
+ let test_initial_storage =
101
+ let (taddr, _, _) = Test.originate main initial_storage 0tez in
102
+ assert (Test.get_storage taddr = initial_storage)
103
+
104
+ let test_increment =
105
+ let (taddr, _, _) = Test.originate main initial_storage 0tez in
106
+ let contr = Test.to_contract taddr in
107
+ let _ = Test.transfer_to_contract_exn contr (Increment 1) 1mutez in
108
+ assert (Test.get_storage taddr = initial_storage + 1)
109
+ ```
110
+
111
+ By running `taq test testCounter.mligo`, you should get the following:
112
+ ```
113
+ ┌───────────────────┬──────────────────────────────────────────────┐
114
+ │ Contract │ Test Results │
115
+ ├───────────────────┼──────────────────────────────────────────────┤
116
+ │ testCounter.mligo │ Everything at the top-level was executed. │
117
+ │ │ - test_initial_storage exited with value (). │
118
+ │ │ - test_increment exited with value (). │
119
+ │ │ │
120
+ │ │ 🎉 All tests passed 🎉 │
121
+ └───────────────────┴──────────────────────────────────────────────┘
122
+ ```
123
+
57
124
  ## Template creation
58
125
  The LIGO plugin also exposes a contract template via the `taq create contract <contractName>` task. This task will create a new LIGO contract in the `contracts` directory, insert some boilerplate LIGO contract code and will register the contract with Taqueria
59
126
 
package/_readme.eta CHANGED
@@ -59,6 +59,73 @@ Make sure you name it `hello.storages.mligo` and not `hello.storage.mligo` (note
59
59
 
60
60
  None for now.
61
61
 
62
+ ## The `taq test` Task
63
+
64
+ Basic usage is:
65
+
66
+ ```shell
67
+ taq test <filename>
68
+ ```
69
+
70
+ ### Basic description
71
+ This task tests the LIGO source code and ouputs a result suggesting a failure or success. Normally you'd have a contract file and a separate test file that includes the contract's code, both within the `/contracts` directory.
72
+
73
+ For example, refer to the following 2 code snippets:
74
+ ```ligo title="counter.mligo"
75
+ type storage = int
76
+
77
+ type parameter =
78
+ Increment of int
79
+ | Decrement of int
80
+ | Reset
81
+
82
+ type return = operation list * storage
83
+
84
+ // Two entrypoints
85
+
86
+ let add (store, delta : storage * int) : storage = store + delta
87
+ let sub (store, delta : storage * int) : storage = store - delta
88
+
89
+ (* Main access point that dispatches to the entrypoints according to
90
+ the smart contract parameter. *)
91
+
92
+ let main (action, store : parameter * storage) : return =
93
+ ([] : operation list), // No operations
94
+ (match action with
95
+ Increment (n) -> add (store, n)
96
+ | Decrement (n) -> sub (store, n)
97
+ | Reset -> 0)
98
+ ```
99
+
100
+ ```ligo title="testCounter.mligo"
101
+ #include "counter.mligo"
102
+
103
+ let initial_storage = 42
104
+
105
+ let test_initial_storage =
106
+ let (taddr, _, _) = Test.originate main initial_storage 0tez in
107
+ assert (Test.get_storage taddr = initial_storage)
108
+
109
+ let test_increment =
110
+ let (taddr, _, _) = Test.originate main initial_storage 0tez in
111
+ let contr = Test.to_contract taddr in
112
+ let _ = Test.transfer_to_contract_exn contr (Increment 1) 1mutez in
113
+ assert (Test.get_storage taddr = initial_storage + 1)
114
+ ```
115
+
116
+ By running `taq test testCounter.mligo`, you should get the following:
117
+ ```
118
+ ┌───────────────────┬──────────────────────────────────────────────┐
119
+ │ Contract │ Test Results │
120
+ ├───────────────────┼──────────────────────────────────────────────┤
121
+ │ testCounter.mligo │ Everything at the top-level was executed. │
122
+ │ │ - test_initial_storage exited with value (). │
123
+ │ │ - test_increment exited with value (). │
124
+ │ │ │
125
+ │ │ 🎉 All tests passed 🎉 │
126
+ └───────────────────┴──────────────────────────────────────────────┘
127
+ ```
128
+
62
129
  ## Template creation
63
130
  The LIGO plugin also exposes a contract template via the `taq create contract <contractName>` task. This task will create a new LIGO contract in the `contracts` directory, insert some boilerplate LIGO contract code and will register the contract with Taqueria
64
131
 
package/compile.ts CHANGED
@@ -161,7 +161,7 @@ const compileExprs = (parsedArgs: Opts, sourceFile: string, exprKind: ExprKind):
161
161
  })
162
162
  .then(mergeArtifactsOutput(sourceFile));
163
163
 
164
- const compileContractWithStorageAndParameter = async (parsedArgs: Opts, sourceFile: string) => {
164
+ const compileContractWithStorageAndParameter = async (parsedArgs: Opts, sourceFile: string): Promise<TableRow[]> => {
165
165
  const contractCompileResult = await compileContract(parsedArgs, sourceFile);
166
166
  if (contractCompileResult.artifact === COMPILE_ERR_MSG) return [contractCompileResult];
167
167
 
@@ -226,7 +226,6 @@ const mergeArtifactsOutput = (sourceFile: string) =>
226
226
 
227
227
  export const compile = (parsedArgs: Opts): Promise<void> => {
228
228
  const sourceFile = parsedArgs.sourceFile;
229
- if (!sourceFile) return sendAsyncErr('No source file specified.');
230
229
  let p: Promise<TableRow[]>;
231
230
  if (isStoragesFile(sourceFile)) p = compileExprs(parsedArgs, sourceFile, 'storage');
232
231
  else if (isParametersFile(sourceFile)) p = compileExprs(parsedArgs, sourceFile, 'parameter');
package/index.js CHANGED
@@ -305,7 +305,6 @@ e.g.
305
305
  };
306
306
  const $24b2f47d8f306cb3$export$ef7acd7185315e22 = (parsedArgs)=>{
307
307
  const sourceFile = parsedArgs.sourceFile;
308
- if (!sourceFile) return (0, $kQNfl$taquerianodesdk.sendAsyncErr)("No source file specified.");
309
308
  let p;
310
309
  if ($24b2f47d8f306cb3$var$isStoragesFile(sourceFile)) p = $24b2f47d8f306cb3$var$compileExprs(parsedArgs, sourceFile, "storage");
311
310
  else if ($24b2f47d8f306cb3$var$isParametersFile(sourceFile)) p = $24b2f47d8f306cb3$var$compileExprs(parsedArgs, sourceFile, "parameter");
@@ -316,12 +315,47 @@ const $24b2f47d8f306cb3$export$ef7acd7185315e22 = (parsedArgs)=>{
316
315
  var $24b2f47d8f306cb3$export$2e2bcd8739ae039 = $24b2f47d8f306cb3$export$ef7acd7185315e22;
317
316
 
318
317
 
318
+
319
+
320
+ const $8d09eb70c0505719$var$getInputFilename = (parsedArgs, sourceFile)=>(0, $kQNfl$path.join)(parsedArgs.config.contractsDir, sourceFile);
321
+ const $8d09eb70c0505719$var$getTestContractCmd = (parsedArgs, sourceFile)=>{
322
+ const projectDir = process.env.PROJECT_DIR ?? parsedArgs.projectDir;
323
+ if (!projectDir) throw `No project directory provided`;
324
+ const baseCmd = `DOCKER_DEFAULT_PLATFORM=linux/amd64 docker run --rm -v \"${projectDir}\":/project -w /project -u $(id -u):$(id -g) ligolang/ligo:next run test`;
325
+ const inputFile = $8d09eb70c0505719$var$getInputFilename(parsedArgs, sourceFile);
326
+ const cmd = `${baseCmd} ${inputFile}`;
327
+ return cmd;
328
+ };
329
+ const $8d09eb70c0505719$var$testContract = (parsedArgs, sourceFile)=>(0, $kQNfl$taquerianodesdk.getArch)().then(()=>$8d09eb70c0505719$var$getTestContractCmd(parsedArgs, sourceFile)).then((0, $kQNfl$taquerianodesdk.execCmd)).then(({ stdout: stdout , stderr: stderr })=>{
330
+ if (stderr.length > 0) (0, $kQNfl$taquerianodesdk.sendWarn)(stderr);
331
+ const result = "\uD83C\uDF89 All tests passed \uD83C\uDF89";
332
+ return {
333
+ contract: sourceFile,
334
+ testResults: stdout.length > 0 ? `${stdout}\n${result}` : result
335
+ };
336
+ }).catch((err)=>{
337
+ (0, $kQNfl$taquerianodesdk.sendErr)(`\n=== For ${sourceFile} ===`);
338
+ (0, $kQNfl$taquerianodesdk.sendErr)(err.message.replace(/Command failed.+?\n/, ""));
339
+ return {
340
+ contract: sourceFile,
341
+ testResults: "Some tests failed :("
342
+ };
343
+ });
344
+ const $8d09eb70c0505719$export$e0969da9b8fb378d = (parsedArgs)=>{
345
+ const sourceFile = parsedArgs.sourceFile;
346
+ return $8d09eb70c0505719$var$testContract(parsedArgs, sourceFile).then((result)=>[
347
+ result
348
+ ]).then((0, $kQNfl$taquerianodesdk.sendJsonRes)).catch((err)=>(0, $kQNfl$taquerianodesdk.sendAsyncErr)(err, false));
349
+ };
350
+ var $8d09eb70c0505719$export$2e2bcd8739ae039 = $8d09eb70c0505719$export$e0969da9b8fb378d;
351
+
352
+
319
353
  const $0be740342372c80a$export$e476ec665a77580b = (parsedArgs)=>{
320
354
  switch(parsedArgs.task){
321
355
  case "compile":
322
356
  return (0, $24b2f47d8f306cb3$export$2e2bcd8739ae039)(parsedArgs);
323
- // case 'test':
324
- // return test(parsedArgs); // TODO: to be implemented in the future
357
+ case "test":
358
+ return (0, $8d09eb70c0505719$export$e0969da9b8fb378d)(parsedArgs);
325
359
  default:
326
360
  return (0, $kQNfl$taquerianodesdk.sendAsyncErr)(`${parsedArgs.task} is not an understood task by the LIGO plugin`);
327
361
  }
@@ -344,6 +378,13 @@ var $0be740342372c80a$export$2e2bcd8739ae039 = $0be740342372c80a$export$e476ec66
344
378
  description: "Compile a smart contract written in a LIGO syntax to Michelson code, along with its associated storages and parameters files if they are found",
345
379
  handler: "proxy",
346
380
  encoding: "json"
381
+ }),
382
+ (0, $kQNfl$taquerianodesdk.Task).create({
383
+ task: "test",
384
+ command: "test <sourceFile>",
385
+ description: "Test a smart contract written in LIGO",
386
+ handler: "proxy",
387
+ encoding: "json"
347
388
  }),
348
389
  ],
349
390
  templates: [
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":";;;;AAAA;ACAA;;ACAO,MAAM,yCAAc,GAAG,CAAC;;;;;;;;;;;;;;;;;;;;;;;;AAwB/B,CAAC,AAAC;AAEK,MAAM,yCAAkB,GAAG,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BnC,CAAC,AAAC;AAEK,MAAM,yCAAe,GAAG,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;AAyBhC,CAAC,AAAC;AAEK,MAAM,yCAAe,GAAG,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;AAyBhC,CAAC,AAAC;;;ADlGF,MAAM,sCAAgB,GAAG,CAAC,GAAS,EAAE,YAAoB,GAAK;IAC7D,CAAA,GAAA,mCAAY,CAAA,CAAC,gBAAgB,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;CACjD,AAAC;AAEF,MAAM,qCAAe,GAAG,OAAO,YAAoB,EAAE,MAA0B,GAAsB;IACpG,MAAM,WAAW,GAAG,YAAY,CAAC,KAAK,YAAY,AAAC;IACnD,MAAM,GAAG,GAAG,WAAW,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,AAAC;IAE7D,IAAI,MAAM,KAAK,OAAO,EAAE,OAAO,GAAA,yCAAc,CAAC;IAC9C,IAAI,MAAM,KAAK,MAAM,EAAE,OAAO,GAAA,yCAAkB,CAAC;IACjD,IAAI,MAAM,KAAK,QAAQ,EAAE,OAAO,GAAA,yCAAe,CAAC;IAChD,IAAI,MAAM,KAAK,QAAQ,EAAE,OAAO,GAAA,yCAAe,CAAC;IAEhD,IAAI,MAAM,KAAK,SAAS,EAAE;QACzB,IAAI,GAAG,KAAK,OAAO,EAAE,OAAO,GAAA,yCAAc,CAAC;Q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.ts","taqueria-plugin-ligo/compile.ts"],"sourcesContent":["import { Option, Plugin, PositionalArg, Task, Template } from '@taqueria/node-sdk';\nimport createContract from './createContract';\nimport ligo from './ligo';\n\nPlugin.create(i18n => ({\n\tschema: '1.0',\n\tversion: '0.1',\n\talias: 'ligo',\n\ttasks: [\n\t\tTask.create({\n\t\t\ttask: 'compile',\n\t\t\tcommand: 'compile <sourceFile>',\n\t\t\taliases: ['c', 'compile-ligo'],\n\t\t\tdescription:\n\t\t\t\t'Compile a smart contract written in a LIGO syntax to Michelson code, along with its associated storages and parameters files if they are found',\n\t\t\thandler: 'proxy',\n\t\t\tencoding: 'json',\n\t\t}),\n\t],\n\ttemplates: [\n\t\tTemplate.create({\n\t\t\ttemplate: 'contract',\n\t\t\tcommand: 'contract <sourceFileName>',\n\t\t\tdescription: 'Create a LIGO contract with boilerplate code',\n\t\t\tpositionals: [\n\t\t\t\tPositionalArg.create({\n\t\t\t\t\tplaceholder: 'sourceFileName',\n\t\t\t\t\ttype: 'string',\n\t\t\t\t\tdescription: 'The name of the LIGO contract to generate',\n\t\t\t\t}),\n\t\t\t],\n\t\t\toptions: [\n\t\t\t\tOption.create({\n\t\t\t\t\tshortFlag: 's',\n\t\t\t\t\tflag: 'syntax',\n\t\t\t\t\ttype: 'string',\n\t\t\t\t\tdescription: 'The syntax used in the contract',\n\t\t\t\t}),\n\t\t\t],\n\t\t\thandler: createContract,\n\t\t}),\n\t],\n\tproxy: ligo,\n}), process.argv);\n","import { experimental, sendAsyncErr } from '@taqueria/node-sdk';\nimport * as RequestArgs from '@taqueria/protocol/RequestArgs';\nimport { writeFile } from 'fs/promises';\nimport { jsligo_template, mligo_template, pascaligo_template, religo_template } from './ligo_templates';\n\ninterface Opts extends RequestArgs.t {\n\tsourceFileName?: string;\n\tsyntax?: string;\n}\n\nconst registerContract = (arg: Opts, contractName: string) => {\n\texperimental.registerContract(arg, contractName);\n};\n\nconst getLigoTemplate = async (contractName: string, syntax: string | undefined): Promise<string> => {\n\tconst matchResult = contractName.match(/\\.[^.]+$/);\n\tconst ext = matchResult ? matchResult[0].substring(1) : null;\n\n\tif (syntax === 'mligo') return mligo_template;\n\tif (syntax === 'ligo') return pascaligo_template;\n\tif (syntax === 'religo') return religo_template;\n\tif (syntax === 'jsligo') return jsligo_template;\n\n\tif (syntax === undefined) {\n\t\tif (ext === 'mligo') return mligo_template;\n\t\tif (ext === 'ligo') return pascaligo_template;\n\t\tif (ext === 'religo') return religo_template;\n\t\tif (ext === 'jsligo') return jsligo_template;\n\t\treturn sendAsyncErr(\n\t\t\t`Unable to infer LIGO syntax from \"${contractName}\". Please specify a LIGO syntax via the --syntax option`,\n\t\t);\n\t} else {\n\t\treturn sendAsyncErr(`\"${syntax}\" is not a valid syntax. Please specify a valid LIGO syntax`);\n\t}\n};\n\nconst createContract = (arg: Opts) => {\n\tconst contractName = arg.sourceFileName as string;\n\tconst syntax = arg.syntax;\n\tconst contractsDir = `${arg.config.projectDir}/${arg.config.contractsDir}`;\n\treturn getLigoTemplate(contractName, syntax)\n\t\t.then(ligo_template => writeFile(`${contractsDir}/${contractName}`, ligo_template))\n\t\t.then(_ => registerContract(arg, contractName));\n};\n\nexport default createContract;\n","export const mligo_template = `\ntype storage = int\n\ntype parameter =\n Increment of int\n| Decrement of int\n| Reset\n\ntype return = operation list * storage\n\n// Two entrypoints\n\nlet add (store, delta : storage * int) : storage = store + delta\nlet sub (store, delta : storage * int) : storage = store - delta\n\n(* Main access point that dispatches to the entrypoints according to\n the smart contract parameter. *)\n \nlet main (action, store : parameter * storage) : return =\n ([] : operation list), // No operations\n (match action with\n Increment (n) -> add (store, n)\n | Decrement (n) -> sub (store, n)\n | Reset -> 0)\n`;\n\nexport const pascaligo_template = `\ntype storage is int\n\ntype parameter is\n Increment of int\n| Decrement of int\n| Reset\n\ntype return is list (operation) * storage\n\n// Two entrypoints\n\nfunction add (const store : storage; const delta : int) : storage is \n store + delta\n\nfunction sub (const store : storage; const delta : int) : storage is \n store - delta\n\n(* Main access point that dispatches to the entrypoints according to\n the smart contract parameter. *)\n \nfunction main (const action : parameter; const store : storage) : return is\n ((nil : list (operation)), // No operations\n case action of [\n Increment (n) -> add (store, n)\n | Decrement (n) -> sub (store, n)\n | Reset -> 0\n ])\n`;\n\nexport const religo_template = `\ntype storage = int;\n\ntype parameter =\n Increment (int)\n| Decrement (int)\n| Reset;\n\ntype return = (list (operation), storage);\n\n// Two entrypoints\n\nlet add = ((store, delta) : (storage, int)) : storage => store + delta;\nlet sub = ((store, delta) : (storage, int)) : storage => store - delta;\n\n/* Main access point that dispatches to the entrypoints according to\n the smart contract parameter. */\n \nlet main = ((action, store) : (parameter, storage)) : return => {\n (([] : list (operation)), // No operations\n (switch (action) {\n | Increment (n) => add ((store, n))\n | Decrement (n) => sub ((store, n))\n | Reset => 0}))\n};\n`;\n\nexport const jsligo_template = `\ntype storage = int;\n\ntype parameter =\n [\"Increment\", int]\n| [\"Decrement\", int]\n| [\"Reset\"];\n\ntype ret = [list<operation>, storage];\n\n// Two entrypoints\n\nconst add = ([store, delta] : [storage, int]) : storage => store + delta;\nconst sub = ([store, delta] : [storage, int]) : storage => store - delta;\n\n/* Main access point that dispatches to the entrypoints according to\n the smart contract parameter. */\n\nconst main = ([action, store] : [parameter, storage]) : ret => {\n return [list([]) as list<operation>, // No operations\n match (action, {\n Increment:(n: int) => add ([store, n]),\n Decrement:(n: int) => sub ([store, n]),\n Reset :() => 0})]\n};\n`;\n","import { sendAsyncErr } from '@taqueria/node-sdk';\nimport { RequestArgs } from '@taqueria/node-sdk/types';\nimport compile from './compile';\n\ninterface Opts extends RequestArgs.ProxyRequestArgs {\n\tsourceFile: string;\n}\n\nexport const ligo = (parsedArgs: Opts): Promise<void> => {\n\tswitch (parsedArgs.task) {\n\t\tcase 'compile':\n\t\t\treturn compile(parsedArgs);\n\t\t// case 'test':\n\t\t// \treturn test(parsedArgs); // TODO: to be implemented in the future\n\t\tdefault:\n\t\t\treturn sendAsyncErr(`${parsedArgs.task} is not an understood task by the LIGO plugin`);\n\t}\n};\n\nexport default ligo;\n","import { execCmd, getArch, sendAsyncErr, sendErr, sendJsonRes, sendWarn } from '@taqueria/node-sdk';\nimport { RequestArgs } from '@taqueria/node-sdk/types';\nimport { access, readFile, writeFile } from 'fs/promises';\nimport { basename, extname, join } from 'path';\n\ninterface Opts extends RequestArgs.t {\n\tsourceFile: string;\n}\n\ntype TableRow = { contract: string; artifact: string };\n\ntype ExprKind = 'storage' | 'default_storage' | 'parameter';\n\nconst COMPILE_ERR_MSG: string = 'Not compiled';\n\nconst isStorageKind = (exprKind: ExprKind): boolean => exprKind === 'storage' || exprKind === 'default_storage';\n\nconst isLIGOFile = (sourceFile: string): boolean => /.+\\.(ligo|religo|mligo|jsligo)$/.test(sourceFile);\n\nconst isStoragesFile = (sourceFile: string): boolean => /.+\\.storages\\.(ligo|religo|mligo|jsligo)$/.test(sourceFile);\n\nconst isParametersFile = (sourceFile: string): boolean =>\n\t/.+\\.parameters\\.(ligo|religo|mligo|jsligo)$/.test(sourceFile);\n\nconst isContractFile = (sourceFile: string): boolean =>\n\tisLIGOFile(sourceFile) && !isStoragesFile(sourceFile) && !isParametersFile(sourceFile);\n\nconst extractExt = (path: string): string => {\n\tconst matchResult = path.match(/\\.(ligo|religo|mligo|jsligo)$/);\n\treturn matchResult ? matchResult[0] : '';\n};\n\nconst removeExt = (path: string): string => {\n\tconst extRegex = new RegExp(extractExt(path));\n\treturn path.replace(extRegex, '');\n};\n\nconst getInputFilename = (parsedArgs: Opts, sourceFile: string): string =>\n\tjoin(parsedArgs.config.contractsDir, sourceFile);\n\nconst getOutputFilename = (parsedArgs: Opts, sourceFile: string): string => {\n\tconst outputFile = basename(sourceFile, extname(sourceFile));\n\treturn join(parsedArgs.config.artifactsDir, `${outputFile}.tz`);\n};\n\n// Get the contract name that the storage/parameter file is associated with\n// e.g. If sourceFile is token.storages.mligo, then it'll return token.mligo\nconst getContractNameForExpr = (sourceFile: string, exprKind: ExprKind): string => {\n\ttry {\n\t\treturn isStorageKind(exprKind)\n\t\t\t? sourceFile.match(/.+(?=\\.storages\\.(ligo|religo|mligo|jsligo))/)!.join('.')\n\t\t\t: sourceFile.match(/.+(?=\\.parameters\\.(ligo|religo|mligo|jsligo))/)!.join('.');\n\t} catch (err) {\n\t\tthrow new Error(`Something went wrong internally when dealing with filename format: ${err}`);\n\t}\n};\n\n// If sourceFile is token.storages.mligo, then it'll return token.storage.{storageName}.tz\nconst getOutputExprFileName = (parsedArgs: Opts, sourceFile: string, exprKind: ExprKind, exprName: string): string => {\n\tconst contractName = basename(getContractNameForExpr(sourceFile, exprKind), extname(sourceFile));\n\tconst outputFile = exprKind === 'default_storage'\n\t\t? `${contractName}.default_storage.tz`\n\t\t: `${contractName}.${exprKind}.${exprName}.tz`;\n\treturn join(parsedArgs.config.artifactsDir, `${outputFile}`);\n};\n\nconst getCompileContractCmd = (parsedArgs: Opts, sourceFile: string): string => {\n\tconst projectDir = process.env.PROJECT_DIR ?? parsedArgs.projectDir;\n\tif (!projectDir) throw `No project directory provided`;\n\tconst baseCmd =\n\t\t`DOCKER_DEFAULT_PLATFORM=linux/amd64 docker run --rm -v \\\"${projectDir}\\\":/project -w /project -u $(id -u):$(id -g) ligolang/ligo:next compile contract`;\n\tconst inputFile = getInputFilename(parsedArgs, sourceFile);\n\tconst outputFile = `-o ${getOutputFilename(parsedArgs, sourceFile)}`;\n\tconst cmd = `${baseCmd} ${inputFile} ${outputFile}`;\n\treturn cmd;\n};\n\nconst getCompileExprCmd = (parsedArgs: Opts, sourceFile: string, exprKind: ExprKind, exprName: string): string => {\n\tconst projectDir = process.env.PROJECT_DIR ?? parsedArgs.projectDir;\n\tif (!projectDir) throw `No project directory provided`;\n\tconst compilerType = isStorageKind(exprKind) ? 'storage' : 'parameter';\n\tconst baseCmd =\n\t\t`DOCKER_DEFAULT_PLATFORM=linux/amd64 docker run --rm -v \\\"${projectDir}\\\":/project -w /project -u $(id -u):$(id -g) ligolang/ligo:next compile ${compilerType}`;\n\tconst inputFile = getInputFilename(parsedArgs, sourceFile);\n\tconst outputFile = `-o ${getOutputExprFileName(parsedArgs, sourceFile, exprKind, exprName)}`;\n\tconst cmd = `${baseCmd} ${inputFile} ${exprName} ${outputFile}`;\n\treturn cmd;\n};\n\nconst compileContract = (parsedArgs: Opts, sourceFile: string): Promise<TableRow> =>\n\tgetArch()\n\t\t.then(() => getCompileContractCmd(parsedArgs, sourceFile))\n\t\t.then(execCmd)\n\t\t.then(({ stderr }) => {\n\t\t\tif (stderr.length > 0) sendWarn(stderr);\n\t\t\treturn {\n\t\t\t\tcontract: sourceFile,\n\t\t\t\tartifact: getOutputFilename(parsedArgs, sourceFile),\n\t\t\t};\n\t\t})\n\t\t.catch(err => {\n\t\t\tsendErr(`\\n=== For ${sourceFile} ===`);\n\t\t\tsendErr(err.message.replace(/Command failed.+?\\n/, ''));\n\t\t\treturn {\n\t\t\t\tcontract: sourceFile,\n\t\t\t\tartifact: COMPILE_ERR_MSG,\n\t\t\t};\n\t\t});\n\nconst compileExpr = (parsedArgs: Opts, sourceFile: string, exprKind: ExprKind) =>\n\t(exprName: string): Promise<TableRow> =>\n\t\tgetArch()\n\t\t\t.then(() => getCompileExprCmd(parsedArgs, sourceFile, exprKind, exprName))\n\t\t\t.then(execCmd)\n\t\t\t.then(({ stderr }) => {\n\t\t\t\tif (stderr.length > 0) sendWarn(stderr);\n\t\t\t\treturn {\n\t\t\t\t\tcontract: sourceFile,\n\t\t\t\t\tartifact: getOutputExprFileName(parsedArgs, sourceFile, exprKind, exprName),\n\t\t\t\t};\n\t\t\t})\n\t\t\t.catch(err => {\n\t\t\t\tsendErr(`\\n=== For ${sourceFile} ===`);\n\t\t\t\tsendErr(err.message.replace(/Command failed.+?\\n/, ''));\n\t\t\t\treturn {\n\t\t\t\t\tcontract: sourceFile,\n\t\t\t\t\tartifact: COMPILE_ERR_MSG,\n\t\t\t\t};\n\t\t\t});\n\nconst compileExprs = (parsedArgs: Opts, sourceFile: string, exprKind: ExprKind): Promise<TableRow[]> =>\n\treadFile(getInputFilename(parsedArgs, sourceFile), 'utf8')\n\t\t.then(data => {\n\t\t\tif (!data.includes('#include')) {\n\t\t\t\twriteFile(\n\t\t\t\t\tgetInputFilename(parsedArgs, sourceFile),\n\t\t\t\t\t`#include \"${getContractNameForExpr(sourceFile, exprKind)}\"\\n` + data,\n\t\t\t\t\t'utf8',\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn data;\n\t\t})\n\t\t.then(data => data.match(/(?<=\\s*(let|const)\\s+)[a-zA-Z0-9_]+/g))\n\t\t.then(exprNames => {\n\t\t\tif (!exprNames) return [];\n\t\t\tconst firstExprName = exprNames.slice(0, 1)[0];\n\t\t\tconst restExprNames = exprNames.slice(1, exprNames.length);\n\t\t\tconst firstExprKind = isStorageKind(exprKind) ? 'default_storage' : 'parameter';\n\t\t\tconst restExprKind = isStorageKind(exprKind) ? 'storage' : 'parameter';\n\t\t\tconst firstExprResult = compileExpr(parsedArgs, sourceFile, firstExprKind)(firstExprName);\n\t\t\tconst restExprResults = restExprNames.map(compileExpr(parsedArgs, sourceFile, restExprKind));\n\t\t\treturn Promise.all([firstExprResult].concat(restExprResults));\n\t\t})\n\t\t.catch(err => {\n\t\t\tsendErr(`\\n=== For ${sourceFile} ===`);\n\t\t\tsendErr(err.message);\n\t\t\treturn [{\n\t\t\t\tcontract: sourceFile,\n\t\t\t\tartifact: `No ${isStorageKind(exprKind) ? 'storages' : 'parameters'} compiled`,\n\t\t\t}];\n\t\t})\n\t\t.then(mergeArtifactsOutput(sourceFile));\n\nconst compileContractWithStorageAndParameter = async (parsedArgs: Opts, sourceFile: string) => {\n\tconst contractCompileResult = await compileContract(parsedArgs, sourceFile);\n\tif (contractCompileResult.artifact === COMPILE_ERR_MSG) return [contractCompileResult];\n\n\tconst storagesFile = `${removeExt(sourceFile)}.storages${extractExt(sourceFile)}`;\n\tconst parametersFile = `${removeExt(sourceFile)}.parameters${extractExt(sourceFile)}`;\n\tconst storagesFilename = getInputFilename(parsedArgs, storagesFile);\n\tconst parametersFilename = getInputFilename(parsedArgs, parametersFile);\n\n\tconst storageCompileResult = await access(storagesFilename)\n\t\t.then(() => compileExprs(parsedArgs, storagesFile, 'storage'))\n\t\t.catch(() => {\n\t\t\t// sendWarn(\n\t\t\t// \t`Note: storage file associated with \"${sourceFile}\" can't be found. You should create a file \"${storagesFile}\" and define initial storage values as a list of LIGO variable definitions. e.g. \"let STORAGE_NAME: storage = LIGO_EXPR\" for CameLigo`,\n\t\t\t// )\n\t\t});\n\n\tconst parameterCompileResult = await access(parametersFilename)\n\t\t.then(() => compileExprs(parsedArgs, parametersFile, 'parameter'))\n\t\t.catch(() => {\n\t\t\t// sendWarn(\n\t\t\t// \t`Note: parameter file associated with \"${sourceFile}\" can't be found. You should create a file \"${parametersFile}\" and define parameter values as a list of LIGO variable definitions. e.g. \"let PARAMETER_NAME: parameter = LIGO_EXPR\" for CameLigo`,\n\t\t\t// )\n\t\t});\n\n\tlet compileResults: TableRow[] = [contractCompileResult];\n\tif (storageCompileResult) compileResults = compileResults.concat(storageCompileResult);\n\tif (parameterCompileResult) compileResults = compileResults.concat(parameterCompileResult);\n\treturn compileResults;\n};\n\n/*\nCompiling storage/parameter file amounts to compiling multiple expressions in that file,\nresulting in multiple rows with the same file name but different artifact names.\nThis will merge these rows into one row with just one mention of the file name.\ne.g.\n┌──────────────────────┬─────────────────────────────────────────────┐\n│ Contract │ Artifact │\n├──────────────────────┼─────────────────────────────────────────────┤\n│ hello.storages.mligo │ artifacts/hello.default_storage.storage1.tz │\n├──────────────────────┼─────────────────────────────────────────────┤\n│ hello.storages.mligo │ artifacts/hello.storage.storage2.tz │\n└──────────────────────┴─────────────────────────────────────────────┘\n\t\t\t\t\t\t\t\tversus\n┌──────────────────────┬─────────────────────────────────────────────┐\n│ Contract │ Artifact │\n├──────────────────────┼─────────────────────────────────────────────┤\n│ hello.storages.mligo │ artifacts/hello.default_storage.storage1.tz │\n│ │ artifacts/hello.storage.storage2.tz │\n└──────────────────────┴─────────────────────────────────────────────┘\n*/\nconst mergeArtifactsOutput = (sourceFile: string) =>\n\t(tableRows: TableRow[]): TableRow[] => {\n\t\tconst artifactsOutput = tableRows.reduce(\n\t\t\t(acc: string, row: TableRow) => row.artifact === COMPILE_ERR_MSG ? acc : `${acc}${row.artifact}\\n`,\n\t\t\t'',\n\t\t);\n\t\treturn [{\n\t\t\tcontract: sourceFile,\n\t\t\tartifact: artifactsOutput,\n\t\t}];\n\t};\n\nexport const compile = (parsedArgs: Opts): Promise<void> => {\n\tconst sourceFile = parsedArgs.sourceFile;\n\tif (!sourceFile) return sendAsyncErr('No source file specified.');\n\tlet p: Promise<TableRow[]>;\n\tif (isStoragesFile(sourceFile)) p = compileExprs(parsedArgs, sourceFile, 'storage');\n\telse if (isParametersFile(sourceFile)) p = compileExprs(parsedArgs, sourceFile, 'parameter');\n\telse if (isContractFile(sourceFile)) p = compileContractWithStorageAndParameter(parsedArgs, sourceFile);\n\telse {\n\t\treturn sendAsyncErr(\n\t\t\t`${sourceFile} doesn't have a valid LIGO extension ('.ligo', '.religo', '.mligo' or '.jsligo')`,\n\t\t);\n\t}\n\treturn p.then(sendJsonRes).catch(err => sendAsyncErr(err, false));\n};\n\nexport default compile;\n"],"names":[],"version":3,"file":"index.js.map","sourceRoot":"../"}
1
+ {"mappings":";;;;AAAA;ACAA;;ACAO,MAAM,yCAAc,GAAG,CAAC;;;;;;;;;;;;;;;;;;;;;;;;AAwB/B,CAAC,AAAC;AAEK,MAAM,yCAAkB,GAAG,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BnC,CAAC,AAAC;AAEK,MAAM,yCAAe,GAAG,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;AAyBhC,CAAC,AAAC;AAEK,MAAM,yCAAe,GAAG,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;AAyBhC,CAAC,AAAC;;;ADlGF,MAAM,sCAAgB,GAAG,CAAC,GAAS,EAAE,YAAoB,GAAK;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;wBACd,WAAW,EAAE,iCAAiC;qBAC9C,CAAC;iBACF;gBACD,OAAO,EAAE,CAAA,GAAA,wCAAc,CAAA;aACvB,CAAC;SACF;QACD,KAAK,EAAE,CAAA,GAAA,wCAAI,CAAA;KACX,CAAA,AAAC,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC","sources":["taqueria-plugin-ligo/index.ts","taqueria-plugin-ligo/createContract.ts","taqueria-plugin-ligo/ligo_templates.ts","taqueria-plugin-ligo/ligo.ts","taqueria-plugin-ligo/compile.ts","taqueria-plugin-ligo/test.ts"],"sourcesContent":["import { Option, Plugin, PositionalArg, Task, Template } from '@taqueria/node-sdk';\nimport createContract from './createContract';\nimport ligo from './ligo';\n\nPlugin.create(i18n => ({\n\tschema: '1.0',\n\tversion: '0.1',\n\talias: 'ligo',\n\ttasks: [\n\t\tTask.create({\n\t\t\ttask: 'compile',\n\t\t\tcommand: 'compile <sourceFile>',\n\t\t\taliases: ['c', 'compile-ligo'],\n\t\t\tdescription:\n\t\t\t\t'Compile a smart contract written in a LIGO syntax to Michelson code, along with its associated storages and parameters files if they are found',\n\t\t\thandler: 'proxy',\n\t\t\tencoding: 'json',\n\t\t}),\n\t\tTask.create({\n\t\t\ttask: 'test',\n\t\t\tcommand: 'test <sourceFile>',\n\t\t\tdescription: 'Test a smart contract written in LIGO',\n\t\t\thandler: 'proxy',\n\t\t\tencoding: 'json',\n\t\t}),\n\t],\n\ttemplates: [\n\t\tTemplate.create({\n\t\t\ttemplate: 'contract',\n\t\t\tcommand: 'contract <sourceFileName>',\n\t\t\tdescription: 'Create a LIGO contract with boilerplate code',\n\t\t\tpositionals: [\n\t\t\t\tPositionalArg.create({\n\t\t\t\t\tplaceholder: 'sourceFileName',\n\t\t\t\t\ttype: 'string',\n\t\t\t\t\tdescription: 'The name of the LIGO contract to generate',\n\t\t\t\t}),\n\t\t\t],\n\t\t\toptions: [\n\t\t\t\tOption.create({\n\t\t\t\t\tshortFlag: 's',\n\t\t\t\t\tflag: 'syntax',\n\t\t\t\t\ttype: 'string',\n\t\t\t\t\tdescription: 'The syntax used in the contract',\n\t\t\t\t}),\n\t\t\t],\n\t\t\thandler: createContract,\n\t\t}),\n\t],\n\tproxy: ligo,\n}), process.argv);\n","import { experimental, sendAsyncErr } from '@taqueria/node-sdk';\nimport * as RequestArgs from '@taqueria/protocol/RequestArgs';\nimport { writeFile } from 'fs/promises';\nimport { jsligo_template, mligo_template, pascaligo_template, religo_template } from './ligo_templates';\n\ninterface Opts extends RequestArgs.t {\n\tsourceFileName?: string;\n\tsyntax?: string;\n}\n\nconst registerContract = (arg: Opts, contractName: string) => {\n\texperimental.registerContract(arg, contractName);\n};\n\nconst getLigoTemplate = async (contractName: string, syntax: string | undefined): Promise<string> => {\n\tconst matchResult = contractName.match(/\\.[^.]+$/);\n\tconst ext = matchResult ? matchResult[0].substring(1) : null;\n\n\tif (syntax === 'mligo') return mligo_template;\n\tif (syntax === 'ligo') return pascaligo_template;\n\tif (syntax === 'religo') return religo_template;\n\tif (syntax === 'jsligo') return jsligo_template;\n\n\tif (syntax === undefined) {\n\t\tif (ext === 'mligo') return mligo_template;\n\t\tif (ext === 'ligo') return pascaligo_template;\n\t\tif (ext === 'religo') return religo_template;\n\t\tif (ext === 'jsligo') return jsligo_template;\n\t\treturn sendAsyncErr(\n\t\t\t`Unable to infer LIGO syntax from \"${contractName}\". Please specify a LIGO syntax via the --syntax option`,\n\t\t);\n\t} else {\n\t\treturn sendAsyncErr(`\"${syntax}\" is not a valid syntax. Please specify a valid LIGO syntax`);\n\t}\n};\n\nconst createContract = (arg: Opts) => {\n\tconst contractName = arg.sourceFileName as string;\n\tconst syntax = arg.syntax;\n\tconst contractsDir = `${arg.config.projectDir}/${arg.config.contractsDir}`;\n\treturn getLigoTemplate(contractName, syntax)\n\t\t.then(ligo_template => writeFile(`${contractsDir}/${contractName}`, ligo_template))\n\t\t.then(_ => registerContract(arg, contractName));\n};\n\nexport default createContract;\n","export const mligo_template = `\ntype storage = int\n\ntype parameter =\n Increment of int\n| Decrement of int\n| Reset\n\ntype return = operation list * storage\n\n// Two entrypoints\n\nlet add (store, delta : storage * int) : storage = store + delta\nlet sub (store, delta : storage * int) : storage = store - delta\n\n(* Main access point that dispatches to the entrypoints according to\n the smart contract parameter. *)\n \nlet main (action, store : parameter * storage) : return =\n ([] : operation list), // No operations\n (match action with\n Increment (n) -> add (store, n)\n | Decrement (n) -> sub (store, n)\n | Reset -> 0)\n`;\n\nexport const pascaligo_template = `\ntype storage is int\n\ntype parameter is\n Increment of int\n| Decrement of int\n| Reset\n\ntype return is list (operation) * storage\n\n// Two entrypoints\n\nfunction add (const store : storage; const delta : int) : storage is \n store + delta\n\nfunction sub (const store : storage; const delta : int) : storage is \n store - delta\n\n(* Main access point that dispatches to the entrypoints according to\n the smart contract parameter. *)\n \nfunction main (const action : parameter; const store : storage) : return is\n ((nil : list (operation)), // No operations\n case action of [\n Increment (n) -> add (store, n)\n | Decrement (n) -> sub (store, n)\n | Reset -> 0\n ])\n`;\n\nexport const religo_template = `\ntype storage = int;\n\ntype parameter =\n Increment (int)\n| Decrement (int)\n| Reset;\n\ntype return = (list (operation), storage);\n\n// Two entrypoints\n\nlet add = ((store, delta) : (storage, int)) : storage => store + delta;\nlet sub = ((store, delta) : (storage, int)) : storage => store - delta;\n\n/* Main access point that dispatches to the entrypoints according to\n the smart contract parameter. */\n \nlet main = ((action, store) : (parameter, storage)) : return => {\n (([] : list (operation)), // No operations\n (switch (action) {\n | Increment (n) => add ((store, n))\n | Decrement (n) => sub ((store, n))\n | Reset => 0}))\n};\n`;\n\nexport const jsligo_template = `\ntype storage = int;\n\ntype parameter =\n [\"Increment\", int]\n| [\"Decrement\", int]\n| [\"Reset\"];\n\ntype ret = [list<operation>, storage];\n\n// Two entrypoints\n\nconst add = ([store, delta] : [storage, int]) : storage => store + delta;\nconst sub = ([store, delta] : [storage, int]) : storage => store - delta;\n\n/* Main access point that dispatches to the entrypoints according to\n the smart contract parameter. */\n\nconst main = ([action, store] : [parameter, storage]) : ret => {\n return [list([]) as list<operation>, // No operations\n match (action, {\n Increment:(n: int) => add ([store, n]),\n Decrement:(n: int) => sub ([store, n]),\n Reset :() => 0})]\n};\n`;\n","import { sendAsyncErr } from '@taqueria/node-sdk';\nimport { RequestArgs } from '@taqueria/node-sdk/types';\nimport compile from './compile';\nimport { test } from './test';\n\ninterface Opts extends RequestArgs.ProxyRequestArgs {\n\tsourceFile: string;\n}\n\nexport const ligo = (parsedArgs: Opts): Promise<void> => {\n\tswitch (parsedArgs.task) {\n\t\tcase 'compile':\n\t\t\treturn compile(parsedArgs);\n\t\tcase 'test':\n\t\t\treturn test(parsedArgs);\n\t\tdefault:\n\t\t\treturn sendAsyncErr(`${parsedArgs.task} is not an understood task by the LIGO plugin`);\n\t}\n};\n\nexport default ligo;\n","import { execCmd, getArch, sendAsyncErr, sendErr, sendJsonRes, sendWarn } from '@taqueria/node-sdk';\nimport { RequestArgs } from '@taqueria/node-sdk/types';\nimport { access, readFile, writeFile } from 'fs/promises';\nimport { basename, extname, join } from 'path';\n\ninterface Opts extends RequestArgs.t {\n\tsourceFile: string;\n}\n\ntype TableRow = { contract: string; artifact: string };\n\ntype ExprKind = 'storage' | 'default_storage' | 'parameter';\n\nconst COMPILE_ERR_MSG: string = 'Not compiled';\n\nconst isStorageKind = (exprKind: ExprKind): boolean => exprKind === 'storage' || exprKind === 'default_storage';\n\nconst isLIGOFile = (sourceFile: string): boolean => /.+\\.(ligo|religo|mligo|jsligo)$/.test(sourceFile);\n\nconst isStoragesFile = (sourceFile: string): boolean => /.+\\.storages\\.(ligo|religo|mligo|jsligo)$/.test(sourceFile);\n\nconst isParametersFile = (sourceFile: string): boolean =>\n\t/.+\\.parameters\\.(ligo|religo|mligo|jsligo)$/.test(sourceFile);\n\nconst isContractFile = (sourceFile: string): boolean =>\n\tisLIGOFile(sourceFile) && !isStoragesFile(sourceFile) && !isParametersFile(sourceFile);\n\nconst extractExt = (path: string): string => {\n\tconst matchResult = path.match(/\\.(ligo|religo|mligo|jsligo)$/);\n\treturn matchResult ? matchResult[0] : '';\n};\n\nconst removeExt = (path: string): string => {\n\tconst extRegex = new RegExp(extractExt(path));\n\treturn path.replace(extRegex, '');\n};\n\nconst getInputFilename = (parsedArgs: Opts, sourceFile: string): string =>\n\tjoin(parsedArgs.config.contractsDir, sourceFile);\n\nconst getOutputFilename = (parsedArgs: Opts, sourceFile: string): string => {\n\tconst outputFile = basename(sourceFile, extname(sourceFile));\n\treturn join(parsedArgs.config.artifactsDir, `${outputFile}.tz`);\n};\n\n// Get the contract name that the storage/parameter file is associated with\n// e.g. If sourceFile is token.storages.mligo, then it'll return token.mligo\nconst getContractNameForExpr = (sourceFile: string, exprKind: ExprKind): string => {\n\ttry {\n\t\treturn isStorageKind(exprKind)\n\t\t\t? sourceFile.match(/.+(?=\\.storages\\.(ligo|religo|mligo|jsligo))/)!.join('.')\n\t\t\t: sourceFile.match(/.+(?=\\.parameters\\.(ligo|religo|mligo|jsligo))/)!.join('.');\n\t} catch (err) {\n\t\tthrow new Error(`Something went wrong internally when dealing with filename format: ${err}`);\n\t}\n};\n\n// If sourceFile is token.storages.mligo, then it'll return token.storage.{storageName}.tz\nconst getOutputExprFileName = (parsedArgs: Opts, sourceFile: string, exprKind: ExprKind, exprName: string): string => {\n\tconst contractName = basename(getContractNameForExpr(sourceFile, exprKind), extname(sourceFile));\n\tconst outputFile = exprKind === 'default_storage'\n\t\t? `${contractName}.default_storage.tz`\n\t\t: `${contractName}.${exprKind}.${exprName}.tz`;\n\treturn join(parsedArgs.config.artifactsDir, `${outputFile}`);\n};\n\nconst getCompileContractCmd = (parsedArgs: Opts, sourceFile: string): string => {\n\tconst projectDir = process.env.PROJECT_DIR ?? parsedArgs.projectDir;\n\tif (!projectDir) throw `No project directory provided`;\n\tconst baseCmd =\n\t\t`DOCKER_DEFAULT_PLATFORM=linux/amd64 docker run --rm -v \\\"${projectDir}\\\":/project -w /project -u $(id -u):$(id -g) ligolang/ligo:next compile contract`;\n\tconst inputFile = getInputFilename(parsedArgs, sourceFile);\n\tconst outputFile = `-o ${getOutputFilename(parsedArgs, sourceFile)}`;\n\tconst cmd = `${baseCmd} ${inputFile} ${outputFile}`;\n\treturn cmd;\n};\n\nconst getCompileExprCmd = (parsedArgs: Opts, sourceFile: string, exprKind: ExprKind, exprName: string): string => {\n\tconst projectDir = process.env.PROJECT_DIR ?? parsedArgs.projectDir;\n\tif (!projectDir) throw `No project directory provided`;\n\tconst compilerType = isStorageKind(exprKind) ? 'storage' : 'parameter';\n\tconst baseCmd =\n\t\t`DOCKER_DEFAULT_PLATFORM=linux/amd64 docker run --rm -v \\\"${projectDir}\\\":/project -w /project -u $(id -u):$(id -g) ligolang/ligo:next compile ${compilerType}`;\n\tconst inputFile = getInputFilename(parsedArgs, sourceFile);\n\tconst outputFile = `-o ${getOutputExprFileName(parsedArgs, sourceFile, exprKind, exprName)}`;\n\tconst cmd = `${baseCmd} ${inputFile} ${exprName} ${outputFile}`;\n\treturn cmd;\n};\n\nconst compileContract = (parsedArgs: Opts, sourceFile: string): Promise<TableRow> =>\n\tgetArch()\n\t\t.then(() => getCompileContractCmd(parsedArgs, sourceFile))\n\t\t.then(execCmd)\n\t\t.then(({ stderr }) => {\n\t\t\tif (stderr.length > 0) sendWarn(stderr);\n\t\t\treturn {\n\t\t\t\tcontract: sourceFile,\n\t\t\t\tartifact: getOutputFilename(parsedArgs, sourceFile),\n\t\t\t};\n\t\t})\n\t\t.catch(err => {\n\t\t\tsendErr(`\\n=== For ${sourceFile} ===`);\n\t\t\tsendErr(err.message.replace(/Command failed.+?\\n/, ''));\n\t\t\treturn {\n\t\t\t\tcontract: sourceFile,\n\t\t\t\tartifact: COMPILE_ERR_MSG,\n\t\t\t};\n\t\t});\n\nconst compileExpr = (parsedArgs: Opts, sourceFile: string, exprKind: ExprKind) =>\n\t(exprName: string): Promise<TableRow> =>\n\t\tgetArch()\n\t\t\t.then(() => getCompileExprCmd(parsedArgs, sourceFile, exprKind, exprName))\n\t\t\t.then(execCmd)\n\t\t\t.then(({ stderr }) => {\n\t\t\t\tif (stderr.length > 0) sendWarn(stderr);\n\t\t\t\treturn {\n\t\t\t\t\tcontract: sourceFile,\n\t\t\t\t\tartifact: getOutputExprFileName(parsedArgs, sourceFile, exprKind, exprName),\n\t\t\t\t};\n\t\t\t})\n\t\t\t.catch(err => {\n\t\t\t\tsendErr(`\\n=== For ${sourceFile} ===`);\n\t\t\t\tsendErr(err.message.replace(/Command failed.+?\\n/, ''));\n\t\t\t\treturn {\n\t\t\t\t\tcontract: sourceFile,\n\t\t\t\t\tartifact: COMPILE_ERR_MSG,\n\t\t\t\t};\n\t\t\t});\n\nconst compileExprs = (parsedArgs: Opts, sourceFile: string, exprKind: ExprKind): Promise<TableRow[]> =>\n\treadFile(getInputFilename(parsedArgs, sourceFile), 'utf8')\n\t\t.then(data => {\n\t\t\tif (!data.includes('#include')) {\n\t\t\t\twriteFile(\n\t\t\t\t\tgetInputFilename(parsedArgs, sourceFile),\n\t\t\t\t\t`#include \"${getContractNameForExpr(sourceFile, exprKind)}\"\\n` + data,\n\t\t\t\t\t'utf8',\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn data;\n\t\t})\n\t\t.then(data => data.match(/(?<=\\s*(let|const)\\s+)[a-zA-Z0-9_]+/g))\n\t\t.then(exprNames => {\n\t\t\tif (!exprNames) return [];\n\t\t\tconst firstExprName = exprNames.slice(0, 1)[0];\n\t\t\tconst restExprNames = exprNames.slice(1, exprNames.length);\n\t\t\tconst firstExprKind = isStorageKind(exprKind) ? 'default_storage' : 'parameter';\n\t\t\tconst restExprKind = isStorageKind(exprKind) ? 'storage' : 'parameter';\n\t\t\tconst firstExprResult = compileExpr(parsedArgs, sourceFile, firstExprKind)(firstExprName);\n\t\t\tconst restExprResults = restExprNames.map(compileExpr(parsedArgs, sourceFile, restExprKind));\n\t\t\treturn Promise.all([firstExprResult].concat(restExprResults));\n\t\t})\n\t\t.catch(err => {\n\t\t\tsendErr(`\\n=== For ${sourceFile} ===`);\n\t\t\tsendErr(err.message);\n\t\t\treturn [{\n\t\t\t\tcontract: sourceFile,\n\t\t\t\tartifact: `No ${isStorageKind(exprKind) ? 'storages' : 'parameters'} compiled`,\n\t\t\t}];\n\t\t})\n\t\t.then(mergeArtifactsOutput(sourceFile));\n\nconst compileContractWithStorageAndParameter = async (parsedArgs: Opts, sourceFile: string): Promise<TableRow[]> => {\n\tconst contractCompileResult = await compileContract(parsedArgs, sourceFile);\n\tif (contractCompileResult.artifact === COMPILE_ERR_MSG) return [contractCompileResult];\n\n\tconst storagesFile = `${removeExt(sourceFile)}.storages${extractExt(sourceFile)}`;\n\tconst parametersFile = `${removeExt(sourceFile)}.parameters${extractExt(sourceFile)}`;\n\tconst storagesFilename = getInputFilename(parsedArgs, storagesFile);\n\tconst parametersFilename = getInputFilename(parsedArgs, parametersFile);\n\n\tconst storageCompileResult = await access(storagesFilename)\n\t\t.then(() => compileExprs(parsedArgs, storagesFile, 'storage'))\n\t\t.catch(() => {\n\t\t\t// sendWarn(\n\t\t\t// \t`Note: storage file associated with \"${sourceFile}\" can't be found. You should create a file \"${storagesFile}\" and define initial storage values as a list of LIGO variable definitions. e.g. \"let STORAGE_NAME: storage = LIGO_EXPR\" for CameLigo`,\n\t\t\t// )\n\t\t});\n\n\tconst parameterCompileResult = await access(parametersFilename)\n\t\t.then(() => compileExprs(parsedArgs, parametersFile, 'parameter'))\n\t\t.catch(() => {\n\t\t\t// sendWarn(\n\t\t\t// \t`Note: parameter file associated with \"${sourceFile}\" can't be found. You should create a file \"${parametersFile}\" and define parameter values as a list of LIGO variable definitions. e.g. \"let PARAMETER_NAME: parameter = LIGO_EXPR\" for CameLigo`,\n\t\t\t// )\n\t\t});\n\n\tlet compileResults: TableRow[] = [contractCompileResult];\n\tif (storageCompileResult) compileResults = compileResults.concat(storageCompileResult);\n\tif (parameterCompileResult) compileResults = compileResults.concat(parameterCompileResult);\n\treturn compileResults;\n};\n\n/*\nCompiling storage/parameter file amounts to compiling multiple expressions in that file,\nresulting in multiple rows with the same file name but different artifact names.\nThis will merge these rows into one row with just one mention of the file name.\ne.g.\n┌──────────────────────┬─────────────────────────────────────────────┐\n│ Contract │ Artifact │\n├──────────────────────┼─────────────────────────────────────────────┤\n│ hello.storages.mligo │ artifacts/hello.default_storage.storage1.tz │\n├──────────────────────┼─────────────────────────────────────────────┤\n│ hello.storages.mligo │ artifacts/hello.storage.storage2.tz │\n└──────────────────────┴─────────────────────────────────────────────┘\n\t\t\t\t\t\t\t\tversus\n┌──────────────────────┬─────────────────────────────────────────────┐\n│ Contract │ Artifact │\n├──────────────────────┼─────────────────────────────────────────────┤\n│ hello.storages.mligo │ artifacts/hello.default_storage.storage1.tz │\n│ │ artifacts/hello.storage.storage2.tz │\n└──────────────────────┴─────────────────────────────────────────────┘\n*/\nconst mergeArtifactsOutput = (sourceFile: string) =>\n\t(tableRows: TableRow[]): TableRow[] => {\n\t\tconst artifactsOutput = tableRows.reduce(\n\t\t\t(acc: string, row: TableRow) => row.artifact === COMPILE_ERR_MSG ? acc : `${acc}${row.artifact}\\n`,\n\t\t\t'',\n\t\t);\n\t\treturn [{\n\t\t\tcontract: sourceFile,\n\t\t\tartifact: artifactsOutput,\n\t\t}];\n\t};\n\nexport const compile = (parsedArgs: Opts): Promise<void> => {\n\tconst sourceFile = parsedArgs.sourceFile;\n\tlet p: Promise<TableRow[]>;\n\tif (isStoragesFile(sourceFile)) p = compileExprs(parsedArgs, sourceFile, 'storage');\n\telse if (isParametersFile(sourceFile)) p = compileExprs(parsedArgs, sourceFile, 'parameter');\n\telse if (isContractFile(sourceFile)) p = compileContractWithStorageAndParameter(parsedArgs, sourceFile);\n\telse {\n\t\treturn sendAsyncErr(\n\t\t\t`${sourceFile} doesn't have a valid LIGO extension ('.ligo', '.religo', '.mligo' or '.jsligo')`,\n\t\t);\n\t}\n\treturn p.then(sendJsonRes).catch(err => sendAsyncErr(err, false));\n};\n\nexport default compile;\n","import { execCmd, getArch, sendAsyncErr, sendErr, sendJsonRes, sendWarn } from '@taqueria/node-sdk';\nimport { RequestArgs } from '@taqueria/node-sdk/types';\nimport { join } from 'path';\n\ninterface Opts extends RequestArgs.t {\n\tsourceFile: string;\n}\n\ntype TableRow = { contract: string; testResults: string };\n\nconst getInputFilename = (parsedArgs: Opts, sourceFile: string): string =>\n\tjoin(parsedArgs.config.contractsDir, sourceFile);\n\nconst getTestContractCmd = (parsedArgs: Opts, sourceFile: string): string => {\n\tconst projectDir = process.env.PROJECT_DIR ?? parsedArgs.projectDir;\n\tif (!projectDir) throw `No project directory provided`;\n\tconst baseCmd =\n\t\t`DOCKER_DEFAULT_PLATFORM=linux/amd64 docker run --rm -v \\\"${projectDir}\\\":/project -w /project -u $(id -u):$(id -g) ligolang/ligo:next run test`;\n\tconst inputFile = getInputFilename(parsedArgs, sourceFile);\n\tconst cmd = `${baseCmd} ${inputFile}`;\n\treturn cmd;\n};\n\nconst testContract = (parsedArgs: Opts, sourceFile: string): Promise<TableRow> =>\n\tgetArch()\n\t\t.then(() => getTestContractCmd(parsedArgs, sourceFile))\n\t\t.then(execCmd)\n\t\t.then(({ stdout, stderr }) => {\n\t\t\tif (stderr.length > 0) sendWarn(stderr);\n\t\t\tconst result = '🎉 All tests passed 🎉';\n\t\t\treturn {\n\t\t\t\tcontract: sourceFile,\n\t\t\t\ttestResults: stdout.length > 0 ? `${stdout}\\n${result}` : result,\n\t\t\t};\n\t\t})\n\t\t.catch(err => {\n\t\t\tsendErr(`\\n=== For ${sourceFile} ===`);\n\t\t\tsendErr(err.message.replace(/Command failed.+?\\n/, ''));\n\t\t\treturn {\n\t\t\t\tcontract: sourceFile,\n\t\t\t\ttestResults: 'Some tests failed :(',\n\t\t\t};\n\t\t});\n\nexport const test = (parsedArgs: Opts): Promise<void> => {\n\tconst sourceFile = parsedArgs.sourceFile;\n\treturn testContract(parsedArgs, sourceFile).then(result => [result]).then(sendJsonRes).catch(err =>\n\t\tsendAsyncErr(err, false)\n\t);\n};\n\nexport default test;\n"],"names":[],"version":3,"file":"index.js.map","sourceRoot":"../"}
package/index.ts CHANGED
@@ -16,6 +16,13 @@ Plugin.create(i18n => ({
16
16
  handler: 'proxy',
17
17
  encoding: 'json',
18
18
  }),
19
+ Task.create({
20
+ task: 'test',
21
+ command: 'test <sourceFile>',
22
+ description: 'Test a smart contract written in LIGO',
23
+ handler: 'proxy',
24
+ encoding: 'json',
25
+ }),
19
26
  ],
20
27
  templates: [
21
28
  Template.create({
package/ligo.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { sendAsyncErr } from '@taqueria/node-sdk';
2
2
  import { RequestArgs } from '@taqueria/node-sdk/types';
3
3
  import compile from './compile';
4
+ import { test } from './test';
4
5
 
5
6
  interface Opts extends RequestArgs.ProxyRequestArgs {
6
7
  sourceFile: string;
@@ -10,8 +11,8 @@ export const ligo = (parsedArgs: Opts): Promise<void> => {
10
11
  switch (parsedArgs.task) {
11
12
  case 'compile':
12
13
  return compile(parsedArgs);
13
- // case 'test':
14
- // return test(parsedArgs); // TODO: to be implemented in the future
14
+ case 'test':
15
+ return test(parsedArgs);
15
16
  default:
16
17
  return sendAsyncErr(`${parsedArgs.task} is not an understood task by the LIGO plugin`);
17
18
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taqueria/plugin-ligo",
3
- "version": "0.18.0",
3
+ "version": "0.19.3",
4
4
  "description": "A taqueria plugin for compiling LIGO smart contracts",
5
5
  "targets": {
6
6
  "default": {
@@ -41,7 +41,7 @@
41
41
  },
42
42
  "homepage": "https://github.com/ecadlabs/taqueria#readme",
43
43
  "dependencies": {
44
- "@taqueria/node-sdk": "^0.18.0",
44
+ "@taqueria/node-sdk": "^0.19.3",
45
45
  "fast-glob": "^3.2.11"
46
46
  },
47
47
  "devDependencies": {
package/test.ts ADDED
@@ -0,0 +1,52 @@
1
+ import { execCmd, getArch, sendAsyncErr, sendErr, sendJsonRes, sendWarn } from '@taqueria/node-sdk';
2
+ import { RequestArgs } from '@taqueria/node-sdk/types';
3
+ import { join } from 'path';
4
+
5
+ interface Opts extends RequestArgs.t {
6
+ sourceFile: string;
7
+ }
8
+
9
+ type TableRow = { contract: string; testResults: string };
10
+
11
+ const getInputFilename = (parsedArgs: Opts, sourceFile: string): string =>
12
+ join(parsedArgs.config.contractsDir, sourceFile);
13
+
14
+ const getTestContractCmd = (parsedArgs: Opts, sourceFile: string): string => {
15
+ const projectDir = process.env.PROJECT_DIR ?? parsedArgs.projectDir;
16
+ if (!projectDir) throw `No project directory provided`;
17
+ const baseCmd =
18
+ `DOCKER_DEFAULT_PLATFORM=linux/amd64 docker run --rm -v \"${projectDir}\":/project -w /project -u $(id -u):$(id -g) ligolang/ligo:next run test`;
19
+ const inputFile = getInputFilename(parsedArgs, sourceFile);
20
+ const cmd = `${baseCmd} ${inputFile}`;
21
+ return cmd;
22
+ };
23
+
24
+ const testContract = (parsedArgs: Opts, sourceFile: string): Promise<TableRow> =>
25
+ getArch()
26
+ .then(() => getTestContractCmd(parsedArgs, sourceFile))
27
+ .then(execCmd)
28
+ .then(({ stdout, stderr }) => {
29
+ if (stderr.length > 0) sendWarn(stderr);
30
+ const result = '🎉 All tests passed 🎉';
31
+ return {
32
+ contract: sourceFile,
33
+ testResults: stdout.length > 0 ? `${stdout}\n${result}` : result,
34
+ };
35
+ })
36
+ .catch(err => {
37
+ sendErr(`\n=== For ${sourceFile} ===`);
38
+ sendErr(err.message.replace(/Command failed.+?\n/, ''));
39
+ return {
40
+ contract: sourceFile,
41
+ testResults: 'Some tests failed :(',
42
+ };
43
+ });
44
+
45
+ export const test = (parsedArgs: Opts): Promise<void> => {
46
+ const sourceFile = parsedArgs.sourceFile;
47
+ return testContract(parsedArgs, sourceFile).then(result => [result]).then(sendJsonRes).catch(err =>
48
+ sendAsyncErr(err, false)
49
+ );
50
+ };
51
+
52
+ export default test;