Revert "Sync upstream 7.12.2022"

This commit is contained in:
a10zn8
2022-12-09 14:00:45 +04:00
committed by GitHub
parent 20564e58ba
commit dca78160ba
95 changed files with 8426 additions and 446 deletions

View File

@@ -23,7 +23,7 @@ class CacheConfigReaderSpec extends Specification {
def "Read full"() {
setup:
def config = this.class.getClassLoader().getResourceAsStream("configs/cache-redis-full.yaml")
def config = this.class.getClassLoader().getResourceAsStream("cache-redis-full.yaml")
when:
def act = reader.read(config)
@@ -39,7 +39,7 @@ class CacheConfigReaderSpec extends Specification {
def "Read disabled"() {
setup:
def config = this.class.getClassLoader().getResourceAsStream("configs/cache-redis-disabled.yaml")
def config = this.class.getClassLoader().getResourceAsStream("cache-redis-disabled.yaml")
when:
def act = reader.read(config)

View File

@@ -24,7 +24,7 @@ class HealthConfigReaderSpec extends Specification {
def "Read empty"() {
setup:
def config = this.class.getClassLoader().getResourceAsStream("configs/dshackle-health-empty.yaml")
def config = this.class.getClassLoader().getResourceAsStream("dshackle-health-empty.yaml")
when:
def act = reader.read(config)
@@ -38,7 +38,7 @@ class HealthConfigReaderSpec extends Specification {
def "Read single"() {
setup:
def config = this.class.getClassLoader().getResourceAsStream("configs/dshackle-health-1.yaml")
def config = this.class.getClassLoader().getResourceAsStream("dshackle-health-1.yaml")
when:
def act = reader.read(config)
@@ -58,7 +58,7 @@ class HealthConfigReaderSpec extends Specification {
def "Read multiple"() {
setup:
def config = this.class.getClassLoader().getResourceAsStream("configs/dshackle-health-2.yaml")
def config = this.class.getClassLoader().getResourceAsStream("dshackle-health-2.yaml")
when:
def act = reader.read(config)

View File

@@ -22,12 +22,11 @@ import spock.lang.Specification
class MainConfigReaderSpec extends Specification {
def "Read full config with inclusion"() {
MainConfigReader reader = new MainConfigReader(TestingCommons.fileResolver())
def "Read full config"() {
setup:
// the File Resolver should be able to resolve/include files
MainConfigReader reader = new MainConfigReader(TestingCommons.fileResolver())
// note that it references another config to be included
def config = this.class.getClassLoader().getResourceAsStream("configs/dshackle-full.yaml")
def config = this.class.getClassLoader().getResourceAsStream("dshackle-full.yaml")
when:
def act = reader.read(config)

View File

@@ -23,7 +23,7 @@ class MonitoringConfigReaderSpec extends Specification {
def "Read basic monitoring config"() {
setup:
def config = this.class.getClassLoader().getResourceAsStream("configs/dshackle-monitoring-basic.yaml")
def config = this.class.getClassLoader().getResourceAsStream("dshackle-monitoring-basic.yaml")
when:
def act = reader.read(config)

View File

@@ -24,7 +24,7 @@ class ProxyConfigReaderSpec extends Specification {
def "Read basic proxy config"() {
setup:
def config = this.class.getClassLoader().getResourceAsStream("configs/dshackle-proxy-basic.yaml")
def config = this.class.getClassLoader().getResourceAsStream("dshackle-proxy-basic.yaml")
when:
def act = reader.read(config)
@@ -42,7 +42,7 @@ class ProxyConfigReaderSpec extends Specification {
def "Read proxy config with websocket disabled"() {
setup:
def config = this.class.getClassLoader().getResourceAsStream("configs/dshackle-proxy-no-ws.yaml")
def config = this.class.getClassLoader().getResourceAsStream("dshackle-proxy-no-ws.yaml")
when:
def act = reader.read(config)
@@ -53,7 +53,7 @@ class ProxyConfigReaderSpec extends Specification {
def "Read proxy config with two elements"() {
setup:
def config = this.class.getClassLoader().getResourceAsStream("configs/dshackle-proxy-two.yaml")
def config = this.class.getClassLoader().getResourceAsStream("dshackle-proxy-two.yaml")
when:
def act = reader.read(config)
@@ -73,7 +73,7 @@ class ProxyConfigReaderSpec extends Specification {
def "Read max proxy config"() {
setup:
def config = this.class.getClassLoader().getResourceAsStream("configs/dshackle-proxy-max.yaml")
def config = this.class.getClassLoader().getResourceAsStream("dshackle-proxy-max.yaml")
when:
def act = reader.read(config)

View File

@@ -25,7 +25,7 @@ class UpstreamsConfigReaderSpec extends Specification {
def "Parse standard config"() {
setup:
def config = this.class.getClassLoader().getResourceAsStream("configs/upstreams-basic.yaml")
def config = this.class.getClassLoader().getResourceAsStream("upstreams-basic.yaml")
when:
def act = reader.read(config)
then:
@@ -73,7 +73,7 @@ class UpstreamsConfigReaderSpec extends Specification {
def "Parse websocket-only config"() {
setup:
def config = this.class.getClassLoader().getResourceAsStream("configs/upstreams-ws-only.yaml")
def config = this.class.getClassLoader().getResourceAsStream("upstreams-ws-only.yaml")
when:
def act = reader.read(config)
then:
@@ -98,7 +98,7 @@ class UpstreamsConfigReaderSpec extends Specification {
def "Parse full defined websocket config"() {
setup:
def config = this.class.getClassLoader().getResourceAsStream("configs/upstreams-ws-full.yaml")
def config = this.class.getClassLoader().getResourceAsStream("upstreams-ws-full.yaml")
when:
def act = reader.read(config)
then:
@@ -125,7 +125,7 @@ class UpstreamsConfigReaderSpec extends Specification {
def "Parse bitcoin upstreams"() {
setup:
def config = this.class.getClassLoader().getResourceAsStream("configs/upstreams-bitcoin.yaml")
def config = this.class.getClassLoader().getResourceAsStream("upstreams-bitcoin.yaml")
when:
def act = reader.read(config)
then:
@@ -173,7 +173,7 @@ class UpstreamsConfigReaderSpec extends Specification {
def "Parse bitcoin upstreams with esplora"() {
setup:
def config = this.class.getClassLoader().getResourceAsStream("configs/upstreams-bitcoin-esplora.yaml")
def config = this.class.getClassLoader().getResourceAsStream("upstreams-bitcoin-esplora.yaml")
when:
def act = reader.read(config)
then:
@@ -202,7 +202,7 @@ class UpstreamsConfigReaderSpec extends Specification {
def "Parse ds config"() {
setup:
def config = this.class.getClassLoader().getResourceAsStream("configs/upstreams-ds.yaml")
def config = this.class.getClassLoader().getResourceAsStream("upstreams-ds.yaml")
when:
def act = reader.read(config)
then:
@@ -225,7 +225,7 @@ class UpstreamsConfigReaderSpec extends Specification {
def "Parse config with labels"() {
setup:
def config = this.class.getClassLoader().getResourceAsStream("configs/upstreams-labels.yaml")
def config = this.class.getClassLoader().getResourceAsStream("upstreams-labels.yaml")
when:
def act = reader.read(config)
then:
@@ -246,7 +246,7 @@ class UpstreamsConfigReaderSpec extends Specification {
def "Parse config with options"() {
setup:
def config = this.class.getClassLoader().getResourceAsStream("configs/upstreams-options.yaml")
def config = this.class.getClassLoader().getResourceAsStream("upstreams-options.yaml")
when:
def act = reader.read(config)
then:
@@ -262,7 +262,7 @@ class UpstreamsConfigReaderSpec extends Specification {
def "Parse config without defaults"() {
setup:
def config = this.class.getClassLoader().getResourceAsStream("configs/upstreams-no-defaults.yaml")
def config = this.class.getClassLoader().getResourceAsStream("upstreams-no-defaults.yaml")
when:
def act = reader.read(config)
then:
@@ -285,7 +285,7 @@ class UpstreamsConfigReaderSpec extends Specification {
def "Parse config with methods"() {
setup:
def config = this.class.getClassLoader().getResourceAsStream("configs/upstreams-methods.yaml")
def config = this.class.getClassLoader().getResourceAsStream("upstreams-methods.yaml")
when:
def act = reader.read(config)
then:
@@ -305,7 +305,7 @@ class UpstreamsConfigReaderSpec extends Specification {
def "Parse config with methods and quorum"() {
setup:
def config = this.class.getClassLoader().getResourceAsStream("configs/upstreams-methods-quorum.yaml")
def config = this.class.getClassLoader().getResourceAsStream("upstreams-methods-quorum.yaml")
when:
def act = reader.read(config)
then:
@@ -328,7 +328,7 @@ class UpstreamsConfigReaderSpec extends Specification {
def "Parse config with invalid ids"() {
setup:
def config = this.class.getClassLoader().getResourceAsStream("configs/upstreams-no-id.yaml")
def config = this.class.getClassLoader().getResourceAsStream("upstreams-no-id.yaml")
when:
def act = reader.read(config)
then:
@@ -355,7 +355,7 @@ class UpstreamsConfigReaderSpec extends Specification {
def "Parse config without fallback role"() {
setup:
def config = this.class.getClassLoader().getResourceAsStream("configs/upstreams-basic.yaml")
def config = this.class.getClassLoader().getResourceAsStream("upstreams-basic.yaml")
when:
def act = reader.read(config)
then:
@@ -367,7 +367,7 @@ class UpstreamsConfigReaderSpec extends Specification {
def "Parse config with fallback role"() {
setup:
def config = this.class.getClassLoader().getResourceAsStream("configs/upstreams-roles.yaml")
def config = this.class.getClassLoader().getResourceAsStream("upstreams-roles.yaml")
when:
def act = reader.read(config)
then:
@@ -379,7 +379,7 @@ class UpstreamsConfigReaderSpec extends Specification {
def "Parse config with secondary role"() {
setup:
def config = this.class.getClassLoader().getResourceAsStream("configs/upstreams-roles-2.yaml")
def config = this.class.getClassLoader().getResourceAsStream("upstreams-roles-2.yaml")
when:
def act = reader.read(config)
then:
@@ -392,7 +392,7 @@ class UpstreamsConfigReaderSpec extends Specification {
def "Parse config with invalid role"() {
setup:
def config = this.class.getClassLoader().getResourceAsStream("configs/upstreams-roles-invalid.yaml")
def config = this.class.getClassLoader().getResourceAsStream("upstreams-roles-invalid.yaml")
when:
def act = reader.read(config)
then:

View File

@@ -34,8 +34,6 @@ import io.emeraldpay.dshackle.upstream.Selector
import io.emeraldpay.dshackle.upstream.MultistreamHolder
import io.emeraldpay.dshackle.upstream.calls.DefaultEthereumMethods
import io.emeraldpay.dshackle.upstream.calls.ManagedCallMethods
import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcError
import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcException
import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest
import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse
import io.emeraldpay.dshackle.upstream.signature.ResponseSigner
@@ -155,35 +153,6 @@ class NativeCallSpec extends Specification {
.verify(Duration.ofSeconds(1))
}
def "Returns error details from remote"() {
setup:
def quorum = new AlwaysQuorum()
def nativeCall = nativeCall()
nativeCall.quorumReaderFactory = Mock(QuorumReaderFactory) {
1 * create(_, _, _) >> Mock(Reader) {
1 * read(new JsonRpcRequest("eth_test", [], 10)) >> Mono.error(
new JsonRpcException(JsonRpcResponse.Id.from(12), new JsonRpcError(-32123, "Foo Bar", "Foo Bar Baz"))
)
}
}
def call = new NativeCall.ValidCallContext(12, 10, TestingCommons.multistream(TestingCommons.api()), Selector.empty, quorum,
new NativeCall.ParsedCallDetails("eth_test", []))
when:
def resp = nativeCall.executeOnRemote(call).block(Duration.ofSeconds(1))
then:
resp.isError()
with(resp.getError()) {
message == "Foo Bar"
upstreamError != null
with (upstreamError) {
code == -32123
details == "Foo Bar Baz"
}
}
}
def "Packs call exception into response with id"() {
setup:
def nativeCall = nativeCall()

View File

@@ -26,6 +26,14 @@ class MockGrpcServer {
GrpcCleanupRule grpcCleanup = new GrpcCleanupRule()
ReactorBlockchainGrpc.ReactorBlockchainStub clientForServer(ReactorBlockchainGrpc.BlockchainImplBase impl) {
String serverName = InProcessServerBuilder.generateName()
grpcCleanup.register(InProcessServerBuilder
.forName(serverName).directExecutor().addService(impl).build().start());
def channel = grpcCleanup.register(InProcessChannelBuilder.forName(serverName).directExecutor().build())
return ReactorBlockchainGrpc.newReactorStub(channel)
}
ReactorBlockchainGrpc.ReactorBlockchainStub clientForServer(BlockchainGrpc.BlockchainImplBase impl){
String serverName = InProcessServerBuilder.generateName()
grpcCleanup.register(InProcessServerBuilder

View File

@@ -108,7 +108,7 @@ class TestingCommons {
}
static FileResolver fileResolver() {
return new FileResolver(new File("src/test/resources/configs"))
return new FileResolver(new File("src/test/resources"))
}
static BlockContainer blockForEthereum(Long height) {

View File

@@ -92,7 +92,7 @@ class WsConnectionSpec extends Specification {
it.id.asNumber() == 15L && Global.objectMapper.readValue(it.result, TransactionJson) == tx
}
.expectComplete()
.verify(Duration.ofSeconds(1))
.verify(Duration.ofSeconds(5))
}
def "Makes a RPC call - return null"() {
@@ -115,7 +115,7 @@ class WsConnectionSpec extends Specification {
it.resultAsRawString == 'null'
}
.expectComplete()
.verify(Duration.ofSeconds(1))
.verify(Duration.ofSeconds(5))
}
def "Makes a RPC call - return error"() {
@@ -140,6 +140,6 @@ class WsConnectionSpec extends Specification {
it.error.code == RpcResponseError.CODE_METHOD_NOT_EXIST && it.error.message == "test"
}
.expectComplete()
.verify(Duration.ofSeconds(1))
.verify(Duration.ofSeconds(5))
}
}

View File

@@ -1,88 +0,0 @@
package io.emeraldpay.dshackle.upstream.rpcclient
import com.google.protobuf.ByteString
import io.emeraldpay.api.proto.BlockchainGrpc
import io.emeraldpay.api.proto.BlockchainOuterClass
import io.emeraldpay.api.proto.Common
import io.emeraldpay.dshackle.test.MockGrpcServer
import io.emeraldpay.dshackle.upstream.Selector
import io.emeraldpay.etherjar.rpc.RpcException
import io.emeraldpay.etherjar.rpc.RpcResponseError
import io.emeraldpay.dshackle.Chain
import io.grpc.stub.StreamObserver
import spock.lang.Specification
import java.time.Duration
import java.util.concurrent.atomic.AtomicReference
class JsonRpcGrpcClientSpec extends Specification {
def "Makes a request"() {
setup:
def mockGrpc = new MockGrpcServer()
def requested = new AtomicReference<BlockchainOuterClass.NativeCallRequest>()
def grpc = mockGrpc.clientForServer(new BlockchainGrpc.BlockchainImplBase() {
@Override
void nativeCall(BlockchainOuterClass.NativeCallRequest request, StreamObserver<BlockchainOuterClass.NativeCallReplyItem> responseObserver) {
requested.set(request)
responseObserver.onNext(BlockchainOuterClass.NativeCallReplyItem.newBuilder()
.setId(1)
.setSucceed(true)
.setPayload(ByteString.copyFromUtf8("\"hello world!\""))
.build())
responseObserver.onCompleted()
}
})
def client = new JsonRpcGrpcClient(
grpc, Chain.BITCOIN, null
).getReader()
when:
def act = client.read(
new JsonRpcRequest("test", [])
).block(Duration.ofSeconds(1))
then:
!act.hasError()
act.resultAsProcessedString == "hello world!"
requested.get() == BlockchainOuterClass.NativeCallRequest.newBuilder()
.setChain(Common.ChainRef.CHAIN_BITCOIN)
.addAllItems([
BlockchainOuterClass.NativeCallItem.newBuilder()
.setId(1)
.setMethod("test")
.setPayload(ByteString.copyFromUtf8("[]"))
.build()
])
.build()
}
def "Return error on HTTP error"() {
setup:
def mockGrpc = new MockGrpcServer()
def grpc = mockGrpc.clientForServer(new BlockchainGrpc.BlockchainImplBase() {
@Override
void nativeCall(BlockchainOuterClass.NativeCallRequest request, StreamObserver<BlockchainOuterClass.NativeCallReplyItem> responseObserver) {
responseObserver.onError(new IllegalStateException("fail"))
}
})
def client = new JsonRpcGrpcClient(
grpc, Chain.BITCOIN, null
).getReader()
when:
client.read(
new JsonRpcRequest("test", [])
).block(Duration.ofSeconds(1))
then:
def t = thrown(RpcException)
with(t.error) {
message == "Remote status code: UNKNOWN"
it.code == RpcResponseError.CODE_UPSTREAM_CONNECTION_ERROR
}
}
}

View File

@@ -26,7 +26,6 @@ import org.mockserver.model.HttpRequest
import org.mockserver.model.HttpResponse
import org.mockserver.model.MediaType
import org.springframework.util.SocketUtils
import reactor.core.Exceptions
import reactor.test.StepVerifier
import spock.lang.Specification
@@ -85,7 +84,7 @@ class JsonRpcHttpClientSpec extends Specification {
.withBody("pong")
)
when:
def act = client.execute("ping".bytes).map { new String(it.t2) }
def act = client.execute("ping".bytes).map { new String(it) }
then:
StepVerifier.create(act)
.expectNext("pong")
@@ -112,44 +111,13 @@ class JsonRpcHttpClientSpec extends Specification {
.withBody("pong")
)
when:
def act = client.read(
new JsonRpcRequest("ping", [])
).block(Duration.ofSeconds(1))
def act = client.execute("ping".bytes).map { new String(it) }
then:
def t = thrown(RuntimeException) // reactor.core.Exceptions$ReactiveException
t.cause instanceof JsonRpcException
with(((JsonRpcException)t.cause).error) {
code == RpcResponseError.CODE_UPSTREAM_INVALID_RESPONSE
message == "HTTP Code: 500"
}
}
def "Tries to extract message if HTTP error if it still contains a JSON RPC message"() {
setup:
def client = new JsonRpcHttpClient("localhost:${port}", metrics, null, null)
mockServer.when(
HttpRequest.request()
).respond(
HttpResponse.response()
.withStatusCode(500)
.withBody('{' +
'"jsonrpc": "2.0", ' +
'"id": 1, ' +
'"error": {"code": -32603, "message": "Something happened"}' +
'}')
)
when:
def act = client.read(
new JsonRpcRequest("ping", [])
).block(Duration.ofSeconds(1))
then:
def t = thrown(RuntimeException) // reactor.core.Exceptions$ReactiveException
t.cause instanceof JsonRpcException
with(((JsonRpcException)t.cause).error) {
code == -32603
message == "Something happened"
}
StepVerifier.create(act)
.expectErrorMatches { t ->
t instanceof JsonRpcException && t.error.code == RpcResponseError.CODE_UPSTREAM_INVALID_RESPONSE
}
.verify(Duration.ofSeconds(1))
}
}

View File

@@ -223,27 +223,4 @@ class ResponseRpcParserSpec extends Specification {
!act.hasResult()
}
def "Keep provided ID even if JSON is not full"() {
setup:
def json = '{"jsonrpc": "2.0", "id": 1}'
when:
def act = parser.parse(json.getBytes())
then:
act.id.asNumber() == 1
act.error != null
act.hasError()
!act.hasResult()
}
def "Keep provided ID even if JSON is broken"() {
setup:
def json = '{"jsonrpc": "2.0", "id": 101, "resu'
when:
def act = parser.parse(json.getBytes())
then:
act.id.asNumber() == 101
act.error != null
act.hasError()
!act.hasResult()
}
}

View File

@@ -103,24 +103,4 @@ class ResponseWSParserSpec extends Specification {
act.error == null
new String(act.value) == "null"
}
def "Keep provided ID even if JSON is not full"() {
setup:
def json = '{"jsonrpc": "2.0", "id": 1}'
when:
def act = parser.parse(json.getBytes())
then:
act.id.asNumber() == 1
act.error != null
}
def "Keep provided ID even if JSON is broken"() {
setup:
def json = '{"jsonrpc": "2.0", "id": 101, "resu'
when:
def act = parser.parse(json.getBytes())
then:
act.id.asNumber() == 101
act.error != null
}
}

View File

@@ -49,7 +49,7 @@ class EcdsaSignerSpec extends Specification {
setup:
def conf = new SignatureConfig()
conf.enabled = true
conf.privateKey = "src/test/resources/signer/test_key"
conf.privateKey = "testing/dshackle/test_key"
def signer = new ResponseSignerFactory(conf).getObject() as EcdsaSigner
// To verify the test, check the hash of test key above:
@@ -114,7 +114,7 @@ class EcdsaSignerSpec extends Specification {
def conf = new SignatureConfig()
conf.enabled = true
conf.privateKey = "src/test/resources/signer/test_key"
conf.privateKey = "testing/dshackle/test_key"
def factory = new ResponseSignerFactory(conf)
def sk = factory.readKey(conf.algorithm, conf.privateKey).first

View File

@@ -1,26 +0,0 @@
version: v1
upstreams:
- id: local
chain: ethereum
priority: 100
connection:
ethereum:
rpc:
url: "http://localhost:8545"
- id: infura
chain: ethereum
role: fallback
priority: 50
connection:
ethereum:
rpc:
url: "https://mainnet.infura.io/v3/fa28c968191849c1aff541ad1d8511f2"
- id: remote
priority: 75
connection:
grpc:
host: "10.2.0.15"

View File

@@ -1,5 +0,0 @@
-----BEGIN PRIVATE KEY-----
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgWz2Pxo+O3UAWFLqJ
BMLoT8VtWNXn4FHb+VMiyrn0sfehRANCAAR7z21AewiDegaV/4zBkBbNWGOSg1Zo
tE6HGCLMMuKP0XmOg2jVoIvnHJ1OZCIKb236HwnogF4G+o/qlCTi90P1
-----END PRIVATE KEY-----

View File

@@ -1,4 +0,0 @@
-----BEGIN PUBLIC KEY-----
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEe89tQHsIg3oGlf+MwZAWzVhjkoNW
aLROhxgizDLij9F5joNo1aCL5xydTmQiCm9t+h8J6IBeBvqP6pQk4vdD9Q==
-----END PUBLIC KEY-----