Search in sources :

Example 1 with HFileMeta

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

the class FeeSchedulesManagerTest method setup.

@BeforeEach
private void setup() {
    attr = new HFileMeta(false, new JContractIDKey(1, 2, 3), Instant.now().getEpochSecond());
    fees = mock(FeeCalculator.class);
    subject = new FeeSchedulesManager(new MockFileNumbers(), fees);
}
Also used : FeeCalculator(com.hedera.services.fees.FeeCalculator) HFileMeta(com.hedera.services.files.HFileMeta) JContractIDKey(com.hedera.services.legacy.core.jproto.JContractIDKey) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with HFileMeta

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

the class FileAppendTransitionLogic method doStateTransition.

@Override
public void doStateTransition() {
    var op = txnCtx.accessor().getTxn().getFileAppend();
    try {
        var target = op.getFileID();
        var data = op.getContents().toByteArray();
        ResponseCodeEnum validity;
        if (fileNumbers.isSoftwareUpdateFile(target.getFileNum())) {
            validity = hfs.exists(target) ? OK : INVALID_FILE_ID;
        } else {
            Optional<HFileMeta> attr = hfs.exists(target) ? Optional.of(hfs.getattr(target)) : Optional.empty();
            validity = classify(attr);
        }
        if (validity != OK) {
            txnCtx.setStatus(validity);
            return;
        }
        if (networkCtx.get().getPreparedUpdateFileNum() == target.getFileNum()) {
            txnCtx.setStatus(PREPARED_UPDATE_FILE_IS_IMMUTABLE);
            return;
        }
        final var result = hfs.append(target, data);
        final var status = result.outcome();
        txnCtx.setStatus(status);
    } catch (IllegalArgumentException iae) {
        mapToStatus(iae, txnCtx);
    } catch (Exception unknown) {
        log.warn("Unrecognized failure handling {}!", txnCtx.accessor().getSignedTxnWrapper(), unknown);
        txnCtx.setStatus(FAIL_INVALID);
    }
}
Also used : ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) HFileMeta(com.hedera.services.files.HFileMeta)

Example 3 with HFileMeta

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

the class FileCreateTransitionLogicTest method setup.

@BeforeEach
private void setup() throws Throwable {
    hederaWacl = waclSkeleton.asJKey();
    attr = new HFileMeta(false, hederaWacl, expiry);
    accessor = mock(PlatformTxnAccessor.class);
    txnCtx = mock(TransactionContext.class);
    hfs = mock(HederaFs.class);
    sigImpactHistorian = mock(SigImpactHistorian.class);
    validator = mock(OptionValidator.class);
    given(validator.isValidAutoRenewPeriod(expectedDuration)).willReturn(true);
    given(validator.hasGoodEncoding(wacl)).willReturn(true);
    given(validator.memoCheck(any())).willReturn(OK);
    subject = new FileCreateTransitionLogic(hfs, validator, sigImpactHistorian, txnCtx);
}
Also used : PlatformTxnAccessor(com.hedera.services.utils.PlatformTxnAccessor) OptionValidator(com.hedera.services.txns.validation.OptionValidator) SigImpactHistorian(com.hedera.services.ledger.SigImpactHistorian) TransactionContext(com.hedera.services.context.TransactionContext) HFileMeta(com.hedera.services.files.HFileMeta) TieredHederaFs(com.hedera.services.files.TieredHederaFs) HederaFs(com.hedera.services.files.HederaFs) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with HFileMeta

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

the class FileUpdateTransitionLogicTest method doesntUpdateWaclIfNoNew.

@Test
void doesntUpdateWaclIfNoNew() {
    // setup:
    HederaFs.UpdateResult res = mock(HederaFs.UpdateResult.class);
    ArgumentCaptor<HFileMeta> captor = ArgumentCaptor.forClass(HFileMeta.class);
    givenTxnCtxUpdating(EnumSet.of(UpdateTarget.EXPIRY));
    // and:
    given(hfs.getattr(nonSysFileTarget)).willReturn(new HFileMeta(false, oldWacl, oldExpiry));
    given(hfs.setattr(any(), any())).willReturn(res);
    // when:
    subject.doStateTransition();
    // then:
    verify(hfs).setattr(argThat(nonSysFileTarget::equals), captor.capture());
    // and:
    assertEquals(oldAttr.getWacl().toString(), captor.getValue().getWacl().toString());
}
Also used : HFileMeta(com.hedera.services.files.HFileMeta) TieredHederaFs(com.hedera.services.files.TieredHederaFs) HederaFs(com.hedera.services.files.HederaFs) Test(org.junit.jupiter.api.Test)

Example 5 with HFileMeta

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

the class FileUpdateTransitionLogicTest method setup.

@BeforeEach
private void setup() throws Throwable {
    oldWacl = TxnHandlingScenario.SIMPLE_NEW_WACL_KT.asJKey();
    oldAttr = new HFileMeta(false, oldWacl, oldExpiry, oldMemo);
    deletedAttr = new HFileMeta(true, oldWacl, oldExpiry);
    immutableAttr = new HFileMeta(false, StateView.EMPTY_WACL, oldExpiry);
    actionableNewWacl = TxnHandlingScenario.MISC_FILE_WACL_KT.asJKey();
    newAttr = new HFileMeta(false, actionableNewWacl, newExpiry, newMemo);
    accessor = mock(PlatformTxnAccessor.class);
    txnCtx = mock(TransactionContext.class);
    given(txnCtx.activePayer()).willReturn(nonSysAdmin);
    networkCtx = mock(MerkleNetworkContext.class);
    hfs = mock(HederaFs.class);
    given(hfs.exists(nonSysFileTarget)).willReturn(true);
    given(hfs.getattr(nonSysFileTarget)).willReturn(oldAttr);
    validator = mock(OptionValidator.class);
    given(validator.isValidAutoRenewPeriod(expectedDuration)).willReturn(false);
    given(validator.hasGoodEncoding(newWacl)).willReturn(true);
    given(validator.memoCheck(newMemo)).willReturn(OK);
    sigImpactHistorian = mock(SigImpactHistorian.class);
    subject = new FileUpdateTransitionLogic(hfs, number, validator, sigImpactHistorian, txnCtx, () -> networkCtx);
}
Also used : PlatformTxnAccessor(com.hedera.services.utils.PlatformTxnAccessor) MerkleNetworkContext(com.hedera.services.state.merkle.MerkleNetworkContext) OptionValidator(com.hedera.services.txns.validation.OptionValidator) SigImpactHistorian(com.hedera.services.ledger.SigImpactHistorian) TransactionContext(com.hedera.services.context.TransactionContext) HFileMeta(com.hedera.services.files.HFileMeta) TieredHederaFs(com.hedera.services.files.TieredHederaFs) HederaFs(com.hedera.services.files.HederaFs) 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