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

Commit 307ae60

Browse files
committed
Added direct_tx method to tester
1 parent 3a0d4d7 commit 307ae60

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

ethereum/tests/test_contracts.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,7 +1088,7 @@ def kall(a:arr, b, c:arr, d:str, e):
10881088
def test_multiarg_code():
10891089
c = tester.Chain()
10901090
x = c.contract(multiarg_code, language='serpent')
1091-
o = x.kall([1, 2, 3], 4, [5, 6, 7], "doge", 8)
1091+
o = x.kall([1, 2, 3], 4, [5, 6, 7], b"doge", 8)
10921092
assert o == [862541, safe_ord('d') + safe_ord('o') + safe_ord('g'), 4]
10931093

10941094
peano_code = """
@@ -1378,7 +1378,7 @@ def mcopy_test(foo:str, a, b, c):
13781378
def test_mcopy():
13791379
c = tester.Chain()
13801380
x = c.contract(mcopy_code, language='serpent')
1381-
assert x.mcopy_test("123", 5, 6, 259) == \
1381+
assert x.mcopy_test(b"123", 5, 6, 259) == \
13821382
b'\x00'*31+b'\x05'+b'\x00'*31+b'\x06'+b'\x00'*30+b'\x01\x03'+b'123'
13831383

13841384

@@ -1493,7 +1493,7 @@ def test_double_array():
14931493
c = tester.Chain()
14941494
x = c.contract(double_array_code, language='serpent')
14951495
assert x.foo([1, 2, 3], [4, 5, 6, 7]) == [123, 4567]
1496-
assert x.bar([1, 2, 3], "moo", [4, 5, 6, 7]) == [123, 4567]
1496+
assert x.bar([1, 2, 3], b"moo", [4, 5, 6, 7]) == [123, 4567]
14971497

14981498

14991499
abi_logging_code = """
@@ -1527,7 +1527,7 @@ def test_abi_logging():
15271527
x.test_frog(5)
15281528
assert o == [{"_event_type": b"frog", "y": 5}]
15291529
o.pop()
1530-
x.test_moose(7, "nine", 11, [13, 15, 17])
1530+
x.test_moose(7, b"nine", 11, [13, 15, 17])
15311531
assert o == [{"_event_type": b"moose", "a": 7, "b": b"nine",
15321532
"c": 11, "d": [13, 15, 17]}]
15331533
o.pop()

ethereum/tools/tester.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,17 +132,22 @@ def __init__(self, alloc=None, env=None):
132132
self.last_sender = None
133133
self.last_tx = None
134134

135-
def tx(self, sender=k0, to=b'\x00' * 20, value=0, data=b'', startgas=STARTGAS, gasprice=GASPRICE):
136-
sender_addr = privtoaddr(sender)
137-
transaction = Transaction(self.head_state.get_nonce(sender_addr), gasprice, startgas,
138-
to, value, data).sign(sender)
139-
self.last_tx, self.last_sender = transaction, sender
135+
def direct_tx(self, transaction):
136+
self.last_tx, self.last_sender = transaction, None
140137
success, output = apply_transaction(self.head_state, transaction)
141138
self.block.transactions.append(transaction)
142139
if not success:
143140
raise TransactionFailed()
144141
return output
145142

143+
def tx(self, sender=k0, to=b'\x00' * 20, value=0, data=b'', startgas=STARTGAS, gasprice=GASPRICE):
144+
sender_addr = privtoaddr(sender)
145+
transaction = Transaction(self.head_state.get_nonce(sender_addr), gasprice, startgas,
146+
to, value, data).sign(sender)
147+
o = self.direct_tx(transaction)
148+
self.last_sender = sender
149+
return o
150+
146151
def contract(self, sourcecode, args=[], sender=k0, value=0, language='evm', startgas=STARTGAS, gasprice=GASPRICE):
147152
if language == 'evm':
148153
assert len(args) == 0

0 commit comments

Comments
 (0)