mirror of https://github.com/BTCPrivate/lnd.git
wallet_test: ensure funding tx has been properly stored
* Doesn’t yet include checksums, backups, etc
This commit is contained in:
parent
6bb5febe9e
commit
cc6c59a427
|
@ -1,6 +1,7 @@
|
||||||
package wallet
|
package wallet
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
@ -12,6 +13,7 @@ import (
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/btcsuite/btcutil"
|
"github.com/btcsuite/btcutil"
|
||||||
"github.com/btcsuite/btcwallet/waddrmgr"
|
"github.com/btcsuite/btcwallet/waddrmgr"
|
||||||
|
"github.com/btcsuite/btcwallet/walletdb"
|
||||||
"github.com/btcsuite/btcwallet/wtxmgr"
|
"github.com/btcsuite/btcwallet/wtxmgr"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -340,9 +342,41 @@ func TestBasicWalletReservationWorkFlow(t *testing.T) {
|
||||||
t.Fatalf("unable to complete funding tx: %v", err)
|
t.Fatalf("unable to complete funding tx: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(roasbeef):
|
// At this point, the channel can be considered "open" when the funding
|
||||||
// * verify funding tx commited to disk
|
// txn hits a "comfortable" depth.
|
||||||
// * all sigs valid for all inputs
|
|
||||||
|
// A bucket should have been created for this pending channel, and the
|
||||||
|
// state commited.
|
||||||
|
err = lnwallet.lnNamespace.View(func(tx walletdb.Tx) error {
|
||||||
|
// The open channel bucket should have been created.
|
||||||
|
rootBucket := tx.RootBucket()
|
||||||
|
openChanBucket := rootBucket.Bucket(openChannelBucket)
|
||||||
|
if openChanBucket == nil {
|
||||||
|
t.Fatalf("openChanBucket should be created, but isn't")
|
||||||
|
}
|
||||||
|
|
||||||
|
// The sub-bucket for this channel, keyed by the txid of the
|
||||||
|
// funding transaction
|
||||||
|
txid := chanReservation.fundingTx.TxSha()
|
||||||
|
bobChanBucket := openChanBucket.Bucket(txid[:])
|
||||||
|
if bobChanBucket == nil {
|
||||||
|
t.Fatalf("bucket for the alice-bob channe should exist, " +
|
||||||
|
"but doesn't")
|
||||||
|
}
|
||||||
|
|
||||||
|
var storedTx wire.MsgTx
|
||||||
|
b := bytes.NewReader(bobChanBucket.Get(fundingTxKey))
|
||||||
|
storedTx.Deserialize(b)
|
||||||
|
|
||||||
|
// The hash of the stored tx should be indentical to our funding tx.
|
||||||
|
storedTxId := storedTx.TxSha()
|
||||||
|
actualTxId := chanReservation.fundingTx.TxSha()
|
||||||
|
if !bytes.Equal(storedTxId.Bytes(), actualTxId.Bytes()) {
|
||||||
|
t.Fatalf("stored funding tx doesn't match actual")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
// The funding tx should now be valid and complete.
|
// The funding tx should now be valid and complete.
|
||||||
// Check each input and ensure all scripts are fully valid.
|
// Check each input and ensure all scripts are fully valid.
|
||||||
|
@ -356,9 +390,9 @@ func TestBasicWalletReservationWorkFlow(t *testing.T) {
|
||||||
pkscript = bobNode.changeOutputs[0].PkScript
|
pkscript = bobNode.changeOutputs[0].PkScript
|
||||||
} else {
|
} else {
|
||||||
// Does the wallet know about the txin?
|
// Does the wallet know about the txin?
|
||||||
txDetail, _ := lnwallet.wallet.TxStore.TxDetails(&input.PreviousOutPoint.Hash)
|
txDetail, err := lnwallet.wallet.TxStore.TxDetails(&input.PreviousOutPoint.Hash)
|
||||||
if txDetail == nil {
|
if txDetail == nil || err != nil {
|
||||||
panic(fmt.Errorf("not found!"))
|
t.Fatalf("txstore can't find tx detail, err: %v", err)
|
||||||
}
|
}
|
||||||
prevIndex := input.PreviousOutPoint.Index
|
prevIndex := input.PreviousOutPoint.Index
|
||||||
pkscript = txDetail.TxRecord.MsgTx.TxOut[prevIndex].PkScript
|
pkscript = txDetail.TxRecord.MsgTx.TxOut[prevIndex].PkScript
|
||||||
|
|
Loading…
Reference in New Issue