use of com.hederahashgraph.api.proto.java.NodeAddress in project hedera-mirror-node by hashgraph.
the class AddressBookServiceImplTest method verifyEmptyDeprecatedMemo.
@Test
void verifyEmptyDeprecatedMemo() throws UnknownHostException {
List<NodeAddress> nodeAddressList = new ArrayList<>();
int nodeAccountStart = 3;
int addressBookEntries = 5;
// service endpoint
int numEndpointsPerNode = 1;
for (int i = nodeAccountStart; i < addressBookEntries + nodeAccountStart; i++) {
// empty deprecated ip
nodeAddressList.add(getNodeAddress(i, "", null, List.of(String.format("127.0.%d.0", i))));
}
NodeAddressBook.Builder nodeAddressBookBuilder = NodeAddressBook.newBuilder().addAllNodeAddress(nodeAddressList);
byte[] addressBookBytes = nodeAddressBookBuilder.build().toByteArray();
update(addressBookBytes, 2L, true);
assertArrayEquals(addressBookBytes, addressBookService.getCurrent().getFileData());
// bootstrap and new address book with service endpoints
assertEquals(2, addressBookRepository.count());
assertEquals(TEST_INITIAL_ADDRESS_BOOK_NODE_COUNT + addressBookEntries, addressBookEntryRepository.count());
assertEquals(addressBookEntries * numEndpointsPerNode, addressBookServiceEndpointRepository.count());
}
use of com.hederahashgraph.api.proto.java.NodeAddress in project hedera-mirror-node by hashgraph.
the class AddressBookServiceImplTest method verifyDuplicateEndpointsPerNodeAddressAreCollapsed.
@Test
void verifyDuplicateEndpointsPerNodeAddressAreCollapsed() throws UnknownHostException {
List<NodeAddress> nodeAddressList = new ArrayList<>();
int nodeAccountStart = 3;
int addressBookEntries = 5;
// 127.0.<nodeId>.0, 127.0.<nodeId>.1, 127.0.<nodeId>.2
int numEndpointsPerNode = 3;
for (int i = nodeAccountStart; i < addressBookEntries + nodeAccountStart; i++) {
// deprecated ip
nodeAddressList.add(getNodeAddress(i, baseAccountId + i, String.format("127.0.%d.0", i), List.of()));
// subset of only service endpoints
nodeAddressList.add(getNodeAddress(i, baseAccountId + i, null, List.of(String.format("127.0.%d.0", i))));
// another deprecated ip and more service endpoints
nodeAddressList.add(getNodeAddress(i, baseAccountId + i, String.format("127.0.%d.0", i), List.of(String.format("127.0.%d.1", i), String.format("127.0.%d.2", i))));
}
NodeAddressBook.Builder nodeAddressBookBuilder = NodeAddressBook.newBuilder().addAllNodeAddress(nodeAddressList);
byte[] addressBookBytes = nodeAddressBookBuilder.build().toByteArray();
update(addressBookBytes, 2L, true);
assertArrayEquals(addressBookBytes, addressBookService.getCurrent().getFileData());
// bootstrap and new address book with service endpoints
assertEquals(2, addressBookRepository.count());
assertEquals(TEST_INITIAL_ADDRESS_BOOK_NODE_COUNT + addressBookEntries, addressBookEntryRepository.count());
assertEquals(addressBookEntries * numEndpointsPerNode, addressBookServiceEndpointRepository.count());
}
use of com.hederahashgraph.api.proto.java.NodeAddress 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.hederahashgraph.api.proto.java.NodeAddress in project hedera-mirror-node by hashgraph.
the class AddressBookServiceImplTest method verifyAddressBookWithServiceEndpointsOnly.
@Test
void verifyAddressBookWithServiceEndpointsOnly() throws UnknownHostException {
List<NodeAddress> nodeAddressList = new ArrayList<>();
int nodeAccountStart = 3;
int addressBookEntries = 5;
int numEndpointsPerNode = 4;
for (int i = nodeAccountStart; i < addressBookEntries + nodeAccountStart; i++) {
nodeAddressList.add(getNodeAddress(i, baseAccountId + i, null, List.of(String.format("127.0.%d.1", i), String.format("127.0.%d.2", i), String.format("127.0.%d.3", i), String.format("127.0.%d.4", i))));
}
NodeAddressBook.Builder nodeAddressBookBuilder = NodeAddressBook.newBuilder().addAllNodeAddress(nodeAddressList);
byte[] addressBookBytes = nodeAddressBookBuilder.build().toByteArray();
update(addressBookBytes, 2L, false);
assertArrayEquals(initialAddressBookBytes, addressBookService.getCurrent().getFileData());
// bootstrap and new address book with service endpoints
assertEquals(2, addressBookRepository.count());
assertEquals(TEST_INITIAL_ADDRESS_BOOK_NODE_COUNT + addressBookEntries, addressBookEntryRepository.count());
assertEquals(addressBookEntries * numEndpointsPerNode, addressBookServiceEndpointRepository.count());
}
use of com.hederahashgraph.api.proto.java.NodeAddress in project hedera-mirror-node by hashgraph.
the class MissingAddressBooksMigrationTest method assertAddressBook.
private void assertAddressBook(AddressBook actual, NodeAddressBook expected) {
ListAssert<AddressBookEntry> listAssert = assertThat(actual.getEntries()).hasSize(expected.getNodeAddressCount());
for (NodeAddress nodeAddress : expected.getNodeAddressList()) {
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());
assertThat(abe.getNodeId()).isEqualTo(nodeAddress.getNodeId());
});
}
}
Aggregations