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

Commit f75ff85

Browse files
vubvub
authored andcommitted
Switched contract tests to new tester module
1 parent f0b696a commit f75ff85

File tree

2 files changed

+310
-298
lines changed

2 files changed

+310
-298
lines changed

ethereum/tester2.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from ethereum.utils import sha3, privtoaddr, int_to_addr, to_string
1+
from ethereum.utils import sha3, privtoaddr, int_to_addr, to_string, big_endian_to_int
22
from ethereum.parse_genesis_declaration import mk_basic_state
33
from ethereum import chain
44
from ethereum.transactions import Transaction
@@ -90,6 +90,10 @@ def kall(self, *args, **kwargs):
9090
startgas=kwargs.get('startgas', STARTGAS)
9191
)
9292

93+
if result is False:
94+
return result
95+
if result == b'':
96+
return None
9397
o = self.translator.decode(function_name, result)
9498
return o[0] if len(o) == 1 else o
9599
return kall
@@ -136,9 +140,18 @@ def mine(self, number_of_blocks=1, coinbase=a0):
136140
assert self.chain.add_block(self.block)
137141
assert self.head_state.trie.root_hash == self.chain.state.trie.root_hash
138142
for i in range(1, number_of_blocks):
139-
b = self.cs.block_setup(self.chain, timestamp=self.chain.state.timestamp + 1)
143+
b = self.cs.block_setup(self.chain, timestamp=self.chain.state.timestamp + 14)
140144
pre_seal(self.chain.state.ephemeral_clone(), b)
141145
b = Miner(b).mine(rounds=100, start_nonce=0)
142146
assert self.chain.add_block(b)
143-
self.block = self.cs.block_setup(self.chain, timestamp=self.chain.state.timestamp + 1)
147+
self.block = self.cs.block_setup(self.chain, timestamp=self.chain.state.timestamp + 14)
144148
self.head_state = self.chain.state.ephemeral_clone()
149+
150+
def snapshot(self):
151+
return self.head_state.snapshot(), len(self.block.transactions), self.block.number
152+
153+
def revert(self, snapshot):
154+
state_snapshot, txcount, blknum = snapshot
155+
assert blknum == self.block.number
156+
self.block.transactions = self.block.transactions[:txcount]
157+
self.head_state.revert(state_snapshot)

0 commit comments

Comments
 (0)