Search in sources :

Example 26 with AddressBook

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

the class AddressBookServiceImplTest method appendCompleteFileAcrossFileIds.

@Test
void appendCompleteFileAcrossFileIds() {
    // file 102 update contents to be split over 1 update and 1 append operation
    byte[] addressBookBytes = UPDATED.toByteArray();
    int index = addressBookBytes.length / 2;
    byte[] addressBookBytes1 = Arrays.copyOfRange(addressBookBytes, 0, index);
    byte[] addressBookBytes2 = Arrays.copyOfRange(addressBookBytes, index, addressBookBytes.length);
    // file 101 update contents to be split over 1 update and 1 append operation
    byte[] addressBook101Bytes = FINAL.toByteArray();
    int index101 = addressBook101Bytes.length / 2;
    byte[] addressBook101Bytes1 = Arrays.copyOfRange(addressBook101Bytes, 0, index101);
    byte[] addressBook101Bytes2 = Arrays.copyOfRange(addressBook101Bytes, index101, addressBook101Bytes.length);
    // init address book and verify initial state
    assertEquals(0, addressBookEntryRepository.count());
    assertEquals(0, addressBookRepository.count());
    // perform file 102 first update and confirm no change to current address book and nodes addresses
    // fileID 102
    update(addressBookBytes1, 2L, true);
    assertEquals(TEST_INITIAL_ADDRESS_BOOK_NODE_COUNT, addressBookEntryRepository.count());
    // initial
    assertEquals(1, addressBookRepository.count());
    addressBookService.getCurrent();
    update(addressBook101Bytes1, 3L, false);
    long addressBook101ConsensusTimeStamp = 5L;
    append(addressBook101Bytes2, addressBook101ConsensusTimeStamp, false);
    // verify partial bytes match 101 complete address book update
    assertAddressBookData(FINAL.toByteArray(), addressBook101ConsensusTimeStamp + 1);
    assertEquals(TEST_INITIAL_ADDRESS_BOOK_NODE_COUNT + FINAL.getNodeAddressCount(), addressBookEntryRepository.count());
    assertEquals(2, addressBookRepository.count());
    // verify current address book bytes still match original load and not 101 update and append
    assertArrayEquals(initialAddressBookBytes, addressBookService.getCurrent().getFileData());
    // perform file 102 append
    long addressBook102ConsensusTimeStamp = 7L;
    append(addressBookBytes2, addressBook102ConsensusTimeStamp, true);
    // verify address book and node addresses are updated
    AddressBook addressBook = addressBookService.getCurrent();
    assertThat(addressBook.getStartConsensusTimestamp()).isEqualTo(addressBook102ConsensusTimeStamp + 1);
    assertAddressBook(addressBookService.getCurrent(), UPDATED);
    // 15 (101 update) + 12 (102 update)
    assertEquals(TEST_INITIAL_ADDRESS_BOOK_NODE_COUNT + UPDATED.getNodeAddressCount() + FINAL.getNodeAddressCount(), addressBookEntryRepository.count());
    assertAddressBookData(UPDATED.toByteArray(), addressBook102ConsensusTimeStamp + 1);
    assertEquals(3, addressBookRepository.count());
}
Also used : AddressBook(com.hedera.mirror.common.domain.addressbook.AddressBook) NodeAddressBook(com.hederahashgraph.api.proto.java.NodeAddressBook) 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 27 with AddressBook

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

the class AddressBookServiceImplTest method verifyUpdateCallPopulatesInitialAddressBook.

@Test
void verifyUpdateCallPopulatesInitialAddressBook() {
    byte[] addressBookBytes = UPDATED.toByteArray();
    int index = addressBookBytes.length / 2;
    byte[] addressBookPartial = Arrays.copyOfRange(addressBookBytes, 0, index);
    assertEquals(0, addressBookRepository.count());
    update(addressBookPartial, 2L, false);
    assertThat(addressBookService.getCurrent()).returns(initialAddressBookBytes, AddressBook::getFileData).returns(AddressBookServiceImpl.ADDRESS_BOOK_102_ENTITY_ID, AddressBook::getFileId).returns(1L, AddressBook::getStartConsensusTimestamp).returns(null, AddressBook::getEndConsensusTimestamp);
    assertEquals(1, addressBookRepository.count());
    assertEquals(TEST_INITIAL_ADDRESS_BOOK_NODE_COUNT, addressBookEntryRepository.count());
}
Also used : AddressBook(com.hedera.mirror.common.domain.addressbook.AddressBook) NodeAddressBook(com.hederahashgraph.api.proto.java.NodeAddressBook) 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 28 with AddressBook

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

the class AddressBookServiceImplTest method startupWithDefaultNetwork.

@Test
void startupWithDefaultNetwork() {
    // init address book and verify initial state
    assertEquals(0, addressBookEntryRepository.count());
    assertEquals(0, addressBookRepository.count());
    AddressBook addressBook = addressBookService.getCurrent();
    assertThat(addressBook.getStartConsensusTimestamp()).isEqualTo(1L);
    assertEquals(1, addressBookRepository.count());
    assertEquals(TEST_INITIAL_ADDRESS_BOOK_NODE_COUNT, addressBookEntryRepository.count());
}
Also used : AddressBook(com.hedera.mirror.common.domain.addressbook.AddressBook) NodeAddressBook(com.hederahashgraph.api.proto.java.NodeAddressBook) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest)

Example 29 with AddressBook

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

the class AddressBookServiceImplTest method verifyUpdateWithNewFileDataAfterCurrentAddressBook.

@Test
void verifyUpdateWithNewFileDataAfterCurrentAddressBook() {
    byte[] addressBookBytes1 = UPDATED.toByteArray();
    store(addressBookBytes1, 2L, false);
    byte[] addressBookBytes2 = UPDATED.toByteArray();
    store(addressBookBytes2, 3L, true);
    // initial migration
    AddressBook addressBook = addressBookService.getCurrent();
    assertThat(addressBook.getStartConsensusTimestamp()).isEqualTo(4L);
    assertAddressBook(addressBook, UPDATED);
    // valid file data added but no address book produced
    // file 101 update contents to be split over 1 update and 1 append operation
    byte[] addressBook101Bytes = FINAL.toByteArray();
    int index101 = addressBook101Bytes.length / 2;
    byte[] addressBook101Bytes1 = Arrays.copyOfRange(addressBook101Bytes, 0, index101);
    byte[] addressBook101Bytes2 = Arrays.copyOfRange(addressBook101Bytes, index101, addressBook101Bytes.length);
    fileDataRepository.save(createFileData(addressBook101Bytes1, 4L, false, TransactionType.FILEUPDATE));
    fileDataRepository.save(createFileData(addressBook101Bytes2, 5L, false, TransactionType.FILEAPPEND));
    // file 102 update contents to be split over 1 update and 1 append operation
    byte[] addressBook102Bytes = FINAL.toByteArray();
    int index = addressBook102Bytes.length / 2;
    byte[] addressBook102Bytes1 = Arrays.copyOfRange(addressBook102Bytes, 0, index);
    byte[] addressBook102Bytes2 = Arrays.copyOfRange(addressBook102Bytes, index, addressBook102Bytes.length);
    fileDataRepository.save(createFileData(addressBook102Bytes1, 6L, true, TransactionType.FILEUPDATE));
    fileDataRepository.save(createFileData(addressBook102Bytes2, 7L, true, TransactionType.FILEAPPEND));
    // migration on update, missing address books are created
    addressBookService.update(createFileData(addressBook101Bytes1, 10L, false, TransactionType.FILEUPDATE));
    // latest missing address book is current
    AddressBook newAddressBook = addressBookService.getCurrent();
    assertThat(newAddressBook.getStartConsensusTimestamp()).isEqualTo(8L);
    assertAddressBook(newAddressBook, FINAL);
    assertEquals(6, fileDataRepository.count());
    // initial plus 4 files
    assertEquals(5, addressBookRepository.count());
    assertEquals(TEST_INITIAL_ADDRESS_BOOK_NODE_COUNT + (UPDATED.getNodeAddressCount() * 2) + (FINAL.getNodeAddressCount() * 2), addressBookEntryRepository.count());
}
Also used : AddressBook(com.hedera.mirror.common.domain.addressbook.AddressBook) NodeAddressBook(com.hederahashgraph.api.proto.java.NodeAddressBook) 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 30 with AddressBook

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

the class NetworkServiceTest method moreThanPageSize.

@Test
void moreThanPageSize() {
    addressBookProperties.setPageSize(2);
    AddressBook addressBook = addressBook();
    AddressBookEntry addressBookEntry1 = addressBookEntry();
    AddressBookEntry addressBookEntry2 = addressBookEntry();
    AddressBookEntry addressBookEntry3 = addressBookEntry();
    AddressBookFilter filter = AddressBookFilter.builder().fileId(addressBook.getFileId()).build();
    assertThat(getNodes(filter)).containsExactly(addressBookEntry1, addressBookEntry2, addressBookEntry3);
}
Also used : AddressBookFilter(com.hedera.mirror.grpc.domain.AddressBookFilter) AddressBook(com.hedera.mirror.common.domain.addressbook.AddressBook) AddressBookEntry(com.hedera.mirror.common.domain.addressbook.AddressBookEntry) GrpcIntegrationTest(com.hedera.mirror.grpc.GrpcIntegrationTest) Test(org.junit.jupiter.api.Test)

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