Search in sources :

Example 6 with AddressBookEntry

use of com.hedera.mirror.common.domain.addressbook.AddressBookEntry in project hedera-mirror-node by hashgraph.

the class AddressBookServiceImplTest 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());
            assertAddressBookEndPoints(abe.getServiceEndpoints(), nodeAddress.getServiceEndpointList());
        });
    }
}
Also used : AddressBookEntry(com.hedera.mirror.common.domain.addressbook.AddressBookEntry) NodeAddress(com.hederahashgraph.api.proto.java.NodeAddress)

Example 7 with AddressBookEntry

use of com.hedera.mirror.common.domain.addressbook.AddressBookEntry 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());
        });
    }
}
Also used : AddressBook(com.hedera.mirror.common.domain.addressbook.AddressBook) NodeAddressBook(com.hederahashgraph.api.proto.java.NodeAddressBook) NodeAddressBook(com.hederahashgraph.api.proto.java.NodeAddressBook) AddressBookEntry(com.hedera.mirror.common.domain.addressbook.AddressBookEntry) NodeAddress(com.hederahashgraph.api.proto.java.NodeAddress) ByteString(com.google.protobuf.ByteString) ServiceEndpoint(com.hederahashgraph.api.proto.java.ServiceEndpoint) AddressBookServiceEndpoint(com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest)

Example 8 with AddressBookEntry

use of com.hedera.mirror.common.domain.addressbook.AddressBookEntry 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();
}
Also used : AddressBook(com.hedera.mirror.common.domain.addressbook.AddressBook) AddressBookEntry(com.hedera.mirror.common.domain.addressbook.AddressBookEntry) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 9 with AddressBookEntry

use of com.hedera.mirror.common.domain.addressbook.AddressBookEntry 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());
        });
    }
}
Also used : AddressBookEntry(com.hedera.mirror.common.domain.addressbook.AddressBookEntry) NodeAddress(com.hederahashgraph.api.proto.java.NodeAddress)

Example 10 with AddressBookEntry

use of com.hedera.mirror.common.domain.addressbook.AddressBookEntry in project hedera-mirror-node by hashgraph.

the class AddAddressBookServiceEndpointsMigrationTest method verifyMigrateWhenBothDeprecatedIpAndAddressBookServiceEndpointsAreSet.

@Test
void verifyMigrateWhenBothDeprecatedIpAndAddressBookServiceEndpointsAreSet() throws IOException {
    long consensusTimestamp = 1;
    int nodeIdCount = 3;
    int endPointPerNode = 3;
    int numEndPoints = nodeIdCount * (endPointPerNode + 1);
    insertAddressBook(AddressBookServiceImpl.ADDRESS_BOOK_101_ENTITY_ID, consensusTimestamp, nodeIdCount);
    getAndSaveAddressBookEntries(true, consensusTimestamp, nodeIdCount, endPointPerNode);
    assertThat(addressBookEntryRepository.count()).isEqualTo(numEndPoints);
    runMigration();
    assertThat(addressBookEntryRepository.findAll()).isNotEmpty().hasSize(nodeIdCount).extracting(AddressBookEntry::getId).extracting(AddressBookEntry.Id::getNodeId).containsExactlyInAnyOrder(0L, 1L, 2L);
    assertThat(addressBookServiceEndpointRepository.findAll()).isNotEmpty().hasSize(numEndPoints).extracting(AddressBookServiceEndpoint::getId).extracting(AddressBookServiceEndpoint.Id::getPort).containsExactlyInAnyOrder(443, 444, 445, 446, 447, 448, 449, 450, 451, 452, 453, 454);
}
Also used : AddressBookServiceEndpoint(com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint) AddressBookEntry(com.hedera.mirror.common.domain.addressbook.AddressBookEntry) AddressBookServiceEndpoint(com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest)

Aggregations

AddressBookEntry (com.hedera.mirror.common.domain.addressbook.AddressBookEntry)26 Test (org.junit.jupiter.api.Test)18 AddressBook (com.hedera.mirror.common.domain.addressbook.AddressBook)12 AddressBookServiceEndpoint (com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint)11 GrpcIntegrationTest (com.hedera.mirror.grpc.GrpcIntegrationTest)10 EntityId (com.hedera.mirror.common.domain.entity.EntityId)6 AddressBookFilter (com.hedera.mirror.grpc.domain.AddressBookFilter)6 IntegrationTest (com.hedera.mirror.importer.IntegrationTest)6 NodeAddress (com.hederahashgraph.api.proto.java.NodeAddress)6 ByteString (com.google.protobuf.ByteString)4 AtomicLong (java.util.concurrent.atomic.AtomicLong)4 AddressBookQuery (com.hedera.mirror.api.proto.AddressBookQuery)3 Log4j2 (lombok.extern.log4j.Log4j2)3 ReactorNetworkServiceGrpc (com.hedera.mirror.api.proto.ReactorNetworkServiceGrpc)2 DomainBuilder (com.hedera.mirror.common.domain.DomainBuilder)2 EntityType (com.hedera.mirror.common.domain.entity.EntityType)2 ProtoUtil (com.hedera.mirror.grpc.util.ProtoUtil)2 FileID (com.hederahashgraph.api.proto.java.FileID)2 ServiceEndpoint (com.hederahashgraph.api.proto.java.ServiceEndpoint)2 Status (io.grpc.Status)2