decred.org/dcrdex@v1.0.5/server/asset/ltc/live_test.go (about) 1 //go:build ltclive 2 3 // go test -v -tags ltclive -run UTXOStats 4 // ----------------------------------- 5 // Grab the most recent block and iterate it's outputs, taking account of 6 // how many UTXOs are found, how many are of an unknown type, etc. 7 // 8 // go test -v -tags ltclive -run P2SHStats 9 // ----------------------------------------- 10 // For each output in the last block, check it's previous outpoint to see if 11 // it's a P2SH or P2WSH. If so, takes statistics on the script types, including 12 // for the redeem script. 13 // 14 // go test -v -tags ltclive -run LiveFees 15 // ------------------------------------------ 16 // Test that fees rates are parsed without error and that a few historical fee 17 // rates are correct 18 // 19 // go test -v -tags ltclive -run TestMedianFeeRates 20 // ------------------------------------------ 21 // Test that a median fee rate can be calculated. 22 23 package ltc 24 25 import ( 26 "context" 27 "fmt" 28 "os" 29 "sync" 30 "testing" 31 32 "decred.org/dcrdex/dex" 33 "decred.org/dcrdex/server/asset" 34 "decred.org/dcrdex/server/asset/btc" 35 ) 36 37 var ( 38 ltc *btc.Backend 39 ctx context.Context 40 ) 41 42 func TestMain(m *testing.M) { 43 // Wrap everything for defers. 44 doIt := func() int { 45 var cancel context.CancelFunc 46 ctx, cancel = context.WithCancel(context.Background()) 47 wg := new(sync.WaitGroup) 48 defer func() { 49 cancel() 50 wg.Wait() 51 }() 52 53 logger := dex.StdOutLogger("LTCTEST", dex.LevelTrace) 54 dexAsset, err := NewBackend(&asset.BackendConfig{ 55 AssetID: BipID, 56 Logger: logger, 57 Net: dex.Mainnet, 58 }) 59 if err != nil { 60 fmt.Printf("NewBackend error: %v\n", err) 61 return 1 62 } 63 64 var ok bool 65 ltc, ok = dexAsset.(*btc.Backend) 66 if !ok { 67 fmt.Printf("Could not cast asset.Backend to *Backend") 68 return 1 69 } 70 71 wg, err = dexAsset.Connect(ctx) 72 if err != nil { 73 fmt.Printf("Connect failed: %v", err) 74 return 1 75 } 76 77 return m.Run() 78 } 79 80 os.Exit(doIt()) 81 } 82 83 func TestUTXOStats(t *testing.T) { 84 btc.LiveUTXOStats(ltc, t) 85 } 86 87 func TestP2SHStats(t *testing.T) { 88 btc.LiveP2SHStats(ltc, t, 1000) 89 } 90 91 func TestLiveFees(t *testing.T) { 92 btc.LiveFeeRates(ltc, t, map[string]uint64{ 93 "d9ec52f3d2c8497638b7de47f77b1e00e91ca98f88bf844b1ae3a2a8ca44bf0b": 1000, 94 "da68b225de1650d69fb57216d8403f91ea0a4b04f7be89150061748863480980": 703, 95 "6e7bfce6aee69312629b1f60afe6dcef02f367207642f2dc380a554c21181eb2": 888, 96 "9387d8b2097ee23cc3da36daf90262dda9a98eb25063ddddb630cf15513fa9b8": 1, 97 }) 98 } 99 100 func TestMedianFeeRates(t *testing.T) { 101 btc.TestMedianFees(ltc, t) 102 }