Skip to content

Commit

Permalink
refactor test
Browse files Browse the repository at this point in the history
  • Loading branch information
mehdi-aouadi committed May 16, 2023
1 parent 9437a7a commit d7a4b06
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 234 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,21 @@
public class DeserializeBlocksTest {

static Spec spec = TestSpecFactory.createMinimalDeneb();
public static final DeserializableOneOfTypeDefinition<
tech.pegasys.teku.spec.datastructures.blocks.BlockContainer, BlockContainerBuilder>
public static final DeserializableOneOfTypeDefinition<BlockContainer, BlockContainerBuilder>
DESERIALIZABLE_ONE_OF_SIGNED_BEACON_BLOCK_OR_SIGNED_BLOCK_CONTENTS =
DeserializableOneOfTypeDefinition.object(
tech.pegasys.teku.spec.datastructures.blocks.BlockContainer.class,
BlockContainerBuilder.class)
BlockContainer.class, BlockContainerBuilder.class)
.description(
"Submit a signed beacon block to the beacon node to be imported."
+ " The beacon node performs the required validation.")
.withType(
tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock.isInstance,
SignedBeaconBlock.isInstance,
s -> !s.contains("blob_sidecars"),
spec.getGenesisSchemaDefinitions()
.getSignedBeaconBlockSchema()
.getJsonTypeDefinition())
.withType(
tech.pegasys.teku.spec.datastructures.blocks.versions.deneb.SignedBlockContents
.isInstance,
SignedBlockContents.isInstance,
s -> s.contains("blob_sidecars"),
SignedBlockContentsSchema.create(
spec.getGenesisSpecConfig().toVersionDeneb().orElseThrow(),
Expand All @@ -67,17 +64,15 @@ public class DeserializeBlocksTest {

@Test
void shouldDeserializeSignedBlockContents() throws JsonProcessingException {
final tech.pegasys.teku.spec.datastructures.blocks.BlockContainer result =
final BlockContainer result =
JsonUtil.parse(
readResource("json/signed_block_contents.json"),
DESERIALIZABLE_ONE_OF_SIGNED_BEACON_BLOCK_OR_SIGNED_BLOCK_CONTENTS);
assertThat(result).isInstanceOf(SignedBlockContents.class);

SignedBlockContents signedBlockContents = (SignedBlockContents) result;

assertThat(signedBlockContents.getSignedBeaconBlock()).isPresent();
assertThat(signedBlockContents.getSignedBlobSidecars()).isPresent();
assertThat(signedBlockContents.getSignedBlobSidecars().get())
assertThat(result.getSignedBeaconBlock()).isPresent();
assertThat(result.getSignedBlobSidecars()).isPresent();
assertThat(result.getSignedBlobSidecars().get())
.hasSize(spec.getMaxBlobsPerBlock().orElseThrow());
}

Expand All @@ -90,10 +85,8 @@ void shouldDeserializeSignedBeaconBlock() throws JsonProcessingException {

assertThat(result).isInstanceOf(SignedBeaconBlock.class);

SignedBeaconBlock signedBeaconBlock = (SignedBeaconBlock) result;

assertThat(signedBeaconBlock.getSignedBeaconBlock()).isPresent();
assertThat(signedBeaconBlock.getSignedBlobSidecars()).isEmpty();
assertThat(result.getSignedBeaconBlock()).isPresent();
assertThat(result.getSignedBlobSidecars()).isEmpty();
}

protected String readResource(final String resource) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
public class ExecutionPayloadBellatrix extends ExecutionPayloadCommon implements ExecutionPayload {

@ArraySchema(schema = @Schema(type = "string", format = "byte"))
public List<Bytes> transactions;
public final List<Bytes> transactions;

@JsonCreator
public ExecutionPayloadBellatrix(
Expand Down Expand Up @@ -96,8 +96,6 @@ public ExecutionPayloadBellatrix(
.collect(Collectors.toList());
}

public ExecutionPayloadBellatrix() {}

public tech.pegasys.teku.spec.datastructures.execution.ExecutionPayload
asInternalExecutionPayload(final Spec spec, final UInt64 slot) {
return asInternalExecutionPayload(spec.atSlot(slot));
Expand Down Expand Up @@ -139,14 +137,6 @@ protected ExecutionPayloadBuilder applyToBuilder(
.transactions(transactions);
}

public List<Bytes> getTransactions() {
return transactions;
}

public void setTransactions(List<Bytes> transactions) {
this.transactions = transactions;
}

@Override
public Optional<ExecutionPayloadBellatrix> toVersionBellatrix() {
return Optional.of(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,76 +36,74 @@ public abstract class ExecutionPayloadCommon {
format = "byte",
pattern = PATTERN_BYTES32,
description = DESCRIPTION_BYTES32)
public Bytes32 parentHash;
public final Bytes32 parentHash;

@JsonProperty("fee_recipient")
@Schema(
type = "string",
format = "byte",
pattern = PATTERN_BYTES20,
description = DESCRIPTION_BYTES20)
public Bytes20 feeRecipient;
public final Bytes20 feeRecipient;

@JsonProperty("state_root")
@Schema(
type = "string",
format = "byte",
pattern = PATTERN_BYTES32,
description = DESCRIPTION_BYTES32)
public Bytes32 stateRoot;
public final Bytes32 stateRoot;

@JsonProperty("receipts_root")
@Schema(
type = "string",
format = "byte",
pattern = PATTERN_BYTES32,
description = DESCRIPTION_BYTES32)
public Bytes32 receiptsRoot;
public final Bytes32 receiptsRoot;

@JsonProperty("logs_bloom")
@Schema(type = "string", format = "byte")
public Bytes logsBloom;
public final Bytes logsBloom;

@JsonProperty("prev_randao")
@Schema(
type = "string",
format = "byte",
pattern = PATTERN_BYTES32,
description = DESCRIPTION_BYTES32)
public Bytes32 prevRandao;
public final Bytes32 prevRandao;

@JsonProperty("block_number")
@Schema(type = "string", format = "uint64")
public UInt64 blockNumber;
public final UInt64 blockNumber;

@JsonProperty("gas_limit")
@Schema(type = "string", format = "uint64")
public UInt64 gasLimit;
public final UInt64 gasLimit;

@JsonProperty("gas_used")
@Schema(type = "string", format = "uint64")
public UInt64 gasUsed;
public final UInt64 gasUsed;

@Schema(type = "string", format = "uint64")
public UInt64 timestamp;
public final UInt64 timestamp;

@JsonProperty("extra_data")
@Schema(type = "string", format = "byte")
public Bytes extraData;
public final Bytes extraData;

@JsonProperty("base_fee_per_gas")
@Schema(type = "string", format = "uint256")
public UInt256 baseFeePerGas;
public final UInt256 baseFeePerGas;

@JsonProperty("block_hash")
@Schema(
type = "string",
format = "byte",
pattern = PATTERN_BYTES32,
description = DESCRIPTION_BYTES32)
public Bytes32 blockHash;

public ExecutionPayloadCommon() {}
public final Bytes32 blockHash;

public ExecutionPayloadCommon(
@JsonProperty("parent_hash") Bytes32 parentHash,
Expand Down Expand Up @@ -136,110 +134,6 @@ public ExecutionPayloadCommon(
this.blockHash = blockHash;
}

public Bytes32 getParentHash() {
return parentHash;
}

public void setParentHash(Bytes32 parentHash) {
this.parentHash = parentHash;
}

public Bytes20 getFeeRecipient() {
return feeRecipient;
}

public void setFeeRecipient(Bytes20 feeRecipient) {
this.feeRecipient = feeRecipient;
}

public Bytes32 getStateRoot() {
return stateRoot;
}

public void setStateRoot(Bytes32 stateRoot) {
this.stateRoot = stateRoot;
}

public Bytes32 getReceiptsRoot() {
return receiptsRoot;
}

public void setReceiptsRoot(Bytes32 receiptsRoot) {
this.receiptsRoot = receiptsRoot;
}

public Bytes getLogsBloom() {
return logsBloom;
}

public void setLogsBloom(Bytes logsBloom) {
this.logsBloom = logsBloom;
}

public Bytes32 getPrevRandao() {
return prevRandao;
}

public void setPrevRandao(Bytes32 prevRandao) {
this.prevRandao = prevRandao;
}

public UInt64 getBlockNumber() {
return blockNumber;
}

public void setBlockNumber(UInt64 blockNumber) {
this.blockNumber = blockNumber;
}

public UInt64 getGasLimit() {
return gasLimit;
}

public void setGasLimit(UInt64 gasLimit) {
this.gasLimit = gasLimit;
}

public UInt64 getGasUsed() {
return gasUsed;
}

public void setGasUsed(UInt64 gasUsed) {
this.gasUsed = gasUsed;
}

public UInt64 getTimestamp() {
return timestamp;
}

public void setTimestamp(UInt64 timestamp) {
this.timestamp = timestamp;
}

public Bytes getExtraData() {
return extraData;
}

public void setExtraData(Bytes extraData) {
this.extraData = extraData;
}

public UInt256 getBaseFeePerGas() {
return baseFeePerGas;
}

public void setBaseFeePerGas(UInt256 baseFeePerGas) {
this.baseFeePerGas = baseFeePerGas;
}

public Bytes32 getBlockHash() {
return blockHash;
}

public void setBlockHash(Bytes32 blockHash) {
this.blockHash = blockHash;
}

@Override
public boolean equals(final Object o) {
if (this == o) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class ExecutionPayloadCapella extends ExecutionPayloadBellatrix implement

@JsonProperty("withdrawals")
@ArraySchema(schema = @Schema(type = "string", format = "byte"))
public List<Withdrawal> withdrawals;
public final List<Withdrawal> withdrawals;

@JsonCreator
public ExecutionPayloadCapella(
Expand Down Expand Up @@ -84,16 +84,6 @@ public ExecutionPayloadCapella(
.collect(toList());
}

public ExecutionPayloadCapella() {}

public List<Withdrawal> getWithdrawals() {
return withdrawals;
}

public void setWithdrawals(List<Withdrawal> withdrawals) {
this.withdrawals = withdrawals;
}

@Override
protected ExecutionPayloadBuilder applyToBuilder(
final ExecutionPayloadSchema<?> executionPayloadSchema,
Expand Down
Loading

0 comments on commit d7a4b06

Please sign in to comment.