Search in sources :

Example 1 with ConstructionDeriveRequestMetadataPreparedStakes

use of com.radixdlt.api.core.openapitools.model.ConstructionDeriveRequestMetadataPreparedStakes in project radixdlt by radixdlt.

the class ConstructionDeriveHandlerTest method derive_prepared_stakes_should_return_entity_identifier.

@Test
public void derive_prepared_stakes_should_return_entity_identifier() throws CoreApiException {
    // Arrange
    var publicKey = PrivateKeys.ofNumeric(2).getPublicKey();
    var validatorKey = PrivateKeys.ofNumeric(3).getPublicKey();
    start();
    // Act
    var request = new ConstructionDeriveRequest().networkIdentifier(networkIdentifier()).publicKey(coreModelMapper.publicKey(publicKey)).metadata(new ConstructionDeriveRequestMetadataPreparedStakes().validator(coreModelMapper.entityIdentifier(validatorKey)).type("PreparedStakes"));
    var response = sut.handleRequest(request);
    // Assert
    assertThat(response.getEntityIdentifier()).isEqualTo(coreModelMapper.entityIdentifierPreparedStake(REAddr.ofPubKeyAccount(publicKey), validatorKey));
}
Also used : ConstructionDeriveRequestMetadataPreparedStakes(com.radixdlt.api.core.openapitools.model.ConstructionDeriveRequestMetadataPreparedStakes) ConstructionDeriveRequest(com.radixdlt.api.core.openapitools.model.ConstructionDeriveRequest) ApiTest(com.radixdlt.api.ApiTest) Test(org.junit.Test)

Example 2 with ConstructionDeriveRequestMetadataPreparedStakes

use of com.radixdlt.api.core.openapitools.model.ConstructionDeriveRequestMetadataPreparedStakes in project radixdlt by radixdlt.

the class ConstructionDeriveHandlerTest method derive_prepared_stakes_with_invalid_validator_should_return_error.

@Test
public void derive_prepared_stakes_with_invalid_validator_should_return_error() {
    // Arrange
    var publicKey = PrivateKeys.ofNumeric(2).getPublicKey();
    var validatorKey = PrivateKeys.ofNumeric(3).getPublicKey();
    start();
    // Act
    // Assert
    var request = new ConstructionDeriveRequest().networkIdentifier(networkIdentifier()).publicKey(coreModelMapper.publicKey(publicKey)).metadata(new ConstructionDeriveRequestMetadataPreparedStakes().validator(coreModelMapper.entityIdentifier(REAddr.ofPubKeyAccount(validatorKey))).type("PreparedStakes"));
    assertThatThrownBy(() -> sut.handleRequest(request)).isInstanceOfSatisfying(CoreApiException.class, e -> {
        assertThat(e.toError().getDetails()).isInstanceOf(NotValidatorEntityError.class);
    });
}
Also used : ConstructionDeriveRequestMetadataPreparedStakes(com.radixdlt.api.core.openapitools.model.ConstructionDeriveRequestMetadataPreparedStakes) ConstructionDeriveRequest(com.radixdlt.api.core.openapitools.model.ConstructionDeriveRequest) ApiTest(com.radixdlt.api.ApiTest) Test(org.junit.Test)

Example 3 with ConstructionDeriveRequestMetadataPreparedStakes

use of com.radixdlt.api.core.openapitools.model.ConstructionDeriveRequestMetadataPreparedStakes in project radixdlt by radixdlt.

the class StakeTokens method toOperationGroups.

@Override
public List<OperationGroup> toOperationGroups(EngineConfiguration configuration, Function<ConstructionDeriveRequestMetadata, EntityIdentifier> identifierFunction) {
    var nativeToken = configuration.getNativeToken();
    var from = identifierFunction.apply(new ConstructionDeriveRequestMetadataAccount().type("Account"));
    var to = identifierFunction.apply(new ConstructionDeriveRequestMetadataPreparedStakes().validator(validator).type("PreparedStakes"));
    var operationGroup = new OperationGroup().addOperationsItem(new Operation().type("Resource").amount(new ResourceAmount().resourceIdentifier(nativeToken).value("-" + amount.toSubunits().toString())).entityIdentifier(from)).addOperationsItem(new Operation().type("Resource").amount(new ResourceAmount().resourceIdentifier(nativeToken).value(amount.toSubunits().toString())).entityIdentifier(to));
    return List.of(operationGroup);
}
Also used : ConstructionDeriveRequestMetadataAccount(com.radixdlt.api.core.openapitools.model.ConstructionDeriveRequestMetadataAccount) ConstructionDeriveRequestMetadataPreparedStakes(com.radixdlt.api.core.openapitools.model.ConstructionDeriveRequestMetadataPreparedStakes) ResourceAmount(com.radixdlt.api.core.openapitools.model.ResourceAmount) OperationGroup(com.radixdlt.api.core.openapitools.model.OperationGroup) Operation(com.radixdlt.api.core.openapitools.model.Operation)

Aggregations

ConstructionDeriveRequestMetadataPreparedStakes (com.radixdlt.api.core.openapitools.model.ConstructionDeriveRequestMetadataPreparedStakes)3 ApiTest (com.radixdlt.api.ApiTest)2 ConstructionDeriveRequest (com.radixdlt.api.core.openapitools.model.ConstructionDeriveRequest)2 Test (org.junit.Test)2 ConstructionDeriveRequestMetadataAccount (com.radixdlt.api.core.openapitools.model.ConstructionDeriveRequestMetadataAccount)1 Operation (com.radixdlt.api.core.openapitools.model.Operation)1 OperationGroup (com.radixdlt.api.core.openapitools.model.OperationGroup)1 ResourceAmount (com.radixdlt.api.core.openapitools.model.ResourceAmount)1