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
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
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_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)
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."
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)
def __init__(self, nym, asset1, asset2): self.nym = nym self.account1 = Account(asset1, self.nym) self.account2 = Account(asset2, self.nym)