uuosio / ascdk

MIT License
12 stars 9 forks source link

Add support for writing unit tests in js&ts #74

Closed learnforpractice closed 2 years ago

jafri commented 2 years ago

Have a look here: https://github.com/ProtonProtocol/vert

Have been doing this for a while, works well with ascdk. Although it uses a chain simulator instead of a real chain

learnforpractice commented 2 years ago

Yeah, I'm thinking about a more compatible approach.

How python runs tests using chain tester is really compatible, maybe similar for JS/TS?

Right, call chain tester from JS/TS through RPC interfaces.

jafri commented 2 years ago

How python runs tests using chain tester is really compatible, maybe similar for JS/TS?

jafri commented 2 years ago

Also I realized theres no real way to test the new intrinsics since ascdk doesn't use the new EOS repo: https://github.com/eosnetworkfoundation/mandel

learnforpractice commented 2 years ago

Also I realized theres no real way to test the new intrinsics since ascdk doesn't use the new EOS repo: https://github.com/eosnetworkfoundation/mandel

Under planning.

jafri commented 2 years ago

An interesting idea I had here was, what if we modified ascdk to be portable. The AS compiler itself is written in portable Assemblyscript. What this allows for is compiling using tsc, then tests could theoretically be run against a JS compiled version of the contract, and get full JS support + debugger

learnforpractice commented 2 years ago

Sounds practical. some low-level functions such as store, and 'load` wouldn't work though.

jafri commented 2 years ago

we could replace them with custom WASM imports/intrinsics in a debug build

learnforpractice commented 2 years ago

That make things much more complicated. I think we should recommend developers not to use low-level functions.

jafri commented 2 years ago

Thats fine for devs but I believe ascdk library itself uses store and load

learnforpractice commented 2 years ago

So we need to replace all these functions in the assemblyscript source code which is not compatible with the typescript with custom functions. That's a practical solution.

jafri commented 2 years ago

Is it possible to use a debugger/breakpoints?

learnforpractice commented 2 years ago

It is possible to debug wasm in a browser. See the following link:

https://blog.bitsrc.io/debugging-webassembly-with-chrome-devtools-99dbad485451

For debugging smart contracts in wasm, there is no good solution I think.

The solution I currently use for debugging Rust & Go Smart Contracts is compiling source code to native which is not possible for Assemblyscript Smart Contracts I think.