channeldb: remove redudant test

After addition of the bidirectional payment test in htlcswitch packet,
which is more abstract, we may remove redudant test.
This commit is contained in:
Andrey Samokhvalov 2017-05-22 20:30:15 +03:00 committed by Olaoluwa Osuntokun
parent 7595bee27c
commit 79feebea80

@ -8,7 +8,6 @@ import (
"testing"
"github.com/davecgh/go-spew/spew"
"github.com/go-errors/errors"
"github.com/lightningnetwork/lnd/chainntnfs"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/lnwire"
@ -741,112 +740,6 @@ func TestCooperativeChannelClosure(t *testing.T) {
}
}
// TestCheckHTLCNumberConstraint checks that we can't add HTLC or receive
// HTLC if number of HTLCs exceed maximum available number, also this test
// checks that if for some reason max number of HTLCs was exceeded and not
// caught before, the creation of new commitment will not be possible because
// of validation error.
func TestCheckHTLCNumberConstraint(t *testing.T) {
createHTLC := func(i int) *lnwire.UpdateAddHTLC {
preimage := bytes.Repeat([]byte{byte(i)}, 32)
paymentHash := sha256.Sum256(preimage)
return &lnwire.UpdateAddHTLC{
PaymentHash: paymentHash,
Amount: btcutil.Amount(1e7),
Expiry: uint32(5),
}
}
checkError := func(err error) error {
if err == nil {
return errors.New("Exceed max htlc count error was " +
"not received")
} else if err != ErrMaxHTLCNumber {
return errors.Errorf("Unexpected error occured: %v", err)
}
return nil
}
// Create a test channel which will be used for the duration of this
// unittest. The channel will be funded evenly with Alice having 5 BTC,
// and Bob having 5 BTC.
aliceChannel, bobChannel, cleanUp, err := createTestChannels(1)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
}
defer cleanUp()
// Add max available number of HTLCs.
for i := 0; i < MaxHTLCNumber; i++ {
htlc := createHTLC(i)
if _, err := aliceChannel.AddHTLC(htlc); err != nil {
t.Fatalf("alice unable to add htlc: %v", err)
}
if _, err := bobChannel.ReceiveHTLC(htlc); err != nil {
t.Fatalf("bob unable to receive htlc: %v", err)
}
}
// Next addition should cause HTLC max number validation error.
htlc := createHTLC(0)
if _, err := aliceChannel.AddHTLC(htlc); err != nil {
if err := checkError(err); err != nil {
t.Fatal(err)
}
} else {
t.Fatal("Error was not received")
}
if _, err := bobChannel.AddHTLC(htlc); err != nil {
if err := checkError(err); err != nil {
t.Fatal(err)
}
} else {
t.Fatal("Error was not received")
}
if _, err := aliceChannel.ReceiveHTLC(htlc); err != nil {
if err := checkError(err); err != nil {
t.Fatal(err)
}
} else {
t.Fatal("Error was not received")
}
if _, err := bobChannel.ReceiveHTLC(htlc); err != nil {
if err := checkError(err); err != nil {
t.Fatal(err)
}
} else {
t.Fatal("Error was not received")
}
// Manually add HTLC to check SignNextCommitment validation error.
aliceChannel.localUpdateLog.appendUpdate(
&PaymentDescriptor{
Index: aliceChannel.localUpdateLog.logIndex,
},
)
_, err = aliceChannel.SignNextCommitment()
if err := checkError(err); err != nil {
t.Fatal(err)
}
// Manually add HTLC to check ReceiveNewCommitment validation error.
bobChannel.remoteUpdateLog.appendUpdate(
&PaymentDescriptor{
Index: bobChannel.remoteUpdateLog.logIndex,
},
)
// And on this stage we should receive the weight error.
someSig := []byte("somesig")
err = bobChannel.ReceiveNewCommitment(someSig)
if err := checkError(err); err != nil {
t.Fatal(err)
}
}
// TestForceClose checks that the resulting ForceCloseSummary is correct when
// a peer is ForceClosing the channel. Will check outputs both above and below
// the dust limit.