func errorPriceTest(order *AuctionOrder, t *testing.T) {
	var err error
	var origPrice float64
	if origPrice, err = order.Price(); err == nil {
		t.Errorf("There was no error while calculating price for order, instead a price of %f was returned", origPrice)
		return
	}
	return
}
validPriceTest runs a test to make sure the order has an error for calculating its price
package match
import (
	"crypto/rand"
	mathrand "math/rand"
	"testing"
	"github.com/mit-dci/lit/crypto/koblitz"
	"golang.org/x/crypto/sha3"
)
var (
	orderPair = Pair{
		AssetWant: BTC,
		AssetHave: VTC,
	}
	emptyOrder = &AuctionOrder{}
	origOrderID = OrderID([32]byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07})
	origOrder   = &AuctionOrder{
		Side:        Buy,
		TradingPair: orderPair,
		AmountHave:  100000000,
		AmountWant:  100000000,
		Nonce: [2]byte{0xff, 0x12},
	}
	origOrderCounterID = OrderID([32]byte{0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f})
	origOrderCounter   = &AuctionOrder{
		Side:        Sell,
		TradingPair: orderPair,
		AmountHave:  100000000,
		AmountWant:  100000000,
		Nonce: [2]byte{0xff, 0x12},
	}
	origOrderFullExec = &OrderExecution{
		OrderID: OrderID([32]byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}),
		NewAmountWant: 23892323,
		NewAmountHave: 37348722,
		Filled:        true,
	}
	origOrderFullDebit = &SettlementExecution{
		Amount: 100000000,
		Asset:  BTC,
		Type:   Debit,
	}
	origOrderFullCredit = &SettlementExecution{
		Amount: 100000000,
		Asset:  VTC,
		Type:   Credit,
	}
	origOrderDoubleExec = &OrderExecution{
		OrderID: OrderID([32]byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}),
		NewAmountWant: 53872666,
		NewAmountHave: 47666772,
		Filled:        true,
	}
	origOrderDoubleCredit = &SettlementExecution{
		Amount: 100000000,
		Asset:  VTC,
		Type:   Credit,
	}
	origOrderDoubleDebit = &SettlementExecution{
		Amount: 200000000,
		Asset:  BTC,
		Type:   Debit,
	}
)
func TestIsBuySide(t *testing.T) {
	buyAuction := &AuctionOrder{
		Side: Buy,
	}
	var res bool
	if res = buyAuction.IsBuySide(); !res {
		t.Errorf("Buy auction should have returned true, instead returned %t", res)
	}
	sellAuction := &AuctionOrder{
		Side: Sell,
	}
	if res = sellAuction.IsBuySide(); res {
		t.Errorf("Sell auction should have returned false, instead returned %t", res)
	}
	return
}
func TestIsSellSide(t *testing.T) {
	sellAuction := &AuctionOrder{
		Side: Sell,
	}
	var res bool
	if res = sellAuction.IsSellSide(); !res {
		t.Errorf("Sell auction should have returned true, instead returned %t", res)
	}
	buyAuction := &AuctionOrder{
		Side: Buy,
	}
	if res = buyAuction.IsSellSide(); res {
		t.Errorf("Buy auction should have returned false, instead returned %t", res)
	}
	return
}
func createInclusionMap(setExecs []*SettlementExecution) (resMap map[SettlementExecution]bool) {
	resMap = make(map[SettlementExecution]bool)
	for _, setExec := range setExecs {
		resMap[*setExec] = true
	}
	return
}
func TestGenerateEasyExecutionFromPrice(t *testing.T) {
	var err error
	var resExec OrderExecution
	var setExecs []*SettlementExecution
	var fillRemainder uint64
	if resExec, setExecs, fillRemainder, err = origOrder.GenerateExecutionFromPrice(&origOrderID, float64(1), 100000000); err != nil {
		t.Errorf("Error generating execution from price, should not error: %s", err)
		return
	}
	if resExec.Filled != origOrderFullExec.Filled {
		t.Errorf("Both executions should be filled, but the result's filled variable is %t", resExec.Filled)
		return
	}
	if resExec.OrderID != origOrderFullExec.OrderID {
		t.Errorf("Order IDs should be equal for both executions. The result should be %x but was %x", origOrderFullExec.OrderID, resExec.OrderID)
		return
	}
	execMap := createInclusionMap(setExecs)
	var inExecutions bool
	if _, inExecutions = execMap[*origOrderFullCredit]; !inExecutions {
		t.Errorf("Credit not the same. The result did not include %s", origOrderFullCredit)
		return
	}
	if _, inExecutions = execMap[*origOrderFullDebit]; !inExecutions {
		t.Errorf("Debit not the same. The result did not include %s", origOrderFullDebit)
		return
	}
	if resExec.NewAmountHave != 0 {
		t.Errorf("A filled order should have no 'NewAmountHave' left. It has %d instead", resExec.NewAmountHave)
		return
	}
	if fillRemainder != 0 {
		t.Errorf("The remainder from this order fill should be 0 since it should be exact. Was %d instead", fillRemainder)
		return
	}
	return
}
func TestGenerateDoubleFill(t *testing.T) {
	var err error
	var resExec OrderExecution
	var setExecs []*SettlementExecution
	if resExec, setExecs, err = origOrder.GenerateOrderFill(&origOrderID, float64(2)); err != nil {
		t.Errorf("Error generating execution from price, should not error: %s", err)
		return
	}
	if resExec.Filled != origOrderDoubleExec.Filled {
		t.Errorf("Both executions should be filled, but the result's filled variable is %t", resExec.Filled)
		return
	}
	if resExec.OrderID != origOrderDoubleExec.OrderID {
		t.Errorf("Order IDs should be equal for both executions. The result should be %x but was %x", origOrderDoubleExec.OrderID, resExec.OrderID)
		return
	}
	execMap := createInclusionMap(setExecs)
	var inExecutions bool
	if _, inExecutions = execMap[*origOrderDoubleCredit]; !inExecutions {
		t.Errorf("Credit not the same. The result did not include %s", origOrderDoubleCredit)
		return
	}
	if _, inExecutions = execMap[*origOrderDoubleDebit]; !inExecutions {
		t.Errorf("Debit not the same. The result did not include %s", origOrderDoubleDebit)
		return
	}
	if resExec.NewAmountHave != 0 {
		t.Errorf("A filled order should have no 'NewAmountHave' left. It has %d instead", resExec.NewAmountHave)
		return
	}
	return
}
func TestGenerateEasyFillFromPrice(t *testing.T) {
	var err error
	var resExec OrderExecution
	var setExecs []*SettlementExecution
	if resExec, setExecs, err = origOrder.GenerateOrderFill(&origOrderID, float64(1)); err != nil {
		t.Errorf("Error generating execution from price, should not error: %s", err)
		return
	}
	if resExec.Filled != origOrderFullExec.Filled {
		t.Errorf("Both executions should be filled, but the result's filled variable is %t", resExec.Filled)
		return
	}
	if resExec.OrderID != origOrderFullExec.OrderID {
		t.Errorf("Order IDs should be equal for both executions. The result should be %x but was %x", origOrderFullExec.OrderID, resExec.OrderID)
		return
	}
	execMap := createInclusionMap(setExecs)
	var inExecutions bool
	if _, inExecutions = execMap[*origOrderFullCredit]; !inExecutions {
		t.Errorf("Credit not the same. The result did not include %s", origOrderFullCredit)
		return
	}
	if _, inExecutions = execMap[*origOrderFullDebit]; !inExecutions {
		t.Errorf("Debit not the same. The result did not include %s", origOrderFullDebit)
		return
	}
	if resExec.NewAmountHave != 0 {
		t.Errorf("A filled order should have no 'NewAmountHave' left. It has %d instead", resExec.NewAmountHave)
		return
	}
	return
}
func TestGenerateBadPriceFill(t *testing.T) {
	var err error
	badOrder := new(AuctionOrder)
	*badOrder = *origOrder
	var resExec OrderExecution
	var setExecs []*SettlementExecution
	if resExec, setExecs, err = badOrder.GenerateOrderFill(&origOrderID, float64(0)); err == nil {
		t.Errorf("There was no error trying to generate an order fill for a price of zero")
		return
	}
	emptyExec := &OrderExecution{}
	if !(&resExec).Equal(emptyExec) {
		t.Errorf("GenerateOrderFill created part of an order execution on failure, this should not happen")
		return
	}
	if len(setExecs) != 0 {
		t.Errorf("GenerateOrderFill created a settlement execution on failure, this should not happen")
		return
	}
	return
}
func TestGenerateEasyPriceFillAmounts(t *testing.T) {
	var err error
	zeroPriceOrder := new(AuctionOrder)
	*zeroPriceOrder = *origOrder
	var resExec OrderExecution
	var setExecs []*SettlementExecution
	if resExec, setExecs, err = zeroPriceOrder.GenerateOrderFill(&origOrderID, float64(1)); err != nil {
		t.Errorf("Error generating execution from price, should not error: %s", err)
		return
	}
	if resExec.Filled != origOrderFullExec.Filled {
		t.Errorf("Both executions should be filled, but the result's filled variable is %t", resExec.Filled)
		return
	}
	if resExec.OrderID != origOrderFullExec.OrderID {
		t.Errorf("Order IDs should be equal for both executions. The result should be %x but was %x", origOrderFullExec.OrderID, resExec.OrderID)
		return
	}
	if resExec.NewAmountHave != 0 {
		t.Errorf("A filled order should have no 'NewAmountHave' left. It has %d instead", resExec.NewAmountHave)
		return
	}
	execMap := createInclusionMap(setExecs)
	var inExecutions bool
	if _, inExecutions = execMap[*origOrderFullCredit]; !inExecutions {
		t.Errorf("Credit not the same. The result did not include %s", origOrderFullCredit)
		return
	}
	if _, inExecutions = execMap[*origOrderFullDebit]; !inExecutions {
		t.Errorf("Debit not the same. The result did not include %s", origOrderFullDebit)
		return
	}
	return
}
func TestSimplePriceValidBuy(t *testing.T) {
	var err error
	var retPriceOne float64
	if retPriceOne, err = origOrder.Price(); err != nil {
		t.Errorf("Calculating price for origOrder should not have failed, here's the err: %s", err)
		return
	}
	expectedPrice := 1.0
	if retPriceOne != expectedPrice {
		t.Errorf("Price for origOrder should have been %f but was %f", expectedPrice, retPriceOne)
		return
	}
	var retPriceOneCounter float64
	if retPriceOneCounter, err = origOrderCounter.Price(); err != nil {
		t.Errorf("Calculating price for origOrderCounter should not have failed, here's the err: %s", err)
		return
	}
	expectedPriceCounter := 1.0
	if retPriceOneCounter != expectedPriceCounter {
		t.Errorf("Price for origOrderCounter should have been %f but was %f", expectedPriceCounter, retPriceOneCounter)
		return
	}
	if retPriceOneCounter != retPriceOne {
		t.Errorf("The price for retPriceOne, which was %f, should have been the same as retPriceOneCounter, which was %f", retPriceOne, retPriceOneCounter)
		return
	}
}
var (
	priceTwoBuy = &AuctionOrder{
		Side:        Buy,
		TradingPair: orderPair,
		AmountWant:  200000000,  
		AmountHave:  100000000,  
		Nonce: [2]byte{0xff, 0x12},
	}
	priceTwoSell = &AuctionOrder{
		Side:        Sell,
		TradingPair: orderPair,
		AmountWant:  200000000,  
		AmountHave:  100000000,  
		Nonce: [2]byte{0xf1, 0x23},
	}
	priceErrorWant = &AuctionOrder{
		Side:        Sell,
		TradingPair: orderPair,
		AmountWant:  0,          
		AmountHave:  100000000,  
		Nonce: [2]byte{0xf1, 0x23},
	}
	priceErrorHave = &AuctionOrder{
		Side:        Buy,
		TradingPair: orderPair,
		AmountWant:  200000000,  
		AmountHave:  0,          
		Nonce: [2]byte{0xf1, 0x23},
	}
	priceErrorBoth = &AuctionOrder{
		Side:        Buy,
		TradingPair: orderPair,
		AmountWant:  0,  
		AmountHave:  0,  
		Nonce: [2]byte{0xf1, 0x23},
	}
)
func validPriceTest(order *AuctionOrder, expectedPrice float64, t *testing.T) {
	var err error
	var origPrice float64
	if origPrice, err = order.Price(); err != nil {
		t.Errorf("Error getting price for order: %s", err)
		return
	}
	if origPrice != expectedPrice {
		t.Errorf("Test failed: price should have been %f but was %f", expectedPrice, origPrice)
		return
	}
	return
}