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