Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
YusukeShimizu committed May 2, 2024
1 parent e2adc50 commit f955257
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lwk/lwkwallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,9 @@ func (r *LWKRpcWallet) SendRawTx(txHex string) (string, error) {
func (r *LWKRpcWallet) getFeePerKb(ctx context.Context) SatPerKVByte {
feeBTCPerKb, err := r.electrumClient.GetFee(ctx, wallet.LiquidTargetBlocks)
// convert to sat per byte
satPerByte := uint64(float64(feeBTCPerKb) * math.Pow10(int(8)))
// 1 kb = 1000 bytes
var kb float64 = 1000
satPerByte := uint64(float64(feeBTCPerKb) * math.Pow10(int(8)) / kb)
if satPerByte < minimumSatPerByte {
satPerByte = minimumSatPerByte
}
Expand Down
80 changes: 80 additions & 0 deletions test/lwk_cln_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,84 @@ func Test_ClnCln_LWK_SwapIn(t *testing.T) {
}()
preimageClaimTest(t, params)
})
t.Run("claim_coop", func(t *testing.T) {
t.Parallel()
require := require.New(t)

bitcoind, liquidd, lightningds, scid, electrs, lwk := clnclnLWKSetup(t, uint64(math.Pow10(9)))
defer func() {
if t.Failed() {
filter := os.Getenv("PEERSWAP_TEST_FILTER")
pprintFail(
tailableProcess{
p: bitcoind.DaemonProcess,
lines: defaultLines,
},
tailableProcess{
p: liquidd.DaemonProcess,
lines: defaultLines,
},
tailableProcess{
p: lightningds[0].DaemonProcess,
filter: filter,
lines: 3000,
},
tailableProcess{
p: lightningds[1].DaemonProcess,
filter: filter,
lines: 3000,
},
tailableProcess{
p: electrs.Process,
lines: defaultLines,
},
tailableProcess{
p: lwk.Process,
lines: defaultLines,
},
)
}
}()

var channelBalances []uint64
var walletBalances []uint64
for _, lightningd := range lightningds {
b, err := lightningd.GetBtcBalanceSat()
require.NoError(err)
walletBalances = append(walletBalances, b)

b, err = lightningd.GetChannelBalanceSat(scid)
require.NoError(err)
channelBalances = append(channelBalances, b)
}

params := &testParams{
swapAmt: channelBalances[0] / 2,
scid: scid,
origTakerWallet: walletBalances[0],
origMakerWallet: walletBalances[1],
origTakerBalance: channelBalances[0],
origMakerBalance: channelBalances[1],
takerNode: lightningds[0],
makerNode: lightningds[1],
takerPeerswap: lightningds[0].DaemonProcess,
makerPeerswap: lightningds[1].DaemonProcess,
chainRpc: liquidd.RpcProxy,
chaind: liquidd,
confirms: LiquidConfirms + 1,
csv: LiquidCsv,
swapType: swap.SWAPTYPE_IN,
}
asset := "lbtc"

// Do swap.
go func() {
var response map[string]interface{}
err := lightningds[1].Rpc.Request(&clightning.SwapIn{SatAmt: params.swapAmt, ShortChannelId: params.scid, Asset: asset}, &response)
require.NoError(err)

}()
coopClaimTest(t, params)
})

}

0 comments on commit f955257

Please sign in to comment.