Skip to content

Commit

Permalink
Merge pull request #1972 from aeternity/feature/prerelease-fixes
Browse files Browse the repository at this point in the history
Prerelease fixes
  • Loading branch information
davidyuk authored Apr 4, 2024
2 parents 8ed6634 + 677bcf5 commit df2d76c
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 77 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
name: Test & build
on: [pull_request]
on:
push:
branches:
master
develop
pull_request:
jobs:
main:
runs-on: ubuntu-22.04
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion commitlint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ module.exports = {
'compiler',
'contract',
'middleware',
'docs', // TODO: remove after releasing 13.1.0
'deps',
'deps-dev',
'node',
Expand All @@ -24,4 +23,5 @@ module.exports = {
],
],
},
ignores: [(message) => /^Bumps \[.+]\(.+\) from .+ to .+\.$/m.test(message)],
};
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
25 changes: 8 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
25 changes: 13 additions & 12 deletions src/Middleware.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -120,10 +120,20 @@ export default class Middleware
retryOverallDelay?: number;
} = {},
) {
let version: string | undefined;
const getVersion = async (opts: OperationOptions): Promise<string> => {
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),
Expand All @@ -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<string> => {
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' });
}
}
21 changes: 11 additions & 10 deletions src/Node.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -130,10 +130,14 @@ export default class Node extends (NodeTransformed as unknown as NodeTransformed
retryOverallDelay?: number;
} = {},
) {
const getVersion = async (opts: OperationOptions): Promise<string> => (
(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),
Expand All @@ -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<string> => (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<Node['getStatus']>;

async _getCachedStatus(): ReturnType<Node['getStatus']> {
async _getCachedStatus(options?: OperationOptions): ReturnType<Node['getStatus']> {
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<InstanceType<NodeTransformedApi>['getStatus']>
): ReturnType<InstanceType<NodeTransformedApi>['getStatus']> {
Expand Down
23 changes: 11 additions & 12 deletions src/contract/compiler/Http.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
RestError, userAgentPolicyName, setClientRequestIdPolicyName,
} from '@azure/core-rest-pipeline';
import { OperationOptions } from '@azure/core-client';
import {
Compiler as CompilerApi,
ErrorModel,
Expand Down Expand Up @@ -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<string> => {
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) {
Expand All @@ -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<string> => {
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(
Expand Down
28 changes: 17 additions & 11 deletions src/utils/autorest.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -94,18 +94,24 @@ export const genErrorFormatterPolicy = (

export const genVersionCheckPolicy = (
name: string,
ignorePath: string,
versionCb: () => Promise<string>,
versionCb: (options: OperationOptions) => Promise<string>,
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 = (
Expand Down
10 changes: 4 additions & 6 deletions test/integration/AeSdkMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand All @@ -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' },
Expand Down
2 changes: 1 addition & 1 deletion test/integration/aens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit df2d76c

Please sign in to comment.