2021-02-24 22:50:47 +00:00
|
|
|
package kv
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
2022-01-06 17:33:08 +00:00
|
|
|
fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams"
|
2021-09-15 22:55:11 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/crypto/hash"
|
2021-09-23 18:53:46 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/testing/require"
|
2021-02-24 22:50:47 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestStore_GraffitiOrderedIndex_ReadAndWrite(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
2022-01-06 17:33:08 +00:00
|
|
|
db := setupDB(t, [][fieldparams.BLSPubkeyLength]byte{})
|
2021-02-24 22:50:47 +00:00
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
want uint64
|
|
|
|
write uint64
|
|
|
|
fileHash [32]byte
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "empty then write",
|
|
|
|
want: 0,
|
|
|
|
write: 15,
|
2021-09-15 22:55:11 +00:00
|
|
|
fileHash: hash.Hash([]byte("one")),
|
2021-02-24 22:50:47 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "update with same file hash",
|
|
|
|
want: 15,
|
|
|
|
write: 20,
|
2021-09-15 22:55:11 +00:00
|
|
|
fileHash: hash.Hash([]byte("one")),
|
2021-02-24 22:50:47 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "continued updates",
|
|
|
|
want: 20,
|
|
|
|
write: 21,
|
2021-09-15 22:55:11 +00:00
|
|
|
fileHash: hash.Hash([]byte("one")),
|
2021-02-24 22:50:47 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "reset with new file hash",
|
|
|
|
want: 0,
|
|
|
|
write: 10,
|
2021-09-15 22:55:11 +00:00
|
|
|
fileHash: hash.Hash([]byte("two")),
|
2021-02-24 22:50:47 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "read with new file hash",
|
|
|
|
want: 10,
|
2021-09-15 22:55:11 +00:00
|
|
|
fileHash: hash.Hash([]byte("two")),
|
2021-02-24 22:50:47 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
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)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|