Skip to content
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
"test:api-specs-multichain": "SELENIUM_BROWSER=chrome tsx test/e2e/run-api-specs-multichain.ts",
"test:e2e:benchmark": "yarn tsx test/e2e/benchmarks/run-benchmark.ts",
"test:e2e:pw:report": "yarn playwright show-report public/playwright/playwright-reports/html",
"test:e2e:smoke:local-node-ports": "tsx test/e2e/scripts/smoke-local-node-ports.ts",
"test:e2e:feature-flag:coverage": "tsx test/e2e/scripts/feature-flag-coverage-report.ts",
"test:e2e:chrome:rpc": "SELENIUM_BROWSER=chrome tsx test/e2e/run-all.mts --rpc",
"test:e2e:chrome:multi-provider": "MULTIPROVIDER=true SELENIUM_BROWSER=chrome tsx test/e2e/run-all.mts --multi-provider",
Expand Down
10 changes: 9 additions & 1 deletion test/e2e/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,14 @@ async function withFixtures(options, testSuite) {
localNodes.push(localNode);
break;

case 'tron':
// eslint-disable-next-line n/global-require, no-case-declarations -- load this module conditionally
const { TronNode } = require('./seeder/tron/node');
localNode = new TronNode();
await localNode.start(nodeOptions);
localNodes.push(localNode);
break;

Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
case 'none':
break;

Expand Down Expand Up @@ -407,7 +415,7 @@ async function withFixtures(options, testSuite) {
let effectiveUnifiedEvmAccountsApiBalances =
unifiedEvmAccountsApiBalances ?? {};
const localChainId = localNodeOptsNormalized[0]?.options.chainId ?? 1337;
if (localNodes[0]) {
if (localNodes[0] && localNodeOptsNormalized[0]?.type === 'anvil') {
const nodeBalance = Number(
(await localNodes[0].getBalance()).toFixed(3),
).toString();
Expand Down
104 changes: 104 additions & 0 deletions test/e2e/scripts/smoke-local-node-ports.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import { getAvailablePorts } from '../seeder/ports';
import { TronNode } from '../seeder/tron/node';

type TronBlockResponse = Partial<
Record<
'block_header',
Partial<Record<'raw_data', { number?: number | string }>>
>
>;

async function main(): Promise<void> {
const [firstFullNodePort, secondFullNodePort] =
await getAvailablePortsWithGaps(2);
const ports = [
{ fullNodePort: firstFullNodePort },
{ fullNodePort: secondFullNodePort },
] as const;
const nodes = [new TronNode(), new TronNode()] as const;

console.log(
`Starting two java-tron private networks on ${formatNodeUrls(
ports.map(({ fullNodePort }) => fullNodePort),
)}`,
);

try {
await startAll(
nodes.map((node, index) => () => node.start({ ports: ports[index] })),
);

const blocks = await Promise.all(
nodes.map(
(node) =>
node.fetchJson('/wallet/getnowblock', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: '{}',
}) as Promise<TronBlockResponse>,
),
);
console.log(
`Tron smoke passed: ${blocks
.map(
(block, index) =>
`node ${index + 1} block ${
block.block_header?.raw_data?.number ?? 'unknown'
}`,
)
.join(', ')}`,
);
} finally {
await quitAll(nodes);
}
}

async function getAvailablePortsWithGaps(
count: number,
gapSize = 8,
): Promise<number[]> {
const ports: number[] = [];
const excludedPorts = new Set<number>();

while (ports.length < count) {
const [port] = await getAvailablePorts(1, excludedPorts);
ports.push(port);

for (let offset = -gapSize; offset <= gapSize; offset += 1) {
const excludedPort = port + offset;
if (excludedPort >= 1 && excludedPort <= 65_535) {
excludedPorts.add(excludedPort);
}
}
}

return ports;
}

async function startAll(starts: (() => Promise<void>)[]): Promise<void> {
for (const start of starts) {
await start();
}
}

async function quitAll(
nodes: readonly { quit: () => Promise<void> }[],
): Promise<void> {
const results = await Promise.allSettled(nodes.map((node) => node.quit()));
const failure = results.find(
(result): result is PromiseRejectedResult => result.status === 'rejected',
);

if (failure) {
throw failure.reason;
}
}

function formatNodeUrls(ports: readonly number[]): string {
return ports.map((port) => `127.0.0.1:${port}`).join(' and ');
}

main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
Loading