|
|
|
@ -34,8 +34,8 @@ import java.util.Arrays; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Optional; |
|
|
|
|
import java.util.Random; |
|
|
|
|
import java.util.function.Supplier; |
|
|
|
|
|
|
|
|
|
import com.google.common.base.Supplier; |
|
|
|
|
import com.google.common.base.Suppliers; |
|
|
|
|
import com.google.common.collect.Lists; |
|
|
|
|
import org.apache.tuweni.bytes.Bytes; |
|
|
|
@ -77,7 +77,6 @@ public class IbftExtraDataEncoderTest { |
|
|
|
|
@Test |
|
|
|
|
public void correctlyCodedRoundConstitutesValidContent() { |
|
|
|
|
final List<Address> validators = Lists.newArrayList(); |
|
|
|
|
final Optional<Vote> vote = Optional.of(Vote.authVote(Address.fromHexString("1"))); |
|
|
|
|
final int round = 0x00FEDCBA; |
|
|
|
|
final byte[] roundAsByteArray = new byte[] {(byte) 0x00, (byte) 0xFE, (byte) 0xDC, (byte) 0xBA}; |
|
|
|
|
final List<SECPSignature> committerSeals = Lists.newArrayList(); |
|
|
|
@ -92,7 +91,10 @@ public class IbftExtraDataEncoderTest { |
|
|
|
|
encoder.writeList(validators, (validator, rlp) -> rlp.writeBytes(validator)); |
|
|
|
|
|
|
|
|
|
// encoded vote
|
|
|
|
|
vote.get().writeTo(encoder); |
|
|
|
|
encoder.startList(); |
|
|
|
|
encoder.writeBytes(Address.fromHexString("1")); |
|
|
|
|
encoder.writeByte(Vote.ADD_BYTE_VALUE); |
|
|
|
|
encoder.endList(); |
|
|
|
|
|
|
|
|
|
// This is to verify that the decoding works correctly when the round is encoded as 4 bytes
|
|
|
|
|
encoder.writeBytes(Bytes.wrap(roundAsByteArray)); |
|
|
|
@ -116,7 +118,6 @@ public class IbftExtraDataEncoderTest { |
|
|
|
|
@Test |
|
|
|
|
public void incorrectlyEncodedRoundThrowsRlpException() { |
|
|
|
|
final List<Address> validators = Lists.newArrayList(); |
|
|
|
|
final Optional<Vote> vote = Optional.of(Vote.authVote(Address.fromHexString("1"))); |
|
|
|
|
final byte[] roundAsByteArray = new byte[] {(byte) 0xFE, (byte) 0xDC, (byte) 0xBA}; |
|
|
|
|
final List<SECPSignature> committerSeals = Lists.newArrayList(); |
|
|
|
|
|
|
|
|
@ -130,7 +131,10 @@ public class IbftExtraDataEncoderTest { |
|
|
|
|
encoder.writeList(validators, (validator, rlp) -> rlp.writeBytes(validator)); |
|
|
|
|
|
|
|
|
|
// encoded vote
|
|
|
|
|
vote.get().writeTo(encoder); |
|
|
|
|
encoder.startList(); |
|
|
|
|
encoder.writeBytes(Address.fromHexString("1")); |
|
|
|
|
encoder.writeByte(Vote.ADD_BYTE_VALUE); |
|
|
|
|
encoder.endList(); |
|
|
|
|
|
|
|
|
|
// This is to verify that the decoding throws an exception when the round number is not encoded
|
|
|
|
|
// in 4 byte format
|
|
|
|
@ -201,7 +205,6 @@ public class IbftExtraDataEncoderTest { |
|
|
|
|
@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(); |
|
|
|
|
|
|
|
|
@ -215,7 +218,10 @@ public class IbftExtraDataEncoderTest { |
|
|
|
|
encoder.writeList(validators, (validator, rlp) -> rlp.writeBytes(validator)); |
|
|
|
|
|
|
|
|
|
// encoded vote
|
|
|
|
|
vote.get().writeTo(encoder); |
|
|
|
|
encoder.startList(); |
|
|
|
|
encoder.writeBytes(Address.fromHexString("1")); |
|
|
|
|
encoder.writeByte(Vote.DROP_BYTE_VALUE); |
|
|
|
|
encoder.endList(); |
|
|
|
|
|
|
|
|
|
encoder.writeInt(round); |
|
|
|
|
encoder.writeList(committerSeals, (committer, rlp) -> rlp.writeBytes(committer.encodedBytes())); |
|
|
|
@ -358,7 +364,10 @@ public class IbftExtraDataEncoderTest { |
|
|
|
|
encoder.writeList(validators, (validator, rlp) -> rlp.writeBytes(validator)); |
|
|
|
|
|
|
|
|
|
// encoded vote
|
|
|
|
|
vote.get().writeTo(encoder); |
|
|
|
|
encoder.startList(); |
|
|
|
|
encoder.writeBytes(vote.get().getRecipient()); |
|
|
|
|
encoder.writeByte(Vote.ADD_BYTE_VALUE); |
|
|
|
|
encoder.endList(); |
|
|
|
|
|
|
|
|
|
encoder.writeInt(round); |
|
|
|
|
encoder.endList(); |
|
|
|
@ -393,7 +402,10 @@ public class IbftExtraDataEncoderTest { |
|
|
|
|
encoder.writeList(validators, (validator, rlp) -> rlp.writeBytes(validator)); |
|
|
|
|
|
|
|
|
|
// encoded vote
|
|
|
|
|
vote.get().writeTo(encoder); |
|
|
|
|
encoder.startList(); |
|
|
|
|
encoder.writeBytes(vote.get().getRecipient()); |
|
|
|
|
encoder.writeByte(Vote.ADD_BYTE_VALUE); |
|
|
|
|
encoder.endList(); |
|
|
|
|
|
|
|
|
|
encoder.endList(); |
|
|
|
|
|
|
|
|
@ -409,7 +421,6 @@ public class IbftExtraDataEncoderTest { |
|
|
|
|
@Test |
|
|
|
|
public void incorrectlyStructuredRlpThrowsException() { |
|
|
|
|
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(); |
|
|
|
|
|
|
|
|
@ -423,7 +434,10 @@ public class IbftExtraDataEncoderTest { |
|
|
|
|
encoder.writeList(validators, (validator, rlp) -> rlp.writeBytes(validator)); |
|
|
|
|
|
|
|
|
|
// encoded vote
|
|
|
|
|
vote.get().writeTo(encoder); |
|
|
|
|
encoder.startList(); |
|
|
|
|
encoder.writeBytes(Address.fromHexString("1")); |
|
|
|
|
encoder.writeByte(Vote.ADD_BYTE_VALUE); |
|
|
|
|
encoder.endList(); |
|
|
|
|
|
|
|
|
|
encoder.writeInt(round); |
|
|
|
|
encoder.writeList(committerSeals, (committer, rlp) -> rlp.writeBytes(committer.encodedBytes())); |
|
|
|
|