mirror of
https://github.com/trezor/blockbook.git
synced 2026-02-20 00:51:39 +01:00
integration tests: fixing bitcoin and zcash issues : racing, missing output, invalid vout index and block-not-found
This commit is contained in:
@@ -512,7 +512,8 @@ func (b *BitcoinRPC) GetChainInfo() (*bchain.ChainInfo, error) {
|
|||||||
// IsErrBlockNotFound returns true if error means block was not found
|
// IsErrBlockNotFound returns true if error means block was not found
|
||||||
func IsErrBlockNotFound(err *bchain.RPCError) bool {
|
func IsErrBlockNotFound(err *bchain.RPCError) bool {
|
||||||
return err.Message == "Block not found" ||
|
return err.Message == "Block not found" ||
|
||||||
err.Message == "Block height out of range"
|
err.Message == "Block height out of range" ||
|
||||||
|
err.Message == "Provided index is greater than the current tip"
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetBlockHash returns hash of block in best-block-chain at given height.
|
// GetBlockHash returns hash of block in best-block-chain at given height.
|
||||||
|
|||||||
@@ -204,6 +204,8 @@ func testGetTransactionForMempool(t *testing.T, h *TestHandler) {
|
|||||||
for txid, want := range h.TestData.TxDetails {
|
for txid, want := range h.TestData.TxDetails {
|
||||||
// reset fields that are not parsed by BlockChainParser
|
// reset fields that are not parsed by BlockChainParser
|
||||||
want.Confirmations, want.Blocktime, want.Time, want.CoinSpecificData = 0, 0, 0, nil
|
want.Confirmations, want.Blocktime, want.Time, want.CoinSpecificData = 0, 0, 0, nil
|
||||||
|
// Mempool endpoints may or may not include segwit witness; keep comparisons backend-agnostic.
|
||||||
|
stripWitness(want)
|
||||||
|
|
||||||
got, err := h.Chain.GetTransactionForMempool(txid)
|
got, err := h.Chain.GetTransactionForMempool(txid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -215,6 +217,7 @@ func testGetTransactionForMempool(t *testing.T, h *TestHandler) {
|
|||||||
|
|
||||||
// transactions parsed from JSON may contain additional data
|
// transactions parsed from JSON may contain additional data
|
||||||
got.Confirmations, got.Blocktime, got.Time, got.CoinSpecificData = 0, 0, 0, nil
|
got.Confirmations, got.Blocktime, got.Time, got.CoinSpecificData = 0, 0, 0, nil
|
||||||
|
stripWitness(got)
|
||||||
if !reflect.DeepEqual(got, want) {
|
if !reflect.DeepEqual(got, want) {
|
||||||
t.Errorf("GetTransactionForMempool() got %+#v, want %+#v", got, want)
|
t.Errorf("GetTransactionForMempool() got %+#v, want %+#v", got, want)
|
||||||
}
|
}
|
||||||
@@ -248,6 +251,12 @@ func normalizeAddresses(tx *bchain.Tx, parser bchain.BlockChainParser) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func stripWitness(tx *bchain.Tx) {
|
||||||
|
for i := range tx.Vin {
|
||||||
|
tx.Vin[i].Witness = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func testMempoolSync(t *testing.T, h *TestHandler) {
|
func testMempoolSync(t *testing.T, h *TestHandler) {
|
||||||
for i := 0; i < 3; i++ {
|
for i := 0; i < 3; i++ {
|
||||||
txs := getMempool(t, h)
|
txs := getMempool(t, h)
|
||||||
@@ -334,6 +343,10 @@ func testGetBestBlockHash(t *testing.T, h *TestHandler) {
|
|||||||
}
|
}
|
||||||
hh, err := h.Chain.GetBlockHash(height)
|
hh, err := h.Chain.GetBlockHash(height)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if err == bchain.ErrBlockNotFound {
|
||||||
|
time.Sleep(time.Millisecond * 100)
|
||||||
|
continue
|
||||||
|
}
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if hash != hh {
|
if hash != hh {
|
||||||
|
|||||||
14
tests/rpc/testdata/bitcoin_testnet4.json
vendored
14
tests/rpc/testdata/bitcoin_testnet4.json
vendored
@@ -43,13 +43,13 @@
|
|||||||
"hex": "0014de4e79ce2048a42698e04e079e94c97fd6e012cf"
|
"hex": "0014de4e79ce2048a42698e04e079e94c97fd6e012cf"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"value": 0.00948127,
|
"value": 0.00948127,
|
||||||
"n": 1,
|
"n": 1,
|
||||||
"scriptPubKey": {
|
"scriptPubKey": {
|
||||||
"hex": "a914c9e67d2b78a38857c786ea9a2fc3e64cb6e7756487"
|
"hex": "a914d9e303986df109b001b97b45f3a00d84b6c9d72787"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"value": 0.00161416,
|
"value": 0.00161416,
|
||||||
"n": 2,
|
"n": 2,
|
||||||
|
|||||||
9
tests/sync/testdata/bitcoin_testnet4.json
vendored
9
tests/sync/testdata/bitcoin_testnet4.json
vendored
@@ -39,6 +39,13 @@
|
|||||||
"scriptPubKey": {
|
"scriptPubKey": {
|
||||||
"hex": "00144237fc8335d817b911332fc9df26744215266b17"
|
"hex": "00144237fc8335d817b911332fc9df26744215266b17"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"value": 0.00316052,
|
||||||
|
"n": 2,
|
||||||
|
"scriptPubKey": {
|
||||||
|
"hex": "a914e5bd951e8d6b10fab8cea5b103c71ae3a37b95bf87"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -91,7 +98,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"value": 0.00168669,
|
"value": 0.00168669,
|
||||||
"n": 1,
|
"n": 2,
|
||||||
"scriptPubKey": {
|
"scriptPubKey": {
|
||||||
"hex": "a914fa793409354d909ceaf168b7b7f91a92e0b4ba8587"
|
"hex": "a914fa793409354d909ceaf168b7b7f91a92e0b4ba8587"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user