-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from pipermerriam/piper/fix-clientVersion-to-b…
…e-correct implement and test the personal api
- Loading branch information
Showing
12 changed files
with
228 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
Werkzeug>=0.11.10 | ||
json-rpc>=1.10.3 | ||
# TODO: bump this once the next version of pyethereum is released. | ||
ethereum>=1.3.6 | ||
rlp>=0.4.4 | ||
ethereum-tester-client>=0.3.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import pytest | ||
|
||
|
||
@pytest.fixture() | ||
def account_password(): | ||
return "a-password" | ||
|
||
|
||
@pytest.fixture() | ||
def account_private_key(): | ||
from eth_tester_client.utils import mk_random_privkey | ||
return mk_random_privkey() | ||
|
||
|
||
@pytest.fixture() | ||
def account_public_key(account_private_key): | ||
from ethereum.utils import privtoaddr | ||
from eth_tester_client.utils import encode_address | ||
return encode_address(privtoaddr(account_private_key)) | ||
|
||
|
||
@pytest.fixture() | ||
def password_account(rpc_client, accounts, account_password, | ||
account_private_key, account_public_key): | ||
from eth_tester_client.utils import normalize_address | ||
address = rpc_client( | ||
'personal_importRawKey', | ||
[account_private_key, account_password], | ||
) | ||
assert normalize_address(address) == normalize_address(account_public_key) | ||
|
||
initial_balance = 1000000000000000000000 # 1,000 ether | ||
|
||
rpc_client('eth_sendTransaction', [{ | ||
'from': accounts[0], | ||
'to': address, | ||
'value': initial_balance, | ||
}]) | ||
|
||
assert rpc_client('eth_getBalance', [address]) == initial_balance | ||
return address |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from eth_tester_client.utils import ( | ||
normalize_address, | ||
mk_random_privkey, | ||
) | ||
|
||
|
||
def test_personal_importRawKey(accounts, rpc_client): | ||
initial_accounts = rpc_client('personal_listAccounts') | ||
|
||
private_key = mk_random_privkey() | ||
|
||
new_account = rpc_client('personal_importRawKey', [private_key, 'a-password']) | ||
n_new_account = normalize_address(new_account) | ||
|
||
assert n_new_account in {normalize_address(acct) for acct in rpc_client('personal_listAccounts')} | ||
assert rpc_client('personal_unlockAccount', [new_account, 'a-password']) is True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from eth_tester_client.utils import ( | ||
normalize_address, | ||
) | ||
|
||
|
||
def test_personal_listAccounts(accounts, rpc_client): | ||
actual = rpc_client('personal_listAccounts') | ||
n_actual = {normalize_address(acct) for acct in actual} | ||
n_expected = {normalize_address(acct) for acct in accounts} | ||
|
||
assert n_actual == n_expected |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import pytest | ||
|
||
from eth_tester_client.utils import ( | ||
normalize_address, | ||
mk_random_privkey, | ||
) | ||
|
||
|
||
def test_personal_lockAccount(accounts, rpc_client, password_account, account_password): | ||
assert rpc_client('personal_unlockAccount', [password_account, account_password]) | ||
|
||
initial_balance = rpc_client('eth_getBalance', [accounts[1]]) | ||
|
||
# confirm it's unlocked | ||
rpc_client('eth_sendTransaction', [{ | ||
'from': password_account, | ||
'to': accounts[1], | ||
'value': 1234, | ||
}]) | ||
after_balance = rpc_client('eth_getBalance', [accounts[1]]) | ||
|
||
assert after_balance - initial_balance == 1234 | ||
|
||
assert rpc_client('personal_lockAccount', [password_account]) | ||
|
||
# sanity check | ||
before_balance = rpc_client('eth_getBalance', [accounts[2]]) | ||
|
||
with pytest.raises(AssertionError): | ||
# confirm it's now locked | ||
rpc_client('eth_sendTransaction', [{ | ||
'from': password_account, | ||
'to': accounts[2], | ||
'value': 1234, | ||
}]) | ||
|
||
# sanity check | ||
assert rpc_client('eth_getBalance', [accounts[2]]) == before_balance |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
def test_personal_newAccount(rpc_client): | ||
initial_accounts = rpc_client('personal_listAccounts') | ||
|
||
new_account = rpc_client('personal_newAccount', ['some-password']) | ||
|
||
assert new_account not in initial_accounts | ||
assert new_account in rpc_client('personal_listAccounts') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import pytest | ||
|
||
|
||
def test_personal_sendTransaction(accounts, rpc_client, password_account, account_password): | ||
initial_balance = rpc_client('eth_getBalance', [accounts[1]]) | ||
|
||
# confirm it fails with a bad password | ||
with pytest.raises(AssertionError): | ||
rpc_client('personal_sendTransaction', [{ | ||
'from': password_account, | ||
'to': accounts[1], | ||
'value': 1234, | ||
}, "incorrect-password"]) | ||
assert rpc_client('eth_getBalance', [accounts[1]]) == initial_balance | ||
|
||
rpc_client('personal_sendTransaction', [{ | ||
'from': password_account, | ||
'to': accounts[1], | ||
'value': 1234, | ||
}, account_password]) | ||
after_balance = rpc_client('eth_getBalance', [accounts[1]]) | ||
|
||
assert after_balance - initial_balance == 1234 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import pytest | ||
|
||
from eth_tester_client.utils import ( | ||
normalize_address, | ||
mk_random_privkey, | ||
) | ||
|
||
|
||
def test_personal_unlockAccount(accounts, rpc_client, password_account, account_password): | ||
initial_balance = rpc_client('eth_getBalance', [accounts[1]]) | ||
|
||
# confirm it didn't start unlocked | ||
with pytest.raises(AssertionError): | ||
rpc_client('eth_sendTransaction', [{ | ||
'from': password_account, | ||
'to': accounts[2], | ||
'value': 1234, | ||
}]) | ||
assert rpc_client('eth_getBalance', [accounts[1]]) == initial_balance | ||
|
||
assert not rpc_client('personal_unlockAccount', [password_account, 'not-correct-password']) | ||
|
||
# confirm it didn't get unlocked. | ||
with pytest.raises(AssertionError): | ||
rpc_client('eth_sendTransaction', [{ | ||
'from': password_account, | ||
'to': accounts[2], | ||
'value': 1234, | ||
}]) | ||
assert rpc_client('eth_getBalance', [accounts[1]]) == initial_balance | ||
|
||
assert rpc_client('personal_unlockAccount', [password_account, account_password]) | ||
|
||
# confirm it's unlocked | ||
rpc_client('eth_sendTransaction', [{ | ||
'from': password_account, | ||
'to': accounts[1], | ||
'value': 1234, | ||
}]) | ||
after_balance = rpc_client('eth_getBalance', [accounts[1]]) | ||
|
||
assert after_balance - initial_balance == 1234 |