Moves get_channel,get_stream out of Class into their own functions

This commit is contained in:
Oleg Silkin 2019-06-12 20:25:32 -04:00 committed by Lex Berezhny
parent 8e0888b846
commit 636f36ebad

View file

@ -25,47 +25,47 @@ def get_tx():
return Transaction().add_inputs([get_input()])
def get_channel(claim_name='@foo'):
channel_txo = Output.pay_claim_name_pubkey_hash(CENT, claim_name, Claim(), b'abc')
channel_txo.generate_channel_private_key()
get_tx().add_outputs([channel_txo])
return channel_txo
def get_stream(claim_name='foo'):
stream_txo = Output.pay_claim_name_pubkey_hash(CENT, claim_name, Claim(), b'abc')
get_tx().add_outputs([stream_txo])
return stream_txo
class TestSigningAndValidatingClaim(AsyncioTestCase):
@staticmethod
def get_channel():
channel_txo = Output.pay_claim_name_pubkey_hash(CENT, '@foo', Claim(), b'abc')
channel_txo.generate_channel_private_key()
get_tx().add_outputs([channel_txo])
return channel_txo
@staticmethod
def get_stream():
stream_txo = Output.pay_claim_name_pubkey_hash(CENT, 'foo', Claim(), b'abc')
get_tx().add_outputs([stream_txo])
return stream_txo
def test_successful_create_sign_and_validate(self):
channel = self.get_channel()
stream = self.get_stream()
channel = get_channel()
stream = get_stream()
stream.sign(channel)
self.assertTrue(stream.is_signed_by(channel))
def test_fail_to_validate_on_wrong_channel(self):
stream = self.get_stream()
stream.sign(self.get_channel())
self.assertFalse(stream.is_signed_by(self.get_channel()))
stream = get_stream()
stream.sign(get_channel())
self.assertFalse(stream.is_signed_by(get_channel()))
def test_fail_to_validate_altered_claim(self):
channel = self.get_channel()
stream = self.get_stream()
channel = get_channel()
stream = get_stream()
stream.sign(channel)
self.assertTrue(stream.is_signed_by(channel))
stream.claim.stream.title = 'hello'
self.assertFalse(stream.is_signed_by(channel))
def test_valid_private_key_for_cert(self):
channel = self.get_channel()
channel = get_channel()
self.assertTrue(channel.is_channel_private_key(channel.private_key))
def test_fail_to_load_wrong_private_key_for_cert(self):
channel = self.get_channel()
self.assertFalse(channel.is_channel_private_key(self.get_channel().private_key))
channel = get_channel()
self.assertFalse(channel.is_channel_private_key(get_channel().private_key))
class TestValidatingOldSignatures(AsyncioTestCase):