use of tech.pegasys.teku.spec.datastructures.operations.AggregateAndProof in project teku by ConsenSys.
the class SlashingProtectedSignerTest method signAggregateAndProof_shouldAlwaysSign.
@Test
void signAggregateAndProof_shouldAlwaysSign() {
final AggregateAndProof aggregateAndProof = dataStructureUtil.randomAggregateAndProof();
when(delegate.signAggregateAndProof(aggregateAndProof, forkInfo)).thenReturn(signatureFuture);
assertThatSafeFuture(signer.signAggregateAndProof(aggregateAndProof, forkInfo)).isCompletedWithValue(signature);
}
use of tech.pegasys.teku.spec.datastructures.operations.AggregateAndProof in project teku by ConsenSys.
the class ExternalSignerIntegrationTest method shouldSignAggregateAndProof.
@Test
public void shouldSignAggregateAndProof() throws Exception {
final AggregateAndProof aggregateAndProof = dataStructureUtil.randomAggregateAndProof();
final BLSSignature expectedSignature = BLSSignature.fromBytesCompressed(Bytes.fromBase64String("kHbIuvFcS/kDppbCj0ILOU27ZjSU1P2wPsOKBBwGaz1uvXQxtUXQAdbybN1zotZqCs6pstChIIxDS/WgAZH2z4yX2cM/cM/iKayT2rZZJuu31V2uxP1AYVcyHLEMtF07"));
client.when(request()).respond(response().withBody(expectedSignature.toString()));
final BLSSignature response = externalSigner.signAggregateAndProof(aggregateAndProof, fork).join();
assertThat(response).isEqualTo(expectedSignature);
final SigningRequestBody signingRequestBody = new SigningRequestBody(signingRootUtil.signingRootForSignAggregateAndProof(aggregateAndProof, fork), SignType.AGGREGATE_AND_PROOF, Map.of("fork_info", createForkInfo(fork), "aggregate_and_proof", new tech.pegasys.teku.api.schema.AggregateAndProof(aggregateAndProof)));
verifySignRequest(client, KEYPAIR.getPublicKey().toString(), signingRequestBody);
validateMetrics(metricsSystem, 1, 0, 0);
}
use of tech.pegasys.teku.spec.datastructures.operations.AggregateAndProof in project teku by ConsenSys.
the class AggregationDutyTest method shouldProduceAggregateAndProofForMultipleCommittees.
@SuppressWarnings("unchecked")
@Test
public void shouldProduceAggregateAndProofForMultipleCommittees() {
final int validator1Index = 1;
final int validator1CommitteeIndex = 2;
final BLSSignature validator1Proof = dataStructureUtil.randomSignature();
final int validator2Index = 6;
final int validator2CommitteeIndex = 0;
final BLSSignature validator2Proof = dataStructureUtil.randomSignature();
final AttestationData committee1AttestationData = dataStructureUtil.randomAttestationData();
final AttestationData committee2AttestationData = dataStructureUtil.randomAttestationData();
final Attestation committee1Aggregate = dataStructureUtil.randomAttestation();
final Attestation committee2Aggregate = dataStructureUtil.randomAttestation();
duty.addValidator(validator1, validator1Index, validator1Proof, validator1CommitteeIndex, completedFuture(Optional.of(committee1AttestationData)));
duty.addValidator(validator2, validator2Index, validator2Proof, validator2CommitteeIndex, completedFuture(Optional.of(committee2AttestationData)));
when(validatorApiChannel.createAggregate(SLOT, committee1AttestationData.hashTreeRoot())).thenReturn(completedFuture(Optional.of(committee1Aggregate)));
when(validatorApiChannel.createAggregate(SLOT, committee2AttestationData.hashTreeRoot())).thenReturn(completedFuture(Optional.of(committee2Aggregate)));
final AggregateAndProof aggregateAndProof1 = aggregateAndProofSchema.create(UInt64.valueOf(validator1Index), committee1Aggregate, validator1Proof);
final AggregateAndProof aggregateAndProof2 = aggregateAndProofSchema.create(UInt64.valueOf(validator2Index), committee2Aggregate, validator2Proof);
final BLSSignature aggregateSignature1 = dataStructureUtil.randomSignature();
final BLSSignature aggregateSignature2 = dataStructureUtil.randomSignature();
when(signer1.signAggregateAndProof(aggregateAndProof1, forkInfo)).thenReturn(SafeFuture.completedFuture(aggregateSignature1));
when(signer2.signAggregateAndProof(aggregateAndProof2, forkInfo)).thenReturn(SafeFuture.completedFuture(aggregateSignature2));
assertThat(duty.performDuty()).isCompleted();
ArgumentCaptor<List<SignedAggregateAndProof>> argumentCaptor = ArgumentCaptor.forClass(List.class);
verify(validatorApiChannel).sendAggregateAndProofs(argumentCaptor.capture());
assertThat(argumentCaptor.getValue()).containsExactlyInAnyOrder(signedAggregateAndProofSchema.create(aggregateAndProof1, aggregateSignature1), signedAggregateAndProofSchema.create(aggregateAndProof2, aggregateSignature2));
}
use of tech.pegasys.teku.spec.datastructures.operations.AggregateAndProof in project teku by ConsenSys.
the class AggregationDutyTest method shouldProduceSingleAggregateAndProofWhenMultipleValidatorsAggregateSameCommittee.
@Test
public void shouldProduceSingleAggregateAndProofWhenMultipleValidatorsAggregateSameCommittee() {
final int committeeIndex = 2;
final int validator1Index = 1;
final BLSSignature validator1Proof = dataStructureUtil.randomSignature();
final int validator2Index = 6;
final BLSSignature validator2Proof = dataStructureUtil.randomSignature();
final AttestationData attestationData = dataStructureUtil.randomAttestationData();
final Attestation aggregate = dataStructureUtil.randomAttestation();
duty.addValidator(validator1, validator1Index, validator1Proof, committeeIndex, completedFuture(Optional.of(attestationData)));
duty.addValidator(validator2, validator2Index, validator2Proof, committeeIndex, completedFuture(Optional.of(attestationData)));
when(validatorApiChannel.createAggregate(SLOT, attestationData.hashTreeRoot())).thenReturn(completedFuture(Optional.of(aggregate)));
when(validatorApiChannel.sendAggregateAndProofs(anyList())).thenReturn(SafeFuture.completedFuture(Collections.emptyList()));
final AggregateAndProof aggregateAndProof = aggregateAndProofSchema.create(UInt64.valueOf(validator1Index), aggregate, validator1Proof);
final BLSSignature aggregateSignature1 = dataStructureUtil.randomSignature();
when(signer1.signAggregateAndProof(aggregateAndProof, forkInfo)).thenReturn(SafeFuture.completedFuture(aggregateSignature1));
performAndReportDuty();
verify(validatorApiChannel).sendAggregateAndProofs(List.of(signedAggregateAndProofSchema.create(aggregateAndProof, aggregateSignature1)));
// Only one proof should be sent.
verify(validatorApiChannel, times(1)).sendAggregateAndProofs(anyList());
verify(validatorLogger).dutyCompleted(TYPE, SLOT, 1, Set.of(aggregate.getData().getBeacon_block_root()));
verifyNoMoreInteractions(validatorLogger);
}
use of tech.pegasys.teku.spec.datastructures.operations.AggregateAndProof in project teku by ConsenSys.
the class AggregationDutyTest method shouldProduceAggregateAndProof.
@Test
public void shouldProduceAggregateAndProof() {
final int validatorIndex = 1;
final int attestationCommitteeIndex = 2;
final BLSSignature proof = dataStructureUtil.randomSignature();
final AttestationData attestationData = dataStructureUtil.randomAttestationData();
final Attestation aggregate = dataStructureUtil.randomAttestation();
duty.addValidator(validator1, validatorIndex, proof, attestationCommitteeIndex, completedFuture(Optional.of(attestationData)));
when(validatorApiChannel.createAggregate(SLOT, attestationData.hashTreeRoot())).thenReturn(completedFuture(Optional.of(aggregate)));
final AggregateAndProof expectedAggregateAndProof = aggregateAndProofSchema.create(UInt64.valueOf(validatorIndex), aggregate, proof);
final BLSSignature aggregateSignature = dataStructureUtil.randomSignature();
when(signer1.signAggregateAndProof(expectedAggregateAndProof, forkInfo)).thenReturn(SafeFuture.completedFuture(aggregateSignature));
assertThat(duty.performDuty()).isCompleted();
verify(validatorApiChannel).sendAggregateAndProofs(List.of(signedAggregateAndProofSchema.create(expectedAggregateAndProof, aggregateSignature)));
}
Aggregations