@taqueria/plugin-jest 0.42.3 → 0.42.6
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 +7 -0
- package/contractTestTemplate.ts +15 -16
- package/index.cjs.map +1 -1
- package/index.js.map +1 -1
- package/package.json +3 -3
package/README.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Jest Plugin
|
|
2
|
+
|
|
3
|
+
The Jest plugin provides a `taq test` task to run tests written in JavaScript or TypeScript using the [Jest](https://jestjs.io/) testing framework.
|
|
4
|
+
|
|
5
|
+
We encourage you to write your tests with Jest and Taquito.
|
|
6
|
+
|
|
7
|
+
For more information, please see our documentation for the [Jest plugin](https://taqueria.io/docs/plugins/plugin-jest/)
|
package/contractTestTemplate.ts
CHANGED
|
@@ -62,19 +62,18 @@ const generateTestSuite = (parsedArgs: Opts) => {
|
|
|
62
62
|
.then(() => jestSuiteAbspath);
|
|
63
63
|
};
|
|
64
64
|
|
|
65
|
-
const toJest = (contractName: string) =>
|
|
66
|
-
(
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
return `
|
|
65
|
+
const toJest = (contractName: string) => (generator: Generator) => {
|
|
66
|
+
const methodCalls = generator.methods.map(m => ({
|
|
67
|
+
name: m.name,
|
|
68
|
+
methodCall: generator.generateMethodCall({
|
|
69
|
+
methodName: m.name,
|
|
70
|
+
formatting: {
|
|
71
|
+
indent: 2,
|
|
72
|
+
},
|
|
73
|
+
}),
|
|
74
|
+
storageAccess: generator.generateStorageAccess({ storagePath: '' }),
|
|
75
|
+
}));
|
|
76
|
+
return `
|
|
78
77
|
import { TezosToolkit } from '@taquito/taquito';
|
|
79
78
|
import { char2Bytes } from '@taquito/utils';
|
|
80
79
|
import { tas } from './types/type-aliases';
|
|
@@ -97,7 +96,7 @@ describe('${contractName}', () => {
|
|
|
97
96
|
});
|
|
98
97
|
|
|
99
98
|
${
|
|
100
|
-
|
|
99
|
+
methodCalls.map(x => `
|
|
101
100
|
it('should call ${x.name}', async () => {
|
|
102
101
|
${x.storageAccess.getStorageValueFunctionCode}
|
|
103
102
|
const storageValueBefore = await ${x.storageAccess.getStorageValueFunctionName}();
|
|
@@ -107,9 +106,9 @@ ${
|
|
|
107
106
|
expect(storageValueAfter.toString()).toBe('');
|
|
108
107
|
});
|
|
109
108
|
`).join('')
|
|
110
|
-
|
|
109
|
+
}});
|
|
111
110
|
`;
|
|
112
|
-
|
|
111
|
+
};
|
|
113
112
|
|
|
114
113
|
export default (args: RequestArgs.t) => {
|
|
115
114
|
const parsedArgs = args as Opts;
|
package/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.ts","common.ts","contractTestTemplate.ts","proxy.ts"],"sourcesContent":["import { Option, Plugin, PositionalArg, Task, Template } from '@taqueria/node-sdk';\nimport { CustomRequestArgs, toRequestArgs } from './common';\nimport createContractTest from './contractTestTemplate';\nimport proxy from './proxy';\n\nPlugin.create<CustomRequestArgs>(requestArgs => ({\n\tschema: '0.1',\n\tversion: '0.4.0',\n\talias: 'jest',\n\ttasks: [\n\t\tTask.create({\n\t\t\ttask: 'test',\n\t\t\tcommand: 'test [partition]',\n\t\t\tdescription: 'Setup a directory as a partition to run Jest tests',\n\t\t\taliases: ['jest'],\n\t\t\thandler: 'proxy',\n\t\t\tpositionals: [\n\t\t\t\tPositionalArg.create({\n\t\t\t\t\tplaceholder: 'partition',\n\t\t\t\t\tdescription: 'Name of the partition for these tests',\n\t\t\t\t\tdefaultValue: 'tests',\n\t\t\t\t\ttype: 'string',\n\t\t\t\t}),\n\t\t\t],\n\t\t\toptions: [\n\t\t\t\tOption.create({\n\t\t\t\t\tflag: 'init',\n\t\t\t\t\tshortFlag: 'i',\n\t\t\t\t\tdescription: 'Initializes the partition for Jest',\n\t\t\t\t\tboolean: true,\n\t\t\t\t}),\n\t\t\t\tOption.create({\n\t\t\t\t\tflag: 'testPattern',\n\t\t\t\t\tshortFlag: 't',\n\t\t\t\t\tdescription: 'Run test files that match the provided pattern',\n\t\t\t\t}),\n\t\t\t],\n\t\t}),\n\t],\n\ttemplates: [\n\t\tTemplate.create({\n\t\t\ttemplate: 'contract-test',\n\t\t\tcommand: 'contract-test <michelsonArtifact>',\n\t\t\tpositionals: [\n\t\t\t\tPositionalArg.create({\n\t\t\t\t\tplaceholder: 'michelsonArtifact',\n\t\t\t\t\tdescription: 'Name of the michelson contract (artifact) to generate tests for',\n\t\t\t\t\trequired: true,\n\t\t\t\t\ttype: 'string',\n\t\t\t\t}),\n\t\t\t],\n\t\t\toptions: [\n\t\t\t\tOption.create({\n\t\t\t\t\tflag: 'partition',\n\t\t\t\t\tdescription: 'Partition to place generated test suite',\n\t\t\t\t\ttype: 'string',\n\t\t\t\t\tdefaultValue: toRequestArgs(requestArgs).config.jest.testsRootDir,\n\t\t\t\t}),\n\t\t\t],\n\t\t\tdescription: 'Generate integration test for a contract',\n\t\t\thandler: createContractTest,\n\t\t}),\n\t],\n\tproxy,\n}), process.argv);\n","import { noop, RequestArgs, sendAsyncErr, sendAsyncRes } from '@taqueria/node-sdk';\nimport { SanitizedAbsPath, SanitizedPath } from '@taqueria/node-sdk/types';\nimport { mkdir, stat, writeFile } from 'fs/promises';\nimport { defaults } from 'jest-config';\nimport { join, relative } from 'path';\nimport JestConfig from './config';\n\nexport type DefaultConfig = typeof defaults;\n\nexport interface CustomRequestArgs extends RequestArgs.t {\n\tconfig: JestConfig;\n\tpartition?: string;\n\tinit?: string;\n\ttestPattern?: string;\n}\n\nexport const toRequestArgs = (args: RequestArgs.t): CustomRequestArgs => {\n\tconst config = {\n\t\t...args.config,\n\t\tjest: {\n\t\t\ttestsRootDir: 'tests',\n\t\t},\n\t};\n\n\treturn {\n\t\t...args,\n\t\tconfig,\n\t};\n};\n\nexport const getDefaultConfig = (defaultConfig: DefaultConfig) => {\n\tconst settings = { ...defaults, preset: 'ts-jest', testEnvironment: 'node' };\n\treturn (\n\t\t`\nmodule.exports = ${JSON.stringify(settings, null, 4)}\n`\n\t);\n};\n\nexport const ensureRootConfigExists = (projectDir: SanitizedAbsPath.t) => {\n\tconst jestRootConfig = getRootConfigAbspath(projectDir);\n\treturn stat(jestRootConfig)\n\t\t.catch(_ => writeFile(jestRootConfig, getDefaultConfig(defaults)))\n\t\t.then(_ => jestRootConfig);\n};\n\nexport const getRootConfigAbspath = (projectDir: SanitizedAbsPath.t) =>\n\tSanitizedAbsPath.create(\n\t\tjoin(projectDir, '.taq', 'jest.config.js'),\n\t);\n\nexport const getTestsRootDir = (config: JestConfig) => {\n\treturn config.jest.testsRootDir;\n};\n\nexport const toPartitionCfg = (partitionRelpath: SanitizedPath.t, rootConfigRelPath: SanitizedPath.t) => `\nconst parentConfig = require('${rootConfigRelPath}')\n\nmodule.exports = {\n ...parentConfig,\n roots: [\n \"${partitionRelpath}\"\n ]\n}\n`;\n\nexport const getPartitionAbspath = (partitionDir: string) => SanitizedAbsPath.create(partitionDir);\n\nexport const getPartitionConfigAbspath = (partitionDir: string) =>\n\tSanitizedAbsPath.create(join(partitionDir, 'jest.config.js'));\n\nexport const initPartition = (partitionDir: SanitizedAbsPath.t, projectDir: SanitizedAbsPath.t) => {\n\treturn writeFile(\n\t\tgetPartitionConfigAbspath(partitionDir),\n\t\ttoPartitionCfg(\n\t\t\tSanitizedPath.create('./'),\n\t\t\tSanitizedPath.create(relative(partitionDir, getRootConfigAbspath(projectDir))),\n\t\t),\n\t);\n};\n\nexport const ensurePartitionExists = async (\n\tpartitionDir: SanitizedAbsPath.t,\n\tprojectDir: SanitizedAbsPath.t,\n\tforceCreate = false,\n) =>\n\tensureRootConfigExists(projectDir)\n\t\t.then(_ => stat(partitionDir))\n\t\t.then(stats =>\n\t\t\tstats.isFile()\n\t\t\t\t? sendAsyncErr(`${partitionDir} is an invalid partition directory`)\n\t\t\t\t: stats\n\t\t)\n\t\t.catch(_ => mkdir(partitionDir, { recursive: true }))\n\t\t.then(_ => getPartitionConfigAbspath(partitionDir))\n\t\t.then(partitionCfgAbsPath =>\n\t\t\tstat(partitionCfgAbsPath)\n\t\t\t\t.then(_ => forceCreate ? initPartition(partitionDir, projectDir) : undefined)\n\t\t\t\t.catch(_ => initPartition(partitionDir, projectDir))\n\t\t)\n\t\t.then(_ => getPartitionConfigAbspath(partitionDir));\n\nexport const ensureSelectedPartitionExists = (args: CustomRequestArgs, forceCreate = false) =>\n\targs.partition\n\t\t? ensurePartitionExists(\n\t\t\tSanitizedAbsPath.create(join(args.projectDir, args.partition)),\n\t\t\tSanitizedPath.create(args.projectDir),\n\t\t\tforceCreate,\n\t\t)\n\t\t: ensurePartitionExists(\n\t\t\tSanitizedAbsPath.create(\n\t\t\t\tjoin(args.projectDir, getTestsRootDir(args.config)),\n\t\t\t),\n\t\t\tSanitizedPath.create(args.projectDir),\n\t\t\tforceCreate,\n\t\t);\n","// import { normalizeContractName } from '@taqueria/plugin-contract-types/src/generator/contract-name';\nimport { RequestArgs, sendAsyncErr, sendAsyncRes } from '@taqueria/node-sdk';\nimport { generateContractTypesProcessContractFiles } from '@taqueria/plugin-contract-types/src/cli-process.js';\nimport {\n\tcreateTestingCodeGenerator,\n\tnormalizeContractName,\n} from '@taqueria/plugin-contract-types/src/generator/testing-code-generator.js';\nimport { readFile, stat, writeFile } from 'fs/promises';\nimport { basename, dirname, join } from 'path';\nimport { CustomRequestArgs, ensureSelectedPartitionExists, getPartitionAbspath, getTestsRootDir } from './common';\n\ntype Generator = ReturnType<typeof createTestingCodeGenerator>;\n\ninterface Opts extends CustomRequestArgs {\n\treadonly michelsonArtifact?: string;\n\treadonly partition?: string;\n\treadonly name?: string;\n}\n\nconst getMichelsonAbspath = (parsedArgs: Opts) =>\n\tjoin(parsedArgs.config.artifactsDir ?? 'artifacts', parsedArgs.michelsonArtifact!);\n\nconst ensureMichelsonExists = (parsedArgs: Opts) => {\n\tconst abspath = getMichelsonAbspath(parsedArgs);\n\treturn stat(abspath)\n\t\t.then(() => parsedArgs)\n\t\t.catch(() => Promise.reject(`${abspath} does not exist. Perhaps you need to run \"taq compile\"?`));\n};\n\nconst getPartition = (parsedArgs: Opts) => {\n\tconst partition = parsedArgs.partition ?? getTestsRootDir(parsedArgs.config);\n\treturn getPartitionAbspath(partition);\n};\n\nconst getTypesOutputAbspath = (parsedArgs: Opts) => join(getPartition(parsedArgs), 'types');\n\nconst generateContractTypes = (parsedArgs: Opts) =>\n\tgenerateContractTypesProcessContractFiles({\n\t\tinputTzContractDirectory: parsedArgs.config.artifactsDir ?? 'artifacts',\n\t\tinputFiles: [getMichelsonAbspath(parsedArgs)],\n\t\toutputTypescriptDirectory: getTypesOutputAbspath(parsedArgs),\n\t\tformat: 'tz',\n\t\ttypeAliasMode: 'file',\n\t}).then(_ => parsedArgs);\n\nconst getContractName = (parsedArgs: Opts) =>\n\tparsedArgs.name\n\t\t? parsedArgs.name.trim().replace(/\\.ts$/, '')\n\t\t: basename(parsedArgs.michelsonArtifact!, '.tz');\n\nconst generateTestSuite = (parsedArgs: Opts) => {\n\tconst michelsonAbspath = getMichelsonAbspath(parsedArgs);\n\tconst contractName = getContractName(parsedArgs);\n\tconst partition = getPartition(parsedArgs);\n\tconst jestSuiteAbspath = join(partition, `${contractName}.spec.ts`);\n\n\treturn readFile(michelsonAbspath, { encoding: 'utf-8' })\n\t\t.then(contractSource => ({ contractSource, contractFormat: 'tz' as const }))\n\t\t.then(createTestingCodeGenerator)\n\t\t.then(toJest(contractName))\n\t\t.then(contents => writeFile(jestSuiteAbspath, contents, { encoding: 'utf-8' }))\n\t\t.then(() => jestSuiteAbspath);\n};\n\nconst toJest = (contractName: string) =>\n\t(generator: Generator) => {\n\t\tconst methodCalls = generator.methods.map(m => ({\n\t\t\tname: m.name,\n\t\t\tmethodCall: generator.generateMethodCall({\n\t\t\t\tmethodName: m.name,\n\t\t\t\tformatting: {\n\t\t\t\t\tindent: 2,\n\t\t\t\t},\n\t\t\t}),\n\t\t\tstorageAccess: generator.generateStorageAccess({ storagePath: '' }),\n\t\t}));\n\t\treturn `\nimport { TezosToolkit } from '@taquito/taquito';\nimport { char2Bytes } from '@taquito/utils';\nimport { tas } from './types/type-aliases';\nimport { InMemorySigner, importKey } from '@taquito/signer';\nimport { ${normalizeContractName(contractName)}ContractType as ContractType } from './types/${contractName}.types';\nimport { ${normalizeContractName(contractName)}Code as ContractCode } from './types/${contractName}.code';\n\njest.setTimeout(20000)\n\ndescribe('${contractName}', () => {\n\tconst config = require('../.taq/config.json')\n const Tezos = new TezosToolkit(config.sandbox.local.rpcUrl);\n\tconst key = config.sandbox.local.accounts.bob.secretKey.replace('unencrypted:', '')\n\tTezos.setProvider({\n\t\tsigner: new InMemorySigner(key),\n\t });\n let contract: ContractType = undefined as unknown as ContractType;\n beforeAll(async () => {\n ${generator.generateOrigination({ formatting: { indent: 3 } }).code}\n });\n\n${\n\t\t\tmethodCalls.map(x => `\n it('should call ${x.name}', async () => {\n ${x.storageAccess.getStorageValueFunctionCode}\n const storageValueBefore = await ${x.storageAccess.getStorageValueFunctionName}();\n ${x.methodCall.code}\n const storageValueAfter = await ${x.storageAccess.getStorageValueFunctionName}();\n\n expect(storageValueAfter.toString()).toBe('');\n });\n`).join('')\n\t\t}});\n`;\n\t};\n\nexport default (args: RequestArgs.t) => {\n\tconst parsedArgs = args as Opts;\n\tparsedArgs.michelsonArtifact\n\t\t? ensureMichelsonExists(parsedArgs)\n\t\t\t.then(ensureSelectedPartitionExists)\n\t\t\t.then(() => parsedArgs)\n\t\t\t.then(generateContractTypes)\n\t\t\t.then(generateTestSuite)\n\t\t\t.then((outFile: string) => sendAsyncRes(`Test suite generated: ${outFile}`))\n\t\t\t.catch(sendAsyncErr)\n\t\t: sendAsyncErr(`No michelson artifact provided`);\n};\n","import { sendAsyncRes, sendErr } from '@taqueria/node-sdk';\nimport { RequestArgs } from '@taqueria/node-sdk';\nimport { execa } from 'execa';\nimport { CustomRequestArgs, ensureSelectedPartitionExists, toRequestArgs } from './common';\n\nconst execCmd = (cmd: string, args: string[]) => {\n\tconst child = execa(cmd, args, {\n\t\tshell: true,\n\t\treject: false,\n\t\tenv: { FORCE_COLOR: 'true' },\n\t});\n\n\tchild.stdout?.pipe(process.stdout);\n\tchild.stderr?.pipe(process.stderr);\n\n\treturn child;\n};\nexport default (args: RequestArgs.t) => {\n\tconst parsedArgs = toRequestArgs(args);\n\treturn ensureSelectedPartitionExists(parsedArgs, parsedArgs.init ? true : false)\n\t\t.then(configAbsPath => {\n\t\t\tif (!parsedArgs.init) {\n\t\t\t\tconst retval = parsedArgs.testPattern\n\t\t\t\t\t? execCmd('npx', ['jest', '-c', configAbsPath, '--testPathPattern', parsedArgs.testPattern])\n\t\t\t\t\t: execCmd('npx', ['jest', '-c', configAbsPath]);\n\t\t\t\treturn retval.then(child => {\n\t\t\t\t\tif (child.exitCode === 0) return;\n\t\t\t\t\telse process.exit(child.exitCode);\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treturn sendAsyncRes('Initialized successfully.');\n\t\t});\n};\n"],"mappings":";;;AAAA,IAAAA,mBAA8D;;;ACA9D,sBAA8D;AAC9D,mBAAgD;AAChD,sBAAuC;AACvC,yBAAyB;AACzB,kBAA+B;AAYxB,IAAM,gBAAgB,CAAC,SAA2C;AACxE,QAAM,SAAS;AAAA,IACd,GAAG,KAAK;AAAA,IACR,MAAM;AAAA,MACL,cAAc;AAAA,IACf;AAAA,EACD;AAEA,SAAO;AAAA,IACN,GAAG;AAAA,IACH;AAAA,EACD;AACD;AAEO,IAAM,mBAAmB,CAAC,kBAAiC;AACjE,QAAM,WAAW,EAAE,GAAG,6BAAU,QAAQ,WAAW,iBAAiB,OAAO;AAC3E,SACC;AAAA,mBACiB,KAAK,UAAU,UAAU,MAAM,CAAC,CAAC;AAAA;AAGpD;AAEO,IAAM,yBAAyB,CAAC,eAAmC;AACzE,QAAM,iBAAiB,qBAAqB,UAAU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,OAAO;AAAA,IACN,sBAAK,OAAO;AAAA,MACX,MAAM;AAAA,MACN,SAAS;AAAA,MACT,aAAa;AAAA,MACb,SAAS,CAAC,MAAM;AAAA,MAChB,SAAS;AAAA,MACT,aAAa;AAAA,QACZ,+BAAc,OAAO;AAAA,UACpB,aAAa;AAAA,UACb,aAAa;AAAA,UACb,cAAc;AAAA,UACd,MAAM;AAAA,QACP,CAAC;AAAA,MACF;AAAA,MACA,SAAS;AAAA,QACR,wBAAO,OAAO;AAAA,UACb,MAAM;AAAA,UACN,WAAW;AAAA,UACX,aAAa;AAAA,UACb,SAAS;AAAA,QACV,CAAC;AAAA,QACD,wBAAO,OAAO;AAAA,UACb,MAAM;AAAA,UACN,WAAW;AAAA,UACX,aAAa;AAAA,QACd,CAAC;AAAA,MACF;AAAA,IACD,CAAC;AAAA,EACF;AAAA,EACA,WAAW;AAAA,IACV,0BAAS,OAAO;AAAA,MACf,UAAU;AAAA,MACV,SAAS;AAAA,MACT,aAAa;AAAA,QACZ,+BAAc,OAAO;AAAA,UACpB,aAAa;AAAA,UACb,aAAa;AAAA,UACb,UAAU;AAAA,UACV,MAAM;AAAA,QACP,CAAC;AAAA,MACF;AAAA,MACA,SAAS;AAAA,QACR,wBAAO,OAAO;AAAA,UACb,MAAM;AAAA,UACN,aAAa;AAAA,UACb,MAAM;AAAA,UACN,cAAc,cAAc,WAAW,EAAE,OAAO,KAAK;AAAA,QACtD,CAAC;AAAA,MACF;AAAA,MACA,aAAa;AAAA,MACb,SAAS;AAAA,IACV,CAAC;AAAA,EACF;AAAA,EACA;AACD,IAAI,QAAQ,IAAI;","names":["import_node_sdk","import_node_sdk","import_promises","import_path","import_node_sdk"]}
|
|
1
|
+
{"version":3,"sources":["index.ts","common.ts","contractTestTemplate.ts","proxy.ts"],"sourcesContent":["import { Option, Plugin, PositionalArg, Task, Template } from '@taqueria/node-sdk';\nimport { CustomRequestArgs, toRequestArgs } from './common';\nimport createContractTest from './contractTestTemplate';\nimport proxy from './proxy';\n\nPlugin.create<CustomRequestArgs>(requestArgs => ({\n\tschema: '0.1',\n\tversion: '0.4.0',\n\talias: 'jest',\n\ttasks: [\n\t\tTask.create({\n\t\t\ttask: 'test',\n\t\t\tcommand: 'test [partition]',\n\t\t\tdescription: 'Setup a directory as a partition to run Jest tests',\n\t\t\taliases: ['jest'],\n\t\t\thandler: 'proxy',\n\t\t\tpositionals: [\n\t\t\t\tPositionalArg.create({\n\t\t\t\t\tplaceholder: 'partition',\n\t\t\t\t\tdescription: 'Name of the partition for these tests',\n\t\t\t\t\tdefaultValue: 'tests',\n\t\t\t\t\ttype: 'string',\n\t\t\t\t}),\n\t\t\t],\n\t\t\toptions: [\n\t\t\t\tOption.create({\n\t\t\t\t\tflag: 'init',\n\t\t\t\t\tshortFlag: 'i',\n\t\t\t\t\tdescription: 'Initializes the partition for Jest',\n\t\t\t\t\tboolean: true,\n\t\t\t\t}),\n\t\t\t\tOption.create({\n\t\t\t\t\tflag: 'testPattern',\n\t\t\t\t\tshortFlag: 't',\n\t\t\t\t\tdescription: 'Run test files that match the provided pattern',\n\t\t\t\t}),\n\t\t\t],\n\t\t}),\n\t],\n\ttemplates: [\n\t\tTemplate.create({\n\t\t\ttemplate: 'contract-test',\n\t\t\tcommand: 'contract-test <michelsonArtifact>',\n\t\t\tpositionals: [\n\t\t\t\tPositionalArg.create({\n\t\t\t\t\tplaceholder: 'michelsonArtifact',\n\t\t\t\t\tdescription: 'Name of the michelson contract (artifact) to generate tests for',\n\t\t\t\t\trequired: true,\n\t\t\t\t\ttype: 'string',\n\t\t\t\t}),\n\t\t\t],\n\t\t\toptions: [\n\t\t\t\tOption.create({\n\t\t\t\t\tflag: 'partition',\n\t\t\t\t\tdescription: 'Partition to place generated test suite',\n\t\t\t\t\ttype: 'string',\n\t\t\t\t\tdefaultValue: toRequestArgs(requestArgs).config.jest.testsRootDir,\n\t\t\t\t}),\n\t\t\t],\n\t\t\tdescription: 'Generate integration test for a contract',\n\t\t\thandler: createContractTest,\n\t\t}),\n\t],\n\tproxy,\n}), process.argv);\n","import { noop, RequestArgs, sendAsyncErr, sendAsyncRes } from '@taqueria/node-sdk';\nimport { SanitizedAbsPath, SanitizedPath } from '@taqueria/node-sdk/types';\nimport { mkdir, stat, writeFile } from 'fs/promises';\nimport { defaults } from 'jest-config';\nimport { join, relative } from 'path';\nimport JestConfig from './config';\n\nexport type DefaultConfig = typeof defaults;\n\nexport interface CustomRequestArgs extends RequestArgs.t {\n\tconfig: JestConfig;\n\tpartition?: string;\n\tinit?: string;\n\ttestPattern?: string;\n}\n\nexport const toRequestArgs = (args: RequestArgs.t): CustomRequestArgs => {\n\tconst config = {\n\t\t...args.config,\n\t\tjest: {\n\t\t\ttestsRootDir: 'tests',\n\t\t},\n\t};\n\n\treturn {\n\t\t...args,\n\t\tconfig,\n\t};\n};\n\nexport const getDefaultConfig = (defaultConfig: DefaultConfig) => {\n\tconst settings = { ...defaults, preset: 'ts-jest', testEnvironment: 'node' };\n\treturn (\n\t\t`\nmodule.exports = ${JSON.stringify(settings, null, 4)}\n`\n\t);\n};\n\nexport const ensureRootConfigExists = (projectDir: SanitizedAbsPath.t) => {\n\tconst jestRootConfig = getRootConfigAbspath(projectDir);\n\treturn stat(jestRootConfig)\n\t\t.catch(_ => writeFile(jestRootConfig, getDefaultConfig(defaults)))\n\t\t.then(_ => jestRootConfig);\n};\n\nexport const getRootConfigAbspath = (projectDir: SanitizedAbsPath.t) =>\n\tSanitizedAbsPath.create(\n\t\tjoin(projectDir, '.taq', 'jest.config.js'),\n\t);\n\nexport const getTestsRootDir = (config: JestConfig) => {\n\treturn config.jest.testsRootDir;\n};\n\nexport const toPartitionCfg = (partitionRelpath: SanitizedPath.t, rootConfigRelPath: SanitizedPath.t) => `\nconst parentConfig = require('${rootConfigRelPath}')\n\nmodule.exports = {\n ...parentConfig,\n roots: [\n \"${partitionRelpath}\"\n ]\n}\n`;\n\nexport const getPartitionAbspath = (partitionDir: string) => SanitizedAbsPath.create(partitionDir);\n\nexport const getPartitionConfigAbspath = (partitionDir: string) =>\n\tSanitizedAbsPath.create(join(partitionDir, 'jest.config.js'));\n\nexport const initPartition = (partitionDir: SanitizedAbsPath.t, projectDir: SanitizedAbsPath.t) => {\n\treturn writeFile(\n\t\tgetPartitionConfigAbspath(partitionDir),\n\t\ttoPartitionCfg(\n\t\t\tSanitizedPath.create('./'),\n\t\t\tSanitizedPath.create(relative(partitionDir, getRootConfigAbspath(projectDir))),\n\t\t),\n\t);\n};\n\nexport const ensurePartitionExists = async (\n\tpartitionDir: SanitizedAbsPath.t,\n\tprojectDir: SanitizedAbsPath.t,\n\tforceCreate = false,\n) =>\n\tensureRootConfigExists(projectDir)\n\t\t.then(_ => stat(partitionDir))\n\t\t.then(stats =>\n\t\t\tstats.isFile()\n\t\t\t\t? sendAsyncErr(`${partitionDir} is an invalid partition directory`)\n\t\t\t\t: stats\n\t\t)\n\t\t.catch(_ => mkdir(partitionDir, { recursive: true }))\n\t\t.then(_ => getPartitionConfigAbspath(partitionDir))\n\t\t.then(partitionCfgAbsPath =>\n\t\t\tstat(partitionCfgAbsPath)\n\t\t\t\t.then(_ => forceCreate ? initPartition(partitionDir, projectDir) : undefined)\n\t\t\t\t.catch(_ => initPartition(partitionDir, projectDir))\n\t\t)\n\t\t.then(_ => getPartitionConfigAbspath(partitionDir));\n\nexport const ensureSelectedPartitionExists = (args: CustomRequestArgs, forceCreate = false) =>\n\targs.partition\n\t\t? ensurePartitionExists(\n\t\t\tSanitizedAbsPath.create(join(args.projectDir, args.partition)),\n\t\t\tSanitizedPath.create(args.projectDir),\n\t\t\tforceCreate,\n\t\t)\n\t\t: ensurePartitionExists(\n\t\t\tSanitizedAbsPath.create(\n\t\t\t\tjoin(args.projectDir, getTestsRootDir(args.config)),\n\t\t\t),\n\t\t\tSanitizedPath.create(args.projectDir),\n\t\t\tforceCreate,\n\t\t);\n","// import { normalizeContractName } from '@taqueria/plugin-contract-types/src/generator/contract-name';\nimport { RequestArgs, sendAsyncErr, sendAsyncRes } from '@taqueria/node-sdk';\nimport { generateContractTypesProcessContractFiles } from '@taqueria/plugin-contract-types/src/cli-process.js';\nimport {\n\tcreateTestingCodeGenerator,\n\tnormalizeContractName,\n} from '@taqueria/plugin-contract-types/src/generator/testing-code-generator.js';\nimport { readFile, stat, writeFile } from 'fs/promises';\nimport { basename, dirname, join } from 'path';\nimport { CustomRequestArgs, ensureSelectedPartitionExists, getPartitionAbspath, getTestsRootDir } from './common';\n\ntype Generator = ReturnType<typeof createTestingCodeGenerator>;\n\ninterface Opts extends CustomRequestArgs {\n\treadonly michelsonArtifact?: string;\n\treadonly partition?: string;\n\treadonly name?: string;\n}\n\nconst getMichelsonAbspath = (parsedArgs: Opts) =>\n\tjoin(parsedArgs.config.artifactsDir ?? 'artifacts', parsedArgs.michelsonArtifact!);\n\nconst ensureMichelsonExists = (parsedArgs: Opts) => {\n\tconst abspath = getMichelsonAbspath(parsedArgs);\n\treturn stat(abspath)\n\t\t.then(() => parsedArgs)\n\t\t.catch(() => Promise.reject(`${abspath} does not exist. Perhaps you need to run \"taq compile\"?`));\n};\n\nconst getPartition = (parsedArgs: Opts) => {\n\tconst partition = parsedArgs.partition ?? getTestsRootDir(parsedArgs.config);\n\treturn getPartitionAbspath(partition);\n};\n\nconst getTypesOutputAbspath = (parsedArgs: Opts) => join(getPartition(parsedArgs), 'types');\n\nconst generateContractTypes = (parsedArgs: Opts) =>\n\tgenerateContractTypesProcessContractFiles({\n\t\tinputTzContractDirectory: parsedArgs.config.artifactsDir ?? 'artifacts',\n\t\tinputFiles: [getMichelsonAbspath(parsedArgs)],\n\t\toutputTypescriptDirectory: getTypesOutputAbspath(parsedArgs),\n\t\tformat: 'tz',\n\t\ttypeAliasMode: 'file',\n\t}).then(_ => parsedArgs);\n\nconst getContractName = (parsedArgs: Opts) =>\n\tparsedArgs.name\n\t\t? parsedArgs.name.trim().replace(/\\.ts$/, '')\n\t\t: basename(parsedArgs.michelsonArtifact!, '.tz');\n\nconst generateTestSuite = (parsedArgs: Opts) => {\n\tconst michelsonAbspath = getMichelsonAbspath(parsedArgs);\n\tconst contractName = getContractName(parsedArgs);\n\tconst partition = getPartition(parsedArgs);\n\tconst jestSuiteAbspath = join(partition, `${contractName}.spec.ts`);\n\n\treturn readFile(michelsonAbspath, { encoding: 'utf-8' })\n\t\t.then(contractSource => ({ contractSource, contractFormat: 'tz' as const }))\n\t\t.then(createTestingCodeGenerator)\n\t\t.then(toJest(contractName))\n\t\t.then(contents => writeFile(jestSuiteAbspath, contents, { encoding: 'utf-8' }))\n\t\t.then(() => jestSuiteAbspath);\n};\n\nconst toJest = (contractName: string) => (generator: Generator) => {\n\tconst methodCalls = generator.methods.map(m => ({\n\t\tname: m.name,\n\t\tmethodCall: generator.generateMethodCall({\n\t\t\tmethodName: m.name,\n\t\t\tformatting: {\n\t\t\t\tindent: 2,\n\t\t\t},\n\t\t}),\n\t\tstorageAccess: generator.generateStorageAccess({ storagePath: '' }),\n\t}));\n\treturn `\nimport { TezosToolkit } from '@taquito/taquito';\nimport { char2Bytes } from '@taquito/utils';\nimport { tas } from './types/type-aliases';\nimport { InMemorySigner, importKey } from '@taquito/signer';\nimport { ${normalizeContractName(contractName)}ContractType as ContractType } from './types/${contractName}.types';\nimport { ${normalizeContractName(contractName)}Code as ContractCode } from './types/${contractName}.code';\n\njest.setTimeout(20000)\n\ndescribe('${contractName}', () => {\n\tconst config = require('../.taq/config.json')\n const Tezos = new TezosToolkit(config.sandbox.local.rpcUrl);\n\tconst key = config.sandbox.local.accounts.bob.secretKey.replace('unencrypted:', '')\n\tTezos.setProvider({\n\t\tsigner: new InMemorySigner(key),\n\t });\n let contract: ContractType = undefined as unknown as ContractType;\n beforeAll(async () => {\n ${generator.generateOrigination({ formatting: { indent: 3 } }).code}\n });\n\n${\n\t\tmethodCalls.map(x => `\n it('should call ${x.name}', async () => {\n ${x.storageAccess.getStorageValueFunctionCode}\n const storageValueBefore = await ${x.storageAccess.getStorageValueFunctionName}();\n ${x.methodCall.code}\n const storageValueAfter = await ${x.storageAccess.getStorageValueFunctionName}();\n\n expect(storageValueAfter.toString()).toBe('');\n });\n`).join('')\n\t}});\n`;\n};\n\nexport default (args: RequestArgs.t) => {\n\tconst parsedArgs = args as Opts;\n\tparsedArgs.michelsonArtifact\n\t\t? ensureMichelsonExists(parsedArgs)\n\t\t\t.then(ensureSelectedPartitionExists)\n\t\t\t.then(() => parsedArgs)\n\t\t\t.then(generateContractTypes)\n\t\t\t.then(generateTestSuite)\n\t\t\t.then((outFile: string) => sendAsyncRes(`Test suite generated: ${outFile}`))\n\t\t\t.catch(sendAsyncErr)\n\t\t: sendAsyncErr(`No michelson artifact provided`);\n};\n","import { sendAsyncRes, sendErr } from '@taqueria/node-sdk';\nimport { RequestArgs } from '@taqueria/node-sdk';\nimport { execa } from 'execa';\nimport { CustomRequestArgs, ensureSelectedPartitionExists, toRequestArgs } from './common';\n\nconst execCmd = (cmd: string, args: string[]) => {\n\tconst child = execa(cmd, args, {\n\t\tshell: true,\n\t\treject: false,\n\t\tenv: { FORCE_COLOR: 'true' },\n\t});\n\n\tchild.stdout?.pipe(process.stdout);\n\tchild.stderr?.pipe(process.stderr);\n\n\treturn child;\n};\nexport default (args: RequestArgs.t) => {\n\tconst parsedArgs = toRequestArgs(args);\n\treturn ensureSelectedPartitionExists(parsedArgs, parsedArgs.init ? true : false)\n\t\t.then(configAbsPath => {\n\t\t\tif (!parsedArgs.init) {\n\t\t\t\tconst retval = parsedArgs.testPattern\n\t\t\t\t\t? execCmd('npx', ['jest', '-c', configAbsPath, '--testPathPattern', parsedArgs.testPattern])\n\t\t\t\t\t: execCmd('npx', ['jest', '-c', configAbsPath]);\n\t\t\t\treturn retval.then(child => {\n\t\t\t\t\tif (child.exitCode === 0) return;\n\t\t\t\t\telse process.exit(child.exitCode);\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treturn sendAsyncRes('Initialized successfully.');\n\t\t});\n};\n"],"mappings":";;;AAAA,IAAAA,mBAA8D;;;ACA9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MACF;AAAA,MACA,SAAS;AAAA,QACR,wBAAO,OAAO;AAAA,UACb,MAAM;AAAA,UACN,aAAa;AAAA,UACb,MAAM;AAAA,UACN,cAAc,cAAc,WAAW,EAAE,OAAO,KAAK;AAAA,QACtD,CAAC;AAAA,MACF;AAAA,MACA,aAAa;AAAA,MACb,SAAS;AAAA,IACV,CAAC;AAAA,EACF;AAAA,EACA;AACD,IAAI,QAAQ,IAAI;","names":["import_node_sdk","import_node_sdk","import_promises","import_path","import_node_sdk"]}
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.ts","common.ts","contractTestTemplate.ts","proxy.ts"],"sourcesContent":["import { Option, Plugin, PositionalArg, Task, Template } from '@taqueria/node-sdk';\nimport { CustomRequestArgs, toRequestArgs } from './common';\nimport createContractTest from './contractTestTemplate';\nimport proxy from './proxy';\n\nPlugin.create<CustomRequestArgs>(requestArgs => ({\n\tschema: '0.1',\n\tversion: '0.4.0',\n\talias: 'jest',\n\ttasks: [\n\t\tTask.create({\n\t\t\ttask: 'test',\n\t\t\tcommand: 'test [partition]',\n\t\t\tdescription: 'Setup a directory as a partition to run Jest tests',\n\t\t\taliases: ['jest'],\n\t\t\thandler: 'proxy',\n\t\t\tpositionals: [\n\t\t\t\tPositionalArg.create({\n\t\t\t\t\tplaceholder: 'partition',\n\t\t\t\t\tdescription: 'Name of the partition for these tests',\n\t\t\t\t\tdefaultValue: 'tests',\n\t\t\t\t\ttype: 'string',\n\t\t\t\t}),\n\t\t\t],\n\t\t\toptions: [\n\t\t\t\tOption.create({\n\t\t\t\t\tflag: 'init',\n\t\t\t\t\tshortFlag: 'i',\n\t\t\t\t\tdescription: 'Initializes the partition for Jest',\n\t\t\t\t\tboolean: true,\n\t\t\t\t}),\n\t\t\t\tOption.create({\n\t\t\t\t\tflag: 'testPattern',\n\t\t\t\t\tshortFlag: 't',\n\t\t\t\t\tdescription: 'Run test files that match the provided pattern',\n\t\t\t\t}),\n\t\t\t],\n\t\t}),\n\t],\n\ttemplates: [\n\t\tTemplate.create({\n\t\t\ttemplate: 'contract-test',\n\t\t\tcommand: 'contract-test <michelsonArtifact>',\n\t\t\tpositionals: [\n\t\t\t\tPositionalArg.create({\n\t\t\t\t\tplaceholder: 'michelsonArtifact',\n\t\t\t\t\tdescription: 'Name of the michelson contract (artifact) to generate tests for',\n\t\t\t\t\trequired: true,\n\t\t\t\t\ttype: 'string',\n\t\t\t\t}),\n\t\t\t],\n\t\t\toptions: [\n\t\t\t\tOption.create({\n\t\t\t\t\tflag: 'partition',\n\t\t\t\t\tdescription: 'Partition to place generated test suite',\n\t\t\t\t\ttype: 'string',\n\t\t\t\t\tdefaultValue: toRequestArgs(requestArgs).config.jest.testsRootDir,\n\t\t\t\t}),\n\t\t\t],\n\t\t\tdescription: 'Generate integration test for a contract',\n\t\t\thandler: createContractTest,\n\t\t}),\n\t],\n\tproxy,\n}), process.argv);\n","import { noop, RequestArgs, sendAsyncErr, sendAsyncRes } from '@taqueria/node-sdk';\nimport { SanitizedAbsPath, SanitizedPath } from '@taqueria/node-sdk/types';\nimport { mkdir, stat, writeFile } from 'fs/promises';\nimport { defaults } from 'jest-config';\nimport { join, relative } from 'path';\nimport JestConfig from './config';\n\nexport type DefaultConfig = typeof defaults;\n\nexport interface CustomRequestArgs extends RequestArgs.t {\n\tconfig: JestConfig;\n\tpartition?: string;\n\tinit?: string;\n\ttestPattern?: string;\n}\n\nexport const toRequestArgs = (args: RequestArgs.t): CustomRequestArgs => {\n\tconst config = {\n\t\t...args.config,\n\t\tjest: {\n\t\t\ttestsRootDir: 'tests',\n\t\t},\n\t};\n\n\treturn {\n\t\t...args,\n\t\tconfig,\n\t};\n};\n\nexport const getDefaultConfig = (defaultConfig: DefaultConfig) => {\n\tconst settings = { ...defaults, preset: 'ts-jest', testEnvironment: 'node' };\n\treturn (\n\t\t`\nmodule.exports = ${JSON.stringify(settings, null, 4)}\n`\n\t);\n};\n\nexport const ensureRootConfigExists = (projectDir: SanitizedAbsPath.t) => {\n\tconst jestRootConfig = getRootConfigAbspath(projectDir);\n\treturn stat(jestRootConfig)\n\t\t.catch(_ => writeFile(jestRootConfig, getDefaultConfig(defaults)))\n\t\t.then(_ => jestRootConfig);\n};\n\nexport const getRootConfigAbspath = (projectDir: SanitizedAbsPath.t) =>\n\tSanitizedAbsPath.create(\n\t\tjoin(projectDir, '.taq', 'jest.config.js'),\n\t);\n\nexport const getTestsRootDir = (config: JestConfig) => {\n\treturn config.jest.testsRootDir;\n};\n\nexport const toPartitionCfg = (partitionRelpath: SanitizedPath.t, rootConfigRelPath: SanitizedPath.t) => `\nconst parentConfig = require('${rootConfigRelPath}')\n\nmodule.exports = {\n ...parentConfig,\n roots: [\n \"${partitionRelpath}\"\n ]\n}\n`;\n\nexport const getPartitionAbspath = (partitionDir: string) => SanitizedAbsPath.create(partitionDir);\n\nexport const getPartitionConfigAbspath = (partitionDir: string) =>\n\tSanitizedAbsPath.create(join(partitionDir, 'jest.config.js'));\n\nexport const initPartition = (partitionDir: SanitizedAbsPath.t, projectDir: SanitizedAbsPath.t) => {\n\treturn writeFile(\n\t\tgetPartitionConfigAbspath(partitionDir),\n\t\ttoPartitionCfg(\n\t\t\tSanitizedPath.create('./'),\n\t\t\tSanitizedPath.create(relative(partitionDir, getRootConfigAbspath(projectDir))),\n\t\t),\n\t);\n};\n\nexport const ensurePartitionExists = async (\n\tpartitionDir: SanitizedAbsPath.t,\n\tprojectDir: SanitizedAbsPath.t,\n\tforceCreate = false,\n) =>\n\tensureRootConfigExists(projectDir)\n\t\t.then(_ => stat(partitionDir))\n\t\t.then(stats =>\n\t\t\tstats.isFile()\n\t\t\t\t? sendAsyncErr(`${partitionDir} is an invalid partition directory`)\n\t\t\t\t: stats\n\t\t)\n\t\t.catch(_ => mkdir(partitionDir, { recursive: true }))\n\t\t.then(_ => getPartitionConfigAbspath(partitionDir))\n\t\t.then(partitionCfgAbsPath =>\n\t\t\tstat(partitionCfgAbsPath)\n\t\t\t\t.then(_ => forceCreate ? initPartition(partitionDir, projectDir) : undefined)\n\t\t\t\t.catch(_ => initPartition(partitionDir, projectDir))\n\t\t)\n\t\t.then(_ => getPartitionConfigAbspath(partitionDir));\n\nexport const ensureSelectedPartitionExists = (args: CustomRequestArgs, forceCreate = false) =>\n\targs.partition\n\t\t? ensurePartitionExists(\n\t\t\tSanitizedAbsPath.create(join(args.projectDir, args.partition)),\n\t\t\tSanitizedPath.create(args.projectDir),\n\t\t\tforceCreate,\n\t\t)\n\t\t: ensurePartitionExists(\n\t\t\tSanitizedAbsPath.create(\n\t\t\t\tjoin(args.projectDir, getTestsRootDir(args.config)),\n\t\t\t),\n\t\t\tSanitizedPath.create(args.projectDir),\n\t\t\tforceCreate,\n\t\t);\n","// import { normalizeContractName } from '@taqueria/plugin-contract-types/src/generator/contract-name';\nimport { RequestArgs, sendAsyncErr, sendAsyncRes } from '@taqueria/node-sdk';\nimport { generateContractTypesProcessContractFiles } from '@taqueria/plugin-contract-types/src/cli-process.js';\nimport {\n\tcreateTestingCodeGenerator,\n\tnormalizeContractName,\n} from '@taqueria/plugin-contract-types/src/generator/testing-code-generator.js';\nimport { readFile, stat, writeFile } from 'fs/promises';\nimport { basename, dirname, join } from 'path';\nimport { CustomRequestArgs, ensureSelectedPartitionExists, getPartitionAbspath, getTestsRootDir } from './common';\n\ntype Generator = ReturnType<typeof createTestingCodeGenerator>;\n\ninterface Opts extends CustomRequestArgs {\n\treadonly michelsonArtifact?: string;\n\treadonly partition?: string;\n\treadonly name?: string;\n}\n\nconst getMichelsonAbspath = (parsedArgs: Opts) =>\n\tjoin(parsedArgs.config.artifactsDir ?? 'artifacts', parsedArgs.michelsonArtifact!);\n\nconst ensureMichelsonExists = (parsedArgs: Opts) => {\n\tconst abspath = getMichelsonAbspath(parsedArgs);\n\treturn stat(abspath)\n\t\t.then(() => parsedArgs)\n\t\t.catch(() => Promise.reject(`${abspath} does not exist. Perhaps you need to run \"taq compile\"?`));\n};\n\nconst getPartition = (parsedArgs: Opts) => {\n\tconst partition = parsedArgs.partition ?? getTestsRootDir(parsedArgs.config);\n\treturn getPartitionAbspath(partition);\n};\n\nconst getTypesOutputAbspath = (parsedArgs: Opts) => join(getPartition(parsedArgs), 'types');\n\nconst generateContractTypes = (parsedArgs: Opts) =>\n\tgenerateContractTypesProcessContractFiles({\n\t\tinputTzContractDirectory: parsedArgs.config.artifactsDir ?? 'artifacts',\n\t\tinputFiles: [getMichelsonAbspath(parsedArgs)],\n\t\toutputTypescriptDirectory: getTypesOutputAbspath(parsedArgs),\n\t\tformat: 'tz',\n\t\ttypeAliasMode: 'file',\n\t}).then(_ => parsedArgs);\n\nconst getContractName = (parsedArgs: Opts) =>\n\tparsedArgs.name\n\t\t? parsedArgs.name.trim().replace(/\\.ts$/, '')\n\t\t: basename(parsedArgs.michelsonArtifact!, '.tz');\n\nconst generateTestSuite = (parsedArgs: Opts) => {\n\tconst michelsonAbspath = getMichelsonAbspath(parsedArgs);\n\tconst contractName = getContractName(parsedArgs);\n\tconst partition = getPartition(parsedArgs);\n\tconst jestSuiteAbspath = join(partition, `${contractName}.spec.ts`);\n\n\treturn readFile(michelsonAbspath, { encoding: 'utf-8' })\n\t\t.then(contractSource => ({ contractSource, contractFormat: 'tz' as const }))\n\t\t.then(createTestingCodeGenerator)\n\t\t.then(toJest(contractName))\n\t\t.then(contents => writeFile(jestSuiteAbspath, contents, { encoding: 'utf-8' }))\n\t\t.then(() => jestSuiteAbspath);\n};\n\nconst toJest = (contractName: string) =>\n\t(generator: Generator) => {\n\t\tconst methodCalls = generator.methods.map(m => ({\n\t\t\tname: m.name,\n\t\t\tmethodCall: generator.generateMethodCall({\n\t\t\t\tmethodName: m.name,\n\t\t\t\tformatting: {\n\t\t\t\t\tindent: 2,\n\t\t\t\t},\n\t\t\t}),\n\t\t\tstorageAccess: generator.generateStorageAccess({ storagePath: '' }),\n\t\t}));\n\t\treturn `\nimport { TezosToolkit } from '@taquito/taquito';\nimport { char2Bytes } from '@taquito/utils';\nimport { tas } from './types/type-aliases';\nimport { InMemorySigner, importKey } from '@taquito/signer';\nimport { ${normalizeContractName(contractName)}ContractType as ContractType } from './types/${contractName}.types';\nimport { ${normalizeContractName(contractName)}Code as ContractCode } from './types/${contractName}.code';\n\njest.setTimeout(20000)\n\ndescribe('${contractName}', () => {\n\tconst config = require('../.taq/config.json')\n const Tezos = new TezosToolkit(config.sandbox.local.rpcUrl);\n\tconst key = config.sandbox.local.accounts.bob.secretKey.replace('unencrypted:', '')\n\tTezos.setProvider({\n\t\tsigner: new InMemorySigner(key),\n\t });\n let contract: ContractType = undefined as unknown as ContractType;\n beforeAll(async () => {\n ${generator.generateOrigination({ formatting: { indent: 3 } }).code}\n });\n\n${\n\t\t\tmethodCalls.map(x => `\n it('should call ${x.name}', async () => {\n ${x.storageAccess.getStorageValueFunctionCode}\n const storageValueBefore = await ${x.storageAccess.getStorageValueFunctionName}();\n ${x.methodCall.code}\n const storageValueAfter = await ${x.storageAccess.getStorageValueFunctionName}();\n\n expect(storageValueAfter.toString()).toBe('');\n });\n`).join('')\n\t\t}});\n`;\n\t};\n\nexport default (args: RequestArgs.t) => {\n\tconst parsedArgs = args as Opts;\n\tparsedArgs.michelsonArtifact\n\t\t? ensureMichelsonExists(parsedArgs)\n\t\t\t.then(ensureSelectedPartitionExists)\n\t\t\t.then(() => parsedArgs)\n\t\t\t.then(generateContractTypes)\n\t\t\t.then(generateTestSuite)\n\t\t\t.then((outFile: string) => sendAsyncRes(`Test suite generated: ${outFile}`))\n\t\t\t.catch(sendAsyncErr)\n\t\t: sendAsyncErr(`No michelson artifact provided`);\n};\n","import { sendAsyncRes, sendErr } from '@taqueria/node-sdk';\nimport { RequestArgs } from '@taqueria/node-sdk';\nimport { execa } from 'execa';\nimport { CustomRequestArgs, ensureSelectedPartitionExists, toRequestArgs } from './common';\n\nconst execCmd = (cmd: string, args: string[]) => {\n\tconst child = execa(cmd, args, {\n\t\tshell: true,\n\t\treject: false,\n\t\tenv: { FORCE_COLOR: 'true' },\n\t});\n\n\tchild.stdout?.pipe(process.stdout);\n\tchild.stderr?.pipe(process.stderr);\n\n\treturn child;\n};\nexport default (args: RequestArgs.t) => {\n\tconst parsedArgs = toRequestArgs(args);\n\treturn ensureSelectedPartitionExists(parsedArgs, parsedArgs.init ? true : false)\n\t\t.then(configAbsPath => {\n\t\t\tif (!parsedArgs.init) {\n\t\t\t\tconst retval = parsedArgs.testPattern\n\t\t\t\t\t? execCmd('npx', ['jest', '-c', configAbsPath, '--testPathPattern', parsedArgs.testPattern])\n\t\t\t\t\t: execCmd('npx', ['jest', '-c', configAbsPath]);\n\t\t\t\treturn retval.then(child => {\n\t\t\t\t\tif (child.exitCode === 0) return;\n\t\t\t\t\telse process.exit(child.exitCode);\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treturn sendAsyncRes('Initialized successfully.');\n\t\t});\n};\n"],"mappings":";AAAA,SAAS,QAAQ,QAAQ,eAAe,MAAM,gBAAgB;;;ACA9D,SAA4B,oBAAkC;AAC9D,SAAS,kBAAkB,qBAAqB;AAChD,SAAS,OAAO,MAAM,iBAAiB;AACvC,SAAS,gBAAgB;AACzB,SAAS,MAAM,gBAAgB;AAYxB,IAAM,gBAAgB,CAAC,SAA2C;AACxE,QAAM,SAAS;AAAA,IACd,GAAG,KAAK;AAAA,IACR,MAAM;AAAA,MACL,cAAc;AAAA,IACf;AAAA,EACD;AAEA,SAAO;AAAA,IACN,GAAG;AAAA,IACH;AAAA,EACD;AACD;AAEO,IAAM,mBAAmB,CAAC,kBAAiC;AACjE,QAAM,WAAW,EAAE,GAAG,UAAU,QAAQ,WAAW,iBAAiB,OAAO;AAC3E,SACC;AAAA,mBACiB,KAAK,UAAU,UAAU,MAAM,CAAC,CAAC;AAAA;AAGpD;AAEO,IAAM,yBAAyB,CAAC,eAAmC;AACzE,QAAM,iBAAiB,qBAAqB,UAAU;AACtD,SAAO,KAAK,cAAc,EACxB,MAAM,OAAK,UAAU,gBAAgB,iBAAiB,QAAQ,C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AAO;AAAA,IACN,KAAK,OAAO;AAAA,MACX,MAAM;AAAA,MACN,SAAS;AAAA,MACT,aAAa;AAAA,MACb,SAAS,CAAC,MAAM;AAAA,MAChB,SAAS;AAAA,MACT,aAAa;AAAA,QACZ,cAAc,OAAO;AAAA,UACpB,aAAa;AAAA,UACb,aAAa;AAAA,UACb,cAAc;AAAA,UACd,MAAM;AAAA,QACP,CAAC;AAAA,MACF;AAAA,MACA,SAAS;AAAA,QACR,OAAO,OAAO;AAAA,UACb,MAAM;AAAA,UACN,WAAW;AAAA,UACX,aAAa;AAAA,UACb,SAAS;AAAA,QACV,CAAC;AAAA,QACD,OAAO,OAAO;AAAA,UACb,MAAM;AAAA,UACN,WAAW;AAAA,UACX,aAAa;AAAA,QACd,CAAC;AAAA,MACF;AAAA,IACD,CAAC;AAAA,EACF;AAAA,EACA,WAAW;AAAA,IACV,SAAS,OAAO;AAAA,MACf,UAAU;AAAA,MACV,SAAS;AAAA,MACT,aAAa;AAAA,QACZ,cAAc,OAAO;AAAA,UACpB,aAAa;AAAA,UACb,aAAa;AAAA,UACb,UAAU;AAAA,UACV,MAAM;AAAA,QACP,CAAC;AAAA,MACF;AAAA,MACA,SAAS;AAAA,QACR,OAAO,OAAO;AAAA,UACb,MAAM;AAAA,UACN,aAAa;AAAA,UACb,MAAM;AAAA,UACN,cAAc,cAAc,WAAW,EAAE,OAAO,KAAK;AAAA,QACtD,CAAC;AAAA,MACF;AAAA,MACA,aAAa;AAAA,MACb,SAAS;AAAA,IACV,CAAC;AAAA,EACF;AAAA,EACA;AACD,IAAI,QAAQ,IAAI;","names":["sendAsyncErr","sendAsyncRes","stat","writeFile","join","join","stat","writeFile","sendAsyncRes","sendAsyncErr","sendAsyncRes","sendAsyncRes"]}
|
|
1
|
+
{"version":3,"sources":["index.ts","common.ts","contractTestTemplate.ts","proxy.ts"],"sourcesContent":["import { Option, Plugin, PositionalArg, Task, Template } from '@taqueria/node-sdk';\nimport { CustomRequestArgs, toRequestArgs } from './common';\nimport createContractTest from './contractTestTemplate';\nimport proxy from './proxy';\n\nPlugin.create<CustomRequestArgs>(requestArgs => ({\n\tschema: '0.1',\n\tversion: '0.4.0',\n\talias: 'jest',\n\ttasks: [\n\t\tTask.create({\n\t\t\ttask: 'test',\n\t\t\tcommand: 'test [partition]',\n\t\t\tdescription: 'Setup a directory as a partition to run Jest tests',\n\t\t\taliases: ['jest'],\n\t\t\thandler: 'proxy',\n\t\t\tpositionals: [\n\t\t\t\tPositionalArg.create({\n\t\t\t\t\tplaceholder: 'partition',\n\t\t\t\t\tdescription: 'Name of the partition for these tests',\n\t\t\t\t\tdefaultValue: 'tests',\n\t\t\t\t\ttype: 'string',\n\t\t\t\t}),\n\t\t\t],\n\t\t\toptions: [\n\t\t\t\tOption.create({\n\t\t\t\t\tflag: 'init',\n\t\t\t\t\tshortFlag: 'i',\n\t\t\t\t\tdescription: 'Initializes the partition for Jest',\n\t\t\t\t\tboolean: true,\n\t\t\t\t}),\n\t\t\t\tOption.create({\n\t\t\t\t\tflag: 'testPattern',\n\t\t\t\t\tshortFlag: 't',\n\t\t\t\t\tdescription: 'Run test files that match the provided pattern',\n\t\t\t\t}),\n\t\t\t],\n\t\t}),\n\t],\n\ttemplates: [\n\t\tTemplate.create({\n\t\t\ttemplate: 'contract-test',\n\t\t\tcommand: 'contract-test <michelsonArtifact>',\n\t\t\tpositionals: [\n\t\t\t\tPositionalArg.create({\n\t\t\t\t\tplaceholder: 'michelsonArtifact',\n\t\t\t\t\tdescription: 'Name of the michelson contract (artifact) to generate tests for',\n\t\t\t\t\trequired: true,\n\t\t\t\t\ttype: 'string',\n\t\t\t\t}),\n\t\t\t],\n\t\t\toptions: [\n\t\t\t\tOption.create({\n\t\t\t\t\tflag: 'partition',\n\t\t\t\t\tdescription: 'Partition to place generated test suite',\n\t\t\t\t\ttype: 'string',\n\t\t\t\t\tdefaultValue: toRequestArgs(requestArgs).config.jest.testsRootDir,\n\t\t\t\t}),\n\t\t\t],\n\t\t\tdescription: 'Generate integration test for a contract',\n\t\t\thandler: createContractTest,\n\t\t}),\n\t],\n\tproxy,\n}), process.argv);\n","import { noop, RequestArgs, sendAsyncErr, sendAsyncRes } from '@taqueria/node-sdk';\nimport { SanitizedAbsPath, SanitizedPath } from '@taqueria/node-sdk/types';\nimport { mkdir, stat, writeFile } from 'fs/promises';\nimport { defaults } from 'jest-config';\nimport { join, relative } from 'path';\nimport JestConfig from './config';\n\nexport type DefaultConfig = typeof defaults;\n\nexport interface CustomRequestArgs extends RequestArgs.t {\n\tconfig: JestConfig;\n\tpartition?: string;\n\tinit?: string;\n\ttestPattern?: string;\n}\n\nexport const toRequestArgs = (args: RequestArgs.t): CustomRequestArgs => {\n\tconst config = {\n\t\t...args.config,\n\t\tjest: {\n\t\t\ttestsRootDir: 'tests',\n\t\t},\n\t};\n\n\treturn {\n\t\t...args,\n\t\tconfig,\n\t};\n};\n\nexport const getDefaultConfig = (defaultConfig: DefaultConfig) => {\n\tconst settings = { ...defaults, preset: 'ts-jest', testEnvironment: 'node' };\n\treturn (\n\t\t`\nmodule.exports = ${JSON.stringify(settings, null, 4)}\n`\n\t);\n};\n\nexport const ensureRootConfigExists = (projectDir: SanitizedAbsPath.t) => {\n\tconst jestRootConfig = getRootConfigAbspath(projectDir);\n\treturn stat(jestRootConfig)\n\t\t.catch(_ => writeFile(jestRootConfig, getDefaultConfig(defaults)))\n\t\t.then(_ => jestRootConfig);\n};\n\nexport const getRootConfigAbspath = (projectDir: SanitizedAbsPath.t) =>\n\tSanitizedAbsPath.create(\n\t\tjoin(projectDir, '.taq', 'jest.config.js'),\n\t);\n\nexport const getTestsRootDir = (config: JestConfig) => {\n\treturn config.jest.testsRootDir;\n};\n\nexport const toPartitionCfg = (partitionRelpath: SanitizedPath.t, rootConfigRelPath: SanitizedPath.t) => `\nconst parentConfig = require('${rootConfigRelPath}')\n\nmodule.exports = {\n ...parentConfig,\n roots: [\n \"${partitionRelpath}\"\n ]\n}\n`;\n\nexport const getPartitionAbspath = (partitionDir: string) => SanitizedAbsPath.create(partitionDir);\n\nexport const getPartitionConfigAbspath = (partitionDir: string) =>\n\tSanitizedAbsPath.create(join(partitionDir, 'jest.config.js'));\n\nexport const initPartition = (partitionDir: SanitizedAbsPath.t, projectDir: SanitizedAbsPath.t) => {\n\treturn writeFile(\n\t\tgetPartitionConfigAbspath(partitionDir),\n\t\ttoPartitionCfg(\n\t\t\tSanitizedPath.create('./'),\n\t\t\tSanitizedPath.create(relative(partitionDir, getRootConfigAbspath(projectDir))),\n\t\t),\n\t);\n};\n\nexport const ensurePartitionExists = async (\n\tpartitionDir: SanitizedAbsPath.t,\n\tprojectDir: SanitizedAbsPath.t,\n\tforceCreate = false,\n) =>\n\tensureRootConfigExists(projectDir)\n\t\t.then(_ => stat(partitionDir))\n\t\t.then(stats =>\n\t\t\tstats.isFile()\n\t\t\t\t? sendAsyncErr(`${partitionDir} is an invalid partition directory`)\n\t\t\t\t: stats\n\t\t)\n\t\t.catch(_ => mkdir(partitionDir, { recursive: true }))\n\t\t.then(_ => getPartitionConfigAbspath(partitionDir))\n\t\t.then(partitionCfgAbsPath =>\n\t\t\tstat(partitionCfgAbsPath)\n\t\t\t\t.then(_ => forceCreate ? initPartition(partitionDir, projectDir) : undefined)\n\t\t\t\t.catch(_ => initPartition(partitionDir, projectDir))\n\t\t)\n\t\t.then(_ => getPartitionConfigAbspath(partitionDir));\n\nexport const ensureSelectedPartitionExists = (args: CustomRequestArgs, forceCreate = false) =>\n\targs.partition\n\t\t? ensurePartitionExists(\n\t\t\tSanitizedAbsPath.create(join(args.projectDir, args.partition)),\n\t\t\tSanitizedPath.create(args.projectDir),\n\t\t\tforceCreate,\n\t\t)\n\t\t: ensurePartitionExists(\n\t\t\tSanitizedAbsPath.create(\n\t\t\t\tjoin(args.projectDir, getTestsRootDir(args.config)),\n\t\t\t),\n\t\t\tSanitizedPath.create(args.projectDir),\n\t\t\tforceCreate,\n\t\t);\n","// import { normalizeContractName } from '@taqueria/plugin-contract-types/src/generator/contract-name';\nimport { RequestArgs, sendAsyncErr, sendAsyncRes } from '@taqueria/node-sdk';\nimport { generateContractTypesProcessContractFiles } from '@taqueria/plugin-contract-types/src/cli-process.js';\nimport {\n\tcreateTestingCodeGenerator,\n\tnormalizeContractName,\n} from '@taqueria/plugin-contract-types/src/generator/testing-code-generator.js';\nimport { readFile, stat, writeFile } from 'fs/promises';\nimport { basename, dirname, join } from 'path';\nimport { CustomRequestArgs, ensureSelectedPartitionExists, getPartitionAbspath, getTestsRootDir } from './common';\n\ntype Generator = ReturnType<typeof createTestingCodeGenerator>;\n\ninterface Opts extends CustomRequestArgs {\n\treadonly michelsonArtifact?: string;\n\treadonly partition?: string;\n\treadonly name?: string;\n}\n\nconst getMichelsonAbspath = (parsedArgs: Opts) =>\n\tjoin(parsedArgs.config.artifactsDir ?? 'artifacts', parsedArgs.michelsonArtifact!);\n\nconst ensureMichelsonExists = (parsedArgs: Opts) => {\n\tconst abspath = getMichelsonAbspath(parsedArgs);\n\treturn stat(abspath)\n\t\t.then(() => parsedArgs)\n\t\t.catch(() => Promise.reject(`${abspath} does not exist. Perhaps you need to run \"taq compile\"?`));\n};\n\nconst getPartition = (parsedArgs: Opts) => {\n\tconst partition = parsedArgs.partition ?? getTestsRootDir(parsedArgs.config);\n\treturn getPartitionAbspath(partition);\n};\n\nconst getTypesOutputAbspath = (parsedArgs: Opts) => join(getPartition(parsedArgs), 'types');\n\nconst generateContractTypes = (parsedArgs: Opts) =>\n\tgenerateContractTypesProcessContractFiles({\n\t\tinputTzContractDirectory: parsedArgs.config.artifactsDir ?? 'artifacts',\n\t\tinputFiles: [getMichelsonAbspath(parsedArgs)],\n\t\toutputTypescriptDirectory: getTypesOutputAbspath(parsedArgs),\n\t\tformat: 'tz',\n\t\ttypeAliasMode: 'file',\n\t}).then(_ => parsedArgs);\n\nconst getContractName = (parsedArgs: Opts) =>\n\tparsedArgs.name\n\t\t? parsedArgs.name.trim().replace(/\\.ts$/, '')\n\t\t: basename(parsedArgs.michelsonArtifact!, '.tz');\n\nconst generateTestSuite = (parsedArgs: Opts) => {\n\tconst michelsonAbspath = getMichelsonAbspath(parsedArgs);\n\tconst contractName = getContractName(parsedArgs);\n\tconst partition = getPartition(parsedArgs);\n\tconst jestSuiteAbspath = join(partition, `${contractName}.spec.ts`);\n\n\treturn readFile(michelsonAbspath, { encoding: 'utf-8' })\n\t\t.then(contractSource => ({ contractSource, contractFormat: 'tz' as const }))\n\t\t.then(createTestingCodeGenerator)\n\t\t.then(toJest(contractName))\n\t\t.then(contents => writeFile(jestSuiteAbspath, contents, { encoding: 'utf-8' }))\n\t\t.then(() => jestSuiteAbspath);\n};\n\nconst toJest = (contractName: string) => (generator: Generator) => {\n\tconst methodCalls = generator.methods.map(m => ({\n\t\tname: m.name,\n\t\tmethodCall: generator.generateMethodCall({\n\t\t\tmethodName: m.name,\n\t\t\tformatting: {\n\t\t\t\tindent: 2,\n\t\t\t},\n\t\t}),\n\t\tstorageAccess: generator.generateStorageAccess({ storagePath: '' }),\n\t}));\n\treturn `\nimport { TezosToolkit } from '@taquito/taquito';\nimport { char2Bytes } from '@taquito/utils';\nimport { tas } from './types/type-aliases';\nimport { InMemorySigner, importKey } from '@taquito/signer';\nimport { ${normalizeContractName(contractName)}ContractType as ContractType } from './types/${contractName}.types';\nimport { ${normalizeContractName(contractName)}Code as ContractCode } from './types/${contractName}.code';\n\njest.setTimeout(20000)\n\ndescribe('${contractName}', () => {\n\tconst config = require('../.taq/config.json')\n const Tezos = new TezosToolkit(config.sandbox.local.rpcUrl);\n\tconst key = config.sandbox.local.accounts.bob.secretKey.replace('unencrypted:', '')\n\tTezos.setProvider({\n\t\tsigner: new InMemorySigner(key),\n\t });\n let contract: ContractType = undefined as unknown as ContractType;\n beforeAll(async () => {\n ${generator.generateOrigination({ formatting: { indent: 3 } }).code}\n });\n\n${\n\t\tmethodCalls.map(x => `\n it('should call ${x.name}', async () => {\n ${x.storageAccess.getStorageValueFunctionCode}\n const storageValueBefore = await ${x.storageAccess.getStorageValueFunctionName}();\n ${x.methodCall.code}\n const storageValueAfter = await ${x.storageAccess.getStorageValueFunctionName}();\n\n expect(storageValueAfter.toString()).toBe('');\n });\n`).join('')\n\t}});\n`;\n};\n\nexport default (args: RequestArgs.t) => {\n\tconst parsedArgs = args as Opts;\n\tparsedArgs.michelsonArtifact\n\t\t? ensureMichelsonExists(parsedArgs)\n\t\t\t.then(ensureSelectedPartitionExists)\n\t\t\t.then(() => parsedArgs)\n\t\t\t.then(generateContractTypes)\n\t\t\t.then(generateTestSuite)\n\t\t\t.then((outFile: string) => sendAsyncRes(`Test suite generated: ${outFile}`))\n\t\t\t.catch(sendAsyncErr)\n\t\t: sendAsyncErr(`No michelson artifact provided`);\n};\n","import { sendAsyncRes, sendErr } from '@taqueria/node-sdk';\nimport { RequestArgs } from '@taqueria/node-sdk';\nimport { execa } from 'execa';\nimport { CustomRequestArgs, ensureSelectedPartitionExists, toRequestArgs } from './common';\n\nconst execCmd = (cmd: string, args: string[]) => {\n\tconst child = execa(cmd, args, {\n\t\tshell: true,\n\t\treject: false,\n\t\tenv: { FORCE_COLOR: 'true' },\n\t});\n\n\tchild.stdout?.pipe(process.stdout);\n\tchild.stderr?.pipe(process.stderr);\n\n\treturn child;\n};\nexport default (args: RequestArgs.t) => {\n\tconst parsedArgs = toRequestArgs(args);\n\treturn ensureSelectedPartitionExists(parsedArgs, parsedArgs.init ? true : false)\n\t\t.then(configAbsPath => {\n\t\t\tif (!parsedArgs.init) {\n\t\t\t\tconst retval = parsedArgs.testPattern\n\t\t\t\t\t? execCmd('npx', ['jest', '-c', configAbsPath, '--testPathPattern', parsedArgs.testPattern])\n\t\t\t\t\t: execCmd('npx', ['jest', '-c', configAbsPath]);\n\t\t\t\treturn retval.then(child => {\n\t\t\t\t\tif (child.exitCode === 0) return;\n\t\t\t\t\telse process.exit(child.exitCode);\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treturn sendAsyncRes('Initialized successfully.');\n\t\t});\n};\n"],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IACV,SAAS,OAAO;AAAA,MACf,UAAU;AAAA,MACV,SAAS;AAAA,MACT,aAAa;AAAA,QACZ,cAAc,OAAO;AAAA,UACpB,aAAa;AAAA,UACb,aAAa;AAAA,UACb,UAAU;AAAA,UACV,MAAM;AAAA,QACP,CAAC;AAAA,MACF;AAAA,MACA,SAAS;AAAA,QACR,OAAO,OAAO;AAAA,UACb,MAAM;AAAA,UACN,aAAa;AAAA,UACb,MAAM;AAAA,UACN,cAAc,cAAc,WAAW,EAAE,OAAO,KAAK;AAAA,QACtD,CAAC;AAAA,MACF;AAAA,MACA,aAAa;AAAA,MACb,SAAS;AAAA,IACV,CAAC;AAAA,EACF;AAAA,EACA;AACD,IAAI,QAAQ,IAAI;","names":["sendAsyncErr","sendAsyncRes","stat","writeFile","join","join","stat","writeFile","sendAsyncRes","sendAsyncErr","sendAsyncRes","sendAsyncRes"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@taqueria/plugin-jest",
|
|
3
|
-
"version": "0.42.
|
|
3
|
+
"version": "0.42.6",
|
|
4
4
|
"main": "index.cjs",
|
|
5
5
|
"module": "index.js",
|
|
6
6
|
"source": "index.ts",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"directory": "taqueria-plugin-jest"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@taqueria/node-sdk": "^0.42.
|
|
31
|
-
"@taqueria/plugin-contract-types": "^0.42.
|
|
30
|
+
"@taqueria/node-sdk": "^0.42.6",
|
|
31
|
+
"@taqueria/plugin-contract-types": "^0.42.6",
|
|
32
32
|
"@taquito/signer": "^18.0.0-RC.0",
|
|
33
33
|
"@taquito/taquito": "^18.0.0-RC.0",
|
|
34
34
|
"@taquito/utils": "^18.0.0-RC.0",
|