Search in sources :

Example 11 with HFileMeta

use of com.hedera.services.files.HFileMeta in project hedera-services by hashgraph.

the class HfsSystemFilesManagerTest method setup.

@BeforeEach
@SuppressWarnings("unchecked")
void setup() throws DecoderException {
    masterKey = TxnHandlingScenario.COMPLEX_KEY_ACCOUNT_KT.asJKey();
    expectedInfo = new HFileMeta(false, JKey.mapKey(Key.newBuilder().setKeyList(KeyList.newBuilder().addKeys(TxnHandlingScenario.COMPLEX_KEY_ACCOUNT_KT.asKey())).build()), expiry);
    final var keyA = mock(PublicKey.class);
    given(keyA.getEncoded()).willReturn(aKeyEncoding);
    final var addressA = mock(Address.class);
    final var aIpv4 = new byte[] { (byte) 1, (byte) 2, (byte) 3, (byte) 4 };
    final var memoA = "A new memo that is not the node account ID.";
    given(addressA.getId()).willReturn(111L);
    given(addressA.getMemo()).willReturn(memoA);
    given(addressA.getAddressExternalIpv4()).willReturn(aIpv4);
    given(addressA.getSigPublicKey()).willReturn(keyA);
    final var keyB = mock(PublicKey.class);
    given(keyB.getEncoded()).willReturn(bKeyEncoding);
    final var addressB = mock(Address.class);
    final var bIpv4 = new byte[] { (byte) 2, (byte) 3, (byte) 4, (byte) 5 };
    final var memoB = "0.0.3";
    given(addressB.getId()).willReturn(222L);
    given(addressB.getMemo()).willReturn(memoB);
    given(addressB.getAddressExternalIpv4()).willReturn(bIpv4);
    given(addressB.getSigPublicKey()).willReturn(keyB);
    currentBook = mock(AddressBook.class);
    given(currentBook.getAddress(0L)).willReturn(addressA);
    given(currentBook.getAddress(1L)).willReturn(addressB);
    given(currentBook.getSize()).willReturn(2);
    data = mock(Map.class);
    metadata = mock(Map.class);
    hfs = mock(TieredHederaFs.class);
    specialFiles = mock(MerkleSpecialFiles.class);
    given(hfs.getData()).willReturn(data);
    given(hfs.getMetadata()).willReturn(metadata);
    given(hfs.specialFiles()).willReturn(specialFiles);
    fileNumbers = new MockFileNumbers();
    fileNumbers.setShard(0L);
    fileNumbers.setRealm(0L);
    given(specialFiles.contains(fileNumbers.toFid(111))).willReturn(false);
    properties = mock(PropertySource.class);
    given(properties.getStringProperty("bootstrap.hapiPermissions.path")).willReturn(bootstrapJutilPermsLoc);
    given(properties.getStringProperty("bootstrap.networkProperties.path")).willReturn(bootstrapJutilPropsLoc);
    given(properties.getLongProperty("bootstrap.system.entityExpiry")).willReturn(expiry);
    given(properties.getIntProperty("bootstrap.rates.currentHbarEquiv")).willReturn(curHbarEquiv);
    given(properties.getIntProperty("bootstrap.rates.currentCentEquiv")).willReturn(curCentEquiv);
    given(properties.getLongProperty("bootstrap.rates.currentExpiry")).willReturn(expiry);
    given(properties.getIntProperty("bootstrap.rates.nextHbarEquiv")).willReturn(nxtHbarEquiv);
    given(properties.getIntProperty("bootstrap.rates.nextCentEquiv")).willReturn(nxtCentEquiv);
    given(properties.getLongProperty("bootstrap.rates.nextExpiry")).willReturn(nextExpiry);
    given(properties.getStringProperty("bootstrap.feeSchedulesJson.resource")).willReturn("R4FeeSchedule.json");
    given(properties.getStringProperty("bootstrap.throttleDefsJson.resource")).willReturn("bootstrap/throttles.json");
    ratesCb = mock(Consumer.class);
    schedulesCb = mock(Consumer.class);
    propertiesCb = mock(Consumer.class);
    permissionsCb = mock(Consumer.class);
    throttlesCb = mock(Consumer.class);
    callbacks = mock(SysFileCallbacks.class);
    subject = new HfsSystemFilesManager(() -> currentBook, fileNumbers, properties, hfs, () -> masterKey, callbacks);
}
Also used : MerkleSpecialFiles(com.hedera.services.state.merkle.MerkleSpecialFiles) TieredHederaFs(com.hedera.services.files.TieredHederaFs) AddressBook(com.swirlds.common.AddressBook) NodeAddressBook(com.hederahashgraph.api.proto.java.NodeAddressBook) Consumer(java.util.function.Consumer) SysFileCallbacks(com.hedera.services.files.SysFileCallbacks) HFileMeta(com.hedera.services.files.HFileMeta) MockFileNumbers(com.hedera.services.files.interceptors.MockFileNumbers) Map(java.util.Map) PropertySource(com.hedera.services.context.properties.PropertySource) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 12 with HFileMeta

use of com.hedera.services.files.HFileMeta in project hedera-services by hashgraph.

the class StateViewTest method setup.

@BeforeEach
@SuppressWarnings("unchecked")
private void setup() throws Throwable {
    metadata = new HFileMeta(false, TxnHandlingScenario.MISC_FILE_WACL_KT.asJKey(), expiry, fileMemo);
    immutableMetadata = new HFileMeta(false, StateView.EMPTY_WACL, expiry);
    expectedImmutable = FileGetInfoResponse.FileInfo.newBuilder().setLedgerId(ledgerId).setDeleted(false).setExpirationTime(Timestamp.newBuilder().setSeconds(expiry)).setFileID(target).setSize(data.length).build();
    expected = expectedImmutable.toBuilder().setKeys(TxnHandlingScenario.MISC_FILE_WACL_KT.asKey().getKeyList()).setMemo(fileMemo).build();
    tokenAccount = MerkleAccountFactory.newAccount().isSmartContract(false).tokens(tokenId).get();
    tokenAccount.setNftsOwned(10);
    tokenAccount.setMaxAutomaticAssociations(123);
    tokenAccount.setAlias(TxnHandlingScenario.TOKEN_ADMIN_KT.asKey().getEd25519());
    contract = MerkleAccountFactory.newAccount().alias(create2Address).memo("Stay cold...").numKvPairs(wellKnownNumKvPairs).isSmartContract(true).accountKeys(COMPLEX_KEY_ACCOUNT_KT).proxy(asAccount("0.0.3")).senderThreshold(1_234L).receiverThreshold(4_321L).receiverSigRequired(true).balance(555L).autoRenewPeriod(1_000_000L).deleted(true).expirationTime(9_999_999L).get();
    contracts = (MerkleMap<EntityNum, MerkleAccount>) mock(MerkleMap.class);
    topics = (MerkleMap<EntityNum, MerkleTopic>) mock(MerkleMap.class);
    tokenRels = new MerkleMap<>();
    tokenRels.put(EntityNumPair.fromLongs(tokenAccountId.getAccountNum(), tokenId.getTokenNum()), new MerkleTokenRelStatus(123L, false, true, true));
    tokenStore = mock(TokenStore.class);
    token = new MerkleToken(Long.MAX_VALUE, 100, 1, "UnfrozenToken", "UnfrozenTokenName", true, true, new EntityId(0, 0, 3));
    token.setMemo(tokenMemo);
    token.setAdminKey(TxnHandlingScenario.TOKEN_ADMIN_KT.asJKey());
    token.setFreezeKey(TxnHandlingScenario.TOKEN_FREEZE_KT.asJKey());
    token.setKycKey(TxnHandlingScenario.TOKEN_KYC_KT.asJKey());
    token.setSupplyKey(COMPLEX_KEY_ACCOUNT_KT.asJKey());
    token.setWipeKey(MISC_ACCOUNT_KT.asJKey());
    token.setFeeScheduleKey(MISC_ACCOUNT_KT.asJKey());
    token.setPauseKey(TxnHandlingScenario.TOKEN_PAUSE_KT.asJKey());
    token.setAutoRenewAccount(EntityId.fromGrpcAccountId(autoRenew));
    token.setExpiry(expiry);
    token.setAutoRenewPeriod(autoRenewPeriod);
    token.setDeleted(true);
    token.setPaused(true);
    token.setTokenType(TokenType.FUNGIBLE_COMMON);
    token.setSupplyType(TokenSupplyType.FINITE);
    token.setFeeScheduleFrom(grpcCustomFees);
    scheduleStore = mock(ScheduleStore.class);
    final var scheduleMemo = "For what but eye and ear";
    parentScheduleCreate = scheduleCreateTxnWith(SCHEDULE_ADMIN_KT.asKey(), scheduleMemo, payerAccountId, creatorAccountID, MiscUtils.asTimestamp(now.toJava()));
    schedule = MerkleSchedule.from(parentScheduleCreate.toByteArray(), expiry);
    schedule.witnessValidSignature("01234567890123456789012345678901".getBytes());
    schedule.witnessValidSignature("_123456789_123456789_123456789_1".getBytes());
    schedule.witnessValidSignature("_o23456789_o23456789_o23456789_o".getBytes());
    contents = mock(Map.class);
    attrs = mock(Map.class);
    bytecode = mock(Map.class);
    specialFiles = mock(MerkleSpecialFiles.class);
    mockTokenRelsFn = (BiFunction<StateView, EntityNum, List<TokenRelationship>>) mock(BiFunction.class);
    StateView.tokenRelsFn = mockTokenRelsFn;
    final var uniqueTokens = new MerkleMap<EntityNumPair, MerkleUniqueToken>();
    uniqueTokens.put(targetNftKey, targetNft);
    uniqueTokens.put(treasuryNftKey, treasuryNft);
    storage = (VirtualMap<VirtualBlobKey, VirtualBlobValue>) mock(VirtualMap.class);
    contractStorage = (VirtualMap<ContractKey, ContractValue>) mock(VirtualMap.class);
    children = new MutableStateChildren();
    children.setUniqueTokens(uniqueTokens);
    children.setAccounts(contracts);
    children.setTokenAssociations(tokenRels);
    children.setSpecialFiles(specialFiles);
    networkInfo = mock(NetworkInfo.class);
    subject = new StateView(tokenStore, scheduleStore, children, networkInfo);
    subject.fileAttrs = attrs;
    subject.fileContents = contents;
    subject.contractBytecode = bytecode;
}
Also used : NetworkInfo(com.hedera.services.config.NetworkInfo) MerkleToken(com.hedera.services.state.merkle.MerkleToken) MerkleAccount(com.hedera.services.state.merkle.MerkleAccount) MerkleTopic(com.hedera.services.state.merkle.MerkleTopic) EntityNum(com.hedera.services.utils.EntityNum) MerkleTokenRelStatus(com.hedera.services.state.merkle.MerkleTokenRelStatus) EntityId(com.hedera.services.state.submerkle.EntityId) MerkleSpecialFiles(com.hedera.services.state.merkle.MerkleSpecialFiles) ContractValue(com.hedera.services.state.virtual.ContractValue) MutableStateChildren(com.hedera.services.context.MutableStateChildren) ContractKey(com.hedera.services.state.virtual.ContractKey) HFileMeta(com.hedera.services.files.HFileMeta) MerkleMap(com.swirlds.merkle.map.MerkleMap) VirtualBlobValue(com.hedera.services.state.virtual.VirtualBlobValue) KeyList(com.hederahashgraph.api.proto.java.KeyList) List(java.util.List) TokenStore(com.hedera.services.store.tokens.TokenStore) ScheduleStore(com.hedera.services.store.schedule.ScheduleStore) Map(java.util.Map) VirtualMap(com.swirlds.virtualmap.VirtualMap) MerkleMap(com.swirlds.merkle.map.MerkleMap) VirtualBlobKey(com.hedera.services.state.virtual.VirtualBlobKey) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 13 with HFileMeta

use of com.hedera.services.files.HFileMeta in project hedera-services by hashgraph.

the class StateChildrenSigMetadataLookupTest method givenFile.

private void givenFile(final FileID fid, final boolean isDeleted, final long expiry, final JKey wacl) throws IOException {
    final var meta = new HFileMeta(isDeleted, wacl, expiry);
    final var num = EntityNum.fromLong(fid.getFileNum());
    given(storage.get(new VirtualBlobKey(VirtualBlobKey.Type.FILE_METADATA, num.intValue()))).willReturn(new VirtualBlobValue(meta.serialize()));
}
Also used : HFileMeta(com.hedera.services.files.HFileMeta) VirtualBlobValue(com.hedera.services.state.virtual.VirtualBlobValue) VirtualBlobKey(com.hedera.services.state.virtual.VirtualBlobKey)

Example 14 with HFileMeta

use of com.hedera.services.files.HFileMeta in project hedera-services by hashgraph.

the class ContextOptionValidatorTest method setup.

@BeforeEach
private void setup() throws Exception {
    txnCtx = mock(TransactionContext.class);
    given(txnCtx.consensusTime()).willReturn(now);
    accounts = mock(MerkleMap.class);
    given(accounts.get(EntityNum.fromAccountId(a))).willReturn(aV);
    given(accounts.get(EntityNum.fromAccountId(deleted))).willReturn(deletedV);
    given(accounts.get(fromContractId(contract))).willReturn(contractV);
    given(accounts.get(fromContractId(deletedContract))).willReturn(deletedContractV);
    dynamicProperties = mock(GlobalDynamicProperties.class);
    given(dynamicProperties.maxMemoUtf8Bytes()).willReturn(100);
    properties = mock(PropertySource.class);
    given(properties.getLongProperty("entities.maxLifetime")).willReturn(maxLifetime);
    topics = mock(MerkleMap.class);
    deletedMerkleTopic = TopicFactory.newTopic().deleted(true).get();
    expiredMerkleTopic = TopicFactory.newTopic().expiry(now.minusSeconds(555L).getEpochSecond()).get();
    merkleTopic = TopicFactory.newTopic().memo("Hi, over here!").expiry(now.plusSeconds(555L).getEpochSecond()).get();
    given(topics.get(EntityNum.fromTopicId(topicId))).willReturn(merkleTopic);
    given(topics.get(EntityNum.fromTopicId(missingTopicId))).willReturn(null);
    given(topics.get(EntityNum.fromTopicId(deletedTopicId))).willReturn(deletedMerkleTopic);
    given(topics.get(EntityNum.fromTopicId(expiredTopicId))).willReturn(expiredMerkleTopic);
    NodeInfo nodeInfo = mock(NodeInfo.class);
    given(nodeInfo.selfAccount()).willReturn(thisNodeAccount);
    wacl = TxnHandlingScenario.SIMPLE_NEW_WACL_KT.asJKey();
    attr = new HFileMeta(false, wacl, expiry);
    deletedAttr = new HFileMeta(true, wacl, expiry);
    view = mock(StateView.class);
    subject = new ContextOptionValidator(nodeInfo, properties, txnCtx, dynamicProperties);
}
Also used : TransactionContext(com.hedera.services.context.TransactionContext) NodeInfo(com.hedera.services.context.NodeInfo) HFileMeta(com.hedera.services.files.HFileMeta) MerkleMap(com.swirlds.merkle.map.MerkleMap) StateView(com.hedera.services.context.primitives.StateView) GlobalDynamicProperties(com.hedera.services.context.properties.GlobalDynamicProperties) PropertySource(com.hedera.services.context.properties.PropertySource) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

HFileMeta (com.hedera.services.files.HFileMeta)14 BeforeEach (org.junit.jupiter.api.BeforeEach)11 TransactionContext (com.hedera.services.context.TransactionContext)7 HederaFs (com.hedera.services.files.HederaFs)6 PlatformTxnAccessor (com.hedera.services.utils.PlatformTxnAccessor)6 TieredHederaFs (com.hedera.services.files.TieredHederaFs)5 SigImpactHistorian (com.hedera.services.ledger.SigImpactHistorian)4 Map (java.util.Map)4 PropertySource (com.hedera.services.context.properties.PropertySource)3 JContractIDKey (com.hedera.services.legacy.core.jproto.JContractIDKey)3 Consumer (java.util.function.Consumer)3 GlobalDynamicProperties (com.hedera.services.context.properties.GlobalDynamicProperties)2 MerkleNetworkContext (com.hedera.services.state.merkle.MerkleNetworkContext)2 MerkleSpecialFiles (com.hedera.services.state.merkle.MerkleSpecialFiles)2 VirtualBlobKey (com.hedera.services.state.virtual.VirtualBlobKey)2 VirtualBlobValue (com.hedera.services.state.virtual.VirtualBlobValue)2 OptionValidator (com.hedera.services.txns.validation.OptionValidator)2 MerkleMap (com.swirlds.merkle.map.MerkleMap)2 MockAccountNumbers (com.hedera.services.config.MockAccountNumbers)1 NetworkInfo (com.hedera.services.config.NetworkInfo)1