decred.org/dcrdex@v1.0.5/server/asset/zec/live_test.go (about)

     1  //go:build zeclive
     2  
     3  // go test -v -tags zeclive -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 zeclive -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 zeclive -run LiveFees
    15  // ------------------------------------------
    16  // Test that fees rates are parsed without error and that a few historical fee
    17  // rates are correct
    18  
    19  package zec
    20  
    21  import (
    22  	"context"
    23  	"fmt"
    24  	"os"
    25  	"testing"
    26  
    27  	"decred.org/dcrdex/dex"
    28  	"decred.org/dcrdex/server/asset"
    29  	"decred.org/dcrdex/server/asset/btc"
    30  )
    31  
    32  var (
    33  	zec *ZECBackend
    34  	ctx context.Context
    35  )
    36  
    37  func TestMain(m *testing.M) {
    38  	// Wrap everything for defers.
    39  	doIt := func() int {
    40  		logger := dex.StdOutLogger("ZECTEST", dex.LevelTrace)
    41  		be, err := NewBackend(&asset.BackendConfig{
    42  			AssetID: BipID,
    43  			Logger:  logger,
    44  			Net:     dex.Mainnet,
    45  		})
    46  		if err != nil {
    47  			fmt.Printf("NewBackend error: %v\n", err)
    48  			return 1
    49  		}
    50  
    51  		var ok bool
    52  		zec, ok = be.(*ZECBackend)
    53  		if !ok {
    54  			fmt.Printf("Could not cast asset.Backend to *Backend")
    55  			return 1
    56  		}
    57  
    58  		ctx, cancel := context.WithCancel(context.Background())
    59  		wg, err := zec.Connect(ctx)
    60  		if err != nil {
    61  			fmt.Printf("Connect failed: %v", err)
    62  			return 1
    63  		}
    64  		defer wg.Wait()
    65  		defer cancel()
    66  
    67  		return m.Run()
    68  	}
    69  
    70  	os.Exit(doIt())
    71  }
    72  
    73  func TestUTXOStats(t *testing.T) {
    74  	btc.LiveUTXOStats(zec.Backend, t)
    75  }
    76  
    77  func TestP2SHStats(t *testing.T) {
    78  	btc.LiveP2SHStats(zec.Backend, t, 50)
    79  }
    80  
    81  func TestLiveFees(t *testing.T) {
    82  	btc.LiveFeeRates(zec.Backend, t, map[string]uint64{
    83  		"920456117a0a9c55867e55cb02487d20a39feb4e4f6c9a69ec6f55fb243123e7": 5,
    84  		"90c2fbb3636e5bd8d35fc17202bfe86935fad3e8244e736f9b267c8d0ad14f90": 4631,
    85  	})
    86  }