use of com.hedera.services.state.submerkle.EntityId in project hedera-services by hashgraph.
the class LedgerBalanceChangesTest method nonFungibleTokenWithTreasury.
private MerkleToken nonFungibleTokenWithTreasury(AccountID treasury) {
final var token = new MerkleToken();
token.setTreasury(new EntityId(treasury.getShardNum(), treasury.getRealmNum(), treasury.getAccountNum()));
token.setTokenType(TokenType.NON_FUNGIBLE_UNIQUE);
return token;
}
use of com.hedera.services.state.submerkle.EntityId in project hedera-services by hashgraph.
the class LedgerBalanceChangesTest method fungibleTokenWithTreasury.
private MerkleToken fungibleTokenWithTreasury(AccountID treasury) {
final var token = new MerkleToken();
token.setTreasury(new EntityId(treasury.getShardNum(), treasury.getRealmNum(), treasury.getAccountNum()));
token.setTokenType(TokenType.FUNGIBLE_COMMON);
return token;
}
use of com.hedera.services.state.submerkle.EntityId 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.state.submerkle.EntityId in project hedera-services by hashgraph.
the class TypedTokenStoreTest method loadsUniqueTokens.
@Test
void loadsUniqueTokens() {
final var aToken = new Token(miscId);
final var merkleUniqueToken = mock(MerkleUniqueToken.class);
final var serialNumbers = List.of(1L, 2L);
given(merkleUniqueToken.getOwner()).willReturn(new EntityId(Id.DEFAULT));
given(uniqueTokens.getImmutableRef(any())).willReturn(merkleUniqueToken);
subject.loadUniqueTokens(aToken, serialNumbers);
assertEquals(2, aToken.getLoadedUniqueTokens().size());
given(uniqueTokens.getImmutableRef(any())).willReturn(null);
assertThrows(InvalidTransactionException.class, () -> subject.loadUniqueTokens(aToken, serialNumbers));
}
use of com.hedera.services.state.submerkle.EntityId in project hedera-services by hashgraph.
the class HederaWorldStateTest method updaterGetsHederaAccount.
@Test
void updaterGetsHederaAccount() {
givenNonNullWorldLedgers();
final var zeroAddress = EntityIdUtils.accountIdFromEvmAddress(Address.ZERO.toArray());
final var updater = subject.updater();
// and:
given(entityAccess.isExtant(zeroAddress)).willReturn(true);
given(entityAccess.getBalance(zeroAddress)).willReturn(balance);
given(entityAccess.getProxy(zeroAddress)).willReturn(EntityId.MISSING_ENTITY_ID);
given(entityAccess.getAutoRenew(zeroAddress)).willReturn(123L);
// and:
final var expected = subject.new WorldStateAccount(Address.ZERO, Wei.of(balance), 0, 0, new EntityId());
// when:
final var result = updater.getHederaAccount(Address.ZERO);
// then:
assertEquals(expected.getAddress(), result.getAddress());
assertEquals(expected.getBalance(), result.getBalance());
assertEquals(expected.getProxyAccount(), result.getProxyAccount());
assertEquals(expected.getExpiry(), result.getExpiry());
// and:
verify(entityAccess).isExtant(zeroAddress);
verify(entityAccess).getBalance(zeroAddress);
verify(entityAccess).getProxy(zeroAddress);
verify(entityAccess).getAutoRenew(zeroAddress);
}
Aggregations