use of com.hedera.mirror.common.domain.token.Token in project hedera-mirror-node by hashgraph.
the class SqlEntityListenerTest method onNftTransferOwnershipAndDeleteOutOfOrder.
@Test
void onNftTransferOwnershipAndDeleteOutOfOrder() {
// 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);
completeFileAndCommit();
// 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);
// nft 1 burn w transfer coming first
// 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(nft1BurnTransfer);
sqlEntityListener.onNft(nft1Burn);
// nft 2 burn w transfer coming first
// 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(nft2BurnTransfer);
sqlEntityListener.onNft(nft2Burn);
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.token.Token in project hedera-mirror-node by hashgraph.
the class SqlEntityListenerTest method onTokenAccountDissociate.
@Test
void onTokenAccountDissociate() {
EntityId tokenId1 = EntityId.of("0.0.3", TOKEN);
// save token entities first
Token token1 = getToken(tokenId1, EntityId.of("0.0.500", ACCOUNT), 1L, 1L);
sqlEntityListener.onToken(token1);
completeFileAndCommit();
EntityId accountId1 = EntityId.of("0.0.7", ACCOUNT);
TokenAccount associate = getTokenAccount(tokenId1, accountId1, 5L, 5L, true, false, TokenFreezeStatusEnum.NOT_APPLICABLE, TokenKycStatusEnum.NOT_APPLICABLE);
TokenAccount dissociate = getTokenAccount(tokenId1, accountId1, null, 10L, false, null, null, null);
// when
sqlEntityListener.onTokenAccount(associate);
sqlEntityListener.onTokenAccount(dissociate);
sqlEntityListener.onTokenAccount(dissociate);
completeFileAndCommit();
// then
assertThat(tokenAccountRepository.findAll()).containsExactlyInAnyOrder(associate, getTokenAccount(tokenId1, accountId1, 5L, 10L, false, false, TokenFreezeStatusEnum.NOT_APPLICABLE, TokenKycStatusEnum.NOT_APPLICABLE));
}
use of com.hedera.mirror.common.domain.token.Token in project hedera-mirror-node by hashgraph.
the class SqlEntityListenerTest method getTokenUpdate.
private Token getTokenUpdate(EntityId tokenId, long modifiedTimestamp) {
Token token = Token.of(tokenId);
token.setModifiedTimestamp(modifiedTimestamp);
return token;
}
use of com.hedera.mirror.common.domain.token.Token in project hedera-mirror-node by hashgraph.
the class SqlEntityListenerTest method onNft.
@Test
void onNft() {
// create token first
EntityId tokenId1 = EntityId.of("0.0.1", TOKEN);
EntityId tokenId2 = EntityId.of("0.0.3", TOKEN);
EntityId accountId1 = EntityId.of("0.0.2", ACCOUNT);
EntityId accountId2 = EntityId.of("0.0.4", ACCOUNT);
EntityId treasuryId = EntityId.of("0.0.98", ACCOUNT);
String metadata1 = "nft1";
String metadata2 = "nft2";
Token token1 = getToken(tokenId1, treasuryId, 1L, 1L);
Token token2 = getToken(tokenId2, treasuryId, 2L, 2L);
sqlEntityListener.onToken(token1);
sqlEntityListener.onToken(token2);
completeFileAndCommit();
// create nft 1
// mint
sqlEntityListener.onNft(getNft(tokenId1, 1L, null, 3L, false, metadata1, 3L));
// transfer
sqlEntityListener.onNft(getNft(tokenId1, 1L, accountId1, null, null, null, 3L));
// create nft 2
// mint
sqlEntityListener.onNft(getNft(tokenId2, 1L, null, 4L, false, metadata2, 4L));
// transfer
sqlEntityListener.onNft(getNft(tokenId2, 1L, accountId2, null, null, null, 4L));
completeFileAndCommit();
// transfer
Nft nft1 = getNft(tokenId1, 1L, accountId1, 3L, false, metadata1, 3L);
// transfer
Nft nft2 = getNft(tokenId2, 1L, accountId2, 4L, false, metadata2, 4L);
assertThat(nftRepository.findAll()).containsExactlyInAnyOrder(nft1, nft2);
}
use of com.hedera.mirror.common.domain.token.Token in project hedera-mirror-node by hashgraph.
the class SqlEntityListenerTest method getToken.
private Token getToken(EntityId tokenId, EntityId accountId, Long createdTimestamp, long modifiedTimestamp, Integer decimals, Boolean freezeDefault, Key freezeKey, Long initialSupply, Key kycKey, String name, Key supplyKey, String symbol, Key wipeKey, Key pauseKey, TokenPauseStatusEnum pauseStatus) {
Token token = new Token();
token.setCreatedTimestamp(createdTimestamp);
token.setDecimals(decimals);
token.setFreezeDefault(freezeDefault);
token.setFreezeKey(freezeKey != null ? freezeKey.toByteArray() : null);
token.setInitialSupply(initialSupply);
token.setKycKey(kycKey != null ? kycKey.toByteArray() : null);
token.setMaxSupply(0L);
token.setModifiedTimestamp(modifiedTimestamp);
token.setName(name);
token.setPauseKey(pauseKey != null ? pauseKey.toByteArray() : null);
token.setPauseStatus(pauseStatus);
token.setSupplyKey(supplyKey != null ? supplyKey.toByteArray() : null);
token.setSupplyType(TokenSupplyTypeEnum.INFINITE);
token.setSymbol(symbol);
token.setTokenId(new TokenId(tokenId));
token.setType(TokenTypeEnum.FUNGIBLE_COMMON);
token.setTreasuryAccountId(accountId);
token.setWipeKey(wipeKey != null ? wipeKey.toByteArray() : null);
return token;
}
Aggregations