@@ -5,7 +5,7 @@ import { createClient } from 'polkadot-api';
55import { getSmProvider } from 'polkadot-api/sm-provider' ;
66import { cryptoWaitReady } from '@polkadot/util-crypto' ;
77import { 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' ;
99import { cidFromBytes } from "./cid_dag_metadata.js" ;
1010import { bulletin } from './.papi/descriptors/dist/index.mjs' ;
1111
@@ -95,10 +95,12 @@ async function createSmoldotClient(chainSpecPath, parachainSpecPath = null) {
9595async 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