-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
solution: integration test with two upstreams
- Loading branch information
Showing
8 changed files
with
130 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
testing/simple-upstream/src/main/groovy/testing/InternalHandler.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package testing | ||
|
||
import java.time.Instant | ||
import java.util.concurrent.atomic.AtomicInteger | ||
|
||
class InternalHandler implements CallHandler { | ||
|
||
private AtomicInteger ids = new AtomicInteger() | ||
private List<Item> requests = new ArrayList() | ||
|
||
def record(String json) { | ||
requests << new Item(ids.getAndIncrement(), json) | ||
} | ||
|
||
@Override | ||
Result handle(String method, List<Object> params) { | ||
if (method == "eth_call" | ||
&& params[0].to?.toLowerCase() == "0x0123456789abcdef0123456789abcdef00000002".toLowerCase()) { | ||
return Result.ok(Collections.unmodifiableList(requests)) | ||
} | ||
return null | ||
} | ||
|
||
class Item { | ||
Integer id | ||
String timestamp | ||
String json | ||
|
||
Item(Integer id, String json) { | ||
this.id = id | ||
this.timestamp = Instant.now().toString() | ||
this.json = json | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
testing/simple-upstream/src/main/groovy/testing/PingPongHandler.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package testing | ||
|
||
class PingPongHandler implements CallHandler { | ||
@Override | ||
Result handle(String method, List<Object> params) { | ||
if (method == "eth_call" | ||
&& params[0].to?.toLowerCase() == "0x0123456789abcdef0123456789abcdef00000001".toLowerCase()) { | ||
return Result.ok([data: params[0].data]) | ||
} | ||
return null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
testing/trial/src/test/groovy/io/emeraldpay/dshackle/testing/trial/proxy/DispatchSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package io.emeraldpay.dshackle.testing.trial.proxy | ||
|
||
import io.emeraldpay.dshackle.testing.trial.ProxyClient | ||
import spock.lang.Specification | ||
|
||
class DispatchSpec extends Specification { | ||
|
||
def client = ProxyClient.forPrefix("eth") | ||
|
||
def "multiple calls routed roughly equal to upstreams"() { | ||
when: | ||
def calls1before = ProxyClient.forOriginal(18545).execute("eth_call", [[to: "0x0123456789abcdef0123456789abcdef00000002"]]).result as List | ||
def calls2before = ProxyClient.forOriginal(18546).execute("eth_call", [[to: "0x0123456789abcdef0123456789abcdef00000002"]]).result as List | ||
|
||
100.times { | ||
client.execute("eth_call", [[to: "0x0123456789abcdef0123456789abcdef00000001", data: "0x00000000" + Integer.toString(it, 16)]]) | ||
} | ||
|
||
def calls1after = ProxyClient.forOriginal(18545).execute("eth_call", [[to: "0x0123456789abcdef0123456789abcdef00000002"]]).result as List | ||
def calls2after = ProxyClient.forOriginal(18546).execute("eth_call", [[to: "0x0123456789abcdef0123456789abcdef00000002"]]).result as List | ||
|
||
def calls1 = onlyNew(calls1before, calls1after) | ||
def calls2 = onlyNew(calls2before, calls2after) | ||
|
||
then: | ||
calls1.size() >= 48 | ||
calls2.size() >= 48 | ||
calls1.size() + calls2.size() == 100 | ||
} | ||
|
||
private List onlyNew(List before, List after) { | ||
return after.findAll { a -> | ||
!before.any { b -> | ||
b.id == a.id | ||
} | ||
}.findAll { | ||
(it.json as String).contains("0x0123456789abcdef0123456789abcdef00000001") | ||
} | ||
} | ||
} |