Skip to content

Commit

Permalink
Add trace sending CLI (#204)
Browse files Browse the repository at this point in the history
  • Loading branch information
dzmitryhil authored Apr 12, 2024
1 parent f0d44b3 commit 2534b82
Show file tree
Hide file tree
Showing 15 changed files with 850 additions and 85 deletions.
8 changes: 5 additions & 3 deletions integration-tests/processes/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func NewRunnerEnv(ctx context.Context, t *testing.T, cfg RunnerEnvConfig, chains

// fund to cover the fees
chains.Coreum.FundAccountWithOptions(ctx, t, contractOwner, coreumintegration.BalancesOptions{
Amount: chains.Coreum.QueryAssetFTParams(ctx, t).IssueFee.Amount.AddRaw(1_000_000),
Amount: chains.Coreum.QueryAssetFTParams(ctx, t).IssueFee.Amount.AddRaw(10_000_000),
})

contractClient := coreum.NewContractClient(
Expand Down Expand Up @@ -418,7 +418,8 @@ func (r *RunnerEnv) SendFromCoreumToXRPL(
amount sdk.Coin,
deliverAmount *sdkmath.Int,
) {
require.NoError(t, r.BridgeClient.SendFromCoreumToXRPL(ctx, sender, recipient, amount, deliverAmount))
_, err := r.BridgeClient.SendFromCoreumToXRPL(ctx, sender, recipient, amount, deliverAmount)
require.NoError(t, err)
}

// SendFromXRPLToCoreum sends tokens form XRPL to Coreum.
Expand All @@ -429,7 +430,8 @@ func (r *RunnerEnv) SendFromXRPLToCoreum(
amount rippledata.Amount,
recipient sdk.AccAddress,
) {
require.NoError(t, r.BridgeClient.SendFromXRPLToCoreum(ctx, senderKeyName, amount, recipient))
_, err := r.BridgeClient.SendFromXRPLToCoreum(ctx, senderKeyName, amount, recipient)
require.NoError(t, err)
}

// SendXRPLPaymentTx sends Payment transaction.
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/processes/sending_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1953,7 +1953,7 @@ func TestSendFromCoreumToXRPLProhibitedAddresses(t *testing.T) {
runnerEnv.BridgeClient.UpdateProhibitedXRPLAddresses(ctx, runnerEnv.ContractOwner, prohibitedXRPLAddresses),
)

err = runnerEnv.BridgeClient.SendFromCoreumToXRPL(
_, err = runnerEnv.BridgeClient.SendFromCoreumToXRPL(
ctx,
coreumSenderAddress,
xrplRecipientAddress,
Expand Down
160 changes: 160 additions & 0 deletions integration-tests/processes/sending_tracing_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
//go:build integrationtests
// +build integrationtests

package processes_test

import (
"testing"

sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
rippledata "github.com/rubblelabs/ripple/data"
"github.com/stretchr/testify/require"

coreumintegration "github.com/CoreumFoundation/coreum/v4/testutil/integration"
integrationtests "github.com/CoreumFoundation/coreumbridge-xrpl/integration-tests"
"github.com/CoreumFoundation/coreumbridge-xrpl/relayer/coreum"
"github.com/CoreumFoundation/coreumbridge-xrpl/relayer/xrpl"
)

func TestTraceXRPLToCoreumTransfer(t *testing.T) {
t.Parallel()

ctx, chains := integrationtests.NewTestingContext(t)

envCfg := DefaultRunnerEnvConfig()
runnerEnv := NewRunnerEnv(ctx, t, envCfg, chains)
runnerEnv.StartAllRunnerProcesses()
runnerEnv.AllocateTickets(ctx, t, uint32(200))

coreumRecipient := chains.Coreum.GenAccount()
xrplRecipientAddress := chains.XRPL.GenAccount(ctx, t, 0)
t.Logf("XRPL recipient: %s", xrplRecipientAddress.String())

xrplIssuerAddress := chains.XRPL.GenAccount(ctx, t, 1)
// enable to be able to send to any address
runnerEnv.EnableXRPLAccountRippling(ctx, t, xrplIssuerAddress)
registeredXRPLCurrency := integrationtests.GenerateXRPLCurrency(t)
registeredXRPLToken := runnerEnv.RegisterXRPLOriginatedToken(
ctx,
t,
xrplIssuerAddress,
registeredXRPLCurrency,
int32(6),
integrationtests.ConvertStringWithDecimalsToSDKInt(t, "1", 30),
sdk.ZeroInt(),
)

valueSentToCoreum, err := rippledata.NewValue("1.0", false)
require.NoError(t, err)
amountToSendToCoreum := rippledata.Amount{
Value: valueSentToCoreum,
Currency: registeredXRPLCurrency,
Issuer: xrplIssuerAddress,
}

txHash, err := runnerEnv.BridgeClient.SendFromXRPLToCoreum(
ctx, xrplIssuerAddress.String(), amountToSendToCoreum, coreumRecipient,
)
require.NoError(t, err)

runnerEnv.AwaitCoreumBalance(
ctx,
t,
coreumRecipient,
sdk.NewCoin(
registeredXRPLToken.CoreumDenom,
integrationtests.ConvertStringWithDecimalsToSDKInt(
t,
valueSentToCoreum.String(),
xrpl.XRPLIssuedTokenDecimals,
),
),
)

tracingInfo, err := runnerEnv.BridgeClient.GetXRPLToCoreumTracingInfo(ctx, txHash)
require.NoError(t, err)
require.NotNil(t, tracingInfo.CoreumTx)
require.Len(t, tracingInfo.EvidenceToTxs, 2)
}

func TestTraceCoreumToXRPLTransfer(t *testing.T) {
t.Parallel()

ctx, chains := integrationtests.NewTestingContext(t)

xrplRecipient1Address := chains.XRPL.GenAccount(ctx, t, 0)
xrplRecipient2Address := chains.XRPL.GenAccount(ctx, t, 0)

coreumSenderAddress := chains.Coreum.GenAccount()
issueFee := chains.Coreum.QueryAssetFTParams(ctx, t).IssueFee
chains.Coreum.FundAccountWithOptions(ctx, t, coreumSenderAddress, coreumintegration.BalancesOptions{
Amount: issueFee.Amount.Add(sdkmath.NewIntWithDecimal(1, 7)),
})

envCfg := DefaultRunnerEnvConfig()
runnerEnv := NewRunnerEnv(ctx, t, envCfg, chains)

// start relayers
runnerEnv.StartAllRunnerProcesses()
// recover tickets so we can register tokens
runnerEnv.AllocateTickets(ctx, t, 200)

// issue asset ft and register it
sendingPrecision := int32(2)
tokenDecimals := uint32(4)
initialAmount := sdkmath.NewIntWithDecimal(1, 16)
maxHoldingAmount := sdkmath.NewIntWithDecimal(1, 16)
registeredCoreumOriginatedToken := runnerEnv.IssueAndRegisterCoreumOriginatedToken(
ctx,
t,
coreumSenderAddress,
tokenDecimals,
initialAmount,
sendingPrecision,
maxHoldingAmount,
sdkmath.ZeroInt(),
)

// send TrustSet to be able to receive coins from the bridge
xrplCurrency, err := rippledata.NewCurrency(registeredCoreumOriginatedToken.XRPLCurrency)
require.NoError(t, err)
runnerEnv.SendXRPLMaxTrustSetTx(ctx, t, xrplRecipient1Address, runnerEnv.BridgeXRPLAddress, xrplCurrency)
runnerEnv.SendXRPLMaxTrustSetTx(ctx, t, xrplRecipient2Address, runnerEnv.BridgeXRPLAddress, xrplCurrency)

amountToSendToRecipient1 := sdkmath.NewInt(111111)
amountToSendToRecipient2 := sdkmath.NewInt(211111)
txRes, err := runnerEnv.ContractClient.MultiSendToXRPL(
ctx,
coreumSenderAddress,
[]coreum.SendToXRPLRequest{
{
Recipient: xrplRecipient1Address.String(),
DeliverAmount: nil,
Amount: sdk.NewCoin(registeredCoreumOriginatedToken.Denom, amountToSendToRecipient1),
},
{
Recipient: xrplRecipient2Address.String(),
DeliverAmount: nil,
Amount: sdk.NewCoin(registeredCoreumOriginatedToken.Denom, amountToSendToRecipient2),
},
}...,
)
require.NoError(t, err)
runnerEnv.AwaitNoPendingOperations(ctx, t)

// check the XRPL recipients balance
xrplRecipient1Balance := runnerEnv.Chains.XRPL.GetAccountBalance(
ctx, t, xrplRecipient1Address, runnerEnv.BridgeXRPLAddress, xrplCurrency,
)
require.Equal(t, "11.11", xrplRecipient1Balance.Value.String())
xrplRecipient2Balance := runnerEnv.Chains.XRPL.GetAccountBalance(
ctx, t, xrplRecipient2Address, runnerEnv.BridgeXRPLAddress, xrplCurrency,
)
require.Equal(t, "21.11", xrplRecipient2Balance.Value.String())

tracingInfo, err := runnerEnv.BridgeClient.GetCoreumToXRPLTracingInfo(ctx, txRes.TxHash)
require.NoError(t, err)
require.Len(t, tracingInfo.XRPLTxs, 2)
require.Len(t, tracingInfo.EvidenceToTxs, 2)
}
7 changes: 3 additions & 4 deletions integration-tests/stress/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,8 @@ func (env *Env) FundCoreumAccountsWithXRP(

coreumFaucetAccount := env.Chains.Coreum.GenAccount()

require.NoError(
t, env.BridgeClient.SendFromXRPLToCoreum(ctx, xrplFaucetAccount.String(), xrpAmount, coreumFaucetAccount),
)
_, err = env.BridgeClient.SendFromXRPLToCoreum(ctx, xrplFaucetAccount.String(), xrpAmount, coreumFaucetAccount)
require.NoError(t, err)

require.NoError(t, env.AwaitCoreumBalance(
ctx,
Expand Down Expand Up @@ -336,7 +335,7 @@ func (env *Env) AwaitContractCall(ctx context.Context, call func() error) error
})
}

func (env *Env) callAdminAction(ctx context.Context, action func() error, rollbackAction func() error) error {
func (env *Env) callAdminAction(ctx context.Context, action, rollbackAction func() error) error {
ctx, cancel := context.WithTimeout(ctx, env.Cfg.TestCaseTimeout)
defer cancel()
// use common BridgeClient to prevent sequence mismatch
Expand Down
11 changes: 7 additions & 4 deletions integration-tests/stress/stress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,10 @@ func sendXRPFromXRPLAndBack(ctx context.Context, t *testing.T, env *Env) {
ctx, cancel := context.WithTimeout(ctx, env.Cfg.TestCaseTimeout)
defer cancel()

if err := bridgeClient.SendFromXRPLToCoreum(
_, err := bridgeClient.SendFromXRPLToCoreum(
ctx, xrplAccount.String(), amountToSendFromXRPLtoCoreum, coreumAccount,
); err != nil {
)
if err != nil {
return err
}

Expand All @@ -141,13 +142,14 @@ func sendXRPFromXRPLAndBack(ctx context.Context, t *testing.T, env *Env) {

// send back to XRPL
if err = env.AwaitContractCall(ctx, func() error {
return bridgeClient.SendFromCoreumToXRPL(
_, err := bridgeClient.SendFromCoreumToXRPL(
ctx,
coreumAccount,
xrplAccount,
coreumAmount,
nil,
)
return err
}); err != nil {
return err
}
Expand Down Expand Up @@ -210,7 +212,7 @@ func sendWithFailureAndClaimRefund(ctx context.Context, t *testing.T, env *Env)
xrplAccount := xrpl.GenPrivKeyTxSigner().Account()

if err = env.AwaitContractCall(ctx, func() error {
return bridgeClient.SendFromCoreumToXRPL(
_, err := bridgeClient.SendFromCoreumToXRPL(
ctx,
coreumAccount,
xrplAccount,
Expand All @@ -219,6 +221,7 @@ func sendWithFailureAndClaimRefund(ctx context.Context, t *testing.T, env *Env)
amountToSendFromCoreumXRPL),
nil,
)
return err
}); err != nil {
return err
}
Expand Down
Loading

0 comments on commit 2534b82

Please sign in to comment.