fixed wallet/server/test_sqldb.py tests

This commit is contained in:
Lex Berezhny 2019-05-05 19:16:51 -04:00
parent 091bef1ead
commit d2608bdf43
2 changed files with 14 additions and 14 deletions

View file

View file

@ -34,9 +34,11 @@ class TestSQLDB(unittest.TestCase):
self.sql = SQLDB(':memory:') self.sql = SQLDB(':memory:')
self.sql.open() self.sql.open()
self._current_height = 0 self._current_height = 0
self._txos = {}
def _make_tx(self, output): def _make_tx(self, output):
tx = get_tx().add_outputs([output]) tx = get_tx().add_outputs([output])
self._txos[output.ref.hash] = output
return OldWalletServerTransaction(tx), tx.hash return OldWalletServerTransaction(tx), tx.hash
def get_channel(self, title, amount, name='@foo'): def get_channel(self, title, amount, name='@foo'):
@ -68,8 +70,8 @@ class TestSQLDB(unittest.TestCase):
) )
def get_controlling(self): def get_controlling(self):
for claim in self.sql.execute("select claim.*, raw from claimtrie natural join claim natural join tx"): for claim in self.sql.execute("select claim.* from claimtrie natural join claim"):
txo = Transaction(claim['raw']).outputs[0] txo = self._txos[claim['txo_hash']]
controlling = txo.claim.stream.title, claim['amount'], claim['effective_amount'], claim['activation_height'] controlling = txo.claim.stream.title, claim['amount'], claim['effective_amount'], claim['activation_height']
return controlling return controlling
@ -77,9 +79,8 @@ class TestSQLDB(unittest.TestCase):
controlling = self.get_controlling() controlling = self.get_controlling()
active = [] active = []
for claim in self.sql.execute( for claim in self.sql.execute(
f"select claim.*, raw from claim join tx using (tx_hash) " f"select * from claim where activation_height <= {self._current_height}"):
f"where activation_height <= {self._current_height}"): txo = self._txos[claim['txo_hash']]
txo = Transaction(claim['raw']).outputs[0]
if controlling and controlling[0] == txo.claim.stream.title: if controlling and controlling[0] == txo.claim.stream.title:
continue continue
active.append((txo.claim.stream.title, claim['amount'], claim['effective_amount'], claim['activation_height'])) active.append((txo.claim.stream.title, claim['amount'], claim['effective_amount'], claim['activation_height']))
@ -88,9 +89,8 @@ class TestSQLDB(unittest.TestCase):
def get_accepted(self): def get_accepted(self):
accepted = [] accepted = []
for claim in self.sql.execute( for claim in self.sql.execute(
f"select claim.*, raw from claim join tx using (tx_hash) " f"select * from claim where activation_height > {self._current_height}"):
f"where activation_height > {self._current_height}"): txo = self._txos[claim['txo_hash']]
txo = Transaction(claim['raw']).outputs[0]
accepted.append((txo.claim.stream.title, claim['amount'], claim['effective_amount'], claim['activation_height'])) accepted.append((txo.claim.stream.title, claim['amount'], claim['effective_amount'], claim['activation_height']))
return accepted return accepted
@ -151,19 +151,19 @@ class TestSQLDB(unittest.TestCase):
state( state(
controlling=('Claim D', 300*COIN, 300*COIN, 1051), controlling=('Claim D', 300*COIN, 300*COIN, 1051),
active=[ active=[
('Claim A', 10*COIN, 24*COIN, 1051), ('Claim A', 10*COIN, 24*COIN, 13),
('Claim B', 20*COIN, 20*COIN, 1051), ('Claim B', 20*COIN, 20*COIN, 1031),
('Claim C', 50*COIN, 50*COIN, 1051)], ('Claim C', 50*COIN, 50*COIN, 1051)],
accepted=[] accepted=[]
) )
# beyond example # beyond example
advance(1052, [self.get_stream_update(stream, 290*COIN)]) advance(1052, [self.get_stream_update(stream, 290*COIN)])
state( state(
controlling=('Claim A', 290*COIN, 304*COIN, 1052), controlling=('Claim A', 290*COIN, 304*COIN, 13),
active=[ active=[
('Claim B', 20*COIN, 20*COIN, 1052), ('Claim B', 20*COIN, 20*COIN, 1031),
('Claim C', 50*COIN, 50*COIN, 1052), ('Claim C', 50*COIN, 50*COIN, 1051),
('Claim D', 300*COIN, 300*COIN, 1052), ('Claim D', 300*COIN, 300*COIN, 1051),
], ],
accepted=[] accepted=[]
) )