Example #1
0
    def test_empty_vault_override(self):
        # wait until blocks are generated
        info = utils.wait_until_blocks_are_generated(self.connection)
        self.assertTrue(info.blocks >= -1)

        vaultamount = 45
        vaultaddress = utils.send_to_vault(self.connection, vaultamount)
        self.assertIsNotNone(vaultaddress)

        # wait for vault to get updated
        vault = utils.wait_until_vault_has_balance(self.connection,
                                                   vaultaddress)
        self.assertEqual(int(vault['balance']), vaultamount)

        # initiate vault withdraw
        fromaddress = vaultaddress
        toaddress = self.connection.getnewaddress()
        withdrawamount = vaultamount - 2
        self.connection.withdrawfromvault(fromaddress, toaddress,
                                          withdrawamount)

        # wait for account to get updated
        subaccount = utils.wait_until_account_has_balance(
            self.connection, toaddress)
        self.assertEqual(int(subaccount['balance']), withdrawamount)
        vault = self.connection.getvaults()[vaultaddress]
        self.assertEqual(0, int(vault['balance']))

        # initiate empty vault override
        fromaddress = vaultaddress
        toaddress = self.connection.getnewaddress()
        amount = self.connection.overridevaulttx(fromaddress, toaddress)
        self.assertEqual(0, amount)
Example #2
0
    def test_vault_uniqueness(self):
        # wait until blocks are generated
        info = utils.wait_until_blocks_are_generated(self.connection)
        self.assertTrue(info.blocks >= -1)

        amount = 45
        timeout = 10
        maxfees = 10
        toaddress = self.connection.getnewaddress()
        tomaster_address = self.connection.getnewaddress()

        vaultaddress = self.connection.newvault(toaddress, tomaster_address,
                                                timeout, maxfees)

        self.assertIsNotNone(vaultaddress)
        vaultaddress = self.connection.sendtovault(vaultaddress, amount)
        self.assertIsNotNone(vaultaddress)

        vault = utils.wait_until_vault_has_balance(self.connection,
                                                   vaultaddress)
        self.assertEqual(int(vault['balance']), amount)

        # try resending to vault
        vaultaddress = self.connection.sendtovault(vaultaddress, amount)
        self.assertIsNone(vaultaddress)
Example #3
0
    def test_vault_override(self):
        # wait until blocks are generated
        info = utils.wait_until_blocks_are_generated(self.connection)
        self.assertTrue(info.blocks >= -1)

        vaultamount = 45
        vaultaddress = utils.send_to_vault(self.connection, vaultamount)
        self.assertIsNotNone(vaultaddress)

        # wait for vault to get updated
        vault = utils.wait_until_vault_has_balance(self.connection,
                                                   vaultaddress)
        self.assertEqual(int(vault['balance']), vaultamount)

        # initiate vault withdraw
        fromaddress = vaultaddress
        toaddress = self.connection.getnewaddress()
        amount = random.randint(1, vaultamount - 2)
        self.connection.withdrawfromvault(fromaddress, toaddress, amount)

        # wait until withdraw begins
        vault = utils.wait_until_vault_is_empty(self.connection, vaultaddress)
        self.assertEqual(int(vault['balance']), 0)

        # initiate vault override
        fromaddress = vaultaddress
        toaddress = self.connection.getnewaddress()
        amount = self.connection.overridevaulttx(fromaddress, toaddress)
        self.assertEqual(amount, vaultamount - 2)

        # check for updated balance
        account = utils.wait_until_account_has_balance(self.connection,
                                                       toaddress)
        self.assertEqual(int(account['balance']), amount)
Example #4
0
    def test_vault_withdraw_more_than_balance(self):
        # wait until blocks are generated
        info = utils.wait_until_blocks_are_generated(self.connection)
        self.assertTrue(info.blocks >= -1)

        amount = 45
        vaultaddress = utils.send_to_vault(self.connection, amount)
        self.assertIsNotNone(vaultaddress)

        # wait for vault to get updated
        vault = utils.wait_until_vault_has_balance(self.connection,
                                                   vaultaddress)
        self.assertEqual(int(vault['balance']), amount)

        # initiate vault withdraw
        fromaddress = vaultaddress
        toaddress = self.connection.getnewaddress()
        transfered = self.connection.withdrawfromvault(fromaddress, toaddress,
                                                       amount)

        # assert that no balance has been transfered
        self.assertEqual(0, transfered)

        # wait until few more blocks are generated
        utils.wait_until_n_more_blocks_are_generated(self.connection, 2)

        # assert that the balances are still the same
        vaults = self.connection.getvaults()
        vault = vaults[vaultaddress]
        self.assertEqual(int(vault['balance']), amount)
Example #5
0
    def test_vault_send_more_than_balance(self):
        LARGE_AMOUNT = 500000000000
        # wait until blocks are generated
        info = utils.wait_until_blocks_are_generated(self.connection)
        self.assertTrue(info.blocks >= -1)

        total_balance = utils.get_total_balance(self.connection)
        amount = total_balance + LARGE_AMOUNT

        vaultaddress = utils.send_to_vault(self.connection, amount)
        self.assertIsNone(vaultaddress)
Example #6
0
    def test_vault_send_more_than_balance(self):
        LARGE_AMOUNT = 500000000000
        # wait until blocks are generated
        info = utils.wait_until_blocks_are_generated(self.connection)
        self.assertTrue(info.blocks >= -1)

        total_balance = utils.get_total_balance(self.connection)
        amount = total_balance + LARGE_AMOUNT

        vaultaddress = utils.send_to_vault(self.connection, amount)
        self.assertIsNone(vaultaddress)
Example #7
0
    def test_vault_send(self):
        # wait until blocks are generated
        info = utils.wait_until_blocks_are_generated(self.connection)
        self.assertTrue(info.blocks >= -1)

        amount = 45
        vaultaddress = utils.send_to_vault(self.connection, amount)
        self.assertIsNotNone(vaultaddress)

        # wait for vault to get updated
        vault = utils.wait_until_vault_has_balance(self.connection,
                                                   vaultaddress)
        self.assertEqual(int(vault['balance']), amount)
Example #8
0
    def test_send(self):
        # wait until blocks are generated
        info = utils.wait_until_blocks_are_generated(self.connection)
        self.assertTrue(info.blocks >= -1)

        # generate a new toaddress
        toaddress = self.connection.getnewaddress()
        amount = random.randint(20, 30)
        self.connection.sendtoaddress(toaddress, amount)

        account = self.connection.getaccount(self.account)
        self.assertIn(toaddress, account)

        # wait for account to get updated
        subaccount = utils.wait_until_account_has_balance(self.connection, toaddress)
        self.assertEqual(int(subaccount['balance']), amount)
Example #9
0
    def test_send(self):
        # wait until blocks are generated
        info = utils.wait_until_blocks_are_generated(self.connection)
        self.assertTrue(info.blocks >= -1)

        # generate a new toaddress
        toaddress = self.connection.getnewaddress()
        amount = random.randint(20, 30)
        self.connection.sendtoaddress(toaddress, amount)

        account = self.connection.getaccount(self.account)
        self.assertIn(toaddress, account)

        # wait for account to get updated
        subaccount = utils.wait_until_account_has_balance(
            self.connection, toaddress)
        self.assertEqual(int(subaccount['balance']), amount)
Example #10
0
    def test_multiple_vault_withdraws(self):
        # wait until blocks are generated
        info = utils.wait_until_blocks_are_generated(self.connection)
        self.assertTrue(info.blocks >= -1)

        amount = 45
        vaultaddress = utils.send_to_vault(self.connection, amount)
        self.assertIsNotNone(vaultaddress)

        # wait for vault to get updated
        vault = utils.wait_until_vault_has_balance(self.connection,
                                                   vaultaddress)
        self.assertEqual(int(vault['balance']), amount)

        # initiate vault withdraw
        fromaddress = vaultaddress
        toaddress = self.connection.getnewaddress()
        withdrawamount = random.randint(1, amount / 2)
        self.connection.withdrawfromvault(fromaddress, toaddress,
                                          withdrawamount)

        # wait for account to get updated
        subaccount = utils.wait_until_account_has_balance(
            self.connection, toaddress)
        self.assertEqual(int(subaccount['balance']), withdrawamount)
        time.sleep(10)
        vault = self.connection.getvaults()[vaultaddress]
        self.assertEqual(int(vault['balance']), amount - withdrawamount - 2)

        amount = int(vault['balance'])
        # initiate another vault withdraw
        fromaddress = vaultaddress
        toaddress = self.connection.getnewaddress()
        withdrawamount = random.randint(1, amount - 2)
        self.connection.withdrawfromvault(fromaddress, toaddress,
                                          withdrawamount)

        # wait for account to get updated
        subaccount = utils.wait_until_account_has_balance(
            self.connection, toaddress)
        self.assertEqual(int(subaccount['balance']), withdrawamount)
        vault = self.connection.getvaults()[vaultaddress]
        self.assertEqual(int(vault['balance']), amount - withdrawamount - 2)
Example #11
0
    def test_vault_double_withdraw(self):
        # wait until blocks are generated
        info = utils.wait_until_blocks_are_generated(self.connection)
        self.assertTrue(info.blocks >= -1)

        amount = 45
        vaultaddress = utils.send_to_vault(self.connection, amount)
        self.assertIsNotNone(vaultaddress)

        # wait for vault to get updated
        vault = utils.wait_until_vault_has_balance(self.connection,
                                                   vaultaddress)
        self.assertEqual(int(vault['balance']), amount)

        # initiate vault withdraw
        fromaddress = vaultaddress
        toaddress1 = self.connection.getnewaddress()
        toaddress2 = self.connection.getnewaddress()
        amount = amount - 2
        transfered1 = self.connection.withdrawfromvault(
            fromaddress, toaddress1, amount)
        transfered2 = self.connection.withdrawfromvault(
            fromaddress, toaddress2, amount)
        self.assertEqual(transfered1, amount)
        self.assertEqual(transfered2, amount)

        # wait for one of the accounts to get updated
        while True:
            utils.wait_until_n_more_blocks_are_generated(self.connection, 1)
            account = self.connection.getaccount(self.account)
            subaccount1 = account[toaddress1]
            subaccount2 = account[toaddress2]
            if subaccount1['balance'] or subaccount2['balance']:
                balance_max = max(subaccount1['balance'],
                                  subaccount2['balance'])
                balance_min = min(subaccount1['balance'],
                                  subaccount2['balance'])
                self.assertEqual(int(balance_max), amount)
                self.assertEqual(int(balance_min), 0)
                break
Example #12
0
    def test_vault_fast_withdraw(self):
        # wait until blocks are generated
        info = utils.wait_until_blocks_are_generated(self.connection)
        self.assertTrue(info.blocks >= -1)

        amount = 45
        vaultaddress = utils.send_to_vault(self.connection, amount)
        self.assertIsNotNone(vaultaddress)

        # wait for vault to get updated
        vault = utils.wait_until_vault_has_balance(self.connection,
                                                   vaultaddress)
        self.assertEqual(int(vault['balance']), amount)

        # initiate fast withdraw
        fromaddress = vaultaddress
        toaddress = self.connection.getnewaddress()
        amount = random.randint(1, amount - 1)
        self.connection.fastwithdrawfromvault(fromaddress, toaddress, amount)

        # wait for account to get updated
        subaccount = utils.wait_until_account_has_balance(
            self.connection, toaddress)
        self.assertEqual(int(subaccount['balance']), amount)
Example #13
0
 def test_info(self):
     # wait until blocks are generated
     info = utils.wait_until_blocks_are_generated(self.connection)
     self.assertTrue(info.blocks >= -1)
Example #14
0
 def test_info(self):
     # wait until blocks are generated
     info = utils.wait_until_blocks_are_generated(self.connection)
     self.assertTrue(info.blocks >= -1)