-
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.
fixup! multi: lwk configuration support for Liquid swaps
- Loading branch information
1 parent
fa84e0f
commit 69cc68e
Showing
7 changed files
with
302 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package clightning_test | ||
|
||
import ( | ||
"io/fs" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/elementsproject/peerswap/clightning" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/vulpemventures/go-elements/network" | ||
) | ||
|
||
func TestLWKConfigFromToml(t *testing.T) { | ||
t.Parallel() | ||
t.Run("valid toml config", func(t *testing.T) { | ||
t.Parallel() | ||
file := ` | ||
[LWK] | ||
signername="signername" | ||
walletname="walletname" | ||
lwkendpoint="http://localhost:32110" | ||
network="liquid" | ||
liquidswaps=true | ||
` | ||
filePath := filepath.Join(t.TempDir(), "peerswap.conf") | ||
assert.NoError(t, os.WriteFile(filePath, []byte(file), fs.ModePerm)) | ||
got, err := clightning.LWKConfigFromToml(filePath) | ||
if err != nil { | ||
t.Errorf("LWKConfigFromToml() error = %v", err) | ||
return | ||
} | ||
assert.Equal(t, got.GetChain(), &network.Liquid) | ||
assert.Equal(t, got.GetElectrumEndpoint(), "blockstream.info:995") | ||
assert.Equal(t, got.GetLWKEndpoint(), "http://localhost:32110") | ||
assert.Equal(t, got.GetLiquidSwaps(), true) | ||
assert.Equal(t, got.GetNetwork(), "liquid") | ||
}) | ||
t.Run("default toml config", func(t *testing.T) { | ||
t.Parallel() | ||
file := ` | ||
[LWK] | ||
network="liquid-testnet" | ||
liquidswaps=true | ||
` | ||
filePath := filepath.Join(t.TempDir(), "peerswap.conf") | ||
assert.NoError(t, os.WriteFile(filePath, []byte(file), fs.ModePerm)) | ||
got, err := clightning.LWKConfigFromToml(filePath) | ||
if err != nil { | ||
t.Errorf("LWKConfigFromToml() error = %v", err) | ||
return | ||
} | ||
assert.Equal(t, got.GetChain(), &network.Testnet) | ||
assert.Equal(t, got.GetElectrumEndpoint(), "blockstream.info:465") | ||
assert.Equal(t, got.GetLWKEndpoint(), "http://localhost:32111") | ||
assert.Equal(t, got.GetLiquidSwaps(), true) | ||
assert.Equal(t, got.GetNetwork(), "liquid-testnet") | ||
}) | ||
} |
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,59 @@ | ||
package peerswaplnd_test | ||
|
||
import ( | ||
"io/fs" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/elementsproject/peerswap/cmd/peerswaplnd" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/vulpemventures/go-elements/network" | ||
) | ||
|
||
func TestLWKFromIniFileConfig(t *testing.T) { | ||
t.Parallel() | ||
t.Run("valid ini config", func(t *testing.T) { | ||
t.Parallel() | ||
file := ` | ||
lwk.signername=signername | ||
lwk.walletname=walletname | ||
lwk.lwkendpoint=http://localhost:32110 | ||
lwk.network=liquid | ||
lwk.liquidswaps=true | ||
` | ||
|
||
filePath := filepath.Join(t.TempDir(), "peerswap.conf") | ||
assert.NoError(t, os.WriteFile(filePath, []byte(file), fs.ModePerm)) | ||
got, err := peerswaplnd.LWKFromIniFileConfig(filePath) | ||
if err != nil { | ||
t.Errorf("LWKConfigFromToml() error = %v", err) | ||
return | ||
} | ||
assert.Equal(t, got.GetChain(), &network.Liquid) | ||
assert.Equal(t, got.GetElectrumEndpoint(), "blockstream.info:995") | ||
assert.Equal(t, got.GetLWKEndpoint(), "http://localhost:32110") | ||
assert.Equal(t, got.GetLiquidSwaps(), true) | ||
assert.Equal(t, got.GetNetwork(), "liquid") | ||
}) | ||
t.Run("default ini config", func(t *testing.T) { | ||
t.Parallel() | ||
file := ` | ||
lwk.network=liquid-testnet | ||
lwk.liquidswaps=true | ||
` | ||
|
||
filePath := filepath.Join(t.TempDir(), "peerswap.conf") | ||
assert.NoError(t, os.WriteFile(filePath, []byte(file), fs.ModePerm)) | ||
got, err := peerswaplnd.LWKFromIniFileConfig(filePath) | ||
if err != nil { | ||
t.Errorf("LWKConfigFromToml() error = %v", err) | ||
return | ||
} | ||
assert.Equal(t, got.GetChain(), &network.Testnet) | ||
assert.Equal(t, got.GetElectrumEndpoint(), "blockstream.info:465") | ||
assert.Equal(t, got.GetLWKEndpoint(), "http://localhost:32111") | ||
assert.Equal(t, got.GetLiquidSwaps(), true) | ||
assert.Equal(t, got.GetNetwork(), "liquid-testnet") | ||
}) | ||
} |
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,86 @@ | ||
package lwk_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/elementsproject/peerswap/lwk" | ||
"github.com/vulpemventures/go-elements/network" | ||
) | ||
|
||
func Test_confBuilder_DefaultConf(t *testing.T) { | ||
t.Parallel() | ||
b, err := lwk.NewConfBuilder(lwk.NetworkTestnet).DefaultConf() | ||
if err != nil { | ||
t.Fatalf("unexpected error: %v", err) | ||
} | ||
c, err := b.Build() | ||
if err != nil { | ||
t.Fatalf("unexpected error: %v", err) | ||
} | ||
if c.GetChain() != &network.Testnet { | ||
t.Fatalf("unexpected chain: %v", c.GetChain()) | ||
} | ||
if c.GetElectrumEndpoint() != "blockstream.info:465" { | ||
t.Fatalf("unexpected electrum endpoint: %v", c.GetElectrumEndpoint()) | ||
} | ||
if c.GetLWKEndpoint() != "http://localhost:32111" { | ||
t.Fatalf("unexpected lwk endpoint: %v", c.GetLWKEndpoint()) | ||
} | ||
if c.GetLiquidSwaps() != true { | ||
t.Fatalf("unexpected liquid swaps: %v", c.GetLiquidSwaps()) | ||
} | ||
if c.GetNetwork() != lwk.NetworkTestnet.String() { | ||
t.Fatalf("unexpected network: %v", c.GetNetwork()) | ||
} | ||
if c.GetSignerName() != "defaultPeerswapSigner" { | ||
t.Fatalf("unexpected signer name: %v", c.GetSignerName()) | ||
} | ||
if c.GetWalletName() != "defaultPeerswapWallet" { | ||
t.Fatalf("unexpected wallet name: %v", c.GetWalletName()) | ||
} | ||
} | ||
|
||
func Test_confBuilder_SetConfs(t *testing.T) { | ||
t.Parallel() | ||
t.Run("OK if it called with valid arguments", func(t *testing.T) { | ||
b, err := lwk.NewConfBuilder(lwk.NetworkTestnet).DefaultConf() | ||
if err != nil { | ||
t.Fatalf("unexpected error: %v", err) | ||
} | ||
c, err := b.SetSignerName("testSigner").SetWalletName("testSigner").Build() | ||
if err != nil { | ||
t.Fatalf("unexpected error: %v", err) | ||
} | ||
if c.GetChain() != &network.Testnet { | ||
t.Fatalf("unexpected chain: %v", c.GetChain()) | ||
} | ||
if c.GetElectrumEndpoint() != "blockstream.info:465" { | ||
t.Fatalf("unexpected electrum endpoint: %v", c.GetElectrumEndpoint()) | ||
} | ||
if c.GetLWKEndpoint() != "http://localhost:32111" { | ||
t.Fatalf("unexpected lwk endpoint: %v", c.GetLWKEndpoint()) | ||
} | ||
if c.GetLiquidSwaps() != true { | ||
t.Fatalf("unexpected liquid swaps: %v", c.GetLiquidSwaps()) | ||
} | ||
if c.GetNetwork() != lwk.NetworkTestnet.String() { | ||
t.Fatalf("unexpected network: %v", c.GetNetwork()) | ||
} | ||
if c.GetSignerName() != "testSigner" { | ||
t.Fatalf("unexpected signer name: %v", c.GetSignerName()) | ||
} | ||
if c.GetWalletName() != "testSigner" { | ||
t.Fatalf("unexpected wallet name: %v", c.GetWalletName()) | ||
} | ||
}) | ||
t.Run("Error if it called with empty signer name", func(t *testing.T) { | ||
b, err := lwk.NewConfBuilder(lwk.NetworkTestnet).DefaultConf() | ||
if err != nil { | ||
t.Fatalf("unexpected error: %v", err) | ||
} | ||
_, err = b.SetSignerName("").Build() | ||
if err == nil { | ||
t.Fatalf("expected error, got nil") | ||
} | ||
}) | ||
} |
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,78 @@ | ||
package lwk_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/elementsproject/peerswap/lwk" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestNewlwkNetwork(t *testing.T) { | ||
t.Parallel() | ||
tests := map[string]struct { | ||
network string | ||
want lwk.LwkNetwork | ||
}{ | ||
"mainnet": { | ||
network: "liquid", | ||
want: lwk.NetworkMainnet, | ||
}, | ||
"testnet": { | ||
network: "liquid-testnet", | ||
want: lwk.NetworkTestnet, | ||
}, | ||
"regtest": { | ||
network: "liquid-regtest", | ||
want: lwk.NetworkRegtest, | ||
}, | ||
} | ||
for name, tt := range tests { | ||
tt := tt | ||
t.Run(name, func(t *testing.T) { | ||
t.Parallel() | ||
got, err := lwk.NewlwkNetwork(tt.network) | ||
if err != nil { | ||
t.Errorf("NewlwkNetwork() error = %v", err) | ||
} | ||
if got != tt.want { | ||
t.Errorf("NewlwkNetwork() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestNewConfURL(t *testing.T) { | ||
t.Parallel() | ||
tests := map[string]struct { | ||
endpoint string | ||
want string | ||
wantErr bool | ||
}{ | ||
"valid url": { | ||
endpoint: "http://localhost:32111", | ||
want: "http://localhost:32111", | ||
}, | ||
"without protocol": { | ||
endpoint: "localhost:32111", | ||
want: "localhost:32111", | ||
}, | ||
"invalid url": { | ||
endpoint: "invalid url", | ||
wantErr: true, | ||
}, | ||
} | ||
for name, tt := range tests { | ||
tt := tt | ||
t.Run(name, func(t *testing.T) { | ||
t.Parallel() | ||
got, err := lwk.NewConfURL(tt.endpoint) | ||
if tt.wantErr { | ||
assert.Error(t, err) | ||
return | ||
} | ||
if got.String() != tt.want { | ||
t.Errorf("NewConfURL() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |