Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update compiler to 7.0.1 #1457

Merged
merged 2 commits into from
Aug 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
NODE_TAG=v6.5.2
COMPILER_TAG=v6.1.0
COMPILER_TAG=v7.0.1
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ coverage.*
.site
site
/src/apis/
/tooling/autorest/compiler-swagger.yaml
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"sideEffects": false,
"scripts": {
"build:es": "tsc && babel src --config-file ./babel.esm.config.js --out-dir es --extensions .js,.ts --out-file-extension .mjs --source-maps true",
"build:api": "npx autorest tooling/autorest/compiler.yaml --output-artifact:code-model-v4 && npx autorest tooling/autorest/node.yaml --output-artifact:code-model-v4",
"build:api": "node tooling/autorest/compiler-prepare.mjs && npx autorest tooling/autorest/compiler.yaml --output-artifact:code-model-v4 && npx autorest tooling/autorest/node.yaml --output-artifact:code-model-v4",
"build": "npm run build:api && webpack && npm run build:es",
"docs:examples": "node tooling/docs/examples-to-md.js examples/node/*.mjs",
"docs:api": "typedoc",
Expand Down
4 changes: 2 additions & 2 deletions src/contract/Compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ export default class Compiler extends CompilerApi {
],
});
if (ignoreVersion !== true) {
const versionPromise = this.aPIVersion().then(({ apiVersion }) => apiVersion);
const versionPromise = this.apiVersion().then(({ apiVersion }) => apiVersion);
this.pipeline.addPolicy(
genVersionCheckPolicy('compiler', '/api-version', versionPromise, '6.1.0', '7.0.0'),
genVersionCheckPolicy('compiler', '/api-version', versionPromise, '7.0.1', '8.0.0'),
);
}
}
Expand Down
6 changes: 2 additions & 4 deletions test/integration/contract-aci.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ namespace Test =

contract interface RemoteI =
type test_type = int
record state = { value: string, key: test_type, testOption: option(string) }
record test_record = { value: string, key: list(test_type) }
entrypoint test : () => int
datatype event = RemoteEvent1(int) | RemoteEvent2(string, int) | Duplicate(int)
Expand Down Expand Up @@ -273,9 +272,8 @@ describe('Contract instance', () => {
}));

it('rejects not matching bytecode with enabled validation', async () => expect(aeSdk.getContractInstance({
bytecode: (await aeSdk.compilerApi.compileContract({
code: identityContractSourceCode, options: {},
})).bytecode,
bytecode: (await aeSdk.compilerApi.compileContract({ code: identityContractSourceCode }))
.bytecode,
aci: await aeSdk.compilerApi
.generateACI({ code: identityContractSourceCode, options: { fileSystem } }),
address: testContractAddress,
Expand Down
28 changes: 12 additions & 16 deletions test/integration/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,8 @@ describe('Contract', () => {
});

it('compiles Sophia code', async () => {
bytecode = (await aeSdk.compilerApi.compileContract({
code: identityContract, options: {},
})).bytecode as Encoded.ContractBytearray;
bytecode = (await aeSdk.compilerApi.compileContract({ code: identityContract }))
.bytecode as Encoded.ContractBytearray;
expect(bytecode).to.satisfy((b: string) => b.startsWith('cb_'));
});

Expand Down Expand Up @@ -267,9 +266,8 @@ describe('Contract', () => {

describe('Sophia Compiler', () => {
it('compile', async () => {
bytecode = (await aeSdk.compilerApi.compileContract({
code: identityContract, options: {},
})).bytecode as Encoded.ContractBytearray;
bytecode = (await aeSdk.compilerApi.compileContract({ code: identityContract }))
.bytecode as Encoded.ContractBytearray;
expect(bytecode.split('_')[0]).to.be.equal('cb');
});

Expand All @@ -280,39 +278,37 @@ describe('Contract', () => {
+ ' entrypoint getArg(x : bar) = x\n'
+ ' entrypoint getArg(x : int) = baz\n'
+ ' entrypoint getArg1(x : int) = baz\n',
options: {},
})).to.be.rejectedWith(
'compile error:\n'
+ 'type_error:3:3: Duplicate definitions of getArg at\n'
+ 'type_error:3:3: Duplicate definitions of `getArg` at\n'
+ ' - line 2, column 3\n'
+ ' - line 3, column 3\n'
+ 'type_error:3:32: Unbound variable baz at line 3, column 32\n'
+ 'type_error:4:33: Unbound variable baz at line 4, column 33',
+ 'type_error:3:32: Unbound variable `baz`\n'
+ 'type_error:4:33: Unbound variable `baz`',
);
});

it('generate contract ACI', async () => {
const aci = await aeSdk.compilerApi.generateACI({ code: identityContract, options: {} });
const aci = await aeSdk.compilerApi.generateACI({ code: identityContract });
expect(aci).to.have.property('encodedAci');
expect(aci).to.have.property('externalEncodedAci');
expect(aci).to.have.property('interface');
});

it('throws clear exception if generating ACI with no arguments', async () => {
await expect(aeSdk.compilerApi.generateACI({ options: {} } as any))
await expect(aeSdk.compilerApi.generateACI({} as any))
.to.be.rejectedWith('Error "body.code cannot be null or undefined." occurred in serializing the payload - undefined');
});

it('validate bytecode', async () => {
expect(await aeSdk.compilerApi.validateByteCode({
bytecode, source: identityContract, options: {},
})).to.be.eql({ body: {} });
expect(await aeSdk.compilerApi.validateByteCode({ bytecode, source: identityContract }))
.to.be.eql({ body: {} });
});

it('Use invalid compiler url', async () => {
const url = aeSdk.compilerApi.$host;
aeSdk.setCompilerUrl('https://compiler.aepps.comas');
await expect(aeSdk.compilerApi.generateACI({ code: 'test', options: {} }))
await expect(aeSdk.compilerApi.generateACI({ code: 'test' }))
.to.be.rejectedWith('getaddrinfo ENOTFOUND compiler.aepps.comas');
aeSdk.setCompilerUrl(url);
});
Expand Down
2 changes: 1 addition & 1 deletion test/integration/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ describe('Transaction', () => {
}),
], [
'contract create',
'tx_+LAqAaEB1c8IQA6YgiLybrSwLI+JB3RXRnIRpubZVe23B0nGozsBuGr4aEYDoKEijZbj/w2AeiWwAbldusME5pm3ZgPuomnZ3TbUbYgrwLg7nv5E1kQfADcANwAaDoI/AQM//oB4IJIANwEHBwEBAJgvAhFE1kQfEWluaXQRgHggkhlnZXRBcmeCLwCFNi4xLjAAgwcAA4ZHcyzkwAAAAACDTEtAhDuaygCHKxFE1kQfPxOlnVo=',
'tx_+LAqAaEB1c8IQA6YgiLybrSwLI+JB3RXRnIRpubZVe23B0nGozsBuGr4aEYDoKEijZbj/w2AeiWwAbldusME5pm3ZgPuomnZ3TbUbYgrwLg7nv5E1kQfADcANwAaDoI/AQM//oB4IJIANwEHBwEBAJgvAhFE1kQfEWluaXQRgHggkhlnZXRBcmeCLwCFNy4wLjEAgwcAA4ZHcyzkwAAAAACDTEtAhDuaygCHKxFE1kQfP6vKAEo=',
async () => aeSdk.buildTx(Tag.ContractCreateTx, {
nonce,
ownerId: address,
Expand Down
17 changes: 17 additions & 0 deletions tooling/autorest/compiler-prepare.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import https from 'https';
import fs from 'fs';

const swaggerUrl = 'https://raw.githubusercontent.com/aeternity/aesophia_http/v7.0.1/config/swagger.yaml';

let swagger = await new Promise((resolve) => {
https.get(swaggerUrl, (res) => {
let data = '';
res.on('data', (chunk) => { data += chunk; });
res.on('close', () => resolve(data));
}).end();
});

swagger = swagger.replace(/basePath: \//, '');
// TODO: Remove after fixing https://github.com/aeternity/aesophia_http/issues/87
swagger = swagger.replace(/'400':.{80,120}?Error'\s+'400':/gms, '\'400\':');
await fs.promises.writeFile('./tooling/autorest/compiler-swagger.yaml', swagger);
2 changes: 1 addition & 1 deletion tooling/autorest/compiler.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use-extension:
'@autorest/modelerfour': ^4.23.1
# replace with a link to https://github.com/aeternity/aesophia_http/blob/master/config/swagger.yaml
# at specific version after fixing https://github.com/aeternity/aesophia_http/issues/87
input-file: https://compiler.aeternity.io/api
input-file: compiler-swagger.yaml
output-folder: ../../src/apis/compiler
source-code-folder-path: .
client-side-validation: true
Expand Down