This commit is contained in:
@@ -4,8 +4,51 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"gl/domain/ledger"
|
||||
)
|
||||
|
||||
func TestIgnoreByOperatorRejectsActiveLockedAndTerminalSettlements(t *testing.T) {
|
||||
for _, state := range []struct{ status, lock string }{
|
||||
{"PENDING", ""}, {"SUBMITTED", ""}, {"CONFIRMED", ""}, {"IGNORED", ""}, {"RETRYABLE", "worker"},
|
||||
} {
|
||||
tx := &fakeTx{rows: []Row{fakeRow{values: []any{state.status, state.lock}}}}
|
||||
repository := NewSettlementRepository(&fakeDatabase{tx: tx})
|
||||
if _, err := repository.IgnoreByOperator(context.Background(), "id", "actor", "reviewed"); err == nil {
|
||||
t.Fatalf("dismissed ineligible state: %+v", state)
|
||||
}
|
||||
if tx.execCount != 0 || tx.committed || !tx.rolledBack {
|
||||
t.Fatalf("ineligible dismissal changed state: %+v", tx)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestIgnoreByOperatorAuditsAndResolvesAtomically(t *testing.T) {
|
||||
tx := &fakeTx{rows: []Row{fakeRow{values: []any{"MANUAL_REVIEW", ""}}}}
|
||||
repository := NewSettlementRepository(&fakeDatabase{tx: tx, directRow: fakeRow{values: []any{
|
||||
"id", "wallet", "110", "wallet:110:kuknos", ledger.SettlementIgnored, "kuknos", "", 1, time.Now(), "tx_bad_seq", "signed-xdr",
|
||||
}}})
|
||||
got, err := repository.IgnoreByOperator(context.Background(), "id", "actor", "reviewed")
|
||||
if err != nil || got.Status != ledger.SettlementIgnored || got.LastError != "tx_bad_seq" || !tx.committed || tx.execCount != 3 {
|
||||
t.Fatalf("unexpected dismissal: %+v tx=%+v err=%v", got, tx, err)
|
||||
}
|
||||
for _, failedStep := range []int{2, 3} {
|
||||
tx := &fakeTx{rows: []Row{fakeRow{values: []any{"RETRYABLE", ""}}}, execErrAt: failedStep}
|
||||
repository := NewSettlementRepository(&fakeDatabase{tx: tx})
|
||||
if _, err := repository.IgnoreByOperator(context.Background(), "id", "actor", "reviewed"); err == nil || tx.committed || !tx.rolledBack {
|
||||
t.Fatalf("audit or issue failure did not roll back: %+v err=%v", tx, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestIgnoredSettlementCannotBeRetried(t *testing.T) {
|
||||
tx := &fakeTx{rows: []Row{fakeRow{values: []any{ledger.SettlementIgnored}}}}
|
||||
repository := NewSettlementRepository(&fakeDatabase{tx: tx})
|
||||
if _, err := repository.RetryByOperator(context.Background(), "id", "actor", "retry", time.Now()); err == nil || tx.execCount != 0 {
|
||||
t.Fatal("ignored settlement was queued again")
|
||||
}
|
||||
}
|
||||
|
||||
func TestReconcileConfirmationEvidenceCommitsDurableIssueStats(t *testing.T) {
|
||||
tx := &fakeTx{rows: []Row{
|
||||
fakeRow{values: []any{int64(1)}},
|
||||
|
||||
Reference in New Issue
Block a user