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());
}
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());
}
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());
}
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());
}
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);
}
Aggregations