diff --git a/contract/src/contract.rs b/contract/src/contract.rs index a8b70100..33c973fc 100644 --- a/contract/src/contract.rs +++ b/contract/src/contract.rs @@ -277,7 +277,7 @@ fn register_coreum_token( .to_string() .to_lowercase(); - // Format will be the hex representation in XRPL of the string coreum + // Format will be the hex representation in XRPL of the string coreum in uppercase let xrpl_currency = convert_currency_to_xrpl_hexadecimal(format!("{}{}", COREUM_CURRENCY_PREFIX, hex_string)); @@ -799,11 +799,8 @@ fn send_to_xrpl( amount_after_transfer_fees(amount_after_bridge_fees, xrpl_token.transfer_rate)?; // We don't need any decimal conversion because the token is an XRPL originated token and they are issued with same decimals - (amount_to_send, remainder) = truncate_amount( - xrpl_token.sending_precision, - decimals, - amount_after_fees, - )?; + (amount_to_send, remainder) = + truncate_amount(xrpl_token.sending_precision, decimals, amount_after_fees)?; handle_fee_collection( deps.storage, @@ -1002,11 +999,26 @@ pub fn validate_xrpl_issuer_and_currency( ) -> Result<(), ContractError> { validate_xrpl_address(issuer).map_err(|_| ContractError::InvalidXRPLIssuer {})?; - // We check that currency is either a standard 3 character currency or it's a 40 character hex string currency - if !(currency.len() == 3 && currency.is_ascii() - || currency.len() == 40 && currency.chars().all(|c| c.is_ascii_hexdigit())) - { - return Err(ContractError::InvalidXRPLCurrency {}); + // We check that currency is either a standard 3 character currency or it's a 40 character hex string currency, any other scenario is invalid + match currency.len() { + 3 => { + if !currency.is_ascii() { + return Err(ContractError::InvalidXRPLCurrency {}); + } + + if currency == "XRP" { + return Err(ContractError::InvalidXRPLCurrency {}); + } + } + 40 => { + if !currency + .chars() + .all(|c| c.is_ascii_hexdigit() && (c.is_numeric() || c.is_uppercase())) + { + return Err(ContractError::InvalidXRPLCurrency {}); + } + } + _ => return Err(ContractError::InvalidXRPLCurrency {}), } Ok(()) @@ -1124,5 +1136,5 @@ fn is_token_xrp(issuer: String, currency: String) -> bool { fn convert_currency_to_xrpl_hexadecimal(currency: String) -> String { // Fill with zeros to get the correct hex representation in XRPL of our currency. - format!("{:0<40}", hex::encode(currency)) + format!("{:0<40}", hex::encode(currency)).to_uppercase() } diff --git a/contract/src/evidence.rs b/contract/src/evidence.rs index 1f430fb7..0ff6eeb4 100644 --- a/contract/src/evidence.rs +++ b/contract/src/evidence.rs @@ -85,7 +85,7 @@ impl Evidence { Evidence::XRPLToCoreumTransfer { tx_hash, .. } => tx_hash.clone(), Evidence::XRPLTransactionResult { tx_hash, .. } => tx_hash.clone().unwrap(), } - .to_lowercase() + .to_uppercase() } pub fn is_operation_valid(&self) -> bool { match self { diff --git a/contract/src/operation.rs b/contract/src/operation.rs index eabb0c4f..8d3e39e0 100644 --- a/contract/src/operation.rs +++ b/contract/src/operation.rs @@ -125,7 +125,10 @@ pub fn handle_coreum_to_xrpl_transfer_confirmation( // If transaction was accepted and the token that was sent back was an XRPL originated token, we must burn the token amount and transfer_fee if transaction_result.eq(&TransactionResult::Accepted) { let burn_msg = CosmosMsg::from(CoreumMsg::AssetFT(assetft::Msg::Burn { - coin: coin(amount.checked_add(transfer_fee)?.u128(), xrpl_token.coreum_denom), + coin: coin( + amount.checked_add(transfer_fee)?.u128(), + xrpl_token.coreum_denom, + ), })); *response = response.to_owned().add_message(burn_msg); @@ -133,7 +136,10 @@ pub fn handle_coreum_to_xrpl_transfer_confirmation( // If transaction was rejected, we must send the token amount and transfer_fee back to the user let send_msg = BankMsg::Send { to_address: sender.to_string(), - amount: coins(amount.checked_add(transfer_fee)?.u128(), xrpl_token.coreum_denom), + amount: coins( + amount.checked_add(transfer_fee)?.u128(), + xrpl_token.coreum_denom, + ), }; *response = response.to_owned().add_message(send_msg); diff --git a/contract/src/tests.rs b/contract/src/tests.rs index 6d0760f0..2352d5ce 100644 --- a/contract/src/tests.rs +++ b/contract/src/tests.rs @@ -697,6 +697,14 @@ mod tests { assert_eq!(query_coreum_tokens.tokens.len(), 2); assert_eq!(query_coreum_tokens.tokens[0].denom, test_tokens[0].denom); assert_eq!(query_coreum_tokens.tokens[1].denom, test_tokens[1].denom); + assert_eq!( + query_coreum_tokens.tokens[0].xrpl_currency, + query_coreum_tokens.tokens[0].xrpl_currency.to_uppercase() + ); + assert_eq!( + query_coreum_tokens.tokens[1].xrpl_currency, + query_coreum_tokens.tokens[1].xrpl_currency.to_uppercase() + ); // Query tokens with limit let query_coreum_tokens = wasm @@ -859,6 +867,48 @@ mod tests { .to_string() .contains(ContractError::InvalidXRPLCurrency {}.to_string().as_str())); + // Registering a token with an invalid hexadecimal currency (not uppercase) should fail + let currency_error = wasm + .execute::( + &contract_addr, + &ExecuteMsg::RegisterXRPLToken { + issuer: test_tokens[1].issuer.clone(), + currency: "015841551A748AD2C1f76FF6ECB0CCCD00000000".to_string(), + sending_precision: test_tokens[1].sending_precision.clone(), + max_holding_amount: test_tokens[1].max_holding_amount.clone(), + bridging_fee: test_tokens[1].bridging_fee, + transfer_rate: test_tokens[0].transfer_rate, + }, + &query_issue_fee(&asset_ft), + &signer, + ) + .unwrap_err(); + + assert!(currency_error + .to_string() + .contains(ContractError::InvalidXRPLCurrency {}.to_string().as_str())); + + // Registering a token with an "XRP" as currency should fail + let currency_error = wasm + .execute::( + &contract_addr, + &ExecuteMsg::RegisterXRPLToken { + issuer: test_tokens[1].issuer.clone(), + currency: "XRP".to_string(), + sending_precision: test_tokens[1].sending_precision.clone(), + max_holding_amount: test_tokens[1].max_holding_amount.clone(), + bridging_fee: test_tokens[1].bridging_fee, + transfer_rate: test_tokens[0].transfer_rate, + }, + &query_issue_fee(&asset_ft), + &signer, + ) + .unwrap_err(); + + assert!(currency_error + .to_string() + .contains(ContractError::InvalidXRPLCurrency {}.to_string().as_str())); + // Registering a token with an invalid transfer_rate should fail. let transfer_rate_error = wasm .execute::( diff --git a/integration-tests/coreum/contract_client_test.go b/integration-tests/coreum/contract_client_test.go index 662237c9..e920d366 100644 --- a/integration-tests/coreum/contract_client_test.go +++ b/integration-tests/coreum/contract_client_test.go @@ -275,7 +275,9 @@ func TestRegisterCoreumToken(t *testing.T) { require.NoError(t, chains.XRPL.AutoFillSignAndSubmitTx(ctx, t, &paymentTx, issuerAcc)) balancesAfterSend := chains.XRPL.GetAccountBalances(ctx, t, recipientAcc) t.Logf("Recipient account balances after send: %s", balancesAfterSend) - receiveAmount, ok := balancesAfterSend[fmt.Sprintf("%s/%s", currency.String(), issuerAcc.String())] + receiveAmount, ok := balancesAfterSend[fmt.Sprintf("%s/%s", + xrpl.ConvertCurrencyToString(currency), issuerAcc.String(), + )] require.True(t, ok) require.Equal(t, amountToSend.String(), receiveAmount.Value.String()) } @@ -842,13 +844,13 @@ func TestSendFromXRPLToCoreumXRPToken(t *testing.T) { registeredXRPToken, err := contractClient.GetXRPLTokenByIssuerAndCurrency( ctx, xrpl.XRPTokenIssuer.String(), - xrpl.XRPTokenCurrency.String(), + xrpl.ConvertCurrencyToString(xrpl.XRPTokenCurrency), ) require.NoError(t, err) require.Equal(t, coreum.XRPLToken{ Issuer: xrpl.XRPTokenIssuer.String(), - Currency: xrpl.XRPTokenCurrency.String(), + Currency: xrpl.ConvertCurrencyToString(xrpl.XRPTokenCurrency), CoreumDenom: assetfttypes.BuildDenom("drop", contractClient.GetContractAddress()), SendingPrecision: 6, MaxHoldingAmount: sdkmath.NewInt(10000000000000000), @@ -2135,7 +2137,7 @@ func TestSendFromCoreumToXRPLXRPToken(t *testing.T) { xrpl.GenPrivKeyTxSigner().Account().String(), ) registeredXRPToken, err := contractClient.GetXRPLTokenByIssuerAndCurrency( - ctx, xrpl.XRPTokenIssuer.String(), xrpl.XRPTokenCurrency.String(), + ctx, xrpl.XRPTokenIssuer.String(), xrpl.ConvertCurrencyToString(xrpl.XRPTokenCurrency), ) require.NoError(t, err) @@ -3008,5 +3010,5 @@ func genXRPLTxHash(t *testing.T) string { _, err := rand.Read(hash[:]) require.NoError(t, err) - return hash.String() + return strings.ToUpper(hash.String()) } diff --git a/integration-tests/processes/send_test.go b/integration-tests/processes/send_test.go index 7e2199cc..e7e8f83f 100644 --- a/integration-tests/processes/send_test.go +++ b/integration-tests/processes/send_test.go @@ -153,7 +153,7 @@ func TestSendXRPTokenFromXRPLToCoreumAndBack(t *testing.T) { t.Logf("XRPL sender: %s", xrplSenderAddress.String()) registeredXRPToken, err := runnerEnv.ContractClient.GetXRPLTokenByIssuerAndCurrency( - ctx, xrpl.XRPTokenIssuer.String(), xrpl.XRPTokenCurrency.String(), + ctx, xrpl.XRPTokenIssuer.String(), xrpl.ConvertCurrencyToString(xrpl.XRPTokenCurrency), ) require.NoError(t, err) @@ -603,7 +603,7 @@ func TestRecoverXRPLOriginatedTokenRegistrationAndSendFromXRPLToCoreumAndBack(t runnerEnv.Chains.XRPL.CreateAccount(ctx, t, xrplIssuerAddress, 1) // recover from owner _, err = runnerEnv.ContractClient.RecoverXRPLTokenRegistration( - ctx, runnerEnv.ContractOwner, xrplIssuerAddress.String(), registeredXRPLCurrency.String(), + ctx, runnerEnv.ContractOwner, xrplIssuerAddress.String(), xrpl.ConvertCurrencyToString(registeredXRPLCurrency), ) require.NoError(t, err) runnerEnv.AwaitNoPendingOperations(ctx, t) diff --git a/integration-tests/xrpl.go b/integration-tests/xrpl.go index 8ddf7583..55dd5092 100644 --- a/integration-tests/xrpl.go +++ b/integration-tests/xrpl.go @@ -232,7 +232,8 @@ func (c XRPLChain) AutoFillTx(ctx context.Context, t *testing.T, tx rippledata.T func (c XRPLChain) GetAccountBalance( ctx context.Context, t *testing.T, account, issuer rippledata.Account, currency rippledata.Currency, ) rippledata.Amount { - balance, ok := c.GetAccountBalances(ctx, t, account)[fmt.Sprintf("%s/%s", currency.String(), issuer.String())] + balance, ok := c.GetAccountBalances(ctx, t, account)[fmt.Sprintf("%s/%s", + xrpl.ConvertCurrencyToString(currency), issuer.String())] if !ok { // equal to zero return rippledata.Amount{ @@ -254,7 +255,9 @@ func (c XRPLChain) GetAccountBalances( accInfo, err := c.rpcClient.AccountInfo(ctx, acc) require.NoError(t, err) - amounts[fmt.Sprintf("%s/%s", xrpl.XRPTokenCurrency.String(), xrpl.XRPTokenIssuer.String())] = rippledata.Amount{ + amounts[fmt.Sprintf( + "%s/%s", + xrpl.ConvertCurrencyToString(xrpl.XRPTokenCurrency), xrpl.XRPTokenIssuer.String())] = rippledata.Amount{ Value: accInfo.AccountData.Balance, } // none xrp amounts @@ -263,7 +266,9 @@ func (c XRPLChain) GetAccountBalances( for _, line := range accLines.Lines { lineCopy := line - amounts[fmt.Sprintf("%s/%s", lineCopy.Currency.String(), lineCopy.Account.String())] = rippledata.Amount{ + amounts[fmt.Sprintf( + "%s/%s", + xrpl.ConvertCurrencyToString(lineCopy.Currency), lineCopy.Account.String())] = rippledata.Amount{ Value: &lineCopy.Balance.Value, Currency: lineCopy.Currency, Issuer: lineCopy.Account, diff --git a/integration-tests/xrpl/rpc_test.go b/integration-tests/xrpl/rpc_test.go index 2591ee0a..d70e9637 100644 --- a/integration-tests/xrpl/rpc_test.go +++ b/integration-tests/xrpl/rpc_test.go @@ -6,6 +6,7 @@ package xrpl_test import ( "context" "fmt" + "strings" "testing" rippledata "github.com/rubblelabs/ripple/data" @@ -13,6 +14,7 @@ import ( "github.com/stretchr/testify/require" integrationtests "github.com/CoreumFoundation/coreumbridge-xrpl/integration-tests" + "github.com/CoreumFoundation/coreumbridge-xrpl/relayer/xrpl" ) func TestXRPAndIssuedTokensPayment(t *testing.T) { @@ -146,7 +148,7 @@ func TestMultisigPayment(t *testing.T) { // compare hashes t.Logf("TwoSignersHash/ThreeSignersHash: %s/%s", xrpPaymentTxTwoSigners.Hash, xrpPaymentTxThreeSigners.Hash) - require.NotEqual(t, xrpPaymentTxTwoSigners.Hash.String(), xrpPaymentTxThreeSigners.Hash.String()) + require.NotEqual(t, strings.ToUpper(xrpPaymentTxTwoSigners.GetHash().String()), xrpPaymentTxThreeSigners.Hash.String()) t.Logf( "Recipient account balance before: %s", @@ -865,8 +867,8 @@ func getBalanceAccount( currency rippledata.Currency, ) string { t.Helper() - issuerCurrencyKey := fmt.Sprintf("%s/%s", currency.String(), issuer.String()) - balance, ok := xrplChain.GetAccountBalances(ctx, t, acc)[issuerCurrencyKey] + currencyIssuerKey := fmt.Sprintf("%s/%s", xrpl.ConvertCurrencyToString(currency), issuer.String()) + balance, ok := xrplChain.GetAccountBalances(ctx, t, acc)[currencyIssuerKey] if !ok { return "0" } diff --git a/integration-tests/xrpl/scanner_test.go b/integration-tests/xrpl/scanner_test.go index 2d38db6c..6b697102 100644 --- a/integration-tests/xrpl/scanner_test.go +++ b/integration-tests/xrpl/scanner_test.go @@ -5,6 +5,7 @@ package xrpl_test import ( "context" + "strings" "testing" "time" @@ -121,7 +122,7 @@ func TestRecentHistoryScanAccountTx(t *testing.T) { spawn("wait", parallel.Exit, func(ctx context.Context) error { t.Logf("Waiting for %d transactions to be scanned by the scanner", txsCount) for tx := range txsCh { - receivedTxHashes[tx.GetHash().String()] = struct{}{} + receivedTxHashes[strings.ToUpper(tx.GetHash().String())] = struct{}{} if len(receivedTxHashes) == txsCount { return nil } @@ -156,11 +157,11 @@ func sendMultipleTxs( err = xrplChain.AutoFillSignAndSubmitTx(ctx, t, &xrpPaymentTx, senderAcc) if errors.Is(err, context.Canceled) { // we add the hash here since we cancel the context once we read it - writtenTxHashes[xrpPaymentTx.Hash.String()] = struct{}{} + writtenTxHashes[strings.ToUpper(xrpPaymentTx.GetHash().String())] = struct{}{} return writtenTxHashes } require.NoError(t, err) - writtenTxHashes[xrpPaymentTx.Hash.String()] = struct{}{} + writtenTxHashes[strings.ToUpper(xrpPaymentTx.GetHash().String())] = struct{}{} } t.Logf("Successfully sent %d transactions", len(writtenTxHashes)) return writtenTxHashes @@ -182,7 +183,7 @@ func validateTxsHashesInChannel( return scanCtx.Err() case tx := <-txsCh: // validate that we have all sent hashed and no duplicated - hash := tx.GetHash().String() + hash := strings.ToUpper(tx.GetHash().String()) if _, found := expectedHashes[hash]; !found { return errors.Errorf("not found expected tx hash:%s", hash) } diff --git a/relayer/processes/amount.go b/relayer/processes/amount.go index 73c6fc1c..5802579c 100644 --- a/relayer/processes/amount.go +++ b/relayer/processes/amount.go @@ -121,5 +121,5 @@ func convertCoreumAmountToXRPLAmountWithDecimals( } func isXRPToken(issuer, currency string) bool { - return issuer == xrpl.XRPTokenIssuer.String() && currency == xrpl.XRPTokenCurrency.String() + return issuer == xrpl.XRPTokenIssuer.String() && currency == xrpl.ConvertCurrencyToString(xrpl.XRPTokenCurrency) } diff --git a/relayer/processes/amount_test.go b/relayer/processes/amount_test.go index 28a9cbcd..5392931e 100644 --- a/relayer/processes/amount_test.go +++ b/relayer/processes/amount_test.go @@ -112,28 +112,28 @@ func TestConvertXRPLOriginatedTokenCoreumAmountToXRPLAmount(t *testing.T) { name: "one_coreum_XRP_to_XRPL_XRP", coreumAmount: sdkmath.NewIntFromUint64(1_000_000), issuer: xrpl.XRPTokenIssuer.String(), - currency: xrpl.XRPTokenCurrency.String(), + currency: xrpl.ConvertCurrencyToString(xrpl.XRPTokenCurrency), want: amountStringToXRPLAmount(t, "1.0XRP"), }, { name: "one_with_some_decimals_coreum_XRP_to_XRPL_XRP", coreumAmount: sdkmath.NewIntFromUint64(1000100), issuer: xrpl.XRPTokenIssuer.String(), - currency: xrpl.XRPTokenCurrency.String(), + currency: xrpl.ConvertCurrencyToString(xrpl.XRPTokenCurrency), want: amountStringToXRPLAmount(t, "1.0001XRP"), }, { name: "min_decimals_coreum_XRP_to_XRPL_XRP", coreumAmount: sdkmath.NewIntFromUint64(999000001), issuer: xrpl.XRPTokenIssuer.String(), - currency: xrpl.XRPTokenCurrency.String(), + currency: xrpl.ConvertCurrencyToString(xrpl.XRPTokenCurrency), want: amountStringToXRPLAmount(t, "999.000001XRP"), }, { name: "high_value_coreum_XRP_to_XRPL_XRP", coreumAmount: sdkmath.NewIntFromUint64(1000000000000001), issuer: xrpl.XRPTokenIssuer.String(), - currency: xrpl.XRPTokenCurrency.String(), + currency: xrpl.ConvertCurrencyToString(xrpl.XRPTokenCurrency), want: amountStringToXRPLAmount(t, "1000000000.000001XRP"), }, { diff --git a/relayer/processes/xrpl_tx_observer.go b/relayer/processes/xrpl_tx_observer.go index 373f6327..ca655a04 100644 --- a/relayer/processes/xrpl_tx_observer.go +++ b/relayer/processes/xrpl_tx_observer.go @@ -74,7 +74,7 @@ func (o *XRPLTxObserver) Start(ctx context.Context) error { if errors.Is(err, context.Canceled) { o.log.Warn(ctx, "Context canceled during the XRPL tx processing", zap.String("error", err.Error())) } else { - return errors.Wrapf(err, "failed to process XRPL tx, txHash:%s", tx.GetHash().String()) + return errors.Wrapf(err, "failed to process XRPL tx, txHash:%s", strings.ToUpper(tx.GetHash().String())) } } } @@ -86,7 +86,7 @@ func (o *XRPLTxObserver) Start(ctx context.Context) error { } func (o *XRPLTxObserver) processTx(ctx context.Context, tx rippledata.TransactionWithMetaData) error { - ctx = tracing.WithTracingXRPLTxHash(tracing.WithTracingID(ctx), tx.GetHash().String()) + ctx = tracing.WithTracingXRPLTxHash(tracing.WithTracingID(ctx), strings.ToUpper(tx.GetHash().String())) if !txIsFinal(tx) { o.log.Debug(ctx, "Transaction is not final", zap.String("txStatus", tx.MetaData.TransactionResult.String())) return nil @@ -128,8 +128,6 @@ func (o *XRPLTxObserver) processIncomingTx(ctx context.Context, tx rippledata.Tr deliveredXRPLAmount := tx.MetaData.DeliveredAmount - stringCurrency := xrpl.ConvertCurrencyToString(deliveredXRPLAmount.Currency) - coreumAmount, err := ConvertXRPLAmountToCoreumAmount(*deliveredXRPLAmount) if err != nil { return err @@ -141,9 +139,9 @@ func (o *XRPLTxObserver) processIncomingTx(ctx context.Context, tx rippledata.Tr } evidence := coreum.XRPLToCoreumTransferEvidence{ - TxHash: paymentTx.GetHash().String(), + TxHash: strings.ToUpper(paymentTx.GetHash().String()), Issuer: deliveredXRPLAmount.Issuer.String(), - Currency: stringCurrency, + Currency: xrpl.ConvertCurrencyToString(deliveredXRPLAmount.Currency), Amount: coreumAmount, Recipient: coreumRecipient, } @@ -206,7 +204,7 @@ func (o *XRPLTxObserver) sendXRPLTicketsAllocationTransactionResultEvidence( } evidence := coreum.XRPLTransactionResultTicketsAllocationEvidence{ XRPLTransactionResultEvidence: coreum.XRPLTransactionResultEvidence{ - TxHash: tx.GetHash().String(), + TxHash: strings.ToUpper(tx.GetHash().String()), TransactionResult: txResult, }, Tickets: tickets, @@ -240,7 +238,7 @@ func (o *XRPLTxObserver) sendXRPLTrustSetTransactionResultEvidence( } evidence := coreum.XRPLTransactionResultTrustSetEvidence{ XRPLTransactionResultEvidence: coreum.XRPLTransactionResultEvidence{ - TxHash: tx.GetHash().String(), + TxHash: strings.ToUpper(tx.GetHash().String()), TransactionResult: getTransactionResult(tx), TicketSequence: trustSetTx.TicketSequence, }, @@ -267,7 +265,7 @@ func (o *XRPLTxObserver) sendCoreumToXRPLTransferTransactionResultEvidence( } evidence := coreum.XRPLTransactionResultCoreumToXRPLTransferEvidence{ XRPLTransactionResultEvidence: coreum.XRPLTransactionResultEvidence{ - TxHash: tx.GetHash().String(), + TxHash: strings.ToUpper(tx.GetHash().String()), TransactionResult: getTransactionResult(tx), TicketSequence: paymentTx.TicketSequence, }, diff --git a/relayer/processes/xrpl_tx_observer_test.go b/relayer/processes/xrpl_tx_observer_test.go index 2ded0045..559d5172 100644 --- a/relayer/processes/xrpl_tx_observer_test.go +++ b/relayer/processes/xrpl_tx_observer_test.go @@ -116,7 +116,7 @@ func TestXRPLTxObserver_Start(t *testing.T) { coreum.XRPLToCoreumTransferEvidence{ TxHash: rippledata.Hash256{}.String(), Issuer: xrplOriginatedTokenXRPLAmount.Issuer.String(), - Currency: xrplOriginatedTokenXRPLAmount.Currency.String(), + Currency: xrpl.ConvertCurrencyToString(xrplOriginatedTokenXRPLAmount.Currency), Amount: sdkmath.NewIntWithDecimal(999, xrpl.XRPLIssuedTokenDecimals), Recipient: coreumRecipientAddress, }, diff --git a/relayer/processes/xrpl_tx_submitter.go b/relayer/processes/xrpl_tx_submitter.go index 0fe9fe3e..cd3f140e 100644 --- a/relayer/processes/xrpl_tx_submitter.go +++ b/relayer/processes/xrpl_tx_submitter.go @@ -2,6 +2,7 @@ package processes import ( "context" + "strings" "time" sdk "github.com/cosmos/cosmos-sdk/types" @@ -232,33 +233,41 @@ func (s *XRPLTxSubmitter) signOrSubmitOperation( return errors.Wrapf(err, "failed to submit transaction:%+v", tx) } if txRes.EngineResult.Success() { - s.log.Info(ctx, "Transaction has been successfully submitted", zap.String("txHash", tx.GetHash().String())) + s.log.Info( + ctx, + "Transaction has been successfully submitted", + zap.String("txHash", strings.ToUpper(tx.GetHash().String())), + ) return nil } switch txRes.EngineResult.String() { case xrpl.TefNOTicketTxResult, xrpl.TefPastSeqTxResult: - s.log.Debug(ctx, "Transaction has been already submitted", zap.String("txHash", tx.GetHash().String())) + s.log.Debug( + ctx, + "Transaction has been already submitted", + zap.String("txHash", strings.ToUpper(tx.GetHash().String())), + ) return nil case xrpl.TecPathDryTxResult: //nolint:lll // breaking down the log line will make it less readable. s.log.Info( ctx, "The transaction has been sent, but will be reverted since the provided path does not have enough liquidity or the receipt doesn't link by trust lines.", - zap.String("txHash", tx.GetHash().String())) + zap.String("txHash", strings.ToUpper(tx.GetHash().String()))) return nil case xrpl.TecNoDstTxResult: s.log.Info( ctx, "The transaction has been sent, but will be reverted since account used in the transaction doesn't exist.", - zap.String("txHash", tx.GetHash().String())) + zap.String("txHash", strings.ToUpper(tx.GetHash().String()))) return nil case xrpl.TecInsufficientReserveTxResult: // for that case the tx will be accepted by the node and its rejection will be handled in the observer s.log.Error( ctx, "Insufficient reserve to complete the operation", - zap.String("txHash", tx.GetHash().String()), + zap.String("txHash", strings.ToUpper(tx.GetHash().String())), ) return nil default: diff --git a/relayer/xrpl/constatns_test.go b/relayer/xrpl/constatns_test.go index fb98cd17..6f16b033 100644 --- a/relayer/xrpl/constatns_test.go +++ b/relayer/xrpl/constatns_test.go @@ -11,5 +11,5 @@ import ( func TestXRP_ConstantsStringer(t *testing.T) { require.Equal(t, crypto.ACCOUNT_ZERO, xrpl.XRPTokenIssuer.String()) - require.Equal(t, "XRP", xrpl.XRPTokenCurrency.String()) + require.Equal(t, "XRP", xrpl.ConvertCurrencyToString(xrpl.XRPTokenCurrency)) } diff --git a/relayer/xrpl/currency.go b/relayer/xrpl/currency.go index 936472cf..7f227830 100644 --- a/relayer/xrpl/currency.go +++ b/relayer/xrpl/currency.go @@ -16,5 +16,5 @@ func ConvertCurrencyToString(currency rippledata.Currency) string { hexString := hex.EncodeToString([]byte(currencyString)) // append tailing zeros to match the contract expectation hexString += strings.Repeat("0", 40-len(hexString)) - return hexString + return strings.ToUpper(hexString) } diff --git a/relayer/xrpl/currency_test.go b/relayer/xrpl/currency_test.go index a18d9c07..f40a5122 100644 --- a/relayer/xrpl/currency_test.go +++ b/relayer/xrpl/currency_test.go @@ -20,19 +20,29 @@ func TestConvertCurrencyToString(t *testing.T) { want string }{ { - name: "short_currency", + name: "XRP_currency", + currency: xrpl.XRPTokenCurrency, + want: "XRP", + }, + { + name: "short_currency_lower", + currency: mustCurrency(t, "abc"), + want: "abc", + }, + { + name: "short_currency_upper", currency: mustCurrency(t, "ABC"), want: "ABC", }, { name: "hex_full_length_currency", currency: mustCurrency(t, hex.EncodeToString([]byte(strings.Repeat("Z", 20)))), - want: "5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a", + want: "5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A", }, { name: "tailing_zero_currency", currency: mustCurrency(t, "636f7265756d3939663062653133663900000000"), - want: "636f7265756d3939663062653133663900000000", + want: "636F7265756D3939663062653133663900000000", }, } for _, tt := range tests { diff --git a/relayer/xrpl/rpc.go b/relayer/xrpl/rpc.go index 850294de..6d179272 100644 --- a/relayer/xrpl/rpc.go +++ b/relayer/xrpl/rpc.go @@ -346,7 +346,7 @@ func (c *RPCClient) AutoFillTx(ctx context.Context, tx rippledata.Transaction, s // SubmitAndAwaitSuccess submits tx a waits for its result, if result is not success returns an error. func (c *RPCClient) SubmitAndAwaitSuccess(ctx context.Context, tx rippledata.Transaction) error { - c.log.Info(ctx, "Submitting transaction", zap.String("txHash", tx.GetHash().String())) + c.log.Info(ctx, "Submitting transaction", zap.String("txHash", strings.ToUpper(tx.GetHash().String()))) // submit the transaction res, err := c.Submit(ctx, tx) if err != nil { @@ -361,7 +361,7 @@ func (c *RPCClient) SubmitAndAwaitSuccess(ctx context.Context, tx rippledata.Tra c.log.Info( ctx, "Transaction is submitted waiting for tx to be accepted", - zap.String("txHash", tx.GetHash().String()), + zap.String("txHash", strings.ToUpper(tx.GetHash().String())), ) return retry.Do(retryCtx, 250*time.Millisecond, func() error { reqCtx, reqCtxCancel := context.WithTimeout(ctx, 3*time.Second) diff --git a/relayer/xrpl/scanner_test.go b/relayer/xrpl/scanner_test.go index b848b2fb..d41f582a 100644 --- a/relayer/xrpl/scanner_test.go +++ b/relayer/xrpl/scanner_test.go @@ -213,7 +213,7 @@ func readTxHashesFromChannels( case <-ctx.Done(): t.Fail() case tx := <-txsCh: - decoded, err := hex.DecodeString(strings.TrimRight(tx.GetHash().String(), "0")) + decoded, err := hex.DecodeString(strings.TrimRight(strings.ToUpper(tx.GetHash().String()), "0")) require.NoError(t, err) gotTxHashes[string(decoded)] = struct{}{} if len(gotTxHashes) == count {