@@ -281,6 +281,7 @@ func swapStream(t *testing.T, client client.Boltz, swapId string) (streamFunc, s
281
281
require .Fail (t , fmt .Sprintf ("update stream for swap %s stopped before state %s" , swapId , state ))
282
282
}
283
283
case <- time .After (15 * time .Second ):
284
+ test .PrintBackendLogs ()
284
285
require .Fail (t , fmt .Sprintf ("timed out while waiting for swap %s to reach state %s" , swapId , state ))
285
286
}
286
287
}
@@ -703,8 +704,8 @@ func TestSwap(t *testing.T) {
703
704
client , _ , stop = setup (t , setupOptions {cfg : cfg })
704
705
defer stop ()
705
706
706
- ticker := time .NewTicker (100 * time .Millisecond )
707
- timeout := time .After (1 * time .Second )
707
+ ticker := time .NewTicker (200 * time .Millisecond )
708
+ timeout := time .After (5 * time .Second )
708
709
for {
709
710
select {
710
711
case <- ticker .C :
@@ -1091,8 +1092,8 @@ func TestReverseSwap(t *testing.T) {
1091
1092
1092
1093
client , _ , stop = setup (t , setupOptions {cfg : cfg })
1093
1094
1094
- ticker := time .NewTicker (100 * time .Millisecond )
1095
- timeout := time .After (3 * time .Second )
1095
+ ticker := time .NewTicker (200 * time .Millisecond )
1096
+ timeout := time .After (5 * time .Second )
1096
1097
for info .GetReverseSwap ().GetState () != boltzrpc .SwapState_SUCCESSFUL {
1097
1098
select {
1098
1099
case <- ticker .C :
@@ -1809,7 +1810,7 @@ func TestChainSwap(t *testing.T) {
1809
1810
1810
1811
func TestAutoSwap (t * testing.T ) {
1811
1812
cfg := loadConfig (t )
1812
- cfg .Node = "LND "
1813
+ cfg .Node = "CLN "
1813
1814
1814
1815
_ , err := connectLightning (cfg .Cln )
1815
1816
require .NoError (t , err )
@@ -1819,13 +1820,15 @@ func TestAutoSwap(t *testing.T) {
1819
1820
admin , autoSwap , stop := setup (t , setupOptions {cfg : cfg })
1820
1821
defer stop ()
1821
1822
1822
- _ , err = autoSwap .ResetConfig (client .LnAutoSwap )
1823
- require .NoError (t , err )
1824
-
1825
- _ , err = autoSwap .ResetConfig (client .ChainAutoSwap )
1826
- require .NoError (t , err )
1823
+ reset := func (t * testing.T ) {
1824
+ _ , err = autoSwap .ResetConfig (client .LnAutoSwap )
1825
+ require .NoError (t , err )
1826
+ _ , err = autoSwap .ResetConfig (client .ChainAutoSwap )
1827
+ require .NoError (t , err )
1828
+ }
1827
1829
1828
1830
t .Run ("Chain" , func (t * testing.T ) {
1831
+ reset (t )
1829
1832
cfg := & autoswaprpc.ChainConfig {
1830
1833
FromWallet : walletName ,
1831
1834
ToWallet : cfg .Node ,
@@ -1876,17 +1879,7 @@ func TestAutoSwap(t *testing.T) {
1876
1879
})
1877
1880
1878
1881
t .Run ("Lightning" , func (t * testing.T ) {
1879
- _ , err := autoSwap .ResetConfig (client .LnAutoSwap )
1880
- require .NoError (t , err )
1881
-
1882
- var us , them lightning.LightningNode
1883
- if strings .EqualFold (cfg .Node , "lnd" ) {
1884
- us = cfg .LND
1885
- them = cfg .Cln
1886
- } else {
1887
- us = cfg .Cln
1888
- them = cfg .LND
1889
- }
1882
+ reset (t )
1890
1883
1891
1884
t .Run ("Setup" , func (t * testing.T ) {
1892
1885
running := func (value bool ) * autoswaprpc.GetStatusResponse {
@@ -1928,41 +1921,9 @@ func TestAutoSwap(t *testing.T) {
1928
1921
})
1929
1922
1930
1923
t .Run ("Start" , func (t * testing.T ) {
1931
- getChannel := func (from lightning.LightningNode , peer string ) * lightning.LightningChannel {
1932
- channels , err := from .ListChannels ()
1933
- require .NoError (t , err )
1934
- for _ , channel := range channels {
1935
- if channel .PeerId == peer {
1936
- return channel
1937
- }
1938
- }
1939
- return nil
1940
- }
1941
-
1942
- pay := func (from lightning.LightningNode , to lightning.LightningNode , amount uint64 ) {
1943
- info , err := to .GetInfo ()
1944
- require .NoError (t , err )
1945
-
1946
- channel := getChannel (from , info .Pubkey )
1947
- require .NotNil (t , channel )
1948
-
1949
- if channel .InboundSat < channel .Capacity / 2 {
1950
- amount = amount + (channel .Capacity / 2 - channel .InboundSat )/ 1000
1951
- }
1952
- if channel .OutboundSat < amount {
1953
- return
1954
- }
1955
-
1956
- response , err := to .CreateInvoice (amount , nil , 100000 , "Testt" )
1957
- require .NoError (t , err )
1958
- _ , err = from .PayInvoice (context .Background (), response .PaymentRequest , 10000 , 30 , []lightning.ChanId {channel .Id })
1959
- require .NoError (t , err )
1960
-
1961
- time .Sleep (1000 * time .Millisecond )
1962
- }
1963
-
1964
1924
swapCfg := autoswap .DefaultLightningConfig ()
1965
1925
swapCfg .AcceptZeroConf = true
1926
+ swapCfg .Budget = 1000000
1966
1927
swapCfg .MaxFeePercent = 10
1967
1928
swapCfg .Currency = boltzrpc .Currency_BTC
1968
1929
swapCfg .InboundBalance = 1
@@ -1976,7 +1937,9 @@ func TestAutoSwap(t *testing.T) {
1976
1937
require .NoError (t , err )
1977
1938
recommendation := recommendations .Lightning [0 ]
1978
1939
require .Nil (t , recommendation .Swap )
1979
- swapCfg .InboundBalance = recommendation .Channel .InboundSat + 100
1940
+ offset := uint64 (100000 )
1941
+ swapCfg .InboundBalance = recommendation .Channel .InboundSat + offset
1942
+ swapCfg .OutboundBalance = recommendation .Channel .OutboundSat - offset
1980
1943
1981
1944
_ , err = autoSwap .UpdateLightningConfig (& autoswaprpc.UpdateLightningConfigRequest {Config : swapCfg })
1982
1945
require .NoError (t , err )
@@ -1989,17 +1952,20 @@ func TestAutoSwap(t *testing.T) {
1989
1952
})
1990
1953
1991
1954
t .Run ("Auto" , func (t * testing.T ) {
1992
- pay (them , us , 1_000_000 )
1993
1955
_ , err := autoSwap .Enable ()
1994
1956
require .NoError (t , err )
1995
1957
1996
- time .Sleep (200 * time .Millisecond )
1958
+ stream , _ := swapStream (t , admin , "" )
1959
+ test .MineBlock ()
1960
+ info := stream (boltzrpc .SwapState_PENDING )
1961
+ require .NotNil (t , info .ReverseSwap )
1962
+ require .True (t , info .ReverseSwap .IsAuto )
1963
+ id := info .ReverseSwap .Id
1964
+
1997
1965
swaps , err := admin .ListSwaps (& boltzrpc.ListSwapsRequest {Include : boltzrpc .IncludeSwaps_AUTO })
1998
1966
require .NoError (t , err )
1999
-
2000
- require .NotEmpty (t , swaps .ReverseSwaps )
2001
- require .True (t , swaps .ReverseSwaps [0 ].IsAuto )
2002
- stream , _ := swapStream (t , admin , swaps .ReverseSwaps [0 ].Id )
1967
+ require .Equal (t , id , swaps .ReverseSwaps [0 ].Id )
1968
+ stream , _ = swapStream (t , admin , id )
2003
1969
stream (boltzrpc .SwapState_SUCCESSFUL )
2004
1970
2005
1971
status , err := autoSwap .GetStatus ()
0 commit comments