Skip tests that are no able to connect their backends

This commit is contained in:
Jakub Matys 2018-06-27 12:35:26 +02:00
parent 8d0a31927a
commit 7040853212
8 changed files with 97 additions and 9 deletions

View File

@ -6,6 +6,8 @@ import (
"blockbook/bchain" "blockbook/bchain"
"blockbook/bchain/tests/rpc" "blockbook/bchain/tests/rpc"
"encoding/json" "encoding/json"
"flag"
"os"
"testing" "testing"
) )
@ -25,12 +27,17 @@ func getRPCClient(cfg json.RawMessage) (bchain.BlockChain, error) {
var rpcTest *rpc.Test var rpcTest *rpc.Test
func init() { func TestMain(m *testing.M) {
flag.Parse()
t, err := rpc.NewTest("Bcash Testnet", getRPCClient) t, err := rpc.NewTest("Bcash Testnet", getRPCClient)
if err != nil { if err != nil {
panic(err) panic(err)
} }
t.TryConnect()
rpcTest = t rpcTest = t
os.Exit(m.Run())
} }
func TestBCashRPC_GetBlockHash(t *testing.T) { func TestBCashRPC_GetBlockHash(t *testing.T) {

View File

@ -6,6 +6,8 @@ import (
"blockbook/bchain" "blockbook/bchain"
"blockbook/bchain/tests/rpc" "blockbook/bchain/tests/rpc"
"encoding/json" "encoding/json"
"flag"
"os"
"testing" "testing"
) )
@ -25,12 +27,17 @@ func getRPCClient(cfg json.RawMessage) (bchain.BlockChain, error) {
var rpcTest *rpc.Test var rpcTest *rpc.Test
func init() { func TestMain(m *testing.M) {
flag.Parse()
t, err := rpc.NewTest("Bitcoin Testnet", getRPCClient) t, err := rpc.NewTest("Bitcoin Testnet", getRPCClient)
if err != nil { if err != nil {
panic(err) panic(err)
} }
t.TryConnect()
rpcTest = t rpcTest = t
os.Exit(m.Run())
} }
func TestBitcoinRPC_GetBlockHash(t *testing.T) { func TestBitcoinRPC_GetBlockHash(t *testing.T) {

View File

@ -6,6 +6,8 @@ import (
"blockbook/bchain" "blockbook/bchain"
"blockbook/bchain/tests/rpc" "blockbook/bchain/tests/rpc"
"encoding/json" "encoding/json"
"flag"
"os"
"testing" "testing"
) )
@ -22,12 +24,17 @@ func getRPCClient(cfg json.RawMessage) (bchain.BlockChain, error) {
var rpcTest *rpc.Test var rpcTest *rpc.Test
func init() { func TestMain(m *testing.M) {
flag.Parse()
t, err := rpc.NewTest("Dash Testnet", getRPCClient) t, err := rpc.NewTest("Dash Testnet", getRPCClient)
if err != nil { if err != nil {
panic(err) panic(err)
} }
t.TryConnect()
rpcTest = t rpcTest = t
os.Exit(m.Run())
} }
func TestDashRPC_GetBlockHash(t *testing.T) { func TestDashRPC_GetBlockHash(t *testing.T) {

View File

@ -6,6 +6,8 @@ import (
"blockbook/bchain" "blockbook/bchain"
"blockbook/bchain/tests/rpc" "blockbook/bchain/tests/rpc"
"encoding/json" "encoding/json"
"flag"
"os"
"reflect" "reflect"
"testing" "testing"
@ -22,12 +24,17 @@ func getRPCClient(cfg json.RawMessage) (bchain.BlockChain, error) {
var rpcTest *rpc.Test var rpcTest *rpc.Test
func init() { func TestMain(m *testing.M) {
flag.Parse()
t, err := rpc.NewTest("Ethereum Testnet", getRPCClient) t, err := rpc.NewTest("Ethereum Testnet", getRPCClient)
if err != nil { if err != nil {
panic(err) panic(err)
} }
t.TryConnect()
rpcTest = t rpcTest = t
os.Exit(m.Run())
} }
func TestEthRPC_GetBlockHash(t *testing.T) { func TestEthRPC_GetBlockHash(t *testing.T) {

View File

@ -6,6 +6,8 @@ import (
"blockbook/bchain" "blockbook/bchain"
"blockbook/bchain/tests/rpc" "blockbook/bchain/tests/rpc"
"encoding/json" "encoding/json"
"flag"
"os"
"testing" "testing"
) )
@ -25,12 +27,17 @@ func getRPCClient(cfg json.RawMessage) (bchain.BlockChain, error) {
var rpcTest *rpc.Test var rpcTest *rpc.Test
func init() { func TestMain(m *testing.M) {
flag.Parse()
t, err := rpc.NewTest("Namecoin", getRPCClient) t, err := rpc.NewTest("Namecoin", getRPCClient)
if err != nil { if err != nil {
panic(err) panic(err)
} }
t.TryConnect()
rpcTest = t rpcTest = t
os.Exit(m.Run())
} }
func TestNamecoinRPC_GetBlockHash(t *testing.T) { func TestNamecoinRPC_GetBlockHash(t *testing.T) {

View File

@ -6,6 +6,8 @@ import (
"blockbook/bchain" "blockbook/bchain"
"blockbook/bchain/tests/rpc" "blockbook/bchain/tests/rpc"
"encoding/json" "encoding/json"
"flag"
"os"
"testing" "testing"
) )
@ -25,12 +27,17 @@ func getRPCClient(cfg json.RawMessage) (bchain.BlockChain, error) {
var rpcTest *rpc.Test var rpcTest *rpc.Test
func init() { func TestMain(m *testing.M) {
flag.Parse()
t, err := rpc.NewTest("Vertcoin", getRPCClient) t, err := rpc.NewTest("Vertcoin", getRPCClient)
if err != nil { if err != nil {
panic(err) panic(err)
} }
t.TryConnect()
rpcTest = t rpcTest = t
os.Exit(m.Run())
} }
func TestVertcoinRPC_GetBlockHash(t *testing.T) { func TestVertcoinRPC_GetBlockHash(t *testing.T) {

View File

@ -6,6 +6,8 @@ import (
"blockbook/bchain" "blockbook/bchain"
"blockbook/bchain/tests/rpc" "blockbook/bchain/tests/rpc"
"encoding/json" "encoding/json"
"flag"
"os"
"testing" "testing"
) )
@ -22,12 +24,17 @@ func getRPCClient(cfg json.RawMessage) (bchain.BlockChain, error) {
var rpcTest *rpc.Test var rpcTest *rpc.Test
func init() { func TestMain(m *testing.M) {
flag.Parse()
t, err := rpc.NewTest("Zcash Testnet", getRPCClient) t, err := rpc.NewTest("Zcash Testnet", getRPCClient)
if err != nil { if err != nil {
panic(err) panic(err)
} }
t.TryConnect()
rpcTest = t rpcTest = t
os.Exit(m.Run())
} }
func TestZCashRPC_GetBlockHash(t *testing.T) { func TestZCashRPC_GetBlockHash(t *testing.T) {

View File

@ -6,6 +6,7 @@ import (
"blockbook/bchain" "blockbook/bchain"
"encoding/json" "encoding/json"
"math/rand" "math/rand"
"net"
"reflect" "reflect"
"testing" "testing"
"time" "time"
@ -26,8 +27,9 @@ type TestData struct {
} }
type Test struct { type Test struct {
Client bchain.BlockChain Client bchain.BlockChain
TestData *TestData TestData *TestData
connected bool
} }
type TestChainFactoryFunc func(json.RawMessage) (bchain.BlockChain, error) type TestChainFactoryFunc func(json.RawMessage) (bchain.BlockChain, error)
@ -75,7 +77,28 @@ func setTxAddresses(parser bchain.BlockChainParser, tx *bchain.Tx) error {
} }
return err return err
} }
func (rt *Test) TryConnect() {
_, err := rt.Client.GetBlockChainInfo()
if err != nil {
switch err.(type) {
case net.Error:
rt.connected = false
return
}
}
rt.connected = true
}
func (rt *Test) skipUnconnected(t *testing.T) {
if !rt.connected {
t.Skip("Skipping test, not connected to backend service")
}
}
func (rt *Test) TestGetBlockHash(t *testing.T) { func (rt *Test) TestGetBlockHash(t *testing.T) {
rt.skipUnconnected(t)
hash, err := rt.Client.GetBlockHash(rt.TestData.BlockHeight) hash, err := rt.Client.GetBlockHash(rt.TestData.BlockHeight)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
@ -88,6 +111,8 @@ func (rt *Test) TestGetBlockHash(t *testing.T) {
} }
func (rt *Test) TestGetBlock(t *testing.T) { func (rt *Test) TestGetBlock(t *testing.T) {
rt.skipUnconnected(t)
blk, err := rt.Client.GetBlock(rt.TestData.BlockHash, 0) blk, err := rt.Client.GetBlock(rt.TestData.BlockHash, 0)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
@ -107,6 +132,8 @@ func (rt *Test) TestGetBlock(t *testing.T) {
} }
func (rt *Test) TestGetTransaction(t *testing.T) { func (rt *Test) TestGetTransaction(t *testing.T) {
rt.skipUnconnected(t)
for txid, want := range rt.TestData.TxDetails { for txid, want := range rt.TestData.TxDetails {
got, err := rt.Client.GetTransaction(txid) got, err := rt.Client.GetTransaction(txid)
if err != nil { if err != nil {
@ -166,6 +193,8 @@ func (rt *Test) getMempoolTransaction(t *testing.T, txid string) *bchain.Tx {
} }
func (rt *Test) TestGetTransactionForMempool(t *testing.T) { func (rt *Test) TestGetTransactionForMempool(t *testing.T) {
rt.skipUnconnected(t)
txs := rt.getMempool(t) txs := rt.getMempool(t)
txid := txs[rand.Intn(len(txs))] txid := txs[rand.Intn(len(txs))]
got := rt.getMempoolTransaction(t, txid) got := rt.getMempoolTransaction(t, txid)
@ -203,6 +232,8 @@ func (rt *Test) getMempoolAddresses(t *testing.T, txs []string) map[string][]str
} }
func (rt *Test) TestMempoolSync(t *testing.T) { func (rt *Test) TestMempoolSync(t *testing.T) {
rt.skipUnconnected(t)
for i := 0; i < 3; i++ { for i := 0; i < 3; i++ {
txs := rt.getMempool(t) txs := rt.getMempool(t)
txid2addrs := rt.getMempoolAddresses(t, txs) txid2addrs := rt.getMempoolAddresses(t, txs)
@ -253,6 +284,8 @@ func containsString(slice []string, s string) bool {
} }
func (rt *Test) TestGetMempoolEntry(t *testing.T) { func (rt *Test) TestGetMempoolEntry(t *testing.T) {
rt.skipUnconnected(t)
for i := 0; i < 3; i++ { for i := 0; i < 3; i++ {
txs := rt.getMempool(t) txs := rt.getMempool(t)
h, err := rt.Client.GetBestBlockHeight() h, err := rt.Client.GetBestBlockHeight()
@ -286,6 +319,8 @@ func (rt *Test) TestGetMempoolEntry(t *testing.T) {
} }
func (rt *Test) TestSendRawTransaction(t *testing.T) { func (rt *Test) TestSendRawTransaction(t *testing.T) {
rt.skipUnconnected(t)
for txid, tx := range rt.TestData.TxDetails { for txid, tx := range rt.TestData.TxDetails {
_, err := rt.Client.SendRawTransaction(tx.Hex) _, err := rt.Client.SendRawTransaction(tx.Hex)
if err != nil { if err != nil {
@ -298,6 +333,8 @@ func (rt *Test) TestSendRawTransaction(t *testing.T) {
} }
func (rt *Test) TestEstimateSmartFee(t *testing.T) { func (rt *Test) TestEstimateSmartFee(t *testing.T) {
rt.skipUnconnected(t)
for _, blocks := range []int{1, 2, 3, 5, 10} { for _, blocks := range []int{1, 2, 3, 5, 10} {
fee, err := rt.Client.EstimateSmartFee(blocks, true) fee, err := rt.Client.EstimateSmartFee(blocks, true)
if err != nil { if err != nil {
@ -310,6 +347,8 @@ func (rt *Test) TestEstimateSmartFee(t *testing.T) {
} }
func (rt *Test) TestEstimateFee(t *testing.T) { func (rt *Test) TestEstimateFee(t *testing.T) {
rt.skipUnconnected(t)
for _, blocks := range []int{1, 2, 3, 5, 10} { for _, blocks := range []int{1, 2, 3, 5, 10} {
fee, err := rt.Client.EstimateFee(blocks) fee, err := rt.Client.EstimateFee(blocks)
if err != nil { if err != nil {