diff --git a/store/store_test.go b/store/store_test.go index 358aae2..6955bc1 100644 --- a/store/store_test.go +++ b/store/store_test.go @@ -541,3 +541,37 @@ func TestPebbleStore_TransferTransactions(t *testing.T) { _, err = store.GetTransferTransactionsPerTick(ctx, idOne, 14) require.EqualError(t, err, ErrNotFound.Error()) } + +func TestPebbleStore_QChainHash(t *testing.T) { + ctx := context.Background() + + // Setup test environment + dbDir, err := os.MkdirTemp("", "pebble_test") + require.NoError(t, err) + defer os.RemoveAll(dbDir) + + db, err := pebble.Open(filepath.Join(dbDir, "testdb"), &pebble.Options{}) + require.NoError(t, err) + defer db.Close() + + logger, _ := zap.NewDevelopment() + store := NewPebbleStore(db, logger) + + // Sample QChainHash for testing + tickNumber := uint64(12795005) + qChainHash := []byte("qChainHash") + + // Set QChainHash + err = store.PutQChainDigest(ctx, tickNumber, qChainHash) + require.NoError(t, err) + + // Get QChainHash + retrievedQChainHash, err := store.GetQChainDigest(ctx, tickNumber) + require.NoError(t, err) + require.Equal(t, qChainHash, retrievedQChainHash) + + // Test retrieval of non-existent QChainHash + _, err = store.GetQChainDigest(ctx, 999) // Assuming 999 is a tick number that wasn't stored + require.Error(t, err) + require.Equal(t, ErrNotFound, err) +} diff --git a/validator/qchain/qchain_test.go b/validator/qchain/qchain_test.go new file mode 100644 index 0000000..187d21b --- /dev/null +++ b/validator/qchain/qchain_test.go @@ -0,0 +1,28 @@ +package qchain + +import ( + "github.com/stretchr/testify/require" + "testing" +) + +func TestQChain_Digest(t *testing.T) { + qChain := QChain{ + ComputorIndex: 1, + Epoch: 20, + Tick: 30, + Millisecond: 40, + Second: 50, + Minute: 60, + Hour: 70, + Day: 80, + Month: 90, + Year: 10, + PreviousResourceTestingDigest: 13423432, + PreviousSpectrumDigest: [32]byte{}, + PreviousUniverseDigest: [32]byte{}, + PreviousComputerDigest: [32]byte{}, + TxDigest: [32]byte{}, + } + _, err := qChain.Digest() + require.NoError(t, err) +}