use of com.hedera.mirror.common.domain.addressbook.AddressBook in project hedera-mirror-node by hashgraph.
the class AddressBookServiceImplTest method assertAddressBookData.
private void assertAddressBookData(byte[] expected, long consensusTimestamp) {
AddressBook actualAddressBook = addressBookRepository.findById(consensusTimestamp).get();
assertArrayEquals(expected, actualAddressBook.getFileData());
}
use of com.hedera.mirror.common.domain.addressbook.AddressBook in project hedera-mirror-node by hashgraph.
the class AddressBookServiceImplTest method verifyAddressBookEntriesWithNodeIdAndPortNotSet.
@Test
void verifyAddressBookEntriesWithNodeIdAndPortNotSet() {
Map<String, Integer> memoToNodeIdMap = Map.of("0.0.3", 0, "0.0.4", 1);
String[] accountIds = memoToNodeIdMap.keySet().stream().sorted().toArray(String[]::new);
// nodeId 0, port 0
NodeAddress nodeAddress1 = NodeAddress.newBuilder().setIpAddress(ByteString.copyFromUtf8("127.0.0.1")).setMemo(ByteString.copyFromUtf8(accountIds[0])).setNodeAccountId(AccountID.newBuilder().setAccountNum(3)).setNodeCertHash(ByteString.copyFromUtf8("nodeCertHash")).setRSAPubKey("rsa+public/key").build();
// nodeId 0, port 50211
NodeAddress nodeAddress2 = NodeAddress.newBuilder(nodeAddress1).setIpAddress(ByteString.copyFromUtf8("127.0.0.2")).setMemo(ByteString.copyFromUtf8(accountIds[1])).setNodeAccountId(AccountID.newBuilder().setAccountNum(4)).setPortno(50211).build();
NodeAddressBook nodeAddressBook = NodeAddressBook.newBuilder().addAllNodeAddress(List.of(nodeAddress1, nodeAddress2)).build();
byte[] addressBookBytes = nodeAddressBook.toByteArray();
long addressBookConsensusTimeStamp = 5L;
update(addressBookBytes, addressBookConsensusTimeStamp, true);
assertAddressBookData(addressBookBytes, addressBookConsensusTimeStamp + 1);
AddressBook addressBook = addressBookService.getCurrent();
ListAssert<AddressBookEntry> listAssert = assertThat(addressBook.getEntries()).hasSize(nodeAddressBook.getNodeAddressCount());
for (NodeAddress nodeAddress : nodeAddressBook.getNodeAddressList()) {
int expectedNodeId = memoToNodeIdMap.get(nodeAddress.getMemo().toStringUtf8());
listAssert.anySatisfy(abe -> {
assertThat(abe.getMemo()).isEqualTo(nodeAddress.getMemo().toStringUtf8());
assertThat(abe.getNodeAccountId()).isEqualTo(EntityId.of(nodeAddress.getNodeAccountId()));
assertThat(abe.getNodeCertHash()).isEqualTo(nodeAddress.getNodeCertHash().toByteArray());
assertThat(abe.getPublicKey()).isEqualTo(nodeAddress.getRSAPubKey());
// both entries have null node id
assertThat(abe.getNodeId()).isEqualTo(expectedNodeId);
assertAddressBookEndPoints(abe.getServiceEndpoints(), nodeAddress.getServiceEndpointList());
});
}
}
use of com.hedera.mirror.common.domain.addressbook.AddressBook in project hedera-mirror-node by hashgraph.
the class AbstractDownloaderTest method oneThirdConsensus.
@Test
@DisplayName("Exactly 1/3 consensus")
void oneThirdConsensus() throws Exception {
List<AddressBookEntry> entries = addressBook.getEntries().stream().limit(3).collect(Collectors.toList());
AddressBook addressBookWith3Nodes = addressBook.toBuilder().entries(entries).nodeCount(entries.size()).build();
doReturn(addressBookWith3Nodes).when(addressBookService).getCurrent();
mirrorProperties.setStartBlockNumber(null);
String nodeAccountId = entries.get(0).getNodeAccountId().toString();
log.info("Only copy node {}'s stream files and signature files for a 3-node network", nodeAccountId);
fileCopier.filterDirectories("*" + nodeAccountId).copy();
expectLastStreamFile(Instant.EPOCH);
downloader.download();
verifyForSuccess();
}
use of com.hedera.mirror.common.domain.addressbook.AddressBook in project hedera-mirror-node by hashgraph.
the class Fix102AddressBookMigrationTest method latest102WithNonNullTimestamp.
@Test
void latest102WithNonNullTimestamp() throws IOException {
AddressBook addressBook1 = addressBook(102, 1, 100L);
AddressBook addressBook2 = addressBook(101, 101, null);
AddressBook addressBook3 = addressBook(101, 201, null);
runMigration();
assertEndTimestamp(addressBook1, null);
assertEndTimestamp(addressBook2, 200L);
assertEndTimestamp(addressBook3, null);
}
use of com.hedera.mirror.common.domain.addressbook.AddressBook in project hedera-mirror-node by hashgraph.
the class Fix102AddressBookMigrationTest method noChanges.
@Test
void noChanges() throws IOException {
AddressBook addressBook1 = addressBook(102, 1, 100L);
AddressBook addressBook2 = addressBook(102, 101, null);
AddressBook addressBook3 = addressBook(101, 201, 300L);
AddressBook addressBook4 = addressBook(101, 301, null);
runMigration();
assertEndTimestamp(addressBook1, 100L);
assertEndTimestamp(addressBook2, null);
assertEndTimestamp(addressBook3, 300L);
assertEndTimestamp(addressBook4, null);
}
Aggregations