use of org.hyperledger.besu.ethereum.eth.manager.ForkId in project besu by hyperledger.
the class StatusMessageTest method serializeDeserializeWithForkId.
@Test
public void serializeDeserializeWithForkId() {
final int version = EthProtocol.EthVersion.V64;
final BigInteger networkId = BigInteger.ONE;
final Difficulty td = Difficulty.of(1000L);
final Hash bestHash = randHash(1L);
final Hash genesisHash = randHash(2L);
final ForkId forkId = new ForkId(Bytes.fromHexString("0xa00bc334"), 0L);
final MessageData msg = StatusMessage.create(version, networkId, td, bestHash, genesisHash, forkId);
final StatusMessage copy = new StatusMessage(msg.getData());
assertThat(copy.protocolVersion()).isEqualTo(version);
assertThat(copy.networkId()).isEqualTo(networkId);
assertThat(copy.totalDifficulty()).isEqualTo(td);
assertThat(copy.bestHash()).isEqualTo(bestHash);
assertThat(copy.genesisHash()).isEqualTo(genesisHash);
assertThat(copy.forkId()).isEqualTo(forkId);
}
use of org.hyperledger.besu.ethereum.eth.manager.ForkId in project besu by hyperledger.
the class ForkIdBackwardCompatibilityTest method assertBackwardCompatibilityWorks.
@Test
public void assertBackwardCompatibilityWorks() {
LOG.info("Running test case {}", name);
final ForkIdManager forkIdManager = new ForkIdManager(mockBlockchain(genesisHash, head), forks, legacyEth64);
final ForkId legacyForkId = legacyEth64 ? new LegacyForkIdManager(mockBlockchain(genesisHash, head), forks).getLatestForkId() : null;
assertThat(forkIdManager.getForkIdForChainHead()).isEqualTo(legacyEth64 ? legacyForkId : wantForkId);
}
use of org.hyperledger.besu.ethereum.eth.manager.ForkId in project besu by hyperledger.
the class LegacyForkIdManager method readFrom.
public static ForkId readFrom(final RLPInput in) {
in.enterList();
final Bytes hash = in.readBytes();
final Bytes next = in.readBytes();
in.leaveList();
return new ForkId(hash, next);
}
use of org.hyperledger.besu.ethereum.eth.manager.ForkId in project besu by hyperledger.
the class LegacyForkIdManager method createForkIds.
private void createForkIds() {
final CRC32 crc = new CRC32();
crc.update(genesisHash.toArray());
final List<Bytes> forkHashes = new ArrayList<>(List.of(getCurrentCrcHash(crc)));
for (final Long fork : forks) {
updateCrc(crc, fork);
forkHashes.add(getCurrentCrcHash(crc));
}
final List<ForkId> forkIds = new ArrayList<>();
// This loop is for all the fork hashes that have an associated "next fork"
for (int i = 0; i < forks.size(); i++) {
forkIds.add(new ForkId(forkHashes.get(i), forks.get(i)));
}
if (!forks.isEmpty()) {
forkIds.add(new ForkId(forkHashes.get(forkHashes.size() - 1), 0));
}
this.forkAndHashList = forkIds;
System.out.println(this.forkAndHashList);
}
use of org.hyperledger.besu.ethereum.eth.manager.ForkId in project besu by hyperledger.
the class StatusMessageTest method toStringHasExpectedInfo.
@Test
public void toStringHasExpectedInfo() {
final int version = EthProtocol.EthVersion.V64;
final BigInteger networkId = BigInteger.ONE;
final Difficulty td = Difficulty.of(1000L);
final Hash bestHash = randHash(1L);
final Hash genesisHash = randHash(2L);
final ForkId forkId = new ForkId(Bytes.fromHexString("0xa00bc334"), 0L);
final MessageData msg = StatusMessage.create(version, networkId, td, bestHash, genesisHash, forkId);
final StatusMessage copy = new StatusMessage(msg.getData());
final String copyToString = copy.toString();
assertThat(copyToString).contains("bestHash=" + bestHash);
assertThat(copyToString).contains("genesisHash=" + genesisHash);
}
Aggregations