htlcswitch: add test for integrated control tower

This commit is contained in:
Vadym Popov 2018-08-12 16:20:57 +03:00 committed by Conner Fromknecht
parent 21fc7aa829
commit 033fd3c83d
No known key found for this signature in database
GPG Key ID: E7D737B67FA592C7
3 changed files with 26 additions and 35 deletions

@ -3755,8 +3755,8 @@ func TestChannelLinkAcceptDuplicatePayment(t *testing.T) {
n.firstBobChannelLink.ShortChanID(), htlc,
newMockDeobfuscator(),
)
if err != nil {
t.Fatalf("error shouldn't have been received got: %v", err)
if err != ErrAlreadyPaid {
t.Fatalf("ErrAlreadyPaid should have been received got: %v", err)
}
}

@ -124,14 +124,26 @@ type mockServer struct {
var _ lnpeer.Peer = (*mockServer)(nil)
func initSwitchWithDB(startingHeight uint32, db *channeldb.DB) (*Switch, error) {
if db == nil {
func initDB() (*channeldb.DB, error) {
tempPath, err := ioutil.TempDir("", "switchdb")
if err != nil {
return nil, err
}
db, err = channeldb.Open(tempPath)
db, err := channeldb.Open(tempPath)
if err != nil {
return nil, err
}
return db, err
}
func initSwitchWithDB(startingHeight uint32, db *channeldb.DB) (*Switch, error) {
var err error
if db == nil {
db, err = initDB()
if err != nil {
return nil, err
}

@ -1678,7 +1678,9 @@ func TestSwitchSendPayment(t *testing.T) {
}
case err := <-errChan:
if err != ErrPaymentInFlight {
t.Fatalf("unable to send payment: %v", err)
}
case <-time.After(time.Second):
t.Fatal("request was not propagated to destination")
}
@ -1695,11 +1697,11 @@ func TestSwitchSendPayment(t *testing.T) {
t.Fatal("request was not propagated to destination")
}
if s.numPendingPayments() != 2 {
if s.numPendingPayments() != 1 {
t.Fatal("wrong amount of pending payments")
}
if s.circuits.NumOpen() != 2 {
if s.circuits.NumOpen() != 1 {
t.Fatal("wrong amount of circuits")
}
@ -1735,29 +1737,6 @@ func TestSwitchSendPayment(t *testing.T) {
t.Fatal("err wasn't received")
}
packet = &htlcPacket{
outgoingChanID: aliceChannelLink.ShortChanID(),
outgoingHTLCID: 1,
htlc: &lnwire.UpdateFailHTLC{
Reason: reason,
},
}
// Send second failure response and check that user were able to
// receive the error.
if err := s.forward(packet); err != nil {
t.Fatalf("can't forward htlc packet: %v", err)
}
select {
case err := <-errChan:
if err.Error() != errors.New(lnwire.CodeIncorrectPaymentAmount).Error() {
t.Fatal("err wasn't received")
}
case <-time.After(time.Second):
t.Fatal("err wasn't received")
}
if s.numPendingPayments() != 0 {
t.Fatal("wrong amount of pending payments")
}