server: extract bootstrap logic into new function w/ unit test

This commit is contained in:
Olaoluwa Osuntokun
2021-08-04 18:27:27 -07:00
parent 6b1696c4f2
commit 673acd781d
2 changed files with 96 additions and 5 deletions

View File

@@ -17,6 +17,8 @@ import (
"os"
"testing"
"time"
"github.com/lightningnetwork/lnd/lncfg"
)
func TestParseHexColor(t *testing.T) {
@@ -203,3 +205,84 @@ func genExpiredCertPair(t *testing.T, certDirPath string) ([]byte, []byte) {
return certDerBytes, keyBytes
}
// TestShouldPeerBootstrap tests that we properly skip network bootstrap for
// the developer networks, and also if bootstrapping is explicitly disabled.
func TestShouldPeerBootstrap(t *testing.T) {
t.Parallel()
testCases := []struct {
cfg *Config
shouldBoostrap bool
}{
// Simnet active, no bootstrap.
{
cfg: &Config{
Bitcoin: &lncfg.Chain{
SimNet: true,
},
Litecoin: &lncfg.Chain{},
},
},
// Regtest active, no bootstrap.
{
cfg: &Config{
Bitcoin: &lncfg.Chain{
RegTest: true,
},
Litecoin: &lncfg.Chain{},
},
},
// Signet active, no bootstrap.
{
cfg: &Config{
Bitcoin: &lncfg.Chain{
SigNet: true,
},
Litecoin: &lncfg.Chain{},
},
},
// Mainnet active, but boostrap disabled, no boostrap.
{
cfg: &Config{
Bitcoin: &lncfg.Chain{
MainNet: true,
},
Litecoin: &lncfg.Chain{},
NoNetBootstrap: true,
},
},
// Mainnet active, should boostrap.
{
cfg: &Config{
Bitcoin: &lncfg.Chain{
MainNet: true,
},
Litecoin: &lncfg.Chain{},
},
shouldBoostrap: true,
},
// Testnet active, should boostrap.
{
cfg: &Config{
Bitcoin: &lncfg.Chain{
TestNet3: true,
},
Litecoin: &lncfg.Chain{},
},
shouldBoostrap: true,
},
}
for i, testCase := range testCases {
bootstrapped := shouldPeerBootstrap(testCase.cfg)
if bootstrapped != testCase.shouldBoostrap {
t.Fatalf("#%v: expected bootstrap=%v, got bootstrap=%v",
i, testCase.shouldBoostrap, bootstrapped)
}
}
}