diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2ef7bfbae3..03388882f4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,5 +1,10 @@ name: Test & build -on: [pull_request] +on: + push: + branches: + master + develop + pull_request: jobs: main: runs-on: ubuntu-22.04 @@ -27,10 +32,10 @@ jobs: BASE: ${{ github.event.pull_request.base.sha }} run: npx commitlint --from $BASE --to $HEAD --verbose - run: npm run lint - # TODO: remove after merging https://github.com/aeternity/aeternity/pull/4307 + # TODO: remove after merging https://github.com/aeternity/aeternity/pull/4319 - run: chmod 666 ./docker/accounts-pub.json - run: docker compose up -d --wait - - run: npx nyc npm run test + - run: npx nyc npm test - run: npx nyc report --reporter=text-lcov > coverage.lcov - uses: codecov/codecov-action@v4 with: diff --git a/commitlint.config.js b/commitlint.config.js index 1ff9f4adce..813ce53814 100644 --- a/commitlint.config.js +++ b/commitlint.config.js @@ -13,7 +13,6 @@ module.exports = { 'compiler', 'contract', 'middleware', - 'docs', // TODO: remove after releasing 13.1.0 'deps', 'deps-dev', 'node', @@ -24,4 +23,5 @@ module.exports = { ], ], }, + ignores: [(message) => /^Bumps \[.+]\(.+\) from .+ to .+\.$/m.test(message)], }; diff --git a/docker-compose.yml b/docker-compose.yml index e4ae64bf1b..94cfbfed1e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,7 +2,7 @@ version: '3' services: node: # TODO: switch to master after merging https://github.com/aeternity/aeternity/pull/4303 - image: aeternity/aeternity:master-bundle@sha256:54eefa1204b631dd477e3928b50e4449750a7c0e06b53eda4cf1493835b08caa + image: aeternity/aeternity:v6.13.0-bundle # TODO: remove 3313 port after merging https://github.com/aeternity/aeternity/pull/4303 ports: [3013:3013, 3113:3113, 3014:3014, 3313:3313] # TODO: remove after releasing https://github.com/aeternity/aeternity/pull/4292 @@ -11,7 +11,7 @@ services: volumes: - ./docker/aeternity.yaml:/home/aeternity/node/aeternity.yaml - ./docker/accounts.json:/home/aeternity/node/data/aeplugin_dev_mode/devmode_prefunded_accounts.json - # TODO: remove after merging https://github.com/aeternity/aeternity/pull/4307 + # TODO: remove after merging https://github.com/aeternity/aeternity/pull/4319 - ./docker/accounts-pub.json:/home/aeternity/node/data/aeplugin_dev_mode/devmode_prefunded_accounts-PUB.json stop_grace_period: 0s diff --git a/package-lock.json b/package-lock.json index aacfb6cf72..303f45f570 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "13.2.2", "license": "ISC", "dependencies": { - "@aeternity/aepp-calldata": "github:aeternity/aepp-calldata-js#8e9c8b8e1b394a01be1c84b13cf76271f7624d38", + "@aeternity/aepp-calldata": "^1.7.0", "@aeternity/argon2": "^0.0.1", "@aeternity/uuid": "^0.0.1", "@azure/core-client": "^1.8.0", @@ -18,7 +18,7 @@ "@ledgerhq/hw-transport": "^6.30.4", "@types/aes-js": "^3.1.4", "@types/json-bigint": "^1.0.4", - "@types/node": "~20.11.25", + "@types/node": "~18.13", "@types/sha.js": "^2.4.4", "@types/uuid": "^9.0.8", "@types/webextension-polyfill": "^0.10.7", @@ -105,10 +105,9 @@ } }, "node_modules/@aeternity/aepp-calldata": { - "version": "1.5.1", - "resolved": "git+ssh://git@github.com/aeternity/aepp-calldata-js.git#8e9c8b8e1b394a01be1c84b13cf76271f7624d38", - "integrity": "sha512-pDJBAfyOMfi5lBr+4M0V8edXAJ1dkNMdBuQNt6+opPgZgLSUmO/Cl4Qhp8mMfXm+fPJiTrc52dcZvot/Hx9KRQ==", - "license": "ISC", + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/@aeternity/aepp-calldata/-/aepp-calldata-1.7.0.tgz", + "integrity": "sha512-SxxJI+Z/FcxMNRtxmGWSRzrbRwsLI9fGKNdSWKevxa+QWVVOPF9o8XogCbM5FaW+u15P+O0dSvJWZCuJLQ7S9Q==", "dependencies": { "blakejs": "^1.2.1", "bs58": "^5.0.0", @@ -3330,12 +3329,9 @@ "dev": true }, "node_modules/@types/node": { - "version": "20.11.25", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.11.25.tgz", - "integrity": "sha512-TBHyJxk2b7HceLVGFcpAUjsa5zIdsPWlR6XHfyGzd0SFu+/NFgQgMAl96MSDZgQDvJAvV6BKsFOrt6zIL09JDw==", - "dependencies": { - "undici-types": "~5.26.4" - } + "version": "18.13.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.13.0.tgz", + "integrity": "sha512-gC3TazRzGoOnoKAhUx+Q0t8S9Tzs74z7m0ipwGpSqQrleP14hKxP4/JUeEQcD3W1/aIpnWl8pHowI7WokuZpXg==" }, "node_modules/@types/node-hid": { "version": "1.3.4", @@ -13431,11 +13427,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/undici-types": { - "version": "5.26.5", - "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", - "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==" - }, "node_modules/unicode-canonical-property-names-ecmascript": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-2.0.0.tgz", diff --git a/package.json b/package.json index e5aba82cc6..2078b66406 100644 --- a/package.json +++ b/package.json @@ -75,7 +75,7 @@ "SDK" ], "dependencies": { - "@aeternity/aepp-calldata": "github:aeternity/aepp-calldata-js#8e9c8b8e1b394a01be1c84b13cf76271f7624d38", + "@aeternity/aepp-calldata": "^1.7.0", "@aeternity/argon2": "^0.0.1", "@aeternity/uuid": "^0.0.1", "@azure/core-client": "^1.8.0", @@ -84,7 +84,7 @@ "@ledgerhq/hw-transport": "^6.30.4", "@types/aes-js": "^3.1.4", "@types/json-bigint": "^1.0.4", - "@types/node": "~20.11.25", + "@types/node": "~18.13", "@types/sha.js": "^2.4.4", "@types/uuid": "^9.0.8", "@types/webextension-polyfill": "^0.10.7", diff --git a/src/Middleware.ts b/src/Middleware.ts index 1e1013de2e..4d94f2db6c 100644 --- a/src/Middleware.ts +++ b/src/Middleware.ts @@ -1,6 +1,6 @@ // eslint-disable-next-line max-classes-per-file import BigNumber from 'bignumber.js'; -import { OperationArguments, OperationSpec } from '@azure/core-client'; +import { OperationArguments, OperationOptions, OperationSpec } from '@azure/core-client'; import { userAgentPolicyName, setClientRequestIdPolicyName } from '@azure/core-rest-pipeline'; import { genRequestQueuesPolicy, genCombineGetRequestsPolicy, genErrorFormatterPolicy, @@ -120,10 +120,20 @@ export default class Middleware retryOverallDelay?: number; } = {}, ) { + let version: string | undefined; + const getVersion = async (opts: OperationOptions): Promise => { + if (version != null) return version; + version = (await this.getStatus(opts)).mdwVersion; + return version; + }; + // eslint-disable-next-line constructor-super super(url, { allowInsecureConnection: true, additionalPolicies: [ + ...ignoreVersion ? [] : [ + genVersionCheckPolicy('middleware', getVersion, '1.47.0', '2.0.0'), + ], genRequestQueuesPolicy(), genCombineGetRequestsPolicy(), genRetryOnFailurePolicy(retryCount, retryOverallDelay), @@ -133,16 +143,7 @@ export default class Middleware }); this.pipeline.removePolicy({ name: userAgentPolicyName }); this.pipeline.removePolicy({ name: setClientRequestIdPolicyName }); - if (!ignoreVersion) { - let version: string | undefined; - const getVersion = async (): Promise => { - if (version != null) return version; - version = (await this.getStatus()).mdwVersion; - return version; - }; - this.pipeline.addPolicy( - genVersionCheckPolicy('middleware', '/mdw/v2/status', getVersion, '1.47.0', '2.0.0'), - ); - } + // TODO: use instead our retry policy + this.pipeline.removePolicy({ name: 'defaultRetryPolicy' }); } } diff --git a/src/Node.ts b/src/Node.ts index 601d85493e..80ad2bf019 100644 --- a/src/Node.ts +++ b/src/Node.ts @@ -1,6 +1,6 @@ // eslint-disable-next-line max-classes-per-file import BigNumber from 'bignumber.js'; -import { OperationArguments, OperationSpec } from '@azure/core-client'; +import { OperationArguments, OperationOptions, OperationSpec } from '@azure/core-client'; import { userAgentPolicyName, setClientRequestIdPolicyName } from '@azure/core-rest-pipeline'; import { genRequestQueuesPolicy, genCombineGetRequestsPolicy, genErrorFormatterPolicy, @@ -130,10 +130,14 @@ export default class Node extends (NodeTransformed as unknown as NodeTransformed retryOverallDelay?: number; } = {}, ) { + const getVersion = async (opts: OperationOptions): Promise => ( + (await this._getCachedStatus(opts)).nodeVersion + ); // eslint-disable-next-line constructor-super super(url, { allowInsecureConnection: true, additionalPolicies: [ + ...ignoreVersion ? [] : [genVersionCheckPolicy('node', getVersion, '6.2.0', '7.0.0')], genRequestQueuesPolicy(), genCombineGetRequestsPolicy(), genRetryOnFailurePolicy(retryCount, retryOverallDelay), @@ -145,23 +149,20 @@ export default class Node extends (NodeTransformed as unknown as NodeTransformed }); this.pipeline.removePolicy({ name: userAgentPolicyName }); this.pipeline.removePolicy({ name: setClientRequestIdPolicyName }); - if (!ignoreVersion) { - const getVersion = async (): Promise => (await this._getCachedStatus()).nodeVersion; - this.pipeline.addPolicy( - genVersionCheckPolicy('node', '/v3/status', getVersion, '6.2.0', '7.0.0'), - ); - } + // TODO: use instead our retry policy + this.pipeline.removePolicy({ name: 'defaultRetryPolicy' }); this.intAsString = true; } #cachedStatusPromise?: ReturnType; - async _getCachedStatus(): ReturnType { + async _getCachedStatus(options?: OperationOptions): ReturnType { if (this.#cachedStatusPromise != null) return this.#cachedStatusPromise; - return this.getStatus(); + return this.getStatus(options); } - // @ts-expect-error use code generation to create node class? + // eslint-disable-next-line rulesdir/tsdoc-syntax + /** @ts-expect-error use code generation to create node class? */ override async getStatus( ...args: Parameters['getStatus']> ): ReturnType['getStatus']> { diff --git a/src/contract/compiler/Http.ts b/src/contract/compiler/Http.ts index 5282d7d151..72b5c363a7 100644 --- a/src/contract/compiler/Http.ts +++ b/src/contract/compiler/Http.ts @@ -1,6 +1,7 @@ import { RestError, userAgentPolicyName, setClientRequestIdPolicyName, } from '@azure/core-rest-pipeline'; +import { OperationOptions } from '@azure/core-client'; import { Compiler as CompilerApi, ErrorModel, @@ -31,11 +32,20 @@ export default class CompilerHttp extends CompilerBase { * @param options - Options * @param options.ignoreVersion - Don't check compiler version */ - constructor(compilerUrl: string, { ignoreVersion }: { ignoreVersion?: boolean } = {}) { + constructor(compilerUrl: string, { ignoreVersion = false }: { ignoreVersion?: boolean } = {}) { super(); + + let version: string | undefined; + const getVersion = async (opts: OperationOptions): Promise => { + if (version != null) return version; + version = (await this.api.apiVersion(opts)).apiVersion; + return version; + }; + this.api = new CompilerApi(compilerUrl, { allowInsecureConnection: true, additionalPolicies: [ + ...ignoreVersion ? [] : [genVersionCheckPolicy('compiler', getVersion, '7.3.0', '9.0.0')], genErrorFormatterPolicy((body: GeneralCompilerError | CompilerErrorApi[]) => { let message = ''; if ('reason' in body) { @@ -55,17 +65,6 @@ export default class CompilerHttp extends CompilerBase { }); this.api.pipeline.removePolicy({ name: userAgentPolicyName }); this.api.pipeline.removePolicy({ name: setClientRequestIdPolicyName }); - if (ignoreVersion !== true) { - let version: string | undefined; - const getVersion = async (): Promise => { - if (version != null) return version; - version = (await this.api.apiVersion()).apiVersion; - return version; - }; - this.api.pipeline.addPolicy( - genVersionCheckPolicy('compiler', '/api-version', getVersion, '7.3.0', '9.0.0'), - ); - } } async compileBySourceCode( diff --git a/src/utils/autorest.ts b/src/utils/autorest.ts index 32456cabe9..17de2ce7d6 100644 --- a/src/utils/autorest.ts +++ b/src/utils/autorest.ts @@ -1,5 +1,5 @@ -import { RestError, PipelineResponse, PipelinePolicy } from '@azure/core-rest-pipeline'; -import { AdditionalPolicyConfig, FullOperationResponse } from '@azure/core-client'; +import { RestError, PipelineResponse } from '@azure/core-rest-pipeline'; +import { AdditionalPolicyConfig, FullOperationResponse, OperationOptions } from '@azure/core-client'; import { pause } from './other'; import semverSatisfies from './semver-satisfies'; import { UnsupportedVersionError } from './errors'; @@ -94,18 +94,24 @@ export const genErrorFormatterPolicy = ( export const genVersionCheckPolicy = ( name: string, - ignorePath: string, - versionCb: () => Promise, + versionCb: (options: OperationOptions) => Promise, geVersion: string, ltVersion: string, -): PipelinePolicy => ({ - name: 'version-check', - async sendRequest(request, next) { - if (new URL(request.url).pathname === ignorePath) return next(request); - const args = [await versionCb(), geVersion, ltVersion] as const; - if (!semverSatisfies(...args)) throw new UnsupportedVersionError(name, ...args); - return next(request); +): AdditionalPolicyConfig => ({ + policy: { + name: 'version-check', + async sendRequest(request, next) { + if (request.headers.has('__version-check')) { + request.headers.delete('__version-check'); + return next(request); + } + const options = { requestOptions: { customHeaders: { '__version-check': 'true' } } }; + const args = [await versionCb(options), geVersion, ltVersion] as const; + if (!semverSatisfies(...args)) throw new UnsupportedVersionError(name, ...args); + return next(request); + }, }, + position: 'perCall', }); export const genRetryOnFailurePolicy = ( diff --git a/test/integration/AeSdkMethods.ts b/test/integration/AeSdkMethods.ts index 0536e7dd54..7c861d389d 100644 --- a/test/integration/AeSdkMethods.ts +++ b/test/integration/AeSdkMethods.ts @@ -56,31 +56,29 @@ describe('AeSdkMethods', () => { { policy: { name: 'decompressResponsePolicy' }, options: {} }, { policy: { name: 'formDataPolicy' }, options: { beforePolicies: ['multipartPolicy'] } }, { policy: { name: 'multipartPolicy' }, options: { afterPhase: 'Deserialize' } }, - { policy: { name: 'defaultRetryPolicy' }, options: { phase: 'Retry' } }, { policy: { name: 'tracingPolicy' }, options: { afterPhase: 'Retry' } }, { policy: { name: 'redirectPolicy' }, options: { afterPhase: 'Retry' } }, { policy: { name: 'logPolicy' }, options: { afterPhase: 'Sign' } }, { policy: { name: 'serializationPolicy' }, options: { phase: 'Serialize' } }, { policy: { name: 'deserializationPolicy' }, options: { phase: 'Deserialize' } }, + { policy: { name: 'version-check' }, options: {} }, { policy: { name: 'request-queues' }, options: {} }, { policy: { name: 'combine-get-requests' }, options: {} }, { policy: { name: 'retry-on-failure' }, options: {} }, { policy: { name: 'error-formatter' }, options: {} }, - { policy: { name: 'version-check' }, options: {} }, ], _orderedPolicies: [ { name: 'serializationPolicy' }, { name: 'proxyPolicy' }, { name: 'decompressResponsePolicy' }, { name: 'formDataPolicy' }, + { name: 'version-check' }, { name: 'request-queues' }, { name: 'combine-get-requests' }, { name: 'retry-on-failure' }, { name: 'error-formatter' }, - { name: 'version-check' }, { name: 'deserializationPolicy' }, { name: 'multipartPolicy' }, - { name: 'defaultRetryPolicy' }, { name: 'tracingPolicy' }, { name: 'redirectPolicy' }, { name: 'logPolicy' }, @@ -107,16 +105,16 @@ describe('AeSdkMethods', () => { { policy: { name: 'logPolicy' }, options: { afterPhase: 'Sign' } }, { policy: { name: 'serializationPolicy' }, options: { phase: 'Serialize' } }, { policy: { name: 'deserializationPolicy' }, options: { phase: 'Deserialize' } }, - { policy: { name: 'error-formatter' }, options: {} }, { policy: { name: 'version-check' }, options: {} }, + { policy: { name: 'error-formatter' }, options: {} }, ], _orderedPolicies: [ { name: 'serializationPolicy' }, { name: 'proxyPolicy' }, { name: 'decompressResponsePolicy' }, { name: 'formDataPolicy' }, - { name: 'error-formatter' }, { name: 'version-check' }, + { name: 'error-formatter' }, { name: 'deserializationPolicy' }, { name: 'multipartPolicy' }, { name: 'defaultRetryPolicy' }, diff --git a/test/integration/aens.ts b/test/integration/aens.ts index 8c1a45209e..c1f4b21761 100644 --- a/test/integration/aens.ts +++ b/test/integration/aens.ts @@ -80,7 +80,7 @@ describe('Aens', () => { expect(claimed.extendTtl).to.be.a('function'); assertNotNull(claimed.tx); assertNotNull(claimed.signatures); - expect(claimed.tx.fee).to.satisfy((fee: bigint) => fee >= 16960000000000n); + expect(claimed.tx.fee).to.satisfy((fee: bigint) => fee >= 16940000000000n); expect(claimed.tx.fee).to.satisfy((fee: bigint) => fee < 17100000000000n); expect(claimed).to.be.eql({ tx: {