99 * - Deposit fee: 10,000,000 base units (1 TFT)
1010 * - Withdraw fee: 10,000,000 base units (1 TFT)
1111 *
12- * No pallet calls are made — there is no sudo pallet on TFChain and all bridge
13- * admin calls require root or council approval. The genesis configuration is
14- * sufficient for single-validator local development.
12+ * The dev chain genesis is sufficient for bridge configuration (no sudo needed).
13+ * This script additionally creates Alice's twin (needed for deposit tests).
1514 *
1615 * Usage:
1716 * node scripts/bridge_setup.js
@@ -27,13 +26,38 @@ function log (msg) { console.log(`[setup] ${msg}`) }
2726function warn ( msg ) { console . warn ( `[setup] WARN: ${ msg } ` ) }
2827function die ( msg ) { console . error ( `[setup] ERROR: ${ msg } ` ) ; process . exit ( 1 ) }
2928
29+ /** Sign a tx, wait for InBlock, and throw on dispatch error */
30+ function signAndWait ( api , tx , signer ) {
31+ return new Promise ( ( resolve , reject ) => {
32+ let unsub
33+ tx . signAndSend ( signer , ( { status, dispatchError, events } ) => {
34+ if ( ! status . isInBlock && ! status . isFinalized ) return
35+ if ( dispatchError ) {
36+ let msg = dispatchError . toString ( )
37+ if ( dispatchError . isModule ) {
38+ try {
39+ const decoded = api . registry . findMetaError ( dispatchError . asModule )
40+ msg = `${ decoded . section } .${ decoded . name } : ${ decoded . docs } `
41+ } catch { }
42+ }
43+ if ( unsub ) unsub ( )
44+ reject ( new Error ( msg ) )
45+ return
46+ }
47+ if ( unsub ) unsub ( )
48+ resolve ( { status, events } )
49+ } ) . then ( u => { unsub = u } ) . catch ( reject )
50+ } )
51+ }
52+
3053async function main ( ) {
3154 log ( `Connecting to TFChain at ${ TFCHAIN_URL } ...` )
3255 const api = await ApiPromise . create ( { provider : new WsProvider ( TFCHAIN_URL ) } )
3356
3457 try {
3558 const keyring = new Keyring ( { type : 'sr25519' } )
3659
60+ const alice = keyring . addFromUri ( '//Alice' )
3761 const bob = keyring . addFromUri ( '//Bob' )
3862 const charlie = keyring . addFromUri ( '//Charlie' )
3963 const ferdie = keyring . addFromUri ( '//Ferdie' )
@@ -73,6 +97,20 @@ async function main () {
7397 warn ( 'Deposit fee is 0 — bridge may not charge fees' )
7498 }
7599
100+ // Create Alice's twin (needed for test5_deposit)
101+ // Alice must accept T&C before creating a twin
102+ const aliceTwinOpt = await api . query . tfgridModule . twinIdByAccountID ( alice . address )
103+ const aliceTwinId = aliceTwinOpt . toJSON ( )
104+ if ( ! aliceTwinId ) {
105+ log ( 'Accepting T&C and creating Alice twin for deposit tests...' )
106+ await signAndWait ( api , api . tx . tfgridModule . userAcceptTc ( 'https://localhost/tc' , 'deadbeef' ) , alice )
107+ await signAndWait ( api , api . tx . tfgridModule . createTwin ( null , null ) , alice )
108+ const newTwin = await api . query . tfgridModule . twinIdByAccountID ( alice . address )
109+ log ( `Alice twin created (ID: ${ newTwin . toJSON ( ) } )` )
110+ } else {
111+ log ( `Alice twin already exists (ID: ${ aliceTwinId } )` )
112+ }
113+
76114 log ( 'Setup verification complete.' )
77115 } finally {
78116 await api . disconnect ( )
0 commit comments