Skip to content

Commit 2a0fa9d

Browse files
committed
Added tansaction tests
1 parent 93cc4ac commit 2a0fa9d

File tree

5 files changed

+63
-19
lines changed

5 files changed

+63
-19
lines changed

Diff for: Master.py

+18-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
1-
import account
1+
from transaction import Build
2+
from account import Details
3+
4+
ALICE = 'GBCKQLHFUZF36FIJUKUW37YFQG5O5MXT3YB2M7ZGVBORLUZMPIITWHZI'
5+
ALICE_SEED = 'SAKM5BVR5OK75VAC4YCUXD4YLPIJEV7WIUY6WJUXNZF6LCJ3CGYD6WU2'
6+
BOB = 'GAATZTOYFZSLGKM6BUTXNWMIWUETMEK74VBJNEPRGB5WW3ELVTKBWNGN'
7+
28

39
if __name__ == '__main__':
4-
Address1 = 'GBCKQLHFUZF36FIJUKUW37YFQG5O5MXT3YB2M7ZGVBORLUZMPIITWHZI'
5-
account.Details(Address1).get()
10+
if Details(ALICE).check and Details(BOB).check:
11+
transaction = Build(sender=ALICE_SEED, receiver=BOB, amount=20)
12+
transaction.send()
13+
[account, address, balance, asset] = Details(ALICE).get
14+
print('Balance:{}'.format(balance))
15+
print('Address:{}'.format(address))
16+
print('---------------------------')
17+
[account, address, balance, asset] = Details(BOB).get
18+
print('Balance:{}'.format(balance))
19+
print('Address:{}'.format(address))
20+
print('---------------------------')

Diff for: account.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ def __init__(self, address):
1010
self.account.get()
1111
except AccountNotExistError:
1212
self.account = None
13-
print('Account does not exist')
1413

14+
@property
15+
def check(self):
16+
return True if self.account else False
17+
1518
@property
1619
def get(self):
1720
if self.account:
18-
print('Account ID:{}'.format(self.address))
19-
print('Balance:{}'.format(self.balance))
20-
print('Asset:{}'.format(self.asset))
21-
return self.address, self.balance, self.asset
21+
return self.account, self.address, self.balance, self.asset
2222
else:
2323
return None
2424

Diff for: test/account_tests.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from account import Details
33

44

5-
class TestStringMethods(unittest.TestCase):
5+
class TestDetailClass(unittest.TestCase):
66
def test_accountDetailsExist(self):
77
account_id = 'GBCKQLHFUZF36FIJUKUW37YFQG5O5MXT3YB2M7ZGVBORLUZMPIITWHZI'
88
self.assertTrue(Details(account_id).get, msg='Test exist failed case failed')

Diff for: test/transaction_tests.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import unittest
2+
from transaction import Build
3+
4+
ANONYMOUS = 'GBCKQLHFUZF36FIJUKUW37YFQG5O5MXT3YB2M7ZGVBORLUZMPIITW'
5+
ALICE_SEED = 'SAKM5BVR5OK75VAC4YCUXD4YLPIJEV7WIUY6WJUXNZF6LCJ3CGYD6WU2'
6+
BOB = 'GAATZTOYFZSLGKM6BUTXNWMIWUETMEK74VBJNEPRGB5WW3ELVTKBWNGN'
7+
8+
9+
class TestTransactionClass(unittest.TestCase):
10+
11+
def test_transaction(self):
12+
self.assertTrue(Build(ALICE_SEED, BOB, 20).send())
13+
14+
def test_invalid_account(self):
15+
self.assertFalse(Build(ALICE_SEED, ANONYMOUS, 20).send())
16+
17+
18+
if __name__ == "__main__":
19+
unittest.main()

Diff for: transaction.py

+20-10
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
11
from stellar_base.builder import Builder
2+
from account import Details
23

34

45
class Build:
6+
"""Creates a transaction between the sender and receiver.
57
6-
def __init__(self, sender, receiver, amount=0, text_memo=None):
7-
self.text_memo = text_memo
8-
self.sender = sender
9-
self.receiver = receiver
10-
self.amount = amount
8+
:param: sender: Account that sends the money (seed).
9+
:param: receiver: Account that receives the money (Account ID).
10+
:param: amount: Amount that needs to be sent.
11+
"""
12+
def __init__(self, sender, receiver, amount=0):
13+
self.sender, self.receiver, self.amount = sender, receiver, amount
1114
self.builder = None
1215

1316
def send(self):
14-
self.builder = Builder(secret=self.sender, horizon='https://horizon-testnet.stellar.org')
15-
self.builder.append_payment_op(self.receiver, self.amount)
16-
self.builder.add_text_memo('Hello world!')
17-
self.builder.sign()
18-
self.builder.submit()
17+
"""Text Memo needs to be added."""
18+
if self.check_account_validity:
19+
self.builder = Builder(secret=self.sender, horizon='https://horizon-testnet.stellar.org')
20+
self.builder.append_payment_op(self.receiver, self.amount)
21+
self.builder.sign()
22+
self.builder.submit()
23+
return True
24+
return False
25+
26+
@property
27+
def check_account_validity(self):
28+
return Details(self.receiver).check

0 commit comments

Comments
 (0)