Skip to content

Commit eb898e5

Browse files
committed
unified JS logging and justfile echoing
1 parent 02023c0 commit eb898e5

File tree

8 files changed

+146
-286
lines changed

8 files changed

+146
-286
lines changed

docs/rust-setup.md

Lines changed: 0 additions & 225 deletions
This file was deleted.

examples/authorize_and_store_papi.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { createClient } from 'polkadot-api';
33
import { getWsProvider } from 'polkadot-api/ws-provider';
44
import { cryptoWaitReady } from '@polkadot/util-crypto';
55
import { authorizeAccount, fetchCid, store, TX_MODE_FINALIZED_BLOCK } from './api.js';
6-
import { setupKeyringAndSigners } from './common.js';
6+
import { setupKeyringAndSigners, logHeader, logConnection, logSuccess, logError, logTestResult } from './common.js';
77
import { cidFromBytes } from "./cid_dag_metadata.js";
88
import { bulletin } from './.papi/descriptors/dist/index.mjs';
99

@@ -16,9 +16,8 @@ const HTTP_IPFS_API = args[2] || 'http://127.0.0.1:8080';
1616
async function main() {
1717
await cryptoWaitReady();
1818

19-
console.log(`Connecting to: ${NODE_WS}`);
20-
console.log(`Using seed: ${SEED}`);
21-
console.log(`Using IPFS API: ${HTTP_IPFS_API}`);
19+
logHeader('AUTHORIZE AND STORE TEST (WebSocket)');
20+
logConnection(NODE_WS, SEED, HTTP_IPFS_API);
2221

2322
let client, resultCode;
2423
try {
@@ -45,11 +44,11 @@ async function main() {
4544

4645
// Store data.
4746
const { cid } = await store(bulletinAPI, whoSigner, dataToStore);
48-
console.log("✅ Data stored successfully with CID:", cid);
47+
logSuccess(`Data stored successfully with CID: ${cid}`);
4948

5049
// Read back from IPFS
5150
let downloadedContent = await fetchCid(HTTP_IPFS_API, cid);
52-
console.log("✅ Downloaded content:", downloadedContent.toString());
51+
logSuccess(`Downloaded content: ${downloadedContent.toString()}`);
5352
assert.deepStrictEqual(
5453
cid,
5554
expectedCid,
@@ -60,12 +59,13 @@ async function main() {
6059
downloadedContent.toString(),
6160
'❌ dataToStore does not match downloadedContent!'
6261
);
63-
console.log(`✅ Verified content!`);
62+
logSuccess('Verified content!');
6463

65-
console.log(`\n\n\n✅✅✅ Test passed! ✅✅✅`);
64+
logTestResult(true, 'Authorize and Store Test');
6665
resultCode = 0;
6766
} catch (error) {
68-
console.error("❌ Error:", error);
67+
logError(`Error: ${error.message}`);
68+
console.error(error);
6969
resultCode = 1;
7070
} finally {
7171
if (client) client.destroy();

examples/authorize_and_store_papi_smoldot.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { createClient } from 'polkadot-api';
55
import { getSmProvider } from 'polkadot-api/sm-provider';
66
import { cryptoWaitReady } from '@polkadot/util-crypto';
77
import { authorizeAccount, fetchCid, store } from './api.js';
8-
import { setupKeyringAndSigners, waitForChainReady } from './common.js';
8+
import { setupKeyringAndSigners, waitForChainReady, logHeader, logConfig, logSuccess, logError, logTestResult } from './common.js';
99
import { cidFromBytes } from "./cid_dag_metadata.js";
1010
import { bulletin } from './.papi/descriptors/dist/index.mjs';
1111

@@ -95,10 +95,12 @@ async function createSmoldotClient(chainSpecPath, parachainSpecPath = null) {
9595
async function main() {
9696
await cryptoWaitReady();
9797

98+
logHeader('AUTHORIZE AND STORE TEST (Smoldot Light Client)');
99+
98100
// Get chainspec path from command line argument (required - main chain: relay for para, or solo)
99101
const chainSpecPath = process.argv[2];
100102
if (!chainSpecPath) {
101-
console.error('❌ Error: Chain spec path is required as first argument');
103+
logError('Chain spec path is required as first argument');
102104
console.error('Usage: node authorize_and_store_papi_smoldot.js <chain-spec-path> [parachain-spec-path] [ipfs-api-url]');
103105
console.error(' For parachains: <relay-chain-spec-path> <parachain-spec-path> [ipfs-api-url]');
104106
console.error(' For solochains: <solo-chain-spec-path> [ipfs-api-url]');
@@ -110,7 +112,12 @@ async function main() {
110112
// Optional IPFS API URL
111113
const HTTP_IPFS_API = process.argv[4] || 'http://127.0.0.1:8080';
112114

113-
console.log(`Using IPFS API: ${HTTP_IPFS_API}`);
115+
logConfig({
116+
'Mode': 'Smoldot Light Client',
117+
'Chain Spec': chainSpecPath,
118+
'Parachain Spec': parachainSpecPath || 'N/A (solochain)',
119+
'IPFS API': HTTP_IPFS_API
120+
});
114121

115122
let sd, client, resultCode;
116123
try {
@@ -143,11 +150,11 @@ async function main() {
143150

144151
// Store data.
145152
const { cid } = await store(bulletinAPI, whoSigner, dataToStore);
146-
console.log("✅ Data stored successfully with CID:", cid);
153+
logSuccess(`Data stored successfully with CID: ${cid}`);
147154

148155
// Read back from IPFS
149156
let downloadedContent = await fetchCid(HTTP_IPFS_API, cid);
150-
console.log("✅ Downloaded content:", downloadedContent.toString());
157+
logSuccess(`Downloaded content: ${downloadedContent.toString()}`);
151158
assert.deepStrictEqual(
152159
cid,
153160
expectedCid,
@@ -158,12 +165,13 @@ async function main() {
158165
downloadedContent.toString(),
159166
'❌ dataToStore does not match downloadedContent!'
160167
);
161-
console.log(`✅ Verified content!`);
168+
logSuccess('Verified content!');
162169

163-
console.log(`\n\n\n✅✅✅ Test passed! ✅✅✅`);
170+
logTestResult(true, 'Authorize and Store Test (Smoldot)');
164171
resultCode = 0;
165172
} catch (error) {
166-
console.error("❌ Error:", error);
173+
logError(`Error: ${error.message}`);
174+
console.error(error);
167175
resultCode = 1;
168176
} finally {
169177
if (client) client.destroy();

0 commit comments

Comments
 (0)