prysm-pulse/validator/db/kv/graffiti_test.go
Josh Yudaken f0eb843138
Graffiti ordered index (#8482)
* Added ordered option to graffiti file

* Updated validator to use Ordered graffiti

* Track graffiti ordered index in db

* Update `ordered` to only emit each graffiti once

Co-authored-by: pinglamb <pinglambs@gmail.com>
2021-02-24 22:50:47 +00:00

60 lines
1.2 KiB
Go

package kv
import (
"context"
"testing"
"github.com/prysmaticlabs/prysm/shared/hashutil"
"github.com/prysmaticlabs/prysm/shared/testutil/require"
)
func TestStore_GraffitiOrderedIndex_ReadAndWrite(t *testing.T) {
ctx := context.Background()
db := setupDB(t, [][48]byte{})
tests := []struct {
name string
want uint64
write uint64
fileHash [32]byte
}{
{
name: "empty then write",
want: 0,
write: 15,
fileHash: hashutil.Hash([]byte("one")),
},
{
name: "update with same file hash",
want: 15,
write: 20,
fileHash: hashutil.Hash([]byte("one")),
},
{
name: "continued updates",
want: 20,
write: 21,
fileHash: hashutil.Hash([]byte("one")),
},
{
name: "reset with new file hash",
want: 0,
write: 10,
fileHash: hashutil.Hash([]byte("two")),
},
{
name: "read with new file hash",
want: 10,
fileHash: hashutil.Hash([]byte("two")),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := db.GraffitiOrderedIndex(ctx, tt.fileHash)
require.NoError(t, err)
require.DeepEqual(t, tt.want, got)
err = db.SaveGraffitiOrderedIndex(ctx, tt.write)
require.NoError(t, err)
})
}
}