예제 #1
0
    def __init__(self, asset=None):
        self.asset = asset or Asset().issue(Nym().register(),
                                            open(btc_contract_file))

        self.source = Account(self.asset, Nym().register()).create()
        self.target = Account(self.asset, Nym().register()).create()
        self.issuer = self.asset.issuer_account
예제 #2
0
class TradeAccount:
    def __init__(self, nym, asset1, asset2):
        self.nym = nym
        self.account1 = Account(asset1, self.nym)
        self.account2 = Account(asset2, self.nym)

    def create(self):
        self.account1.create()
        self.account2.create()
        return self
예제 #3
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
예제 #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
class TransferAccounts:
    '''A class to hold issuer/source/target accounts to test transfers.
       Start with 100 balance in the source account'''
    def __init__(self, asset=None):
        self.asset = asset or Asset().issue(Nym().register(),
                                            open(btc_contract_file))

        self.source = Account(self.asset, Nym().register()).create()
        self.target = Account(self.asset, Nym().register()).create()
        self.issuer = self.asset.issuer_account

    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

    def assert_balances(self, issuer, source, target):
        assert (issuer, source, target) == (self.issuer.balance(),
                                            self.source.balance(),
                                            self.target.balance()),\
            "Issuer/source/target balances do not match."
예제 #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 __init__(self, nym, asset1, asset2):
     self.nym = nym
     self.account1 = Account(asset1, self.nym)
     self.account2 = Account(asset2, self.nym)