예제 #1
0
def test_create_account_nonexistent_asset():
    '''Test that we can't create an account for an asset that doesn't exist'''
    fake_id = Nym().create()._id  # just to get a plausible asset id
    fake_asset = Asset(_id=fake_id, server_id=server.first_active_id())
    acct = account.Account(fake_asset, Nym().register())
    with error.expected(ReturnValueError):
        acct.create()
예제 #2
0
def test_client_knows_nym_registered():
    me = Nym().create()
    assert not opentxs.OTAPI_Wrap_IsNym_RegisteredAtServer(me._id, server.first_active_id())
    me.register()
    assert opentxs.OTAPI_Wrap_IsNym_RegisteredAtServer(me._id, me.server_id)
    me.delete()
    assert not opentxs.OTAPI_Wrap_IsNym_RegisteredAtServer(me._id, server.first_active_id())
예제 #3
0
def test_issue_asset_contract(issue_for_other_nym, expect_success):
    server_id = server.first_id()
    nym = Nym().register(server_id)
    issue_for_nym = Nym().register(server_id) if issue_for_other_nym else nym
    with error.expected(None if expect_success else ReturnValueError):
        Asset().issue(nym,
                      open(data.btc_contract_file),
                      server_id,
                      issue_for_nym=issue_for_nym)
예제 #4
0
def test_withdraw_voucher_to_unregistered_nym(prepared_accounts,
                                              recipient_is_blank):
    unreg_nym = Nym().create()
    v = instrument.Voucher(prepared_accounts.source.server_id, 50,
                           prepared_accounts.source,
                           prepared_accounts.source.nym, "test cheque!",
                           None if recipient_is_blank else unreg_nym)
    v.withdraw()
    # now register the nym and deposit
    unreg_nym.register()
    new_acct = Account(prepared_accounts.source.asset, unreg_nym).create()
    v.deposit(unreg_nym, new_acct)
    prepared_accounts.assert_balances(-100, 50, 0)
예제 #5
0
def test_withdraw_voucher_to_unregistered_nym(prepared_accounts, recipient_is_blank):
    unreg_nym = Nym().create()
    v = instrument.Voucher(
        prepared_accounts.source.server_id,
        50,
        prepared_accounts.source,
        prepared_accounts.source.nym,
        "test cheque!",
        None if recipient_is_blank else unreg_nym
    )
    v.withdraw()
    # now register the nym and deposit
    unreg_nym.register()
    new_acct = Account(prepared_accounts.source.asset, unreg_nym).create()
    v.deposit(unreg_nym, new_acct)
    prepared_accounts.assert_balances(-100, 50, 0)
예제 #6
0
 def test_write_cheque_to_unregistered_nym(self, prepared_accounts,
                                           recipient_is_blank):
     unreg_nym = Nym().create()
     now = datetime.utcnow()
     c = instrument.Cheque(prepared_accounts.source.server_id, 50,
                           now + timedelta(0, -1000),
                           now + timedelta(0, 1000),
                           prepared_accounts.source,
                           prepared_accounts.source.nym, "test cheque!",
                           None if recipient_is_blank else unreg_nym)
     c.write()
     # now register the nym and deposit
     unreg_nym.register()
     new_acct = Account(prepared_accounts.source.asset, unreg_nym).create()
     c.deposit(unreg_nym, new_acct)
     prepared_accounts.assert_balances(-100, 50, 0)
예제 #7
0
def test_create_account():
    server_id = server.first_id()
    nym = Nym().register(server_id)
    asset = Asset().issue(nym, open(data.btc_contract_file), server_id)
    myacct = account.Account(asset, nym).create()

    accounts = account.get_all_ids()
    assert myacct._id in accounts
예제 #8
0
 def test_write_cheque_to_unregistered_nym(self, prepared_accounts, recipient_is_blank):
     unreg_nym = Nym().create()
     now = datetime.utcnow()
     c = instrument.Cheque(
         prepared_accounts.source.server_id,
         50,
         now + timedelta(0, -1000),
         now + timedelta(0, 1000),
         prepared_accounts.source,
         prepared_accounts.source.nym,
         "test cheque!",
         None if recipient_is_blank else unreg_nym
     )
     c.write()
     # now register the nym and deposit
     unreg_nym.register()
     new_acct = Account(prepared_accounts.source.asset, unreg_nym).create()
     c.deposit(unreg_nym, new_acct)
     prepared_accounts.assert_balances(-100, 50, 0)
예제 #9
0
 def __init__(self,
              asset=None,
              nym=None,
              server_id=None,
              name=None,
              _id=None):
     self.server_id = server_id or (asset and asset.server_id)
     self.nym = nym or Nym().register()
     self.asset = asset
     self._id = _id
     self.name = name
예제 #10
0
def test_client_knows_nym_registered():
    me = Nym().create()
    assert not opentxs.OTAPI_Wrap_IsNym_RegisteredAtServer(
        me._id, server.first_active_id())
    me.register()
    assert opentxs.OTAPI_Wrap_IsNym_RegisteredAtServer(me._id, me.server_id)
    me.delete()
    assert not opentxs.OTAPI_Wrap_IsNym_RegisteredAtServer(
        me._id, server.first_active_id())
예제 #11
0
def get_mail(server_id, nym, index, outgoing=False):
    (get_contents, get_other) = (
        opentxs.OTAPI_Wrap_GetNym_OutmailContentsByIndex,
        opentxs.OTAPI_Wrap_GetNym_OutmailRecipientIDByIndex
    ) if outgoing else (
        opentxs.OTAPI_Wrap_GetNym_MailContentsByIndex,
        opentxs.OTAPI_Wrap_GetNym_MailSenderIDByIndex
    )
    content = get_contents(nym._id, index)
    contact = Nym(server_id, get_other(nym._id, index))
    return Message(
        content,
        server_id=server_id,
        from_nym=nym if outgoing else contact,
        to_nym=contact if outgoing else nym)
예제 #12
0
def test_asset_count_increments():
    then = opentxs.OTAPI_Wrap_GetAssetTypeCount()
    Asset().issue(Nym().register(), open(data.btc_contract_file))
    now = opentxs.OTAPI_Wrap_GetAssetTypeCount()
    assert then + 1 == now
예제 #13
0
def test_account_nym_not_registered():
    nym = Nym().register()
    asset = Asset().issue(nym, open(data.btc_contract_file))
    with error.expected(ReturnValueError):
        account.Account(asset, Nym().create()).create()
예제 #14
0
def test_asset_nym_not_registered():
    with error.expected(ReturnValueError):
        Asset().issue(Nym().create(), open(data.btc_contract_file))
예제 #15
0
def test_set_name(newname):
    newname = newname() if callable(newname) else newname
    n = Nym().create()
    origname = "Joe"
    n.set_name(origname)
    assert n.get_name() == origname
    n.register()
    n.set_name(newname)
    assert n.get_name() == newname
    n.register()
예제 #16
0
def an_asset():
    return Asset().issue(Nym().register(), open(data.btc_contract_file))
예제 #17
0
def test_double_delete():
    n = Nym().register()
    n.delete()
    with error.expected(ReturnValueError):
        n.delete()
예제 #18
0
def test_double_delete():
    n = Nym().register()
    n.delete()
    with error.expected(ReturnValueError):
        n.delete()
예제 #19
0
def test_delete_nym():
    Nym().register().delete()
예제 #20
0
def friends():
    return [Nym().register() for _ in range(2)]
예제 #21
0
def test_check_nym():
    me = Nym().register()
    other = Nym().register()
    nym.check(server.first_active_id(), me._id, other._id)
예제 #22
0
def test_check_nym_unregistered():
    me = Nym().register()
    with error.expected(ReturnValueError):
        nym.check(server.first_active_id(), me._id, Nym().create()._id)
예제 #23
0
    def __init__(self):
        self.asset = Asset().issue(Nym().register(), open(btc_contract_file))

        self.source = account.Account(self.asset, Nym().register()).create()
        self.target = account.Account(self.asset, Nym().register()).create()
        self.issuer = self.asset.issuer_account
예제 #24
0
def an_account():
    '''Generates a test account (non-issuer)'''
    nym = Nym().register()
    asset = Asset().issue(nym, open(data.btc_contract_file))
    return account.Account(asset, Nym().register())
예제 #25
0
def test_set_name(newname):
    newname = newname() if callable(newname) else newname
    n = Nym().create()
    origname = "Joe"
    n.set_name(origname)
    assert n.get_name() == origname
    n.register()
    n.set_name(newname)
    assert n.get_name() == newname
    n.register()
예제 #26
0
def test_two_assets_same_nym_and_contract():
    '''Should be able to create two asset types with the same contract'''
    nym = Nym().register()
    asset1 = Asset().issue(nym, open(data.btc_contract_file))
    asset2 = Asset().issue(nym, open(data.btc_contract_file))
    assert asset1._id != asset2._id
예제 #27
0
def test_reregister_nym():
    n = Nym().register()
    n.delete()
    n.register()
예제 #28
0
def test_nym_id_retrievable():
    n = Nym().create()
    nym_count = opentxs.OTAPI_Wrap_GetNymCount()
    ids = [opentxs.OTAPI_Wrap_GetNym_ID(i) for i in range(nym_count)]
    assert n._id in set(ids)
예제 #29
0
def test_reregister_nym():
    n = Nym().register()
    n.delete()
    n.register()
예제 #30
0
def test_register_nym():
    Nym().register()
예제 #31
0
def get_mail(server_id, nym, index):
    content = opentxs.OTAPI_Wrap_GetNym_MailContentsByIndex(nym._id, index)
    from_nym = Nym(
        server_id,
        opentxs.OTAPI_Wrap_GetNym_MailSenderIDByIndex(nym._id, index))
    return Message(content, server_id=server_id, from_nym=from_nym, to_nym=nym)