mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-03-26 21:42:48 +01:00
Add unit test to make sure DataMessageHandler exception doesn't stop node (#2536)
This commit is contained in:
parent
e44a620ea1
commit
7e942ba66d
1 changed files with 25 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
|||
package org.bitcoins.node.networking.peer
|
||||
|
||||
import org.bitcoins.core.config.SigNet
|
||||
import org.bitcoins.core.currency._
|
||||
import org.bitcoins.core.gcs.{FilterType, GolombFilter}
|
||||
import org.bitcoins.core.p2p._
|
||||
|
@ -27,6 +28,30 @@ class DataMessageHandlerTest extends NodeUnitTest {
|
|||
override def withFixture(test: OneArgAsyncTest): FutureOutcome =
|
||||
withSpvNodeConnectedToBitcoindV19(test)
|
||||
|
||||
it must "catch errors and not fail when processing an invalid payload" in {
|
||||
param: SpvNodeConnectedWithBitcoindV19 =>
|
||||
val SpvNodeConnectedWithBitcoindV19(spv, _) = param
|
||||
|
||||
for {
|
||||
sender <- spv.peerMsgSenderF
|
||||
chainApi <- spv.chainApiFromDb()
|
||||
dataMessageHandler = DataMessageHandler(chainApi)(spv.executionContext,
|
||||
spv.nodeAppConfig,
|
||||
spv.chainConfig)
|
||||
|
||||
// Use signet genesis block header, this should be invalid for regtest
|
||||
invalidPayload =
|
||||
HeadersMessage(Vector(SigNet.chainParams.genesisBlock.blockHeader))
|
||||
|
||||
// Validate that it causes a failure
|
||||
_ <- recoverToSucceededIf[RuntimeException](
|
||||
chainApi.processHeaders(invalidPayload.headers))
|
||||
|
||||
// Verify we handle the payload correctly
|
||||
_ <- dataMessageHandler.handleDataPayload(invalidPayload, sender)
|
||||
} yield succeed
|
||||
}
|
||||
|
||||
it must "verify OnMerkleBlock callbacks are executed" in {
|
||||
param: FixtureParam =>
|
||||
val SpvNodeConnectedWithBitcoindV19(spv, bitcoind) = param
|
||||
|
|
Loading…
Add table
Reference in a new issue