Skip to content

Commit

Permalink
Merge branch 'main' into ducnt/vm_type
Browse files Browse the repository at this point in the history
  • Loading branch information
anhductn2001 committed Aug 8, 2024
2 parents 4c27fd4 + 2c85852 commit fec8b19
Show file tree
Hide file tree
Showing 11 changed files with 570 additions and 529 deletions.
60 changes: 34 additions & 26 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -533,42 +533,50 @@ e2e-test-all: e2e-test-ibc-success-evm \
clean-e2e-live:
sh clean-live.sh

e2e-live-test-ibc-transfer-success: clean-e2e-live
cd live-tests && go test -timeout=25m -race -v -run TestIBCTransfer_Live .
e2e-live-test-ibc-transfer-success-rolx: clean-e2e-live
cd live-tests && go test -timeout=25m -race -v -run TestIBCTransferRolX_Live .

e2e-live-test-delayedack-rollapp-to-hub: clean-e2e-live
cd live-tests && go test -timeout=25m -race -v -run TestDelayackRollappToHub_Live .
e2e-live-test-ibc-transfer-success-roly: clean-e2e-live
cd live-tests && go test -timeout=25m -race -v -run TestIBCTransferRolY_Live .

e2e-live-test-eibc-timeout: clean-e2e-live
cd live-tests && go test -timeout=25m -race -v -run TestEIBCTimeout_Live .
e2e-live-test-delayedack-rollapp-to-hub-rolx: clean-e2e-live
cd live-tests && go test -timeout=25m -race -v -run TestDelayackRollappToHubRolX_Live .

e2e-live-test-delayack-ack-error-from-dym: clean-e2e-live
cd live-tests && go test -timeout=25m -race -v -run TestEIBC_AckError_Dym_EVM_Live .
e2e-live-test-eibc-timeout-rolx: clean-e2e-live
cd live-tests && go test -timeout=25m -race -v -run TestEIBCTimeoutRolX_Live .

e2e-live-test-eibc-3rd-token: clean-e2e-live
cd live-tests && go test -timeout=25m -race -v -run TestEIBC_3rd_Token_Live .
e2e-live-test-eibc-timeout-roly: clean-e2e-live
cd live-tests && go test -timeout=25m -race -v -run TestEIBCTimeoutRolY_Live .

e2e-live-test-eibc-3rd-token-timeout: clean-e2e-live
cd live-tests && go test -timeout=25m -race -v -run TestEIBC_3rd_Token_Timeout_Live .
e2e-live-test-delayack-ack-error-from-dym-roly: clean-e2e-live
cd live-tests && go test -timeout=25m -race -v -run TestEIBC_AckError_Dym_RolY_Live .

e2e-live-test-eibc-pfm: clean-e2e-live
cd live-tests && go test -timeout=25m -race -v -run TestEIBCPFM_Live .
e2e-live-test-eibc-3rd-token-roly: clean-e2e-live
cd live-tests && go test -timeout=25m -race -v -run TestEIBC_3rd_Token_RolY_Live .

e2e-live-test-eibc-3rd-token-timeout-roly: clean-e2e-live
cd live-tests && go test -timeout=25m -race -v -run TestEIBC_3rd_Token_Timeout_RolY_Live .

e2e-live-test-eibc-pfm-rolx: clean-e2e-live
cd live-tests && go test -timeout=25m -race -v -run TestEIBCPFMRolX_Live .

e2e-live-test-eibc-invalid-fee: clean-e2e-live
cd live-tests && go test -timeout=25m -race -v -run TestEIBC_Invalid_Fee_Live .
e2e-live-test-eibc-invalid-fee-rolx: clean-e2e-live
cd live-tests && go test -timeout=25m -race -v -run TestEIBC_Invalid_Fee_RolX_Live .

e2e-live-test-eibc-fulfillment: clean-e2e-live
cd live-tests && go test -timeout=25m -race -v -run TestEIBCFulfill_Live .
e2e-live-test-eibc-fulfillment-rolx: clean-e2e-live
cd live-tests && go test -timeout=35m -race -v -run TestEIBCFulfillRolX_Live .

e2e-live-test-delayack-rollapp-to-hub-no-finalized: clean-e2e-live
cd live-tests && go test -timeout=25m -race -v -run TestDelayackRollappToHubNoFinalized_Live .
e2e-live-test-delayack-rollapp-to-hub-no-finalized-rolx: clean-e2e-live
cd live-tests && go test -timeout=25m -race -v -run TestDelayackRollappToHubNoFinalizedRolX_Live .

e2e-live-test-eibc-no-memo: clean-e2e-live
cd live-tests && go test -timeout=25m -race -v -run TestEIBC_No_Memo_Live .
e2e-live-test-eibc-no-memo-rolx: clean-e2e-live
cd live-tests && go test -timeout=25m -race -v -run TestEIBC_No_Memo_RolX_Live .

e2e-live-test-eibc-demand-order-ignored: clean-e2e-live
cd live-tests && go test -timeout=25m -race -v -run TestEIBC_Demand_Order_Ignored_Live .
e2e-live-test-eibc-demand-order-ignored-rolx: clean-e2e-live
cd live-tests && go test -timeout=25m -race -v -run TestEIBC_Demand_Order_Ignored_RolX_Live .

e2e-live-test-eibc-eibc-fee-bgt-amount: clean-e2e-live
cd live-tests && go test -timeout=25m -race -v -run TestEIBCFeeBgtAmount_Live .
e2e-live-test-eibc-eibc-fee-bgt-amount-rolx: clean-e2e-live
cd live-tests && go test -timeout=25m -race -v -run TestEIBCFeeBgtAmountRolX_Live .

e2e-live-test-eibc-eibc-fee-bgt-amount-roly: clean-e2e-live
cd live-tests && go test -timeout=25m -race -v -run TestEIBCFeeBgtAmountRolY_Live .
229 changes: 229 additions & 0 deletions live-tests/delayed_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
package livetests

import (
"context"
"fmt"
"sync"
"testing"
"time"

sdkmath "cosmossdk.io/math"
transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
"github.com/decentrio/e2e-testing-live/cosmos"
"github.com/decentrio/e2e-testing-live/testutil"
"github.com/decentrio/rollup-e2e-testing/ibc"
"github.com/stretchr/testify/require"
)

// TestDelayackRollappToHubNoFinalized_Live test IBC transfer from rollapp to hub, so that its succeeds (creates rollapp packet) when rollapp has NO FINALIZED STATES AT ALL (just pending)
func TestDelayackRollappToHubNoFinalizedRolX_Live(t *testing.T) {
if testing.Short() {
t.Skip()
}
ctx := context.Background()

hub := cosmos.CosmosChain{
RPCAddr: "rpc-blumbus.mzonder.com:443",
GrpcAddr: "grpc-blumbus.mzonder.com:9090",
ChainID: "blumbus_111-1",
Bin: "dymd",
GasPrices: "1000adym",
GasAdjustment: "1.1",
Denom: "adym",
}

rollappX := cosmos.CosmosChain{
RPCAddr: "rpc.rolxtwo.evm.ra.blumbus.noisnemyd.xyz:443",
GrpcAddr: "3.123.185.77:9090",
ChainID: "rolx_100004-1",
Bin: "rollapp-evm",
GasPrices: "0.0arolx",
GasAdjustment: "1.1",
Denom: "arolx",
}

dymensionUser, err := hub.CreateUser("dym1")
require.NoError(t, err)
rollappXUser, err := rollappX.CreateUser("rolx1")
require.NoError(t, err)

err = hub.NewClient("https://" + hub.RPCAddr)
require.NoError(t, err)

err = rollappX.NewClient("https://" + rollappX.RPCAddr)
require.NoError(t, err)

dymensionUser.GetFaucet("http://18.184.170.181:3000/api/get-dym")
rollappXUser.GetFaucet("http://18.184.170.181:3000/api/get-rollx")

// Wait for blocks
testutil.WaitForBlocks(ctx, 5, hub)

// Get the IBC denom
rollappXTokenDenom := transfertypes.GetPrefixedDenom("transfer", channelIDDymRollappX, rollappXUser.Denom)
rollappXIBCDenom := transfertypes.ParseDenomTrace(rollappXTokenDenom).IBCDenom()

dymensionOrigBal, err := dymensionUser.GetBalance(ctx, dymensionUser.Denom, hub.GrpcAddr)
require.NoError(t, err)
fmt.Println("hub original balance: ", dymensionOrigBal, dymensionUser.Denom)

rollappXOrigBal, err := rollappXUser.GetBalance(ctx, rollappXUser.Denom, rollappX.GrpcAddr)
require.NoError(t, err)
fmt.Println("rollapp x original balance: ", rollappXOrigBal, rollappXUser.Denom)

erc20_OrigBal, err := GetERC20Balance(ctx, erc20IBCDenom, rollappX.GrpcAddr)
require.NoError(t, err)
fmt.Println("rol x user balance of denom send from dym: ", erc20_OrigBal)

// Compose an IBC transfer and send from rollapp -> hub
transferData := ibc.WalletData{
Address: dymensionUser.Address,
Denom: rollappXUser.Denom,
Amount: transferAmount,
}

var options ibc.TransferOptions
_, err = cosmos.SendIBCTransfer(rollappX, channelIDRollappXDym, rollappXUser.Address, transferData, rolxFee, options)
require.NoError(t, err)
// Amount should not be received by hub yet
testutil.AssertBalance(t, ctx, dymensionUser, rollappXIBCDenom, hub.GrpcAddr, sdkmath.NewInt(0))

// Check the state info status every 5 seconds to ensure it is always pending
// Run QueryRollappState in parallel with WaitForBlocks
var wg sync.WaitGroup
wg.Add(2)

// Channel to capture errors
errChan := make(chan error, 1)

// Goroutine to query Rollapp state every 5 seconds
go func() {
defer wg.Done()
ticker := time.NewTicker(5 * time.Second)
defer ticker.Stop()
timeout := time.After(400 * time.Second) // Set a timeout for the whole check

for {
select {
case <-ticker.C:
res, err := hub.QueryRollappState(rollappX.ChainID, false)
if err != nil {
errChan <- err
return
}
if res.StateInfo.Status != "PENDING" {
errChan <- fmt.Errorf("unexpected state: %s", res.StateInfo.Status)
return
}
case <-timeout:
return
}
}
}()

// Goroutine to wait for blocks
go func() {
defer wg.Done()
testutil.WaitForBlocks(ctx, disputed_period_plus_batch_submit_blocks, hub)
fmt.Println("wait for blocks done")
}()

// Wait for both goroutines to complete
wg.Wait()
close(errChan)

// Check for errors from goroutines
if err := <-errChan; err != nil {
require.NoError(t, err)
}

// TODO: sub bridging fee on new version
testutil.AssertBalance(t, ctx, dymensionUser, rollappXIBCDenom, hub.GrpcAddr, transferAmount)

}

// TestDelayackRollappToHub_Live test delayack, rollapp token transfer should only be recieved on the hub upon rollapp finalized state (assume no elBC packet, i.e no memo)
func TestDelayackRollappToHubRolX_Live(t *testing.T) {
if testing.Short() {
t.Skip()
}
ctx := context.Background()

hub := cosmos.CosmosChain{
RPCAddr: "rpc-blumbus.mzonder.com:443",
GrpcAddr: "grpc-blumbus.mzonder.com:9090",
ChainID: "blumbus_111-1",
Bin: "dymd",
GasPrices: "1000adym",
GasAdjustment: "1.1",
Denom: "adym",
}

rollappX := cosmos.CosmosChain{
RPCAddr: "rpc.rolxtwo.evm.ra.blumbus.noisnemyd.xyz:443",
GrpcAddr: "3.123.185.77:9090",
ChainID: "rolx_100004-1",
Bin: "rollapp-evm",
GasPrices: "0.0arolx",
GasAdjustment: "1.1",
Denom: "arolx",
}

dymensionUser, err := hub.CreateUser("dym1")
require.NoError(t, err)
rollappXUser, err := rollappX.CreateUser("rolx1")
require.NoError(t, err)

err = hub.NewClient("https://" + hub.RPCAddr)
require.NoError(t, err)

err = rollappX.NewClient("https://" + rollappX.RPCAddr)
require.NoError(t, err)

dymensionUser.GetFaucet("http://18.184.170.181:3000/api/get-dym")
rollappXUser.GetFaucet("http://18.184.170.181:3000/api/get-rollx")

// Wait for blocks
testutil.WaitForBlocks(ctx, 5, hub)

// Get the IBC denom
rollappXTokenDenom := transfertypes.GetPrefixedDenom("transfer", channelIDDymRollappX, rollappXUser.Denom)
rollappXIBCDenom := transfertypes.ParseDenomTrace(rollappXTokenDenom).IBCDenom()

dymensionOrigBal, err := dymensionUser.GetBalance(ctx, dymensionUser.Denom, hub.GrpcAddr)
require.NoError(t, err)
fmt.Println("hub original balance: ", dymensionOrigBal, dymensionUser.Denom)

rollappXOrigBal, err := rollappXUser.GetBalance(ctx, rollappXUser.Denom, rollappX.GrpcAddr)
require.NoError(t, err)
fmt.Println("rollapp x original balance: ", rollappXOrigBal, rollappXUser.Denom)

erc20_OrigBal, err := GetERC20Balance(ctx, erc20IBCDenom, rollappX.GrpcAddr)
require.NoError(t, err)
fmt.Println("rol x user balance of denom send from dym: ", erc20_OrigBal)

// Compose an IBC transfer and send from rollapp -> hub
transferData := ibc.WalletData{
Address: dymensionUser.Address,
Denom: rollappXUser.Denom,
Amount: transferAmount,
}

var options ibc.TransferOptions
_, err = cosmos.SendIBCTransfer(rollappX, channelIDRollappXDym, rollappXUser.Address, transferData, rolxFee, options)
require.NoError(t, err)
// Amount should not be received by hub yet
testutil.AssertBalance(t, ctx, dymensionUser, rollappXIBCDenom, hub.GrpcAddr, sdkmath.NewInt(0))

rollappXHeight, err := rollappX.Height(ctx)
require.NoError(t, err)
fmt.Println(rollappXHeight)
// wait until the packet is finalized on Rollapp 1
isFinalized, err := hub.WaitUntilRollappHeightIsFinalized(ctx, rollappX.ChainID, rollappXHeight, 1000)
require.NoError(t, err)
require.True(t, isFinalized)

fmt.Println("rollapp x ibc denom: ", rollappXIBCDenom, dymensionUser)
// TODO: sub bridging fee on new version
testutil.AssertBalance(t, ctx, dymensionUser, rollappXIBCDenom, hub.GrpcAddr, transferAmount)
}
Loading

0 comments on commit fec8b19

Please sign in to comment.