use of com.hedera.services.store.models.UniqueToken in project hedera-services by hashgraph.
the class TypedTokenStoreTest method savesTokenAsExpected.
/* --- Token saving --- */
@Test
void savesTokenAsExpected() {
// setup:
final var mintedSerialNo = 33L;
final var wipedSerialNo = 33L;
final var mintedSerialNo2 = 44;
final var burnedSerialNo = 44;
final var nftMeta = "abcdefgh".getBytes();
final var treasuryId = new EntityId(0, 0, treasuryAccountNum);
final var tokenEntityId = new EntityId(0, 0, tokenNum);
final var creationTime = new RichInstant(1_234_567L, 8);
final var modelTreasuryId = new Id(0, 0, treasuryAccountNum);
final var mintedToken = new UniqueToken(tokenId, mintedSerialNo, creationTime, Id.DEFAULT, nftMeta);
final var wipedToken = new UniqueToken(tokenId, wipedSerialNo, creationTime, modelTreasuryId, nftMeta);
final var mintedToken2 = new UniqueToken(tokenId, mintedSerialNo2, creationTime, Id.DEFAULT, nftMeta);
final var burnedToken = new UniqueToken(tokenId, burnedSerialNo, creationTime, modelTreasuryId, nftMeta);
// and:
final var expectedReplacementToken = new MerkleToken(expiry, tokenSupply * 2, 0, symbol, name, freezeDefault, true, new EntityId(0, 0, autoRenewAccountNum));
expectedReplacementToken.setAutoRenewAccount(treasuryId);
expectedReplacementToken.setSupplyKey(supplyKey);
expectedReplacementToken.setFreezeKey(freezeKey);
expectedReplacementToken.setKycKey(kycKey);
expectedReplacementToken.setPauseKey(pauseKey);
expectedReplacementToken.setAccountsFrozenByDefault(!freezeDefault);
expectedReplacementToken.setMemo(memo);
expectedReplacementToken.setAutoRenewPeriod(autoRenewPeriod);
// and:
final var expectedReplacementToken2 = new MerkleToken(expiry, tokenSupply * 4, 0, symbol, name, freezeDefault, true, new EntityId(0, 0, treasuryAccountNum));
expectedReplacementToken2.setAutoRenewAccount(treasuryId);
expectedReplacementToken2.setSupplyKey(supplyKey);
expectedReplacementToken2.setFreezeKey(freezeKey);
expectedReplacementToken2.setKycKey(kycKey);
expectedReplacementToken2.setPauseKey(pauseKey);
expectedReplacementToken2.setAccountsFrozenByDefault(!freezeDefault);
expectedReplacementToken2.setMemo(memo);
expectedReplacementToken2.setAutoRenewPeriod(autoRenewPeriod);
// and:
final var expectedNewUniqTokenId = NftId.withDefaultShardRealm(tokenEntityId.num(), mintedSerialNo);
final var expectedNewUniqTokenId2 = NftId.withDefaultShardRealm(tokenEntityId.num(), mintedSerialNo2);
final var expectedNewUniqToken = new MerkleUniqueToken(MISSING_ENTITY_ID, nftMeta, creationTime);
final var expectedPastUniqTokenId = NftId.withDefaultShardRealm(tokenEntityId.num(), wipedSerialNo);
final var expectedPastUniqTokenId2 = NftId.withDefaultShardRealm(tokenEntityId.num(), burnedSerialNo);
givenModifiableToken(merkleTokenId, merkleToken);
givenToken(merkleTokenId, merkleToken);
// when:
var modelToken = subject.loadToken(tokenId);
// and:
modelToken.setTotalSupply(tokenSupply * 2);
modelToken.setAutoRenewAccount(treasuryAccount);
modelToken.setTreasury(autoRenewAccount);
modelToken.setFrozenByDefault(!freezeDefault);
modelToken.mintedUniqueTokens().add(mintedToken);
modelToken.setIsDeleted(false);
modelToken.setExpiry(expiry);
modelToken.setAutoRenewPeriod(autoRenewPeriod);
modelToken.removedUniqueTokens().add(wipedToken);
modelToken.setAutoRenewPeriod(autoRenewPeriod);
modelToken.setCustomFees(List.of());
modelToken.setMemo(memo);
// and:
subject.commitToken(modelToken);
// then:
assertEquals(expectedReplacementToken, merkleToken);
// and:
verify(sideEffectsTracker).trackTokenChanges(modelToken);
verify(uniqueTokens).put(expectedNewUniqTokenId, expectedNewUniqToken);
verify(uniqueTokens).put(NftId.withDefaultShardRealm(tokenEntityId.num(), mintedSerialNo), expectedNewUniqToken);
verify(uniqueTokens).remove(expectedPastUniqTokenId);
// when:
modelToken = subject.loadToken(tokenId);
// and:
modelToken.setTotalSupply(tokenSupply * 4);
modelToken.setAutoRenewAccount(treasuryAccount);
modelToken.setTreasury(treasuryAccount);
modelToken.setFrozenByDefault(!freezeDefault);
modelToken.mintedUniqueTokens().add(mintedToken2);
modelToken.setIsDeleted(false);
modelToken.setExpiry(expiry);
modelToken.removedUniqueTokens().add(burnedToken);
modelToken.setCustomFees(List.of());
// and:
subject.commitToken(modelToken);
// then:
assertEquals(expectedReplacementToken2, merkleToken);
// and:
verify(sideEffectsTracker).trackTokenChanges(modelToken);
verify(uniqueTokens).put(expectedNewUniqTokenId2, expectedNewUniqToken);
verify(uniqueTokens).remove(expectedPastUniqTokenId2);
}
use of com.hedera.services.store.models.UniqueToken in project hedera-services by hashgraph.
the class SideEffectsTrackerTest method tracksAndResetsNftMintsAsExpected.
@Test
void tracksAndResetsNftMintsAsExpected() {
final var changedToken = new Token(Id.fromGrpcToken(aToken));
changedToken.mintedUniqueTokens().add(new UniqueToken(Id.fromGrpcToken(cSN1.tokenId()), cSN1.serialNo()));
subject.trackTokenChanges(changedToken);
assertTrue(subject.hasTrackedNftMints());
assertEquals(List.of(cSN1.serialNo()), subject.getTrackedNftMints());
subject.reset();
assertFalse(subject.hasTrackedNftMints());
assertTrue(subject.getTrackedNftMints().isEmpty());
}
use of com.hedera.services.store.models.UniqueToken in project hedera-services by hashgraph.
the class SideEffectsTrackerTest method canClearJustTokenChanges.
@Test
void canClearJustTokenChanges() {
final var newSupply = 1_234L;
final var changedToken = new Token(Id.fromGrpcToken(aToken));
changedToken.setNew(true);
changedToken.setTotalSupply(newSupply);
changedToken.mintedUniqueTokens().add(new UniqueToken(Id.fromGrpcToken(cSN1.tokenId()), cSN1.serialNo()));
subject.trackHbarChange(aAccount, aFirstBalanceChange);
subject.trackTokenUnitsChange(bToken, cAccount, cOnlyBalanceChange);
subject.trackNftOwnerChange(cSN1, aAccount, bAccount);
subject.trackAutoAssociation(aToken, bAccount);
subject.trackTokenChanges(changedToken);
subject.resetTrackedTokenChanges();
assertFalse(subject.hasTrackedNewTokenId());
assertFalse(subject.hasTrackedTokenSupply());
assertFalse(subject.hasTrackedNftMints());
assertTrue(subject.getTrackedAutoAssociations().isEmpty());
assertSame(Collections.emptyList(), subject.getNetTrackedTokenUnitAndOwnershipChanges());
final var netChanges = subject.getNetTrackedHbarChanges();
assertEquals(1, netChanges.getAccountAmountsCount());
final var aChange = netChanges.getAccountAmounts(0);
assertEquals(aAccount, aChange.getAccountID());
assertEquals(aFirstBalanceChange, aChange.getAmount());
}
Aggregations