mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-10-10 18:12:59 +02:00
lnwallet: update tests to AddContribution API change
This commit is contained in:
@@ -3,6 +3,7 @@ package lnwallet
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -61,7 +62,12 @@ func assertProperBalance(t *testing.T, lw *LightningWallet, numConfirms, amount
|
|||||||
// only "default-route", we have a direct connection with him.
|
// only "default-route", we have a direct connection with him.
|
||||||
type bobNode struct {
|
type bobNode struct {
|
||||||
privKey *btcec.PrivateKey
|
privKey *btcec.PrivateKey
|
||||||
multiSigKey *btcec.PublicKey
|
|
||||||
|
// For simplicity, used for both the commit tx and the multi-sig output.
|
||||||
|
channelKey *btcec.PublicKey
|
||||||
|
deliveryAddress btcutil.Address
|
||||||
|
revocation [wire.HashSize]byte
|
||||||
|
delay int64
|
||||||
|
|
||||||
availableOutputs []*wire.TxIn
|
availableOutputs []*wire.TxIn
|
||||||
changeOutputs []*wire.TxOut
|
changeOutputs []*wire.TxOut
|
||||||
@@ -118,9 +124,18 @@ func newBobNode() (*bobNode, error) {
|
|||||||
// Using bobs priv key above, create a change address he can spend.
|
// Using bobs priv key above, create a change address he can spend.
|
||||||
bobChangeOutput := wire.NewTxOut(2*1e8, bobAddrScript)
|
bobChangeOutput := wire.NewTxOut(2*1e8, bobAddrScript)
|
||||||
|
|
||||||
|
// Bob's initial revocation hash is just his private key with the first
|
||||||
|
// byte changed...
|
||||||
|
var revocation [wire.HashSize]byte
|
||||||
|
copy(revocation[:], bobsPrivKey)
|
||||||
|
revocation[0] = 0xff
|
||||||
|
|
||||||
return &bobNode{
|
return &bobNode{
|
||||||
privKey: privKey,
|
privKey: privKey,
|
||||||
multiSigKey: pubKey,
|
channelKey: pubKey,
|
||||||
|
deliveryAddress: bobAddr,
|
||||||
|
revocation: revocation,
|
||||||
|
delay: 5,
|
||||||
availableOutputs: []*wire.TxIn{bobTxIn},
|
availableOutputs: []*wire.TxIn{bobTxIn},
|
||||||
changeOutputs: []*wire.TxOut{bobChangeOutput},
|
changeOutputs: []*wire.TxOut{bobChangeOutput},
|
||||||
}, nil
|
}, nil
|
||||||
@@ -293,17 +308,19 @@ func testBasicWalletReservationWorkFlow(lnwallet *LightningWallet, t *testing.T)
|
|||||||
t.Fatalf("alice's key for multi-sig not found")
|
t.Fatalf("alice's key for multi-sig not found")
|
||||||
}
|
}
|
||||||
if ourCommitKey == nil {
|
if ourCommitKey == nil {
|
||||||
// TODO(roasbeef): gen commit
|
t.Fatalf("alice's key for commit not found")
|
||||||
// t.Fatalf("alice's key for commit not found")
|
|
||||||
}
|
}
|
||||||
if ourChange[0].Value != 3e8 {
|
if ourChange[0].Value != 3e8 {
|
||||||
t.Fatalf("coin selection failed, change output should be 3e8 "+
|
t.Fatalf("coin selection failed, change output should be 3e8 "+
|
||||||
"satoshis, is instead %v", ourChange[0].Value)
|
"satoshis, is instead %v", ourChange[0].Value)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bob sends over his output, change addr and multi-sig key.
|
// Bob sends over his output, change addr, pub keys, initial revocation,
|
||||||
if err := chanReservation.AddFunds(bobNode.availableOutputs,
|
// final delivery address, and his accepted csv delay for the commitmen
|
||||||
bobNode.changeOutputs, bobNode.multiSigKey); err != nil {
|
// t transactions.
|
||||||
|
if err := chanReservation.AddContribution(bobNode.availableOutputs,
|
||||||
|
bobNode.changeOutputs, bobNode.channelKey, bobNode.channelKey,
|
||||||
|
bobNode.deliveryAddress, bobNode.revocation, bobNode.delay); err != nil {
|
||||||
t.Fatalf("unable to add bob's funds to the funding tx: %v", err)
|
t.Fatalf("unable to add bob's funds to the funding tx: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -328,8 +345,7 @@ func testBasicWalletReservationWorkFlow(lnwallet *LightningWallet, t *testing.T)
|
|||||||
t.Fatalf("bob's key for multi-sig not found")
|
t.Fatalf("bob's key for multi-sig not found")
|
||||||
}
|
}
|
||||||
if theirCommitKey == nil {
|
if theirCommitKey == nil {
|
||||||
// TODO(roasbeef): gen commit
|
t.Fatalf("bob's key for commit tx not found")
|
||||||
// t.Fatalf("alice's key for commit not found")
|
|
||||||
}
|
}
|
||||||
if theirChange[0].Value != 2e8 {
|
if theirChange[0].Value != 2e8 {
|
||||||
t.Fatalf("bob should have one change output with value 2e8"+
|
t.Fatalf("bob should have one change output with value 2e8"+
|
||||||
@@ -342,7 +358,8 @@ func testBasicWalletReservationWorkFlow(lnwallet *LightningWallet, t *testing.T)
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to sign inputs for bob: %v", err)
|
t.Fatalf("unable to sign inputs for bob: %v", err)
|
||||||
}
|
}
|
||||||
if err := chanReservation.CompleteReservation(bobsSigs); err != nil {
|
var fakeCommitSig []byte
|
||||||
|
if err := chanReservation.CompleteReservation(bobsSigs, fakeCommitSig); err != nil {
|
||||||
t.Fatalf("unable to complete funding tx: %v", err)
|
t.Fatalf("unable to complete funding tx: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user