-
Notifications
You must be signed in to change notification settings - Fork 697
Support defining accounts instead of the randomly generated ones #24
Conversation
Switching Dapple over to use TestRPC as it seems more actively developed. This feature is something we need in order to successfully make the switch. |
Great to hear @ryepdx. Looking at it now! And thanks @axic! |
Question for both of you (@ryepdx, @axic): If the accounts list were input as an optional configuration file, much like a Here's an example: http://jev.io/genesis_block.json I'm thinking something like
or
Edit: we could easily have quick options like Either we could strictly adhere to the |
With that specific I think the
are all possible options. In my opinion Update: I am personally not using testrpc for signing, I do that myself (via provider-engine). I also do not mind which way is implemented as long as I can define addresses with balances, but I would prefer such a feature to arrive shortly as I don't really want to maintain my branch :) |
Giving a second thought I'm leaning towards:
|
Definitely agree the improved genesis file is the right answer, which could include the private keys needed for signing.
I'm not sure I agree with that. The genesis file would include a list of initial accounts and, optionally, their starting balance. If I understand this PR correctly, that's what you're trying to achieve. If the improved genesis file were also included, Assuming we go the genesis file route (not set in stone), here's what I imagine it would look like: {
// likely won't matter:
nonce: "0x0000000000000042",
// won't matter
difficulty: "0x400000000",
// specify initial accounts, balances, and private keys
alloc: {
"3282791d6fd713f1e94f4bfd565eaa78b3a0599d": {
balance: "1337000000000000000000" // Optional. Will be set to default if not specified.
private_key: "..." // Optional. Non-standard.
},
...
},
// Could matter in rare cases
mixhash: "0x0000000000000000000000000000000000000000000000000000000000000000",
// Easy to set, could matter in rare cases
coinbase: "0x0000000000000000000000000000000000000000",
// Likely won't matter
timestamp: "0x00",
// Likely won't matter
parentHash: "0x0000000000000000000000000000000000000000000000000000000000000000",
// Likely won't matter
extraData: "0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa",
// Good for specifying the initial gas limit.
gasLimit: "0x1388"
} Alternatively, we could create our own config. Something like: {
accounts: {
"0x1234...": {
balance: ...
private_key: ...
}
},
coinbase: "0xabcd...",
// other options...
} The good thing about using the genesis.json format is that the TestRPC could share configuration with other Ethereum clients that support it. The bad thing about it is there's extra config that likely won't matter to the TestRPC. In both cases, however, setting initial accounts and their private keys will be one of the main features. |
@axic Looks like we posted at the same time.
Completely agree. And supporting keystore files would be 💥 💰 🎉 I'm leaning toward 1 and 3. I suppose the question is: Should we also support |
@tcoulter if both genesis and the keystore is supported probably there is no need for that tbh. (You can still use bits of the PR - the first two commits.) |
being able to set a full genesis is awesome, but my primary usage is just getting ether in an externally managed account. currently i do this by starting the testrpc and sending a tx from one of the managed accounts giving ether to my account. but it adds another setup step to the process. all im looking for is |
@kumavis The jury's still out on whether this should be merged, but you can write a quick script that will do this for you: var TestRPC = require("ethereumjs-testrpc");
var Web3 = require("web3");
var server = TestRPC.server();
server.listen(8545, function(err, accounts) {
if (err) throw err;
var web3 = new Web3();
web3.setProvider(new Web3.providers.HttpProvider("http://localhost:8545"));
web3.eth.sendTransaction({
from: accounts[0],
to: "0x1234..." // your address,
value: 100000000000 // a gazillion
}, function(err) {
if (err) throw err;
console.log("Success!");
});
}); This will fire up a TestRPC server and transfer the balances all in one go. |
How about having
|
@axic there are no keystore filesm, everything is in memory |
@kumavis - I think he's suggesting copying over keystore files from geth.
|
@kumavis it has been suggested a few comments up that it could be possible to support keystore files, too |
Just an update regarding the switch to TestRPC: ran into some sort of non-deterministic behavior which led to certain tests in Dapple failing. Ended up being easier to just update EtherSim's dependencies. Will keep an eye on TestRPC going forward, though. If you're interested in poking around yourself, the branch with the sometimes-failing tests is at https://github.com/ryepdx/dapple/tree/testRPC |
Will definitely check it out @ryepdx. Can you tell me which tests I should
|
|
@ryepdx Can you create a ticket that I can comment on on your dapple branch? I'd like to move this discussion there. If not, can you create a new TestRPC ticket for your specific issue? I have some questions, but don't want to bog down this ticket. @axic @kumavis - I've been coming around to merging this PR, so the functionality exists at least for the short term. All opposed say "eye". |
Update on this. I'm adding a feature that will make the testrpc initial state deterministic, mostly to debug a race condition with the testrpc itself. This PR will be included with that feature. If all goes well, expect something today. (famous last words) |
…. Add -a/--accounts options to specify how many accounts you want to create.
Merged this PR. Thanks @axic! Along with it I added two other options:
This is in addition to @axic's |
Also added one more option:
|
Great stuff, thanks @tcoulter! One note on the deterministic feature, it would be still very useful to either:
One small risk I see is if in the future some other code is referenced by addAccount which uses the rng, then it won't generate the same 10 accounts. |
Good feature requests @axic, totally agree. Regarding:
Can you elaborate? I'm not sure I understand. |
It will only create the same set of accounts, if the following code is strictly run in succession and nothing else uses
Right now |
Speaking of account creation, maybe you could use the lightweight HD wallet feature from ethereumjs-wallet and just generate 10 accounts on a specific HD path? 😎 |
@axic I think that's handled, mostly due to the initialization code in the Manager. Requests won't be pushed through until the accounts have been created. The only other thing that could use the rng in that case is more of TestRPC's initialization. Relevant code: |
I'm not well versed in the lightwallet, but I will accept a PR. :) What benefit would that provide other than being fancy? This is a mock ethereum client so we don't need to be (cryptographically)secure after all. |
Oh, hmm. If we use the lightwallet, that means the private keys are deterministic as well correct? |
Yes, it would be fully deterministic and users could easily generate the same set. No magic required from testrpc's part. |
Sample code: const bip39 = require('bip39')
const hdkey = require('ethereumjs-wallet/hdkey')
var mnemonic = 'awake book subject inch gentle blur grant damage process float month clown'
var wallet = hdkey.fromMasterSeed(bip39.mnemonicToSeed(mnemonic)
var account = wallet.derivePath("m/44'/60'/0'/0/" + index) // index is a number
var address = account.getWallet().getAddressString() // 0x prefixed String
var publicKey = account.getWallet().getPublicKey() // Buffer
var secretkey = account.getWallet().getPrivateKey() // Buffer If you want it to be really easy to use, offer the configurability of:
|
@axic And you'd do this 10 times like we're doing now? Only issue is mnemonic's are fairly nasty from a UI perspective. Imagine having to input the pneumonic on the command line. If only there were a less secure, easier to use version (TestRPC doesn't need security). I might opt to simply print out the private keys. |
Although -- thinking out loud at this point -- if the |
You do On a commandline: Assuming testrpc has a default mnemonic built in, the user could use import this mnemonic into the client app too. Printing the private key on top of that I think is a useful feature anyway. |
Ya, I'm 👍, we should support it. I created a new ticket so we can discuss there: #42 |
It also adds a command line argument
--account=1f1f...
which can be passed multiple times to enable more accounts.