use of com.hedera.mirror.common.domain.entity.EntityId in project hedera-mirror-node by hashgraph.
the class SqlEntityListenerTest method onTokenAccountMissingLastAssociation.
@Test
void onTokenAccountMissingLastAssociation() {
EntityId tokenId1 = EntityId.of("0.0.3", TOKEN);
EntityId accountId1 = EntityId.of("0.0.7", ACCOUNT);
// given token in db and missing last account token association
Token token = getToken(tokenId1, EntityId.of("0.0.500", ACCOUNT), 1L, 1L);
tokenRepository.save(token);
// when
TokenAccount freeze = getTokenAccount(tokenId1, accountId1, null, 10L, null, null, TokenFreezeStatusEnum.FROZEN, null);
sqlEntityListener.onTokenAccount(freeze);
TokenAccount kycGrant = getTokenAccount(tokenId1, accountId1, null, 15L, null, null, null, TokenKycStatusEnum.GRANTED);
sqlEntityListener.onTokenAccount(kycGrant);
completeFileAndCommit();
// then
assertThat(tokenAccountRepository.count()).isZero();
}
use of com.hedera.mirror.common.domain.entity.EntityId in project hedera-mirror-node by hashgraph.
the class SqlEntityListenerTest method onTokenAccountMerge.
@Test
void onTokenAccountMerge() {
EntityId tokenId1 = EntityId.of("0.0.3", TOKEN);
// save token entities first
Token token = getToken(tokenId1, EntityId.of("0.0.500", ACCOUNT), 1L, 1L);
sqlEntityListener.onToken(token);
// when
EntityId accountId1 = EntityId.of("0.0.7", ACCOUNT);
TokenAccount tokenAccountAssociate = getTokenAccount(tokenId1, accountId1, 5L, 5L, true, false, null, null);
sqlEntityListener.onTokenAccount(tokenAccountAssociate);
TokenAccount tokenAccountKyc = getTokenAccount(tokenId1, accountId1, null, 15L, null, null, null, TokenKycStatusEnum.GRANTED);
sqlEntityListener.onTokenAccount(tokenAccountKyc);
completeFileAndCommit();
// then
TokenAccount tokenAccountMerged = getTokenAccount(tokenId1, accountId1, 5L, 15L, true, false, TokenFreezeStatusEnum.UNFROZEN, TokenKycStatusEnum.GRANTED);
assertThat(tokenAccountRepository.findAll()).hasSize(2).contains(tokenAccountMerged);
}
use of com.hedera.mirror.common.domain.entity.EntityId in project hedera-mirror-node by hashgraph.
the class SqlEntityListenerTest method onNftTransferOwnershipAndDelete.
@Test
void onNftTransferOwnershipAndDelete() {
// create token first
EntityId tokenId1 = EntityId.of("0.0.1", TOKEN);
EntityId accountId1 = EntityId.of("0.0.2", ACCOUNT);
EntityId accountId2 = EntityId.of("0.0.3", ACCOUNT);
EntityId treasury = EntityId.of("0.0.98", ACCOUNT);
String metadata1 = "nft1";
String metadata2 = "nft2";
// save token entities first
Token token1 = getToken(tokenId1, treasury, 1L, 1L);
sqlEntityListener.onToken(token1);
// create nfts
// mint transfer combined
Nft nft1Combined = getNft(tokenId1, 1L, accountId1, 3L, false, metadata1, 3L);
// mint transfer combined
Nft nft2Combined = getNft(tokenId1, 2L, accountId2, 4L, false, metadata2, 4L);
sqlEntityListener.onNft(nft1Combined);
sqlEntityListener.onNft(nft2Combined);
completeFileAndCommit();
assertEquals(2, nftRepository.count());
// mint/burn
Nft nft1Burn = getNft(tokenId1, 1L, EntityId.EMPTY, null, true, null, 5L);
// mint/burn transfer
Nft nft1BurnTransfer = getNft(tokenId1, 1L, null, null, null, null, 5L);
sqlEntityListener.onNft(nft1Burn);
sqlEntityListener.onNft(nft1BurnTransfer);
// mint/burn
Nft nft2Burn = getNft(tokenId1, 2L, EntityId.EMPTY, null, true, null, 6L);
// mint/burn transfer
Nft nft2BurnTransfer = getNft(tokenId1, 2L, null, null, null, null, 6L);
sqlEntityListener.onNft(nft2Burn);
sqlEntityListener.onNft(nft2BurnTransfer);
completeFileAndCommit();
// expected nfts
// transfer
Nft nft1 = getNft(tokenId1, 1L, null, 3L, true, metadata1, 5L);
// transfer
Nft nft2 = getNft(tokenId1, 2L, null, 4L, true, metadata2, 6L);
assertThat(nftRepository.findAll()).containsExactlyInAnyOrder(nft1, nft2);
}
use of com.hedera.mirror.common.domain.entity.EntityId in project hedera-mirror-node by hashgraph.
the class SqlEntityListenerTest method onNonFeeTransfer.
@Test
void onNonFeeTransfer() {
// given
NonFeeTransfer nonFeeTransfer1 = domainBuilder.nonFeeTransfer().customize(n -> n.amount(1L).consensusTimestamp(1L).entityId(EntityId.of(1L, ACCOUNT)).payerAccountId(TRANSACTION_PAYER)).get();
NonFeeTransfer nonFeeTransfer2 = domainBuilder.nonFeeTransfer().customize(n -> n.amount(2L).consensusTimestamp(2L).entityId(EntityId.of(2L, ACCOUNT)).payerAccountId(TRANSACTION_PAYER)).get();
// when
sqlEntityListener.onNonFeeTransfer(nonFeeTransfer1);
sqlEntityListener.onNonFeeTransfer(nonFeeTransfer2);
completeFileAndCommit();
// then
assertThat(findNonFeeTransfers()).containsExactlyInAnyOrder(nonFeeTransfer1, nonFeeTransfer2);
}
use of com.hedera.mirror.common.domain.entity.EntityId in project hedera-mirror-node by hashgraph.
the class SqlEntityListenerTest method onTokenAccountSpanningRecordFiles.
@Test
void onTokenAccountSpanningRecordFiles() {
List<TokenAccount> expected = new ArrayList<>();
EntityId tokenId1 = EntityId.of("0.0.3", TOKEN);
EntityId accountId1 = EntityId.of("0.0.7", ACCOUNT);
// given token in db
Token token = getToken(tokenId1, EntityId.of("0.0.500", ACCOUNT), 1L, 1L);
tokenRepository.save(token);
// given association in a previous record file
TokenAccount associate = getTokenAccount(tokenId1, accountId1, 5L, 5L, true, false, null, null);
sqlEntityListener.onTokenAccount(associate);
expected.add(getTokenAccount(tokenId1, accountId1, 5L, 5L, true, false, TokenFreezeStatusEnum.UNFROZEN, TokenKycStatusEnum.REVOKED));
completeFileAndCommit();
// when in the next record file we have freeze, kycGrant, dissociate, associate, kycGrant
TokenAccount freeze = getTokenAccount(tokenId1, accountId1, null, 10L, null, null, TokenFreezeStatusEnum.FROZEN, null);
sqlEntityListener.onTokenAccount(freeze);
expected.add(getTokenAccount(tokenId1, accountId1, 5L, 10L, true, false, TokenFreezeStatusEnum.FROZEN, TokenKycStatusEnum.REVOKED));
TokenAccount kycGrant = getTokenAccount(tokenId1, accountId1, null, 12L, null, null, null, TokenKycStatusEnum.GRANTED);
sqlEntityListener.onTokenAccount(kycGrant);
expected.add(getTokenAccount(tokenId1, accountId1, 5L, 12L, true, false, TokenFreezeStatusEnum.FROZEN, TokenKycStatusEnum.GRANTED));
TokenAccount dissociate = getTokenAccount(tokenId1, accountId1, null, 15L, false, null, null, null);
sqlEntityListener.onTokenAccount(dissociate);
expected.add(getTokenAccount(tokenId1, accountId1, 5L, 15L, false, false, TokenFreezeStatusEnum.FROZEN, TokenKycStatusEnum.GRANTED));
associate = getTokenAccount(tokenId1, accountId1, 20L, 20L, true, true, null, null);
sqlEntityListener.onTokenAccount(associate);
expected.add(getTokenAccount(tokenId1, accountId1, 20L, 20L, true, true, TokenFreezeStatusEnum.UNFROZEN, TokenKycStatusEnum.REVOKED));
kycGrant = getTokenAccount(tokenId1, accountId1, null, 22L, null, null, null, TokenKycStatusEnum.GRANTED);
sqlEntityListener.onTokenAccount(kycGrant);
expected.add(getTokenAccount(tokenId1, accountId1, 20L, 22L, true, true, TokenFreezeStatusEnum.UNFROZEN, TokenKycStatusEnum.GRANTED));
completeFileAndCommit();
// then
assertThat(tokenAccountRepository.findAll()).containsExactlyInAnyOrderElementsOf(expected);
}
Aggregations