@@ -40,34 +40,34 @@ async function testWithdraw(
4040 requiresMainnetETH : boolean ,
4141 options : DataUnionWithdrawOptions ,
4242) {
43- log ( ` Connecting to Ethereum networks, config = ${ JSON . stringify ( config ) } ` )
43+ log ( ' Connecting to Ethereum networks, config = %o' , config )
4444 const network = await providerMainnet . getNetwork ( )
45- log ( 'Connected to "mainnet" network: ' , JSON . stringify ( network ) )
45+ log ( 'Connected to "mainnet" network: %o ' , network )
4646 const network2 = await providerSidechain . getNetwork ( )
47- log ( 'Connected to sidechain network: ' , JSON . stringify ( network2 ) )
47+ log ( 'Connected to sidechain network: %o ' , network2 )
4848
49- log ( ` Minting 100 tokens to ${ adminWalletMainnet . address } ` )
49+ log ( ' Minting 100 tokens to %s' , adminWalletMainnet . address )
5050 const tx1 = await tokenMainnet . mint ( adminWalletMainnet . address , parseEther ( '100' ) )
5151 await tx1 . wait ( )
5252
5353 const adminClient = new StreamrClient ( config . clientOptions )
5454
5555 const dataUnion = await adminClient . deployDataUnion ( )
5656 const secret = await dataUnion . createSecret ( 'test secret' )
57- log ( ` DataUnion ${ dataUnion . getAddress ( ) } is ready to roll` )
57+ log ( ' DataUnion %s is ready to roll' , dataUnion . getAddress ( ) )
5858 // dataUnion = await adminClient.getDataUnionContract({dataUnion: "0xd778CfA9BB1d5F36E42526B2BAFD07B74b4066c0"})
5959
6060 testWalletId += 1
6161 const memberWallet = new Wallet ( `0x100000000000000000000000000000000000000012300000000000001${ testWalletId } ` , providerSidechain )
6262 const recipient = recipientAddress || memberWallet . address
6363 const sendTx = await adminWalletSidechain . sendTransaction ( { to : memberWallet . address , value : parseEther ( '0.1' ) } )
6464 await sendTx . wait ( )
65- log ( ` Sent 0.1 sidechain-ETH to ${ memberWallet . address } ` )
65+ log ( ' Sent 0.1 sidechain-ETH to %s' , memberWallet . address )
6666
6767 if ( requiresMainnetETH ) {
6868 const send2Tx = await adminWalletMainnet . sendTransaction ( { to : memberWallet . address , value : parseEther ( '0.1' ) } )
6969 await send2Tx . wait ( )
70- log ( ` Sent 0.1 mainnet-ETH to ${ memberWallet . address } ` )
70+ log ( ' Sent 0.1 mainnet-ETH to %s' , memberWallet . address )
7171 }
7272
7373 const memberClient = new StreamrClient ( {
@@ -89,55 +89,54 @@ async function testWithdraw(
8989 } )
9090 const res = await memberClient . getDataUnion ( dataUnion . getAddress ( ) ) . join ( secret )
9191 // await adminClient.addMembers([memberWallet.address], { dataUnion })
92- log ( ` Member joined data union: ${ JSON . stringify ( res ) } ` )
92+ log ( ' Member joined data union %o' , res )
9393
9494 // eslint-disable-next-line no-underscore-dangle
9595 const contract = await dataUnion . _getContract ( )
9696 const tokenAddress = await contract . token ( )
97- log ( ` Token address: ${ tokenAddress } ` )
97+ log ( ' Token address: %s' , tokenAddress )
9898 const adminTokenMainnet = new Contract ( tokenAddress , Token . abi , adminWalletMainnet )
99+ async function logBalance ( owner : string , address : EthereumAddress ) {
100+ const balance = await adminTokenMainnet . balanceOf ( address )
101+ log ( '%s (%s) mainnet token balance: %s (%s)' , owner , address , formatEther ( balance ) , balance . toString ( ) )
102+ }
99103
100104 const amount = parseEther ( '1' )
101105 const duSidechainEarningsBefore = await contract . sidechain . totalEarnings ( )
102106
103- const duBalance1 = await adminTokenMainnet . balanceOf ( dataUnion . getAddress ( ) )
104- log ( `Token balance of ${ dataUnion . getAddress ( ) } : ${ formatEther ( duBalance1 ) } (${ duBalance1 . toString ( ) } )` )
105- const balance1 = await adminTokenMainnet . balanceOf ( adminWalletMainnet . address )
106- log ( `Token balance of ${ adminWalletMainnet . address } : ${ formatEther ( balance1 ) } (${ balance1 . toString ( ) } )` )
107+ await logBalance ( 'Data union' , dataUnion . getAddress ( ) )
108+ await logBalance ( 'Admin' , adminWalletMainnet . address )
107109
108- log ( ` Transferring ${ amount } token-wei ${ adminWalletMainnet . address } -> ${ dataUnion . getAddress ( ) } ` )
110+ log ( ' Transferring %s token-wei %s->%s' , amount , adminWalletMainnet . address , dataUnion . getAddress ( ) )
109111 const txTokenToDU = await adminTokenMainnet . transfer ( dataUnion . getAddress ( ) , amount )
110112 await txTokenToDU . wait ( )
111113
112- const duBalance2 = await adminTokenMainnet . balanceOf ( dataUnion . getAddress ( ) )
113- log ( `Token balance of ${ dataUnion . getAddress ( ) } : ${ formatEther ( duBalance2 ) } (${ duBalance2 . toString ( ) } )` )
114- const balance2 = await adminTokenMainnet . balanceOf ( adminWalletMainnet . address )
115- log ( `Token balance of ${ adminWalletMainnet . address } : ${ formatEther ( balance2 ) } (${ balance2 . toString ( ) } )` )
114+ await logBalance ( 'Data union' , dataUnion . getAddress ( ) )
115+ await logBalance ( 'Admin' , adminWalletMainnet . address )
116116
117- log ( ` DU member count: ${ await contract . sidechain . activeMemberCount ( ) } ` )
117+ log ( ' DU member count: %d' , await contract . sidechain . activeMemberCount ( ) )
118118
119- log ( ` Transferred ${ formatEther ( amount ) } tokens, next sending to bridge` )
119+ log ( ' Transferred %s tokens, next sending to bridge' , formatEther ( amount ) )
120120 const tx2 = await contract . sendTokensToBridge ( )
121- await tx2 . wait ( )
121+ const tr2 = await tx2 . wait ( )
122+ log ( 'sendTokensToBridge returned %o' , tr2 )
122123
123- log ( `Sent to bridge, waiting for the tokens to appear at ${ contract . sidechain . address } in sidechain` )
124+ log ( 'Waiting for the tokens to appear at sidechain %s' , contract . sidechain . address )
124125 await until ( async ( ) => ! ( await tokenSidechain . balanceOf ( contract . sidechain . address ) ) . eq ( '0' ) , 300000 , 3000 )
125- log ( ` Confirmed tokens arrived, DU balance: ${ duSidechainEarningsBefore } -> ${ await contract . sidechain . totalEarnings ( ) } ` )
126+ log ( ' Confirmed tokens arrived, DU balance: %s -> %s' , duSidechainEarningsBefore , await contract . sidechain . totalEarnings ( ) )
126127
127128 // make a "full" sidechain contract object that has all functions, not just those required by StreamrClient
128129 const sidechainContract = new Contract ( contract . sidechain . address , DataUnionSidechain . abi , adminWalletSidechain )
129130 const tx3 = await sidechainContract . refreshRevenue ( )
130131 const tr3 = await tx3 . wait ( )
131- log ( ` refreshRevenue returned ${ JSON . stringify ( tr3 ) } ` )
132- log ( ` DU balance: ${ await contract . sidechain . totalEarnings ( ) } ` )
132+ log ( ' refreshRevenue returned %o' , tr3 )
133+ log ( ' DU sidechain totalEarnings: %o' , await contract . sidechain . totalEarnings ( ) )
133134
134- const duBalance3 = await adminTokenMainnet . balanceOf ( dataUnion . getAddress ( ) )
135- log ( `Token balance of ${ dataUnion . getAddress ( ) } : ${ formatEther ( duBalance3 ) } (${ duBalance3 . toString ( ) } )` )
136- const balance3 = await adminTokenMainnet . balanceOf ( adminWalletMainnet . address )
137- log ( `Token balance of ${ adminWalletMainnet . address } : ${ formatEther ( balance3 ) } (${ balance3 . toString ( ) } )` )
135+ await logBalance ( 'Data union' , dataUnion . getAddress ( ) )
136+ await logBalance ( 'Admin' , adminWalletMainnet . address )
138137
139138 const stats = await memberClient . getDataUnion ( dataUnion . getAddress ( ) ) . getMemberStats ( memberWallet . address )
140- log ( ` Stats: ${ JSON . stringify ( stats ) } ` )
139+ log ( ' Stats: %o' , stats )
141140
142141 const getRecipientBalance = async ( ) => (
143142 options . sendToMainnet
@@ -146,11 +145,11 @@ async function testWithdraw(
146145 )
147146
148147 const balanceBefore = await getRecipientBalance ( )
149- log ( ` Balance before: ${ balanceBefore } . Withdrawing tokens...` )
148+ log ( ' Balance before: %s . Withdrawing tokens...' , balanceBefore )
150149
151150 // "bridge-sponsored mainnet withdraw" case
152151 if ( ! options . payForTransport && options . waitUntilTransportIsComplete ) {
153- log ( ` Adding ${ recipient } to bridge-sponsored withdraw whitelist` )
152+ log ( ' Adding %s to bridge-sponsored withdraw whitelist' , recipient )
154153 bridgeWhitelist . push ( recipient )
155154 }
156155
@@ -159,15 +158,15 @@ async function testWithdraw(
159158
160159 // "other-sponsored mainnet withdraw" case
161160 if ( typeof ret === 'string' ) {
162- log ( ` Transporting message "${ ret } "` )
161+ log ( ' Transporting message "%s"' , ret )
163162 ret = await dataUnion . transportMessage ( String ( ret ) )
164163 }
165- log ( ` Tokens withdrawn, return value: ${ JSON . stringify ( ret ) } ` )
164+ log ( ' Tokens withdrawn, return value: %o' , ret )
166165
167166 // "skip waiting" or "without checking the recipient account" case
168167 // we need to wait nevertheless, to be able to assert that balance in fact changed
169168 if ( ! options . waitUntilTransportIsComplete ) {
170- log ( ` Waiting until balance changes from ${ balanceBefore . toString ( ) } ` )
169+ log ( ' Waiting until balance changes from %s' , balanceBefore )
171170 await until ( async ( ) => getRecipientBalance ( ) . then ( ( b ) => ! b . eq ( balanceBefore ) ) )
172171 }
173172
@@ -192,17 +191,17 @@ providerSidechain.on({
192191 address : sidechainAmbAddress ,
193192 topics : [ signatureRequestEventSignature ]
194193} , async ( event ) => {
195- log ( ` Observed signature request for message id=${ event . topics [ 1 ] } ` ) // messageId is indexed so it's in topics...
194+ log ( ' Observed signature request for message ( id=%s)' , event . topics [ 1 ] ) // messageId is indexed so it's in topics...
196195 const message = defaultAbiCoder . decode ( [ 'bytes' ] , event . data ) [ 0 ] // ...only encodedData is in data
197196 const recipient = '0x' + message . slice ( 200 , 240 )
198197 if ( ! bridgeWhitelist . find ( ( address ) => address . toLowerCase ( ) === recipient ) ) {
199- log ( ` Recipient ${ recipient } not whitelisted, ignoring` )
198+ log ( ' Recipient %s not whitelisted, ignoring' , recipient )
200199 return
201200 }
202201 const hash = keccak256 ( message )
203202 const adminClient = new StreamrClient ( config . clientOptions )
204203 await adminClient . getDataUnion ( '0x0000000000000000000000000000000000000000' ) . transportMessage ( hash , 100 , 120000 )
205- log ( ` Transported message hash=${ hash } ` )
204+ log ( ' Transported message ( hash=%s)' , hash )
206205} )
207206
208207describe ( 'DataUnion withdraw' , ( ) => {
0 commit comments