Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement blocked channels #7

Merged
merged 4 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion e2e/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.21

require (
github.com/cosmos/cosmos-sdk v0.45.16
github.com/cosmos/ibc-go/v4 v4.6.0
github.com/gogo/protobuf v1.3.3
github.com/noble-assets/aura v1.0.0
github.com/strangelove-ventures/interchaintest/v4 v4.0.0-20231026153934-334934f17a68
Expand Down Expand Up @@ -42,7 +43,6 @@ require (
github.com/cosmos/go-bip39 v1.0.0 // indirect
github.com/cosmos/gorocksdb v1.2.0 // indirect
github.com/cosmos/iavl v0.19.5 // indirect
github.com/cosmos/ibc-go/v4 v4.5.1 // indirect
github.com/cosmos/ledger-cosmos-go v0.12.2 // indirect
github.com/danieljoos/wincred v1.1.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
Expand Down
4 changes: 2 additions & 2 deletions e2e/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ github.com/cosmos/gorocksdb v1.2.0 h1:d0l3jJG8M4hBouIZq0mDUHZ+zjOx044J3nGRskwTb4
github.com/cosmos/gorocksdb v1.2.0/go.mod h1:aaKvKItm514hKfNJpUJXnnOWeBnk2GL4+Qw9NHizILw=
github.com/cosmos/iavl v0.19.5 h1:rGA3hOrgNxgRM5wYcSCxgQBap7fW82WZgY78V9po/iY=
github.com/cosmos/iavl v0.19.5/go.mod h1:X9PKD3J0iFxdmgNLa7b2LYWdsGd90ToV5cAONApkEPw=
github.com/cosmos/ibc-go/v4 v4.5.1 h1:+P73X7aIikGAXBUJ9vP9rEbvdSuekt3KGXmAWCSYets=
github.com/cosmos/ibc-go/v4 v4.5.1/go.mod h1:2EOi40Bx/j6rJrtP1ui8k8yUAMpGybmL1EjakYqYv5U=
github.com/cosmos/ibc-go/v4 v4.6.0 h1:G7kiD4Zf8Wrxc8BXWIKuFnzI0W4wpvRPrl5HwdfTIsA=
github.com/cosmos/ibc-go/v4 v4.6.0/go.mod h1:ksiZHUypws0NVP50E3ea0ivVFO/bfS8q8yLg8yZ2ATQ=
github.com/cosmos/ledger-cosmos-go v0.12.4 h1:drvWt+GJP7Aiw550yeb3ON/zsrgW0jgh5saFCr7pDnw=
github.com/cosmos/ledger-cosmos-go v0.12.4/go.mod h1:fjfVWRf++Xkygt9wzCsjEBdjcf7wiiY35fv3ctT+k4M=
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
Expand Down
98 changes: 95 additions & 3 deletions e2e/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import (
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
transfertypes "github.com/cosmos/ibc-go/v4/modules/apps/transfer/types"
"github.com/strangelove-ventures/interchaintest/v4/ibc"
"github.com/strangelove-ventures/interchaintest/v4/testutil"
"github.com/stretchr/testify/require"
)

Expand All @@ -14,7 +16,7 @@ func TestMintBurn(t *testing.T) {
t.Parallel()

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

// ASSERT: Minter has an allowance of 1 $USDY.
Expand Down Expand Up @@ -56,7 +58,7 @@ func TestMintTransferBurn(t *testing.T) {
t.Parallel()

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

// ASSERT: Minter has an allowance of 1 $USDY.
Expand Down Expand Up @@ -115,7 +117,7 @@ func TestMintTransferBlockBurn(t *testing.T) {
t.Parallel()

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

// ASSERT: Minter has an allowance of 1 $USDY.
Expand Down Expand Up @@ -191,3 +193,93 @@ func TestMintTransferBlockBurn(t *testing.T) {
// ASSERT: Burner has no allowance.
EnsureBurner(t, wrapper, ctx, wrapper.burner.FormattedAddress(), sdk.ZeroInt())
}

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

var wrapper Wrapper
ctx := Suite(t, &wrapper, true)
validator := wrapper.chain.Validators[0]
denom := transfertypes.DenomTrace{
Path: "transfer/channel-0",
BaseDenom: "ausdy",
}.IBCDenom()

// ARRANGE: Mint 2 $USDY to Alice.
_, err := validator.ExecTx(
ctx, wrapper.owner.KeyName(),
"aura", "set-minter-allowance", wrapper.minter.FormattedAddress(), ONE.MulRaw(2).String(),
)
require.NoError(t, err)
_, err = validator.ExecTx(
ctx, wrapper.minter.KeyName(),
"aura", "mint", wrapper.alice.FormattedAddress(), ONE.MulRaw(2).String(),
)
require.NoError(t, err)

// ACT: Attempt to transfer out of Noble, channel is allowed.
_, err = wrapper.chain.SendIBCTransfer(ctx, "channel-0", wrapper.alice.KeyName(), ibc.WalletAmount{
Address: wrapper.charlie.FormattedAddress(),
Denom: "ausdy",
Amount: ONE.MulRaw(2).Int64(),
}, ibc.TransferOptions{})
// ASSERT: The action should've succeeded.
require.NoError(t, err)
require.NoError(t, testutil.WaitForBlocks(ctx, 5, wrapper.chain, wrapper.gaia))
balance, err := wrapper.chain.GetBalance(ctx, wrapper.alice.FormattedAddress(), "ausdy")
require.NoError(t, err)
require.Zero(t, balance)
balance, err = wrapper.gaia.GetBalance(ctx, wrapper.charlie.FormattedAddress(), denom)
require.NoError(t, err)
require.Equal(t, ONE.MulRaw(2).Int64(), balance)

// ACT: Attempt to transfer back to Noble, channel is allowed.
_, err = wrapper.gaia.SendIBCTransfer(ctx, "channel-0", wrapper.charlie.KeyName(), ibc.WalletAmount{
Address: wrapper.alice.FormattedAddress(),
Denom: denom,
Amount: ONE.Int64(),
}, ibc.TransferOptions{})
// ASSERT: The action should've succeeded.
require.NoError(t, err)
require.NoError(t, testutil.WaitForBlocks(ctx, 5, wrapper.chain, wrapper.gaia))
balance, err = wrapper.chain.GetBalance(ctx, wrapper.alice.FormattedAddress(), "ausdy")
require.NoError(t, err)
require.Equal(t, ONE.Int64(), balance)
balance, err = wrapper.gaia.GetBalance(ctx, wrapper.charlie.FormattedAddress(), denom)
require.NoError(t, err)
require.Equal(t, ONE.Int64(), balance)

// ACT: Block transfers over channel-0.
_, err = validator.ExecTx(
ctx, wrapper.owner.KeyName(),
"aura", "add-blocked-channel", "channel-0",
)
require.NoError(t, err)
// ASSERT: channel-0 has been blocked.
EnsureBlockedChannel(t, wrapper, ctx, "channel-0")

// ACT: Attempt to transfer out of Noble, channel is blocked.
_, err = wrapper.chain.SendIBCTransfer(ctx, "channel-0", wrapper.alice.KeyName(), ibc.WalletAmount{
Address: wrapper.charlie.FormattedAddress(),
Denom: "ausdy",
Amount: ONE.Int64(),
}, ibc.TransferOptions{})
// ASSERT: The action should've failed.
require.ErrorContains(t, err, "ausdy transfers are blocked on channel-0")

// ACT: Attempt to transfer back to Noble, channel is allowed.
_, err = wrapper.gaia.SendIBCTransfer(ctx, "channel-0", wrapper.charlie.KeyName(), ibc.WalletAmount{
Address: wrapper.alice.FormattedAddress(),
Denom: denom,
Amount: ONE.Int64(),
}, ibc.TransferOptions{})
// ASSERT: The action should've succeeded.
require.NoError(t, err)
require.NoError(t, testutil.WaitForBlocks(ctx, 5, wrapper.chain, wrapper.gaia))
balance, err = wrapper.chain.GetBalance(ctx, wrapper.alice.FormattedAddress(), "ausdy")
require.NoError(t, err)
require.Equal(t, ONE.MulRaw(2).Int64(), balance)
balance, err = wrapper.gaia.GetBalance(ctx, wrapper.charlie.FormattedAddress(), denom)
require.NoError(t, err)
require.Zero(t, balance)
}
78 changes: 71 additions & 7 deletions e2e/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,25 @@ import (
"github.com/strangelove-ventures/interchaintest/v4"
"github.com/strangelove-ventures/interchaintest/v4/chain/cosmos"
"github.com/strangelove-ventures/interchaintest/v4/ibc"
"github.com/strangelove-ventures/interchaintest/v4/relayer/rly"
"github.com/strangelove-ventures/interchaintest/v4/testreporter"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zaptest"
)

type Wrapper struct {
chain *cosmos.CosmosChain

owner ibc.Wallet
minter ibc.Wallet
burner ibc.Wallet
alice ibc.Wallet
bob ibc.Wallet
gaia *cosmos.CosmosChain

owner ibc.Wallet
minter ibc.Wallet
burner ibc.Wallet
alice ibc.Wallet
bob ibc.Wallet
charlie ibc.Wallet
}

func Suite(t *testing.T, wrapper *Wrapper) (ctx context.Context) {
func Suite(t *testing.T, wrapper *Wrapper, ibcEnabled bool) (ctx context.Context) {
ctx = context.Background()
logger := zaptest.NewLogger(t)
reporter := testreporter.NewNopReporter()
Expand Down Expand Up @@ -135,6 +138,31 @@ func Suite(t *testing.T, wrapper *Wrapper) (ctx context.Context) {
},
},
}
if ibcEnabled {
specs = append(specs, &interchaintest.ChainSpec{
Name: "ibc-go-simd",
Version: "v4.5.0",
NumValidators: &numValidators,
NumFullNodes: &numFullNodes,
ChainConfig: ibc.ChainConfig{
PreGenesis: func(cfg ibc.ChainConfig) (err error) {
validator := wrapper.gaia.Validators[0]
ONE := sdk.NewCoins(sdk.NewInt64Coin(cfg.Denom, 1_000_000))

wrapper.charlie, err = wrapper.gaia.BuildWallet(ctx, "owner", "")
if err != nil {
return err
}
err = validator.AddGenesisAccount(ctx, wrapper.charlie.FormattedAddress(), ONE)
if err != nil {
return err
}

return nil
},
},
})
}
factory := interchaintest.NewBuiltinChainFactory(logger, specs)

chains, err := factory.Chains(t.Name())
Expand All @@ -144,6 +172,26 @@ func Suite(t *testing.T, wrapper *Wrapper) (ctx context.Context) {
wrapper.chain = noble

interchain := interchaintest.NewInterchain().AddChain(noble)
var relayer *rly.CosmosRelayer
if ibcEnabled {
relayer = interchaintest.NewBuiltinRelayerFactory(
ibc.CosmosRly,
logger,
).Build(t, client, network).(*rly.CosmosRelayer)

gaia := chains[1].(*cosmos.CosmosChain)
wrapper.gaia = gaia

interchain = interchain.
AddChain(gaia).
AddRelayer(relayer, "relayer").
AddLink(interchaintest.InterchainLink{
Chain1: noble,
Chain2: gaia,
Relayer: relayer,
Path: "transfer",
})
}
require.NoError(t, interchain.Build(ctx, execReporter, interchaintest.InterchainBuildOptions{
TestName: t.Name(),
Client: client,
Expand All @@ -154,6 +202,10 @@ func Suite(t *testing.T, wrapper *Wrapper) (ctx context.Context) {
_ = interchain.Close()
})

if ibcEnabled {
require.NoError(t, relayer.StartRelayer(ctx, execReporter))
}

return
}

Expand Down Expand Up @@ -194,3 +246,15 @@ func EnsureMinter(t *testing.T, wrapper Wrapper, ctx context.Context, address st

require.Contains(t, res.Minters, types.Minter{Address: address, Allowance: allowance})
}

func EnsureBlockedChannel(t *testing.T, wrapper Wrapper, ctx context.Context, channel string) {
validator := wrapper.chain.Validators[0]

raw, _, err := validator.ExecQuery(ctx, "aura", "blocked-channels")
require.NoError(t, err)

var res types.QueryBlockedChannelsResponse
require.NoError(t, json.Unmarshal(raw, &res))

require.Contains(t, res.BlockedChannels, channel)
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.21
require (
cosmossdk.io/errors v1.0.0
github.com/cosmos/cosmos-sdk v0.45.16
github.com/cosmos/ibc-go/v4 v4.6.0
github.com/gogo/protobuf v1.3.3
github.com/golang/protobuf v1.5.3
github.com/golangci/golangci-lint v1.55.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ github.com/cosmos/gorocksdb v1.2.0 h1:d0l3jJG8M4hBouIZq0mDUHZ+zjOx044J3nGRskwTb4
github.com/cosmos/gorocksdb v1.2.0/go.mod h1:aaKvKItm514hKfNJpUJXnnOWeBnk2GL4+Qw9NHizILw=
github.com/cosmos/iavl v0.19.5 h1:rGA3hOrgNxgRM5wYcSCxgQBap7fW82WZgY78V9po/iY=
github.com/cosmos/iavl v0.19.5/go.mod h1:X9PKD3J0iFxdmgNLa7b2LYWdsGd90ToV5cAONApkEPw=
github.com/cosmos/ibc-go/v4 v4.6.0 h1:G7kiD4Zf8Wrxc8BXWIKuFnzI0W4wpvRPrl5HwdfTIsA=
github.com/cosmos/ibc-go/v4 v4.6.0/go.mod h1:ksiZHUypws0NVP50E3ea0ivVFO/bfS8q8yLg8yZ2ATQ=
github.com/cosmos/ledger-cosmos-go v0.12.4 h1:drvWt+GJP7Aiw550yeb3ON/zsrgW0jgh5saFCr7pDnw=
github.com/cosmos/ledger-cosmos-go v0.12.4/go.mod h1:fjfVWRf++Xkygt9wzCsjEBdjcf7wiiY35fv3ctT+k4M=
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
Expand Down
Loading