use of tech.pegasys.teku.ethereum.pow.api.Deposit in project teku by ConsenSys.
the class DepositsFromBlockEventTest method create_withDuplicateDeposit.
@Test
public void create_withDuplicateDeposit() {
final Deposit deposit1 = dataStructureUtil.randomDepositEvent(1);
final Stream<Deposit> depositStream = Stream.of(deposit1, deposit1);
assertThatThrownBy(() -> DepositsFromBlockEvent.create(UInt64.ONE, dataStructureUtil.randomBytes32(), UInt64.ONE, depositStream)).isInstanceOf(InvalidDepositEventsException.class).hasMessageContaining("Deposits must be ordered and contiguous. Deposit at index 1 does not follow prior deposit at index 1");
}
use of tech.pegasys.teku.ethereum.pow.api.Deposit in project teku by ConsenSys.
the class DepositsFromBlockEventSerializer method deserialize.
@Override
public DepositsFromBlockEvent deserialize(final byte[] data) {
return SSZ.decode(Bytes.of(data), reader -> {
final UInt64 blockNumber = UInt64.fromLongBits(reader.readUInt64());
final Bytes32 blockHash = Bytes32.wrap(reader.readFixedBytes(Bytes32.SIZE));
final UInt64 blockTimestamp = UInt64.fromLongBits(reader.readUInt64());
final Stream<Deposit> depositsStream = reader.readBytesList().stream().map(this::decodeDeposit);
return DepositsFromBlockEvent.create(blockNumber, blockHash, blockTimestamp, depositsStream);
});
}
use of tech.pegasys.teku.ethereum.pow.api.Deposit in project teku by ConsenSys.
the class DepositsFromBlockEventSerializer method decodeDeposit.
private Deposit decodeDeposit(final Bytes data) {
return SSZ.decode(data, reader -> {
final BLSPublicKey publicKey = BLSPublicKey.fromSSZBytes(Bytes.wrap(reader.readFixedBytes(BLSPublicKey.SSZ_BLS_PUBKEY_SIZE)));
final Bytes32 withdrawalCredentials = Bytes32.wrap(reader.readFixedBytes(Bytes32.SIZE));
final BLSSignature signature = BLSSignature.fromSSZBytes(reader.readFixedBytes(BLSSignature.SSZ_BLS_SIGNATURE_SIZE));
final UInt64 amount = UInt64.fromLongBits(reader.readUInt64());
final UInt64 merkleTreeIndex = UInt64.fromLongBits(reader.readUInt64());
return new Deposit(publicKey, withdrawalCredentials, signature, amount, merkleTreeIndex);
});
}
use of tech.pegasys.teku.ethereum.pow.api.Deposit in project teku by ConsenSys.
the class DepositsFromBlockEventTest method create_withMissingDeposit.
@Test
public void create_withMissingDeposit() {
final Deposit deposit1 = dataStructureUtil.randomDepositEvent(1);
final Deposit deposit3 = dataStructureUtil.randomDepositEvent(3);
final Stream<Deposit> depositStream = Stream.of(deposit3, deposit1);
assertThatThrownBy(() -> DepositsFromBlockEvent.create(UInt64.ONE, dataStructureUtil.randomBytes32(), UInt64.ONE, depositStream)).isInstanceOf(InvalidDepositEventsException.class).hasMessageContaining("Deposits must be ordered and contiguous. Deposit at index 3 does not follow prior deposit at index 1");
}
use of tech.pegasys.teku.ethereum.pow.api.Deposit in project teku by ConsenSys.
the class DepositsFromBlockEventTest method create_withOutOfOrderDeposits.
@Test
public void create_withOutOfOrderDeposits() {
final Deposit deposit1 = dataStructureUtil.randomDepositEvent(1);
final Deposit deposit2 = dataStructureUtil.randomDepositEvent(2);
final Deposit deposit3 = dataStructureUtil.randomDepositEvent(3);
final Stream<Deposit> depositStream = Stream.of(deposit3, deposit1, deposit2);
final DepositsFromBlockEvent event = DepositsFromBlockEvent.create(UInt64.ONE, dataStructureUtil.randomBytes32(), UInt64.ONE, depositStream);
assertThat(event.getDeposits()).containsExactly(deposit1, deposit2, deposit3);
assertThat(event.getFirstDepositIndex()).isEqualTo(deposit1.getMerkle_tree_index());
assertThat(event.getLastDepositIndex()).isEqualTo(deposit3.getMerkle_tree_index());
}
Aggregations