slot height matcher implementation (#353)

This commit is contained in:
Vyacheslav
2023-11-28 15:52:55 +02:00
committed by GitHub
parent bb3d56856c
commit 353a483cce
10 changed files with 81 additions and 4 deletions

View File

@@ -68,6 +68,11 @@ class EthereumHeadMock implements Head {
return latest?.height
}
@Override
Long getCurrentSlotHeight() {
return latest?.slot
}
@Override
void start() {

View File

@@ -462,7 +462,7 @@ class FilteredApisSpec extends Specification {
_ * getRole() >> UpstreamsConfig.UpstreamRole.PRIMARY
_ * isAvailable() >> true
_ * getHead() >> Mock(Head) {
_ * getCurrentHeight() >> 100000001
_ * getCurrentSlotHeight() >> 100000001
}
_ * getStatus() >> UpstreamAvailability.OK
_ * getLabels() >> of(UpstreamsConfig.Labels.fromMap(Map.of("node", "test")))
@@ -474,7 +474,7 @@ class FilteredApisSpec extends Specification {
_ * getId() >> "id1"
_ * getStatus() >> UpstreamAvailability.OK
_ * getHead() >> Mock(Head) {
_ * getCurrentHeight() >> 100000
_ * getCurrentSlotHeight() >> 100000
}
_ * getLabels() >> of(UpstreamsConfig.Labels.fromMap(Map.of("node", "archive")))
}, up
@@ -484,7 +484,7 @@ class FilteredApisSpec extends Specification {
Chain.ETHEREUM__MAINNET, ups,
new Selector.MultiMatcher(
of(
new Selector.HeightMatcher(100000000),
new Selector.SlotMatcher(100000000),
new Selector.LabelMatcher("node", of("test"))
)
)

View File

@@ -32,6 +32,21 @@ class SelectorSpec extends Specification {
private BlockchainOuterClass.Selector selectLabel2Selector = BlockchainOuterClass.Selector.newBuilder()
.setLabelSelector(selectLabel2).build()
def "Convert slot height selector"() {
setup:
def slotHeightSelector = BlockchainOuterClass.Selector.newBuilder()
.setSlotHeightSelector(
BlockchainOuterClass.SlotHeightSelector.newBuilder()
.setSlotHeight(10000)
.build()
)
.build()
when:
def act = Selector.convertToMatcher(List.of(slotHeightSelector), Stub(Head))
then:
act == new Selector.MultiMatcher(List.of(new Selector.SlotMatcher(10000)))
}
def "Convert height selector"() {
setup:
def heightSelector = BlockchainOuterClass.Selector.newBuilder()