Search in sources :

Example 1 with AliasManager

use of com.hedera.services.ledger.accounts.AliasManager 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 2 with AliasManager

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

the class SigOpsRegressionTest method setupFor.

private void setupFor(TxnHandlingScenario scenario) throws Throwable {
    hfs = scenario.hfs();
    aliasManager = mock(AliasManager.class);
    runningAvgs = mock(MiscRunningAvgs.class);
    speedometers = mock(MiscSpeedometers.class);
    accounts = scenario.accounts();
    platformTxn = scenario.platformTxn();
    expectedErrorStatus = null;
    final var hfsSigMetaLookup = new HfsSigMetaLookup(hfs, fileNumbers);
    signingOrder = new SigRequirements(defaultLookupsFor(aliasManager, hfsSigMetaLookup, () -> accounts, () -> null, ref -> null, ref -> null), mockSignatureWaivers);
    final var payerKeys = signingOrder.keysForPayer(platformTxn.getTxn(), CODE_ORDER_RESULT_FACTORY);
    expectedSigs = new ArrayList<>();
    if (payerKeys.hasErrorReport()) {
        expectedErrorStatus = payerKeys.getErrorReport();
    } else {
        PlatformSigsCreationResult payerResult = PlatformSigOps.createCryptoSigsFrom(payerKeys.getOrderedKeys(), new PojoSigMapPubKeyToSigBytes(platformTxn.getSigMap()), new ReusableBodySigningFactory(platformTxn));
        expectedSigs.addAll(payerResult.getPlatformSigs());
        SigningOrderResult<ResponseCodeEnum> otherKeys = signingOrder.keysForOtherParties(platformTxn.getTxn(), CODE_ORDER_RESULT_FACTORY);
        if (otherKeys.hasErrorReport()) {
            expectedErrorStatus = otherKeys.getErrorReport();
        } else {
            PlatformSigsCreationResult otherResult = PlatformSigOps.createCryptoSigsFrom(otherKeys.getOrderedKeys(), new PojoSigMapPubKeyToSigBytes(platformTxn.getSigMap()), new ReusableBodySigningFactory(platformTxn));
            if (!otherResult.hasFailed()) {
                expectedSigs.addAll(otherResult.getPlatformSigs());
            }
        }
    }
}
Also used : AliasManager(com.hedera.services.ledger.accounts.AliasManager) SigRequirements(com.hedera.services.sigs.order.SigRequirements) PojoSigMapPubKeyToSigBytes(com.hedera.services.sigs.sourcing.PojoSigMapPubKeyToSigBytes) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) MiscSpeedometers(com.hedera.services.stats.MiscSpeedometers) HfsSigMetaLookup(com.hedera.services.sigs.metadata.lookups.HfsSigMetaLookup) MiscRunningAvgs(com.hedera.services.stats.MiscRunningAvgs) ReusableBodySigningFactory(com.hedera.services.sigs.factories.ReusableBodySigningFactory)

Example 3 with AliasManager

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

the class SigVerifierRegressionTest method setupFor.

private void setupFor(TxnHandlingScenario scenario) throws Throwable {
    accounts = scenario.accounts();
    platformTxn = scenario.platformTxn();
    aliasManager = mock(AliasManager.class);
    keyOrder = new SigRequirements(defaultLookupsFor(aliasManager, null, () -> accounts, () -> null, ref -> null, ref -> null), mockSignatureWaivers);
    final var nodeInfo = mock(NodeInfo.class);
    given(nodeInfo.selfAccount()).willReturn(DEFAULT_NODE);
    isQueryPayment = PrecheckUtils.queryPaymentTestFor(nodeInfo);
    SyncVerifier syncVerifier = new CryptoEngine()::verifySync;
    precheckKeyReqs = new PrecheckKeyReqs(keyOrder, isQueryPayment);
    precheckVerifier = new PrecheckVerifier(syncVerifier, precheckKeyReqs);
}
Also used : SyncVerifier(com.hedera.services.sigs.verification.SyncVerifier) AliasManager(com.hedera.services.ledger.accounts.AliasManager) SigRequirements(com.hedera.services.sigs.order.SigRequirements) PrecheckKeyReqs(com.hedera.services.sigs.verification.PrecheckKeyReqs) PrecheckVerifier(com.hedera.services.sigs.verification.PrecheckVerifier) CryptoEngine(com.swirlds.common.crypto.engine.CryptoEngine)

Example 4 with AliasManager

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

the class GetAccountBalanceAnswerTest method setup.

@BeforeEach
private void setup() {
    deleted = mock(MerkleToken.class);
    given(deleted.isDeleted()).willReturn(true);
    given(deleted.decimals()).willReturn(123);
    notDeleted = mock(MerkleToken.class);
    given(notDeleted.isDeleted()).willReturn(false);
    given(notDeleted.decimals()).willReturn(1).willReturn(2);
    tokenRels = new MerkleMap<>();
    tokenRels.put(fromAccountTokenRel(target, aToken), new MerkleTokenRelStatus(aBalance, true, true, true));
    tokenRels.put(fromAccountTokenRel(target, bToken), new MerkleTokenRelStatus(bBalance, false, false, false));
    tokenRels.put(fromAccountTokenRel(target, cToken), new MerkleTokenRelStatus(cBalance, false, false, true));
    tokenRels.put(fromAccountTokenRel(target, dToken), new MerkleTokenRelStatus(dBalance, false, false, true));
    accounts = mock(MerkleMap.class);
    nodeProps = mock(NodeLocalProperties.class);
    given(accounts.get(fromAccountId(asAccount(accountIdLit)))).willReturn(accountV);
    given(accounts.get(fromContractId(asContract(contractIdLit)))).willReturn(contractV);
    tokenStore = mock(TokenStore.class);
    given(tokenStore.exists(aToken)).willReturn(true);
    given(tokenStore.exists(bToken)).willReturn(true);
    given(tokenStore.exists(cToken)).willReturn(true);
    given(tokenStore.exists(dToken)).willReturn(false);
    given(tokenStore.get(aToken)).willReturn(notDeleted);
    given(tokenStore.get(bToken)).willReturn(notDeleted);
    given(tokenStore.get(cToken)).willReturn(deleted);
    scheduleStore = mock(ScheduleStore.class);
    final MutableStateChildren children = new MutableStateChildren();
    children.setAccounts(accounts);
    children.setTokenAssociations(tokenRels);
    view = new StateView(tokenStore, scheduleStore, children, null);
    optionValidator = mock(OptionValidator.class);
    aliasManager = mock(AliasManager.class);
    subject = new GetAccountBalanceAnswer(aliasManager, optionValidator);
}
Also used : MerkleTokenRelStatus(com.hedera.services.state.merkle.MerkleTokenRelStatus) AliasManager(com.hedera.services.ledger.accounts.AliasManager) MutableStateChildren(com.hedera.services.context.MutableStateChildren) OptionValidator(com.hedera.services.txns.validation.OptionValidator) MerkleToken(com.hedera.services.state.merkle.MerkleToken) MerkleMap(com.swirlds.merkle.map.MerkleMap) StateView(com.hedera.services.context.primitives.StateView) NodeLocalProperties(com.hedera.services.context.properties.NodeLocalProperties) TokenStore(com.hedera.services.store.tokens.TokenStore) ScheduleStore(com.hedera.services.store.schedule.ScheduleStore) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with AliasManager

use of com.hedera.services.ledger.accounts.AliasManager 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)

Aggregations

AliasManager (com.hedera.services.ledger.accounts.AliasManager)9 Test (org.junit.jupiter.api.Test)6 MerkleAccount (com.hedera.services.state.merkle.MerkleAccount)5 SigRequirements (com.hedera.services.sigs.order.SigRequirements)4 MerkleMap (com.swirlds.merkle.map.MerkleMap)4 ReusableBodySigningFactory (com.hedera.services.sigs.factories.ReusableBodySigningFactory)3 HfsSigMetaLookup (com.hedera.services.sigs.metadata.lookups.HfsSigMetaLookup)3 PojoSigMapPubKeyToSigBytes (com.hedera.services.sigs.sourcing.PojoSigMapPubKeyToSigBytes)3 SyncVerifier (com.hedera.services.sigs.verification.SyncVerifier)3 MiscRunningAvgs (com.hedera.services.stats.MiscRunningAvgs)3 MiscSpeedometers (com.hedera.services.stats.MiscSpeedometers)3 EntityNum (com.hedera.services.utils.EntityNum)3 EntityNumbers (com.hedera.services.config.EntityNumbers)2 FileNumbers (com.hedera.services.config.FileNumbers)2 MockEntityNumbers (com.hedera.services.config.MockEntityNumbers)2 MockFileNumbers (com.hedera.services.config.MockFileNumbers)2 HederaFs (com.hedera.services.files.HederaFs)2 DEFAULT_ACTIVATION_CHARACTERISTICS (com.hedera.services.keys.DefaultActivationCharacteristics.DEFAULT_ACTIVATION_CHARACTERISTICS)2 HederaKeyActivation (com.hedera.services.keys.HederaKeyActivation)2 ONLY_IF_SIG_IS_VALID (com.hedera.services.keys.HederaKeyActivation.ONLY_IF_SIG_IS_VALID)2