mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-01 18:27:43 +02:00
contractcourt: use T.TempDir
to create temporary test directory
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
This commit is contained in:
@@ -200,27 +200,19 @@ type dlpTestCase struct {
|
||||
// state) are returned.
|
||||
func executeStateTransitions(t *testing.T, htlcAmount lnwire.MilliSatoshi,
|
||||
aliceChannel, bobChannel *lnwallet.LightningChannel,
|
||||
numUpdates uint8) ([]*channeldb.OpenChannel, func(), error) {
|
||||
numUpdates uint8) ([]*channeldb.OpenChannel, error) {
|
||||
|
||||
// We'll make a copy of the channel state before each transition.
|
||||
var (
|
||||
chanStates []*channeldb.OpenChannel
|
||||
cleanupFuncs []func()
|
||||
chanStates []*channeldb.OpenChannel
|
||||
)
|
||||
|
||||
cleanAll := func() {
|
||||
for _, f := range cleanupFuncs {
|
||||
f()
|
||||
}
|
||||
}
|
||||
|
||||
state, f, err := copyChannelState(aliceChannel.State())
|
||||
state, err := copyChannelState(t, aliceChannel.State())
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
chanStates = append(chanStates, state)
|
||||
cleanupFuncs = append(cleanupFuncs, f)
|
||||
|
||||
for i := 0; i < int(numUpdates); i++ {
|
||||
addFakeHTLC(
|
||||
@@ -229,21 +221,18 @@ func executeStateTransitions(t *testing.T, htlcAmount lnwire.MilliSatoshi,
|
||||
|
||||
err := lnwallet.ForceStateTransition(aliceChannel, bobChannel)
|
||||
if err != nil {
|
||||
cleanAll()
|
||||
return nil, nil, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
state, f, err := copyChannelState(aliceChannel.State())
|
||||
state, err := copyChannelState(t, aliceChannel.State())
|
||||
if err != nil {
|
||||
cleanAll()
|
||||
return nil, nil, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
chanStates = append(chanStates, state)
|
||||
cleanupFuncs = append(cleanupFuncs, f)
|
||||
}
|
||||
|
||||
return chanStates, cleanAll, nil
|
||||
return chanStates, nil
|
||||
}
|
||||
|
||||
// TestChainWatcherDataLossProtect tests that if we've lost data (and are
|
||||
@@ -278,7 +267,7 @@ func TestChainWatcherDataLossProtect(t *testing.T) {
|
||||
// new HTLC to add to the commitment, and then lock in a state
|
||||
// transition.
|
||||
const htlcAmt = 1000
|
||||
states, cleanStates, err := executeStateTransitions(
|
||||
states, err := executeStateTransitions(
|
||||
t, htlcAmt, aliceChannel, bobChannel,
|
||||
testCase.BroadcastStateNum,
|
||||
)
|
||||
@@ -287,7 +276,6 @@ func TestChainWatcherDataLossProtect(t *testing.T) {
|
||||
"transition: %v", err)
|
||||
return false
|
||||
}
|
||||
defer cleanStates()
|
||||
|
||||
// We'll use the state this test case wants Alice to start at.
|
||||
aliceChanState := states[testCase.NumUpdates]
|
||||
@@ -455,7 +443,7 @@ func TestChainWatcherLocalForceCloseDetect(t *testing.T) {
|
||||
// get more coverage of various state hint encodings beyond 0
|
||||
// and 1.
|
||||
const htlcAmt = 1000
|
||||
states, cleanStates, err := executeStateTransitions(
|
||||
states, err := executeStateTransitions(
|
||||
t, htlcAmt, aliceChannel, bobChannel, numUpdates,
|
||||
)
|
||||
if err != nil {
|
||||
@@ -463,7 +451,6 @@ func TestChainWatcherLocalForceCloseDetect(t *testing.T) {
|
||||
"transition: %v", err)
|
||||
return false
|
||||
}
|
||||
defer cleanStates()
|
||||
|
||||
// We'll use the state this test case wants Alice to start at.
|
||||
aliceChanState := states[localState]
|
||||
|
Reference in New Issue
Block a user