decred.org/dcrdex@v1.0.5/server/asset/firo/firo_live_test.go (about) 1 //go:build firolive 2 3 package firo 4 5 import ( 6 "context" 7 "encoding/json" 8 "fmt" 9 "os/user" 10 "path/filepath" 11 "testing" 12 13 "decred.org/dcrdex/dex" 14 "decred.org/dcrdex/dex/config" 15 dexbtc "decred.org/dcrdex/dex/networks/btc" 16 "github.com/decred/dcrd/rpcclient/v8" 17 ) 18 19 func TestScanTestnetBlocks(t *testing.T) { 20 // Testnet switched to ProgPOW at 37_310 21 testScanBlocks(t, dex.Testnet, 35_000, 40_000, "18888") 22 } 23 24 func TestScanMainnetBlocks(t *testing.T) { 25 // Mainnet switched to ProgPOW at 419_269 26 testScanBlocks(t, dex.Mainnet, 415_000, 425_000, "8888") 27 } 28 29 func testScanBlocks(t *testing.T, net dex.Network, startHeight, endHeight int64, port string) { 30 u, _ := user.Current() 31 configPath := filepath.Join(u.HomeDir, ".firo", "firo.conf") 32 var cfg dexbtc.RPCConfig 33 34 if err := config.ParseInto(configPath, &cfg); err != nil { 35 t.Fatalf("ParseInto error: %v", err) 36 } 37 dexbtc.StandardizeRPCConf(&cfg, port) 38 cl, err := rpcclient.New(&rpcclient.ConnConfig{ 39 HTTPPostMode: true, 40 DisableTLS: true, 41 Host: cfg.RPCBind, 42 User: cfg.RPCUser, 43 Pass: cfg.RPCPass, 44 }, nil) 45 if err != nil { 46 t.Fatalf("rpcclient.New error: %v", err) 47 } 48 49 ctx, cancel := context.WithCancel(context.Background()) 50 defer cancel() 51 52 deserializeBlockAtHeight := func(blockHeight int64) { 53 blockHash, err := cl.GetBlockHash(ctx, blockHeight) 54 if err != nil { 55 t.Fatalf("Error getting block hash for ") 56 } 57 58 hashStr, _ := json.Marshal(blockHash.String()) 59 60 b, err := cl.RawRequest(ctx, "getblock", []json.RawMessage{hashStr, []byte("false")}) 61 if err != nil { 62 t.Fatalf("RawRequest error: %v", err) 63 } 64 var blockB dex.Bytes 65 if err := json.Unmarshal(b, &blockB); err != nil { 66 t.Fatalf("Error unmarshalling hash string: %v", err) 67 } 68 firoBlock, err := deserializeFiroBlock(blockB, net) 69 if err != nil { 70 t.Fatalf("Deserialize error for block %s at height %d: %v", blockHash, blockHeight, err) 71 } 72 if firoBlock.HashRootMTP != [16]byte{} { 73 // None found on testnet or mainnet. I think the MTP proof stuff 74 // was cleaned out in an upgrade or something. 75 fmt.Printf("##### Block %d has MTP proofs \n", blockHeight) 76 } 77 } 78 79 for i := startHeight; i <= endHeight; i++ { 80 deserializeBlockAtHeight(i) 81 } 82 }