Search in sources :

Example 1 with SideEffectsTracker

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

the class BaseHederaLedgerTestHelper method commonSetup.

protected void commonSetup() {
    sideEffectsTracker = mock(SideEffectsTracker.class);
    creator = mock(ExpiringCreations.class);
    historian = mock(AccountRecordsHistorian.class);
    ids = new EntityIdSource() {

        long nextId = NEXT_ID;

        @Override
        public TopicID newTopicId(final AccountID sponsor) {
            return TopicID.newBuilder().setTopicNum(nextId++).build();
        }

        @Override
        public AccountID newAccountId(AccountID newAccountSponsor) {
            return AccountID.newBuilder().setAccountNum(nextId++).build();
        }

        @Override
        public ContractID newContractId(AccountID newContractSponsor) {
            return ContractID.newBuilder().setContractNum(nextId++).build();
        }

        @Override
        public FileID newFileId(AccountID newFileSponsor) {
            return FileID.newBuilder().setFileNum(nextId++).build();
        }

        @Override
        public TokenID newTokenId(AccountID sponsor) {
            return TokenID.newBuilder().setTokenNum(nextId++).build();
        }

        @Override
        public ScheduleID newScheduleId(AccountID sponsor) {
            return ScheduleID.newBuilder().setScheduleNum(nextId++).build();
        }

        @Override
        public void reclaimLastId() {
            nextId--;
        }

        @Override
        public void reclaimProvisionalIds() {
        }

        @Override
        public void resetProvisionalIds() {
        }
    };
}
Also used : EntityIdSource(com.hedera.services.ledger.ids.EntityIdSource) AccountID(com.hederahashgraph.api.proto.java.AccountID) SideEffectsTracker(com.hedera.services.context.SideEffectsTracker) TopicID(com.hederahashgraph.api.proto.java.TopicID) FileID(com.hederahashgraph.api.proto.java.FileID) ContractID(com.hederahashgraph.api.proto.java.ContractID) ExpiringCreations(com.hedera.services.state.expiry.ExpiringCreations) TokenID(com.hederahashgraph.api.proto.java.TokenID) ScheduleID(com.hederahashgraph.api.proto.java.ScheduleID) AccountRecordsHistorian(com.hedera.services.records.AccountRecordsHistorian)

Example 2 with SideEffectsTracker

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

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

the class TransactionalLedgerTest method setup.

@BeforeEach
private void setup() {
    scopedCheck = new TestAccountScopedCheck();
    accountsLedger = new TransactionalLedger<>(AccountProperty.class, MerkleAccount::new, backingAccounts, new ChangeSummaryManager<>());
    final var accountsCommitInterceptor = new AccountsCommitInterceptor(new SideEffectsTracker());
    accountsLedger.setCommitInterceptor(accountsCommitInterceptor);
    subject = new TransactionalLedger<>(TestAccountProperty.class, TestAccount::new, backingTestAccounts, changeManager);
    final var testAccountCommitInterceptor = new TestAccountCommitInterceptor(new SideEffectsTracker());
    subject.setCommitInterceptor(testAccountCommitInterceptor);
}
Also used : ChangeSummaryManager(com.hedera.services.ledger.properties.ChangeSummaryManager) SideEffectsTracker(com.hedera.services.context.SideEffectsTracker) TestAccountProperty(com.hedera.services.ledger.properties.TestAccountProperty) TestAccountCommitInterceptor(com.hedera.services.ledger.properties.TestAccountCommitInterceptor) TestAccountProperty(com.hedera.services.ledger.properties.TestAccountProperty) AccountProperty(com.hedera.services.ledger.properties.AccountProperty) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with SideEffectsTracker

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

the class LedgerBalanceChangesTest method setUp.

@BeforeEach
void setUp() throws ConstructableRegistryException {
    MockitoAnnotations.initMocks(this);
    accountsLedger = new TransactionalLedger<>(AccountProperty.class, MerkleAccount::new, backingAccounts, new ChangeSummaryManager<>());
    accountsLedger.setCommitInterceptor(accountsCommitInterceptor);
    tokenRelsLedger = new TransactionalLedger<>(TokenRelProperty.class, MerkleTokenRelStatus::new, backingRels, new ChangeSummaryManager<>());
    nftsLedger = new TransactionalLedger<>(NftProperty.class, MerkleUniqueToken::new, backingNfts, new ChangeSummaryManager<>());
    nftsLedger.setCommitInterceptor(uniqueTokensCommitInterceptor);
    tokenRelsLedger.setKeyToString(BackingTokenRels::readableTokenRel);
    tokenRelsLedger.setCommitInterceptor(tokenRelsCommitInterceptor);
    backingTokens.put(tokenKey.toGrpcTokenId(), fungibleTokenWithTreasury(aModel));
    backingTokens.put(anotherTokenKey.toGrpcTokenId(), fungibleTokenWithTreasury(aModel));
    backingTokens.put(yetAnotherTokenKey.toGrpcTokenId(), fungibleTokenWithTreasury(aModel));
    backingTokens.put(aNftKey.toGrpcTokenId(), nonFungibleTokenWithTreasury(aModel));
    backingTokens.put(bNftKey.toGrpcTokenId(), nonFungibleTokenWithTreasury(bModel));
    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);
    tokenStore.rebuildViews();
    subject = new HederaLedger(tokenStore, ids, creator, validator, sideEffectsTracker, historian, dynamicProperties, accountsLedger, transferLogic, autoCreationLogic);
    subject.setMutableEntityAccess(mutableEntityAccess);
    subject.setTokenRelsLedger(tokenRelsLedger);
}
Also used : HederaTokenStore(com.hedera.services.store.tokens.HederaTokenStore) ChangeSummaryManager(com.hedera.services.ledger.properties.ChangeSummaryManager) SideEffectsTracker(com.hedera.services.context.SideEffectsTracker) NftProperty(com.hedera.services.ledger.properties.NftProperty) BackingTokenRels(com.hedera.services.ledger.backing.BackingTokenRels) HashMapBackingTokenRels(com.hedera.services.ledger.backing.HashMapBackingTokenRels) AccountProperty(com.hedera.services.ledger.properties.AccountProperty) TokenRelProperty(com.hedera.services.ledger.properties.TokenRelProperty) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with SideEffectsTracker

use of com.hedera.services.context.SideEffectsTracker 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();
}
Also used : HederaTokenStore(com.hedera.services.store.tokens.HederaTokenStore) SideEffectsTracker(com.hedera.services.context.SideEffectsTracker) HashMapBackingTokens(com.hedera.services.ledger.backing.HashMapBackingTokens) Test(org.junit.jupiter.api.Test)

Aggregations

SideEffectsTracker (com.hedera.services.context.SideEffectsTracker)5 AccountProperty (com.hedera.services.ledger.properties.AccountProperty)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 EntityIdSource (com.hedera.services.ledger.ids.EntityIdSource)2 ChangeSummaryManager (com.hedera.services.ledger.properties.ChangeSummaryManager)2 NftProperty (com.hedera.services.ledger.properties.NftProperty)2 HederaTokenStore (com.hedera.services.store.tokens.HederaTokenStore)2 AccountID (com.hederahashgraph.api.proto.java.AccountID)2 GlobalDynamicProperties (com.hedera.services.context.properties.GlobalDynamicProperties)1 HederaLedger (com.hedera.services.ledger.HederaLedger)1 TransactionalLedger (com.hedera.services.ledger.TransactionalLedger)1 BackingTokenRels (com.hedera.services.ledger.backing.BackingTokenRels)1 BackingTokens (com.hedera.services.ledger.backing.BackingTokens)1 HashMapBackingTokenRels (com.hedera.services.ledger.backing.HashMapBackingTokenRels)1 HashMapBackingTokens (com.hedera.services.ledger.backing.HashMapBackingTokens)1 TestAccountCommitInterceptor (com.hedera.services.ledger.properties.TestAccountCommitInterceptor)1 TestAccountProperty (com.hedera.services.ledger.properties.TestAccountProperty)1 TokenRelProperty (com.hedera.services.ledger.properties.TokenRelProperty)1 AccountRecordsHistorian (com.hedera.services.records.AccountRecordsHistorian)1 ExpiringCreations (com.hedera.services.state.expiry.ExpiringCreations)1