decred.org/dcrdex@v1.0.5/server/db/testhelpers_test.go (about) 1 package db 2 3 import ( 4 "time" 5 6 "decred.org/dcrdex/dex" 7 "decred.org/dcrdex/dex/order" 8 "decred.org/dcrdex/server/account" 9 ) 10 11 const ( 12 LotSize = uint64(100_0000_0000) // 100 13 RateStep = uint64(10_0000) // 0.001 14 EpochDuration = uint64(10_000) 15 MarketBuyBuffer = 1.1 16 ) 17 18 // The asset integer IDs should set in TestMain or other bring up function (e.g. 19 // openDB()) prior to using them. 20 var ( 21 AssetDCR uint32 22 AssetBTC uint32 23 ) 24 25 func startLogger() { 26 logger := dex.StdOutLogger("ORDER_DB_TEST", dex.LevelTrace) 27 UseLogger(logger) 28 } 29 30 var acct0 = account.AccountID{ 31 0x22, 0x4c, 0xba, 0xaa, 0xfa, 0x80, 0xbf, 0x3b, 0xd1, 0xff, 0x73, 0x15, 32 0x90, 0xbc, 0xbd, 0xda, 0x5a, 0x76, 0xf9, 0x1e, 0x60, 0xa1, 0x56, 0x99, 33 0x46, 0x34, 0xe9, 0x1c, 0xec, 0x25, 0xd5, 0x40, 34 } 35 36 func newLimitOrder(sell bool, rate, quantityLots uint64, force order.TimeInForce, timeOffset int64) *order.LimitOrder { 37 addr := "DcqXswjTPnUcd4FRCkX4vRJxmVtfgGVa5ui" 38 if sell { 39 addr = "149RQGLaHf2gGiL4NXZdH7aA8nYEuLLrgm" 40 } 41 return &order.LimitOrder{ 42 P: order.Prefix{ 43 AccountID: acct0, 44 BaseAsset: AssetDCR, 45 QuoteAsset: AssetBTC, 46 OrderType: order.LimitOrderType, 47 ClientTime: time.Unix(1566497653+timeOffset, 0), 48 ServerTime: time.Unix(1566497656+timeOffset, 0), 49 }, 50 T: order.Trade{ 51 Coins: []order.CoinID{ 52 { 53 0x45, 0xb8, 0x21, 0x38, 0xca, 0x90, 0xe6, 0x65, 0xa1, 0xc8, 0x79, 0x3a, 54 0xa9, 0x01, 0xaa, 0x23, 0x2d, 0xd8, 0x2b, 0xe4, 0x1b, 0x8e, 0x63, 0x0d, 55 0xd6, 0x21, 0xf2, 0x4e, 0x71, 0x7f, 0xc1, 0x3a, 0x00, 0x00, 0x00, 0x02, 56 }, 57 }, 58 Sell: sell, 59 Quantity: quantityLots * LotSize, 60 Address: addr, 61 }, 62 Rate: rate, 63 Force: force, 64 } 65 } 66 67 func newMarketSellOrder(quantityLots uint64, timeOffset int64) *order.MarketOrder { 68 return &order.MarketOrder{ 69 P: order.Prefix{ 70 AccountID: acct0, 71 BaseAsset: AssetDCR, 72 QuoteAsset: AssetBTC, 73 OrderType: order.MarketOrderType, 74 ClientTime: time.Unix(1566497653+timeOffset, 0), 75 ServerTime: time.Unix(1566497656+timeOffset, 0), 76 }, 77 T: order.Trade{ 78 Coins: []order.CoinID{}, 79 Sell: true, 80 Quantity: quantityLots * LotSize, 81 Address: "149RQGLaHf2gGiL4NXZdH7aA8nYEuLLrgm", 82 }, 83 } 84 } 85 86 func newMarketBuyOrder(quantityQuoteAsset uint64, timeOffset int64) *order.MarketOrder { 87 return &order.MarketOrder{ 88 P: order.Prefix{ 89 AccountID: acct0, 90 BaseAsset: AssetDCR, 91 QuoteAsset: AssetBTC, 92 OrderType: order.MarketOrderType, 93 ClientTime: time.Unix(1566497653+timeOffset, 0), 94 ServerTime: time.Unix(1566497656+timeOffset, 0), 95 }, 96 T: order.Trade{ 97 Coins: []order.CoinID{}, 98 Sell: false, 99 Quantity: quantityQuoteAsset, 100 Address: "DcqXswjTPnUcd4FRCkX4vRJxmVtfgGVa5ui", 101 }, 102 } 103 } 104 105 func newCancelOrder(targetOrderID order.OrderID, base, quote uint32, timeOffset int64) *order.CancelOrder { 106 return &order.CancelOrder{ 107 P: order.Prefix{ 108 AccountID: acct0, 109 BaseAsset: base, 110 QuoteAsset: quote, 111 OrderType: order.CancelOrderType, 112 ClientTime: time.Unix(1566497653+timeOffset, 0), 113 ServerTime: time.Unix(1566497656+timeOffset, 0), 114 }, 115 TargetOrderID: targetOrderID, 116 } 117 }