2019-02-25 04:26:42 +00:00
|
|
|
package storage_test
|
2019-02-19 21:01:07 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
|
|
. "github.com/onsi/ginkgo"
|
|
|
|
. "github.com/onsi/gomega"
|
2019-04-25 02:49:33 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
2019-02-25 04:26:42 +00:00
|
|
|
|
|
|
|
"github.com/vulcanize/vulcanizedb/libraries/shared/storage"
|
|
|
|
"github.com/vulcanize/vulcanizedb/libraries/shared/storage/utils"
|
2019-02-19 21:01:07 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/test_config"
|
|
|
|
)
|
|
|
|
|
|
|
|
var _ = Describe("Storage queue", func() {
|
2019-04-25 02:49:33 +00:00
|
|
|
var (
|
|
|
|
db *postgres.DB
|
|
|
|
row utils.StorageDiffRow
|
|
|
|
queue storage.IStorageQueue
|
|
|
|
)
|
|
|
|
|
|
|
|
BeforeEach(func() {
|
|
|
|
row = utils.StorageDiffRow{
|
2019-02-19 21:01:07 +00:00
|
|
|
Contract: common.HexToAddress("0x123456"),
|
|
|
|
BlockHash: common.HexToHash("0x678901"),
|
|
|
|
BlockHeight: 987,
|
|
|
|
StorageKey: common.HexToHash("0x654321"),
|
|
|
|
StorageValue: common.HexToHash("0x198765"),
|
|
|
|
}
|
2019-04-25 02:49:33 +00:00
|
|
|
db = test_config.NewTestDB(test_config.NewTestNode())
|
|
|
|
test_config.CleanTestDB(db)
|
|
|
|
queue = storage.NewStorageQueue(db)
|
2019-02-19 21:01:07 +00:00
|
|
|
addErr := queue.Add(row)
|
|
|
|
Expect(addErr).NotTo(HaveOccurred())
|
2019-04-25 02:49:33 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
It("adds a storage row to the db", func() {
|
2019-02-25 04:26:42 +00:00
|
|
|
var result utils.StorageDiffRow
|
2019-02-19 21:01:07 +00:00
|
|
|
getErr := db.Get(&result, `SELECT contract, block_hash, block_height, storage_key, storage_value FROM public.queued_storage`)
|
|
|
|
Expect(getErr).NotTo(HaveOccurred())
|
|
|
|
Expect(result).To(Equal(row))
|
|
|
|
})
|
2019-04-25 02:49:33 +00:00
|
|
|
|
|
|
|
It("deletes storage row from db", func() {
|
|
|
|
rows, getErr := queue.GetAll()
|
|
|
|
Expect(getErr).NotTo(HaveOccurred())
|
|
|
|
Expect(len(rows)).To(Equal(1))
|
|
|
|
|
|
|
|
err := queue.Delete(rows[0].Id)
|
|
|
|
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
remainingRows, secondGetErr := queue.GetAll()
|
|
|
|
Expect(secondGetErr).NotTo(HaveOccurred())
|
|
|
|
Expect(len(remainingRows)).To(BeZero())
|
|
|
|
})
|
|
|
|
|
|
|
|
It("gets all storage rows from db", func() {
|
|
|
|
rowTwo := utils.StorageDiffRow{
|
|
|
|
Contract: common.HexToAddress("0x123456"),
|
|
|
|
BlockHash: common.HexToHash("0x678902"),
|
|
|
|
BlockHeight: 988,
|
|
|
|
StorageKey: common.HexToHash("0x654322"),
|
|
|
|
StorageValue: common.HexToHash("0x198766"),
|
|
|
|
}
|
|
|
|
addErr := queue.Add(rowTwo)
|
|
|
|
Expect(addErr).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
rows, err := queue.GetAll()
|
|
|
|
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(len(rows)).To(Equal(2))
|
|
|
|
Expect(rows[0]).NotTo(Equal(rows[1]))
|
|
|
|
Expect(rows[0].Id).NotTo(BeZero())
|
|
|
|
Expect(rows[0].Contract).To(Or(Equal(row.Contract), Equal(rowTwo.Contract)))
|
|
|
|
Expect(rows[0].BlockHash).To(Or(Equal(row.BlockHash), Equal(rowTwo.BlockHash)))
|
|
|
|
Expect(rows[0].BlockHeight).To(Or(Equal(row.BlockHeight), Equal(rowTwo.BlockHeight)))
|
|
|
|
Expect(rows[0].StorageKey).To(Or(Equal(row.StorageKey), Equal(rowTwo.StorageKey)))
|
|
|
|
Expect(rows[0].StorageValue).To(Or(Equal(row.StorageValue), Equal(rowTwo.StorageValue)))
|
|
|
|
Expect(rows[1].Id).NotTo(BeZero())
|
|
|
|
Expect(rows[1].Contract).To(Or(Equal(row.Contract), Equal(rowTwo.Contract)))
|
|
|
|
Expect(rows[1].BlockHash).To(Or(Equal(row.BlockHash), Equal(rowTwo.BlockHash)))
|
|
|
|
Expect(rows[1].BlockHeight).To(Or(Equal(row.BlockHeight), Equal(rowTwo.BlockHeight)))
|
|
|
|
Expect(rows[1].StorageKey).To(Or(Equal(row.StorageKey), Equal(rowTwo.StorageKey)))
|
|
|
|
Expect(rows[1].StorageValue).To(Or(Equal(row.StorageValue), Equal(rowTwo.StorageValue)))
|
|
|
|
})
|
2019-02-19 21:01:07 +00:00
|
|
|
})
|