Skip to content
This repository was archived by the owner on May 23, 2023. It is now read-only.

Commit a32bd45

Browse files
committed
Implement EIP155 specific tx test #417
This new testcase aims to reproduce ethereum/EIPs#155
1 parent e116dec commit a32bd45

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

ethereum/tests/test_transactions.py

+55
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,61 @@
1717
encode_hex('')
1818

1919

20+
def test_eip155_transaction():
21+
"""Replicate the example from https://github.com/ethereum/eips/issues/155
22+
and ensure old style tx fails and new style transaction validates.
23+
"""
24+
nonce = 9
25+
gasprice = 20 * 10 ** 9
26+
startgas = 21000
27+
to = "3535353535353535353535353535353535353535"
28+
value = 10 ** 18
29+
data = ''
30+
private_key = "4646464646464646464646464646464646464646464646464646464646464646"
31+
old_style = transactions.Transaction(nonce, gasprice, startgas, to, value, data)
32+
new_style = transactions.EIP155Transaction(nonce, gasprice, startgas, to, value, data)
33+
34+
new_signing_data = "ec098504a817c800825208943535353535353535353535353535353535353535880de0b6b3a764000080128080"
35+
36+
new_signing_data_sedes = transactions.Transaction(
37+
new_style.nonce,
38+
new_style.gasprice,
39+
new_style.startgas,
40+
new_style.to,
41+
new_style.value,
42+
new_style.data,
43+
18,
44+
0,
45+
0
46+
)
47+
48+
assert rlp.encode(new_signing_data_sedes, transactions.Transaction) == decode_hex(new_signing_data)
49+
50+
new_signing_hash = "ac9813f00ec955e65a50cc778243f6c22dcfe9d64253462b16187f1c99e0a8fa"
51+
52+
assert encode_hex(utils.sha3(rlp.encode(new_signing_data_sedes, transactions.Transaction))) == new_signing_hash
53+
54+
new_v, new_r, new_s = (
55+
38,
56+
11616088462479929722209511590713166362238170772128436772837473395614974864269L,
57+
19832642777361886450959973766490059191918327598807281226090984148355472235004L
58+
)
59+
60+
new_style_signed = "f86e098504a817c800825208943535353535353535353535353535353535353535880de0b6b3a7640000801ca1a019ae791bb8378a38bb83f5b930fe78a0320cec27d86e5e258c69f0fa9541eb8da1a02bd8e0c5bde4c0800238ce5a59d2f3ce723f1e84a62cab53d961fe3b019d19fc"
61+
62+
old_style.sign(private_key)
63+
64+
new_style.sign(private_key)
65+
66+
assert new_style.v == new_v
67+
assert new_style.r == new_r
68+
assert new_style.s == new_s
69+
70+
assert encode_hex(rlp.encode(new_style)) == new_style_signed
71+
72+
# TODO: test deserialize new style rlp fails with old_style Transaction class
73+
74+
2075
def test_transaction(filename, testname, testdata):
2176
testdata = fixture_to_bytes(testdata)
2277

0 commit comments

Comments
 (0)