* Start implementation * Add implementation + some e2e test * Fix lint * Squashed: sdk upgrade to v0.50 * rebuild protos with newer proto builder (cherry picked from commit fd8f4c1d0d2163f0a504356c16cd2d250f6218f3) * update ibc-go (cherry picked from commit fb8667960fbeedb7d242baa644572986a154d4b6) * bump cosmos-sdk and ibc in the v50 branch (#1616) * tidy * upgade ibc * remove the toolchain command * Bump sdk version * Use correct bech32 prefix * Bump SDK * Enable fraud system test again * Fix genesis param name * Fix import/export simulations * set log level for benchmarks (cherry picked from commit 1cfb93008c596db62d22aba882f37a469546bfb9) * Apply review comments * Remove gov beta1 helpers * Bump sdk version to latest in branch * Fix linter * Setup mergify for main * Update mergify for better branch name --------- Co-authored-by: Pino' Surace <pino.surace@live.it> Co-authored-by: Jacob Gadikian <jacobgadikian@gmail.com>
85 lines
2.5 KiB
Go
85 lines
2.5 KiB
Go
package keeper
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
)
|
|
|
|
func TestDontBindPortNonIBCContract(t *testing.T) {
|
|
ctx, keepers := CreateTestInput(t, false, AvailableCapabilities)
|
|
example := InstantiateHackatomExampleContract(t, ctx, keepers) // ensure we bound the port
|
|
_, _, err := keepers.IBCKeeper.PortKeeper.LookupModuleByPort(ctx, keepers.WasmKeeper.GetContractInfo(ctx, example.Contract).IBCPortID)
|
|
require.Error(t, err)
|
|
}
|
|
|
|
func TestBindingPortForIBCContractOnInstantiate(t *testing.T) {
|
|
ctx, keepers := CreateTestInput(t, false, AvailableCapabilities)
|
|
example := InstantiateIBCReflectContract(t, ctx, keepers) // ensure we bound the port
|
|
owner, _, err := keepers.IBCKeeper.PortKeeper.LookupModuleByPort(ctx, keepers.WasmKeeper.GetContractInfo(ctx, example.Contract).IBCPortID)
|
|
require.NoError(t, err)
|
|
require.Equal(t, "wasm", owner)
|
|
|
|
initMsgBz, err := json.Marshal(IBCReflectInitMsg{
|
|
ReflectCodeID: example.ReflectCodeID,
|
|
})
|
|
require.NoError(t, err)
|
|
|
|
// create a second contract should give yet another portID (and different address)
|
|
creator := RandomAccountAddress(t)
|
|
addr, _, err := keepers.ContractKeeper.Instantiate(ctx, example.CodeID, creator, nil, initMsgBz, "ibc-reflect-2", nil)
|
|
require.NoError(t, err)
|
|
require.NotEqual(t, example.Contract, addr)
|
|
|
|
portID2 := PortIDForContract(addr)
|
|
owner, _, err = keepers.IBCKeeper.PortKeeper.LookupModuleByPort(ctx, portID2)
|
|
require.NoError(t, err)
|
|
require.Equal(t, "wasm", owner)
|
|
}
|
|
|
|
func TestContractFromPortID(t *testing.T) {
|
|
contractAddr := BuildContractAddressClassic(1, 100)
|
|
specs := map[string]struct {
|
|
srcPort string
|
|
expAddr sdk.AccAddress
|
|
expErr bool
|
|
}{
|
|
"all good": {
|
|
srcPort: fmt.Sprintf("wasm.%s", contractAddr.String()),
|
|
expAddr: contractAddr,
|
|
},
|
|
"without prefix": {
|
|
srcPort: contractAddr.String(),
|
|
expErr: true,
|
|
},
|
|
"invalid prefix": {
|
|
srcPort: fmt.Sprintf("wasmx.%s", contractAddr.String()),
|
|
expErr: true,
|
|
},
|
|
"without separator char": {
|
|
srcPort: fmt.Sprintf("wasm%s", contractAddr.String()),
|
|
expErr: true,
|
|
},
|
|
"invalid account": {
|
|
srcPort: "wasm.foobar",
|
|
expErr: true,
|
|
},
|
|
}
|
|
for name, spec := range specs {
|
|
t.Run(name, func(t *testing.T) {
|
|
gotAddr, gotErr := ContractFromPortID(spec.srcPort)
|
|
if spec.expErr {
|
|
require.Error(t, gotErr)
|
|
return
|
|
}
|
|
require.NoError(t, gotErr)
|
|
assert.Equal(t, spec.expAddr, gotAddr)
|
|
})
|
|
}
|
|
}
|