diff --git a/build.gradle.kts b/build.gradle.kts index 41285146..df1c035e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -24,6 +24,7 @@ val hamcrestVersion: String by project val mockkVersion: String by project val springMockkVersion: String by project val wireMockVersion: String by project +val kotestVersion: String by project val ktorVersion: String by project @@ -303,6 +304,7 @@ configure( dependency("org.hamcrest:hamcrest-library:$hamcrestVersion") dependency("com.github.tomakehurst:wiremock-jre8:$wireMockVersion") + dependency("io.kotest:kotest-runner-junit5:$kotestVersion") } } diff --git a/gradle.properties b/gradle.properties index 8c8f1bc8..139360b0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -43,6 +43,7 @@ hamcrestVersion=2.2 mockkVersion=1.12.3 springMockkVersion=3.1.1 wireMockVersion=2.33.2 +kotestVersion=5.0.0 # Publishing values githubUrl=https://github.com/waves-enterprise/ diff --git a/we-node-client-domain/src/main/kotlin/com/wavesenterprise/sdk/node/domain/PermitDataEntry.kt b/we-node-client-domain/src/main/kotlin/com/wavesenterprise/sdk/node/domain/PermitDataEntry.kt deleted file mode 100644 index 8cfd2015..00000000 --- a/we-node-client-domain/src/main/kotlin/com/wavesenterprise/sdk/node/domain/PermitDataEntry.kt +++ /dev/null @@ -1,14 +0,0 @@ -package com.wavesenterprise.sdk.node.domain - -import com.wavesenterprise.sdk.node.domain.sign.SerializableToBytes - -data class PermitDataEntry( - val key: DataKey, - val action: PermitDataAction, -) : SerializableToBytes { - override fun getSignatureBytes(networkByte: Byte?): ByteArray = - DataEntry( - key = key, - value = (action as PermitDataAction.SetDataAction).value, // TODO: https://jira.web3tech.ru/browse/WTCH-212 - ).getSignatureBytes() -} diff --git a/we-node-client-domain/src/main/kotlin/com/wavesenterprise/sdk/node/domain/sign/DataSignRequest.kt b/we-node-client-domain/src/main/kotlin/com/wavesenterprise/sdk/node/domain/sign/DataSignRequest.kt index ea85fdaa..606e4546 100644 --- a/we-node-client-domain/src/main/kotlin/com/wavesenterprise/sdk/node/domain/sign/DataSignRequest.kt +++ b/we-node-client-domain/src/main/kotlin/com/wavesenterprise/sdk/node/domain/sign/DataSignRequest.kt @@ -1,10 +1,10 @@ package com.wavesenterprise.sdk.node.domain.sign import com.wavesenterprise.sdk.node.domain.Address +import com.wavesenterprise.sdk.node.domain.DataEntry import com.wavesenterprise.sdk.node.domain.Fee import com.wavesenterprise.sdk.node.domain.FeeAssetId import com.wavesenterprise.sdk.node.domain.Password -import com.wavesenterprise.sdk.node.domain.PermitDataEntry import com.wavesenterprise.sdk.node.domain.TxVersion import com.wavesenterprise.sdk.node.domain.tx.DataTx @@ -15,7 +15,7 @@ data class DataSignRequest( val fee: Fee, val feeAssetId: FeeAssetId? = null, val author: Address, - val data: List, + val data: List, ) : SignRequest { override fun withAddress(address: Address) = copy(senderAddress = address) diff --git a/we-node-client-domain/src/main/kotlin/com/wavesenterprise/sdk/node/domain/sign/RegisterNodeSignRequest.kt b/we-node-client-domain/src/main/kotlin/com/wavesenterprise/sdk/node/domain/sign/RegisterNodeSignRequest.kt index b9603ad7..6bc3e3fb 100644 --- a/we-node-client-domain/src/main/kotlin/com/wavesenterprise/sdk/node/domain/sign/RegisterNodeSignRequest.kt +++ b/we-node-client-domain/src/main/kotlin/com/wavesenterprise/sdk/node/domain/sign/RegisterNodeSignRequest.kt @@ -17,7 +17,6 @@ data class RegisterNodeSignRequest( override val password: Password? = null, val fee: Fee, val opType: OpType, - val target: Address, val targetPublicKey: PublicKey, val nodeName: NodeName, ) : SignRequest { @@ -30,7 +29,6 @@ data class RegisterNodeSignRequest( fun RegisterNodeSignRequest.toTx(senderPublicKey: PublicKey) = RegisterNodeTx( id = TxId.EMPTY, senderPublicKey = senderPublicKey, - target = target, targetPublicKey = targetPublicKey, nodeName = nodeName, opType = opType, diff --git a/we-node-client-domain/src/main/kotlin/com/wavesenterprise/sdk/node/domain/tx/DataTx.kt b/we-node-client-domain/src/main/kotlin/com/wavesenterprise/sdk/node/domain/tx/DataTx.kt index 1d78ba8d..ae7f2a2b 100644 --- a/we-node-client-domain/src/main/kotlin/com/wavesenterprise/sdk/node/domain/tx/DataTx.kt +++ b/we-node-client-domain/src/main/kotlin/com/wavesenterprise/sdk/node/domain/tx/DataTx.kt @@ -1,9 +1,9 @@ package com.wavesenterprise.sdk.node.domain.tx import com.wavesenterprise.sdk.node.domain.Address +import com.wavesenterprise.sdk.node.domain.DataEntry import com.wavesenterprise.sdk.node.domain.Fee import com.wavesenterprise.sdk.node.domain.FeeAssetId -import com.wavesenterprise.sdk.node.domain.PermitDataEntry import com.wavesenterprise.sdk.node.domain.PublicKey import com.wavesenterprise.sdk.node.domain.Signature import com.wavesenterprise.sdk.node.domain.Timestamp @@ -18,7 +18,7 @@ data class DataTx( @FieldInfo(required = true, sinceVersion = 1, bytesPosition = 2) val authorPublicKey: PublicKey, @FieldInfo(required = true, sinceVersion = 1, bytesPosition = 3) - val data: List, + val data: List, @FieldInfo(required = true, sinceVersion = 1, bytesPosition = 4) override val timestamp: Timestamp, @FieldInfo(required = true, sinceVersion = 1, bytesPosition = 5) diff --git a/we-node-client-domain/src/main/kotlin/com/wavesenterprise/sdk/node/domain/tx/RegisterNodeTx.kt b/we-node-client-domain/src/main/kotlin/com/wavesenterprise/sdk/node/domain/tx/RegisterNodeTx.kt index 7e225973..0e86d9a3 100644 --- a/we-node-client-domain/src/main/kotlin/com/wavesenterprise/sdk/node/domain/tx/RegisterNodeTx.kt +++ b/we-node-client-domain/src/main/kotlin/com/wavesenterprise/sdk/node/domain/tx/RegisterNodeTx.kt @@ -15,7 +15,6 @@ data class RegisterNodeTx( override val id: TxId, @FieldInfo(required = true, sinceVersion = 1, bytesPosition = 1) val senderPublicKey: PublicKey, - val target: Address, @FieldInfo(required = true, sinceVersion = 1, bytesPosition = 2) val targetPublicKey: PublicKey, @FieldInfo(required = true, sinceVersion = 1, bytesPosition = 3) diff --git a/we-node-client-grpc/we-node-client-grpc-mapper/build.gradle.kts b/we-node-client-grpc/we-node-client-grpc-mapper/build.gradle.kts index 727fa860..cc40f760 100644 --- a/we-node-client-grpc/we-node-client-grpc-mapper/build.gradle.kts +++ b/we-node-client-grpc/we-node-client-grpc-mapper/build.gradle.kts @@ -2,4 +2,10 @@ dependencies { implementation(kotlin("stdlib")) api(project(":we-node-client-grpc:we-node-client-grpc-java")) + + testImplementation("io.mockk:mockk") + testImplementation("io.kotest:kotest-runner-junit5") + testImplementation("org.junit.jupiter:junit-jupiter-api") + testImplementation("org.junit.jupiter:junit-jupiter-params") + testImplementation("org.junit.jupiter:junit-jupiter-engine") } diff --git a/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/AtomicBadgeMapper.kt b/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/AtomicBadgeMapper.kt index 3a4eae2a..ea94da25 100644 --- a/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/AtomicBadgeMapper.kt +++ b/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/AtomicBadgeMapper.kt @@ -27,6 +27,6 @@ object AtomicBadgeMapper { @JvmStatic internal fun domainInternal(atomicBadge: ProtoAtomicBadge): AtomicBadge = AtomicBadge( - trustedSender = Address(atomicBadge.trustedSender.byteArray()) + trustedSender = Address(atomicBadge.trustedSender.value.byteArray()) ) } diff --git a/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/TransferMapper.kt b/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/TransferMapper.kt new file mode 100644 index 00000000..d82be20b --- /dev/null +++ b/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/TransferMapper.kt @@ -0,0 +1,21 @@ +package com.wavesenterprise.sdk.node.client.grpc.mapper + +import com.wavesenterprise.sdk.node.client.grpc.mapper.GrpcTypesMapper.byteArray +import com.wavesenterprise.sdk.node.domain.Address +import com.wavesenterprise.sdk.node.domain.Amount +import com.wavesenterprise.sdk.node.domain.Transfer +import com.wavesenterprise.transaction.protobuf.Transfer as ProtoTransfer + +object TransferMapper { + + @JvmStatic + fun ProtoTransfer.domain(): Transfer = + domainInternal(this) + + @JvmStatic + internal fun domainInternal(protoTransfer: ProtoTransfer): Transfer = + Transfer( + recipient = Address(protoTransfer.recipient.byteArray()), + amount = Amount(protoTransfer.amount), + ) +} diff --git a/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/AtomicTxMapper.kt b/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/AtomicTxMapper.kt index 1b1e13a0..382994f4 100644 --- a/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/AtomicTxMapper.kt +++ b/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/AtomicTxMapper.kt @@ -19,6 +19,7 @@ import com.wavesenterprise.sdk.node.domain.TxVersion import com.wavesenterprise.sdk.node.domain.tx.AtomicTx import com.wavesenterprise.transaction.protobuf.AtomicTransaction import com.wavesenterprise.transaction.protobuf.atomicTransaction +import com.wavesenterprise.transaction.protobuf.minerOrNull object AtomicTxMapper { @JvmStatic @@ -48,13 +49,10 @@ object AtomicTxMapper { AtomicTx( id = TxId(tx.id.byteArray()), senderPublicKey = PublicKey(tx.senderPublicKey.toByteArray()), + miner = tx.minerOrNull?.let { Address(it.value.byteArray()) }, txs = tx.transactionsList.map { it.domain(version) }, - timestamp = Timestamp.fromUtcTimestamp(tx.timestamp), - proofs = tx.proofsList?.let { dtoProofs -> - dtoProofs.map { - Signature(it.byteArray()) - } - }, + timestamp = Timestamp(tx.timestamp), + proofs = tx.proofsList?.map { Signature(it.byteArray()) }, senderAddress = Address(tx.senderAddress.byteArray()), fee = Fee(0), version = version, diff --git a/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/BurnTxMapper.kt b/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/BurnTxMapper.kt index 40d945bc..84ce50e0 100644 --- a/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/BurnTxMapper.kt +++ b/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/BurnTxMapper.kt @@ -51,18 +51,12 @@ object BurnTxMapper { BurnTx( id = TxId(tx.id.byteArray()), chainId = ChainId(tx.chainId.toByte()), - senderPublicKey = PublicKey(tx.senderPublicKey.toByteArray()), - assetId = tx.assetId?.let { - AssetId.fromByteArray(it.byteArray()) - }, + senderPublicKey = PublicKey(tx.senderPublicKey.byteArray()), + assetId = AssetId(tx.assetId.byteArray()), amount = Amount(tx.amount), fee = Fee(tx.fee), timestamp = Timestamp.fromUtcTimestamp(tx.timestamp), - proofs = tx.proofsList?.let { dtoProofs -> - dtoProofs.map { - Signature(it.byteArray()) - } - }, + proofs = tx.proofsList?.map { Signature(it.byteArray()) }, senderAddress = Address(tx.senderAddress.byteArray()), version = version, ) diff --git a/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/CallContractTxMapper.kt b/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/CallContractTxMapper.kt index e5fbfba9..5f4f00dc 100644 --- a/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/CallContractTxMapper.kt +++ b/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/CallContractTxMapper.kt @@ -23,7 +23,6 @@ import com.wavesenterprise.sdk.node.domain.TxVersion import com.wavesenterprise.sdk.node.domain.contract.ContractId import com.wavesenterprise.sdk.node.domain.contract.ContractVersion import com.wavesenterprise.sdk.node.domain.tx.CallContractTx -import com.wavesenterprise.transaction.protobuf.DataEntry import com.wavesenterprise.transaction.protobuf.docker.CallContractTransaction import com.wavesenterprise.transaction.protobuf.docker.atomicBadgeOrNull import com.wavesenterprise.transaction.protobuf.docker.callContractTransaction @@ -60,23 +59,21 @@ object CallContractTxMapper { internal fun domainInternal(tx: CallContractTransaction, version: TxVersion): CallContractTx = CallContractTx( id = TxId(tx.id.byteArray()), - senderPublicKey = PublicKey(tx.senderPublicKey.toByteArray()), - contractId = ContractId.fromByteArray(tx.contractId.toByteArray()), - params = tx.paramsList.map { param: DataEntry -> - param.domain() - }, + senderPublicKey = PublicKey(tx.senderPublicKey.byteArray()), + contractId = ContractId( + txId = TxId(tx.contractId.byteArray()) + ), + params = tx.paramsList.map { it.domain() }, fee = Fee(tx.fee), - timestamp = Timestamp.fromUtcTimestamp(tx.timestamp), + timestamp = Timestamp(tx.timestamp), contractVersion = ContractVersion(tx.contractVersion), feeAssetId = tx.feeAssetIdOrNull?.let { - FeeAssetId.fromByteArray(it.byteArray()) + FeeAssetId( + txId = TxId(it.value.byteArray()) + ) }, atomicBadge = tx.atomicBadgeOrNull?.domain(), - proofs = tx.proofsList?.let { dtoProofs -> - dtoProofs.map { - Signature(it.byteArray()) - } - }, + proofs = tx.proofsList?.map { Signature(it.byteArray()) }, senderAddress = Address(tx.senderAddress.byteArray()), version = version, ) diff --git a/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/CreateAliasTxMapper.kt b/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/CreateAliasTxMapper.kt index 06048378..600ab785 100644 --- a/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/CreateAliasTxMapper.kt +++ b/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/CreateAliasTxMapper.kt @@ -1,10 +1,40 @@ package com.wavesenterprise.sdk.node.client.grpc.mapper.tx +import com.wavesenterprise.sdk.node.client.grpc.mapper.GrpcTypesMapper.byteArray +import com.wavesenterprise.sdk.node.domain.Address +import com.wavesenterprise.sdk.node.domain.Alias +import com.wavesenterprise.sdk.node.domain.Fee +import com.wavesenterprise.sdk.node.domain.FeeAssetId +import com.wavesenterprise.sdk.node.domain.PublicKey +import com.wavesenterprise.sdk.node.domain.Signature +import com.wavesenterprise.sdk.node.domain.Timestamp +import com.wavesenterprise.sdk.node.domain.TxId +import com.wavesenterprise.sdk.node.domain.TxVersion import com.wavesenterprise.sdk.node.domain.tx.CreateAliasTx import com.wavesenterprise.transaction.protobuf.CreateAliasTransaction +import com.wavesenterprise.transaction.protobuf.feeAssetIdOrNull object CreateAliasTxMapper { + fun dtoInternal(tx: CreateAliasTx): CreateAliasTransaction { TODO("Not yet implemented") } + + @JvmStatic + fun CreateAliasTransaction.domain(version: TxVersion): CreateAliasTx = + domainInternal(this, version) + + @JvmStatic + internal fun domainInternal(tx: CreateAliasTransaction, version: TxVersion): CreateAliasTx = + CreateAliasTx( + id = TxId(tx.id.byteArray()), + senderPublicKey = PublicKey(tx.senderPublicKey.toByteArray()), + alias = Alias(tx.alias.toString()), + fee = Fee(tx.fee), + timestamp = Timestamp.fromUtcTimestamp(tx.timestamp), + feeAssetId = tx.feeAssetIdOrNull?.let { FeeAssetId.fromByteArray(it.value.toByteArray()) }, + proofs = tx.proofsList?.map { Signature(it.byteArray()) }, + senderAddress = Address(tx.senderAddress.toByteArray()), + version = version, + ) } diff --git a/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/CreateContractTxMapper.kt b/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/CreateContractTxMapper.kt index 68d064b3..6c6cc7c2 100644 --- a/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/CreateContractTxMapper.kt +++ b/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/CreateContractTxMapper.kt @@ -27,7 +27,6 @@ import com.wavesenterprise.sdk.node.domain.contract.ContractImage import com.wavesenterprise.sdk.node.domain.contract.ContractImageHash import com.wavesenterprise.sdk.node.domain.contract.ContractName import com.wavesenterprise.sdk.node.domain.tx.CreateContractTx -import com.wavesenterprise.transaction.protobuf.DataEntry import com.wavesenterprise.transaction.protobuf.docker.CreateContractTransaction import com.wavesenterprise.transaction.protobuf.docker.apiVersionOrNull import com.wavesenterprise.transaction.protobuf.docker.atomicBadgeOrNull @@ -69,26 +68,22 @@ object CreateContractTxMapper { internal fun domainInternal(tx: CreateContractTransaction, version: TxVersion): CreateContractTx = CreateContractTx( id = TxId(tx.id.byteArray()), - senderPublicKey = PublicKey(tx.senderPublicKey.toByteArray()), + senderPublicKey = PublicKey(tx.senderPublicKey.byteArray()), image = ContractImage(tx.image), imageHash = ContractImageHash(tx.imageHash), contractName = ContractName(tx.contractName), - params = tx.paramsList.map { param: DataEntry -> - param.domain() - }, + params = tx.paramsList.map { it.domain() }, fee = Fee(tx.fee), - timestamp = Timestamp.fromUtcTimestamp(tx.timestamp), + timestamp = Timestamp(tx.timestamp), feeAssetId = tx.feeAssetIdOrNull?.let { - FeeAssetId.fromByteArray(it.byteArray()) + FeeAssetId( + txId = TxId(it.value.byteArray()) + ) }, atomicBadge = tx.atomicBadgeOrNull?.domain(), validationPolicy = tx.validationPolicyOrNull?.domain(), apiVersion = tx.apiVersionOrNull?.domain(), - proofs = tx.proofsList?.let { dtoProofs -> - dtoProofs.map { - Signature(it.byteArray()) - } - }, + proofs = tx.proofsList?.map { Signature(it.byteArray()) }, senderAddress = Address(tx.senderAddress.byteArray()), version = version, ) diff --git a/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/CreatePolicyTxMapper.kt b/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/CreatePolicyTxMapper.kt index 7e178dcf..8faae036 100644 --- a/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/CreatePolicyTxMapper.kt +++ b/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/CreatePolicyTxMapper.kt @@ -57,16 +57,14 @@ object CreatePolicyTxMapper { internal fun domainInternal(tx: CreatePolicyTransaction, version: TxVersion): CreatePolicyTx = CreatePolicyTx( id = TxId(tx.id.byteArray()), - senderPublicKey = PublicKey(tx.senderPublicKey.toByteArray()), + senderPublicKey = PublicKey(tx.senderPublicKey.byteArray()), policyName = PolicyName(tx.policyName), description = PolicyDescription(tx.description), recipients = tx.recipientsList.map { Address(it.byteArray()) }, owners = tx.ownersList.map { Address(it.byteArray()) }, timestamp = Timestamp.fromUtcTimestamp(tx.timestamp), fee = Fee(tx.fee), - feeAssetId = tx.feeAssetIdOrNull?.let { - FeeAssetId.fromByteArray(it.byteArray()) - }, + feeAssetId = tx.feeAssetIdOrNull?.let { FeeAssetId.fromByteArray(it.value.byteArray()) }, atomicBadge = tx.atomicBadgeOrNull?.domain(), proofs = tx.proofsList?.let { dtoProofs -> dtoProofs.map { diff --git a/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/DataTxMapper.kt b/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/DataTxMapper.kt index 2b607e39..d9f05b5e 100644 --- a/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/DataTxMapper.kt +++ b/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/DataTxMapper.kt @@ -1,10 +1,46 @@ package com.wavesenterprise.sdk.node.client.grpc.mapper.tx +import com.wavesenterprise.sdk.node.client.grpc.mapper.DataEntryMapper.domain +import com.wavesenterprise.sdk.node.client.grpc.mapper.GrpcTypesMapper.byteArray +import com.wavesenterprise.sdk.node.domain.Address +import com.wavesenterprise.sdk.node.domain.Fee +import com.wavesenterprise.sdk.node.domain.FeeAssetId +import com.wavesenterprise.sdk.node.domain.PublicKey +import com.wavesenterprise.sdk.node.domain.Signature +import com.wavesenterprise.sdk.node.domain.Timestamp +import com.wavesenterprise.sdk.node.domain.TxId +import com.wavesenterprise.sdk.node.domain.TxVersion import com.wavesenterprise.sdk.node.domain.tx.DataTx import com.wavesenterprise.transaction.protobuf.DataTransaction +import com.wavesenterprise.transaction.protobuf.feeAssetIdOrNull object DataTxMapper { + fun dtoInternal(tx: DataTx): DataTransaction { TODO("Not yet implemented") } + + @JvmStatic + fun DataTransaction.domain(version: TxVersion): DataTx = + domainInternal(this, version) + + @JvmStatic + internal fun domainInternal(tx: DataTransaction, version: TxVersion): DataTx = + DataTx( + id = TxId(tx.id.byteArray()), + senderPublicKey = PublicKey(tx.senderPublicKey.byteArray()), + authorPublicKey = PublicKey(tx.authorPublicKey.byteArray()), + data = tx.dataList.map { it.domain() }, + fee = Fee(tx.fee), + feeAssetId = tx.feeAssetIdOrNull?.let { + FeeAssetId( + txId = TxId(it.value.byteArray()) + ) + }, + timestamp = Timestamp(tx.timestamp), + proofs = tx.proofsList?.map { Signature(it.byteArray()) }, + senderAddress = Address(tx.senderAddress.byteArray()), + authorAddress = Address(tx.authorPublicKey.byteArray()), + version = version, + ) } diff --git a/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/DisableContractTxMapper.kt b/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/DisableContractTxMapper.kt index 023934e3..869b3fae 100644 --- a/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/DisableContractTxMapper.kt +++ b/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/DisableContractTxMapper.kt @@ -54,18 +54,20 @@ object DisableContractTxMapper { internal fun domainInternal(tx: DisableContractTransaction, version: TxVersion): DisableContractTx = DisableContractTx( id = TxId(tx.id.byteArray()), - senderPublicKey = PublicKey(tx.senderPublicKey.toByteArray()), - contractId = ContractId.fromByteArray(tx.contractId.toByteArray()), + senderPublicKey = PublicKey(tx.senderPublicKey.byteArray()), + contractId = ContractId( + txId = TxId(tx.contractId.byteArray()), + ), fee = Fee(tx.fee), - timestamp = Timestamp.fromUtcTimestamp(tx.timestamp), + timestamp = Timestamp(tx.timestamp), feeAssetId = tx.feeAssetIdOrNull?.let { - FeeAssetId.fromByteArray(it.byteArray()) + FeeAssetId( + txId = TxId(it.value.byteArray()), + ) }, atomicBadge = tx.atomicBadgeOrNull?.domain(), - proofs = tx.proofsList?.let { dtoProofs -> - dtoProofs.map { - Signature(it.byteArray()) - } + proofs = tx.proofsList?.map { + Signature(it.byteArray()) }, senderAddress = Address(tx.senderAddress.byteArray()), version = version, diff --git a/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/ExecutedContractTxMapper.kt b/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/ExecutedContractTxMapper.kt index ffe36851..30b9c965 100644 --- a/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/ExecutedContractTxMapper.kt +++ b/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/ExecutedContractTxMapper.kt @@ -53,19 +53,15 @@ object ExecutedContractTxMapper { internal fun domainInternal(tx: ExecutedContractTransaction, version: TxVersion): ExecutedContractTx = ExecutedContractTx( id = TxId(tx.id.byteArray()), - senderPublicKey = PublicKey(tx.senderPublicKey.toByteArray()), + senderPublicKey = PublicKey(tx.senderPublicKey.byteArray()), tx = tx.tx.domain(), results = tx.resultsList.map { it.domain() }, resultsHash = Hash(tx.resultsHash.byteArray()), fee = Fee(0), validationProofs = tx.validationProofsList.map { it.domain() }, - timestamp = Timestamp.fromUtcTimestamp(tx.timestamp), + timestamp = Timestamp(tx.timestamp), atomicBadge = null, - proofs = tx.proofsList.let { dtoProofs -> - dtoProofs.map { - Signature(it.byteArray()) - } - }, + proofs = tx.proofsList.map { Signature(it.byteArray()) }, senderAddress = Address(tx.senderAddress.byteArray()), version = version, ) diff --git a/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/GenesisPermitTxMapper.kt b/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/GenesisPermitTxMapper.kt index e5c52339..ffae7465 100644 --- a/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/GenesisPermitTxMapper.kt +++ b/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/GenesisPermitTxMapper.kt @@ -1,10 +1,35 @@ package com.wavesenterprise.sdk.node.client.grpc.mapper.tx +import com.wavesenterprise.sdk.node.client.grpc.mapper.GrpcTypesMapper.byteArray +import com.wavesenterprise.sdk.node.client.grpc.mapper.RoleMapper.domain +import com.wavesenterprise.sdk.node.domain.Address +import com.wavesenterprise.sdk.node.domain.Fee +import com.wavesenterprise.sdk.node.domain.Signature +import com.wavesenterprise.sdk.node.domain.Timestamp +import com.wavesenterprise.sdk.node.domain.TxId +import com.wavesenterprise.sdk.node.domain.TxVersion import com.wavesenterprise.sdk.node.domain.tx.GenesisPermitTx import com.wavesenterprise.transaction.protobuf.GenesisPermitTransactionOuterClass.GenesisPermitTransaction object GenesisPermitTxMapper { + fun dtoInternal(tx: GenesisPermitTx): GenesisPermitTransaction { TODO("Not yet implemented") } + + @JvmStatic + fun GenesisPermitTransaction.domain(version: TxVersion): GenesisPermitTx = + domainInternal(this, version) + + @JvmStatic + internal fun domainInternal(tx: GenesisPermitTransaction, version: TxVersion): GenesisPermitTx = + GenesisPermitTx( + id = TxId(tx.id.byteArray()), + target = Address(tx.target.byteArray()), + role = tx.role.domain(), + fee = Fee(tx.fee), + timestamp = Timestamp.fromUtcTimestamp(tx.timestamp), + version = version, + signature = Signature(tx.signature.byteArray()), + ) } diff --git a/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/GenesisRegisterNodeTxMapper.kt b/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/GenesisRegisterNodeTxMapper.kt index fcda1844..f98775f4 100644 --- a/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/GenesisRegisterNodeTxMapper.kt +++ b/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/GenesisRegisterNodeTxMapper.kt @@ -1,10 +1,33 @@ package com.wavesenterprise.sdk.node.client.grpc.mapper.tx +import com.wavesenterprise.sdk.node.client.grpc.mapper.GrpcTypesMapper.byteArray +import com.wavesenterprise.sdk.node.domain.Fee +import com.wavesenterprise.sdk.node.domain.PublicKey +import com.wavesenterprise.sdk.node.domain.Signature +import com.wavesenterprise.sdk.node.domain.Timestamp +import com.wavesenterprise.sdk.node.domain.TxId +import com.wavesenterprise.sdk.node.domain.TxVersion import com.wavesenterprise.sdk.node.domain.tx.GenesisRegisterNodeTx import com.wavesenterprise.transaction.protobuf.GenesisRegisterNodeTransactionOuterClass.GenesisRegisterNodeTransaction object GenesisRegisterNodeTxMapper { + fun dtoInternal(tx: GenesisRegisterNodeTx): GenesisRegisterNodeTransaction { TODO("Not yet implemented") } + + @JvmStatic + fun GenesisRegisterNodeTransaction.domain(version: TxVersion): GenesisRegisterNodeTx = + domainInternal(this, version) + + @JvmStatic + internal fun domainInternal(tx: GenesisRegisterNodeTransaction, version: TxVersion): GenesisRegisterNodeTx = + GenesisRegisterNodeTx( + id = TxId(tx.id.byteArray()), + targetPublicKey = PublicKey(tx.targetPublicKey.byteArray()), + fee = Fee(tx.fee), + timestamp = Timestamp.fromUtcTimestamp(tx.timestamp), + version = version, + signature = Signature(tx.signature.byteArray()), + ) } diff --git a/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/GenesisTxMapper.kt b/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/GenesisTxMapper.kt index eb736a07..b050e2d6 100644 --- a/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/GenesisTxMapper.kt +++ b/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/GenesisTxMapper.kt @@ -1,10 +1,35 @@ package com.wavesenterprise.sdk.node.client.grpc.mapper.tx +import com.wavesenterprise.sdk.node.client.grpc.mapper.GrpcTypesMapper.byteArray +import com.wavesenterprise.sdk.node.domain.Address +import com.wavesenterprise.sdk.node.domain.Amount +import com.wavesenterprise.sdk.node.domain.Fee +import com.wavesenterprise.sdk.node.domain.Signature +import com.wavesenterprise.sdk.node.domain.Timestamp +import com.wavesenterprise.sdk.node.domain.TxId +import com.wavesenterprise.sdk.node.domain.TxVersion import com.wavesenterprise.sdk.node.domain.tx.GenesisTx import com.wavesenterprise.transaction.protobuf.GenesisTransactionOuterClass.GenesisTransaction object GenesisTxMapper { + fun dtoInternal(tx: GenesisTx): GenesisTransaction { TODO("Not yet implemented") } + + @JvmStatic + fun GenesisTransaction.domain(version: TxVersion): GenesisTx = + domainInternal(this, version) + + @JvmStatic + internal fun domainInternal(tx: GenesisTransaction, version: TxVersion): GenesisTx = + GenesisTx( + id = TxId(tx.id.byteArray()), + amount = Amount(tx.amount), + fee = Fee(tx.fee), + timestamp = Timestamp.fromUtcTimestamp(tx.timestamp), + version = version, + recipient = Address(tx.recipient.byteArray()), + signature = Signature(tx.signature.byteArray()), + ) } diff --git a/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/IssueTxMapper.kt b/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/IssueTxMapper.kt index 347371b2..3b177f6e 100644 --- a/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/IssueTxMapper.kt +++ b/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/IssueTxMapper.kt @@ -1,10 +1,49 @@ package com.wavesenterprise.sdk.node.client.grpc.mapper.tx +import com.wavesenterprise.sdk.node.client.grpc.mapper.GrpcTypesMapper.byteArray +import com.wavesenterprise.sdk.node.domain.Address +import com.wavesenterprise.sdk.node.domain.ChainId +import com.wavesenterprise.sdk.node.domain.Decimals +import com.wavesenterprise.sdk.node.domain.Fee +import com.wavesenterprise.sdk.node.domain.IssueTxDescription +import com.wavesenterprise.sdk.node.domain.IssueTxName +import com.wavesenterprise.sdk.node.domain.PublicKey +import com.wavesenterprise.sdk.node.domain.Quantity +import com.wavesenterprise.sdk.node.domain.Reissuable +import com.wavesenterprise.sdk.node.domain.Script +import com.wavesenterprise.sdk.node.domain.Signature +import com.wavesenterprise.sdk.node.domain.Timestamp +import com.wavesenterprise.sdk.node.domain.TxId +import com.wavesenterprise.sdk.node.domain.TxVersion import com.wavesenterprise.sdk.node.domain.tx.IssueTx import com.wavesenterprise.transaction.protobuf.assets.IssueTransaction +import com.wavesenterprise.transaction.protobuf.assets.scriptOrNull object IssueTxMapper { fun dtoInternal(tx: IssueTx): IssueTransaction { TODO("Not yet implemented") } + + @JvmStatic + fun IssueTransaction.domain(version: TxVersion): IssueTx = + domainInternal(this, version) + + @JvmStatic + internal fun domainInternal(tx: IssueTransaction, version: TxVersion): IssueTx = + IssueTx( + id = TxId(tx.id.byteArray()), + chainId = ChainId(tx.chainId.toByte()), + senderPublicKey = PublicKey(tx.senderPublicKey.byteArray()), + name = IssueTxName(tx.name.byteArray()), + description = IssueTxDescription(tx.description.byteArray()), + quantity = Quantity(tx.quantity), + decimals = Decimals(tx.decimals.toByte()), + reissuable = Reissuable(tx.reissuable), + fee = Fee(tx.fee), + timestamp = Timestamp.fromUtcTimestamp(tx.timestamp), + script = tx.scriptOrNull?.let { Script(it.value.byteArray()) }, + proofs = tx.proofsList?.map { Signature(it.byteArray()) }, + senderAddress = Address(tx.senderAddress.byteArray()), + version = version, + ) } diff --git a/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/LeaseCancelTxMapper.kt b/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/LeaseCancelTxMapper.kt index b0a14d03..15cd5f6e 100644 --- a/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/LeaseCancelTxMapper.kt +++ b/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/LeaseCancelTxMapper.kt @@ -1,10 +1,41 @@ package com.wavesenterprise.sdk.node.client.grpc.mapper.tx +import com.wavesenterprise.sdk.node.client.grpc.mapper.GrpcTypesMapper.byteArray +import com.wavesenterprise.sdk.node.domain.Address +import com.wavesenterprise.sdk.node.domain.ChainId +import com.wavesenterprise.sdk.node.domain.Fee +import com.wavesenterprise.sdk.node.domain.LeaseId +import com.wavesenterprise.sdk.node.domain.PublicKey +import com.wavesenterprise.sdk.node.domain.Signature +import com.wavesenterprise.sdk.node.domain.Timestamp +import com.wavesenterprise.sdk.node.domain.TxId +import com.wavesenterprise.sdk.node.domain.TxVersion import com.wavesenterprise.sdk.node.domain.tx.LeaseCancelTx import com.wavesenterprise.transaction.protobuf.lease.LeaseCancelTransaction object LeaseCancelTxMapper { + fun dtoInternal(tx: LeaseCancelTx): LeaseCancelTransaction { TODO("Not yet implemented") } + + @JvmStatic + fun LeaseCancelTransaction.domain(version: TxVersion): LeaseCancelTx = + domainInternal(this, version) + + @JvmStatic + internal fun domainInternal(tx: LeaseCancelTransaction, version: TxVersion): LeaseCancelTx = + LeaseCancelTx( + id = TxId(tx.id.byteArray()), + chainId = ChainId(tx.chainId.toByte()), + senderPublicKey = PublicKey(tx.senderPublicKey.byteArray()), + fee = Fee(tx.fee), + timestamp = Timestamp.fromUtcTimestamp(tx.timestamp), + leaseId = LeaseId( + txId = TxId(tx.leaseId.byteArray()) + ), + proofs = tx.proofsList?.map { Signature(it.byteArray()) }, + senderAddress = Address(tx.senderAddress.byteArray()), + version = version, + ) } diff --git a/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/LeaseTxMapper.kt b/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/LeaseTxMapper.kt index 35c1cc9c..76d9a6d8 100644 --- a/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/LeaseTxMapper.kt +++ b/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/LeaseTxMapper.kt @@ -1,10 +1,40 @@ package com.wavesenterprise.sdk.node.client.grpc.mapper.tx +import com.wavesenterprise.sdk.node.client.grpc.mapper.GrpcTypesMapper.byteArray +import com.wavesenterprise.sdk.node.domain.Address +import com.wavesenterprise.sdk.node.domain.Amount +import com.wavesenterprise.sdk.node.domain.AssetId +import com.wavesenterprise.sdk.node.domain.Fee +import com.wavesenterprise.sdk.node.domain.PublicKey +import com.wavesenterprise.sdk.node.domain.Signature +import com.wavesenterprise.sdk.node.domain.Timestamp +import com.wavesenterprise.sdk.node.domain.TxId +import com.wavesenterprise.sdk.node.domain.TxVersion import com.wavesenterprise.sdk.node.domain.tx.LeaseTx import com.wavesenterprise.transaction.protobuf.lease.LeaseTransaction +import com.wavesenterprise.transaction.protobuf.lease.assetIdOrNull object LeaseTxMapper { fun dtoInternal(tx: LeaseTx): LeaseTransaction { TODO("Not yet implemented") } + + @JvmStatic + fun LeaseTransaction.domain(version: TxVersion): LeaseTx = + domainInternal(this, version) + + @JvmStatic + internal fun domainInternal(tx: LeaseTransaction, version: TxVersion): LeaseTx = + LeaseTx( + id = TxId(tx.id.byteArray()), + assetId = tx.assetIdOrNull?.let { AssetId(it.value.byteArray()) }, + senderPublicKey = PublicKey(tx.senderPublicKey.toByteArray()), + recipient = Address(tx.recipient.byteArray()), + amount = Amount(tx.amount), + fee = Fee(tx.fee), + timestamp = Timestamp.fromUtcTimestamp(tx.timestamp), + proofs = tx.proofsList?.map { Signature(it.byteArray()) }, + senderAddress = Address(tx.senderAddress.toByteArray()), + version = version, + ) } diff --git a/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/MassTransferTxMapper.kt b/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/MassTransferTxMapper.kt index b6f38415..f5fb6635 100644 --- a/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/MassTransferTxMapper.kt +++ b/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/MassTransferTxMapper.kt @@ -1,10 +1,50 @@ package com.wavesenterprise.sdk.node.client.grpc.mapper.tx +import com.wavesenterprise.sdk.node.client.grpc.mapper.AtomicBadgeMapper.domain +import com.wavesenterprise.sdk.node.client.grpc.mapper.GrpcTypesMapper.byteArray +import com.wavesenterprise.sdk.node.client.grpc.mapper.TransferMapper.domain +import com.wavesenterprise.sdk.node.domain.Address +import com.wavesenterprise.sdk.node.domain.AssetId +import com.wavesenterprise.sdk.node.domain.Attachment +import com.wavesenterprise.sdk.node.domain.Fee +import com.wavesenterprise.sdk.node.domain.FeeAssetId +import com.wavesenterprise.sdk.node.domain.PublicKey +import com.wavesenterprise.sdk.node.domain.Signature +import com.wavesenterprise.sdk.node.domain.Timestamp +import com.wavesenterprise.sdk.node.domain.TxId +import com.wavesenterprise.sdk.node.domain.TxVersion import com.wavesenterprise.sdk.node.domain.tx.MassTransferTx import com.wavesenterprise.transaction.protobuf.transfer.MassTransferTransaction +import com.wavesenterprise.transaction.protobuf.transfer.assetIdOrNull +import com.wavesenterprise.transaction.protobuf.transfer.feeAssetIdOrNull object MassTransferTxMapper { + fun dtoInternal(tx: MassTransferTx): MassTransferTransaction { TODO("Not yet implemented") } + + @JvmStatic + fun MassTransferTransaction.domain(version: TxVersion): MassTransferTx = + domainInternal(this, version) + + @JvmStatic + internal fun domainInternal(tx: MassTransferTransaction, version: TxVersion): MassTransferTx = + MassTransferTx( + id = TxId(tx.id.byteArray()), + senderPublicKey = PublicKey(tx.senderPublicKey.byteArray()), + assetId = tx.assetIdOrNull?.let { AssetId(it.value.byteArray()) }, + transfers = tx.transfersList.map { it.domain() }, + feeAssetId = tx.feeAssetIdOrNull?.let { + FeeAssetId( + txId = TxId(it.value.byteArray()), + ) + }, + timestamp = Timestamp(tx.timestamp), + fee = Fee(tx.fee), + attachment = Attachment(tx.attachment.byteArray()), + proofs = tx.proofsList?.map { Signature(it.byteArray()) }, + senderAddress = Address(tx.senderAddress.byteArray()), + version = version, + ) } diff --git a/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/PermitTxMapper.kt b/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/PermitTxMapper.kt index b8f21e6a..f14f6ee1 100644 --- a/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/PermitTxMapper.kt +++ b/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/PermitTxMapper.kt @@ -51,16 +51,14 @@ object PermitTxMapper { internal fun domainInternal(tx: PermitTransaction, version: TxVersion): PermitTx = PermitTx( id = TxId(tx.id.byteArray()), - senderPublicKey = PublicKey(tx.senderPublicKey.toByteArray()), + senderPublicKey = PublicKey(tx.senderPublicKey.byteArray()), target = Address(tx.target.byteArray()), - timestamp = Timestamp.fromUtcTimestamp(tx.timestamp), + timestamp = Timestamp(tx.timestamp), fee = Fee(tx.fee), permissionOp = tx.permissionOp.domain(), atomicBadge = tx.atomicBadgeOrNull?.domain(), - proofs = tx.proofsList?.let { dtoProofs -> - dtoProofs.map { - Signature(it.byteArray()) - } + proofs = tx.proofsList?.map { + Signature(it.byteArray()) }, senderAddress = Address(tx.senderAddress.byteArray()), version = version, diff --git a/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/PolicyDataHashTxMapper.kt b/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/PolicyDataHashTxMapper.kt index b5a48f38..0022869d 100644 --- a/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/PolicyDataHashTxMapper.kt +++ b/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/PolicyDataHashTxMapper.kt @@ -57,20 +57,20 @@ object PolicyDataHashTxMapper { internal fun domainInternal(tx: PolicyDataHashTransaction, version: TxVersion): PolicyDataHashTx = PolicyDataHashTx( id = TxId(tx.id.byteArray()), - senderPublicKey = PublicKey(tx.senderPublicKey.toByteArray()), + senderPublicKey = PublicKey(tx.senderPublicKey.byteArray()), dataHash = Hash(tx.dataHash.byteArray()), - policyId = PolicyId.fromByteArray(tx.policyId.byteArray()), - timestamp = Timestamp.fromUtcTimestamp(tx.timestamp), + policyId = PolicyId( + txId = TxId(tx.policyId.byteArray()) + ), + timestamp = Timestamp(tx.timestamp), fee = Fee(tx.fee), feeAssetId = tx.feeAssetIdOrNull?.let { - FeeAssetId.fromByteArray(it.byteArray()) + FeeAssetId( + txId = TxId(it.value.byteArray()) + ) }, atomicBadge = tx.atomicBadgeOrNull?.domain(), - proofs = tx.proofsList?.let { dtoProofs -> - dtoProofs.map { - Signature(it.byteArray()) - } - }, + proofs = tx.proofsList?.map { Signature(it.byteArray()) }, senderAddress = Address(tx.senderAddress.byteArray()), version = version, ) diff --git a/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/RegisterNodeTxMapper.kt b/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/RegisterNodeTxMapper.kt index 4ed3e969..feb79032 100644 --- a/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/RegisterNodeTxMapper.kt +++ b/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/RegisterNodeTxMapper.kt @@ -1,10 +1,41 @@ package com.wavesenterprise.sdk.node.client.grpc.mapper.tx +import com.wavesenterprise.sdk.node.client.grpc.mapper.GrpcTypesMapper.byteArray +import com.wavesenterprise.sdk.node.client.grpc.mapper.OpTypeMapper.domain +import com.wavesenterprise.sdk.node.domain.Address +import com.wavesenterprise.sdk.node.domain.Fee +import com.wavesenterprise.sdk.node.domain.NodeName +import com.wavesenterprise.sdk.node.domain.PublicKey +import com.wavesenterprise.sdk.node.domain.Signature +import com.wavesenterprise.sdk.node.domain.Timestamp +import com.wavesenterprise.sdk.node.domain.TxId +import com.wavesenterprise.sdk.node.domain.TxVersion import com.wavesenterprise.sdk.node.domain.tx.RegisterNodeTx import com.wavesenterprise.transaction.protobuf.RegisterNodeTransaction +import com.wavesenterprise.transaction.protobuf.nodeNameOrNull object RegisterNodeTxMapper { + fun dtoInternal(tx: RegisterNodeTx): RegisterNodeTransaction { TODO("Not yet implemented") } + + @JvmStatic + fun RegisterNodeTransaction.domain(version: TxVersion): RegisterNodeTx = + domainInternal(this, version) + + @JvmStatic + internal fun domainInternal(tx: RegisterNodeTransaction, version: TxVersion): RegisterNodeTx = + RegisterNodeTx( + id = TxId(tx.id.byteArray()), + senderPublicKey = PublicKey(tx.senderPublicKey.byteArray()), + targetPublicKey = PublicKey(tx.target.byteArray()), + nodeName = tx.nodeNameOrNull?.let { NodeName(it.value) }, + opType = tx.opType.domain(), + timestamp = Timestamp.fromUtcTimestamp(tx.timestamp), + fee = Fee(tx.fee), + proofs = tx.proofsList?.map { Signature(it.byteArray()) }, + senderAddress = Address(tx.senderAddress.byteArray()), + version = version, + ) } diff --git a/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/ReissueTxMapper.kt b/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/ReissueTxMapper.kt index 906ecc90..40190489 100644 --- a/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/ReissueTxMapper.kt +++ b/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/ReissueTxMapper.kt @@ -1,10 +1,43 @@ package com.wavesenterprise.sdk.node.client.grpc.mapper.tx +import com.wavesenterprise.sdk.node.client.grpc.mapper.GrpcTypesMapper.byteArray +import com.wavesenterprise.sdk.node.domain.Address +import com.wavesenterprise.sdk.node.domain.AssetId +import com.wavesenterprise.sdk.node.domain.ChainId +import com.wavesenterprise.sdk.node.domain.Fee +import com.wavesenterprise.sdk.node.domain.PublicKey +import com.wavesenterprise.sdk.node.domain.Quantity +import com.wavesenterprise.sdk.node.domain.Reissuable +import com.wavesenterprise.sdk.node.domain.Signature +import com.wavesenterprise.sdk.node.domain.Timestamp +import com.wavesenterprise.sdk.node.domain.TxId +import com.wavesenterprise.sdk.node.domain.TxVersion import com.wavesenterprise.sdk.node.domain.tx.ReissueTx import com.wavesenterprise.transaction.protobuf.assets.ReissueTransaction object ReissueTxMapper { + fun dtoInternal(tx: ReissueTx): ReissueTransaction { TODO("Not yet implemented") } + + @JvmStatic + fun ReissueTransaction.domain(version: TxVersion): ReissueTx = + domainInternal(this, version) + + @JvmStatic + internal fun domainInternal(tx: ReissueTransaction, version: TxVersion): ReissueTx = + ReissueTx( + id = TxId(tx.id.byteArray()), + chainId = ChainId(tx.chainId.toByte()), + senderPublicKey = PublicKey(tx.senderPublicKey.byteArray()), + assetId = AssetId(tx.assetId.byteArray()), + quantity = Quantity(tx.quantity), + reissuable = Reissuable(tx.reissuable), + fee = Fee(tx.fee), + timestamp = Timestamp(tx.timestamp), + proofs = tx.proofsList?.map { Signature(it.byteArray()) }, + senderAddress = Address(tx.senderAddress.byteArray()), + version = version, + ) } diff --git a/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/SetAssetScriptTxMapper.kt b/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/SetAssetScriptTxMapper.kt index 798286bf..0a5a3499 100644 --- a/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/SetAssetScriptTxMapper.kt +++ b/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/SetAssetScriptTxMapper.kt @@ -1,10 +1,42 @@ package com.wavesenterprise.sdk.node.client.grpc.mapper.tx +import com.wavesenterprise.sdk.node.client.grpc.mapper.GrpcTypesMapper.byteArray +import com.wavesenterprise.sdk.node.domain.Address +import com.wavesenterprise.sdk.node.domain.AssetId +import com.wavesenterprise.sdk.node.domain.ChainId +import com.wavesenterprise.sdk.node.domain.Fee +import com.wavesenterprise.sdk.node.domain.PublicKey +import com.wavesenterprise.sdk.node.domain.Script +import com.wavesenterprise.sdk.node.domain.Signature +import com.wavesenterprise.sdk.node.domain.Timestamp +import com.wavesenterprise.sdk.node.domain.TxId +import com.wavesenterprise.sdk.node.domain.TxVersion import com.wavesenterprise.sdk.node.domain.tx.SetAssetScriptTx import com.wavesenterprise.transaction.protobuf.assets.SetAssetScriptTransaction +import com.wavesenterprise.transaction.protobuf.assets.scriptOrNull object SetAssetScriptTxMapper { + fun dtoInternal(tx: SetAssetScriptTx): SetAssetScriptTransaction { TODO("Not yet implemented") } + + @JvmStatic + fun SetAssetScriptTransaction.domain(version: TxVersion): SetAssetScriptTx = + domainInternal(this, version) + + @JvmStatic + internal fun domainInternal(tx: SetAssetScriptTransaction, version: TxVersion): SetAssetScriptTx = + SetAssetScriptTx( + id = TxId(tx.id.byteArray()), + chainId = ChainId(tx.chainId.toByte()), + senderPublicKey = PublicKey(tx.senderPublicKey.byteArray()), + assetId = AssetId(tx.assetId.byteArray()), + script = tx.scriptOrNull?.let { Script(it.value.byteArray()) }, + fee = Fee(tx.fee), + timestamp = Timestamp(tx.timestamp), + proofs = tx.proofsList?.map { Signature(it.byteArray()) }, + senderAddress = Address(tx.senderAddress.byteArray()), + version = version, + ) } diff --git a/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/SetScriptTxMapper.kt b/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/SetScriptTxMapper.kt index 0e48bb7e..dba84f1c 100644 --- a/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/SetScriptTxMapper.kt +++ b/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/SetScriptTxMapper.kt @@ -1,10 +1,45 @@ package com.wavesenterprise.sdk.node.client.grpc.mapper.tx +import com.wavesenterprise.sdk.node.client.grpc.mapper.GrpcTypesMapper.byteArray +import com.wavesenterprise.sdk.node.domain.Address +import com.wavesenterprise.sdk.node.domain.ChainId +import com.wavesenterprise.sdk.node.domain.Fee +import com.wavesenterprise.sdk.node.domain.PublicKey +import com.wavesenterprise.sdk.node.domain.Script +import com.wavesenterprise.sdk.node.domain.ScriptDescription +import com.wavesenterprise.sdk.node.domain.ScriptName +import com.wavesenterprise.sdk.node.domain.Signature +import com.wavesenterprise.sdk.node.domain.Timestamp +import com.wavesenterprise.sdk.node.domain.TxId +import com.wavesenterprise.sdk.node.domain.TxVersion import com.wavesenterprise.sdk.node.domain.tx.SetScriptTx +import com.wavesenterprise.transaction.protobuf.assets.scriptOrNull import com.wavesenterprise.transaction.protobuf.smart.SetScriptTransaction +import com.wavesenterprise.transaction.protobuf.smart.scriptOrNull object SetScriptTxMapper { + fun dtoInternal(tx: SetScriptTx): SetScriptTransaction { TODO("Not yet implemented") } + + @JvmStatic + fun SetScriptTransaction.domain(version: TxVersion): SetScriptTx = + domainInternal(this, version) + + @JvmStatic + internal fun domainInternal(tx: SetScriptTransaction, version: TxVersion): SetScriptTx = + SetScriptTx( + id = TxId(tx.id.byteArray()), + chainId = ChainId(tx.chainId.toByte()), + senderPublicKey = PublicKey(tx.senderPublicKey.byteArray()), + script = tx.scriptOrNull?.let { Script(it.value.byteArray()) }, + name = ScriptName(tx.name.byteArray()), + description = ScriptDescription(tx.description.byteArray()), + fee = Fee(tx.fee), + timestamp = Timestamp(tx.timestamp), + proofs = tx.proofsList?.map { Signature(it.byteArray()) }, + senderAddress = Address(tx.senderAddress.byteArray()), + version = version, + ) } diff --git a/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/SponsorFeeTxMapper.kt b/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/SponsorFeeTxMapper.kt index ca673edc..2a797596 100644 --- a/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/SponsorFeeTxMapper.kt +++ b/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/SponsorFeeTxMapper.kt @@ -1,10 +1,39 @@ package com.wavesenterprise.sdk.node.client.grpc.mapper.tx +import com.wavesenterprise.sdk.node.client.grpc.mapper.GrpcTypesMapper.byteArray +import com.wavesenterprise.sdk.node.domain.Address +import com.wavesenterprise.sdk.node.domain.AssetId +import com.wavesenterprise.sdk.node.domain.Enabled +import com.wavesenterprise.sdk.node.domain.Fee +import com.wavesenterprise.sdk.node.domain.PublicKey +import com.wavesenterprise.sdk.node.domain.Signature +import com.wavesenterprise.sdk.node.domain.Timestamp +import com.wavesenterprise.sdk.node.domain.TxId +import com.wavesenterprise.sdk.node.domain.TxVersion import com.wavesenterprise.sdk.node.domain.tx.SponsorFeeTx import com.wavesenterprise.transaction.protobuf.assets.SponsorFeeTransaction object SponsorFeeTxMapper { + fun dtoInternal(tx: SponsorFeeTx): SponsorFeeTransaction { TODO("Not yet implemented") } + + @JvmStatic + fun SponsorFeeTransaction.domain(version: TxVersion): SponsorFeeTx = + domainInternal(this, version) + + @JvmStatic + internal fun domainInternal(tx: SponsorFeeTransaction, version: TxVersion): SponsorFeeTx = + SponsorFeeTx( + id = TxId(tx.id.byteArray()), + assetId = AssetId(tx.assetId.byteArray()), + enabled = Enabled(tx.isEnabled), + senderPublicKey = PublicKey(tx.senderPublicKey.byteArray()), + fee = Fee(tx.fee), + timestamp = Timestamp(tx.timestamp), + proofs = tx.proofsList?.map { Signature(it.byteArray()) }, + senderAddress = Address(tx.senderAddress.byteArray()), + version = version, + ) } diff --git a/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/TransferTxMapper.kt b/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/TransferTxMapper.kt index b8e1f5d7..e2d59ddb 100644 --- a/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/TransferTxMapper.kt +++ b/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/TransferTxMapper.kt @@ -14,6 +14,7 @@ import com.wavesenterprise.sdk.node.client.grpc.mapper.Util.setIfNotNull import com.wavesenterprise.sdk.node.domain.Address import com.wavesenterprise.sdk.node.domain.Amount import com.wavesenterprise.sdk.node.domain.AssetId +import com.wavesenterprise.sdk.node.domain.Attachment import com.wavesenterprise.sdk.node.domain.Fee import com.wavesenterprise.sdk.node.domain.FeeAssetId import com.wavesenterprise.sdk.node.domain.PublicKey @@ -23,6 +24,7 @@ import com.wavesenterprise.sdk.node.domain.TxId import com.wavesenterprise.sdk.node.domain.TxVersion import com.wavesenterprise.sdk.node.domain.tx.TransferTx import com.wavesenterprise.transaction.protobuf.transfer.TransferTransaction +import com.wavesenterprise.transaction.protobuf.transfer.assetIdOrNull import com.wavesenterprise.transaction.protobuf.transfer.atomicBadgeOrNull import com.wavesenterprise.transaction.protobuf.transfer.feeAssetIdOrNull import com.wavesenterprise.transaction.protobuf.transfer.transferTransaction @@ -59,21 +61,20 @@ object TransferTxMapper { internal fun domainInternal(tx: TransferTransaction, version: TxVersion): TransferTx = TransferTx( id = TxId(tx.id.byteArray()), - senderPublicKey = PublicKey(tx.senderPublicKey.toByteArray()), - assetId = tx.assetId?.let { AssetId(it.byteArray()) }, + senderPublicKey = PublicKey(tx.senderPublicKey.byteArray()), + assetId = tx.assetIdOrNull?.let { AssetId(it.value.byteArray()) }, feeAssetId = tx.feeAssetIdOrNull?.let { - FeeAssetId.fromByteArray(it.byteArray()) + FeeAssetId( + txId = TxId(it.value.byteArray()), + ) }, - timestamp = Timestamp.fromUtcTimestamp(tx.timestamp), + timestamp = Timestamp(tx.timestamp), amount = Amount(tx.amount), fee = Fee(tx.fee), recipient = Address(tx.recipient.byteArray()), + attachment = Attachment(tx.attachment.byteArray()), atomicBadge = tx.atomicBadgeOrNull?.domain(), - proofs = tx.proofsList?.let { dtoProofs -> - dtoProofs.map { - Signature(it.byteArray()) - } - }, + proofs = tx.proofsList?.map { Signature(it.byteArray()) }, senderAddress = Address(tx.senderAddress.byteArray()), version = version, ) diff --git a/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/TxMapper.kt b/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/TxMapper.kt index 3fd12975..3c818222 100644 --- a/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/TxMapper.kt +++ b/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/TxMapper.kt @@ -3,13 +3,28 @@ package com.wavesenterprise.sdk.node.client.grpc.mapper.tx import com.wavesenterprise.sdk.node.client.grpc.mapper.tx.AtomicTxMapper.domain import com.wavesenterprise.sdk.node.client.grpc.mapper.tx.BurnTxMapper.domain import com.wavesenterprise.sdk.node.client.grpc.mapper.tx.CallContractTxMapper.domain +import com.wavesenterprise.sdk.node.client.grpc.mapper.tx.CreateAliasTxMapper.domain import com.wavesenterprise.sdk.node.client.grpc.mapper.tx.CreateContractTxMapper.domain import com.wavesenterprise.sdk.node.client.grpc.mapper.tx.CreatePolicyTxMapper.domain +import com.wavesenterprise.sdk.node.client.grpc.mapper.tx.DataTxMapper.domain import com.wavesenterprise.sdk.node.client.grpc.mapper.tx.DisableContractTxMapper.domain import com.wavesenterprise.sdk.node.client.grpc.mapper.tx.ExecutedContractTxMapper.domain +import com.wavesenterprise.sdk.node.client.grpc.mapper.tx.GenesisPermitTxMapper.domain +import com.wavesenterprise.sdk.node.client.grpc.mapper.tx.GenesisRegisterNodeTxMapper.domain +import com.wavesenterprise.sdk.node.client.grpc.mapper.tx.GenesisTxMapper.domain +import com.wavesenterprise.sdk.node.client.grpc.mapper.tx.IssueTxMapper.domain +import com.wavesenterprise.sdk.node.client.grpc.mapper.tx.LeaseCancelTxMapper.domain +import com.wavesenterprise.sdk.node.client.grpc.mapper.tx.LeaseTxMapper.domain +import com.wavesenterprise.sdk.node.client.grpc.mapper.tx.MassTransferTxMapper.domain import com.wavesenterprise.sdk.node.client.grpc.mapper.tx.PermitTxMapper.domain import com.wavesenterprise.sdk.node.client.grpc.mapper.tx.PolicyDataHashTxMapper.domain +import com.wavesenterprise.sdk.node.client.grpc.mapper.tx.RegisterNodeTxMapper.domain +import com.wavesenterprise.sdk.node.client.grpc.mapper.tx.ReissueTxMapper.domain +import com.wavesenterprise.sdk.node.client.grpc.mapper.tx.SetAssetScriptTxMapper.domain +import com.wavesenterprise.sdk.node.client.grpc.mapper.tx.SetScriptTxMapper.domain +import com.wavesenterprise.sdk.node.client.grpc.mapper.tx.SponsorFeeTxMapper.domain import com.wavesenterprise.sdk.node.client.grpc.mapper.tx.TransferTxMapper.domain +import com.wavesenterprise.sdk.node.client.grpc.mapper.tx.TxMapper.domain import com.wavesenterprise.sdk.node.client.grpc.mapper.tx.UpdateContractTxMapper.domain import com.wavesenterprise.sdk.node.client.grpc.mapper.tx.UpdatePolicyTxMapper.domain import com.wavesenterprise.sdk.node.domain.TxVersion @@ -87,35 +102,35 @@ object TxMapper { val version = TxVersion(version) return when (transactionCase) { Transaction.TransactionCase.GENESIS_TRANSACTION, - -> TODO("Not yet implemented") + -> genesisTransaction.domain(version) Transaction.TransactionCase.GENESIS_PERMIT_TRANSACTION, -> TODO("Not yet implemented") Transaction.TransactionCase.GENESIS_REGISTER_NODE_TRANSACTION, - -> TODO("Not yet implemented") + -> genesisRegisterNodeTransaction.domain(version) Transaction.TransactionCase.REGISTER_NODE_TRANSACTION, - -> TODO("Not yet implemented") + -> registerNodeTransaction.domain(version) Transaction.TransactionCase.CREATE_ALIAS_TRANSACTION, - -> TODO("Not yet implemented") + -> createAliasTransaction.domain(version) Transaction.TransactionCase.ISSUE_TRANSACTION, - -> TODO("Not yet implemented") + -> issueTransaction.domain(version) Transaction.TransactionCase.REISSUE_TRANSACTION, - -> TODO("Not yet implemented") + -> reissueTransaction.domain(version) Transaction.TransactionCase.BURN_TRANSACTION, -> burnTransaction.domain(version) Transaction.TransactionCase.LEASE_TRANSACTION, - -> TODO("Not yet implemented") + -> leaseTransaction.domain(version) Transaction.TransactionCase.LEASE_CANCEL_TRANSACTION, - -> TODO("Not yet implemented") + -> leaseCancelTransaction.domain(version) Transaction.TransactionCase.SPONSOR_FEE_TRANSACTION, - -> TODO("Not yet implemented") + -> sponsorFeeTransaction.domain(version) Transaction.TransactionCase.SET_ASSET_SCRIPT_TRANSACTION, - -> TODO("Not yet implemented") + -> setAssetScriptTransaction.domain(version) Transaction.TransactionCase.DATA_TRANSACTION, - -> TODO("Not yet implemented") + -> dataTransaction.domain(version) Transaction.TransactionCase.TRANSFER_TRANSACTION, -> transferTransaction.domain(version) Transaction.TransactionCase.MASS_TRANSFER_TRANSACTION, - -> TODO("Not yet implemented") + -> massTransferTransaction.domain(version) Transaction.TransactionCase.PERMIT_TRANSACTION, -> permitTransaction.domain(version) Transaction.TransactionCase.CREATE_POLICY_TRANSACTION, @@ -135,7 +150,7 @@ object TxMapper { Transaction.TransactionCase.UPDATE_CONTRACT_TRANSACTION, -> updateContractTransaction.domain(version) Transaction.TransactionCase.SET_SCRIPT_TRANSACTION, - -> TODO("Not yet implemented") + -> setScriptTransaction.domain(version) Transaction.TransactionCase.ATOMIC_TRANSACTION, -> atomicTransaction.domain(version) Transaction.TransactionCase.TRANSACTION_NOT_SET, diff --git a/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/UpdateContractTxMapper.kt b/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/UpdateContractTxMapper.kt index 837839a1..6bbca220 100644 --- a/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/UpdateContractTxMapper.kt +++ b/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/UpdateContractTxMapper.kt @@ -3,6 +3,7 @@ package com.wavesenterprise.sdk.node.client.grpc.mapper.tx import com.wavesenterprise.sdk.node.client.grpc.mapper.AddressMapper.byteString import com.wavesenterprise.sdk.node.client.grpc.mapper.AtomicBadgeMapper.domain import com.wavesenterprise.sdk.node.client.grpc.mapper.AtomicBadgeMapper.dto +import com.wavesenterprise.sdk.node.client.grpc.mapper.ContractApiVersionMapper.domain import com.wavesenterprise.sdk.node.client.grpc.mapper.ContractIdMapper.byteString import com.wavesenterprise.sdk.node.client.grpc.mapper.FeeAssetIdMapper.bytesValue import com.wavesenterprise.sdk.node.client.grpc.mapper.GrpcTypesMapper.byteArray @@ -10,6 +11,7 @@ import com.wavesenterprise.sdk.node.client.grpc.mapper.PublicKeyMapper.byteStrin import com.wavesenterprise.sdk.node.client.grpc.mapper.SignatureMapper.byteString import com.wavesenterprise.sdk.node.client.grpc.mapper.TxIdMapper.byteString import com.wavesenterprise.sdk.node.client.grpc.mapper.Util.setIfNotNull +import com.wavesenterprise.sdk.node.client.grpc.mapper.ValidationPolicyMapper.domain import com.wavesenterprise.sdk.node.domain.Address import com.wavesenterprise.sdk.node.domain.Fee import com.wavesenterprise.sdk.node.domain.FeeAssetId @@ -23,9 +25,11 @@ import com.wavesenterprise.sdk.node.domain.contract.ContractImage import com.wavesenterprise.sdk.node.domain.contract.ContractImageHash import com.wavesenterprise.sdk.node.domain.tx.UpdateContractTx import com.wavesenterprise.transaction.protobuf.docker.UpdateContractTransaction +import com.wavesenterprise.transaction.protobuf.docker.apiVersionOrNull import com.wavesenterprise.transaction.protobuf.docker.atomicBadgeOrNull import com.wavesenterprise.transaction.protobuf.docker.feeAssetIdOrNull import com.wavesenterprise.transaction.protobuf.docker.updateContractTransaction +import com.wavesenterprise.transaction.protobuf.docker.validationPolicyOrNull object UpdateContractTxMapper { @JvmStatic @@ -58,21 +62,23 @@ object UpdateContractTxMapper { internal fun domainInternal(tx: UpdateContractTransaction, version: TxVersion): UpdateContractTx = UpdateContractTx( id = TxId(tx.id.byteArray()), - senderPublicKey = PublicKey(tx.senderPublicKey.toByteArray()), - contractId = ContractId.fromByteArray(tx.contractId.toByteArray()), + senderPublicKey = PublicKey(tx.senderPublicKey.byteArray()), + contractId = ContractId( + txId = TxId(tx.contractId.byteArray()) + ), image = ContractImage(tx.image), imageHash = ContractImageHash(tx.imageHash), fee = Fee(tx.fee), - timestamp = Timestamp.fromUtcTimestamp(tx.timestamp), + timestamp = Timestamp(tx.timestamp), feeAssetId = tx.feeAssetIdOrNull?.let { - FeeAssetId.fromByteArray(it.byteArray()) + FeeAssetId( + txId = TxId(it.value.byteArray()) + ) }, atomicBadge = tx.atomicBadgeOrNull?.domain(), - proofs = tx.proofsList?.let { dtoProofs -> - dtoProofs.map { - Signature(it.byteArray()) - } - }, + validationPolicy = tx.validationPolicyOrNull?.domain(), + apiVersion = tx.apiVersionOrNull?.domain(), + proofs = tx.proofsList?.map { Signature(it.byteArray()) }, senderAddress = Address(tx.senderAddress.byteArray()), version = version, ) diff --git a/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/UpdatePolicyTxMapper.kt b/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/UpdatePolicyTxMapper.kt index 9a465ac1..9dd056d5 100644 --- a/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/UpdatePolicyTxMapper.kt +++ b/we-node-client-grpc/we-node-client-grpc-mapper/src/main/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/UpdatePolicyTxMapper.kt @@ -59,22 +59,18 @@ object UpdatePolicyTxMapper { internal fun domainInternal(tx: UpdatePolicyTransaction, version: TxVersion): UpdatePolicyTx = UpdatePolicyTx( id = TxId(tx.id.byteArray()), - senderPublicKey = PublicKey(tx.senderPublicKey.toByteArray()), - policyId = PolicyId.fromByteArray(tx.policyId.byteArray()), + senderPublicKey = PublicKey(tx.senderPublicKey.byteArray()), + policyId = PolicyId( + txId = TxId(tx.policyId.byteArray()) + ), recipients = tx.recipientsList.map { Address(it.byteArray()) }, owners = tx.ownersList.map { Address(it.byteArray()) }, opType = tx.opType.domain(), - timestamp = Timestamp.fromUtcTimestamp(tx.timestamp), + timestamp = Timestamp(tx.timestamp), fee = Fee(tx.fee), - feeAssetId = tx.feeAssetIdOrNull?.let { - FeeAssetId.fromByteArray(it.byteArray()) - }, + feeAssetId = tx.feeAssetIdOrNull?.let { FeeAssetId.fromByteArray(it.byteArray()) }, atomicBadge = tx.atomicBadgeOrNull?.domain(), - proofs = tx.proofsList?.let { dtoProofs -> - dtoProofs.map { - Signature(it.byteArray()) - } - }, + proofs = tx.proofsList?.map { Signature(it.byteArray()) }, senderAddress = Address(tx.senderAddress.byteArray()), version = version, ) diff --git a/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/AtomicInnerTxMapperTest.kt b/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/AtomicInnerTxMapperTest.kt new file mode 100644 index 00000000..be6a0e24 --- /dev/null +++ b/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/AtomicInnerTxMapperTest.kt @@ -0,0 +1,157 @@ +package com.wavesenterprise.sdk.node.client.grpc.mapper.tx + +import com.wavesenterprise.sdk.node.domain.TxVersion +import com.wavesenterprise.transaction.protobuf.acl.permitTransaction +import com.wavesenterprise.transaction.protobuf.atomicInnerTransaction +import com.wavesenterprise.transaction.protobuf.createPolicyTransaction +import com.wavesenterprise.transaction.protobuf.docker.callContractTransaction +import com.wavesenterprise.transaction.protobuf.docker.createContractTransaction +import com.wavesenterprise.transaction.protobuf.docker.disableContractTransaction +import com.wavesenterprise.transaction.protobuf.docker.executedContractTransaction +import com.wavesenterprise.transaction.protobuf.docker.updateContractTransaction +import com.wavesenterprise.transaction.protobuf.policyDataHashTransaction +import com.wavesenterprise.transaction.protobuf.transfer.transferTransaction +import com.wavesenterprise.transaction.protobuf.updatePolicyTransaction +import io.mockk.clearAllMocks +import io.mockk.every +import io.mockk.mockk +import io.mockk.mockkStatic +import io.mockk.verify +import org.junit.jupiter.api.AfterEach +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test + +class AtomicInnerTxMapperTest { + + @BeforeEach + fun beforeEach() { + clearAllMocks() + } + + @AfterEach + fun afterEach() { + clearAllMocks() + } + + private val mockkVersion = 1 + + @Test + fun `should call map to CallContractTx`() { + mockkStatic(CallContractTxMapper::domainInternal) + every { CallContractTxMapper.domainInternal(any(), any()) } returns mockk() + val innerTransaction = callContractTransaction { } + val mockkGrpcTransaction = atomicInnerTransaction { + callContractTransaction = innerTransaction + } + AtomicInnerTxMapper.domainInternal(mockkGrpcTransaction, TxVersion(mockkVersion)) + verify { CallContractTxMapper.domainInternal(innerTransaction, TxVersion(mockkVersion)) } + } + + @Test + fun `should call map to CreateContractTx`() { + mockkStatic(CreateContractTxMapper::domainInternal) + every { CreateContractTxMapper.domainInternal(any(), any()) } returns mockk() + val innerTransaction = createContractTransaction { } + val mockkGrpcTransaction = atomicInnerTransaction { + createContractTransaction = innerTransaction + } + AtomicInnerTxMapper.domainInternal(mockkGrpcTransaction, TxVersion(mockkVersion)) + verify { CreateContractTxMapper.domainInternal(innerTransaction, TxVersion(mockkVersion)) } + } + + @Test + fun `should call map to DisableContractTx`() { + mockkStatic(DisableContractTxMapper::domainInternal) + every { DisableContractTxMapper.domainInternal(any(), any()) } returns mockk() + val innerTransaction = disableContractTransaction { } + val mockkGrpcTransaction = atomicInnerTransaction { + disableContractTransaction = innerTransaction + } + AtomicInnerTxMapper.domainInternal(mockkGrpcTransaction, TxVersion(mockkVersion)) + verify { DisableContractTxMapper.domainInternal(innerTransaction, TxVersion(mockkVersion)) } + } + + @Test + fun `should call map to UpdateContractTx`() { + mockkStatic(UpdateContractTxMapper::domainInternal) + every { UpdateContractTxMapper.domainInternal(any(), any()) } returns mockk() + val innerTransaction = updateContractTransaction { } + val mockkGrpcTransaction = atomicInnerTransaction { + updateContractTransaction = innerTransaction + } + AtomicInnerTxMapper.domainInternal(mockkGrpcTransaction, TxVersion(mockkVersion)) + verify { UpdateContractTxMapper.domainInternal(innerTransaction, TxVersion(mockkVersion)) } + } + + @Test + fun `should call map to ExecutedContractTx`() { + mockkStatic(ExecutedContractTxMapper::domainInternal) + every { ExecutedContractTxMapper.domainInternal(any(), any()) } returns mockk() + val innerTransaction = executedContractTransaction { } + val mockkGrpcTransaction = atomicInnerTransaction { + executedContractTransaction = innerTransaction + } + AtomicInnerTxMapper.domainInternal(mockkGrpcTransaction, TxVersion(mockkVersion)) + verify { ExecutedContractTxMapper.domainInternal(innerTransaction, TxVersion(mockkVersion)) } + } + + @Test + fun `should call map to CreatePolicyTx`() { + mockkStatic(CreatePolicyTxMapper::domainInternal) + every { CreatePolicyTxMapper.domainInternal(any(), any()) } returns mockk() + val innerTransaction = createPolicyTransaction { } + val mockkGrpcTransaction = atomicInnerTransaction { + createPolicyTransaction = innerTransaction + } + AtomicInnerTxMapper.domainInternal(mockkGrpcTransaction, TxVersion(mockkVersion)) + verify { CreatePolicyTxMapper.domainInternal(innerTransaction, TxVersion(mockkVersion)) } + } + + @Test + fun `should call map to PolicyDataHashTx`() { + mockkStatic(PolicyDataHashTxMapper::domainInternal) + every { PolicyDataHashTxMapper.domainInternal(any(), any()) } returns mockk() + val innerTransaction = policyDataHashTransaction { } + val mockkGrpcTransaction = atomicInnerTransaction { + policyDataHashTransaction = innerTransaction + } + AtomicInnerTxMapper.domainInternal(mockkGrpcTransaction, TxVersion(mockkVersion)) + verify { PolicyDataHashTxMapper.domainInternal(innerTransaction, TxVersion(mockkVersion)) } + } + + @Test + fun `should call map to UpdatePolicyTx`() { + mockkStatic(UpdatePolicyTxMapper::domainInternal) + every { UpdatePolicyTxMapper.domainInternal(any(), any()) } returns mockk() + val innerTransaction = updatePolicyTransaction { } + val mockkGrpcTransaction = atomicInnerTransaction { + updatePolicyTransaction = innerTransaction + } + AtomicInnerTxMapper.domainInternal(mockkGrpcTransaction, TxVersion(mockkVersion)) + verify { UpdatePolicyTxMapper.domainInternal(innerTransaction, TxVersion(mockkVersion)) } + } + + @Test + fun `should call map to PermitTx`() { + mockkStatic(PermitTxMapper::domainInternal) + every { PermitTxMapper.domainInternal(any(), any()) } returns mockk() + val innerTransaction = permitTransaction { } + val mockkGrpcTransaction = atomicInnerTransaction { + permitTransaction = innerTransaction + } + AtomicInnerTxMapper.domainInternal(mockkGrpcTransaction, TxVersion(mockkVersion)) + verify { PermitTxMapper.domainInternal(innerTransaction, TxVersion(mockkVersion)) } + } + + @Test + fun `should call map to TransferTx`() { + mockkStatic(TransferTxMapper::domainInternal) + every { TransferTxMapper.domainInternal(any(), any()) } returns mockk() + val innerTransaction = transferTransaction { } + val mockkGrpcTransaction = atomicInnerTransaction { + transferTransaction = innerTransaction + } + AtomicInnerTxMapper.domainInternal(mockkGrpcTransaction, TxVersion(mockkVersion)) + verify { TransferTxMapper.domainInternal(innerTransaction, TxVersion(mockkVersion)) } + } +} diff --git a/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/AtomicTxMapperTest.kt b/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/AtomicTxMapperTest.kt new file mode 100644 index 00000000..93cc0e99 --- /dev/null +++ b/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/AtomicTxMapperTest.kt @@ -0,0 +1,82 @@ +package com.wavesenterprise.sdk.node.client.grpc.mapper.tx + +import com.google.protobuf.bytesValue +import com.wavesenterprise.sdk.node.client.grpc.mapper.GrpcTypesMapper.byteArray +import com.wavesenterprise.sdk.node.client.grpc.mapper.tx.AtomicTxMapper.domain +import com.wavesenterprise.sdk.node.client.grpc.mapper.tx.SetScriptTxMapper.domain +import com.wavesenterprise.sdk.node.domain.Address +import com.wavesenterprise.sdk.node.domain.Fee +import com.wavesenterprise.sdk.node.domain.PublicKey +import com.wavesenterprise.sdk.node.domain.Signature +import com.wavesenterprise.sdk.node.domain.Timestamp +import com.wavesenterprise.sdk.node.domain.TxId +import com.wavesenterprise.sdk.node.domain.TxVersion +import com.wavesenterprise.sdk.node.domain.tx.AtomicTx +import com.wavesenterprise.transaction.protobuf.atomicTransaction +import io.kotest.matchers.shouldBe +import org.junit.jupiter.api.Test + +class AtomicTxMapperTest { + + @Test + fun `should map to AtomicTx (all fields)`() { + val txVersion = TxVersion.fromInt(1) + val grpcTx = atomicTransaction { + id = byteString("DnK5Xfi2wXUJx9BjK9X6ZpFdTLdq2GtWH9pWrcxcmrhB") + miner = bytesValue { + byteString("3N9vL3apA4j2L5PojHW8TYmfHx9Lo2ZaKPB") + } + senderPublicKey = byteString("C4eRfdUFaZMRkfUp91bYr7uMgdBRnUfAxuAjetxmK7KY") + timestamp = 1716881331027L + proofs += byteString( + "2Gns72hraH5yay3eiWeyHQEA1wTqiiAztaLjHinEYX91FEv62HFW38Hq89GnsEJFHUvo9KHYtBBrb8hgTA9wN7DM" + ) + senderAddress = byteString("3N9vL3apA4j2L5PojHW8TYmfHx9Lo2ZaKPB") + } + grpcTx + .domain(txVersion) + .shouldBe( + AtomicTx( + id = TxId(grpcTx.id.byteArray()), + senderPublicKey = PublicKey(grpcTx.senderPublicKey.byteArray()), + miner = Address(grpcTx.miner.value.byteArray()), + txs = listOf(), + fee = Fee(0), + timestamp = Timestamp(grpcTx.timestamp), + proofs = grpcTx.proofsList?.map { Signature(it.byteArray()) }, + senderAddress = Address(grpcTx.senderAddress.byteArray()), + version = txVersion, + ) + ) + } + + @Test + fun `should map to AtomicTx (with nulls)`() { + val txVersion = TxVersion.fromInt(1) + val grpcTx = atomicTransaction { + id = byteString("DnK5Xfi2wXUJx9BjK9X6ZpFdTLdq2GtWH9pWrcxcmrhB") + clearMiner() + senderPublicKey = byteString("C4eRfdUFaZMRkfUp91bYr7uMgdBRnUfAxuAjetxmK7KY") + timestamp = 1716881331027L + proofs += byteString( + "2Gns72hraH5yay3eiWeyHQEA1wTqiiAztaLjHinEYX91FEv62HFW38Hq89GnsEJFHUvo9KHYtBBrb8hgTA9wN7DM" + ) + senderAddress = byteString("3N9vL3apA4j2L5PojHW8TYmfHx9Lo2ZaKPB") + } + grpcTx + .domain(txVersion) + .shouldBe( + AtomicTx( + id = TxId(grpcTx.id.byteArray()), + senderPublicKey = PublicKey(grpcTx.senderPublicKey.byteArray()), + miner = null, + txs = listOf(), + fee = Fee(0), + timestamp = Timestamp(grpcTx.timestamp), + proofs = grpcTx.proofsList?.map { Signature(it.byteArray()) }, + senderAddress = Address(grpcTx.senderAddress.byteArray()), + version = txVersion, + ) + ) + } +} diff --git a/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/BurnTxMapperTest.kt b/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/BurnTxMapperTest.kt new file mode 100644 index 00000000..3a2e52d2 --- /dev/null +++ b/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/BurnTxMapperTest.kt @@ -0,0 +1,55 @@ +package com.wavesenterprise.sdk.node.client.grpc.mapper.tx + +import com.wavesenterprise.sdk.node.client.grpc.mapper.GrpcTypesMapper.byteArray +import com.wavesenterprise.sdk.node.client.grpc.mapper.tx.BurnTxMapper.domain +import com.wavesenterprise.sdk.node.domain.Address +import com.wavesenterprise.sdk.node.domain.Amount +import com.wavesenterprise.sdk.node.domain.AssetId +import com.wavesenterprise.sdk.node.domain.ChainId +import com.wavesenterprise.sdk.node.domain.Fee +import com.wavesenterprise.sdk.node.domain.PublicKey +import com.wavesenterprise.sdk.node.domain.Signature +import com.wavesenterprise.sdk.node.domain.Timestamp +import com.wavesenterprise.sdk.node.domain.TxId +import com.wavesenterprise.sdk.node.domain.TxVersion +import com.wavesenterprise.sdk.node.domain.tx.BurnTx +import com.wavesenterprise.transaction.protobuf.assets.burnTransaction +import io.kotest.matchers.shouldBe +import org.junit.jupiter.api.Test + +class BurnTxMapperTest { + + @Test + fun `should map to BurnTx (all fields)`() { + val txVersion = TxVersion.fromInt(1) + val grpcTx = burnTransaction { + id = byteString("DnK5Xfi2wXUJx9BjK9X6ZpFdTLdq2GtWH9pWrcxcmrhB") + chainId = 73 + senderPublicKey = byteString("C4eRfdUFaZMRkfUp91bYr7uMgdBRnUfAxuAjetxmK7KY") + assetId = byteString("assetId") + amount = 1_000_000L + fee = 10L + timestamp = 1716881331027L + proofs += byteString( + "2Gns72hraH5yay3eiWeyHQEA1wTqiiAztaLjHinEYX91FEv62HFW38Hq89GnsEJFHUvo9KHYtBBrb8hgTA9wN7DM" + ) + senderAddress = byteString("3N9vL3apA4j2L5PojHW8TYmfHx9Lo2ZaKPB") + } + grpcTx + .domain(txVersion) + .shouldBe( + BurnTx( + id = TxId(grpcTx.id.byteArray()), + chainId = ChainId(grpcTx.chainId.toByte()), + senderPublicKey = PublicKey(grpcTx.senderPublicKey.byteArray()), + assetId = AssetId(grpcTx.assetId.byteArray()), + amount = Amount(grpcTx.amount), + fee = Fee(grpcTx.fee), + timestamp = Timestamp.fromUtcTimestamp(grpcTx.timestamp), + proofs = grpcTx.proofsList.map { Signature(it.byteArray()) }, + senderAddress = Address(grpcTx.senderAddress.byteArray()), + version = txVersion, + ) + ) + } +} diff --git a/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/CallContractTxMapperTest.kt b/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/CallContractTxMapperTest.kt new file mode 100644 index 00000000..32a1b146 --- /dev/null +++ b/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/CallContractTxMapperTest.kt @@ -0,0 +1,240 @@ +package com.wavesenterprise.sdk.node.client.grpc.mapper.tx + +import com.google.protobuf.ByteString +import com.google.protobuf.bytesValue +import com.wavesenterprise.sdk.node.client.grpc.mapper.tx.CallContractTxMapper.domain +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.domain.DataValue +import com.wavesenterprise.sdk.node.domain.Fee +import com.wavesenterprise.sdk.node.domain.FeeAssetId +import com.wavesenterprise.sdk.node.domain.PublicKey +import com.wavesenterprise.sdk.node.domain.Signature +import com.wavesenterprise.sdk.node.domain.Timestamp +import com.wavesenterprise.sdk.node.domain.TxId +import com.wavesenterprise.sdk.node.domain.TxVersion +import com.wavesenterprise.sdk.node.domain.ValidationPolicy +import com.wavesenterprise.sdk.node.domain.atomic.AtomicBadge +import com.wavesenterprise.sdk.node.domain.contract.ContractId +import com.wavesenterprise.sdk.node.domain.contract.ContractVersion +import com.wavesenterprise.sdk.node.domain.tx.CallContractTx +import com.wavesenterprise.transaction.protobuf.ValidationPolicyKt.any +import com.wavesenterprise.transaction.protobuf.ValidationPolicyKt.majority +import com.wavesenterprise.transaction.protobuf.ValidationPolicyKt.majorityWithOneOf +import com.wavesenterprise.transaction.protobuf.atomicBadge +import com.wavesenterprise.transaction.protobuf.dataEntry +import com.wavesenterprise.transaction.protobuf.docker.callContractTransaction +import com.wavesenterprise.transaction.protobuf.validationPolicy +import io.kotest.matchers.shouldBe +import org.junit.jupiter.api.TestInstance +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.Arguments +import org.junit.jupiter.params.provider.Arguments.arguments +import org.junit.jupiter.params.provider.MethodSource +import com.wavesenterprise.transaction.protobuf.DataEntry as ProtoDataEntry +import com.wavesenterprise.transaction.protobuf.ValidationPolicy as ProtoValidationPolicy + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +class CallContractTxMapperTest { + + @ParameterizedTest + @MethodSource("mappingArguments") + fun `should map to CallContractTx (all fields)`( + paramsMapping: TestParamsMapping, + validationPolicyMapping: TestValidationPolicyMapping, + ) { + val grpcTx = callContractTransaction { + id = byteString("DnK5Xfi2wXUJx9BjK9X6ZpFdTLdq2GtWH9pWrcxcmrhB") + senderPublicKey = byteString("3M1V41oGFr3hLmo3ecNQWPWVHPSfsguWepc") + contractId = byteString("6kJUWZcvpFPqymsyQeDWux4RPYyvni3Q6dzb7KLrhArB") + params += paramsMapping.protoParams + fee = 10L + timestamp = 1716881331027L + contractVersion = 1 + feeAssetId = bytesValue { + value = byteString("3Ge1AptYWH3Xw2jCNkCkYLPECr5q4aSJMXKMSUGL4eEs") + } + atomicBadge = atomicBadge { + trustedSender = bytesValue { + value = byteString("3M7EEnszPAT2yr72SgWVDLxfYCa4AYvVRwv") + } + } + proofs += listOf( + byteString("4NccZyPCgchDjeMdMmFKu7kxyU8AFF4e9cWaPFTQVQyYU1ZCCu3QmtmkfJkrDpDwGs4eJhYUVh5TnwYvjZYKPhLp"), + byteString("QMGoz6rycNsDLhN3mDce2mqGRQQ8r26vDDw551pnYcAecpFBDA8j38FVqDjLTGuFHs6ScX32fsGcaemmptpCFHk"), + ) + senderAddress = byteString("3MLti6qku2gD4rhnRcypvFxJE5UYV2P2myM") + } + val txVersion = TxVersion.fromInt(4) + + grpcTx + .domain(txVersion) + .shouldBe( + CallContractTx( + id = TxId(grpcTx.id.toByteArray()), + senderPublicKey = PublicKey(grpcTx.senderPublicKey.toByteArray()), + contractId = ContractId( + txId = TxId(grpcTx.contractId.toByteArray()) + ), + params = paramsMapping.domainParams, + fee = Fee(grpcTx.fee), + timestamp = Timestamp(grpcTx.timestamp), + contractVersion = ContractVersion(grpcTx.contractVersion), + feeAssetId = FeeAssetId( + txId = TxId(grpcTx.feeAssetId.value.toByteArray()), + ), + atomicBadge = AtomicBadge( + trustedSender = Address(grpcTx.atomicBadge.trustedSender.value.toByteArray()), + ), + proofs = grpcTx.proofsList.map { Signature(it.toByteArray()) }.toList(), + senderAddress = Address(grpcTx.senderAddress.toByteArray()), + version = txVersion, + ) + ) + } + + @ParameterizedTest + @MethodSource("mappingArguments") + fun `should map to CallContractTx (with nulls)`( + paramsMapping: TestParamsMapping, + validationPolicyMapping: TestValidationPolicyMapping, + ) { + val grpcTx = callContractTransaction { + id = byteString("DnK5Xfi2wXUJx9BjK9X6ZpFdTLdq2GtWH9pWrcxcmrhB") + senderPublicKey = byteString("3M1V41oGFr3hLmo3ecNQWPWVHPSfsguWepc") + contractId = byteString("6kJUWZcvpFPqymsyQeDWux4RPYyvni3Q6dzb7KLrhArB") + params += paramsMapping.protoParams + fee = 10L + timestamp = 1716881331027L + contractVersion = 1 + clearFeeAssetId() + clearAtomicBadge() + proofs += listOf( + byteString("4NccZyPCgchDjeMdMmFKu7kxyU8AFF4e9cWaPFTQVQyYU1ZCCu3QmtmkfJkrDpDwGs4eJhYUVh5TnwYvjZYKPhLp"), + byteString("QMGoz6rycNsDLhN3mDce2mqGRQQ8r26vDDw551pnYcAecpFBDA8j38FVqDjLTGuFHs6ScX32fsGcaemmptpCFHk"), + ) + senderAddress = byteString("3MLti6qku2gD4rhnRcypvFxJE5UYV2P2myM") + } + val txVersion = TxVersion.fromInt(2) + + grpcTx + .domain(txVersion) + .shouldBe( + CallContractTx( + id = TxId(grpcTx.id.toByteArray()), + senderPublicKey = PublicKey(grpcTx.senderPublicKey.toByteArray()), + contractId = ContractId( + txId = TxId(grpcTx.contractId.toByteArray()) + ), + params = paramsMapping.domainParams, + fee = Fee(grpcTx.fee), + timestamp = Timestamp(grpcTx.timestamp), + contractVersion = ContractVersion(grpcTx.contractVersion), + feeAssetId = null, + atomicBadge = null, + proofs = grpcTx.proofsList.map { Signature(it.toByteArray()) }.toList(), + senderAddress = Address(grpcTx.senderAddress.toByteArray()), + version = txVersion, + ) + ) + } + + private fun mappingArguments(): List = + cartesianProduct( + TestParamsMapping.cases(), + TestValidationPolicyMapping.cases() + ).map { (testParamsMapping, testValidationPolicyMapping) -> + arguments(testParamsMapping, testValidationPolicyMapping) + } + + data class TestParamsMapping( + val protoParams: List, + val domainParams: List, + ) { + companion object { + fun cases(): List = + listOf( + TestParamsMapping( + protoParams = listOf( + dataEntry { key = "int_0"; intValue = 0 }, + dataEntry { key = "int_1"; intValue = 1 }, + ), + domainParams = listOf( + DataEntry(key = DataKey("int_0"), value = DataValue.IntegerDataValue(0)), + DataEntry(key = DataKey("int_1"), value = DataValue.IntegerDataValue(1)), + ) + ), + TestParamsMapping( + protoParams = listOf( + dataEntry { key = "bool_true"; boolValue = true }, + dataEntry { key = "bool_false"; boolValue = false }, + ), + domainParams = listOf( + DataEntry(key = DataKey("bool_true"), value = DataValue.BooleanDataValue(true)), + DataEntry(key = DataKey("bool_false"), value = DataValue.BooleanDataValue(false)), + ) + ), + TestParamsMapping( + protoParams = listOf( + dataEntry { key = "binary_0"; binaryValue = ByteString.copyFrom(byteArrayOf(0)) }, + dataEntry { key = "binary_1"; binaryValue = ByteString.copyFrom(byteArrayOf(1)) } + ), + domainParams = listOf( + DataEntry(key = DataKey("binary_0"), value = DataValue.BinaryDataValue(byteArrayOf(0))), + DataEntry(key = DataKey("binary_1"), value = DataValue.BinaryDataValue(byteArrayOf(1))), + ) + ), + TestParamsMapping( + protoParams = listOf( + dataEntry { key = "string_1"; stringValue = "string_1" }, + dataEntry { key = "string_2"; stringValue = "string_2" }, + ), + domainParams = listOf( + DataEntry(key = DataKey("string_1"), value = DataValue.StringDataValue("string_1")), + DataEntry(key = DataKey("string_2"), value = DataValue.StringDataValue("string_2")), + ) + ), + ) + } + } + + data class TestValidationPolicyMapping( + val protoValidationPolicy: ProtoValidationPolicy, + val domainValidationPolicy: ValidationPolicy, + ) { + companion object { + fun cases(): List = + listOf( + TestValidationPolicyMapping( + protoValidationPolicy = validationPolicy { + any = any {} + }, + domainValidationPolicy = ValidationPolicy.Any + ), + TestValidationPolicyMapping( + protoValidationPolicy = validationPolicy { + majority = majority {} + }, + domainValidationPolicy = ValidationPolicy.Majority + ), + TestValidationPolicyMapping( + protoValidationPolicy = validationPolicy { + majorityWithOneOf = majorityWithOneOf { + addresses += listOf( + byteString("3M7EEnszPAT2yr72SgWVDLxfYCa4AYvVRwv"), + byteString("3M3xGmJGmxBv2aZ4UFmn93rHxVXTJDKSAnh"), + ) + } + }, + domainValidationPolicy = ValidationPolicy.MajorityWithOneOf( + addresses = listOf( + Address("3M7EEnszPAT2yr72SgWVDLxfYCa4AYvVRwv".toByteArray()), + Address("3M3xGmJGmxBv2aZ4UFmn93rHxVXTJDKSAnh".toByteArray()), + ) + ) + ) + ) + } + } +} diff --git a/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/CreateAliasTxMapperTest.kt b/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/CreateAliasTxMapperTest.kt new file mode 100644 index 00000000..a5e80370 --- /dev/null +++ b/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/CreateAliasTxMapperTest.kt @@ -0,0 +1,85 @@ +package com.wavesenterprise.sdk.node.client.grpc.mapper.tx + +import com.google.protobuf.ByteString +import com.google.protobuf.BytesValue +import com.wavesenterprise.sdk.node.client.grpc.mapper.tx.CreateAliasTxMapper.domain +import com.wavesenterprise.sdk.node.domain.Address +import com.wavesenterprise.sdk.node.domain.Alias +import com.wavesenterprise.sdk.node.domain.Fee +import com.wavesenterprise.sdk.node.domain.FeeAssetId +import com.wavesenterprise.sdk.node.domain.PublicKey +import com.wavesenterprise.sdk.node.domain.Signature +import com.wavesenterprise.sdk.node.domain.Timestamp +import com.wavesenterprise.sdk.node.domain.TxId +import com.wavesenterprise.sdk.node.domain.TxVersion +import com.wavesenterprise.sdk.node.domain.tx.CreateAliasTx +import com.wavesenterprise.transaction.protobuf.createAliasTransaction +import io.kotest.matchers.shouldBe +import org.junit.jupiter.api.Test + +class CreateAliasTxMapperTest { + + @Test + fun `should map to CreateAliasTx (all fields)`() { + val txVersion = TxVersion.fromInt(1) + val grpcTx = createAliasTransaction { + id = ByteString.copyFromUtf8("DnK5Xfi2wXUJx9BjK9X6ZpFdTLdq2GtWH9pWrcxcmrhB") + senderPublicKey = ByteString.copyFromUtf8("C4eRfdUFaZMRkfUp91bYr7uMgdBRnUfAxuAjetxmK7KY") + alias = ByteString.copyFromUtf8("alias") + fee = 10L + timestamp = 1716881331027L + feeAssetId = BytesValue.of(ByteString.copyFromUtf8("DnK5Xfi2wXUJx9BjK9X6ZpFdTLdq2GtWH9pWrcxcmrhB")) + proofs += ByteString.copyFromUtf8( + "2Gns72hraH5yay3eiWeyHQEA1wTqiiAztaLjHinEYX91FEv62HFW38Hq89GnsEJFHUvo9KHYtBBrb8hgTA9wN7DM" + ) + senderAddress = ByteString.copyFromUtf8("3N9vL3apA4j2L5PojHW8TYmfHx9Lo2ZaKPB") + } + grpcTx.domain(txVersion).apply { + shouldBe( + CreateAliasTx( + id = TxId(grpcTx.id.toByteArray()), + senderPublicKey = PublicKey(grpcTx.senderPublicKey.toByteArray()), + alias = Alias(grpcTx.alias.toString()), + fee = Fee(grpcTx.fee), + timestamp = Timestamp(grpcTx.timestamp), + feeAssetId = FeeAssetId(TxId(grpcTx.feeAssetId.value.toByteArray())), + proofs = grpcTx.proofsList.map { Signature(it.toByteArray()) }, + senderAddress = Address(grpcTx.senderAddress.toByteArray()), + version = txVersion, + ) + ) + } + } + + @Test + fun `should map to CreateAliasTx (with nulls)`() { + val txVersion = TxVersion.fromInt(1) + val grpcTx = createAliasTransaction { + id = ByteString.copyFromUtf8("DnK5Xfi2wXUJx9BjK9X6ZpFdTLdq2GtWH9pWrcxcmrhB") + senderPublicKey = ByteString.copyFromUtf8("C4eRfdUFaZMRkfUp91bYr7uMgdBRnUfAxuAjetxmK7KY") + alias = ByteString.copyFromUtf8("alias") + fee = 10L + timestamp = 1716881331027L + clearFeeAssetId() + proofs += ByteString.copyFromUtf8( + "2Gns72hraH5yay3eiWeyHQEA1wTqiiAztaLjHinEYX91FEv62HFW38Hq89GnsEJFHUvo9KHYtBBrb8hgTA9wN7DM" + ) + senderAddress = ByteString.copyFromUtf8("3N9vL3apA4j2L5PojHW8TYmfHx9Lo2ZaKPB") + } + grpcTx.domain(txVersion).apply { + shouldBe( + CreateAliasTx( + id = TxId(grpcTx.id.toByteArray()), + senderPublicKey = PublicKey(grpcTx.senderPublicKey.toByteArray()), + alias = Alias(grpcTx.alias.toString()), + fee = Fee(grpcTx.fee), + timestamp = Timestamp(grpcTx.timestamp), + feeAssetId = null, + proofs = grpcTx.proofsList.map { Signature(it.toByteArray()) }, + senderAddress = Address(grpcTx.senderAddress.toByteArray()), + version = txVersion, + ) + ) + } + } +} diff --git a/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/CreateContractTxMapperTest.kt b/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/CreateContractTxMapperTest.kt new file mode 100644 index 00000000..301e238b --- /dev/null +++ b/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/CreateContractTxMapperTest.kt @@ -0,0 +1,259 @@ +package com.wavesenterprise.sdk.node.client.grpc.mapper.tx + +import com.google.protobuf.ByteString +import com.google.protobuf.bytesValue +import com.wavesenterprise.sdk.node.client.grpc.mapper.tx.CreateContractTxMapper.domain +import com.wavesenterprise.sdk.node.domain.Address +import com.wavesenterprise.sdk.node.domain.ContractApiVersion +import com.wavesenterprise.sdk.node.domain.DataEntry +import com.wavesenterprise.sdk.node.domain.DataKey +import com.wavesenterprise.sdk.node.domain.DataValue +import com.wavesenterprise.sdk.node.domain.Fee +import com.wavesenterprise.sdk.node.domain.FeeAssetId +import com.wavesenterprise.sdk.node.domain.MajorVersion +import com.wavesenterprise.sdk.node.domain.MinorVersion +import com.wavesenterprise.sdk.node.domain.PublicKey +import com.wavesenterprise.sdk.node.domain.Signature +import com.wavesenterprise.sdk.node.domain.Timestamp +import com.wavesenterprise.sdk.node.domain.TxId +import com.wavesenterprise.sdk.node.domain.TxVersion +import com.wavesenterprise.sdk.node.domain.ValidationPolicy +import com.wavesenterprise.sdk.node.domain.atomic.AtomicBadge +import com.wavesenterprise.sdk.node.domain.contract.ContractImage +import com.wavesenterprise.sdk.node.domain.contract.ContractImageHash +import com.wavesenterprise.sdk.node.domain.contract.ContractName +import com.wavesenterprise.sdk.node.domain.tx.CreateContractTx +import com.wavesenterprise.transaction.protobuf.ValidationPolicyKt.any +import com.wavesenterprise.transaction.protobuf.ValidationPolicyKt.majority +import com.wavesenterprise.transaction.protobuf.ValidationPolicyKt.majorityWithOneOf +import com.wavesenterprise.transaction.protobuf.atomicBadge +import com.wavesenterprise.transaction.protobuf.contractApiVersion +import com.wavesenterprise.transaction.protobuf.dataEntry +import com.wavesenterprise.transaction.protobuf.docker.createContractTransaction +import com.wavesenterprise.transaction.protobuf.validationPolicy +import io.kotest.matchers.shouldBe +import org.junit.jupiter.api.TestInstance +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.Arguments +import org.junit.jupiter.params.provider.Arguments.arguments +import org.junit.jupiter.params.provider.MethodSource +import com.wavesenterprise.transaction.protobuf.DataEntry as ProtoDataEntry +import com.wavesenterprise.transaction.protobuf.ValidationPolicy as ProtoValidationPolicy + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +class CreateContractTxMapperTest { + + @ParameterizedTest + @MethodSource("mappingArguments") + fun `should map to CreateContractTx (all fields)`( + paramsMapping: TestParamsMapping, + validationPolicyMapping: TestValidationPolicyMapping, + ) { + val grpcTx = createContractTransaction { + id = byteString("DnK5Xfi2wXUJx9BjK9X6ZpFdTLdq2GtWH9pWrcxcmrhB") + senderPublicKey = byteString("3M1V41oGFr3hLmo3ecNQWPWVHPSfsguWepc") + image = "registry.test-domain.com/test-docker-repo/contract:1.0.0" + imageHash = "573387bbf50cfdeda462054b8d85d6c24007f91044501250877392e43ff5ed50" + contractName = "Test contract name" + params += paramsMapping.protoParams + fee = 10L + timestamp = 1716881331027L + feeAssetId = bytesValue { + value = byteString("3Ge1AptYWH3Xw2jCNkCkYLPECr5q4aSJMXKMSUGL4eEs") + } + atomicBadge = atomicBadge { + trustedSender = bytesValue { + value = byteString("3M7EEnszPAT2yr72SgWVDLxfYCa4AYvVRwv") + } + } + validationPolicy = validationPolicyMapping.protoValidationPolicy + apiVersion = contractApiVersion { + majorVersion = 1 + minorVersion = 0 + } + proofs += listOf( + byteString("4NccZyPCgchDjeMdMmFKu7kxyU8AFF4e9cWaPFTQVQyYU1ZCCu3QmtmkfJkrDpDwGs4eJhYUVh5TnwYvjZYKPhLp"), + byteString("QMGoz6rycNsDLhN3mDce2mqGRQQ8r26vDDw551pnYcAecpFBDA8j38FVqDjLTGuFHs6ScX32fsGcaemmptpCFHk"), + ) + senderAddress = byteString("3MLti6qku2gD4rhnRcypvFxJE5UYV2P2myM") + } + val txVersion = TxVersion.fromInt(4) + + grpcTx + .domain(txVersion) + .shouldBe( + CreateContractTx( + id = TxId(grpcTx.id.toByteArray()), + version = txVersion, + senderPublicKey = PublicKey(grpcTx.senderPublicKey.toByteArray()), + image = ContractImage(grpcTx.image), + imageHash = ContractImageHash(grpcTx.imageHash), + contractName = ContractName(grpcTx.contractName), + params = paramsMapping.domainParams, + fee = Fee(grpcTx.fee), + timestamp = Timestamp(grpcTx.timestamp), + feeAssetId = FeeAssetId( + txId = TxId(grpcTx.feeAssetId.value.toByteArray()), + ), + atomicBadge = AtomicBadge( + trustedSender = Address(grpcTx.atomicBadge.trustedSender.value.toByteArray()), + ), + validationPolicy = validationPolicyMapping.domainValidationPolicy, + apiVersion = ContractApiVersion( + major = MajorVersion(grpcTx.apiVersion.majorVersion), + minor = MinorVersion(grpcTx.apiVersion.minorVersion), + ), + proofs = grpcTx.proofsList.map { Signature(it.toByteArray()) }.toList(), + senderAddress = Address(grpcTx.senderAddress.toByteArray()), + ) + ) + } + + @ParameterizedTest + @MethodSource("mappingArguments") + fun `should map to CreateContractTx (with nulls)`( + paramsMapping: TestParamsMapping, + validationPolicyMapping: TestValidationPolicyMapping, + ) { + val grpcTx = createContractTransaction { + id = byteString("DnK5Xfi2wXUJx9BjK9X6ZpFdTLdq2GtWH9pWrcxcmrhB") + senderPublicKey = byteString("3M1V41oGFr3hLmo3ecNQWPWVHPSfsguWepc") + image = "registry.test-domain.com/test-docker-repo/contract:1.0.0" + imageHash = "573387bbf50cfdeda462054b8d85d6c24007f91044501250877392e43ff5ed50" + contractName = "Test contract name" + params += paramsMapping.protoParams + fee = 10L + timestamp = 1716881331027L + clearFeeAssetId() + clearAtomicBadge() + clearValidationPolicy() + clearApiVersion() + proofs += listOf( + byteString("4NccZyPCgchDjeMdMmFKu7kxyU8AFF4e9cWaPFTQVQyYU1ZCCu3QmtmkfJkrDpDwGs4eJhYUVh5TnwYvjZYKPhLp"), + byteString("QMGoz6rycNsDLhN3mDce2mqGRQQ8r26vDDw551pnYcAecpFBDA8j38FVqDjLTGuFHs6ScX32fsGcaemmptpCFHk"), + ) + senderAddress = byteString("3MLti6qku2gD4rhnRcypvFxJE5UYV2P2myM") + } + val txVersion = TxVersion.fromInt(1) + + grpcTx + .domain(txVersion) + .shouldBe( + CreateContractTx( + id = TxId(grpcTx.id.toByteArray()), + version = txVersion, + senderPublicKey = PublicKey(grpcTx.senderPublicKey.toByteArray()), + image = ContractImage(grpcTx.image), + imageHash = ContractImageHash(grpcTx.imageHash), + contractName = ContractName(grpcTx.contractName), + params = paramsMapping.domainParams, + fee = Fee(grpcTx.fee), + timestamp = Timestamp(grpcTx.timestamp), + feeAssetId = null, + atomicBadge = null, + validationPolicy = null, + apiVersion = null, + proofs = grpcTx.proofsList.map { Signature(it.toByteArray()) }.toList(), + senderAddress = Address(grpcTx.senderAddress.toByteArray()), + ) + ) + } + + private fun mappingArguments(): List = + cartesianProduct( + TestParamsMapping.cases(), + TestValidationPolicyMapping.cases() + ).map { (testParamsMapping, testValidationPolicyMapping) -> + arguments(testParamsMapping, testValidationPolicyMapping) + } + + data class TestParamsMapping( + val protoParams: List, + val domainParams: List, + ) { + companion object { + fun cases(): List = + listOf( + TestParamsMapping( + protoParams = listOf( + dataEntry { key = "int_0"; intValue = 0 }, + dataEntry { key = "int_1"; intValue = 1 }, + ), + domainParams = listOf( + DataEntry(key = DataKey("int_0"), value = DataValue.IntegerDataValue(0)), + DataEntry(key = DataKey("int_1"), value = DataValue.IntegerDataValue(1)), + ) + ), + TestParamsMapping( + protoParams = listOf( + dataEntry { key = "bool_true"; boolValue = true }, + dataEntry { key = "bool_false"; boolValue = false }, + ), + domainParams = listOf( + DataEntry(key = DataKey("bool_true"), value = DataValue.BooleanDataValue(true)), + DataEntry(key = DataKey("bool_false"), value = DataValue.BooleanDataValue(false)), + ) + ), + TestParamsMapping( + protoParams = listOf( + dataEntry { key = "binary_0"; binaryValue = ByteString.copyFrom(byteArrayOf(0)) }, + dataEntry { key = "binary_1"; binaryValue = ByteString.copyFrom(byteArrayOf(1)) } + ), + domainParams = listOf( + DataEntry(key = DataKey("binary_0"), value = DataValue.BinaryDataValue(byteArrayOf(0))), + DataEntry(key = DataKey("binary_1"), value = DataValue.BinaryDataValue(byteArrayOf(1))), + ) + ), + TestParamsMapping( + protoParams = listOf( + dataEntry { key = "string_1"; stringValue = "string_1" }, + dataEntry { key = "string_2"; stringValue = "string_2" }, + ), + domainParams = listOf( + DataEntry(key = DataKey("string_1"), value = DataValue.StringDataValue("string_1")), + DataEntry(key = DataKey("string_2"), value = DataValue.StringDataValue("string_2")), + ) + ), + ) + } + } + + data class TestValidationPolicyMapping( + val protoValidationPolicy: ProtoValidationPolicy, + val domainValidationPolicy: ValidationPolicy, + ) { + companion object { + fun cases(): List = + listOf( + TestValidationPolicyMapping( + protoValidationPolicy = validationPolicy { + any = any {} + }, + domainValidationPolicy = ValidationPolicy.Any + ), + TestValidationPolicyMapping( + protoValidationPolicy = validationPolicy { + majority = majority {} + }, + domainValidationPolicy = ValidationPolicy.Majority + ), + TestValidationPolicyMapping( + protoValidationPolicy = validationPolicy { + majorityWithOneOf = majorityWithOneOf { + addresses += listOf( + byteString("3M7EEnszPAT2yr72SgWVDLxfYCa4AYvVRwv"), + byteString("3M3xGmJGmxBv2aZ4UFmn93rHxVXTJDKSAnh"), + ) + } + }, + domainValidationPolicy = ValidationPolicy.MajorityWithOneOf( + addresses = listOf( + Address("3M7EEnszPAT2yr72SgWVDLxfYCa4AYvVRwv".toByteArray()), + Address("3M3xGmJGmxBv2aZ4UFmn93rHxVXTJDKSAnh".toByteArray()), + ) + ) + ) + ) + } + } +} diff --git a/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/CreatePolicyTxMapperTest.kt b/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/CreatePolicyTxMapperTest.kt new file mode 100644 index 00000000..fd7af85b --- /dev/null +++ b/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/CreatePolicyTxMapperTest.kt @@ -0,0 +1,131 @@ +package com.wavesenterprise.sdk.node.client.grpc.mapper.tx + +import com.google.protobuf.bytesValue +import com.wavesenterprise.sdk.node.client.grpc.mapper.tx.CreatePolicyTxMapper.domain +import com.wavesenterprise.sdk.node.domain.Address +import com.wavesenterprise.sdk.node.domain.Fee +import com.wavesenterprise.sdk.node.domain.FeeAssetId +import com.wavesenterprise.sdk.node.domain.PolicyDescription +import com.wavesenterprise.sdk.node.domain.PolicyName +import com.wavesenterprise.sdk.node.domain.PublicKey +import com.wavesenterprise.sdk.node.domain.Signature +import com.wavesenterprise.sdk.node.domain.Timestamp +import com.wavesenterprise.sdk.node.domain.TxId +import com.wavesenterprise.sdk.node.domain.TxVersion +import com.wavesenterprise.sdk.node.domain.atomic.AtomicBadge +import com.wavesenterprise.sdk.node.domain.tx.CreatePolicyTx +import com.wavesenterprise.transaction.protobuf.atomicBadge +import com.wavesenterprise.transaction.protobuf.createPolicyTransaction +import io.kotest.matchers.shouldBe +import org.junit.jupiter.api.Test + +class CreatePolicyTxMapperTest { + + @Test + fun `should map to CreatePolicyTx (all fields)`() { + val grpcTx = createPolicyTransaction { + id = byteString("DnK5Xfi2wXUJx9BjK9X6ZpFdTLdq2GtWH9pWrcxcmrhB") + senderPublicKey = byteString("3M1V41oGFr3hLmo3ecNQWPWVHPSfsguWepc") + policyName = "TEST_POLICY" + description = "TEST_POLICY description" + recipients += listOf( + byteString("3MLti6qku2gD4rhnRcypvFxJE5UYV2P2myM"), + byteString("3MNP3Cea3epMQsRNya66UEh5uCq9wiuw1fn"), + ) + owners += listOf( + byteString("3MLti6qku2gD4rhnRcypvFxJE5UYV2P2myM"), + byteString("3MNP3Cea3epMQsRNya66UEh5uCq9wiuw1fn"), + byteString("3M7EEnszPAT2yr72SgWVDLxfYCa4AYvVRwv"), + ) + timestamp = 1716881331027L + fee = 10L + feeAssetId = bytesValue { + byteString("3Ge1AptYWH3Xw2jCNkCkYLPECr5q4aSJMXKMSUGL4eEs") + } + atomicBadge = atomicBadge { + trustedSender = bytesValue { + byteString("3M7EEnszPAT2yr72SgWVDLxfYCa4AYvVRwv") + } + } + proofs += listOf( + byteString("4NccZyPCgchDjeMdMmFKu7kxyU8AFF4e9cWaPFTQVQyYU1ZCCu3QmtmkfJkrDpDwGs4eJhYUVh5TnwYvjZYKPhLp"), + byteString("QMGoz6rycNsDLhN3mDce2mqGRQQ8r26vDDw551pnYcAecpFBDA8j38FVqDjLTGuFHs6ScX32fsGcaemmptpCFHk"), + ) + senderAddress = byteString("3MLti6qku2gD4rhnRcypvFxJE5UYV2P2myM") + } + val txVersion = TxVersion.fromInt(3) + + grpcTx + .domain(txVersion) + .shouldBe( + CreatePolicyTx( + id = TxId(grpcTx.id.toByteArray()), + senderPublicKey = PublicKey(grpcTx.senderPublicKey.toByteArray()), + policyName = PolicyName(grpcTx.policyName), + description = PolicyDescription(grpcTx.description), + recipients = grpcTx.recipientsList.map { Address(it.toByteArray()) }.toList(), + owners = grpcTx.ownersList.map { Address(it.toByteArray()) }.toList(), + timestamp = Timestamp(grpcTx.timestamp), + fee = Fee(grpcTx.fee), + feeAssetId = FeeAssetId( + txId = TxId(grpcTx.feeAssetId.value.toByteArray()), + ), + atomicBadge = AtomicBadge( + trustedSender = Address(grpcTx.atomicBadge.trustedSender.value.toByteArray()), + ), + proofs = grpcTx.proofsList.map { Signature(it.toByteArray()) }.toList(), + senderAddress = Address(grpcTx.senderAddress.toByteArray()), + version = txVersion, + ) + ) + } + + @Test + fun `should map to CreatePolicyTx (with nulls)`() { + val grpcTx = createPolicyTransaction { + id = byteString("DnK5Xfi2wXUJx9BjK9X6ZpFdTLdq2GtWH9pWrcxcmrhB") + senderPublicKey = byteString("3M1V41oGFr3hLmo3ecNQWPWVHPSfsguWepc") + policyName = "TEST_POLICY" + description = "TEST_POLICY description" + recipients += listOf( + byteString("3MLti6qku2gD4rhnRcypvFxJE5UYV2P2myM"), + byteString("3MNP3Cea3epMQsRNya66UEh5uCq9wiuw1fn"), + ) + owners += listOf( + byteString("3MLti6qku2gD4rhnRcypvFxJE5UYV2P2myM"), + byteString("3MNP3Cea3epMQsRNya66UEh5uCq9wiuw1fn"), + byteString("3M7EEnszPAT2yr72SgWVDLxfYCa4AYvVRwv"), + ) + timestamp = 1716881331027L + fee = 10L + clearFeeAssetId() + clearAtomicBadge() + proofs += listOf( + byteString("4NccZyPCgchDjeMdMmFKu7kxyU8AFF4e9cWaPFTQVQyYU1ZCCu3QmtmkfJkrDpDwGs4eJhYUVh5TnwYvjZYKPhLp"), + byteString("QMGoz6rycNsDLhN3mDce2mqGRQQ8r26vDDw551pnYcAecpFBDA8j38FVqDjLTGuFHs6ScX32fsGcaemmptpCFHk"), + ) + senderAddress = byteString("3MLti6qku2gD4rhnRcypvFxJE5UYV2P2myM") + } + val txVersion = TxVersion.fromInt(1) + + grpcTx + .domain(txVersion) + .shouldBe( + CreatePolicyTx( + id = TxId(grpcTx.id.toByteArray()), + senderPublicKey = PublicKey(grpcTx.senderPublicKey.toByteArray()), + policyName = PolicyName(grpcTx.policyName), + description = PolicyDescription(grpcTx.description), + recipients = grpcTx.recipientsList.map { Address(it.toByteArray()) }.toList(), + owners = grpcTx.ownersList.map { Address(it.toByteArray()) }.toList(), + timestamp = Timestamp(grpcTx.timestamp), + fee = Fee(grpcTx.fee), + feeAssetId = null, + atomicBadge = null, + proofs = grpcTx.proofsList.map { Signature(it.toByteArray()) }.toList(), + senderAddress = Address(grpcTx.senderAddress.toByteArray()), + version = txVersion, + ) + ) + } +} diff --git a/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/DataTxMapperTest.kt b/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/DataTxMapperTest.kt new file mode 100644 index 00000000..31edd6f2 --- /dev/null +++ b/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/DataTxMapperTest.kt @@ -0,0 +1,165 @@ +package com.wavesenterprise.sdk.node.client.grpc.mapper.tx + +import com.google.protobuf.bytesValue +import com.wavesenterprise.sdk.node.client.grpc.mapper.DataEntryMapper.domain +import com.wavesenterprise.sdk.node.client.grpc.mapper.GrpcTypesMapper.byteArray +import com.wavesenterprise.sdk.node.client.grpc.mapper.tx.DataTxMapper.domain +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.domain.DataValue +import com.wavesenterprise.sdk.node.domain.Fee +import com.wavesenterprise.sdk.node.domain.FeeAssetId +import com.wavesenterprise.sdk.node.domain.PublicKey +import com.wavesenterprise.sdk.node.domain.Signature +import com.wavesenterprise.sdk.node.domain.Timestamp +import com.wavesenterprise.sdk.node.domain.TxId +import com.wavesenterprise.sdk.node.domain.TxVersion +import com.wavesenterprise.sdk.node.domain.tx.DataTx +import com.wavesenterprise.transaction.protobuf.dataEntry +import com.wavesenterprise.transaction.protobuf.dataTransaction +import io.kotest.matchers.shouldBe +import org.junit.jupiter.api.Test + +class DataTxMapperTest { + + @Test + fun `should map to DataTx (all fields)`() { + val txVersion = TxVersion.fromInt(1) + val grpcTx = dataTransaction { + id = byteString("DnK5Xfi2wXUJx9BjK9X6ZpFdTLdq2GtWH9pWrcxcmrhB") + senderPublicKey = byteString("C4eRfdUFaZMRkfUp91bYr7uMgdBRnUfAxuAjetxmK7KY") + authorPublicKey = byteString("C4eRfdUFaZMRkfUp91bYr7uMgdBRnUfAxuAjetxmK7KY") + data += listOf( + dataEntry { + key = "key" + stringValue = "value" + }, + dataEntry { + key = "key" + boolValue = true + }, + dataEntry { + key = "key" + intValue = 1 + }, + dataEntry { + key = "key" + binaryValue = byteString("binaryValue") + }, + ) + fee = 10L + feeAssetId = bytesValue { + value = byteString("feeAssetId") + } + timestamp = 1716881331027L + proofs += byteString( + "2Gns72hraH5yay3eiWeyHQEA1wTqiiAztaLjHinEYX91FEv62HFW38Hq89GnsEJFHUvo9KHYtBBrb8hgTA9wN7DM" + ) + senderAddress = byteString("3N9vL3apA4j2L5PojHW8TYmfHx9Lo2ZaKPB") + } + grpcTx + .domain(txVersion) + .shouldBe( + DataTx( + id = TxId(grpcTx.id.byteArray()), + senderPublicKey = PublicKey(grpcTx.senderPublicKey.byteArray()), + authorPublicKey = PublicKey(grpcTx.authorPublicKey.byteArray()), + data = listOf( + DataEntry( + key = DataKey("key"), + value = DataValue.StringDataValue("value") + ), + DataEntry( + key = DataKey("key"), + value = DataValue.BooleanDataValue(true) + ), + DataEntry( + key = DataKey("key"), + value = DataValue.IntegerDataValue(1) + ), + DataEntry( + key = DataKey("key"), + value = DataValue.BinaryDataValue("binaryValue".toByteArray()) + ), + ), + fee = Fee(grpcTx.fee), + feeAssetId = FeeAssetId(txId = TxId(grpcTx.feeAssetId.value.byteArray())), + timestamp = Timestamp(grpcTx.timestamp), + proofs = grpcTx.proofsList?.map { Signature(it.byteArray()) }, + senderAddress = Address(grpcTx.senderAddress.byteArray()), + authorAddress = Address(grpcTx.authorPublicKey.byteArray()), + version = txVersion, + ) + ) + } + + @Test + fun `should map to DataTx (with nulls)`() { + val txVersion = TxVersion.fromInt(1) + val grpcTx = dataTransaction { + id = byteString("DnK5Xfi2wXUJx9BjK9X6ZpFdTLdq2GtWH9pWrcxcmrhB") + senderPublicKey = byteString("C4eRfdUFaZMRkfUp91bYr7uMgdBRnUfAxuAjetxmK7KY") + authorPublicKey = byteString("C4eRfdUFaZMRkfUp91bYr7uMgdBRnUfAxuAjetxmK7KY") + data += listOf( + dataEntry { + key = "key" + stringValue = "value" + }, + dataEntry { + key = "key" + boolValue = true + }, + dataEntry { + key = "key" + intValue = 1 + }, + dataEntry { + key = "key" + binaryValue = byteString("binaryValue") + }, + ) + fee = 10L + clearFeeAssetId() + timestamp = 1716881331027L + proofs += byteString( + "2Gns72hraH5yay3eiWeyHQEA1wTqiiAztaLjHinEYX91FEv62HFW38Hq89GnsEJFHUvo9KHYtBBrb8hgTA9wN7DM" + ) + senderAddress = byteString("3N9vL3apA4j2L5PojHW8TYmfHx9Lo2ZaKPB") + } + grpcTx + .domain(txVersion) + .shouldBe( + DataTx( + id = TxId(grpcTx.id.byteArray()), + senderPublicKey = PublicKey(grpcTx.senderPublicKey.byteArray()), + authorPublicKey = PublicKey(grpcTx.authorPublicKey.byteArray()), + data = listOf( + DataEntry( + key = DataKey("key"), + value = DataValue.StringDataValue("value") + ), + DataEntry( + key = DataKey("key"), + value = DataValue.BooleanDataValue(true) + ), + DataEntry( + key = DataKey("key"), + value = DataValue.IntegerDataValue(1) + ), + DataEntry( + key = DataKey("key"), + value = DataValue.BinaryDataValue("binaryValue".toByteArray()) + ), + ), + fee = Fee(grpcTx.fee), + feeAssetId = null, + timestamp = Timestamp(grpcTx.timestamp), + proofs = grpcTx.proofsList?.map { Signature(it.byteArray()) }, + senderAddress = Address(grpcTx.senderAddress.byteArray()), + authorAddress = Address(grpcTx.authorPublicKey.byteArray()), + version = txVersion, + ) + ) + } +} diff --git a/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/DisableContractTxMapperTest.kt b/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/DisableContractTxMapperTest.kt new file mode 100644 index 00000000..a25fd38f --- /dev/null +++ b/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/DisableContractTxMapperTest.kt @@ -0,0 +1,110 @@ +package com.wavesenterprise.sdk.node.client.grpc.mapper.tx + +import com.google.protobuf.ByteString +import com.google.protobuf.bytesValue +import com.wavesenterprise.sdk.node.client.grpc.mapper.AtomicBadgeMapper.domain +import com.wavesenterprise.sdk.node.client.grpc.mapper.GrpcTypesMapper.byteArray +import com.wavesenterprise.sdk.node.client.grpc.mapper.tx.CreateAliasTxMapper.domain +import com.wavesenterprise.sdk.node.client.grpc.mapper.tx.DisableContractTxMapper.domain +import com.wavesenterprise.sdk.node.domain.Address +import com.wavesenterprise.sdk.node.domain.Fee +import com.wavesenterprise.sdk.node.domain.FeeAssetId +import com.wavesenterprise.sdk.node.domain.PublicKey +import com.wavesenterprise.sdk.node.domain.Signature +import com.wavesenterprise.sdk.node.domain.Timestamp +import com.wavesenterprise.sdk.node.domain.TxId +import com.wavesenterprise.sdk.node.domain.TxVersion +import com.wavesenterprise.sdk.node.domain.atomic.AtomicBadge +import com.wavesenterprise.sdk.node.domain.contract.ContractId +import com.wavesenterprise.sdk.node.domain.tx.DisableContractTx +import com.wavesenterprise.transaction.protobuf.atomicBadge +import com.wavesenterprise.transaction.protobuf.docker.disableContractTransaction +import io.kotest.matchers.shouldBe +import org.junit.jupiter.api.Test + +class DisableContractTxMapperTest { + + @Test + fun `should map to DisableContractTx (all fields)`() { + val txVersion = TxVersion.fromInt(1) + val grpcTx = disableContractTransaction { + id = byteString("DnK5Xfi2wXUJx9BjK9X6ZpFdTLdq2GtWH9pWrcxcmrhB") + senderPublicKey = byteString("C4eRfdUFaZMRkfUp91bYr7uMgdBRnUfAxuAjetxmK7KY") + contractId = byteString("contractId") + fee = 10L + timestamp = 1716881331027L + feeAssetId = bytesValue { + value = byteString("feeAssetId") + } + atomicBadge = atomicBadge { + trustedSender = bytesValue { + value = byteString("3N9vL3apA4j2L5PojHW8TYmfHx9Lo2ZaKPB") + } + } + proofs += byteString( + "2Gns72hraH5yay3eiWeyHQEA1wTqiiAztaLjHinEYX91FEv62HFW38Hq89GnsEJFHUvo9KHYtBBrb8hgTA9wN7DM" + ) + senderAddress = ByteString.copyFromUtf8("3N9vL3apA4j2L5PojHW8TYmfHx9Lo2ZaKPB") + } + grpcTx + .domain(txVersion) + .shouldBe( + DisableContractTx( + id = TxId(grpcTx.id.byteArray()), + senderPublicKey = PublicKey(grpcTx.senderPublicKey.byteArray()), + contractId = ContractId( + txId = TxId(grpcTx.contractId.byteArray()), + ), + fee = Fee(grpcTx.fee), + timestamp = Timestamp(grpcTx.timestamp), + feeAssetId = FeeAssetId( + txId = TxId(grpcTx.feeAssetId.value.byteArray()) + ), + atomicBadge = AtomicBadge( + trustedSender = Address(grpcTx.atomicBadge.trustedSender.value.byteArray()), + ), + proofs = grpcTx.proofsList?.map { + Signature(it.byteArray()) + }, + senderAddress = Address(grpcTx.senderAddress.byteArray()), + version = txVersion, + ) + ) + } + + @Test + fun `should map to DisableContractTx (with nulls)`() { + val txVersion = TxVersion.fromInt(1) + val grpcTx = disableContractTransaction { + id = byteString("DnK5Xfi2wXUJx9BjK9X6ZpFdTLdq2GtWH9pWrcxcmrhB") + senderPublicKey = byteString("C4eRfdUFaZMRkfUp91bYr7uMgdBRnUfAxuAjetxmK7KY") + contractId = byteString("contractId") + fee = 10L + timestamp = 1716881331027L + clearFeeAssetId() + clearAtomicBadge() + proofs += byteString( + "2Gns72hraH5yay3eiWeyHQEA1wTqiiAztaLjHinEYX91FEv62HFW38Hq89GnsEJFHUvo9KHYtBBrb8hgTA9wN7DM" + ) + senderAddress = ByteString.copyFromUtf8("3N9vL3apA4j2L5PojHW8TYmfHx9Lo2ZaKPB") + } + grpcTx + .domain(txVersion) + .shouldBe( + DisableContractTx( + id = TxId(grpcTx.id.toByteArray()), + senderPublicKey = PublicKey(grpcTx.senderPublicKey.toByteArray()), + contractId = ContractId( + txId = TxId(grpcTx.contractId.byteArray()), + ), + fee = Fee(grpcTx.fee), + timestamp = Timestamp(grpcTx.timestamp), + feeAssetId = null, + atomicBadge = null, + proofs = grpcTx.proofsList.map { Signature(it.toByteArray()) }, + senderAddress = Address(grpcTx.senderAddress.toByteArray()), + version = txVersion, + ) + ) + } +} diff --git a/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/ExecutableTxMapperTest.kt b/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/ExecutableTxMapperTest.kt new file mode 100644 index 00000000..6088e3a6 --- /dev/null +++ b/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/ExecutableTxMapperTest.kt @@ -0,0 +1,118 @@ +package com.wavesenterprise.sdk.node.client.grpc.mapper.tx + +import com.wavesenterprise.sdk.node.client.grpc.mapper.tx.ExecutableTxMapper.domain +import com.wavesenterprise.sdk.node.domain.TxVersion +import com.wavesenterprise.sdk.node.domain.tx.CallContractTx +import com.wavesenterprise.sdk.node.domain.tx.CreateContractTx +import com.wavesenterprise.sdk.node.domain.tx.UpdateContractTx +import com.wavesenterprise.transaction.protobuf.docker.CallContractTransaction +import com.wavesenterprise.transaction.protobuf.docker.CreateContractTransaction +import com.wavesenterprise.transaction.protobuf.docker.UpdateContractTransaction +import com.wavesenterprise.transaction.protobuf.executableTransaction +import io.kotest.matchers.shouldBe +import io.mockk.clearAllMocks +import io.mockk.every +import io.mockk.mockk +import io.mockk.mockkStatic +import io.mockk.verify +import org.junit.jupiter.api.AfterEach +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.TestInstance +import org.junit.jupiter.api.assertThrows + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +class ExecutableTxMapperTest { + + @BeforeEach + fun beforeEach() { + clearAllMocks() + } + + @AfterEach + fun afterEach() { + clearAllMocks() + } + + @Test + fun `should map to CreateContractTx`() { + val (grpcCreateContractTx, domainCreateContractTx) = + mockk() to mockk() + val executableTxVersion = 4 + val grpcTx = executableTransaction { + createContractTransaction = grpcCreateContractTx + version = executableTxVersion + } + mockkStatic(CreateContractTxMapper::domainInternal) + every { CreateContractTxMapper.domainInternal(any(), any()) } returns domainCreateContractTx + + grpcTx + .domain() + .shouldBe(domainCreateContractTx) + + verify { + CreateContractTxMapper.domainInternal( + tx = grpcCreateContractTx, + version = TxVersion(executableTxVersion) + ) + } + } + + @Test + fun `should map to CallContractTx`() { + val (grpcCallContractTx, domainCallContractTx) = + mockk() to mockk() + val executableTxVersion = 4 + val grpcTx = executableTransaction { + callContractTransaction = grpcCallContractTx + version = executableTxVersion + } + mockkStatic(CallContractTxMapper::domainInternal) + every { CallContractTxMapper.domainInternal(any(), any()) } returns domainCallContractTx + + grpcTx + .domain() + .shouldBe(domainCallContractTx) + + verify { + CallContractTxMapper.domainInternal( + tx = grpcCallContractTx, + version = TxVersion(executableTxVersion) + ) + } + } + + @Test + fun `should map to UpdateContractTx`() { + val (grpcUpdateContractTx, domainUpdateContractTx) = + mockk() to mockk() + val executableTxVersion = 4 + val grpcTx = executableTransaction { + updateContractTransaction = grpcUpdateContractTx + version = executableTxVersion + } + mockkStatic(UpdateContractTxMapper::domainInternal) + every { UpdateContractTxMapper.domainInternal(any(), any()) } returns domainUpdateContractTx + + grpcTx + .domain() + .shouldBe(domainUpdateContractTx) + + verify { + UpdateContractTxMapper.domainInternal( + tx = grpcUpdateContractTx, + version = TxVersion(executableTxVersion) + ) + } + } + + @Test + fun `should throw IllegalStateException`() { + val grpcTx = executableTransaction {} + + val ex = assertThrows { + grpcTx.domain() + } + ex.message shouldBe "Transaction not set" + } +} diff --git a/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/ExecutedContractTxMapperTest.kt b/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/ExecutedContractTxMapperTest.kt new file mode 100644 index 00000000..58e28e6a --- /dev/null +++ b/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/ExecutedContractTxMapperTest.kt @@ -0,0 +1,164 @@ +package com.wavesenterprise.sdk.node.client.grpc.mapper.tx + +import com.google.protobuf.ByteString +import com.wavesenterprise.sdk.node.client.grpc.mapper.tx.ExecutedContractTxMapper.domain +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.domain.DataValue +import com.wavesenterprise.sdk.node.domain.Hash +import com.wavesenterprise.sdk.node.domain.PublicKey +import com.wavesenterprise.sdk.node.domain.Signature +import com.wavesenterprise.sdk.node.domain.Timestamp +import com.wavesenterprise.sdk.node.domain.TxId +import com.wavesenterprise.sdk.node.domain.TxVersion +import com.wavesenterprise.sdk.node.domain.ValidationProof +import com.wavesenterprise.sdk.node.domain.tx.ExecutableTx +import com.wavesenterprise.sdk.node.domain.tx.ExecutedContractTx +import com.wavesenterprise.transaction.protobuf.ExecutableTransaction +import com.wavesenterprise.transaction.protobuf.dataEntry +import com.wavesenterprise.transaction.protobuf.docker.executedContractTransaction +import com.wavesenterprise.transaction.protobuf.validationProof +import io.kotest.matchers.shouldBe +import io.mockk.clearAllMocks +import io.mockk.every +import io.mockk.mockk +import io.mockk.mockkStatic +import org.junit.jupiter.api.AfterEach +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.TestInstance +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.Arguments +import org.junit.jupiter.params.provider.Arguments.arguments +import org.junit.jupiter.params.provider.MethodSource +import com.wavesenterprise.transaction.protobuf.DataEntry as ProtoDataEntry + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +class ExecutedContractTxMapperTest { + + @BeforeEach + fun beforeEach() { + clearAllMocks() + } + + @AfterEach + fun afterEach() { + clearAllMocks() + } + + @ParameterizedTest + @MethodSource("mappingArguments") + fun `should map to ExecutedContractTx (all fields)`( + resultsMapping: TestResultsMapping, + ) { + val (grpcExecutableTx, domainExecutableTx) = mockk() to mockk() + mockkStatic(ExecutableTxMapper::domainInternal) + every { ExecutableTxMapper.domainInternal(grpcExecutableTx) } returns domainExecutableTx + + val grpcTx = executedContractTransaction { + id = byteString("DnK5Xfi2wXUJx9BjK9X6ZpFdTLdq2GtWH9pWrcxcmrhB") + senderPublicKey = byteString("3M1V41oGFr3hLmo3ecNQWPWVHPSfsguWepc") + tx = grpcExecutableTx + results += resultsMapping.protoResults + resultsHash = byteString("3u9ApJCJEX3AoYtKfachMZGfxrLDGaD6FvMrq8EnjPaq") + validationProofs += listOf( + validationProof { + validatorPublicKey = byteString("3M1V41oGFr3hLmo3ecNQWPWVHPSfsguWepc") + signature = + byteString("2hRxJ2876CdJ498UCpErNfDSYdt2mTK4XUnmZNgZiq63RupJs5WTrAqR46c4rLQdq4toBZk2tSYCeAQWEQyi72U6") + }, + validationProof { + validatorPublicKey = byteString("4WnvQPit2Di1iYXDgDcXnJZ5yroKW54vauNoxdNeMi2g") + signature = + byteString("5ahD78wciu8YTsLoxo1XRghJWAGG7At7ePiBWTNzdkvX7cViRCKRLjjjPTGCoAH2mdGQK9i1JiY1wh18eh4h7pGy") + }, + ) + timestamp = 1716881331027L + proofs += listOf( + byteString("4NccZyPCgchDjeMdMmFKu7kxyU8AFF4e9cWaPFTQVQyYU1ZCCu3QmtmkfJkrDpDwGs4eJhYUVh5TnwYvjZYKPhLp"), + byteString("QMGoz6rycNsDLhN3mDce2mqGRQQ8r26vDDw551pnYcAecpFBDA8j38FVqDjLTGuFHs6ScX32fsGcaemmptpCFHk"), + ) + senderAddress = byteString("3MLti6qku2gD4rhnRcypvFxJE5UYV2P2myM") + } + val txVersion = TxVersion.fromInt(2) + + grpcTx + .domain(txVersion) + .shouldBe( + ExecutedContractTx( + id = TxId(grpcTx.id.toByteArray()), + senderPublicKey = PublicKey(grpcTx.senderPublicKey.toByteArray()), + tx = domainExecutableTx, + results = resultsMapping.domainResults, + resultsHash = Hash(grpcTx.resultsHash.toByteArray()), + validationProofs = grpcTx.validationProofsList.map { + ValidationProof( + validatorPublicKey = PublicKey(it.validatorPublicKey.toByteArray()), + signature = Signature(it.signature.toByteArray()), + ) + }, + timestamp = Timestamp(grpcTx.timestamp), + atomicBadge = null, + proofs = grpcTx.proofsList.map { Signature(it.toByteArray()) }.toList(), + senderAddress = Address(grpcTx.senderAddress.toByteArray()), + version = txVersion, + ) + ) + } + + private fun mappingArguments(): List = + TestResultsMapping.cases().map { testResultsMapping -> + arguments(testResultsMapping) + } + + data class TestResultsMapping( + val protoResults: List, + val domainResults: List, + ) { + companion object { + fun cases(): List = + listOf( + TestResultsMapping( + protoResults = listOf( + dataEntry { key = "int_0"; intValue = 0 }, + dataEntry { key = "int_1"; intValue = 1 }, + ), + domainResults = listOf( + DataEntry(key = DataKey("int_0"), value = DataValue.IntegerDataValue(0)), + DataEntry(key = DataKey("int_1"), value = DataValue.IntegerDataValue(1)), + ) + ), + TestResultsMapping( + protoResults = listOf( + dataEntry { key = "bool_true"; boolValue = true }, + dataEntry { key = "bool_false"; boolValue = false }, + ), + domainResults = listOf( + DataEntry(key = DataKey("bool_true"), value = DataValue.BooleanDataValue(true)), + DataEntry(key = DataKey("bool_false"), value = DataValue.BooleanDataValue(false)), + ) + ), + TestResultsMapping( + protoResults = listOf( + dataEntry { key = "binary_0"; binaryValue = ByteString.copyFrom(byteArrayOf(0)) }, + dataEntry { key = "binary_1"; binaryValue = ByteString.copyFrom(byteArrayOf(1)) } + ), + domainResults = listOf( + DataEntry(key = DataKey("binary_0"), value = DataValue.BinaryDataValue(byteArrayOf(0))), + DataEntry(key = DataKey("binary_1"), value = DataValue.BinaryDataValue(byteArrayOf(1))), + ) + ), + TestResultsMapping( + protoResults = listOf( + dataEntry { key = "string_1"; stringValue = "string_1" }, + dataEntry { key = "string_2"; stringValue = "string_2" }, + ), + domainResults = listOf( + DataEntry(key = DataKey("string_1"), value = DataValue.StringDataValue("string_1")), + DataEntry(key = DataKey("string_2"), value = DataValue.StringDataValue("string_2")), + ) + ), + ) + } + } +} diff --git a/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/GenesisPermitTxMapperTest.kt b/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/GenesisPermitTxMapperTest.kt new file mode 100644 index 00000000..7ef19fdd --- /dev/null +++ b/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/GenesisPermitTxMapperTest.kt @@ -0,0 +1,52 @@ +package com.wavesenterprise.sdk.node.client.grpc.mapper.tx + +import com.wavesenterprise.sdk.node.client.grpc.mapper.AddressMapper.byteString +import com.wavesenterprise.sdk.node.client.grpc.mapper.RoleMapper.dto +import com.wavesenterprise.sdk.node.client.grpc.mapper.SignatureMapper.byteString +import com.wavesenterprise.sdk.node.client.grpc.mapper.TxIdMapper.byteString +import com.wavesenterprise.sdk.node.client.grpc.mapper.tx.GenesisPermitTxMapper.domain +import com.wavesenterprise.sdk.node.domain.Address +import com.wavesenterprise.sdk.node.domain.Fee +import com.wavesenterprise.sdk.node.domain.Role +import com.wavesenterprise.sdk.node.domain.Signature +import com.wavesenterprise.sdk.node.domain.Timestamp +import com.wavesenterprise.sdk.node.domain.TxId +import com.wavesenterprise.sdk.node.domain.TxVersion +import com.wavesenterprise.transaction.protobuf.genesisPermitTransaction +import io.kotest.matchers.shouldBe +import org.junit.jupiter.api.Test + +class GenesisPermitTxMapperTest { + + @Test + fun `should map to GenesisPermitTx (all fields)`() { + val txId = TxId.fromBase58("DnK5Xfi2wXUJx9BjK9X6ZpFdTLdq2GtWH9pWrcxcmrhB") + val txTarget = Address.fromBase58("3N9vL3apA4j2L5PojHW8TYmfHx9Lo2ZaKPB") + val txRole = Role.SENDER + val txFee = Fee(10L) + val txTimestamp = Timestamp(1716881331027L) + val txSignature = Signature( + "2Gns72hraH5yay3eiWeyHQEA1wTqiiAztaLjHinEYX91FEv62HFW38Hq89GnsEJFHUvo9KHYtBBrb8hgTA9wN7DM".toByteArray() + ) + val txVersion = TxVersion.fromInt(1) + + val grpcTx = genesisPermitTransaction { + id = txId.byteString() + target = txTarget.byteString() + role = txRole.dto() + fee = txFee.value + timestamp = txTimestamp.utcTimestampMillis + signature = txSignature.byteString() + } + + grpcTx.domain(txVersion).apply { + id.bytes shouldBe grpcTx.id.toByteArray() + target.bytes shouldBe grpcTx.target.toByteArray() + role.code shouldBe grpcTx.role.id + fee.value shouldBe grpcTx.fee + timestamp.utcTimestampMillis shouldBe grpcTx.timestamp + signature.bytes shouldBe grpcTx.signature.toByteArray() + version.value shouldBe txVersion.value + } + } +} diff --git a/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/GenesisRegisterNodeTxMapperTest.kt b/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/GenesisRegisterNodeTxMapperTest.kt new file mode 100644 index 00000000..336ac47f --- /dev/null +++ b/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/GenesisRegisterNodeTxMapperTest.kt @@ -0,0 +1,33 @@ +package com.wavesenterprise.sdk.node.client.grpc.mapper.tx + +import com.google.protobuf.ByteString +import com.wavesenterprise.sdk.node.client.grpc.mapper.tx.GenesisRegisterNodeTxMapper.domain +import com.wavesenterprise.sdk.node.domain.TxVersion +import com.wavesenterprise.transaction.protobuf.genesisRegisterNodeTransaction +import io.kotest.matchers.shouldBe +import org.junit.jupiter.api.Test + +class GenesisRegisterNodeTxMapperTest { + + @Test + fun `should map to GenesisRegisterNodeTx (all fields)`() { + val txVersion = TxVersion.fromInt(1) + val grpcTx = genesisRegisterNodeTransaction { + id = ByteString.copyFromUtf8("DnK5Xfi2wXUJx9BjK9X6ZpFdTLdq2GtWH9pWrcxcmrhB") + fee = 10L + timestamp = 1716881331027L + signature = ByteString.copyFromUtf8( + "2Gns72hraH5yay3eiWeyHQEA1wTqiiAztaLjHinEYX91FEv62HFW38Hq89GnsEJFHUvo9KHYtBBrb8hgTA9wN7DM" + ) + } + + grpcTx.domain(txVersion).apply { + id.bytes shouldBe grpcTx.id.toByteArray() + targetPublicKey.bytes shouldBe grpcTx.targetPublicKey.toByteArray() + fee.value shouldBe grpcTx.fee + timestamp.utcTimestampMillis shouldBe grpcTx.timestamp + signature.bytes shouldBe grpcTx.signature.toByteArray() + version.value shouldBe txVersion.value + } + } +} diff --git a/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/GenesisTxMapperTest.kt b/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/GenesisTxMapperTest.kt new file mode 100644 index 00000000..f7d360e8 --- /dev/null +++ b/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/GenesisTxMapperTest.kt @@ -0,0 +1,51 @@ +package com.wavesenterprise.sdk.node.client.grpc.mapper.tx + +import com.wavesenterprise.sdk.node.client.grpc.mapper.AddressMapper.byteString +import com.wavesenterprise.sdk.node.client.grpc.mapper.SignatureMapper.byteString +import com.wavesenterprise.sdk.node.client.grpc.mapper.TxIdMapper.byteString +import com.wavesenterprise.sdk.node.client.grpc.mapper.tx.GenesisTxMapper.domain +import com.wavesenterprise.sdk.node.domain.Address +import com.wavesenterprise.sdk.node.domain.Amount +import com.wavesenterprise.sdk.node.domain.Fee +import com.wavesenterprise.sdk.node.domain.Signature +import com.wavesenterprise.sdk.node.domain.Timestamp +import com.wavesenterprise.sdk.node.domain.TxId +import com.wavesenterprise.sdk.node.domain.TxVersion +import com.wavesenterprise.transaction.protobuf.genesisTransaction +import io.kotest.matchers.shouldBe +import org.junit.jupiter.api.Test + +class GenesisTxMapperTest { + + @Test + fun `should map to GenesisTx (all fields)`() { + val txId = TxId.fromBase58("DnK5Xfi2wXUJx9BjK9X6ZpFdTLdq2GtWH9pWrcxcmrhB") + val txAmount = Amount(1000L) + val txFee = Fee(10L) + val txTimestamp = Timestamp(1716881331027L) + val txRecipient = Address("3N9vL3apA4j2L5PojHW8TYmfHx9Lo2ZaKPB".toByteArray()) + val txSignature = Signature( + "2Gns72hraH5yay3eiWeyHQEA1wTqiiAztaLjHinEYX91FEv62HFW38Hq89GnsEJFHUvo9KHYtBBrb8hgTA9wN7DM".toByteArray() + ) + val txVersion = TxVersion.fromInt(1) + + val grpcTx = genesisTransaction { + id = txId.byteString() + amount = txAmount.value + fee = txFee.value + timestamp = txTimestamp.utcTimestampMillis + recipient = txRecipient.byteString() + signature = txSignature.byteString() + } + + grpcTx.domain(txVersion).apply { + id.bytes shouldBe grpcTx.id.toByteArray() + amount.value shouldBe grpcTx.amount + fee.value shouldBe grpcTx.fee + timestamp.utcTimestampMillis shouldBe grpcTx.timestamp + recipient.bytes shouldBe grpcTx.recipient.toByteArray() + signature.bytes shouldBe grpcTx.signature.toByteArray() + version.value shouldBe txVersion.value + } + } +} diff --git a/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/IssueTxMapperTest.kt b/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/IssueTxMapperTest.kt new file mode 100644 index 00000000..16e19715 --- /dev/null +++ b/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/IssueTxMapperTest.kt @@ -0,0 +1,110 @@ +package com.wavesenterprise.sdk.node.client.grpc.mapper.tx + +import com.google.protobuf.BytesValue +import com.wavesenterprise.sdk.node.client.grpc.mapper.GrpcTypesMapper.byteArray +import com.wavesenterprise.sdk.node.client.grpc.mapper.tx.IssueTxMapper.domain +import com.wavesenterprise.sdk.node.domain.Address +import com.wavesenterprise.sdk.node.domain.ChainId +import com.wavesenterprise.sdk.node.domain.Decimals +import com.wavesenterprise.sdk.node.domain.Fee +import com.wavesenterprise.sdk.node.domain.IssueTxDescription +import com.wavesenterprise.sdk.node.domain.IssueTxName +import com.wavesenterprise.sdk.node.domain.PublicKey +import com.wavesenterprise.sdk.node.domain.Quantity +import com.wavesenterprise.sdk.node.domain.Reissuable +import com.wavesenterprise.sdk.node.domain.Script +import com.wavesenterprise.sdk.node.domain.Signature +import com.wavesenterprise.sdk.node.domain.Timestamp +import com.wavesenterprise.sdk.node.domain.TxId +import com.wavesenterprise.sdk.node.domain.TxVersion +import com.wavesenterprise.sdk.node.domain.tx.IssueTx +import com.wavesenterprise.transaction.protobuf.assets.issueTransaction +import io.kotest.matchers.shouldBe +import org.junit.jupiter.api.Test + +@Suppress +class IssueTxMapperTest { + @Test + fun `should map to IssueTx (all fields)`() { + val txVersion = TxVersion.fromInt(1) + val grpcTx = issueTransaction { + id = byteString("DnK5Xfi2wXUJx9BjK9X6ZpFdTLdq2GtWH9pWrcxcmrhB") + chainId = 73 + senderPublicKey = byteString("C4eRfdUFaZMRkfUp91bYr7uMgdBRnUfAxuAjetxmK7KY") + name = byteString("not_coin") + description = byteString("description") + quantity = 1_000_000L + decimals = 5 + reissuable = false + fee = 10L + timestamp = 1716881331027L + script = BytesValue.of(byteString("script")) + proofs += byteString( + "2Gns72hraH5yay3eiWeyHQEA1wTqiiAztaLjHinEYX91FEv62HFW38Hq89GnsEJFHUvo9KHYtBBrb8hgTA9wN7DM" + ) + senderAddress = byteString("3N9vL3apA4j2L5PojHW8TYmfHx9Lo2ZaKPB") + } + grpcTx.domain(txVersion).apply { + shouldBe( + IssueTx( + id = TxId(grpcTx.id.byteArray()), + chainId = ChainId(grpcTx.chainId.toByte()), + senderPublicKey = PublicKey(grpcTx.senderPublicKey.byteArray()), + name = IssueTxName(grpcTx.name.byteArray()), + description = IssueTxDescription(grpcTx.description.byteArray()), + quantity = Quantity(grpcTx.quantity), + decimals = Decimals(grpcTx.decimals.toByte()), + reissuable = Reissuable(grpcTx.reissuable), + fee = Fee(grpcTx.fee), + timestamp = Timestamp.fromUtcTimestamp(grpcTx.timestamp), + script = Script(grpcTx.script.value.byteArray()), + proofs = grpcTx.proofsList.map { Signature(it.byteArray()) }, + senderAddress = Address(grpcTx.senderAddress.byteArray()), + version = txVersion, + ) + ) + } + } + + @Test + fun `should map to IssueTx (with nulls)`() { + val txVersion = TxVersion.fromInt(1) + val grpcTx = issueTransaction { + id = byteString("DnK5Xfi2wXUJx9BjK9X6ZpFdTLdq2GtWH9pWrcxcmrhB") + chainId = 73 + senderPublicKey = byteString("C4eRfdUFaZMRkfUp91bYr7uMgdBRnUfAxuAjetxmK7KY") + name = byteString("not_coin") + description = byteString("description") + quantity = 1_000_000L + decimals = 5 + reissuable = false + fee = 10L + timestamp = 1716881331027L + clearScript() + proofs += byteString( + "2Gns72hraH5yay3eiWeyHQEA1wTqiiAztaLjHinEYX91FEv62HFW38Hq89GnsEJFHUvo9KHYtBBrb8hgTA9wN7DM" + ) + senderAddress = byteString("3N9vL3apA4j2L5PojHW8TYmfHx9Lo2ZaKPB") + } + grpcTx.domain(txVersion).apply { + shouldBe( + IssueTx( + id = TxId(grpcTx.id.byteArray()), + chainId = ChainId(grpcTx.chainId.toByte()), + senderPublicKey = PublicKey(grpcTx.senderPublicKey.byteArray()), + name = IssueTxName(grpcTx.name.byteArray()), + description = IssueTxDescription(grpcTx.description.byteArray()), + quantity = Quantity(grpcTx.quantity), + decimals = Decimals(grpcTx.decimals.toByte()), + reissuable = Reissuable(grpcTx.reissuable), + fee = Fee(grpcTx.fee), + timestamp = Timestamp.fromUtcTimestamp(grpcTx.timestamp), + script = null, + proofs = grpcTx.proofsList.map { Signature(it.byteArray()) }, + senderAddress = Address(grpcTx.senderAddress.byteArray()), + version = txVersion, + ) + ) + } + } +} diff --git a/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/LeaseCancelTxMapperTest.kt b/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/LeaseCancelTxMapperTest.kt new file mode 100644 index 00000000..94e73be9 --- /dev/null +++ b/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/LeaseCancelTxMapperTest.kt @@ -0,0 +1,54 @@ +package com.wavesenterprise.sdk.node.client.grpc.mapper.tx + +import com.wavesenterprise.sdk.node.client.grpc.mapper.GrpcTypesMapper.byteArray +import com.wavesenterprise.sdk.node.client.grpc.mapper.tx.LeaseCancelTxMapper.domain +import com.wavesenterprise.sdk.node.domain.Address +import com.wavesenterprise.sdk.node.domain.ChainId +import com.wavesenterprise.sdk.node.domain.Fee +import com.wavesenterprise.sdk.node.domain.LeaseId +import com.wavesenterprise.sdk.node.domain.PublicKey +import com.wavesenterprise.sdk.node.domain.Signature +import com.wavesenterprise.sdk.node.domain.Timestamp +import com.wavesenterprise.sdk.node.domain.TxId +import com.wavesenterprise.sdk.node.domain.TxVersion +import com.wavesenterprise.sdk.node.domain.tx.LeaseCancelTx +import com.wavesenterprise.transaction.protobuf.lease.leaseCancelTransaction +import io.kotest.matchers.shouldBe +import org.junit.jupiter.api.Test + +class LeaseCancelTxMapperTest { + + @Test + fun `should map to LeaseCancelTx (all fields)`() { + val txVersion = TxVersion.fromInt(1) + val grpcTx = leaseCancelTransaction { + id = byteString("DnK5Xfi2wXUJx9BjK9X6ZpFdTLdq2GtWH9pWrcxcmrhB") + chainId = 73 + senderPublicKey = byteString("C4eRfdUFaZMRkfUp91bYr7uMgdBRnUfAxuAjetxmK7KY") + fee = 10L + timestamp = 1716881331027L + leaseId = byteString("leaseId") + proofs += byteString( + "2Gns72hraH5yay3eiWeyHQEA1wTqiiAztaLjHinEYX91FEv62HFW38Hq89GnsEJFHUvo9KHYtBBrb8hgTA9wN7DM" + ) + senderAddress = byteString("3N9vL3apA4j2L5PojHW8TYmfHx9Lo2ZaKPB") + } + grpcTx + .domain(txVersion) + .shouldBe( + LeaseCancelTx( + id = TxId(grpcTx.id.byteArray()), + chainId = ChainId(grpcTx.chainId.toByte()), + senderPublicKey = PublicKey(grpcTx.senderPublicKey.byteArray()), + fee = Fee(grpcTx.fee), + timestamp = Timestamp(grpcTx.timestamp), + leaseId = LeaseId( + txId = TxId(grpcTx.leaseId.byteArray()) + ), + proofs = grpcTx.proofsList.map { Signature(it.byteArray()) }, + senderAddress = Address(grpcTx.senderAddress.byteArray()), + version = txVersion, + ) + ) + } +} diff --git a/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/LeaseTxMapperTest.kt b/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/LeaseTxMapperTest.kt new file mode 100644 index 00000000..f7ded255 --- /dev/null +++ b/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/LeaseTxMapperTest.kt @@ -0,0 +1,89 @@ +package com.wavesenterprise.sdk.node.client.grpc.mapper.tx + +import com.google.protobuf.bytesValue +import com.wavesenterprise.sdk.node.client.grpc.mapper.GrpcTypesMapper.byteArray +import com.wavesenterprise.sdk.node.client.grpc.mapper.tx.LeaseTxMapper.domain +import com.wavesenterprise.sdk.node.domain.Address +import com.wavesenterprise.sdk.node.domain.Amount +import com.wavesenterprise.sdk.node.domain.AssetId +import com.wavesenterprise.sdk.node.domain.Fee +import com.wavesenterprise.sdk.node.domain.PublicKey +import com.wavesenterprise.sdk.node.domain.Signature +import com.wavesenterprise.sdk.node.domain.Timestamp +import com.wavesenterprise.sdk.node.domain.TxId +import com.wavesenterprise.sdk.node.domain.TxVersion +import com.wavesenterprise.sdk.node.domain.tx.LeaseTx +import com.wavesenterprise.transaction.protobuf.lease.leaseTransaction +import io.kotest.matchers.shouldBe +import org.junit.jupiter.api.Test + +class LeaseTxMapperTest { + + @Test + fun `should map to LeaseTx (all fields)`() { + val txVersion = TxVersion.fromInt(1) + val grpcTx = leaseTransaction { + id = byteString("DnK5Xfi2wXUJx9BjK9X6ZpFdTLdq2GtWH9pWrcxcmrhB") + assetId = bytesValue { byteString("assetId") } + senderPublicKey = byteString("C4eRfdUFaZMRkfUp91bYr7uMgdBRnUfAxuAjetxmK7KY") + recipient = byteString("3N9vL3apA4j2L5PojHW8TYmfHx9Lo2ZaKPB") + amount = 1_000_000L + fee = 10L + timestamp = 1716881331027L + proofs += byteString( + "2Gns72hraH5yay3eiWeyHQEA1wTqiiAztaLjHinEYX91FEv62HFW38Hq89GnsEJFHUvo9KHYtBBrb8hgTA9wN7DM" + ) + senderAddress = byteString("3N9vL3apA4j2L5PojHW8TYmfHx9Lo2ZaKPB") + } + grpcTx + .domain(txVersion) + .shouldBe( + LeaseTx( + id = TxId(grpcTx.id.byteArray()), + assetId = AssetId(grpcTx.assetId.byteArray()), + senderPublicKey = PublicKey(grpcTx.senderPublicKey.byteArray()), + recipient = Address(grpcTx.recipient.byteArray()), + amount = Amount(grpcTx.amount), + fee = Fee(grpcTx.fee), + timestamp = Timestamp(grpcTx.timestamp), + proofs = grpcTx.proofsList.map { Signature(it.byteArray()) }, + senderAddress = Address(grpcTx.senderAddress.byteArray()), + version = txVersion, + ) + ) + } + + @Test + fun `should map to LeaseTx (with nulls)`() { + val txVersion = TxVersion.fromInt(1) + val grpcTx = leaseTransaction { + id = byteString("DnK5Xfi2wXUJx9BjK9X6ZpFdTLdq2GtWH9pWrcxcmrhB") + clearAssetId() + senderPublicKey = byteString("C4eRfdUFaZMRkfUp91bYr7uMgdBRnUfAxuAjetxmK7KY") + recipient = byteString("3N9vL3apA4j2L5PojHW8TYmfHx9Lo2ZaKPB") + amount = 1_000_000L + fee = 10L + timestamp = 1716881331027L + proofs += byteString( + "2Gns72hraH5yay3eiWeyHQEA1wTqiiAztaLjHinEYX91FEv62HFW38Hq89GnsEJFHUvo9KHYtBBrb8hgTA9wN7DM" + ) + senderAddress = byteString("3N9vL3apA4j2L5PojHW8TYmfHx9Lo2ZaKPB") + } + grpcTx + .domain(txVersion) + .shouldBe( + LeaseTx( + id = TxId(grpcTx.id.byteArray()), + assetId = null, + senderPublicKey = PublicKey(grpcTx.senderPublicKey.byteArray()), + recipient = Address(grpcTx.recipient.byteArray()), + amount = Amount(grpcTx.amount), + fee = Fee(grpcTx.fee), + timestamp = Timestamp(grpcTx.timestamp), + proofs = grpcTx.proofsList.map { Signature(it.byteArray()) }, + senderAddress = Address(grpcTx.senderAddress.byteArray()), + version = txVersion, + ) + ) + } +} diff --git a/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/MassTransferTxMapperTest.kt b/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/MassTransferTxMapperTest.kt new file mode 100644 index 00000000..e37024a1 --- /dev/null +++ b/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/MassTransferTxMapperTest.kt @@ -0,0 +1,120 @@ +package com.wavesenterprise.sdk.node.client.grpc.mapper.tx + +import com.google.protobuf.bytesValue +import com.wavesenterprise.sdk.node.client.grpc.mapper.GrpcTypesMapper.byteArray +import com.wavesenterprise.sdk.node.client.grpc.mapper.tx.MassTransferTxMapper.domain +import com.wavesenterprise.sdk.node.client.grpc.mapper.tx.TransferTxMapper.domain +import com.wavesenterprise.sdk.node.domain.Address +import com.wavesenterprise.sdk.node.domain.Amount +import com.wavesenterprise.sdk.node.domain.AssetId +import com.wavesenterprise.sdk.node.domain.Attachment +import com.wavesenterprise.sdk.node.domain.Fee +import com.wavesenterprise.sdk.node.domain.FeeAssetId +import com.wavesenterprise.sdk.node.domain.PublicKey +import com.wavesenterprise.sdk.node.domain.Signature +import com.wavesenterprise.sdk.node.domain.Timestamp +import com.wavesenterprise.sdk.node.domain.Transfer +import com.wavesenterprise.sdk.node.domain.TxId +import com.wavesenterprise.sdk.node.domain.TxVersion +import com.wavesenterprise.sdk.node.domain.tx.MassTransferTx +import com.wavesenterprise.transaction.protobuf.transfer +import com.wavesenterprise.transaction.protobuf.transfer.massTransferTransaction +import io.kotest.matchers.shouldBe +import org.junit.jupiter.api.Test + +class MassTransferTxMapperTest { + + @Test + fun `should map to MassTransferTx (all fields)`() { + val txVersion = TxVersion.fromInt(1) + val grpcTx = massTransferTransaction { + id = byteString("DnK5Xfi2wXUJx9BjK9X6ZpFdTLdq2GtWH9pWrcxcmrhB") + senderPublicKey = byteString("C4eRfdUFaZMRkfUp91bYr7uMgdBRnUfAxuAjetxmK7KY") + assetId = bytesValue { + byteString("assetId") + } + feeAssetId = bytesValue { + byteString("feeAssetId") + } + transfers += transfer { + recipient = byteString("recipient") + amount = 100L + } + timestamp = 1716881331027L + fee = 10L + attachment = byteString("attachment") + proofs += byteString( + "2Gns72hraH5yay3eiWeyHQEA1wTqiiAztaLjHinEYX91FEv62HFW38Hq89GnsEJFHUvo9KHYtBBrb8hgTA9wN7DM" + ) + senderAddress = byteString("3N9vL3apA4j2L5PojHW8TYmfHx9Lo2ZaKPB") + } + grpcTx + .domain(txVersion) + .shouldBe( + MassTransferTx( + id = TxId(grpcTx.id.byteArray()), + senderPublicKey = PublicKey(grpcTx.senderPublicKey.byteArray()), + assetId = AssetId(grpcTx.assetId.value.byteArray()), + transfers = listOf( + Transfer( + recipient = Address("recipient".toByteArray()), + amount = Amount(100L), + ) + ), + feeAssetId = FeeAssetId( + txId = TxId(grpcTx.feeAssetId.value.byteArray()), + ), + timestamp = Timestamp(grpcTx.timestamp), + fee = Fee(grpcTx.fee), + attachment = Attachment(grpcTx.attachment.byteArray()), + proofs = grpcTx.proofsList?.map { Signature(it.byteArray()) }, + senderAddress = Address(grpcTx.senderAddress.byteArray()), + version = txVersion, + ) + ) + } + + @Test + fun `should map to MassTransferTx (with nulls)`() { + val txVersion = TxVersion.fromInt(1) + val grpcTx = massTransferTransaction { + id = byteString("DnK5Xfi2wXUJx9BjK9X6ZpFdTLdq2GtWH9pWrcxcmrhB") + senderPublicKey = byteString("C4eRfdUFaZMRkfUp91bYr7uMgdBRnUfAxuAjetxmK7KY") + clearAssetId() + clearFeeAssetId() + transfers += transfer { + recipient = byteString("recipient") + amount = 100L + } + timestamp = 1716881331027L + fee = 10L + attachment = byteString("attachment") + proofs += byteString( + "2Gns72hraH5yay3eiWeyHQEA1wTqiiAztaLjHinEYX91FEv62HFW38Hq89GnsEJFHUvo9KHYtBBrb8hgTA9wN7DM" + ) + senderAddress = byteString("3N9vL3apA4j2L5PojHW8TYmfHx9Lo2ZaKPB") + } + grpcTx + .domain(txVersion) + .shouldBe( + MassTransferTx( + id = TxId(grpcTx.id.byteArray()), + senderPublicKey = PublicKey(grpcTx.senderPublicKey.byteArray()), + assetId = null, + transfers = listOf( + Transfer( + recipient = Address("recipient".toByteArray()), + amount = Amount(100L), + ) + ), + feeAssetId = null, + timestamp = Timestamp(grpcTx.timestamp), + fee = Fee(grpcTx.fee), + attachment = Attachment(grpcTx.attachment.byteArray()), + proofs = grpcTx.proofsList?.map { Signature(it.byteArray()) }, + senderAddress = Address(grpcTx.senderAddress.byteArray()), + version = txVersion, + ) + ) + } +} diff --git a/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/PermitTxMapperTest.kt b/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/PermitTxMapperTest.kt new file mode 100644 index 00000000..ff161b59 --- /dev/null +++ b/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/PermitTxMapperTest.kt @@ -0,0 +1,143 @@ +package com.wavesenterprise.sdk.node.client.grpc.mapper.tx + +import com.google.protobuf.bytesValue +import com.google.protobuf.int64Value +import com.wavesenterprise.sdk.node.client.grpc.mapper.GrpcTypesMapper.byteArray +import com.wavesenterprise.sdk.node.client.grpc.mapper.tx.PermitTxMapper.domain +import com.wavesenterprise.sdk.node.domain.Address +import com.wavesenterprise.sdk.node.domain.Fee +import com.wavesenterprise.sdk.node.domain.OpType +import com.wavesenterprise.sdk.node.domain.PermissionOp +import com.wavesenterprise.sdk.node.domain.PublicKey +import com.wavesenterprise.sdk.node.domain.Role +import com.wavesenterprise.sdk.node.domain.Signature +import com.wavesenterprise.sdk.node.domain.Timestamp +import com.wavesenterprise.sdk.node.domain.TxId +import com.wavesenterprise.sdk.node.domain.TxVersion +import com.wavesenterprise.sdk.node.domain.atomic.AtomicBadge +import com.wavesenterprise.sdk.node.domain.tx.PermitTx +import com.wavesenterprise.transaction.protobuf.acl.permitTransaction +import com.wavesenterprise.transaction.protobuf.atomicBadge +import com.wavesenterprise.transaction.protobuf.permissionOp +import com.wavesenterprise.transaction.protobuf.role +import io.kotest.matchers.shouldBe +import org.junit.jupiter.api.TestInstance +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.MethodSource +import com.wavesenterprise.transaction.protobuf.OpType as ProtoOpType +import com.wavesenterprise.transaction.protobuf.PermissionOp as ProtoPermissionOp + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +class PermitTxMapperTest { + + @ParameterizedTest + @MethodSource("permissionOpMappingArguments") + fun `should map to PermitTx (all fields)`(permissionOpMapping: TestPermissionOpMapping) { + val txVersion = TxVersion.fromInt(1) + val grpcTx = permitTransaction { + id = byteString("DnK5Xfi2wXUJx9BjK9X6ZpFdTLdq2GtWH9pWrcxcmrhB") + senderPublicKey = byteString("C4eRfdUFaZMRkfUp91bYr7uMgdBRnUfAxuAjetxmK7KY") + target = byteString("3N9vL3apA4j2L5PojHW8TYmfHx9Lo2ZaKPB") + timestamp = 1716881331027L + fee = 10L + permissionOp = permissionOpMapping.protoParam + atomicBadge = atomicBadge { + trustedSender = bytesValue { + byteString("3M7EEnszPAT2yr72SgWVDLxfYCa4AYvVRwv") + } + } + proofs += byteString( + "2Gns72hraH5yay3eiWeyHQEA1wTqiiAztaLjHinEYX91FEv62HFW38Hq89GnsEJFHUvo9KHYtBBrb8hgTA9wN7DM" + ) + senderAddress = byteString("3N9vL3apA4j2L5PojHW8TYmfHx9Lo2ZaKPB") + } + grpcTx + .domain(txVersion) + .shouldBe( + PermitTx( + id = TxId(grpcTx.id.byteArray()), + senderPublicKey = PublicKey(grpcTx.senderPublicKey.byteArray()), + target = Address(grpcTx.target.byteArray()), + timestamp = Timestamp(grpcTx.timestamp), + fee = Fee(grpcTx.fee), + permissionOp = permissionOpMapping.domainParam, + atomicBadge = AtomicBadge( + trustedSender = Address(grpcTx.atomicBadge.trustedSender.value.toByteArray()), + ), + proofs = grpcTx.proofsList?.map { Signature(it.byteArray()) }, + senderAddress = Address(grpcTx.senderAddress.byteArray()), + version = txVersion, + ) + ) + } + + @ParameterizedTest + @MethodSource("permissionOpMappingArguments") + fun `should map to PermitTx (with nulls)`(permissionOpMapping: TestPermissionOpMapping) { + val txVersion = TxVersion.fromInt(1) + val grpcTx = permitTransaction { + id = byteString("DnK5Xfi2wXUJx9BjK9X6ZpFdTLdq2GtWH9pWrcxcmrhB") + senderPublicKey = byteString("C4eRfdUFaZMRkfUp91bYr7uMgdBRnUfAxuAjetxmK7KY") + target = byteString("3N9vL3apA4j2L5PojHW8TYmfHx9Lo2ZaKPB") + timestamp = 1716881331027L + fee = 10L + permissionOp = permissionOpMapping.protoParam + clearAtomicBadge() + proofs += byteString( + "2Gns72hraH5yay3eiWeyHQEA1wTqiiAztaLjHinEYX91FEv62HFW38Hq89GnsEJFHUvo9KHYtBBrb8hgTA9wN7DM" + ) + senderAddress = byteString("3N9vL3apA4j2L5PojHW8TYmfHx9Lo2ZaKPB") + } + grpcTx + .domain(txVersion) + .shouldBe( + PermitTx( + id = TxId(grpcTx.id.byteArray()), + senderPublicKey = PublicKey(grpcTx.senderPublicKey.byteArray()), + target = Address(grpcTx.target.byteArray()), + timestamp = Timestamp(grpcTx.timestamp), + fee = Fee(grpcTx.fee), + permissionOp = permissionOpMapping.domainParam, + atomicBadge = null, + proofs = grpcTx.proofsList?.map { Signature(it.byteArray()) }, + senderAddress = Address(grpcTx.senderAddress.byteArray()), + version = txVersion, + ) + ) + } + + private fun permissionOpMappingArguments(): List { + val opTypes = OpType.values().toMutableList().also { + it.remove(OpType.UNKNOWN) + } + val roles = Role.values().toList() + val timestamp = 1716881331027L + val dueTimestamp = 1716881331027L + val test = cartesianProduct(opTypes, roles) + return test.map { (opType, role) -> + TestPermissionOpMapping( + protoParam = permissionOp { + this.opType = ProtoOpType.valueOf(opType.name) + this.role = role { + id = role.code + } + this.timestamp = timestamp + this.dueTimestamp = int64Value { + value = dueTimestamp + } + }, + domainParam = PermissionOp( + opType = opType, + role = role, + timestamp = Timestamp(1716881331027L), + dueTimestamp = Timestamp(1716881331027L), + ), + ) + } + } + + data class TestPermissionOpMapping( + val protoParam: ProtoPermissionOp, + val domainParam: PermissionOp, + ) +} diff --git a/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/PolicyDataHashTxMapperTest.kt b/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/PolicyDataHashTxMapperTest.kt new file mode 100644 index 00000000..741c7684 --- /dev/null +++ b/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/PolicyDataHashTxMapperTest.kt @@ -0,0 +1,113 @@ +package com.wavesenterprise.sdk.node.client.grpc.mapper.tx + +import com.google.protobuf.bytesValue +import com.wavesenterprise.sdk.node.client.grpc.mapper.tx.PolicyDataHashTxMapper.domain +import com.wavesenterprise.sdk.node.domain.Address +import com.wavesenterprise.sdk.node.domain.Fee +import com.wavesenterprise.sdk.node.domain.FeeAssetId +import com.wavesenterprise.sdk.node.domain.Hash +import com.wavesenterprise.sdk.node.domain.PolicyId +import com.wavesenterprise.sdk.node.domain.PublicKey +import com.wavesenterprise.sdk.node.domain.Signature +import com.wavesenterprise.sdk.node.domain.Timestamp +import com.wavesenterprise.sdk.node.domain.TxId +import com.wavesenterprise.sdk.node.domain.TxVersion +import com.wavesenterprise.sdk.node.domain.atomic.AtomicBadge +import com.wavesenterprise.sdk.node.domain.tx.PolicyDataHashTx +import com.wavesenterprise.transaction.protobuf.atomicBadge +import com.wavesenterprise.transaction.protobuf.policyDataHashTransaction +import io.kotest.matchers.shouldBe +import org.junit.jupiter.api.Test + +class PolicyDataHashTxMapperTest { + + @Test + fun `should map to PolicyDataHashTx (all fields)`() { + val grpcTx = policyDataHashTransaction { + id = byteString("DnK5Xfi2wXUJx9BjK9X6ZpFdTLdq2GtWH9pWrcxcmrhB") + senderPublicKey = byteString("3M1V41oGFr3hLmo3ecNQWPWVHPSfsguWepc") + dataHash = byteString("8GPtHQeLxhtt8HianM9c8otS2EeAHNVZCfpCRUmYbSFi") + policyId = byteString("UkvoboGXiwWpASr1GLG9M1MUbhrEMo4NBS7kquxVMw5") + timestamp = 1716881331027L + fee = 10L + feeAssetId = bytesValue { + value = byteString("3Ge1AptYWH3Xw2jCNkCkYLPECr5q4aSJMXKMSUGL4eEs") + } + atomicBadge = atomicBadge { + trustedSender = bytesValue { + value = byteString("3M7EEnszPAT2yr72SgWVDLxfYCa4AYvVRwv") + } + } + proofs += listOf( + byteString("4NccZyPCgchDjeMdMmFKu7kxyU8AFF4e9cWaPFTQVQyYU1ZCCu3QmtmkfJkrDpDwGs4eJhYUVh5TnwYvjZYKPhLp"), + byteString("QMGoz6rycNsDLhN3mDce2mqGRQQ8r26vDDw551pnYcAecpFBDA8j38FVqDjLTGuFHs6ScX32fsGcaemmptpCFHk"), + ) + senderAddress = byteString("3MLti6qku2gD4rhnRcypvFxJE5UYV2P2myM") + } + val txVersion = TxVersion.fromInt(3) + + grpcTx + .domain(txVersion) + .shouldBe( + PolicyDataHashTx( + id = TxId(grpcTx.id.toByteArray()), + senderPublicKey = PublicKey(grpcTx.senderPublicKey.toByteArray()), + dataHash = Hash(grpcTx.dataHash.toByteArray()), + policyId = PolicyId( + txId = TxId(grpcTx.policyId.toByteArray()) + ), + timestamp = Timestamp(grpcTx.timestamp), + fee = Fee(grpcTx.fee), + feeAssetId = FeeAssetId( + txId = TxId(grpcTx.feeAssetId.value.toByteArray()), + ), + atomicBadge = AtomicBadge( + trustedSender = Address(grpcTx.atomicBadge.trustedSender.value.toByteArray()), + ), + proofs = grpcTx.proofsList.map { Signature(it.toByteArray()) }.toList(), + senderAddress = Address(grpcTx.senderAddress.toByteArray()), + version = txVersion, + ) + ) + } + + @Test + fun `should map to PolicyDataHashTx (with nulls)`() { + val grpcTx = policyDataHashTransaction { + id = byteString("DnK5Xfi2wXUJx9BjK9X6ZpFdTLdq2GtWH9pWrcxcmrhB") + senderPublicKey = byteString("3M1V41oGFr3hLmo3ecNQWPWVHPSfsguWepc") + dataHash = byteString("8GPtHQeLxhtt8HianM9c8otS2EeAHNVZCfpCRUmYbSFi") + policyId = byteString("UkvoboGXiwWpASr1GLG9M1MUbhrEMo4NBS7kquxVMw5") + timestamp = 1716881331027L + fee = 10L + clearFeeAssetId() + clearAtomicBadge() + proofs += listOf( + byteString("4NccZyPCgchDjeMdMmFKu7kxyU8AFF4e9cWaPFTQVQyYU1ZCCu3QmtmkfJkrDpDwGs4eJhYUVh5TnwYvjZYKPhLp"), + byteString("QMGoz6rycNsDLhN3mDce2mqGRQQ8r26vDDw551pnYcAecpFBDA8j38FVqDjLTGuFHs6ScX32fsGcaemmptpCFHk"), + ) + senderAddress = byteString("3MLti6qku2gD4rhnRcypvFxJE5UYV2P2myM") + } + val txVersion = TxVersion.fromInt(1) + + grpcTx + .domain(txVersion) + .shouldBe( + PolicyDataHashTx( + id = TxId(grpcTx.id.toByteArray()), + senderPublicKey = PublicKey(grpcTx.senderPublicKey.toByteArray()), + dataHash = Hash(grpcTx.dataHash.toByteArray()), + policyId = PolicyId( + txId = TxId(grpcTx.policyId.toByteArray()) + ), + timestamp = Timestamp(grpcTx.timestamp), + fee = Fee(grpcTx.fee), + feeAssetId = null, + atomicBadge = null, + proofs = grpcTx.proofsList.map { Signature(it.toByteArray()) }.toList(), + senderAddress = Address(grpcTx.senderAddress.toByteArray()), + version = txVersion, + ) + ) + } +} diff --git a/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/RegisterNodeTxMapperTest.kt b/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/RegisterNodeTxMapperTest.kt new file mode 100644 index 00000000..94826193 --- /dev/null +++ b/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/RegisterNodeTxMapperTest.kt @@ -0,0 +1,91 @@ +package com.wavesenterprise.sdk.node.client.grpc.mapper.tx + +import com.google.protobuf.ByteString +import com.google.protobuf.StringValue +import com.wavesenterprise.sdk.node.client.grpc.mapper.tx.RegisterNodeTxMapper.domain +import com.wavesenterprise.sdk.node.domain.Address +import com.wavesenterprise.sdk.node.domain.Fee +import com.wavesenterprise.sdk.node.domain.NodeName +import com.wavesenterprise.sdk.node.domain.OpType +import com.wavesenterprise.sdk.node.domain.PublicKey +import com.wavesenterprise.sdk.node.domain.Signature +import com.wavesenterprise.sdk.node.domain.Timestamp +import com.wavesenterprise.sdk.node.domain.TxId +import com.wavesenterprise.sdk.node.domain.TxVersion +import com.wavesenterprise.sdk.node.domain.tx.RegisterNodeTx +import com.wavesenterprise.transaction.protobuf.registerNodeTransaction +import io.kotest.matchers.shouldBe +import org.junit.jupiter.api.Test +import com.wavesenterprise.transaction.protobuf.OpType as ProtoOpType + +class RegisterNodeTxMapperTest { + + @Test + fun `should map to RegisterNodeTx (all fields)`() { + val txVersion = TxVersion.fromInt(1) + val grpcTx = registerNodeTransaction { + id = ByteString.copyFromUtf8("DnK5Xfi2wXUJx9BjK9X6ZpFdTLdq2GtWH9pWrcxcmrhB") + senderPublicKey = ByteString.copyFromUtf8("3N9vL3apA4j2L5PojHW8TYmfHx9Lo2ZaKPB") + target = ByteString.copyFromUtf8("3N9vL3apA4j2L5PojHW8TYmfHx9Lo2ZaKPB") + nodeName = StringValue.of("node-0") + opType = ProtoOpType.ADD + timestamp = 1716881331027L + fee = 10L + senderAddress = ByteString.copyFromUtf8("3N9vL3apA4j2L5PojHW8TYmfHx9Lo2ZaKPB") + proofs += ByteString.copyFromUtf8( + "2Gns72hraH5yay3eiWeyHQEA1wTqiiAztaLjHinEYX91FEv62HFW38Hq89GnsEJFHUvo9KHYtBBrb8hgTA9wN7DM" + ) + } + grpcTx.domain(txVersion).apply { + shouldBe( + RegisterNodeTx( + id = TxId(grpcTx.id.toByteArray()), + senderPublicKey = PublicKey(grpcTx.senderPublicKey.toByteArray()), + targetPublicKey = PublicKey(grpcTx.target.toByteArray()), + nodeName = NodeName(grpcTx.nodeName.value), + opType = OpType.valueOf(grpcTx.opType.name), + timestamp = Timestamp(grpcTx.timestamp), + fee = Fee(grpcTx.fee), + senderAddress = Address(grpcTx.senderAddress.toByteArray()), + proofs = grpcTx.proofsList.map { Signature(it.toByteArray()) }, + version = txVersion, + ) + ) + } + } + + @Test + fun `should map to RegisterNodeTx (with nulls)`() { + val txVersion = TxVersion.fromInt(1) + val grpcTx = registerNodeTransaction { + id = ByteString.copyFromUtf8("DnK5Xfi2wXUJx9BjK9X6ZpFdTLdq2GtWH9pWrcxcmrhB") + senderPublicKey = ByteString.copyFromUtf8("3N9vL3apA4j2L5PojHW8TYmfHx9Lo2ZaKPB") + target = ByteString.copyFromUtf8("3N9vL3apA4j2L5PojHW8TYmfHx9Lo2ZaKPB") + clearNodeName() + opType = ProtoOpType.ADD + timestamp = 1716881331027L + fee = 10L + senderAddress = ByteString.copyFromUtf8("3N9vL3apA4j2L5PojHW8TYmfHx9Lo2ZaKPB") + proofs += ByteString.copyFromUtf8( + "2Gns72hraH5yay3eiWeyHQEA1wTqiiAztaLjHinEYX91FEv62HFW38Hq89GnsEJFHUvo9KHYtBBrb8hgTA9wN7DM" + ) + } + + grpcTx.domain(txVersion).apply { + shouldBe( + RegisterNodeTx( + id = TxId(grpcTx.id.toByteArray()), + senderPublicKey = PublicKey(grpcTx.senderPublicKey.toByteArray()), + targetPublicKey = PublicKey(grpcTx.target.toByteArray()), + nodeName = null, + opType = OpType.valueOf(grpcTx.opType.name), + timestamp = Timestamp(grpcTx.timestamp), + fee = Fee(grpcTx.fee), + senderAddress = Address(grpcTx.senderAddress.toByteArray()), + proofs = grpcTx.proofsList.map { Signature(it.toByteArray()) }, + version = txVersion, + ) + ) + } + } +} diff --git a/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/ReissueTxMapperTest.kt b/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/ReissueTxMapperTest.kt new file mode 100644 index 00000000..0ea106ef --- /dev/null +++ b/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/ReissueTxMapperTest.kt @@ -0,0 +1,57 @@ +package com.wavesenterprise.sdk.node.client.grpc.mapper.tx + +import com.wavesenterprise.sdk.node.client.grpc.mapper.GrpcTypesMapper.byteArray +import com.wavesenterprise.sdk.node.client.grpc.mapper.tx.ReissueTxMapper.domain +import com.wavesenterprise.sdk.node.domain.Address +import com.wavesenterprise.sdk.node.domain.AssetId +import com.wavesenterprise.sdk.node.domain.ChainId +import com.wavesenterprise.sdk.node.domain.Fee +import com.wavesenterprise.sdk.node.domain.PublicKey +import com.wavesenterprise.sdk.node.domain.Quantity +import com.wavesenterprise.sdk.node.domain.Reissuable +import com.wavesenterprise.sdk.node.domain.Signature +import com.wavesenterprise.sdk.node.domain.Timestamp +import com.wavesenterprise.sdk.node.domain.TxId +import com.wavesenterprise.sdk.node.domain.TxVersion +import com.wavesenterprise.sdk.node.domain.tx.ReissueTx +import com.wavesenterprise.transaction.protobuf.assets.reissueTransaction +import io.kotest.matchers.shouldBe +import org.junit.jupiter.api.Test + +class ReissueTxMapperTest { + @Test + fun `should map to ReissueTx (all fields)`() { + val txVersion = TxVersion.fromInt(1) + val grpcTx = reissueTransaction { + id = byteString("DnK5Xfi2wXUJx9BjK9X6ZpFdTLdq2GtWH9pWrcxcmrhB") + chainId = 73 + senderPublicKey = byteString("C4eRfdUFaZMRkfUp91bYr7uMgdBRnUfAxuAjetxmK7KY") + assetId = byteString("assetId") + quantity = 1_000_000L + reissuable = false + fee = 10L + timestamp = 1716881331027L + proofs += byteString( + "2Gns72hraH5yay3eiWeyHQEA1wTqiiAztaLjHinEYX91FEv62HFW38Hq89GnsEJFHUvo9KHYtBBrb8hgTA9wN7DM" + ) + senderAddress = byteString("3N9vL3apA4j2L5PojHW8TYmfHx9Lo2ZaKPB") + } + grpcTx + .domain(txVersion) + .shouldBe( + ReissueTx( + id = TxId(grpcTx.id.byteArray()), + chainId = ChainId(grpcTx.chainId.toByte()), + senderPublicKey = PublicKey(grpcTx.senderPublicKey.byteArray()), + assetId = AssetId(grpcTx.assetId.byteArray()), + quantity = Quantity(grpcTx.quantity), + reissuable = Reissuable(grpcTx.reissuable), + fee = Fee(grpcTx.fee), + timestamp = Timestamp(grpcTx.timestamp), + proofs = grpcTx.proofsList.map { Signature(it.byteArray()) }, + senderAddress = Address(grpcTx.senderAddress.byteArray()), + version = txVersion, + ) + ) + } +} diff --git a/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/SetAssetScriptTxMapperTest.kt b/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/SetAssetScriptTxMapperTest.kt new file mode 100644 index 00000000..f21eeccb --- /dev/null +++ b/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/SetAssetScriptTxMapperTest.kt @@ -0,0 +1,92 @@ +package com.wavesenterprise.sdk.node.client.grpc.mapper.tx + +import com.google.protobuf.bytesValue +import com.wavesenterprise.sdk.node.client.grpc.mapper.GrpcTypesMapper.byteArray +import com.wavesenterprise.sdk.node.client.grpc.mapper.tx.SetAssetScriptTxMapper.domain +import com.wavesenterprise.sdk.node.domain.Address +import com.wavesenterprise.sdk.node.domain.AssetId +import com.wavesenterprise.sdk.node.domain.ChainId +import com.wavesenterprise.sdk.node.domain.Fee +import com.wavesenterprise.sdk.node.domain.PublicKey +import com.wavesenterprise.sdk.node.domain.Script +import com.wavesenterprise.sdk.node.domain.Signature +import com.wavesenterprise.sdk.node.domain.Timestamp +import com.wavesenterprise.sdk.node.domain.TxId +import com.wavesenterprise.sdk.node.domain.TxVersion +import com.wavesenterprise.sdk.node.domain.tx.SetAssetScriptTx +import com.wavesenterprise.transaction.protobuf.assets.setAssetScriptTransaction +import io.kotest.matchers.shouldBe +import org.junit.jupiter.api.Test + +class SetAssetScriptTxMapperTest { + + @Test + fun `should map to SetAssetScriptTx (all fields)`() { + val txVersion = TxVersion.fromInt(1) + val grpcTx = setAssetScriptTransaction { + id = byteString("DnK5Xfi2wXUJx9BjK9X6ZpFdTLdq2GtWH9pWrcxcmrhB") + chainId = 73 + assetId = byteString("assetId") + script = bytesValue { + value = byteString("script") + } + senderPublicKey = byteString("C4eRfdUFaZMRkfUp91bYr7uMgdBRnUfAxuAjetxmK7KY") + fee = 10L + timestamp = 1716881331027L + proofs += byteString( + "2Gns72hraH5yay3eiWeyHQEA1wTqiiAztaLjHinEYX91FEv62HFW38Hq89GnsEJFHUvo9KHYtBBrb8hgTA9wN7DM" + ) + senderAddress = byteString("3N9vL3apA4j2L5PojHW8TYmfHx9Lo2ZaKPB") + } + grpcTx + .domain(txVersion) + .shouldBe( + SetAssetScriptTx( + id = TxId(grpcTx.id.byteArray()), + chainId = ChainId(grpcTx.chainId.toByte()), + assetId = AssetId(grpcTx.assetId.byteArray()), + script = Script(grpcTx.script.value.byteArray()), + senderPublicKey = PublicKey(grpcTx.senderPublicKey.byteArray()), + fee = Fee(grpcTx.fee), + timestamp = Timestamp(grpcTx.timestamp), + proofs = grpcTx.proofsList.map { Signature(it.byteArray()) }, + senderAddress = Address(grpcTx.senderAddress.byteArray()), + version = txVersion, + ) + ) + } + + @Test + fun `should map to SetAssetScriptTx (with nulls)`() { + val txVersion = TxVersion.fromInt(1) + val grpcTx = setAssetScriptTransaction { + id = byteString("DnK5Xfi2wXUJx9BjK9X6ZpFdTLdq2GtWH9pWrcxcmrhB") + chainId = 73 + assetId = byteString("assetId") + clearScript() + senderPublicKey = byteString("C4eRfdUFaZMRkfUp91bYr7uMgdBRnUfAxuAjetxmK7KY") + fee = 10L + timestamp = 1716881331027L + proofs += byteString( + "2Gns72hraH5yay3eiWeyHQEA1wTqiiAztaLjHinEYX91FEv62HFW38Hq89GnsEJFHUvo9KHYtBBrb8hgTA9wN7DM" + ) + senderAddress = byteString("3N9vL3apA4j2L5PojHW8TYmfHx9Lo2ZaKPB") + } + grpcTx + .domain(txVersion) + .shouldBe( + SetAssetScriptTx( + id = TxId(grpcTx.id.byteArray()), + chainId = ChainId(grpcTx.chainId.toByte()), + assetId = AssetId(grpcTx.assetId.byteArray()), + script = null, + senderPublicKey = PublicKey(grpcTx.senderPublicKey.byteArray()), + fee = Fee(grpcTx.fee), + timestamp = Timestamp(grpcTx.timestamp), + proofs = grpcTx.proofsList.map { Signature(it.byteArray()) }, + senderAddress = Address(grpcTx.senderAddress.byteArray()), + version = txVersion, + ) + ) + } +} diff --git a/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/SetScriptTxMapperTest.kt b/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/SetScriptTxMapperTest.kt new file mode 100644 index 00000000..8d274871 --- /dev/null +++ b/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/SetScriptTxMapperTest.kt @@ -0,0 +1,97 @@ +package com.wavesenterprise.sdk.node.client.grpc.mapper.tx + +import com.google.protobuf.bytesValue +import com.wavesenterprise.sdk.node.client.grpc.mapper.GrpcTypesMapper.byteArray +import com.wavesenterprise.sdk.node.client.grpc.mapper.tx.SetScriptTxMapper.domain +import com.wavesenterprise.sdk.node.domain.Address +import com.wavesenterprise.sdk.node.domain.ChainId +import com.wavesenterprise.sdk.node.domain.Fee +import com.wavesenterprise.sdk.node.domain.PublicKey +import com.wavesenterprise.sdk.node.domain.Script +import com.wavesenterprise.sdk.node.domain.ScriptDescription +import com.wavesenterprise.sdk.node.domain.ScriptName +import com.wavesenterprise.sdk.node.domain.Signature +import com.wavesenterprise.sdk.node.domain.Timestamp +import com.wavesenterprise.sdk.node.domain.TxId +import com.wavesenterprise.sdk.node.domain.TxVersion +import com.wavesenterprise.sdk.node.domain.tx.SetScriptTx +import com.wavesenterprise.transaction.protobuf.smart.setScriptTransaction +import io.kotest.matchers.shouldBe +import org.junit.jupiter.api.Test + +class SetScriptTxMapperTest { + + @Test + fun `should map to SetScriptTx (all fields)`() { + val txVersion = TxVersion.fromInt(1) + val grpcTx = setScriptTransaction { + id = byteString("DnK5Xfi2wXUJx9BjK9X6ZpFdTLdq2GtWH9pWrcxcmrhB") + chainId = 73 + script = bytesValue { + value = byteString("script") + } + name = byteString("name") + description = byteString("description") + senderPublicKey = byteString("C4eRfdUFaZMRkfUp91bYr7uMgdBRnUfAxuAjetxmK7KY") + fee = 10L + timestamp = 1716881331027L + proofs += byteString( + "2Gns72hraH5yay3eiWeyHQEA1wTqiiAztaLjHinEYX91FEv62HFW38Hq89GnsEJFHUvo9KHYtBBrb8hgTA9wN7DM" + ) + senderAddress = byteString("3N9vL3apA4j2L5PojHW8TYmfHx9Lo2ZaKPB") + } + grpcTx + .domain(txVersion) + .shouldBe( + SetScriptTx( + id = TxId(grpcTx.id.byteArray()), + chainId = ChainId(grpcTx.chainId.toByte()), + senderPublicKey = PublicKey(grpcTx.senderPublicKey.byteArray()), + script = Script(grpcTx.script.value.byteArray()), + name = ScriptName(grpcTx.name.byteArray()), + description = ScriptDescription(grpcTx.description.byteArray()), + fee = Fee(grpcTx.fee), + timestamp = Timestamp(grpcTx.timestamp), + proofs = grpcTx.proofsList?.map { Signature(it.byteArray()) }, + senderAddress = Address(grpcTx.senderAddress.byteArray()), + version = txVersion, + ) + ) + } + + @Test + fun `should map to SetScriptTx (with nulls)`() { + val txVersion = TxVersion.fromInt(1) + val grpcTx = setScriptTransaction { + id = byteString("DnK5Xfi2wXUJx9BjK9X6ZpFdTLdq2GtWH9pWrcxcmrhB") + chainId = 73 + clearScript() + name = byteString("name") + description = byteString("description") + senderPublicKey = byteString("C4eRfdUFaZMRkfUp91bYr7uMgdBRnUfAxuAjetxmK7KY") + fee = 10L + timestamp = 1716881331027L + proofs += byteString( + "2Gns72hraH5yay3eiWeyHQEA1wTqiiAztaLjHinEYX91FEv62HFW38Hq89GnsEJFHUvo9KHYtBBrb8hgTA9wN7DM" + ) + senderAddress = byteString("3N9vL3apA4j2L5PojHW8TYmfHx9Lo2ZaKPB") + } + grpcTx + .domain(txVersion) + .shouldBe( + SetScriptTx( + id = TxId(grpcTx.id.byteArray()), + chainId = ChainId(grpcTx.chainId.toByte()), + senderPublicKey = PublicKey(grpcTx.senderPublicKey.byteArray()), + script = null, + name = ScriptName(grpcTx.name.byteArray()), + description = ScriptDescription(grpcTx.description.byteArray()), + fee = Fee(grpcTx.fee), + timestamp = Timestamp(grpcTx.timestamp), + proofs = grpcTx.proofsList?.map { Signature(it.byteArray()) }, + senderAddress = Address(grpcTx.senderAddress.byteArray()), + version = txVersion, + ) + ) + } +} diff --git a/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/SponsorFeeTxMapperTest.kt b/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/SponsorFeeTxMapperTest.kt new file mode 100644 index 00000000..58c11e02 --- /dev/null +++ b/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/SponsorFeeTxMapperTest.kt @@ -0,0 +1,54 @@ +package com.wavesenterprise.sdk.node.client.grpc.mapper.tx + +import com.wavesenterprise.sdk.node.client.grpc.mapper.GrpcTypesMapper.byteArray +import com.wavesenterprise.sdk.node.client.grpc.mapper.tx.SponsorFeeTxMapper.domain +import com.wavesenterprise.sdk.node.domain.Address +import com.wavesenterprise.sdk.node.domain.AssetId +import com.wavesenterprise.sdk.node.domain.Enabled +import com.wavesenterprise.sdk.node.domain.Fee +import com.wavesenterprise.sdk.node.domain.PublicKey +import com.wavesenterprise.sdk.node.domain.Signature +import com.wavesenterprise.sdk.node.domain.Timestamp +import com.wavesenterprise.sdk.node.domain.TxId +import com.wavesenterprise.sdk.node.domain.TxVersion +import com.wavesenterprise.sdk.node.domain.tx.SponsorFeeTx +import com.wavesenterprise.transaction.protobuf.assets.sponsorFeeTransaction +import io.kotest.matchers.shouldBe +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.ValueSource + +class SponsorFeeTxMapperTest { + + @ParameterizedTest + @ValueSource(booleans = [true, false]) + fun `should map to SponsorFeeTx (all fields)`(sponsorshipIsEnabled: Boolean) { + val txVersion = TxVersion.fromInt(1) + val grpcTx = sponsorFeeTransaction { + id = byteString("DnK5Xfi2wXUJx9BjK9X6ZpFdTLdq2GtWH9pWrcxcmrhB") + assetId = byteString("assetId") + isEnabled = sponsorshipIsEnabled + senderPublicKey = byteString("C4eRfdUFaZMRkfUp91bYr7uMgdBRnUfAxuAjetxmK7KY") + fee = 10L + timestamp = 1716881331027L + proofs += byteString( + "2Gns72hraH5yay3eiWeyHQEA1wTqiiAztaLjHinEYX91FEv62HFW38Hq89GnsEJFHUvo9KHYtBBrb8hgTA9wN7DM" + ) + senderAddress = byteString("3N9vL3apA4j2L5PojHW8TYmfHx9Lo2ZaKPB") + } + grpcTx + .domain(txVersion) + .shouldBe( + SponsorFeeTx( + id = TxId(grpcTx.id.byteArray()), + assetId = AssetId(grpcTx.assetId.byteArray()), + enabled = Enabled(grpcTx.isEnabled), + senderPublicKey = PublicKey(grpcTx.senderPublicKey.byteArray()), + fee = Fee(grpcTx.fee), + timestamp = Timestamp(grpcTx.timestamp), + proofs = grpcTx.proofsList.map { Signature(it.byteArray()) }, + senderAddress = Address(grpcTx.senderAddress.byteArray()), + version = txVersion, + ) + ) + } +} diff --git a/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/TransferTxMapperTest.kt b/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/TransferTxMapperTest.kt new file mode 100644 index 00000000..d8c3211e --- /dev/null +++ b/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/TransferTxMapperTest.kt @@ -0,0 +1,117 @@ +package com.wavesenterprise.sdk.node.client.grpc.mapper.tx + +import com.google.protobuf.bytesValue +import com.wavesenterprise.sdk.node.client.grpc.mapper.GrpcTypesMapper.byteArray +import com.wavesenterprise.sdk.node.client.grpc.mapper.tx.TransferTxMapper.domain +import com.wavesenterprise.sdk.node.domain.Address +import com.wavesenterprise.sdk.node.domain.Amount +import com.wavesenterprise.sdk.node.domain.AssetId +import com.wavesenterprise.sdk.node.domain.Attachment +import com.wavesenterprise.sdk.node.domain.Fee +import com.wavesenterprise.sdk.node.domain.FeeAssetId +import com.wavesenterprise.sdk.node.domain.PublicKey +import com.wavesenterprise.sdk.node.domain.Signature +import com.wavesenterprise.sdk.node.domain.Timestamp +import com.wavesenterprise.sdk.node.domain.TxId +import com.wavesenterprise.sdk.node.domain.TxVersion +import com.wavesenterprise.sdk.node.domain.atomic.AtomicBadge +import com.wavesenterprise.sdk.node.domain.tx.TransferTx +import com.wavesenterprise.transaction.protobuf.atomicBadge +import com.wavesenterprise.transaction.protobuf.transfer.transferTransaction +import io.kotest.matchers.shouldBe +import org.junit.jupiter.api.Test + +class TransferTxMapperTest { + + @Test + fun `should map to TransferTx (all fields)`() { + val txVersion = TxVersion.fromInt(1) + val grpcTx = transferTransaction { + id = byteString("DnK5Xfi2wXUJx9BjK9X6ZpFdTLdq2GtWH9pWrcxcmrhB") + senderPublicKey = byteString("C4eRfdUFaZMRkfUp91bYr7uMgdBRnUfAxuAjetxmK7KY") + assetId = bytesValue { + byteString("assetId") + } + feeAssetId = bytesValue { + byteString("feeAssetId") + } + timestamp = 1716881331027L + amount = 1_000_000L + fee = 10L + recipient = byteString("DnK5Xfi2wXUJx9BjK9X6ZpFdTLdq2GtWH9pWrcxcmrhB") + attachment = byteString("attachment") + atomicBadge = atomicBadge { + trustedSender = bytesValue { + byteString("DnK5Xfi2wXUJx9BjK9X6ZpFdTLdq2GtWH9pWrcxcmrhB") + } + } + proofs += byteString( + "2Gns72hraH5yay3eiWeyHQEA1wTqiiAztaLjHinEYX91FEv62HFW38Hq89GnsEJFHUvo9KHYtBBrb8hgTA9wN7DM" + ) + senderAddress = byteString("3N9vL3apA4j2L5PojHW8TYmfHx9Lo2ZaKPB") + } + grpcTx + .domain(txVersion) + .shouldBe( + TransferTx( + id = TxId(grpcTx.id.byteArray()), + senderPublicKey = PublicKey(grpcTx.senderPublicKey.byteArray()), + assetId = AssetId(grpcTx.assetId.value.byteArray()), + feeAssetId = FeeAssetId( + txId = TxId(grpcTx.feeAssetId.value.byteArray()), + ), + timestamp = Timestamp(grpcTx.timestamp), + amount = Amount(grpcTx.amount), + fee = Fee(grpcTx.fee), + recipient = Address(grpcTx.recipient.byteArray()), + attachment = Attachment(grpcTx.attachment.byteArray()), + atomicBadge = AtomicBadge( + trustedSender = Address(grpcTx.atomicBadge.trustedSender.value.byteArray()), + ), + proofs = grpcTx.proofsList?.map { Signature(it.byteArray()) }, + senderAddress = Address(grpcTx.senderAddress.byteArray()), + version = txVersion, + ) + ) + } + + @Test + fun `should map to TransferTx (with nulls)`() { + val txVersion = TxVersion.fromInt(1) + val grpcTx = transferTransaction { + id = byteString("DnK5Xfi2wXUJx9BjK9X6ZpFdTLdq2GtWH9pWrcxcmrhB") + senderPublicKey = byteString("C4eRfdUFaZMRkfUp91bYr7uMgdBRnUfAxuAjetxmK7KY") + clearAssetId() + clearFeeAssetId() + timestamp = 1716881331027L + amount = 1_000_000L + fee = 10L + recipient = byteString("DnK5Xfi2wXUJx9BjK9X6ZpFdTLdq2GtWH9pWrcxcmrhB") + attachment = byteString("attachment") + clearAtomicBadge() + proofs += byteString( + "2Gns72hraH5yay3eiWeyHQEA1wTqiiAztaLjHinEYX91FEv62HFW38Hq89GnsEJFHUvo9KHYtBBrb8hgTA9wN7DM" + ) + senderAddress = byteString("3N9vL3apA4j2L5PojHW8TYmfHx9Lo2ZaKPB") + } + grpcTx + .domain(txVersion) + .shouldBe( + TransferTx( + id = TxId(grpcTx.id.byteArray()), + senderPublicKey = PublicKey(grpcTx.senderPublicKey.byteArray()), + assetId = null, + feeAssetId = null, + timestamp = Timestamp(grpcTx.timestamp), + amount = Amount(grpcTx.amount), + fee = Fee(grpcTx.fee), + recipient = Address(grpcTx.recipient.byteArray()), + attachment = Attachment(grpcTx.attachment.byteArray()), + atomicBadge = null, + proofs = grpcTx.proofsList?.map { Signature(it.byteArray()) }, + senderAddress = Address(grpcTx.senderAddress.byteArray()), + version = txVersion, + ) + ) + } +} diff --git a/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/TxMapperTestUtil.kt b/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/TxMapperTestUtil.kt new file mode 100644 index 00000000..8305279f --- /dev/null +++ b/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/TxMapperTestUtil.kt @@ -0,0 +1,13 @@ +package com.wavesenterprise.sdk.node.client.grpc.mapper.tx + +import com.google.protobuf.ByteString + +internal fun byteString(value: String): ByteString = + ByteString.copyFromUtf8(value) + +internal fun cartesianProduct(i1: Iterable, i2: Iterable): List> = + i1.flatMap { first -> + i2.map { second -> + first to second + } + } diff --git a/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/UpdateContractTxMapperTest.kt b/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/UpdateContractTxMapperTest.kt new file mode 100644 index 00000000..ae84e81c --- /dev/null +++ b/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/UpdateContractTxMapperTest.kt @@ -0,0 +1,195 @@ +package com.wavesenterprise.sdk.node.client.grpc.mapper.tx + +import com.google.protobuf.bytesValue +import com.wavesenterprise.sdk.node.client.grpc.mapper.tx.UpdateContractTxMapper.domain +import com.wavesenterprise.sdk.node.domain.Address +import com.wavesenterprise.sdk.node.domain.ContractApiVersion +import com.wavesenterprise.sdk.node.domain.Fee +import com.wavesenterprise.sdk.node.domain.FeeAssetId +import com.wavesenterprise.sdk.node.domain.MajorVersion +import com.wavesenterprise.sdk.node.domain.MinorVersion +import com.wavesenterprise.sdk.node.domain.PublicKey +import com.wavesenterprise.sdk.node.domain.Signature +import com.wavesenterprise.sdk.node.domain.Timestamp +import com.wavesenterprise.sdk.node.domain.TxId +import com.wavesenterprise.sdk.node.domain.TxVersion +import com.wavesenterprise.sdk.node.domain.ValidationPolicy +import com.wavesenterprise.sdk.node.domain.atomic.AtomicBadge +import com.wavesenterprise.sdk.node.domain.contract.ContractId +import com.wavesenterprise.sdk.node.domain.contract.ContractImage +import com.wavesenterprise.sdk.node.domain.contract.ContractImageHash +import com.wavesenterprise.sdk.node.domain.tx.UpdateContractTx +import com.wavesenterprise.transaction.protobuf.ValidationPolicyKt.any +import com.wavesenterprise.transaction.protobuf.ValidationPolicyKt.majority +import com.wavesenterprise.transaction.protobuf.ValidationPolicyKt.majorityWithOneOf +import com.wavesenterprise.transaction.protobuf.atomicBadge +import com.wavesenterprise.transaction.protobuf.contractApiVersion +import com.wavesenterprise.transaction.protobuf.docker.updateContractTransaction +import com.wavesenterprise.transaction.protobuf.validationPolicy +import io.kotest.matchers.shouldBe +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.TestInstance +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.Arguments +import org.junit.jupiter.params.provider.Arguments.arguments +import org.junit.jupiter.params.provider.MethodSource +import com.wavesenterprise.transaction.protobuf.ValidationPolicy as ProtoValidationPolicy + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +class UpdateContractTxMapperTest { + + @ParameterizedTest + @MethodSource("mappingArguments") + fun `should map to UpdateContractTx (all fields)`( + validationPolicyMapping: TestValidationPolicyMapping, + ) { + val grpcTx = updateContractTransaction { + id = byteString("DnK5Xfi2wXUJx9BjK9X6ZpFdTLdq2GtWH9pWrcxcmrhB") + senderPublicKey = byteString("3M1V41oGFr3hLmo3ecNQWPWVHPSfsguWepc") + contractId = byteString("CJrZPGYjjnZp1kLR3a7vCtEoM6Bx7Su2zJ8kU8Zxet4X") + image = "registry.test-domain.com/test-docker-repo/contract:1.0.1" + imageHash = "586d70cb288e82198a924871d75849c263c51b205764fa3e51755e54fcde18e8" + fee = 10L + timestamp = 1716881331027L + feeAssetId = bytesValue { + value = byteString("3Ge1AptYWH3Xw2jCNkCkYLPECr5q4aSJMXKMSUGL4eEs") + } + atomicBadge = atomicBadge { + trustedSender = bytesValue { + value = byteString("3M7EEnszPAT2yr72SgWVDLxfYCa4AYvVRwv") + } + } + validationPolicy = validationPolicyMapping.protoValidationPolicy + apiVersion = contractApiVersion { + majorVersion = 1 + minorVersion = 0 + } + proofs += listOf( + byteString("4NccZyPCgchDjeMdMmFKu7kxyU8AFF4e9cWaPFTQVQyYU1ZCCu3QmtmkfJkrDpDwGs4eJhYUVh5TnwYvjZYKPhLp"), + byteString("QMGoz6rycNsDLhN3mDce2mqGRQQ8r26vDDw551pnYcAecpFBDA8j38FVqDjLTGuFHs6ScX32fsGcaemmptpCFHk"), + ) + senderAddress = byteString("3MLti6qku2gD4rhnRcypvFxJE5UYV2P2myM") + } + val txVersion = TxVersion.fromInt(4) + + grpcTx + .domain(txVersion) + .shouldBe( + UpdateContractTx( + id = TxId(grpcTx.id.toByteArray()), + senderPublicKey = PublicKey(grpcTx.senderPublicKey.toByteArray()), + contractId = ContractId( + txId = TxId(grpcTx.contractId.toByteArray()) + ), + image = ContractImage(grpcTx.image), + imageHash = ContractImageHash(grpcTx.imageHash), + fee = Fee(grpcTx.fee), + timestamp = Timestamp(grpcTx.timestamp), + feeAssetId = FeeAssetId( + txId = TxId(grpcTx.feeAssetId.value.toByteArray()), + ), + atomicBadge = AtomicBadge( + trustedSender = Address(grpcTx.atomicBadge.trustedSender.value.toByteArray()), + ), + validationPolicy = validationPolicyMapping.domainValidationPolicy, + apiVersion = ContractApiVersion( + major = MajorVersion(grpcTx.apiVersion.majorVersion), + minor = MinorVersion(grpcTx.apiVersion.minorVersion), + ), + proofs = grpcTx.proofsList.map { Signature(it.toByteArray()) }.toList(), + senderAddress = Address(grpcTx.senderAddress.toByteArray()), + version = txVersion, + ) + ) + } + + @Test + fun `should map to UpdateContractTx (with nulls)`() { + val grpcTx = updateContractTransaction { + id = byteString("DnK5Xfi2wXUJx9BjK9X6ZpFdTLdq2GtWH9pWrcxcmrhB") + senderPublicKey = byteString("3M1V41oGFr3hLmo3ecNQWPWVHPSfsguWepc") + contractId = byteString("CJrZPGYjjnZp1kLR3a7vCtEoM6Bx7Su2zJ8kU8Zxet4X") + image = "registry.test-domain.com/test-docker-repo/contract:1.0.1" + imageHash = "586d70cb288e82198a924871d75849c263c51b205764fa3e51755e54fcde18e8" + fee = 10L + timestamp = 1716881331027L + clearFeeAssetId() + clearAtomicBadge() + clearValidationPolicy() + clearApiVersion() + proofs += listOf( + byteString("4NccZyPCgchDjeMdMmFKu7kxyU8AFF4e9cWaPFTQVQyYU1ZCCu3QmtmkfJkrDpDwGs4eJhYUVh5TnwYvjZYKPhLp"), + byteString("QMGoz6rycNsDLhN3mDce2mqGRQQ8r26vDDw551pnYcAecpFBDA8j38FVqDjLTGuFHs6ScX32fsGcaemmptpCFHk"), + ) + senderAddress = byteString("3MLti6qku2gD4rhnRcypvFxJE5UYV2P2myM") + } + val txVersion = TxVersion.fromInt(2) + + grpcTx + .domain(txVersion) + .shouldBe( + UpdateContractTx( + id = TxId(grpcTx.id.toByteArray()), + senderPublicKey = PublicKey(grpcTx.senderPublicKey.toByteArray()), + contractId = ContractId( + txId = TxId(grpcTx.contractId.toByteArray()) + ), + image = ContractImage(grpcTx.image), + imageHash = ContractImageHash(grpcTx.imageHash), + fee = Fee(grpcTx.fee), + timestamp = Timestamp(grpcTx.timestamp), + feeAssetId = null, + atomicBadge = null, + validationPolicy = null, + apiVersion = null, + proofs = grpcTx.proofsList.map { Signature(it.toByteArray()) }.toList(), + senderAddress = Address(grpcTx.senderAddress.toByteArray()), + version = txVersion, + ) + ) + } + + private fun mappingArguments(): List = + TestValidationPolicyMapping.cases().map { testValidationPolicyMapping -> + arguments(testValidationPolicyMapping) + } + + data class TestValidationPolicyMapping( + val protoValidationPolicy: ProtoValidationPolicy, + val domainValidationPolicy: ValidationPolicy, + ) { + companion object { + fun cases(): List = + listOf( + TestValidationPolicyMapping( + protoValidationPolicy = validationPolicy { + any = any {} + }, + domainValidationPolicy = ValidationPolicy.Any + ), + TestValidationPolicyMapping( + protoValidationPolicy = validationPolicy { + majority = majority {} + }, + domainValidationPolicy = ValidationPolicy.Majority + ), + TestValidationPolicyMapping( + protoValidationPolicy = validationPolicy { + majorityWithOneOf = majorityWithOneOf { + addresses += listOf( + byteString("3M7EEnszPAT2yr72SgWVDLxfYCa4AYvVRwv"), + byteString("3M3xGmJGmxBv2aZ4UFmn93rHxVXTJDKSAnh"), + ) + } + }, + domainValidationPolicy = ValidationPolicy.MajorityWithOneOf( + addresses = listOf( + Address("3M7EEnszPAT2yr72SgWVDLxfYCa4AYvVRwv".toByteArray()), + Address("3M3xGmJGmxBv2aZ4UFmn93rHxVXTJDKSAnh".toByteArray()), + ) + ) + ) + ) + } + } +} diff --git a/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/UpdatePolicyTxMapperTest.kt b/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/UpdatePolicyTxMapperTest.kt new file mode 100644 index 00000000..f3dcf42e --- /dev/null +++ b/we-node-client-grpc/we-node-client-grpc-mapper/src/test/kotlin/com/wavesenterprise/sdk/node/client/grpc/mapper/tx/UpdatePolicyTxMapperTest.kt @@ -0,0 +1,162 @@ +package com.wavesenterprise.sdk.node.client.grpc.mapper.tx + +import com.google.protobuf.bytesValue +import com.wavesenterprise.sdk.node.client.grpc.mapper.tx.UpdatePolicyTxMapper.domain +import com.wavesenterprise.sdk.node.domain.Address +import com.wavesenterprise.sdk.node.domain.Fee +import com.wavesenterprise.sdk.node.domain.FeeAssetId +import com.wavesenterprise.sdk.node.domain.OpType +import com.wavesenterprise.sdk.node.domain.PolicyId +import com.wavesenterprise.sdk.node.domain.PublicKey +import com.wavesenterprise.sdk.node.domain.Signature +import com.wavesenterprise.sdk.node.domain.Timestamp +import com.wavesenterprise.sdk.node.domain.TxId +import com.wavesenterprise.sdk.node.domain.TxVersion +import com.wavesenterprise.sdk.node.domain.atomic.AtomicBadge +import com.wavesenterprise.sdk.node.domain.tx.UpdatePolicyTx +import com.wavesenterprise.transaction.protobuf.atomicBadge +import com.wavesenterprise.transaction.protobuf.updatePolicyTransaction +import io.kotest.matchers.shouldBe +import org.junit.jupiter.api.TestInstance +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.MethodSource +import com.wavesenterprise.transaction.protobuf.OpType as ProtoOpType + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +class UpdatePolicyTxMapperTest { + + @ParameterizedTest + @MethodSource("opTypeMappingArguments") + fun `should map to UpdatePolicyTx (all fields)`(opTypeMapping: TestOpTypeMapping) { + val grpcTx = updatePolicyTransaction { + id = byteString("DnK5Xfi2wXUJx9BjK9X6ZpFdTLdq2GtWH9pWrcxcmrhB") + senderPublicKey = byteString("3M1V41oGFr3hLmo3ecNQWPWVHPSfsguWepc") + policyId = byteString("UkvoboGXiwWpASr1GLG9M1MUbhrEMo4NBS7kquxVMw5") + recipients += listOf( + byteString("3MLti6qku2gD4rhnRcypvFxJE5UYV2P2myM"), + byteString("3MNP3Cea3epMQsRNya66UEh5uCq9wiuw1fn"), + ) + owners += listOf( + byteString("3MLti6qku2gD4rhnRcypvFxJE5UYV2P2myM"), + byteString("3MNP3Cea3epMQsRNya66UEh5uCq9wiuw1fn"), + byteString("3M7EEnszPAT2yr72SgWVDLxfYCa4AYvVRwv"), + ) + opType = opTypeMapping.protoOpType + timestamp = 1716881331027L + fee = 10L + feeAssetId = bytesValue { + byteString("3Ge1AptYWH3Xw2jCNkCkYLPECr5q4aSJMXKMSUGL4eEs") + } + atomicBadge = atomicBadge { + trustedSender = bytesValue { + byteString("3M7EEnszPAT2yr72SgWVDLxfYCa4AYvVRwv") + } + } + proofs += listOf( + byteString("4NccZyPCgchDjeMdMmFKu7kxyU8AFF4e9cWaPFTQVQyYU1ZCCu3QmtmkfJkrDpDwGs4eJhYUVh5TnwYvjZYKPhLp"), + byteString("QMGoz6rycNsDLhN3mDce2mqGRQQ8r26vDDw551pnYcAecpFBDA8j38FVqDjLTGuFHs6ScX32fsGcaemmptpCFHk"), + ) + senderAddress = byteString("3MLti6qku2gD4rhnRcypvFxJE5UYV2P2myM") + } + val txVersion = TxVersion.fromInt(3) + + grpcTx + .domain(txVersion) + .shouldBe( + UpdatePolicyTx( + id = TxId(grpcTx.id.toByteArray()), + senderPublicKey = PublicKey(grpcTx.senderPublicKey.toByteArray()), + policyId = PolicyId( + txId = TxId(grpcTx.policyId.toByteArray()) + ), + recipients = grpcTx.recipientsList.map { Address(it.toByteArray()) }.toList(), + owners = grpcTx.ownersList.map { Address(it.toByteArray()) }.toList(), + opType = opTypeMapping.domainOpType, + timestamp = Timestamp(grpcTx.timestamp), + fee = Fee(grpcTx.fee), + feeAssetId = FeeAssetId( + txId = TxId(grpcTx.feeAssetId.value.toByteArray()), + ), + atomicBadge = AtomicBadge( + trustedSender = Address(grpcTx.atomicBadge.trustedSender.value.toByteArray()), + ), + proofs = grpcTx.proofsList.map { Signature(it.toByteArray()) }.toList(), + senderAddress = Address(grpcTx.senderAddress.toByteArray()), + version = txVersion, + ) + ) + } + + @ParameterizedTest + @MethodSource("opTypeMappingArguments") + fun `should map to UpdatePolicyTx (with nulls)`(opTypeMapping: TestOpTypeMapping) { + val grpcTx = updatePolicyTransaction { + id = byteString("DnK5Xfi2wXUJx9BjK9X6ZpFdTLdq2GtWH9pWrcxcmrhB") + senderPublicKey = byteString("3M1V41oGFr3hLmo3ecNQWPWVHPSfsguWepc") + policyId = byteString("UkvoboGXiwWpASr1GLG9M1MUbhrEMo4NBS7kquxVMw5") + recipients += listOf( + byteString("3MLti6qku2gD4rhnRcypvFxJE5UYV2P2myM"), + byteString("3MNP3Cea3epMQsRNya66UEh5uCq9wiuw1fn"), + ) + owners += listOf( + byteString("3MLti6qku2gD4rhnRcypvFxJE5UYV2P2myM"), + byteString("3MNP3Cea3epMQsRNya66UEh5uCq9wiuw1fn"), + byteString("3M7EEnszPAT2yr72SgWVDLxfYCa4AYvVRwv"), + ) + opType = opTypeMapping.protoOpType + timestamp = 1716881331027L + fee = 10L + clearFeeAssetId() + clearAtomicBadge() + proofs += listOf( + byteString("4NccZyPCgchDjeMdMmFKu7kxyU8AFF4e9cWaPFTQVQyYU1ZCCu3QmtmkfJkrDpDwGs4eJhYUVh5TnwYvjZYKPhLp"), + byteString("QMGoz6rycNsDLhN3mDce2mqGRQQ8r26vDDw551pnYcAecpFBDA8j38FVqDjLTGuFHs6ScX32fsGcaemmptpCFHk"), + ) + senderAddress = byteString("3MLti6qku2gD4rhnRcypvFxJE5UYV2P2myM") + } + val txVersion = TxVersion.fromInt(1) + + grpcTx + .domain(txVersion) + .shouldBe( + UpdatePolicyTx( + id = TxId(grpcTx.id.toByteArray()), + senderPublicKey = PublicKey(grpcTx.senderPublicKey.toByteArray()), + policyId = PolicyId( + txId = TxId(grpcTx.policyId.toByteArray()) + ), + recipients = grpcTx.recipientsList.map { Address(it.toByteArray()) }.toList(), + owners = grpcTx.ownersList.map { Address(it.toByteArray()) }.toList(), + opType = opTypeMapping.domainOpType, + timestamp = Timestamp(grpcTx.timestamp), + fee = Fee(grpcTx.fee), + feeAssetId = null, + atomicBadge = null, + proofs = grpcTx.proofsList.map { Signature(it.toByteArray()) }.toList(), + senderAddress = Address(grpcTx.senderAddress.toByteArray()), + version = txVersion, + ) + ) + } + + data class TestOpTypeMapping( + val protoOpType: ProtoOpType, + val domainOpType: OpType, + ) + + private fun opTypeMappingArguments(): List = + listOf( + TestOpTypeMapping( + protoOpType = ProtoOpType.UNKNOWN_OP_TYPE, + domainOpType = OpType.UNKNOWN, + ), + TestOpTypeMapping( + protoOpType = ProtoOpType.ADD, + domainOpType = OpType.ADD, + ), + TestOpTypeMapping( + protoOpType = ProtoOpType.REMOVE, + domainOpType = OpType.REMOVE, + ) + ) +} diff --git a/we-node-client-json/src/main/kotlin/com/wavesenterprise/sdk/node/client/http/PermitDataEntryDto.kt b/we-node-client-json/src/main/kotlin/com/wavesenterprise/sdk/node/client/http/PermitDataEntryDto.kt deleted file mode 100644 index 846f3bfa..00000000 --- a/we-node-client-json/src/main/kotlin/com/wavesenterprise/sdk/node/client/http/PermitDataEntryDto.kt +++ /dev/null @@ -1,58 +0,0 @@ -package com.wavesenterprise.sdk.node.client.http - -import com.wavesenterprise.sdk.node.domain.DataKey -import com.wavesenterprise.sdk.node.domain.DataValue -import com.wavesenterprise.sdk.node.domain.PermitDataAction -import com.wavesenterprise.sdk.node.domain.PermitDataEntry -import java.util.Base64 - -data class PermitDataEntryDto( - val key: String, - val type: String?, - val value: Any?, -) { - companion object { - private val BASE_64_ENCODER = Base64.getEncoder() - private val BASE_64_DECODER = Base64.getDecoder() - - @JvmStatic - fun PermitDataEntry.toDto(): PermitDataEntryDto { - val (type: String?, value: Any?) = when (val action = action) { - PermitDataAction.DeleteDataAction -> Pair(null, null) - is PermitDataAction.SetDataAction -> when (val value = action.value) { - is DataValue.BinaryDataValue -> { - Pair(DataEntryDto.BINARY_TYPE, BASE_64_ENCODER.encodeToString(value.value)) - } - is DataValue.BooleanDataValue -> Pair(DataEntryDto.BOOLEAN_TYPE, value.value) - is DataValue.IntegerDataValue -> Pair(DataEntryDto.INTEGER_TYPE, value.value) - is DataValue.StringDataValue -> Pair(DataEntryDto.STRING_TYPE, value.value) - } - } - return PermitDataEntryDto( - key = key.value, - type = type, - value = value, - ) - } - - @JvmStatic - fun PermitDataEntryDto.toDomain(): PermitDataEntry { - val action = when (type) { - null -> PermitDataAction.DeleteDataAction - else -> PermitDataAction.SetDataAction( - when (type) { - DataEntryDto.BINARY_TYPE -> DataValue.BinaryDataValue(BASE_64_DECODER.decode(value as String)) - DataEntryDto.BOOLEAN_TYPE -> DataValue.BooleanDataValue(value as Boolean) - DataEntryDto.INTEGER_TYPE -> DataValue.IntegerDataValue((value as Number).toLong()) - DataEntryDto.STRING_TYPE -> DataValue.StringDataValue(value as String) - else -> error("Unknown data type $type for key $key") - } - ) - } - return PermitDataEntry( - key = DataKey(key), - action = action - ) - } - } -} diff --git a/we-node-client-json/src/main/kotlin/com/wavesenterprise/sdk/node/client/http/sign/DataSignRequestDto.kt b/we-node-client-json/src/main/kotlin/com/wavesenterprise/sdk/node/client/http/sign/DataSignRequestDto.kt index 431bb76b..0157a0f7 100644 --- a/we-node-client-json/src/main/kotlin/com/wavesenterprise/sdk/node/client/http/sign/DataSignRequestDto.kt +++ b/we-node-client-json/src/main/kotlin/com/wavesenterprise/sdk/node/client/http/sign/DataSignRequestDto.kt @@ -1,7 +1,7 @@ package com.wavesenterprise.sdk.node.client.http.sign -import com.wavesenterprise.sdk.node.client.http.PermitDataEntryDto -import com.wavesenterprise.sdk.node.client.http.PermitDataEntryDto.Companion.toDto +import com.wavesenterprise.sdk.node.client.http.DataEntryDto +import com.wavesenterprise.sdk.node.client.http.DataEntryDto.Companion.toDto import com.wavesenterprise.sdk.node.client.http.tx.DataTxDto import com.wavesenterprise.sdk.node.domain.TxType import com.wavesenterprise.sdk.node.domain.sign.DataSignRequest @@ -14,7 +14,7 @@ data class DataSignRequestDto( val fee: Long, val feeAssetId: String?, val author: String, - val data: List, + val data: List, ) : SignRequestDto { companion object { @JvmStatic diff --git a/we-node-client-json/src/main/kotlin/com/wavesenterprise/sdk/node/client/http/sign/RegisterNodeSignRequestDto.kt b/we-node-client-json/src/main/kotlin/com/wavesenterprise/sdk/node/client/http/sign/RegisterNodeSignRequestDto.kt index 30af56bd..21716fa3 100644 --- a/we-node-client-json/src/main/kotlin/com/wavesenterprise/sdk/node/client/http/sign/RegisterNodeSignRequestDto.kt +++ b/we-node-client-json/src/main/kotlin/com/wavesenterprise/sdk/node/client/http/sign/RegisterNodeSignRequestDto.kt @@ -12,7 +12,6 @@ data class RegisterNodeSignRequestDto( val password: String?, val fee: Long, val opType: String, - val target: String, val targetPublicKey: String, val nodeName: String, ) : SignRequestDto { @@ -25,7 +24,6 @@ data class RegisterNodeSignRequestDto( password = password?.value, fee = fee.value, opType = opType.toDto(), - target = target.asBase58String(), targetPublicKey = targetPublicKey.asBase58String(), nodeName = nodeName.value, ) diff --git a/we-node-client-json/src/main/kotlin/com/wavesenterprise/sdk/node/client/http/tx/DataTxDto.kt b/we-node-client-json/src/main/kotlin/com/wavesenterprise/sdk/node/client/http/tx/DataTxDto.kt index c3a90276..7f80d161 100644 --- a/we-node-client-json/src/main/kotlin/com/wavesenterprise/sdk/node/client/http/tx/DataTxDto.kt +++ b/we-node-client-json/src/main/kotlin/com/wavesenterprise/sdk/node/client/http/tx/DataTxDto.kt @@ -1,8 +1,8 @@ package com.wavesenterprise.sdk.node.client.http.tx -import com.wavesenterprise.sdk.node.client.http.PermitDataEntryDto -import com.wavesenterprise.sdk.node.client.http.PermitDataEntryDto.Companion.toDomain -import com.wavesenterprise.sdk.node.client.http.PermitDataEntryDto.Companion.toDto +import com.wavesenterprise.sdk.node.client.http.DataEntryDto +import com.wavesenterprise.sdk.node.client.http.DataEntryDto.Companion.toDomain +import com.wavesenterprise.sdk.node.client.http.DataEntryDto.Companion.toDto import com.wavesenterprise.sdk.node.domain.Address import com.wavesenterprise.sdk.node.domain.Fee import com.wavesenterprise.sdk.node.domain.FeeAssetId @@ -20,7 +20,7 @@ data class DataTxDto( val senderPublicKey: String, val author: String, val authorPublicKey: String, - val data: List, + val data: List, override val timestamp: Long, val fee: Long, val feeAssetId: String?, diff --git a/we-node-client-json/src/main/kotlin/com/wavesenterprise/sdk/node/client/http/tx/RegisterNodeTxDto.kt b/we-node-client-json/src/main/kotlin/com/wavesenterprise/sdk/node/client/http/tx/RegisterNodeTxDto.kt index aa3998ea..60111287 100644 --- a/we-node-client-json/src/main/kotlin/com/wavesenterprise/sdk/node/client/http/tx/RegisterNodeTxDto.kt +++ b/we-node-client-json/src/main/kotlin/com/wavesenterprise/sdk/node/client/http/tx/RegisterNodeTxDto.kt @@ -17,7 +17,6 @@ data class RegisterNodeTxDto( override val id: String, override val type: Int = TxType.REGISTER_NODE.code, val senderPublicKey: String, - val target: String, val targetPubKey: String, val nodeName: String?, val opType: String, @@ -34,7 +33,6 @@ data class RegisterNodeTxDto( RegisterNodeTxDto( id = id.asBase58String(), senderPublicKey = senderPublicKey.asBase58String(), - target = target.asBase58String(), targetPubKey = targetPublicKey.asBase58String(), nodeName = nodeName?.value, opType = opType.toDto(), @@ -50,7 +48,6 @@ data class RegisterNodeTxDto( RegisterNodeTx( id = TxId.fromBase58(id), senderPublicKey = PublicKey.fromBase58(senderPublicKey), - target = Address.fromBase58(target), targetPublicKey = PublicKey.fromBase58(targetPubKey), nodeName = nodeName?.let { NodeName(it) }, opType = opType.fromOpTypeDtoToDomain(), diff --git a/we-tx-signer/we-tx-signer-bouncy-castle/src/test/kotlin/com/wavesenterprise/tx/signer/bouncycastle/BouncyCastleSelfTxSignerTest.kt b/we-tx-signer/we-tx-signer-bouncy-castle/src/test/kotlin/com/wavesenterprise/tx/signer/bouncycastle/BouncyCastleSelfTxSignerTest.kt index 3a675d7e..d770fada 100644 --- a/we-tx-signer/we-tx-signer-bouncy-castle/src/test/kotlin/com/wavesenterprise/tx/signer/bouncycastle/BouncyCastleSelfTxSignerTest.kt +++ b/we-tx-signer/we-tx-signer-bouncy-castle/src/test/kotlin/com/wavesenterprise/tx/signer/bouncycastle/BouncyCastleSelfTxSignerTest.kt @@ -347,11 +347,10 @@ class BouncyCastleSelfTxSignerTest { @Test fun `should sign RegisterNodeTx`() { val signRequest = RegisterNodeSignRequest( - senderAddress = Address.EMPTY, version = TxVersion(2), + senderAddress = Address.EMPTY, fee = Fee(0), opType = OpType.ADD, - target = Address.fromBase58("3HgjVZvBHNaVfU7fHx9mqDXeJy4J8khadRC"), targetPublicKey = bouncyCastleSigner.getPublicKey(), nodeName = NodeName("test"), )