mirror of
https://github.com/luxfi/proto.git
synced 2026-10-30 15:21:09 +00:00
53 lines
1.1 KiB
Go
53 lines
1.1 KiB
Go
// Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package mempool
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/luxfi/crypto"
|
|
"github.com/luxfi/ids"
|
|
"github.com/luxfi/metric"
|
|
|
|
"github.com/luxfi/proto/x/txs"
|
|
|
|
lux "github.com/luxfi/utxo"
|
|
)
|
|
|
|
func newMempool() (*Mempool, error) {
|
|
return New("mempool", metric.NewNoOpRegistry())
|
|
}
|
|
|
|
func TestMempoolBasics(t *testing.T) {
|
|
require := require.New(t)
|
|
|
|
mempool, err := newMempool()
|
|
require.NoError(err)
|
|
|
|
// Test that mempool starts empty
|
|
require.False(mempool.HasTxs())
|
|
|
|
// Add a transaction
|
|
tx := newTx(0, 32)
|
|
require.NoError(mempool.Add(tx))
|
|
|
|
// Verify mempool now has transactions
|
|
require.True(mempool.HasTxs())
|
|
}
|
|
|
|
func newTx(index uint32, size int) *txs.Tx {
|
|
tx := &txs.Tx{Unsigned: &txs.BaseTx{BaseTx: lux.BaseTx{
|
|
Ins: []*lux.TransferableInput{{
|
|
UTXOID: lux.UTXOID{
|
|
TxID: ids.ID{'t', 'x', 'I', 'D'},
|
|
OutputIndex: index,
|
|
},
|
|
}},
|
|
}}}
|
|
tx.SetBytes(crypto.RandomBytes(size), crypto.RandomBytes(size))
|
|
return tx
|
|
}
|