sweep: make sure nil tx is handled

After previous commit, it should be clear that the tx may be failed to
created in a `TxFailed` event. We now make sure to catch it to avoid
panic.
This commit is contained in:
yyforyongyu
2024-11-07 20:28:50 +08:00
parent 78ce757e7b
commit 30ee450091
3 changed files with 35 additions and 14 deletions

View File

@@ -91,13 +91,6 @@ func TestBumpResultValidate(t *testing.T) {
}
require.ErrorIs(t, b.Validate(), ErrInvalidBumpResult)
// A failed event without a tx will give an error.
b = BumpResult{
Event: TxFailed,
Err: errDummy,
}
require.ErrorIs(t, b.Validate(), ErrInvalidBumpResult)
// A fatal event without a failure reason will give an error.
b = BumpResult{
Event: TxFailed,
@@ -118,6 +111,13 @@ func TestBumpResultValidate(t *testing.T) {
}
require.NoError(t, b.Validate())
// Tx is allowed to be nil in a TxFailed event.
b = BumpResult{
Event: TxFailed,
Err: errDummy,
}
require.NoError(t, b.Validate())
// Tx is allowed to be nil in a TxFatal event.
b = BumpResult{
Event: TxFatal,