Skip to content
This repository was archived by the owner on Jul 5, 2024. It is now read-only.

Commit 43add22

Browse files
committed
test: adding proof len check
1 parent b82ea41 commit 43add22

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

geth-utils/gethutil/mpt/witness/gen_witness_transactions_test.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,20 +98,36 @@ func transactionsStackTrieInsertionTemplate(t *testing.T, n int) {
9898
rlp_last_tx, _ := txs[n-1].MarshalBinary()
9999
last_proofC := proofs[len(proofs)-1].GetProofC()
100100

101+
tx_len := len(txs)
102+
proof_len := len(proofs)
103+
101104
// Proof of the first tx is appended at the end of the proofs if len(tx) < 0x80
102105
// That's why we minus 2 here.
103-
if len(txs) > 1 && len(txs) < 256 {
104-
last_proofC = proofs[len(proofs)-2].GetProofC()
106+
if tx_len > 1 && tx_len < 256 {
107+
last_proofC = proofs[proof_len-2].GetProofC()
105108
}
106109
last_leaf_proof := last_proofC[len(last_proofC)-1]
107110

111+
if tx_len != proof_len {
112+
fmt.Println("Expected to have", tx_len, ", but only got", proof_len)
113+
t.Fail()
114+
}
115+
108116
if !bytes.Equal(last_leaf_proof, rlp_last_tx) {
109117
fmt.Println("- last_tx ", rlp_last_tx)
110118
fmt.Println("- last_proof ", last_leaf_proof)
111119
t.Fail()
112120
}
113121
}
114122

123+
// func TestJson(t *testing.T, n int) {
124+
// txs := makeTransactions(n)
125+
// db := rawdb.NewMemoryDatabase()
126+
// stackTrie := trie.NewStackTrie(db)
127+
128+
// proofs, _ := stackTrie.UpdateAndGetProofs(db, types.Transactions(txs))
129+
// }
130+
115131
func TestStackTrieInsertion_1Tx(t *testing.T) {
116132
// Only one leaf
117133
transactionsStackTrieInsertionTemplate(t, 1)

0 commit comments

Comments
 (0)