From c08377d303d7f95b45dc51933ea9c0579eb01b27 Mon Sep 17 00:00:00 2001 From: carla Date: Thu, 30 Jan 2020 10:01:10 +0200 Subject: [PATCH] htlcswitch/test: replace mock server delta with constant --- htlcswitch/link_test.go | 1 + htlcswitch/switch_test.go | 96 +++++++++++++++++++++++++++++---------- 2 files changed, 73 insertions(+), 24 deletions(-) diff --git a/htlcswitch/link_test.go b/htlcswitch/link_test.go index 16d64d70..427322ee 100644 --- a/htlcswitch/link_test.go +++ b/htlcswitch/link_test.go @@ -39,6 +39,7 @@ import ( const ( testStartingHeight = 100 + testDefaultDelta = 6 ) // concurrentTester is a thread-safe wrapper around the Fatalf method of a diff --git a/htlcswitch/switch_test.go b/htlcswitch/switch_test.go index 69425dc2..1497f009 100644 --- a/htlcswitch/switch_test.go +++ b/htlcswitch/switch_test.go @@ -32,7 +32,9 @@ func genPreimage() ([32]byte, error) { func TestSwitchAddDuplicateLink(t *testing.T) { t.Parallel() - alicePeer, err := newMockServer(t, "alice", testStartingHeight, nil, 6) + alicePeer, err := newMockServer( + t, "alice", testStartingHeight, nil, testDefaultDelta, + ) if err != nil { t.Fatalf("unable to create alice server: %v", err) } @@ -90,7 +92,9 @@ func TestSwitchAddDuplicateLink(t *testing.T) { func TestSwitchHasActiveLink(t *testing.T) { t.Parallel() - alicePeer, err := newMockServer(t, "alice", testStartingHeight, nil, 6) + alicePeer, err := newMockServer( + t, "alice", testStartingHeight, nil, testDefaultDelta, + ) if err != nil { t.Fatalf("unable to create alice server: %v", err) } @@ -158,7 +162,9 @@ func TestSwitchHasActiveLink(t *testing.T) { func TestSwitchSendPending(t *testing.T) { t.Parallel() - alicePeer, err := newMockServer(t, "alice", testStartingHeight, nil, 6) + alicePeer, err := newMockServer( + t, "alice", testStartingHeight, nil, testDefaultDelta, + ) if err != nil { t.Fatalf("unable to create alice server: %v", err) } @@ -253,11 +259,15 @@ func TestSwitchSendPending(t *testing.T) { func TestSwitchForward(t *testing.T) { t.Parallel() - alicePeer, err := newMockServer(t, "alice", testStartingHeight, nil, 6) + alicePeer, err := newMockServer( + t, "alice", testStartingHeight, nil, testDefaultDelta, + ) if err != nil { t.Fatalf("unable to create alice server: %v", err) } - bobPeer, err := newMockServer(t, "bob", testStartingHeight, nil, 6) + bobPeer, err := newMockServer( + t, "bob", testStartingHeight, nil, testDefaultDelta, + ) if err != nil { t.Fatalf("unable to create bob server: %v", err) } @@ -358,11 +368,15 @@ func TestSwitchForwardFailAfterFullAdd(t *testing.T) { chanID1, chanID2, aliceChanID, bobChanID := genIDs() - alicePeer, err := newMockServer(t, "alice", testStartingHeight, nil, 6) + alicePeer, err := newMockServer( + t, "alice", testStartingHeight, nil, testDefaultDelta, + ) if err != nil { t.Fatalf("unable to create alice server: %v", err) } - bobPeer, err := newMockServer(t, "bob", testStartingHeight, nil, 6) + bobPeer, err := newMockServer( + t, "bob", testStartingHeight, nil, testDefaultDelta, + ) if err != nil { t.Fatalf("unable to create bob server: %v", err) } @@ -549,11 +563,15 @@ func TestSwitchForwardSettleAfterFullAdd(t *testing.T) { chanID1, chanID2, aliceChanID, bobChanID := genIDs() - alicePeer, err := newMockServer(t, "alice", testStartingHeight, nil, 6) + alicePeer, err := newMockServer( + t, "alice", testStartingHeight, nil, testDefaultDelta, + ) if err != nil { t.Fatalf("unable to create alice server: %v", err) } - bobPeer, err := newMockServer(t, "bob", testStartingHeight, nil, 6) + bobPeer, err := newMockServer( + t, "bob", testStartingHeight, nil, testDefaultDelta, + ) if err != nil { t.Fatalf("unable to create bob server: %v", err) } @@ -743,11 +761,15 @@ func TestSwitchForwardDropAfterFullAdd(t *testing.T) { chanID1, chanID2, aliceChanID, bobChanID := genIDs() - alicePeer, err := newMockServer(t, "alice", testStartingHeight, nil, 6) + alicePeer, err := newMockServer( + t, "alice", testStartingHeight, nil, testDefaultDelta, + ) if err != nil { t.Fatalf("unable to create alice server: %v", err) } - bobPeer, err := newMockServer(t, "bob", testStartingHeight, nil, 6) + bobPeer, err := newMockServer( + t, "bob", testStartingHeight, nil, testDefaultDelta, + ) if err != nil { t.Fatalf("unable to create bob server: %v", err) } @@ -906,11 +928,15 @@ func TestSwitchForwardFailAfterHalfAdd(t *testing.T) { chanID1, chanID2, aliceChanID, bobChanID := genIDs() - alicePeer, err := newMockServer(t, "alice", testStartingHeight, nil, 6) + alicePeer, err := newMockServer( + t, "alice", testStartingHeight, nil, testDefaultDelta, + ) if err != nil { t.Fatalf("unable to create alice server: %v", err) } - bobPeer, err := newMockServer(t, "bob", testStartingHeight, nil, 6) + bobPeer, err := newMockServer( + t, "bob", testStartingHeight, nil, testDefaultDelta, + ) if err != nil { t.Fatalf("unable to create bob server: %v", err) } @@ -1064,11 +1090,15 @@ func TestSwitchForwardCircuitPersistence(t *testing.T) { chanID1, chanID2, aliceChanID, bobChanID := genIDs() - alicePeer, err := newMockServer(t, "alice", testStartingHeight, nil, 6) + alicePeer, err := newMockServer( + t, "alice", testStartingHeight, nil, testDefaultDelta, + ) if err != nil { t.Fatalf("unable to create alice server: %v", err) } - bobPeer, err := newMockServer(t, "bob", testStartingHeight, nil, 6) + bobPeer, err := newMockServer( + t, "bob", testStartingHeight, nil, testDefaultDelta, + ) if err != nil { t.Fatalf("unable to create bob server: %v", err) } @@ -1359,11 +1389,15 @@ func testSkipIneligibleLinksMultiHopForward(t *testing.T, var packet *htlcPacket - alicePeer, err := newMockServer(t, "alice", testStartingHeight, nil, 6) + alicePeer, err := newMockServer( + t, "alice", testStartingHeight, nil, testDefaultDelta, + ) if err != nil { t.Fatalf("unable to create alice server: %v", err) } - bobPeer, err := newMockServer(t, "bob", testStartingHeight, nil, 6) + bobPeer, err := newMockServer( + t, "bob", testStartingHeight, nil, testDefaultDelta, + ) if err != nil { t.Fatalf("unable to create bob server: %v", err) } @@ -1470,7 +1504,9 @@ func testSkipLinkLocalForward(t *testing.T, eligible bool, // We'll create a single link for this test, marking it as being unable // to forward form the get go. - alicePeer, err := newMockServer(t, "alice", testStartingHeight, nil, 6) + alicePeer, err := newMockServer( + t, "alice", testStartingHeight, nil, testDefaultDelta, + ) if err != nil { t.Fatalf("unable to create alice server: %v", err) } @@ -1524,11 +1560,15 @@ func testSkipLinkLocalForward(t *testing.T, eligible bool, func TestSwitchCancel(t *testing.T) { t.Parallel() - alicePeer, err := newMockServer(t, "alice", testStartingHeight, nil, 6) + alicePeer, err := newMockServer( + t, "alice", testStartingHeight, nil, testDefaultDelta, + ) if err != nil { t.Fatalf("unable to create alice server: %v", err) } - bobPeer, err := newMockServer(t, "bob", testStartingHeight, nil, 6) + bobPeer, err := newMockServer( + t, "bob", testStartingHeight, nil, testDefaultDelta, + ) if err != nil { t.Fatalf("unable to create bob server: %v", err) } @@ -1637,11 +1677,15 @@ func TestSwitchAddSamePayment(t *testing.T) { chanID1, chanID2, aliceChanID, bobChanID := genIDs() - alicePeer, err := newMockServer(t, "alice", testStartingHeight, nil, 6) + alicePeer, err := newMockServer( + t, "alice", testStartingHeight, nil, testDefaultDelta, + ) if err != nil { t.Fatalf("unable to create alice server: %v", err) } - bobPeer, err := newMockServer(t, "bob", testStartingHeight, nil, 6) + bobPeer, err := newMockServer( + t, "bob", testStartingHeight, nil, testDefaultDelta, + ) if err != nil { t.Fatalf("unable to create bob server: %v", err) } @@ -1796,7 +1840,9 @@ func TestSwitchAddSamePayment(t *testing.T) { func TestSwitchSendPayment(t *testing.T) { t.Parallel() - alicePeer, err := newMockServer(t, "alice", testStartingHeight, nil, 6) + alicePeer, err := newMockServer( + t, "alice", testStartingHeight, nil, testDefaultDelta, + ) if err != nil { t.Fatalf("unable to create alice server: %v", err) } @@ -2334,7 +2380,9 @@ func TestSwitchGetPaymentResult(t *testing.T) { func TestInvalidFailure(t *testing.T) { t.Parallel() - alicePeer, err := newMockServer(t, "alice", testStartingHeight, nil, 6) + alicePeer, err := newMockServer( + t, "alice", testStartingHeight, nil, testDefaultDelta, + ) if err != nil { t.Fatalf("unable to create alice server: %v", err) }