Example #1
0
    def test_creation(self):
        sk, vk = wallet.new()
        code = 'while True: do_that_thing'

        contract_tx = ContractTransactionBuilder.create_contract_tx(
            sender_sk=sk, code_str=code)

        self.assertEquals(contract_tx.sender, vk)
        self.assertEquals(contract_tx.code, code)
 def test_creation(self):
     """
     Tests that a created block data reply has the expected properties
     """
     sk = wallet.new()[0]
     contracts = [
         ContractTransactionBuilder.create_contract_tx(sk, code_str) \
         for code_str in ['some random binary', 'some deterministic binary', 'While True: self.eatAss()']
     ]
     tx_binaries = [c.serialize() for c in contracts]
     bdr = TransactionReply.create(tx_binaries)
     self.assertEqual(contracts, bdr.transactions)
    def test_validate_matches_request_no_match(self):
        """
        Tests that a created block data reply has the expected properties
        """
        sk = wallet.new()[0]
        code_strs = ['some random binary', 'some deterministic binary', 'While True: self.eatAss()']
        contracts = [
            ContractTransactionBuilder.create_contract_tx(sk, code_str) \
            for code_str in code_strs
        ]
        tx_binaries = [c.serialize() for c in contracts]

        tx_hashes = [Hasher.hash(cs+b'bbb') for cs in tx_binaries]
        bdr_req = TransactionRequest.create(tx_hashes)

        bdr_rep = TransactionReply.create(tx_binaries)
        assert not bdr_rep.validate_matches_request(bdr_req)
    def test_serialization(self):
        """
        Tests that a message successfully serializes and deserializes. The deserialized object should have the same
        properties as the original one before it was serialized.
        """
        sk = wallet.new()[0]
        code_strs = ['some random binary', 'some deterministic binary', 'While True: self.eatAss()']
        contracts = [
            ContractTransactionBuilder.create_contract_tx(sk, code_str) \
            for code_str in code_strs
        ]
        tx_binaries = [c.serialize() for c in contracts]
        original = TransactionReply.create(tx_binaries)
        original_binary = original.serialize()
        clone = TransactionReply.from_bytes(original_binary)  # deserialize byte object

        self.assertEqual(original.transactions, clone.transactions)