Search in sources :

Example 66 with EntityId

use of com.hedera.mirror.common.domain.entity.EntityId in project hedera-mirror-node by hashgraph.

the class EntityIdServiceImplTest method lookupAccountsReturnsFirst.

@Test
void lookupAccountsReturnsFirst() {
    AccountID accountId1 = AccountID.newBuilder().setAccountNum(100).build();
    AccountID accountId2 = AccountID.newBuilder().setAccountNum(101).build();
    EntityId entityId = entityIdService.lookup(accountId1, accountId2);
    assertThat(entityId).isEqualTo(EntityId.of(accountId1));
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) AccountID(com.hederahashgraph.api.proto.java.AccountID) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 67 with EntityId

use of com.hedera.mirror.common.domain.entity.EntityId in project hedera-mirror-node by hashgraph.

the class EntityIdServiceImplTest method lookupAccounts.

@Test
void lookupAccounts() {
    AccountID nullAccountId = null;
    AccountID accountId = AccountID.newBuilder().setAccountNum(100).build();
    AccountID accountIdInvalid = AccountID.newBuilder().setRealmNum(1).build();
    Entity accountDeleted = domainBuilder.entity().customize(e -> e.deleted(true)).persist();
    EntityId entityId = entityIdService.lookup(nullAccountId, AccountID.getDefaultInstance(), getProtoAccountId(accountDeleted), accountIdInvalid, accountId);
    assertThat(entityId).isEqualTo(EntityId.of(accountId));
}
Also used : CsvSource(org.junit.jupiter.params.provider.CsvSource) DomainUtils(com.hedera.mirror.common.util.DomainUtils) Contract(com.hedera.mirror.common.domain.contract.Contract) EntityId(com.hedera.mirror.common.domain.entity.EntityId) ContractRepository(com.hedera.mirror.importer.repository.ContractRepository) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Resource(javax.annotation.Resource) Entity(com.hedera.mirror.common.domain.entity.Entity) CONTRACT(com.hedera.mirror.common.domain.entity.EntityType.CONTRACT) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest) ContractID(com.hederahashgraph.api.proto.java.ContractID) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) DomainBuilder(com.hedera.mirror.common.domain.DomainBuilder) Assertions(org.junit.jupiter.api.Assertions) AliasNotFoundException(com.hedera.mirror.importer.exception.AliasNotFoundException) ACCOUNT(com.hedera.mirror.common.domain.entity.EntityType.ACCOUNT) AccountID(com.hederahashgraph.api.proto.java.AccountID) InvalidDatasetException(com.hedera.mirror.importer.exception.InvalidDatasetException) EntityId(com.hedera.mirror.common.domain.entity.EntityId) Entity(com.hedera.mirror.common.domain.entity.Entity) AccountID(com.hederahashgraph.api.proto.java.AccountID) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 68 with EntityId

use of com.hedera.mirror.common.domain.entity.EntityId in project hedera-mirror-node by hashgraph.

the class NodeSignatureVerifierTest method testVerifiedWithFullConsensusRequired.

@Test
void testVerifiedWithFullConsensusRequired() throws GeneralSecurityException {
    Map<String, PublicKey> nodeAccountIDPubKeyMap = new HashMap();
    nodeAccountIDPubKeyMap.put("0.0.3", publicKey);
    nodeAccountIDPubKeyMap.put("0.0.4", publicKey);
    nodeAccountIDPubKeyMap.put("0.0.5", publicKey);
    when(currentAddressBook.getNodeAccountIDPubKeyMap()).thenReturn(nodeAccountIDPubKeyMap);
    when(commonDownloaderProperties.getConsensusRatio()).thenReturn(1f);
    byte[] fileHash = TestUtils.generateRandomByteArray(48);
    byte[] fileHashSignature = signHash(fileHash);
    FileStreamSignature fileStreamSignatureNode3 = buildFileStreamSignature(fileHash, fileHashSignature, null, null);
    fileStreamSignatureNode3.setNodeAccountId(new EntityId(0L, 0L, 3L, EntityType.ACCOUNT));
    FileStreamSignature fileStreamSignatureNode4 = buildFileStreamSignature(fileHash, fileHashSignature, null, null);
    fileStreamSignatureNode4.setNodeAccountId(new EntityId(0L, 0L, 4L, EntityType.ACCOUNT));
    FileStreamSignature fileStreamSignatureNode5 = buildFileStreamSignature(fileHash, fileHashSignature, null, null);
    fileStreamSignatureNode5.setNodeAccountId(new EntityId(0L, 0L, 5L, EntityType.ACCOUNT));
    nodeSignatureVerifier.verify(Arrays.asList(fileStreamSignatureNode3, fileStreamSignatureNode4, fileStreamSignatureNode5));
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) HashMap(java.util.HashMap) PublicKey(java.security.PublicKey) FileStreamSignature(com.hedera.mirror.importer.domain.FileStreamSignature) Test(org.junit.jupiter.api.Test)

Example 69 with EntityId

use of com.hedera.mirror.common.domain.entity.EntityId in project hedera-mirror-node by hashgraph.

the class NodeSignatureVerifierTest method testVerifiedWithOneThirdConsensusWithMissingSignatures.

@Test
void testVerifiedWithOneThirdConsensusWithMissingSignatures() throws GeneralSecurityException {
    Map<String, PublicKey> nodeAccountIDPubKeyMap = new HashMap();
    nodeAccountIDPubKeyMap.put("0.0.3", publicKey);
    nodeAccountIDPubKeyMap.put("0.0.4", publicKey);
    nodeAccountIDPubKeyMap.put("0.0.5", publicKey);
    when(currentAddressBook.getNodeAccountIDPubKeyMap()).thenReturn(nodeAccountIDPubKeyMap);
    byte[] fileHash = TestUtils.generateRandomByteArray(48);
    byte[] fileHashSignature = signHash(fileHash);
    FileStreamSignature fileStreamSignatureNode3 = buildFileStreamSignature(fileHash, fileHashSignature, null, null);
    // Node 4 and 5 will not verify due to missing signature, but 1/3 verified will confirm consensus reached
    FileStreamSignature fileStreamSignatureNode4 = buildFileStreamSignature(fileHash, null, null, null);
    fileStreamSignatureNode4.setNodeAccountId(new EntityId(0L, 0L, 4L, EntityType.ACCOUNT));
    FileStreamSignature fileStreamSignatureNode5 = buildFileStreamSignature(fileHash, null, null, null);
    fileStreamSignatureNode5.setNodeAccountId(new EntityId(0L, 0L, 5L, EntityType.ACCOUNT));
    nodeSignatureVerifier.verify(Arrays.asList(fileStreamSignatureNode3, fileStreamSignatureNode4, fileStreamSignatureNode5));
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) HashMap(java.util.HashMap) PublicKey(java.security.PublicKey) FileStreamSignature(com.hedera.mirror.importer.domain.FileStreamSignature) Test(org.junit.jupiter.api.Test)

Example 70 with EntityId

use of com.hedera.mirror.common.domain.entity.EntityId in project hedera-mirror-node by hashgraph.

the class AddressBookServiceImplTest method isAddressBook.

@Test
void isAddressBook() {
    EntityId fileID = EntityId.of(0, 0, 234, EntityType.FILE);
    boolean isAddressBook = addressBookService.isAddressBook(fileID);
    assertThat(isAddressBook).isFalse();
    fileID = EntityId.of(0, 0, 101, EntityType.FILE);
    isAddressBook = addressBookService.isAddressBook(fileID);
    assertThat(isAddressBook).isTrue();
    fileID = EntityId.of(0, 0, 102, EntityType.FILE);
    isAddressBook = addressBookService.isAddressBook(fileID);
    assertThat(isAddressBook).isTrue();
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest)

Aggregations

EntityId (com.hedera.mirror.common.domain.entity.EntityId)134 Test (org.junit.jupiter.api.Test)64 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)43 IntegrationTest (com.hedera.mirror.importer.IntegrationTest)33 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)22 EntityType (com.hedera.mirror.common.domain.entity.EntityType)21 TokenAccount (com.hedera.mirror.common.domain.token.TokenAccount)21 Token (com.hedera.mirror.common.domain.token.Token)20 Entity (com.hedera.mirror.common.domain.entity.Entity)17 Transaction (com.hedera.mirror.common.domain.transaction.Transaction)17 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)16 Assertions (org.junit.jupiter.api.Assertions)16 Contract (com.hedera.mirror.common.domain.contract.Contract)15 ACCOUNT (com.hedera.mirror.common.domain.entity.EntityType.ACCOUNT)15 DomainUtils (com.hedera.mirror.common.util.DomainUtils)15 ByteString (com.google.protobuf.ByteString)14 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)14 AccountID (com.hederahashgraph.api.proto.java.AccountID)14 ContractID (com.hederahashgraph.api.proto.java.ContractID)14 Consumer (java.util.function.Consumer)13