fix ehtereum constants, fix tests
This commit is contained in:
Submodule emerald-java-client updated: a704b789a6...a3dde262ff
@@ -41,7 +41,7 @@ class TokensConfig(
|
|||||||
type == null -> type
|
type == null -> type
|
||||||
address.isNullOrBlank() -> "address"
|
address.isNullOrBlank() -> "address"
|
||||||
blockchain != null &&
|
blockchain != null &&
|
||||||
BlockchainType.from(blockchain!!) == BlockchainType.ETHEREUM &&
|
(BlockchainType.from(blockchain!!) == BlockchainType.ETHEREUM_POS || BlockchainType.from(blockchain!!) == BlockchainType.ETHEREUM) &&
|
||||||
!Address.isValidAddress(address) -> "address"
|
!Address.isValidAddress(address) -> "address"
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ import java.util.EnumMap
|
|||||||
@Service
|
@Service
|
||||||
open class NativeCall(
|
open class NativeCall(
|
||||||
@Autowired private val multistreamHolder: MultistreamHolder,
|
@Autowired private val multistreamHolder: MultistreamHolder,
|
||||||
@Autowired private val signer: ResponseSigner,
|
@Autowired private val signer: ResponseSigner
|
||||||
) {
|
) {
|
||||||
|
|
||||||
private val log = LoggerFactory.getLogger(NativeCall::class.java)
|
private val log = LoggerFactory.getLogger(NativeCall::class.java)
|
||||||
@@ -62,7 +62,8 @@ open class NativeCall(
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
multistreamHolder.observeChains().subscribe { chain ->
|
multistreamHolder.observeChains().subscribe { chain ->
|
||||||
if (BlockchainType.from(chain) == BlockchainType.ETHEREUM && !ethereumCallSelectors.containsKey(chain)) {
|
if ((BlockchainType.from(chain) == BlockchainType.ETHEREUM_POS || BlockchainType.from(chain) == BlockchainType.ETHEREUM) && !ethereumCallSelectors.containsKey(chain)
|
||||||
|
) {
|
||||||
multistreamHolder.getUpstream(chain)?.let { up ->
|
multistreamHolder.getUpstream(chain)?.let { up ->
|
||||||
val reader = up.cast(EthereumMultistream::class.java).getReader()
|
val reader = up.cast(EthereumMultistream::class.java).getReader()
|
||||||
ethereumCallSelectors[chain] = EthereumCallSelector(reader.heightByHash())
|
ethereumCallSelectors[chain] = EthereumCallSelector(reader.heightByHash())
|
||||||
@@ -186,7 +187,7 @@ open class NativeCall(
|
|||||||
}
|
}
|
||||||
// for ethereum the actual block needed for the call may be specified in the call parameters
|
// for ethereum the actual block needed for the call may be specified in the call parameters
|
||||||
val callSpecificMatcher: Mono<Selector.Matcher> =
|
val callSpecificMatcher: Mono<Selector.Matcher> =
|
||||||
if (BlockchainType.from(upstream.chain) == BlockchainType.ETHEREUM) {
|
if (BlockchainType.from(upstream.chain) == BlockchainType.ETHEREUM_POS || BlockchainType.from(upstream.chain) == BlockchainType.ETHEREUM) {
|
||||||
ethereumCallSelectors[chain]?.getMatcher(method, params, upstream.getHead())
|
ethereumCallSelectors[chain]?.getMatcher(method, params, upstream.getHead())
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ open class NativeSubscribe(
|
|||||||
|
|
||||||
fun start(it: BlockchainOuterClass.NativeSubscribeRequest): Publisher<out Any> {
|
fun start(it: BlockchainOuterClass.NativeSubscribeRequest): Publisher<out Any> {
|
||||||
val chain = Chain.byId(it.chainValue)
|
val chain = Chain.byId(it.chainValue)
|
||||||
if (BlockchainType.from(chain) != BlockchainType.ETHEREUM) {
|
if (BlockchainType.from(chain) != BlockchainType.ETHEREUM_POS && BlockchainType.from(chain) != BlockchainType.ETHEREUM) {
|
||||||
return Mono.error(UnsupportedOperationException("Native subscribe is not supported for ${chain.chainCode}"))
|
return Mono.error(UnsupportedOperationException("Native subscribe is not supported for ${chain.chainCode}"))
|
||||||
}
|
}
|
||||||
val method = it.method
|
val method = it.method
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import io.emeraldpay.dshackle.SilentException
|
|||||||
import io.emeraldpay.dshackle.config.TokensConfig
|
import io.emeraldpay.dshackle.config.TokensConfig
|
||||||
import io.emeraldpay.dshackle.upstream.MultistreamHolder
|
import io.emeraldpay.dshackle.upstream.MultistreamHolder
|
||||||
import io.emeraldpay.dshackle.upstream.ethereum.ERC20Balance
|
import io.emeraldpay.dshackle.upstream.ethereum.ERC20Balance
|
||||||
import io.emeraldpay.dshackle.upstream.ethereum.EthereumMultistream
|
import io.emeraldpay.dshackle.upstream.ethereum.EthereumPosMultiStream
|
||||||
import io.emeraldpay.etherjar.domain.Address
|
import io.emeraldpay.etherjar.domain.Address
|
||||||
import io.emeraldpay.etherjar.domain.EventId
|
import io.emeraldpay.etherjar.domain.EventId
|
||||||
import io.emeraldpay.etherjar.erc20.ERC20Token
|
import io.emeraldpay.etherjar.erc20.ERC20Token
|
||||||
@@ -58,7 +58,8 @@ class TrackERC20Address(
|
|||||||
val asset = token.name!!.lowercase(Locale.getDefault())
|
val asset = token.name!!.lowercase(Locale.getDefault())
|
||||||
val id = TokenId(chain, asset)
|
val id = TokenId(chain, asset)
|
||||||
val definition = TokenDefinition(
|
val definition = TokenDefinition(
|
||||||
chain, asset,
|
chain,
|
||||||
|
asset,
|
||||||
ERC20Token(Address.from(token.address))
|
ERC20Token(Address.from(token.address))
|
||||||
)
|
)
|
||||||
tokens[id] = definition
|
tokens[id] = definition
|
||||||
@@ -68,7 +69,7 @@ class TrackERC20Address(
|
|||||||
|
|
||||||
override fun isSupported(chain: Chain, asset: String): Boolean {
|
override fun isSupported(chain: Chain, asset: String): Boolean {
|
||||||
return tokens.containsKey(TokenId(chain, asset.lowercase(Locale.getDefault()))) &&
|
return tokens.containsKey(TokenId(chain, asset.lowercase(Locale.getDefault()))) &&
|
||||||
BlockchainType.from(chain) == BlockchainType.ETHEREUM && multistreamHolder.isAvailable(chain)
|
(BlockchainType.from(chain) == BlockchainType.ETHEREUM_POS || BlockchainType.from(chain) == BlockchainType.ETHEREUM) && multistreamHolder.isAvailable(chain)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getBalance(request: BlockchainOuterClass.BalanceRequest): Flux<BlockchainOuterClass.AddressBalance> {
|
override fun getBalance(request: BlockchainOuterClass.BalanceRequest): Flux<BlockchainOuterClass.AddressBalance> {
|
||||||
@@ -121,8 +122,8 @@ class TrackERC20Address(
|
|||||||
return erc20Balance.getBalance(upstream, addr.token, addr.address)
|
return erc20Balance.getBalance(upstream, addr.token, addr.address)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getUpstream(chain: Chain): EthereumMultistream {
|
fun getUpstream(chain: Chain): EthereumPosMultiStream {
|
||||||
return multistreamHolder.getUpstream(chain)?.cast(EthereumMultistream::class.java)
|
return multistreamHolder.getUpstream(chain)?.cast(EthereumPosMultiStream::class.java)
|
||||||
?: throw SilentException.UnsupportedBlockchain(chain)
|
?: throw SilentException.UnsupportedBlockchain(chain)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import io.emeraldpay.api.proto.Common
|
|||||||
import io.emeraldpay.dshackle.Defaults
|
import io.emeraldpay.dshackle.Defaults
|
||||||
import io.emeraldpay.dshackle.SilentException
|
import io.emeraldpay.dshackle.SilentException
|
||||||
import io.emeraldpay.dshackle.upstream.MultistreamHolder
|
import io.emeraldpay.dshackle.upstream.MultistreamHolder
|
||||||
import io.emeraldpay.dshackle.upstream.ethereum.EthereumMultistream
|
import io.emeraldpay.dshackle.upstream.ethereum.EthereumPosMultiStream
|
||||||
import io.emeraldpay.etherjar.domain.Address
|
import io.emeraldpay.etherjar.domain.Address
|
||||||
import io.emeraldpay.etherjar.domain.Wei
|
import io.emeraldpay.etherjar.domain.Wei
|
||||||
import io.emeraldpay.grpc.BlockchainType
|
import io.emeraldpay.grpc.BlockchainType
|
||||||
@@ -43,7 +43,7 @@ class TrackEthereumAddress(
|
|||||||
|
|
||||||
override fun isSupported(chain: Chain, asset: String): Boolean {
|
override fun isSupported(chain: Chain, asset: String): Boolean {
|
||||||
return asset == "ether" &&
|
return asset == "ether" &&
|
||||||
BlockchainType.from(chain) == BlockchainType.ETHEREUM && multistreamHolder.isAvailable(chain)
|
(BlockchainType.from(chain) == BlockchainType.ETHEREUM_POS || BlockchainType.from(chain) == BlockchainType.ETHEREUM) && multistreamHolder.isAvailable(chain)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getBalance(request: BlockchainOuterClass.BalanceRequest): Flux<BlockchainOuterClass.AddressBalance> {
|
override fun getBalance(request: BlockchainOuterClass.BalanceRequest): Flux<BlockchainOuterClass.AddressBalance> {
|
||||||
@@ -89,8 +89,8 @@ class TrackEthereumAddress(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getUpstream(chain: Chain): EthereumMultistream {
|
fun getUpstream(chain: Chain): EthereumPosMultiStream {
|
||||||
return multistreamHolder.getUpstream(chain)?.cast(EthereumMultistream::class.java)
|
return multistreamHolder.getUpstream(chain)?.cast(EthereumPosMultiStream::class.java)
|
||||||
?: throw SilentException.UnsupportedBlockchain(chain)
|
?: throw SilentException.UnsupportedBlockchain(chain)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import io.emeraldpay.dshackle.SilentException
|
|||||||
import io.emeraldpay.dshackle.data.BlockContainer
|
import io.emeraldpay.dshackle.data.BlockContainer
|
||||||
import io.emeraldpay.dshackle.data.TxId
|
import io.emeraldpay.dshackle.data.TxId
|
||||||
import io.emeraldpay.dshackle.upstream.MultistreamHolder
|
import io.emeraldpay.dshackle.upstream.MultistreamHolder
|
||||||
import io.emeraldpay.dshackle.upstream.ethereum.EthereumMultistream
|
import io.emeraldpay.dshackle.upstream.ethereum.EthereumPosMultiStream
|
||||||
import io.emeraldpay.etherjar.domain.BlockHash
|
import io.emeraldpay.etherjar.domain.BlockHash
|
||||||
import io.emeraldpay.etherjar.domain.TransactionId
|
import io.emeraldpay.etherjar.domain.TransactionId
|
||||||
import io.emeraldpay.etherjar.rpc.RpcException
|
import io.emeraldpay.etherjar.rpc.RpcException
|
||||||
@@ -62,7 +62,7 @@ class TrackEthereumTx(
|
|||||||
private val log = LoggerFactory.getLogger(TrackEthereumTx::class.java)
|
private val log = LoggerFactory.getLogger(TrackEthereumTx::class.java)
|
||||||
|
|
||||||
override fun isSupported(chain: Chain): Boolean {
|
override fun isSupported(chain: Chain): Boolean {
|
||||||
return BlockchainType.from(chain) == BlockchainType.ETHEREUM && multistreamHolder.isAvailable(chain)
|
return (BlockchainType.from(chain) == BlockchainType.ETHEREUM_POS || BlockchainType.from(chain) == BlockchainType.ETHEREUM) && multistreamHolder.isAvailable(chain)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun subscribe(request: BlockchainOuterClass.TxStatusRequest): Flux<BlockchainOuterClass.TxStatus> {
|
override fun subscribe(request: BlockchainOuterClass.TxStatusRequest): Flux<BlockchainOuterClass.TxStatus> {
|
||||||
@@ -81,12 +81,12 @@ class TrackEthereumTx(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getUpstream(chain: Chain): EthereumMultistream {
|
fun getUpstream(chain: Chain): EthereumPosMultiStream {
|
||||||
return multistreamHolder.getUpstream(chain)?.cast(EthereumMultistream::class.java)
|
return multistreamHolder.getUpstream(chain)?.cast(EthereumPosMultiStream::class.java)
|
||||||
?: throw SilentException.UnsupportedBlockchain(chain)
|
?: throw SilentException.UnsupportedBlockchain(chain)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun subscribe(base: TxDetails, up: EthereumMultistream): Flux<TxDetails> {
|
fun subscribe(base: TxDetails, up: EthereumPosMultiStream): Flux<TxDetails> {
|
||||||
var latestTx = base
|
var latestTx = base
|
||||||
|
|
||||||
val untilFound = Mono.just(latestTx)
|
val untilFound = Mono.just(latestTx)
|
||||||
@@ -213,7 +213,7 @@ class TrackEthereumTx(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateFromBlock(upstream: EthereumMultistream, tx: TxDetails, blockTx: TransactionJson): Mono<TxDetails> {
|
fun updateFromBlock(upstream: EthereumPosMultiStream, tx: TxDetails, blockTx: TransactionJson): Mono<TxDetails> {
|
||||||
return if (blockTx.blockNumber != null && blockTx.blockHash != null && blockTx.blockHash != ZERO_BLOCK) {
|
return if (blockTx.blockNumber != null && blockTx.blockHash != null && blockTx.blockHash != ZERO_BLOCK) {
|
||||||
val updated = tx.withStatus(
|
val updated = tx.withStatus(
|
||||||
blockHash = blockTx.blockHash,
|
blockHash = blockTx.blockHash,
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ open class ERC20Balance {
|
|||||||
private val log = LoggerFactory.getLogger(ERC20Balance::class.java)
|
private val log = LoggerFactory.getLogger(ERC20Balance::class.java)
|
||||||
}
|
}
|
||||||
|
|
||||||
open fun getBalance(upstreams: EthereumMultistream, token: ERC20Token, address: Address): Mono<BigInteger> {
|
open fun getBalance(upstreams: EthereumPosMultiStream, token: ERC20Token, address: Address): Mono<BigInteger> {
|
||||||
return upstreams
|
return upstreams
|
||||||
// use only up-to-date upstreams
|
// use only up-to-date upstreams
|
||||||
.getApiSource(Selector.HeightMatcher(upstreams.getHead().getCurrentHeight() ?: 0))
|
.getApiSource(Selector.HeightMatcher(upstreams.getHead().getCurrentHeight() ?: 0))
|
||||||
@@ -49,7 +49,7 @@ open class ERC20Balance {
|
|||||||
apis.request(1)
|
apis.request(1)
|
||||||
return Flux.from(apis)
|
return Flux.from(apis)
|
||||||
.flatMap {
|
.flatMap {
|
||||||
getBalance(it.cast(EthereumRpcUpstream::class.java), token, address)
|
getBalance(it.cast(EthereumPosRpcUpstream::class.java), token, address)
|
||||||
}
|
}
|
||||||
.doOnNext {
|
.doOnNext {
|
||||||
apis.resolve()
|
apis.resolve()
|
||||||
@@ -57,7 +57,7 @@ open class ERC20Balance {
|
|||||||
.next()
|
.next()
|
||||||
}
|
}
|
||||||
|
|
||||||
open fun getBalance(upstream: EthereumRpcUpstream, token: ERC20Token, address: Address): Mono<BigInteger> {
|
open fun getBalance(upstream: EthereumPosRpcUpstream, token: ERC20Token, address: Address): Mono<BigInteger> {
|
||||||
return upstream
|
return upstream
|
||||||
.getApi()
|
.getApi()
|
||||||
.read(prepareEthCall(token, address, upstream.getHead()))
|
.read(prepareEthCall(token, address, upstream.getHead()))
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import com.google.protobuf.ByteString
|
|||||||
import io.emeraldpay.api.proto.BlockchainOuterClass
|
import io.emeraldpay.api.proto.BlockchainOuterClass
|
||||||
import io.emeraldpay.dshackle.test.MultistreamHolderMock
|
import io.emeraldpay.dshackle.test.MultistreamHolderMock
|
||||||
import io.emeraldpay.dshackle.upstream.ethereum.EthereumMultistream
|
import io.emeraldpay.dshackle.upstream.ethereum.EthereumMultistream
|
||||||
|
import io.emeraldpay.dshackle.upstream.ethereum.EthereumPosMultiStream
|
||||||
import io.emeraldpay.dshackle.upstream.ethereum.EthereumSubscribe
|
import io.emeraldpay.dshackle.upstream.ethereum.EthereumSubscribe
|
||||||
import io.emeraldpay.grpc.Chain
|
import io.emeraldpay.grpc.Chain
|
||||||
import reactor.core.publisher.Flux
|
import reactor.core.publisher.Flux
|
||||||
@@ -34,7 +35,7 @@ class NativeSubscribeSpec extends Specification {
|
|||||||
def subscribe = Mock(EthereumSubscribe) {
|
def subscribe = Mock(EthereumSubscribe) {
|
||||||
1 * it.subscribe("newHeads", null) >> Flux.just("{}")
|
1 * it.subscribe("newHeads", null) >> Flux.just("{}")
|
||||||
}
|
}
|
||||||
def up = Mock(EthereumMultistream) {
|
def up = Mock(EthereumPosMultiStream) {
|
||||||
1 * it.getSubscribe() >> subscribe
|
1 * it.getSubscribe() >> subscribe
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,7 +67,7 @@ class NativeSubscribeSpec extends Specification {
|
|||||||
ok
|
ok
|
||||||
}) >> Flux.just("{}")
|
}) >> Flux.just("{}")
|
||||||
}
|
}
|
||||||
def up = Mock(EthereumMultistream) {
|
def up = Mock(EthereumPosMultiStream) {
|
||||||
1 * it.getSubscribe() >> subscribe
|
1 * it.getSubscribe() >> subscribe
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,10 +22,10 @@ import io.emeraldpay.api.proto.BlockchainOuterClass
|
|||||||
import io.emeraldpay.api.proto.Common
|
import io.emeraldpay.api.proto.Common
|
||||||
import io.emeraldpay.dshackle.Global
|
import io.emeraldpay.dshackle.Global
|
||||||
import io.emeraldpay.dshackle.data.BlockContainer
|
import io.emeraldpay.dshackle.data.BlockContainer
|
||||||
import io.emeraldpay.dshackle.test.EthereumRpcUpstreamMock
|
import io.emeraldpay.dshackle.test.EthereumPosRpcUpstreamMock
|
||||||
import io.emeraldpay.dshackle.test.TestingCommons
|
import io.emeraldpay.dshackle.test.TestingCommons
|
||||||
import io.emeraldpay.dshackle.test.MultistreamHolderMock
|
import io.emeraldpay.dshackle.test.MultistreamHolderMock
|
||||||
import io.emeraldpay.dshackle.upstream.ethereum.EthereumRpcUpstream
|
import io.emeraldpay.dshackle.upstream.ethereum.EthereumPosRpcUpstream
|
||||||
import io.emeraldpay.grpc.Chain
|
import io.emeraldpay.grpc.Chain
|
||||||
import io.emeraldpay.etherjar.domain.BlockHash
|
import io.emeraldpay.etherjar.domain.BlockHash
|
||||||
import io.emeraldpay.etherjar.rpc.json.BlockJson
|
import io.emeraldpay.etherjar.rpc.json.BlockJson
|
||||||
@@ -43,7 +43,7 @@ class StreamHeadSpec extends Specification {
|
|||||||
|
|
||||||
def "Errors on unavailable chain"() {
|
def "Errors on unavailable chain"() {
|
||||||
setup:
|
setup:
|
||||||
def upstreams = new MultistreamHolderMock(Chain.ETHEREUM, Stub(EthereumRpcUpstream))
|
def upstreams = new MultistreamHolderMock(Chain.ETHEREUM, Stub(EthereumPosRpcUpstream))
|
||||||
def streamHead = new StreamHead(upstreams)
|
def streamHead = new StreamHead(upstreams)
|
||||||
when:
|
when:
|
||||||
def flux = streamHead.add(
|
def flux = streamHead.add(
|
||||||
@@ -78,7 +78,7 @@ class StreamHeadSpec extends Specification {
|
|||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
def upstream = new EthereumRpcUpstreamMock(Chain.ETHEREUM, TestingCommons.api())
|
def upstream = new EthereumPosRpcUpstreamMock(Chain.ETHEREUM, TestingCommons.api())
|
||||||
def upstreams = new MultistreamHolderMock(Chain.ETHEREUM, upstream)
|
def upstreams = new MultistreamHolderMock(Chain.ETHEREUM, upstream)
|
||||||
def streamHead = new StreamHead(upstreams)
|
def streamHead = new StreamHead(upstreams)
|
||||||
when:
|
when:
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import io.emeraldpay.dshackle.config.TokensConfig
|
|||||||
import io.emeraldpay.dshackle.upstream.MultistreamHolder
|
import io.emeraldpay.dshackle.upstream.MultistreamHolder
|
||||||
import io.emeraldpay.dshackle.upstream.ethereum.ERC20Balance
|
import io.emeraldpay.dshackle.upstream.ethereum.ERC20Balance
|
||||||
import io.emeraldpay.dshackle.upstream.ethereum.EthereumMultistream
|
import io.emeraldpay.dshackle.upstream.ethereum.EthereumMultistream
|
||||||
|
import io.emeraldpay.dshackle.upstream.ethereum.EthereumPosMultiStream
|
||||||
import io.emeraldpay.dshackle.upstream.ethereum.EthereumSubscribe
|
import io.emeraldpay.dshackle.upstream.ethereum.EthereumSubscribe
|
||||||
import io.emeraldpay.dshackle.upstream.ethereum.subscribe.ConnectLogs
|
import io.emeraldpay.dshackle.upstream.ethereum.subscribe.ConnectLogs
|
||||||
import io.emeraldpay.dshackle.upstream.ethereum.subscribe.json.LogMessage
|
import io.emeraldpay.dshackle.upstream.ethereum.subscribe.json.LogMessage
|
||||||
@@ -178,9 +179,9 @@ class TrackERC20AddressSpec extends Specification {
|
|||||||
def sub = Mock(EthereumSubscribe) {
|
def sub = Mock(EthereumSubscribe) {
|
||||||
1 * getLogs() >> logs
|
1 * getLogs() >> logs
|
||||||
}
|
}
|
||||||
def up = Mock(EthereumMultistream) {
|
def up = Mock(EthereumPosMultiStream) {
|
||||||
1 * getSubscribe() >> sub
|
1 * getSubscribe() >> sub
|
||||||
_ * cast(EthereumMultistream) >> { args ->
|
_ * cast(EthereumPosMultiStream) >> { args ->
|
||||||
it
|
it
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import io.emeraldpay.dshackle.test.MultistreamHolderMock
|
|||||||
import io.emeraldpay.dshackle.upstream.Head
|
import io.emeraldpay.dshackle.upstream.Head
|
||||||
import io.emeraldpay.dshackle.upstream.MultistreamHolder
|
import io.emeraldpay.dshackle.upstream.MultistreamHolder
|
||||||
import io.emeraldpay.dshackle.upstream.ethereum.EthereumMultistream
|
import io.emeraldpay.dshackle.upstream.ethereum.EthereumMultistream
|
||||||
|
import io.emeraldpay.dshackle.upstream.ethereum.EthereumPosMultiStream
|
||||||
import io.emeraldpay.grpc.Chain
|
import io.emeraldpay.grpc.Chain
|
||||||
import io.emeraldpay.etherjar.domain.BlockHash
|
import io.emeraldpay.etherjar.domain.BlockHash
|
||||||
import io.emeraldpay.etherjar.domain.TransactionId
|
import io.emeraldpay.etherjar.domain.TransactionId
|
||||||
@@ -118,7 +119,7 @@ class TrackEthereumTxSpec extends Specification {
|
|||||||
def apiMock = TestingCommons.api()
|
def apiMock = TestingCommons.api()
|
||||||
def upstreamMock = TestingCommons.upstream(apiMock)
|
def upstreamMock = TestingCommons.upstream(apiMock)
|
||||||
MultistreamHolder upstreams = new MultistreamHolderMock(Chain.ETHEREUM, upstreamMock)
|
MultistreamHolder upstreams = new MultistreamHolderMock(Chain.ETHEREUM, upstreamMock)
|
||||||
((EthereumMultistream) upstreams.getUpstream(Chain.ETHEREUM)).head = Mock(Head) {
|
((EthereumPosMultiStream) upstreams.getUpstream(Chain.ETHEREUM)).head = Mock(Head) {
|
||||||
_ * getFlux() >> Flux.empty()
|
_ * getFlux() >> Flux.empty()
|
||||||
}
|
}
|
||||||
TrackEthereumTx trackTx = new TrackEthereumTx(upstreams)
|
TrackEthereumTx trackTx = new TrackEthereumTx(upstreams)
|
||||||
@@ -130,7 +131,7 @@ class TrackEthereumTxSpec extends Specification {
|
|||||||
when:
|
when:
|
||||||
def tx = new TrackEthereumTx.TxDetails(Chain.ETHEREUM, Instant.now(), TransactionId.from(txId), 6)
|
def tx = new TrackEthereumTx.TxDetails(Chain.ETHEREUM, Instant.now(), TransactionId.from(txId), 6)
|
||||||
def act = StepVerifier.withVirtualTime(
|
def act = StepVerifier.withVirtualTime(
|
||||||
{ trackTx.subscribe(tx, upstreams.getUpstream(Chain.ETHEREUM).cast(EthereumMultistream)) },
|
{ trackTx.subscribe(tx, upstreams.getUpstream(Chain.ETHEREUM).cast(EthereumPosMultiStream)) },
|
||||||
{ scheduler },
|
{ scheduler },
|
||||||
5)
|
5)
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,88 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2019 ETCDEV GmbH
|
||||||
|
* Copyright (c) 2020 EmeraldPay, Inc
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package io.emeraldpay.dshackle.test
|
||||||
|
|
||||||
|
|
||||||
|
import io.emeraldpay.dshackle.config.UpstreamsConfig
|
||||||
|
import io.emeraldpay.dshackle.data.BlockContainer
|
||||||
|
import io.emeraldpay.dshackle.upstream.calls.AggregatedCallMethods
|
||||||
|
import io.emeraldpay.dshackle.upstream.calls.CallMethods
|
||||||
|
import io.emeraldpay.dshackle.startup.QuorumForLabels
|
||||||
|
import io.emeraldpay.dshackle.upstream.calls.DefaultBitcoinMethods
|
||||||
|
import io.emeraldpay.dshackle.upstream.calls.DefaultEthereumMethods
|
||||||
|
import io.emeraldpay.dshackle.upstream.calls.DirectCallMethods
|
||||||
|
import io.emeraldpay.dshackle.upstream.ethereum.EthereumPosRpcUpstream
|
||||||
|
import io.emeraldpay.dshackle.upstream.ethereum.EthereumRpcUpstream
|
||||||
|
import io.emeraldpay.dshackle.upstream.UpstreamAvailability
|
||||||
|
import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest
|
||||||
|
import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse
|
||||||
|
import io.emeraldpay.dshackle.reader.Reader
|
||||||
|
import io.emeraldpay.grpc.Chain
|
||||||
|
import org.jetbrains.annotations.NotNull
|
||||||
|
import org.reactivestreams.Publisher
|
||||||
|
|
||||||
|
|
||||||
|
class EthereumPosRpcUpstreamMock extends EthereumPosRpcUpstream {
|
||||||
|
EthereumHeadMock ethereumHeadMock
|
||||||
|
|
||||||
|
|
||||||
|
static CallMethods allMethods() {
|
||||||
|
new AggregatedCallMethods([
|
||||||
|
new DefaultEthereumMethods(Chain.ETHEREUM),
|
||||||
|
new DefaultBitcoinMethods(),
|
||||||
|
new DirectCallMethods(["eth_test"])
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
EthereumPosRpcUpstreamMock(@NotNull Chain chain, @NotNull Reader<JsonRpcRequest, JsonRpcResponse> api) {
|
||||||
|
this(chain, api, allMethods())
|
||||||
|
}
|
||||||
|
|
||||||
|
EthereumPosRpcUpstreamMock(@NotNull String id, @NotNull Chain chain, @NotNull Reader<JsonRpcRequest, JsonRpcResponse> api) {
|
||||||
|
this(id, chain, api, allMethods())
|
||||||
|
}
|
||||||
|
|
||||||
|
EthereumPosRpcUpstreamMock(@NotNull Chain chain, @NotNull Reader<JsonRpcRequest, JsonRpcResponse> api, CallMethods methods) {
|
||||||
|
this("test", chain, api, methods)
|
||||||
|
}
|
||||||
|
|
||||||
|
EthereumPosRpcUpstreamMock(@NotNull String id, @NotNull Chain chain, @NotNull Reader<JsonRpcRequest, JsonRpcResponse> api, CallMethods methods) {
|
||||||
|
super(id, chain,
|
||||||
|
UpstreamsConfig.Options.getDefaults(),
|
||||||
|
UpstreamsConfig.UpstreamRole.PRIMARY,
|
||||||
|
methods,
|
||||||
|
new QuorumForLabels.QuorumItem(1, new UpstreamsConfig.Labels()),
|
||||||
|
new ConnectorFactoryMock(api, new EthereumHeadMock()))
|
||||||
|
this.ethereumHeadMock = this.getHead() as EthereumHeadMock
|
||||||
|
setLag(0)
|
||||||
|
setStatus(UpstreamAvailability.OK)
|
||||||
|
start()
|
||||||
|
}
|
||||||
|
|
||||||
|
void nextBlock(BlockContainer block) {
|
||||||
|
this.ethereumHeadMock.nextBlock(block)
|
||||||
|
}
|
||||||
|
|
||||||
|
void setBlocks(Publisher<BlockContainer> blocks) {
|
||||||
|
this.ethereumHeadMock.predefined = blocks
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
String toString() {
|
||||||
|
return "Upstream mock ${getId()}"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -27,6 +27,8 @@ import io.emeraldpay.dshackle.upstream.calls.DefaultEthereumMethods
|
|||||||
import io.emeraldpay.dshackle.upstream.Upstream
|
import io.emeraldpay.dshackle.upstream.Upstream
|
||||||
import io.emeraldpay.dshackle.upstream.MultistreamHolder
|
import io.emeraldpay.dshackle.upstream.MultistreamHolder
|
||||||
import io.emeraldpay.dshackle.upstream.ethereum.EthereumMultistream
|
import io.emeraldpay.dshackle.upstream.ethereum.EthereumMultistream
|
||||||
|
import io.emeraldpay.dshackle.upstream.ethereum.EthereumPosMultiStream
|
||||||
|
import io.emeraldpay.dshackle.upstream.ethereum.EthereumPosRpcUpstream
|
||||||
import io.emeraldpay.dshackle.upstream.ethereum.EthereumReader
|
import io.emeraldpay.dshackle.upstream.ethereum.EthereumReader
|
||||||
import io.emeraldpay.dshackle.upstream.ethereum.EthereumRpcUpstream
|
import io.emeraldpay.dshackle.upstream.ethereum.EthereumRpcUpstream
|
||||||
import io.emeraldpay.grpc.BlockchainType
|
import io.emeraldpay.grpc.BlockchainType
|
||||||
@@ -45,11 +47,11 @@ class MultistreamHolderMock implements MultistreamHolder {
|
|||||||
|
|
||||||
Multistream addUpstream(@NotNull Chain chain, @NotNull Upstream up) {
|
Multistream addUpstream(@NotNull Chain chain, @NotNull Upstream up) {
|
||||||
if (!upstreams.containsKey(chain)) {
|
if (!upstreams.containsKey(chain)) {
|
||||||
if (BlockchainType.from(chain) == BlockchainType.ETHEREUM) {
|
if (BlockchainType.from(chain) == BlockchainType.ETHEREUM_POS) {
|
||||||
if (up instanceof EthereumMultistream) {
|
if (up instanceof EthereumPosMultiStream) {
|
||||||
upstreams[chain] = up
|
upstreams[chain] = up
|
||||||
} else if (up instanceof EthereumRpcUpstream) {
|
} else if (up instanceof EthereumPosRpcUpstream) {
|
||||||
upstreams[chain] = new EthereumMultistreamMock(chain, [up as EthereumRpcUpstream], Caches.default())
|
upstreams[chain] = new EthereumPosMultiStream(chain, [up as EthereumPosRpcUpstream], Caches.default())
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("Unsupported upstream type ${up.class}")
|
throw new IllegalArgumentException("Unsupported upstream type ${up.class}")
|
||||||
}
|
}
|
||||||
@@ -99,21 +101,21 @@ class MultistreamHolderMock implements MultistreamHolder {
|
|||||||
return upstreams.containsKey(chain)
|
return upstreams.containsKey(chain)
|
||||||
}
|
}
|
||||||
|
|
||||||
static class EthereumMultistreamMock extends EthereumMultistream {
|
static class EthereumMultistreamMock extends EthereumPosMultiStream {
|
||||||
|
|
||||||
EthereumReader customReader = null
|
EthereumReader customReader = null
|
||||||
CallMethods customMethods = null
|
CallMethods customMethods = null
|
||||||
Head customHead = null
|
Head customHead = null
|
||||||
|
|
||||||
EthereumMultistreamMock(@NotNull Chain chain, @NotNull List<EthereumRpcUpstream> upstreams, @NotNull Caches caches) {
|
EthereumMultistreamMock(@NotNull Chain chain, @NotNull List<EthereumPosRpcUpstream> upstreams, @NotNull Caches caches) {
|
||||||
super(chain, upstreams, caches)
|
super(chain, upstreams, caches)
|
||||||
}
|
}
|
||||||
|
|
||||||
EthereumMultistreamMock(@NotNull Chain chain, @NotNull List<EthereumRpcUpstream> upstreams) {
|
EthereumMultistreamMock(@NotNull Chain chain, @NotNull List<EthereumPosRpcUpstream> upstreams) {
|
||||||
this(chain, upstreams, Caches.default())
|
this(chain, upstreams, Caches.default())
|
||||||
}
|
}
|
||||||
|
|
||||||
EthereumMultistreamMock(@NotNull Chain chain, @NotNull EthereumRpcUpstream upstream) {
|
EthereumMultistreamMock(@NotNull Chain chain, @NotNull EthereumPosRpcUpstream upstream) {
|
||||||
this(chain, [upstream])
|
this(chain, [upstream])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ import io.emeraldpay.dshackle.reader.Reader
|
|||||||
import io.emeraldpay.dshackle.upstream.Multistream
|
import io.emeraldpay.dshackle.upstream.Multistream
|
||||||
import io.emeraldpay.dshackle.upstream.calls.DirectCallMethods
|
import io.emeraldpay.dshackle.upstream.calls.DirectCallMethods
|
||||||
import io.emeraldpay.dshackle.upstream.ethereum.EthereumMultistream
|
import io.emeraldpay.dshackle.upstream.ethereum.EthereumMultistream
|
||||||
|
import io.emeraldpay.dshackle.upstream.ethereum.EthereumPosMultiStream
|
||||||
|
import io.emeraldpay.dshackle.upstream.ethereum.EthereumPosRpcUpstream
|
||||||
import io.emeraldpay.dshackle.upstream.ethereum.EthereumRpcUpstream
|
import io.emeraldpay.dshackle.upstream.ethereum.EthereumRpcUpstream
|
||||||
import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest
|
import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest
|
||||||
import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse
|
import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse
|
||||||
@@ -46,36 +48,36 @@ class TestingCommons {
|
|||||||
return new ApiReaderMock()
|
return new ApiReaderMock()
|
||||||
}
|
}
|
||||||
|
|
||||||
static EthereumRpcUpstreamMock upstream() {
|
static EthereumPosRpcUpstreamMock upstream() {
|
||||||
return new EthereumRpcUpstreamMock(Chain.ETHEREUM, api())
|
return new EthereumPosRpcUpstreamMock(Chain.ETHEREUM, api())
|
||||||
}
|
}
|
||||||
|
|
||||||
static EthereumRpcUpstreamMock upstream(String id) {
|
static EthereumPosRpcUpstreamMock upstream(String id) {
|
||||||
return new EthereumRpcUpstreamMock(id, Chain.ETHEREUM, api())
|
return new EthereumPosRpcUpstreamMock(id, Chain.ETHEREUM, api())
|
||||||
}
|
}
|
||||||
|
|
||||||
static EthereumRpcUpstreamMock upstream(String id, Reader<JsonRpcRequest, JsonRpcResponse> api) {
|
static EthereumPosRpcUpstreamMock upstream(String id, Reader<JsonRpcRequest, JsonRpcResponse> api) {
|
||||||
return new EthereumRpcUpstreamMock(id, Chain.ETHEREUM, api)
|
return new EthereumPosRpcUpstreamMock(id, Chain.ETHEREUM, api)
|
||||||
}
|
}
|
||||||
|
|
||||||
static EthereumRpcUpstreamMock upstream(Reader<JsonRpcRequest, JsonRpcResponse> api) {
|
static EthereumPosRpcUpstreamMock upstream(Reader<JsonRpcRequest, JsonRpcResponse> api) {
|
||||||
return new EthereumRpcUpstreamMock(Chain.ETHEREUM, api)
|
return new EthereumPosRpcUpstreamMock(Chain.ETHEREUM, api)
|
||||||
}
|
}
|
||||||
|
|
||||||
static EthereumRpcUpstreamMock upstream(Reader<JsonRpcRequest, JsonRpcResponse> api, String method) {
|
static EthereumPosRpcUpstreamMock upstream(Reader<JsonRpcRequest, JsonRpcResponse> api, String method) {
|
||||||
return upstream(api, [method])
|
return upstream(api, [method])
|
||||||
}
|
}
|
||||||
|
|
||||||
static EthereumRpcUpstreamMock upstream(Reader<JsonRpcRequest, JsonRpcResponse> api, List<String> methods) {
|
static EthereumPosRpcUpstreamMock upstream(Reader<JsonRpcRequest, JsonRpcResponse> api, List<String> methods) {
|
||||||
return new EthereumRpcUpstreamMock(Chain.ETHEREUM, api, new DirectCallMethods(methods))
|
return new EthereumPosRpcUpstreamMock(Chain.ETHEREUM, api, new DirectCallMethods(methods))
|
||||||
}
|
}
|
||||||
|
|
||||||
static Multistream multistream(Reader<JsonRpcRequest, JsonRpcResponse> api) {
|
static Multistream multistream(Reader<JsonRpcRequest, JsonRpcResponse> api) {
|
||||||
return multistream(upstream(api))
|
return multistream(upstream(api))
|
||||||
}
|
}
|
||||||
|
|
||||||
static Multistream multistream(EthereumRpcUpstream up) {
|
static Multistream multistream(EthereumPosRpcUpstreamMock up) {
|
||||||
return new EthereumMultistream(Chain.ETHEREUM, [up], Caches.default()).tap {
|
return new EthereumPosMultiStream(Chain.ETHEREUM, [up], Caches.default()).tap {
|
||||||
start()
|
start()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
package io.emeraldpay.dshackle.upstream
|
package io.emeraldpay.dshackle.upstream
|
||||||
|
|
||||||
import io.emeraldpay.dshackle.startup.UpstreamChange
|
import io.emeraldpay.dshackle.startup.UpstreamChange
|
||||||
|
import io.emeraldpay.dshackle.test.EthereumPosRpcUpstreamMock
|
||||||
import io.emeraldpay.dshackle.test.EthereumRpcUpstreamMock
|
import io.emeraldpay.dshackle.test.EthereumRpcUpstreamMock
|
||||||
import io.emeraldpay.dshackle.test.TestingCommons
|
import io.emeraldpay.dshackle.test.TestingCommons
|
||||||
import io.emeraldpay.grpc.Chain
|
import io.emeraldpay.grpc.Chain
|
||||||
@@ -26,7 +27,7 @@ class CurrentMultistreamHolderSpec extends Specification {
|
|||||||
def "add upstream"() {
|
def "add upstream"() {
|
||||||
setup:
|
setup:
|
||||||
def current = new CurrentMultistreamHolder(TestingCommons.emptyCaches())
|
def current = new CurrentMultistreamHolder(TestingCommons.emptyCaches())
|
||||||
def up = new EthereumRpcUpstreamMock("test", Chain.ETHEREUM, TestingCommons.api())
|
def up = new EthereumPosRpcUpstreamMock("test", Chain.ETHEREUM, TestingCommons.api())
|
||||||
when:
|
when:
|
||||||
current.update(new UpstreamChange(Chain.ETHEREUM, up, UpstreamChange.ChangeType.ADDED))
|
current.update(new UpstreamChange(Chain.ETHEREUM, up, UpstreamChange.ChangeType.ADDED))
|
||||||
then:
|
then:
|
||||||
@@ -37,9 +38,9 @@ class CurrentMultistreamHolderSpec extends Specification {
|
|||||||
def "add multiple upstreams"() {
|
def "add multiple upstreams"() {
|
||||||
setup:
|
setup:
|
||||||
def current = new CurrentMultistreamHolder(TestingCommons.emptyCaches())
|
def current = new CurrentMultistreamHolder(TestingCommons.emptyCaches())
|
||||||
def up1 = new EthereumRpcUpstreamMock("test1", Chain.ETHEREUM, TestingCommons.api())
|
def up1 = new EthereumPosRpcUpstreamMock("test1", Chain.ETHEREUM, TestingCommons.api())
|
||||||
def up2 = new EthereumRpcUpstreamMock("test2", Chain.ETHEREUM_CLASSIC, TestingCommons.api())
|
def up2 = new EthereumRpcUpstreamMock("test2", Chain.ETHEREUM_CLASSIC, TestingCommons.api())
|
||||||
def up3 = new EthereumRpcUpstreamMock("test3", Chain.ETHEREUM, TestingCommons.api())
|
def up3 = new EthereumPosRpcUpstreamMock("test3", Chain.ETHEREUM, TestingCommons.api())
|
||||||
when:
|
when:
|
||||||
current.update(new UpstreamChange(Chain.ETHEREUM, up1, UpstreamChange.ChangeType.ADDED))
|
current.update(new UpstreamChange(Chain.ETHEREUM, up1, UpstreamChange.ChangeType.ADDED))
|
||||||
current.update(new UpstreamChange(Chain.ETHEREUM_CLASSIC, up2, UpstreamChange.ChangeType.ADDED))
|
current.update(new UpstreamChange(Chain.ETHEREUM_CLASSIC, up2, UpstreamChange.ChangeType.ADDED))
|
||||||
@@ -53,10 +54,10 @@ class CurrentMultistreamHolderSpec extends Specification {
|
|||||||
def "remove upstream"() {
|
def "remove upstream"() {
|
||||||
setup:
|
setup:
|
||||||
def current = new CurrentMultistreamHolder(TestingCommons.emptyCaches())
|
def current = new CurrentMultistreamHolder(TestingCommons.emptyCaches())
|
||||||
def up1 = new EthereumRpcUpstreamMock("test1", Chain.ETHEREUM, TestingCommons.api())
|
def up1 = new EthereumPosRpcUpstreamMock("test1", Chain.ETHEREUM, TestingCommons.api())
|
||||||
def up2 = new EthereumRpcUpstreamMock("test2", Chain.ETHEREUM_CLASSIC, TestingCommons.api())
|
def up2 = new EthereumRpcUpstreamMock("test2", Chain.ETHEREUM_CLASSIC, TestingCommons.api())
|
||||||
def up3 = new EthereumRpcUpstreamMock("test3", Chain.ETHEREUM, TestingCommons.api())
|
def up3 = new EthereumPosRpcUpstreamMock("test3", Chain.ETHEREUM, TestingCommons.api())
|
||||||
def up1_del = new EthereumRpcUpstreamMock("test1", Chain.ETHEREUM, TestingCommons.api())
|
def up1_del = new EthereumPosRpcUpstreamMock("test1", Chain.ETHEREUM, TestingCommons.api())
|
||||||
when:
|
when:
|
||||||
current.update(new UpstreamChange(Chain.ETHEREUM, up1, UpstreamChange.ChangeType.ADDED))
|
current.update(new UpstreamChange(Chain.ETHEREUM, up1, UpstreamChange.ChangeType.ADDED))
|
||||||
current.update(new UpstreamChange(Chain.ETHEREUM_CLASSIC, up2, UpstreamChange.ChangeType.ADDED))
|
current.update(new UpstreamChange(Chain.ETHEREUM_CLASSIC, up2, UpstreamChange.ChangeType.ADDED))
|
||||||
@@ -71,7 +72,7 @@ class CurrentMultistreamHolderSpec extends Specification {
|
|||||||
def "available after adding"() {
|
def "available after adding"() {
|
||||||
setup:
|
setup:
|
||||||
def current = new CurrentMultistreamHolder(TestingCommons.emptyCaches())
|
def current = new CurrentMultistreamHolder(TestingCommons.emptyCaches())
|
||||||
def up1 = new EthereumRpcUpstreamMock("test1", Chain.ETHEREUM, TestingCommons.api())
|
def up1 = new EthereumPosRpcUpstreamMock("test1", Chain.ETHEREUM, TestingCommons.api())
|
||||||
|
|
||||||
when:
|
when:
|
||||||
def act = current.isAvailable(Chain.ETHEREUM)
|
def act = current.isAvailable(Chain.ETHEREUM)
|
||||||
|
|||||||
@@ -20,10 +20,12 @@ import io.emeraldpay.dshackle.cache.Caches
|
|||||||
import io.emeraldpay.dshackle.config.UpstreamsConfig
|
import io.emeraldpay.dshackle.config.UpstreamsConfig
|
||||||
import io.emeraldpay.dshackle.quorum.AlwaysQuorum
|
import io.emeraldpay.dshackle.quorum.AlwaysQuorum
|
||||||
import io.emeraldpay.dshackle.reader.Reader
|
import io.emeraldpay.dshackle.reader.Reader
|
||||||
|
import io.emeraldpay.dshackle.test.EthereumPosRpcUpstreamMock
|
||||||
import io.emeraldpay.dshackle.test.EthereumRpcUpstreamMock
|
import io.emeraldpay.dshackle.test.EthereumRpcUpstreamMock
|
||||||
import io.emeraldpay.dshackle.test.TestingCommons
|
import io.emeraldpay.dshackle.test.TestingCommons
|
||||||
import io.emeraldpay.dshackle.upstream.calls.DirectCallMethods
|
import io.emeraldpay.dshackle.upstream.calls.DirectCallMethods
|
||||||
import io.emeraldpay.dshackle.upstream.ethereum.EthereumMultistream
|
import io.emeraldpay.dshackle.upstream.ethereum.EthereumMultistream
|
||||||
|
import io.emeraldpay.dshackle.upstream.ethereum.EthereumPosMultiStream
|
||||||
import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest
|
import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest
|
||||||
import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse
|
import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse
|
||||||
import io.emeraldpay.grpc.Chain
|
import io.emeraldpay.grpc.Chain
|
||||||
@@ -38,9 +40,9 @@ class MultistreamSpec extends Specification {
|
|||||||
|
|
||||||
def "Aggregates methods"() {
|
def "Aggregates methods"() {
|
||||||
setup:
|
setup:
|
||||||
def up1 = new EthereumRpcUpstreamMock("test1", Chain.ETHEREUM, TestingCommons.api(), new DirectCallMethods(["eth_test1", "eth_test2"]))
|
def up1 = new EthereumPosRpcUpstreamMock("test1", Chain.ETHEREUM, TestingCommons.api(), new DirectCallMethods(["eth_test1", "eth_test2"]))
|
||||||
def up2 = new EthereumRpcUpstreamMock("test1", Chain.ETHEREUM, TestingCommons.api(), new DirectCallMethods(["eth_test2", "eth_test3"]))
|
def up2 = new EthereumPosRpcUpstreamMock("test1", Chain.ETHEREUM, TestingCommons.api(), new DirectCallMethods(["eth_test2", "eth_test3"]))
|
||||||
def aggr = new EthereumMultistream(Chain.ETHEREUM, [up1, up2], Caches.default())
|
def aggr = new EthereumPosMultiStream(Chain.ETHEREUM, [up1, up2], Caches.default())
|
||||||
when:
|
when:
|
||||||
aggr.onUpstreamsUpdated()
|
aggr.onUpstreamsUpdated()
|
||||||
def act = aggr.getMethods()
|
def act = aggr.getMethods()
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package io.emeraldpay.dshackle.upstream.ethereum
|
package io.emeraldpay.dshackle.upstream.ethereum
|
||||||
|
|
||||||
|
import io.emeraldpay.dshackle.test.EthereumPosRpcUpstreamMock
|
||||||
import io.emeraldpay.dshackle.test.EthereumRpcUpstreamMock
|
import io.emeraldpay.dshackle.test.EthereumRpcUpstreamMock
|
||||||
import io.emeraldpay.dshackle.test.ReaderMock
|
import io.emeraldpay.dshackle.test.ReaderMock
|
||||||
import io.emeraldpay.dshackle.upstream.ApiSource
|
import io.emeraldpay.dshackle.upstream.ApiSource
|
||||||
@@ -47,7 +48,7 @@ class ERC20BalanceSpec extends Specification {
|
|||||||
JsonRpcResponse.ok('"0x0000000000000000000000000000000000000000000000000000001f28d72868"')
|
JsonRpcResponse.ok('"0x0000000000000000000000000000000000000000000000000000001f28d72868"')
|
||||||
)
|
)
|
||||||
|
|
||||||
EthereumRpcUpstream upstream = new EthereumRpcUpstreamMock(Chain.ETHEREUM, api)
|
EthereumPosRpcUpstream upstream = new EthereumPosRpcUpstreamMock(Chain.ETHEREUM, api)
|
||||||
ERC20Token token = new ERC20Token(Address.from("0x54EedeAC495271d0F6B175474E89094C44Da98b9"))
|
ERC20Token token = new ERC20Token(Address.from("0x54EedeAC495271d0F6B175474E89094C44Da98b9"))
|
||||||
ERC20Balance query = new ERC20Balance()
|
ERC20Balance query = new ERC20Balance()
|
||||||
|
|
||||||
@@ -73,7 +74,7 @@ class ERC20BalanceSpec extends Specification {
|
|||||||
JsonRpcResponse.ok('"0x0000000000000000000000000000000000000000000000000000001f28d72868"')
|
JsonRpcResponse.ok('"0x0000000000000000000000000000000000000000000000000000001f28d72868"')
|
||||||
)
|
)
|
||||||
|
|
||||||
EthereumRpcUpstream upstream = new EthereumRpcUpstreamMock(Chain.ETHEREUM, api)
|
EthereumPosRpcUpstream upstream = new EthereumPosRpcUpstreamMock(Chain.ETHEREUM, api)
|
||||||
ERC20Token token = new ERC20Token(Address.from("0x54EedeAC495271d0F6B175474E89094C44Da98b9"))
|
ERC20Token token = new ERC20Token(Address.from("0x54EedeAC495271d0F6B175474E89094C44Da98b9"))
|
||||||
ERC20Balance query = new ERC20Balance()
|
ERC20Balance query = new ERC20Balance()
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import io.emeraldpay.dshackle.data.BlockContainer
|
|||||||
import io.emeraldpay.dshackle.data.BlockId
|
import io.emeraldpay.dshackle.data.BlockId
|
||||||
import io.emeraldpay.dshackle.data.TxContainer
|
import io.emeraldpay.dshackle.data.TxContainer
|
||||||
import io.emeraldpay.dshackle.data.TxId
|
import io.emeraldpay.dshackle.data.TxId
|
||||||
|
import io.emeraldpay.dshackle.test.EthereumPosRpcUpstreamMock
|
||||||
import io.emeraldpay.dshackle.test.EthereumRpcUpstreamMock
|
import io.emeraldpay.dshackle.test.EthereumRpcUpstreamMock
|
||||||
import io.emeraldpay.dshackle.test.TestingCommons
|
import io.emeraldpay.dshackle.test.TestingCommons
|
||||||
import io.emeraldpay.dshackle.upstream.Multistream
|
import io.emeraldpay.dshackle.upstream.Multistream
|
||||||
@@ -203,7 +204,7 @@ class EthereumReaderSpec extends Specification {
|
|||||||
api.answerOnce("eth_getBalance", ["0x70b91ff87a902b53dc6e2f6bda8bb9b330ccd30c", "latest"], "0x10")
|
api.answerOnce("eth_getBalance", ["0x70b91ff87a902b53dc6e2f6bda8bb9b330ccd30c", "latest"], "0x10")
|
||||||
// height 101 + 1 => 102 => 0x66
|
// height 101 + 1 => 102 => 0x66
|
||||||
api.answerOnce("eth_getBalance", ["0x70b91ff87a902b53dc6e2f6bda8bb9b330ccd30c", "0x66"], "0xff")
|
api.answerOnce("eth_getBalance", ["0x70b91ff87a902b53dc6e2f6bda8bb9b330ccd30c", "0x66"], "0xff")
|
||||||
EthereumRpcUpstreamMock upstream = new EthereumRpcUpstreamMock(Chain.ETHEREUM, api)
|
EthereumPosRpcUpstreamMock upstream = new EthereumPosRpcUpstreamMock(Chain.ETHEREUM, api)
|
||||||
def upstreams = TestingCommons.multistream(upstream)
|
def upstreams = TestingCommons.multistream(upstream)
|
||||||
def reader = new EthereumReader(upstreams, Caches.default(), calls)
|
def reader = new EthereumReader(upstreams, Caches.default(), calls)
|
||||||
reader.start()
|
reader.start()
|
||||||
@@ -241,7 +242,7 @@ class EthereumReaderSpec extends Specification {
|
|||||||
api.answerOnce("eth_getTransactionReceipt", ["0xf85b826fdf98ee0f48f7db001be00472e63ceb056846f4ecac5f0c32878b8ab2"], [
|
api.answerOnce("eth_getTransactionReceipt", ["0xf85b826fdf98ee0f48f7db001be00472e63ceb056846f4ecac5f0c32878b8ab2"], [
|
||||||
transactionHash: "0xf85b826fdf98ee0f48f7db001be00472e63ceb056846f4ecac5f0c32878b8ab2"
|
transactionHash: "0xf85b826fdf98ee0f48f7db001be00472e63ceb056846f4ecac5f0c32878b8ab2"
|
||||||
])
|
])
|
||||||
EthereumRpcUpstreamMock upstream = new EthereumRpcUpstreamMock(Chain.ETHEREUM, api)
|
EthereumPosRpcUpstreamMock upstream = new EthereumPosRpcUpstreamMock(Chain.ETHEREUM, api)
|
||||||
def upstreams = TestingCommons.multistream(upstream)
|
def upstreams = TestingCommons.multistream(upstream)
|
||||||
def reader = new EthereumReader(upstreams, Caches.default(), calls)
|
def reader = new EthereumReader(upstreams, Caches.default(), calls)
|
||||||
reader.start()
|
reader.start()
|
||||||
@@ -257,7 +258,7 @@ class EthereumReaderSpec extends Specification {
|
|||||||
def "Read receipt from cache if available"() {
|
def "Read receipt from cache if available"() {
|
||||||
setup:
|
setup:
|
||||||
def api = TestingCommons.api()
|
def api = TestingCommons.api()
|
||||||
EthereumRpcUpstreamMock upstream = new EthereumRpcUpstreamMock(Chain.ETHEREUM, api)
|
EthereumPosRpcUpstreamMock upstream = new EthereumPosRpcUpstreamMock(Chain.ETHEREUM, api)
|
||||||
def upstreams = TestingCommons.multistream(upstream)
|
def upstreams = TestingCommons.multistream(upstream)
|
||||||
def receiptCache = Mock(ReceiptRedisCache) {
|
def receiptCache = Mock(ReceiptRedisCache) {
|
||||||
1 * it.read(TxId.from("0xf85b826fdf98ee0f48f7db001be00472e63ceb056846f4ecac5f0c32878b8ab2")) >>
|
1 * it.read(TxId.from("0xf85b826fdf98ee0f48f7db001be00472e63ceb056846f4ecac5f0c32878b8ab2")) >>
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ class EthereumSubscribeSpec extends Specification {
|
|||||||
|
|
||||||
def "read empty logs request"() {
|
def "read empty logs request"() {
|
||||||
setup:
|
setup:
|
||||||
def ethereumSubscribe = new EthereumSubscribe(TestingCommons.emptyMultistream() as EthereumMultistream)
|
def ethereumSubscribe = new EthereumSubscribe(TestingCommons.emptyMultistream() as EthereumPosMultiStream)
|
||||||
when:
|
when:
|
||||||
def act = ethereumSubscribe.readLogsRequest([:])
|
def act = ethereumSubscribe.readLogsRequest([:])
|
||||||
|
|
||||||
@@ -35,7 +35,7 @@ class EthereumSubscribeSpec extends Specification {
|
|||||||
|
|
||||||
def "read single address logs request"() {
|
def "read single address logs request"() {
|
||||||
setup:
|
setup:
|
||||||
def ethereumSubscribe = new EthereumSubscribe(TestingCommons.emptyMultistream() as EthereumMultistream)
|
def ethereumSubscribe = new EthereumSubscribe(TestingCommons.emptyMultistream() as EthereumPosMultiStream)
|
||||||
when:
|
when:
|
||||||
def act = ethereumSubscribe.readLogsRequest([
|
def act = ethereumSubscribe.readLogsRequest([
|
||||||
address: "0x829bd824b016326a401d083b33d092293333a830"
|
address: "0x829bd824b016326a401d083b33d092293333a830"
|
||||||
@@ -60,7 +60,7 @@ class EthereumSubscribeSpec extends Specification {
|
|||||||
|
|
||||||
def "ignores invalid address for logs request"() {
|
def "ignores invalid address for logs request"() {
|
||||||
setup:
|
setup:
|
||||||
def ethereumSubscribe = new EthereumSubscribe(TestingCommons.emptyMultistream() as EthereumMultistream)
|
def ethereumSubscribe = new EthereumSubscribe(TestingCommons.emptyMultistream() as EthereumPosMultiStream)
|
||||||
when:
|
when:
|
||||||
def act = ethereumSubscribe.readLogsRequest([
|
def act = ethereumSubscribe.readLogsRequest([
|
||||||
address: "829bd824b016326a401d083b33d092293333a830"
|
address: "829bd824b016326a401d083b33d092293333a830"
|
||||||
@@ -73,7 +73,7 @@ class EthereumSubscribeSpec extends Specification {
|
|||||||
|
|
||||||
def "read multi address logs request"() {
|
def "read multi address logs request"() {
|
||||||
setup:
|
setup:
|
||||||
def ethereumSubscribe = new EthereumSubscribe(TestingCommons.emptyMultistream() as EthereumMultistream)
|
def ethereumSubscribe = new EthereumSubscribe(TestingCommons.emptyMultistream() as EthereumPosMultiStream)
|
||||||
when:
|
when:
|
||||||
def act = ethereumSubscribe.readLogsRequest([
|
def act = ethereumSubscribe.readLogsRequest([
|
||||||
address: ["0x829bd824b016326a401d083b33d092293333a830", "0x401d083b33d092293333a83829bd824b016326a0"]
|
address: ["0x829bd824b016326a401d083b33d092293333a830", "0x401d083b33d092293333a83829bd824b016326a0"]
|
||||||
@@ -89,7 +89,7 @@ class EthereumSubscribeSpec extends Specification {
|
|||||||
|
|
||||||
def "read single topic logs request"() {
|
def "read single topic logs request"() {
|
||||||
setup:
|
setup:
|
||||||
def ethereumSubscribe = new EthereumSubscribe(TestingCommons.emptyMultistream() as EthereumMultistream)
|
def ethereumSubscribe = new EthereumSubscribe(TestingCommons.emptyMultistream() as EthereumPosMultiStream)
|
||||||
when:
|
when:
|
||||||
def act = ethereumSubscribe.readLogsRequest([
|
def act = ethereumSubscribe.readLogsRequest([
|
||||||
topics: "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"
|
topics: "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"
|
||||||
@@ -114,7 +114,7 @@ class EthereumSubscribeSpec extends Specification {
|
|||||||
|
|
||||||
def "read invalid topic for request"() {
|
def "read invalid topic for request"() {
|
||||||
setup:
|
setup:
|
||||||
def ethereumSubscribe = new EthereumSubscribe(TestingCommons.emptyMultistream() as EthereumMultistream)
|
def ethereumSubscribe = new EthereumSubscribe(TestingCommons.emptyMultistream() as EthereumPosMultiStream)
|
||||||
when:
|
when:
|
||||||
def act = ethereumSubscribe.readLogsRequest([
|
def act = ethereumSubscribe.readLogsRequest([
|
||||||
topics: [
|
topics: [
|
||||||
@@ -132,7 +132,7 @@ class EthereumSubscribeSpec extends Specification {
|
|||||||
|
|
||||||
def "read multi topic logs request"() {
|
def "read multi topic logs request"() {
|
||||||
setup:
|
setup:
|
||||||
def ethereumSubscribe = new EthereumSubscribe(TestingCommons.emptyMultistream() as EthereumMultistream)
|
def ethereumSubscribe = new EthereumSubscribe(TestingCommons.emptyMultistream() as EthereumPosMultiStream)
|
||||||
when:
|
when:
|
||||||
def act = ethereumSubscribe.readLogsRequest([
|
def act = ethereumSubscribe.readLogsRequest([
|
||||||
topics: [
|
topics: [
|
||||||
@@ -151,7 +151,7 @@ class EthereumSubscribeSpec extends Specification {
|
|||||||
|
|
||||||
def "read full logs request"() {
|
def "read full logs request"() {
|
||||||
setup:
|
setup:
|
||||||
def ethereumSubscribe = new EthereumSubscribe(TestingCommons.emptyMultistream() as EthereumMultistream)
|
def ethereumSubscribe = new EthereumSubscribe(TestingCommons.emptyMultistream() as EthereumPosMultiStream)
|
||||||
when:
|
when:
|
||||||
def act = ethereumSubscribe.readLogsRequest([
|
def act = ethereumSubscribe.readLogsRequest([
|
||||||
address: "0x298d492e8c1d909d3f63bc4a36c66c64acb3d695",
|
address: "0x298d492e8c1d909d3f63bc4a36c66c64acb3d695",
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ package io.emeraldpay.dshackle.upstream.ethereum.subscribe
|
|||||||
|
|
||||||
import io.emeraldpay.dshackle.test.TestingCommons
|
import io.emeraldpay.dshackle.test.TestingCommons
|
||||||
import io.emeraldpay.dshackle.upstream.ethereum.EthereumMultistream
|
import io.emeraldpay.dshackle.upstream.ethereum.EthereumMultistream
|
||||||
|
import io.emeraldpay.dshackle.upstream.ethereum.EthereumPosMultiStream
|
||||||
import io.emeraldpay.dshackle.upstream.ethereum.subscribe.json.LogMessage
|
import io.emeraldpay.dshackle.upstream.ethereum.subscribe.json.LogMessage
|
||||||
import io.emeraldpay.etherjar.domain.Address
|
import io.emeraldpay.etherjar.domain.Address
|
||||||
import io.emeraldpay.etherjar.domain.BlockHash
|
import io.emeraldpay.etherjar.domain.BlockHash
|
||||||
@@ -86,7 +87,7 @@ class ConnectLogsSpec extends Specification {
|
|||||||
|
|
||||||
def "Filter is empty"() {
|
def "Filter is empty"() {
|
||||||
setup:
|
setup:
|
||||||
def connectLogs = new ConnectLogs(TestingCommons.emptyMultistream() as EthereumMultistream)
|
def connectLogs = new ConnectLogs(TestingCommons.emptyMultistream() as EthereumPosMultiStream)
|
||||||
when:
|
when:
|
||||||
def input = Flux.fromIterable([
|
def input = Flux.fromIterable([
|
||||||
log1, log2, log3, log4
|
log1, log2, log3, log4
|
||||||
@@ -104,7 +105,7 @@ class ConnectLogsSpec extends Specification {
|
|||||||
|
|
||||||
def "Filter by address"() {
|
def "Filter by address"() {
|
||||||
setup:
|
setup:
|
||||||
def connectLogs = new ConnectLogs(TestingCommons.emptyMultistream() as EthereumMultistream)
|
def connectLogs = new ConnectLogs(TestingCommons.emptyMultistream() as EthereumPosMultiStream)
|
||||||
when:
|
when:
|
||||||
def input = Flux.fromIterable([
|
def input = Flux.fromIterable([
|
||||||
log1, log2
|
log1, log2
|
||||||
@@ -119,7 +120,7 @@ class ConnectLogsSpec extends Specification {
|
|||||||
|
|
||||||
def "Filter by topic"() {
|
def "Filter by topic"() {
|
||||||
setup:
|
setup:
|
||||||
def connectLogs = new ConnectLogs(TestingCommons.emptyMultistream() as EthereumMultistream)
|
def connectLogs = new ConnectLogs(TestingCommons.emptyMultistream() as EthereumPosMultiStream)
|
||||||
when:
|
when:
|
||||||
def input = Flux.fromIterable([
|
def input = Flux.fromIterable([
|
||||||
log1, log2, log3, log4
|
log1, log2, log3, log4
|
||||||
@@ -136,7 +137,7 @@ class ConnectLogsSpec extends Specification {
|
|||||||
|
|
||||||
def "Filter by address and topic"() {
|
def "Filter by address and topic"() {
|
||||||
setup:
|
setup:
|
||||||
def connectLogs = new ConnectLogs(TestingCommons.emptyMultistream() as EthereumMultistream)
|
def connectLogs = new ConnectLogs(TestingCommons.emptyMultistream() as EthereumPosMultiStream)
|
||||||
when:
|
when:
|
||||||
def input = Flux.fromIterable([
|
def input = Flux.fromIterable([
|
||||||
log1, log2, log3, log4
|
log1, log2, log3, log4
|
||||||
|
|||||||
Reference in New Issue
Block a user