Skip to content

Commit

Permalink
[ANCHOR-586] Enable SEP-31 and SEP-38 for native asset (#1259)
Browse files Browse the repository at this point in the history
### Description

Support native in sep31/38

### Context

Enable SEP-31 and SEP-38 support for the native asset, and add tests
back.

### Testing

- `./gradlew test`
  • Loading branch information
JiahuiWho authored Jan 19, 2024
2 parents ab082ed + 769a53c commit 32de962
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 186 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ public static void validate(AssetService assetService) throws InvalidConfigExcep
throw new InvalidConfigException("0 assets defined in configuration");
}

// TODO: remove this check once we support SEP-31 and SEP-38 for native asset
AssetInfo nativeAsset = assetService.getAsset("native");
if (nativeAsset != null && (nativeAsset.getSep31Enabled() || nativeAsset.getSep38Enabled())) {
throw new InvalidConfigException("Native asset does not support SEP-31 or SEP-38");
}

// Check for duplicate assets
Set<String> existingAssetNames = new HashSet<>();
for (AssetInfo asset : assetService.listAllAssets()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,6 @@ internal class DefaultAssetServiceTest {
}
}

@Test
fun `test native asset with SEP-31 or SEP-38 enabled`() {
assertThrows<InvalidConfigException> {
DefaultAssetService.fromJsonResource("test_native_asset_sep31.json.bad")
}
assertThrows<InvalidConfigException> {
DefaultAssetService.fromJsonResource("test_native_asset_sep38.json.bad")
}
}

@Test
fun `test invalid config with duplicate assets`() {
assertThrows<InvalidConfigException> {
Expand Down Expand Up @@ -389,8 +379,8 @@ internal class DefaultAssetServiceTest {
},
"sep6_enabled": false,
"sep24_enabled": true,
"sep31_enabled": false,
"sep38_enabled": false
"sep31_enabled": true,
"sep38_enabled": true
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ class InfoResponseTest {
@Test
fun `test the InfoResponse construction`() {
val infoResponse = InfoResponse(assets)
assertEquals(3, infoResponse.assets.size)
assertEquals(4, infoResponse.assets.size)

val assetMap = HashMap<String, InfoResponse.Asset>()
infoResponse.assets.forEach { assetMap[it.asset] = it }
assertEquals(3, assetMap.size)
assertEquals(4, assetMap.size)

val stellarUSDC =
assetMap["stellar:USDC:GDQOE23CFSUMSVQK4Y5JHPPYK73VYCNHZHA7ENKCV37P6SUEO6XQBKPP"]
Expand Down Expand Up @@ -65,5 +65,14 @@ class InfoResponseTest {
)
assertTrue(fiatUSD.exchangeableAssetNames.containsAll(wantAssets))
assertTrue(wantAssets.containsAll(fiatUSD.exchangeableAssetNames))

val stellarNative = assetMap["stellar:native"]
assertNotNull(stellarNative)
assertNull(stellarNative!!.countryCodes)
assertNull(stellarNative.sellDeliveryMethods)
assertNull(stellarNative.buyDeliveryMethods)
wantAssets = listOf("stellar:USDC:GDQOE23CFSUMSVQK4Y5JHPPYK73VYCNHZHA7ENKCV37P6SUEO6XQBKPP")
assertTrue(stellarNative.exchangeableAssetNames.containsAll(wantAssets))
assertTrue(wantAssets.containsAll(stellarNative.exchangeableAssetNames))
}
}
13 changes: 11 additions & 2 deletions core/src/test/kotlin/org/stellar/anchor/sep38/Sep38ServiceTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ class Sep38ServiceTest {
@Test
fun `test GET info`() {
val infoResponse = sep38Service.info
assertEquals(3, infoResponse.assets.size)
assertEquals(4, infoResponse.assets.size)

val assetMap = HashMap<String, InfoResponse.Asset>()
infoResponse.assets.forEach { assetMap[it.asset] = it }
assertEquals(3, assetMap.size)
assertEquals(4, assetMap.size)

val usdcAsset = assetMap[stellarUSDC]
assertNotNull(usdcAsset)
Expand Down Expand Up @@ -128,6 +128,15 @@ class Sep38ServiceTest {
listOf("stellar:JPYC:GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5", stellarUSDC)
assertTrue(fiatUSD.exchangeableAssetNames.containsAll(wantAssets))
assertTrue(wantAssets.containsAll(fiatUSD.exchangeableAssetNames))

val stellarNative = assetMap["stellar:native"]
assertNotNull(stellarNative)
assertNull(stellarNative!!.countryCodes)
assertNull(stellarNative.sellDeliveryMethods)
assertNull(stellarNative.buyDeliveryMethods)
wantAssets = listOf("stellar:USDC:GDQOE23CFSUMSVQK4Y5JHPPYK73VYCNHZHA7ENKCV37P6SUEO6XQBKPP")
assertTrue(stellarNative.exchangeableAssetNames.containsAll(wantAssets))
assertTrue(wantAssets.containsAll(stellarNative.exchangeableAssetNames))
}

@Test
Expand Down
4 changes: 2 additions & 2 deletions core/src/test/resources/test_assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,8 @@
},
"sep6_enabled": false,
"sep24_enabled": true,
"sep31_enabled": false,
"sep38_enabled": false
"sep31_enabled": true,
"sep38_enabled": true
}
]
}
4 changes: 2 additions & 2 deletions core/src/test/resources/test_assets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -205,5 +205,5 @@ assets:
decimals: 7
sep6_enabled: false
sep24_enabled: true
sep31_enabled: false
sep38_enabled: false
sep31_enabled: true
sep38_enabled: true
79 changes: 0 additions & 79 deletions core/src/test/resources/test_native_asset_sep31.json.bad

This file was deleted.

79 changes: 0 additions & 79 deletions core/src/test/resources/test_native_asset_sep38.json.bad

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,59 @@ private const val expectedSep31Info =
}
}
}
},
"native": {
"enabled": true,
"quotes_supported": true,
"quotes_required": true,
"fee_fixed": 0,
"fee_percent": 0,
"max_amount": 1000000,
"sep12": {
"sender": {
"types": {
"sep31-sender": {
"description": "U.S. citizens limited to sending payments of less than ${'$'}10,000 in value"
},
"sep31-large-sender": {
"description": "U.S. citizens that do not have sending limits"
},
"sep31-foreign-sender": {
"description": "non-U.S. citizens sending payments of less than ${'$'}10,000 in value"
}
}
},
"receiver": {
"types": {
"sep31-receiver": {
"description": "U.S. citizens receiving USD"
},
"sep31-foreign-receiver": {
"description": "non-U.S. citizens receiving USD"
}
}
}
},
"fields": {
"transaction": {
"receiver_routing_number": {
"description": "routing number of the destination bank account",
"optional": false
},
"receiver_account_number": {
"description": "bank account number of the destination",
"optional": false
},
"type": {
"description": "type of deposit to make",
"choices": [
"SEPA",
"SWIFT"
],
"optional": false
}
}
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions service-runner/src/main/resources/config/assets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,6 @@ assets:
- stellar:USDC:GDQOE23CFSUMSVQK4Y5JHPPYK73VYCNHZHA7ENKCV37P6SUEO6XQBKPP
decimals: 7
sep6_enabled: false
sep31_enabled: false
sep38_enabled: false
sep31_enabled: true
sep38_enabled: true
sep24_enabled: true

0 comments on commit 32de962

Please sign in to comment.