Compiling storage with compile-storage command instead of compile-expression

This commit is contained in:
Maksym Bykovskyy 2020-02-27 22:20:23 +00:00 committed by Jev Björsell
parent f39ff186d6
commit a434b935c6
7 changed files with 138 additions and 3 deletions

View File

@ -132,7 +132,7 @@ export const OutputTabComponent = (props: {
return ( return (
<Container visible={props.selected}> <Container visible={props.selected}>
{output.length !== 0 && ( {!(loading.loading || output.length === 0) && (
<OutputToolbarComponent <OutputToolbarComponent
onCopy={() => copyOutput(preRef.current)} onCopy={() => copyOutput(preRef.current)}
onDownload={() => downloadOutput(preRef.current)} onDownload={() => downloadOutput(preRef.current)}

View File

@ -2,7 +2,7 @@ import { Tezos } from '@taquito/taquito';
import { TezBridgeSigner } from '@taquito/tezbridge-signer'; import { TezBridgeSigner } from '@taquito/tezbridge-signer';
import { Dispatch } from 'redux'; import { Dispatch } from 'redux';
import { compileContract, compileExpression, deploy, getErrorMessage } from '../../services/api'; import { compileContract, compileStorage, deploy, getErrorMessage } from '../../services/api';
import { AppState } from '../app'; import { AppState } from '../app';
import { MichelsonFormat } from '../compile'; import { MichelsonFormat } from '../compile';
import { DoneLoadingAction, UpdateLoadingAction } from '../loading'; import { DoneLoadingAction, UpdateLoadingAction } from '../loading';
@ -32,8 +32,10 @@ export class DeployAction extends CancellableAction {
} }
dispatch({ ...new UpdateLoadingAction('Compiling storage...') }); dispatch({ ...new UpdateLoadingAction('Compiling storage...') });
const michelsonStorage = await compileExpression( const michelsonStorage = await compileStorage(
editorState.language, editorState.language,
editorState.code,
deployState.entrypoint,
deployState.storage, deployState.storage,
MichelsonFormat.Json MichelsonFormat.Json
); );

View File

@ -36,6 +36,23 @@ export async function compileExpression(
return response.data; return response.data;
} }
export async function compileStorage(
syntax: Language,
code: string,
entrypoint: string,
storage: string,
format?: string
) {
const response = await axios.post('/api/compile-storage', {
syntax,
code,
entrypoint,
storage,
format
});
return response.data;
}
export async function dryRun( export async function dryRun(
syntax: Language, syntax: Language,
code: string, code: string,

View File

@ -79,6 +79,19 @@ exports.verifyAllExamples = async (action, done) => {
done(); done();
}; };
exports.verifyWithParameter = async (command, parameter, value, action, done) => {
await page.click('#command-select');
await page.click(`#${command}`);
await page.click(`#${parameter}`);
await exports.clearText(page.keyboard);
await page.keyboard.type(value);
expect(await action()).toEqual(`Error: "${parameter}" is not allowed to be empty`);
done();
}
exports.verifyWithBlankParameter = async (command, parameter, action, done) => { exports.verifyWithBlankParameter = async (command, parameter, action, done) => {
await page.click('#command-select'); await page.click('#command-select');
await page.click(`#${command}`); await page.click(`#${command}`);

View File

@ -0,0 +1,38 @@
const commonUtils = require('./common-utils');
const API_HOST = commonUtils.API_HOST;
const runCommandAndGetOutputFor = commonUtils.runCommandAndGetOutputFor;
const clearText = commonUtils.clearText;
const COMMAND = 'deploy';
const COMMAND_ENDPOINT = 'deploy';
async function deploy() {
return await runCommandAndGetOutputFor(COMMAND, COMMAND_ENDPOINT);
}
describe('Deploy contract', () => {
beforeAll(() => jest.setTimeout(60000));
beforeEach(async () => await page.goto(API_HOST));
it('should deploy', async done => {
expect(await deploy()).toContain('The contract was successfully deployed to the babylonnet test network.');
done();
});
it('should fail to deploy contract with invalid storage', async done => {
await page.click('#command-select');
await page.click(`#deploy`);
await page.click(`#storage`);
await clearText(page.keyboard);
await page.keyboard.type('asdf');
expect(await deploy()).toContain('Error: ');
done();
});
});

View File

@ -120,6 +120,7 @@ export class LigoCompiler {
format: string format: string
) { ) {
const { name, remove } = await this.createTemporaryFile(code); const { name, remove } = await this.createTemporaryFile(code);
try { try {
const result = await this.execPromise(this.ligoCmd, [ const result = await this.execPromise(this.ligoCmd, [
'compile-contract', 'compile-contract',
@ -148,6 +149,33 @@ export class LigoCompiler {
return result; return result;
} }
async compileStorage(
syntax: string,
code: string,
entrypoint: string,
format: string,
storage: string
) {
const { name, remove } = await this.createTemporaryFile(code);
try {
const result = await this.execPromise(this.ligoCmd, [
'compile-storage',
'--michelson-format',
format,
'-s',
syntax,
name,
entrypoint,
storage
]);
return result;
} finally {
remove();
}
}
async dryRun( async dryRun(
syntax: string, syntax: string,
code: string, code: string,

View File

@ -0,0 +1,37 @@
import { LigoCompiler } from '../src/ligo-compiler';
const PASCALIGO_CODE = `
type action is
| Increment of int
| Decrement of int
function add (const a : int ; const b : int) : int is
block { skip } with a + b
function subtract (const a : int ; const b : int) : int is
block { skip } with a - b
function main (const p : action ; const s : int) :
(list(operation) * int) is
block { skip } with ((nil : list(operation)),
case p of
| Increment(n) -> add(s, n)
| Decrement(n) -> subtract(s, n)
end)
`;
describe('Ligo compiler', () => {
it('should compile storage', async done => {
const michelsonCode = await new LigoCompiler().compileStorage(
'pascaligo',
PASCALIGO_CODE,
'main',
'json',
'0'
);
expect(michelsonCode.trim()).toEqual('{ "int": "0" }');
done();
});
});