decred.org/dcrdex@v1.0.3/client/asset/dcr/vspd_http_test.go (about)

     1  //go:build vspd && !harness
     2  
     3  package dcr
     4  
     5  import (
     6  	"encoding/json"
     7  	"fmt"
     8  	"testing"
     9  
    10  	"decred.org/dcrdex/client/asset"
    11  	"decred.org/dcrdex/dex"
    12  )
    13  
    14  func TestHTTPForVSPD(t *testing.T) {
    15  	w := &ExchangeWallet{
    16  		network: dex.Testnet,
    17  		log:     dex.StdOutLogger("TEST", dex.LevelInfo),
    18  	}
    19  	vsps, err := w.ListVSPs()
    20  	if err != nil {
    21  		t.Fatalf("ListVSPs (testnet) error: %v", err)
    22  	}
    23  
    24  	fmt.Printf("##### %d testnet VSPs fetched \n", len(vsps))
    25  
    26  	w.network = dex.Mainnet
    27  	vsps, err = w.ListVSPs()
    28  	if err != nil {
    29  		t.Fatalf("ListVSPs (mainnet) error: %v", err)
    30  	}
    31  	if len(vsps) == 0 {
    32  		t.Fatalf("no mainnet VSPs listed")
    33  	}
    34  
    35  	fmt.Printf("##### %d mainnet VSPs fetched \n", len(vsps))
    36  
    37  	var biggestVSP *asset.VotingServiceProvider
    38  	for _, v := range vsps {
    39  		if biggestVSP == nil || v.Voting > biggestVSP.Voting {
    40  			biggestVSP = v
    41  		}
    42  	}
    43  
    44  	fmt.Printf("##### VSP with the most voting is %s, with %d tickets \n", biggestVSP.URL, biggestVSP.Voting)
    45  
    46  	vspi, err := vspInfo(biggestVSP.URL)
    47  	if err != nil {
    48  		t.Fatalf("vspInfo error: %v", err)
    49  	}
    50  
    51  	b, _ := json.MarshalIndent(vspi, "", "    ")
    52  	fmt.Printf("##### VSP Info fetched \n----------------------\n%s\n", string(b))
    53  }