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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations