Skip to content

Commit

Permalink
feat: test multiple packets on same height (#736)
Browse files Browse the repository at this point in the history
* add(test): multiple packets on same heigt

* rf: simplfy recursion call

* ci: remove cw_common from inside the docker container (#712)

Signed-off-by: Night Owl <[email protected]>

* chore: exclude cosmwasm library and common file from contract deployment (#698)

---------

Signed-off-by: Night Owl <[email protected]>
Co-authored-by: Debendra Oli <[email protected]>
Co-authored-by: Night Owl <[email protected]>
Co-authored-by: DeepakBomjan <[email protected]>
  • Loading branch information
4 people authored Sep 20, 2023
1 parent 6eb6a85 commit 26bcb55
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/deploy-cosmwasm-contracts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
- scripts/archway/**
jobs:
Build:
name: Build & Deploy Cosmasm Contracts
name: Build & Deploy Cosmwasm Contracts
runs-on: ubuntu-latest
steps:
- name: Checkout sources
Expand Down Expand Up @@ -50,7 +50,7 @@ jobs:
- name: Deploy WASM
run: |
container=$(docker ps --format '{{.Names}}')
sudo rm -rf artifacts/archway/cw_common.wasm
docker exec $container sh -c "rm /contracts/*_latest.wasm;rm /contracts/cw_common*.wasm"
# cp -r {artifacts,scripts/deploy_cosmwasm.sh} contracts/cosmwasm-vm/archway/contracts
docker ps -a
docker exec $container chmod +x /opt/deploy_cosmwasm.sh
Expand Down
4 changes: 4 additions & 0 deletions scripts/deploy_cosmwasm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ deploy_wasm() {

# This wasm directory is inside the docker container
for CONTRACT_WASM in /contracts/*.wasm; do
if [[ $CONTRACT_WASM == *"_lib"* || $CONTRACT_WASM == *"cw_common"* ]]; then
echo "Skipping library: $CONTRACT_WASM"
continue
fi
echo "=> Deploying $CONTRACT_WASM"
deploy_wasm "$CONTRACT_WASM"
done
47 changes: 38 additions & 9 deletions test/integration/tests/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package tests
import (
"context"
"fmt"
"github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
"github.com/stretchr/testify/assert"
"testing"
"time"

"github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
"github.com/stretchr/testify/assert"

"github.com/icon-project/ibc-integration/test/chains"
"github.com/icon-project/ibc-integration/test/testsuite"
"github.com/strangelove-ventures/interchaintest/v7/ibc"
Expand Down Expand Up @@ -147,13 +148,13 @@ func (r *RelayerTestSuite) TestRelayer(ctx context.Context, relayer ibc.Relayer)
})

r.T.Run("single relay packet flow chainA-chainB", func(t *testing.T) {
response, err := r.SendPacket(ctx, chainA, chainB, "data", 1000)
response, err := r.SendPacket(ctx, chainA, chainB, "data", 1000, false)
assert.NoErrorf(t, err, "Error while sending package from chainA-chainB")
assert.Truef(t, response.IsPacketSent, "The packet has not been sent to the target chain.")
assert.Truef(t, response.IsPacketReceiptEventFound, "The packet event has not received on the target chain.")
})
r.T.Run("single relay packet flow chainB-chainA", func(t *testing.T) {
response, err := r.SendPacket(ctx, chainB, chainA, "data", 1000)
response, err := r.SendPacket(ctx, chainB, chainA, "data", 1000, false)
assert.NoErrorf(t, err, "Error while sending package from chainB-chainA")
assert.Truef(t, response.IsPacketSent, "The packet has not been sent to the target chain.")
assert.Truef(t, response.IsPacketReceiptEventFound, "The packet event has not received on the target chain.")
Expand Down Expand Up @@ -218,14 +219,14 @@ func (r *RelayerTestSuite) TestRelayer(ctx context.Context, relayer ibc.Relayer)
})

r.T.Run("single relay packet flow chainA-chainB", func(t *testing.T) {
response, err := r.SendPacket(ctx, chainA, chainB, "data", 1000)
response, err := r.SendPacket(ctx, chainA, chainB, "data", 1000, false)
assert.NoErrorf(t, err, "Error while sending package from chainA-chainB")
assert.Truef(t, response.IsPacketSent, "The packet has not been sent to the target chain.")
assert.Truef(t, response.IsPacketReceiptEventFound, "The packet event has not received on the target chain.")
})

r.T.Run("single relay packet flow chainB-chainA", func(t *testing.T) {
response, err := r.SendPacket(ctx, chainB, chainA, "data", 1000)
response, err := r.SendPacket(ctx, chainB, chainA, "data", 1000, false)
assert.NoErrorf(t, err, "Error while sending package from chainB-chainA")
assert.Truef(t, response.IsPacketSent, "The packet has not been sent to the target chain.")
assert.Truef(t, response.IsPacketReceiptEventFound, "The packet event has not received on the target chain.")
Expand All @@ -240,6 +241,19 @@ func (r *RelayerTestSuite) TestRelayer(ctx context.Context, relayer ibc.Relayer)
})
})

r.T.Run("send multiple packets on same ChainA height", func(t *testing.T) {
chainA, chainB := r.GetChains()
height, err := chainA.(ibc.Chain).Height(ctx)
r.Require().NoError(err)
r.Require().NoError(r.multiplePacketsOnSameHeight(chainA, chainB, height+100, 5))
})

r.T.Run("send multiple packets on same ChainB height", func(t *testing.T) {
chainA, chainB := r.GetChains()
height, err := chainB.(ibc.Chain).Height(ctx)
r.Require().NoError(err)
r.Require().NoError(r.multiplePacketsOnSameHeight(chainB, chainA, height+100, 5))
})
}

func (r *RelayerTestSuite) PacketFlowTest(ctx context.Context, t *testing.T, src, target chains.Chain, order ibc.Order) {
Expand All @@ -257,7 +271,7 @@ func (r *RelayerTestSuite) PacketFlowTest(ctx context.Context, t *testing.T, src
assert.Falsef(t, isPacketReceived, "The packet event has received on the target chain.\n%v\n", packet)

msg := "new-message"
response, err := r.SendPacket(ctx, src, target, msg, 1000) //new packet
response, err := r.SendPacket(ctx, src, target, msg, 1000, false) //new packet
if order == ibc.Ordered {
assert.Errorf(t, err, "Error on sending packet (%s): %v", msg, err)
assert.Falsef(t, response.IsPacketReceiptEventFound, "The packet event has been received on the target chain.")
Expand Down Expand Up @@ -302,7 +316,7 @@ func (r *RelayerTestSuite) RelayerCrashTest(ctx context.Context, chainA, chainB

// check if relay is working as expected with ping pong to cross chain
msg := "new-message"
response, err := r.SendPacket(ctx, chainA, chainB, msg, 1000)
response, err := r.SendPacket(ctx, chainA, chainB, msg, 1000, false)
assert.NoErrorf(r.T, err, "Error on sending packet (%s) %v", msg, err)
assert.Truef(r.T, response.IsPacketSent, "The packet has not been sent to the target chain.")
assert.Truef(r.T, response.IsPacketReceiptEventFound, "The packet event has NOT been received on the target chain.")
Expand Down Expand Up @@ -330,7 +344,7 @@ func (r *RelayerTestSuite) handleCrashAndSendPacket(ctx context.Context, src cha
r.T.Logf("crashed at: %s %d", chainID, crashedHeight)
// send packet from src to target crashed node and check if it is received
var msg = fmt.Sprintf("data-%s", chainID)
response, _ := r.SendPacket(ctx, src, target, msg, 1000000)
response, _ := r.SendPacket(ctx, src, target, msg, 1000000, false)
packet := response.Packet
assert.NotEqualf(r.T, types.Packet{}, packet, "packet is empty")
assert.Truef(r.T, response.IsPacketSent, "The packet has not been sent to the target chain.")
Expand Down Expand Up @@ -361,3 +375,18 @@ func findPacket(ctx context.Context, chain chains.Chain, params map[string]inter
}
}
}

func (r *RelayerTestSuite) multiplePacketsOnSameHeight(src, dst chains.Chain, height uint64, numPackets uint) error {
ctx := context.Background()
res, err := r.SendPacket(ctx, src, dst, fmt.Sprintf("test-%d", numPackets), height, true)
if err != nil {
return err
}
if !res.IsPacketSent {
return fmt.Errorf("packet not sent")
}
if numPackets == 0 {
return nil
}
return r.multiplePacketsOnSameHeight(src, dst, height, numPackets-1)
}
7 changes: 5 additions & 2 deletions test/testsuite/integration_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,11 @@ func (s *E2ETestSuite) GetNextConnectionSequence(ctx context.Context, chain chai
}

// SendPacket sends a packet from src to dst
func (s *E2ETestSuite) SendPacket(ctx context.Context, src, target chains.Chain, msg string, timeout uint64) (chains.PacketTransferResponse, error) {
height, _ := src.(ibc.Chain).Height(ctx)
func (s *E2ETestSuite) SendPacket(ctx context.Context, src, target chains.Chain, msg string, timeout uint64, isCurrentHeight bool) (chains.PacketTransferResponse, error) {
var height uint64
if !isCurrentHeight {
height, _ = src.(ibc.Chain).Height(ctx)
}
params := map[string]interface{}{
"msg": chains.BufferArray(msg),
"timeout_height": height + timeout,
Expand Down

0 comments on commit 26bcb55

Please sign in to comment.