From 994911f1716a52857d68b79a56f2d18908ae38bb Mon Sep 17 00:00:00 2001 From: Denis Davidyuk Date: Tue, 9 Aug 2022 13:37:56 +0300 Subject: [PATCH 1/2] chore(compiler)!: update to 7.0.1 BREAKING CHANGE: Dropped compatibility with compilers below 7.0.1 --- .env | 2 +- .gitignore | 1 + package.json | 2 +- src/contract/Compiler.ts | 4 ++-- test/integration/contract-aci.ts | 1 - test/integration/contract.ts | 6 +++--- test/integration/transaction.ts | 2 +- tooling/autorest/compiler-prepare.mjs | 17 +++++++++++++++++ tooling/autorest/compiler.yaml | 2 +- 9 files changed, 27 insertions(+), 10 deletions(-) create mode 100644 tooling/autorest/compiler-prepare.mjs diff --git a/.env b/.env index 0c148ff899..05fa007e66 100644 --- a/.env +++ b/.env @@ -1,2 +1,2 @@ NODE_TAG=v6.5.2 -COMPILER_TAG=v6.1.0 +COMPILER_TAG=v7.0.1 diff --git a/.gitignore b/.gitignore index 8e448c47a7..cbe5d9e877 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,4 @@ coverage.* .site site /src/apis/ +/tooling/autorest/compiler-swagger.yaml diff --git a/package.json b/package.json index ef9f6b77f5..f161fb8e08 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/contract/Compiler.ts b/src/contract/Compiler.ts index 5441db4e84..77dc1d0ca2 100644 --- a/src/contract/Compiler.ts +++ b/src/contract/Compiler.ts @@ -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'), ); } } diff --git a/test/integration/contract-aci.ts b/test/integration/contract-aci.ts index 6820de041f..057bd64141 100644 --- a/test/integration/contract-aci.ts +++ b/test/integration/contract-aci.ts @@ -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) diff --git a/test/integration/contract.ts b/test/integration/contract.ts index 9872675053..c4aef5722d 100644 --- a/test/integration/contract.ts +++ b/test/integration/contract.ts @@ -283,11 +283,11 @@ describe('Contract', () => { 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`', ); }); diff --git a/test/integration/transaction.ts b/test/integration/transaction.ts index 47023f769b..8900b2ee0d 100644 --- a/test/integration/transaction.ts +++ b/test/integration/transaction.ts @@ -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, diff --git a/tooling/autorest/compiler-prepare.mjs b/tooling/autorest/compiler-prepare.mjs new file mode 100644 index 0000000000..f960622d76 --- /dev/null +++ b/tooling/autorest/compiler-prepare.mjs @@ -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); diff --git a/tooling/autorest/compiler.yaml b/tooling/autorest/compiler.yaml index ceb8ca5f38..fd0a0fddd1 100644 --- a/tooling/autorest/compiler.yaml +++ b/tooling/autorest/compiler.yaml @@ -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 From 47c349b318ea4a33d3fc48251a13732f67c00100 Mon Sep 17 00:00:00 2001 From: Denis Davidyuk Date: Tue, 9 Aug 2022 09:54:23 +0300 Subject: [PATCH 2/2] test: remove empty options objects --- test/integration/contract-aci.ts | 5 ++--- test/integration/contract.ts | 22 +++++++++------------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/test/integration/contract-aci.ts b/test/integration/contract-aci.ts index 057bd64141..9e06294345 100644 --- a/test/integration/contract-aci.ts +++ b/test/integration/contract-aci.ts @@ -272,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, diff --git a/test/integration/contract.ts b/test/integration/contract.ts index c4aef5722d..97117640da 100644 --- a/test/integration/contract.ts +++ b/test/integration/contract.ts @@ -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_')); }); @@ -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'); }); @@ -280,7 +278,6 @@ 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' @@ -292,27 +289,26 @@ describe('Contract', () => { }); 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); });