tendermint / tm-db

Common database interface for various database backends for Tendermint Core and Cosmos SDK
Apache License 2.0
89 stars 136 forks source link

Business logic error: PrefixDB unit tests #336

Open ivansukach opened 1 year ago

ivansukach commented 1 year ago

https://github.com/tendermint/tm-db/blob/master/prefixdb_test.go#L120

For each iteration you are going through values [0; len(mine)) for key := range mine { and allocate slice of 4 bytes bs := make([]byte, 4) Then you splitting into 4 bytes golang runes in reverse order binary.LittleEndian.PutUint32(bs, uint32(key)) Finally
if err := db.Delete(bs); err != nil { t.Errorf("Delete %q: %v", key, err) } You try to delete element by the index of rune in the key pattern in little-endian order.

ivansukach commented 1 year ago

Solution: // Delete all the keys we inserted. for k := 1; k <= numKeys; k++ { key := taskKey(i, k) // say, "task--key-" if err := db.Delete(key); err != nil { t.Errorf("Delete %q: %v", key, err) } }