use of com.radixdlt.constraintmachine.exceptions.InvalidPermissionException in project radixdlt by radixdlt.
the class RadixEngineStateComputerTest method preparing_system_update_from_vertex_should_fail.
@Test
public void preparing_system_update_from_vertex_should_fail() throws TxBuilderException {
// Arrange
var txn = radixEngine.construct(new NextRound(1, false, 0, i -> proposerElection.getProposer(View.of(i)).getKey())).buildWithoutSignature();
var illegalTxn = TxLowLevelBuilder.newBuilder(currentForkView.currentForkConfig().engineRules().serialization()).down(SubstateId.ofSubstate(txn.getId(), 1)).up(new RoundData(2, 0)).end().build();
var v = UnverifiedVertex.create(mock(QuorumCertificate.class), View.of(1), List.of(illegalTxn), proposerElection.getProposer(View.of(1)));
var vertex = new VerifiedVertex(v, mock(HashCode.class));
// Act
var result = sut.prepare(ImmutableList.of(), vertex, 0);
// Assert
assertThat(result.getSuccessfulCommands()).hasSize(1);
assertThat(result.getFailedCommands()).hasValueSatisfying(new Condition<>(e -> {
var ex = (RadixEngineException) e;
var cmException = (ConstraintMachineException) ex.getCause();
return cmException.getCause() instanceof InvalidPermissionException;
}, "Is invalid_execution_permission error"));
}
use of com.radixdlt.constraintmachine.exceptions.InvalidPermissionException in project radixdlt by radixdlt.
the class ConstraintMachine method callProcedure.
/**
* Executes a transition procedure given the next spun particle and a current validation state.
*/
private ReducerState callProcedure(Procedure procedure, Object procedureParam, ReducerState reducerState, Resources immutableAddrs, ExecutionContext context) throws SignedSystemException, InvalidPermissionException, AuthorizationException, MeterException, ProcedureException {
// System permissions don't require additional authorization
var authorization = procedure.authorization(procedureParam);
var requiredLevel = authorization.permissionLevel();
context.verifyPermissionLevel(requiredLevel);
if (context.permissionLevel() != PermissionLevel.SYSTEM) {
try {
if (requiredLevel == PermissionLevel.USER) {
this.meter.onUserProcedure(procedure.key(), procedureParam, context);
} else if (requiredLevel == PermissionLevel.SUPER_USER) {
this.meter.onSuperUserProcedure(procedure.key(), procedureParam, context);
}
} catch (Exception e) {
throw new MeterException(e);
}
if (!context.skipAuthorization()) {
try {
authorization.authorizer().verify(immutableAddrs, context);
} catch (Exception e) {
throw new AuthorizationException(e);
}
}
}
return procedure.call(procedureParam, reducerState, immutableAddrs, context).state();
}
Aggregations