-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_blockchain.py
66 lines (46 loc) · 1.8 KB
/
test_blockchain.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from blockchain import Blockchain
from wallet import Wallet
from client import Client
from init_transactions import hashImg
from transaction import Transaction
from init_datas import creator_address
blockchain = Blockchain()
wallet = Wallet()
guy_wallet = Wallet(1024, True)
def test_submit_transaction():
transaction = Client.generate_transaction(
wallet, guy_wallet.address, 10)
# don't forget genesis block
assert len(blockchain.current_transactions) == 0
blockchain.submit_transaction(transaction)
assert len(blockchain.chain) == 1
def test_mine():
for i in range(10):
transaction = Client.generate_transaction(
wallet, guy_wallet.address, 10)
blockchain.submit_transaction(transaction)
print(blockchain.mine())
def test_chain_for_network():
for i in range(3):
transaction = Client.generate_transaction(
wallet, guy_wallet.address, 10)
blockchain.submit_transaction(transaction)
blockchain.mine()
s = blockchain.chain_for_network
assert isinstance(s, str) == True
def test_valid_chain():
s = blockchain.chain_for_network
valid = blockchain.valid_chain(s)
assert valid == True
def test_check_sender_stock():
testWallet = Wallet(testDatas=True)
appleHash = hashImg('./items/apple.png')
tx = Transaction(guy_wallet.address, creator_address, appleHash)
assert blockchain.check_sender_stock(tx) == False
txAB = Transaction(creator_address, guy_wallet.address, appleHash)
assert blockchain.check_sender_stock(txAB) == True
txBA = Transaction(guy_wallet.address, creator_address, appleHash)
assert blockchain.check_sender_stock(txBA) == False
txAB.sign(testWallet)
if blockchain.submit_transaction(txAB):
assert blockchain.check_sender_stock(txBA) == True