mirror of https://github.com/hyperledger/besu
Remove qbft reference tests (#4893)
* Remove qbft reference tests submodule
* Remove snakeyml dependency
Signed-off-by: Jason Frame <jason.frame@consensys.net>
* Revert "Remove snakeyml dependency"
This reverts commit 4ae0dcd8e5
.
Signed-off-by: Jason Frame <jason.frame@consensys.net>
Signed-off-by: Jason Frame <jason.frame@consensys.net>
Co-authored-by: Sally MacFarlane <macfarla.github@gmail.com>
pull/4905/head
parent
25f197eeb9
commit
173da2a15d
@ -1,85 +0,0 @@ |
||||
/* |
||||
* Copyright ConsenSys AG. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
package org.hyperledger.besu.consensus.qbt.support; |
||||
|
||||
import org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier; |
||||
import org.hyperledger.besu.consensus.common.bft.messagewrappers.BftMessage; |
||||
import org.hyperledger.besu.consensus.common.bft.payload.SignedData; |
||||
import org.hyperledger.besu.consensus.qbft.messagewrappers.Commit; |
||||
import org.hyperledger.besu.consensus.qbft.payload.CommitPayload; |
||||
import org.hyperledger.besu.crypto.SignatureAlgorithm; |
||||
import org.hyperledger.besu.crypto.SignatureAlgorithmFactory; |
||||
import org.hyperledger.besu.datatypes.Hash; |
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator; |
||||
import com.fasterxml.jackson.annotation.JsonProperty; |
||||
import com.google.common.base.Supplier; |
||||
import com.google.common.base.Suppliers; |
||||
import org.apache.tuweni.bytes.Bytes; |
||||
|
||||
public class CommitMessage implements RlpTestCaseMessage { |
||||
private static final Supplier<SignatureAlgorithm> SIGNATURE_ALGORITHM = |
||||
Suppliers.memoize(SignatureAlgorithmFactory::getInstance); |
||||
private final UnsignedCommit unsignedCommit; |
||||
private final String signature; |
||||
|
||||
@JsonCreator |
||||
public CommitMessage( |
||||
@JsonProperty("unsignedCommit") final UnsignedCommit unsignedCommit, |
||||
@JsonProperty("signature") final String signature) { |
||||
this.unsignedCommit = unsignedCommit; |
||||
this.signature = signature; |
||||
} |
||||
|
||||
@Override |
||||
public BftMessage<CommitPayload> fromRlp(final Bytes rlp) { |
||||
return Commit.decode(rlp); |
||||
} |
||||
|
||||
@Override |
||||
public BftMessage<CommitPayload> toBftMessage() { |
||||
final CommitPayload commitPayload = |
||||
new CommitPayload( |
||||
new ConsensusRoundIdentifier(unsignedCommit.sequence, unsignedCommit.round), |
||||
Hash.fromHexStringLenient(unsignedCommit.digest), |
||||
SIGNATURE_ALGORITHM |
||||
.get() |
||||
.decodeSignature(Bytes.fromHexString(unsignedCommit.commitSeal))); |
||||
final SignedData<CommitPayload> signedCommitPayload = |
||||
SignedData.create( |
||||
commitPayload, |
||||
SIGNATURE_ALGORITHM.get().decodeSignature(Bytes.fromHexString(signature))); |
||||
return new Commit(signedCommitPayload); |
||||
} |
||||
|
||||
public static class UnsignedCommit { |
||||
private final long sequence; |
||||
private final int round; |
||||
private final String commitSeal; |
||||
private final String digest; |
||||
|
||||
@JsonCreator |
||||
public UnsignedCommit( |
||||
@JsonProperty("sequence") final long sequence, |
||||
@JsonProperty("round") final int round, |
||||
@JsonProperty("commitSeal") final String commitSeal, |
||||
@JsonProperty("digest") final String digest) { |
||||
this.sequence = sequence; |
||||
this.round = round; |
||||
this.commitSeal = commitSeal; |
||||
this.digest = digest; |
||||
} |
||||
} |
||||
} |
@ -1,77 +0,0 @@ |
||||
/* |
||||
* Copyright ConsenSys AG. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
package org.hyperledger.besu.consensus.qbt.support; |
||||
|
||||
import org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier; |
||||
import org.hyperledger.besu.consensus.common.bft.messagewrappers.BftMessage; |
||||
import org.hyperledger.besu.consensus.common.bft.payload.SignedData; |
||||
import org.hyperledger.besu.consensus.qbft.messagewrappers.Prepare; |
||||
import org.hyperledger.besu.consensus.qbft.payload.PreparePayload; |
||||
import org.hyperledger.besu.crypto.SignatureAlgorithmFactory; |
||||
import org.hyperledger.besu.datatypes.Hash; |
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator; |
||||
import com.fasterxml.jackson.annotation.JsonProperty; |
||||
import org.apache.tuweni.bytes.Bytes; |
||||
|
||||
public class PrepareMessage implements RlpTestCaseMessage { |
||||
private final UnsignedPrepare unsignedPrepare; |
||||
private final String signature; |
||||
|
||||
@JsonCreator |
||||
public PrepareMessage( |
||||
@JsonProperty("unsignedPrepare") final UnsignedPrepare unsignedPrepare, |
||||
@JsonProperty("signature") final String signature) { |
||||
this.unsignedPrepare = unsignedPrepare; |
||||
this.signature = signature; |
||||
} |
||||
|
||||
@Override |
||||
public BftMessage<PreparePayload> fromRlp(final Bytes rlp) { |
||||
return Prepare.decode(rlp); |
||||
} |
||||
|
||||
@Override |
||||
public BftMessage<PreparePayload> toBftMessage() { |
||||
return new Prepare(toSignedPreparePayload(this)); |
||||
} |
||||
|
||||
public static SignedData<PreparePayload> toSignedPreparePayload( |
||||
final PrepareMessage prepareMessage) { |
||||
final UnsignedPrepare unsignedPrepare = prepareMessage.unsignedPrepare; |
||||
return SignedData.create( |
||||
new PreparePayload( |
||||
new ConsensusRoundIdentifier(unsignedPrepare.sequence, unsignedPrepare.round), |
||||
Hash.fromHexString(unsignedPrepare.digest)), |
||||
SignatureAlgorithmFactory.getInstance() |
||||
.decodeSignature(Bytes.fromHexString(prepareMessage.signature))); |
||||
} |
||||
|
||||
public static class UnsignedPrepare { |
||||
private final long sequence; |
||||
private final int round; |
||||
private final String digest; |
||||
|
||||
@JsonCreator |
||||
public UnsignedPrepare( |
||||
@JsonProperty("sequence") final long sequence, |
||||
@JsonProperty("round") final int round, |
||||
@JsonProperty("digest") final String digest) { |
||||
this.sequence = sequence; |
||||
this.round = round; |
||||
this.digest = digest; |
||||
} |
||||
} |
||||
} |
@ -1,115 +0,0 @@ |
||||
/* |
||||
* Copyright ConsenSys AG. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
package org.hyperledger.besu.consensus.qbt.support; |
||||
|
||||
import org.hyperledger.besu.consensus.common.bft.BftBlockHeaderFunctions; |
||||
import org.hyperledger.besu.consensus.common.bft.BftExtraDataCodec; |
||||
import org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier; |
||||
import org.hyperledger.besu.consensus.common.bft.messagewrappers.BftMessage; |
||||
import org.hyperledger.besu.consensus.common.bft.payload.SignedData; |
||||
import org.hyperledger.besu.consensus.qbft.QbftExtraDataCodec; |
||||
import org.hyperledger.besu.consensus.qbft.messagewrappers.Proposal; |
||||
import org.hyperledger.besu.consensus.qbft.payload.PreparePayload; |
||||
import org.hyperledger.besu.consensus.qbft.payload.ProposalPayload; |
||||
import org.hyperledger.besu.consensus.qbft.payload.RoundChangePayload; |
||||
import org.hyperledger.besu.consensus.qbt.support.RoundChangeMessage.SignedRoundChange; |
||||
import org.hyperledger.besu.crypto.SignatureAlgorithmFactory; |
||||
import org.hyperledger.besu.ethereum.core.Block; |
||||
import org.hyperledger.besu.ethereum.rlp.RLP; |
||||
|
||||
import java.util.List; |
||||
import java.util.stream.Collectors; |
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator; |
||||
import com.fasterxml.jackson.annotation.JsonProperty; |
||||
import com.fasterxml.jackson.annotation.JsonTypeInfo; |
||||
import org.apache.tuweni.bytes.Bytes; |
||||
|
||||
public class ProposalMessage implements RlpTestCaseMessage { |
||||
private static final BftExtraDataCodec bftExtraDataCodec = new QbftExtraDataCodec(); |
||||
|
||||
private final SignedProposal signedProposal; |
||||
private final List<SignedRoundChange> roundChanges; |
||||
|
||||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, defaultImpl = PrepareMessage.class) |
||||
private final List<PrepareMessage> prepares; |
||||
|
||||
public ProposalMessage( |
||||
@JsonProperty("signedProposal") final SignedProposal signedProposal, |
||||
@JsonProperty("roundChanges") final List<SignedRoundChange> roundChanges, |
||||
@JsonProperty("prepares") final List<PrepareMessage> prepares) { |
||||
this.signedProposal = signedProposal; |
||||
this.roundChanges = roundChanges; |
||||
this.prepares = prepares; |
||||
} |
||||
|
||||
@Override |
||||
public BftMessage<ProposalPayload> fromRlp(final Bytes rlp) { |
||||
return Proposal.decode(rlp, bftExtraDataCodec); |
||||
} |
||||
|
||||
@Override |
||||
public BftMessage<ProposalPayload> toBftMessage() { |
||||
final List<SignedData<RoundChangePayload>> signedRoundChanges = |
||||
roundChanges.stream() |
||||
.map(SignedRoundChange::toSignedRoundChangePayload) |
||||
.collect(Collectors.toList()); |
||||
final List<SignedData<PreparePayload>> signedPrepares = |
||||
prepares.stream().map(PrepareMessage::toSignedPreparePayload).collect(Collectors.toList()); |
||||
final Block block = |
||||
Block.readFrom( |
||||
RLP.input(Bytes.fromHexString(signedProposal.unsignedProposal.block)), |
||||
BftBlockHeaderFunctions.forCommittedSeal(new QbftExtraDataCodec())); |
||||
final ProposalPayload proposalPayload = |
||||
new ProposalPayload( |
||||
new ConsensusRoundIdentifier( |
||||
signedProposal.unsignedProposal.sequence, signedProposal.unsignedProposal.round), |
||||
block); |
||||
final SignedData<ProposalPayload> signedProposalPayload = |
||||
SignedData.create( |
||||
proposalPayload, |
||||
SignatureAlgorithmFactory.getInstance() |
||||
.decodeSignature(Bytes.fromHexString(signedProposal.signature))); |
||||
return new Proposal(signedProposalPayload, signedRoundChanges, signedPrepares); |
||||
} |
||||
|
||||
public static class SignedProposal { |
||||
private final UnsignedProposal unsignedProposal; |
||||
private final String signature; |
||||
|
||||
public SignedProposal( |
||||
@JsonProperty("unsignedProposal") final UnsignedProposal unsignedProposal, |
||||
@JsonProperty("signature") final String signature) { |
||||
this.unsignedProposal = unsignedProposal; |
||||
this.signature = signature; |
||||
} |
||||
} |
||||
|
||||
public static class UnsignedProposal { |
||||
private final long sequence; |
||||
private final int round; |
||||
private final String block; |
||||
|
||||
@JsonCreator |
||||
public UnsignedProposal( |
||||
@JsonProperty("sequence") final long sequence, |
||||
@JsonProperty("round") final int round, |
||||
@JsonProperty("block") final String block) { |
||||
this.sequence = sequence; |
||||
this.round = round; |
||||
this.block = block; |
||||
} |
||||
} |
||||
} |
@ -1,35 +0,0 @@ |
||||
/* |
||||
* Copyright ConsenSys AG. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
package org.hyperledger.besu.consensus.qbt.support; |
||||
|
||||
import org.hyperledger.besu.consensus.common.bft.messagewrappers.BftMessage; |
||||
|
||||
import com.fasterxml.jackson.annotation.JsonSubTypes; |
||||
import com.fasterxml.jackson.annotation.JsonTypeInfo; |
||||
import org.apache.tuweni.bytes.Bytes; |
||||
|
||||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type") |
||||
@JsonSubTypes({ |
||||
@JsonSubTypes.Type(value = CommitMessage.class, name = "commit"), |
||||
@JsonSubTypes.Type(value = PrepareMessage.class, name = "prepare"), |
||||
@JsonSubTypes.Type(value = RoundChangeMessage.class, name = "roundChange"), |
||||
@JsonSubTypes.Type(value = ProposalMessage.class, name = "proposal"), |
||||
}) |
||||
public interface RlpTestCaseMessage { |
||||
|
||||
BftMessage<?> fromRlp(Bytes rlp); |
||||
|
||||
BftMessage<?> toBftMessage(); |
||||
} |
@ -1,39 +0,0 @@ |
||||
/* |
||||
* Copyright ConsenSys AG. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
package org.hyperledger.besu.consensus.qbt.support; |
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator; |
||||
import com.fasterxml.jackson.annotation.JsonProperty; |
||||
|
||||
public class RlpTestCaseSpec { |
||||
private final RlpTestCaseMessage message; |
||||
private final String rlp; |
||||
|
||||
@JsonCreator |
||||
public RlpTestCaseSpec( |
||||
@JsonProperty("message") final RlpTestCaseMessage message, |
||||
@JsonProperty("rlp") final String rlp) { |
||||
this.message = message; |
||||
this.rlp = rlp; |
||||
} |
||||
|
||||
public RlpTestCaseMessage getMessage() { |
||||
return message; |
||||
} |
||||
|
||||
public String getRlp() { |
||||
return rlp; |
||||
} |
||||
} |
@ -1,128 +0,0 @@ |
||||
/* |
||||
* Copyright ConsenSys AG. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
package org.hyperledger.besu.consensus.qbt.support; |
||||
|
||||
import static org.hyperledger.besu.consensus.common.bft.BftBlockHeaderFunctions.forCommittedSeal; |
||||
|
||||
import org.hyperledger.besu.consensus.common.bft.BftExtraDataCodec; |
||||
import org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier; |
||||
import org.hyperledger.besu.consensus.common.bft.messagewrappers.BftMessage; |
||||
import org.hyperledger.besu.consensus.common.bft.payload.SignedData; |
||||
import org.hyperledger.besu.consensus.qbft.QbftExtraDataCodec; |
||||
import org.hyperledger.besu.consensus.qbft.messagewrappers.RoundChange; |
||||
import org.hyperledger.besu.consensus.qbft.payload.PreparePayload; |
||||
import org.hyperledger.besu.consensus.qbft.payload.PreparedRoundMetadata; |
||||
import org.hyperledger.besu.consensus.qbft.payload.RoundChangePayload; |
||||
import org.hyperledger.besu.crypto.SignatureAlgorithmFactory; |
||||
import org.hyperledger.besu.datatypes.Hash; |
||||
import org.hyperledger.besu.ethereum.core.Block; |
||||
import org.hyperledger.besu.ethereum.rlp.RLP; |
||||
import org.hyperledger.besu.ethereum.rlp.RLPInput; |
||||
|
||||
import java.util.List; |
||||
import java.util.Optional; |
||||
import java.util.stream.Collectors; |
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator; |
||||
import com.fasterxml.jackson.annotation.JsonProperty; |
||||
import com.fasterxml.jackson.annotation.JsonTypeInfo; |
||||
import org.apache.tuweni.bytes.Bytes; |
||||
|
||||
public class RoundChangeMessage implements RlpTestCaseMessage { |
||||
private static final BftExtraDataCodec bftExtraDataCodec = new QbftExtraDataCodec(); |
||||
|
||||
private final SignedRoundChange signedRoundChange; |
||||
private final Optional<String> block; |
||||
|
||||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, defaultImpl = PrepareMessage.class) |
||||
private final List<PrepareMessage> prepares; |
||||
|
||||
public RoundChangeMessage( |
||||
@JsonProperty("signedRoundChange") final SignedRoundChange signedRoundChange, |
||||
@JsonProperty("block") final Optional<String> block, |
||||
@JsonProperty("prepares") final List<PrepareMessage> prepares) { |
||||
this.signedRoundChange = signedRoundChange; |
||||
this.block = block; |
||||
this.prepares = prepares; |
||||
} |
||||
|
||||
@Override |
||||
public BftMessage<RoundChangePayload> fromRlp(final Bytes rlp) { |
||||
return RoundChange.decode(rlp, bftExtraDataCodec); |
||||
} |
||||
|
||||
@Override |
||||
public BftMessage<RoundChangePayload> toBftMessage() { |
||||
final Optional<RLPInput> blockRlp = this.block.map(s -> RLP.input(Bytes.fromHexString(s))); |
||||
final Optional<Block> block = |
||||
blockRlp.map(r -> Block.readFrom(r, forCommittedSeal(new QbftExtraDataCodec()))); |
||||
final List<SignedData<PreparePayload>> signedPrepares = |
||||
prepares.stream().map(PrepareMessage::toSignedPreparePayload).collect(Collectors.toList()); |
||||
return new RoundChange( |
||||
SignedRoundChange.toSignedRoundChangePayload(signedRoundChange), block, signedPrepares); |
||||
} |
||||
|
||||
public static class UnsignedRoundChange { |
||||
private final long sequence; |
||||
private final int round; |
||||
private final Optional<String> preparedValue; |
||||
private final Optional<Integer> preparedRound; |
||||
|
||||
@JsonCreator |
||||
public UnsignedRoundChange( |
||||
@JsonProperty("sequence") final long sequence, |
||||
@JsonProperty("round") final int round, |
||||
@JsonProperty("preparedValue") final Optional<String> preparedValue, |
||||
@JsonProperty("preparedRound") final Optional<Integer> preparedRound) { |
||||
this.sequence = sequence; |
||||
this.round = round; |
||||
this.preparedValue = preparedValue; |
||||
this.preparedRound = preparedRound; |
||||
} |
||||
} |
||||
|
||||
public static class SignedRoundChange { |
||||
private final UnsignedRoundChange unsignedRoundChange; |
||||
private final String signature; |
||||
|
||||
public SignedRoundChange( |
||||
@JsonProperty("unsignedRoundChange") final UnsignedRoundChange unsignedRoundChange, |
||||
@JsonProperty("signature") final String signature) { |
||||
this.unsignedRoundChange = unsignedRoundChange; |
||||
this.signature = signature; |
||||
} |
||||
|
||||
public static SignedData<RoundChangePayload> toSignedRoundChangePayload( |
||||
final SignedRoundChange signedRoundChange) { |
||||
final UnsignedRoundChange unsignedRoundChange = signedRoundChange.unsignedRoundChange; |
||||
final Optional<PreparedRoundMetadata> preparedRoundMetadata = |
||||
unsignedRoundChange.preparedRound.isPresent() |
||||
&& unsignedRoundChange.preparedValue.isPresent() |
||||
? Optional.of( |
||||
new PreparedRoundMetadata( |
||||
Hash.fromHexString(unsignedRoundChange.preparedValue.get()), |
||||
unsignedRoundChange.preparedRound.get())) |
||||
: Optional.empty(); |
||||
final RoundChangePayload roundChangePayload = |
||||
new RoundChangePayload( |
||||
new ConsensusRoundIdentifier(unsignedRoundChange.sequence, unsignedRoundChange.round), |
||||
preparedRoundMetadata); |
||||
return SignedData.create( |
||||
roundChangePayload, |
||||
SignatureAlgorithmFactory.getInstance() |
||||
.decodeSignature(Bytes.fromHexString(signedRoundChange.signature))); |
||||
} |
||||
} |
||||
} |
@ -1,64 +0,0 @@ |
||||
/* |
||||
* Copyright ConsenSys AG. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
package org.hyperledger.besu.consensus.qbt.test; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
import static org.junit.Assume.assumeTrue; |
||||
|
||||
import org.hyperledger.besu.consensus.common.bft.messagewrappers.BftMessage; |
||||
import org.hyperledger.besu.consensus.qbt.support.RlpTestCaseSpec; |
||||
import org.hyperledger.besu.testutil.JsonTestParameters; |
||||
|
||||
import java.util.Collection; |
||||
|
||||
import org.apache.tuweni.bytes.Bytes; |
||||
import org.junit.Test; |
||||
import org.junit.runner.RunWith; |
||||
import org.junit.runners.Parameterized; |
||||
import org.junit.runners.Parameterized.Parameters; |
||||
|
||||
@RunWith(Parameterized.class) |
||||
public class MessageRlpTest { |
||||
|
||||
private static final String TEST_CONFIG_PATH = "MessageRLPTests/"; |
||||
private final RlpTestCaseSpec spec; |
||||
|
||||
@Parameters(name = "Name: {0}") |
||||
public static Collection<Object[]> getTestParametersForConfig() { |
||||
return JsonTestParameters.create(RlpTestCaseSpec.class).generate(TEST_CONFIG_PATH); |
||||
} |
||||
|
||||
@Test |
||||
public void encode() { |
||||
final Bytes expectedRlp = Bytes.fromHexString(spec.getRlp()); |
||||
assertThat(spec.getMessage().toBftMessage().encode()).isEqualTo(expectedRlp); |
||||
} |
||||
|
||||
@Test |
||||
public void decode() { |
||||
final BftMessage<?> expectedBftMessage = spec.getMessage().toBftMessage(); |
||||
final BftMessage<?> decodedBftMessage = |
||||
spec.getMessage().fromRlp(Bytes.fromHexString(spec.getRlp())); |
||||
assertThat(decodedBftMessage) |
||||
.usingRecursiveComparison() |
||||
.usingOverriddenEquals() |
||||
.isEqualTo(expectedBftMessage); |
||||
} |
||||
|
||||
public MessageRlpTest(final String name, final RlpTestCaseSpec spec, final boolean runTest) { |
||||
this.spec = spec; |
||||
assumeTrue("Test was blacklisted", runTest); |
||||
} |
||||
} |
@ -1 +0,0 @@ |
||||
Subproject commit c0077a14e0d773e239ba944f371ea640df8b1b60 |
Loading…
Reference in new issue