コード例 #1
0
    def test_deposit_twice(self, prepared_accounts, amount, first_valid, later_income,
                           second_valid):
        # create cheque and try to deposit it
        cheque = new_cheque(prepared_accounts.source, prepared_accounts.target, amount)
        with error.expected(None if first_valid else ReturnValueError):
            transfer(cheque, prepared_accounts.source, prepared_accounts.target)

        expected_source = 100
        expected_target = 0
        if (first_valid):
            expected_source -= amount
            expected_target += amount
        prepared_accounts.assert_balances(-100, expected_source, expected_target)

        # now transfer more funds to source
        if later_income != 0:
            income = new_cheque(prepared_accounts.issuer, prepared_accounts.source, later_income)
            transfer(income, prepared_accounts.issuer, prepared_accounts.source)
        expected_source += later_income

        # and repeat cheque deposit
        with error.expected(None if second_valid else ReturnValueError):
            deposit = cheque.deposit(prepared_accounts.target.nym, prepared_accounts.target)
        if second_valid:
            expected_source -= amount
            expected_target += amount
            assert is_message_success(deposit)

        prepared_accounts.assert_balances(-100 - later_income, expected_source, expected_target)
コード例 #2
0
def test_not_account_owner(prepared_accounts, instrument_constructor):
    '''Test that we get a graceful failure when we try to deposit an
       instrument for an account we don't own'''

    instrument = instrument_constructor(
        prepared_accounts.source, prepared_accounts.target, 50,
        source_nym=prepared_accounts.target.nym)
    with error.expected(ReturnValueError):
        transfer(instrument, prepared_accounts.source, prepared_accounts.target)
コード例 #3
0
def test_issuer_bidirectional(prepared_accounts, amount):
    '''Test a cheque and then an invoice for the same amount, from issuer
    to source (or the other way around)'''
    first_transfer = new_cheque(prepared_accounts.issuer, prepared_accounts.source, amount)
    transfer(first_transfer, prepared_accounts.issuer, prepared_accounts.source)
    prepared_accounts.assert_balances(-100 - amount, 100 + amount, 0)
    second_transfer = new_cheque(prepared_accounts.issuer, prepared_accounts.source, -amount)
    transfer(second_transfer, prepared_accounts.issuer, prepared_accounts.source)
    prepared_accounts.assert_balances(-100, 100, 0)
コード例 #4
0
 def test_simple_transfer(self, prepared_accounts, amount, should_pass, instrument_constructor):
     instrument = instrument_constructor(
         prepared_accounts.issuer, prepared_accounts.target, amount)
     with error.expected(None if should_pass else ReturnValueError):
         transfer(instrument, prepared_accounts.issuer, prepared_accounts.target)
     if should_pass:
         prepared_accounts.assert_balances(-100 - amount, 100, amount)
     else:
         prepared_accounts.assert_balances(-100, 100, 0)
コード例 #5
0
 def test_expired_cheque(self, prepared_accounts, valid_from, valid_to, valid):
     with error.expected(None if valid else ReturnValueError):
         transfer(new_cheque(prepared_accounts.source, prepared_accounts.target, 10,
                             valid_from, valid_to),
                  prepared_accounts.source,
                  prepared_accounts.target)
     if valid:
         prepared_accounts.assert_balances(-100, 90, 10)
     else:
         prepared_accounts.assert_balances(-100, 100, 0)
コード例 #6
0
def test_wrong_asset_type(instrument_constructor):
    '''Try to transfer eg a cheque from one asset account to another of a
       different type. Should fail'''
    ta_asset1 = data.TransferAccounts().initial_balance()
    ta_asset2 = data.TransferAccounts().initial_balance()
    source = ta_asset1.source
    target = ta_asset2.target
    instrument = instrument_constructor(source, target, 50)
    with error.expected(ReturnValueError):
        transfer(instrument, source, target)
    ta_asset2.assert_balances(-100, 100, 0)
コード例 #7
0
 def test_simple_transfer(self, prepared_accounts, amount, should_pass,
                          instrument_constructor):
     instrument = instrument_constructor(prepared_accounts.source,
                                         prepared_accounts.target, amount)
     with error.expected(None if should_pass else ReturnValueError):
         transfer(instrument, prepared_accounts.source,
                  prepared_accounts.target)
     if should_pass:
         prepared_accounts.assert_balances(-100, 100 - amount, amount)
     else:
         prepared_accounts.assert_balances(-100, 100, 0)
コード例 #8
0
 def test_expired_cheque(self, prepared_accounts, valid_from, valid_to,
                         valid):
     with error.expected(None if valid else ReturnValueError):
         transfer(
             new_cheque(prepared_accounts.source, prepared_accounts.target,
                        10, valid_from, valid_to), prepared_accounts.source,
             prepared_accounts.target)
     if valid:
         prepared_accounts.assert_balances(-100, 90, 10)
     else:
         prepared_accounts.assert_balances(-100, 100, 0)
コード例 #9
0
def test_wrong_asset_type(instrument_constructor):
    '''Try to transfer eg a cheque from one asset account to another of a
       different type. Should fail'''
    ta_asset1 = data.TransferAccounts().initial_balance()
    ta_asset2 = data.TransferAccounts().initial_balance()
    source = ta_asset1.source
    target = ta_asset2.target
    instrument = instrument_constructor(source, target, 50)
    with error.expected(ReturnValueError):
        transfer(instrument, source, target)
    ta_asset2.assert_balances(-100, 100, 0)
コード例 #10
0
def test_not_account_owner(prepared_accounts, instrument_constructor):
    '''Test that we get a graceful failure when we try to deposit an
       instrument for an account we don't own'''

    instrument = instrument_constructor(
        prepared_accounts.source,
        prepared_accounts.target,
        50,
        source_nym=prepared_accounts.target.nym)
    with error.expected(ReturnValueError):
        transfer(instrument, prepared_accounts.source,
                 prepared_accounts.target)
コード例 #11
0
def test_issuer_bidirectional(prepared_accounts, amount):
    '''Test a cheque and then an invoice for the same amount, from issuer
    to source (or the other way around)'''
    first_transfer = new_cheque(prepared_accounts.issuer,
                                prepared_accounts.source, amount)
    transfer(first_transfer, prepared_accounts.issuer,
             prepared_accounts.source)
    prepared_accounts.assert_balances(-100 - amount, 100 + amount, 0)
    second_transfer = new_cheque(prepared_accounts.issuer,
                                 prepared_accounts.source, -amount)
    transfer(second_transfer, prepared_accounts.issuer,
             prepared_accounts.source)
    prepared_accounts.assert_balances(-100, 100, 0)
コード例 #12
0
    def test_simple_transfer(self, prepared_accounts, amount, should_pass, instrument_constructor):
        instrument = instrument_constructor(
            prepared_accounts.source, prepared_accounts.target, amount)

        if instrument_constructor == new_cash:
            # skip if testing with large amount
            if amount > 1000:
                pytest.skip("https://github.com/Open-Transactions/opentxs/issues/536")
            # make sure there's a mint created for this asset
            cash.create_mint(prepared_accounts.asset)

        with error.expected(None if should_pass else ReturnValueError):
            transfer(instrument, prepared_accounts.source, prepared_accounts.target)
        if should_pass:
            prepared_accounts.assert_balances(-100, 100 - amount, amount)
        else:
            prepared_accounts.assert_balances(-100, 100, 0)
コード例 #13
0
    def test_simple_transfer(self, prepared_accounts, amount, should_pass,
                             instrument_constructor):
        instrument = instrument_constructor(prepared_accounts.source,
                                            prepared_accounts.target, amount)

        if instrument_constructor == new_cash:
            # skip if testing with large amount
            if amount > 1000:
                pytest.skip(
                    "https://github.com/Open-Transactions/opentxs/issues/536")
            # make sure there's a mint created for this asset
            cash.create_mint(prepared_accounts.asset)

        with error.expected(None if should_pass else ReturnValueError):
            transfer(instrument, prepared_accounts.source,
                     prepared_accounts.target)
        if should_pass:
            prepared_accounts.assert_balances(-100, 100 - amount, amount)
        else:
            prepared_accounts.assert_balances(-100, 100, 0)
コード例 #14
0
    def test_deposit_twice(self, prepared_accounts, amount, first_valid,
                           later_income, second_valid):
        # create cheque and try to deposit it
        cheque = new_cheque(prepared_accounts.source, prepared_accounts.target,
                            amount)
        with error.expected(None if first_valid else ReturnValueError):
            transfer(cheque, prepared_accounts.source,
                     prepared_accounts.target)

        expected_source = 100
        expected_target = 0
        if (first_valid):
            expected_source -= amount
            expected_target += amount
        prepared_accounts.assert_balances(-100, expected_source,
                                          expected_target)

        # now transfer more funds to source
        if later_income != 0:
            income = new_cheque(prepared_accounts.issuer,
                                prepared_accounts.source, later_income)
            transfer(income, prepared_accounts.issuer,
                     prepared_accounts.source)
        expected_source += later_income

        # and repeat cheque deposit
        with error.expected(None if second_valid else ReturnValueError):
            deposit = cheque.deposit(prepared_accounts.target.nym,
                                     prepared_accounts.target)
        if second_valid:
            expected_source -= amount
            expected_target += amount
            assert is_message_success(deposit)

        prepared_accounts.assert_balances(-100 - later_income, expected_source,
                                          expected_target)
コード例 #15
0
 def initial_balance(self, balance=100):
     # send 100 from issuer to nym_source_id
     # self.cheque = new_cheque(self.issuer, self.source, balance)
     # transfer(self.cheque, self.issuer, self.source)
     transfer(balance, self.issuer, self.source)
     return self
コード例 #16
0
 def initial_balance(self, balance=100):
     # send 100 from issuer to nym_source_id
     # self.cheque = new_cheque(self.issuer, self.source, balance)
     # transfer(self.cheque, self.issuer, self.source)
     transfer(balance, self.issuer, self.source)
     return self
コード例 #17
0
    def initial_balance(self, balance=100):
        # start everyone off with 100 of each asset

        transfer(balance, self.asset1.issuer_account, self.alice.account1)
        transfer(balance, self.asset1.issuer_account, self.bob.account1)
        transfer(balance, self.asset1.issuer_account, self.charlie.account1)

        transfer(balance, self.asset2.issuer_account, self.alice.account2)
        transfer(balance, self.asset2.issuer_account, self.bob.account2)
        transfer(balance, self.asset2.issuer_account, self.charlie.account2)
        return self