-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The integration test for LWK is added to ensure that the swap functionality works as expected with the LWK and electrs support. The setup functions are implemented to create the necessary test environment, including lwk, Bitcoin and Liquid nodes, as well as two lightning nodes with the PeerSwap. This setup is crucial for testing the swap-in process in an environment that closely mimics production. also, added Electrs and LWK structs for testing framework. - Implement `Electrs` struct to manage electrs daemon processes - Implement `LWK` struct to manage LWK daemon processes - Provide constructors for both structs to initialize with dynamic ports and configurations - Include methods to run the processes and connect
- Loading branch information
1 parent
e16e4ec
commit f6b3031
Showing
5 changed files
with
337 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package test | ||
|
||
import ( | ||
"math" | ||
"os" | ||
"testing" | ||
|
||
"github.com/elementsproject/peerswap/clightning" | ||
"github.com/elementsproject/peerswap/swap" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_ClnCln_LWK_SwapIn(t *testing.T) { | ||
t.Skip("Skipping test until we have lwk and electrs support on nix") | ||
IsIntegrationTest(t) | ||
t.Parallel() | ||
|
||
t.Run("claim_normal", func(t *testing.T) { | ||
t.Parallel() | ||
require := require.New(t) | ||
|
||
bitcoind, liquidd, lightningds, scid := 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: defaultLines, | ||
}, | ||
tailableProcess{ | ||
p: lightningds[1].DaemonProcess, | ||
filter: filter, | ||
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, | ||
csv: LiquidCsv, | ||
swapType: swap.SWAPTYPE_IN, | ||
} | ||
asset := "lbtc" | ||
|
||
// Do swap. | ||
go func() { | ||
var response map[string]interface{} | ||
lightningds[1].Rpc.Request(&clightning.SwapIn{SatAmt: params.swapAmt, ShortChannelId: params.scid, Asset: asset}, &response) | ||
|
||
}() | ||
preimageClaimTest(t, params) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package testframework | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/url" | ||
|
||
"github.com/checksum0/go-electrum/electrum" | ||
) | ||
|
||
type Electrs struct { | ||
Process *DaemonProcess | ||
rpcURL *url.URL | ||
} | ||
|
||
func NewElectrs(testDir string, id int, elements *LiquidNode) (*Electrs, error) { | ||
rpcPort, err := GetFreePort() | ||
if err != nil { | ||
return nil, err | ||
} | ||
u, err := url.Parse(fmt.Sprintf("127.0.0.1:%d", rpcPort)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
cmdLine := []string{ | ||
"electrs", | ||
"-v", | ||
"--network=liquidregtest", | ||
fmt.Sprintf("daemon-rpc-addr=%s:%d", elements.rpcHost, elements.rpcPort), | ||
fmt.Sprintf("electrum-rpc-addr=:%s", u.String()), | ||
fmt.Sprintf("cookie=%s", elements.RpcUser+":"+elements.RpcPassword), | ||
fmt.Sprintf("daemon-dir=%s", elements.DataDir), | ||
"- --jsonrpc-import", | ||
} | ||
return &Electrs{ | ||
Process: NewDaemonProcess(cmdLine, fmt.Sprintf("electrs-%d", id)), | ||
rpcURL: u, | ||
}, nil | ||
} | ||
|
||
func (e *Electrs) Run(ctx context.Context) error { | ||
e.Process.Run() | ||
ec, err := electrum.NewClientTCP(ctx, e.rpcURL.String()) | ||
if err != nil { | ||
return err | ||
} | ||
return ec.Ping(ctx) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package testframework | ||
|
||
import ( | ||
"fmt" | ||
"net/url" | ||
) | ||
|
||
type LWK struct { | ||
Process *DaemonProcess | ||
} | ||
|
||
func NewLWK(testDir string, id int, electrs *Electrs) (*Electrs, error) { | ||
rpcPort, err := GetFreePort() | ||
if err != nil { | ||
return nil, err | ||
} | ||
u, err := url.Parse(fmt.Sprintf("127.0.0.1:%d", rpcPort)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
cmdLine := []string{ | ||
"lwk_cli", | ||
"--network=regtest", | ||
fmt.Sprintf("--addr=%s", u.String()), | ||
"server", | ||
"start", | ||
fmt.Sprintf("--electrum-url=%s", electrs.rpcURL.String()), | ||
} | ||
return &Electrs{ | ||
Process: NewDaemonProcess(cmdLine, fmt.Sprintf("lwk-%d", id)), | ||
}, nil | ||
} |