Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task/psgs 55 cardano api units #17

Merged
merged 16 commits into from
Oct 7, 2020
14 changes: 7 additions & 7 deletions src/it/resources/application.conf
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
cardano.wallet.baseUrl=${BASE_URL}
cardano.wallet.baseUrl=${?BASE_URL}

cardano.wallet1.passphrase=${CARDANO_API_WALLET_1_PASSPHRASE}
cardano.wallet1.passphrase=${?CARDANO_API_WALLET_1_PASSPHRASE}
cardano.wallet1.name="cardano_api_wallet_1"
cardano.wallet1.amount=2000000
cardano.wallet1.mnemonic=${CARDANO_API_WALLET_1_MNEMONIC}
cardano.wallet1.mnemonic=${?CARDANO_API_WALLET_1_MNEMONIC}
cardano.wallet1.id="6cd6d11a489b7ea82a4624d18b93bdf9b77f0620"
cardano.wallet1.metadata="0:0123456789012345678901234567890123456789012345678901234567890123:2:TESTINGCARDANOAPI"

cardano.wallet2.mnemonic=${CARDANO_API_WALLET_2_MNEMONIC}
cardano.wallet2.mnemonic=${?CARDANO_API_WALLET_2_MNEMONIC}
cardano.wallet2.id="bfa9530c4ecfee6e5561e950bd7a7a332e4e7497"
cardano.wallet2.name="somethrowawayname"
cardano.wallet2.passphrase="somethrowawayname"

cardano.wallet3.mnemonic=${CARDANO_API_WALLET_3_MNEMONIC}
cardano.wallet3.mnemonicsecondary=${CARDANO_API_WALLET_3_MNEMONIC_SECONDARY}
cardano.wallet3.mnemonic=${?CARDANO_API_WALLET_3_MNEMONIC}
cardano.wallet3.mnemonicsecondary=${?CARDANO_API_WALLET_3_MNEMONIC_SECONDARY}
cardano.wallet3.id="4a583f9487bac2059caf50d753da1c91ede74345"
cardano.wallet3.name="cardano_api_wallet_3"
cardano.wallet3.passphrase=${CARDANO_API_WALLET_3_PASSPHRASE}
cardano.wallet3.passphrase=${?CARDANO_API_WALLET_3_PASSPHRASE}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers

import scala.jdk.CollectionConverters.{MapHasAsJava, SeqHasAsJava}
import scala.jdk.OptionConverters.RichOption


class CardanoJpiSpec extends AnyFlatSpec with Matchers with Configure with ModelCompare with BeforeAndAfterAll {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CardanoJpiSpec has a println on line 60


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,10 @@ private ListTransactionsParamBuilder(String walletId) {
Objects.requireNonNull(walletId, "WalletId cannot be null");
}

static ListTransactionsParamBuilder create(String walletId) {
public static ListTransactionsParamBuilder create(String walletId) {
return new ListTransactionsParamBuilder(walletId);
}


public ListTransactionsParamBuilder withEndTime(ZonedDateTime endTime) {
this.endTime = endTime;
return this;
Expand Down
8 changes: 8 additions & 0 deletions src/main/scala/iog/psg/cardano/jpi/HelpExecute.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ object HelpExecute {
case (k, v) => k.toLong -> MetadataValueStr (v)
}
}.toMap

def failOnLeft[T](future: Future[CardanoApiResponse[T]])(implicit ec: ExecutionContext): Future[T] = for {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

failOnLeft should be unwrap and since we're in the area future should probably be responseF

either <- future
response <- either match {
case Left(error) => Future.failed(new CardanoApiException(error.message, error.code))
case Right(value) => Future.successful(value)
}
} yield response
}

class HelpExecute(implicit ec: ExecutionContext, as: ActorSystem) extends JApiRequestExecutor {
Expand Down
17 changes: 17 additions & 0 deletions src/test/java/iog/psg/cardano/jpi/JpiResponseCheck.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package iog.psg.cardano.jpi;

import akka.actor.ActorSystem;
import iog.psg.cardano.CardanoApiCodec;
import scala.Enumeration;
import scala.Option;
import scala.concurrent.Future;
import scala.jdk.CollectionConverters;

import java.time.ZonedDateTime;
import java.util.*;
import java.util.concurrent.*;
import static scala.compat.java8.FutureConverters.*;
import scala.util.Either;

public class JpiResponseCheck {

Expand Down Expand Up @@ -105,6 +109,19 @@ public CardanoApiCodec.CreateTransactionResponse getTx(String walletId, String t
return jpi.getTransaction(walletId, txId).toCompletableFuture().get(timeout, timeoutUnit);
}

public static CardanoApi buildWithPredefinedApiExecutor(iog.psg.cardano.ApiRequestExecutor executor, ActorSystem as) {
CardanoApiBuilder builder = CardanoApiBuilder.create("http://fake:1234/").withApiExecutor(new ApiRequestExecutor() {
@Override
public <T> CompletionStage<T> execute(iog.psg.cardano.CardanoApi.CardanoApiRequest<T> request) throws CardanoApiException {
Future<Either<iog.psg.cardano.CardanoApi.ErrorMessage, T>> sResponse = executor.execute(request, as.dispatcher(), as);
CompletionStage<T> jResponse = toJava(HelpExecute.failOnLeft(sResponse, as.dispatcher()));
return jResponse;
}
});

return builder.build();
}

public static CardanoApi buildWithDummyApiExecutor() {
CardanoApiBuilder builder = CardanoApiBuilder.create("http://fake/").withApiExecutor(new ApiRequestExecutor() {
@Override
Expand Down
8 changes: 4 additions & 4 deletions src/test/resources/application.conf
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
cardano.wallet.baseUrl=${BASE_URL}
cardano.wallet.passphrase=${CARDANO_API_WALLET_1_PASSPHRASE}
cardano.wallet.baseUrl=${?BASE_URL}
cardano.wallet.passphrase=${?CARDANO_API_WALLET_1_PASSPHRASE}
cardano.wallet.name="cardano_api_wallet_1"
cardano.wallet.amount=2000000
cardano.wallet.mnemonic=${CARDANO_API_WALLET_1_MNEMONIC}
cardano.wallet.mnemonic=${?CARDANO_API_WALLET_1_MNEMONIC}
cardano.wallet.id="6cd6d11a489b7ea82a4624d18b93bdf9b77f0620"
cardano.wallet.metadata="0:0123456789012345678901234567890123456789012345678901234567890123:2:TESTINGCARDANOAPI"

cardano.wallet2.mnemonic=${CARDANO_API_WALLET_2_MNEMONIC}
cardano.wallet2.mnemonic=${?CARDANO_API_WALLET_2_MNEMONIC}
cardano.wallet2.id="bfa9530c4ecfee6e5561e950bd7a7a332e4e7497"
cardano.wallet2.name="somethrowawayname"
cardano.wallet2.passphrase="somethrowawayname"
8 changes: 8 additions & 0 deletions src/test/resources/jsons/addresses.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
[
{
"id": "addr1sjck9mdmfyhzvjhydcjllgj9vjvl522w0573ncustrrr2rg7h9azg4cyqd36yyd48t5ut72hgld0fg2xfvz82xgwh7wal6g2xt8n996s3xvu5g",
"state": "unused"
},
{
"id": "addr2sjck9mdmfyhzvjhydcjllgj9vjvl522w0573ncustrrr2rg7h9azg4cyqd36yyd48t5ut72hgld0fg2xfvz82xgwh7wal6g2xt8n996s3xvu5g",
"state": "used"
},
{
"id": "addr3sjck9mdmfyhzvjhydcjllgj9vjvl522w0573ncustrrr2rg7h9azg4cyqd36yyd48t5ut72hgld0fg2xfvz82xgwh7wal6g2xt8n996s3xvu5g",
"state": "unused"
}
]
2 changes: 1 addition & 1 deletion src/test/resources/jsons/estimate_fees.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"unit": "lovelace"
},
"estimated_max": {
"quantity": 42000000,
"quantity": 126000000,
"unit": "lovelace"
}
}
10 changes: 10 additions & 0 deletions src/test/resources/jsons/unused_addresses.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"id": "addr1sjck9mdmfyhzvjhydcjllgj9vjvl522w0573ncustrrr2rg7h9azg4cyqd36yyd48t5ut72hgld0fg2xfvz82xgwh7wal6g2xt8n996s3xvu5g",
"state": "unused"
},
{
"id": "addr3sjck9mdmfyhzvjhydcjllgj9vjvl522w0573ncustrrr2rg7h9azg4cyqd36yyd48t5ut72hgld0fg2xfvz82xgwh7wal6g2xt8n996s3xvu5g",
"state": "unused"
}
]
6 changes: 6 additions & 0 deletions src/test/resources/jsons/used_addresses.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"id": "addr2sjck9mdmfyhzvjhydcjllgj9vjvl522w0573ncustrrr2rg7h9azg4cyqd36yyd48t5ut72hgld0fg2xfvz82xgwh7wal6g2xt8n996s3xvu5g",
"state": "used"
}
]