|
1 | 1 | package witness
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "bytes" |
4 | 5 | "fmt"
|
5 | 6 | "main/gethutil/mpt/trie"
|
6 | 7 | "main/gethutil/mpt/types"
|
@@ -87,59 +88,67 @@ The second element is the 16-th transaction. For example, the third byte (16) re
|
87 | 88 | the transaction index.
|
88 | 89 | */
|
89 | 90 |
|
90 |
| -func transactionsStackTrieInsertionTemplate(n int) { |
| 91 | +func transactionsStackTrieInsertionTemplate(t *testing.T, n int) { |
91 | 92 | txs := makeTransactions(n)
|
92 | 93 | db := rawdb.NewMemoryDatabase()
|
93 | 94 | stackTrie := trie.NewStackTrie(db)
|
94 | 95 |
|
95 |
| - stackTrie.UpdateAndGetProofs(db, types.Transactions(txs)) |
| 96 | + proofs, _ := stackTrie.UpdateAndGetProofs(db, types.Transactions(txs)) |
96 | 97 |
|
97 |
| - fmt.Println("===") |
| 98 | + rlp_last_tx, _ := txs[n-1].MarshalBinary() |
| 99 | + last_proofC := proofs[len(proofs)-1].GetProofC() |
| 100 | + last_leaf_proof := last_proofC[len(last_proofC)-1] |
| 101 | + |
| 102 | + if !bytes.Equal(last_leaf_proof, rlp_last_tx) { |
| 103 | + fmt.Println("- last_tx ", rlp_last_tx) |
| 104 | + fmt.Println("- last_proof ", last_leaf_proof) |
| 105 | + t.Fail() |
| 106 | + } |
98 | 107 | }
|
99 | 108 |
|
100 | 109 | func TestStackTrieInsertion_1Tx(t *testing.T) {
|
101 | 110 | // Only one leaf
|
102 |
| - transactionsStackTrieInsertionTemplate(1) |
| 111 | + transactionsStackTrieInsertionTemplate(t, 1) |
103 | 112 | }
|
104 | 113 |
|
105 | 114 | func TestStackTrieInsertion_2Txs(t *testing.T) {
|
106 | 115 | // One ext. node and one leaf
|
107 |
| - transactionsStackTrieInsertionTemplate(2) |
| 116 | + transactionsStackTrieInsertionTemplate(t, 2) |
108 | 117 | }
|
109 | 118 |
|
110 | 119 | func TestStackTrieInsertion_3Txs(t *testing.T) {
|
111 | 120 | // One ext. node, one branch and one leaf
|
112 |
| - transactionsStackTrieInsertionTemplate(3) |
| 121 | + transactionsStackTrieInsertionTemplate(t, 3) |
113 | 122 | }
|
114 | 123 |
|
115 | 124 | func TestStackTrieInsertion_4Txs(t *testing.T) {
|
116 | 125 | // One ext. node, one branch and two leaves
|
117 |
| - transactionsStackTrieInsertionTemplate(4) |
| 126 | + transactionsStackTrieInsertionTemplate(t, 4) |
118 | 127 | }
|
119 | 128 |
|
120 | 129 | func TestStackTrieInsertion_16Txs(t *testing.T) {
|
121 | 130 | // One ext. node and one branch with full leaves (16 leaves)
|
122 |
| - transactionsStackTrieInsertionTemplate(16) |
| 131 | + transactionsStackTrieInsertionTemplate(t, 16) |
123 | 132 | }
|
124 | 133 |
|
125 | 134 | func TestStackTrieInsertion_17Txs(t *testing.T) {
|
126 | 135 | // One ext. node, 3 branches and 17 leaves.
|
127 | 136 | // The original ext. node turns into a branch (B1) which has children at position 0 and 1.
|
128 | 137 | // At position 0 of B1, it has a branch with full leaves
|
129 | 138 | // At position 1 of B1, it has a newly leaf
|
130 |
| - transactionsStackTrieInsertionTemplate(17) |
| 139 | + transactionsStackTrieInsertionTemplate(t, 17) |
131 | 140 | }
|
132 | 141 |
|
133 | 142 | func TestStackTrieInsertion_33Txs(t *testing.T) {
|
134 | 143 | // Follow above test and have one more branch generated
|
135 |
| - transactionsStackTrieInsertionTemplate(33) |
| 144 | + transactionsStackTrieInsertionTemplate(t, 33) |
136 | 145 | }
|
137 | 146 |
|
138 | 147 | func TestStackTrieInsertion_ManyTxs(t *testing.T) {
|
139 | 148 | // Just randomly picking a large number.
|
140 | 149 | // The cap of block gas limit is 30M, the minimum gas cost of a tx is 21k
|
141 | 150 | // 30M / 21k ~= 1429
|
142 |
| - transactionsStackTrieInsertionTemplate(2000) |
| 151 | + transactionsStackTrieInsertionTemplate(t, 2000) |
143 | 152 | }
|
144 | 153 |
|
145 | 154 | /*
|
|
0 commit comments