@@ -1539,22 +1539,12 @@ func TestEVMTransferBaseTokens(t *testing.T) {
1539
1539
1540
1540
// issue a tx with non-0 amount (try to send ETH/basetoken)
1541
1541
// try sending 1 million base tokens (expressed in ethereum decimals)
1542
- value := util .BaseTokensDecimalsToEthereumDecimals (
1542
+ value := util .MustBaseTokensDecimalsToEthereumDecimalsExact (
1543
1543
1 * isc .Million ,
1544
1544
testparameters .GetL1ParamsForTesting ().BaseToken .Decimals ,
1545
1545
)
1546
1546
sendTx (value )
1547
1547
env .Chain .AssertL2BaseTokens (someAgentID , 1 * isc .Million )
1548
-
1549
- // by default iota/shimmer base token has 6 decimal cases, so anything past the 6th decimal case should be ignored
1550
- valueWithExtraDecimals := big .NewInt (1_000_000_999_999_999_999 ) // all these 9's will be ignored and only 1 million tokens should be transferred
1551
- sendTx (valueWithExtraDecimals )
1552
- env .Chain .AssertL2BaseTokens (someAgentID , 2 * isc .Million )
1553
-
1554
- // issue a tx with a too low amount
1555
- lowValue := big .NewInt (999_999_999_999 ) // all these 9's will be ignored and nothing should be transferred
1556
- sendTx (lowValue )
1557
- env .Chain .AssertL2BaseTokens (someAgentID , 2 * isc .Million )
1558
1548
}
1559
1549
1560
1550
func TestSolidityTransferBaseTokens (t * testing.T ) {
@@ -1566,7 +1556,7 @@ func TestSolidityTransferBaseTokens(t *testing.T) {
1566
1556
iscTest := env .deployISCTestContract (ethKey )
1567
1557
1568
1558
// try sending funds to `someEthereumAddr` by sending a "value tx" to the isc test contract
1569
- oneMillionInEthDecimals := util .BaseTokensDecimalsToEthereumDecimals (
1559
+ oneMillionInEthDecimals := util .MustBaseTokensDecimalsToEthereumDecimalsExact (
1570
1560
1 * isc .Million ,
1571
1561
testparameters .GetL1ParamsForTesting ().BaseToken .Decimals ,
1572
1562
)
@@ -1579,7 +1569,7 @@ func TestSolidityTransferBaseTokens(t *testing.T) {
1579
1569
env .Chain .AssertL2BaseTokens (someEthereumAgentID , 1 * isc .Million )
1580
1570
1581
1571
// attempt to send more than the contract will have available
1582
- twoMillionInEthDecimals := util .BaseTokensDecimalsToEthereumDecimals (
1572
+ twoMillionInEthDecimals := util .MustBaseTokensDecimalsToEthereumDecimalsExact (
1583
1573
2 * isc .Million ,
1584
1574
testparameters .GetL1ParamsForTesting ().BaseToken .Decimals ,
1585
1575
)
@@ -1591,26 +1581,6 @@ func TestSolidityTransferBaseTokens(t *testing.T) {
1591
1581
require .Error (t , err )
1592
1582
env .Chain .AssertL2BaseTokens (someEthereumAgentID , 1 * isc .Million )
1593
1583
1594
- {
1595
- // try sending a value to too high precision (anything over the 6 decimals will be ignored)
1596
- _ , err = iscTest .CallFn ([]ethCallOptions {{
1597
- sender : ethKey ,
1598
- value : oneMillionInEthDecimals ,
1599
- // wei is expressed with 18 decimal precision, iota/smr is 6, so anything in the 12 last decimal cases will be ignored
1600
- }}, "sendTo" , someEthereumAddr , big .NewInt (1_000_000_999_999_999_999 ))
1601
- require .Error (t , err )
1602
- env .Chain .AssertL2BaseTokens (someEthereumAgentID , 1 * isc .Million )
1603
- // this will fail if the (ignored) decimals are above the contract balance,
1604
- // but if we provide enough funds, the call should succeed and the extra decimals should be correctly ignored
1605
- _ , err = iscTest .CallFn ([]ethCallOptions {{
1606
- sender : ethKey ,
1607
- value : twoMillionInEthDecimals ,
1608
- // wei is expressed with 18 decimal precision, iota/smr is 6, so anything in the 12 last decimal cases will be ignored
1609
- }}, "sendTo" , someEthereumAddr , big .NewInt (1_000_000_999_999_999_999 ))
1610
- require .NoError (t , err )
1611
- env .Chain .AssertL2BaseTokens (someEthereumAgentID , 2 * isc .Million )
1612
- }
1613
-
1614
1584
// fund the contract via a L1 wallet ISC transfer, then call `sendTo` to use those funds
1615
1585
l1Wallet , _ := env .Chain .Env .NewKeyPairWithFunds ()
1616
1586
env .Chain .TransferAllowanceTo (
@@ -1619,7 +1589,7 @@ func TestSolidityTransferBaseTokens(t *testing.T) {
1619
1589
l1Wallet ,
1620
1590
)
1621
1591
1622
- tenMillionInEthDecimals := util .BaseTokensDecimalsToEthereumDecimals (
1592
+ tenMillionInEthDecimals := util .MustBaseTokensDecimalsToEthereumDecimalsExact (
1623
1593
10 * isc .Million ,
1624
1594
testparameters .GetL1ParamsForTesting ().BaseToken .Decimals ,
1625
1595
)
@@ -1628,7 +1598,7 @@ func TestSolidityTransferBaseTokens(t *testing.T) {
1628
1598
sender : ethKey ,
1629
1599
}}, "sendTo" , someEthereumAddr , tenMillionInEthDecimals )
1630
1600
require .NoError (t , err )
1631
- env .Chain .AssertL2BaseTokens (someEthereumAgentID , 12 * isc .Million )
1601
+ env .Chain .AssertL2BaseTokens (someEthereumAgentID , 11 * isc .Million )
1632
1602
1633
1603
// send more than the balance
1634
1604
_ , err = iscTest .CallFn ([]ethCallOptions {{
@@ -1637,7 +1607,7 @@ func TestSolidityTransferBaseTokens(t *testing.T) {
1637
1607
gasLimit : 100_000 , // provide a gas limit value as the estimation will fail
1638
1608
}}, "sendTo" , someEthereumAddr , big .NewInt (0 ))
1639
1609
require .Error (t , err )
1640
- env .Chain .AssertL2BaseTokens (someEthereumAgentID , 12 * isc .Million )
1610
+ env .Chain .AssertL2BaseTokens (someEthereumAgentID , 11 * isc .Million )
1641
1611
}
1642
1612
1643
1613
func TestSendEntireBalance (t * testing.T ) {
@@ -1649,7 +1619,7 @@ func TestSendEntireBalance(t *testing.T) {
1649
1619
// send all initial
1650
1620
initial := env .Chain .L2BaseTokens (isc .NewEthereumAddressAgentID (env .Chain .ChainID , ethAddr ))
1651
1621
// try sending funds to `someEthereumAddr` by sending a "value tx"
1652
- initialBalanceInEthDecimals := util .BaseTokensDecimalsToEthereumDecimals (
1622
+ initialBalanceInEthDecimals := util .MustBaseTokensDecimalsToEthereumDecimalsExact (
1653
1623
initial ,
1654
1624
testparameters .GetL1ParamsForTesting ().BaseToken .Decimals ,
1655
1625
)
@@ -1669,7 +1639,7 @@ func TestSendEntireBalance(t *testing.T) {
1669
1639
// now try sending all balance, minus the funds needed for gas
1670
1640
currentBalance := env .Chain .L2BaseTokens (isc .NewEthereumAddressAgentID (env .Chain .ChainID , ethAddr ))
1671
1641
1672
- currentBalanceInEthDecimals := util .BaseTokensDecimalsToEthereumDecimals (
1642
+ currentBalanceInEthDecimals := util .MustBaseTokensDecimalsToEthereumDecimalsExact (
1673
1643
currentBalance ,
1674
1644
testparameters .GetL1ParamsForTesting ().BaseToken .Decimals ,
1675
1645
)
@@ -1687,7 +1657,7 @@ func TestSendEntireBalance(t *testing.T) {
1687
1657
1688
1658
gasLimit := feePolicy .GasBudgetFromTokens (tokensForGasBudget )
1689
1659
1690
- valueToSendInEthDecimals := util .BaseTokensDecimalsToEthereumDecimals (
1660
+ valueToSendInEthDecimals := util .MustBaseTokensDecimalsToEthereumDecimalsExact (
1691
1661
currentBalance - tokensForGasBudget ,
1692
1662
testparameters .GetL1ParamsForTesting ().BaseToken .Decimals ,
1693
1663
)
@@ -2082,7 +2052,7 @@ func TestL1DepositEVM(t *testing.T) {
2082
2052
require .ErrorIs (t , err , io .EOF )
2083
2053
2084
2054
require .EqualValues (t ,
2085
- util .EthereumDecimalsToBaseTokenDecimals (bal , parameters .L1 ().BaseToken .Decimals ),
2055
+ util .MustEthereumDecimalsToBaseTokenDecimalsExact (bal , parameters .L1 ().BaseToken .Decimals ),
2086
2056
assets .BaseTokens )
2087
2057
2088
2058
evmRec := env .Chain .EVM ().TransactionReceipt (tx .Hash ())
@@ -2093,3 +2063,28 @@ func TestL1DepositEVM(t *testing.T) {
2093
2063
expectedGas := gas .ISCGasBudgetToEVM (iscRec .GasBurned , & feePolicy .EVMGasRatio )
2094
2064
require .EqualValues (t , expectedGas , evmRec .GasUsed )
2095
2065
}
2066
+
2067
+ func TestDecimalsConversion (t * testing.T ) {
2068
+ parameters .InitL1 (parameters .L1ForTesting )
2069
+ env := InitEVM (t )
2070
+ ethKey , _ := env .Chain .NewEthereumAccountWithL2Funds ()
2071
+ iscTest := env .deployISCTestContract (ethKey )
2072
+
2073
+ // call any function including 999999999999 wei as value (which is just 1 wei short of 1 base token)
2074
+ lessThanOneSMR := new (big.Int ).SetUint64 (999999999999 )
2075
+ valueInBaseTokens , remainder := util .EthereumDecimalsToBaseTokenDecimals (
2076
+ lessThanOneSMR ,
2077
+ parameters .L1 ().BaseToken .Decimals ,
2078
+ )
2079
+ t .Log (valueInBaseTokens )
2080
+ require .Zero (t , valueInBaseTokens )
2081
+ require .EqualValues (t , lessThanOneSMR .Uint64 (), remainder .Uint64 ())
2082
+
2083
+ _ , err := iscTest .CallFn (
2084
+ []ethCallOptions {{sender : ethKey , value : lessThanOneSMR , gasLimit : 100000 }},
2085
+ "sendTo" ,
2086
+ iscTest .address ,
2087
+ big .NewInt (0 ),
2088
+ )
2089
+ require .ErrorContains (t , err , "non-zero remainder" )
2090
+ }
0 commit comments