package domain import ( "encoding/hex" "errors" "testing" ) // TestSendIsRemembered: the wallet is the only record of what it sent, so the bytes, the // destination and the amount are kept and come back by txid. func TestSendIsRemembered(t *testing.T) { r := fundedRestored(t, 100_000) destination, err := r.domain.Addresses("btc", false, 2, 1) if err != nil { t.Fatal(err) } txid, err := r.domain.Send("btc", destination[0].Text, 50_000, 1_000, SendPolicy{}) if err != nil { t.Fatalf("Send: %v", err) } display := hex.EncodeToString(reversed(txid[:])) sent, err := r.domain.SentTx("btc", display) if err != nil { t.Fatalf("SentTx: %v", err) } if sent.Hex != hex.EncodeToString(r.chains["btc"].broadcast[0]) { t.Fatal("the journal does not hold the bytes that were broadcast") } if sent.Address != destination[0].Text || sent.Amount != 50_000 || sent.Vout != 0 || sent.Chain != "btc" { t.Fatalf("sent %+v", sent) } all, err := r.domain.Sends("btc") if err != nil || len(all) != 1 || all[0].TxID != display { t.Fatalf("sends %+v, %v", all, err) } if _, err := r.domain.SentTx("btc", "ff"); !errors.Is(err, ErrNoSentTx) { t.Fatalf("an unknown txid: %v", err) } // The journal is in the store, so it survives a lock and a reopen of the same cache. fresh, err := New(r.cache) if err != nil { t.Fatal(err) } if _, err := fresh.SentTx("btc", display); err != nil { t.Fatalf("after reopening the domain: %v", err) } }