Skip to content

Commit 0511555

Browse files
committed
wallet: add tx store edge-case itests
Add additive integration coverage for the remaining CreateTx and UpdateTx edge conditions that were still below the db-only coverage target. These tests keep the branch focused on public store behavior while pushing the split backend files above the current 90 percent goal.
1 parent 4b649b0 commit 0511555

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

wallet/internal/db/itest/tx_store_create_edge_cases_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,45 @@ func TestCreateTxRejectsDuplicateConfirmedTransaction(t *testing.T) {
9191
err = store.CreateTx(t.Context(), params)
9292
require.ErrorIs(t, err, db.ErrTxAlreadyExists)
9393
}
94+
95+
// TestCreateTxRejectsMissingConfirmingBlockForExistingUnminedRow verifies that
96+
// re-confirming an existing unmined row still requires the confirming block to
97+
// exist in block history.
98+
func TestCreateTxRejectsMissingConfirmingBlockForExistingUnminedRow(t *testing.T) {
99+
t.Parallel()
100+
101+
store := NewTestStore(t)
102+
walletID := newWallet(t, store, "wallet-missing-confirming-block")
103+
createDerivedAccount(t, store, walletID, db.KeyScopeBIP0084, "default")
104+
105+
addr := newDerivedAddress(
106+
t, store, walletID, db.KeyScopeBIP0084, "default", false,
107+
)
108+
tx := newRegularTx(
109+
[]wire.OutPoint{randomOutPoint()},
110+
[]*wire.TxOut{{Value: 4600, PkScript: addr.ScriptPubKey}},
111+
)
112+
113+
err := store.CreateTx(t.Context(), db.CreateTxParams{
114+
WalletID: walletID,
115+
Tx: tx,
116+
Received: time.Unix(1710000860, 0),
117+
Status: db.TxStatusPending,
118+
Credits: map[uint32]btcutil.Address{0: nil},
119+
})
120+
require.NoError(t, err)
121+
122+
err = store.CreateTx(t.Context(), db.CreateTxParams{
123+
WalletID: walletID,
124+
Tx: tx,
125+
Received: time.Unix(1710000861, 0),
126+
Block: &db.Block{
127+
Hash: RandomHash(),
128+
Height: 999,
129+
Timestamp: time.Unix(1710000862, 0),
130+
},
131+
Status: db.TxStatusPublished,
132+
Credits: map[uint32]btcutil.Address{0: nil},
133+
})
134+
require.ErrorContains(t, err, "require confirming block")
135+
}

wallet/internal/db/itest/tx_store_edge_cases_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package itest
44

55
import (
6+
"strings"
67
"testing"
78
"time"
89

@@ -161,3 +162,32 @@ func TestTxReadsReturnQueryErrorsWhenClosed(t *testing.T) {
161162
})
162163
require.ErrorContains(t, err, "list transactions by height")
163164
}
165+
166+
// TestUpdateTxRejectsTooLongLabel verifies that backend label updates surface
167+
// query errors when the requested label exceeds the stored column limit.
168+
func TestUpdateTxRejectsTooLongLabel(t *testing.T) {
169+
t.Parallel()
170+
171+
store := NewTestStore(t)
172+
walletID := newWallet(t, store, "wallet-update-label-too-long")
173+
174+
tx := newRegularTx(
175+
[]wire.OutPoint{randomOutPoint()},
176+
[]*wire.TxOut{{Value: 9100, PkScript: []byte{0x51}}},
177+
)
178+
err := store.CreateTx(t.Context(), db.CreateTxParams{
179+
WalletID: walletID,
180+
Tx: tx,
181+
Received: time.Unix(1710001600, 0),
182+
Status: db.TxStatusPending,
183+
})
184+
require.NoError(t, err)
185+
186+
label := strings.Repeat("x", 501)
187+
err = store.UpdateTx(t.Context(), db.UpdateTxParams{
188+
WalletID: walletID,
189+
Txid: tx.TxHash(),
190+
Label: &label,
191+
})
192+
require.ErrorContains(t, err, "update transaction label")
193+
}

0 commit comments

Comments
 (0)