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)
}
TestSidecarsWithOrder tests that we're able to properly insert a new order
into a sidecar sub-bucket along with the ticket, as well as retrieve it again
in the future.
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)
}