Skip to content

Commit 1aac2e9

Browse files
committed
Merge branch 'coordinator-code-reuse-3' into coordinator-code-reuse-4
2 parents 6374430 + 8468afe commit 1aac2e9

File tree

7 files changed

+66
-40
lines changed

7 files changed

+66
-40
lines changed

coordinator/core/src/test/kotlin/net/consensys/zkevm/ethereum/coordination/conflation/BlockToBatchSubmissionCoordinatorTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import org.mockito.kotlin.verify
2424
import org.mockito.kotlin.whenever
2525
import tech.pegasys.teku.ethereum.executionclient.schema.randomExecutionPayload
2626
import tech.pegasys.teku.infrastructure.async.SafeFuture
27-
import kotlin.time.Duration.Companion.milliseconds
27+
import kotlin.time.Duration.Companion.seconds
2828
import kotlin.time.toJavaDuration
2929

3030
@ExtendWith(VertxExtension::class)
@@ -79,7 +79,7 @@ class BlockToBatchSubmissionCoordinatorTest {
7979

8080
val captor = argumentCaptor<Throwable>()
8181
Assertions.assertThat(blockToBatchSubmissionCoordinator.acceptBlock(baseBlock)).isCompleted
82-
Awaitility.await().atMost(200.milliseconds.toJavaDuration())
82+
Awaitility.await().atMost(1.seconds.toJavaDuration())
8383
.untilAsserted {
8484
verify(testLogger, times(1)).error(
8585
eq("Failed to conflate block={} errorMessage={}"),
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package build.linea
2+
3+
import java.net.URI
4+
5+
fun URI.getPortWithSchemeDefaults(): Int {
6+
return if (port != -1) {
7+
port
8+
} else {
9+
when (scheme.lowercase()) {
10+
"http" -> 80
11+
"https" -> 443
12+
// Focous on HTTP as it is what we need for now
13+
else -> throw IllegalArgumentException("Unsupported scheme: $scheme")
14+
}
15+
}
16+
}

jvm-libs/generic/extensions/kotlin/src/test/kotlin/build/linea/URIExtensionsTest.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ import java.net.URI
88
class URIExtensionsTest {
99
@Test
1010
fun `getPortWithSchemaDefaults`() {
11-
assertThat(URI.create("http://example.com").getPortWithSchemaDefaults()).isEqualTo(80)
12-
assertThat(URI.create("https://example.com").getPortWithSchemaDefaults()).isEqualTo(443)
13-
assertThat(URI.create("http://example.com:8080").getPortWithSchemaDefaults()).isEqualTo(8080)
14-
assertThat(URI.create("https://example.com:8080").getPortWithSchemaDefaults()).isEqualTo(8080)
15-
assertThat(URI.create("myschema://example.com:8080").getPortWithSchemaDefaults()).isEqualTo(8080)
16-
assertThatThrownBy { (URI.create("mySchema://example.com").getPortWithSchemaDefaults()) }
11+
assertThat(URI.create("http://example.com").getPortWithSchemeDefaults()).isEqualTo(80)
12+
assertThat(URI.create("https://example.com").getPortWithSchemeDefaults()).isEqualTo(443)
13+
assertThat(URI.create("http://example.com:8080").getPortWithSchemeDefaults()).isEqualTo(8080)
14+
assertThat(URI.create("https://example.com:8080").getPortWithSchemeDefaults()).isEqualTo(8080)
15+
assertThat(URI.create("myschema://example.com:8080").getPortWithSchemeDefaults()).isEqualTo(8080)
16+
assertThatThrownBy { (URI.create("mySchema://example.com").getPortWithSchemeDefaults()) }
1717
.isInstanceOf(IllegalArgumentException::class.java)
1818
.hasMessage("Unsupported scheme: mySchema")
1919
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package net.consensys.linea.vertx
22

3-
import build.linea.getPortWithSchemaDefaults
3+
import build.linea.getPortWithSchemeDefaults
44
import io.vertx.core.http.HttpClientOptions
55
import java.net.URI
66

77
fun <T : HttpClientOptions> T.setDefaultsFrom(uri: URI): T {
88
isSsl = uri.scheme.lowercase() == "https"
99
defaultHost = uri.host
10-
defaultPort = uri.getPortWithSchemaDefaults()
10+
defaultPort = uri.getPortWithSchemeDefaults()
1111

1212
return this
1313
}

jvm-libs/linea/blob-decompressor/src/test/kotlin/net/consensys/linea/blob/BlobDecompressorDataDecodingTest.kt

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ package net.consensys.linea.blob
22

33
import net.consensys.linea.testing.filesystem.findPathTo
44
import org.apache.tuweni.bytes.Bytes
5+
import org.assertj.core.api.Assertions.assertThat
56
import org.hyperledger.besu.ethereum.core.Block
67
import org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions
78
import org.hyperledger.besu.ethereum.rlp.RLP
89
import org.junit.jupiter.api.BeforeEach
910
import org.junit.jupiter.api.Disabled
11+
import org.junit.jupiter.api.Test
1012
import kotlin.io.path.readBytes
1113

1214
class BlobDecompressorDataDecodingTest {
@@ -17,18 +19,21 @@ class BlobDecompressorDataDecodingTest {
1719
decompressor = GoNativeBlobDecompressorFactory.getInstance(BlobDecompressorVersion.V1_1_0)
1820
}
1921

20-
@Disabled("Until Besu supports deserializing transactions without signatures validation")
22+
@Test
2123
fun `can deserialize native lib testdata blobs`() {
2224
val blob = findPathTo("prover")!!
2325
.resolve("lib/compressor/blob/testdata/v0/sample-blob-0151eda71505187b5.bin")
2426
.readBytes()
2527
val decompressedBlob = decompressor.decompress(blob)
2628
val blocksRlpEncoded = rlpDecodeAsListOfBytes(decompressedBlob)
27-
blocksRlpEncoded.forEachIndexed { index, blockRlp ->
28-
val rlpInput = RLP.input(Bytes.wrap(blockRlp))
29-
val decodedBlock = Block.readFrom(rlpInput, MainnetBlockHeaderFunctions())
30-
println("$index: $decodedBlock")
31-
}
29+
assertThat(blocksRlpEncoded).hasSize(254)
30+
// TODO: enable after Besu supports deserializing transactions without signatures validation
31+
//
32+
// blocksRlpEncoded.forEachIndexed { index, blockRlp ->
33+
// val rlpInput = RLP.input(Bytes.wrap(blockRlp))
34+
// val decodedBlock = Block.readFrom(rlpInput, MainnetBlockHeaderFunctions())
35+
// println("$index: $decodedBlock")
36+
// }
3237
}
3338

3439
@Disabled("for local dev validation")
@@ -42,26 +47,4 @@ class BlobDecompressorDataDecodingTest {
4247
val decodedBlock = Block.readFrom(rlpInput, MainnetBlockHeaderFunctions())
4348
println(decodedBlock)
4449
}
45-
46-
private fun rlpEncode(list: List<ByteArray>): ByteArray {
47-
return RLP.encode { rlpWriter ->
48-
rlpWriter.startList()
49-
list.forEach { bytes ->
50-
rlpWriter.writeBytes(Bytes.wrap(bytes))
51-
}
52-
rlpWriter.endList()
53-
}.toArray()
54-
}
55-
56-
private fun rlpDecodeAsListOfBytes(rlpEncoded: ByteArray): List<ByteArray> {
57-
val decodedBytes = mutableListOf<ByteArray>()
58-
RLP.input(Bytes.wrap(rlpEncoded), true).also { rlpInput ->
59-
rlpInput.enterList()
60-
while (!rlpInput.isEndOfCurrentList) {
61-
decodedBytes.add(rlpInput.readBytes().toArray())
62-
}
63-
rlpInput.leaveList()
64-
}
65-
return decodedBytes
66-
}
6750
}

jvm-libs/linea/blob-decompressor/src/test/kotlin/net/consensys/linea/blob/GoNativeBlobDecompressorTest.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class GoNativeBlobDecompressorTest {
2727

2828
@Test
2929
fun `when blocks are compressed with compressor shall decompress them back`() {
30-
val blocks = CompressorTestData.blocksRlpEncoded.slice(0..1)
30+
val blocks = CompressorTestData.blocksRlpEncoded
3131
assertTrue(compressor.Write(blocks[0], blocks[0].size))
3232
assertTrue(compressor.Write(blocks[1], blocks[1].size))
3333

@@ -36,6 +36,7 @@ class GoNativeBlobDecompressorTest {
3636

3737
val decompressedBlob = decompressor.decompress(compressedData)
3838
assertThat(decompressedBlob.size).isGreaterThan(compressedData.size)
39-
// TODO: assert decompressedDataBuffer content
39+
val decompressedBlocks: List<ByteArray> = rlpDecodeAsListOfBytes(decompressedBlob)
40+
assertThat(decompressedBlocks).hasSize(2)
4041
}
4142
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package net.consensys.linea.blob
2+
3+
import org.apache.tuweni.bytes.Bytes
4+
import org.hyperledger.besu.ethereum.rlp.RLP
5+
6+
internal fun rlpEncode(list: List<ByteArray>): ByteArray {
7+
return RLP.encode { rlpWriter ->
8+
rlpWriter.startList()
9+
list.forEach { bytes ->
10+
rlpWriter.writeBytes(Bytes.wrap(bytes))
11+
}
12+
rlpWriter.endList()
13+
}.toArray()
14+
}
15+
16+
internal fun rlpDecodeAsListOfBytes(rlpEncoded: ByteArray): List<ByteArray> {
17+
val decodedBytes = mutableListOf<ByteArray>()
18+
RLP.input(Bytes.wrap(rlpEncoded), true).also { rlpInput ->
19+
rlpInput.enterList()
20+
while (!rlpInput.isEndOfCurrentList) {
21+
decodedBytes.add(rlpInput.readBytes().toArray())
22+
}
23+
rlpInput.leaveList()
24+
}
25+
return decodedBytes
26+
}

0 commit comments

Comments
 (0)