invoices: refactor updateHtlc to return new state

With this refactor updateHtlc is renamed to getUpdatedHtlcState and
changed such that it won't change the HTLC's state and resolve time but
instead returns whether the change is needed. This change is part of a
multi-commit refactor to ensure that all changes to the invoice will be
tracked individually.
This commit is contained in:
Andras Banki-Horvath
2023-11-24 17:13:05 +01:00
parent ef5a31733e
commit 342eb4eac2
2 changed files with 56 additions and 32 deletions

View File

@@ -2997,7 +2997,14 @@ func TestUpdateHTLC(t *testing.T) {
func testUpdateHTLC(t *testing.T, test updateHTLCTest) {
htlc := test.input.Copy()
_, err := updateHtlc(testNow, htlc, test.invState, test.setID)
stateChanged, state, err := getUpdatedHtlcState(
htlc, test.invState, test.setID,
)
if stateChanged {
htlc.State = state
htlc.ResolveTime = testNow
}
require.Equal(t, test.expErr, err)
require.Equal(t, test.output, *htlc)
}