Exemplo n.º 1
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())
Exemplo n.º 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())
Exemplo n.º 3
0
def test_mail_content(friends, content):
    alice, bob = friends
    s1 = server.first_active_id()
    alicemsg = messaging.Message(content, from_nym=alice, to_nym=bob, server_id=s1)
    alicemsg.send()
    bobmsg = messaging.get_all_mail(s1, bob)[0]
    assert bobmsg.content == content
Exemplo n.º 4
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()
Exemplo n.º 5
0
    def issue(self,
              nym=None,
              contract_stream=None,
              server_id=None,
              issue_for_nym=None):
        '''Issues a new asset type on the given server and nym.  contract
           should be a string with the contract contents.

           nym must be registered.

           issue_for_nym is the nym to try to create the issuer account as (OT shouldn't allow
             if this isn't the same as the issuer nym) - for testing purposes
        '''
        # first create the contract if necessary
        self.server_id = self.server_id or server_id or server.first_active_id(
        )
        assert self.server_id
        if not self._id:
            self.create_contract(nym, contract_stream)
        signed_contract = opentxs.OTAPI_Wrap_GetAssetType_Contract(self._id)
        message = otme.issue_asset_type(self.server_id,
                                        (issue_for_nym and issue_for_nym._id)
                                        or nym._id, signed_contract)
        assert is_message_success(message)
        account_id = opentxs.OTAPI_Wrap_Message_GetNewIssuerAcctID(message)
        self.issuer_account = Account(asset=self,
                                      nym=self.issuer,
                                      server_id=self.server_id,
                                      _id=account_id)
        return self
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()
Exemplo n.º 7
0
 def __init__(self, server_id, amount, sender_account, sender_nym, memo, recipient_nym):
     self.server_id = server_id or server.first_active_id()
     self.amount = amount
     self.sender_account = sender_account
     self.sender_nym = sender_nym
     self.memo = memo
     self.recipient_nym = recipient_nym
     self._body = None
Exemplo n.º 8
0
 def __init__(self, server_id, amount, sender_account, sender_nym, memo,
              recipient_nym):
     self.server_id = server_id or server.first_active_id()
     self.amount = amount
     self.sender_account = sender_account
     self.sender_nym = sender_nym
     self.memo = memo
     self.recipient_nym = recipient_nym
     self._body = None
Exemplo n.º 9
0
def test_issue_asset_contract(issue_for_other_nym, expect_success):
    server_id = server.first_active_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)
Exemplo n.º 10
0
 def __init__(self, server_id, cheque_amount, valid_from, valid_to,
              sender_account, sender_nym, cheque_memo, recipient_nym):
     self.server_id = server_id or server.first_active_id()
     self.cheque_amount = cheque_amount
     self.valid_from = valid_from
     self.valid_to = valid_to
     self.sender_account = sender_account
     self.sender_nym = sender_nym
     self.cheque_memo = cheque_memo
     self.recipient_nym = recipient_nym
     self._body = None  # prepared cheque returned by server
Exemplo n.º 11
0
def test_send_many_messages(friends):
    alice, bob = friends
    s1 = server.first_active_id()
    msgs = [messaging.Message("hello bob, this is msg %s" % i,
                              from_nym=alice, to_nym=bob, server_id=s1)
            for i in range(10)]
    for m in msgs:
        m.send()
    # now make sure they're all in bob's inbox
    bobinbox = sorted(messaging.get_all_mail(s1, bob), key=lambda m: m.content)
    assert bobinbox == msgs
Exemplo n.º 12
0
 def __init__(self, server_id, cheque_amount, valid_from, valid_to, sender_account,
              sender_nym, cheque_memo, recipient_nym):
     self.server_id = server_id or server.first_active_id()
     self.cheque_amount = cheque_amount
     self.valid_from = valid_from
     self.valid_to = valid_to
     self.sender_account = sender_account
     self.sender_nym = sender_nym
     self.cheque_memo = cheque_memo
     self.recipient_nym = recipient_nym
     self._body = None  # prepared cheque returned by server
Exemplo n.º 13
0
def test_basic_messaging(friends):
    alice, bob = friends
    s1 = server.first_active_id()
    alicemsg = messaging.Message("hi bob, foo bar baz!",
                                 from_nym=alice,
                                 to_nym=bob,
                                 server_id=s1)
    assert messaging.remote_mail_count(s1, bob) == 0
    alicemsg.send()
    bobinbox = messaging.get_all_mail(s1, bob)
    assert len(bobinbox) == 1
    bobmsg = bobinbox[0]
    assert bobmsg == alicemsg
    messaging.delete_all_mail(bob)
    assert messaging.mail_count(bob) == 0
Exemplo n.º 14
0
    def register(self, server_id=None):
        '''Registers the nym with the given server.  If there is no nym id yet
           (this object is still empty), the nym data will be created
           with defaults first, and then registered to the server.
           Returns the nym object.

        '''
        server_id = server_id or self.server_id or server.first_active_id()
        assert server_id, "Can't register a nym without a server id.'"
        self.server_id = server_id
        if not self._id:
            self.create()
        message = otme.register_nym(server_id, self._id)
        assert is_message_success(message)
        return self
Exemplo n.º 15
0
    def register(self, server_id=None):
        '''Registers the nym with the given server.  If there is no nym id yet
           (this object is still empty), the nym data will be created
           with defaults first, and then registered to the server.
           Returns the nym object.

        '''
        server_id = server_id or self.server_id or server.first_active_id()
        assert server_id, "Can't register a nym without a server id.'"
        self.server_id = server_id
        if not self._id:
            self.create()
        message = otme.register_nym(server_id, self._id)
        assert is_message_success(message)
        return self
Exemplo n.º 16
0
def test_basic_messaging(friends):
    alice, bob = friends
    s1 = server.first_active_id()
    alicemsg = messaging.Message("hi bob, foo bar baz!", from_nym=alice, to_nym=bob, server_id=s1)
    assert messaging.remote_mail_count(s1, bob) == 0
    alicemsg.send()
    bobinbox = messaging.get_all_mail(s1, bob)
    aliceoutbox = messaging.get_all_mail(s1, alice, outgoing=True)
    messaging.verify_mail(bob, 0)
    messaging.verify_mail(alice, 0, outgoing=True)
    assert messaging.get_mail_notary_id(bob, 0) == s1
    assert messaging.get_mail_notary_id(alice, 0, outgoing=True) == s1
    assert len(bobinbox) == 1
    assert len(aliceoutbox) == 1
    bobmsg = bobinbox[0]
    aliceoutboxmsg = aliceoutbox[0]
    assert bobmsg == alicemsg and bobmsg == aliceoutboxmsg
    messaging.delete_all_mail(bob)
    assert messaging.mail_count(bob) == 0
    messaging.delete_all_mail(alice, outgoing=True)
    assert messaging.mail_count(alice, outgoing=True) == 0
Exemplo n.º 17
0
def test_check_nym_unregistered():
    me = Nym().register()
    with error.expected(ReturnValueError):
        nym.check(server.first_active_id(), me._id, Nym().create()._id)
Exemplo n.º 18
0
def test_check_nym():
    me = Nym().register()
    other = Nym().register()
    nym.check(server.first_active_id(), me._id, other._id)
Exemplo n.º 19
0
def test_issue_asset_contract(issue_for_other_nym, expect_success):
    server_id = server.first_active_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)
Exemplo n.º 20
0
def test_check_nym_unregistered():
    me = Nym().register()
    with error.expected(ReturnValueError):
        nym.check(server.first_active_id(), me._id, Nym().create()._id)
Exemplo n.º 21
0
def test_check_nym():
    me = Nym().register()
    other = Nym().register()
    nym.check(server.first_active_id(), me._id, other._id)