Skip to content

Commit

Permalink
chore: adapt e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
boojamya committed Nov 9, 2024
1 parent bb70671 commit a8c90ae
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 83 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ ifeq (,$(shell which heighliner))
@echo heighliner not found. https://github.com/strangelove-ventures/heighliner
else
@echo "🤖 Building image..."
@heighliner build --chain noble-authority-simd --local 1> /dev/null
@heighliner build --file ./e2e/chains.yaml --chain noble-authority-simd --local
@echo "✅ Completed build!"
endif

Expand Down
File renamed without changes.
26 changes: 0 additions & 26 deletions e2e/clients.json

This file was deleted.

52 changes: 40 additions & 12 deletions e2e/clients_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ package e2e

import (
_ "embed"
"path"
"testing"
"time"

"cosmossdk.io/math"

Expand All @@ -19,15 +19,12 @@ import (
"github.com/stretchr/testify/require"
)

//go:embed clients.json
var Clients []byte

// TestClientSubstitution tests the module's ability to substitute IBC clients.
func TestClientSubstitution(t *testing.T) {
t.Parallel()

var wrapper Wrapper
ctx, reporter, rly := Suite(t, &wrapper, true)
ctx, logger, reporter, rly := Suite(t, &wrapper, true)
validator := wrapper.chain.Validators[0]

nobleChainID, gaiaChainID := wrapper.chain.Config().ChainID, wrapper.gaia.Config().ChainID
Expand All @@ -36,10 +33,18 @@ func TestClientSubstitution(t *testing.T) {
err := rly.GeneratePath(ctx, reporter, nobleChainID, gaiaChainID, pathName)
require.NoError(t, err)

tp := 20 * time.Second
err = rly.CreateClient(ctx, reporter, nobleChainID, gaiaChainID, pathName, ibc.CreateClientOptions{
TrustingPeriod: "30s",
TrustingPeriod: tp.String(),
})
require.NoError(t, err)

nobleClients, err := rly.GetClients(ctx, reporter, nobleChainID)
require.NoError(t, err)
require.Len(t, nobleClients, 2) // ignore 09-localhost client

nobleClientToExpire := nobleClients[0]

err = rly.CreateClient(ctx, reporter, gaiaChainID, nobleChainID, pathName, ibc.CreateClientOptions{})
require.NoError(t, err)
require.NoError(t, testutil.WaitForBlocks(ctx, 1, wrapper.chain, wrapper.gaia))
Expand All @@ -51,8 +56,12 @@ func TestClientSubstitution(t *testing.T) {
err = rly.CreateChannel(ctx, reporter, pathName, ibc.DefaultChannelOpts())
require.NoError(t, err)

timer := time.NewTimer(tp + 2*time.Second)

users := interchaintest.GetAndFundTestUsers(t, ctx, "user", math.NewInt(5_000_000), wrapper.chain, wrapper.gaia)
require.NoError(t, testutil.WaitForBlocks(ctx, 10, wrapper.chain, wrapper.gaia))

logger.Info("waiting for client to expire...")
<-timer.C

_, err = validator.SendIBCTransfer(ctx, "channel-0", users[0].KeyName(), ibc.WalletAmount{
Address: users[1].FormattedAddress(),
Expand All @@ -61,13 +70,32 @@ func TestClientSubstitution(t *testing.T) {
}, ibc.TransferOptions{})
require.ErrorContains(t, err, "client state is not active")

res := rly.Exec(ctx, reporter, []string{"rly", "tx", "client", nobleChainID, gaiaChainID, pathName, "--override", "--home", rly.HomeDir()}, nil)
require.NoError(t, res.Err)
err = rly.CreateClient(ctx, reporter, nobleChainID, gaiaChainID, pathName, ibc.CreateClientOptions{Override: true})
require.NoError(t, err)

nobleClients, err = rly.GetClients(ctx, reporter, nobleChainID)
require.NoError(t, err)
require.Len(t, nobleClients, 3) // ignore 09-localhost client

newNobleClient := nobleClients[1]

notAuthorized := interchaintest.GetAndFundTestUsers(t, ctx, "wallet", math.NewInt(100000), wrapper.chain)[0]

cmd := []string{"authority", "recover-client", nobleClientToExpire.ClientID, newNobleClient.ClientID}

// broadcast from un-authorized account
_, err = validator.ExecTx(
ctx,
notAuthorized.KeyName(),
cmd...,
)
require.ErrorContains(t, err, "signer is not authority")

require.NoError(t, validator.WriteFile(ctx, Clients, "clients.json"))
// broadcast from authorized authority account
_, err = validator.ExecTx(
ctx, wrapper.owner.KeyName(),
"authority", "execute", path.Join(validator.HomeDir(), "clients.json"),
ctx,
wrapper.owner.KeyName(),
cmd...,
)
require.NoError(t, err)

Expand Down
2 changes: 1 addition & 1 deletion e2e/fee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestBeginBlocker(t *testing.T) {
t.Parallel()

var wrapper Wrapper
ctx, _, _ := Suite(t, &wrapper, false)
ctx, _, _, _ := Suite(t, &wrapper, false)
validator := wrapper.chain.Validators[0]

oldBalance, err := wrapper.chain.BankQueryAllBalances(ctx, wrapper.owner.FormattedAddress())
Expand Down
2 changes: 1 addition & 1 deletion e2e/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ require (
github.com/cosmos/gogogateway v1.2.0 // indirect
github.com/cosmos/iavl v1.2.0 // indirect
github.com/cosmos/ibc-go/modules/capability v1.0.1 // indirect
github.com/cosmos/ibc-go/v8 v8.5.1 // indirect
github.com/cosmos/ibc-go/v8 v8.5.2 // indirect
github.com/cosmos/ics23/go v0.11.0 // indirect
github.com/cosmos/interchain-security/v5 v5.1.1 // indirect
github.com/cosmos/ledger-cosmos-go v0.13.3 // indirect
Expand Down
4 changes: 2 additions & 2 deletions e2e/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,8 @@ github.com/cosmos/iavl v1.2.0 h1:kVxTmjTh4k0Dh1VNL046v6BXqKziqMDzxo93oh3kOfM=
github.com/cosmos/iavl v1.2.0/go.mod h1:HidWWLVAtODJqFD6Hbne2Y0q3SdxByJepHUOeoH4LiI=
github.com/cosmos/ibc-go/modules/capability v1.0.1 h1:ibwhrpJ3SftEEZRxCRkH0fQZ9svjthrX2+oXdZvzgGI=
github.com/cosmos/ibc-go/modules/capability v1.0.1/go.mod h1:rquyOV262nGJplkumH+/LeYs04P3eV8oB7ZM4Ygqk4E=
github.com/cosmos/ibc-go/v8 v8.5.1 h1:3JleEMKBjRKa3FeTKt4fjg22za/qygLBo7mDkoYTNBs=
github.com/cosmos/ibc-go/v8 v8.5.1/go.mod h1:P5hkAvq0Qbg0h18uLxDVA9q1kOJ0l36htMsskiNwXbo=
github.com/cosmos/ibc-go/v8 v8.5.2 h1:27s9oeD2AxLQF3e9BQsYt9doONyZ7FwZi/qkBv6Sdks=
github.com/cosmos/ibc-go/v8 v8.5.2/go.mod h1:P5hkAvq0Qbg0h18uLxDVA9q1kOJ0l36htMsskiNwXbo=
github.com/cosmos/ics23/go v0.11.0 h1:jk5skjT0TqX5e5QJbEnwXIS2yI2vnmLOgpQPeM5RtnU=
github.com/cosmos/ics23/go v0.11.0/go.mod h1:A8OjxPE67hHST4Icw94hOxxFEJMBG031xIGF/JHNIY0=
github.com/cosmos/interchain-security/v5 v5.1.1 h1:xmRRMeE4xoc+JAZUh0XzXFYWaGBtzFFj5SETuOgnEnY=
Expand Down
2 changes: 1 addition & 1 deletion e2e/ownership_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestOwnershipTransfer(t *testing.T) {
t.Parallel()

var wrapper Wrapper
ctx, _, _ := Suite(t, &wrapper, false)
ctx, _, _, _ := Suite(t, &wrapper, false)
validator := wrapper.chain.Validators[0]

EnsureOwner(t, wrapper, ctx, wrapper.owner.FormattedAddress())
Expand Down
3 changes: 2 additions & 1 deletion e2e/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ import (
var Params []byte

// TestParameterUpdate tests the module's ability to modify module parameters.
// This test uses the "execute" command to test broadcasting arbitrary messages.
func TestParameterUpdate(t *testing.T) {
t.Parallel()

var wrapper Wrapper
ctx, _, _ := Suite(t, &wrapper, false)
ctx, _, _, _ := Suite(t, &wrapper, false)
validator := wrapper.chain.Validators[0]

EnsureParams(t, wrapper, ctx, 0)
Expand Down
28 changes: 0 additions & 28 deletions e2e/upgrade.json

This file was deleted.

28 changes: 20 additions & 8 deletions e2e/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,41 @@ package e2e

import (
_ "embed"
"path"
"testing"

"cosmossdk.io/math"
"github.com/strangelove-ventures/interchaintest/v8"
"github.com/stretchr/testify/require"
)

//go:embed upgrade.json
var Upgrade []byte

// TestScheduleUpgrade tests the module's ability to schedule an upgrade on-chain.
func TestScheduleUpgrade(t *testing.T) {
t.Parallel()

var wrapper Wrapper
ctx, _, _ := Suite(t, &wrapper, false)
ctx, _, _, _ := Suite(t, &wrapper, false)
validator := wrapper.chain.Validators[0]

notAuthorized := interchaintest.GetAndFundTestUsers(t, ctx, "wallet", math.NewInt(100000), wrapper.chain)[0]

EnsureUpgrade(t, wrapper, ctx, "", 0)

require.NoError(t, validator.WriteFile(ctx, Upgrade, "upgrade.json"))
cmd := []string{"authority", "software-upgrade", "v2", "--upgrade-height", "50",
"--chain-id", wrapper.chain.Config().ChainID, "--no-validate"}

// broadcast from un-authorized account
_, err := validator.ExecTx(
ctx, wrapper.owner.KeyName(),
"authority", "execute", path.Join(validator.HomeDir(), "upgrade.json"),
ctx,
notAuthorized.KeyName(),
cmd...,
)
require.ErrorContains(t, err, "signer is not authority")

// broadcast from authorized authority account
_, err = validator.ExecTx(
ctx,
wrapper.owner.KeyName(),
cmd...,
)
require.NoError(t, err)

Expand Down
5 changes: 3 additions & 2 deletions e2e/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/strangelove-ventures/interchaintest/v8/relayer/rly"
"github.com/strangelove-ventures/interchaintest/v8/testreporter"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
"go.uber.org/zap/zaptest"
)

Expand All @@ -34,9 +35,9 @@ type Wrapper struct {
pendingOwner ibc.Wallet
}

func Suite(t *testing.T, wrapper *Wrapper, ibcEnabled bool) (ctx context.Context, execReporter *testreporter.RelayerExecReporter, relayer *rly.CosmosRelayer) {
func Suite(t *testing.T, wrapper *Wrapper, ibcEnabled bool) (ctx context.Context, logger *zap.Logger, execReporter *testreporter.RelayerExecReporter, relayer *rly.CosmosRelayer) {
ctx = context.Background()
logger := zaptest.NewLogger(t)
logger = zaptest.NewLogger(t)
reporter := testreporter.NewNopReporter()
execReporter = reporter.RelayerExecReporter(t)
client, network := interchaintest.DockerSetup(t)
Expand Down

0 comments on commit a8c90ae

Please sign in to comment.