chainntnfs: add TestTxNotifierMaxConfs
This commit is contained in:
parent
7239e04696
commit
fd2bfaa007
@ -26,7 +26,8 @@ var (
|
||||
|
||||
// ErrTxMaxConfs signals that the user requested a number of
|
||||
// confirmations beyond the reorg safety limit.
|
||||
ErrTxMaxConfs = errors.New("too many confirmations requested")
|
||||
ErrTxMaxConfs = fmt.Errorf("too many confirmations requested, max is %d",
|
||||
MaxNumConfs)
|
||||
)
|
||||
|
||||
// rescanState indicates the progression of a registration before the notifier
|
||||
|
@ -99,6 +99,36 @@ func newMockHintCache() *mockHintCache {
|
||||
}
|
||||
}
|
||||
|
||||
// TestTxNotifierMaxConfs ensures that we are not able to register for more
|
||||
// confirmations on a transaction than the maximum supported.
|
||||
func TestTxNotifierMaxConfs(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
hintCache := newMockHintCache()
|
||||
n := chainntnfs.NewTxNotifier(
|
||||
10, chainntnfs.ReorgSafetyLimit, hintCache, hintCache,
|
||||
)
|
||||
|
||||
// Registering one confirmation above the maximum should fail with
|
||||
// ErrTxMaxConfs.
|
||||
ntfn := &chainntnfs.ConfNtfn{
|
||||
ConfID: 1,
|
||||
TxID: &zeroHash,
|
||||
NumConfirmations: chainntnfs.MaxNumConfs + 1,
|
||||
Event: chainntnfs.NewConfirmationEvent(
|
||||
chainntnfs.MaxNumConfs,
|
||||
),
|
||||
}
|
||||
if _, err := n.RegisterConf(ntfn); err != chainntnfs.ErrTxMaxConfs {
|
||||
t.Fatalf("expected chainntnfs.ErrTxMaxConfs, got %v", err)
|
||||
}
|
||||
|
||||
ntfn.NumConfirmations--
|
||||
if _, err := n.RegisterConf(ntfn); err != nil {
|
||||
t.Fatalf("unable to register conf ntfn: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// TestTxNotifierFutureConfDispatch tests that the TxNotifier dispatches
|
||||
// registered notifications when a transaction confirms after registration.
|
||||
func TestTxNotifierFutureConfDispatch(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user