@@ -14,7 +14,9 @@ import (
1414 rippledata "github.com/rubblelabs/ripple/data"
1515 "github.com/stretchr/testify/require"
1616
17+ "github.com/CoreumFoundation/coreum/v3/pkg/client"
1718 coreumintegration "github.com/CoreumFoundation/coreum/v3/testutil/integration"
19+ assetfttypes "github.com/CoreumFoundation/coreum/v3/x/asset/ft/types"
1820 integrationtests "github.com/CoreumFoundation/coreumbridge-xrpl/integration-tests"
1921 "github.com/CoreumFoundation/coreumbridge-xrpl/relayer/coreum"
2022 "github.com/CoreumFoundation/coreumbridge-xrpl/relayer/xrpl"
@@ -203,3 +205,93 @@ func TestSendFromXRPLToCoreumWithTicketsReallocation(t *testing.T) {
203205 balance := runnerEnv .Chains .XRPL .GetAccountBalance (ctx , t , xrplRecipientAddress , xrplIssuerAddress , registeredXRPLCurrency )
204206 require .Equal (t , totalSent .Quo (sdkmath .NewIntWithDecimal (1 , XRPLTokenDecimals )).String (), balance .Value .String ())
205207}
208+
209+ func TestRegisterCoreumOriginatedTokenAndSendFromXRPLToCoreum (t * testing.T ) {
210+ t .Parallel ()
211+
212+ ctx , chains := integrationtests .NewTestingContext (t )
213+
214+ xrplRecipientAddress := chains .XRPL .GenAccount (ctx , t , 0 )
215+ t .Logf ("XRPL recipient address: %s" , xrplRecipientAddress )
216+
217+ coreumSenderAddress := chains .Coreum .GenAccount ()
218+ issueFee := chains .Coreum .QueryAssetFTParams (ctx , t ).IssueFee
219+ chains .Coreum .FundAccountWithOptions (ctx , t , coreumSenderAddress , coreumintegration.BalancesOptions {
220+ Amount : issueFee .Amount .Add (sdkmath .NewInt (10_000_000 )),
221+ })
222+
223+ // issue asset ft and register it
224+ sendingPrecision := int32 (2 )
225+ tokenDecimals := uint32 (4 )
226+ maxHoldingAmount , ok := sdk .NewIntFromString ("10000000000000000" )
227+ require .True (t , ok )
228+ issueMsg := & assetfttypes.MsgIssue {
229+ Issuer : coreumSenderAddress .String (),
230+ Symbol : "denom" ,
231+ Subunit : "denom" ,
232+ Precision : tokenDecimals , // token decimals in terms of the contract
233+ InitialAmount : maxHoldingAmount ,
234+ }
235+ _ , err := client .BroadcastTx (
236+ ctx ,
237+ chains .Coreum .ClientContext .WithFromAddress (coreumSenderAddress ),
238+ chains .Coreum .TxFactory ().WithSimulateAndExecute (true ),
239+ issueMsg ,
240+ )
241+ require .NoError (t , err )
242+
243+ envCfg := DefaultRunnerEnvConfig ()
244+ runnerEnv := NewRunnerEnv (ctx , t , envCfg , chains )
245+
246+ bridgeXRPLAccountInfo , err := chains .XRPL .RPCClient ().AccountInfo (ctx , runnerEnv .bridgeXRPLAddress )
247+ require .NoError (t , err )
248+
249+ // recover tickets so we can register tokens
250+ numberOfTicketsToAllocate := uint32 (200 )
251+ chains .XRPL .FundAccountForTicketAllocation (ctx , t , runnerEnv .bridgeXRPLAddress , numberOfTicketsToAllocate )
252+ _ , err = runnerEnv .ContractClient .RecoverTickets (ctx , runnerEnv .ContractOwner , * bridgeXRPLAccountInfo .AccountData .Sequence , & numberOfTicketsToAllocate )
253+ require .NoError (t , err )
254+
255+ // start relayers
256+ runnerEnv .StartAllRunnerProcesses (ctx , t )
257+ runnerEnv .AwaitNoPendingOperations (ctx , t )
258+ availableTickets , err := runnerEnv .ContractClient .GetAvailableTickets (ctx )
259+ require .NoError (t , err )
260+ require .Len (t , availableTickets , int (numberOfTicketsToAllocate ))
261+
262+ // register Coreum originated token
263+ require .NoError (t , err )
264+ denom := assetfttypes .BuildDenom (issueMsg .Subunit , coreumSenderAddress )
265+ _ , err = runnerEnv .ContractClient .RegisterCoreumToken (ctx , runnerEnv .ContractOwner , denom , tokenDecimals , sendingPrecision , maxHoldingAmount )
266+ require .NoError (t , err )
267+ registeredCoreumOriginatedToken , err := runnerEnv .ContractClient .GetCoreumTokenByDenom (ctx , denom )
268+ require .NoError (t , err )
269+
270+ // send TrustSet to be able to receive coins from the bridge
271+ xrplCurrency , err := rippledata .NewCurrency (registeredCoreumOriginatedToken .XRPLCurrency )
272+ require .NoError (t , err )
273+ runnerEnv .SendXRPLMaxTrustSetTx (ctx , t , xrplRecipientAddress , runnerEnv .bridgeXRPLAddress , xrplCurrency )
274+
275+ // equal to 11.1111 on XRPL, but with the sending prec 2 we expect 11.11 to be received
276+ amountToSend1 := sdkmath .NewInt (111111 )
277+ // TODO(dzmitryhil) update assertion once we add the final tx revert/recovery
278+ _ , err = runnerEnv .ContractClient .SendToXRPL (ctx , coreumSenderAddress , xrplRecipientAddress .String (), sdk .NewCoin (registeredCoreumOriginatedToken .Denom , amountToSend1 ))
279+ require .NoError (t , err )
280+
281+ runnerEnv .AwaitNoPendingOperations (ctx , t )
282+
283+ // check the XRPL recipient balance
284+ balance := runnerEnv .Chains .XRPL .GetAccountBalance (ctx , t , xrplRecipientAddress , runnerEnv .bridgeXRPLAddress , xrplCurrency )
285+ require .Equal (t , "11.11" , balance .Value .String ())
286+
287+ amountToSend2 := maxHoldingAmount .QuoRaw (2 )
288+ require .NoError (t , err )
289+ _ , err = runnerEnv .ContractClient .SendToXRPL (ctx , coreumSenderAddress , xrplRecipientAddress .String (), sdk .NewCoin (registeredCoreumOriginatedToken .Denom , amountToSend2 ))
290+ require .NoError (t , err )
291+
292+ runnerEnv .AwaitNoPendingOperations (ctx , t )
293+
294+ // check the XRPL recipient balance
295+ balance = runnerEnv .Chains .XRPL .GetAccountBalance (ctx , t , xrplRecipientAddress , runnerEnv .bridgeXRPLAddress , xrplCurrency )
296+ require .Equal (t , "50000000001111e-2" , balance .Value .String ())
297+ }
0 commit comments