Closed amiecorso closed 4 years ago
Merging #203 into master will increase coverage by
1.15%
. The diff coverage is95.23%
.
@@ Coverage Diff @@
## master #203 +/- ##
==========================================
+ Coverage 42.23% 43.38% +1.15%
==========================================
Files 61 61
Lines 1892 1934 +42
==========================================
+ Hits 799 839 +40
- Misses 1093 1095 +2
Impacted Files | Coverage Δ | |
---|---|---|
XpringKit/XRP/Utils.swift | 96.29% <95.23%> (-3.71%) |
:arrow_down: |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact)
,ø = not affected
,? = missing data
Powered by Codecov. Last update 405ce23...0132e26. Read the comment docs.
High Level Overview of Change
This PR adds the utility functions
xrpToDrops
anddropsToXrp
toXrpingKit/XRP/Utils
. These utility methods originally existed inripple-lib
, which is a robust and well-tested implementation that can handle either string or numeric values. Their implementation here is a translation into Swift. Note, however, that the Swift (and Java) methods currently only handle String arguments (whereas the JS implementation also handles BigNumber and Number types). Test cases are also based on the cases included inripple-lib
and added toTests/UtilsTest
.The logic in the conversions begins with a regex to determine whether the argument is a well-formed number, and includes additional checks such as (in
dropsToXrp
) that any drops amount submitted as a decimal is actually a whole number (i.e. 5.00, 0.0 etc.) and (inxrpToDrops
) that any xrp amount submitted as a decimal doesn't contain more than 6 non-zero numbers after the decimal, as the 7th and beyond would represent a fractional amount in drops - not allowed.Analogue in JS: https://github.com/xpring-eng/Xpring-JS/pull/399 Analogue in Java: https://github.com/xpring-eng/xpring4j/pull/217
Context of Change
Since this is such a common conversion, a robust implementation should be part of the SDKs.
Type of Change
Before / After
xrpToDrops
anddropsToXrp
can now be imported fromXpringKit
Test Plan
New test cases pulled from
ripple-lib
to explore all conversion logic.Future Tasks