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

[Chore] Merge feature/v3 into feature/m24-demo #1536

Merged
merged 4 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public class GetQuoteResponse {
@SerializedName("sell_asset")
String sellAsset;

@JsonProperty("sell_delivery_method")
@SerializedName("sell_delivery_method")
String sellDeliveryMethod;

@JsonProperty("buy_amount")
@SerializedName("buy_amount")
String buyAmount;
Expand All @@ -31,6 +35,10 @@ public class GetQuoteResponse {
@SerializedName("buy_asset")
String buyAsset;

@JsonProperty("buy_delivery_method")
@SerializedName("buy_delivery_method")
String buyDeliveryMethod;

@JsonProperty("expires_at")
@SerializedName("expires_at")
Instant expiresAt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,17 @@ public class Sep38QuoteResponse {
@SerializedName("sell_amount")
String sellAmount;

@SerializedName("sell_delivery_method")
String sellDeliveryMethod;

@SerializedName("buy_asset")
String buyAsset;

@SerializedName("buy_amount")
String buyAmount;

@SerializedName("buy_delivery_method")
String buyDeliveryMethod;

FeeDetails fee;
}
6 changes: 6 additions & 0 deletions core/src/main/java/org/stellar/anchor/sep38/Sep38Service.java
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,9 @@ public Sep38QuoteResponse postQuote(Sep10Jwt token, Sep38PostQuoteRequest reques
.expiresAt(rate.getExpiresAt())
.price(rate.getPrice())
.sellAsset(request.getSellAssetName())
.sellDeliveryMethod(request.getSellDeliveryMethod())
.buyAsset(request.getBuyAssetName())
.buyDeliveryMethod(request.getBuyDeliveryMethod())
.fee(rate.getFee());

String sellAmount = formatAmount(decimal(rate.getSellAmount()), sellAsset.getDecimals());
Expand Down Expand Up @@ -412,8 +414,10 @@ public Sep38QuoteResponse postQuote(Sep10Jwt token, Sep38PostQuoteRequest reques
updateField(newQuote, "id", event, "quote.id");
updateField(newQuote, "sellAsset", event, "quote.sellAsset");
updateField(newQuote, "sellAmount", event, "quote.sellAmount");
updateField(newQuote, "sellDeliveryMethod", event, "quote.sellDeliveryMethod");
updateField(newQuote, "buyAsset", event, "quote.buyAsset");
updateField(newQuote, "buyAmount", event, "quote.buyAmount");
updateField(newQuote, "buyDeliveryMethod", event, "quote.buyDeliveryMethod");
updateField(newQuote, "expiresAt", event, "quote.expiresAt");
updateField(newQuote, "createdAt", event, "quote.createdAt");
updateField(newQuote, "price", event, "quote.price");
Expand Down Expand Up @@ -473,8 +477,10 @@ public Sep38QuoteResponse getQuote(Sep10Jwt token, String quoteId) throws Anchor
.price(quote.getPrice())
.sellAsset(quote.getSellAsset())
.sellAmount(quote.getSellAmount())
.sellDeliveryMethod(quote.getSellDeliveryMethod())
.buyAsset(quote.getBuyAsset())
.buyAmount(quote.getBuyAmount())
.buyDeliveryMethod(quote.getBuyDeliveryMethod())
.fee(quote.getFee())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,7 @@ class Sep38ServiceTest {
.totalPrice("1.0300000004")
.sellAsset(fiatUSD)
.sellAmount("100")
.sellDeliveryMethod("WIRE")
.buyAsset(stellarUSDC)
.buyAmount("97.09")
.fee(mockFee)
Expand Down Expand Up @@ -1113,6 +1114,7 @@ class Sep38ServiceTest {
wantEvent.quote.id = "123"
wantEvent.quote.sellAsset = fiatUSD
wantEvent.quote.sellAmount = "100"
wantEvent.quote.sellDeliveryMethod = "WIRE"
wantEvent.quote.buyAsset = stellarUSDC
wantEvent.quote.buyAmount = "97.09"
wantEvent.quote.expiresAt = tomorrow
Expand Down Expand Up @@ -1183,6 +1185,7 @@ class Sep38ServiceTest {
.totalPrice("1.03")
.sellAsset(fiatUSD)
.sellAmount("103")
.sellDeliveryMethod("WIRE")
.buyAsset(stellarUSDC)
.buyAmount("100")
.fee(mockFee)
Expand Down Expand Up @@ -1215,6 +1218,7 @@ class Sep38ServiceTest {
wantEvent.quote.id = "456"
wantEvent.quote.sellAsset = fiatUSD
wantEvent.quote.sellAmount = "103"
wantEvent.quote.sellDeliveryMethod = "WIRE"
wantEvent.quote.buyAsset = stellarUSDC
wantEvent.quote.buyAmount = "100"
wantEvent.quote.expiresAt = tomorrow
Expand Down Expand Up @@ -1293,6 +1297,7 @@ class Sep38ServiceTest {
.totalPrice(anchorCalculatedPrice)
.sellAsset(fiatUSD)
.sellAmount(anchorCalculatedSellAmount)
.sellDeliveryMethod("WIRE")
.buyAsset(stellarUSDC)
.buyAmount(anchorCalculatedBuyAmount)
.fee(mockFee)
Expand Down Expand Up @@ -1325,6 +1330,7 @@ class Sep38ServiceTest {
wantEvent.quote.id = "456"
wantEvent.quote.sellAsset = fiatUSD
wantEvent.quote.sellAmount = anchorCalculatedSellAmount
wantEvent.quote.sellDeliveryMethod = "WIRE"
wantEvent.quote.buyAsset = stellarUSDC
wantEvent.quote.buyAmount = anchorCalculatedBuyAmount
wantEvent.quote.expiresAt = tomorrow
Expand Down Expand Up @@ -1473,6 +1479,7 @@ class Sep38ServiceTest {
.totalPrice("1.03")
.sellAsset(fiatUSD)
.sellAmount("100")
.sellDeliveryMethod("WIRE")
.buyAsset(stellarUSDC)
.buyAmount("97.0873786")
.fee(mockFee)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ public boolean supports(@NotNull Class<?> clazz) {

@Override
public void validate(@NotNull Object target, @NotNull Errors errors) {
// If type is FILE, value must be defined
// if type is INLINE, items can be left empty as this not a required config
if (this.getType() == ClientsConfigType.FILE && isEmpty(this.getValue())) {
errors.reject("invalid-no-value-defined", "clients.value is empty. Please define.");
}

// Parse the file and validate the contents
try {
parseConfigIntoItemList();
Expand Down Expand Up @@ -119,9 +113,10 @@ void validateCallbackUrls(ClientConfig client, Errors errors) {
}

private void parseConfigIntoItemList() throws InvalidConfigException {
if (this.getType().equals(ClientsConfigType.INLINE)) {
if (this.getType().equals(ClientsConfigType.INLINE) || isEmpty(this.getValue())) {
return;
}

// 1. Parse the content into a map with "items" as the key and a List<Object> as the value.
Map<String, List<Object>> contentMap = new HashMap<>();
switch (this.getType()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package org.stellar.anchor.platform.config

import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.EnumSource
import org.springframework.validation.BindException
import org.springframework.validation.Errors
import org.stellar.anchor.client.ClientConfig.CallbackUrls
Expand Down Expand Up @@ -162,4 +163,21 @@ class ClientsConfigTest {
config.validate(config, errors)
assertEquals(4, errors.errorCount)
}

@ParameterizedTest
@EnumSource(ClientsConfig.ClientsConfigType::class, names = ["FILE", "JSON", "YAML"])
fun `test empty value for file, json, yaml config type`(
configType: ClientsConfig.ClientsConfigType
) {
config.setType(configType)
assertTrue(config.getValue().isNullOrEmpty())
assertDoesNotThrow { config.validate(config, errors) }
}

@Test
fun `test empty value for inline config type`() {
config.setType(ClientsConfig.ClientsConfigType.INLINE)
assertTrue { config.getItems().isEmpty() }
assertDoesNotThrow { config.validate(config, errors) }
}
}
Loading