Search in sources :

Example 1 with EntityId

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;
}
Also used : EntityId(com.hedera.services.state.submerkle.EntityId) MerkleToken(com.hedera.services.state.merkle.MerkleToken)

Example 2 with EntityId

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;
}
Also used : EntityId(com.hedera.services.state.submerkle.EntityId) MerkleToken(com.hedera.services.state.merkle.MerkleToken)

Example 3 with EntityId

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);
}
Also used : EntityId(com.hedera.services.state.submerkle.EntityId) UniqueToken(com.hedera.services.store.models.UniqueToken) MerkleUniqueToken(com.hedera.services.state.merkle.MerkleUniqueToken) MerkleToken(com.hedera.services.state.merkle.MerkleToken) MerkleUniqueToken(com.hedera.services.state.merkle.MerkleUniqueToken) EntityId(com.hedera.services.state.submerkle.EntityId) Id(com.hedera.services.store.models.Id) NftId(com.hedera.services.store.models.NftId) RichInstant(com.hedera.services.state.submerkle.RichInstant) Test(org.junit.jupiter.api.Test)

Example 4 with EntityId

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));
}
Also used : EntityId(com.hedera.services.state.submerkle.EntityId) Token(com.hedera.services.store.models.Token) MerkleToken(com.hedera.services.state.merkle.MerkleToken) UniqueToken(com.hedera.services.store.models.UniqueToken) MerkleUniqueToken(com.hedera.services.state.merkle.MerkleUniqueToken) Test(org.junit.jupiter.api.Test)

Example 5 with EntityId

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);
}
Also used : EntityId(com.hedera.services.state.submerkle.EntityId) Test(org.junit.jupiter.api.Test)

Aggregations

EntityId (com.hedera.services.state.submerkle.EntityId)35 Test (org.junit.jupiter.api.Test)18 MerkleToken (com.hedera.services.state.merkle.MerkleToken)9 RichInstant (com.hedera.services.state.submerkle.RichInstant)6 MerkleAccount (com.hedera.services.state.merkle.MerkleAccount)5 ExpirableTxnRecord (com.hedera.services.state.submerkle.ExpirableTxnRecord)5 TxnId (com.hedera.services.state.submerkle.TxnId)4 EntityNum (com.hedera.services.utils.EntityNum)4 ClassConstructorPair (com.swirlds.common.constructable.ClassConstructorPair)4 TxnReceipt (com.hedera.services.legacy.core.jproto.TxnReceipt)3 MerkleAccountState (com.hedera.services.state.merkle.MerkleAccountState)3 MerkleTopic (com.hedera.services.state.merkle.MerkleTopic)3 CurrencyAdjustments (com.hedera.services.state.submerkle.CurrencyAdjustments)3 ScheduleStore (com.hedera.services.store.schedule.ScheduleStore)3 AccountID (com.hederahashgraph.api.proto.java.AccountID)3 ByteString (com.google.protobuf.ByteString)2 JKeyList (com.hedera.services.legacy.core.jproto.JKeyList)2 MerkleEntityId (com.hedera.services.state.merkle.MerkleEntityId)2 MerkleUniqueToken (com.hedera.services.state.merkle.MerkleUniqueToken)2 DomainSerdes (com.hedera.services.state.serdes.DomainSerdes)2