-
Notifications
You must be signed in to change notification settings - Fork 15
idea for better rust wasm contract development/testing experience #10
Comments
for actually using contracts (not testing) there would be a default Context implementation which would delegate to |
to clarify: i'm proposing an attribute or macro which makes a smart contract and it's ABI from a module like definition. functions within that definition take a less boilerplate because there no longer is a need to specify both trait and impl for a contract. |
I like your ideas. The way we are mocking externs right now seems not very nice, to be honest. Maybe context.storage().write instead of storage_write (and context.storage().read) is a bit overkill.. |
@fckt i prefer |
👍 |
such approach has a lot of downsides
|
@NikVolf great that we start a discussion on this the points you raise focus on the removal of the trait in the example. do you see any downsides to passing in a
good point. but i'm sure one could model the problem in a way where one could use traits if that is needed and not use traits if they are not needed and would just be boilerplate.
other than 1) what is gained by splitting trait and implementation?
can you elaborate? seems like you currently generate the abi using only the trait: i'm sure one can derive the abi from the trait, a module like thing or |
Better to keep contract Endpoint and Client generation using trait, but I like idea of context.. |
@snd yeah, downside with
it's easy, i can declare trait in one crate and other crate will just import this trait and implement it for it's own structures, with abi already defined as exactly the same across all implementations. So user, to guarantee that his contract is compliant to the specific abi, just implements the trait and that's all. |
Like Solidity interfaces |
the trait stuff is clear to me. just thought 1) and 2) were essentially the same point and wanted to know whether there's more to it. |
On the second thought, idea with context might be useful, if traits will not be generic over it. |
i already like this much better than the current way 👍 i don't like that the following nontrivial boilerplate is now required for every contract: struct Token<'a, T: 'a + Context> {
context: &'a mut T
}
impl<'a, T: 'a + Context> Token<'a, T> {
fn new (context: &'a mut T) -> Token<'a, T> {
Token{ context: context }
}
} one could write a macro to automate that. but macros obfuscate things and add complexity. not saying one should never use them but a solution without them is often simpler. the generics with lifetime params are not the easiest and might result in difficult error messages. let's keep iterating! |
why |
Just wanted to note about gist is that better always require Not to mention that tests might want to write some logging data when |
Can we just have:
? https://play.rust-lang.org/?gist=99209e78f4bbd2de7d8df909f9d4a2e4&version=stable |
@pepyakin yeap, the context gives us this flexibility. In the |
Name |
isn't that an implementation detail that shouldn't affect the public API? |
it has nothing to do with solidity actually, it's just me; i will rename it in abi reimplementation i'm working on now |
just looked at https://play.rust-lang.org/?gist=6570adb28cbd3bb1c139e08389a6a12b&version=stable again in the test at the bottom: having to use explicit blocks and recreating the contract many times because the contract exclusively mutably borrows the context is not the best developer experience. that's just a minor thing though |
@pepyakin really like how your modification removed the need for lifetime params for the real (non testing) case |
polkadot uses the concept of an maybe we can get some useful ideas from their code i like the word |
@snd, it has little to do with context and tests, it's how runtime works parity has the same "externalities" (and with much more functions) for both evm and wasm |
it has quite a bit to do with context in the sense that the context idea and externalities both model abilities of an execution environment (and those environments are even similar) through a trait. so design decisions in one could be useful in the other |
We have a current limitation with a "context" approach: |
Guys, run failed with a bunch of errors |
fixed for the latest rust version |
not sure if this is the right repo for this issue. if someone points me to a better repo i'll move the issue there.
i know rust wasm contract development is super early days. even so the contract developer/tester experience could already be improved a lot.
room for improvement imho:
EXTERNS
)self
https://github.com/paritytech/pwasm-token-example/blob/b23d486120a2007a3727864deb7b67f79dc5bf50/src/token.rs#L79it would be great if we could write rust contracts a bit like this (wishful thinking):
this looks much cleaner to me.
it requires no knowledge about global mutable state to understand.
testing would be more natural, require no macros and no setting of global mutable state:
what do you think?
The text was updated successfully, but these errors were encountered: