use of com.hedera.services.ledger.backing.HashMapBackingTokens 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());
}
use of com.hedera.services.ledger.backing.HashMapBackingTokens 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());
}
use of com.hedera.services.ledger.backing.HashMapBackingTokens 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);
}
use of com.hedera.services.ledger.backing.HashMapBackingTokens 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);
}
use of com.hedera.services.ledger.backing.HashMapBackingTokens in project hedera-services by hashgraph.
the class LedgerBalanceChangesTest method rejectsMissingToken.
@Test
void rejectsMissingToken() {
// setup:
backingTokens = new HashMapBackingTokens();
backingTokens.put(anotherTokenKey.toGrpcTokenId(), fungibleTokenWithTreasury(aModel));
backingTokens.put(yetAnotherTokenKey.toGrpcTokenId(), fungibleTokenWithTreasury(aModel));
final var sideEffectsTracker = new SideEffectsTracker();
tokenStore = new HederaTokenStore(ids, validator, sideEffectsTracker, dynamicProperties, tokenRelsLedger, nftsLedger, backingTokens);
transferLogic = new TransferLogic(accountsLedger, nftsLedger, tokenRelsLedger, tokenStore, sideEffectsTracker, dynamicProperties, validator, autoCreationLogic, historian);
subject = new HederaLedger(tokenStore, ids, creator, validator, sideEffectsTracker, historian, dynamicProperties, accountsLedger, transferLogic, autoCreationLogic);
subject.setTokenRelsLedger(tokenRelsLedger);
subject.setMutableEntityAccess(mutableEntityAccess);
tokenStore.rebuildViews();
givenInitialBalancesAndOwnership();
// when:
subject.begin();
// and:
assertFailsWith(() -> subject.doZeroSum(fixtureChanges()), ResponseCodeEnum.INVALID_TOKEN_ID);
subject.commit();
// then:
assertInitialBalanceUnchanged();
}
Aggregations