Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tbenr committed Apr 26, 2024
1 parent 0e8c8eb commit c33cc16
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@
import static tech.pegasys.teku.api.schema.SchemaConstants.DESCRIPTION_BYTES_SSZ;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.Objects;
import org.apache.tuweni.bytes.Bytes;
import tech.pegasys.teku.infrastructure.ssz.SszData;
import tech.pegasys.teku.spec.Spec;
import tech.pegasys.teku.spec.SpecVersion;
import tech.pegasys.teku.spec.datastructures.operations.AttestationSchema;
Expand All @@ -32,23 +35,30 @@ public class Attestation {

public final AttestationData data;

@JsonInclude(Include.NON_NULL)
@Schema(type = "string", format = "byte", description = DESCRIPTION_BYTES_SSZ)
public final Bytes committee_bits;

@Schema(type = "string", format = "byte", description = DESCRIPTION_BYTES96)
public final BLSSignature signature;

public Attestation(
final tech.pegasys.teku.spec.datastructures.operations.Attestation attestation) {
this.aggregation_bits = attestation.getAggregationBits().sszSerialize();
this.data = new AttestationData(attestation.getData());
this.committee_bits = attestation.getCommitteeBits().map(SszData::sszSerialize).orElse(null);
this.signature = new BLSSignature(attestation.getAggregateSignature());
}

@JsonCreator
public Attestation(
@JsonProperty("aggregation_bits") final Bytes aggregation_bits,
@JsonProperty("data") final AttestationData data,
@JsonProperty("committee_bits") final Bytes committee_bits,
@JsonProperty("signature") final BLSSignature signature) {
this.aggregation_bits = aggregation_bits;
this.data = data;
this.committee_bits = committee_bits;
this.signature = signature;
}

Expand Down Expand Up @@ -78,11 +88,12 @@ public boolean equals(final Object o) {
Attestation that = (Attestation) o;
return Objects.equals(aggregation_bits, that.aggregation_bits)
&& Objects.equals(data, that.data)
&& Objects.equals(committee_bits, that.committee_bits)
&& Objects.equals(signature, that.signature);
}

@Override
public int hashCode() {
return Objects.hash(aggregation_bits, data, signature);
return Objects.hash(aggregation_bits, data, committee_bits, signature);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,10 @@ public SszBitlist randomBitlist(final int n) {
return SszBitlistSchema.create(n).ofBits(n, bits);
}

public SszBitvector randomCommitteeBitvector() {
return randomSszBitvector(getMaxCommitteesPerSlot());
}

public SszBitvector randomSszBitvector(final int n) {
Random random = new Random(nextSeed());
int[] bits = IntStream.range(0, n).sequential().filter(__ -> random.nextBoolean()).toArray();
Expand Down Expand Up @@ -792,7 +796,11 @@ public AttestationData randomAttestationData(final UInt64 slot, final Bytes32 bl
public Attestation randomAttestation() {
return spec.getGenesisSchemaDefinitions()
.getAttestationSchema()
.create(randomBitlist(), randomAttestationData(), randomSignature());
.create(
randomBitlist(),
randomAttestationData(),
Optional.of(randomCommitteeBitvector()),
randomSignature());
}

public Attestation randomAttestation(final long slot) {
Expand All @@ -802,13 +810,21 @@ public Attestation randomAttestation(final long slot) {
public Attestation randomAttestation(final UInt64 slot) {
return spec.getGenesisSchemaDefinitions()
.getAttestationSchema()
.create(randomBitlist(), randomAttestationData(slot), randomSignature());
.create(
randomBitlist(),
randomAttestationData(slot),
Optional.of(randomCommitteeBitvector()),
randomSignature());
}

public Attestation randomAttestation(final AttestationData attestationData) {
return spec.getGenesisSchemaDefinitions()
.getAttestationSchema()
.create(randomBitlist(), attestationData, randomSignature());
.create(
randomBitlist(),
attestationData,
Optional.of(randomCommitteeBitvector()),
randomSignature());
}

public AggregateAndProof randomAggregateAndProof() {
Expand Down Expand Up @@ -2572,6 +2588,10 @@ private int getMaxValidatorsPerCommittee() {
return getConstant(SpecConfig::getMaxValidatorsPerCommittee);
}

private int getMaxCommitteesPerSlot() {
return getConstant(SpecConfig::getMaxCommitteesPerSlot);
}

private UInt64 getMaxEffectiveBalance() {
return getConstant(SpecConfig::getMaxEffectiveBalance);
}
Expand Down

0 comments on commit c33cc16

Please sign in to comment.