From 3b5adc82f4358f3124e97e8c3a0d1841b768c2f1 Mon Sep 17 00:00:00 2001 From: jiahuihu Date: Thu, 9 Jan 2025 16:30:30 -0500 Subject: [PATCH] country code validation and bump version --- build.gradle.kts | 2 +- .../stellar/anchor/util/AssetValidator.java | 6 ++-- .../config/anchor-asset-default-values.yaml | 6 ++-- .../anchor/asset/DefaultAssetServiceTest.kt | 2 +- .../anchor/dto/sep38/InfoResponseTest.kt | 2 +- .../stellar/anchor/sep38/Sep38ServiceTest.kt | 30 +++++++++---------- core/src/test/resources/test_assets.json | 2 +- core/src/test/resources/test_assets.yaml | 2 +- docs/README.md | 2 +- helm-charts/sep-service/values.yaml | 4 +-- .../platform/PlatformServerBeans.java | 1 - .../main/resources/example.anchor-config.yaml | 2 +- platform/src/test/resources/test_assets.json | 2 +- platform/src/test/resources/test_assets.yaml | 2 +- .../test/resources/test_sep38_get_info.json | 2 +- .../src/main/resources/config/assets.yaml | 4 +-- 16 files changed, 34 insertions(+), 37 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index ba1c766015..7aa11e7441 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -216,7 +216,7 @@ subprojects { allprojects { group = "org.stellar.anchor-sdk" - version = "3.0.0" + version = "3.0.1" tasks.jar { manifest { diff --git a/core/src/main/java/org/stellar/anchor/util/AssetValidator.java b/core/src/main/java/org/stellar/anchor/util/AssetValidator.java index aefdda3f50..03514e0824 100644 --- a/core/src/main/java/org/stellar/anchor/util/AssetValidator.java +++ b/core/src/main/java/org/stellar/anchor/util/AssetValidator.java @@ -132,9 +132,7 @@ static void validateSep38(AssetService assetService, Sep38Info sep38Info, String } } - // TODO: Enable validate country codes in version 3.x because 2.x does not conform to the ISO - // country code - /* + // Validate country codes if (sep38Info.getCountryCodes() != null) { for (String country : sep38Info.getCountryCodes()) { if (!isCountryCodeValid(country)) @@ -142,7 +140,7 @@ static void validateSep38(AssetService assetService, Sep38Info sep38Info, String String.format("Invalid country code %s defined for asset %s.", country, assetId)); } } - */ + if (sep38Info.getBuyDeliveryMethods() != null) { // Validate methods for (DeliveryMethod method : sep38Info.getBuyDeliveryMethods()) { diff --git a/core/src/main/resources/config/anchor-asset-default-values.yaml b/core/src/main/resources/config/anchor-asset-default-values.yaml index 9b55d46de9..484425fa08 100644 --- a/core/src/main/resources/config/anchor-asset-default-values.yaml +++ b/core/src/main/resources/config/anchor-asset-default-values.yaml @@ -142,10 +142,10 @@ items: # - stellar:USDC:GBN4NNCDGJO4XW4KQU3CBIESUJWFVBUZPOKUZHT7W7WRB7CWOA7BXVQF exchangeable_assets: - # The list of the country codes that the asset is available in. + # The list of the ISO 3166-1 alpha-2 country codes that the asset is available in. # Example: - # - USA - # - CAN + # - US + # - CA country_codes: # An array of objects describing the methods a client can use to sell/deliver funds to the anchor. diff --git a/core/src/test/kotlin/org/stellar/anchor/asset/DefaultAssetServiceTest.kt b/core/src/test/kotlin/org/stellar/anchor/asset/DefaultAssetServiceTest.kt index 20c601c19b..dfd434f9bb 100644 --- a/core/src/test/kotlin/org/stellar/anchor/asset/DefaultAssetServiceTest.kt +++ b/core/src/test/kotlin/org/stellar/anchor/asset/DefaultAssetServiceTest.kt @@ -239,7 +239,7 @@ internal class DefaultAssetServiceTest { "stellar:USDC:GDQOE23CFSUMSVQK4Y5JHPPYK73VYCNHZHA7ENKCV37P6SUEO6XQBKPP" ], "country_codes": [ - "USA" + "US" ], "sell_delivery_methods": [ { diff --git a/core/src/test/kotlin/org/stellar/anchor/dto/sep38/InfoResponseTest.kt b/core/src/test/kotlin/org/stellar/anchor/dto/sep38/InfoResponseTest.kt index 6e0870b49d..52daa219ae 100644 --- a/core/src/test/kotlin/org/stellar/anchor/dto/sep38/InfoResponseTest.kt +++ b/core/src/test/kotlin/org/stellar/anchor/dto/sep38/InfoResponseTest.kt @@ -51,7 +51,7 @@ class InfoResponseTest { val fiatUSD = assetMap["iso4217:USD"] assertNotNull(fiatUSD) - assertEquals(listOf("USA"), fiatUSD!!.countryCodes) + assertEquals(listOf("US"), fiatUSD!!.countryCodes) val wantSellDeliveryMethod = Sep38Info.DeliveryMethod("WIRE", "Send USD directly to the Anchor's bank account.") assertEquals(listOf(wantSellDeliveryMethod), fiatUSD.sellDeliveryMethods) diff --git a/core/src/test/kotlin/org/stellar/anchor/sep38/Sep38ServiceTest.kt b/core/src/test/kotlin/org/stellar/anchor/sep38/Sep38ServiceTest.kt index 3aa3fc28bc..16097d8c65 100644 --- a/core/src/test/kotlin/org/stellar/anchor/sep38/Sep38ServiceTest.kt +++ b/core/src/test/kotlin/org/stellar/anchor/sep38/Sep38ServiceTest.kt @@ -120,7 +120,7 @@ class Sep38ServiceTest { val fiatUSD = assetMap[fiatUSD] assertNotNull(fiatUSD) - assertEquals(listOf("USA"), fiatUSD!!.countryCodes) + assertEquals(listOf("US"), fiatUSD!!.countryCodes) val wantSellDeliveryMethod = Sep38Info.DeliveryMethod("WIRE", "Send USD directly to the Anchor's bank account.") assertEquals(listOf(wantSellDeliveryMethod), fiatUSD.sellDeliveryMethods) @@ -236,7 +236,7 @@ class Sep38ServiceTest { .sellAsset(fiatUSD) .buyAsset("stellar:JPYC:GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5") .sellAmount("100") - .countryCode("USA") + .countryCode("US") .sellDeliveryMethod("WIRE") .build() every { mockRateIntegration.getRate(getRateReq1) } returns @@ -248,7 +248,7 @@ class Sep38ServiceTest { .sellAsset(fiatUSD) .buyAsset(stellarUSDC) .sellAmount("100") - .countryCode("USA") + .countryCode("US") .sellDeliveryMethod("WIRE") .build() every { mockRateIntegration.getRate(getRateReq2) } returns @@ -258,7 +258,7 @@ class Sep38ServiceTest { // test happy path with all the parameters var gotResponse: GetPricesResponse? = null - assertDoesNotThrow { gotResponse = sep38Service.getPrices(fiatUSD, "100", "WIRE", null, "USA") } + assertDoesNotThrow { gotResponse = sep38Service.getPrices(fiatUSD, "100", "WIRE", null, "US") } val wantResponse = GetPricesResponse() wantResponse.addAsset(stellarJPYC, 2, "1.1") wantResponse.addAsset(stellarUSDC, 2, "2.1") @@ -393,13 +393,13 @@ class Sep38ServiceTest { // unsupported country_code getPriceRequestBuilder = getPriceRequestBuilder.buyDeliveryMethod(null) - getPriceRequestBuilder = getPriceRequestBuilder.countryCode("BRA") + getPriceRequestBuilder = getPriceRequestBuilder.countryCode("BR") ex = assertThrows { sep38Service.getPrice(null, getPriceRequestBuilder.build()) } assertInstanceOf(BadRequestException::class.java, ex) assertEquals("Unsupported country code", ex.message) // unsupported (null) context - getPriceRequestBuilder = getPriceRequestBuilder.countryCode("USA") + getPriceRequestBuilder = getPriceRequestBuilder.countryCode("US") ex = assertThrows { sep38Service.getPrice(null, getPriceRequestBuilder.build()) } assertInstanceOf(BadRequestException::class.java, ex) assertEquals("Unsupported context. Should be one of [sep6, sep31].", ex.message) @@ -497,7 +497,7 @@ class Sep38ServiceTest { .sellAsset(fiatUSD) .buyAsset(stellarUSDC) .sellAmount("100") - .countryCode("USA") + .countryCode("US") .sellDeliveryMethod("WIRE") .build() every { mockRateIntegration.getRate(getRateReq) } returns @@ -512,7 +512,7 @@ class Sep38ServiceTest { .sellAmount("100") .sellDeliveryMethod("WIRE") .buyAssetName(stellarUSDC) - .countryCode("USA") + .countryCode("US") .context(SEP6) .build() var gotResponse: GetPriceResponse? = null @@ -537,7 +537,7 @@ class Sep38ServiceTest { .sellAsset(fiatUSD) .buyAsset(stellarUSDC) .buyAmount("100") - .countryCode("USA") + .countryCode("US") .sellDeliveryMethod("WIRE") .build() @@ -553,7 +553,7 @@ class Sep38ServiceTest { .sellDeliveryMethod("WIRE") .buyAssetName(stellarUSDC) .buyAmount("100") - .countryCode("USA") + .countryCode("US") .context(SEP31) .build() var gotResponse: GetPriceResponse? = null @@ -788,7 +788,7 @@ class Sep38ServiceTest { .sellAmount("1.23") .sellDeliveryMethod("WIRE") .buyAssetName(stellarUSDC) - .countryCode("BRA") + .countryCode("BR") .build() ) } @@ -804,7 +804,7 @@ class Sep38ServiceTest { .sellAmount("1.23") .sellDeliveryMethod("WIRE") .buyAssetName(stellarUSDC) - .countryCode("USA") + .countryCode("US") .expireAfter("2022-04-18T23:33:24.629719Z") .build() ) @@ -1063,7 +1063,7 @@ class Sep38ServiceTest { .sellAmount("100") .sellDeliveryMethod("WIRE") .buyAssetName(stellarUSDC) - .countryCode("USA") + .countryCode("US") .expireAfter(now.toString()) .build() ) @@ -1167,7 +1167,7 @@ class Sep38ServiceTest { .sellDeliveryMethod("WIRE") .buyAssetName(stellarUSDC) .buyAmount("100") - .countryCode("USA") + .countryCode("US") .expireAfter(now.toString()) .build() ) @@ -1279,7 +1279,7 @@ class Sep38ServiceTest { .sellDeliveryMethod("WIRE") .buyAssetName(stellarUSDC) .buyAmount(requestBuyAmount) - .countryCode("USA") + .countryCode("US") .expireAfter(now.toString()) .build() ) diff --git a/core/src/test/resources/test_assets.json b/core/src/test/resources/test_assets.json index 61624d803b..ea908cd02b 100644 --- a/core/src/test/resources/test_assets.json +++ b/core/src/test/resources/test_assets.json @@ -159,7 +159,7 @@ "stellar:USDC:GDQOE23CFSUMSVQK4Y5JHPPYK73VYCNHZHA7ENKCV37P6SUEO6XQBKPP" ], "country_codes": [ - "USA" + "US" ], "decimals": 4, "sell_delivery_methods": [ diff --git a/core/src/test/resources/test_assets.yaml b/core/src/test/resources/test_assets.yaml index eb5f805148..60cf4795b7 100644 --- a/core/src/test/resources/test_assets.yaml +++ b/core/src/test/resources/test_assets.yaml @@ -100,7 +100,7 @@ items: - stellar:JPYC:GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5 - stellar:USDC:GDQOE23CFSUMSVQK4Y5JHPPYK73VYCNHZHA7ENKCV37P6SUEO6XQBKPP country_codes: - - USA + - US sell_delivery_methods: - name: WIRE description: Send USD directly to the Anchor's bank account. diff --git a/docs/README.md b/docs/README.md index 907d3d76d1..23f633b58b 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,6 +1,6 @@ [![License](https://badgen.net/badge/license/Apache%202/blue?icon=github&label=License)](https://github.com/stellar/java-stellar-anchor-sdk/blob/develop/LICENSE) [![GitHub Version](https://badgen.net/github/release/stellar/java-stellar-anchor-sdk?icon=github&label=Latest%20release)](https://github.com/stellar/java-stellar-anchor-sdk/releases) -[![Docker](https://badgen.net/badge/Latest%20Release/v3.0.0/blue?icon=docker)](https://hub.docker.com/r/stellar/anchor-platform/tags?page=1&name=3.0.0) +[![Docker](https://badgen.net/badge/Latest%20Release/v3.0.1/blue?icon=docker)](https://hub.docker.com/r/stellar/anchor-platform/tags?page=1&name=3.0.1) ![Develop Branch](https://github.com/stellar/java-stellar-anchor-sdk/actions/workflows/on_push_to_develop.yml/badge.svg?branch=develop)
diff --git a/helm-charts/sep-service/values.yaml b/helm-charts/sep-service/values.yaml index 77131899be..59a5d3f9ed 100644 --- a/helm-charts/sep-service/values.yaml +++ b/helm-charts/sep-service/values.yaml @@ -274,7 +274,7 @@ assets_config: | exchangeable_assets: - stellar:USDC:GDQOE23CFSUMSVQK4Y5JHPPYK73VYCNHZHA7ENKCV37P6SUEO6XQBKPP country_codes: - - USA + - US sell_delivery_methods: - name: WIRE description: Send USD directly to the Anchor's bank account. @@ -293,7 +293,7 @@ assets_config: | exchangeable_assets: - stellar:USDC:GDQOE23CFSUMSVQK4Y5JHPPYK73VYCNHZHA7ENKCV37P6SUEO6XQBKPP country_codes: - - CAN + - CA sell_delivery_methods: - name: WIRE description: Send CAD directly to the Anchor's bank account. diff --git a/platform/src/main/java/org/stellar/anchor/platform/component/platform/PlatformServerBeans.java b/platform/src/main/java/org/stellar/anchor/platform/component/platform/PlatformServerBeans.java index 4332841576..985651f2ae 100644 --- a/platform/src/main/java/org/stellar/anchor/platform/component/platform/PlatformServerBeans.java +++ b/platform/src/main/java/org/stellar/anchor/platform/component/platform/PlatformServerBeans.java @@ -19,7 +19,6 @@ import org.stellar.anchor.filter.PlatformAuthJwtFilter; import org.stellar.anchor.horizon.Horizon; import org.stellar.anchor.platform.apiclient.CustodyApiClient; -import org.stellar.anchor.platform.condition.OnAnySepsEnabled; import org.stellar.anchor.platform.config.PlatformApiConfig; import org.stellar.anchor.platform.config.PlatformServerConfig; import org.stellar.anchor.platform.config.PropertyCustodyConfig; diff --git a/platform/src/main/resources/example.anchor-config.yaml b/platform/src/main/resources/example.anchor-config.yaml index fdc8cbb72e..bf0f64a0da 100644 --- a/platform/src/main/resources/example.anchor-config.yaml +++ b/platform/src/main/resources/example.anchor-config.yaml @@ -212,7 +212,7 @@ assets: "stellar:JPYC:GDQOE23CFSUMSVQK4Y5JHPPYK73VYCNHZHA7ENKCV37P6SUEO6XQBKPP" ], "country_codes": [ - "USA" + "US" ], "decimals": 4, "sell_delivery_methods": [ diff --git a/platform/src/test/resources/test_assets.json b/platform/src/test/resources/test_assets.json index 55d78df010..574641fd0c 100644 --- a/platform/src/test/resources/test_assets.json +++ b/platform/src/test/resources/test_assets.json @@ -65,7 +65,7 @@ "exchangeable_assets": [ "stellar:USDC:GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN" ], - "country_codes": ["USA"], + "country_codes": ["US"], "decimals": 4, "sell_delivery_methods": [ { diff --git a/platform/src/test/resources/test_assets.yaml b/platform/src/test/resources/test_assets.yaml index e07ac851da..a3f98c80e7 100644 --- a/platform/src/test/resources/test_assets.yaml +++ b/platform/src/test/resources/test_assets.yaml @@ -47,7 +47,7 @@ items: exchangeable_assets: - stellar:USDC:GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN country_codes: - - USA + - US decimals: 4 sell_delivery_methods: - name: WIRE diff --git a/platform/src/test/resources/test_sep38_get_info.json b/platform/src/test/resources/test_sep38_get_info.json index daff0d652a..b1a17d870c 100644 --- a/platform/src/test/resources/test_sep38_get_info.json +++ b/platform/src/test/resources/test_sep38_get_info.json @@ -8,7 +8,7 @@ }, { "asset": "iso4217:USD", - "country_codes": ["USA"], + "country_codes": ["US"], "decimals": 4, "sell_delivery_methods": [ { diff --git a/service-runner/src/main/resources/config/assets.yaml b/service-runner/src/main/resources/config/assets.yaml index 3297df2fd0..12706cf514 100644 --- a/service-runner/src/main/resources/config/assets.yaml +++ b/service-runner/src/main/resources/config/assets.yaml @@ -181,7 +181,7 @@ items: - stellar:USDC:GDQOE23CFSUMSVQK4Y5JHPPYK73VYCNHZHA7ENKCV37P6SUEO6XQBKPP - stellar:USDC:GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5 country_codes: - - USA + - US sell_delivery_methods: - name: WIRE description: Send USD directly to the Anchor's bank account. @@ -204,7 +204,7 @@ items: - stellar:USDC:GDQOE23CFSUMSVQK4Y5JHPPYK73VYCNHZHA7ENKCV37P6SUEO6XQBKPP - stellar:USDC:GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5 country_codes: - - CAN + - CA sell_delivery_methods: - name: WIRE description: Send CAD directly to the Anchor's bank account.