def test_createNewRecord(self): ledger = bitcoin_ledger.BitcoinLedger() self.assertIsNotNone(ledger) new_uuid = str(uuid.uuid4()).upper() new_ledger_id = ledger.createLedgerRecord(uuid=new_uuid,bitcoinAddr='1JrTrzBJ9LnJVk9Mkt5WccGRMrN2ysRnSQ') self.assertTrue(new_ledger_id > 0) ledger_record = ledger.getLedgerRecord(ledgerId=new_ledger_id) self.assertIsNotNone(ledger_record) self.assertTrue('uuid' in ledger_record) self.assertTrue(ledger_record['uuid'] == new_uuid) self.assertIsNone(ledger_record['pricePaid'])
def test_markPaid(self): new_uuid1 = str(uuid.uuid4()).upper() bitcoin_addr1 = '1JrTrzBJ1LnJVk1Mkt1WccGRMrN2ysRnSQ' ledger = bitcoin_ledger.BitcoinLedger() self.assertIsNotNone(ledger) new_record = ledger.createLedgerRecord(uuid=new_uuid1,bitcoinAddr=bitcoin_addr1) self.assertTrue(new_record > 0) ledger.setBalance(new_record,59000,2) ledger_record = ledger.getLedgerRecord(new_record) self.assertIsNotNone(ledger_record) self.assertEqual(ledger_record['bitcoinBalance'],59000) self.assertEqual(ledger_record['bitcoinConfirmations'],2) self.assertTrue(ledger.markPaid(new_record,59000)) ledger_record = ledger.getLedgerRecord(new_record) self.assertIsNotNone(ledger_record) self.assertIsNotNone(ledger_record['datePaid']) self.assertEqual(ledger_record['pricePaid'],59000)
def __init__(self, screenLogHandler=None, logFile=None): # set up logging self.logger = logging.getLogger(LOG_CHANNEL) self.logger.setLevel(logging.DEBUG) fh = None if logFile == None: fh = logging.FileHandler(LOG_FILE) else: fh = logging.FileHandler(logFile) fh.setLevel(LOG_FILE_LEVEL) formatter = logging.Formatter( '%(asctime)s - %(name)s - %(levelname)s - %(message)s') fh.setFormatter(formatter) self.logger.addHandler(fh) if screenLogHandler: self.logger.addHandler(screenLogHandler) # make sure we can connect to bitcoin client RPC interface self.rpc_conn = AuthServiceProxy( "http://%s:%s@%s:%d" % (RPC_USER, RPC_PASSWD, RPC_HOST, RPC_PORT)) try: self.bitcoin_client_info = self.rpc_conn.getinfo() except JSONRPCException as e: self.logger.error("could not reach bitcoin RPC server: " + str(e)) return None except e: self.logger.error("Core exception: " + str(e)) return None # Initalize modules self.pricing = bitcoin_pricing.BitcoinPricing(logFile=logFile) self.ledger = bitcoin_ledger.BitcoinLedger(logFile=logFile) self.activation = activation.ActivationSignatureGenerator( logFile=logFile) if self.pricing == None or self.ledger == None: self.logger.error( "One or more modules failed to start. Check you configuration!" ) return None
def test_fetchLatestRecords(self): ledger = bitcoin_ledger.BitcoinLedger() self.assertIsNotNone(ledger) new_uuid1 = str(uuid.uuid4()).upper() new_uuid2 = str(uuid.uuid4()).upper() new_uuid3 = str(uuid.uuid4()).upper() bitcoin_addr1 = '1JrTrzBJ8LnJVk9Mkt5WccGRMrN2ysRnSQ' bitcoin_addr2 = '1JrTrzBJ6LnJVk9Mkt5WccGRMrN2ysRnSQ' bitcoin_addr3 = '1JrTrzBJ7LnJVk9Mkt5WccGRMrN2ysRnSQ' new_ledger_id1 = ledger.createLedgerRecord(uuid=new_uuid1,bitcoinAddr=bitcoin_addr1) new_ledger_id2 = ledger.createLedgerRecord(uuid=new_uuid2,bitcoinAddr=bitcoin_addr2,emailAddr='*****@*****.**') new_ledger_id3 = ledger.createLedgerRecord(uuid=new_uuid3,bitcoinAddr=bitcoin_addr3) self.assertTrue(new_ledger_id1 > 0) self.assertTrue(new_ledger_id2 > 0) self.assertTrue(new_ledger_id3 > 0) latestRecords = ledger.latestRecords(0,3) self.assertIsNone(latestRecords[0]['emailAddress']) self.assertEqual(latestRecords[0]['uuid'],new_uuid3) self.assertEqual(latestRecords[0]['id'],new_ledger_id3) self.assertEqual(latestRecords[0]['bitcoinAddress'],bitcoin_addr3) self.assertIsNone(latestRecords[0]['pricePaid']) self.assertEqual(latestRecords[1]['emailAddress'],'*****@*****.**') self.assertEqual(latestRecords[1]['uuid'],new_uuid2) self.assertEqual(latestRecords[1]['id'],new_ledger_id2) self.assertEqual(latestRecords[1]['bitcoinAddress'],bitcoin_addr2) self.assertIsNone(latestRecords[0]['pricePaid']) self.assertIsNone(latestRecords[2]['emailAddress']) self.assertEqual(latestRecords[2]['uuid'],new_uuid1) self.assertEqual(latestRecords[2]['id'],new_ledger_id1) self.assertEqual(latestRecords[2]['bitcoinAddress'],bitcoin_addr1) self.assertIsNone(latestRecords[0]['pricePaid'])
def test_markRefunded(self): new_uuid1 = str(uuid.uuid4()).upper() bitcoin_addr1 = '1JrTrzEF1LnJVk1Mkt1WccGRMrN2ysRnSQ' ledger = bitcoin_ledger.BitcoinLedger() self.assertIsNotNone(ledger) new_record = ledger.createLedgerRecord(uuid=new_uuid1,bitcoinAddr=bitcoin_addr1) self.assertTrue(new_record > 0) ledger.setBalance(new_record,59000,2) ledger_record = ledger.getLedgerRecord(new_record) self.assertIsNotNone(ledger_record) self.assertEqual(ledger_record['bitcoinBalance'],59000) self.assertEqual(ledger_record['bitcoinConfirmations'],2) self.assertTrue(ledger.markPaid(new_record,59000)) ledger_record = ledger.getLedgerRecord(new_record) self.assertIsNotNone(ledger_record) self.assertIsNotNone(ledger_record['datePaid']) self.assertEqual(ledger_record['pricePaid'],59000) self.assertFalse(ledger.markRefunded(new_record,25000,'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855','automatic')) ledger.setRefundAddress(new_record,'1JrTrzBJ8LnJVk9Mkt5WccGRMrN2ysRnSQ') self.assertTrue(ledger.markRefunded(new_record,25000,'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855','automatic'))