-
Notifications
You must be signed in to change notification settings - Fork 241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: replace fungible token example sim tests with workspaces #699
Conversation
let none: Option<bool> = None; | ||
let res = contract | ||
.call(&worker, "storage_deposit") | ||
.args_json((account_id, none))? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@austinabell is there a way to instantiate None
with an explicit generic type in one line? I have tried None: Option<bool>
, but apparently type ascriptions are experimental.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, can just do ()
or I think Option::<bool>::None
works if you want it to be clear the type (serializes no different though)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem with ()
is that it does not match the function's signature. Even if None
and ()
do serialize the same way, as an external user reading these examples I would be confused why we are passing ()
instead of Option<bool>
.
Option::<bool>::None
works though, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops forgot to finalize this review, sorry if any are stale comments. Was just a quick scan until the CI passes, which seemed more workspaces/sandbox utils related
const TEN_THOUSAND_NEAR: u128 = 100_000_000_000_000_000_000_000_000_000; | ||
const ONE_HUNDRED_NEAR: u128 = 100_000_000_000_000_000_000_000_000; | ||
const FIFTY_NEAR: u128 = 50_000_000_000_000_000_000_000_000; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we have the ONE_NEAR
constant in the SDK we can use it here to be more readable? Mult can be used with consts with no added cost. Or can just avoid using these constants and do that where it is used
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, at first I have refactored these values to look like 10000 * ONE_NEAR
, but later I found out about parse_near!
so ended up with in-place parse_near!("10000 N")
instead. lmk which way you prefer.
.deposit(ONE_YOCTO) | ||
.transact() | ||
.await?; | ||
assert!(matches!(res.status, FinalExecutionStatus::SuccessValue(_))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe worth adding an is_success
method or something equivalent to the result to abstract this away in workspaces? cc @ChaoticTempest
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, that would simplify my life as a workspaces user
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. Normally the pattern for these was to do an into_result()?
to forward the error, but I see that in this case we want to do assertions to be more explicit. Good idea overall, I'll add a ticket here's a PR near/near-workspaces-rs#58 for it since it's pretty small addition anyways
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, CallExecutionDetails
does not have into_result()
anyway. Thanks for the PR, I will take a look shortly
let none: Option<bool> = None; | ||
let res = contract | ||
.call(&worker, "storage_deposit") | ||
.args_json((account_id, none))? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, can just do ()
or I think Option::<bool>::None
works if you want it to be clear the type (serializes no different though)
No worries. Indeed, I have already refactored most of the weird stuff away.
Yeah, I am still trying to figure out why Github Actions don't want to run the downloaded sandbox binaries... There is some weirdness going on in Buildkite too, but I have not looked too deeply into that yet. |
.deposit(ONE_YOCTO) | ||
.transact() | ||
.await?; | ||
assert!(matches!(res.status, FinalExecutionStatus::SuccessValue(_))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. Normally the pattern for these was to do an into_result()?
to forward the error, but I see that in this case we want to do assertions to be more explicit. Good idea overall, I'll add a ticket here's a PR near/near-workspaces-rs#58 for it since it's pretty small addition anyways
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, I'll wait for @ChaoticTempest approval before pulling in because he might have some tricks :)
register_user(&worker, &contract, defi_contract.id()).await?; | ||
|
||
// root invests in defi by calling `ft_transfer_call` | ||
// TODO: Pack into one transaction |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you explain what you mean by this? Not completely intuitive
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah sorry for using incorrect terminology. What I meant to say is that these two actions (fn call ft_transfer_call
and fn call storage_unregister
) are supposed to be batched into a single transaction according to the old simtest-powered tests. Since workspaces do not support batched transactions yet, I had to split these two actions into two separate transactions. But to be fair I do not really see why you would want to batch these two specific action other than to (maybe?) save some gas... Atomicity does not matter here I think.
I will re-phrase the wording
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good to me as well. Will be adding the promise results soon, so hopefully we can add in those commented out promise_error
checks
@@ -5,8 +5,13 @@ authors = ["Near Inc <hello@nearprotocol.com>"] | |||
edition = "2018" | |||
|
|||
[dev-dependencies] | |||
anyhow = "1.0" | |||
near-primitives = "0.5.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah an extension of what Phuong mentioned, this shouldn't be included
near-primitives = "0.5.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As @ChaoticTempest mentioned in the other thread I actually need this to pull FinalExecutionStatus
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like something that shouldn't be exposed through workspaces
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, do you mean that workspaces should have its own type for expressing the call execution status?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, this is not an ideal pattern for workspace users to have to import a nearcore internal crate. Not a big deal, but something that should be changed at some point
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ooof, this was a pattern I wasn't expecting to cover with asserts!
with FinalExecutionStatus
. Think we can defer this later until a new minor version of workspaces is released and we can convert these asserts!
over to using is_success
calls
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think we can defer this later until a new minor version of workspaces is released and we can convert these
asserts!
over to usingis_success
calls
Yeah, we can defer for sure and is_success
will help in this case, but CallExecutionDetails::status
(which is a part of the public API) will still be a type from near-primitives
so I think eventually we would want to replace it with something else.
# Conflicts: # examples/fungible-token/Cargo.lock # examples/fungible-token/res/defi.wasm # examples/fungible-token/res/fungible_token.wasm
3a913d8
to
1af263a
Compare
I had to cut a few asserts from some of the tests since workspaces does not expose some of the stuff they needed, but at the very least all of the tests have survived the migration without losing meaningfulness. I left TODOs in appropriate places for us to revisit later.
Also, I took the liberty to delete
examples/heavy.rs
since it was originally added in #307 to showcase sim tests performance. But lmk if you would prefer for me to keep and refactor it too.Related to #563 #662