Add BroadcastReader instead of BroadcastQuorum (#263)

This commit is contained in:
KirillPamPam
2023-08-01 17:26:31 +04:00
committed by GitHub
parent 6f576fc20c
commit 674c69f4d3
12 changed files with 497 additions and 207 deletions

View File

@@ -39,6 +39,7 @@ class QuorumRpcReaderSpec extends Specification {
setup:
def up = Mock(Upstream) {
_ * isAvailable() >> true
_ * getId() >> "id"
_ * getRole() >> UpstreamsConfig.UpstreamRole.PRIMARY
1 * getIngressReader() >> Mock(Reader) {
1 * read(new JsonRpcRequest("eth_test", [])) >> Mono.just(JsonRpcResponse.ok("1"))
@@ -72,6 +73,7 @@ class QuorumRpcReaderSpec extends Specification {
}
def up = Mock(Upstream) {
_ * isAvailable() >> true
_ * getId() >> "id"
_ * getRole() >> UpstreamsConfig.UpstreamRole.PRIMARY
_ * getIngressReader() >> api
}
@@ -109,6 +111,7 @@ class QuorumRpcReaderSpec extends Specification {
}
def up = Mock(Upstream) {
_ * isAvailable() >> true
_ * getId() >> "id"
_ * getRole() >> UpstreamsConfig.UpstreamRole.PRIMARY
_ * getIngressReader() >> api
}
@@ -136,6 +139,7 @@ class QuorumRpcReaderSpec extends Specification {
setup:
def up = Mock(Upstream) {
_ * isAvailable() >> true
_ * getId() >> "id"
_ * getRole() >> UpstreamsConfig.UpstreamRole.PRIMARY
_ * getIngressReader() >> Mock(Reader) {
2 * read(new JsonRpcRequest("eth_test", [])) >>> [
@@ -168,6 +172,7 @@ class QuorumRpcReaderSpec extends Specification {
setup:
def up = Mock(Upstream) {
_ * isAvailable() >> true
_ * getId() >> "id"
_ * getRole() >> UpstreamsConfig.UpstreamRole.PRIMARY
_ * getIngressReader() >> Mock(Reader) {
2 * read(new JsonRpcRequest("eth_test", [])) >>> [
@@ -236,6 +241,7 @@ class QuorumRpcReaderSpec extends Specification {
}
def up = Mock(Upstream) {
_ * isAvailable() >> true
_ * getId() >> "id"
_ * getRole() >> UpstreamsConfig.UpstreamRole.PRIMARY
_ * getIngressReader() >> api
}
@@ -264,6 +270,7 @@ class QuorumRpcReaderSpec extends Specification {
setup:
def up = Mock(Upstream) {
_ * getLag() >> 0
_ * getId() >> "id"
_ * isAvailable() >> true
_ * getRole() >> UpstreamsConfig.UpstreamRole.PRIMARY
_ * getIngressReader() >> Mock(Reader) {

View File

@@ -0,0 +1,192 @@
package io.emeraldpay.dshackle.reader
import io.emeraldpay.dshackle.upstream.Selector
import io.emeraldpay.dshackle.upstream.Upstream
import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcException
import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest
import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse
import org.springframework.cloud.sleuth.Tracer
import reactor.core.publisher.Mono
import reactor.test.StepVerifier
import spock.lang.Specification
import java.time.Duration
class BroadcastReaderSpec extends Specification {
def "Return responses from all upstreams"() {
setup:
def result = "123".getBytes()
def up = Mock(Upstream) {
1 * isAvailable() >> true
_ * getId() >> "id"
1 * getIngressReader() >> Mock(Reader) {
1 * read(new JsonRpcRequest("eth_sendRawTransaction", ["0x1"])) >>
Mono.just(new JsonRpcResponse(result, null))
}
}
def up1 = Mock(Upstream) {
1 * isAvailable() >> true
_ * getId() >> "id"
1 * getIngressReader() >> Mock(Reader) {
1 * read(new JsonRpcRequest("eth_sendRawTransaction", ["0x1"])) >>
Mono.just(new JsonRpcResponse(result, null))
}
}
def up2 = Mock(Upstream) {
1 * isAvailable() >> true
_ * getId() >> "id"
1 * getIngressReader() >> Mock(Reader) {
1 * read(new JsonRpcRequest("eth_sendRawTransaction", ["0x1"])) >>
Mono.just(new JsonRpcResponse(result, null))
}
}
def reader = new BroadcastReader([up, up1, up2], new Selector.EmptyMatcher(), null, Stub(Tracer))
when:
def act = reader.read(new JsonRpcRequest("eth_sendRawTransaction", ["0x1"]))
then:
StepVerifier.create(act)
.expectNextMatches {
it.value == result
}
.expectComplete()
.verify(Duration.ofSeconds(3))
}
def "Return response if at least one upstream responds"() {
setup:
def result = "123".getBytes()
def up = Mock(Upstream) {
1 * isAvailable() >> true
_ * getId() >> "id"
1 * getIngressReader() >> Mock(Reader) {
1 * read(new JsonRpcRequest("eth_sendRawTransaction", ["0x1"])) >>
Mono.just(new JsonRpcResponse(result, null))
}
}
def up1 = Mock(Upstream) {
1 * isAvailable() >> true
_ * getId() >> "id"
1 * getIngressReader() >> Mock(Reader) {
1 * read(new JsonRpcRequest("eth_sendRawTransaction", ["0x1"])) >>
Mono.error(new JsonRpcException(1, "too low"))
}
}
def up2 = Mock(Upstream) {
1 * isAvailable() >> true
_ * getId() >> "id"
1 * getIngressReader() >> Mock(Reader) {
1 * read(new JsonRpcRequest("eth_sendRawTransaction", ["0x1"])) >>
Mono.error(new JsonRpcException(1, "too low")) }
}
def reader = new BroadcastReader([up, up1, up2], new Selector.EmptyMatcher(), null, Stub(Tracer))
when:
def act = reader.read(new JsonRpcRequest("eth_sendRawTransaction", ["0x1"]))
then:
StepVerifier.create(act)
.expectNextMatches {
it.value == result
}
.expectComplete()
.verify(Duration.ofSeconds(3))
}
def "Return response from matched upstream"() {
setup:
def result = "123".getBytes()
def up = Mock(Upstream) {
1 * isAvailable() >> true
_ * getId() >> "id"
1 * getIngressReader() >> Mock(Reader) {
1 * read(new JsonRpcRequest("eth_sendRawTransaction", ["0x1"])) >>
Mono.just(new JsonRpcResponse(result, null))
}
}
def up1 = Mock(Upstream) {
1 * isAvailable() >> false
0 * getId() >> "id"
0 * getIngressReader() >> Mock(Reader)
}
def up2 = Mock(Upstream) {
1 * isAvailable() >> false
0 * getId() >> "id"
0 * getIngressReader() >> Mock(Reader)
}
def reader = new BroadcastReader([up, up1, up2], new Selector.EmptyMatcher(), null, Stub(Tracer))
when:
def act = reader.read(new JsonRpcRequest("eth_sendRawTransaction", ["0x1"]))
then:
StepVerifier.create(act)
.expectNextMatches {
it.value == result
}
.expectComplete()
.verify(Duration.ofSeconds(3))
}
def "Return error if all upstreams return error"() {
setup:
def up = Mock(Upstream) {
1 * isAvailable() >> true
_ * getId() >> "id"
1 * getIngressReader() >> Mock(Reader) {
1 * read(new JsonRpcRequest("eth_sendRawTransaction", ["0x1"])) >>
Mono.error(new JsonRpcException(1, "too low"))
}
}
def up1 = Mock(Upstream) {
1 * isAvailable() >> true
_ * getId() >> "id"
1 * getIngressReader() >> Mock(Reader) {
1 * read(new JsonRpcRequest("eth_sendRawTransaction", ["0x1"])) >>
Mono.error(new JsonRpcException(1, "too low"))
}
}
def up2 = Mock(Upstream) {
1 * isAvailable() >> true
_ * getId() >> "id"
1 * getIngressReader() >> Mock(Reader) {
1 * read(new JsonRpcRequest("eth_sendRawTransaction", ["0x1"])) >>
Mono.error(new JsonRpcException(1, "too low"))
}
}
def reader = new BroadcastReader([up, up1, up2], new Selector.EmptyMatcher(), null, Stub(Tracer))
when:
def act = reader.read(new JsonRpcRequest("eth_sendRawTransaction", ["0x1"]))
then:
StepVerifier.create(act)
.expectError(JsonRpcException.class)
.verify(Duration.ofSeconds(3))
}
def "No response if no available upstreams"() {
setup:
def up = Mock(Upstream) {
1 * isAvailable() >> false
0 * getId() >> "id"
0 * getIngressReader() >> Mock(Reader)
}
def up1 = Mock(Upstream) {
1 * isAvailable() >> false
0 * getId() >> "id"
0 * getIngressReader() >> Mock(Reader)
}
def up2 = Mock(Upstream) {
1 * isAvailable() >> false
0 * getId() >> "id"
0 * getIngressReader() >> Mock(Reader)
}
def reader = new BroadcastReader([up, up1, up2], new Selector.EmptyMatcher(), null, Stub(Tracer))
when:
def act = reader
.read(new JsonRpcRequest("eth_sendRawTransaction", ["0x1"]))
.switchIfEmpty(Mono.just(new RpcReader.Result(new byte[0], null, 0, null)))
then:
StepVerifier.create(act)
.expectNextMatches {
it.value == new byte[0]
}
.expectComplete()
.verify(Duration.ofSeconds(3))
}
}

View File

@@ -25,17 +25,12 @@ import io.emeraldpay.dshackle.Global
import io.emeraldpay.dshackle.config.CacheConfig
import io.emeraldpay.dshackle.config.MainConfig
import io.emeraldpay.dshackle.quorum.AlwaysQuorum
import io.emeraldpay.dshackle.quorum.QuorumReader
import io.emeraldpay.dshackle.quorum.QuorumReaderFactory
import io.emeraldpay.dshackle.quorum.QuorumRpcReader
import io.emeraldpay.dshackle.reader.Reader
import io.emeraldpay.dshackle.reader.RpcReader
import io.emeraldpay.dshackle.reader.RpcReaderFactory
import io.emeraldpay.dshackle.test.MultistreamHolderMock
import io.emeraldpay.dshackle.test.TestingCommons
import io.emeraldpay.dshackle.upstream.Head
import io.emeraldpay.dshackle.upstream.Multistream
import io.emeraldpay.dshackle.upstream.MultistreamHolder
import io.emeraldpay.dshackle.upstream.Selector
import io.emeraldpay.dshackle.upstream.Upstream
import io.emeraldpay.dshackle.upstream.*
import io.emeraldpay.dshackle.upstream.calls.DefaultEthereumMethods
import io.emeraldpay.dshackle.upstream.calls.ManagedCallMethods
import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcError
@@ -132,9 +127,9 @@ class NativeCallSpec extends Specification {
}
def nativeCall = nativeCall()
nativeCall.quorumReaderFactory = Mock(QuorumReaderFactory) {
1 * create(_, _, _, _) >> Mock(QuorumReader) {
1 * read(_) >> Mono.just(new QuorumRpcReader.Result("\"foo\"".bytes, null, 1, ups))
nativeCall.rpcReaderFactory = Mock(RpcReaderFactory) {
1 * create(_) >> Mock(RpcReader) {
1 * read(_) >> Mono.just(new RpcReader.Result("\"foo\"".bytes, null, 1, ups))
}
}
def call = new NativeCall.ValidCallContext(1, 10, TestingCommons.multistream(TestingCommons.api()), Selector.empty, quorum,
@@ -153,8 +148,8 @@ class NativeCallSpec extends Specification {
def quorum = new AlwaysQuorum()
def nativeCall = nativeCall()
nativeCall.quorumReaderFactory = Mock(QuorumReaderFactory) {
1 * create(_, _, _, _) >> Mock(QuorumReader) {
nativeCall.rpcReaderFactory = Mock(RpcReaderFactory) {
1 * create(_) >> Mock(RpcReader) {
1 * attempts() >> new AtomicInteger(1)
1 * read(new JsonRpcRequest("eth_test", [], 10)) >> Mono.empty()
}
@@ -178,8 +173,8 @@ class NativeCallSpec extends Specification {
def quorum = new AlwaysQuorum()
def nativeCall = nativeCall()
nativeCall.quorumReaderFactory = Mock(QuorumReaderFactory) {
1 * create(_, _, _, _) >> Mock(QuorumReader) {
nativeCall.rpcReaderFactory = Mock(RpcReaderFactory) {
1 * create(_) >> Mock(RpcReader) {
1 * read(new JsonRpcRequest("eth_test", [], 10)) >> Mono.error(
new JsonRpcException(JsonRpcResponse.Id.from(12), new JsonRpcError(-32123, "Foo Bar", "Foo Bar Baz"), null, true)
)
@@ -615,9 +610,9 @@ class NativeCallSpec extends Specification {
_ * it.observeChains() >> Flux.empty()
}
def nativeCall = nativeCall(multistreamHolder)
nativeCall.quorumReaderFactory = Mock(QuorumReaderFactory) {
1 * create(_, _, _, _) >> Mock(QuorumReader) {
1 * read(_) >> Mono.just(new QuorumRpcReader.Result("\"0xab\"".bytes, null, 1, ups))
nativeCall.rpcReaderFactory = Mock(RpcReaderFactory) {
1 * create(_) >> Mock(RpcReader) {
1 * read(_) >> Mono.just(new RpcReader.Result("\"0xab\"".bytes, null, 1, ups))
}
}
def call = new NativeCall.ValidCallContext(1, 10, multistream, Selector.empty, quorum,
@@ -650,9 +645,9 @@ class NativeCallSpec extends Specification {
_ * it.observeChains() >> Flux.empty()
}
def nativeCall = nativeCall(multistreamHolder)
nativeCall.quorumReaderFactory = Mock(QuorumReaderFactory) {
1 * create(_, _, _, _) >> Mock(QuorumReader) {
1 * read(_) >> Mono.just(new QuorumRpcReader.Result("\"0xab\"".bytes, null, 1, ups))
nativeCall.rpcReaderFactory = Mock(RpcReaderFactory) {
1 * create(_) >> Mock(RpcReader) {
1 * read(_) >> Mono.just(new RpcReader.Result("\"0xab\"".bytes, null, 1, ups))
}
}
def call = new NativeCall.ValidCallContext(1, 10, multistream, Selector.empty, quorum,

View File

@@ -5,22 +5,17 @@ import io.emeraldpay.dshackle.Global
import io.emeraldpay.dshackle.cache.Caches
import io.emeraldpay.dshackle.cache.CurrentBlockCache
import io.emeraldpay.dshackle.data.DefaultContainer
import io.emeraldpay.dshackle.quorum.QuorumReader
import io.emeraldpay.dshackle.quorum.QuorumReaderFactory
import io.emeraldpay.dshackle.quorum.QuorumRpcReader
import io.emeraldpay.dshackle.reader.RpcReader
import io.emeraldpay.dshackle.reader.RpcReaderFactory
import io.emeraldpay.dshackle.test.TestingCommons
import io.emeraldpay.dshackle.upstream.ApiSource
import io.emeraldpay.dshackle.upstream.Head
import io.emeraldpay.dshackle.upstream.Multistream
import io.emeraldpay.dshackle.upstream.Selector
import io.emeraldpay.dshackle.upstream.Upstream
import io.emeraldpay.dshackle.upstream.*
import io.emeraldpay.dshackle.upstream.calls.DefaultEthereumMethods
import io.emeraldpay.dshackle.upstream.ethereum.json.BlockJson
import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest
import io.emeraldpay.etherjar.domain.Address
import io.emeraldpay.etherjar.domain.BlockHash
import io.emeraldpay.etherjar.domain.TransactionId
import io.emeraldpay.etherjar.domain.Wei
import io.emeraldpay.dshackle.upstream.ethereum.json.BlockJson
import io.emeraldpay.etherjar.rpc.json.TransactionJson
import io.emeraldpay.etherjar.rpc.json.TransactionReceiptJson
import org.apache.commons.collections4.Factory
@@ -47,19 +42,16 @@ class EthereumDirectReaderSpec extends Specification {
parentHash = BlockHash.from(hash1)
transactions = []
}
def up = Mock(Multistream) {
1 * getApiSource(_) >> Stub(ApiSource)
}
def calls = Mock(Factory) {
1 * create() >> new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET)
}
EthereumDirectReader reader = new EthereumDirectReader(
up, Caches.default(), new CurrentBlockCache(), calls, TestingCommons.tracerMock()
Stub(Multistream), Caches.default(), new CurrentBlockCache(), calls, TestingCommons.tracerMock()
)
reader.quorumReaderFactory = Mock(QuorumReaderFactory) {
1 * create(_, _, _, _,) >> Mock(QuorumReader) {
reader.rpcReaderFactory = Mock(RpcReaderFactory) {
1 * create(_) >> Mock(RpcReader) {
1 * read(new JsonRpcRequest("eth_getBlockByHash", [hash1, false])) >> Mono.just(
new QuorumRpcReader.Result(
new RpcReader.Result(
Global.objectMapper.writeValueAsBytes(json), null, 1, resolver)
)
}
@@ -77,19 +69,16 @@ class EthereumDirectReaderSpec extends Specification {
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__MAINNET)
}
EthereumDirectReader reader = new EthereumDirectReader(
up, Caches.default(), new CurrentBlockCache(), calls, TestingCommons.tracerMock()
Stub(Multistream), Caches.default(), new CurrentBlockCache(), calls, TestingCommons.tracerMock()
)
reader.quorumReaderFactory = Mock(QuorumReaderFactory) {
1 * create(_, _, _, _) >> Mock(QuorumReader) {
reader.rpcReaderFactory = Mock(RpcReaderFactory) {
1 * create(_) >> Mock(RpcReader) {
1 * read(new JsonRpcRequest("eth_getBlockByHash", [hash1, false])) >> Mono.just(
new QuorumRpcReader.Result(
new RpcReader.Result(
Global.objectMapper.writeValueAsBytes(null), null, 1, resolver
)
)
@@ -113,21 +102,16 @@ class EthereumDirectReaderSpec extends Specification {
parentHash = BlockHash.from(hash1)
transactions = []
}
def up = Mock(Multistream) {
1 * getApiSource(
new Selector.Builder().withMatcher(new Selector.HeightMatcher(100)).forMethod("eth_getBlockByNumber").build()
) >> Stub(ApiSource)
}
def calls = Mock(Factory) {
1 * create() >> new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET)
}
EthereumDirectReader reader = new EthereumDirectReader(
up, Caches.default(), new CurrentBlockCache(), calls, TestingCommons.tracerMock()
Stub(Multistream), Caches.default(), new CurrentBlockCache(), calls, TestingCommons.tracerMock()
)
reader.quorumReaderFactory = Mock(QuorumReaderFactory) {
1 * create(_, _, _, _) >> Mock(QuorumReader) {
reader.rpcReaderFactory = Mock(RpcReaderFactory) {
1 * create(_) >> Mock(RpcReader) {
1 * read(new JsonRpcRequest("eth_getBlockByNumber", ["0x64", false])) >> Mono.just(
new QuorumRpcReader.Result(
new RpcReader.Result(
Global.objectMapper.writeValueAsBytes(json), null, 1, resolver
)
)
@@ -151,19 +135,16 @@ class EthereumDirectReaderSpec extends Specification {
blockNumber = 100
blockHash = BlockHash.from(hash1)
}
def up = Mock(Multistream) {
1 * getApiSource(_) >> Stub(ApiSource)
}
def calls = Mock(Factory) {
1 * create() >> new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET)
}
EthereumDirectReader reader = new EthereumDirectReader(
up, Caches.default(), new CurrentBlockCache(), calls, TestingCommons.tracerMock()
Stub(Multistream), Caches.default(), new CurrentBlockCache(), calls, TestingCommons.tracerMock()
)
reader.quorumReaderFactory = Mock(QuorumReaderFactory) {
1 * create(_, _, _, _) >> Mock(QuorumReader) {
reader.rpcReaderFactory = Mock(RpcReaderFactory) {
1 * create(_) >> Mock(RpcReader) {
1 * read(new JsonRpcRequest("eth_getTransactionByHash", [hash1])) >> Mono.just(
new QuorumRpcReader.Result(
new RpcReader.Result(
Global.objectMapper.writeValueAsBytes(json), null, 1, resolver
)
)
@@ -187,19 +168,16 @@ class EthereumDirectReaderSpec extends Specification {
blockNumber = 100
blockHash = BlockHash.from(hash1)
}
def up = Mock(Multistream) {
1 * getApiSource(_) >> Stub(ApiSource)
}
def calls = Mock(Factory) {
1 * create() >> new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET)
}
EthereumDirectReader reader = new EthereumDirectReader(
up, Caches.default(), new CurrentBlockCache(), calls, TestingCommons.tracerMock()
Stub(Multistream), Caches.default(), new CurrentBlockCache(), calls, TestingCommons.tracerMock()
)
reader.quorumReaderFactory = Mock(QuorumReaderFactory) {
1 * create(_, _, _, _) >> Mock(QuorumReader) {
reader.rpcReaderFactory = Mock(RpcReaderFactory) {
1 * create(_) >> Mock(RpcReader) {
1 * read(new JsonRpcRequest("eth_getTransactionReceipt", [hash1])) >> Mono.just(
new QuorumRpcReader.Result(
new RpcReader.Result(
Global.objectMapper.writeValueAsBytes(json), null, 1, resolver
)
)
@@ -220,9 +198,6 @@ class EthereumDirectReaderSpec extends Specification {
blockNumber = 100
blockHash = BlockHash.from(hash1)
}
def up = Mock(Multistream) {
1 * getApiSource(_) >> Stub(ApiSource)
}
def calls = Mock(Factory) {
1 * create() >> new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET)
}
@@ -231,12 +206,12 @@ class EthereumDirectReaderSpec extends Specification {
1 * cacheReceipt(Caches.Tag.REQUESTED, { DefaultContainer data -> data.txId.toHex() == hash1.substring(2) && data.height == 100 })
}
EthereumDirectReader reader = new EthereumDirectReader(
up, caches, new CurrentBlockCache(), calls, TestingCommons.tracerMock()
Stub(Multistream), caches, new CurrentBlockCache(), calls, TestingCommons.tracerMock()
)
reader.quorumReaderFactory = Mock(QuorumReaderFactory) {
1 * create(_, _, _, _) >> Mock(QuorumReader) {
reader.rpcReaderFactory = Mock(RpcReaderFactory) {
1 * create(_) >> Mock(RpcReader) {
1 * read(new JsonRpcRequest("eth_getTransactionReceipt", [hash1])) >> Mono.just(
new QuorumRpcReader.Result(
new RpcReader.Result(
Global.objectMapper.writeValueAsBytes(json), null, 1, resolver
)
)
@@ -252,19 +227,16 @@ class EthereumDirectReaderSpec extends Specification {
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__MAINNET)
}
EthereumDirectReader reader = new EthereumDirectReader(
up, Caches.default(), new CurrentBlockCache(), calls, TestingCommons.tracerMock()
Stub(Multistream), Caches.default(), new CurrentBlockCache(), calls, TestingCommons.tracerMock()
)
reader.quorumReaderFactory = Mock(QuorumReaderFactory) {
1 * create(_, _, _, _) >> Mock(QuorumReader) {
reader.rpcReaderFactory = Mock(RpcReaderFactory) {
1 * create(_) >> Mock(RpcReader) {
1 * read(new JsonRpcRequest("eth_getTransactionByHash", [hash1])) >> Mono.just(
new QuorumRpcReader.Result(
new RpcReader.Result(
Global.objectMapper.writeValueAsBytes(null), null, 1, resolver
)
)
@@ -281,7 +253,6 @@ class EthereumDirectReaderSpec extends Specification {
def "Reads balance - height is unknown"() {
setup:
def up = Mock(Multistream) {
1 * getApiSource(_) >> Stub(ApiSource)
1 * getHead() >> Mock(Head) {
1 * getCurrentHeight() >> null
}
@@ -292,10 +263,10 @@ class EthereumDirectReaderSpec extends Specification {
EthereumDirectReader reader = new EthereumDirectReader(
up, Caches.default(), new CurrentBlockCache(), calls, TestingCommons.tracerMock()
)
reader.quorumReaderFactory = Mock(QuorumReaderFactory) {
1 * create(_, _, _, _) >> Mock(QuorumReader) {
reader.rpcReaderFactory = Mock(RpcReaderFactory) {
1 * create(_) >> Mock(RpcReader) {
1 * read(new JsonRpcRequest("eth_getBalance", [address1, "latest"])) >> Mono.just(
new QuorumRpcReader.Result(
new RpcReader.Result(
Global.objectMapper.writeValueAsBytes("0x100"), null, 1, resolver
)
)
@@ -313,7 +284,6 @@ class EthereumDirectReaderSpec extends Specification {
def "Reads balance - height is known"() {
setup:
def up = Mock(Multistream) {
1 * getApiSource(_) >> Stub(ApiSource)
1 * getHead() >> Mock(Head) {
1 * getCurrentHeight() >> 11_061_691
}
@@ -324,10 +294,10 @@ class EthereumDirectReaderSpec extends Specification {
EthereumDirectReader reader = new EthereumDirectReader(
up, Caches.default(), new CurrentBlockCache(), calls, TestingCommons.tracerMock()
)
reader.quorumReaderFactory = Mock(QuorumReaderFactory) {
1 * create(_, _, _, _) >> Mock(QuorumReader) {
reader.rpcReaderFactory = Mock(RpcReaderFactory) {
1 * create(_) >> Mock(RpcReader) {
1 * read(new JsonRpcRequest("eth_getBalance", [address1, "0xa8c9bb"])) >> Mono.just(
new QuorumRpcReader.Result(
new RpcReader.Result(
Global.objectMapper.writeValueAsBytes("0x100"), null, 1, resolver
)
)
@@ -352,25 +322,22 @@ class EthereumDirectReaderSpec extends Specification {
totalDifficulty = BigInteger.ONE
transactions = []
}
def up = Mock(Multistream) {
3 * getApiSource(_) >> Stub(ApiSource)
}
def calls = Mock(Factory) {
3 * create() >> new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET)
}
def result = Mono.just(
new QuorumRpcReader.Result(
new RpcReader.Result(
Global.objectMapper.writeValueAsBytes(json), null, 1, resolver)
)
EthereumDirectReader ethereumDirectReader = new EthereumDirectReader(
up, Caches.default(), new CurrentBlockCache(), calls, TestingCommons.tracerMock()
Stub(Multistream), Caches.default(), new CurrentBlockCache(), calls, TestingCommons.tracerMock()
)
ethereumDirectReader.quorumReaderFactory = Mock(QuorumReaderFactory) {
2 * create(_, _, _, _) >> Mock(QuorumReader) {
ethereumDirectReader.rpcReaderFactory = Mock(RpcReaderFactory) {
2 * create(_) >> Mock(RpcReader) {
2 * read(new JsonRpcRequest("eth_getBlockByHash", [hash1, false])) >>>
[Mono.error(new RuntimeException()), Mono.error(new RuntimeException())]
}
1 * create(_, _, _, _) >> Mock(QuorumReader) {
1 * create(_) >> Mock(RpcReader) {
1 * read(new JsonRpcRequest("eth_getBlockByHash", [hash1, false])) >> result
}
}
@@ -395,25 +362,22 @@ class EthereumDirectReaderSpec extends Specification {
parentHash = BlockHash.from(hash1)
transactions = []
}
def up = Mock(Multistream) {
3 * getApiSource(_) >> Stub(ApiSource)
}
def calls = Mock(Factory) {
3 * create() >> new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET)
}
def result = Mono.just(
new QuorumRpcReader.Result(
new RpcReader.Result(
Global.objectMapper.writeValueAsBytes(json), null, 1, resolver)
)
EthereumDirectReader ethereumDirectReader = new EthereumDirectReader(
up, Caches.default(), new CurrentBlockCache(), calls, TestingCommons.tracerMock()
Stub(Multistream), Caches.default(), new CurrentBlockCache(), calls, TestingCommons.tracerMock()
)
ethereumDirectReader.quorumReaderFactory = Mock(QuorumReaderFactory) {
2 * create(_, _, _, _) >> Mock(QuorumReader) {
ethereumDirectReader.rpcReaderFactory = Mock(RpcReaderFactory) {
2 * create(_) >> Mock(RpcReader) {
2 * read(new JsonRpcRequest("eth_getBlockByNumber", ["0x64", false])) >>>
[Mono.error(new RuntimeException()), Mono.error(new RuntimeException())]
}
1 * create(_, _, _, _) >> Mock(QuorumReader) {
1 * create(_) >> Mock(RpcReader) {
1 * read(new JsonRpcRequest("eth_getBlockByNumber", ["0x64", false])) >> result
}
}
@@ -431,7 +395,6 @@ class EthereumDirectReaderSpec extends Specification {
def "Reads balance with retries - expects an error within 1 sec"() {
setup:
def up = Mock(Multistream) {
4 * getApiSource(_) >> Stub(ApiSource)
1 * getHead() >> Mock(Head) {
1 * getCurrentHeight() >> null
}
@@ -442,8 +405,8 @@ class EthereumDirectReaderSpec extends Specification {
EthereumDirectReader reader = new EthereumDirectReader(
up, Caches.default(), new CurrentBlockCache(), calls, TestingCommons.tracerMock()
)
reader.quorumReaderFactory = Mock(QuorumReaderFactory) {
4 * create(_, _, _, _) >> Mock(QuorumReader) {
reader.rpcReaderFactory = Mock(RpcReaderFactory) {
4 * create(_) >> Mock(RpcReader) {
4 * read(new JsonRpcRequest("eth_getBalance", [address1, "latest"])) >>>
[Mono.error(new RuntimeException()), Mono.error(new RuntimeException()),
Mono.error(new RuntimeException()), Mono.error(new RuntimeException())]