Skip to content

Commit

Permalink
Add test for StoreCodeUnchecked
Browse files Browse the repository at this point in the history
(cherry picked from commit 2481812)
  • Loading branch information
chipshort authored and mergify[bot] committed Jan 22, 2025
1 parent 65e1526 commit 4f11d5a
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions internal/api/lib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,28 @@ func TestStoreCodeUnchecked(t *testing.T) {
require.Equal(t, wasm, code)
}

func TestStoreCodeUncheckedWorksWithInvalidWasm(t *testing.T) {
cache, cleanup := withCache(t)
defer cleanup()

wasm, err := os.ReadFile("../../testdata/hackatom.wasm")
require.NoError(t, err)

// Look for "interface_version_8" in the wasm file and replace it with "interface_version_9".
// This makes the wasm file invalid.
wasm = bytes.Replace(wasm, []byte("interface_version_8"), []byte("interface_version_9"), 1)

// StoreCode should fail
_, err = StoreCode(cache, wasm, true)
require.ErrorContains(t, err, "Wasm contract has unknown interface_version_* marker export")

// StoreCodeUnchecked should not fail
checksum, err := StoreCodeUnchecked(cache, wasm)
require.NoError(t, err)
expectedChecksum := sha256.Sum256(wasm)
assert.Equal(t, expectedChecksum[:], checksum)
}

func TestPin(t *testing.T) {
cache, cleanup := withCache(t)
defer cleanup()
Expand Down

0 comments on commit 4f11d5a

Please sign in to comment.