Search in sources :

Example 11 with MerkleAccount

use of com.hedera.services.state.merkle.MerkleAccount 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 12 with MerkleAccount

use of com.hedera.services.state.merkle.MerkleAccount 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 13 with MerkleAccount

use of com.hedera.services.state.merkle.MerkleAccount 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)

Example 14 with MerkleAccount

use of com.hedera.services.state.merkle.MerkleAccount in project hedera-services by hashgraph.

the class HederaWorldStateTest method usesContractKeyWhenSponsorDid.

@Test
void usesContractKeyWhenSponsorDid() {
    final var sponsorId = AccountID.newBuilder().setAccountNum(123L).build();
    final var sponsoredId = AccountID.newBuilder().setAccountNum(321L).build();
    final var sponsorAddress = EntityIdUtils.asEvmAddress(sponsorId);
    final var sponsoredAddress = EntityIdUtils.asEvmAddress(sponsoredId);
    givenNonNullWorldLedgers();
    given(entityAccess.isExtant(any())).willReturn(true);
    given(entityAccess.getKey(sponsorId)).willReturn(new JContractIDKey(0, 0, 123L));
    final var updater = subject.updater();
    updater.getSponsorMap().put(Address.fromHexString(Hex.encodeHexString(sponsoredAddress)), Address.fromHexString(Hex.encodeHexString(sponsorAddress)));
    final ArgumentCaptor<HederaAccountCustomizer> captor = forClass(HederaAccountCustomizer.class);
    updater.commit();
    subject.customizeSponsoredAccounts();
    verify(entityAccess).customize(eq(sponsoredId), captor.capture());
    final var customizer = captor.getValue();
    final var standin = new MerkleAccount();
    customizer.customizing(standin);
    final var key = standin.getAccountKey();
    assertInstanceOf(JContractIDKey.class, key);
    assertEquals(sponsoredId.getAccountNum(), ((JContractIDKey) key).getContractID().getContractNum());
}
Also used : MerkleAccount(com.hedera.services.state.merkle.MerkleAccount) JContractIDKey(com.hedera.services.legacy.core.jproto.JContractIDKey) HederaAccountCustomizer(com.hedera.services.ledger.accounts.HederaAccountCustomizer) Test(org.junit.jupiter.api.Test)

Example 15 with MerkleAccount

use of com.hedera.services.state.merkle.MerkleAccount in project hedera-services by hashgraph.

the class BasedLedgerValidatorTest method expectedWith.

private MerkleAccount expectedWith(long balance) throws NegativeAccountBalanceException {
    MerkleAccount hAccount = new HederaAccountCustomizer().isReceiverSigRequired(false).proxy(MISSING_ENTITY_ID).isDeleted(false).expiry(1_234_567L).memo("").isSmartContract(false).customizing(new MerkleAccount());
    hAccount.setBalance(balance);
    return hAccount;
}
Also used : MerkleAccount(com.hedera.services.state.merkle.MerkleAccount) HederaAccountCustomizer(com.hedera.services.ledger.accounts.HederaAccountCustomizer)

Aggregations

MerkleAccount (com.hedera.services.state.merkle.MerkleAccount)22 Test (org.junit.jupiter.api.Test)10 EntityNum (com.hedera.services.utils.EntityNum)9 MerkleToken (com.hedera.services.state.merkle.MerkleToken)8 MerkleTokenRelStatus (com.hedera.services.state.merkle.MerkleTokenRelStatus)6 TransactionalLedger (com.hedera.services.ledger.TransactionalLedger)5 MerkleUniqueToken (com.hedera.services.state.merkle.MerkleUniqueToken)5 HederaAccountCustomizer (com.hedera.services.ledger.accounts.HederaAccountCustomizer)4 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 EntityId (com.hedera.services.state.submerkle.EntityId)4 AliasManager (com.hedera.services.ledger.accounts.AliasManager)3 ExpirableTxnRecord (com.hedera.services.state.submerkle.ExpirableTxnRecord)3 ClassConstructorPair (com.swirlds.common.constructable.ClassConstructorPair)3 MerkleMap (com.swirlds.merkle.map.MerkleMap)3 StackedContractAliases (com.hedera.services.ledger.accounts.StackedContractAliases)2 TxnReceipt (com.hedera.services.legacy.core.jproto.TxnReceipt)2 MerkleAccountState (com.hedera.services.state.merkle.MerkleAccountState)2