Search in sources :

Example 16 with AddressBook

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

Example 17 with AddressBook

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());
        });
    }
}
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 18 with AddressBook

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();
}
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 19 with AddressBook

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);
}
Also used : AddressBook(com.hedera.mirror.common.domain.addressbook.AddressBook) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest)

Example 20 with AddressBook

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);
}
Also used : AddressBook(com.hedera.mirror.common.domain.addressbook.AddressBook) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest)

Aggregations

AddressBook (com.hedera.mirror.common.domain.addressbook.AddressBook)43 Test (org.junit.jupiter.api.Test)33 IntegrationTest (com.hedera.mirror.importer.IntegrationTest)17 NodeAddressBook (com.hederahashgraph.api.proto.java.NodeAddressBook)17 AddressBookEntry (com.hedera.mirror.common.domain.addressbook.AddressBookEntry)12 GrpcIntegrationTest (com.hedera.mirror.grpc.GrpcIntegrationTest)11 ServiceEndpoint (com.hederahashgraph.api.proto.java.ServiceEndpoint)10 AddressBookServiceEndpoint (com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint)9 EntityId (com.hedera.mirror.common.domain.entity.EntityId)6 AddressBookFilter (com.hedera.mirror.grpc.domain.AddressBookFilter)6 Resource (javax.annotation.Resource)5 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 ByteString (com.google.protobuf.ByteString)4 DomainBuilder (com.hedera.mirror.common.domain.DomainBuilder)4 NodeAddress (com.hederahashgraph.api.proto.java.NodeAddress)4 StepVerifier (reactor.test.StepVerifier)4 AddressBookQuery (com.hedera.mirror.api.proto.AddressBookQuery)3 EntityType (com.hedera.mirror.common.domain.entity.EntityType)3 SignatureVerificationException (com.hedera.mirror.importer.exception.SignatureVerificationException)3