1
1
import { convertSource , Asset , convertDestination } from './util'
2
2
3
3
describe ( 'Rates util' , ( ) => {
4
- describe ( 'convert ' , ( ) => {
5
- describe ( 'convert same scales' , ( ) => {
4
+ describe ( 'convertSource ' , ( ) => {
5
+ describe ( 'convertSource same scales' , ( ) => {
6
6
test . each `
7
7
exchangeRate | sourceAmount | assetScale | expectedResult | description
8
8
${ 1.5 } | ${ 100n } | ${ 9 } | ${ { amount : 150n , scaledExchangeRate : 1.5 } } | ${ 'exchange rate above 1' }
@@ -31,11 +31,12 @@ describe('Rates util', () => {
31
31
)
32
32
} )
33
33
34
- describe ( 'convert different scales' , ( ) => {
34
+ describe ( 'convertSource different scales' , ( ) => {
35
35
test . each `
36
- exchangeRate | sourceAmount | sourceAssetScale | destinationAssetScale | expectedResult | description
37
- ${ 1.5 } | ${ 100n } | ${ 9 } | ${ 12 } | ${ { amount : 150_000n , scaledExchangeRate : 1500 } } | ${ 'convert scale from low to high' }
38
- ${ 1.5 } | ${ 100_000n } | ${ 12 } | ${ 9 } | ${ { amount : 150n , scaledExchangeRate : 0.0015 } } | ${ 'convert scale from high to low' }
36
+ exchangeRate | sourceAmount | sourceAssetScale | destinationAssetScale | expectedResult | description
37
+ ${ 1.5 } | ${ 100n } | ${ 9 } | ${ 12 } | ${ { amount : 150_000n , scaledExchangeRate : 1500 } } | ${ 'convert scale from low to high' }
38
+ ${ 1.5 } | ${ 100_000n } | ${ 12 } | ${ 9 } | ${ { amount : 150n , scaledExchangeRate : 0.0015 } } | ${ 'convert scale from high to low' }
39
+ ${ 1 } | ${ 100_000_000n } | ${ 9 } | ${ 2 } | ${ { amount : 10n , scaledExchangeRate : 0.0000001 } } | ${ 'exchange rate of 1 with different scale' }
39
40
` (
40
41
'$description' ,
41
42
async ( {
@@ -57,7 +58,7 @@ describe('Rates util', () => {
57
58
)
58
59
} )
59
60
} )
60
- describe ( 'convert reverse ' , ( ) => {
61
+ describe ( 'convertDestination ' , ( ) => {
61
62
describe ( 'convert same scales' , ( ) => {
62
63
test . each `
63
64
exchangeRate | destinationAmount | assetScale | expectedResult | description
@@ -88,8 +89,9 @@ describe('Rates util', () => {
88
89
describe ( 'convert different scales' , ( ) => {
89
90
test . each `
90
91
exchangeRate | destinationAmount | sourceAssetScale | destinationAssetScale | expectedResult | description
91
- ${ 2.0 } | ${ 100n } | ${ 9 } | ${ 12 } | ${ { amount : 50_000n , scaledExchangeRate : 0.002 } } | ${ 'convert scale from low to high' }
92
- ${ 2.0 } | ${ 100_000n } | ${ 12 } | ${ 9 } | ${ { amount : 50n , scaledExchangeRate : 2000 } } | ${ 'convert scale from high to low' }
92
+ ${ 2.0 } | ${ 100n } | ${ 12 } | ${ 9 } | ${ { amount : 50_000n , scaledExchangeRate : 0.002 } } | ${ 'convert scale from low to high' }
93
+ ${ 2.0 } | ${ 100_000n } | ${ 9 } | ${ 12 } | ${ { amount : 50n , scaledExchangeRate : 2000 } } | ${ 'convert scale from high to low' }
94
+ ${ 1 } | ${ 100_000_000n } | ${ 2 } | ${ 9 } | ${ { amount : 10n , scaledExchangeRate : 10000000 } } | ${ 'convert scale from high to low (same asset)' }
93
95
` (
94
96
'$description' ,
95
97
async ( {
0 commit comments