|
1 | 1 | package api
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "bytes" |
4 | 5 | "crypto/sha256"
|
5 | 6 | "encoding/hex"
|
6 | 7 | "encoding/json"
|
@@ -142,6 +143,28 @@ func TestStoreCodeUnchecked(t *testing.T) {
|
142 | 143 | require.Equal(t, wasm, code)
|
143 | 144 | }
|
144 | 145 |
|
| 146 | +func TestStoreCodeUncheckedWorksWithInvalidWasm(t *testing.T) { |
| 147 | + cache, cleanup := withCache(t) |
| 148 | + defer cleanup() |
| 149 | + |
| 150 | + wasm, err := os.ReadFile("../../testdata/hackatom.wasm") |
| 151 | + require.NoError(t, err) |
| 152 | + |
| 153 | + // Look for "interface_version_8" in the wasm file and replace it with "interface_version_9". |
| 154 | + // This makes the wasm file invalid. |
| 155 | + wasm = bytes.Replace(wasm, []byte("interface_version_8"), []byte("interface_version_9"), 1) |
| 156 | + |
| 157 | + // StoreCode should fail |
| 158 | + _, err = StoreCode(cache, wasm, true) |
| 159 | + require.ErrorContains(t, err, "Wasm contract has unknown interface_version_* marker export") |
| 160 | + |
| 161 | + // StoreCodeUnchecked should not fail |
| 162 | + checksum, err := StoreCodeUnchecked(cache, wasm) |
| 163 | + require.NoError(t, err) |
| 164 | + expectedChecksum := sha256.Sum256(wasm) |
| 165 | + assert.Equal(t, expectedChecksum[:], checksum) |
| 166 | +} |
| 167 | + |
145 | 168 | func TestPin(t *testing.T) {
|
146 | 169 | cache, cleanup := withCache(t)
|
147 | 170 | defer cleanup()
|
|
0 commit comments