Add tests for Cat storage diff transformer

Update schema after rebase migrations

Fix small issues from review
This commit is contained in:
Edvard 2019-02-18 15:21:16 +01:00
parent cd6611d2ec
commit 5746de7c97
7 changed files with 521 additions and 21 deletions

View File

@ -2,8 +2,8 @@
-- PostgreSQL database dump -- PostgreSQL database dump
-- --
-- Dumped from database version 10.4 -- Dumped from database version 10.5
-- Dumped by pg_dump version 10.4 -- Dumped by pg_dump version 10.5
SET statement_timeout = 0; SET statement_timeout = 0;
SET lock_timeout = 0; SET lock_timeout = 0;

View File

@ -0,0 +1,19 @@
package cat_test
import (
"github.com/sirupsen/logrus"
"io/ioutil"
"testing"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
func TestCat(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Cat Suite")
}
var _ = BeforeSuite(func() {
logrus.SetOutput(ioutil.Discard)
})

View File

@ -151,9 +151,8 @@ func (mappings CatMappings) loadFlipsKeys() error {
} }
last := maxFlip.Int64() last := maxFlip.Int64()
var flipStr string
for flip := 0; int64(flip) <= last; flip++ { for flip := 0; int64(flip) <= last; flip++ {
flipStr = strconv.Itoa(flip) flipStr := strconv.Itoa(flip)
mappings.mappings[getFlipIlkKey(flipStr)] = getFlipIlkMetadata(flipStr) mappings.mappings[getFlipIlkKey(flipStr)] = getFlipIlkMetadata(flipStr)
mappings.mappings[getFlipUrnKey(flipStr)] = getFlipUrnMetadata(flipStr) mappings.mappings[getFlipUrnKey(flipStr)] = getFlipUrnMetadata(flipStr)
mappings.mappings[getFlipInkKey(flipStr)] = getFlipInkMetadata(flipStr) mappings.mappings[getFlipInkKey(flipStr)] = getFlipInkMetadata(flipStr)
@ -162,38 +161,38 @@ func (mappings CatMappings) loadFlipsKeys() error {
return nil return nil
} }
func getFlipIlkKey(nflip string) common.Hash { func getFlipIlkKey(flip string) common.Hash {
return storage_diffs.GetMapping(FlipsMappingIndex, nflip) return storage_diffs.GetMapping(FlipsMappingIndex, flip)
} }
func getFlipIlkMetadata(nflip string) shared.StorageValueMetadata { func getFlipIlkMetadata(flip string) shared.StorageValueMetadata {
keys := map[shared.Key]string{shared.Flip: nflip} keys := map[shared.Key]string{shared.Flip: flip}
return shared.GetStorageValueMetadata(FlipIlk, keys, shared.Bytes32) return shared.GetStorageValueMetadata(FlipIlk, keys, shared.Bytes32)
} }
func getFlipUrnKey(nflip string) common.Hash { func getFlipUrnKey(flip string) common.Hash {
return storage_diffs.GetIncrementedKey(getFlipIlkKey(nflip), 1) return storage_diffs.GetIncrementedKey(getFlipIlkKey(flip), 1)
} }
func getFlipUrnMetadata(nflip string) shared.StorageValueMetadata { func getFlipUrnMetadata(flip string) shared.StorageValueMetadata {
keys := map[shared.Key]string{shared.Flip: nflip} keys := map[shared.Key]string{shared.Flip: flip}
return shared.GetStorageValueMetadata(FlipUrn, keys, shared.Bytes32) return shared.GetStorageValueMetadata(FlipUrn, keys, shared.Bytes32)
} }
func getFlipInkKey(nflip string) common.Hash { func getFlipInkKey(flip string) common.Hash {
return storage_diffs.GetIncrementedKey(getFlipIlkKey(nflip), 2) return storage_diffs.GetIncrementedKey(getFlipIlkKey(flip), 2)
} }
func getFlipInkMetadata(nflip string) shared.StorageValueMetadata { func getFlipInkMetadata(flip string) shared.StorageValueMetadata {
keys := map[shared.Key]string{shared.Flip: nflip} keys := map[shared.Key]string{shared.Flip: flip}
return shared.GetStorageValueMetadata(FlipInk, keys, shared.Uint256) return shared.GetStorageValueMetadata(FlipInk, keys, shared.Uint256)
} }
func getFlipTabKey(nflip string) common.Hash { func getFlipTabKey(flip string) common.Hash {
return storage_diffs.GetIncrementedKey(getFlipIlkKey(nflip), 3) return storage_diffs.GetIncrementedKey(getFlipIlkKey(flip), 3)
} }
func getFlipTabMetadata(nflip string) shared.StorageValueMetadata { func getFlipTabMetadata(flip string) shared.StorageValueMetadata {
keys := map[shared.Key]string{shared.Flip: nflip} keys := map[shared.Key]string{shared.Flip: flip}
return shared.GetStorageValueMetadata(FlipTab, keys, shared.Uint256) return shared.GetStorageValueMetadata(FlipTab, keys, shared.Uint256)
} }

View File

@ -0,0 +1,177 @@
package cat_test
import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/vulcanize/vulcanizedb/pkg/fakes"
"github.com/vulcanize/vulcanizedb/pkg/transformers/storage_diffs"
"github.com/vulcanize/vulcanizedb/pkg/transformers/storage_diffs/maker/cat"
"github.com/vulcanize/vulcanizedb/pkg/transformers/storage_diffs/maker/test_helpers"
"github.com/vulcanize/vulcanizedb/pkg/transformers/storage_diffs/shared"
"math/big"
)
var _ = Describe("Cat storage mappings", func() {
const (
fakeIlk = "fakeIlk"
fakeFlip = "2"
)
var (
storageRepository *test_helpers.MockMakerStorageRepository
mappings cat.CatMappings
)
BeforeEach(func() {
storageRepository = &test_helpers.MockMakerStorageRepository{}
mappings = cat.CatMappings{StorageRepository: storageRepository}
})
Describe("looking up static keys", func() {
It("returns value metadata if key exists", func() {
Expect(mappings.Lookup(cat.NFlipKey)).To(Equal(cat.NFlipMetadata))
Expect(mappings.Lookup(cat.LiveKey)).To(Equal(cat.LiveMetadata))
Expect(mappings.Lookup(cat.VatKey)).To(Equal(cat.VatMetadata))
Expect(mappings.Lookup(cat.PitKey)).To(Equal(cat.PitMetadata))
Expect(mappings.Lookup(cat.VowKey)).To(Equal(cat.VowMetadata))
})
It("returns error if key does not exist", func() {
_, err := mappings.Lookup(common.HexToHash(fakes.FakeHash.Hex()))
Expect(err).To(HaveOccurred())
Expect(err).To(MatchError(shared.ErrStorageKeyNotFound{Key: fakes.FakeHash.Hex()}))
})
})
Describe("looking up dynamic keys", func() {
It("refreshes mappings from repository if key not found", func() {
_, _ = mappings.Lookup(fakes.FakeHash)
Expect(storageRepository.GetIlksCalled).To(BeTrue())
Expect(storageRepository.GetMaxFlipCalled).To(BeTrue())
})
It("returns error if ilks lookup fails", func() {
storageRepository.GetIlksError = fakes.FakeError
_, err := mappings.Lookup(fakes.FakeHash)
Expect(err).To(HaveOccurred())
Expect(err).To(MatchError(fakes.FakeError))
})
It("returns error if max flip lookup fails", func() {
storageRepository.GetMaxFlipError = fakes.FakeError
_, err := mappings.Lookup(fakes.FakeHash)
Expect(err).To(HaveOccurred())
Expect(err).To(MatchError(fakes.FakeError))
})
It("interpolates flips up to max", func() {
storageRepository.MaxFlip = big.NewInt(1)
_, err := mappings.Lookup(storage_diffs.GetMapping(storage_diffs.IndexTwo, "0"))
Expect(err).NotTo(HaveOccurred())
_, err = mappings.Lookup(storage_diffs.GetMapping(storage_diffs.IndexTwo, "1"))
Expect(err).NotTo(HaveOccurred())
})
Describe("ilk", func() {
var ilkFlipKey = common.BytesToHash(crypto.Keccak256(common.FromHex(fakeIlk + cat.IlksMappingIndex)))
BeforeEach(func() {
storageRepository.Ilks = []string{fakeIlk}
})
It("returns value metadata for ilk flip", func() {
expectedMetadata := shared.StorageValueMetadata{
Name: cat.IlkFlip,
Keys: map[shared.Key]string{shared.Ilk: fakeIlk},
Type: shared.Address,
}
Expect(mappings.Lookup(ilkFlipKey)).To(Equal(expectedMetadata))
})
It("returns value metadata for ilk chop", func() {
ilkChopKey := storage_diffs.GetIncrementedKey(ilkFlipKey, 1)
expectedMetadata := shared.StorageValueMetadata{
Name: cat.IlkChop,
Keys: map[shared.Key]string{shared.Ilk: fakeIlk},
Type: shared.Uint256,
}
Expect(mappings.Lookup(ilkChopKey)).To(Equal(expectedMetadata))
})
It("returns value metadata for ilk lump", func() {
ilkLumpKey := storage_diffs.GetIncrementedKey(ilkFlipKey, 2)
expectedMetadata := shared.StorageValueMetadata{
Name: cat.IlkLump,
Keys: map[shared.Key]string{shared.Ilk: fakeIlk},
Type: shared.Uint256,
}
Expect(mappings.Lookup(ilkLumpKey)).To(Equal(expectedMetadata))
})
})
Describe("flip", func() {
var flipIlkKey = common.BytesToHash(crypto.Keccak256(common.FromHex(fakeFlip + cat.FlipsMappingIndex)))
BeforeEach(func() {
storageRepository.MaxFlip = big.NewInt(2)
})
It("returns value metadata for flip ilk", func() {
expectedMetadata := shared.StorageValueMetadata{
Name: cat.FlipIlk,
Keys: map[shared.Key]string{shared.Flip: fakeFlip},
Type: shared.Bytes32,
}
actualMetadata, err := mappings.Lookup(flipIlkKey)
Expect(err).NotTo(HaveOccurred())
Expect(actualMetadata).To(Equal(expectedMetadata))
})
It("returns value metadata for flip urn", func() {
flipUrnKey := storage_diffs.GetIncrementedKey(flipIlkKey, 1)
expectedMetadata := shared.StorageValueMetadata{
Name: cat.FlipUrn,
Keys: map[shared.Key]string{shared.Flip: fakeFlip},
Type: shared.Bytes32,
}
actualMetadata, err := mappings.Lookup(flipUrnKey)
Expect(err).NotTo(HaveOccurred())
Expect(actualMetadata).To(Equal(expectedMetadata))
})
It("returns value metadata for flip ink", func() {
flipInkKey := storage_diffs.GetIncrementedKey(flipIlkKey, 2)
expectedMetadata := shared.StorageValueMetadata{
Name: cat.FlipInk,
Keys: map[shared.Key]string{shared.Flip: fakeFlip},
Type: shared.Uint256,
}
actualMetadata, err := mappings.Lookup(flipInkKey)
Expect(err).NotTo(HaveOccurred())
Expect(actualMetadata).To(Equal(expectedMetadata))
})
It("returns value metadata for flip tab", func() {
flipTabKey := storage_diffs.GetIncrementedKey(flipIlkKey, 3)
expectedMetadata := shared.StorageValueMetadata{
Name: cat.FlipTab,
Keys: map[shared.Key]string{shared.Flip: fakeFlip},
Type: shared.Uint256,
}
actualMetadata, err := mappings.Lookup(flipTabKey)
Expect(err).NotTo(HaveOccurred())
Expect(actualMetadata).To(Equal(expectedMetadata))
})
})
})
})

View File

@ -37,7 +37,7 @@ func (repository *CatStorageRepository) Create(blockNumber int, blockHash string
case FlipTab: case FlipTab:
return repository.insertFlipTab(blockNumber, blockHash, metadata, value.(string)) return repository.insertFlipTab(blockNumber, blockHash, metadata, value.(string))
default: default:
panic(fmt.Sprintf("unrecognized vat contract storage name: %s", metadata.Name)) panic(fmt.Sprintf("unrecognized cat contract storage name: %s", metadata.Name))
} }
} }

View File

@ -0,0 +1,294 @@
package cat_test
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
"github.com/vulcanize/vulcanizedb/pkg/transformers/storage_diffs/maker/cat"
"github.com/vulcanize/vulcanizedb/pkg/transformers/storage_diffs/shared"
"github.com/vulcanize/vulcanizedb/test_config"
)
var _ = Describe("Cat storage repository", func() {
var (
db *postgres.DB
repo cat.CatStorageRepository
fakeBlockNumber = 123
fakeBlockHash = "expected_block_hash"
fakeAddress = "0x12345"
fakeIlk = "fake_ilk"
fakeUint256 = "12345"
fakeBytes32 = "fake_bytes32"
)
BeforeEach(func() {
db = test_config.NewTestDB(test_config.NewTestNode())
test_config.CleanTestDB(db)
repo = cat.CatStorageRepository{}
repo.SetDB(db)
})
Describe("Variable", func() {
var result VariableRes
Describe("NFlip", func() {
It("writes a row", func() {
nFlipMetadata := shared.GetStorageValueMetadata(cat.NFlip, nil, shared.Uint256)
err := repo.Create(fakeBlockNumber, fakeBlockHash, nFlipMetadata, fakeUint256)
Expect(err).NotTo(HaveOccurred())
err = db.Get(&result, `SELECT block_number, block_hash, nflip AS value FROM maker.cat_nflip`)
Expect(err).NotTo(HaveOccurred())
Expect(result.BlockNumber).To(Equal(fakeBlockNumber))
Expect(result.BlockHash).To(Equal(fakeBlockHash))
Expect(result.Value).To(Equal(fakeUint256))
})
})
Describe("Live", func() {
It("writes a row", func() {
liveMetadata := shared.GetStorageValueMetadata(cat.Live, nil, shared.Uint256)
err := repo.Create(fakeBlockNumber, fakeBlockHash, liveMetadata, fakeUint256)
Expect(err).NotTo(HaveOccurred())
err = db.Get(&result, `SELECT block_number, block_hash, live AS value FROM maker.cat_live`)
Expect(err).NotTo(HaveOccurred())
Expect(result.BlockNumber).To(Equal(fakeBlockNumber))
Expect(result.BlockHash).To(Equal(fakeBlockHash))
Expect(result.Value).To(Equal(fakeUint256))
})
})
Describe("Vat", func() {
It("writes a row", func() {
vatMetadata := shared.GetStorageValueMetadata(cat.Vat, nil, shared.Address)
err := repo.Create(fakeBlockNumber, fakeBlockHash, vatMetadata, fakeAddress)
Expect(err).NotTo(HaveOccurred())
err = db.Get(&result, `SELECT block_number, block_hash, vat AS value FROM maker.cat_vat`)
Expect(err).NotTo(HaveOccurred())
Expect(result.BlockNumber).To(Equal(fakeBlockNumber))
Expect(result.BlockHash).To(Equal(fakeBlockHash))
Expect(result.Value).To(Equal(fakeAddress))
})
})
Describe("Pit", func() {
It("writes a row", func() {
pitMetadata := shared.GetStorageValueMetadata(cat.Pit, nil, shared.Address)
err := repo.Create(fakeBlockNumber, fakeBlockHash, pitMetadata, fakeAddress)
Expect(err).NotTo(HaveOccurred())
err = db.Get(&result, `SELECT block_number, block_hash, pit AS value FROM maker.cat_pit`)
Expect(err).NotTo(HaveOccurred())
Expect(result.BlockNumber).To(Equal(fakeBlockNumber))
Expect(result.BlockHash).To(Equal(fakeBlockHash))
Expect(result.Value).To(Equal(fakeAddress))
})
})
Describe("Vow", func() {
It("writes a row", func() {
vowMetadata := shared.GetStorageValueMetadata(cat.Vow, nil, shared.Address)
err := repo.Create(fakeBlockNumber, fakeBlockHash, vowMetadata, fakeAddress)
Expect(err).NotTo(HaveOccurred())
err = db.Get(&result, `SELECT block_number, block_hash, vow AS value FROM maker.cat_vow`)
Expect(err).NotTo(HaveOccurred())
Expect(result.BlockNumber).To(Equal(fakeBlockNumber))
Expect(result.BlockHash).To(Equal(fakeBlockHash))
Expect(result.Value).To(Equal(fakeAddress))
})
})
})
Describe("Ilk", func() {
var result MappingRes
Describe("Flip", func() {
It("writes a row", func() {
ilkFlipMetadata := shared.GetStorageValueMetadata(cat.IlkFlip, map[shared.Key]string{shared.Ilk: fakeIlk}, shared.Address)
err := repo.Create(fakeBlockNumber, fakeBlockHash, ilkFlipMetadata, fakeAddress)
Expect(err).NotTo(HaveOccurred())
err = db.Get(&result, `SELECT block_number, block_hash, ilk AS key, flip AS value FROM maker.cat_ilk_flip`)
Expect(err).NotTo(HaveOccurred())
Expect(result.BlockNumber).To(Equal(fakeBlockNumber))
Expect(result.BlockHash).To(Equal(fakeBlockHash))
Expect(result.Key).To(Equal(fakeIlk))
Expect(result.Value).To(Equal(fakeAddress))
})
It("returns an error if metadata missing ilk", func() {
malformedIlkFlipMetadata := shared.GetStorageValueMetadata(cat.IlkFlip, map[shared.Key]string{}, shared.Address)
err := repo.Create(fakeBlockNumber, fakeBlockHash, malformedIlkFlipMetadata, fakeAddress)
Expect(err).To(MatchError(shared.ErrMetadataMalformed{MissingData: shared.Ilk}))
})
})
Describe("Chop", func() {
It("writes a row", func() {
ilkChopMetadata := shared.GetStorageValueMetadata(cat.IlkChop, map[shared.Key]string{shared.Ilk: fakeIlk}, shared.Uint256)
err := repo.Create(fakeBlockNumber, fakeBlockHash, ilkChopMetadata, fakeUint256)
Expect(err).NotTo(HaveOccurred())
err = db.Get(&result, `SELECT block_number, block_hash, ilk AS key, chop AS value FROM maker.cat_ilk_chop`)
Expect(err).NotTo(HaveOccurred())
Expect(result.BlockNumber).To(Equal(fakeBlockNumber))
Expect(result.BlockHash).To(Equal(fakeBlockHash))
Expect(result.Key).To(Equal(fakeIlk))
Expect(result.Value).To(Equal(fakeUint256))
})
It("returns an error if metadata missing ilk", func() {
malformedIlkChopMetadata := shared.GetStorageValueMetadata(cat.IlkChop, map[shared.Key]string{}, shared.Uint256)
err := repo.Create(fakeBlockNumber, fakeBlockHash, malformedIlkChopMetadata, fakeAddress)
Expect(err).To(MatchError(shared.ErrMetadataMalformed{MissingData: shared.Ilk}))
})
})
Describe("Lump", func() {
It("writes a row", func() {
ilkLumpMetadata := shared.GetStorageValueMetadata(cat.IlkLump, map[shared.Key]string{shared.Ilk: fakeIlk}, shared.Uint256)
err := repo.Create(fakeBlockNumber, fakeBlockHash, ilkLumpMetadata, fakeUint256)
Expect(err).NotTo(HaveOccurred())
err = db.Get(&result, `SELECT block_number, block_hash, ilk AS key, lump AS value FROM maker.cat_ilk_lump`)
Expect(err).NotTo(HaveOccurred())
Expect(result.BlockNumber).To(Equal(fakeBlockNumber))
Expect(result.BlockHash).To(Equal(fakeBlockHash))
Expect(result.Key).To(Equal(fakeIlk))
Expect(result.Value).To(Equal(fakeUint256))
})
It("returns an error if metadata missing ilk", func() {
malformedIlkLumpMetadata := shared.GetStorageValueMetadata(cat.IlkLump, map[shared.Key]string{}, shared.Uint256)
err := repo.Create(fakeBlockNumber, fakeBlockHash, malformedIlkLumpMetadata, fakeAddress)
Expect(err).To(MatchError(shared.ErrMetadataMalformed{MissingData: shared.Ilk}))
})
})
})
Describe("Flip", func() {
var result MappingRes
Describe("FlipIlk", func() {
It("writes a row", func() {
flipIlkMetadata := shared.GetStorageValueMetadata(cat.FlipIlk, map[shared.Key]string{shared.Flip: fakeUint256}, shared.Bytes32)
err := repo.Create(fakeBlockNumber, fakeBlockHash, flipIlkMetadata, fakeBytes32)
Expect(err).NotTo(HaveOccurred())
err = db.Get(&result, `SELECT block_number, block_hash, nflip AS key, ilk AS value FROM maker.cat_flip_ilk`)
Expect(err).NotTo(HaveOccurred())
Expect(result.BlockNumber).To(Equal(fakeBlockNumber))
Expect(result.BlockHash).To(Equal(fakeBlockHash))
Expect(result.Key).To(Equal(fakeUint256))
Expect(result.Value).To(Equal(fakeBytes32))
})
It("returns an error if metadata missing flip", func() {
malformedFlipIlkMetadata := shared.GetStorageValueMetadata(cat.FlipIlk, map[shared.Key]string{}, shared.Bytes32)
err := repo.Create(fakeBlockNumber, fakeBlockHash, malformedFlipIlkMetadata, fakeBytes32)
Expect(err).To(MatchError(shared.ErrMetadataMalformed{MissingData: shared.Flip}))
})
})
Describe("FlipUrn", func() {
It("writes a row", func() {
flipUrnMetadata := shared.GetStorageValueMetadata(cat.FlipUrn, map[shared.Key]string{shared.Flip: fakeUint256}, shared.Bytes32)
err := repo.Create(fakeBlockNumber, fakeBlockHash, flipUrnMetadata, fakeBytes32)
Expect(err).NotTo(HaveOccurred())
err = db.Get(&result, `SELECT block_number, block_hash, nflip AS key, urn AS value FROM maker.cat_flip_urn`)
Expect(err).NotTo(HaveOccurred())
Expect(result.BlockNumber).To(Equal(fakeBlockNumber))
Expect(result.BlockHash).To(Equal(fakeBlockHash))
Expect(result.Key).To(Equal(fakeUint256))
Expect(result.Value).To(Equal(fakeBytes32))
})
It("returns an error if metadata missing flip", func() {
malformedFlipUrnMetadata := shared.GetStorageValueMetadata(cat.FlipUrn, map[shared.Key]string{}, shared.Bytes32)
err := repo.Create(fakeBlockNumber, fakeBlockHash, malformedFlipUrnMetadata, fakeBytes32)
Expect(err).To(MatchError(shared.ErrMetadataMalformed{MissingData: shared.Flip}))
})
})
Describe("FlipInk", func() {
It("writes a row", func() {
flipInkMetadata := shared.GetStorageValueMetadata(cat.FlipInk, map[shared.Key]string{shared.Flip: fakeUint256}, shared.Uint256)
err := repo.Create(fakeBlockNumber, fakeBlockHash, flipInkMetadata, fakeUint256)
Expect(err).NotTo(HaveOccurred())
err = db.Get(&result, `SELECT block_number, block_hash, nflip AS key, ink AS value FROM maker.cat_flip_ink`)
Expect(err).NotTo(HaveOccurred())
Expect(result.BlockNumber).To(Equal(fakeBlockNumber))
Expect(result.BlockHash).To(Equal(fakeBlockHash))
Expect(result.Key).To(Equal(fakeUint256))
Expect(result.Value).To(Equal(fakeUint256))
})
It("returns an error if metadata missing flip", func() {
malformedFlipInkMetadata := shared.GetStorageValueMetadata(cat.FlipInk, map[shared.Key]string{}, shared.Uint256)
err := repo.Create(fakeBlockNumber, fakeBlockHash, malformedFlipInkMetadata, fakeUint256)
Expect(err).To(MatchError(shared.ErrMetadataMalformed{MissingData: shared.Flip}))
})
})
Describe("FlipTab", func() {
It("writes a row", func() {
flipTabMetadata := shared.GetStorageValueMetadata(cat.FlipTab, map[shared.Key]string{shared.Flip: fakeUint256}, shared.Uint256)
err := repo.Create(fakeBlockNumber, fakeBlockHash, flipTabMetadata, fakeUint256)
Expect(err).NotTo(HaveOccurred())
err = db.Get(&result, `SELECT block_number, block_hash, nflip AS key, tab AS value FROM maker.cat_flip_tab`)
Expect(err).NotTo(HaveOccurred())
Expect(result.BlockNumber).To(Equal(fakeBlockNumber))
Expect(result.BlockHash).To(Equal(fakeBlockHash))
Expect(result.Key).To(Equal(fakeUint256))
Expect(result.Value).To(Equal(fakeUint256))
})
It("returns an error if metadata missing flip", func() {
malformedFlipTabMetadata := shared.GetStorageValueMetadata(cat.FlipTab, map[shared.Key]string{}, shared.Uint256)
err := repo.Create(fakeBlockNumber, fakeBlockHash, malformedFlipTabMetadata, fakeUint256)
Expect(err).To(MatchError(shared.ErrMetadataMalformed{MissingData: shared.Flip}))
})
})
})
})
type BlockMetadata struct {
BlockNumber int `db:"block_number"`
BlockHash string `db:"block_hash"`
}
type MappingRes struct {
BlockMetadata
Key string
Value string
}
type VariableRes struct {
BlockMetadata
Value string
}

View File

@ -130,6 +130,17 @@ func CleanTestDB(db *postgres.DB) {
db.MustExec("DELETE FROM receipts") db.MustExec("DELETE FROM receipts")
db.MustExec("DELETE FROM transactions") db.MustExec("DELETE FROM transactions")
db.MustExec("DELETE FROM watched_contracts") db.MustExec("DELETE FROM watched_contracts")
db.MustExec("DELETE FROM maker.cat_nflip")
db.MustExec("DELETE FROM maker.cat_live")
db.MustExec("DELETE FROM maker.cat_vat")
db.MustExec("DELETE FROM maker.cat_pit")
db.MustExec("DELETE FROM maker.cat_vow")
db.MustExec("DELETE FROM maker.cat_ilk_flip")
db.MustExec("DELETE FROM maker.cat_ilk_chop")
db.MustExec("DELETE FROM maker.cat_ilk_lump")
db.MustExec("DELETE FROM maker.cat_flip_ilk")
db.MustExec("DELETE FROM maker.cat_flip_ink")
db.MustExec("DELETE FROM maker.cat_flip_tab")
} }
// Returns a new test node, with the same ID // Returns a new test node, with the same ID