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