Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Make sure balances of accounts when forking are correct #128

Closed
cgewecke opened this issue Jun 27, 2018 · 2 comments · Fixed by #129
Closed

Make sure balances of accounts when forking are correct #128

cgewecke opened this issue Jun 27, 2018 · 2 comments · Fixed by #129
Labels

Comments

@cgewecke
Copy link
Contributor

cgewecke commented Jun 27, 2018

For a forked chain to reflect the state of its parent, it needs to map the parent's unlocked accounts onto itself. For example, you would expect

const web3 = new Web3(provider);
const parentAccounts = await web3.eth.getAccounts();

const web3 = new Web3(forkedProvider);
const forkedAccounts = await web3.eth.getAccounts();

assert.arraysEqual(parentAccounts, forkedAccounts);

This is not currently possible unless you pass ganache a list of private keys (I think). One hope of the Truffle V5 migrations work is to make dry-run a meaningful simulation of the deployment sequence and balance checks are necessarily part of that.

It's possible we could manage this at truffle where the forking happens by passing in a list of accounts to unlock, setting a high default ether balance, and then running a set of txs that seed the unlocked accounts with the appropriate balances.

Questions for @seesemichaelj and @benjamincburns:

  • Is this description of how ganache behaves correct?
  • Is managing this at Truffle the right approach? Or is there simpler 5-10 line fix over here?
mikeseese added a commit that referenced this issue Jun 29, 2018
also update the test to make sure the balance isn't too large
(which it was in this case)
for #128
@mikeseese mikeseese changed the title Fork Accounts Make sure balances of accounts when forking are correct Jun 29, 2018
@mikeseese mikeseese added bug and removed question labels Jun 29, 2018
@mikeseese
Copy link
Contributor

I updated this issue after talking to @cgewecke some more; it seems that the issue was presented because of the balances were not necessarily matching up in his dry-run tests.

This prompted me to look into the issue and found that the fallback getBalance method for forked chains was incorrectly converting the balance (i.e. it added 0x to the beginning of a decimal number string, causing the number to be much larger than it should be)

This issue is not for that bug

@cgewecke
Copy link
Contributor Author

Thanks @seesemichaelj! Great.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants