lnd/sweep/fee_bumper_test.go
yyforyongyu 1187b868ad
sweep: introduce Bumper interface to handle RBF
This commit adds a new interface, `Bumper`, to handle RBF for a given
input set. It's responsible for creating the sweeping tx using the input
set, and monitors its confirmation status to decide whether a RBF should
be attempted or not.

We leave implementation details to future commits, and focus on mounting
this `Bumper` interface to our sweeper in this commit.
2024-04-19 21:33:27 +08:00

53 lines
1.2 KiB
Go

package sweep
import (
"testing"
"github.com/btcsuite/btcd/wire"
"github.com/stretchr/testify/require"
)
// TestBumpResultValidate tests the validate method of the BumpResult struct.
func TestBumpResultValidate(t *testing.T) {
t.Parallel()
// An empty result will give an error.
b := BumpResult{}
require.ErrorIs(t, b.Validate(), ErrInvalidBumpResult)
// Unknown event type will give an error.
b = BumpResult{
Tx: &wire.MsgTx{},
Event: sentinalEvent,
}
require.ErrorIs(t, b.Validate(), ErrInvalidBumpResult)
// A replacing event without a new tx will give an error.
b = BumpResult{
Tx: &wire.MsgTx{},
Event: TxReplaced,
}
require.ErrorIs(t, b.Validate(), ErrInvalidBumpResult)
// A failed event without a failure reason will give an error.
b = BumpResult{
Tx: &wire.MsgTx{},
Event: TxFailed,
}
require.ErrorIs(t, b.Validate(), ErrInvalidBumpResult)
// A confirmed event without fee info will give an error.
b = BumpResult{
Tx: &wire.MsgTx{},
Event: TxConfirmed,
}
require.ErrorIs(t, b.Validate(), ErrInvalidBumpResult)
// Test a valid result.
b = BumpResult{
Tx: &wire.MsgTx{},
Event: TxPublished,
}
require.NoError(t, b.Validate())
}