2023-06-01 20:14:08 +00:00
|
|
|
package rawdb
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
2023-06-22 20:00:05 +00:00
|
|
|
"math/big"
|
|
|
|
|
2023-06-01 20:14:08 +00:00
|
|
|
"github.com/ethereum/go-ethereum/ethdb"
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-06-22 20:00:05 +00:00
|
|
|
func TestPlugethInjections(t *testing.T) {
|
|
|
|
var valuesRaw [][]byte
|
|
|
|
var valuesRLP []*big.Int
|
|
|
|
for x := 0; x < 100; x++ {
|
|
|
|
v := getChunk(256, x)
|
|
|
|
valuesRaw = append(valuesRaw, v)
|
|
|
|
iv := big.NewInt(int64(x))
|
|
|
|
iv = iv.Exp(iv, iv, nil)
|
|
|
|
valuesRLP = append(valuesRLP, iv)
|
|
|
|
}
|
|
|
|
tables := map[string]bool{"raw": true, "rlp": false}
|
|
|
|
f, _ := newFreezerForTesting(t, tables)
|
|
|
|
|
|
|
|
t.Run(fmt.Sprintf("test plugeth injections"), func(t *testing.T) {
|
2023-06-01 20:14:08 +00:00
|
|
|
called := false
|
2023-06-22 20:00:05 +00:00
|
|
|
modifyAncientsInjection = &called
|
2023-06-01 20:14:08 +00:00
|
|
|
|
2023-06-22 20:00:05 +00:00
|
|
|
_, _ = f.ModifyAncients(func(op ethdb.AncientWriteOp) error {
|
2023-06-01 20:14:08 +00:00
|
|
|
|
2023-06-22 20:00:05 +00:00
|
|
|
appendRawInjection = &called
|
|
|
|
_ = op.AppendRaw("raw", uint64(0), valuesRaw[0])
|
|
|
|
if *appendRawInjection != true {
|
|
|
|
t.Fatalf("pluginTrackUpdate injection in AppendRaw not called")
|
|
|
|
}
|
2023-06-01 20:14:08 +00:00
|
|
|
|
2023-06-22 20:00:05 +00:00
|
|
|
appendInjection = &called
|
|
|
|
_ = op.Append("rlp", uint64(0), valuesRaw[0])
|
|
|
|
if *appendInjection != true {
|
|
|
|
t.Fatalf("pluginTrackUpdate injection in Append not called")
|
|
|
|
}
|
2023-06-01 20:14:08 +00:00
|
|
|
|
2023-06-22 20:00:05 +00:00
|
|
|
return nil
|
|
|
|
})
|
|
|
|
if *modifyAncientsInjection != true {
|
|
|
|
t.Fatalf("pluginCommitUpdate injection in ModifyAncients not called")
|
2023-06-01 20:14:08 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|