use of org.hyperledger.besu.consensus.common.bft.Vote in project besu by hyperledger.
the class PkiQbftExtraDataCodecTest method getDecodedExtraData.
private static PkiQbftExtraData getDecodedExtraData(final Bytes cms) {
final List<Address> validators = Arrays.asList(Address.fromHexString("1"), Address.fromHexString("2"));
final Optional<Vote> vote = Optional.of(Vote.authVote(Address.fromHexString("1")));
final int round = 0x00FEDCBA;
final List<SECPSignature> committerSeals = Arrays.asList(SIGNATURE_ALGORITHM.get().createSignature(BigInteger.ONE, BigInteger.TEN, (byte) 0), SIGNATURE_ALGORITHM.get().createSignature(BigInteger.TEN, BigInteger.ONE, (byte) 0));
// Create a byte buffer with no data.
final byte[] vanity_bytes = createNonEmptyVanityData();
final Bytes vanity_data = Bytes.wrap(vanity_bytes);
return new PkiQbftExtraData(vanity_data, committerSeals, vote, round, validators, cms);
}
use of org.hyperledger.besu.consensus.common.bft.Vote in project besu by hyperledger.
the class QbftExtraDataCodecTest method extraDataCanBeEncodedWithoutCommitSeals.
@Test
public void extraDataCanBeEncodedWithoutCommitSeals() {
final List<Address> validators = Arrays.asList(Address.fromHexString("1"), Address.fromHexString("2"));
final Optional<Vote> vote = Optional.of(Vote.authVote(Address.fromHexString("1")));
final int round = 0x00FEDCBA;
final List<SECPSignature> committerSeals = Arrays.asList(SIGNATURE_ALGORITHM.get().createSignature(BigInteger.ONE, BigInteger.TEN, (byte) 0), SIGNATURE_ALGORITHM.get().createSignature(BigInteger.TEN, BigInteger.ONE, (byte) 0));
// Create a byte buffer with no data.
final byte[] vanity_bytes = createNonEmptyVanityData();
final Bytes vanity_data = Bytes.wrap(vanity_bytes);
final BytesValueRLPOutput encoder = new BytesValueRLPOutput();
encoder.startList();
encoder.writeBytes(vanity_data);
encoder.writeList(validators, (validator, rlp) -> rlp.writeBytes(validator));
// encoded vote
encoder.startList();
encoder.writeBytes(Address.fromHexString("1"));
encoder.writeByte(Vote.ADD_BYTE_VALUE);
encoder.endList();
encoder.writeIntScalar(round);
encoder.writeEmptyList();
encoder.endList();
Bytes expectedEncoding = encoder.encoded();
Bytes actualEncoding = bftExtraDataCodec.encodeWithoutCommitSeals(new BftExtraData(vanity_data, committerSeals, vote, round, validators));
System.out.println("actualEncoding = " + actualEncoding);
assertThat(actualEncoding).isEqualTo(expectedEncoding);
}
use of org.hyperledger.besu.consensus.common.bft.Vote in project besu by hyperledger.
the class QbftExtraDataCodecTest method emptyListConstituteValidContent.
@Test
public void emptyListConstituteValidContent() {
final List<Address> validators = Lists.newArrayList();
final Optional<Vote> vote = Optional.of(Vote.dropVote(Address.fromHexString("1")));
final int round = 0x00FEDCBA;
final List<SECPSignature> committerSeals = Lists.newArrayList();
// Create a byte buffer with no data.
final byte[] vanity_bytes = new byte[32];
final Bytes vanity_data = Bytes.wrap(vanity_bytes);
final BytesValueRLPOutput encoder = new BytesValueRLPOutput();
encoder.startList();
encoder.writeBytes(vanity_data);
encoder.writeList(validators, (validator, rlp) -> rlp.writeBytes(validator));
// encoded vote
encoder.startList();
encoder.writeBytes(vote.get().getRecipient());
encoder.writeNull();
encoder.endList();
encoder.writeIntScalar(round);
encoder.writeList(committerSeals, (committer, rlp) -> rlp.writeBytes(committer.encodedBytes()));
encoder.endList();
final Bytes bufferToInject = encoder.encoded();
final BftExtraData extraData = bftExtraDataCodec.decodeRaw(bufferToInject);
assertThat(extraData.getVanityData()).isEqualTo(vanity_data);
assertThat(extraData.getRound()).isEqualTo(round);
assertThat(extraData.getSeals()).isEqualTo(committerSeals);
assertThat(extraData.getValidators()).isEqualTo(validators);
}
use of org.hyperledger.besu.consensus.common.bft.Vote in project besu by hyperledger.
the class QbftExtraDataCodecTest method correctlyCodedRoundConstitutesValidContent.
@Test
public void correctlyCodedRoundConstitutesValidContent() {
final List<Address> validators = Lists.newArrayList();
final Optional<Vote> vote = Optional.of(Vote.authVote(Address.fromHexString("1")));
final int round = 0xDCBA;
final byte[] roundAsByteArray = new byte[] { (byte) 0xDC, (byte) 0xBA };
final List<SECPSignature> committerSeals = Lists.newArrayList();
// Create a byte buffer with no data.
final byte[] vanity_bytes = new byte[32];
final Bytes vanity_data = Bytes.wrap(vanity_bytes);
final BytesValueRLPOutput encoder = new BytesValueRLPOutput();
encoder.startList();
encoder.writeBytes(vanity_data);
encoder.writeList(validators, (validator, rlp) -> rlp.writeBytes(validator));
encoder.startList();
encoder.writeBytes(vote.get().getRecipient());
encoder.writeByte(Vote.ADD_BYTE_VALUE);
encoder.endList();
// This is to verify that the decoding works correctly when the round is encoded as non-fixed
// length bytes
encoder.writeBytes(Bytes.wrap(roundAsByteArray));
encoder.writeList(committerSeals, (committer, rlp) -> rlp.writeBytes(committer.encodedBytes()));
encoder.endList();
final Bytes bufferToInject = encoder.encoded();
final BftExtraData extraData = bftExtraDataCodec.decodeRaw(bufferToInject);
assertThat(extraData.getVanityData()).isEqualTo(vanity_data);
assertThat(extraData.getRound()).isEqualTo(round);
assertThat(extraData.getSeals()).isEqualTo(committerSeals);
assertThat(extraData.getValidators()).isEqualTo(validators);
}
use of org.hyperledger.besu.consensus.common.bft.Vote in project besu by hyperledger.
the class QbftExtraDataCodecTest method emptyListsAreEncodedAndDecodedCorrectly.
@Test
public void emptyListsAreEncodedAndDecodedCorrectly() {
final List<Address> validators = Lists.newArrayList();
final Optional<Vote> vote = Optional.of(Vote.authVote(Address.fromHexString("1")));
final int round = 0x00FEDCBA;
final List<SECPSignature> committerSeals = Lists.newArrayList();
// Create a byte buffer with no data.
final byte[] vanity_bytes = new byte[32];
final Bytes vanity_data = Bytes.wrap(vanity_bytes);
BftExtraData expectedExtraData = new BftExtraData(vanity_data, committerSeals, vote, round, validators);
BftExtraData actualExtraData = bftExtraDataCodec.decodeRaw(bftExtraDataCodec.encode(expectedExtraData));
assertThat(actualExtraData).isEqualToComparingFieldByField(expectedExtraData);
}
Aggregations