problem: sporadic unit-test failure
This commit is contained in:
@@ -209,11 +209,11 @@ class TrackEthereumTx(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateFromBlock(upstream: Upstream<EthereumApi>, tx: TxDetails, it: TransactionJson): Mono<TxDetails> {
|
fun updateFromBlock(upstream: Upstream<EthereumApi>, tx: TxDetails, blockTx: TransactionJson): Mono<TxDetails> {
|
||||||
return if (it.blockNumber != null && it.blockHash != null && it.blockHash != ZERO_BLOCK) {
|
return if (blockTx.blockNumber != null && blockTx.blockHash != null && blockTx.blockHash != ZERO_BLOCK) {
|
||||||
val updated = tx.withStatus(
|
val updated = tx.withStatus(
|
||||||
blockHash = it.blockHash,
|
blockHash = blockTx.blockHash,
|
||||||
height = it.blockNumber,
|
height = blockTx.blockNumber,
|
||||||
found = true,
|
found = true,
|
||||||
mined = true,
|
mined = true,
|
||||||
confirmations = 1
|
confirmations = 1
|
||||||
|
|||||||
@@ -303,30 +303,23 @@ class TrackEthereumTxSpec extends Specification {
|
|||||||
apiMock.answer("eth_getBlockByHash", [block.hash.toHex(), false], block)
|
apiMock.answer("eth_getBlockByHash", [block.hash.toHex(), false], block)
|
||||||
}
|
}
|
||||||
|
|
||||||
def nextBlock = { int i ->
|
upstreamMock.blocks = Flux.fromIterable(blocks)
|
||||||
return {
|
.map { block ->
|
||||||
println("block $i");
|
BlockContainer.from(block, TestingCommons.objectMapper())
|
||||||
upstreamMock.nextBlock(BlockContainer.from(blocks[i], TestingCommons.objectMapper()))
|
}
|
||||||
} as Runnable
|
|
||||||
}
|
|
||||||
|
|
||||||
when:
|
when:
|
||||||
def flux = trackTx.subscribe(req)
|
def flux = trackTx.subscribe(req)
|
||||||
then:
|
then:
|
||||||
StepVerifier.create(flux)
|
StepVerifier.create(flux)
|
||||||
.expectNext(exp1.build()).as("Just empty")
|
.expectNext(exp1.build()).as("Just empty")
|
||||||
.then(nextBlock(1))
|
|
||||||
.expectNext(exp1.setBroadcasted(true).build()).as("Found in mempool")
|
.expectNext(exp1.setBroadcasted(true).build()).as("Found in mempool")
|
||||||
.then(nextBlock(2))
|
|
||||||
.expectNext(exp2.setConfirmations(1).build()).as("Mined")
|
.expectNext(exp2.setConfirmations(1).build()).as("Mined")
|
||||||
.then(nextBlock(3))
|
.expectNext(exp2.setConfirmations(2).build()).as("Confirmed 2")
|
||||||
.expectNext(exp2.setConfirmations(2).build())
|
.expectNext(exp2.setConfirmations(3).build()).as("Confirmed 3")
|
||||||
.then(nextBlock(4))
|
.expectNext(exp2.setConfirmations(4).build()).as("Confirmed 4")
|
||||||
.expectNext(exp2.setConfirmations(3).build())
|
|
||||||
.then(nextBlock(5))
|
|
||||||
.expectNext(exp2.setConfirmations(4).build())
|
|
||||||
.expectComplete()
|
.expectComplete()
|
||||||
.verify(Duration.ofSeconds(4))
|
.verify(Duration.ofSeconds(1))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ package io.emeraldpay.dshackle.test
|
|||||||
|
|
||||||
import io.emeraldpay.dshackle.data.BlockContainer
|
import io.emeraldpay.dshackle.data.BlockContainer
|
||||||
import io.emeraldpay.dshackle.upstream.Head
|
import io.emeraldpay.dshackle.upstream.Head
|
||||||
|
import org.reactivestreams.Publisher
|
||||||
import reactor.core.publisher.Flux
|
import reactor.core.publisher.Flux
|
||||||
import reactor.core.publisher.Mono
|
import reactor.core.publisher.Mono
|
||||||
import reactor.core.publisher.TopicProcessor
|
import reactor.core.publisher.TopicProcessor
|
||||||
@@ -25,6 +26,7 @@ import reactor.core.publisher.TopicProcessor
|
|||||||
class EthereumHeadMock implements Head {
|
class EthereumHeadMock implements Head {
|
||||||
|
|
||||||
private TopicProcessor<BlockContainer> bus = TopicProcessor.create()
|
private TopicProcessor<BlockContainer> bus = TopicProcessor.create()
|
||||||
|
private Publisher<BlockContainer> predefined = null
|
||||||
private BlockContainer latest
|
private BlockContainer latest
|
||||||
|
|
||||||
void nextBlock(BlockContainer block) {
|
void nextBlock(BlockContainer block) {
|
||||||
@@ -33,8 +35,20 @@ class EthereumHeadMock implements Head {
|
|||||||
bus.onNext(block)
|
bus.onNext(block)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setPredefined(Publisher<BlockContainer> predefined) {
|
||||||
|
this.predefined = Flux.from(predefined)
|
||||||
|
.publish()
|
||||||
|
.refCount(1)
|
||||||
|
.doOnNext { latest = it }
|
||||||
|
// keep the current block as latest, because getFlux is also used to get the current height
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
Flux<BlockContainer> getFlux() {
|
Flux<BlockContainer> getFlux() {
|
||||||
return Flux.concat(Mono.justOrEmpty(latest), bus).distinctUntilChanged()
|
if (predefined != null) {
|
||||||
|
return Flux.concat(Mono.justOrEmpty(latest), Flux.from(predefined))
|
||||||
|
} else {
|
||||||
|
return Flux.concat(Mono.justOrEmpty(latest), bus).distinctUntilChanged()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import io.emeraldpay.grpc.Chain
|
|||||||
import io.infinitape.etherjar.domain.TransactionId
|
import io.infinitape.etherjar.domain.TransactionId
|
||||||
import io.infinitape.etherjar.rpc.json.BlockJson
|
import io.infinitape.etherjar.rpc.json.BlockJson
|
||||||
import org.jetbrains.annotations.NotNull
|
import org.jetbrains.annotations.NotNull
|
||||||
|
import org.reactivestreams.Publisher
|
||||||
|
|
||||||
class EthereumUpstreamMock extends EthereumUpstream {
|
class EthereumUpstreamMock extends EthereumUpstream {
|
||||||
|
|
||||||
@@ -58,6 +59,10 @@ class EthereumUpstreamMock extends EthereumUpstream {
|
|||||||
ethereumHeadMock.nextBlock(block)
|
ethereumHeadMock.nextBlock(block)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setBlocks(Publisher<BlockContainer> blocks) {
|
||||||
|
ethereumHeadMock.predefined = blocks
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
Head createHead() {
|
Head createHead() {
|
||||||
return ethereumHeadMock
|
return ethereumHeadMock
|
||||||
|
|||||||
Reference in New Issue
Block a user