Skip to content
This repository was archived by the owner on Jan 21, 2022. It is now read-only.

Commit c9c30e6

Browse files
authored
Merge pull request #177 from ethereumjs/develop
3.0.0
2 parents ea7bdf2 + 2ec25b3 commit c9c30e6

21 files changed

Lines changed: 1512 additions & 177 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ TODO
33
*.log
44
.eslintrc.js
55
.tern-project
6+
.DS_Store

README.md

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Options:
2929
* `-a` or `--accounts`: Specify the number of accounts to generate at startup.
3030
* `-b` or `--blocktime`: Specify blocktime in seconds for automatic mining. Default is 0 and no auto-mining.
3131
* `-d` or `--deterministic`: Generate deterministic addresses based on a pre-defined mnemonic.
32+
* `-n` or `--secure`: Lock available accounts by default (good for third party transaction signing)
3233
* `-m` or `--mnemonic`: Use a specific HD wallet mnemonic to generate initial addresses.
3334
* `-p` or `--port`: Port number to listen on. Defaults to 8545.
3435
* `-h` or `--hostname`: Hostname to listen on. Defaults to Node's `server.listen()` [default](https://nodejs.org/api/http.html#http_server_listen_port_hostname_backlog_callback).
@@ -38,15 +39,31 @@ Options:
3839
* `-f` or `--fork`: Fork from another currently running Ethereum client at a given block. Input should be the HTTP location and port of the other client, e.g. `http://localhost:8545`. You can optionally specify the block to fork from using an `@` sign: `http://localhost:8545@1599200`.
3940
* `--debug`: Output VM opcodes for debugging
4041

41-
You can also specify `--account=...` (no 's') any number of times passing arbitrary private keys and their associated balances to generate initial addresses:
42+
Special Options:
4243

43-
```
44-
$ testrpc --account="<privatekey>,balance" [--account="<privatekey>,balance"]
45-
```
44+
* `--account`: Specify `--account=...` (no 's') any number of times passing arbitrary private keys and their associated balances to generate initial addresses:
45+
46+
```
47+
$ testrpc --account="<privatekey>,balance" [--account="<privatekey>,balance"]
48+
```
49+
50+
Note that private keys are 64 characters long, and must be input as a 0x-prefixed hex string. Balance can either be input as an integer or 0x-prefixed hex value specifying the amount of wei in that account.
51+
52+
An HD wallet will not be created for you when using `--account`.
53+
54+
* `-u` or `--unlock`: Specify `--unlock ...` any number of times passing either an address or an account index to unlock specific accounts. When used in conjunction with `--secure`, `--unlock` will override the locked state of specified accounts.
55+
56+
```
57+
$ testrpc --secure --unlock "0x1234..." --unlock "0xabcd..."
58+
```
59+
60+
You can also specify a number, unlocking accounts by their index:
4661

47-
Note that private keys are 64 characters long, and must be input as a 0x-prefixed hex string. Balance can either be input as an integer or 0x-prefixed hex value specifying the amount of wei in that account.
62+
```
63+
$ testrpc --secure -u 0 -u 1
64+
```
4865

49-
An HD wallet will not be created for you when using `--account`.
66+
This feature can also be used to impersonate accounts and unlock addresses you wouldn't otherwise have access to. When used with the `--fork` feature, you can use the TestRPC to make transactions as any address on the blockchain, which is very useful for testing and dynamic analysis.
5067

5168
##### Library
5269

@@ -76,6 +93,8 @@ Both `.provider()` and `.server()` take a single object which allows you to spec
7693
* `"total_accounts"`: `number` - Number of accounts to generate at startup.
7794
* `"fork"`: `string` - Same as `--fork` option above.
7895
* `"time"`: `Date` - Date that the first block should start. Use this feature, along with the `evm_increaseTime` method to test time-dependent code.
96+
* `"locked"`: `boolean` - whether or not accounts are locked by default.
97+
* `"unlocked_accounts"`: `Array` - array of addresses or address indexes specifying which accounts should be unlocked.
7998

8099
# IMPLEMENTED METHODS
81100

@@ -99,6 +118,8 @@ The RPC methods currently implemented are:
99118
* `eth_getLogs`
100119
* `eth_getStorageAt`
101120
* `eth_getTransactionByHash`
121+
* `eth_getTransactionByBlockHashAndIndex`
122+
* `eth_getTransactionByBlockNumberAndIndex`
102123
* `eth_getTransactionCount`
103124
* `eth_getTransactionReceipt`
104125
* `eth_hashrate`
@@ -113,6 +134,9 @@ The RPC methods currently implemented are:
113134
* `net_listening`
114135
* `net_peerCount`
115136
* `net_version`
137+
* `miner_start`
138+
* `miner_stop`
139+
* `rpc_modules`
116140
* `web3_clientVersion`
117141
* `web3_sha3`
118142

@@ -121,7 +145,7 @@ There’s also special non-standard methods that aren’t included within the or
121145
* `evm_snapshot` : Snapshot the state of the blockchain at the current block. Takes no parameters. Returns the integer id of the snapshot created.
122146
* `evm_revert` : Revert the state of the blockchain to a previous snapshot. Takes a single parameter, which is the snapshot id to revert to. If no snapshot id is passed it will revert to the latest snapshot. Returns `true`.
123147
* `evm_increaseTime` : Jump forward in time. Takes one parameter, which is the amount of time to increase in seconds. Returns the total time adjustment, in seconds.
124-
* `evm_mine` : Force a block to be mined. Takes no parameters.
148+
* `evm_mine` : Force a block to be mined. Takes no parameters. Mines a block independent of whether or not mining is started or stopped.
125149

126150
# TESTING
127151

bin/testrpc

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
#!/usr/bin/env node
2-
var argv = require('yargs').argv;
2+
var yargs = require('yargs');
33
var TestRPC = require('..');
44
var pkg = require("../package.json");
55
var util = require("ethereumjs-util");
66
var URL = require("url");
77
var Web3 = require("web3");
88
var web3 = new Web3(); // Used only for its BigNumber library.
99

10+
yargs
11+
.option("unlock", {
12+
type: "string",
13+
alias: "u"
14+
});
15+
16+
var argv = yargs.argv;
17+
1018
function parseAccounts(accounts) {
1119
function splitAccount(account) {
1220
account = account.split(',')
@@ -32,6 +40,10 @@ if (argv.d || argv.deterministic) {
3240
argv.s = "TestRPC is awesome!";
3341
}
3442

43+
if (typeof argv.unlock == "string") {
44+
argv.unlock = [argv.unlock];
45+
}
46+
3547
var options = {
3648
port: argv.p || argv.port || "8545",
3749
hostname: argv.h || argv.hostname,
@@ -43,9 +55,11 @@ var options = {
4355
gasPrice: argv.g || argv.gasPrice,
4456
gasLimit: argv.l || argv.gasLimit,
4557
accounts: parseAccounts(argv.account),
58+
unlocked_accounts: argv.unlock,
4659
fork: argv.f || argv.fork || false,
4760
network_id: argv.i || argv.networkId,
4861
verbose: argv.v || argv.verbose,
62+
secure: argv.n || argv.secure || false,
4963
logger: console
5064
}
5165

@@ -84,7 +98,13 @@ server.listen(options.port, options.hostname, function(err, state) {
8498
var addresses = Object.keys(accounts);
8599

86100
addresses.forEach(function(address, index) {
87-
console.log("(" + index + ") " + address);
101+
var line = "(" + index + ") " + address;
102+
103+
if (state.isUnlocked(address) == false) {
104+
line += " 🔒";
105+
}
106+
107+
console.log(line);
88108
});
89109

90110
console.log("");

0 commit comments

Comments
 (0)