mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-02-22 14:22:37 +01:00
Merge pull request #7272 from positiveblue/fix-7270
rpc: check that closing address matches the current network for open channel requests
This commit is contained in:
commit
cfc48bd81c
5 changed files with 67 additions and 4 deletions
|
@ -55,7 +55,7 @@ func newChanAcceptorCtx(t *testing.T, acceptCallCount int,
|
|||
|
||||
testCtx.acceptor = NewRPCAcceptor(
|
||||
testCtx.receiveResponse, testCtx.sendRequest, testTimeout*5,
|
||||
&chaincfg.TestNet3Params, testCtx.quit,
|
||||
&chaincfg.RegressionNetParams, testCtx.quit,
|
||||
)
|
||||
|
||||
return testCtx
|
||||
|
@ -162,7 +162,7 @@ func (c *channelAcceptorCtx) queryAndAssert(queries map[*lnwire.OpenChannel]*Cha
|
|||
func TestMultipleAcceptClients(t *testing.T) {
|
||||
testAddr := "bcrt1qwrmq9uca0t3dy9t9wtuq5tm4405r7tfzyqn9pp"
|
||||
testUpfront, err := chancloser.ParseUpfrontShutdownAddress(
|
||||
testAddr, &chaincfg.TestNet3Params,
|
||||
testAddr, &chaincfg.RegressionNetParams,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ func TestValidateAcceptorResponse(t *testing.T) {
|
|||
customError = errors.New("custom error")
|
||||
validAddr = "bcrt1qwrmq9uca0t3dy9t9wtuq5tm4405r7tfzyqn9pp"
|
||||
addr, _ = chancloser.ParseUpfrontShutdownAddress(
|
||||
validAddr, &chaincfg.TestNet3Params,
|
||||
validAddr, &chaincfg.RegressionNetParams,
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -124,7 +124,7 @@ func TestValidateAcceptorResponse(t *testing.T) {
|
|||
// Create an acceptor, everything can be nil because
|
||||
// we just need the params.
|
||||
acceptor := NewRPCAcceptor(
|
||||
nil, nil, 0, &chaincfg.TestNet3Params, nil,
|
||||
nil, nil, 0, &chaincfg.RegressionNetParams, nil,
|
||||
)
|
||||
|
||||
accept, acceptErr, shutdown, err := acceptor.validateAcceptorResponse(
|
||||
|
|
|
@ -89,6 +89,9 @@ current gossip sync query status.
|
|||
obtained via `QueryMissionControl`.](
|
||||
https://github.com/lightningnetwork/lnd/pull/6857)
|
||||
|
||||
* [Ensure that closing addresses match the node network for `OpenChannel`
|
||||
requests](https://github.com/lightningnetwork/lnd/pull/7272)
|
||||
|
||||
## Wallet
|
||||
|
||||
* [Allows Taproot public keys and tap scripts to be imported as watch-only
|
||||
|
|
|
@ -918,5 +918,10 @@ func ParseUpfrontShutdownAddress(address string,
|
|||
return nil, fmt.Errorf("invalid address: %v", err)
|
||||
}
|
||||
|
||||
if !addr.IsForNet(params) {
|
||||
return nil, fmt.Errorf("invalid address: %v is not a %s "+
|
||||
"address", addr, params.Name)
|
||||
}
|
||||
|
||||
return txscript.PayToAddrScript(addr)
|
||||
}
|
||||
|
|
|
@ -322,3 +322,58 @@ func TestMaxFeeBailOut(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestParseUpfrontShutdownAddress tests the we are able to parse the upfront
|
||||
// shutdown address properly.
|
||||
func TestParseUpfrontShutdownAddress(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var (
|
||||
testnetAddress = "tb1qdfkmwwgdaa5dnezrlhtftvmj5qn2kwgp7n0z6r"
|
||||
regtestAddress = "bcrt1q09crvvuj95x5nk64wsxf5n6ky0kr8358vpx4d8"
|
||||
)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
address string
|
||||
params chaincfg.Params
|
||||
expectedErr string
|
||||
}{
|
||||
{
|
||||
name: "invalid closing address",
|
||||
address: "non-valid-address",
|
||||
params: chaincfg.RegressionNetParams,
|
||||
expectedErr: "invalid address",
|
||||
},
|
||||
{
|
||||
name: "closing address from another net",
|
||||
address: testnetAddress,
|
||||
params: chaincfg.RegressionNetParams,
|
||||
expectedErr: "not a regtest address",
|
||||
},
|
||||
{
|
||||
name: "valid p2wkh closing address",
|
||||
address: regtestAddress,
|
||||
params: chaincfg.RegressionNetParams,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
tc := tc
|
||||
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
_, err := ParseUpfrontShutdownAddress(
|
||||
tc.address, &tc.params,
|
||||
)
|
||||
|
||||
if tc.expectedErr != "" {
|
||||
require.ErrorContains(t, err, tc.expectedErr)
|
||||
return
|
||||
}
|
||||
|
||||
require.NoError(t, err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue