contractcourt/chainwatcher test: add test cases for future force close
This adds the scenario to the local force close test cases where a node force closes one of its channels, then lose state (or do recovery) before the commmitment is confirmed. Without the previous commit this would go undetected.
This commit is contained in:
parent
2a7a34ae10
commit
ef426be351
@ -446,7 +446,7 @@ func TestChainWatcherLocalForceCloseDetect(t *testing.T) {
|
|||||||
// table driven tests. We'll assert that for any number of state
|
// table driven tests. We'll assert that for any number of state
|
||||||
// updates, and if the commitment transaction has our output or not,
|
// updates, and if the commitment transaction has our output or not,
|
||||||
// we're able to properly detect a local force close.
|
// we're able to properly detect a local force close.
|
||||||
localForceCloseScenario := func(t *testing.T, numUpdates uint8,
|
localForceCloseScenario := func(t *testing.T, numUpdates, localState uint8,
|
||||||
remoteOutputOnly, localOutputOnly bool) bool {
|
remoteOutputOnly, localOutputOnly bool) bool {
|
||||||
|
|
||||||
// First, we'll create two channels which already have
|
// First, we'll create two channels which already have
|
||||||
@ -475,7 +475,7 @@ func TestChainWatcherLocalForceCloseDetect(t *testing.T) {
|
|||||||
defer cleanStates()
|
defer cleanStates()
|
||||||
|
|
||||||
// We'll use the state this test case wants Alice to start at.
|
// We'll use the state this test case wants Alice to start at.
|
||||||
aliceChanState := states[numUpdates]
|
aliceChanState := states[localState]
|
||||||
|
|
||||||
// With the channels created, we'll now create a chain watcher
|
// With the channels created, we'll now create a chain watcher
|
||||||
// instance which will be watching for any closes of Alice's
|
// instance which will be watching for any closes of Alice's
|
||||||
@ -530,7 +530,19 @@ func TestChainWatcherLocalForceCloseDetect(t *testing.T) {
|
|||||||
// should be able to detect the close based on the commitment
|
// should be able to detect the close based on the commitment
|
||||||
// outputs.
|
// outputs.
|
||||||
select {
|
select {
|
||||||
case <-chanEvents.LocalUnilateralClosure:
|
case summary := <-chanEvents.LocalUnilateralClosure:
|
||||||
|
// Make sure we correctly extracted the commit
|
||||||
|
// resolution if we had a local output.
|
||||||
|
if remoteOutputOnly {
|
||||||
|
if summary.CommitResolution != nil {
|
||||||
|
t.Fatalf("expected no commit resolution")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if summary.CommitResolution == nil {
|
||||||
|
t.Fatalf("expected commit resolution")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
case <-time.After(time.Second * 5):
|
case <-time.After(time.Second * 5):
|
||||||
@ -544,31 +556,53 @@ func TestChainWatcherLocalForceCloseDetect(t *testing.T) {
|
|||||||
// present and absent with non or some number of updates in the channel.
|
// present and absent with non or some number of updates in the channel.
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
numUpdates uint8
|
numUpdates uint8
|
||||||
|
localState uint8
|
||||||
remoteOutputOnly bool
|
remoteOutputOnly bool
|
||||||
localOutputOnly bool
|
localOutputOnly bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
numUpdates: 0,
|
numUpdates: 0,
|
||||||
|
localState: 0,
|
||||||
remoteOutputOnly: true,
|
remoteOutputOnly: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
numUpdates: 0,
|
numUpdates: 0,
|
||||||
|
localState: 0,
|
||||||
remoteOutputOnly: false,
|
remoteOutputOnly: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
numUpdates: 0,
|
numUpdates: 0,
|
||||||
|
localState: 0,
|
||||||
localOutputOnly: true,
|
localOutputOnly: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
numUpdates: 20,
|
numUpdates: 20,
|
||||||
|
localState: 20,
|
||||||
remoteOutputOnly: false,
|
remoteOutputOnly: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
numUpdates: 20,
|
numUpdates: 20,
|
||||||
|
localState: 20,
|
||||||
remoteOutputOnly: true,
|
remoteOutputOnly: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
numUpdates: 20,
|
numUpdates: 20,
|
||||||
|
localState: 20,
|
||||||
|
localOutputOnly: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
numUpdates: 20,
|
||||||
|
localState: 5,
|
||||||
|
remoteOutputOnly: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
numUpdates: 20,
|
||||||
|
localState: 5,
|
||||||
|
remoteOutputOnly: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
numUpdates: 20,
|
||||||
|
localState: 5,
|
||||||
localOutputOnly: true,
|
localOutputOnly: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -584,7 +618,8 @@ func TestChainWatcherLocalForceCloseDetect(t *testing.T) {
|
|||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
localForceCloseScenario(
|
localForceCloseScenario(
|
||||||
t, testCase.numUpdates, testCase.remoteOutputOnly,
|
t, testCase.numUpdates, testCase.localState,
|
||||||
|
testCase.remoteOutputOnly,
|
||||||
testCase.localOutputOnly,
|
testCase.localOutputOnly,
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user