func TestSidecarsWithSameID(t *testing.T) {
	t.Parallel()
	db, cleanup := newTestDB(t)
	defer cleanup()
	s := &sidecar.Ticket{
		ID:    [8]byte{12, 34, 56},
		State: sidecar.StateRegistered,
		Offer: sidecar.Offer{
			Capacity:            1000000,
			PushAmt:             200000,
			SignPubKey:          testTraderKey,
			LeaseDurationBlocks: 2016,
		},
		Recipient: &sidecar.Recipient{
			MultiSigPubKey:   testTraderKey,
			MultiSigKeyIndex: 7,
		},
	}
	require.NoError(t, db.AddSidecar(s))
	assertSidecarExists(t, db, s)
	s.Offer.SignPubKey = testBatchKey
	require.NoError(t, db.AddSidecar(s))
	assertSidecarExists(t, db, s)
	s.ID = [8]byte{99, 88, 77}
	require.NoError(t, db.AddSidecar(s))
	assertSidecarExists(t, db, s)
	s.ID = [8]byte{55, 44, 33}
	require.NoError(t, db.AddSidecar(s))
	assertSidecarExists(t, db, s)
	all, err := db.Sidecars()
	require.NoError(t, err)
	require.Len(t, all, 4)
	byID, err := db.SidecarsByID([8]byte{12, 34, 56})
	require.NoError(t, err)
	require.Len(t, byID, 2)
	for _, tkt := range byID {
		require.Equal(t, [8]byte{12, 34, 56}, tkt.ID)
	}
	require.Equal(t, testBatchKey, byID[0].Offer.SignPubKey)
	require.Equal(t, testTraderKey, byID[1].Offer.SignPubKey)
}
TestSidecarsWithSameID makes sure that sidecar tickets with the same ID but
different offer public keys can be stored and retrieved separately.
package clientdb
import (
	"testing"
	"github.com/lightninglabs/pool/order"
	"github.com/lightninglabs/pool/sidecar"
	"github.com/stretchr/testify/require"
)
func assertSidecarExists(t *testing.T, db *DB, expected *sidecar.Ticket) {
	t.Helper()
	found, err := db.Sidecar(expected.ID, expected.Offer.SignPubKey)
	require.NoError(t, err)
	require.Equal(t, expected, found)
}
func TestSidecars(t *testing.T) {
	t.Parallel()
	db, cleanup := newTestDB(t)
	defer cleanup()
	s := &sidecar.Ticket{
		ID:    [8]byte{12, 34, 56},
		State: sidecar.StateRegistered,
		Offer: sidecar.Offer{
			Capacity:            1000000,
			PushAmt:             200000,
			SignPubKey:          testTraderKey,
			LeaseDurationBlocks: 2016,
		},
		Recipient: &sidecar.Recipient{
			MultiSigPubKey:   testTraderKey,
			MultiSigKeyIndex: 7,
		},
	}
	err := db.AddSidecar(s)
	require.NoError(t, err)
	assertSidecarExists(t, db, s)
	s.State = sidecar.StateExpectingChannel
	s.Order = &sidecar.Order{
		BidNonce: order.Nonce{1, 2, 3},
	}
	err = db.UpdateSidecar(s)
	require.NoError(t, err)
	assertSidecarExists(t, db, s)
	sidecars, err := db.Sidecars()
	require.NoError(t, err)
	require.Len(t, sidecars, 1)
	require.Contains(t, sidecars, s)
	updatedTicket, err := db.Sidecar([8]byte{12, 34, 56}, testTraderKey)
	require.NoError(t, err)
	require.Equal(t, s, updatedTicket)
}
func TestSidecarsWithOrder(t *testing.T) {
	t.Parallel()
	db, cleanup := newTestDB(t)
	defer cleanup()
	bid := &order.Bid{
		Kit:             *dummyOrder(500000, 1337),
		MinNodeTier:     2,
		SelfChanBalance: 123,
		SidecarTicket: &sidecar.Ticket{
			ID:    [8]byte{11, 22, 33, 44, 55, 66, 77},
			State: sidecar.StateRegistered,
			Offer: sidecar.Offer{
				Capacity:            1000000,
				PushAmt:             200000,
				LeaseDurationBlocks: 2016,
			},
			Recipient: &sidecar.Recipient{
				MultiSigPubKey:   testTraderKey,
				MultiSigKeyIndex: 7,
			},
		},
	}
	bid.Details().MinUnitsMatch = 10
	ticket := &sidecar.Ticket{
		ID:    [8]byte{12, 34, 56},
		State: sidecar.StateRegistered,
		Offer: sidecar.Offer{
			Capacity:            1000000,
			PushAmt:             200000,
			SignPubKey:          testTraderKey,
			LeaseDurationBlocks: 2016,
		},
		Recipient: &sidecar.Recipient{
			MultiSigPubKey:   testTraderKey,
			MultiSigKeyIndex: 7,
		},
	}
	err := db.AddSidecarWithBid(ticket, bid)
	require.NoError(t, err)
	assertSidecarExists(t, db, ticket)
	diskBid, err := db.SidecarBidTemplate(ticket)
	require.NoError(t, err)
	require.Equal(t, diskBid, bid)
	ticket.State = sidecar.StateCanceled
	err = db.UpdateSidecar(ticket)
	require.NoError(t, err)
	_, err = db.SidecarBidTemplate(ticket)
	require.Equal(t, ErrNoOrder, err)
}