Search in sources :

Example 1 with StateView

use of com.hedera.services.context.primitives.StateView in project hedera-services by hashgraph.

the class GetTxnRecordAnswerTest method setup.

@BeforeEach
private void setup() {
    recordCache = mock(RecordCache.class);
    accounts = mock(MerkleMap.class);
    nodeProps = mock(NodeLocalProperties.class);
    final MutableStateChildren children = new MutableStateChildren();
    children.setAccounts(accounts);
    view = new StateView(null, null, children, null);
    optionValidator = mock(OptionValidator.class);
    answerFunctions = mock(AnswerFunctions.class);
    subject = new GetTxnRecordAnswer(recordCache, optionValidator, answerFunctions);
}
Also used : MutableStateChildren(com.hedera.services.context.MutableStateChildren) OptionValidator(com.hedera.services.txns.validation.OptionValidator) MerkleMap(com.swirlds.merkle.map.MerkleMap) StateView(com.hedera.services.context.primitives.StateView) NodeLocalProperties(com.hedera.services.context.properties.NodeLocalProperties) RecordCache(com.hedera.services.records.RecordCache) AnswerFunctions(com.hedera.services.queries.answering.AnswerFunctions) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with StateView

use of com.hedera.services.context.primitives.StateView 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 3 with StateView

use of com.hedera.services.context.primitives.StateView in project hedera-services by hashgraph.

the class GetAccountInfoAnswerTest method setup.

@BeforeEach
private void setup() throws Throwable {
    tokenRels = new MerkleMap<>();
    tokenRels.put(fromAccountTokenRel(payerId, firstToken), new MerkleTokenRelStatus(firstBalance, true, true, true));
    tokenRels.put(fromAccountTokenRel(payerId, secondToken), new MerkleTokenRelStatus(secondBalance, false, false, true));
    tokenRels.put(fromAccountTokenRel(payerId, thirdToken), new MerkleTokenRelStatus(thirdBalance, true, true, false));
    tokenRels.put(fromAccountTokenRel(payerId, fourthToken), new MerkleTokenRelStatus(fourthBalance, false, false, true));
    tokenRels.put(fromAccountTokenRel(payerId, missingToken), new MerkleTokenRelStatus(missingBalance, false, false, false));
    var tokens = new MerkleAccountTokens();
    tokens.associateAll(Set.of(firstToken, secondToken, thirdToken, fourthToken, missingToken));
    var tokenAllowanceKey = FcTokenAllowanceId.from(EntityNum.fromLong(1000L), EntityNum.fromLong(2000L));
    var tokenAllowanceValue = FcTokenAllowance.from(false, List.of(1L, 2L));
    TreeMap<EntityNum, Long> cryptoAllowances = new TreeMap();
    TreeMap<FcTokenAllowanceId, Long> fungibleTokenAllowances = new TreeMap();
    TreeMap<FcTokenAllowanceId, FcTokenAllowance> nftAllowances = new TreeMap();
    cryptoAllowances.put(EntityNum.fromLong(1L), 10L);
    fungibleTokenAllowances.put(tokenAllowanceKey, 20L);
    nftAllowances.put(tokenAllowanceKey, tokenAllowanceValue);
    payerAccount = MerkleAccountFactory.newAccount().accountKeys(COMPLEX_KEY_ACCOUNT_KT).memo(memo).proxy(asAccount("1.2.3")).senderThreshold(1_234L).receiverThreshold(4_321L).receiverSigRequired(true).balance(555L).autoRenewPeriod(1_000_000L).expirationTime(9_999_999L).cryptoAllowances(cryptoAllowances).fungibleTokenAllowances(fungibleTokenAllowances).nftAllowances(nftAllowances).get();
    payerAccount.setTokens(tokens);
    final MutableStateChildren children = new MutableStateChildren();
    children.setAccounts(accounts);
    children.setTokenAssociations(tokenRels);
    view = new StateView(tokenStore, scheduleStore, children, networkInfo);
    subject = new GetAccountInfoAnswer(optionValidator, aliasManager);
}
Also used : MerkleAccountTokens(com.hedera.services.state.merkle.MerkleAccountTokens) StateView(com.hedera.services.context.primitives.StateView) TreeMap(java.util.TreeMap) EntityNum(com.hedera.services.utils.EntityNum) MerkleTokenRelStatus(com.hedera.services.state.merkle.MerkleTokenRelStatus) FcTokenAllowanceId(com.hedera.services.state.submerkle.FcTokenAllowanceId) MutableStateChildren(com.hedera.services.context.MutableStateChildren) FcTokenAllowance(com.hedera.services.state.submerkle.FcTokenAllowance) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with StateView

use of com.hedera.services.context.primitives.StateView in project hedera-services by hashgraph.

the class GetMerkleTopicInfoAnswerTest method setup.

@BeforeEach
private void setup() throws Exception {
    adminKey = COMPLEX_KEY_ACCOUNT_KT.asKey();
    submitKey = MISC_ACCOUNT_KT.asKey();
    topics = mock(MerkleMap.class);
    merkleTopic = TopicFactory.newTopic().adminKey(adminKey).submitKey(submitKey).memo(memo).expiry(expiry).deleted(false).autoRenewDuration(duration).autoRenewId(asAccount(id)).get();
    merkleTopic.setRunningHash(hash);
    merkleTopic.setSequenceNumber(seqNo);
    given(topics.get(key)).willReturn(merkleTopic);
    nodeProps = mock(NodeLocalProperties.class);
    final MutableStateChildren children = new MutableStateChildren();
    children.setTopics(topics);
    networkInfo = mock(NetworkInfo.class);
    given(networkInfo.ledgerId()).willReturn(ledgerId);
    view = new StateView(null, null, children, networkInfo);
    optionValidator = mock(OptionValidator.class);
    subject = new GetTopicInfoAnswer(optionValidator);
}
Also used : MutableStateChildren(com.hedera.services.context.MutableStateChildren) OptionValidator(com.hedera.services.txns.validation.OptionValidator) NetworkInfo(com.hedera.services.config.NetworkInfo) MerkleMap(com.swirlds.merkle.map.MerkleMap) StateView(com.hedera.services.context.primitives.StateView) NodeLocalProperties(com.hedera.services.context.properties.NodeLocalProperties) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with StateView

use of com.hedera.services.context.primitives.StateView in project hedera-services by hashgraph.

the class AnswerFunctionsTest method setupAccountsView.

private void setupAccountsView() {
    final var children = new MutableStateChildren();
    children.setAccounts(accounts);
    view = new StateView(null, null, children, null);
}
Also used : MutableStateChildren(com.hedera.services.context.MutableStateChildren) StateView(com.hedera.services.context.primitives.StateView)

Aggregations

StateView (com.hedera.services.context.primitives.StateView)11 MutableStateChildren (com.hedera.services.context.MutableStateChildren)10 BeforeEach (org.junit.jupiter.api.BeforeEach)8 MerkleMap (com.swirlds.merkle.map.MerkleMap)6 NodeLocalProperties (com.hedera.services.context.properties.NodeLocalProperties)4 AnswerFunctions (com.hedera.services.queries.answering.AnswerFunctions)4 OptionValidator (com.hedera.services.txns.validation.OptionValidator)4 RecordCache (com.hedera.services.records.RecordCache)2 MerkleTokenRelStatus (com.hedera.services.state.merkle.MerkleTokenRelStatus)2 NetworkInfo (com.hedera.services.config.NetworkInfo)1 AliasManager (com.hedera.services.ledger.accounts.AliasManager)1 MerkleAccountTokens (com.hedera.services.state.merkle.MerkleAccountTokens)1 MerkleToken (com.hedera.services.state.merkle.MerkleToken)1 FcTokenAllowance (com.hedera.services.state.submerkle.FcTokenAllowance)1 FcTokenAllowanceId (com.hedera.services.state.submerkle.FcTokenAllowanceId)1 ScheduleStore (com.hedera.services.store.schedule.ScheduleStore)1 TokenStore (com.hedera.services.store.tokens.TokenStore)1 EntityNum (com.hedera.services.utils.EntityNum)1 CryptoGetInfoQuery (com.hederahashgraph.api.proto.java.CryptoGetInfoQuery)1 CryptoGetInfoResponse (com.hederahashgraph.api.proto.java.CryptoGetInfoResponse)1