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