sweep: remove the prefix used in SweepState types

Don't prefix with `State` we already have information to determine what
the type is. Generated this commit using,
```
gofmt -d -w -r 'StateInit -> Init' .
gofmt -d -w -r 'StatePendingPublish -> PendingPublish' .
gofmt -d -w -r 'StatePublished -> Published' .
gofmt -d -w -r 'StatePublishFailed -> PublishFailed' .
gofmt -d -w -r 'StateSwept -> Swept' .
gofmt -d -w -r 'StateExcluded -> Excluded' .
gofmt -d -w -r 'StateFailed -> Failed' .
```

and some string matching to fix the docs.
This commit is contained in:
yyforyongyu committed 2024-04-19 21:33:30 +08:00
1 parent 19265ac8ed
commit 0063770cb7
2 files changed
+102 -104

No files matched your search

+51 -51
View File
@@ -2147,7 +2147,7 @@ func TestMarkInputsPendingPublish(t *testing.T) {
inputInit.On("OutPoint").Return(&wire.OutPoint{Index: 1})
s.pendingInputs[*inputInit.OutPoint()] = &pendingInput{
state: StateInit,
state: Init,
}
// inputPendingPublish specifies an input that's about to be published.
@@ -2157,7 +2157,7 @@ func TestMarkInputsPendingPublish(t *testing.T) {
inputPendingPublish.On("OutPoint").Return(&wire.OutPoint{Index: 2})
s.pendingInputs[*inputPendingPublish.OutPoint()] = &pendingInput{
state: StatePendingPublish,
state: PendingPublish,
}
// inputTerminated specifies an input that's terminated.
@@ -2167,7 +2167,7 @@ func TestMarkInputsPendingPublish(t *testing.T) {
inputTerminated.On("OutPoint").Return(&wire.OutPoint{Index: 3})
s.pendingInputs[*inputTerminated.OutPoint()] = &pendingInput{
state: StateExcluded,
state: Excluded,
}
// Mark the test inputs. We expect the non-exist input and the
@@ -2182,20 +2182,20 @@ func TestMarkInputsPendingPublish(t *testing.T) {
require.Len(s.pendingInputs, 3)
// We expect the init input's state to become pending publish.
require.Equal(StatePendingPublish,
require.Equal(PendingPublish,
s.pendingInputs[*inputInit.OutPoint()].state)
// We expect the pending-publish to stay unchanged.
require.Equal(StatePendingPublish,
require.Equal(PendingPublish,
s.pendingInputs[*inputPendingPublish.OutPoint()].state)
// We expect the terminated to stay unchanged.
require.Equal(StateExcluded,
require.Equal(Excluded,
s.pendingInputs[*inputTerminated.OutPoint()].state)
}
// TestMarkInputsPublished checks that given a list of inputs with different
// states, only the state `StatePendingPublish` will be marked as `Published`.
// states, only the state `PendingPublish` will be marked as `Published`.
func TestMarkInputsPublished(t *testing.T) {
t.Parallel()
@@ -2228,7 +2228,7 @@ func TestMarkInputsPublished(t *testing.T) {
PreviousOutPoint: wire.OutPoint{Index: 2},
}
s.pendingInputs[inputInit.PreviousOutPoint] = &pendingInput{
state: StateInit,
state: Init,
}
// inputPendingPublish specifies an input that's about to be published.
@@ -2236,7 +2236,7 @@ func TestMarkInputsPublished(t *testing.T) {
PreviousOutPoint: wire.OutPoint{Index: 3},
}
s.pendingInputs[inputPendingPublish.PreviousOutPoint] = &pendingInput{
state: StatePendingPublish,
state: PendingPublish,
}
// First, check that when an error is returned from db, it's properly
@@ -2266,11 +2266,11 @@ func TestMarkInputsPublished(t *testing.T) {
require.Len(s.pendingInputs, 2)
// We expect the init input's state to stay unchanged.
require.Equal(StateInit,
require.Equal(Init,
s.pendingInputs[inputInit.PreviousOutPoint].state)
// We expect the pending-publish input's is now marked as published.
require.Equal(StatePublished,
require.Equal(Published,
s.pendingInputs[inputPendingPublish.PreviousOutPoint].state)
// Assert mocked statements are executed as expected.
@@ -2278,7 +2278,7 @@ func TestMarkInputsPublished(t *testing.T) {
}
// TestMarkInputsPublishFailed checks that given a list of inputs with
// different states, only the state `StatePendingPublish` will be marked as
// different states, only the state `PendingPublish` will be marked as
// `PublishFailed`.
func TestMarkInputsPublishFailed(t *testing.T) {
t.Parallel()
@@ -2308,7 +2308,7 @@ func TestMarkInputsPublishFailed(t *testing.T) {
PreviousOutPoint: wire.OutPoint{Index: 2},
}
s.pendingInputs[inputInit.PreviousOutPoint] = &pendingInput{
state: StateInit,
state: Init,
}
// inputPendingPublish specifies an input that's about to be published.
@@ -2316,7 +2316,7 @@ func TestMarkInputsPublishFailed(t *testing.T) {
PreviousOutPoint: wire.OutPoint{Index: 3},
}
s.pendingInputs[inputPendingPublish.PreviousOutPoint] = &pendingInput{
state: StatePendingPublish,
state: PendingPublish,
}
// Mark the test inputs. We expect the non-exist input and the
@@ -2332,12 +2332,12 @@ func TestMarkInputsPublishFailed(t *testing.T) {
require.Len(s.pendingInputs, 2)
// We expect the init input's state to stay unchanged.
require.Equal(StateInit,
require.Equal(Init,
s.pendingInputs[inputInit.PreviousOutPoint].state)
// We expect the pending-publish input's is now marked as publish
// failed.
require.Equal(StatePublishFailed,
require.Equal(PublishFailed,
s.pendingInputs[inputPendingPublish.PreviousOutPoint].state)
// Assert mocked statements are executed as expected.
@@ -2345,7 +2345,7 @@ func TestMarkInputsPublishFailed(t *testing.T) {
}
// TestMarkInputsSwept checks that given a list of inputs with different
// states, only the non-terminal state will be marked as `StateSwept`.
// states, only the non-terminal state will be marked as `Swept`.
func TestMarkInputsSwept(t *testing.T) {
t.Parallel()
@@ -2374,7 +2374,7 @@ func TestMarkInputsSwept(t *testing.T) {
PreviousOutPoint: wire.OutPoint{Index: 2},
}
s.pendingInputs[inputInit.PreviousOutPoint] = &pendingInput{
state: StateInit,
state: Init,
Input: mockInput,
}
@@ -2383,7 +2383,7 @@ func TestMarkInputsSwept(t *testing.T) {
PreviousOutPoint: wire.OutPoint{Index: 3},
}
s.pendingInputs[inputPendingPublish.PreviousOutPoint] = &pendingInput{
state: StatePendingPublish,
state: PendingPublish,
Input: mockInput,
}
@@ -2392,7 +2392,7 @@ func TestMarkInputsSwept(t *testing.T) {
PreviousOutPoint: wire.OutPoint{Index: 4},
}
s.pendingInputs[inputTerminated.PreviousOutPoint] = &pendingInput{
state: StateExcluded,
state: Excluded,
Input: mockInput,
}
@@ -2411,15 +2411,15 @@ func TestMarkInputsSwept(t *testing.T) {
require.Len(s.pendingInputs, 3)
// We expect the init input's state to become swept.
require.Equal(StateSwept,
require.Equal(Swept,
s.pendingInputs[inputInit.PreviousOutPoint].state)
// We expect the pending-publish becomes swept.
require.Equal(StateSwept,
require.Equal(Swept,
s.pendingInputs[inputPendingPublish.PreviousOutPoint].state)
// We expect the terminated to stay unchanged.
require.Equal(StateExcluded,
require.Equal(Excluded,
s.pendingInputs[inputTerminated.PreviousOutPoint].state)
}
@@ -2479,13 +2479,13 @@ func TestUpdateSweeperInputs(t *testing.T) {
s := New(nil)
// Create a list of inputs using all the states.
input0 := &pendingInput{state: StateInit}
input1 := &pendingInput{state: StatePendingPublish}
input2 := &pendingInput{state: StatePublished}
input3 := &pendingInput{state: StatePublishFailed}
input4 := &pendingInput{state: StateSwept}
input5 := &pendingInput{state: StateExcluded}
input6 := &pendingInput{state: StateFailed}
input0 := &pendingInput{state: Init}
input1 := &pendingInput{state: PendingPublish}
input2 := &pendingInput{state: Published}
input3 := &pendingInput{state: PublishFailed}
input4 := &pendingInput{state: Swept}
input5 := &pendingInput{state: Excluded}
input6 := &pendingInput{state: Failed}
// Add the inputs to the sweeper. After the update, we should see the
// terminated inputs being removed.
@@ -2499,8 +2499,8 @@ func TestUpdateSweeperInputs(t *testing.T) {
{Index: 6}: input6,
}
// We expect the inputs with `StateSwept`, `StateExcluded`, and
// `StateFailed` to be removed.
// We expect the inputs with `Swept`, `Excluded`, and `Failed` to be
// removed.
expectedInputs := map[wire.OutPoint]*pendingInput{
{Index: 0}: input0,
{Index: 1}: input1,
@@ -2508,8 +2508,8 @@ func TestUpdateSweeperInputs(t *testing.T) {
{Index: 3}: input3,
}
// We expect only the inputs with `StateInit` and `StatePublishFailed`
// to be returned.
// We expect only the inputs with `Init` and `PublishFailed` to be
// returned.
expectedReturn := map[wire.OutPoint]*pendingInput{
{Index: 0}: input0,
{Index: 3}: input3,
@@ -2556,7 +2556,7 @@ func TestDecideStateAndRBFInfo(t *testing.T) {
// RBFInfo.
state, rbf := s.decideStateAndRBFInfo(op)
require.True(rbf.IsNone())
require.Equal(StateInit, state)
require.Equal(Init, state)
// Mock the mempool lookup to return a tx three times as we are calling
// attachAvailableRBFInfo three times.
@@ -2570,7 +2570,7 @@ func TestDecideStateAndRBFInfo(t *testing.T) {
// Although the db lookup failed, we expect the state to be Published.
state, rbf = s.decideStateAndRBFInfo(op)
require.True(rbf.IsNone())
require.Equal(StatePublished, state)
require.Equal(Published, state)
// Mock the store to return a db error.
dummyErr := errors.New("dummy error")
@@ -2579,7 +2579,7 @@ func TestDecideStateAndRBFInfo(t *testing.T) {
// Although the db lookup failed, we expect the state to be Published.
state, rbf = s.decideStateAndRBFInfo(op)
require.True(rbf.IsNone())
require.Equal(StatePublished, state)
require.Equal(Published, state)
// Mock the store to return a record.
tr := &TxRecord{
@@ -2600,7 +2600,7 @@ func TestDecideStateAndRBFInfo(t *testing.T) {
require.Equal(rbfInfo, rbf)
// Assert the state is updated.
require.Equal(StatePublished, state)
require.Equal(Published, state)
}
// TestMarkInputFailed checks that the input is marked as failed as expected.
@@ -2619,7 +2619,7 @@ func TestMarkInputFailed(t *testing.T) {
// Create a testing pending input.
pi := &pendingInput{
state: StateInit,
state: Init,
Input: mockInput,
}
@@ -2627,7 +2627,7 @@ func TestMarkInputFailed(t *testing.T) {
s.markInputFailed(pi, errors.New("dummy error"))
// Assert the state is updated.
require.Equal(t, StateFailed, pi.state)
require.Equal(t, Failed, pi.state)
}
// TestSweepPendingInputs checks that `sweepPendingInputs` correctly executes
@@ -2730,9 +2730,9 @@ func TestHandleBumpEventTxFailed(t *testing.T) {
// Construct the initial state for the sweeper.
s.pendingInputs = pendingInputs{
op1: &pendingInput{Input: input1, state: StatePendingPublish},
op2: &pendingInput{Input: input2, state: StatePendingPublish},
op3: &pendingInput{Input: input3, state: StatePendingPublish},
op1: &pendingInput{Input: input1, state: PendingPublish},
op2: &pendingInput{Input: input2, state: PendingPublish},
op3: &pendingInput{Input: input3, state: PendingPublish},
}
// Create a testing tx that spends the first two inputs.
@@ -2756,11 +2756,11 @@ func TestHandleBumpEventTxFailed(t *testing.T) {
require.ErrorIs(t, err, errDummy)
// Assert the states of the first two inputs are updated.
require.Equal(t, StatePublishFailed, s.pendingInputs[op1].state)
require.Equal(t, StatePublishFailed, s.pendingInputs[op2].state)
require.Equal(t, PublishFailed, s.pendingInputs[op1].state)
require.Equal(t, PublishFailed, s.pendingInputs[op2].state)
// Assert the state of the third input is not updated.
require.Equal(t, StatePendingPublish, s.pendingInputs[op3].state)
require.Equal(t, PendingPublish, s.pendingInputs[op3].state)
// Assert the non-existing input is not added to the pending inputs.
require.NotContains(t, s.pendingInputs, opNotExist)
@@ -2789,7 +2789,7 @@ func TestHandleBumpEventTxReplaced(t *testing.T) {
// Construct the initial state for the sweeper.
s.pendingInputs = pendingInputs{
op: &pendingInput{Input: inp, state: StatePendingPublish},
op: &pendingInput{Input: inp, state: PendingPublish},
}
// Create a testing tx that spends the input.
@@ -2853,7 +2853,7 @@ func TestHandleBumpEventTxReplaced(t *testing.T) {
require.NoError(t, err)
// Assert the state of the input is updated.
require.Equal(t, StatePublished, s.pendingInputs[op].state)
require.Equal(t, Published, s.pendingInputs[op].state)
}
// TestHandleBumpEventTxPublished checks that the sweeper correctly handles the
@@ -2879,7 +2879,7 @@ func TestHandleBumpEventTxPublished(t *testing.T) {
// Construct the initial state for the sweeper.
s.pendingInputs = pendingInputs{
op: &pendingInput{Input: inp, state: StatePendingPublish},
op: &pendingInput{Input: inp, state: PendingPublish},
}
// Create a testing tx that spends the input.
@@ -2907,7 +2907,7 @@ func TestHandleBumpEventTxPublished(t *testing.T) {
require.NoError(t, err)
// Assert the state of the input is updated.
require.Equal(t, StatePublished, s.pendingInputs[op].state)
require.Equal(t, Published, s.pendingInputs[op].state)
}
// TestMonitorFeeBumpResult checks that the fee bump monitor loop correctly
@@ -2931,7 +2931,7 @@ func TestMonitorFeeBumpResult(t *testing.T) {
// Construct the initial state for the sweeper.
s.pendingInputs = pendingInputs{
op: &pendingInput{Input: inp, state: StatePendingPublish},
op: &pendingInput{Input: inp, state: PendingPublish},
}
// Create a testing tx that spends the input.