sweep: check all states in TestMarkInputsPublishFailed

This commit is contained in:
yyforyongyu 2024-05-14 20:47:57 +08:00
parent ac5af48319
commit 38184e88c8
No known key found for this signature in database
GPG Key ID: 9BCD95C4FF296868

View File

@ -206,7 +206,7 @@ func TestMarkInputsPublishFailed(t *testing.T) {
Store: mockStore,
})
// Create three testing inputs.
// Create testing inputs for each state.
//
// inputNotExist specifies an input that's not found in the sweeper's
// `inputs` map.
@ -240,18 +240,52 @@ func TestMarkInputsPublishFailed(t *testing.T) {
state: Published,
}
// inputPublishFailed specifies an input that's failed to be published.
inputPublishFailed := &wire.TxIn{
PreviousOutPoint: wire.OutPoint{Index: 5},
}
s.inputs[inputPublishFailed.PreviousOutPoint] = &SweeperInput{
state: PublishFailed,
}
// inputSwept specifies an input that's swept.
inputSwept := &wire.TxIn{
PreviousOutPoint: wire.OutPoint{Index: 6},
}
s.inputs[inputSwept.PreviousOutPoint] = &SweeperInput{
state: Swept,
}
// inputExcluded specifies an input that's excluded.
inputExcluded := &wire.TxIn{
PreviousOutPoint: wire.OutPoint{Index: 7},
}
s.inputs[inputExcluded.PreviousOutPoint] = &SweeperInput{
state: Excluded,
}
// inputFailed specifies an input that's failed.
inputFailed := &wire.TxIn{
PreviousOutPoint: wire.OutPoint{Index: 8},
}
s.inputs[inputFailed.PreviousOutPoint] = &SweeperInput{
state: Failed,
}
// Gather all inputs' outpoints.
pendingOps := make([]wire.OutPoint, 0, len(s.inputs)+1)
for op := range s.inputs {
pendingOps = append(pendingOps, op)
}
pendingOps = append(pendingOps, inputNotExist.PreviousOutPoint)
// Mark the test inputs. We expect the non-exist input and the
// inputInit to be skipped, and the final input to be marked as
// published.
s.markInputsPublishFailed([]wire.OutPoint{
inputNotExist.PreviousOutPoint,
inputInit.PreviousOutPoint,
inputPendingPublish.PreviousOutPoint,
inputPublished.PreviousOutPoint,
})
s.markInputsPublishFailed(pendingOps)
// We expect unchanged number of pending inputs.
require.Len(s.inputs, 3)
require.Len(s.inputs, 7)
// We expect the init input's state to stay unchanged.
require.Equal(Init,
@ -266,6 +300,19 @@ func TestMarkInputsPublishFailed(t *testing.T) {
require.Equal(PublishFailed,
s.inputs[inputPublished.PreviousOutPoint].state)
// We expect the publish failed input to stay unchanged.
require.Equal(PublishFailed,
s.inputs[inputPublishFailed.PreviousOutPoint].state)
// We expect the swept input to stay unchanged.
require.Equal(Swept, s.inputs[inputSwept.PreviousOutPoint].state)
// We expect the excluded input to stay unchanged.
require.Equal(Excluded, s.inputs[inputExcluded.PreviousOutPoint].state)
// We expect the failed input to stay unchanged.
require.Equal(Failed, s.inputs[inputFailed.PreviousOutPoint].state)
// Assert mocked statements are executed as expected.
mockStore.AssertExpectations(t)
}