Skip to content

Commit 9d01fe2

Browse files
committed
merged with main
2 parents 1fea5c0 + 00aa68c commit 9d01fe2

File tree

11 files changed

+520
-133
lines changed

11 files changed

+520
-133
lines changed

.github/workflows/integration-test.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,18 @@ jobs:
175175
- name: Stop services (Westend parachain)
176176
if: always()
177177
working-directory: examples
178+
run: |
179+
export TEST_DIR="$(mktemp -d $GITHUB_WORKSPACE/bulletin-tests-run-XXXXX)/test"
180+
echo "TEST_DIR=$TEST_DIR" >> "$GITHUB_ENV"
181+
mkdir -p "$TEST_DIR"
182+
just run-store-chunked-data "bulletin-westend-runtime"
183+
- name: Run store big data (PJS-API, RPC node, Westend parachain)
184+
working-directory: examples
185+
run: |
186+
export TEST_DIR="$(mktemp -d $GITHUB_WORKSPACE/bulletin-tests-run-XXXXX)/test"
187+
echo "TEST_DIR=$TEST_DIR" >> $GITHUB_ENV
188+
mkdir -p "$TEST_DIR"
189+
just run-store-big-data "bulletin-westend-runtime"
178190
run: just stop-services
179191
- name: Upload Westend logs (on failure)
180192
if: failure()
@@ -206,6 +218,22 @@ jobs:
206218
- name: Stop services (Polkadot solochain)
207219
if: always()
208220
working-directory: examples
221+
run: |
222+
export TEST_DIR="$(mktemp -d $GITHUB_WORKSPACE/bulletin-tests-run-XXXXX)/test"
223+
echo "TEST_DIR=$TEST_DIR" >> "$GITHUB_ENV"
224+
mkdir -p "$TEST_DIR"
225+
just run-store-chunked-data "bulletin-polkadot-runtime"
226+
227+
- name: Run store big data (PJS-API, RPC node, Polkadot solochain)
228+
working-directory: examples
229+
run: |
230+
export TEST_DIR="$(mktemp -d $GITHUB_WORKSPACE/bulletin-tests-run-XXXXX)/test"
231+
echo "TEST_DIR=$TEST_DIR" >> $GITHUB_ENV
232+
mkdir -p "$TEST_DIR"
233+
just run-store-big-data "bulletin-polkadot-runtime"
234+
235+
# Collects logs from the last failed zombienet run.
236+
- name: Upload Zombienet logs (on failure)
209237
run: just stop-services
210238
- name: Upload Polkadot logs (on failure)
211239
if: failure()

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,3 @@ package-lock.json
2222
examples/retrieved_picture.*
2323
kubo/
2424
zombienet-*
25-
zombienet/

examples/api.js

Lines changed: 53 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,66 @@
11
import { cidFromBytes } from "./cid_dag_metadata.js";
2-
import { Binary } from '@polkadot-api/substrate-bindings';
3-
4-
export async function authorizeAccount(typedApi, sudoSigner, who, transactions, bytes) {
5-
console.log('Authorizing account...');
6-
7-
const authorizeTx = typedApi.tx.TransactionStorage.authorize_account({
8-
who,
9-
transactions,
10-
bytes
11-
});
12-
13-
const sudoTx = typedApi.tx.Sudo.sudo({
14-
call: authorizeTx.decodedCall
15-
});
2+
import { Binary, Enum } from '@polkadot-api/substrate-bindings';
3+
4+
export async function authorizeAccount(
5+
typedApi,
6+
sudoSigner,
7+
whos,
8+
transactions,
9+
bytes,
10+
txMode = TX_MODE_IN_BLOCK
11+
) {
12+
const accounts = Array.isArray(whos) ? whos : [whos];
13+
14+
console.log(
15+
`⬆️ Authorizing accounts: ${accounts.join(', ')} ` +
16+
`for transactions: ${transactions} and bytes: ${bytes}...`
17+
);
18+
19+
// TODO: rewrite with batch
20+
for (const who of accounts) {
21+
const auth = await typedApi.query.TransactionStorage.Authorizations.getValue(Enum("Account", who));
22+
console.log(`ℹ Account: ${who} Authorization info: `, auth);
23+
if (auth != null) {
24+
const authValue = auth.extent;
25+
const accountTransactions = authValue.transactions;
26+
const accountBytes = authValue.bytes;
27+
28+
if (accountTransactions > transactions && accountBytes > bytes) {
29+
console.log('✅ Account authorization is sufficient.');
30+
continue;
31+
}
32+
} else {
33+
console.log('ℹ️ No existing authorization found — requesting new one...');
34+
}
35+
36+
const authorizeTx = typedApi.tx.TransactionStorage.authorize_account({
37+
who,
38+
transactions,
39+
bytes
40+
});
41+
const sudoTx = typedApi.tx.Sudo.sudo({
42+
call: authorizeTx.decodedCall
43+
});
1644

17-
// Wait for inclusion in best block (finalization can be unreliable with light clients)
18-
await waitForTransaction(sudoTx, sudoSigner, "Authorize", TX_MODE_IN_BLOCK);
45+
await waitForTransaction(sudoTx, sudoSigner, "Authorize", txMode);
46+
}
1947
}
2048

21-
export async function store(typedApi, signer, data) {
49+
export async function store(typedApi, signer, data, txMode = TX_MODE_IN_BLOCK) {
2250
console.log('⬆️ Storing data with length=', data.length);
2351
const cid = await cidFromBytes(data);
2452

2553
// Convert data to Uint8Array then wrap in Binary for PAPI typed API
26-
const dataBytes = typeof data === 'string' ?
27-
new Uint8Array(Buffer.from(data)) :
28-
new Uint8Array(data);
54+
const bytes =
55+
typeof data === 'string'
56+
? new Uint8Array(Buffer.from(data))
57+
: data instanceof Uint8Array
58+
? data
59+
: new Uint8Array(data);
60+
const binaryData = new Binary(bytes);
2961

30-
const binaryData = Binary.fromBytes(dataBytes);
3162
const tx = typedApi.tx.TransactionStorage.store({ data: binaryData });
32-
33-
// Wait for inclusion in best block (finalization can be unreliable with light clients)
34-
await waitForTransaction(tx, signer, "Store", TX_MODE_IN_BLOCK);
63+
await waitForTransaction(tx, signer, "Store", txMode);
3564
return cid;
3665
}
3766

0 commit comments

Comments
 (0)