Skip to content

Commit

Permalink
Merge pull request #1964 from aeternity/feature/devmode-in-tests
Browse files Browse the repository at this point in the history
Use devmode in tests
  • Loading branch information
davidyuk authored Mar 19, 2024
2 parents df700c4 + 710ca6e commit cc2b2f9
Show file tree
Hide file tree
Showing 25 changed files with 290 additions and 91 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ 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
- run: chmod 666 ./docker/accounts-pub.json
- run: docker compose up -d --wait
- run: npx nyc npm run test
- run: npx nyc report --reporter=text-lcov > coverage.lcov
Expand Down
25 changes: 16 additions & 9 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,36 @@
version: '3'
services:
node:
image: aeternity/aeternity:master@sha256:4ab3f2e33f02b0b96a0cb1b16544cd62498d0b4b983ba74e12b2564f2b908834
hostname: node
ports: ["3013:3013", "3113:3113", "3014:3014", "3114:3114"]
# TODO: switch to master after merging https://github.com/aeternity/aeternity/pull/4303
image: aeternity/aeternity:master-bundle@sha256:54eefa1204b631dd477e3928b50e4449750a7c0e06b53eda4cf1493835b08caa
# 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
healthcheck:
interval: 2s
volumes:
- ./docker/aeternity_node_mean16.yaml:/home/aeternity/node/aeternity.yaml
- ./docker/accounts_test.json:/home/aeternity/node/data/aecore/.genesis/accounts_test.json
- ./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
- ./docker/accounts-pub.json:/home/aeternity/node/data/aeplugin_dev_mode/devmode_prefunded_accounts-PUB.json
stop_grace_period: 0s

emitter:
build: test/emitter
depends_on:
node:
condition: service_healthy

compiler:
image: aeternity/aesophia_http:v8.0.0-rc1
hostname: compiler
ports: ["3080:3080"]
ports: [3080:3080]
# TODO: remove after releasing https://github.com/aeternity/aesophia_http/pull/133
healthcheck:
interval: 2s

compiler-7:
image: aeternity/aesophia_http:v7.6.1
hostname: compiler-7
ports: ["3081:3080"]
ports: [3081:3080]
# TODO: remove after releasing https://github.com/aeternity/aesophia_http/pull/133
healthcheck:
interval: 2s
1 change: 1 addition & 0 deletions docker/accounts-pub.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"ak_21A27UVVt3hDkBE5J7rhhqnH5YNb4Y1dqo4PnSybrH85pnWo7E":10000000000000000000000}
6 changes: 6 additions & 0 deletions docker/accounts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[{
"pub_key": "ak_21A27UVVt3hDkBE5J7rhhqnH5YNb4Y1dqo4PnSybrH85pnWo7E",
"initial_balance": 10000000000000000000000,
"// TODO: encode using base58 after fixing": "https://github.com/aeternity/aeplugin_dev_mode/issues/32",
"priv_key": "sk_nr177aDHmvcqQuzjghpW7/FjWbbfN2zwSa7plVZfAi+hhfna"
}]
3 changes: 0 additions & 3 deletions docker/accounts_test.json

This file was deleted.

21 changes: 21 additions & 0 deletions docker/aeternity.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# yaml-language-server: $schema=https://github.com/aeternity/aeternity/raw/master/apps/aeutils/priv/aeternity_config_schema.json

system:
dev_mode: true
plugins:
# TODO: remove after merging https://github.com/aeternity/aeternity/pull/4303
- name: aeplugin_dev_mode

http:
internal:
debug_endpoints: true
listen_address: 0.0.0.0
endpoints:
dry-run: true

websocket:
channel:
listen_address: 0.0.0.0

chain:
persist: false
37 changes: 0 additions & 37 deletions docker/aeternity_node_mean16.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion docs/transaction-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ These options are common and can be provided to every tx-type:
- The strategy to obtain next nonce for an account via node API
- If set to `max`, then the greatest nonce seen in the account or currently in the transaction pool is incremented with 1 and returned.
If the strategy is set to `continuity`, then transactions in the mempool are checked if there are gaps - missing nonces that prevent transactions with greater nonces to get included
- `ttl` (default: `0`)
- `ttl` (default: `0` if `buildTx` used, current height + `3` otherwise)
- Should be set if you want the transaction to be only valid until a certain block height is reached.
- `fee` (default: calculated for each tx-type, based on network demand)
- The minimum fee is dependent on the tx-type.
Expand Down
10 changes: 7 additions & 3 deletions src/Middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,14 @@ export default class Middleware
this.pipeline.removePolicy({ name: userAgentPolicyName });
this.pipeline.removePolicy({ name: setClientRequestIdPolicyName });
if (!ignoreVersion) {
const statusPromise = this.getStatus();
const versionPromise = statusPromise.then(({ mdwVersion }) => mdwVersion, (error) => error);
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', '/v2/status', versionPromise, '1.47.0', '2.0.0'),
genVersionCheckPolicy('middleware', '/mdw/v2/status', getVersion, '1.47.0', '2.0.0'),
);
}
}
Expand Down
9 changes: 4 additions & 5 deletions src/Node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,9 @@ export default class Node extends (NodeTransformed as unknown as NodeTransformed
this.pipeline.removePolicy({ name: userAgentPolicyName });
this.pipeline.removePolicy({ name: setClientRequestIdPolicyName });
if (!ignoreVersion) {
const versionPromise = this._getCachedStatus()
.then(({ nodeVersion }) => nodeVersion, (error) => error);
const getVersion = async (): Promise<string> => (await this._getCachedStatus()).nodeVersion;
this.pipeline.addPolicy(
genVersionCheckPolicy('node', '/v3/status', versionPromise, '6.2.0', '7.0.0'),
genVersionCheckPolicy('node', '/v3/status', getVersion, '6.2.0', '7.0.0'),
);
}
this.intAsString = true;
Expand All @@ -158,8 +157,8 @@ export default class Node extends (NodeTransformed as unknown as NodeTransformed
#cachedStatusPromise?: ReturnType<Node['getStatus']>;

async _getCachedStatus(): ReturnType<Node['getStatus']> {
this.#cachedStatusPromise ??= this.getStatus();
return this.#cachedStatusPromise;
if (this.#cachedStatusPromise != null) return this.#cachedStatusPromise;
return this.getStatus();
}

// @ts-expect-error use code generation to create node class?
Expand Down
10 changes: 7 additions & 3 deletions src/contract/compiler/Http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,14 @@ export default class CompilerHttp extends CompilerBase {
this.api.pipeline.removePolicy({ name: userAgentPolicyName });
this.api.pipeline.removePolicy({ name: setClientRequestIdPolicyName });
if (ignoreVersion !== true) {
const versionPromise = this.api.apiVersion()
.then(({ apiVersion }) => apiVersion, (error) => error);
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', versionPromise, '7.3.0', '9.0.0'),
genVersionCheckPolicy('compiler', '/api-version', getVersion, '7.3.0', '9.0.0'),
);
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/utils/autorest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,14 @@ export const genErrorFormatterPolicy = (
export const genVersionCheckPolicy = (
name: string,
ignorePath: string,
versionPromise: Promise<string | Error>,
versionCb: () => 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 version = await versionPromise;
if (version instanceof Error) throw version;
const args = [version, geVersion, ltVersion] as const;
const args = [await versionCb(), geVersion, ltVersion] as const;
if (!semverSatisfies(...args)) throw new UnsupportedVersionError(name, ...args);
return next(request);
},
Expand Down
23 changes: 11 additions & 12 deletions test/dynamic-gas-price.html → test/charts/dynamic-gas-price.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<html>
<head>
<title>Run several clients and render stats</title>
<title>Dynamic gas price</title>
</head>
<body>

Expand Down Expand Up @@ -48,31 +48,26 @@
}
</style>

<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js@4"></script>
<script src="../../dist/aepp-sdk.browser-script.js"></script>
<script type="text/javascript">
const commonOptions = {
type: 'line',
plugins: {
colors: {
forceOverride: true
}
},
};

const [chartGasPrice, chartUtilization, chartOverallGas, chartOperationCount] = [
'chart-gas-price', 'chart-utilization', 'chart-overall-gas', 'chart-operation-count',
].map((id) => new Chart(document.getElementById(id), {
type: 'line',
data: {
labels: [],
datasets: [],
}
},
options: {
animation: false,
},
}));

chartOverallGas.data.datasets[0] = {
label: 'Overall used gas',
data: [],
pointStyle: false,
};

const { Node, AeSdk, MemoryAccount, CompilerHttp, MIN_GAS_PRICE } = Aeternity;
Expand Down Expand Up @@ -171,11 +166,13 @@
label: `client ${idx}`,
borderColor: colorDark,
data: new Array(chartGasPrice.data.labels.length).fill(minGasPriceToShow),
pointStyle: false,
});
chartOperationCount.data.datasets.push({
label: `client ${idx} mined`,
borderColor: colorDark,
data: new Array(chartOperationCount.data.labels.length).fill(-1),
pointStyle: false,
}, {
label: `client ${idx} failed`,
borderColor: colorLight,
Expand Down Expand Up @@ -243,10 +240,12 @@
chartGasPrice.data.datasets.push({
label: `node ${minutes} min`,
data: [],
pointStyle: false,
});
chartUtilization.data.datasets.push({
label: `node ${minutes} min`,
data: [],
pointStyle: false,
});
});

Expand Down
Loading

0 comments on commit cc2b2f9

Please sign in to comment.