mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-05-25 03:00:06 +02:00
channeldb: add unique output index to unit test
This commit is contained in:
parent
f94500281f
commit
3d61d157c6
@ -6,6 +6,7 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"sync/atomic"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/btcec/v2"
|
"github.com/btcsuite/btcd/btcec/v2"
|
||||||
@ -64,6 +65,11 @@ var (
|
|||||||
// dummyRemoteOutIndex specifics a default value for their output index
|
// dummyRemoteOutIndex specifics a default value for their output index
|
||||||
// in this test.
|
// in this test.
|
||||||
dummyRemoteOutIndex = uint32(1)
|
dummyRemoteOutIndex = uint32(1)
|
||||||
|
|
||||||
|
// uniqueOutputIndex is used to create a unique funding outpoint.
|
||||||
|
//
|
||||||
|
// NOTE: must be incremented when used.
|
||||||
|
uniqueOutputIndex = atomic.Uint32{}
|
||||||
)
|
)
|
||||||
|
|
||||||
// testChannelParams is a struct which details the specifics of how a channel
|
// testChannelParams is a struct which details the specifics of how a channel
|
||||||
@ -299,10 +305,15 @@ func createTestChannelState(t *testing.T, cdb *ChannelStateDB) *OpenChannel {
|
|||||||
|
|
||||||
chanID := lnwire.NewShortChanIDFromInt(uint64(rand.Int63()))
|
chanID := lnwire.NewShortChanIDFromInt(uint64(rand.Int63()))
|
||||||
|
|
||||||
|
// Increment the uniqueOutputIndex so we always get a unique value for
|
||||||
|
// the funding outpoint.
|
||||||
|
uniqueOutputIndex.Add(1)
|
||||||
|
op := wire.OutPoint{Hash: key, Index: uniqueOutputIndex.Load()}
|
||||||
|
|
||||||
return &OpenChannel{
|
return &OpenChannel{
|
||||||
ChanType: SingleFunderBit | FrozenBit,
|
ChanType: SingleFunderBit | FrozenBit,
|
||||||
ChainHash: key,
|
ChainHash: key,
|
||||||
FundingOutpoint: wire.OutPoint{Hash: key, Index: rand.Uint32()},
|
FundingOutpoint: op,
|
||||||
ShortChannelID: chanID,
|
ShortChannelID: chanID,
|
||||||
IsInitiator: true,
|
IsInitiator: true,
|
||||||
IsPending: true,
|
IsPending: true,
|
||||||
|
@ -243,11 +243,13 @@ func TestFetchChannel(t *testing.T) {
|
|||||||
spew.Sdump(channelState), spew.Sdump(dbChannel))
|
spew.Sdump(channelState), spew.Sdump(dbChannel))
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we attempt to query for a non-exist ante channel, then we should
|
// If we attempt to query for a non-existent channel, then we should
|
||||||
// get an error.
|
// get an error.
|
||||||
channelState2 := createTestChannelState(t, cdb)
|
channelState2 := createTestChannelState(t, cdb)
|
||||||
require.NoError(t, err, "unable to create channel state")
|
require.NoError(t, err, "unable to create channel state")
|
||||||
channelState2.FundingOutpoint.Index ^= 1
|
|
||||||
|
uniqueOutputIndex.Add(1)
|
||||||
|
channelState2.FundingOutpoint.Index = uniqueOutputIndex.Load()
|
||||||
|
|
||||||
_, err = cdb.FetchChannel(nil, channelState2.FundingOutpoint)
|
_, err = cdb.FetchChannel(nil, channelState2.FundingOutpoint)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user