Search in sources :

Example 1 with UInt64

use of org.apache.tuweni.units.bigints.UInt64 in project web3signer by ConsenSys.

the class InterchangeExportIntegrationTestBase method onlyExportBlocksWithSlotEqualToOrGreaterThanEpoch.

@Test
void onlyExportBlocksWithSlotEqualToOrGreaterThanEpoch() throws IOException {
    final int TOTAL_BLOCKS_SIGNED = 6;
    final UInt64 BLOCK_SLOT_WATER_MARK = UInt64.valueOf(3);
    final Bytes validatorPublicKey = Bytes.of(1);
    slashingProtectionContext.getRegisteredValidators().registerValidators(List.of(validatorPublicKey));
    for (int b = 0; b < TOTAL_BLOCKS_SIGNED; b++) {
        insertBlockAt(UInt64.valueOf(b), 1);
    }
    jdbi.useTransaction(h -> lowWatermarkDao.updateSlotWatermarkFor(h, 1, BLOCK_SLOT_WATER_MARK));
    final InterchangeV5Format outputObject = getExportObjectFromDatabase();
    assertThat(outputObject.getSignedArtifacts()).hasSize(1);
    assertThat(outputObject.getSignedArtifacts().get(0).getSignedBlocks()).hasSize(TOTAL_BLOCKS_SIGNED - BLOCK_SLOT_WATER_MARK.intValue());
    final Optional<UInt64> minBlockSlotInExport = outputObject.getSignedArtifacts().get(0).getSignedBlocks().stream().map(SignedBlock::getSlot).min(UInt64::compareTo);
    assertThat(minBlockSlotInExport).isNotEmpty();
    assertThat(minBlockSlotInExport.get()).isEqualTo(BLOCK_SLOT_WATER_MARK);
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) InterchangeV5Format(dsl.InterchangeV5Format) UInt64(org.apache.tuweni.units.bigints.UInt64) Test(org.junit.jupiter.api.Test)

Example 2 with UInt64

use of org.apache.tuweni.units.bigints.UInt64 in project besu by hyperledger.

the class PingPacketDataTest method handleOptionalSourceIP.

@Test
public void handleOptionalSourceIP() {
    final Endpoint to = new Endpoint("127.0.0.2", 30303, Optional.empty());
    final long time = System.currentTimeMillis();
    final UInt64 enrSeq = UInt64.ONE;
    final PingPacketData anon = PingPacketData.create(Optional.empty(), to, time, enrSeq);
    final BytesValueRLPOutput out = new BytesValueRLPOutput();
    anon.writeTo(out);
    final Bytes serialized = out.encoded();
    System.out.println(serialized.toHexString());
    final PingPacketData deserialized = PingPacketData.readFrom(RLP.input(serialized));
    assertThat(deserialized.getFrom()).isEmpty();
    assertThat(deserialized.getTo()).isEqualTo(to);
    assertThat(deserialized.getExpiration()).isEqualTo(time);
    assertThat(deserialized.getEnrSeq().isPresent()).isTrue();
    assertThat(deserialized.getEnrSeq().get()).isEqualTo(enrSeq);
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) Endpoint(org.hyperledger.besu.ethereum.p2p.discovery.Endpoint) UInt64(org.apache.tuweni.units.bigints.UInt64) BytesValueRLPOutput(org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput) Test(org.junit.Test)

Example 3 with UInt64

use of org.apache.tuweni.units.bigints.UInt64 in project besu by hyperledger.

the class PingPacketDataTest method handleSourcePortNullHost.

@Test
public void handleSourcePortNullHost() {
    final Endpoint to = new Endpoint("127.0.0.2", 30303, Optional.empty());
    final BytesValueRLPOutput out = new BytesValueRLPOutput();
    final UInt64 enrSeq = UInt64.MAX_VALUE;
    final long time = System.currentTimeMillis();
    out.startList();
    out.writeIntScalar(4);
    ((RLPOutput) out).startList();
    out.writeNull();
    out.writeIntScalar(30303);
    out.writeNull();
    ((RLPOutput) out).endList();
    to.encodeStandalone(out);
    out.writeLongScalar(time);
    out.writeBigIntegerScalar(enrSeq.toBigInteger());
    out.endList();
    final Bytes serialized = out.encoded();
    final PingPacketData deserialized = PingPacketData.readFrom(RLP.input(serialized));
    assertThat(deserialized.getFrom()).isPresent();
    assertThat(deserialized.getFrom().get().getUdpPort()).isEqualTo(30303);
    assertThat(deserialized.getFrom().get().getHost().isEmpty()).isTrue();
    assertThat(deserialized.getFrom().get().getTcpPort().isEmpty()).isTrue();
    assertThat(deserialized.getTo()).isEqualTo(to);
    assertThat(deserialized.getExpiration()).isEqualTo(time);
    assertThat(deserialized.getEnrSeq().isPresent()).isTrue();
    assertThat(deserialized.getEnrSeq().get()).isEqualTo(enrSeq);
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) Endpoint(org.hyperledger.besu.ethereum.p2p.discovery.Endpoint) BytesValueRLPOutput(org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput) RLPOutput(org.hyperledger.besu.ethereum.rlp.RLPOutput) UInt64(org.apache.tuweni.units.bigints.UInt64) BytesValueRLPOutput(org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput) Test(org.junit.Test)

Example 4 with UInt64

use of org.apache.tuweni.units.bigints.UInt64 in project besu by hyperledger.

the class PingPacketDataTest method readFrom_lowPortValues.

@Test
public void readFrom_lowPortValues() {
    final int version = 4;
    final Endpoint from = new Endpoint("0.1.2.1", 1, Optional.of(1));
    final Endpoint to = new Endpoint("127.0.0.2", 30303, Optional.empty());
    final long time = System.currentTimeMillis();
    final UInt64 enrSeq = UInt64.ONE;
    final BytesValueRLPOutput out = new BytesValueRLPOutput();
    out.startList();
    out.writeIntScalar(version);
    from.encodeStandalone(out);
    to.encodeStandalone(out);
    out.writeLongScalar(time);
    out.writeLongScalar(enrSeq.toLong());
    out.endList();
    final Bytes serialized = out.encoded();
    final PingPacketData deserialized = PingPacketData.readFrom(RLP.input(serialized));
    assertThat(deserialized.getFrom()).contains(from);
    assertThat(deserialized.getTo()).isEqualTo(to);
    assertThat(deserialized.getExpiration()).isEqualTo(time);
    assertThat(deserialized.getEnrSeq().isPresent()).isTrue();
    assertThat(deserialized.getEnrSeq().get()).isEqualTo(enrSeq);
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) Endpoint(org.hyperledger.besu.ethereum.p2p.discovery.Endpoint) UInt64(org.apache.tuweni.units.bigints.UInt64) BytesValueRLPOutput(org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput) Endpoint(org.hyperledger.besu.ethereum.p2p.discovery.Endpoint) Test(org.junit.Test)

Example 5 with UInt64

use of org.apache.tuweni.units.bigints.UInt64 in project besu by hyperledger.

the class PingPacketDataTest method readFrom.

@Test
public void readFrom() {
    final int version = 4;
    final Endpoint from = new Endpoint("127.0.0.1", 30303, Optional.of(30303));
    final Endpoint to = new Endpoint("127.0.0.2", 30303, Optional.empty());
    final long time = System.currentTimeMillis();
    final UInt64 enrSeq = UInt64.ONE;
    final BytesValueRLPOutput out = new BytesValueRLPOutput();
    out.startList();
    out.writeIntScalar(version);
    from.encodeStandalone(out);
    to.encodeStandalone(out);
    out.writeLongScalar(time);
    out.writeLongScalar(enrSeq.toLong());
    out.endList();
    final Bytes serialized = out.encoded();
    final PingPacketData deserialized = PingPacketData.readFrom(RLP.input(serialized));
    assertThat(deserialized.getFrom()).contains(from);
    assertThat(deserialized.getTo()).isEqualTo(to);
    assertThat(deserialized.getExpiration()).isEqualTo(time);
    assertThat(deserialized.getEnrSeq().isPresent()).isTrue();
    assertThat(deserialized.getEnrSeq().get()).isEqualTo(enrSeq);
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) Endpoint(org.hyperledger.besu.ethereum.p2p.discovery.Endpoint) UInt64(org.apache.tuweni.units.bigints.UInt64) BytesValueRLPOutput(org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput) Endpoint(org.hyperledger.besu.ethereum.p2p.discovery.Endpoint) Test(org.junit.Test)

Aggregations

UInt64 (org.apache.tuweni.units.bigints.UInt64)27 Bytes (org.apache.tuweni.bytes.Bytes)20 Endpoint (org.hyperledger.besu.ethereum.p2p.discovery.Endpoint)19 Test (org.junit.Test)16 BytesValueRLPOutput (org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput)13 Bytes32 (org.apache.tuweni.bytes.Bytes32)6 Test (org.junit.jupiter.api.Test)5 InterchangeV5Format (dsl.InterchangeV5Format)3 List (java.util.List)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 NodeKey (org.hyperledger.besu.crypto.NodeKey)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 Suppliers (com.google.common.base.Suppliers)1 InetAddresses (com.google.common.net.InetAddresses)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 InetSocketAddress (java.net.InetSocketAddress)1