Skip to content

Commit

Permalink
enhance testibc
Browse files Browse the repository at this point in the history
  • Loading branch information
faddat committed Jan 12, 2025
1 parent 0b82922 commit ffb4c26
Showing 1 changed file with 38 additions and 9 deletions.
47 changes: 38 additions & 9 deletions ibc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,44 @@ const IBC_TEST_CONTRACT = "./testdata/ibc_reflect.wasm"
func TestIBC(t *testing.T) {
vm := withVM(t)

wasm, err := os.ReadFile(IBC_TEST_CONTRACT)
require.NoError(t, err)

checksum, _, err := vm.StoreCode(wasm, TESTING_GAS_LIMIT)
require.NoError(t, err)

code, err := vm.GetCode(checksum)
require.NoError(t, err)
require.Equal(t, WasmCode(wasm), code)
t.Run("Store and retrieve IBC contract", func(t *testing.T) {
wasm, err := os.ReadFile(IBC_TEST_CONTRACT)
require.NoError(t, err)

checksum, _, err := vm.StoreCode(wasm, TESTING_GAS_LIMIT)
require.NoError(t, err)

code, err := vm.GetCode(checksum)
require.NoError(t, err)
require.Equal(t, WasmCode(wasm), code)
})

t.Run("Analyze stored IBC contract", func(t *testing.T) {
// Re-read the same wasm file and store it again, or retrieve the same checksum from above
wasm, err := os.ReadFile(IBC_TEST_CONTRACT)
require.NoError(t, err)

checksum, _, err := vm.StoreCode(wasm, TESTING_GAS_LIMIT)
require.NoError(t, err)

// Now run the analyzer
report, err := vm.AnalyzeCode(checksum)
require.NoError(t, err)

// We expect IBC entry points to be present in this contract
require.True(t, report.HasIBCEntryPoints, "IBC contract should have IBC entry points")

// You can also assert/update checks regarding capabilities or migration versions:
require.Contains(t, report.RequiredCapabilities, "iterator", "Expected 'iterator' capability for this contract")
require.Contains(t, report.RequiredCapabilities, "stargate", "Expected 'stargate' capability for this contract")

// Optionally check if the contract has a migrate version or not
if report.ContractMigrateVersion != nil {
t.Logf("Contract declares a migration version: %d", *report.ContractMigrateVersion)
} else {
t.Log("Contract does not declare a migration version")
}
})
}

// IBCInstantiateMsg is the Go version of
Expand Down

0 comments on commit ffb4c26

Please sign in to comment.