Search in sources :

Example 1 with SimpleUpdateResult

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

the class FileUpdateTransitionLogicTest method allowsSysAdminToUpdateImmutableSysFile.

@Test
void allowsSysAdminToUpdateImmutableSysFile() {
    givenTxnCtxUpdating(EnumSet.of(UpdateTarget.CONTENTS), sysFileTarget);
    given(txnCtx.activePayer()).willReturn(sysAdmin);
    // and:
    given(hfs.exists(sysFileTarget)).willReturn(true);
    given(hfs.getattr(sysFileTarget)).willReturn(immutableAttr);
    // and:
    given(hfs.overwrite(any(), any())).willReturn(new SimpleUpdateResult(false, true, SUCCESS));
    given(hfs.setattr(any(), any())).willReturn(new SimpleUpdateResult(true, false, SUCCESS));
    // when:
    subject.doStateTransition();
    // then:
    verify(hfs).overwrite(argThat(sysFileTarget::equals), argThat(bytes -> Arrays.equals(newContents, bytes)));
    verify(txnCtx).setStatus(SUCCESS);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) OK(com.hederahashgraph.api.proto.java.ResponseCodeEnum.OK) Arrays(java.util.Arrays) HFileMeta(com.hedera.services.files.HFileMeta) BDDMockito.inOrder(org.mockito.BDDMockito.inOrder) StringValue(com.google.protobuf.StringValue) Duration(com.hederahashgraph.api.proto.java.Duration) BDDMockito.verify(org.mockito.BDDMockito.verify) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) BDDMockito.given(org.mockito.BDDMockito.given) PlatformTxnAccessor(com.hedera.services.utils.PlatformTxnAccessor) EnumSet(java.util.EnumSet) BDDMockito.willThrow(org.mockito.BDDMockito.willThrow) DecoderException(org.apache.commons.codec.DecoderException) BDDMockito.never(org.mockito.BDDMockito.never) SigImpactHistorian(com.hedera.services.ledger.SigImpactHistorian) Instant(java.time.Instant) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) OptionValidator(com.hedera.services.txns.validation.OptionValidator) ByteString(com.google.protobuf.ByteString) Test(org.junit.jupiter.api.Test) MiscUtils(com.hedera.services.utils.MiscUtils) JKey(com.hedera.services.legacy.core.jproto.JKey) AUTORENEW_DURATION_NOT_IN_RANGE(com.hederahashgraph.api.proto.java.ResponseCodeEnum.AUTORENEW_DURATION_NOT_IN_RANGE) INVALID_FILE_ID(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_FILE_ID) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) UNAUTHORIZED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.UNAUTHORIZED) EntityNumbers(com.hedera.services.config.EntityNumbers) INVALID_EXPIRATION_TIME(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_EXPIRATION_TIME) StateView(com.hedera.services.context.primitives.StateView) TieredHederaFs(com.hedera.services.files.TieredHederaFs) AUTHORIZATION_FAILED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.AUTHORIZATION_FAILED) TransactionContext(com.hedera.services.context.TransactionContext) MerkleNetworkContext(com.hedera.services.state.merkle.MerkleNetworkContext) BDDMockito.any(org.mockito.BDDMockito.any) ArgumentCaptor(org.mockito.ArgumentCaptor) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) FILE_DELETED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.FILE_DELETED) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) AccountID(com.hederahashgraph.api.proto.java.AccountID) TxnHandlingScenario(com.hedera.test.factories.scenarios.TxnHandlingScenario) Timestamp(com.hederahashgraph.api.proto.java.Timestamp) PREPARED_UPDATE_FILE_IS_IMMUTABLE(com.hederahashgraph.api.proto.java.ResponseCodeEnum.PREPARED_UPDATE_FILE_IS_IMMUTABLE) FileUpdateTransactionBody(com.hederahashgraph.api.proto.java.FileUpdateTransactionBody) MAX_FILE_SIZE_EXCEEDED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.MAX_FILE_SIZE_EXCEEDED) FileID(com.hederahashgraph.api.proto.java.FileID) InOrder(org.mockito.InOrder) MockEntityNumbers(com.hedera.services.config.MockEntityNumbers) INVALID_ZERO_BYTE_IN_STRING(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_ZERO_BYTE_IN_STRING) TransactionID(com.hederahashgraph.api.proto.java.TransactionID) FAIL_INVALID(com.hederahashgraph.api.proto.java.ResponseCodeEnum.FAIL_INVALID) HederaFs(com.hedera.services.files.HederaFs) IdUtils(com.hedera.test.utils.IdUtils) Key(com.hederahashgraph.api.proto.java.Key) SimpleUpdateResult(com.hedera.services.files.SimpleUpdateResult) BAD_ENCODING(com.hederahashgraph.api.proto.java.ResponseCodeEnum.BAD_ENCODING) BDDMockito.argThat(org.mockito.BDDMockito.argThat) BDDMockito.mock(org.mockito.BDDMockito.mock) SimpleUpdateResult(com.hedera.services.files.SimpleUpdateResult) Test(org.junit.jupiter.api.Test)

Example 2 with SimpleUpdateResult

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

the class FileUpdateTransitionLogicTest method allowsUpdatingExpirationOnly.

@Test
void allowsUpdatingExpirationOnly() {
    givenTxnCtxUpdating(EnumSet.of(UpdateTarget.EXPIRY));
    // and:
    given(hfs.setattr(any(), any())).willReturn(new SimpleUpdateResult(true, false, SUCCESS));
    given(hfs.getattr(nonSysFileTarget)).willReturn(immutableAttr);
    // when:
    subject.doStateTransition();
    // then:
    verify(hfs, never()).overwrite(any(), any());
    // and:
    verify(txnCtx).setStatus(SUCCESS);
}
Also used : SimpleUpdateResult(com.hedera.services.files.SimpleUpdateResult) Test(org.junit.jupiter.api.Test)

Example 3 with SimpleUpdateResult

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

the class FileUpdateTransitionLogicTest method doesntAllowSysAdminToUpdateImmutableNonSysFile.

@Test
void doesntAllowSysAdminToUpdateImmutableNonSysFile() {
    givenTxnCtxUpdating(EnumSet.of(UpdateTarget.CONTENTS), nonSysFileTarget);
    given(txnCtx.activePayer()).willReturn(sysAdmin);
    // and:
    given(hfs.exists(nonSysFileTarget)).willReturn(true);
    given(hfs.getattr(nonSysFileTarget)).willReturn(immutableAttr);
    // and:
    given(hfs.overwrite(any(), any())).willReturn(new SimpleUpdateResult(false, true, SUCCESS));
    given(hfs.setattr(any(), any())).willReturn(new SimpleUpdateResult(true, false, SUCCESS));
    // when:
    subject.doStateTransition();
    // then:
    verify(hfs, never()).overwrite(argThat(nonSysFileTarget::equals), argThat(bytes -> Arrays.equals(newContents, bytes)));
    verify(txnCtx).setStatus(UNAUTHORIZED);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) OK(com.hederahashgraph.api.proto.java.ResponseCodeEnum.OK) Arrays(java.util.Arrays) HFileMeta(com.hedera.services.files.HFileMeta) BDDMockito.inOrder(org.mockito.BDDMockito.inOrder) StringValue(com.google.protobuf.StringValue) Duration(com.hederahashgraph.api.proto.java.Duration) BDDMockito.verify(org.mockito.BDDMockito.verify) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) BDDMockito.given(org.mockito.BDDMockito.given) PlatformTxnAccessor(com.hedera.services.utils.PlatformTxnAccessor) EnumSet(java.util.EnumSet) BDDMockito.willThrow(org.mockito.BDDMockito.willThrow) DecoderException(org.apache.commons.codec.DecoderException) BDDMockito.never(org.mockito.BDDMockito.never) SigImpactHistorian(com.hedera.services.ledger.SigImpactHistorian) Instant(java.time.Instant) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) OptionValidator(com.hedera.services.txns.validation.OptionValidator) ByteString(com.google.protobuf.ByteString) Test(org.junit.jupiter.api.Test) MiscUtils(com.hedera.services.utils.MiscUtils) JKey(com.hedera.services.legacy.core.jproto.JKey) AUTORENEW_DURATION_NOT_IN_RANGE(com.hederahashgraph.api.proto.java.ResponseCodeEnum.AUTORENEW_DURATION_NOT_IN_RANGE) INVALID_FILE_ID(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_FILE_ID) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) UNAUTHORIZED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.UNAUTHORIZED) EntityNumbers(com.hedera.services.config.EntityNumbers) INVALID_EXPIRATION_TIME(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_EXPIRATION_TIME) StateView(com.hedera.services.context.primitives.StateView) TieredHederaFs(com.hedera.services.files.TieredHederaFs) AUTHORIZATION_FAILED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.AUTHORIZATION_FAILED) TransactionContext(com.hedera.services.context.TransactionContext) MerkleNetworkContext(com.hedera.services.state.merkle.MerkleNetworkContext) BDDMockito.any(org.mockito.BDDMockito.any) ArgumentCaptor(org.mockito.ArgumentCaptor) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) FILE_DELETED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.FILE_DELETED) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) AccountID(com.hederahashgraph.api.proto.java.AccountID) TxnHandlingScenario(com.hedera.test.factories.scenarios.TxnHandlingScenario) Timestamp(com.hederahashgraph.api.proto.java.Timestamp) PREPARED_UPDATE_FILE_IS_IMMUTABLE(com.hederahashgraph.api.proto.java.ResponseCodeEnum.PREPARED_UPDATE_FILE_IS_IMMUTABLE) FileUpdateTransactionBody(com.hederahashgraph.api.proto.java.FileUpdateTransactionBody) MAX_FILE_SIZE_EXCEEDED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.MAX_FILE_SIZE_EXCEEDED) FileID(com.hederahashgraph.api.proto.java.FileID) InOrder(org.mockito.InOrder) MockEntityNumbers(com.hedera.services.config.MockEntityNumbers) INVALID_ZERO_BYTE_IN_STRING(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_ZERO_BYTE_IN_STRING) TransactionID(com.hederahashgraph.api.proto.java.TransactionID) FAIL_INVALID(com.hederahashgraph.api.proto.java.ResponseCodeEnum.FAIL_INVALID) HederaFs(com.hedera.services.files.HederaFs) IdUtils(com.hedera.test.utils.IdUtils) Key(com.hederahashgraph.api.proto.java.Key) SimpleUpdateResult(com.hedera.services.files.SimpleUpdateResult) BAD_ENCODING(com.hederahashgraph.api.proto.java.ResponseCodeEnum.BAD_ENCODING) BDDMockito.argThat(org.mockito.BDDMockito.argThat) BDDMockito.mock(org.mockito.BDDMockito.mock) SimpleUpdateResult(com.hedera.services.files.SimpleUpdateResult) Test(org.junit.jupiter.api.Test)

Example 4 with SimpleUpdateResult

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

the class FileUpdateTransitionLogicTest method happyPathFlows.

@Test
void happyPathFlows() {
    // setup:
    InOrder inOrder = inOrder(hfs, txnCtx, sigImpactHistorian);
    givenTxnCtxUpdating(EnumSet.allOf(UpdateTarget.class));
    // and:
    given(hfs.overwrite(any(), any())).willReturn(new SimpleUpdateResult(false, true, SUCCESS));
    given(hfs.setattr(any(), any())).willReturn(new SimpleUpdateResult(true, false, SUCCESS));
    given(hfs.getattr(nonSysFileTarget)).willReturn(oldAttr);
    // when:
    subject.doStateTransition();
    // then:
    inOrder.verify(hfs).overwrite(argThat(nonSysFileTarget::equals), argThat(bytes -> Arrays.equals(newContents, bytes)));
    inOrder.verify(hfs).setattr(argThat(nonSysFileTarget::equals), argThat(attr -> newAttr.toString().equals(attr.toString())));
    inOrder.verify(txnCtx).setStatus(SUCCESS);
    inOrder.verify(sigImpactHistorian).markEntityChanged(nonSysFileTarget.getFileNum());
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) OK(com.hederahashgraph.api.proto.java.ResponseCodeEnum.OK) Arrays(java.util.Arrays) HFileMeta(com.hedera.services.files.HFileMeta) BDDMockito.inOrder(org.mockito.BDDMockito.inOrder) StringValue(com.google.protobuf.StringValue) Duration(com.hederahashgraph.api.proto.java.Duration) BDDMockito.verify(org.mockito.BDDMockito.verify) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) BDDMockito.given(org.mockito.BDDMockito.given) PlatformTxnAccessor(com.hedera.services.utils.PlatformTxnAccessor) EnumSet(java.util.EnumSet) BDDMockito.willThrow(org.mockito.BDDMockito.willThrow) DecoderException(org.apache.commons.codec.DecoderException) BDDMockito.never(org.mockito.BDDMockito.never) SigImpactHistorian(com.hedera.services.ledger.SigImpactHistorian) Instant(java.time.Instant) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) OptionValidator(com.hedera.services.txns.validation.OptionValidator) ByteString(com.google.protobuf.ByteString) Test(org.junit.jupiter.api.Test) MiscUtils(com.hedera.services.utils.MiscUtils) JKey(com.hedera.services.legacy.core.jproto.JKey) AUTORENEW_DURATION_NOT_IN_RANGE(com.hederahashgraph.api.proto.java.ResponseCodeEnum.AUTORENEW_DURATION_NOT_IN_RANGE) INVALID_FILE_ID(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_FILE_ID) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) UNAUTHORIZED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.UNAUTHORIZED) EntityNumbers(com.hedera.services.config.EntityNumbers) INVALID_EXPIRATION_TIME(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_EXPIRATION_TIME) StateView(com.hedera.services.context.primitives.StateView) TieredHederaFs(com.hedera.services.files.TieredHederaFs) AUTHORIZATION_FAILED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.AUTHORIZATION_FAILED) TransactionContext(com.hedera.services.context.TransactionContext) MerkleNetworkContext(com.hedera.services.state.merkle.MerkleNetworkContext) BDDMockito.any(org.mockito.BDDMockito.any) ArgumentCaptor(org.mockito.ArgumentCaptor) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) FILE_DELETED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.FILE_DELETED) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) AccountID(com.hederahashgraph.api.proto.java.AccountID) TxnHandlingScenario(com.hedera.test.factories.scenarios.TxnHandlingScenario) Timestamp(com.hederahashgraph.api.proto.java.Timestamp) PREPARED_UPDATE_FILE_IS_IMMUTABLE(com.hederahashgraph.api.proto.java.ResponseCodeEnum.PREPARED_UPDATE_FILE_IS_IMMUTABLE) FileUpdateTransactionBody(com.hederahashgraph.api.proto.java.FileUpdateTransactionBody) MAX_FILE_SIZE_EXCEEDED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.MAX_FILE_SIZE_EXCEEDED) FileID(com.hederahashgraph.api.proto.java.FileID) InOrder(org.mockito.InOrder) MockEntityNumbers(com.hedera.services.config.MockEntityNumbers) INVALID_ZERO_BYTE_IN_STRING(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_ZERO_BYTE_IN_STRING) TransactionID(com.hederahashgraph.api.proto.java.TransactionID) FAIL_INVALID(com.hederahashgraph.api.proto.java.ResponseCodeEnum.FAIL_INVALID) HederaFs(com.hedera.services.files.HederaFs) IdUtils(com.hedera.test.utils.IdUtils) Key(com.hederahashgraph.api.proto.java.Key) SimpleUpdateResult(com.hedera.services.files.SimpleUpdateResult) BAD_ENCODING(com.hederahashgraph.api.proto.java.ResponseCodeEnum.BAD_ENCODING) BDDMockito.argThat(org.mockito.BDDMockito.argThat) BDDMockito.mock(org.mockito.BDDMockito.mock) InOrder(org.mockito.InOrder) SimpleUpdateResult(com.hedera.services.files.SimpleUpdateResult) Test(org.junit.jupiter.api.Test)

Example 5 with SimpleUpdateResult

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

the class FileUpdateTransitionLogicTest method shortCircuitsOnFailedOverwrite.

@Test
void shortCircuitsOnFailedOverwrite() {
    givenTxnCtxUpdating(EnumSet.allOf(UpdateTarget.class));
    // and:
    given(hfs.getattr(nonSysFileTarget)).willReturn(oldAttr);
    given(hfs.overwrite(any(), any())).willReturn(new SimpleUpdateResult(false, false, AUTHORIZATION_FAILED));
    // when:
    subject.doStateTransition();
    // then:
    verify(hfs, never()).setattr(any(), any());
    verify(txnCtx).setStatus(AUTHORIZATION_FAILED);
}
Also used : SimpleUpdateResult(com.hedera.services.files.SimpleUpdateResult) Test(org.junit.jupiter.api.Test)

Aggregations

SimpleUpdateResult (com.hedera.services.files.SimpleUpdateResult)5 Test (org.junit.jupiter.api.Test)5 ByteString (com.google.protobuf.ByteString)3 StringValue (com.google.protobuf.StringValue)3 EntityNumbers (com.hedera.services.config.EntityNumbers)3 MockEntityNumbers (com.hedera.services.config.MockEntityNumbers)3 TransactionContext (com.hedera.services.context.TransactionContext)3 StateView (com.hedera.services.context.primitives.StateView)3 HFileMeta (com.hedera.services.files.HFileMeta)3 HederaFs (com.hedera.services.files.HederaFs)3 TieredHederaFs (com.hedera.services.files.TieredHederaFs)3 SigImpactHistorian (com.hedera.services.ledger.SigImpactHistorian)3 JKey (com.hedera.services.legacy.core.jproto.JKey)3 MerkleNetworkContext (com.hedera.services.state.merkle.MerkleNetworkContext)3 OptionValidator (com.hedera.services.txns.validation.OptionValidator)3 MiscUtils (com.hedera.services.utils.MiscUtils)3 PlatformTxnAccessor (com.hedera.services.utils.PlatformTxnAccessor)3 TxnHandlingScenario (com.hedera.test.factories.scenarios.TxnHandlingScenario)3 IdUtils (com.hedera.test.utils.IdUtils)3 AccountID (com.hederahashgraph.api.proto.java.AccountID)3