@@ -23,21 +23,23 @@ describe('e2e', () => {
2323 const tl1 = new TLNetwork ( config )
2424 const tl2 = new TLNetwork ( config )
2525 const tl3 = new TLNetwork ( config )
26+ const tl4 = new TLNetwork ( config )
2627 let user1
2728 let user2
2829 let user3
30+ let user4
2931 let networks
3032 let networkDefaultInterestRates
3133 let networkCustomInterestRates
3234 let networkWithoutInterestRates
3335
3436 before ( async ( ) => {
3537 // set network and load users
36- ; [ networks , [ user1 , user2 , user3 ] ] = await Promise . all ( [
38+ ; [ networks , [ user1 , user2 , user3 , user4 ] ] = await Promise . all ( [
3739 tl1 . currencyNetwork . getAll ( ) ,
38- createAndLoadUsers ( [ tl1 , tl2 , tl3 ] )
40+ createAndLoadUsers ( [ tl1 , tl2 , tl3 , tl4 ] )
3941 ] )
40- await deployIdentities ( [ tl1 , tl2 , tl3 ] )
42+ await deployIdentities ( [ tl1 , tl2 , tl3 , tl4 ] )
4143 // get network details
4244 const networksWithDetails = await Promise . all (
4345 networks . map ( network => tl1 . currencyNetwork . getInfo ( network . address ) )
@@ -62,7 +64,8 @@ describe('e2e', () => {
6264 await Promise . all ( [
6365 tl1 . user . requestEth ( ) ,
6466 tl2 . user . requestEth ( ) ,
65- tl3 . user . requestEth ( )
67+ tl3 . user . requestEth ( ) ,
68+ tl4 . user . requestEth ( )
6669 ] )
6770 await wait ( )
6871 } )
@@ -221,6 +224,85 @@ describe('e2e', () => {
221224 tl1 . trustline . confirm ( txFreezing . rawTx )
222225 ) . to . eventually . be . a ( 'string' )
223226 } )
227+
228+ it ( 'should return txHash for trustline update on existing trustline' , async ( ) => {
229+ const proposeAndAcceptTrustline = async ( ) => {
230+ // Create and accept a trustline - start
231+ const txFreezing = await tl1 . trustline . prepareUpdate (
232+ networkCustomInterestRates . address ,
233+ user4 . address ,
234+ 2000 ,
235+ 1000 ,
236+ {
237+ interestRateGiven : 0.02 ,
238+ interestRateReceived : 0.01 ,
239+ isFrozen : false ,
240+ transfer : 123
241+ }
242+ )
243+ await expect (
244+ tl1 . trustline . confirm ( txFreezing . rawTx )
245+ ) . to . eventually . be . a ( 'string' )
246+
247+ const acceptTl = await tl4 . trustline . prepareAccept (
248+ networkCustomInterestRates . address ,
249+ user1 . address ,
250+ 1000 ,
251+ 2000 ,
252+ {
253+ interestRateGiven : 0.01 ,
254+ interestRateReceived : 0.02 ,
255+ isFrozen : false ,
256+ transfer : - 123
257+ }
258+ )
259+
260+ await tl4 . trustline . confirm ( acceptTl . rawTx )
261+ wait ( )
262+ }
263+
264+ const proposeUpdateToExistingTrustline = async transfer => {
265+ const update = await tl1 . trustline . prepareUpdate (
266+ networkCustomInterestRates . address ,
267+ user4 . address ,
268+ 2100 ,
269+ 1100 ,
270+ {
271+ interestRateGiven : 0.02 ,
272+ interestRateReceived : 0.01 ,
273+ isFrozen : false ,
274+ transfer
275+ }
276+ )
277+
278+ const confirmed = await tl1 . trustline . confirm ( update . rawTx )
279+ expect ( confirmed ) . to . be . a ( 'string' )
280+
281+ await wait ( )
282+
283+ const txStatus = await tl1 . transaction . getTxStatus ( update . rawTx )
284+
285+ return txStatus
286+ }
287+
288+ await proposeAndAcceptTrustline ( )
289+ await expect (
290+ proposeUpdateToExistingTrustline ( '0' )
291+ ) . to . eventually . have . property ( 'status' , 'success' )
292+ await expect (
293+ proposeUpdateToExistingTrustline ( 0 )
294+ ) . to . eventually . have . property ( 'status' , 'success' )
295+ await expect (
296+ proposeUpdateToExistingTrustline ( 123 )
297+ ) . to . eventually . have . property ( 'status' , 'failure' )
298+ await expect (
299+ proposeUpdateToExistingTrustline ( '123' )
300+ ) . to . eventually . have . property ( 'status' , 'failure' )
301+
302+ await expect (
303+ proposeUpdateToExistingTrustline ( '' )
304+ ) . to . eventually . be . rejectedWith ( Error , 'Transfer is not a number' )
305+ } )
224306 } )
225307
226308 describe ( '#prepareCancelTrustlineUpdate()' , async ( ) => {
0 commit comments