Exemplo n.º 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)
Exemplo n.º 2
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)
Exemplo n.º 3
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)
Exemplo n.º 4
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)
Exemplo n.º 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)
Exemplo n.º 6
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)
Exemplo n.º 7
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)
Exemplo n.º 8
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
Exemplo n.º 9
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)