From 6e9d1a4857936fb63cda037dab47c7d16bc9786a Mon Sep 17 00:00:00 2001 From: ashalaginov Date: Fri, 8 Dec 2023 16:34:51 +0000 Subject: [PATCH] [WTCH-191] Add AliasService --- .../client/blocking/alias/AliasService.kt | 10 +++ .../lb/LoadBalancingServiceFactory.kt | 44 ++++++----- .../node/NodeBlockingServiceFactory.kt | 12 +-- .../sdk/node/domain/Address.kt | 3 + .../wavesenterprise/sdk/node/domain/Alias.kt | 5 ++ .../sdk/node/exception/NodeErrorCode.kt | 3 +- ...Exception.kt => AliasNotExistException.kt} | 2 +- .../specific/DataKeyNotExistException.kt | 10 +++ .../specific/SpecificExceptionMapper.kt | 6 +- .../AddressGrpcBlockingService.kt | 2 +- .../alias/AliasGrpcBlockingService.kt | 16 ++++ .../contract/ContractGrpcBlockingService.kt | 4 +- .../factory/GrpcNodeServiceFactory.kt | 37 +++++---- .../grpc/blocking/GrpcNodeErrorMapperTest.kt | 6 +- .../ContractGrpcBlockingServiceTest.kt | 2 +- .../feign/address/FeignAddressService.kt | 7 +- .../feign/address/WeAddressServiceApiFeign.kt | 2 +- .../client/feign/alias/FeignAliasService.kt | 23 ++++++ .../feign/alias/WeAliasServiceApiFeign.kt | 14 ++++ .../feign/contract/FeignContractService.kt | 4 +- .../feign/factory/FeignNodeServiceFactory.kt | 76 +++++++++++-------- .../client/feign/FeignNodeErrorMapperTest.kt | 6 +- .../feign/address/FeignAddressServiceTest.kt | 7 +- .../address/WeAddressServiceApiFeignTest.kt | 13 +++- .../feign/alias/FeignAliasServiceTest.kt | 68 +++++++++++++++++ .../feign/alias/WeAliasServiceApiFeignTest.kt | 68 +++++++++++++++++ .../contract/FeignContractServiceTest.kt | 4 +- .../mappings/address/address_value_404.json | 16 ++++ .../mappings/alias/address_by_alias_200.json | 15 ++++ .../mappings/alias/address_by_alias_404.json | 16 ++++ .../alias/aliases_by_address_200.json | 16 ++++ .../client/http/{address => }/AddressDto.kt | 5 +- 32 files changed, 419 insertions(+), 103 deletions(-) create mode 100644 we-node-client-blocking-client/src/main/kotlin/com/wavesenterprise/sdk/node/client/blocking/alias/AliasService.kt rename we-node-client-error/src/main/kotlin/com/wavesenterprise/sdk/node/exception/specific/{DataKeyNotExistsException.kt => AliasNotExistException.kt} (91%) create mode 100644 we-node-client-error/src/main/kotlin/com/wavesenterprise/sdk/node/exception/specific/DataKeyNotExistException.kt rename we-node-client-grpc/we-node-client-grpc-blocking-client/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/blocking/{node => address}/AddressGrpcBlockingService.kt (95%) create mode 100644 we-node-client-grpc/we-node-client-grpc-blocking-client/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/blocking/alias/AliasGrpcBlockingService.kt create mode 100644 we-node-client-http/we-node-client-feign-client/src/main/kotlin/com/wavesenterprise/sdk/node/client/feign/alias/FeignAliasService.kt create mode 100644 we-node-client-http/we-node-client-feign-client/src/main/kotlin/com/wavesenterprise/sdk/node/client/feign/alias/WeAliasServiceApiFeign.kt create mode 100644 we-node-client-http/we-node-client-feign-client/src/test/kotlin/com/wavesenterprise/sdk/node/client/feign/alias/FeignAliasServiceTest.kt create mode 100644 we-node-client-http/we-node-client-feign-client/src/test/kotlin/com/wavesenterprise/sdk/node/client/feign/alias/WeAliasServiceApiFeignTest.kt create mode 100644 we-node-client-http/we-node-client-feign-client/src/test/resources/mappings/address/address_value_404.json create mode 100644 we-node-client-http/we-node-client-feign-client/src/test/resources/mappings/alias/address_by_alias_200.json create mode 100644 we-node-client-http/we-node-client-feign-client/src/test/resources/mappings/alias/address_by_alias_404.json create mode 100644 we-node-client-http/we-node-client-feign-client/src/test/resources/mappings/alias/aliases_by_address_200.json rename we-node-client-json/src/main/kotlin/com/wavesenterprise/sdk/node/client/http/{address => }/AddressDto.kt (69%) diff --git a/we-node-client-blocking-client/src/main/kotlin/com/wavesenterprise/sdk/node/client/blocking/alias/AliasService.kt b/we-node-client-blocking-client/src/main/kotlin/com/wavesenterprise/sdk/node/client/blocking/alias/AliasService.kt new file mode 100644 index 00000000..624e08a9 --- /dev/null +++ b/we-node-client-blocking-client/src/main/kotlin/com/wavesenterprise/sdk/node/client/blocking/alias/AliasService.kt @@ -0,0 +1,10 @@ +package com.wavesenterprise.sdk.node.client.blocking.alias + +import com.wavesenterprise.sdk.node.domain.Address +import com.wavesenterprise.sdk.node.domain.Alias +import java.util.Optional + +interface AliasService { + fun getAliasesByAddress(address: Address): List + fun getAddressByAlias(alias: Alias): Optional
+} diff --git a/we-node-client-blocking-client/src/main/kotlin/com/wavesenterprise/sdk/node/client/blocking/lb/LoadBalancingServiceFactory.kt b/we-node-client-blocking-client/src/main/kotlin/com/wavesenterprise/sdk/node/client/blocking/lb/LoadBalancingServiceFactory.kt index 1ad91e3c..1bd74736 100644 --- a/we-node-client-blocking-client/src/main/kotlin/com/wavesenterprise/sdk/node/client/blocking/lb/LoadBalancingServiceFactory.kt +++ b/we-node-client-blocking-client/src/main/kotlin/com/wavesenterprise/sdk/node/client/blocking/lb/LoadBalancingServiceFactory.kt @@ -1,6 +1,7 @@ package com.wavesenterprise.sdk.node.client.blocking.lb import com.wavesenterprise.sdk.node.client.blocking.address.AddressService +import com.wavesenterprise.sdk.node.client.blocking.alias.AliasService import com.wavesenterprise.sdk.node.client.blocking.blocks.BlocksService import com.wavesenterprise.sdk.node.client.blocking.contract.ContractService import com.wavesenterprise.sdk.node.client.blocking.event.BlockchainEventsService @@ -20,29 +21,19 @@ class LoadBalancingServiceFactory( private val privacyDataNodesCacheLoadBalancerPostInvokeHandler: PrivacyDataNodesCacheLoadBalancerPostInvokeHandler, ) : NodeBlockingServiceFactory { - override fun txService() = - createService(TxService::class.java) { - it.txService() - } - - override fun contractService(): ContractService = - createService(ContractService::class.java) { - it.contractService() - } - override fun addressService(): AddressService = createService(AddressService::class.java) { it.addressService() } - override fun nodeInfoService(): NodeInfoService = - createService(NodeInfoService::class.java) { - it.nodeInfoService() + override fun aliasService(): AliasService = + createService(AliasService::class.java) { + it.aliasService() } - override fun privacyService(): PrivacyService = - createService(PrivacyService::class.java) { - it.privacyService() + override fun blockchainEventsService(): BlockchainEventsService = + createService(BlockchainEventsService::class.java) { + it.blockchainEventsService() } override fun blocksService(): BlocksService = @@ -50,9 +41,14 @@ class LoadBalancingServiceFactory( it.blocksService() } - override fun blockchainEventsService(): BlockchainEventsService = - createService(BlockchainEventsService::class.java) { - it.blockchainEventsService() + override fun contractService(): ContractService = + createService(ContractService::class.java) { + it.contractService() + } + + override fun nodeInfoService(): NodeInfoService = + createService(NodeInfoService::class.java) { + it.nodeInfoService() } override fun nodeUtilsService(): NodeUtilsService = @@ -65,6 +61,16 @@ class LoadBalancingServiceFactory( it.pkiService() } + override fun privacyService(): PrivacyService = + createService(PrivacyService::class.java) { + it.privacyService() + } + + override fun txService() = + createService(TxService::class.java) { + it.txService() + } + @Suppress("UNCHECKED_CAST") private fun createService( clazz: Class, diff --git a/we-node-client-blocking-client/src/main/kotlin/com/wavesenterprise/sdk/node/client/blocking/node/NodeBlockingServiceFactory.kt b/we-node-client-blocking-client/src/main/kotlin/com/wavesenterprise/sdk/node/client/blocking/node/NodeBlockingServiceFactory.kt index 61321e25..9a12e5e2 100644 --- a/we-node-client-blocking-client/src/main/kotlin/com/wavesenterprise/sdk/node/client/blocking/node/NodeBlockingServiceFactory.kt +++ b/we-node-client-blocking-client/src/main/kotlin/com/wavesenterprise/sdk/node/client/blocking/node/NodeBlockingServiceFactory.kt @@ -1,6 +1,7 @@ package com.wavesenterprise.sdk.node.client.blocking.node import com.wavesenterprise.sdk.node.client.blocking.address.AddressService +import com.wavesenterprise.sdk.node.client.blocking.alias.AliasService import com.wavesenterprise.sdk.node.client.blocking.blocks.BlocksService import com.wavesenterprise.sdk.node.client.blocking.contract.ContractService import com.wavesenterprise.sdk.node.client.blocking.event.BlockchainEventsService @@ -10,13 +11,14 @@ import com.wavesenterprise.sdk.node.client.blocking.tx.TxService import com.wavesenterprise.sdk.node.client.blocking.util.NodeUtilsService interface NodeBlockingServiceFactory { - fun txService(): TxService - fun contractService(): ContractService fun addressService(): AddressService - fun nodeInfoService(): NodeInfoService - fun privacyService(): PrivacyService - fun blocksService(): BlocksService + fun aliasService(): AliasService fun blockchainEventsService(): BlockchainEventsService + fun blocksService(): BlocksService + fun contractService(): ContractService + fun nodeInfoService(): NodeInfoService fun nodeUtilsService(): NodeUtilsService fun pkiService(): PkiService + fun privacyService(): PrivacyService + fun txService(): TxService } diff --git a/we-node-client-domain/src/main/kotlin/com/wavesenterprise/sdk/node/domain/Address.kt b/we-node-client-domain/src/main/kotlin/com/wavesenterprise/sdk/node/domain/Address.kt index ded03f10..44861554 100644 --- a/we-node-client-domain/src/main/kotlin/com/wavesenterprise/sdk/node/domain/Address.kt +++ b/we-node-client-domain/src/main/kotlin/com/wavesenterprise/sdk/node/domain/Address.kt @@ -20,6 +20,9 @@ data class Address(val bytes: ByteArray) { WeBase58.decode(string) ) + @JvmStatic + fun String.toDomain(): Address = Address.fromBase58(this) + inline val ByteArray.address: Address get() = Address(this) inline val String.base58Address: Address get() = fromBase58(this) diff --git a/we-node-client-domain/src/main/kotlin/com/wavesenterprise/sdk/node/domain/Alias.kt b/we-node-client-domain/src/main/kotlin/com/wavesenterprise/sdk/node/domain/Alias.kt index 90de4bd9..4c6320aa 100644 --- a/we-node-client-domain/src/main/kotlin/com/wavesenterprise/sdk/node/domain/Alias.kt +++ b/we-node-client-domain/src/main/kotlin/com/wavesenterprise/sdk/node/domain/Alias.kt @@ -6,6 +6,11 @@ data class Alias(val value: String) { fun fromString(str: String): Alias = Alias(str) + @JvmStatic + fun String.toDomain(): Alias = fromString(this.substring(ALIAS_START_INDEX)) + + private const val ALIAS_START_INDEX = 8 + inline val String.alias: Alias get() = Alias(this) } } diff --git a/we-node-client-error/src/main/kotlin/com/wavesenterprise/sdk/node/exception/NodeErrorCode.kt b/we-node-client-error/src/main/kotlin/com/wavesenterprise/sdk/node/exception/NodeErrorCode.kt index 51f1e8ee..78034f46 100644 --- a/we-node-client-error/src/main/kotlin/com/wavesenterprise/sdk/node/exception/NodeErrorCode.kt +++ b/we-node-client-error/src/main/kotlin/com/wavesenterprise/sdk/node/exception/NodeErrorCode.kt @@ -7,7 +7,8 @@ enum class NodeErrorCode(val code: Int) { INVALID_PUBLIC_KEY(108), INVALID_PASSWORD(115), CUSTOM_VALIDATION_ERROR(199), - DATA_KEY_NOT_EXISTS(304), + ALIAS_NOT_EXIST(302), + DATA_KEY_NOT_EXIST(304), CONTRACT_NOT_FOUND(600), POLICY_DOES_NOT_EXIST(612), PRIVACY_API_KEY_NOT_VALID(614), diff --git a/we-node-client-error/src/main/kotlin/com/wavesenterprise/sdk/node/exception/specific/DataKeyNotExistsException.kt b/we-node-client-error/src/main/kotlin/com/wavesenterprise/sdk/node/exception/specific/AliasNotExistException.kt similarity index 91% rename from we-node-client-error/src/main/kotlin/com/wavesenterprise/sdk/node/exception/specific/DataKeyNotExistsException.kt rename to we-node-client-error/src/main/kotlin/com/wavesenterprise/sdk/node/exception/specific/AliasNotExistException.kt index 4929cc75..75dd060d 100644 --- a/we-node-client-error/src/main/kotlin/com/wavesenterprise/sdk/node/exception/specific/DataKeyNotExistsException.kt +++ b/we-node-client-error/src/main/kotlin/com/wavesenterprise/sdk/node/exception/specific/AliasNotExistException.kt @@ -4,7 +4,7 @@ import com.wavesenterprise.sdk.node.exception.NodeError import com.wavesenterprise.sdk.node.exception.NodeErrorInfoHolder import com.wavesenterprise.sdk.node.exception.NodeException -class DataKeyNotExistsException( +class AliasNotExistException( override val nodeError: NodeError, override val cause: Exception, ) : NodeException(cause), NodeErrorInfoHolder diff --git a/we-node-client-error/src/main/kotlin/com/wavesenterprise/sdk/node/exception/specific/DataKeyNotExistException.kt b/we-node-client-error/src/main/kotlin/com/wavesenterprise/sdk/node/exception/specific/DataKeyNotExistException.kt new file mode 100644 index 00000000..857287bc --- /dev/null +++ b/we-node-client-error/src/main/kotlin/com/wavesenterprise/sdk/node/exception/specific/DataKeyNotExistException.kt @@ -0,0 +1,10 @@ +package com.wavesenterprise.sdk.node.exception.specific + +import com.wavesenterprise.sdk.node.exception.NodeError +import com.wavesenterprise.sdk.node.exception.NodeErrorInfoHolder +import com.wavesenterprise.sdk.node.exception.NodeException + +class DataKeyNotExistException( + override val nodeError: NodeError, + override val cause: Exception, +) : NodeException(cause), NodeErrorInfoHolder diff --git a/we-node-client-error/src/main/kotlin/com/wavesenterprise/sdk/node/exception/specific/SpecificExceptionMapper.kt b/we-node-client-error/src/main/kotlin/com/wavesenterprise/sdk/node/exception/specific/SpecificExceptionMapper.kt index 4684726a..19647995 100644 --- a/we-node-client-error/src/main/kotlin/com/wavesenterprise/sdk/node/exception/specific/SpecificExceptionMapper.kt +++ b/we-node-client-error/src/main/kotlin/com/wavesenterprise/sdk/node/exception/specific/SpecificExceptionMapper.kt @@ -2,9 +2,10 @@ package com.wavesenterprise.sdk.node.exception.specific import com.wavesenterprise.sdk.node.exception.NodeError import com.wavesenterprise.sdk.node.exception.NodeErrorCode +import com.wavesenterprise.sdk.node.exception.NodeErrorCode.ALIAS_NOT_EXIST import com.wavesenterprise.sdk.node.exception.NodeErrorCode.CONTRACT_NOT_FOUND import com.wavesenterprise.sdk.node.exception.NodeErrorCode.CUSTOM_VALIDATION_ERROR -import com.wavesenterprise.sdk.node.exception.NodeErrorCode.DATA_KEY_NOT_EXISTS +import com.wavesenterprise.sdk.node.exception.NodeErrorCode.DATA_KEY_NOT_EXIST import com.wavesenterprise.sdk.node.exception.NodeErrorCode.INVALID_ADDRESS import com.wavesenterprise.sdk.node.exception.NodeErrorCode.INVALID_PASSWORD import com.wavesenterprise.sdk.node.exception.NodeErrorCode.INVALID_PUBLIC_KEY @@ -26,7 +27,8 @@ object SpecificExceptionMapper { INVALID_PUBLIC_KEY -> InvalidPublicKeyException(nodeError, cause = exception) INVALID_PASSWORD -> InvalidPasswordException(nodeError, cause = exception) CUSTOM_VALIDATION_ERROR -> CustomValidationErrorException(nodeError, cause = exception) - DATA_KEY_NOT_EXISTS -> DataKeyNotExistsException(nodeError, cause = exception) + ALIAS_NOT_EXIST -> AliasNotExistException(nodeError, exception) + DATA_KEY_NOT_EXIST -> DataKeyNotExistException(nodeError, cause = exception) CONTRACT_NOT_FOUND -> ContractNotFoundException(nodeError, cause = exception) POLICY_DOES_NOT_EXIST -> PolicyDoesNotExistException(nodeError, cause = exception) PRIVACY_API_KEY_NOT_VALID -> PrivacyApiKeyNotValidException(nodeError, cause = exception) diff --git a/we-node-client-grpc/we-node-client-grpc-blocking-client/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/blocking/node/AddressGrpcBlockingService.kt b/we-node-client-grpc/we-node-client-grpc-blocking-client/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/blocking/address/AddressGrpcBlockingService.kt similarity index 95% rename from we-node-client-grpc/we-node-client-grpc-blocking-client/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/blocking/node/AddressGrpcBlockingService.kt rename to we-node-client-grpc/we-node-client-grpc-blocking-client/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/blocking/address/AddressGrpcBlockingService.kt index 8272a838..23e7876d 100644 --- a/we-node-client-grpc/we-node-client-grpc-blocking-client/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/blocking/node/AddressGrpcBlockingService.kt +++ b/we-node-client-grpc/we-node-client-grpc-blocking-client/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/blocking/address/AddressGrpcBlockingService.kt @@ -1,4 +1,4 @@ -package com.wavesenterprise.sdk.node.client.grpc.blocking.node +package com.wavesenterprise.sdk.node.client.grpc.blocking.address import com.wavesenterprise.sdk.node.client.blocking.address.AddressService import com.wavesenterprise.sdk.node.domain.Address diff --git a/we-node-client-grpc/we-node-client-grpc-blocking-client/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/blocking/alias/AliasGrpcBlockingService.kt b/we-node-client-grpc/we-node-client-grpc-blocking-client/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/blocking/alias/AliasGrpcBlockingService.kt new file mode 100644 index 00000000..3efac605 --- /dev/null +++ b/we-node-client-grpc/we-node-client-grpc-blocking-client/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/blocking/alias/AliasGrpcBlockingService.kt @@ -0,0 +1,16 @@ +package com.wavesenterprise.sdk.node.client.grpc.blocking.alias + +import com.wavesenterprise.sdk.node.client.blocking.alias.AliasService +import com.wavesenterprise.sdk.node.domain.Address +import com.wavesenterprise.sdk.node.domain.Alias +import java.util.Optional + +class AliasGrpcBlockingService : AliasService { + override fun getAliasesByAddress(address: Address): List { + TODO("Not yet implemented") + } + + override fun getAddressByAlias(alias: Alias): Optional
{ + TODO("Not yet implemented") + } +} diff --git a/we-node-client-grpc/we-node-client-grpc-blocking-client/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/blocking/contract/ContractGrpcBlockingService.kt b/we-node-client-grpc/we-node-client-grpc-blocking-client/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/blocking/contract/ContractGrpcBlockingService.kt index 612b1f0f..ede35c33 100644 --- a/we-node-client-grpc/we-node-client-grpc-blocking-client/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/blocking/contract/ContractGrpcBlockingService.kt +++ b/we-node-client-grpc/we-node-client-grpc-blocking-client/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/blocking/contract/ContractGrpcBlockingService.kt @@ -21,7 +21,7 @@ import com.wavesenterprise.sdk.node.domain.contract.ExecutionErrorRequest import com.wavesenterprise.sdk.node.domain.contract.ExecutionSuccessRequest import com.wavesenterprise.sdk.node.domain.contract.keys.ContractKeyRequest import com.wavesenterprise.sdk.node.domain.contract.keys.ContractKeysRequest -import com.wavesenterprise.sdk.node.exception.specific.DataKeyNotExistsException +import com.wavesenterprise.sdk.node.exception.specific.DataKeyNotExistException import io.grpc.Channel import io.grpc.ClientInterceptor import io.grpc.Status @@ -68,7 +68,7 @@ class ContractGrpcBlockingService( null else { when (val mappedException = GrpcNodeErrorMapper.mapToGeneralException(ex)) { - is DataKeyNotExistsException -> null + is DataKeyNotExistException -> null else -> throw mappedException } } diff --git a/we-node-client-grpc/we-node-client-grpc-blocking-client/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/blocking/factory/GrpcNodeServiceFactory.kt b/we-node-client-grpc/we-node-client-grpc-blocking-client/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/blocking/factory/GrpcNodeServiceFactory.kt index 9b595db3..ba12e54f 100644 --- a/we-node-client-grpc/we-node-client-grpc-blocking-client/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/blocking/factory/GrpcNodeServiceFactory.kt +++ b/we-node-client-grpc/we-node-client-grpc-blocking-client/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/blocking/factory/GrpcNodeServiceFactory.kt @@ -3,6 +3,7 @@ package com.wavesenterprise.sdk.node.client.grpc.blocking.factory import com.wavesenterprise.protobuf.service.contract.ContractServiceGrpc import com.wavesenterprise.protobuf.service.messagebroker.BlockchainEventsServiceGrpc import com.wavesenterprise.sdk.node.client.blocking.address.AddressService +import com.wavesenterprise.sdk.node.client.blocking.alias.AliasService import com.wavesenterprise.sdk.node.client.blocking.blocks.BlocksService import com.wavesenterprise.sdk.node.client.blocking.contract.ContractService import com.wavesenterprise.sdk.node.client.blocking.event.BlockchainEventsService @@ -23,10 +24,22 @@ class GrpcNodeServiceFactory( private val channel: Channel, ) : NodeBlockingServiceFactory { - override fun txService(): TxService { - return TxGrpcBlockingService( + override fun addressService(): AddressService { + TODO("Not yet implemented") + } + + override fun aliasService(): AliasService { + TODO("Not yet implemented") + } + + override fun blockchainEventsService(): BlockchainEventsService = + BlockchainEventsGrpcBlockingService( channel = channel, + grpc = BlockchainEventsServiceGrpc.newBlockingStub(channel), ) + + override fun blocksService(): BlocksService { + TODO("Not yet implemented") } override fun contractService(): ContractService { @@ -38,33 +51,25 @@ class GrpcNodeServiceFactory( ) } - override fun addressService(): AddressService { + override fun nodeInfoService(): NodeInfoService { TODO("Not yet implemented") } - override fun nodeInfoService(): NodeInfoService { + override fun nodeUtilsService(): NodeUtilsService { TODO("Not yet implemented") } - override fun privacyService(): PrivacyService { + override fun pkiService(): PkiService { TODO("Not yet implemented") } - override fun blocksService(): BlocksService { + override fun privacyService(): PrivacyService { TODO("Not yet implemented") } - override fun blockchainEventsService(): BlockchainEventsService = - BlockchainEventsGrpcBlockingService( + override fun txService(): TxService { + return TxGrpcBlockingService( channel = channel, - grpc = BlockchainEventsServiceGrpc.newBlockingStub(channel), ) - - override fun nodeUtilsService(): NodeUtilsService { - TODO("Not yet implemented") - } - - override fun pkiService(): PkiService { - TODO("Not yet implemented") } } diff --git a/we-node-client-grpc/we-node-client-grpc-blocking-client/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/blocking/GrpcNodeErrorMapperTest.kt b/we-node-client-grpc/we-node-client-grpc-blocking-client/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/blocking/GrpcNodeErrorMapperTest.kt index edbfa498..13d0eabe 100644 --- a/we-node-client-grpc/we-node-client-grpc-blocking-client/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/blocking/GrpcNodeErrorMapperTest.kt +++ b/we-node-client-grpc/we-node-client-grpc-blocking-client/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/blocking/GrpcNodeErrorMapperTest.kt @@ -6,7 +6,7 @@ import com.wavesenterprise.sdk.node.exception.NodeError import com.wavesenterprise.sdk.node.exception.NodeException import com.wavesenterprise.sdk.node.exception.specific.ContractNotFoundException import com.wavesenterprise.sdk.node.exception.specific.CustomValidationErrorException -import com.wavesenterprise.sdk.node.exception.specific.DataKeyNotExistsException +import com.wavesenterprise.sdk.node.exception.specific.DataKeyNotExistException import com.wavesenterprise.sdk.node.exception.specific.InvalidAddressException import com.wavesenterprise.sdk.node.exception.specific.InvalidSignatureException import com.wavesenterprise.sdk.node.exception.specific.PolicyDoesNotExistException @@ -106,8 +106,8 @@ internal class GrpcNodeErrorMapperTest { } returns expectedNodeError.message val ex = GrpcNodeErrorMapper.mapToGeneralException(statusRuntimeException) ex.apply { - assertTrue(this is DataKeyNotExistsException).let { - (this as DataKeyNotExistsException).apply { + assertTrue(this is DataKeyNotExistException).let { + (this as DataKeyNotExistException).apply { assertEquals(expectedNodeError.error, nodeError.error) assertEquals(expectedNodeError.message, nodeError.message) } diff --git a/we-node-client-grpc/we-node-client-grpc-blocking-client/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/blocking/contract/ContractGrpcBlockingServiceTest.kt b/we-node-client-grpc/we-node-client-grpc-blocking-client/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/blocking/contract/ContractGrpcBlockingServiceTest.kt index 9aa4892c..9d30a479 100644 --- a/we-node-client-grpc/we-node-client-grpc-blocking-client/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/blocking/contract/ContractGrpcBlockingServiceTest.kt +++ b/we-node-client-grpc/we-node-client-grpc-blocking-client/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/blocking/contract/ContractGrpcBlockingServiceTest.kt @@ -35,7 +35,7 @@ internal class ContractGrpcBlockingServiceTest { StatusRuntimeException(status, metadata) every { metadata.get(Metadata.Key.of("error-code", Metadata.ASCII_STRING_MARSHALLER)) - } returns NodeErrorCode.DATA_KEY_NOT_EXISTS.code.toString() + } returns NodeErrorCode.DATA_KEY_NOT_EXIST.code.toString() every { metadata.get( Metadata.Key.of("error-message", Metadata.ASCII_STRING_MARSHALLER) diff --git a/we-node-client-http/we-node-client-feign-client/src/main/kotlin/com/wavesenterprise/sdk/node/client/feign/address/FeignAddressService.kt b/we-node-client-http/we-node-client-feign-client/src/main/kotlin/com/wavesenterprise/sdk/node/client/feign/address/FeignAddressService.kt index 9af14138..4b2acab7 100644 --- a/we-node-client-http/we-node-client-feign-client/src/main/kotlin/com/wavesenterprise/sdk/node/client/feign/address/FeignAddressService.kt +++ b/we-node-client-http/we-node-client-feign-client/src/main/kotlin/com/wavesenterprise/sdk/node/client/feign/address/FeignAddressService.kt @@ -1,13 +1,14 @@ package com.wavesenterprise.sdk.node.client.feign.address import com.wavesenterprise.sdk.node.client.blocking.address.AddressService +import com.wavesenterprise.sdk.node.client.http.AddressDto.Companion.toDomain import com.wavesenterprise.sdk.node.client.http.DataEntryDto.Companion.toDomain -import com.wavesenterprise.sdk.node.client.http.address.AddressDto.Companion.toDomain import com.wavesenterprise.sdk.node.client.http.address.SignMessageRequestDto.Companion.toDto import com.wavesenterprise.sdk.node.client.http.address.SignMessageResponseDto.Companion.toDomain import com.wavesenterprise.sdk.node.client.http.address.VerifyMessageSignatureRequestDto.Companion.toDto import com.wavesenterprise.sdk.node.client.http.address.VerifyMessageSignatureResponseDto.Companion.toDomain import com.wavesenterprise.sdk.node.domain.Address +import com.wavesenterprise.sdk.node.domain.Address.Companion.toDomain import com.wavesenterprise.sdk.node.domain.DataEntry import com.wavesenterprise.sdk.node.domain.DataKey import com.wavesenterprise.sdk.node.domain.PublicKey @@ -15,7 +16,7 @@ import com.wavesenterprise.sdk.node.domain.address.SignMessageRequest import com.wavesenterprise.sdk.node.domain.address.SignMessageResponse import com.wavesenterprise.sdk.node.domain.address.VerifyMessageSignatureRequest import com.wavesenterprise.sdk.node.domain.address.VerifyMessageSignatureResponse -import com.wavesenterprise.sdk.node.exception.specific.DataKeyNotExistsException +import com.wavesenterprise.sdk.node.exception.specific.DataKeyNotExistException import java.util.Optional class FeignAddressService( @@ -33,7 +34,7 @@ class FeignAddressService( address = address.asBase58String(), key = key.value, ).map { it.toDomain() } - } catch (ex: DataKeyNotExistsException) { + } catch (ex: DataKeyNotExistException) { Optional.empty() } diff --git a/we-node-client-http/we-node-client-feign-client/src/main/kotlin/com/wavesenterprise/sdk/node/client/feign/address/WeAddressServiceApiFeign.kt b/we-node-client-http/we-node-client-feign-client/src/main/kotlin/com/wavesenterprise/sdk/node/client/feign/address/WeAddressServiceApiFeign.kt index 52b90a70..829338e1 100644 --- a/we-node-client-http/we-node-client-feign-client/src/main/kotlin/com/wavesenterprise/sdk/node/client/feign/address/WeAddressServiceApiFeign.kt +++ b/we-node-client-http/we-node-client-feign-client/src/main/kotlin/com/wavesenterprise/sdk/node/client/feign/address/WeAddressServiceApiFeign.kt @@ -1,7 +1,7 @@ package com.wavesenterprise.sdk.node.client.feign.address +import com.wavesenterprise.sdk.node.client.http.AddressDto import com.wavesenterprise.sdk.node.client.http.DataEntryDto -import com.wavesenterprise.sdk.node.client.http.address.AddressDto import com.wavesenterprise.sdk.node.client.http.address.SignMessageRequestDto import com.wavesenterprise.sdk.node.client.http.address.SignMessageResponseDto import com.wavesenterprise.sdk.node.client.http.address.VerifyMessageSignatureRequestDto diff --git a/we-node-client-http/we-node-client-feign-client/src/main/kotlin/com/wavesenterprise/sdk/node/client/feign/alias/FeignAliasService.kt b/we-node-client-http/we-node-client-feign-client/src/main/kotlin/com/wavesenterprise/sdk/node/client/feign/alias/FeignAliasService.kt new file mode 100644 index 00000000..ebe1eecf --- /dev/null +++ b/we-node-client-http/we-node-client-feign-client/src/main/kotlin/com/wavesenterprise/sdk/node/client/feign/alias/FeignAliasService.kt @@ -0,0 +1,23 @@ +package com.wavesenterprise.sdk.node.client.feign.alias + +import com.wavesenterprise.sdk.node.client.blocking.alias.AliasService +import com.wavesenterprise.sdk.node.client.http.AddressDto.Companion.toDomain +import com.wavesenterprise.sdk.node.domain.Address +import com.wavesenterprise.sdk.node.domain.Alias +import com.wavesenterprise.sdk.node.domain.Alias.Companion.toDomain +import com.wavesenterprise.sdk.node.exception.specific.AliasNotExistException +import java.util.Optional + +class FeignAliasService( + private val weAliasServiceApiFeign: WeAliasServiceApiFeign +) : AliasService { + override fun getAliasesByAddress(address: Address): List = + weAliasServiceApiFeign.getAliasesByAddress(address.asBase58String()).map { it.toDomain() } + + override fun getAddressByAlias(alias: Alias): Optional
= + try { + weAliasServiceApiFeign.getAddressByAlias(alias.value).map { it.toDomain() } + } catch (ex: AliasNotExistException) { + Optional.empty() + } +} diff --git a/we-node-client-http/we-node-client-feign-client/src/main/kotlin/com/wavesenterprise/sdk/node/client/feign/alias/WeAliasServiceApiFeign.kt b/we-node-client-http/we-node-client-feign-client/src/main/kotlin/com/wavesenterprise/sdk/node/client/feign/alias/WeAliasServiceApiFeign.kt new file mode 100644 index 00000000..e3e0b419 --- /dev/null +++ b/we-node-client-http/we-node-client-feign-client/src/main/kotlin/com/wavesenterprise/sdk/node/client/feign/alias/WeAliasServiceApiFeign.kt @@ -0,0 +1,14 @@ +package com.wavesenterprise.sdk.node.client.feign.alias + +import com.wavesenterprise.sdk.node.client.http.AddressDto +import feign.Param +import feign.RequestLine +import java.util.Optional + +interface WeAliasServiceApiFeign { + @RequestLine("GET /alias/by-address/{address}") + fun getAliasesByAddress(@Param("address") address: String): List + + @RequestLine("GET /alias/by-alias/{alias}") + fun getAddressByAlias(@Param("alias") alias: String): Optional +} diff --git a/we-node-client-http/we-node-client-feign-client/src/main/kotlin/com/wavesenterprise/sdk/node/client/feign/contract/FeignContractService.kt b/we-node-client-http/we-node-client-feign-client/src/main/kotlin/com/wavesenterprise/sdk/node/client/feign/contract/FeignContractService.kt index 8c6387d6..98fcf60b 100644 --- a/we-node-client-http/we-node-client-feign-client/src/main/kotlin/com/wavesenterprise/sdk/node/client/feign/contract/FeignContractService.kt +++ b/we-node-client-http/we-node-client-feign-client/src/main/kotlin/com/wavesenterprise/sdk/node/client/feign/contract/FeignContractService.kt @@ -16,7 +16,7 @@ import com.wavesenterprise.sdk.node.domain.contract.ExecutionSuccessRequest import com.wavesenterprise.sdk.node.domain.contract.keys.ContractKeyRequest import com.wavesenterprise.sdk.node.domain.contract.keys.ContractKeysRequest import com.wavesenterprise.sdk.node.exception.specific.ContractNotFoundException -import com.wavesenterprise.sdk.node.exception.specific.DataKeyNotExistsException +import com.wavesenterprise.sdk.node.exception.specific.DataKeyNotExistException import java.util.Optional class FeignContractService( @@ -48,7 +48,7 @@ class FeignContractService( contractId = contractKeyRequest.contractId.asBase58String(), key = contractKeyRequest.key, ).map { it.toDomain() } - } catch (ex: DataKeyNotExistsException) { + } catch (ex: DataKeyNotExistException) { Optional.empty() } diff --git a/we-node-client-http/we-node-client-feign-client/src/main/kotlin/com/wavesenterprise/sdk/node/client/feign/factory/FeignNodeServiceFactory.kt b/we-node-client-http/we-node-client-feign-client/src/main/kotlin/com/wavesenterprise/sdk/node/client/feign/factory/FeignNodeServiceFactory.kt index f00d4503..dfd530e2 100644 --- a/we-node-client-http/we-node-client-feign-client/src/main/kotlin/com/wavesenterprise/sdk/node/client/feign/factory/FeignNodeServiceFactory.kt +++ b/we-node-client-http/we-node-client-feign-client/src/main/kotlin/com/wavesenterprise/sdk/node/client/feign/factory/FeignNodeServiceFactory.kt @@ -1,6 +1,7 @@ package com.wavesenterprise.sdk.node.client.feign.factory import com.wavesenterprise.sdk.node.client.blocking.address.AddressService +import com.wavesenterprise.sdk.node.client.blocking.alias.AliasService import com.wavesenterprise.sdk.node.client.blocking.blocks.BlocksService import com.wavesenterprise.sdk.node.client.blocking.contract.ContractService import com.wavesenterprise.sdk.node.client.blocking.event.BlockchainEventsService @@ -14,6 +15,8 @@ import com.wavesenterprise.sdk.node.client.feign.FeignNodeClientParams import com.wavesenterprise.sdk.node.client.feign.FeignWeApiFactory import com.wavesenterprise.sdk.node.client.feign.address.FeignAddressService import com.wavesenterprise.sdk.node.client.feign.address.WeAddressServiceApiFeign +import com.wavesenterprise.sdk.node.client.feign.alias.FeignAliasService +import com.wavesenterprise.sdk.node.client.feign.alias.WeAliasServiceApiFeign import com.wavesenterprise.sdk.node.client.feign.blocks.FeignBlocksService import com.wavesenterprise.sdk.node.client.feign.blocks.WeBlocksServiceApiFeign import com.wavesenterprise.sdk.node.client.feign.contract.FeignContractService @@ -33,24 +36,6 @@ class FeignNodeServiceFactory( private val params: FeignNodeClientParams, ) : NodeBlockingServiceFactory { - override fun txService(): TxService { - val weTxApi = FeignWeApiFactory.createClient( - clientClass = WeTxApiFeign::class.java, - loggerName = TxService::class.java.name, - feignProperties = params, - ) - return FeignTxService(weTxApi) - } - - override fun contractService(): ContractService { - val weContractServiceApiFeign = FeignWeApiFactory.createClient( - clientClass = WeContractServiceApiFeign::class.java, - loggerName = ContractService::class.java.name, - feignProperties = params, - ) - return FeignContractService(weContractServiceApiFeign) - } - override fun addressService(): AddressService { val weAddressServiceApiFeign = FeignWeApiFactory.createClient( clientClass = WeAddressServiceApiFeign::class.java, @@ -60,22 +45,17 @@ class FeignNodeServiceFactory( return FeignAddressService(weAddressServiceApiFeign) } - override fun nodeInfoService(): NodeInfoService { - val weNodeInfoServiceApiFeign = FeignWeApiFactory.createClient( - clientClass = WeNodeInfoServiceApiFeign::class.java, - loggerName = NodeInfoService::class.java.name, + override fun aliasService(): AliasService { + val weAliasServiceApiFeign = FeignWeApiFactory.createClient( + clientClass = WeAliasServiceApiFeign::class.java, + loggerName = AliasService::class.java.name, feignProperties = params, ) - return FeignNodeInfoService(weNodeInfoServiceApiFeign) + return FeignAliasService(weAliasServiceApiFeign) } - override fun privacyService(): PrivacyService { - val wePrivacyServiceApiFeign = FeignWeApiFactory.createClient( - clientClass = WePrivacyServiceApiFeign::class.java, - loggerName = PrivacyService::class.java.name, - feignProperties = params, - ) - return FeignPrivacyService(wePrivacyServiceApiFeign) + override fun blockchainEventsService(): BlockchainEventsService { + TODO("Not yet implemented") } override fun blocksService(): BlocksService { @@ -87,8 +67,22 @@ class FeignNodeServiceFactory( return FeignBlocksService(weBlocksServiceApiFeign) } - override fun blockchainEventsService(): BlockchainEventsService { - TODO("Not yet implemented") + override fun contractService(): ContractService { + val weContractServiceApiFeign = FeignWeApiFactory.createClient( + clientClass = WeContractServiceApiFeign::class.java, + loggerName = ContractService::class.java.name, + feignProperties = params, + ) + return FeignContractService(weContractServiceApiFeign) + } + + override fun nodeInfoService(): NodeInfoService { + val weNodeInfoServiceApiFeign = FeignWeApiFactory.createClient( + clientClass = WeNodeInfoServiceApiFeign::class.java, + loggerName = NodeInfoService::class.java.name, + feignProperties = params, + ) + return FeignNodeInfoService(weNodeInfoServiceApiFeign) } override fun nodeUtilsService(): NodeUtilsService { @@ -108,4 +102,22 @@ class FeignNodeServiceFactory( ) return FeignPkiService(wePkiServiceApiFeign) } + + override fun privacyService(): PrivacyService { + val wePrivacyServiceApiFeign = FeignWeApiFactory.createClient( + clientClass = WePrivacyServiceApiFeign::class.java, + loggerName = PrivacyService::class.java.name, + feignProperties = params, + ) + return FeignPrivacyService(wePrivacyServiceApiFeign) + } + + override fun txService(): TxService { + val weTxApi = FeignWeApiFactory.createClient( + clientClass = WeTxApiFeign::class.java, + loggerName = TxService::class.java.name, + feignProperties = params, + ) + return FeignTxService(weTxApi) + } } diff --git a/we-node-client-http/we-node-client-feign-client/src/test/kotlin/com/wavesenterprise/sdk/node/client/feign/FeignNodeErrorMapperTest.kt b/we-node-client-http/we-node-client-feign-client/src/test/kotlin/com/wavesenterprise/sdk/node/client/feign/FeignNodeErrorMapperTest.kt index d689ecb3..090c3a78 100644 --- a/we-node-client-http/we-node-client-feign-client/src/test/kotlin/com/wavesenterprise/sdk/node/client/feign/FeignNodeErrorMapperTest.kt +++ b/we-node-client-http/we-node-client-feign-client/src/test/kotlin/com/wavesenterprise/sdk/node/client/feign/FeignNodeErrorMapperTest.kt @@ -7,7 +7,7 @@ import com.wavesenterprise.sdk.node.exception.NodeError import com.wavesenterprise.sdk.node.exception.NodeNotFoundException import com.wavesenterprise.sdk.node.exception.specific.ContractNotFoundException import com.wavesenterprise.sdk.node.exception.specific.CustomValidationErrorException -import com.wavesenterprise.sdk.node.exception.specific.DataKeyNotExistsException +import com.wavesenterprise.sdk.node.exception.specific.DataKeyNotExistException import com.wavesenterprise.sdk.node.exception.specific.InvalidAddressException import com.wavesenterprise.sdk.node.exception.specific.InvalidSignatureException import com.wavesenterprise.sdk.node.exception.specific.PolicyDoesNotExistException @@ -106,8 +106,8 @@ internal class FeignNodeErrorMapperTest { ) ) ex.apply { - assertTrue(this is DataKeyNotExistsException) - (this as DataKeyNotExistsException).apply { + assertTrue(this is DataKeyNotExistException) + (this as DataKeyNotExistException).apply { assertEquals(this.nodeError.error, nodeError.error) assertEquals(this.nodeError.message, nodeError.message) } diff --git a/we-node-client-http/we-node-client-feign-client/src/test/kotlin/com/wavesenterprise/sdk/node/client/feign/address/FeignAddressServiceTest.kt b/we-node-client-http/we-node-client-feign-client/src/test/kotlin/com/wavesenterprise/sdk/node/client/feign/address/FeignAddressServiceTest.kt index 73c82c88..e98b3690 100644 --- a/we-node-client-http/we-node-client-feign-client/src/test/kotlin/com/wavesenterprise/sdk/node/client/feign/address/FeignAddressServiceTest.kt +++ b/we-node-client-http/we-node-client-feign-client/src/test/kotlin/com/wavesenterprise/sdk/node/client/feign/address/FeignAddressServiceTest.kt @@ -1,14 +1,14 @@ package com.wavesenterprise.sdk.node.client.feign.address +import com.wavesenterprise.sdk.node.client.http.AddressDto.Companion.toDto import com.wavesenterprise.sdk.node.client.http.DataEntryDto.Companion.toDto -import com.wavesenterprise.sdk.node.client.http.address.AddressDto.Companion.toDto import com.wavesenterprise.sdk.node.client.http.address.SignMessageResponseDto.Companion.toDto import com.wavesenterprise.sdk.node.client.http.address.VerifyMessageSignatureResponseDto.Companion.toDto import com.wavesenterprise.sdk.node.domain.Address import com.wavesenterprise.sdk.node.domain.DataEntry import com.wavesenterprise.sdk.node.domain.DataKey import com.wavesenterprise.sdk.node.exception.NodeError -import com.wavesenterprise.sdk.node.exception.specific.DataKeyNotExistsException +import com.wavesenterprise.sdk.node.exception.specific.DataKeyNotExistException import com.wavesenterprise.sdk.node.test.data.TestDataFactory.Companion.address import com.wavesenterprise.sdk.node.test.data.TestDataFactory.Companion.dataEntry import com.wavesenterprise.sdk.node.test.data.TestDataFactory.Companion.dataKey @@ -124,10 +124,9 @@ class FeignAddressServiceTest { @Test fun `should return null when catch DataKeyNotExistsException`() { - feignAddressService = FeignAddressService(weAddressServiceApiFeign) every { weAddressServiceApiFeign.getAddressValue(any(), any()) - } throws DataKeyNotExistsException( + } throws DataKeyNotExistException( nodeError = NodeError(error = 304, message = "no data for this key"), cause = Exception(), ) diff --git a/we-node-client-http/we-node-client-feign-client/src/test/kotlin/com/wavesenterprise/sdk/node/client/feign/address/WeAddressServiceApiFeignTest.kt b/we-node-client-http/we-node-client-feign-client/src/test/kotlin/com/wavesenterprise/sdk/node/client/feign/address/WeAddressServiceApiFeignTest.kt index 9758b98a..5b44ff98 100644 --- a/we-node-client-http/we-node-client-feign-client/src/test/kotlin/com/wavesenterprise/sdk/node/client/feign/address/WeAddressServiceApiFeignTest.kt +++ b/we-node-client-http/we-node-client-feign-client/src/test/kotlin/com/wavesenterprise/sdk/node/client/feign/address/WeAddressServiceApiFeignTest.kt @@ -7,13 +7,14 @@ import com.wavesenterprise.sdk.node.client.feign.FeignNodeClientParams import com.wavesenterprise.sdk.node.client.feign.FeignNodeErrorDecoder import com.wavesenterprise.sdk.node.client.feign.FeignNodeErrorMapper import com.wavesenterprise.sdk.node.client.feign.FeignWeApiFactory +import com.wavesenterprise.sdk.node.client.http.AddressDto import com.wavesenterprise.sdk.node.client.http.DataEntryDto -import com.wavesenterprise.sdk.node.client.http.address.AddressDto import com.wavesenterprise.sdk.node.client.http.address.SignMessageRequestDto import com.wavesenterprise.sdk.node.client.http.address.SignMessageResponseDto import com.wavesenterprise.sdk.node.client.http.address.VerifyMessageSignatureRequestDto import com.wavesenterprise.sdk.node.client.http.address.VerifyMessageSignatureResponseDto import com.wavesenterprise.sdk.node.exception.NodeErrorCode +import com.wavesenterprise.sdk.node.exception.specific.DataKeyNotExistException import com.wavesenterprise.sdk.node.exception.specific.InvalidPasswordException import com.wavesenterprise.sdk.node.exception.specific.InvalidPublicKeyException import org.junit.jupiter.api.Assertions.assertEquals @@ -149,6 +150,16 @@ class WeAddressServiceApiFeignTest { } } + @Test + fun `should throw DataKeyNotExistException`() { + assertThrows { + weAddressServiceApiFeign.getAddressValue(address, "non-existent-key") + }.apply { + assertEquals(NodeErrorCode.DATA_KEY_NOT_EXIST.code, nodeError.error) + assertEquals("no data for this key", nodeError.message) + } + } + @Test fun `should throw InvalidPasswordException`() { val request = SignMessageRequestDto( diff --git a/we-node-client-http/we-node-client-feign-client/src/test/kotlin/com/wavesenterprise/sdk/node/client/feign/alias/FeignAliasServiceTest.kt b/we-node-client-http/we-node-client-feign-client/src/test/kotlin/com/wavesenterprise/sdk/node/client/feign/alias/FeignAliasServiceTest.kt new file mode 100644 index 00000000..156a56d6 --- /dev/null +++ b/we-node-client-http/we-node-client-feign-client/src/test/kotlin/com/wavesenterprise/sdk/node/client/feign/alias/FeignAliasServiceTest.kt @@ -0,0 +1,68 @@ +package com.wavesenterprise.sdk.node.client.feign.alias + +import com.wavesenterprise.sdk.node.client.http.AddressDto.Companion.toDto +import com.wavesenterprise.sdk.node.domain.Address +import com.wavesenterprise.sdk.node.domain.Alias +import com.wavesenterprise.sdk.node.domain.Alias.Companion.toDomain +import com.wavesenterprise.sdk.node.exception.NodeError +import com.wavesenterprise.sdk.node.exception.specific.AliasNotExistException +import com.wavesenterprise.sdk.node.test.data.TestDataFactory.Companion.address +import io.mockk.every +import io.mockk.mockk +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.TestInstance +import java.util.Optional + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +class FeignAliasServiceTest { + private lateinit var feignAddressService: FeignAliasService + private val weAliasServiceApiFeign: WeAliasServiceApiFeign = mockk() + + @BeforeEach + fun setUp() { + feignAddressService = FeignAliasService( + weAliasServiceApiFeign = weAliasServiceApiFeign, + ) + } + + @Test + fun `should return aliases by address`() { + val address = address() + val expectedResponse = listOf("alias:R:_firstAlias", "alias:R:_secondAlias") + every { + weAliasServiceApiFeign.getAliasesByAddress(any()) + } returns expectedResponse + assertEquals( + expectedResponse.map { it.toDomain() }, + feignAddressService.getAliasesByAddress(address) + ) + } + + @Test + fun `should return address by alias`() { + val expectedResponse = Optional.of(address()) + every { + weAliasServiceApiFeign.getAddressByAlias(any()) + } returns expectedResponse.map { it.toDto() } + assertEquals( + expectedResponse, + feignAddressService.getAddressByAlias(Alias("_alias1")) + ) + } + + @Test + fun `should return null when catch AliasNotExistException`() { + every { + weAliasServiceApiFeign.getAddressByAlias(any()) + } throws AliasNotExistException( + nodeError = NodeError(error = 302, message = "alias 'alias:R:_non-existent-alias' doesn't exist"), + cause = Exception(), + ) + assertEquals( + Optional.empty
(), + feignAddressService.getAddressByAlias(Alias("_non-existent-alias")) + ) + } +} diff --git a/we-node-client-http/we-node-client-feign-client/src/test/kotlin/com/wavesenterprise/sdk/node/client/feign/alias/WeAliasServiceApiFeignTest.kt b/we-node-client-http/we-node-client-feign-client/src/test/kotlin/com/wavesenterprise/sdk/node/client/feign/alias/WeAliasServiceApiFeignTest.kt new file mode 100644 index 00000000..75a6de2d --- /dev/null +++ b/we-node-client-http/we-node-client-feign-client/src/test/kotlin/com/wavesenterprise/sdk/node/client/feign/alias/WeAliasServiceApiFeignTest.kt @@ -0,0 +1,68 @@ +package com.wavesenterprise.sdk.node.client.feign.alias + +import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo +import com.github.tomakehurst.wiremock.junit5.WireMockTest +import com.wavesenterprise.sdk.node.client.feign.FeignNodeClientParams +import com.wavesenterprise.sdk.node.client.feign.FeignNodeErrorDecoder +import com.wavesenterprise.sdk.node.client.feign.FeignNodeErrorMapper +import com.wavesenterprise.sdk.node.client.feign.FeignWeApiFactory +import com.wavesenterprise.sdk.node.client.http.AddressDto +import com.wavesenterprise.sdk.node.exception.NodeErrorCode +import com.wavesenterprise.sdk.node.exception.specific.AliasNotExistException +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.BeforeAll +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.TestInstance +import org.junit.jupiter.api.assertThrows +import java.util.Optional + +@WireMockTest +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +class WeAliasServiceApiFeignTest { + private lateinit var weAliasServiceApiFeign: WeAliasServiceApiFeign + + @BeforeAll + fun init(wireMockRuntimeInfo: WireMockRuntimeInfo) { + weAliasServiceApiFeign = FeignWeApiFactory.createClient( + clientClass = WeAliasServiceApiFeign::class.java, + feignProperties = FeignNodeClientParams(url = wireMockRuntimeInfo.httpBaseUrl), + errorDecoder = FeignNodeErrorDecoder(FeignNodeErrorMapper(jacksonObjectMapper())), + ) + } + + @Test + fun `should get aliases by address`() { + val address = "3M3ybNZvLG7o7rnM4F7ViRPnDTfVggdfmRX" + assertEquals( + listOf( + "alias:R:_firstAlias", + "alias:R:_secondAlias", + ), + weAliasServiceApiFeign.getAliasesByAddress(address), + ) + } + + @Test + fun `should get address by alias`() { + val alias = "_firstAlias" + val address = "3M3ybNZvLG7o7rnM4F7ViRPnDTfVggdfmRX" + assertEquals( + Optional.of(AddressDto(address)), + weAliasServiceApiFeign.getAddressByAlias(alias) + ) + } + + @Test + fun `should throw AliasNotExistException`() { + assertThrows { + weAliasServiceApiFeign.getAddressByAlias("_non-existent-alias") + }.apply { + assertEquals(NodeErrorCode.ALIAS_NOT_EXIST.code, nodeError.error) + assertEquals( + "alias 'alias:R:_non-existent-alias' doesn't exist", + nodeError.message + ) + } + } +} diff --git a/we-node-client-http/we-node-client-feign-client/src/test/kotlin/com/wavesenterprise/sdk/node/client/feign/contract/FeignContractServiceTest.kt b/we-node-client-http/we-node-client-feign-client/src/test/kotlin/com/wavesenterprise/sdk/node/client/feign/contract/FeignContractServiceTest.kt index 2d67b419..312241f2 100644 --- a/we-node-client-http/we-node-client-feign-client/src/test/kotlin/com/wavesenterprise/sdk/node/client/feign/contract/FeignContractServiceTest.kt +++ b/we-node-client-http/we-node-client-feign-client/src/test/kotlin/com/wavesenterprise/sdk/node/client/feign/contract/FeignContractServiceTest.kt @@ -5,7 +5,7 @@ import com.wavesenterprise.sdk.node.domain.contract.ContractId import com.wavesenterprise.sdk.node.domain.contract.keys.ContractKeyRequest import com.wavesenterprise.sdk.node.exception.NodeError import com.wavesenterprise.sdk.node.exception.specific.ContractNotFoundException -import com.wavesenterprise.sdk.node.exception.specific.DataKeyNotExistsException +import com.wavesenterprise.sdk.node.exception.specific.DataKeyNotExistException import io.mockk.every import io.mockk.mockk import org.junit.jupiter.api.Assertions.assertFalse @@ -41,7 +41,7 @@ class FeignContractServiceTest { contractId = contractKeyRequest.contractId.asBase58String(), key = contractKeyRequest.key, ) - } throws DataKeyNotExistsException( + } throws DataKeyNotExistException( nodeError = NodeError(error = 304, message = "no data for this key"), cause = Exception(), ) diff --git a/we-node-client-http/we-node-client-feign-client/src/test/resources/mappings/address/address_value_404.json b/we-node-client-http/we-node-client-feign-client/src/test/resources/mappings/address/address_value_404.json new file mode 100644 index 00000000..2fc6a8d7 --- /dev/null +++ b/we-node-client-http/we-node-client-feign-client/src/test/resources/mappings/address/address_value_404.json @@ -0,0 +1,16 @@ +{ + "request": { + "method": "GET", + "url": "/addresses/data/3M3ybNZvLG7o7rnM4F7ViRPnDTfVggdfmRX/non-existent-key" + }, + "response": { + "status": 404, + "jsonBody": { + "error": 304, + "message": "no data for this key" + }, + "headers": { + "Content-Type": "application/json" + } + } +} \ No newline at end of file diff --git a/we-node-client-http/we-node-client-feign-client/src/test/resources/mappings/alias/address_by_alias_200.json b/we-node-client-http/we-node-client-feign-client/src/test/resources/mappings/alias/address_by_alias_200.json new file mode 100644 index 00000000..4c259249 --- /dev/null +++ b/we-node-client-http/we-node-client-feign-client/src/test/resources/mappings/alias/address_by_alias_200.json @@ -0,0 +1,15 @@ +{ + "request": { + "method": "GET", + "url": "/alias/by-alias/_firstAlias" + }, + "response": { + "status": 200, + "jsonBody": { + "address": "3M3ybNZvLG7o7rnM4F7ViRPnDTfVggdfmRX" + }, + "headers": { + "Content-Type": "application/json" + } + } +} \ No newline at end of file diff --git a/we-node-client-http/we-node-client-feign-client/src/test/resources/mappings/alias/address_by_alias_404.json b/we-node-client-http/we-node-client-feign-client/src/test/resources/mappings/alias/address_by_alias_404.json new file mode 100644 index 00000000..502aab2b --- /dev/null +++ b/we-node-client-http/we-node-client-feign-client/src/test/resources/mappings/alias/address_by_alias_404.json @@ -0,0 +1,16 @@ +{ + "request": { + "method": "GET", + "url": "/alias/by-alias/_non-existent-alias" + }, + "response": { + "status": 404, + "jsonBody": { + "error": 302, + "message": "alias 'alias:R:_non-existent-alias' doesn't exist" + }, + "headers": { + "Content-Type": "application/json" + } + } +} \ No newline at end of file diff --git a/we-node-client-http/we-node-client-feign-client/src/test/resources/mappings/alias/aliases_by_address_200.json b/we-node-client-http/we-node-client-feign-client/src/test/resources/mappings/alias/aliases_by_address_200.json new file mode 100644 index 00000000..2f2fd711 --- /dev/null +++ b/we-node-client-http/we-node-client-feign-client/src/test/resources/mappings/alias/aliases_by_address_200.json @@ -0,0 +1,16 @@ +{ + "request": { + "method": "GET", + "url": "/alias/by-address/3M3ybNZvLG7o7rnM4F7ViRPnDTfVggdfmRX" + }, + "response": { + "status": 200, + "jsonBody": [ + "alias:R:_firstAlias", + "alias:R:_secondAlias" + ], + "headers": { + "Content-Type": "application/json" + } + } +} \ No newline at end of file diff --git a/we-node-client-json/src/main/kotlin/com/wavesenterprise/sdk/node/client/http/address/AddressDto.kt b/we-node-client-json/src/main/kotlin/com/wavesenterprise/sdk/node/client/http/AddressDto.kt similarity index 69% rename from we-node-client-json/src/main/kotlin/com/wavesenterprise/sdk/node/client/http/address/AddressDto.kt rename to we-node-client-json/src/main/kotlin/com/wavesenterprise/sdk/node/client/http/AddressDto.kt index 56185b7d..e3fe42c1 100644 --- a/we-node-client-json/src/main/kotlin/com/wavesenterprise/sdk/node/client/http/address/AddressDto.kt +++ b/we-node-client-json/src/main/kotlin/com/wavesenterprise/sdk/node/client/http/AddressDto.kt @@ -1,4 +1,4 @@ -package com.wavesenterprise.sdk.node.client.http.address +package com.wavesenterprise.sdk.node.client.http import com.wavesenterprise.sdk.node.domain.Address @@ -11,8 +11,5 @@ data class AddressDto( @JvmStatic fun Address.toDto(): AddressDto = AddressDto(address = asBase58String()) - - @JvmStatic - fun String.toDomain(): Address = Address.fromBase58(this) } }