mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-05 17:22:18 +00:00
d077483577
* v3 import renamings * tidy * fmt * rev * Update beacon-chain/core/epoch/precompute/reward_penalty_test.go * Update beacon-chain/core/helpers/validators_test.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/iface/BUILD.bazel * Update beacon-chain/db/kv/kv.go * Update beacon-chain/db/kv/state.go * Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go * Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go * Update beacon-chain/sync/initial-sync/service.go * fix deps * fix bad replacements * fix bad replacements * change back * gohashtree version * fix deps Co-authored-by: Nishant Das <nishdas93@gmail.com> Co-authored-by: Potuz <potuz@prysmaticlabs.com>
61 lines
1.3 KiB
Go
61 lines
1.3 KiB
Go
package kv
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
|
|
"github.com/prysmaticlabs/prysm/v3/crypto/hash"
|
|
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
|
)
|
|
|
|
func TestStore_GraffitiOrderedIndex_ReadAndWrite(t *testing.T) {
|
|
ctx := context.Background()
|
|
db := setupDB(t, [][fieldparams.BLSPubkeyLength]byte{})
|
|
tests := []struct {
|
|
name string
|
|
want uint64
|
|
write uint64
|
|
fileHash [32]byte
|
|
}{
|
|
{
|
|
name: "empty then write",
|
|
want: 0,
|
|
write: 15,
|
|
fileHash: hash.Hash([]byte("one")),
|
|
},
|
|
{
|
|
name: "update with same file hash",
|
|
want: 15,
|
|
write: 20,
|
|
fileHash: hash.Hash([]byte("one")),
|
|
},
|
|
{
|
|
name: "continued updates",
|
|
want: 20,
|
|
write: 21,
|
|
fileHash: hash.Hash([]byte("one")),
|
|
},
|
|
{
|
|
name: "reset with new file hash",
|
|
want: 0,
|
|
write: 10,
|
|
fileHash: hash.Hash([]byte("two")),
|
|
},
|
|
{
|
|
name: "read with new file hash",
|
|
want: 10,
|
|
fileHash: hash.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)
|
|
})
|
|
}
|
|
}
|