CodeRejected: module imports a non-existent function
- Dominant language
- TypeScript
- Stars
- 31
- Forks
- 3
- PR merge metrics
- No merged PRs in 30d
Description
# Problem: -
Error while deploying contracts that contains methods that deletes storage states. That includes operation like `Mapping.delete()` that call `env().clearContractStroage()`.
### Temporary Fix: -
Commented out the new `seal_clear_storage` from `__unstable__.ts`, that overshadows the old `seal_clear_storage` from `seal0.ts`
https://github.com/ask-lang/ask/blob/a1bd060593b247bc0e2a9d0b5bc88f95ec3fdfa1/as-packages/as-contract-runtime/assembly/unstable.ts#L34-L35
### Substrate Contracts Node Log
v0.22
```
DEBUG tokio-runtime-worker runtime::contracts: CodeRejected: module imports a non-existent function
```
v0.23
```
DEBUG tokio-runtime-worker runtime::contracts: failed to instantiate code: cannot find definition for import __unstable__::seal_clear_storage: Func(DedupFuncType(GuardedEntity { guard_idx: EngineIdx(2), entity_idx: DedupFuncTypeIdx(0) }))
```
## Steps to reproduce: -
Build and deploy any contract that has `delete()` method. Below is the minimal reproduction contract.
```ts
import { HashKeccak256, AccountId, Mapping } from "ask-lang";
@contract()
export class Contract {
_map: Mapping = new Mapping();
@constructor()
default(): void {}
@message({ mutates: true })
remove(k: AccountId): void {
return this._map.delete(k);
}
}
```
## Notes (Not related to this issue) :-
Cannot deploy any contract build with `ark-lang` v0.4.0 on latest [`substrate-contracts-node` v0.23](https://github.com/paritytech/substrate-contracts-node/releases).
Always fails with below error.
```log
DEBUG tokio-runtime-worker runtime::contracts: failed to instantiate code: found an unexpected start function with index 58
```
Maybe related to paritytech/substrate#207
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with as-packages/as-contract-runtime/assembly/unstable.ts at the referenced seal_clear_storage import and compare it with seal0.ts. Build the minimal Mapping.delete() contract and deploy it against the noted substrate-contracts-node versions; done means the generated module no longer imports a function the node cannot resolve.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript, wasm
- Domain
- blockchain
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100