diff --git a/bchain/coins/btc/bitcoinrpc.go b/bchain/coins/btc/bitcoinrpc.go index f6daead2..4fee32d3 100644 --- a/bchain/coins/btc/bitcoinrpc.go +++ b/bchain/coins/btc/bitcoinrpc.go @@ -512,7 +512,8 @@ func (b *BitcoinRPC) GetChainInfo() (*bchain.ChainInfo, error) { // IsErrBlockNotFound returns true if error means block was not found func IsErrBlockNotFound(err *bchain.RPCError) bool { 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. diff --git a/tests/rpc/rpc.go b/tests/rpc/rpc.go index b0745988..de094787 100644 --- a/tests/rpc/rpc.go +++ b/tests/rpc/rpc.go @@ -204,6 +204,8 @@ func testGetTransactionForMempool(t *testing.T, h *TestHandler) { for txid, want := range h.TestData.TxDetails { // reset fields that are not parsed by BlockChainParser 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) if err != nil { @@ -215,6 +217,7 @@ func testGetTransactionForMempool(t *testing.T, h *TestHandler) { // transactions parsed from JSON may contain additional data got.Confirmations, got.Blocktime, got.Time, got.CoinSpecificData = 0, 0, 0, nil + stripWitness(got) if !reflect.DeepEqual(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) { for i := 0; i < 3; i++ { txs := getMempool(t, h) @@ -334,6 +343,10 @@ func testGetBestBlockHash(t *testing.T, h *TestHandler) { } hh, err := h.Chain.GetBlockHash(height) if err != nil { + if err == bchain.ErrBlockNotFound { + time.Sleep(time.Millisecond * 100) + continue + } t.Fatal(err) } if hash != hh { diff --git a/tests/rpc/testdata/bitcoin_testnet4.json b/tests/rpc/testdata/bitcoin_testnet4.json index e61c5d87..fc1a424d 100644 --- a/tests/rpc/testdata/bitcoin_testnet4.json +++ b/tests/rpc/testdata/bitcoin_testnet4.json @@ -43,13 +43,13 @@ "hex": "0014de4e79ce2048a42698e04e079e94c97fd6e012cf" } }, - { - "value": 0.00948127, - "n": 1, - "scriptPubKey": { - "hex": "a914c9e67d2b78a38857c786ea9a2fc3e64cb6e7756487" - } - }, + { + "value": 0.00948127, + "n": 1, + "scriptPubKey": { + "hex": "a914d9e303986df109b001b97b45f3a00d84b6c9d72787" + } + }, { "value": 0.00161416, "n": 2, diff --git a/tests/sync/testdata/bitcoin_testnet4.json b/tests/sync/testdata/bitcoin_testnet4.json index 5bd3c8e2..80e21f28 100644 --- a/tests/sync/testdata/bitcoin_testnet4.json +++ b/tests/sync/testdata/bitcoin_testnet4.json @@ -39,6 +39,13 @@ "scriptPubKey": { "hex": "00144237fc8335d817b911332fc9df26744215266b17" } + }, + { + "value": 0.00316052, + "n": 2, + "scriptPubKey": { + "hex": "a914e5bd951e8d6b10fab8cea5b103c71ae3a37b95bf87" + } } ] }, @@ -91,7 +98,7 @@ }, { "value": 0.00168669, - "n": 1, + "n": 2, "scriptPubKey": { "hex": "a914fa793409354d909ceaf168b7b7f91a92e0b4ba8587" }