github.com/avahowell/sia@v0.5.1-beta.0.20160524050156-83dcc3d37c94/api/explorer_test.go (about) 1 package api 2 3 import ( 4 "testing" 5 6 "github.com/NebulousLabs/Sia/types" 7 ) 8 9 // TestIntegrationExplorerGET probes the GET call to /explorer. 10 func TestIntegrationExplorerGET(t *testing.T) { 11 if testing.Short() { 12 t.SkipNow() 13 } 14 st, err := createServerTester("TestIntegrationExplorerGET") 15 if err != nil { 16 t.Fatal(err) 17 } 18 defer st.server.Close() 19 20 var eg ExplorerGET 21 err = st.getAPI("/explorer", &eg) 22 if err != nil { 23 t.Fatal(err) 24 } 25 if eg.Height != st.server.cs.Height() { 26 t.Error("height not accurately reported by explorer") 27 } 28 if eg.MinerPayoutCount == 0 { 29 t.Error("Miner payout count is incorrect") 30 } 31 } 32 33 // TestIntegrationExplorerBlockGET probes the GET call to /explorer/block. 34 func TestIntegrationExplorerBlockGET(t *testing.T) { 35 if testing.Short() { 36 t.SkipNow() 37 } 38 st, err := createServerTester("TestIntegrationExplorerBlockGET") 39 if err != nil { 40 t.Fatal(err) 41 } 42 defer st.server.Close() 43 44 var ebg ExplorerBlockGET 45 err = st.getAPI("/explorer/blocks/0", &ebg) 46 if err != nil { 47 t.Fatal(err) 48 } 49 if ebg.Block.BlockID != ebg.Block.RawBlock.ID() { 50 t.Error("block id and block do not match up from api call") 51 } 52 if ebg.Block.BlockID != types.GenesisBlock.ID() { 53 t.Error("wrong block returned by /explorer/block?height=0") 54 } 55 } 56 57 // TestIntegrationExplorerHashGet probes the GET call to /explorer/hash/:hash. 58 func TestIntegrationExplorerHashGet(t *testing.T) { 59 if testing.Short() { 60 t.SkipNow() 61 } 62 st, err := createServerTester("TestIntegrationExplorerHashGET") 63 if err != nil { 64 t.Fatal(err) 65 } 66 defer st.server.Close() 67 68 var ehg ExplorerHashGET 69 gb := types.GenesisBlock 70 err = st.getAPI("/explorer/hashes/"+gb.ID().String(), &ehg) 71 if err != nil { 72 t.Fatal(err) 73 } 74 if ehg.HashType != "blockid" { 75 t.Error("wrong hash type returned when requesting block hash") 76 } 77 if ehg.Block.BlockID != gb.ID() { 78 t.Error("wrong block type returned") 79 } 80 }