Search in sources :

Example 1 with TransactionalLedger

use of com.hedera.services.ledger.TransactionalLedger in project hedera-services by hashgraph.

the class HederaTokenStoreTest method setup.

@BeforeEach
void setup() {
    token = mock(MerkleToken.class);
    given(token.expiry()).willReturn(expiry);
    given(token.symbol()).willReturn(symbol);
    given(token.hasAutoRenewAccount()).willReturn(true);
    given(token.adminKey()).willReturn(Optional.of(TOKEN_ADMIN_KT.asJKeyUnchecked()));
    given(token.name()).willReturn(name);
    given(token.hasAdminKey()).willReturn(true);
    given(token.hasFeeScheduleKey()).willReturn(true);
    given(token.treasury()).willReturn(EntityId.fromGrpcAccountId(treasury));
    given(token.tokenType()).willReturn(TokenType.FUNGIBLE_COMMON);
    given(token.decimals()).willReturn(2);
    nonfungibleToken = mock(MerkleToken.class);
    given(nonfungibleToken.hasAdminKey()).willReturn(true);
    given(nonfungibleToken.tokenType()).willReturn(TokenType.NON_FUNGIBLE_UNIQUE);
    ids = mock(EntityIdSource.class);
    given(ids.newTokenId(sponsor)).willReturn(created);
    hederaLedger = mock(HederaLedger.class);
    nftsLedger = (TransactionalLedger<NftId, NftProperty, MerkleUniqueToken>) mock(TransactionalLedger.class);
    given(nftsLedger.get(aNft, NftProperty.OWNER)).willReturn(EntityId.fromGrpcAccountId(sponsor));
    given(nftsLedger.get(tNft, NftProperty.OWNER)).willReturn(EntityId.fromGrpcAccountId(primaryTreasury));
    given(nftsLedger.exists(aNft)).willReturn(true);
    given(nftsLedger.exists(tNft)).willReturn(true);
    accountsLedger = (TransactionalLedger<AccountID, AccountProperty, MerkleAccount>) mock(TransactionalLedger.class);
    given(accountsLedger.exists(treasury)).willReturn(true);
    given(accountsLedger.exists(anotherFeeCollector)).willReturn(true);
    given(accountsLedger.exists(autoRenewAccount)).willReturn(true);
    given(accountsLedger.exists(newAutoRenewAccount)).willReturn(true);
    given(accountsLedger.exists(primaryTreasury)).willReturn(true);
    given(accountsLedger.exists(sponsor)).willReturn(true);
    given(accountsLedger.exists(counterparty)).willReturn(true);
    given(accountsLedger.get(treasury, IS_DELETED)).willReturn(false);
    given(accountsLedger.get(autoRenewAccount, IS_DELETED)).willReturn(false);
    given(accountsLedger.get(newAutoRenewAccount, IS_DELETED)).willReturn(false);
    given(accountsLedger.get(sponsor, IS_DELETED)).willReturn(false);
    given(accountsLedger.get(counterparty, IS_DELETED)).willReturn(false);
    given(accountsLedger.get(primaryTreasury, IS_DELETED)).willReturn(false);
    backingTokens = mock(BackingTokens.class);
    given(backingTokens.contains(misc)).willReturn(true);
    given(backingTokens.contains(nonfungible)).willReturn(true);
    given(backingTokens.getRef(created)).willReturn(token);
    given(backingTokens.getImmutableRef(created)).willReturn(token);
    given(backingTokens.getRef(misc)).willReturn(token);
    given(backingTokens.getImmutableRef(misc)).willReturn(token);
    given(backingTokens.getRef(nonfungible)).willReturn(nonfungibleToken);
    given(backingTokens.getImmutableRef(tNft.tokenId())).willReturn(nonfungibleToken);
    given(backingTokens.getImmutableRef(tNft.tokenId()).treasury()).willReturn(EntityId.fromGrpcAccountId(primaryTreasury));
    given(backingTokens.idSet()).willReturn(Set.of(created));
    tokenRelsLedger = mock(TransactionalLedger.class);
    given(tokenRelsLedger.exists(sponsorMisc)).willReturn(true);
    given(tokenRelsLedger.exists(treasuryNft)).willReturn(true);
    given(tokenRelsLedger.exists(sponsorNft)).willReturn(true);
    given(tokenRelsLedger.exists(counterpartyNft)).willReturn(true);
    given(tokenRelsLedger.get(sponsorMisc, TOKEN_BALANCE)).willReturn(sponsorBalance);
    given(tokenRelsLedger.get(sponsorMisc, IS_FROZEN)).willReturn(false);
    given(tokenRelsLedger.get(sponsorMisc, IS_KYC_GRANTED)).willReturn(true);
    given(tokenRelsLedger.exists(treasuryMisc)).willReturn(true);
    given(tokenRelsLedger.exists(anotherFeeCollectorMisc)).willReturn(true);
    given(tokenRelsLedger.get(treasuryMisc, TOKEN_BALANCE)).willReturn(treasuryBalance);
    given(tokenRelsLedger.get(treasuryMisc, IS_FROZEN)).willReturn(false);
    given(tokenRelsLedger.get(treasuryMisc, IS_KYC_GRANTED)).willReturn(true);
    given(tokenRelsLedger.get(treasuryNft, TOKEN_BALANCE)).willReturn(123L);
    given(tokenRelsLedger.get(treasuryNft, IS_FROZEN)).willReturn(false);
    given(tokenRelsLedger.get(treasuryNft, IS_KYC_GRANTED)).willReturn(true);
    given(tokenRelsLedger.get(sponsorNft, TOKEN_BALANCE)).willReturn(123L);
    given(tokenRelsLedger.get(sponsorNft, IS_FROZEN)).willReturn(false);
    given(tokenRelsLedger.get(sponsorNft, IS_KYC_GRANTED)).willReturn(true);
    given(tokenRelsLedger.get(counterpartyNft, TOKEN_BALANCE)).willReturn(123L);
    given(tokenRelsLedger.get(counterpartyNft, IS_FROZEN)).willReturn(false);
    given(tokenRelsLedger.get(counterpartyNft, IS_KYC_GRANTED)).willReturn(true);
    given(tokenRelsLedger.get(newTreasuryNft, TOKEN_BALANCE)).willReturn(1L);
    properties = mock(GlobalDynamicProperties.class);
    given(properties.maxTokensPerAccount()).willReturn(MAX_TOKENS_PER_ACCOUNT);
    given(properties.maxTokenSymbolUtf8Bytes()).willReturn(MAX_TOKEN_SYMBOL_UTF8_BYTES);
    given(properties.maxTokenNameUtf8Bytes()).willReturn(MAX_TOKEN_NAME_UTF8_BYTES);
    given(properties.maxCustomFeesAllowed()).willReturn(maxCustomFees);
    sideEffectsTracker = new SideEffectsTracker();
    subject = new HederaTokenStore(ids, TEST_VALIDATOR, sideEffectsTracker, properties, tokenRelsLedger, nftsLedger, backingTokens);
    subject.setAccountsLedger(accountsLedger);
    subject.setHederaLedger(hederaLedger);
    subject.knownTreasuries.put(treasury, new HashSet<>() {

        {
            add(misc);
        }
    });
}
Also used : BackingTokens(com.hedera.services.ledger.backing.BackingTokens) EntityIdSource(com.hedera.services.ledger.ids.EntityIdSource) AccountID(com.hederahashgraph.api.proto.java.AccountID) HederaLedger(com.hedera.services.ledger.HederaLedger) SideEffectsTracker(com.hedera.services.context.SideEffectsTracker) MerkleToken(com.hedera.services.state.merkle.MerkleToken) MerkleAccount(com.hedera.services.state.merkle.MerkleAccount) GlobalDynamicProperties(com.hedera.services.context.properties.GlobalDynamicProperties) NftId(com.hedera.services.store.models.NftId) NftProperty(com.hedera.services.ledger.properties.NftProperty) AccountProperty(com.hedera.services.ledger.properties.AccountProperty) TransactionalLedger(com.hedera.services.ledger.TransactionalLedger) MerkleUniqueToken(com.hedera.services.state.merkle.MerkleUniqueToken) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with TransactionalLedger

use of com.hedera.services.ledger.TransactionalLedger in project hedera-services by hashgraph.

the class WorldLedgersTest method wrapsAsExpectedWithoutCommitInterceptors.

@Test
void wrapsAsExpectedWithoutCommitInterceptors() {
    final var liveTokenRels = new TransactionalLedger<>(TokenRelProperty.class, MerkleTokenRelStatus::new, new HashMapBackingTokenRels(), new ChangeSummaryManager<>());
    final var liveAccounts = new TransactionalLedger<>(AccountProperty.class, MerkleAccount::new, new HashMapBackingAccounts(), new ChangeSummaryManager<>());
    final var liveNfts = new TransactionalLedger<>(NftProperty.class, MerkleUniqueToken::new, new HashMapBackingNfts(), new ChangeSummaryManager<>());
    final var liveTokens = new TransactionalLedger<>(TokenProperty.class, MerkleToken::new, new HashMapBackingTokens(), new ChangeSummaryManager<>());
    final var liveAliases = new AliasManager();
    final var source = new WorldLedgers(liveAliases, liveTokenRels, liveAccounts, liveNfts, liveTokens);
    assertTrue(source.areMutable());
    final var nullTokenRels = new WorldLedgers(liveAliases, null, liveAccounts, liveNfts, liveTokens);
    final var nullAccounts = new WorldLedgers(liveAliases, liveTokenRels, null, liveNfts, liveTokens);
    final var nullNfts = new WorldLedgers(liveAliases, liveTokenRels, liveAccounts, null, liveTokens);
    final var nullTokens = new WorldLedgers(liveAliases, liveTokenRels, liveAccounts, liveNfts, null);
    assertFalse(nullTokenRels.areMutable());
    assertFalse(nullAccounts.areMutable());
    assertFalse(nullNfts.areMutable());
    assertFalse(nullTokens.areMutable());
    final var wrappedUnusable = nullAccounts.wrapped();
    assertSame(((StackedContractAliases) wrappedUnusable.aliases()).wrappedAliases(), nullAccounts.aliases());
    assertFalse(wrappedUnusable.areMutable());
    final var wrappedSource = source.wrapped();
    assertSame(liveTokenRels, wrappedSource.tokenRels().getEntitiesLedger());
    assertSame(liveAccounts, wrappedSource.accounts().getEntitiesLedger());
    assertSame(liveNfts, wrappedSource.nfts().getEntitiesLedger());
    assertSame(liveTokens, wrappedSource.tokens().getEntitiesLedger());
    final var stackedAliases = (StackedContractAliases) wrappedSource.aliases();
    assertSame(liveAliases, stackedAliases.wrappedAliases());
}
Also used : HashMapBackingTokenRels(com.hedera.services.ledger.backing.HashMapBackingTokenRels) MerkleToken(com.hedera.services.state.merkle.MerkleToken) MerkleAccount(com.hedera.services.state.merkle.MerkleAccount) TransactionalLedger(com.hedera.services.ledger.TransactionalLedger) MerkleTokenRelStatus(com.hedera.services.state.merkle.MerkleTokenRelStatus) HashMapBackingNfts(com.hedera.services.ledger.backing.HashMapBackingNfts) AliasManager(com.hedera.services.ledger.accounts.AliasManager) StackedContractAliases(com.hedera.services.ledger.accounts.StackedContractAliases) HashMapBackingTokens(com.hedera.services.ledger.backing.HashMapBackingTokens) MerkleUniqueToken(com.hedera.services.state.merkle.MerkleUniqueToken) HashMapBackingAccounts(com.hedera.services.ledger.backing.HashMapBackingAccounts) Test(org.junit.jupiter.api.Test)

Example 3 with TransactionalLedger

use of com.hedera.services.ledger.TransactionalLedger in project hedera-services by hashgraph.

the class WorldLedgersTest method wrapsAsExpectedWithCommitInterceptors.

@Test
void wrapsAsExpectedWithCommitInterceptors() {
    final var liveTokenRels = new TransactionalLedger<>(TokenRelProperty.class, MerkleTokenRelStatus::new, new HashMapBackingTokenRels(), new ChangeSummaryManager<>());
    final var liveAccounts = new TransactionalLedger<>(AccountProperty.class, MerkleAccount::new, new HashMapBackingAccounts(), new ChangeSummaryManager<>());
    final var liveNfts = new TransactionalLedger<>(NftProperty.class, MerkleUniqueToken::new, new HashMapBackingNfts(), new ChangeSummaryManager<>());
    final var liveTokens = new TransactionalLedger<>(TokenProperty.class, MerkleToken::new, new HashMapBackingTokens(), new ChangeSummaryManager<>());
    final var liveAliases = new AliasManager();
    final var source = new WorldLedgers(liveAliases, liveTokenRels, liveAccounts, liveNfts, liveTokens);
    assertTrue(source.areMutable());
    final var nullTokenRels = new WorldLedgers(liveAliases, null, liveAccounts, liveNfts, liveTokens);
    final var nullAccounts = new WorldLedgers(liveAliases, liveTokenRels, null, liveNfts, liveTokens);
    final var nullNfts = new WorldLedgers(liveAliases, liveTokenRels, liveAccounts, null, liveTokens);
    final var nullTokens = new WorldLedgers(liveAliases, liveTokenRels, liveAccounts, liveNfts, null);
    assertFalse(nullTokenRels.areMutable());
    assertFalse(nullAccounts.areMutable());
    assertFalse(nullNfts.areMutable());
    assertFalse(nullTokens.areMutable());
    final var wrappedUnusable = nullAccounts.wrapped(sideEffectsTracker);
    assertSame(((StackedContractAliases) wrappedUnusable.aliases()).wrappedAliases(), nullAccounts.aliases());
    assertFalse(wrappedUnusable.areMutable());
    final var wrappedSource = source.wrapped(sideEffectsTracker);
    assertSame(liveTokenRels, wrappedSource.tokenRels().getEntitiesLedger());
    assertSame(liveAccounts, wrappedSource.accounts().getEntitiesLedger());
    assertSame(liveNfts, wrappedSource.nfts().getEntitiesLedger());
    assertSame(liveTokens, wrappedSource.tokens().getEntitiesLedger());
    final var stackedAliases = (StackedContractAliases) wrappedSource.aliases();
    assertSame(liveAliases, stackedAliases.wrappedAliases());
}
Also used : HashMapBackingTokenRels(com.hedera.services.ledger.backing.HashMapBackingTokenRels) MerkleToken(com.hedera.services.state.merkle.MerkleToken) MerkleAccount(com.hedera.services.state.merkle.MerkleAccount) TransactionalLedger(com.hedera.services.ledger.TransactionalLedger) MerkleTokenRelStatus(com.hedera.services.state.merkle.MerkleTokenRelStatus) HashMapBackingNfts(com.hedera.services.ledger.backing.HashMapBackingNfts) AliasManager(com.hedera.services.ledger.accounts.AliasManager) StackedContractAliases(com.hedera.services.ledger.accounts.StackedContractAliases) HashMapBackingTokens(com.hedera.services.ledger.backing.HashMapBackingTokens) MerkleUniqueToken(com.hedera.services.state.merkle.MerkleUniqueToken) HashMapBackingAccounts(com.hedera.services.ledger.backing.HashMapBackingAccounts) Test(org.junit.jupiter.api.Test)

Example 4 with TransactionalLedger

use of com.hedera.services.ledger.TransactionalLedger in project hedera-services by hashgraph.

the class AbstractLedgerWorldUpdaterTest method setupLedgers.

private void setupLedgers() {
    final var tokenRelsLedger = new TransactionalLedger<>(TokenRelProperty.class, MerkleTokenRelStatus::new, new HashMapBackingTokenRels(), new ChangeSummaryManager<>());
    final var accountsLedger = new TransactionalLedger<>(AccountProperty.class, MerkleAccount::new, new HashMapBackingAccounts(), new ChangeSummaryManager<>());
    final var tokensLedger = new TransactionalLedger<>(TokenProperty.class, MerkleToken::new, new HashMapBackingTokens(), new ChangeSummaryManager<>());
    final var nftsLedger = new TransactionalLedger<>(NftProperty.class, MerkleUniqueToken::new, new HashMapBackingNfts(), new ChangeSummaryManager<>());
    tokenRelsLedger.begin();
    accountsLedger.begin();
    nftsLedger.begin();
    tokensLedger.begin();
    ledgers = new WorldLedgers(aliases, tokenRelsLedger, accountsLedger, nftsLedger, tokensLedger);
}
Also used : MerkleTokenRelStatus(com.hedera.services.state.merkle.MerkleTokenRelStatus) HashMapBackingNfts(com.hedera.services.ledger.backing.HashMapBackingNfts) HashMapBackingTokenRels(com.hedera.services.ledger.backing.HashMapBackingTokenRels) MerkleToken(com.hedera.services.state.merkle.MerkleToken) MerkleAccount(com.hedera.services.state.merkle.MerkleAccount) HashMapBackingTokens(com.hedera.services.ledger.backing.HashMapBackingTokens) MerkleUniqueToken(com.hedera.services.state.merkle.MerkleUniqueToken) HashMapBackingAccounts(com.hedera.services.ledger.backing.HashMapBackingAccounts) TransactionalLedger(com.hedera.services.ledger.TransactionalLedger)

Example 5 with TransactionalLedger

use of com.hedera.services.ledger.TransactionalLedger in project hedera-services by hashgraph.

the class AbstractStackedLedgerUpdaterTest method setupLedgers.

private void setupLedgers() {
    final var tokenRelsLedger = new TransactionalLedger<>(TokenRelProperty.class, MerkleTokenRelStatus::new, new HashMapBackingTokenRels(), new ChangeSummaryManager<>());
    final var accountsLedger = new TransactionalLedger<>(AccountProperty.class, MerkleAccount::new, new HashMapBackingAccounts(), new ChangeSummaryManager<>());
    final var nftsLedger = new TransactionalLedger<>(NftProperty.class, MerkleUniqueToken::new, new HashMapBackingNfts(), new ChangeSummaryManager<>());
    final var tokensLedger = new TransactionalLedger<>(TokenProperty.class, MerkleToken::new, new HashMapBackingTokens(), new ChangeSummaryManager<>());
    tokenRelsLedger.begin();
    accountsLedger.begin();
    nftsLedger.begin();
    ledgers = new WorldLedgers(aliases, tokenRelsLedger, accountsLedger, nftsLedger, tokensLedger);
}
Also used : MerkleTokenRelStatus(com.hedera.services.state.merkle.MerkleTokenRelStatus) HashMapBackingNfts(com.hedera.services.ledger.backing.HashMapBackingNfts) HashMapBackingTokenRels(com.hedera.services.ledger.backing.HashMapBackingTokenRels) MerkleToken(com.hedera.services.state.merkle.MerkleToken) MerkleAccount(com.hedera.services.state.merkle.MerkleAccount) HashMapBackingTokens(com.hedera.services.ledger.backing.HashMapBackingTokens) MerkleUniqueToken(com.hedera.services.state.merkle.MerkleUniqueToken) HashMapBackingAccounts(com.hedera.services.ledger.backing.HashMapBackingAccounts) TransactionalLedger(com.hedera.services.ledger.TransactionalLedger)

Aggregations

TransactionalLedger (com.hedera.services.ledger.TransactionalLedger)5 MerkleAccount (com.hedera.services.state.merkle.MerkleAccount)5 MerkleToken (com.hedera.services.state.merkle.MerkleToken)5 MerkleUniqueToken (com.hedera.services.state.merkle.MerkleUniqueToken)5 HashMapBackingAccounts (com.hedera.services.ledger.backing.HashMapBackingAccounts)4 HashMapBackingNfts (com.hedera.services.ledger.backing.HashMapBackingNfts)4 HashMapBackingTokenRels (com.hedera.services.ledger.backing.HashMapBackingTokenRels)4 HashMapBackingTokens (com.hedera.services.ledger.backing.HashMapBackingTokens)4 MerkleTokenRelStatus (com.hedera.services.state.merkle.MerkleTokenRelStatus)4 AliasManager (com.hedera.services.ledger.accounts.AliasManager)2 StackedContractAliases (com.hedera.services.ledger.accounts.StackedContractAliases)2 Test (org.junit.jupiter.api.Test)2 SideEffectsTracker (com.hedera.services.context.SideEffectsTracker)1 GlobalDynamicProperties (com.hedera.services.context.properties.GlobalDynamicProperties)1 HederaLedger (com.hedera.services.ledger.HederaLedger)1 BackingTokens (com.hedera.services.ledger.backing.BackingTokens)1 EntityIdSource (com.hedera.services.ledger.ids.EntityIdSource)1 AccountProperty (com.hedera.services.ledger.properties.AccountProperty)1 NftProperty (com.hedera.services.ledger.properties.NftProperty)1 NftId (com.hedera.services.store.models.NftId)1