rpcserver: check for compatible network in SendCoins
lnd_test: adding address validation for send coins The commit adds a test that checks that when a user calls sendcoins, the receiving address is validated according to the current network. If the address is not compatible with the current network, it will return an error to the user. rpcserver: adding a check for compatible network in SendCoins This commit adds a check in SendCoins that checks whether the receiving address is compatible with the current network. Fixes #2677.
This commit is contained in:
1 parent
341f5e4329
commit
abfbdf6aec
2 files changed
+46
-13
No files matched your search
+30
-2
@@ -13168,12 +13168,40 @@ func testSweepAllCoins(net *lntest.NetworkHarness, t *harnessTest) {
|
||||
|
||||
// With the two coins above mined, we'll now instruct ainz to sweep all
|
||||
// the coins to an external address not under its control.
|
||||
// We will first attempt to send the coins to addresses that are not
|
||||
// compatible with the current network. This is to test that the wallet
|
||||
// will prevent any onchain transactions to addresses that are not on the
|
||||
// same network as the user.
|
||||
|
||||
// Send coins to a testnet3 address.
|
||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||
sweepReq := &lnrpc.SendCoinsRequest{
|
||||
Addr: "tb1qfc8fusa98jx8uvnhzavxccqlzvg749tvjw82tg",
|
||||
SendAll: true,
|
||||
}
|
||||
_, err = ainz.SendCoins(ctxt, sweepReq)
|
||||
if err == nil {
|
||||
t.Fatalf("expected SendCoins to different network to fail")
|
||||
}
|
||||
|
||||
// Send coins to a mainnet address.
|
||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||
sweepReq = &lnrpc.SendCoinsRequest{
|
||||
Addr: "1MPaXKp5HhsLNjVSqaL7fChE3TVyrTMRT3",
|
||||
SendAll: true,
|
||||
}
|
||||
_, err = ainz.SendCoins(ctxt, sweepReq)
|
||||
if err == nil {
|
||||
t.Fatalf("expected SendCoins to different network to fail")
|
||||
}
|
||||
|
||||
// Send coins to a compatible address.
|
||||
minerAddr, err := net.Miner.NewAddress()
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create new miner addr: %v", err)
|
||||
}
|
||||
|
||||
sweepReq := &lnrpc.SendCoinsRequest{
|
||||
sweepReq = &lnrpc.SendCoinsRequest{
|
||||
Addr: minerAddr.String(),
|
||||
SendAll: true,
|
||||
}
|
||||
@@ -13183,7 +13211,7 @@ func testSweepAllCoins(net *lntest.NetworkHarness, t *harnessTest) {
|
||||
t.Fatalf("unable to sweep coins: %v", err)
|
||||
}
|
||||
|
||||
// We'll mine a block wish should include the sweep transaction we
|
||||
// We'll mine a block which should include the sweep transaction we
|
||||
// generated above.
|
||||
block := mineBlocks(t, net, 1, 1)[0]
|
||||
|
||||
|
||||
Reference in new issue
Block a user