lnd_test+lntest: seperate miner and chain backend
Since we are no longer passing in the miner as the chain backend, we don't have to export the fields.
This commit is contained in:
parent
989fe50da8
commit
92b984a233
74
lnd_test.go
74
lnd_test.go
@ -12930,54 +12930,73 @@ var testsCases = []*testCase{
|
|||||||
func TestLightningNetworkDaemon(t *testing.T) {
|
func TestLightningNetworkDaemon(t *testing.T) {
|
||||||
ht := newHarnessTest(t)
|
ht := newHarnessTest(t)
|
||||||
|
|
||||||
|
// Start a btcd chain backend.
|
||||||
|
chainBackend, cleanUp, err := lntest.NewBtcdBackend()
|
||||||
|
if err != nil {
|
||||||
|
ht.Fatalf("unable to start btcd: %v", err)
|
||||||
|
}
|
||||||
|
defer cleanUp()
|
||||||
|
|
||||||
|
// Declare the network harness here to gain access to its
|
||||||
|
// 'OnTxAccepted' call back.
|
||||||
var lndHarness *lntest.NetworkHarness
|
var lndHarness *lntest.NetworkHarness
|
||||||
|
|
||||||
// First create an instance of the btcd's rpctest.Harness. This will be
|
// Create an instance of the btcd's rpctest.Harness that will act as
|
||||||
// used to fund the wallets of the nodes within the test network and to
|
// the miner for all tests. This will be used to fund the wallets of
|
||||||
// drive blockchain related events within the network. Revert the default
|
// the nodes within the test network and to drive blockchain related
|
||||||
// setting of accepting non-standard transactions on simnet to reject them.
|
// events within the network. Revert the default setting of accepting
|
||||||
// Transactions on the lightning network should always be standard to get
|
// non-standard transactions on simnet to reject them. Transactions on
|
||||||
// better guarantees of getting included in to blocks.
|
// the lightning network should always be standard to get better
|
||||||
logDir := "./.backendlogs"
|
// guarantees of getting included in to blocks.
|
||||||
|
//
|
||||||
|
// We will also connect it to our chain backend.
|
||||||
|
minerLogDir := "./.minerlogs"
|
||||||
args := []string{
|
args := []string{
|
||||||
"--rejectnonstd",
|
"--rejectnonstd",
|
||||||
"--txindex",
|
"--txindex",
|
||||||
"--debuglevel=debug",
|
"--debuglevel=debug",
|
||||||
"--logdir=" + logDir,
|
"--logdir=" + minerLogDir,
|
||||||
|
"--trickleinterval=100ms",
|
||||||
|
"--connect=" + chainBackend.P2PAddr(),
|
||||||
}
|
}
|
||||||
handlers := &rpcclient.NotificationHandlers{
|
handlers := &rpcclient.NotificationHandlers{
|
||||||
OnTxAccepted: func(hash *chainhash.Hash, amt btcutil.Amount) {
|
OnTxAccepted: func(hash *chainhash.Hash, amt btcutil.Amount) {
|
||||||
lndHarness.OnTxAccepted(hash)
|
lndHarness.OnTxAccepted(hash)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
btcdHarness, err := rpctest.New(harnessNetParams, handlers, args)
|
|
||||||
|
miner, err := rpctest.New(harnessNetParams, handlers, args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ht.Fatalf("unable to create mining node: %v", err)
|
ht.Fatalf("unable to create mining node: %v", err)
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
btcdHarness.TearDown()
|
miner.TearDown()
|
||||||
|
|
||||||
// After shutting down the chain backend, we'll make a copy of
|
// After shutting down the miner, we'll make a copy of the log
|
||||||
// the log file before deleting the temporary log dir.
|
// file before deleting the temporary log dir.
|
||||||
logFile := logDir + "/" + harnessNetParams.Name + "/btcd.log"
|
logFile := fmt.Sprintf(
|
||||||
err := lntest.CopyFile("./output_btcd_chainbackend.log",
|
"%s/%s/btcd.log", minerLogDir, harnessNetParams.Name,
|
||||||
logFile)
|
)
|
||||||
|
err := lntest.CopyFile("./output_btcd_miner.log", logFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("unable to copy file: %v\n", err)
|
fmt.Printf("unable to copy file: %v\n", err)
|
||||||
}
|
}
|
||||||
if err = os.RemoveAll(logDir); err != nil {
|
if err = os.RemoveAll(minerLogDir); err != nil {
|
||||||
fmt.Printf("Cannot remove dir %s: %v\n", logDir, err)
|
fmt.Printf("Cannot remove dir %s: %v\n",
|
||||||
|
minerLogDir, err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
chainBackend := lntest.BtcdBackendConfig{
|
if err := miner.SetUp(true, 50); err != nil {
|
||||||
RPCConfig: btcdHarness.RPCConfig(),
|
ht.Fatalf("unable to set up mining node: %v", err)
|
||||||
P2PAddress: btcdHarness.P2PAddress(),
|
}
|
||||||
|
if err := miner.Node.NotifyNewTransactions(false); err != nil {
|
||||||
|
ht.Fatalf("unable to request transaction notifications: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// First create the network harness to gain access to its
|
// Now we can set up our test harness (LND instance), with the chain
|
||||||
// 'OnTxAccepted' call back.
|
// backend we just created.
|
||||||
lndHarness, err = lntest.NewNetworkHarness(btcdHarness, chainBackend)
|
lndHarness, err = lntest.NewNetworkHarness(miner, chainBackend)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ht.Fatalf("unable to create lightning network harness: %v", err)
|
ht.Fatalf("unable to create lightning network harness: %v", err)
|
||||||
}
|
}
|
||||||
@ -12999,17 +13018,10 @@ func TestLightningNetworkDaemon(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if err := btcdHarness.SetUp(true, 50); err != nil {
|
|
||||||
ht.Fatalf("unable to set up mining node: %v", err)
|
|
||||||
}
|
|
||||||
if err := btcdHarness.Node.NotifyNewTransactions(false); err != nil {
|
|
||||||
ht.Fatalf("unable to request transaction notifications: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Next mine enough blocks in order for segwit and the CSV package
|
// Next mine enough blocks in order for segwit and the CSV package
|
||||||
// soft-fork to activate on SimNet.
|
// soft-fork to activate on SimNet.
|
||||||
numBlocks := chaincfg.SimNetParams.MinerConfirmationWindow * 2
|
numBlocks := chaincfg.SimNetParams.MinerConfirmationWindow * 2
|
||||||
if _, err := btcdHarness.Node.Generate(numBlocks); err != nil {
|
if _, err := miner.Node.Generate(numBlocks); err != nil {
|
||||||
ht.Fatalf("unable to generate blocks: %v", err)
|
ht.Fatalf("unable to generate blocks: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,22 +16,22 @@ const logDir = "./.backendlogs"
|
|||||||
// BtcdBackendConfig is an implementation of the BackendConfig interface
|
// BtcdBackendConfig is an implementation of the BackendConfig interface
|
||||||
// backed by a btcd node.
|
// backed by a btcd node.
|
||||||
type BtcdBackendConfig struct {
|
type BtcdBackendConfig struct {
|
||||||
// RPCConfig houses the connection config to the backing btcd instance.
|
// rpcConfig houses the connection config to the backing btcd instance.
|
||||||
RPCConfig rpcclient.ConnConfig
|
rpcConfig rpcclient.ConnConfig
|
||||||
|
|
||||||
// P2PAddress is the p2p address of the btcd instance.
|
// p2pAddress is the p2p address of the btcd instance.
|
||||||
P2PAddress string
|
p2pAddress string
|
||||||
}
|
}
|
||||||
|
|
||||||
// GenArgs returns the arguments needed to be passed to LND at startup for
|
// GenArgs returns the arguments needed to be passed to LND at startup for
|
||||||
// using this node as a chain backend.
|
// using this node as a chain backend.
|
||||||
func (b BtcdBackendConfig) GenArgs() []string {
|
func (b BtcdBackendConfig) GenArgs() []string {
|
||||||
var args []string
|
var args []string
|
||||||
encodedCert := hex.EncodeToString(b.RPCConfig.Certificates)
|
encodedCert := hex.EncodeToString(b.rpcConfig.Certificates)
|
||||||
args = append(args, "--bitcoin.node=btcd")
|
args = append(args, "--bitcoin.node=btcd")
|
||||||
args = append(args, fmt.Sprintf("--btcd.rpchost=%v", b.RPCConfig.Host))
|
args = append(args, fmt.Sprintf("--btcd.rpchost=%v", b.rpcConfig.Host))
|
||||||
args = append(args, fmt.Sprintf("--btcd.rpcuser=%v", b.RPCConfig.User))
|
args = append(args, fmt.Sprintf("--btcd.rpcuser=%v", b.rpcConfig.User))
|
||||||
args = append(args, fmt.Sprintf("--btcd.rpcpass=%v", b.RPCConfig.Pass))
|
args = append(args, fmt.Sprintf("--btcd.rpcpass=%v", b.rpcConfig.Pass))
|
||||||
args = append(args, fmt.Sprintf("--btcd.rawrpccert=%v", encodedCert))
|
args = append(args, fmt.Sprintf("--btcd.rawrpccert=%v", encodedCert))
|
||||||
|
|
||||||
return args
|
return args
|
||||||
@ -40,7 +40,7 @@ func (b BtcdBackendConfig) GenArgs() []string {
|
|||||||
// P2PAddr returns the address of this node to be used when connection over the
|
// P2PAddr returns the address of this node to be used when connection over the
|
||||||
// Bitcoin P2P network.
|
// Bitcoin P2P network.
|
||||||
func (b BtcdBackendConfig) P2PAddr() string {
|
func (b BtcdBackendConfig) P2PAddr() string {
|
||||||
return b.P2PAddress
|
return b.p2pAddress
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewBtcdBackend starts a new rpctest.Harness and returns a BtcdBackendConfig
|
// NewBtcdBackend starts a new rpctest.Harness and returns a BtcdBackendConfig
|
||||||
@ -64,8 +64,8 @@ func NewBtcdBackend() (*BtcdBackendConfig, func(), error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bd := &BtcdBackendConfig{
|
bd := &BtcdBackendConfig{
|
||||||
RPCConfig: chainBackend.RPCConfig(),
|
rpcConfig: chainBackend.RPCConfig(),
|
||||||
P2PAddress: chainBackend.P2PAddress(),
|
p2pAddress: chainBackend.P2PAddress(),
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanUp := func() {
|
cleanUp := func() {
|
||||||
|
Loading…
Reference in New Issue
Block a user