Search in sources :

Example 1 with Deposit

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");
}
Also used : Deposit(tech.pegasys.teku.ethereum.pow.api.Deposit) InvalidDepositEventsException(tech.pegasys.teku.ethereum.pow.api.InvalidDepositEventsException) Test(org.junit.jupiter.api.Test)

Example 2 with Deposit

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);
    });
}
Also used : Deposit(tech.pegasys.teku.ethereum.pow.api.Deposit) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Bytes32(org.apache.tuweni.bytes.Bytes32)

Example 3 with Deposit

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);
    });
}
Also used : Deposit(tech.pegasys.teku.ethereum.pow.api.Deposit) BLSPublicKey(tech.pegasys.teku.bls.BLSPublicKey) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Bytes32(org.apache.tuweni.bytes.Bytes32) BLSSignature(tech.pegasys.teku.bls.BLSSignature)

Example 4 with Deposit

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");
}
Also used : Deposit(tech.pegasys.teku.ethereum.pow.api.Deposit) InvalidDepositEventsException(tech.pegasys.teku.ethereum.pow.api.InvalidDepositEventsException) Test(org.junit.jupiter.api.Test)

Example 5 with Deposit

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());
}
Also used : Deposit(tech.pegasys.teku.ethereum.pow.api.Deposit) DepositsFromBlockEvent(tech.pegasys.teku.ethereum.pow.api.DepositsFromBlockEvent) Test(org.junit.jupiter.api.Test)

Aggregations

Deposit (tech.pegasys.teku.ethereum.pow.api.Deposit)5 Test (org.junit.jupiter.api.Test)3 Bytes32 (org.apache.tuweni.bytes.Bytes32)2 InvalidDepositEventsException (tech.pegasys.teku.ethereum.pow.api.InvalidDepositEventsException)2 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)2 BLSPublicKey (tech.pegasys.teku.bls.BLSPublicKey)1 BLSSignature (tech.pegasys.teku.bls.BLSSignature)1 DepositsFromBlockEvent (tech.pegasys.teku.ethereum.pow.api.DepositsFromBlockEvent)1