Beispiel #1
0
 def test_send_transfer(self):
     """
         Test send_transfer
         Preconditions:
             Seed has at least 1 iota
         Postconditions:
             No error is thrown
             Created bundle is valid
             Address balance has increased by 1 iota
         """
     seed = b'SWMS9HOIE9EKPKWTBKJHTJOX9EU9NNJB9AEDWZPFOBSBQBXBFPYSRCE9SVIHRI9BJAGLSCAMMRUFSQRIJ'
     address = b'ROJLHG9AIQYLSNXZMUABJCVOMCZFILEAVNWKKK9CG9JWISIWX9VCDHCXOIYRFYVUAOAMYGFZWDQWLWHJWTXKJMSPZC'
     bot_api = api(seed)
     bot_db = Database('test_db.db')
     address_index = bot_db.get_address_index()
     new_address = bot_api.get_new_address(address_index)
     starting_balance = bot_api.get_balance(address)
     start_time = time.time()
     bundle = None
     try:
         bundle = bot_api.send_transfer(address, 1, new_address,
                                        address_index)
     except:
         self.fail('Transfer Failed')
     validator = BundleValidator(bundle)
     self.assertTrue(validator.is_valid())
     end_time = time.time()
     end_balance = bot_api.get_balance(address)
     self.assertEqual(end_balance, starting_balance + 1)
     print("Time elapsed: {0}s".format(end_time - start_time))
Beispiel #2
0
 def test_subtract_balance_sunny_1(self):
     bot_db = Database('test_db.db')
     username = '******'
     starting_balance = bot_db.get_user_balance(username)
     bot_db.subtract_balance(username, 10)
     self.assertEqual(bot_db.get_user_balance(username),
                      starting_balance - 10)
Beispiel #3
0
bot_api = api(seed)
reddit = praw.Reddit(user_agent=config.user_agent,
                     client_id=config.client_id,
                     client_secret=config.client_secret,
                     username=config.username,
                     password=config.password)

logging.basicConfig(filename='transactionLogs.log',
                    format='%(levelname)s: %(asctime)s: %(message)s ',
                    level=logging.INFO)

#Message links to be appended to every message/comment reply
help_message = "iotaTipBot is a bot that allows reddit users to send iota to each other through reddit comments. The bot commands are as follows:\n\n* 'Deposit' - Initiates the process of depositing iota into your tipping account\n\n* 'Withdraw' - Withdraw iota from your tipping account. You must put the address you want to withdraw to and the amount of iota in the message.\n\n* 'Balance' - Check the amount of iota you have stored in the bot.\n\n* 'Help' - Sends the help message\n\n* 'Donate' - Get a list of options to help support the project.\n\nThese commands are activated by sending the command to the bot either in the subject or the body of the message.\n\nOnce you have iota in your tipping account you can start tipping! To do this simply reply to a comment with a message of the format: '+<amount> iota'\n\nFor example '+25 iota' will tip 25 iota to the author of the comment you replied to. To tip higher values, you can swap the 'iota' part of the comment with 'miota' to tip megaIota values: '+25 miota' will then tip 25 megaIota.\n\nIf you are new to iota and are looking for more information here are a few useful links:\n\n* [Reddit Newcomer Information](https://www.reddit.com/r/Iota/comments/61rc0c/for_newcomers_all_information_links_you_probably/)\n\n* [IOTA Wallet Download](https://github.com/iotaledger/wallet/releases/)\n\n* [Supply and Units Reference](https://i.imgur.com/lsq4610.jpeg)"
message_links = "\n\n[Deposit](https://np.reddit.com/message/compose/?to=iotaTipBot&subject=Deposit&message=Deposit iota!) | [Withdraw](https://np.reddit.com/message/compose/?to=iotaTipBot&subject=Withdraw&message=I want to withdraw my iota!\namount iota \naddress here) | [Balance](https://np.reddit.com/message/compose/?to=iotaTipBot&subject=Balance&message=I want to check my balance!) | [Help](https://www.reddit.com/r/iotaTipBot/wiki/index) | [Donate](https://np.reddit.com/message/compose/?to=iotaTipBot&subject=Donate&message=I want to support iotaTipBot!) | [What is IOTA?](https://www.youtube.com/watch?v=LyVLq13WfsE)\n"

bot_db = Database()
bot_db_lock = threading.Lock()

deposit_queue = queue.Queue()


def deposits():
    """
    A thread to handle deposits
    Deposits are handled in 2 phases. 
       Phase1: 
          A unique 0 balance address is generated and given to the user
       Phase2: 
          The address is checked for a balance, if the address has a balance greater than 0 then the user has deposited to that address and their account should be credited
    """
Beispiel #4
0
 def test_get_user_balance_sunny_1(self):
     bot_db = Database('test_db.db')
     username = '******'
     bot_db.set_balance(username, 50)
     self.assertEqual(bot_db.get_user_balance(username), 50)
Beispiel #5
0
 def test_check_balance_rainy_1(self):
     bot_db = Database('test_db.db')
     username = '******'
     bot_db.set_balance(username, 50)
     self.assertFalse(bot_db.check_balance(username, 100))
Beispiel #6
0
 def test_check_balance_sunny_2(self):
     bot_db = Database('test_db.db')
     username = '******'
     bot_db.set_balance(username, 50)
     self.assertTrue(bot_db.check_balance(username, 50))
Beispiel #7
0
 def test_add_new_user_sunny_1(self):
     username = '******'
     bot_db = Database('test_db.db')
     bot_db.add_new_user(username)
Beispiel #8
0
    def test_systems(self):
        """
            Test Transactions
            Send 100 transfers and verify that each one is properly received
            """
        bot_api = api(test_seed)
        seed = bot_api.create_seed()
        bot_api_send = api(bytearray(seed, 'utf-8'))
        if os.path.isfile('test_db_send.db'):
            os.remove('test_db_send.db')
        db_send = Database('test_db_send.db')
        send_address_index = db_send.get_address_index()
        fund_address = bot_api_send.get_new_address(send_address_index)
        db_send.add_used_address(send_address_index,
                                 fund_address._trytes.decode('utf-8'))
        print("Please send 100 iota to address {0}".format(
            fund_address._trytes.decode('utf-8')))

        #Wait until the account has been funded
        while True:
            if bot_api_send.get_balance(fund_address) > 0:
                break
            time.sleep(1)

        #Initialize receiving account
        bot_api_receive = api(bytearray(bot_api.create_seed(), 'utf-8'))
        if os.path.isfile('test_db_receive.db'):
            os.remove('test_db_receive.db')
        db_receive = Database('test_db_receive.db')

        confirmation_times = []
        for i in range(0, 100):
            receive_address_index = db_receive.get_address_index()
            receiving_address = bot_api_receive.get_new_address(
                receive_address_index)
            db_receive.add_used_address(
                receive_address_index,
                receiving_address._trytes.decode("utf-8"))
            starting_balance = bot_api_receive.get_balance(receiving_address)

            #Get the new sending address
            send_address_index = db_send.get_address_index()
            new_address = bot_api_send.get_new_address(send_address_index)
            db_send.add_used_address(send_address_index,
                                     new_address._trytes.decode("utf-8"))

            transaction_time = time.time()
            bundle = bot_api_send.send_transfer(receiving_address, 1,
                                                new_address,
                                                send_address_index)
            print(bundle.hash)
            print(bundle.tail_transaction.hash)
            validator = BundleValidator(bundle)
            valid_bundle = validator.is_valid()
            self.assertTrue(valid_bundle)
            confirmation_time = time.time()
            print('Transaction Confirmed in {0} minutes'.format(
                (confirmation_time - transaction_time) / 60))
            self.assertEqual(bot_api_receive.get_balance(receiving_address),
                             starting_balance + 1)

        receive_address_index = db_receive.get_address_index()
        self.assertEqual(
            bot_api_receive.get_account_balance(receive_address_index), 100)
        average_confirmation_time = 0
        for t in confirmation_times:
            average_confirmation_time = average_confirmation_time + t
        average_confirmation_time = average_confirmation_time / len(
            confirmation_times)
        print(
            'Average confirmation time: {0}'.format(average_confirmation_time))