This repository has been archived by the owner on Aug 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor discv5 constructs and test it with an eth2 client * happy with code paths * spotless, refactor tests * Fix all tests * Fix compilation issue * spotless * WIP * don't double hash signature input * Fix expectation of findnode request id being present * Add test for Ticket * spotless * remove the duplicate code identifier of messages * remove unused class
- Loading branch information
Showing
87 changed files
with
1,939 additions
and
3,335 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
71 changes: 71 additions & 0 deletions
71
devp2p/src/integrationTest/kotlin/org/apache/tuweni/devp2p/v5/ConnectTwoServersTest.kt
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,71 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 org.apache.tuweni.devp2p.v5 | ||
|
||
import kotlinx.coroutines.delay | ||
import kotlinx.coroutines.runBlocking | ||
import org.apache.tuweni.bytes.Bytes | ||
import org.apache.tuweni.concurrent.coroutines.await | ||
import org.apache.tuweni.crypto.Hash | ||
import org.apache.tuweni.crypto.SECP256K1 | ||
import org.apache.tuweni.devp2p.EthereumNodeRecord | ||
import org.apache.tuweni.junit.BouncyCastleExtension | ||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.api.Assertions.assertNotNull | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import java.util.concurrent.ConcurrentHashMap | ||
|
||
internal class SimpleTestENRStorage : ENRStorage { | ||
|
||
val storage: MutableMap<Bytes, EthereumNodeRecord> = ConcurrentHashMap() | ||
|
||
override fun find(nodeId: Bytes): EthereumNodeRecord? = storage[nodeId] | ||
|
||
override fun put(nodeId: Bytes, enr: EthereumNodeRecord) { storage.put(nodeId, enr) } | ||
} | ||
|
||
@ExtendWith(BouncyCastleExtension::class) | ||
class ConnectTwoServersTest { | ||
|
||
@Test | ||
fun testConnectTwoServers() = runBlocking { | ||
val storage = SimpleTestENRStorage() | ||
val service = DiscoveryService.open( | ||
SECP256K1.KeyPair.random(), | ||
localPort = 40000, | ||
bootstrapENRList = emptyList(), | ||
enrStorage = storage | ||
) | ||
service.start().await() | ||
|
||
val otherStorage = SimpleTestENRStorage() | ||
val otherService = DiscoveryService.open( | ||
SECP256K1.KeyPair.random(), | ||
localPort = 40001, | ||
bootstrapENRList = emptyList(), | ||
enrStorage = otherStorage | ||
) | ||
otherService.start().await() | ||
otherService.addPeer(service.enr()).await() | ||
delay(500) | ||
assertEquals(1, storage.storage.size) | ||
assertEquals(1, otherStorage.storage.size) | ||
assertNotNull(otherStorage.find(Hash.sha2_256(service.enr().toRLP()))) | ||
assertNotNull(storage.find(Hash.sha2_256(otherService.enr().toRLP()))) | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
devp2p/src/integrationTest/kotlin/org/apache/tuweni/devp2p/v5/LighthouseTest.kt
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,49 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 org.apache.tuweni.devp2p.v5 | ||
|
||
import kotlinx.coroutines.runBlocking | ||
import org.apache.tuweni.crypto.SECP256K1 | ||
import org.apache.tuweni.junit.BouncyCastleExtension | ||
import org.junit.jupiter.api.Disabled | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import java.net.InetSocketAddress | ||
|
||
/** | ||
* Test a developer can run from their machine to contact a remote server. | ||
*/ | ||
@ExtendWith(BouncyCastleExtension::class) | ||
class LighthouseTest { | ||
|
||
@Disabled | ||
@Test | ||
fun testConnect() = runBlocking { | ||
val enrRec = | ||
"-Iu4QHtMAII7O9sQHpBQ-eNvZIi_f_M5f-JZWTr_PUHiLgZ3ZRd2CkGFYL_fONOVTRw0GL2dMo4yzQP2eBcu0sM5C0IB" + | ||
"gmlkgnY0gmlwhH8AAAGJc2VjcDI1NmsxoQIJk7MTrqCvOqk7mysZ6A3F19HDc6ebOOzqSoxVuJbsrYN0Y3CCIyiDdWRwgiMo" | ||
|
||
val service = DiscoveryService.open( | ||
SECP256K1.KeyPair.random(), | ||
localPort = 0, | ||
bindAddress = InetSocketAddress("0.0.0.0", 10000), | ||
bootstrapENRList = listOf(enrRec) | ||
) | ||
service.start().join() | ||
kotlinx.coroutines.delay(50000) | ||
} | ||
} |
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,28 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<!-- | ||
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE | ||
file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file | ||
to You 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. | ||
--> | ||
<configuration> | ||
|
||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
<!-- encoders are assigned the type | ||
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default --> | ||
<encoder> | ||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<logger name="org.apache.tuweni.devp2p.v5" level="TRACE" /> | ||
<root level="debug"> | ||
<appender-ref ref="STDOUT" /> | ||
</root> | ||
</configuration> |
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
Oops, something went wrong.