forked from cerc-io/ipld-eth-server
(VDB-950) Write raw diffs before transforming
- Raw field we can reference by FK for related data - Enables replay for unwatched or mistransformed diffs
This commit is contained in:
committed by
Ian Norden
parent
1178940047
commit
56ce8bdb41
@@ -23,19 +23,21 @@ import (
|
||||
"github.com/vulcanize/vulcanizedb/libraries/shared/storage"
|
||||
"github.com/vulcanize/vulcanizedb/libraries/shared/storage/utils"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories"
|
||||
"github.com/vulcanize/vulcanizedb/test_config"
|
||||
)
|
||||
|
||||
var _ = Describe("Storage queue", func() {
|
||||
var (
|
||||
db *postgres.DB
|
||||
diff utils.StorageDiff
|
||||
queue storage.IStorageQueue
|
||||
db *postgres.DB
|
||||
diff utils.PersistedStorageDiff
|
||||
diffRepository repositories.StorageDiffRepository
|
||||
queue storage.IStorageQueue
|
||||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
fakeAddr := "0x123456"
|
||||
diff = utils.StorageDiff{
|
||||
rawDiff := utils.StorageDiffInput{
|
||||
HashedAddress: utils.HexToKeccak256Hash(fakeAddr),
|
||||
BlockHash: common.HexToHash("0x678901"),
|
||||
BlockHeight: 987,
|
||||
@@ -44,6 +46,10 @@ var _ = Describe("Storage queue", func() {
|
||||
}
|
||||
db = test_config.NewTestDB(test_config.NewTestNode())
|
||||
test_config.CleanTestDB(db)
|
||||
diffRepository = repositories.NewStorageDiffRepository(db)
|
||||
diffID, insertDiffErr := diffRepository.CreateStorageDiff(rawDiff)
|
||||
Expect(insertDiffErr).NotTo(HaveOccurred())
|
||||
diff = utils.ToPersistedDiff(rawDiff, diffID)
|
||||
queue = storage.NewStorageQueue(db)
|
||||
addErr := queue.Add(diff)
|
||||
Expect(addErr).NotTo(HaveOccurred())
|
||||
@@ -51,8 +57,10 @@ var _ = Describe("Storage queue", func() {
|
||||
|
||||
Describe("Add", func() {
|
||||
It("adds a storage diff to the db", func() {
|
||||
var result utils.StorageDiff
|
||||
getErr := db.Get(&result, `SELECT contract, block_hash, block_height, storage_key, storage_value FROM public.queued_storage`)
|
||||
var result utils.PersistedStorageDiff
|
||||
getErr := db.Get(&result, `SELECT storage_diff.id, hashed_address, block_hash, block_height, storage_key, storage_value
|
||||
FROM public.queued_storage
|
||||
LEFT JOIN public.storage_diff ON queued_storage.diff_id = storage_diff.id`)
|
||||
Expect(getErr).NotTo(HaveOccurred())
|
||||
Expect(result).To(Equal(diff))
|
||||
})
|
||||
@@ -82,14 +90,17 @@ var _ = Describe("Storage queue", func() {
|
||||
|
||||
It("gets all storage diffs from db", func() {
|
||||
fakeAddr := "0x234567"
|
||||
diffTwo := utils.StorageDiff{
|
||||
diffTwo := utils.StorageDiffInput{
|
||||
HashedAddress: utils.HexToKeccak256Hash(fakeAddr),
|
||||
BlockHash: common.HexToHash("0x678902"),
|
||||
BlockHeight: 988,
|
||||
StorageKey: common.HexToHash("0x654322"),
|
||||
StorageValue: common.HexToHash("0x198766"),
|
||||
}
|
||||
addErr := queue.Add(diffTwo)
|
||||
persistedDiffTwoID, insertDiffErr := diffRepository.CreateStorageDiff(diffTwo)
|
||||
Expect(insertDiffErr).NotTo(HaveOccurred())
|
||||
persistedDiffTwo := utils.ToPersistedDiff(diffTwo, persistedDiffTwoID)
|
||||
addErr := queue.Add(persistedDiffTwo)
|
||||
Expect(addErr).NotTo(HaveOccurred())
|
||||
|
||||
diffs, err := queue.GetAll()
|
||||
|
||||
Reference in New Issue
Block a user