Search in sources :

Example 1 with ConstructionDeriveRequestMetadataToken

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

the class ConstructionDeriveHandlerTest method invalid_public_key_should_throw_exception.

@Test
public void invalid_public_key_should_throw_exception() {
    // Arrange
    start();
    // Act
    // Assert
    var request = new ConstructionDeriveRequest().networkIdentifier(new NetworkIdentifier().network("localnet")).publicKey(new PublicKey().hex("deadbeaddeadbead")).metadata(new ConstructionDeriveRequestMetadataToken().symbol("test").type("Token"));
    assertThatThrownBy(() -> sut.handleRequest(request)).isInstanceOfSatisfying(CoreApiException.class, e -> {
        var error = e.toError();
        assertThat(error.getDetails()).isInstanceOf(InvalidPublicKeyError.class);
        assertThat(error.getCode()).isEqualTo(CoreApiErrorCode.BAD_REQUEST.getErrorCode());
    });
}
Also used : PublicKey(com.radixdlt.api.core.openapitools.model.PublicKey) NetworkIdentifier(com.radixdlt.api.core.openapitools.model.NetworkIdentifier) ConstructionDeriveRequest(com.radixdlt.api.core.openapitools.model.ConstructionDeriveRequest) ConstructionDeriveRequestMetadataToken(com.radixdlt.api.core.openapitools.model.ConstructionDeriveRequestMetadataToken) ApiTest(com.radixdlt.api.ApiTest) Test(org.junit.Test)

Example 2 with ConstructionDeriveRequestMetadataToken

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

the class CreateTokenDefinition method toOperationGroups.

@Override
public List<OperationGroup> toOperationGroups(EngineConfiguration configuration, Function<ConstructionDeriveRequestMetadata, EntityIdentifier> identifierFunction) {
    var entityIdentifier = identifierFunction.apply(new ConstructionDeriveRequestMetadataToken().symbol(symbol).type("Token"));
    var mintOperation = new Operation().type("Resource").amount(new ResourceAmount().value(amount.toString()).resourceIdentifier(new TokenResourceIdentifier().rri(entityIdentifier.getAddress()).type("Token"))).entityIdentifier(to);
    var createTokenGroup = new OperationGroup();
    createTokenGroup.addOperationsItem(new Operation().type("Data").data(new Data().action(Data.ActionEnum.CREATE).dataObject(new TokenData().isMutable(owner != null).granularity("1").owner(owner).type(PreparedValidatorRegistered.class.getSimpleName()))).entityIdentifier(entityIdentifier));
    if (owner == null) {
        createTokenGroup.addOperationsItem(mintOperation);
    }
    createTokenGroup.addOperationsItem(new Operation().type("Data").data(new Data().action(Data.ActionEnum.CREATE).dataObject(new TokenMetadata().symbol(symbol).name("some_name").description("some_description").url("").iconUrl(""))).entityIdentifier(entityIdentifier));
    if (owner == null) {
        return List.of(createTokenGroup);
    }
    var mintTokenGroup = new OperationGroup().addOperationsItem(mintOperation);
    return List.of(createTokenGroup, mintTokenGroup);
}
Also used : ResourceAmount(com.radixdlt.api.core.openapitools.model.ResourceAmount) OperationGroup(com.radixdlt.api.core.openapitools.model.OperationGroup) TokenResourceIdentifier(com.radixdlt.api.core.openapitools.model.TokenResourceIdentifier) Data(com.radixdlt.api.core.openapitools.model.Data) TokenData(com.radixdlt.api.core.openapitools.model.TokenData) TokenData(com.radixdlt.api.core.openapitools.model.TokenData) Operation(com.radixdlt.api.core.openapitools.model.Operation) PreparedValidatorRegistered(com.radixdlt.api.core.openapitools.model.PreparedValidatorRegistered) ConstructionDeriveRequestMetadataToken(com.radixdlt.api.core.openapitools.model.ConstructionDeriveRequestMetadataToken) TokenMetadata(com.radixdlt.api.core.openapitools.model.TokenMetadata)

Example 3 with ConstructionDeriveRequestMetadataToken

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

the class ConstructionDeriveHandlerTest method derive_token_request_should_return_token_entity_identifier.

@Test
public void derive_token_request_should_return_token_entity_identifier() throws CoreApiException {
    // Arrange
    var publicKey = PrivateKeys.ofNumeric(2).getPublicKey();
    start();
    // Act
    var request = new ConstructionDeriveRequest().networkIdentifier(networkIdentifier()).publicKey(coreModelMapper.publicKey(publicKey)).metadata(new ConstructionDeriveRequestMetadataToken().symbol("test").type("Token"));
    var response = sut.handleRequest(request);
    // Assert
    assertThat(response.getEntityIdentifier()).isEqualTo(coreModelMapper.entityIdentifier(REAddr.ofHashedKey(publicKey, "test"), "test"));
}
Also used : ConstructionDeriveRequest(com.radixdlt.api.core.openapitools.model.ConstructionDeriveRequest) ConstructionDeriveRequestMetadataToken(com.radixdlt.api.core.openapitools.model.ConstructionDeriveRequestMetadataToken) ApiTest(com.radixdlt.api.ApiTest) Test(org.junit.Test)

Aggregations

ConstructionDeriveRequestMetadataToken (com.radixdlt.api.core.openapitools.model.ConstructionDeriveRequestMetadataToken)3 ApiTest (com.radixdlt.api.ApiTest)2 ConstructionDeriveRequest (com.radixdlt.api.core.openapitools.model.ConstructionDeriveRequest)2 Test (org.junit.Test)2 Data (com.radixdlt.api.core.openapitools.model.Data)1 NetworkIdentifier (com.radixdlt.api.core.openapitools.model.NetworkIdentifier)1 Operation (com.radixdlt.api.core.openapitools.model.Operation)1 OperationGroup (com.radixdlt.api.core.openapitools.model.OperationGroup)1 PreparedValidatorRegistered (com.radixdlt.api.core.openapitools.model.PreparedValidatorRegistered)1 PublicKey (com.radixdlt.api.core.openapitools.model.PublicKey)1 ResourceAmount (com.radixdlt.api.core.openapitools.model.ResourceAmount)1 TokenData (com.radixdlt.api.core.openapitools.model.TokenData)1 TokenMetadata (com.radixdlt.api.core.openapitools.model.TokenMetadata)1 TokenResourceIdentifier (com.radixdlt.api.core.openapitools.model.TokenResourceIdentifier)1