Skip to content

Commit 02023c0

Browse files
committed
parametrised all the examples
1 parent e50dcf7 commit 02023c0

File tree

5 files changed

+76
-33
lines changed

5 files changed

+76
-33
lines changed

examples/authorize_and_store_papi.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,18 @@ import { setupKeyringAndSigners } from './common.js';
77
import { cidFromBytes } from "./cid_dag_metadata.js";
88
import { bulletin } from './.papi/descriptors/dist/index.mjs';
99

10-
// Command line arguments: [ws_url] [seed]
10+
// Command line arguments: [ws_url] [seed] [ipfs_api_url]
1111
const args = process.argv.slice(2);
1212
const NODE_WS = args[0] || 'ws://localhost:10000';
1313
const SEED = args[1] || '//Alice';
14-
const HTTP_IPFS_API = 'http://127.0.0.1:8080' // Local IPFS HTTP gateway
14+
const HTTP_IPFS_API = args[2] || 'http://127.0.0.1:8080';
1515

1616
async function main() {
1717
await cryptoWaitReady();
1818

1919
console.log(`Connecting to: ${NODE_WS}`);
2020
console.log(`Using seed: ${SEED}`);
21+
console.log(`Using IPFS API: ${HTTP_IPFS_API}`);
2122

2223
let client, resultCode;
2324
try {

examples/authorize_and_store_papi_smoldot.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import { bulletin } from './.papi/descriptors/dist/index.mjs';
1313
// Increased sync time for parachain mode where smoldot needs more time to sync relay + para
1414
const SYNC_WAIT_SEC = 30;
1515
const SMOLDOT_LOG_LEVEL = 3; // 0=off, 1=error, 2=warn, 3=info, 4=debug, 5=trace
16-
const HTTP_IPFS_API = 'http://127.0.0.1:8080' // Local IPFS HTTP gateway
1716

1817
const TCP_BOOTNODE_REGEX = /^(\/ip[46]\/[^/]+)\/tcp\/(\d+)\/p2p\/(.+)$/;
1918
const WS_BOOTNODE_REGEX = /\/tcp\/\d+\/ws\/p2p\//;
@@ -95,19 +94,23 @@ async function createSmoldotClient(chainSpecPath, parachainSpecPath = null) {
9594

9695
async function main() {
9796
await cryptoWaitReady();
98-
97+
9998
// Get chainspec path from command line argument (required - main chain: relay for para, or solo)
10099
const chainSpecPath = process.argv[2];
101100
if (!chainSpecPath) {
102101
console.error('❌ Error: Chain spec path is required as first argument');
103-
console.error('Usage: node authorize_and_store_papi_smoldot.js <chain-spec-path> [parachain-spec-path]');
104-
console.error(' For parachains: <relay-chain-spec-path> <parachain-spec-path>');
105-
console.error(' For solochains: <solo-chain-spec-path>');
102+
console.error('Usage: node authorize_and_store_papi_smoldot.js <chain-spec-path> [parachain-spec-path] [ipfs-api-url]');
103+
console.error(' For parachains: <relay-chain-spec-path> <parachain-spec-path> [ipfs-api-url]');
104+
console.error(' For solochains: <solo-chain-spec-path> [ipfs-api-url]');
106105
process.exit(1);
107106
}
108-
107+
109108
// Optional parachain chainspec path (only needed for parachains)
110109
const parachainSpecPath = process.argv[3] || null;
110+
// Optional IPFS API URL
111+
const HTTP_IPFS_API = process.argv[4] || 'http://127.0.0.1:8080';
112+
113+
console.log(`Using IPFS API: ${HTTP_IPFS_API}`);
111114

112115
let sd, client, resultCode;
113116
try {

examples/authorize_preimage_and_store_papi.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ import { setupKeyringAndSigners, getContentHash } from './common.js';
77
import { cidFromBytes } from "./cid_dag_metadata.js";
88
import { bulletin } from './.papi/descriptors/dist/index.mjs';
99

10-
const NODE_WS = 'ws://localhost:10000';
11-
const HTTP_IPFS_API = 'http://127.0.0.1:8080' // Local IPFS HTTP gateway
10+
// Command line arguments: [ws_url] [seed] [ipfs_api_url]
11+
const args = process.argv.slice(2);
12+
const NODE_WS = args[0] || 'ws://localhost:10000';
13+
const SEED = args[1] || '//Alice';
14+
const HTTP_IPFS_API = args[2] || 'http://127.0.0.1:8080';
1215

1316
/**
1417
* Run a preimage authorization + store test.
@@ -82,14 +85,18 @@ async function runPreimageStoreTest(testName, bulletinAPI, sudoSigner, signer, s
8285
async function main() {
8386
await cryptoWaitReady();
8487

88+
console.log(`Connecting to: ${NODE_WS}`);
89+
console.log(`Using seed: ${SEED}`);
90+
console.log(`Using IPFS API: ${HTTP_IPFS_API}`);
91+
8592
let client, resultCode;
8693
try {
8794
// Init WS PAPI client and typed api.
8895
client = createClient(getWsProvider(NODE_WS));
8996
const bulletinAPI = client.getTypedApi(bulletin);
9097

9198
// Signers.
92-
const { sudoSigner, whoSigner, whoAddress } = setupKeyringAndSigners('//Alice', '//Preimagesigner');
99+
const { sudoSigner, whoSigner, whoAddress } = setupKeyringAndSigners(SEED, '//Preimagesigner');
93100

94101
// Test 1: Unsigned store with preimage auth (default CID config)
95102
await runPreimageStoreTest(

examples/justfile

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,10 @@ stop-services test_dir:
390390
# test_dir - Test directory where services are running
391391
# runtime - Runtime name for smoldot chainspec path resolution
392392
# mode - Connection mode: "ws" (WebSocket RPC node) or "smoldot" (light client)
393-
run-test-authorize-and-store test_dir runtime mode="ws":
393+
# ws_url - WebSocket URL (default: ws://localhost:10000, only used in ws mode)
394+
# seed - Account seed phrase or dev seed (default: //Alice, only used in ws mode)
395+
# ipfs_api_url - IPFS API URL (default: http://127.0.0.1:8080)
396+
run-test-authorize-and-store test_dir runtime mode="ws" ws_url="ws://localhost:10000" seed="//Alice" ipfs_api_url="http://127.0.0.1:8080":
394397
#!/usr/bin/env bash
395398
set -e
396399

@@ -399,34 +402,43 @@ run-test-authorize-and-store test_dir runtime mode="ws":
399402
SCRIPT_NAME="authorize_and_store_papi_smoldot.js"
400403
elif [ "{{ mode }}" = "ws" ]; then
401404
echo "🧪 Running authorize and store test (mode: ws, runtime: {{ runtime }})..."
405+
echo " WS URL: {{ ws_url }}"
406+
echo " Seed: {{ seed }}"
407+
echo " IPFS API: {{ ipfs_api_url }}"
402408
SCRIPT_NAME="authorize_and_store_papi.js"
403409
else
404410
echo "❌ Error: Invalid mode '{{ mode }}'. Must be 'ws' or 'smoldot'"
405411
exit 1
406412
fi
407413

408-
# Run the script with chainspec_path parameter only for smoldot mode
414+
# Run the script with parameters
409415
if [ "{{ mode }}" = "smoldot" ]; then
410416
if [ "{{ runtime }}" = "bulletin-westend-runtime" ]; then
411417
RELAY_CHAINSPEC_PATH="{{ test_dir }}/bob/cfg/westend-local.json"
412418
PARACHAIN_CHAINSPEC_PATH="{{ test_dir }}/bulletin-westend-collator-2/cfg/westend-local-2487.json"
413-
node $SCRIPT_NAME "$RELAY_CHAINSPEC_PATH" "$PARACHAIN_CHAINSPEC_PATH"
419+
node $SCRIPT_NAME "$RELAY_CHAINSPEC_PATH" "$PARACHAIN_CHAINSPEC_PATH" "{{ ipfs_api_url }}"
414420
else
415421
CHAINSPEC_PATH="{{ test_dir }}/bob/cfg/bulletin-polkadot-local.json"
416-
node $SCRIPT_NAME "$CHAINSPEC_PATH"
422+
node $SCRIPT_NAME "$CHAINSPEC_PATH" "{{ ipfs_api_url }}"
417423
fi
418424
else
419-
node $SCRIPT_NAME
425+
node $SCRIPT_NAME "{{ ws_url }}" "{{ seed }}" "{{ ipfs_api_url }}"
420426
fi
421427

422428
# Run store-chunked-data test only (services must already be running via start-services)
423429
# Parameters:
424430
# test_dir - Test directory where services are running
425-
run-test-store-chunked-data test_dir:
431+
# ws_url - WebSocket URL of the Bulletin chain node (default: ws://localhost:10000)
432+
# seed - Account seed phrase or dev seed (default: //Alice)
433+
# ipfs_api_url - IPFS API URL (default: http://127.0.0.1:8080)
434+
run-test-store-chunked-data test_dir ws_url="ws://localhost:10000" seed="//Alice" ipfs_api_url="http://127.0.0.1:8080":
426435
#!/usr/bin/env bash
427436
set -e
428437
echo "🧪 Running store chunked data test (test_dir: {{ test_dir }})..."
429-
node store_chunked_data.js
438+
echo " WS URL: {{ ws_url }}"
439+
echo " Seed: {{ seed }}"
440+
echo " IPFS API: {{ ipfs_api_url }}"
441+
node store_chunked_data.js "{{ ws_url }}" "{{ seed }}" "{{ ipfs_api_url }}"
430442

431443
# Run store-big-data test only (services must already be running via start-services)
432444
# Parameters:
@@ -446,11 +458,17 @@ run-test-store-big-data test_dir ws_url="ws://localhost:10000" seed="//Alice" ip
446458
# Run authorize-preimage-and-store test only (services must already be running via start-services)
447459
# Parameters:
448460
# test_dir - Test directory where services are running
449-
run-test-authorize-preimage-and-store test_dir:
461+
# ws_url - WebSocket URL of the Bulletin chain node (default: ws://localhost:10000)
462+
# seed - Account seed phrase or dev seed (default: //Alice)
463+
# ipfs_api_url - IPFS API URL (default: http://127.0.0.1:8080)
464+
run-test-authorize-preimage-and-store test_dir ws_url="ws://localhost:10000" seed="//Alice" ipfs_api_url="http://127.0.0.1:8080":
450465
#!/usr/bin/env bash
451466
set -e
452467
echo "🧪 Running authorize preimage and store test (test_dir: {{ test_dir }})..."
453-
node authorize_preimage_and_store_papi.js
468+
echo " WS URL: {{ ws_url }}"
469+
echo " Seed: {{ seed }}"
470+
echo " IPFS API: {{ ipfs_api_url }}"
471+
node authorize_preimage_and_store_papi.js "{{ ws_url }}" "{{ seed }}" "{{ ipfs_api_url }}"
454472

455473
# ============================================================================
456474
# Standalone recipes (with full setup/teardown) - kept for local dev convenience
@@ -479,20 +497,20 @@ run-authorize-and-store runtime mode="ws": npm-install
479497
just setup-services "$TEST_DIR" "{{ runtime }}"
480498

481499
set +e
482-
# Run the script with chainspec_path parameter only for smoldot mode
500+
# Run the script with parameters
483501
if [ "{{ mode }}" = "smoldot" ]; then
484502
# Set chainspec path based on runtime
485503
if [ "{{ runtime }}" = "bulletin-westend-runtime" ]; then
486504
# Parachain: relay chain (required) + parachain spec (optional)
487505
RELAY_CHAINSPEC_PATH="$TEST_DIR/bob/cfg/westend-local.json"
488506
PARACHAIN_CHAINSPEC_PATH="$TEST_DIR/bulletin-westend-collator-2/cfg/westend-local-2487.json"
489-
node $SCRIPT_NAME "$RELAY_CHAINSPEC_PATH" "$PARACHAIN_CHAINSPEC_PATH"
507+
node $SCRIPT_NAME "$RELAY_CHAINSPEC_PATH" "$PARACHAIN_CHAINSPEC_PATH" "http://127.0.0.1:8080"
490508
else # bulletin-polkadot-runtime (solochain)
491509
CHAINSPEC_PATH="$TEST_DIR/bob/cfg/bulletin-polkadot-local.json"
492-
node $SCRIPT_NAME "$CHAINSPEC_PATH"
510+
node $SCRIPT_NAME "$CHAINSPEC_PATH" "http://127.0.0.1:8080"
493511
fi
494512
else
495-
node $SCRIPT_NAME
513+
node $SCRIPT_NAME "ws://localhost:10000" "//Alice" "http://127.0.0.1:8080"
496514
fi
497515
EXAMPLE_EXIT=$?
498516

@@ -510,7 +528,10 @@ run-authorize-and-store runtime mode="ws": npm-install
510528
# Run store chunked data example with Docker IPFS
511529
# Parameters:
512530
# runtime - Runtime name (e.g., "bulletin-polkadot-runtime", "bulletin-westend-runtime")
513-
run-store-chunked-data runtime: npm-install
531+
# ws_url - WebSocket URL (default: ws://localhost:10000)
532+
# seed - Account seed phrase or dev seed (default: //Alice)
533+
# ipfs_api_url - IPFS API URL (default: http://127.0.0.1:8080)
534+
run-store-chunked-data runtime ws_url="ws://localhost:10000" seed="//Alice" ipfs_api_url="http://127.0.0.1:8080": npm-install
514535
#!/usr/bin/env bash
515536
set -e
516537

@@ -520,7 +541,7 @@ run-store-chunked-data runtime: npm-install
520541
just setup-services "$TEST_DIR" "{{ runtime }}"
521542

522543
set +e
523-
node store_chunked_data.js
544+
node store_chunked_data.js "{{ ws_url }}" "{{ seed }}" "{{ ipfs_api_url }}"
524545
EXAMPLE_EXIT=$?
525546

526547
echo ""
@@ -565,7 +586,12 @@ run-store-big-data runtime ws_url="ws://localhost:10000" seed="//Alice" ipfs_api
565586
exit $EXAMPLE_EXIT
566587

567588
# Run authorize preimage and store with PAPI example.
568-
run-authorize-preimage-and-store-papi runtime: npm-install
589+
# Parameters:
590+
# runtime - Runtime name (e.g., "bulletin-polkadot-runtime", "bulletin-westend-runtime")
591+
# ws_url - WebSocket URL (default: ws://localhost:10000)
592+
# seed - Account seed phrase or dev seed (default: //Alice)
593+
# ipfs_api_url - IPFS API URL (default: http://127.0.0.1:8080)
594+
run-authorize-preimage-and-store-papi runtime ws_url="ws://localhost:10000" seed="//Alice" ipfs_api_url="http://127.0.0.1:8080": npm-install
569595
#!/usr/bin/env bash
570596
set -e
571597

@@ -575,7 +601,7 @@ run-authorize-preimage-and-store-papi runtime: npm-install
575601
just setup-services "$TEST_DIR" "{{ runtime }}"
576602

577603
set +e
578-
node authorize_preimage_and_store_papi.js
604+
node authorize_preimage_and_store_papi.js "{{ ws_url }}" "{{ seed }}" "{{ ipfs_api_url }}"
579605
EXAMPLE_EXIT=$?
580606

581607
echo ""

examples/store_chunked_data.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,20 @@ import { CID } from 'multiformats/cid'
66
import * as dagPB from '@ipld/dag-pb'
77
import { TextDecoder } from 'util'
88
import assert from "assert";
9-
import { generateTextImage, filesAreEqual, fileToDisk, setupKeyringAndSigners, HTTP_IPFS_API } from './common.js'
9+
import { generateTextImage, filesAreEqual, fileToDisk, setupKeyringAndSigners } from './common.js'
1010
import { authorizeAccount, fetchCid, store, storeChunkedFile, TX_MODE_FINALIZED_BLOCK } from "./api.js";
1111
import { buildUnixFSDagPB, cidFromBytes, convertCid } from "./cid_dag_metadata.js";
1212
import { createClient } from 'polkadot-api';
1313
import { getWsProvider } from "polkadot-api/ws-provider";
1414
import { Binary } from '@polkadot-api/substrate-bindings';
1515
import { bulletin } from './.papi/descriptors/dist/index.mjs';
1616

17-
// ---- CONFIG ----
18-
const NODE_WS = 'ws://localhost:10000';
17+
// Command line arguments: [ws_url] [seed] [ipfs_api_url]
18+
const args = process.argv.slice(2);
19+
const NODE_WS = args[0] || 'ws://localhost:10000';
20+
const SEED = args[1] || '//Alice';
21+
const HTTP_IPFS_API = args[2] || 'http://127.0.0.1:8080';
1922
const CHUNK_SIZE = 6 * 1024 // 6 KB
20-
// -----------------
2123

2224
/**
2325
* Reads metadata JSON from IPFS by metadataCid.
@@ -156,6 +158,10 @@ async function storeProof(typedApi, sudoSigner, whoSigner, rootCID, dagFileBytes
156158
async function main() {
157159
await cryptoWaitReady()
158160

161+
console.log(`Connecting to: ${NODE_WS}`);
162+
console.log(`Using seed: ${SEED}`);
163+
console.log(`Using IPFS API: ${HTTP_IPFS_API}`);
164+
159165
let client, resultCode;
160166
try {
161167
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "bulletin-chunked-"));
@@ -167,7 +173,7 @@ async function main() {
167173
// Init WS PAPI client and typed api.
168174
client = createClient(getWsProvider(NODE_WS));
169175
const bulletinAPI = client.getTypedApi(bulletin);
170-
const { sudoSigner, whoSigner, whoAddress } = setupKeyringAndSigners('//Alice', '//Chunkedsigner');
176+
const { sudoSigner, whoSigner, whoAddress } = setupKeyringAndSigners(SEED, '//Chunkedsigner');
171177

172178
// Authorize an account.
173179
await authorizeAccount(

0 commit comments

Comments
 (0)