| index 361c13cf0..429ac09dd 100644 |
| --- a/internal/console/domainstore_test.go |
| +++ b/internal/console/domainstore_test.go |
| @@ -285,38 +285,39 @@ func savedTestContact(first string) registrar.Contact { |
| } |
| |
| func TestSavedContactsOrderAndAccountScope(t *testing.T) { |
| + ctx := t.Context() |
| s := openTestStore(t) |
| base := time.Date(2026, 11, 19, 10, 0, 0, 0, time.UTC) |
| - if _, err := s.AddSavedContact(1, registrar.Contact{FirstName: "Half"}, base); err == nil { |
| + if _, err := s.AddSavedContact(ctx, 1, registrar.Contact{FirstName: "Half"}, base); err == nil { |
| t.Fatal("invalid contact saved") |
| } |
| var ids []string |
| for i, name := range []string{"alpha", "bravo", "charlie", "delta"} { |
| - c, err := s.AddSavedContact(1, savedTestContact(name), base.Add(time.Duration(i)*time.Minute)) |
| + c, err := s.AddSavedContact(ctx, 1, savedTestContact(name), base.Add(time.Duration(i)*time.Minute)) |
| if err != nil { |
| t.Fatal(err) |
| } |
| - if !regexp.MustCompile(`^dc_[0-9a-f]{12}$`).MatchString(c.ID) || c.AccountID != 1 || c.Version != 1 || c.Handle != "" || |
| + if !regexp.MustCompile(`^dc_[0-9a-f]{12}$`).MatchString(c.ID) || c.AccountID != 1 || c.Version != 1 || c.RegistrarHandle != "" || |
| !c.LastUsed.IsZero() || !c.CreatedAt.Equal(base.Add(time.Duration(i)*time.Minute)) || c.Contact != savedTestContact(name) { |
| t.Fatalf("added: %+v", c) |
| } |
| ids = append(ids, c.ID) |
| } |
| - other, err := s.AddSavedContact(2, savedTestContact("other"), base.Add(time.Hour)) |
| + other, err := s.AddSavedContact(ctx, 2, savedTestContact("other"), base.Add(time.Hour)) |
| if err != nil { |
| t.Fatal(err) |
| } |
| // bravo used last, alpha before it; charlie and delta never used: newest first. |
| - if err := s.TouchSavedContact(1, ids[0], base.Add(2*time.Hour)); err != nil { |
| + if err := s.TouchSavedContact(ctx, 1, ids[0], base.Add(2*time.Hour)); err != nil { |
| t.Fatal(err) |
| } |
| - if err := s.TouchSavedContact(1, ids[1], base.Add(3*time.Hour)); err != nil { |
| + if err := s.TouchSavedContact(ctx, 1, ids[1], base.Add(3*time.Hour)); err != nil { |
| t.Fatal(err) |
| } |
| - if err := s.TouchSavedContact(1, other.ID, base.Add(4*time.Hour)); err != nil { |
| + if err := s.TouchSavedContact(ctx, 1, other.ID, base.Add(4*time.Hour)); err != nil { |
| t.Fatal(err) |
| } |
| - list, err := s.SavedContacts(1) |
| + list, err := s.SavedContacts(ctx, 1) |
| if err != nil { |
| t.Fatal(err) |
| } |
| @@ -330,96 +331,98 @@ func TestSavedContactsOrderAndAccountScope(t *testing.T) { |
| if !list[0].LastUsed.Equal(base.Add(3 * time.Hour)) { |
| t.Fatalf("last used: %+v", list[0]) |
| } |
| - if c, err := s.SavedContact(1, other.ID); err != nil || c != nil { |
| + if c, err := s.SavedContact(ctx, 1, other.ID); err != nil || c != nil { |
| t.Fatalf("another account's contact: %+v, %v", c, err) |
| } |
| - if c, err := s.SavedContact(1, "dc_000000000000"); err != nil || c != nil { |
| + if c, err := s.SavedContact(ctx, 1, "dc_000000000000"); err != nil || c != nil { |
| t.Fatalf("missing contact: %+v, %v", c, err) |
| } |
| - if c, err := s.SavedContact(2, other.ID); err != nil || c == nil || !c.LastUsed.IsZero() || c.Contact.FirstName != "other" { |
| + if c, err := s.SavedContact(ctx, 2, other.ID); err != nil || c == nil || !c.LastUsed.IsZero() || c.Contact.FirstName != "other" { |
| t.Fatalf("other account touched across accounts or missing: %+v, %v", c, err) |
| } |
| - if err := s.EditSavedContact(1, other.ID, savedTestContact("stolen")); !errors.Is(err, ErrSavedContactNotFound) { |
| + if err := s.EditSavedContact(ctx, 1, other.ID, savedTestContact("stolen")); !errors.Is(err, ErrSavedContactNotFound) { |
| t.Fatalf("cross-account edit: %v", err) |
| } |
| - if err := s.RemoveSavedContact(1, other.ID); !errors.Is(err, ErrSavedContactNotFound) { |
| + if err := s.RemoveSavedContact(ctx, 1, other.ID); !errors.Is(err, ErrSavedContactNotFound) { |
| t.Fatalf("cross-account remove: %v", err) |
| } |
| - if list, err := s.SavedContacts(2); err != nil || len(list) != 1 || list[0].Contact.FirstName != "other" { |
| + if list, err := s.SavedContacts(ctx, 2); err != nil || len(list) != 1 || list[0].Contact.FirstName != "other" { |
| t.Fatalf("other account list: %+v, %v", list, err) |
| } |
| - if err := s.RemoveSavedContact(1, ids[0]); err != nil { |
| + if err := s.RemoveSavedContact(ctx, 1, ids[0]); err != nil { |
| t.Fatal(err) |
| } |
| - if list, err := s.SavedContacts(1); err != nil || len(list) != 3 { |
| + if list, err := s.SavedContacts(ctx, 1); err != nil || len(list) != 3 { |
| t.Fatalf("after remove: %+v, %v", list, err) |
| } |
| } |
| |
| func TestEditSavedContactBumpsVersionClearsHandle(t *testing.T) { |
| + ctx := t.Context() |
| s := openTestStore(t) |
| now := time.Date(2026, 11, 19, 10, 0, 0, 0, time.UTC) |
| - c, err := s.AddSavedContact(1, savedTestContact("jane"), now) |
| + c, err := s.AddSavedContact(ctx, 1, savedTestContact("jane"), now) |
| if err != nil { |
| t.Fatal(err) |
| } |
| - if ok, err := s.SetSavedContactHandle(1, c.ID, 1, "handle-1"); err != nil || !ok { |
| + if ok, err := s.SetSavedContactHandle(ctx, 1, c.ID, 1, "handle-1"); err != nil || !ok { |
| t.Fatalf("set handle: %v, %v", ok, err) |
| } |
| - if err := s.TouchSavedContact(1, c.ID, now.Add(time.Hour)); err != nil { |
| + if err := s.TouchSavedContact(ctx, 1, c.ID, now.Add(time.Hour)); err != nil { |
| t.Fatal(err) |
| } |
| - if err := s.EditSavedContact(1, c.ID, registrar.Contact{FirstName: "Half"}); err == nil { |
| + if err := s.EditSavedContact(ctx, 1, c.ID, registrar.Contact{FirstName: "Half"}); err == nil { |
| t.Fatal("invalid edit accepted") |
| } |
| edited := savedTestContact("janet") |
| - if err := s.EditSavedContact(1, c.ID, edited); err != nil { |
| + if err := s.EditSavedContact(ctx, 1, c.ID, edited); err != nil { |
| t.Fatal(err) |
| } |
| - got, err := s.SavedContact(1, c.ID) |
| + got, err := s.SavedContact(ctx, 1, c.ID) |
| if err != nil || got == nil { |
| t.Fatalf("after edit: %+v, %v", got, err) |
| } |
| - if got.Version != 2 || got.Handle != "" || got.Contact != edited || !got.CreatedAt.Equal(now) || !got.LastUsed.Equal(now.Add(time.Hour)) { |
| + if got.Version != 2 || got.RegistrarHandle != "" || got.Contact != edited || !got.CreatedAt.Equal(now) || !got.LastUsed.Equal(now.Add(time.Hour)) { |
| t.Fatalf("after edit: %+v", got) |
| } |
| - if err := s.EditSavedContact(1, c.ID, edited); err != nil { |
| + if err := s.EditSavedContact(ctx, 1, c.ID, edited); err != nil { |
| t.Fatal(err) |
| } |
| - if got, err := s.SavedContact(1, c.ID); err != nil || got.Version != 3 { |
| + if got, err := s.SavedContact(ctx, 1, c.ID); err != nil || got.Version != 3 { |
| t.Fatalf("second edit: %+v, %v", got, err) |
| } |
| - if err := s.EditSavedContact(1, "dc_000000000000", edited); !errors.Is(err, ErrSavedContactNotFound) { |
| + if err := s.EditSavedContact(ctx, 1, "dc_000000000000", edited); !errors.Is(err, ErrSavedContactNotFound) { |
| t.Fatalf("missing edit: %v", err) |
| } |
| } |
| |
| func TestSetSavedContactHandleIsConditional(t *testing.T) { |
| + ctx := t.Context() |
| s := openTestStore(t) |
| - c, err := s.AddSavedContact(1, savedTestContact("jane"), time.Now()) |
| + c, err := s.AddSavedContact(ctx, 1, savedTestContact("jane"), time.Now()) |
| if err != nil { |
| t.Fatal(err) |
| } |
| - if err := s.EditSavedContact(1, c.ID, savedTestContact("janet")); err != nil { |
| + if err := s.EditSavedContact(ctx, 1, c.ID, savedTestContact("janet")); err != nil { |
| t.Fatal(err) |
| } |
| // A purchase that froze version 1 mints a handle after the edit: refused. |
| - if ok, err := s.SetSavedContactHandle(1, c.ID, 1, "stale"); err != nil || ok { |
| + if ok, err := s.SetSavedContactHandle(ctx, 1, c.ID, 1, "stale"); err != nil || ok { |
| t.Fatalf("stale version: %v, %v", ok, err) |
| } |
| - if got, _ := s.SavedContact(1, c.ID); got.Handle != "" || got.Version != 2 { |
| + if got, _ := s.SavedContact(ctx, 1, c.ID); got.RegistrarHandle != "" || got.Version != 2 { |
| t.Fatalf("stale write changed row: %+v", got) |
| } |
| - if ok, err := s.SetSavedContactHandle(2, c.ID, 2, "cross"); err != nil || ok { |
| + if ok, err := s.SetSavedContactHandle(ctx, 2, c.ID, 2, "cross"); err != nil || ok { |
| t.Fatalf("other account: %v, %v", ok, err) |
| } |
| - if ok, err := s.SetSavedContactHandle(1, c.ID, 2, "first"); err != nil || !ok { |
| + if ok, err := s.SetSavedContactHandle(ctx, 1, c.ID, 2, "first"); err != nil || !ok { |
| t.Fatalf("matching version: %v, %v", ok, err) |
| } |
| - if ok, err := s.SetSavedContactHandle(1, c.ID, 2, "second"); err != nil || ok { |
| + if ok, err := s.SetSavedContactHandle(ctx, 1, c.ID, 2, "second"); err != nil || ok { |
| t.Fatalf("existing handle: %v, %v", ok, err) |
| } |
| - if got, _ := s.SavedContact(1, c.ID); got.Handle != "first" || got.Version != 2 { |
| + if got, _ := s.SavedContact(ctx, 1, c.ID); got.RegistrarHandle != "first" || got.Version != 2 { |
| t.Fatalf("handle: %+v", got) |
| } |
| } |
| @@ -461,8 +464,9 @@ func seedLegacyDomainState(t *testing.T, s *Store) (registered, done registrar.C |
| } |
| |
| func TestMigrateDomainsBackfillsContactsAndRegistrant(t *testing.T) { |
| + ctx := t.Context() |
| s := openTestStore(t) |
| - before, err := s.SavedContacts(123) |
| + before, err := s.SavedContacts(ctx, 123) |
| if err != nil || len(before) != 0 { |
| t.Fatalf("fresh store: %+v, %v", before, err) |
| } |
| @@ -472,16 +476,16 @@ func TestMigrateDomainsBackfillsContactsAndRegistrant(t *testing.T) { |
| t.Fatal(err) |
| } |
| } |
| - list, err := s.SavedContacts(123) |
| + list, err := s.SavedContacts(ctx, 123) |
| if err != nil || len(list) != 1 { |
| t.Fatalf("saved contacts: %+v, %v", list, err) |
| } |
| c := list[0] |
| - if c.Handle != "contact-1" || c.Version != 1 || c.Contact != savedTestContact("legacy") || c.LastUsed.IsZero() || c.AccountID != 123 { |
| + if c.RegistrarHandle != "contact-1" || c.Version != 1 || c.Contact != savedTestContact("legacy") || c.LastUsed.IsZero() || c.AccountID != 123 { |
| t.Fatalf("backfilled contact: %+v", c) |
| } |
| for domain, want := range map[string]registrar.Contact{"one.example": registered, "two.example": done, "three.example": {}} { |
| - r, err := s.DomainRegistrationFor(123, domain) |
| + r, err := s.DomainRegistrationFor(ctx, 123, domain) |
| if err != nil || r == nil || r.Registrant != want { |
| t.Fatalf("%s registrant: %+v, %v; want %+v", domain, r, err, want) |
| } |
| @@ -496,6 +500,7 @@ func TestMigrateDomainsBackfillsContactsAndRegistrant(t *testing.T) { |
| } |
| |
| func TestMigratedContactRemovalSurvivesReopen(t *testing.T) { |
| + ctx := t.Context() |
| path := filepath.Join(t.TempDir(), "console.db") |
| s, err := Open(path) |
| if err != nil { |
| @@ -506,11 +511,11 @@ func TestMigratedContactRemovalSurvivesReopen(t *testing.T) { |
| if err := s.migrateDomains(); err != nil { |
| t.Fatal(err) |
| } |
| - list, err := s.SavedContacts(123) |
| + list, err := s.SavedContacts(ctx, 123) |
| if err != nil || len(list) != 1 { |
| t.Fatalf("saved contacts: %+v, %v", list, err) |
| } |
| - if err := s.RemoveSavedContact(123, list[0].ID); err != nil { |
| + if err := s.RemoveSavedContact(ctx, 123, list[0].ID); err != nil { |
| t.Fatal(err) |
| } |
| if err := s.Close(); err != nil { |
| @@ -519,12 +524,13 @@ func TestMigratedContactRemovalSurvivesReopen(t *testing.T) { |
| if s, err = Open(path); err != nil { |
| t.Fatal(err) |
| } |
| - if list, err := s.SavedContacts(123); err != nil || len(list) != 0 { |
| + if list, err := s.SavedContacts(ctx, 123); err != nil || len(list) != 0 { |
| t.Fatalf("removed contact came back: %+v, %v", list, err) |
| } |
| } |
| |
| func TestDomainObligations(t *testing.T) { |
| + ctx := t.Context() |
| s := openTestStore(t) |
| t0 := time.Date(2026, 11, 1, 0, 0, 0, 0, time.UTC) |
| jane := savedTestContact("jane") |
| @@ -550,24 +556,24 @@ func TestDomainObligations(t *testing.T) { |
| t.Fatal(err) |
| } |
| } |
| - got, err := s.DomainObligations(1) |
| + got, err := s.DomainObligations(ctx, 1) |
| if want := []string{"alpha.example", "dup.example", "live.example", "zed.example"}; err != nil || !reflect.DeepEqual(got, want) { |
| t.Fatalf("obligations = %v, %v; want %v", got, err, want) |
| } |
| - if got, err := s.DomainObligations(3); err != nil || len(got) != 0 { |
| + if got, err := s.DomainObligations(ctx, 3); err != nil || len(got) != 0 { |
| t.Fatalf("empty account: %v, %v", got, err) |
| } |
| - regs, err := s.DomainRegistrations(1) |
| + regs, err := s.DomainRegistrations(ctx, 1) |
| if err != nil || len(regs) != 3 || regs[0].Domain != "alpha.example" || regs[1].Domain != "dup.example" || regs[2].Domain != "zed.example" || regs[2].Registrant != jane || regs[0].Registrant != (registrar.Contact{}) { |
| t.Fatalf("registrations: %+v, %v", regs, err) |
| } |
| - if r, err := s.DomainRegistrationFor(1, "theirs.example"); err != nil || r != nil { |
| + if r, err := s.DomainRegistrationFor(ctx, 1, "theirs.example"); err != nil || r != nil { |
| t.Fatalf("another account's registration: %+v, %v", r, err) |
| } |
| - if r, err := s.DomainRegistrationFor(1, "missing.example"); err != nil || r != nil { |
| + if r, err := s.DomainRegistrationFor(ctx, 1, "missing.example"); err != nil || r != nil { |
| t.Fatalf("missing registration: %+v, %v", r, err) |
| } |
| - purchases, err := s.AccountDomainPurchases(1) |
| + purchases, err := s.AccountDomainPurchases(ctx, 1) |
| if err != nil || len(purchases) != 2 || purchases[0].Domain != "dup.example" || purchases[1].Domain != "live.example" { |
| t.Fatalf("account purchases: %+v, %v", purchases, err) |
| } |