-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_pow.py
108 lines (98 loc) · 3.05 KB
/
test_pow.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
from proof_of_work import *
import transaction
from treestruct import *
import block
import node
# adding the block to the blockchain kept by node1, assuming this test is run from the node1's machine
node0 = node.node()
node1 = node.node()
node2 = node.node()
node3 = node.node()
node4 = node.node()
block1 = block.block(9999) #genesis hash
#transaction 1 in the block sent by node0 with address 1000
t1 = transaction.transaction(0,2)
t1.sign = "sign1"
t1.hash = 12341
# no input trans but has two outputs
t1.outlist = [transaction.outputtrans() for i in range (t1.outcount)]
t1.outlist[0].value = 1
t1.outlist[0].addr = node1.publickey
t1.outlist[1].value = 19
t1.outlist[1].addr = node0.publickey
# adding trans1 to the block
block1.translist[0] = t1
#transaction 2 in the block sent by node0 with address 1000
t1 = transaction.transaction(1,2)
t1.sign = "sign2"
t1.hash = 12342
# input trans
t1.inlist = [transaction.inputtrans() for i in range (t1.incount)]
t1.inlist[0].hash = 12341
t1.inlist[0].n = 1
t1.inlist[0].sign = "signofnode0"
t1.inlist[0].pub = node0.publickey # public key of node 0
# output trans
t1.outlist = [transaction.outputtrans() for i in range (t1.outcount)]
t1.outlist[0].value = 2
t1.outlist[0].addr = node2.publickey
t1.outlist[1].value = 17
t1.outlist[1].addr = node0.publickey
# adding trans1 to the block
block1.translist[1] = t1
#transaction 3 in the block sent by node0 with address 1000
t1 = transaction.transaction(1,2)
t1.sign = "sign3"
t1.hash = 12343
# input trans
t1.inlist = [transaction.inputtrans() for i in range (t1.incount)]
t1.inlist[0].hash = 12342
t1.inlist[0].n = 1
t1.inlist[0].sign = "signofnode0"
t1.inlist[0].pub = node0.publickey # public key of node 0
# output trans
t1.outlist = [transaction.outputtrans() for i in range (t1.outcount)]
t1.outlist[0].value = 5
t1.outlist[0].addr = node3.publickey
t1.outlist[1].value = 12
t1.outlist[1].addr = node0.publickey
# adding trans1 to the block
block1.translist[2] = t1
#transaction 4 in the block sent by node0 with address 1000
t1 = transaction.transaction(1,2)
t1.sign = "sign3"
t1.hash = 12344
# input trans
t1.inlist = [transaction.inputtrans() for i in range (t1.incount)]
t1.inlist[0].hash = 12343
t1.inlist[0].n = 1
t1.inlist[0].sign = "signofnode0"
t1.inlist[0].pub = node0.publickey # public key of node 0
# output trans
t1.outlist = [transaction.outputtrans() for i in range (t1.outcount)]
t1.outlist[0].value = 3
t1.outlist[0].addr = node4.publickey
t1.outlist[1].value = 9
t1.outlist[1].addr = node0.publickey
# adding trans1 to the block
block1.translist[3] = t1
#transaction 5 in the block sent by node0 with address 1001
t1 = transaction.transaction(0,2)
t1.sign = "sign5"
t1.hash = 12345
# no input trans
# output trans
t1.outlist = [transaction.outputtrans() for i in range (t1.outcount)]
t1.outlist[0].value = 5
t1.outlist[0].addr = 1002
t1.outlist[1].value = 15
t1.outlist[1].addr = 1001
# adding trans1 to the block
block1.translist[4] = t1
proofofwork(block1)
print "Nonce value is: %d", block1.nonce
truthval = verify_nonce(block1)
if truthval == 1:
print "verified!"
else:
print "Fraud!"