Search in sources :

Example 1 with MerkleMap

use of com.swirlds.merkle.map.MerkleMap in project hedera-services by hashgraph.

the class FcBlobsBytesStoreTest method putDeletesReplacedValueIfNoCopyIsHeld.

@Test
void putDeletesReplacedValueIfNoCopyIsHeld() {
    final MerkleMap<String, MerkleOptionalBlob> blobs = new MerkleMap<>();
    blobs.put("path", new MerkleOptionalBlob("FIRST".getBytes()));
    final var replaced = blobs.put("path", new MerkleOptionalBlob("SECOND".getBytes()));
    assertTrue(replaced.getDelegate().isReleased());
}
Also used : MerkleOptionalBlob(com.hedera.services.state.merkle.MerkleOptionalBlob) MerkleMap(com.swirlds.merkle.map.MerkleMap) Test(org.junit.jupiter.api.Test)

Example 2 with MerkleMap

use of com.swirlds.merkle.map.MerkleMap in project hedera-services by hashgraph.

the class FcBlobsBytesStoreTest method putDoesNotDeleteReplacedValueIfCopyIsHeld.

@Test
void putDoesNotDeleteReplacedValueIfCopyIsHeld() {
    final MerkleMap<String, MerkleOptionalBlob> blobs = new MerkleMap<>();
    blobs.put("path", new MerkleOptionalBlob("FIRST".getBytes()));
    final var copy = blobs.copy();
    final var replaced = copy.put("path", new MerkleOptionalBlob("SECOND".getBytes()));
    assertFalse(replaced.getDelegate().isReleased());
}
Also used : MerkleOptionalBlob(com.hedera.services.state.merkle.MerkleOptionalBlob) MerkleMap(com.swirlds.merkle.map.MerkleMap) Test(org.junit.jupiter.api.Test)

Example 3 with MerkleMap

use of com.swirlds.merkle.map.MerkleMap 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 4 with MerkleMap

use of com.swirlds.merkle.map.MerkleMap in project hedera-services by hashgraph.

the class AccountsReader method from.

public static MerkleMap<EntityNum, MerkleAccount> from(String loc) throws Exception {
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(MerkleLong.class, MerkleLong::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(FCQueue.class, FCQueue::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(MerkleMap.class, MerkleMap::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(MerkleEntityId.class, MerkleEntityId::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(EntityId.class, EntityId::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(MerkleAccount.class, MerkleAccount::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(MerkleAccountState.class, MerkleAccountState::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(ExpirableTxnRecord.class, ExpirableTxnRecord::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(TxnReceipt.class, TxnReceipt::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(TxnId.class, TxnId::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(CurrencyAdjustments.class, CurrencyAdjustments::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(EvmFnResult.class, EvmFnResult::new));
    try (MerkleDataInputStream in = new MerkleDataInputStream(Files.newInputStream(Path.of(loc)))) {
        MerkleMap<EntityNum, MerkleAccount> fcm = in.readMerkleTree(Integer.MAX_VALUE);
        return fcm;
    }
}
Also used : ExpirableTxnRecord(com.hedera.services.state.submerkle.ExpirableTxnRecord) FCQueue(com.swirlds.fcqueue.FCQueue) MerkleDataInputStream(com.swirlds.common.merkle.io.MerkleDataInputStream) TxnReceipt(com.hedera.services.legacy.core.jproto.TxnReceipt) MerkleAccount(com.hedera.services.state.merkle.MerkleAccount) MerkleEntityId(com.hedera.services.state.merkle.MerkleEntityId) MerkleAccountState(com.hedera.services.state.merkle.MerkleAccountState) EntityNum(com.hedera.services.utils.EntityNum) MerkleLong(com.swirlds.common.merkle.utility.MerkleLong) EntityId(com.hedera.services.state.submerkle.EntityId) MerkleEntityId(com.hedera.services.state.merkle.MerkleEntityId) TxnId(com.hedera.services.state.submerkle.TxnId) EvmFnResult(com.hedera.services.state.submerkle.EvmFnResult) MerkleMap(com.swirlds.merkle.map.MerkleMap) CurrencyAdjustments(com.hedera.services.state.submerkle.CurrencyAdjustments) ClassConstructorPair(com.swirlds.common.constructable.ClassConstructorPair)

Example 5 with MerkleMap

use of com.swirlds.merkle.map.MerkleMap in project hedera-services by hashgraph.

the class FcmCustomFeeSchedulesTest method testObjectContract.

@Test
void testObjectContract() {
    // given:
    MerkleMap<EntityNum, MerkleToken> secondMerkleMap = new MerkleMap<>();
    MerkleToken token = new MerkleToken();
    final var missingFees = List.of(FcCustomFee.fixedFee(50L, missingToken, feeCollector).asGrpc());
    token.setFeeScheduleFrom(missingFees);
    secondMerkleMap.put(EntityNum.fromLong(missingToken.num()), new MerkleToken());
    final var fees1 = new FcmCustomFeeSchedules(() -> tokens);
    final var fees2 = new FcmCustomFeeSchedules(() -> secondMerkleMap);
    // expect:
    assertNotEquals(fees1, fees2);
    assertNotEquals(fees1.hashCode(), fees2.hashCode());
}
Also used : MerkleToken(com.hedera.services.state.merkle.MerkleToken) MerkleMap(com.swirlds.merkle.map.MerkleMap) EntityNum(com.hedera.services.utils.EntityNum) Test(org.junit.jupiter.api.Test)

Aggregations

MerkleMap (com.swirlds.merkle.map.MerkleMap)9 Test (org.junit.jupiter.api.Test)6 EntityNum (com.hedera.services.utils.EntityNum)5 MerkleAccount (com.hedera.services.state.merkle.MerkleAccount)4 MerkleToken (com.hedera.services.state.merkle.MerkleToken)3 MutableStateChildren (com.hedera.services.context.MutableStateChildren)2 AliasManager (com.hedera.services.ledger.accounts.AliasManager)2 MerkleOptionalBlob (com.hedera.services.state.merkle.MerkleOptionalBlob)2 MerkleTokenRelStatus (com.hedera.services.state.merkle.MerkleTokenRelStatus)2 EntityId (com.hedera.services.state.submerkle.EntityId)2 ScheduleStore (com.hedera.services.store.schedule.ScheduleStore)2 TokenStore (com.hedera.services.store.tokens.TokenStore)2 ClassConstructorPair (com.swirlds.common.constructable.ClassConstructorPair)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 NetworkInfo (com.hedera.services.config.NetworkInfo)1 StateView (com.hedera.services.context.primitives.StateView)1 NodeLocalProperties (com.hedera.services.context.properties.NodeLocalProperties)1 HFileMeta (com.hedera.services.files.HFileMeta)1 BackingAccounts (com.hedera.services.ledger.backing.BackingAccounts)1 TxnReceipt (com.hedera.services.legacy.core.jproto.TxnReceipt)1