@@ -1868,3 +1868,91 @@ func toProtoJSON(t *testing.T, resp proto.Message) string {
18681868
18691869 return string (jsonBytes )
18701870}
1871+
1872+ func assertNumHtlcs (t * testing.T , node * HarnessNode , expected int ) {
1873+ t .Helper ()
1874+
1875+ ctxb := context .Background ()
1876+
1877+ err := wait .NoError (func () error {
1878+ listChansRequest := & lnrpc.ListChannelsRequest {}
1879+ listChansResp , err := node .ListChannels (ctxb , listChansRequest )
1880+ if err != nil {
1881+ return err
1882+ }
1883+
1884+ var numHtlcs int
1885+ for _ , channel := range listChansResp .Channels {
1886+ numHtlcs += len (channel .PendingHtlcs )
1887+ }
1888+
1889+ if numHtlcs != expected {
1890+ return fmt .Errorf ("expected %v HTLCs, got %v, %v" , expected , numHtlcs , spew .Sdump (toProtoJSON (t , listChansResp )))
1891+ }
1892+
1893+ return nil
1894+ }, defaultTimeout )
1895+ require .NoError (t , err )
1896+ }
1897+
1898+ type forceCloseExpiryInfo struct {
1899+ currentHeight uint32
1900+ csvDelay uint32
1901+
1902+ cltvDelays map [lntypes.Hash ]uint32
1903+
1904+ localAssetBalance uint64
1905+ remoteAssetBalance uint64
1906+
1907+ t * testing.T
1908+
1909+ node * HarnessNode
1910+ }
1911+
1912+ func (f * forceCloseExpiryInfo ) blockTillExpiry (hash lntypes.Hash ) uint32 {
1913+ ctxb := context .Background ()
1914+ nodeInfo , err := f .node .GetInfo (ctxb , & lnrpc.GetInfoRequest {})
1915+ require .NoError (f .t , err )
1916+
1917+ cltv , ok := f .cltvDelays [hash ]
1918+ require .True (f .t , ok )
1919+
1920+ f .t .Logf ("current_height=%v, expiry=%v, mining %v blocks" ,
1921+ nodeInfo .BlockHeight , cltv , cltv - nodeInfo .BlockHeight )
1922+
1923+ return cltv - nodeInfo .BlockHeight
1924+ }
1925+
1926+ func newCloseExpiryInfo (t * testing.T , node * HarnessNode ) forceCloseExpiryInfo {
1927+ ctxb := context .Background ()
1928+
1929+ listChansRequest := & lnrpc.ListChannelsRequest {}
1930+ listChansResp , err := node .ListChannels (ctxb , listChansRequest )
1931+ require .NoError (t , err )
1932+
1933+ mainChan := listChansResp .Channels [0 ]
1934+
1935+ nodeInfo , err := node .GetInfo (ctxb , & lnrpc.GetInfoRequest {})
1936+ require .NoError (t , err )
1937+
1938+ cltvs := make (map [lntypes.Hash ]uint32 )
1939+ for _ , htlc := range mainChan .PendingHtlcs {
1940+ var payHash lntypes.Hash
1941+ copy (payHash [:], htlc .HashLock )
1942+ cltvs [payHash ] = htlc .ExpirationHeight
1943+ }
1944+
1945+ var assetData rfqmsg.JsonAssetChannel
1946+ err = json .Unmarshal (mainChan .CustomChannelData , & assetData )
1947+ require .NoError (t , err )
1948+
1949+ return forceCloseExpiryInfo {
1950+ csvDelay : mainChan .CsvDelay ,
1951+ currentHeight : nodeInfo .BlockHeight ,
1952+ cltvDelays : cltvs ,
1953+ localAssetBalance : assetData .Assets [0 ].LocalBalance ,
1954+ remoteAssetBalance : assetData .Assets [0 ].RemoteBalance ,
1955+ t : t ,
1956+ node : node ,
1957+ }
1958+ }
0 commit comments