-
Notifications
You must be signed in to change notification settings - Fork 23
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
feat: cache root testnet accounts and destroy the ones created in tests #43
Conversation
c912bfa
to
a8ad2a4
Compare
0f89471
to
f88daa6
Compare
src/jsonrpc.ts
Outdated
const stateStaked = new BN(state.storage_usage).mul(costPerByte); | ||
const staked = new BN(state.locked); | ||
const totalBalance = new BN(state.amount).add(staked); | ||
const availableBalance = totalBalance.sub(BN.max(staked, stateStaked)); |
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 this math to me? Why add staked
to amount
just to subtract it again? Why wouldn't we always want:
const availableBalance = totalBalance.sub(BN.max(staked, stateStaked)); | |
const availableBalance = totalBalance.sub(staked).sub(stateStaked); |
Or, equivalently:
const availableBalance = totalBalance.sub(BN.max(staked, stateStaked)); | |
const availableBalance = BN(state.amount).sub(stateStaked); |
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.
Seems like maybe the same bucket of tokens can be used for storage staking and delegation/validator staking?
5b67eb9
to
44145aa
Compare
Co-authored-by: Chad Ostrowski <221614+chadoh@users.noreply.github.com>
1b4d51a
to
5377ce4
Compare
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 updated the description of this PR with what I think are the main things that were done here. Feel free to edit my descriptions and add others.
I lost the ability to make sense of this PR a long time ago, so I'm marking as Approved so we can merge it and move on (after tests are fixed, obviously). Let's make smaller PRs from here on out, please.
5213deb
to
35d301a
Compare
Co-authored-by: Chad Ostrowski <221614+chadoh@users.noreply.github.com>
Co-authored-by: Chad Ostrowski <221614+chadoh@users.noreply.github.com>
Cache root testnet accounts.
Clean up test accounts like
alice
andbob
at the end of the test run. This involved adding anAccountManager
and subclassTestnetManager
to keep track of accounts created during the test run.AccountManager
also handles all things related to accounts and signing. In the future we may want to use two separate classes for these two needs (spawning/cleaning accounts; handling transactions & signing for a given account).Restructure the project with the goal of removing circular dependencies. This includes adding new
interface NearAccount
.Tests can now skip
beforeAll
, since therunner
instance will wait for the function passed tocreate
to complete before executingrun
calls. That is,beforeAll
is no longer required, and this can be defined at the top level of tests:Use
jest.concurrent
to make tests actually-concurrent (they weren't before) which speeds up test runs significantly and ensures that all near-runner works as designedUse near-units to wrap account balances and clean up assertions about account balances. Example:
Add new JSON RPC wrapper