Skip to content

Commit

Permalink
complete deneb mischelper tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tbenr committed Dec 13, 2024
1 parent ee8e99b commit 0c6da5a
Showing 1 changed file with 58 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assumptions.assumeThat;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static tech.pegasys.teku.spec.config.SpecConfigDeneb.VERSIONED_HASH_VERSION_KZG;

import java.util.List;
Expand Down Expand Up @@ -68,6 +69,39 @@ public void versionedHash() {
assertThat(actual).isEqualTo(VERSIONED_HASH);
}

@Test
void verifyBlobSidecarCompleteness_shouldThrowWhenSizesDoNotMatch() {
assertThatThrownBy(
() ->
miscHelpersDeneb.verifyBlobSidecarCompleteness(
dataStructureUtil.randomBlobSidecars(1),
dataStructureUtil.randomSignedBeaconBlockWithCommitments(2)))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Blob sidecars are not complete");
}

@Test
void verifyBlobSidecarCompleteness_shouldThrowWhenBlobSidecarIndexIsWrong() {
final List<BlobSidecar> blobSidecars = dataStructureUtil.randomBlobSidecars(1);
assertThatThrownBy(
() ->
miscHelpersDeneb.verifyBlobSidecarCompleteness(
blobSidecars, dataStructureUtil.randomSignedBeaconBlockWithCommitments(1)))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage(
"Blob sidecar index mismatch, expected 0, got %s", blobSidecars.getFirst().getIndex());
}

@Test
void verifyBlobSidecarCompleteness_shouldNotThrow() {
final SignedBeaconBlock block = dataStructureUtil.randomSignedBeaconBlockWithCommitments(2);
final List<BlobSidecar> blobSidecars = List.of(dataStructureUtil.randomBlobSidecarForBlock(block, 0), dataStructureUtil.randomBlobSidecarForBlock(block, 1));
assertDoesNotThrow(
() ->
miscHelpersDeneb.verifyBlobSidecarCompleteness(
blobSidecars, block));
}

@Test
void shouldConstructValidBlobSidecar() {
final SignedBeaconBlock signedBeaconBlock =
Expand All @@ -89,6 +123,7 @@ void shouldConstructValidBlobSidecar() {
assertThat(blobSidecar.getSignedBeaconBlockHeader()).isEqualTo(signedBeaconBlock.asHeader());
// verify the merkle proof
assertThat(miscHelpersDeneb.verifyBlobKzgCommitmentInclusionProof(blobSidecar)).isTrue();
assertThat(blobSidecar.isKzgCommitmentInclusionProofValidated()).isTrue();
}

@Test
Expand Down Expand Up @@ -148,6 +183,8 @@ void verifyBlobKzgCommitmentInclusionProofShouldValidate() {
.kzgCommitmentInclusionProof(merkleProof)
.build();
assertThat(miscHelpersDeneb.verifyBlobKzgCommitmentInclusionProof(blobSidecar)).isTrue();
assertThat(blobSidecar.isKzgCommitmentInclusionProofValidated()).isTrue();


// And the same blobSidecar but with wrong merkle proof
for (int j = 0; j < numberOfCommitments; ++j) {
Expand Down Expand Up @@ -178,9 +215,29 @@ void verifyBlobKzgCommitmentInclusionProofShouldValidate() {
.build();
assertThat(miscHelpersDeneb.verifyBlobKzgCommitmentInclusionProof(blobSidecarWrong))
.isFalse();
assertThat(blobSidecarWrong.isKzgCommitmentInclusionProofValidated()).isFalse();
}
}
}

// TODO test mark as validated and verifyBlobSidecarBlockHeaderSignatureViaValidatedSignedBlock

@Test
void verifyBlobSidecarBlockHeaderSignatureViaValidatedSignedBlock_returnsTrue() {
final SignedBeaconBlock signedBeaconBlock =
dataStructureUtil.randomSignedBeaconBlockWithCommitments(1);
final BlobSidecar blobSidecar =
dataStructureUtil.randomBlobSidecarForBlock(signedBeaconBlock, 0);
assertThat(miscHelpersDeneb.verifyBlobSidecarBlockHeaderSignatureViaValidatedSignedBlock(blobSidecar, signedBeaconBlock)).isTrue();
assertThat(blobSidecar.isSignatureValidated()).isTrue();
}

@Test
void verifyBlobSidecarBlockHeaderSignatureViaValidatedSignedBlock_returnsFalse() {
final SignedBeaconBlock signedBeaconBlock =
dataStructureUtil.randomSignedBeaconBlockWithCommitments(1);
final BlobSidecar blobSidecar =
dataStructureUtil.randomBlobSidecar();
assertThat(miscHelpersDeneb.verifyBlobSidecarBlockHeaderSignatureViaValidatedSignedBlock(blobSidecar, signedBeaconBlock)).isFalse();
assertThat(blobSidecar.isSignatureValidated()).isFalse();
}
}

0 comments on commit 0c6da5a

Please sign in to comment.