From 8fa030087c14d218c6596cff117c3571c830eff9 Mon Sep 17 00:00:00 2001 From: Thomas Kammerlocher Date: Tue, 9 Apr 2024 14:35:14 +0200 Subject: [PATCH] Updated Yaci-cli and cardano-client-lib (#4) * updated cardano-cli version * adjusted test to use the scriptHash. Since the ToDo was fixed in a later cardano-client-lib release * changed test case to referenceHash from body --- build.gradle | 4 +- .../yaci/test/YaciCardanoContainer.java | 4 +- .../yaci/test/api/CardanoContainerAssert.java | 2 +- .../cardano/yaci/test/api/UtxoListAssert.java | 7 ++- .../test/api/helper/TransactionHelper.java | 46 ++++++++----------- .../yaci/test/api/helper/YaciTestHelper.java | 2 +- .../yaci/test/backend/TransactionService.java | 17 +++++-- .../yaci/test/backend/UtxoService.java | 15 ++++++ .../yaci/test/api/UtxoListAssertTest.java | 4 +- .../api/helper/TransactionHelperTest.java | 11 ++++- 10 files changed, 67 insertions(+), 45 deletions(-) diff --git a/build.gradle b/build.gradle index ed80257..82e26bf 100644 --- a/build.gradle +++ b/build.gradle @@ -32,8 +32,8 @@ dependencies { exclude group: 'com.fasterxml.jackson.core', module: 'jackson-annotations' } - compileOnly 'com.bloxbean.cardano:cardano-client-lib:0.4.3' - compileOnly 'com.bloxbean.cardano:cardano-client-backend:0.4.3' + implementation 'com.bloxbean.cardano:cardano-client-lib:0.5.1' + implementation 'com.bloxbean.cardano:cardano-client-backend:0.5.1' api 'org.assertj:assertj-core:3.24.2' diff --git a/src/main/java/com/bloxbean/cardano/yaci/test/YaciCardanoContainer.java b/src/main/java/com/bloxbean/cardano/yaci/test/YaciCardanoContainer.java index 02e3139..e0d2198 100644 --- a/src/main/java/com/bloxbean/cardano/yaci/test/YaciCardanoContainer.java +++ b/src/main/java/com/bloxbean/cardano/yaci/test/YaciCardanoContainer.java @@ -29,7 +29,7 @@ @Slf4j public class YaciCardanoContainer extends GenericContainer { private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse("bloxbean/yaci-cli"); - private static final String DEFAULT_TAG = "0.0.12"; + private static final String DEFAULT_TAG = "0.0.19"; public static final int STORE_PORT = 8080; public static final int CLUSTER_HTTP_PORT = 10000; public static final int SUBMIT_API_PORT = 8090; @@ -61,7 +61,7 @@ public YaciCardanoContainer(final DockerImageName dockerImageName, float blockTi if (blockTime >= 1 && blockTime <= 20) { dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME); withExposedPorts(STORE_PORT, CLUSTER_HTTP_PORT, SUBMIT_API_PORT, NODE_PORT); - withCommand("create-cluster", "-o", "--slotLength", String.valueOf(DEFAULT_SLOT_LENGTH), "--blockTime", String.valueOf(blockTime), "--start"); + withCommand("create-cluster", "-o", "--slot-length", String.valueOf(DEFAULT_SLOT_LENGTH), "--block-time", String.valueOf(blockTime), "--start"); addEnv("yaci_store_enabled", "true"); waitingFor(Wait.forHttp("/api/v1/epochs/parameters") diff --git a/src/main/java/com/bloxbean/cardano/yaci/test/api/CardanoContainerAssert.java b/src/main/java/com/bloxbean/cardano/yaci/test/api/CardanoContainerAssert.java index ca09098..3cd153f 100644 --- a/src/main/java/com/bloxbean/cardano/yaci/test/api/CardanoContainerAssert.java +++ b/src/main/java/com/bloxbean/cardano/yaci/test/api/CardanoContainerAssert.java @@ -1,8 +1,8 @@ package com.bloxbean.cardano.yaci.test.api; import com.bloxbean.cardano.client.api.model.Utxo; +import com.bloxbean.cardano.client.api.util.AssetUtil; import com.bloxbean.cardano.client.transaction.spec.Asset; -import com.bloxbean.cardano.client.util.AssetUtil; import com.bloxbean.cardano.yaci.test.YaciCardanoContainer; import com.bloxbean.cardano.yaci.test.api.helper.YaciTestHelper; import lombok.NonNull; diff --git a/src/main/java/com/bloxbean/cardano/yaci/test/api/UtxoListAssert.java b/src/main/java/com/bloxbean/cardano/yaci/test/api/UtxoListAssert.java index d0c053e..2a9df5e 100644 --- a/src/main/java/com/bloxbean/cardano/yaci/test/api/UtxoListAssert.java +++ b/src/main/java/com/bloxbean/cardano/yaci/test/api/UtxoListAssert.java @@ -2,11 +2,11 @@ import com.bloxbean.cardano.client.api.model.Amount; import com.bloxbean.cardano.client.api.model.Utxo; +import com.bloxbean.cardano.client.api.util.AssetUtil; import com.bloxbean.cardano.client.exception.CborSerializationException; import com.bloxbean.cardano.client.plutus.impl.DefaultPlutusObjectConverter; +import com.bloxbean.cardano.client.plutus.spec.PlutusScript; import com.bloxbean.cardano.client.transaction.spec.Asset; -import com.bloxbean.cardano.client.transaction.spec.PlutusScript; -import com.bloxbean.cardano.client.util.AssetUtil; import com.bloxbean.cardano.client.util.HexUtil; import lombok.NonNull; import org.assertj.core.api.ListAssert; @@ -203,11 +203,10 @@ public UtxoListAssert containsReferenceScript(@NonNull PlutusScript plutusScript isNotNull(); try { - String scriptRefHex = HexUtil.encodeHexString(plutusScript.scriptRefBytes()); + String scriptRefHex = HexUtil.encodeHexString(plutusScript.getScriptHash()); boolean found = actual.stream() .anyMatch(utxo -> scriptRefHex.equals(utxo.getReferenceScriptHash())); - //TODO -- The reference script hash in utxo object is actually reference script body. Need to fix this if (!found) failWithMessage("Expected but not found.\n ReferenceScript : <%s>", scriptRefHex); diff --git a/src/main/java/com/bloxbean/cardano/yaci/test/api/helper/TransactionHelper.java b/src/main/java/com/bloxbean/cardano/yaci/test/api/helper/TransactionHelper.java index febd47c..21f3295 100644 --- a/src/main/java/com/bloxbean/cardano/yaci/test/api/helper/TransactionHelper.java +++ b/src/main/java/com/bloxbean/cardano/yaci/test/api/helper/TransactionHelper.java @@ -6,22 +6,28 @@ import com.bloxbean.cardano.client.api.model.Amount; import com.bloxbean.cardano.client.api.model.Result; import com.bloxbean.cardano.client.api.model.Utxo; +import com.bloxbean.cardano.client.api.util.AssetUtil; +import com.bloxbean.cardano.client.api.util.PolicyUtil; import com.bloxbean.cardano.client.backend.model.TransactionContent; import com.bloxbean.cardano.client.common.model.Networks; import com.bloxbean.cardano.client.crypto.KeyGenUtil; import com.bloxbean.cardano.client.crypto.SecretKey; import com.bloxbean.cardano.client.crypto.VerificationKey; import com.bloxbean.cardano.client.crypto.bip32.key.HdPublicKey; -import com.bloxbean.cardano.client.exception.CborSerializationException; import com.bloxbean.cardano.client.function.Output; import com.bloxbean.cardano.client.function.TxBuilder; import com.bloxbean.cardano.client.function.TxBuilderContext; import com.bloxbean.cardano.client.function.helper.MintCreators; import com.bloxbean.cardano.client.function.helper.OutputBuilders; -import com.bloxbean.cardano.client.transaction.spec.*; -import com.bloxbean.cardano.client.util.AssetUtil; +import com.bloxbean.cardano.client.plutus.spec.PlutusData; +import com.bloxbean.cardano.client.plutus.spec.PlutusScript; +import com.bloxbean.cardano.client.transaction.spec.Asset; +import com.bloxbean.cardano.client.transaction.spec.MultiAsset; +import com.bloxbean.cardano.client.transaction.spec.Policy; +import com.bloxbean.cardano.client.transaction.spec.Transaction; +import com.bloxbean.cardano.client.transaction.spec.TransactionOutput; +import com.bloxbean.cardano.client.transaction.spec.Value; import com.bloxbean.cardano.client.util.JsonUtil; -import com.bloxbean.cardano.client.util.PolicyUtil; import com.bloxbean.cardano.yaci.test.YaciCardanoContainer; import lombok.NonNull; import lombok.extern.slf4j.Slf4j; @@ -165,12 +171,8 @@ public Optional mintToken(String receiver, String tokenName, BigInteger */ public Optional lockFund(@NonNull Account senderAccount, @NonNull PlutusScript receiverScript, @NonNull Value value, PlutusData inlineDatum) { - try { - String scriptAddress = AddressProvider.getEntAddress(receiverScript, Networks.testnet()).toBech32(); - return lockFund(senderAccount, scriptAddress, value, inlineDatum); - } catch (CborSerializationException e) { - throw new RuntimeException(e); - } + String scriptAddress = AddressProvider.getEntAddress(receiverScript, Networks.testnet()).toBech32(); + return lockFund(senderAccount, scriptAddress, value, inlineDatum); } /** @@ -183,12 +185,8 @@ public Optional lockFund(@NonNull Account senderAccount, @NonNull Plutus */ public Optional lockFund(@NonNull Account senderAccount, @NonNull PlutusScript receiverScript, @NonNull List amounts, PlutusData inlineDatum) { - try { - String scriptAddress = AddressProvider.getEntAddress(receiverScript, Networks.testnet()).toBech32(); - return lockFund(senderAccount, scriptAddress, amounts, inlineDatum); - } catch (CborSerializationException e) { - throw new RuntimeException(e); - } + String scriptAddress = AddressProvider.getEntAddress(receiverScript, Networks.testnet()).toBech32(); + return lockFund(senderAccount, scriptAddress, amounts, inlineDatum); } /** @@ -242,12 +240,8 @@ public Optional lockFund(@NonNull Account senderAccount, @NonNull String */ public Optional lockFund(@NonNull PlutusScript receiverScript, @NonNull Value value, PlutusData inlineDatum) { - try { - String scriptAddress = AddressProvider.getEntAddress(receiverScript, Networks.testnet()).toBech32(); - return lockFund(scriptAddress, value, inlineDatum); - } catch (CborSerializationException e) { - throw new RuntimeException(e); - } + String scriptAddress = AddressProvider.getEntAddress(receiverScript, Networks.testnet()).toBech32(); + return lockFund(scriptAddress, value, inlineDatum); } /** @@ -259,12 +253,8 @@ public Optional lockFund(@NonNull PlutusScript receiverScript, */ public Optional lockFund(@NonNull PlutusScript receiverScript, @NonNull List amounts, PlutusData inlineDatum) { - try { - String scriptAddress = AddressProvider.getEntAddress(receiverScript, Networks.testnet()).toBech32(); - return lockFund(scriptAddress, amounts, inlineDatum); - } catch (CborSerializationException e) { - throw new RuntimeException(e); - } + String scriptAddress = AddressProvider.getEntAddress(receiverScript, Networks.testnet()).toBech32(); + return lockFund(scriptAddress, amounts, inlineDatum); } diff --git a/src/main/java/com/bloxbean/cardano/yaci/test/api/helper/YaciTestHelper.java b/src/main/java/com/bloxbean/cardano/yaci/test/api/helper/YaciTestHelper.java index d09f3fd..992077f 100644 --- a/src/main/java/com/bloxbean/cardano/yaci/test/api/helper/YaciTestHelper.java +++ b/src/main/java/com/bloxbean/cardano/yaci/test/api/helper/YaciTestHelper.java @@ -4,7 +4,7 @@ import com.bloxbean.cardano.client.api.model.Amount; import com.bloxbean.cardano.client.api.model.Utxo; import com.bloxbean.cardano.client.exception.CborDeserializationException; -import com.bloxbean.cardano.client.transaction.spec.PlutusData; +import com.bloxbean.cardano.client.plutus.spec.PlutusData; import com.bloxbean.cardano.client.util.HexUtil; import com.bloxbean.cardano.yaci.test.YaciCardanoContainer; import lombok.NonNull; diff --git a/src/main/java/com/bloxbean/cardano/yaci/test/backend/TransactionService.java b/src/main/java/com/bloxbean/cardano/yaci/test/backend/TransactionService.java index 3fd066f..c6cb016 100644 --- a/src/main/java/com/bloxbean/cardano/yaci/test/backend/TransactionService.java +++ b/src/main/java/com/bloxbean/cardano/yaci/test/backend/TransactionService.java @@ -2,8 +2,9 @@ import com.bloxbean.cardano.client.api.exception.ApiException; import com.bloxbean.cardano.client.api.model.Result; -import com.bloxbean.cardano.client.backend.model.EvaluationResult; +import com.bloxbean.cardano.client.api.model.Utxo; import com.bloxbean.cardano.client.backend.model.TransactionContent; +import com.bloxbean.cardano.client.backend.model.TxContentRedeemers; import com.bloxbean.cardano.client.backend.model.TxContentUtxo; import com.bloxbean.cardano.yaci.test.backend.http.TransactionApi; import feign.FeignException; @@ -46,14 +47,24 @@ public Result getTransaction(String txnHash) throws ApiExcep } } + @Override + public Result> getTransactions(List list) throws ApiException { + return null; + } + @Override public Result getTransactionUtxos(String txnHash) { throw new UnsupportedOperationException("Not supported"); } @Override - public Result> evaluateTx(byte[] cborData) { - throw new UnsupportedOperationException("Not supported"); + public Result> getTransactionRedeemers(String s) throws ApiException { + return null; + } + + @Override + public Result getTransactionOutput(String txnHash, int outputIndex) throws ApiException { + return com.bloxbean.cardano.client.backend.api.TransactionService.super.getTransactionOutput(txnHash, outputIndex); } } diff --git a/src/main/java/com/bloxbean/cardano/yaci/test/backend/UtxoService.java b/src/main/java/com/bloxbean/cardano/yaci/test/backend/UtxoService.java index 45d2fde..e849676 100644 --- a/src/main/java/com/bloxbean/cardano/yaci/test/backend/UtxoService.java +++ b/src/main/java/com/bloxbean/cardano/yaci/test/backend/UtxoService.java @@ -36,4 +36,19 @@ public Result> getUtxos(String address, int count, int page, OrderEnu throw new ApiException("Error getting utxos", e); } } + + @Override + public Result> getUtxos(String s, String s1, int i, int i1) throws ApiException { + return null; + } + + @Override + public Result> getUtxos(String s, String s1, int i, int i1, OrderEnum orderEnum) throws ApiException { + return null; + } + + @Override + public Result getTxOutput(String s, int i) throws ApiException { + return null; + } } diff --git a/src/test/java/com/bloxbean/cardano/yaci/test/api/UtxoListAssertTest.java b/src/test/java/com/bloxbean/cardano/yaci/test/api/UtxoListAssertTest.java index d13fa51..2401792 100644 --- a/src/test/java/com/bloxbean/cardano/yaci/test/api/UtxoListAssertTest.java +++ b/src/test/java/com/bloxbean/cardano/yaci/test/api/UtxoListAssertTest.java @@ -5,7 +5,7 @@ import com.bloxbean.cardano.client.config.Configuration; import com.bloxbean.cardano.client.plutus.annotation.Constr; import com.bloxbean.cardano.client.plutus.annotation.PlutusField; -import com.bloxbean.cardano.client.transaction.spec.PlutusV2Script; +import com.bloxbean.cardano.client.plutus.spec.PlutusV2Script; import lombok.AllArgsConstructor; import lombok.Data; import org.jetbrains.annotations.NotNull; @@ -182,7 +182,7 @@ private static List testUtxosWithDatumsAndRefScriptHash() throws Exception new Amount("96662071b76a743e44c2267e85f5fa86f9a01a1bea53be5dd812378f57455448", BigInteger.valueOf(100)) )) .dataHash(Configuration.INSTANCE.getPlutusObjectConverter().toPlutusData(new Datum1(5, 10)).getDatumHash()) - .referenceScriptHash("820249480100002221200101") //TODO -- this is actually scriptRefBody as current impl. Change it after fix in yaci-store + .referenceScriptHash("3a888d65f16790950a72daee1f63aa05add6d268434107cfa5b67712") .build(); Utxo utxo3 = Utxo.builder() diff --git a/src/test/java/com/bloxbean/cardano/yaci/test/api/helper/TransactionHelperTest.java b/src/test/java/com/bloxbean/cardano/yaci/test/api/helper/TransactionHelperTest.java index 458ef83..d1894e2 100644 --- a/src/test/java/com/bloxbean/cardano/yaci/test/api/helper/TransactionHelperTest.java +++ b/src/test/java/com/bloxbean/cardano/yaci/test/api/helper/TransactionHelperTest.java @@ -4,9 +4,16 @@ import com.bloxbean.cardano.client.address.AddressProvider; import com.bloxbean.cardano.client.api.model.Amount; import com.bloxbean.cardano.client.api.model.Utxo; +import com.bloxbean.cardano.client.api.util.AssetUtil; import com.bloxbean.cardano.client.common.model.Networks; -import com.bloxbean.cardano.client.transaction.spec.*; -import com.bloxbean.cardano.client.util.AssetUtil; +import com.bloxbean.cardano.client.plutus.spec.BigIntPlutusData; +import com.bloxbean.cardano.client.plutus.spec.PlutusData; +import com.bloxbean.cardano.client.plutus.spec.PlutusV1Script; +import com.bloxbean.cardano.client.plutus.spec.PlutusV2Script; +import com.bloxbean.cardano.client.transaction.spec.Asset; +import com.bloxbean.cardano.client.transaction.spec.MultiAsset; +import com.bloxbean.cardano.client.transaction.spec.Policy; +import com.bloxbean.cardano.client.transaction.spec.Value; import com.bloxbean.cardano.yaci.test.Funding; import com.bloxbean.cardano.yaci.test.YaciCardanoContainer; import lombok.extern.slf4j.Slf4j;