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() {
}
};
}
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);
}
});
}
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);
}
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);
}
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();
}
Aggregations