def setUp(self):
        FlorinCoinSrv.Blocks = { hash(i): { 'address': 0, 'amount': 0, 'tx-comment': '-', 'tx': [], 'height': i, 'hash': hash(i), } for i in range(10) }
#       FlorinCoinSrv.Transactions = { }
        flosrv.Transactions = { }
        self.srv = FlorinCoinSrv()
        self.flo = Florincoin(self.srv.url, self.srv.username, self.srv.passwd)
        self.sync = Synchronizer(self.flo, MockCloud())
class FlorincoinTest(unittest.TestCase):
    DATA_SIZE = 2*1024

    def setUp(self):
        FlorinCoinSrv.Blocks = { hash(i): { 'address': 0, 'amount': 0, 'tx-comment': '-', 'tx': [], 'height': i, 'hash': hash(i), } for i in range(10) }
#       FlorinCoinSrv.Transactions = { }
        flosrv.Transactions = { }
        self.srv = FlorinCoinSrv()
        self.flo = Florincoin(self.srv.url, self.srv.username, self.srv.passwd)
        self.sync = Synchronizer(self.flo, MockCloud())

    def tearDown(self):
        del self.flo
        del self.srv

    def test_misc(self):
        '''Check various jsonrpc queries
        '''
        block_count = self.flo.block_count()
        assert block_count
        response = self.flo.balance()
        assert response
        response = list(self.flo.blocks(0, block_count))
        assert len(response) == block_count

        response = self.flo.address(0)
        assert response

    def test_transactions(self):
        invalid_block = {
            'tx': 0,
        }
        response = self.flo.transactions(invalid_block)
        assert response

    def test_send(self):
        '''Test 'sendtoaddress' method used to store metadata
        '''
        large_data_corpus = b'i' * (FlorincoinTest.DATA_SIZE)
        txid = self.flo.send_data_address(large_data_corpus, 'addr', Decimal('0.01'))
        assert txid

        assert txid in self.srv.httpd.Transactions

    @unittest.skip('unrealistic test case')
    def test_send_high_entropy(self):
        high_entropy = os.urandom(FlorincoinTest.DATA_SIZE)
        response = self.flo.send_data_address(high_entropy, 'addr', Decimal('0.01'))
        assert response

    def test_roundtrip(self):
        large_data_corpus = b'R' * (FlorincoinTest.DATA_SIZE)
        txid = self.flo.send_data_address(large_data_corpus, 'addr', Decimal('0.01'))
        assert txid != None
        assert txid in self.srv.httpd.Transactions

        tx_entry = self.flo._get_transaction(txid)
        assert 'tx-comment' in tx_entry

#       self.sync.scan_database()
        self.sync.scan_blockchain()
        assert txid in self.srv.httpd.Transactions
        assert txid in self.sync.cloud.data_loaded