problem: fails to respond when requested block doesn't exist
This commit is contained in:
@@ -114,9 +114,13 @@ class EthereumDirectReader(
|
|||||||
return readWithQuorum(request)
|
return readWithQuorum(request)
|
||||||
.timeout(Defaults.timeoutInternal, Mono.error(TimeoutException("Block not read $id")))
|
.timeout(Defaults.timeoutInternal, Mono.error(TimeoutException("Block not read $id")))
|
||||||
.retryWhen(Retry.backoff(3, Duration.ofSeconds(1)))
|
.retryWhen(Retry.backoff(3, Duration.ofSeconds(1)))
|
||||||
.map { blockbytes ->
|
.flatMap { blockbytes ->
|
||||||
val block = objectMapper.readValue(blockbytes, BlockJson::class.java) as BlockJson<TransactionRefJson>
|
val block = objectMapper.readValue(blockbytes, BlockJson::class.java) as BlockJson<TransactionRefJson>?
|
||||||
BlockContainer.from(block, blockbytes)
|
if (block == null) {
|
||||||
|
Mono.empty<BlockContainer>()
|
||||||
|
} else {
|
||||||
|
Mono.just(BlockContainer.from(block, blockbytes))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.doOnNext { block ->
|
.doOnNext { block ->
|
||||||
caches.cache(Caches.Tag.REQUESTED, block)
|
caches.cache(Caches.Tag.REQUESTED, block)
|
||||||
|
|||||||
@@ -69,6 +69,34 @@ class EthereumDirectReaderSpec extends Specification {
|
|||||||
.verify(Duration.ofSeconds(1))
|
.verify(Duration.ofSeconds(1))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def "Produce empty result on non-existing block"() {
|
||||||
|
setup:
|
||||||
|
def up = Mock(Multistream) {
|
||||||
|
1 * getApiSource(_) >> Stub(ApiSource)
|
||||||
|
}
|
||||||
|
def calls = Mock(Factory) {
|
||||||
|
1 * create() >> new DefaultEthereumMethods(Chain.ETHEREUM)
|
||||||
|
}
|
||||||
|
EthereumDirectReader reader = new EthereumDirectReader(
|
||||||
|
up, Caches.default(), new CurrentBlockCache(), calls
|
||||||
|
)
|
||||||
|
reader.quorumReaderFactory = Mock(QuorumReaderFactory) {
|
||||||
|
1 * create(_, _) >> Mock(Reader) {
|
||||||
|
1 * read(new JsonRpcRequest("eth_getBlockByHash", [hash1, false])) >> Mono.just(
|
||||||
|
new QuorumRpcReader.Result(
|
||||||
|
Global.objectMapper.writeValueAsBytes(null), 1
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
when:
|
||||||
|
def act = reader.blockReader.read(BlockHash.from(hash1))
|
||||||
|
then:
|
||||||
|
StepVerifier.create(act)
|
||||||
|
.expectComplete()
|
||||||
|
.verify(Duration.ofSeconds(1))
|
||||||
|
}
|
||||||
|
|
||||||
def "Reads block by height"() {
|
def "Reads block by height"() {
|
||||||
setup:
|
setup:
|
||||||
def json = new BlockJson().tap {
|
def json = new BlockJson().tap {
|
||||||
@@ -143,6 +171,34 @@ class EthereumDirectReaderSpec extends Specification {
|
|||||||
.verify(Duration.ofSeconds(1))
|
.verify(Duration.ofSeconds(1))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def "Produce empty on non-existing tx"() {
|
||||||
|
setup:
|
||||||
|
def up = Mock(Multistream) {
|
||||||
|
1 * getApiSource(_) >> Stub(ApiSource)
|
||||||
|
}
|
||||||
|
def calls = Mock(Factory) {
|
||||||
|
1 * create() >> new DefaultEthereumMethods(Chain.ETHEREUM)
|
||||||
|
}
|
||||||
|
EthereumDirectReader reader = new EthereumDirectReader(
|
||||||
|
up, Caches.default(), new CurrentBlockCache(), calls
|
||||||
|
)
|
||||||
|
reader.quorumReaderFactory = Mock(QuorumReaderFactory) {
|
||||||
|
1 * create(_, _) >> Mock(Reader) {
|
||||||
|
1 * read(new JsonRpcRequest("eth_getTransactionByHash", [hash1])) >> Mono.just(
|
||||||
|
new QuorumRpcReader.Result(
|
||||||
|
Global.objectMapper.writeValueAsBytes(null), 1
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
when:
|
||||||
|
def act = reader.txReader.read(TransactionId.from(hash1))
|
||||||
|
then:
|
||||||
|
StepVerifier.create(act)
|
||||||
|
.expectComplete()
|
||||||
|
.verify(Duration.ofSeconds(1))
|
||||||
|
}
|
||||||
|
|
||||||
def "Reads balance - height is unknown"() {
|
def "Reads balance - height is unknown"() {
|
||||||
setup:
|
setup:
|
||||||
def up = Mock(Multistream) {
|
def up = Mock(Multistream) {
|
||||||
|
|||||||
@@ -31,6 +31,33 @@ class StandardCallsSpec extends Specification {
|
|||||||
act.error == null
|
act.error == null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def "get non-existing block"() {
|
||||||
|
when:
|
||||||
|
def act = client.execute("eth_getBlockByNumber", ["0x200001", false])
|
||||||
|
then:
|
||||||
|
act.result == null
|
||||||
|
act.error == null
|
||||||
|
}
|
||||||
|
|
||||||
|
def "get tx"() {
|
||||||
|
when:
|
||||||
|
def act = client.execute("eth_getTransactionByHash", ["0x01c5a8461d06c2c195035c148af0f871c7679841d86ae5bb98676bb2d8e68dfa"])
|
||||||
|
then:
|
||||||
|
act.result != null
|
||||||
|
with(act.result) {
|
||||||
|
blockHash == "0x9a834c53bbee9c2665a5a84789a1d1ad73750b2d77b50de44f457f411d02e52e"
|
||||||
|
}
|
||||||
|
act.error == null
|
||||||
|
}
|
||||||
|
|
||||||
|
def "get non-existing tx"() {
|
||||||
|
when:
|
||||||
|
def act = client.execute("eth_getTransactionByHash", ["0x000000461d06c2c195035c148af0f871c7679841d86ae5bb98676bb2d8e68dfa"])
|
||||||
|
then:
|
||||||
|
act.result == null
|
||||||
|
act.error == null
|
||||||
|
}
|
||||||
|
|
||||||
def "get block with txes"() {
|
def "get block with txes"() {
|
||||||
when:
|
when:
|
||||||
def act = client.execute("eth_getBlockByNumber", ["0x100001", true])
|
def act = client.execute("eth_getBlockByNumber", ["0x100001", true])
|
||||||
|
|||||||
Reference in New Issue
Block a user