Skip to content

Commit

Permalink
Merge pull request #3 from ecadlabs/metadata-plugin-tests
Browse files Browse the repository at this point in the history
added metadata and types plugins
  • Loading branch information
michaelkernaghan authored Dec 21, 2022
2 parents 83779bf + a565ea5 commit c3a64f0
Show file tree
Hide file tree
Showing 12 changed files with 2,927 additions and 6 deletions.
292 changes: 292 additions & 0 deletions src/contract-types-plugin-e2e-tests.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,292 @@
import { exec as exec1 } from 'child_process';
import path from 'path';
import util from 'util';
const exec = util.promisify(exec1);

import { prepareEnvironment } from '@gmrchk/cli-testing-library';

describe('Contract Types Plugin E2E Testing for Taqueria CLI', () => {

jest.setTimeout(30000);

test('contract types plugin will offer help', async () => {
const { execute, spawn, cleanup } = await prepareEnvironment();
const { waitForText } = await spawn('taq', 'init test-project');
await waitForText("Project taq'ified!");
const { stdout } = await execute('taq', 'install @taqueria/plugin-contract-types', './test-project');
expect(stdout).toContain('Plugin installed successfully');

const { stdout: stdout2 } = await execute('taq', '--help --projectDir=./test-project');
expect(stdout2).toEqual(expect.arrayContaining(['Commands:']));

await cleanup();
});

test.skip('1635 - generate types offers contextual help', async () => {
const { execute, spawn, cleanup } = await prepareEnvironment();
const { waitForText } = await spawn('taq', 'init test-project');
await waitForText("Project taq'ified!");
const { stdout } = await execute('taq', 'install @taqueria/plugin-contract-types', './test-project');
expect(stdout).toContain('Plugin installed successfully');

const { stdout: stdout2 } = await execute('taq', 'generate types --help --projectDir=./test-project');
expect(stdout2).toEqual(expect.arrayContaining(['Generate types for a contract to be used with taquito']));

await cleanup();
});

test.skip('1635 - gen offers contextual help', async () => {
const { execute, spawn, cleanup } = await prepareEnvironment();
const { waitForText } = await spawn('taq', 'init test-project');
await waitForText("Project taq'ified!");
const { stdout } = await execute('taq', 'install @taqueria/plugin-contract-types', './test-project');
expect(stdout).toContain('Plugin installed successfully');

const { stdout: stdout2 } = await execute('taq', 'gen --help --projectDir=./test-project');
expect(stdout2).toEqual(expect.arrayContaining(['Generate types for a contract to be used with taquito']));

await cleanup();
});

test('generate types will only output the typeScriptDir and will not create a types dir when no contracts exist', async () => {
const { execute, spawn, cleanup, ls } = await prepareEnvironment();
const { waitForText } = await spawn('taq', 'init test-project');
await waitForText("Project taq'ified!");
const { stdout } = await execute('taq', 'install @taqueria/plugin-contract-types', './test-project');
expect(stdout).toContain('Plugin installed successfully');

const { stdout: stdout1 } = await execute('taq', 'generate types', './test-project');
expect(stdout1).toContain(`generateTypes { typescriptDir: 'types' }`);

expect(await ls('./test-project/')).not.toContain('types');

await cleanup();
});

test('generate types types can compile one contract and generate types', async () => {
const { execute, cleanup, spawn, writeFile, ls } = await prepareEnvironment();
const { waitForText } = await spawn('taq', 'init test-project');
await waitForText("Project taq'ified!");
const { stdout } = await execute('taq', 'install @taqueria/plugin-contract-types', './test-project');
expect(stdout).toContain('Plugin installed successfully');
const { stdout: stdout1 } = await execute('taq', 'install @taqueria/plugin-ligo', './test-project');
expect(stdout1).toContain('Plugin installed successfully');

const jsligo_file = await (await exec(`cat src/test-data/increment.jsligo`)).stdout;
await writeFile('./test-project/contracts/increment.jsligo', jsligo_file);

const {} = await execute('taq', 'compile increment.jsligo', './test-project');

const { stdout: stdout2 } = await execute('taq', 'generate types types', './test-project');
expect(stdout2).toContain(`generateTypes { typescriptDir: 'types' }`);
expect(stdout2).toEqual(
expect.arrayContaining(['Generating Types: {{base}}/test-project/artifacts => {{base}}/test-project/types']),
);
expect(stdout2).toEqual(expect.arrayContaining(['Contracts Found:']));
expect(stdout2).toEqual(expect.arrayContaining(['- {{base}}/test-project/artifacts/increment.tz']));
expect(stdout2).toEqual(expect.arrayContaining(['Processing /increment.tz...']));
expect(stdout2).toEqual(expect.arrayContaining(['increment.tz: Types generated']));

expect(await ls('./test-project/')).toContain('types');
expect(await ls('./test-project/types')).toContain('increment.code.ts');
expect(await ls('./test-project/types')).toContain('increment.types.ts');
expect(await ls('./test-project/types')).toContain('type-aliases.ts');
expect(await ls('./test-project/types')).toContain('type-utils.ts');

await cleanup();
});

test('gentypes types can compile one contract and generate types', async () => {
const { execute, cleanup, spawn, writeFile, ls } = await prepareEnvironment();
const { waitForText } = await spawn('taq', 'init test-project');
await waitForText("Project taq'ified!");
const { stdout } = await execute('taq', 'install @taqueria/plugin-contract-types', './test-project');
expect(stdout).toContain('Plugin installed successfully');
const { stdout: stdout1 } = await execute('taq', 'install @taqueria/plugin-ligo', './test-project');
expect(stdout1).toContain('Plugin installed successfully');

const jsligo_file = await (await exec(`cat src/test-data/increment.jsligo`)).stdout;
await writeFile('./test-project/contracts/increment.jsligo', jsligo_file);

const {} = await execute('taq', 'compile increment.jsligo', './test-project');

const { stdout: stdout2 } = await execute('taq', 'gentypes types', './test-project');
expect(stdout2).toContain(`generateTypes { typescriptDir: 'types' }`);
expect(stdout2).toEqual(
expect.arrayContaining(['Generating Types: {{base}}/test-project/artifacts => {{base}}/test-project/types']),
);
expect(stdout2).toEqual(expect.arrayContaining(['Contracts Found:']));
expect(stdout2).toEqual(expect.arrayContaining(['- {{base}}/test-project/artifacts/increment.tz']));
expect(stdout2).toEqual(expect.arrayContaining(['Processing /increment.tz...']));
expect(stdout2).toEqual(expect.arrayContaining(['increment.tz: Types generated']));

expect(await ls('./test-project/')).toContain('types');
expect(await ls('./test-project/types')).toContain('increment.code.ts');
expect(await ls('./test-project/types')).toContain('increment.types.ts');
expect(await ls('./test-project/types')).toContain('type-aliases.ts');
expect(await ls('./test-project/types')).toContain('type-utils.ts');

await cleanup();
});

test('gen types can compile one contract and generate types', async () => {
const { execute, cleanup, spawn, writeFile, ls } = await prepareEnvironment();
const { waitForText } = await spawn('taq', 'init test-project');
await waitForText("Project taq'ified!");
const { stdout } = await execute('taq', 'install @taqueria/plugin-contract-types', './test-project');
expect(stdout).toContain('Plugin installed successfully');
const { stdout: stdout1 } = await execute('taq', 'install @taqueria/plugin-ligo', './test-project');
expect(stdout1).toContain('Plugin installed successfully');

const jsligo_file = await (await exec(`cat src/test-data/increment.jsligo`)).stdout;
await writeFile('./test-project/contracts/increment.jsligo', jsligo_file);

const {} = await execute('taq', 'compile increment.jsligo', './test-project');

const { stdout: stdout2 } = await execute('taq', 'gen types', './test-project');
expect(stdout2).toContain(`generateTypes { typescriptDir: 'types' }`);
expect(stdout2).toEqual(
expect.arrayContaining(['Generating Types: {{base}}/test-project/artifacts => {{base}}/test-project/types']),
);
expect(stdout2).toEqual(expect.arrayContaining(['Contracts Found:']));
expect(stdout2).toEqual(expect.arrayContaining(['- {{base}}/test-project/artifacts/increment.tz']));
expect(stdout2).toEqual(expect.arrayContaining(['Processing /increment.tz...']));
expect(stdout2).toEqual(expect.arrayContaining(['increment.tz: Types generated']));

expect(await ls('./test-project/')).toContain('types');
expect(await ls('./test-project/types')).toContain('increment.code.ts');
expect(await ls('./test-project/types')).toContain('increment.types.ts');
expect(await ls('./test-project/types')).toContain('type-aliases.ts');
expect(await ls('./test-project/types')).toContain('type-utils.ts');

await cleanup();
});

test('generate types -t "file" can compile one contract and generate types', async () => {
const { execute, cleanup, spawn, writeFile, ls } = await prepareEnvironment();
const { waitForText } = await spawn('taq', 'init test-project');
await waitForText("Project taq'ified!");
const { stdout } = await execute('taq', 'install @taqueria/plugin-contract-types', './test-project');
expect(stdout).toContain('Plugin installed successfully');
const { stdout: stdout1 } = await execute('taq', 'install @taqueria/plugin-ligo', './test-project');
expect(stdout1).toContain('Plugin installed successfully');

const jsligo_file = await (await exec(`cat src/test-data/increment.jsligo`)).stdout;
await writeFile('./test-project/contracts/increment.jsligo', jsligo_file);

const {} = await execute('taq', 'compile increment.jsligo', './test-project');

const { stdout: stdout2 } = await execute('taq', 'generate types -t "file"', './test-project');
expect(stdout2).toContain(`generateTypes { typescriptDir: 'types' }`);
expect(stdout2).toEqual(
expect.arrayContaining(['Generating Types: {{base}}/test-project/artifacts => {{base}}/test-project/types']),
);
expect(stdout2).toEqual(expect.arrayContaining(['Contracts Found:']));
expect(stdout2).toEqual(expect.arrayContaining(['- {{base}}/test-project/artifacts/increment.tz']));
expect(stdout2).toEqual(expect.arrayContaining(['Processing /increment.tz...']));
expect(stdout2).toEqual(expect.arrayContaining(['increment.tz: Types generated']));

expect(await ls('./test-project/')).toContain('types');
expect(await ls('./test-project/types')).toContain('increment.code.ts');
expect(await ls('./test-project/types')).toContain('increment.types.ts');
expect(await ls('./test-project/types')).toContain('type-aliases.ts');
expect(await ls('./test-project/types')).toContain('type-utils.ts');

await cleanup();
});

test('generate types can compile an Auction contract and generate types', async () => {
const { execute, cleanup, spawn, writeFile, readFile } = await prepareEnvironment();
const { waitForText } = await spawn('taq', 'init test-project');
await waitForText("Project taq'ified!");
const { stdout } = await execute('taq', 'install @taqueria/plugin-contract-types', './test-project');
expect(stdout).toContain('Plugin installed successfully');
const { stdout: stdout1 } = await execute('taq', 'install @taqueria/plugin-ligo', './test-project');
expect(stdout1).toContain('Plugin installed successfully');

const tz_file = await (await exec(`cat src/test-data/contracts/example-contract-1.tz`))
.stdout;
await writeFile('./test-project/artifacts/example-contract-1.tz', tz_file);
const expected_types_file =
await (await exec(`cat src/test-data/types-file/example-contract-1.types.ts`)).stdout;

const {} = await execute('taq', 'generate types', './test-project');
const generated_types_file = await readFile(path.join('./test-project', 'types', 'example-contract-1.types.ts'));

expect(generated_types_file).toBe(expected_types_file);

await cleanup();
});

test('generate types can compile an FA2 contract and generate types', async () => {
const { execute, cleanup, spawn, writeFile, readFile } = await prepareEnvironment();
const { waitForText } = await spawn('taq', 'init test-project');
await waitForText("Project taq'ified!");
const { stdout } = await execute('taq', 'install @taqueria/plugin-contract-types', './test-project');
expect(stdout).toContain('Plugin installed successfully');
const { stdout: stdout1 } = await execute('taq', 'install @taqueria/plugin-ligo', './test-project');
expect(stdout1).toContain('Plugin installed successfully');

const tz_file = await (await exec(`cat src/test-data/contracts/example-contract-2.tz`))
.stdout;
await writeFile('./test-project/artifacts/example-contract-2.tz', tz_file);
const expected_types_file =
await (await exec(`cat src/test-data/types-file/example-contract-2.types.ts`)).stdout;

const {} = await execute('taq', 'generate types', './test-project');
const generated_types_file = await readFile(path.join('./test-project', 'types', 'example-contract-2.types.ts'));

expect(generated_types_file).toBe(expected_types_file);

await cleanup();
});

test('generate types can compile a contract from a sub-directory and generate types', async () => {
const { execute, cleanup, spawn, writeFile, readFile } = await prepareEnvironment();
const { waitForText } = await spawn('taq', 'init test-project');
await waitForText("Project taq'ified!");
const { stdout } = await execute('taq', 'install @taqueria/plugin-contract-types', './test-project');
expect(stdout).toContain('Plugin installed successfully');
const { stdout: stdout1 } = await execute('taq', 'install @taqueria/plugin-ligo', './test-project');
expect(stdout1).toContain('Plugin installed successfully');

const tz_file =
await (await exec(`cat src/test-data/contracts/subdir/example-contract-0.tz`)).stdout;
await writeFile('./test-project/artifacts/subdir/example-contract-0.tz', tz_file);
const expected_types_file =
await (await exec(`cat src/test-data/types-file/subdir/example-contract-0.types.ts`))
.stdout;

const {} = await execute('taq', 'generate types', './test-project');
const generated_types_file = await readFile(
path.join('./test-project', 'types', 'subdir/example-contract-0.types.ts'),
);

expect(generated_types_file).toBe(expected_types_file);

await cleanup();
});

test('generate types can compile a Lambda contract and generate types', async () => {
const { execute, cleanup, spawn, writeFile, readFile } = await prepareEnvironment();
const { waitForText } = await spawn('taq', 'init test-project');
await waitForText("Project taq'ified!");
const { stdout } = await execute('taq', 'install @taqueria/plugin-contract-types', './test-project');
expect(stdout).toContain('Plugin installed successfully');
const { stdout: stdout1 } = await execute('taq', 'install @taqueria/plugin-ligo', './test-project');
expect(stdout1).toContain('Plugin installed successfully');

const tz_file = await (await exec(`cat src/test-data/contracts/example-lambda.tz`))
.stdout;
await writeFile('./test-project/artifacts/example-lambda.tz', tz_file);
const expected_types_file =
await (await exec(`cat src/test-data/types-file/example-lambda.types.ts`)).stdout;

const {} = await execute('taq', 'generate types', './test-project');
const generated_types_file = await readFile(path.join('./test-project', 'types', 'example-lambda.types.ts'));

expect(generated_types_file).toBe(expected_types_file);

await cleanup();
});
});
14 changes: 8 additions & 6 deletions src/metadata-plugin-e2e-tests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { prepareEnvironment } from '@gmrchk/cli-testing-library';

describe('Metadata Plugin E2E Testing for the Taqueria CLI', () => {

jest.setTimeout(120000);
jest.setTimeout(90000);

test('generate-project-metadata will add a metadata entry to the config.json', async () => {
const { execute, spawn, cleanup, ls, writeFile, readFile } = await prepareEnvironment();
Expand Down Expand Up @@ -58,10 +58,10 @@ describe('Metadata Plugin E2E Testing for the Taqueria CLI', () => {
'authors': [
'KentBeck',
'MartinFowler',
'ErichGamma'
'ErichGamma',
],
'homepage': 'http://taqueria.io',
'license': '007'
'license': '007',
});

await cleanup();
Expand Down Expand Up @@ -140,10 +140,12 @@ describe('Metadata Plugin E2E Testing for the Taqueria CLI', () => {
'homepage': 'http://taqueria.io',
'license': '007',
'interfaces': [
'TZIP-016'
]
'TZIP-016',
],
});

await cleanup();

});
});
});

Loading

0 comments on commit c3a64f0

Please sign in to comment.