-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestMaxFeeTxHandler.java
156 lines (120 loc) · 6.83 KB
/
TestMaxFeeTxHandler.java
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import java.io.FileNotFoundException;
import java.io.IOException;
public class TestMaxFeeTxHandler {
private static boolean verify(Transaction[] allTxs1, UTXOPool uPool) {
Transaction[] copyTxs1 = new Transaction[allTxs1.length];
for (int i = 0; i < copyTxs1.length; i++)
copyTxs1[i] = allTxs1[i];
MaxFeeTxHandler student1 = new MaxFeeTxHandler(new UTXOPool(uPool));
MaxFeeTxHandlerVerifier verifier1 = new MaxFeeTxHandlerVerifier(uPool);
System.out.println("Total Transactions = " + allTxs1.length);
Transaction[] stx1 = student1.handleTxs(copyTxs1);
System.out.println("Number of transactions returned valid by student = " + stx1.length);
boolean passed1 = verifier1.check(allTxs1, stx1);
return passed1;
}
private static boolean verify(Transaction[] allTxs1, Transaction[] allTxs2, UTXOPool uPool) {
Transaction[] copyTxs1 = new Transaction[allTxs1.length];
for (int i = 0; i < copyTxs1.length; i++)
copyTxs1[i] = allTxs1[i];
Transaction[] copyTxs2 = new Transaction[allTxs2.length];
for (int i = 0; i < copyTxs2.length; i++)
copyTxs2[i] = allTxs2[i];
MaxFeeTxHandler student1 = new MaxFeeTxHandler(new UTXOPool(uPool));
MaxFeeTxHandlerVerifier verifier1 = new MaxFeeTxHandlerVerifier(uPool);
MaxFeeTxHandler student2 = new MaxFeeTxHandler(new UTXOPool(uPool));
MaxFeeTxHandlerVerifier verifier2 = new MaxFeeTxHandlerVerifier(uPool);
System.out.println("Total Transactions = " + allTxs1.length);
Transaction[] stx1 = student1.handleTxs(copyTxs1);
System.out.println("Number of transactions returned valid by student = " + stx1.length);
boolean passed1 = verifier1.check(allTxs1, stx1);
System.out.println("Total Transactions = " + allTxs2.length);
Transaction[] stx2 = student2.handleTxs(copyTxs2);
System.out.println("Number of transactions returned valid by student = " + stx2.length);
boolean passed2 = verifier2.check(allTxs2, stx2);
return passed1 && passed2;
}
private static boolean verify(Transaction[] allTxs1, Transaction[] allTxs2,
Transaction[] allTxs3, UTXOPool uPool) {
Transaction[] copyTxs1 = new Transaction[allTxs1.length];
for (int i = 0; i < copyTxs1.length; i++)
copyTxs1[i] = allTxs1[i];
Transaction[] copyTxs2 = new Transaction[allTxs2.length];
for (int i = 0; i < copyTxs2.length; i++)
copyTxs2[i] = allTxs2[i];
Transaction[] copyTxs3 = new Transaction[allTxs3.length];
for (int i = 0; i < copyTxs3.length; i++)
copyTxs3[i] = allTxs3[i];
MaxFeeTxHandler student1 = new MaxFeeTxHandler(new UTXOPool(uPool));
MaxFeeTxHandlerVerifier verifier1 = new MaxFeeTxHandlerVerifier(uPool);
MaxFeeTxHandler student2 = new MaxFeeTxHandler(new UTXOPool(uPool));
MaxFeeTxHandlerVerifier verifier2 = new MaxFeeTxHandlerVerifier(uPool);
MaxFeeTxHandler student3 = new MaxFeeTxHandler(new UTXOPool(uPool));
MaxFeeTxHandlerVerifier verifier3 = new MaxFeeTxHandlerVerifier(uPool);
System.out.println("Total Transactions = " + allTxs1.length);
Transaction[] stx1 = student1.handleTxs(copyTxs1);
System.out.println("Number of transactions returned valid by student = " + stx1.length);
boolean passed1 = verifier1.check(allTxs1, stx1);
System.out.println("Total Transactions = " + allTxs2.length);
Transaction[] stx2 = student2.handleTxs(copyTxs2);
System.out.println("Number of transactions returned valid by student = " + stx2.length);
boolean passed2 = verifier2.check(allTxs2, stx2);
System.out.println("Total Transactions = " + allTxs3.length);
Transaction[] stx3 = student3.handleTxs(copyTxs3);
System.out.println("Number of transactions returned valid by student = " + stx3.length);
boolean passed3 = verifier3.check(allTxs3, stx3);
return passed1 && passed2 && passed3;
}
private static boolean verifyPoolUpdate(Transaction[] allTxs1, Transaction[] allTxs2,
Transaction[] allTxs3, UTXOPool uPool) {
Transaction[] copyTxs1 = new Transaction[allTxs1.length];
for (int i = 0; i < copyTxs1.length; i++)
copyTxs1[i] = allTxs1[i];
Transaction[] copyTxs2 = new Transaction[allTxs2.length];
for (int i = 0; i < copyTxs2.length; i++)
copyTxs2[i] = allTxs2[i];
Transaction[] copyTxs3 = new Transaction[allTxs3.length];
for (int i = 0; i < copyTxs3.length; i++)
copyTxs3[i] = allTxs3[i];
MaxFeeTxHandler student = new MaxFeeTxHandler(new UTXOPool(uPool));
MaxFeeTxHandlerVerifier verifier = new MaxFeeTxHandlerVerifier(uPool);
System.out.println("Total Transactions = " + allTxs1.length);
Transaction[] stx1 = student.handleTxs(copyTxs1);
System.out.println("Number of transactions returned valid by student = " + stx1.length);
boolean passed1 = verifier.check(allTxs1, stx1);
System.out.println("Total Transactions = " + allTxs2.length);
Transaction[] stx2 = student.handleTxs(copyTxs2);
System.out.println("Number of transactions returned valid by student = " + stx2.length);
boolean passed2 = verifier.check(allTxs2, stx2);
System.out.println("Total Transactions = " + allTxs3.length);
Transaction[] stx3 = student.handleTxs(copyTxs3);
System.out.println("Number of transactions returned valid by student = " + stx3.length);
boolean passed3 = verifier.check(allTxs3, stx3);
return passed1 && passed2 && passed3;
}
// all transactions are simple and valid
public static int test1(UTXOPool uPool) throws FileNotFoundException, IOException {
System.out.println("Test 1: test handleTransactions() with simple and valid transactions");
String common = "files/SampleMaxFeeTxsTest1-";
String file1 = common + "1.txt";
String file2 = common + "2.txt";
String file3 = common + "3.txt";
Transaction[] allTxs1 = TransactionsArrayFileHandler.readTransactionsFromFile(file1);
Transaction[] allTxs2 = TransactionsArrayFileHandler.readTransactionsFromFile(file2);
Transaction[] allTxs3 = TransactionsArrayFileHandler.readTransactionsFromFile(file3);
return UtilCOS.printPassFail(verify(allTxs1, allTxs2, allTxs3, uPool));
}
public static void main(String[] args) throws FileNotFoundException, IOException {
String skpFile = "files/SampleMaxFeeKeyPairs.txt";
String supFile = "files/SampleMaxFeeUTXOPool.txt";
SampleKeyPairs skp = SampleKeyPairsFileHandler.readKeyPairsFromFile(skpFile);
SampleUTXOPool sup = SampleUTXOPoolFileHandler.readSampleUTXOPoolFromFile(skp, supFile);
UTXOPool uPool = sup.getPool();
int total = 0;
int numTests = 1;
UtilCOS.printTotalNumTests(numTests);
total += test1(uPool);
System.out.println();
UtilCOS.printNumTestsPassed(total, numTests);
}
}