Merge pull request #18 from vulcanize/vdb-380-continued
Vdb 380 continued
This commit is contained in:
commit
dc6a4a707e
@ -38,7 +38,7 @@ CREATE TABLE maker.cat_ilk_flip (
|
||||
id SERIAL PRIMARY KEY,
|
||||
block_number BIGINT,
|
||||
block_hash TEXT,
|
||||
ilk TEXT,
|
||||
ilk INTEGER NOT NULL REFERENCES maker.ilks (id),
|
||||
flip TEXT
|
||||
);
|
||||
|
||||
@ -46,7 +46,7 @@ CREATE TABLE maker.cat_ilk_chop (
|
||||
id SERIAL PRIMARY KEY,
|
||||
block_number BIGINT,
|
||||
block_hash TEXT,
|
||||
ilk TEXT,
|
||||
ilk INTEGER NOT NULL REFERENCES maker.ilks (id),
|
||||
chop NUMERIC NOT NULL
|
||||
);
|
||||
|
||||
@ -54,7 +54,7 @@ CREATE TABLE maker.cat_ilk_lump (
|
||||
id SERIAL PRIMARY KEY,
|
||||
block_number BIGINT,
|
||||
block_hash TEXT,
|
||||
ilk TEXT,
|
||||
ilk INTEGER NOT NULL REFERENCES maker.ilks (id),
|
||||
lump NUMERIC NOT NULL
|
||||
);
|
||||
|
||||
@ -63,7 +63,7 @@ CREATE TABLE maker.cat_flip_ilk (
|
||||
block_number BIGINT,
|
||||
block_hash TEXT,
|
||||
flip NUMERIC NOT NULL,
|
||||
ilk TEXT
|
||||
ilk INTEGER NOT NULL REFERENCES maker.ilks (id)
|
||||
);
|
||||
|
||||
CREATE TABLE maker.cat_flip_urn (
|
||||
|
@ -213,7 +213,7 @@ CREATE TABLE maker.cat_flip_ilk (
|
||||
block_number bigint,
|
||||
block_hash text,
|
||||
flip numeric NOT NULL,
|
||||
ilk text
|
||||
ilk integer NOT NULL
|
||||
);
|
||||
|
||||
|
||||
@ -344,7 +344,7 @@ CREATE TABLE maker.cat_ilk_chop (
|
||||
id integer NOT NULL,
|
||||
block_number bigint,
|
||||
block_hash text,
|
||||
ilk text,
|
||||
ilk integer NOT NULL,
|
||||
chop numeric NOT NULL
|
||||
);
|
||||
|
||||
@ -377,7 +377,7 @@ CREATE TABLE maker.cat_ilk_flip (
|
||||
id integer NOT NULL,
|
||||
block_number bigint,
|
||||
block_hash text,
|
||||
ilk text,
|
||||
ilk integer NOT NULL,
|
||||
flip text
|
||||
);
|
||||
|
||||
@ -410,7 +410,7 @@ CREATE TABLE maker.cat_ilk_lump (
|
||||
id integer NOT NULL,
|
||||
block_number bigint,
|
||||
block_hash text,
|
||||
ilk text,
|
||||
ilk integer NOT NULL,
|
||||
lump numeric NOT NULL
|
||||
);
|
||||
|
||||
@ -4413,6 +4413,38 @@ ALTER TABLE ONLY maker.cat_file_pit_vow
|
||||
ADD CONSTRAINT cat_file_pit_vow_header_id_fkey FOREIGN KEY (header_id) REFERENCES public.headers(id) ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- Name: cat_flip_ilk cat_flip_ilk_ilk_fkey; Type: FK CONSTRAINT; Schema: maker; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY maker.cat_flip_ilk
|
||||
ADD CONSTRAINT cat_flip_ilk_ilk_fkey FOREIGN KEY (ilk) REFERENCES maker.ilks(id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: cat_ilk_chop cat_ilk_chop_ilk_fkey; Type: FK CONSTRAINT; Schema: maker; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY maker.cat_ilk_chop
|
||||
ADD CONSTRAINT cat_ilk_chop_ilk_fkey FOREIGN KEY (ilk) REFERENCES maker.ilks(id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: cat_ilk_flip cat_ilk_flip_ilk_fkey; Type: FK CONSTRAINT; Schema: maker; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY maker.cat_ilk_flip
|
||||
ADD CONSTRAINT cat_ilk_flip_ilk_fkey FOREIGN KEY (ilk) REFERENCES maker.ilks(id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: cat_ilk_lump cat_ilk_lump_ilk_fkey; Type: FK CONSTRAINT; Schema: maker; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY maker.cat_ilk_lump
|
||||
ADD CONSTRAINT cat_ilk_lump_ilk_fkey FOREIGN KEY (ilk) REFERENCES maker.ilks(id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: deal deal_header_id_fkey; Type: FK CONSTRAINT; Schema: maker; Owner: -
|
||||
--
|
||||
|
@ -3,6 +3,7 @@ package cat
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
||||
shared2 "github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/storage_diffs/shared"
|
||||
)
|
||||
|
||||
@ -86,10 +87,29 @@ func (repository *CatStorageRepository) insertIlkFlip(blockNumber int, blockHash
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, writeErr := repository.db.Exec(
|
||||
tx, txErr := repository.db.Begin()
|
||||
if txErr != nil {
|
||||
return txErr
|
||||
}
|
||||
ilkID, ilkErr := shared2.GetOrCreateIlkInTransaction(ilk, tx)
|
||||
if ilkErr != nil {
|
||||
rollbackErr := tx.Rollback()
|
||||
if rollbackErr != nil {
|
||||
return fmt.Errorf("failed to rollback transaction after failing to insert ilk: %s", ilkErr.Error())
|
||||
}
|
||||
return ilkErr
|
||||
}
|
||||
_, writeErr := tx.Exec(
|
||||
`INSERT INTO maker.cat_ilk_flip (block_number, block_hash, ilk, flip) VALUES ($1, $2, $3, $4)`,
|
||||
blockNumber, blockHash, ilk, flip)
|
||||
blockNumber, blockHash, ilkID, flip)
|
||||
if writeErr != nil {
|
||||
rollbackErr := tx.Rollback()
|
||||
if rollbackErr != nil {
|
||||
return fmt.Errorf("failed to rollback transaction after failing to insert ilk flip: %s", writeErr.Error())
|
||||
}
|
||||
return writeErr
|
||||
}
|
||||
return tx.Commit()
|
||||
}
|
||||
|
||||
func (repository *CatStorageRepository) insertIlkChop(blockNumber int, blockHash string, metadata shared.StorageValueMetadata, chop string) error {
|
||||
@ -97,10 +117,29 @@ func (repository *CatStorageRepository) insertIlkChop(blockNumber int, blockHash
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, writeErr := repository.db.Exec(
|
||||
tx, txErr := repository.db.Begin()
|
||||
if txErr != nil {
|
||||
return txErr
|
||||
}
|
||||
ilkID, ilkErr := shared2.GetOrCreateIlkInTransaction(ilk, tx)
|
||||
if ilkErr != nil {
|
||||
rollbackErr := tx.Rollback()
|
||||
if rollbackErr != nil {
|
||||
return fmt.Errorf("failed to rollback transaction after failing to insert ilk: %s", ilkErr.Error())
|
||||
}
|
||||
return ilkErr
|
||||
}
|
||||
_, writeErr := tx.Exec(
|
||||
`INSERT INTO maker.cat_ilk_chop (block_number, block_hash, ilk, chop) VALUES ($1, $2, $3, $4)`,
|
||||
blockNumber, blockHash, ilk, chop)
|
||||
blockNumber, blockHash, ilkID, chop)
|
||||
if writeErr != nil {
|
||||
rollbackErr := tx.Rollback()
|
||||
if rollbackErr != nil {
|
||||
return fmt.Errorf("failed to rollback transaction after failing to insert ilk chop: %s", writeErr.Error())
|
||||
}
|
||||
return writeErr
|
||||
}
|
||||
return tx.Commit()
|
||||
}
|
||||
|
||||
func (repository *CatStorageRepository) insertIlkLump(blockNumber int, blockHash string, metadata shared.StorageValueMetadata, lump string) error {
|
||||
@ -108,10 +147,29 @@ func (repository *CatStorageRepository) insertIlkLump(blockNumber int, blockHash
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, writeErr := repository.db.Exec(
|
||||
tx, txErr := repository.db.Begin()
|
||||
if txErr != nil {
|
||||
return txErr
|
||||
}
|
||||
ilkID, ilkErr := shared2.GetOrCreateIlkInTransaction(ilk, tx)
|
||||
if ilkErr != nil {
|
||||
rollbackErr := tx.Rollback()
|
||||
if rollbackErr != nil {
|
||||
return fmt.Errorf("failed to rollback transaction after failing to insert ilk: %s", ilkErr.Error())
|
||||
}
|
||||
return ilkErr
|
||||
}
|
||||
_, writeErr := tx.Exec(
|
||||
`INSERT INTO maker.cat_ilk_lump (block_number, block_hash, ilk, lump) VALUES ($1, $2, $3, $4)`,
|
||||
blockNumber, blockHash, ilk, lump)
|
||||
blockNumber, blockHash, ilkID, lump)
|
||||
if writeErr != nil {
|
||||
rollbackErr := tx.Rollback()
|
||||
if rollbackErr != nil {
|
||||
return fmt.Errorf("failed to rollback transaction after failing to insert ilk lump: %s", writeErr.Error())
|
||||
}
|
||||
return writeErr
|
||||
}
|
||||
return tx.Commit()
|
||||
}
|
||||
|
||||
// Flips mapping: uint256 => ilk, urn bytes32; ink, tab uint256 (both wad)
|
||||
@ -120,10 +178,29 @@ func (repository *CatStorageRepository) insertFlipIlk(blockNumber int, blockHash
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, writeErr := repository.db.Exec(
|
||||
tx, txErr := repository.db.Begin()
|
||||
if txErr != nil {
|
||||
return txErr
|
||||
}
|
||||
ilkID, ilkErr := shared2.GetOrCreateIlkInTransaction(ilk, tx)
|
||||
if ilkErr != nil {
|
||||
rollbackErr := tx.Rollback()
|
||||
if rollbackErr != nil {
|
||||
return fmt.Errorf("failed to rollback transaction after failing to insert ilk: %s", ilkErr.Error())
|
||||
}
|
||||
return ilkErr
|
||||
}
|
||||
_, writeErr := tx.Exec(
|
||||
`INSERT INTO maker.cat_flip_ilk (block_number, block_hash, flip, ilk) VALUES ($1, $2, $3, $4)`,
|
||||
blockNumber, blockHash, flip, ilk)
|
||||
blockNumber, blockHash, flip, ilkID)
|
||||
if writeErr != nil {
|
||||
rollbackErr := tx.Rollback()
|
||||
if rollbackErr != nil {
|
||||
return fmt.Errorf("failed to rollback transaction after failing to insert flip ilk: %s", writeErr.Error())
|
||||
}
|
||||
return writeErr
|
||||
}
|
||||
return tx.Commit()
|
||||
}
|
||||
|
||||
func (repository *CatStorageRepository) insertFlipUrn(blockNumber int, blockHash string, metadata shared.StorageValueMetadata, urn string) error {
|
||||
|
@ -4,10 +4,12 @@ import (
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
||||
shared2 "github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
||||
"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"
|
||||
"github.com/vulcanize/vulcanizedb/test_config"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
var _ = Describe("Cat storage repository", func() {
|
||||
@ -110,7 +112,9 @@ var _ = Describe("Cat storage repository", func() {
|
||||
|
||||
err = db.Get(&result, `SELECT block_number, block_hash, ilk AS key, flip AS value FROM maker.cat_ilk_flip`)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
AssertMapping(result, fakeBlockNumber, fakeBlockHash, fakeIlk, fakeAddress)
|
||||
ilkID, err := shared2.GetOrCreateIlk(fakeIlk, db)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
AssertMapping(result, fakeBlockNumber, fakeBlockHash, strconv.Itoa(ilkID), fakeAddress)
|
||||
})
|
||||
|
||||
It("returns an error if metadata missing ilk", func() {
|
||||
@ -130,7 +134,9 @@ var _ = Describe("Cat storage repository", func() {
|
||||
|
||||
err = db.Get(&result, `SELECT block_number, block_hash, ilk AS key, chop AS value FROM maker.cat_ilk_chop`)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
AssertMapping(result, fakeBlockNumber, fakeBlockHash, fakeIlk, fakeUint256)
|
||||
ilkID, err := shared2.GetOrCreateIlk(fakeIlk, db)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
AssertMapping(result, fakeBlockNumber, fakeBlockHash, strconv.Itoa(ilkID), fakeUint256)
|
||||
})
|
||||
|
||||
It("returns an error if metadata missing ilk", func() {
|
||||
@ -150,7 +156,9 @@ var _ = Describe("Cat storage repository", func() {
|
||||
|
||||
err = db.Get(&result, `SELECT block_number, block_hash, ilk AS key, lump AS value FROM maker.cat_ilk_lump`)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
AssertMapping(result, fakeBlockNumber, fakeBlockHash, fakeIlk, fakeUint256)
|
||||
ilkID, err := shared2.GetOrCreateIlk(fakeIlk, db)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
AssertMapping(result, fakeBlockNumber, fakeBlockHash, strconv.Itoa(ilkID), fakeUint256)
|
||||
})
|
||||
|
||||
It("returns an error if metadata missing ilk", func() {
|
||||
@ -174,7 +182,9 @@ var _ = Describe("Cat storage repository", func() {
|
||||
|
||||
err = db.Get(&result, `SELECT block_number, block_hash, flip AS key, ilk AS value FROM maker.cat_flip_ilk`)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
AssertMapping(result, fakeBlockNumber, fakeBlockHash, fakeUint256, fakeBytes32)
|
||||
ilkID, err := shared2.GetOrCreateIlk(fakeBytes32, db)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
AssertMapping(result, fakeBlockNumber, fakeBlockHash, fakeUint256, strconv.Itoa(ilkID))
|
||||
})
|
||||
|
||||
It("returns an error if metadata missing flip", func() {
|
||||
|
@ -34,9 +34,9 @@ func (repository *PitStorageRepository) SetDB(db *postgres.DB) {
|
||||
func (repository PitStorageRepository) Create(blockNumber int, blockHash string, metadata shared.StorageValueMetadata, value interface{}) error {
|
||||
switch metadata.Name {
|
||||
case IlkLine:
|
||||
return repository.insertIlkLine(blockNumber, blockHash, metadata.Keys[shared.Ilk], value.(string))
|
||||
return repository.insertIlkLine(blockNumber, blockHash, metadata, value.(string))
|
||||
case IlkSpot:
|
||||
return repository.insertIlkSpot(blockNumber, blockHash, metadata.Keys[shared.Ilk], value.(string))
|
||||
return repository.insertIlkSpot(blockNumber, blockHash, metadata, value.(string))
|
||||
case PitDrip:
|
||||
return repository.insertPitDrip(blockNumber, blockHash, value.(string))
|
||||
case PitLine:
|
||||
@ -50,7 +50,11 @@ func (repository PitStorageRepository) Create(blockNumber int, blockHash string,
|
||||
}
|
||||
}
|
||||
|
||||
func (repository PitStorageRepository) insertIlkLine(blockNumber int, blockHash string, ilk string, line string) error {
|
||||
func (repository PitStorageRepository) insertIlkLine(blockNumber int, blockHash string, metadata shared.StorageValueMetadata, line string) error {
|
||||
ilk, err := getIlk(metadata.Keys)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tx, err := repository.db.Begin()
|
||||
if err != nil {
|
||||
return err
|
||||
@ -74,7 +78,11 @@ func (repository PitStorageRepository) insertIlkLine(blockNumber int, blockHash
|
||||
return tx.Commit()
|
||||
}
|
||||
|
||||
func (repository PitStorageRepository) insertIlkSpot(blockNumber int, blockHash string, ilk string, spot string) error {
|
||||
func (repository PitStorageRepository) insertIlkSpot(blockNumber int, blockHash string, metadata shared.StorageValueMetadata, spot string) error {
|
||||
ilk, err := getIlk(metadata.Keys)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tx, err := repository.db.Begin()
|
||||
if err != nil {
|
||||
return err
|
||||
@ -117,3 +125,11 @@ func (repository PitStorageRepository) insertPitVat(blockNumber int, blockHash s
|
||||
_, err := repository.db.Exec(`INSERT INTO maker.pit_vat (block_number, block_hash, vat) VALUES ($1, $2, $3)`, blockNumber, blockHash, vat)
|
||||
return err
|
||||
}
|
||||
|
||||
func getIlk(keys map[shared.Key]string) (string, error) {
|
||||
ilk, ok := keys[shared.Ilk]
|
||||
if !ok {
|
||||
return "", shared.ErrMetadataMalformed{MissingData: shared.Ilk}
|
||||
}
|
||||
return ilk, nil
|
||||
}
|
||||
|
@ -30,111 +30,108 @@ import (
|
||||
|
||||
var _ = Describe("Pit storage repository", func() {
|
||||
var (
|
||||
blockNumber int
|
||||
blockHash string
|
||||
db *postgres.DB
|
||||
err error
|
||||
repo pit.PitStorageRepository
|
||||
fakeAddress = "0x12345"
|
||||
fakeBlockHash = "expected_block_hash"
|
||||
fakeBlockNumber = 123
|
||||
fakeIlk = "fake_ilk"
|
||||
fakeUint256 = "12345"
|
||||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
blockNumber = 123
|
||||
blockHash = "expected_block_hash"
|
||||
db = test_config.NewTestDB(test_config.NewTestNode())
|
||||
test_config.CleanTestDB(db)
|
||||
repo = pit.PitStorageRepository{}
|
||||
repo.SetDB(db)
|
||||
})
|
||||
|
||||
It("persists an ilk line", func() {
|
||||
expectedIlk := "fake_ilk"
|
||||
expectedLine := "12345"
|
||||
ilkLineMetadata := shared.StorageValueMetadata{
|
||||
Name: pit.IlkLine,
|
||||
Keys: map[shared.Key]string{shared.Ilk: expectedIlk},
|
||||
Type: shared.Uint256,
|
||||
}
|
||||
err = repo.Create(blockNumber, blockHash, ilkLineMetadata, expectedLine)
|
||||
Describe("Ilk", func() {
|
||||
Describe("Line", func() {
|
||||
It("writes a row", func() {
|
||||
ilkLineMetadata := shared.GetStorageValueMetadata(pit.IlkLine, map[shared.Key]string{shared.Ilk: fakeIlk}, shared.Uint256)
|
||||
|
||||
err = repo.Create(fakeBlockNumber, fakeBlockHash, ilkLineMetadata, fakeUint256)
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
var result MappingRes
|
||||
err = db.Get(&result, `SELECT block_number, block_hash, ilk AS key, line AS value FROM maker.pit_ilk_line`)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
ilkID, err := shared2.GetOrCreateIlk(expectedIlk, db)
|
||||
ilkID, err := shared2.GetOrCreateIlk(fakeIlk, db)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
AssertMapping(result, blockNumber, blockHash, strconv.Itoa(ilkID), expectedLine)
|
||||
AssertMapping(result, fakeBlockNumber, fakeBlockHash, strconv.Itoa(ilkID), fakeUint256)
|
||||
})
|
||||
|
||||
It("persists an ilk spot", func() {
|
||||
expectedIlk := "fake_ilk"
|
||||
expectedSpot := "12345"
|
||||
ilkSpotMetadata := shared.StorageValueMetadata{
|
||||
Name: pit.IlkSpot,
|
||||
Keys: map[shared.Key]string{shared.Ilk: expectedIlk},
|
||||
Type: shared.Uint256,
|
||||
}
|
||||
err = repo.Create(blockNumber, blockHash, ilkSpotMetadata, expectedSpot)
|
||||
It("returns an error if metadata missing ilk", func() {
|
||||
malformedIlkLineMetadata := shared.GetStorageValueMetadata(pit.IlkLine, nil, shared.Uint256)
|
||||
|
||||
err := repo.Create(fakeBlockNumber, fakeBlockHash, malformedIlkLineMetadata, fakeUint256)
|
||||
Expect(err).To(MatchError(shared.ErrMetadataMalformed{MissingData: shared.Ilk}))
|
||||
})
|
||||
})
|
||||
|
||||
Describe("Spot", func() {
|
||||
It("writes a row", func() {
|
||||
ilkSpotMetadata := shared.GetStorageValueMetadata(pit.IlkSpot, map[shared.Key]string{shared.Ilk: fakeIlk}, shared.Uint256)
|
||||
|
||||
err = repo.Create(fakeBlockNumber, fakeBlockHash, ilkSpotMetadata, fakeUint256)
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
var result MappingRes
|
||||
err = db.Get(&result, `SELECT block_number, block_hash, ilk AS key, spot AS value FROM maker.pit_ilk_spot`)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
ilkID, err := shared2.GetOrCreateIlk(expectedIlk, db)
|
||||
ilkID, err := shared2.GetOrCreateIlk(fakeIlk, db)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
AssertMapping(result, blockNumber, blockHash, strconv.Itoa(ilkID), expectedSpot)
|
||||
AssertMapping(result, fakeBlockNumber, fakeBlockHash, strconv.Itoa(ilkID), fakeUint256)
|
||||
})
|
||||
|
||||
It("returns an error if metadata missing ilk", func() {
|
||||
malformedIlkSpotMetadata := shared.GetStorageValueMetadata(pit.IlkSpot, nil, shared.Uint256)
|
||||
|
||||
err := repo.Create(fakeBlockNumber, fakeBlockHash, malformedIlkSpotMetadata, fakeUint256)
|
||||
Expect(err).To(MatchError(shared.ErrMetadataMalformed{MissingData: shared.Ilk}))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
It("persists a pit drip", func() {
|
||||
expectedDrip := "0x0123456789abcdef0123"
|
||||
|
||||
err = repo.Create(blockNumber, blockHash, pit.DripMetadata, expectedDrip)
|
||||
err = repo.Create(fakeBlockNumber, fakeBlockHash, pit.DripMetadata, fakeAddress)
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
var result VariableRes
|
||||
err = db.Get(&result, `SELECT block_number, block_hash, drip AS value FROM maker.pit_drip`)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
AssertVariable(result, blockNumber, blockHash, expectedDrip)
|
||||
AssertVariable(result, fakeBlockNumber, fakeBlockHash, fakeAddress)
|
||||
})
|
||||
|
||||
It("persists a pit line", func() {
|
||||
expectedLine := "12345"
|
||||
|
||||
err = repo.Create(blockNumber, blockHash, pit.LineMetadata, expectedLine)
|
||||
err = repo.Create(fakeBlockNumber, fakeBlockHash, pit.LineMetadata, fakeUint256)
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
var result VariableRes
|
||||
err = db.Get(&result, `SELECT block_number, block_hash, line AS value FROM maker.pit_line`)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
AssertVariable(result, blockNumber, blockHash, expectedLine)
|
||||
AssertVariable(result, fakeBlockNumber, fakeBlockHash, fakeUint256)
|
||||
})
|
||||
|
||||
It("persists a pit live", func() {
|
||||
expectedLive := "12345"
|
||||
|
||||
err = repo.Create(blockNumber, blockHash, pit.LiveMetadata, expectedLive)
|
||||
err = repo.Create(fakeBlockNumber, fakeBlockHash, pit.LiveMetadata, fakeUint256)
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
var result VariableRes
|
||||
err = db.Get(&result, `SELECT block_number, block_hash, live AS value FROM maker.pit_live`)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
AssertVariable(result, blockNumber, blockHash, expectedLive)
|
||||
AssertVariable(result, fakeBlockNumber, fakeBlockHash, fakeUint256)
|
||||
})
|
||||
|
||||
It("persists a pit vat", func() {
|
||||
expectedVat := "0x0123456789abcdef0123"
|
||||
|
||||
err = repo.Create(blockNumber, blockHash, pit.VatMetadata, expectedVat)
|
||||
err = repo.Create(fakeBlockNumber, fakeBlockHash, pit.VatMetadata, fakeAddress)
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
var result VariableRes
|
||||
err = db.Get(&result, `SELECT block_number, block_hash, vat AS value FROM maker.pit_vat`)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
AssertVariable(result, blockNumber, blockHash, expectedVat)
|
||||
AssertVariable(result, fakeBlockNumber, fakeBlockHash, fakeAddress)
|
||||
})
|
||||
})
|
||||
|
@ -32,11 +32,7 @@ var _ = Describe("Vat storage repository", func() {
|
||||
|
||||
Describe("dai", func() {
|
||||
It("writes a row", func() {
|
||||
daiMetadata := shared.StorageValueMetadata{
|
||||
Name: vat.Dai,
|
||||
Keys: map[shared.Key]string{shared.Guy: fakeGuy},
|
||||
Type: shared.Uint256,
|
||||
}
|
||||
daiMetadata := shared.GetStorageValueMetadata(vat.Dai, map[shared.Key]string{shared.Guy: fakeGuy}, shared.Uint256)
|
||||
|
||||
err := repo.Create(fakeBlockNumber, fakeBlockHash, daiMetadata, fakeUint256)
|
||||
|
||||
@ -49,11 +45,7 @@ var _ = Describe("Vat storage repository", func() {
|
||||
})
|
||||
|
||||
It("returns error if metadata missing guy", func() {
|
||||
malformedDaiMetadata := shared.StorageValueMetadata{
|
||||
Name: vat.Dai,
|
||||
Keys: nil,
|
||||
Type: shared.Uint256,
|
||||
}
|
||||
malformedDaiMetadata := shared.GetStorageValueMetadata(vat.Dai, nil, shared.Uint256)
|
||||
|
||||
err := repo.Create(fakeBlockNumber, fakeBlockHash, malformedDaiMetadata, fakeUint256)
|
||||
|
||||
@ -64,11 +56,7 @@ var _ = Describe("Vat storage repository", func() {
|
||||
|
||||
Describe("gem", func() {
|
||||
It("writes row", func() {
|
||||
gemMetadata := shared.StorageValueMetadata{
|
||||
Name: vat.Gem,
|
||||
Keys: map[shared.Key]string{shared.Ilk: fakeIlk, shared.Guy: fakeGuy},
|
||||
Type: shared.Uint256,
|
||||
}
|
||||
gemMetadata := shared.GetStorageValueMetadata(vat.Gem, map[shared.Key]string{shared.Ilk: fakeIlk, shared.Guy: fakeGuy}, shared.Uint256)
|
||||
|
||||
err := repo.Create(fakeBlockNumber, fakeBlockHash, gemMetadata, fakeUint256)
|
||||
|
||||
@ -83,11 +71,7 @@ var _ = Describe("Vat storage repository", func() {
|
||||
})
|
||||
|
||||
It("returns error if metadata missing ilk", func() {
|
||||
malformedGemMetadata := shared.StorageValueMetadata{
|
||||
Name: vat.Gem,
|
||||
Keys: map[shared.Key]string{shared.Guy: fakeGuy},
|
||||
Type: shared.Uint256,
|
||||
}
|
||||
malformedGemMetadata := shared.GetStorageValueMetadata(vat.Gem, map[shared.Key]string{shared.Guy: fakeGuy}, shared.Uint256)
|
||||
|
||||
err := repo.Create(fakeBlockNumber, fakeBlockHash, malformedGemMetadata, fakeUint256)
|
||||
|
||||
@ -96,11 +80,7 @@ var _ = Describe("Vat storage repository", func() {
|
||||
})
|
||||
|
||||
It("returns error if metadata missing guy", func() {
|
||||
malformedGemMetadata := shared.StorageValueMetadata{
|
||||
Name: vat.Gem,
|
||||
Keys: map[shared.Key]string{shared.Ilk: fakeIlk},
|
||||
Type: shared.Uint256,
|
||||
}
|
||||
malformedGemMetadata := shared.GetStorageValueMetadata(vat.Gem, map[shared.Key]string{shared.Ilk: fakeIlk}, shared.Uint256)
|
||||
|
||||
err := repo.Create(fakeBlockNumber, fakeBlockHash, malformedGemMetadata, fakeUint256)
|
||||
|
||||
@ -111,11 +91,7 @@ var _ = Describe("Vat storage repository", func() {
|
||||
|
||||
Describe("ilk Art", func() {
|
||||
It("writes row", func() {
|
||||
ilkArtMetadata := shared.StorageValueMetadata{
|
||||
Name: vat.IlkArt,
|
||||
Keys: map[shared.Key]string{shared.Ilk: fakeIlk},
|
||||
Type: shared.Uint256,
|
||||
}
|
||||
ilkArtMetadata := shared.GetStorageValueMetadata(vat.IlkArt, map[shared.Key]string{shared.Ilk: fakeIlk}, shared.Uint256)
|
||||
|
||||
err := repo.Create(fakeBlockNumber, fakeBlockHash, ilkArtMetadata, fakeUint256)
|
||||
|
||||
@ -130,11 +106,7 @@ var _ = Describe("Vat storage repository", func() {
|
||||
})
|
||||
|
||||
It("returns error if metadata missing ilk", func() {
|
||||
malformedIlkArtMetadata := shared.StorageValueMetadata{
|
||||
Name: vat.IlkArt,
|
||||
Keys: nil,
|
||||
Type: shared.Uint256,
|
||||
}
|
||||
malformedIlkArtMetadata := shared.GetStorageValueMetadata(vat.IlkArt, nil, shared.Uint256)
|
||||
|
||||
err := repo.Create(fakeBlockNumber, fakeBlockHash, malformedIlkArtMetadata, fakeUint256)
|
||||
|
||||
@ -145,11 +117,7 @@ var _ = Describe("Vat storage repository", func() {
|
||||
|
||||
Describe("ilk Ink", func() {
|
||||
It("writes row", func() {
|
||||
ilkInkMetadata := shared.StorageValueMetadata{
|
||||
Name: vat.IlkInk,
|
||||
Keys: map[shared.Key]string{shared.Ilk: fakeIlk},
|
||||
Type: shared.Uint256,
|
||||
}
|
||||
ilkInkMetadata := shared.GetStorageValueMetadata(vat.IlkInk, map[shared.Key]string{shared.Ilk: fakeIlk}, shared.Uint256)
|
||||
|
||||
err := repo.Create(fakeBlockNumber, fakeBlockHash, ilkInkMetadata, fakeUint256)
|
||||
|
||||
@ -164,11 +132,7 @@ var _ = Describe("Vat storage repository", func() {
|
||||
})
|
||||
|
||||
It("returns error if metadata missing ilk", func() {
|
||||
malformedIlkInkMetadata := shared.StorageValueMetadata{
|
||||
Name: vat.IlkInk,
|
||||
Keys: nil,
|
||||
Type: shared.Uint256,
|
||||
}
|
||||
malformedIlkInkMetadata := shared.GetStorageValueMetadata(vat.IlkInk, nil, shared.Uint256)
|
||||
|
||||
err := repo.Create(fakeBlockNumber, fakeBlockHash, malformedIlkInkMetadata, fakeUint256)
|
||||
|
||||
@ -179,11 +143,7 @@ var _ = Describe("Vat storage repository", func() {
|
||||
|
||||
Describe("ilk rate", func() {
|
||||
It("writes row", func() {
|
||||
ilkRateMetadata := shared.StorageValueMetadata{
|
||||
Name: vat.IlkRate,
|
||||
Keys: map[shared.Key]string{shared.Ilk: fakeIlk},
|
||||
Type: shared.Uint256,
|
||||
}
|
||||
ilkRateMetadata := shared.GetStorageValueMetadata(vat.IlkRate, map[shared.Key]string{shared.Ilk: fakeIlk}, shared.Uint256)
|
||||
|
||||
err := repo.Create(fakeBlockNumber, fakeBlockHash, ilkRateMetadata, fakeUint256)
|
||||
|
||||
@ -198,11 +158,7 @@ var _ = Describe("Vat storage repository", func() {
|
||||
})
|
||||
|
||||
It("returns error if metadata missing ilk", func() {
|
||||
malformedIlkRateMetadata := shared.StorageValueMetadata{
|
||||
Name: vat.IlkRate,
|
||||
Keys: nil,
|
||||
Type: shared.Uint256,
|
||||
}
|
||||
malformedIlkRateMetadata := shared.GetStorageValueMetadata(vat.IlkRate, nil, shared.Uint256)
|
||||
|
||||
err := repo.Create(fakeBlockNumber, fakeBlockHash, malformedIlkRateMetadata, fakeUint256)
|
||||
|
||||
@ -213,11 +169,7 @@ var _ = Describe("Vat storage repository", func() {
|
||||
|
||||
Describe("ilk take", func() {
|
||||
It("writes row", func() {
|
||||
ilkTakeMetadata := shared.StorageValueMetadata{
|
||||
Name: vat.IlkTake,
|
||||
Keys: map[shared.Key]string{shared.Ilk: fakeIlk},
|
||||
Type: shared.Uint256,
|
||||
}
|
||||
ilkTakeMetadata := shared.GetStorageValueMetadata(vat.IlkTake, map[shared.Key]string{shared.Ilk: fakeIlk}, shared.Uint256)
|
||||
|
||||
err := repo.Create(fakeBlockNumber, fakeBlockHash, ilkTakeMetadata, fakeUint256)
|
||||
|
||||
@ -232,11 +184,7 @@ var _ = Describe("Vat storage repository", func() {
|
||||
})
|
||||
|
||||
It("returns error if metadata missing ilk", func() {
|
||||
malformedIlkTakeMetadata := shared.StorageValueMetadata{
|
||||
Name: vat.IlkTake,
|
||||
Keys: nil,
|
||||
Type: shared.Uint256,
|
||||
}
|
||||
malformedIlkTakeMetadata := shared.GetStorageValueMetadata(vat.IlkTake, nil, shared.Uint256)
|
||||
|
||||
err := repo.Create(fakeBlockNumber, fakeBlockHash, malformedIlkTakeMetadata, fakeUint256)
|
||||
|
||||
@ -247,11 +195,7 @@ var _ = Describe("Vat storage repository", func() {
|
||||
|
||||
Describe("sin", func() {
|
||||
It("writes a row", func() {
|
||||
sinMetadata := shared.StorageValueMetadata{
|
||||
Name: vat.Sin,
|
||||
Keys: map[shared.Key]string{shared.Guy: fakeGuy},
|
||||
Type: shared.Uint256,
|
||||
}
|
||||
sinMetadata := shared.GetStorageValueMetadata(vat.Sin, map[shared.Key]string{shared.Guy: fakeGuy}, shared.Uint256)
|
||||
|
||||
err := repo.Create(fakeBlockNumber, fakeBlockHash, sinMetadata, fakeUint256)
|
||||
|
||||
@ -264,11 +208,7 @@ var _ = Describe("Vat storage repository", func() {
|
||||
})
|
||||
|
||||
It("returns error if metadata missing guy", func() {
|
||||
malformedSinMetadata := shared.StorageValueMetadata{
|
||||
Name: vat.Sin,
|
||||
Keys: nil,
|
||||
Type: shared.Uint256,
|
||||
}
|
||||
malformedSinMetadata := shared.GetStorageValueMetadata(vat.Sin, nil, shared.Uint256)
|
||||
|
||||
err := repo.Create(fakeBlockNumber, fakeBlockHash, malformedSinMetadata, fakeUint256)
|
||||
|
||||
@ -279,11 +219,7 @@ var _ = Describe("Vat storage repository", func() {
|
||||
|
||||
Describe("urn art", func() {
|
||||
It("writes row", func() {
|
||||
urnArtMetadata := shared.StorageValueMetadata{
|
||||
Name: vat.UrnArt,
|
||||
Keys: map[shared.Key]string{shared.Ilk: fakeIlk, shared.Guy: fakeGuy},
|
||||
Type: shared.Uint256,
|
||||
}
|
||||
urnArtMetadata := shared.GetStorageValueMetadata(vat.UrnArt, map[shared.Key]string{shared.Ilk: fakeIlk, shared.Guy: fakeGuy}, shared.Uint256)
|
||||
|
||||
err := repo.Create(fakeBlockNumber, fakeBlockHash, urnArtMetadata, fakeUint256)
|
||||
|
||||
@ -298,11 +234,7 @@ var _ = Describe("Vat storage repository", func() {
|
||||
})
|
||||
|
||||
It("returns error if metadata missing ilk", func() {
|
||||
malformedUrnArtMetadata := shared.StorageValueMetadata{
|
||||
Name: vat.UrnArt,
|
||||
Keys: map[shared.Key]string{shared.Guy: fakeGuy},
|
||||
Type: shared.Uint256,
|
||||
}
|
||||
malformedUrnArtMetadata := shared.GetStorageValueMetadata(vat.UrnArt, map[shared.Key]string{shared.Guy: fakeGuy}, shared.Uint256)
|
||||
|
||||
err := repo.Create(fakeBlockNumber, fakeBlockHash, malformedUrnArtMetadata, fakeUint256)
|
||||
|
||||
@ -311,11 +243,7 @@ var _ = Describe("Vat storage repository", func() {
|
||||
})
|
||||
|
||||
It("returns error if metadata missing guy", func() {
|
||||
malformedUrnArtMetadata := shared.StorageValueMetadata{
|
||||
Name: vat.UrnArt,
|
||||
Keys: map[shared.Key]string{shared.Ilk: fakeIlk},
|
||||
Type: shared.Uint256,
|
||||
}
|
||||
malformedUrnArtMetadata := shared.GetStorageValueMetadata(vat.UrnArt, map[shared.Key]string{shared.Ilk: fakeIlk}, shared.Uint256)
|
||||
|
||||
err := repo.Create(fakeBlockNumber, fakeBlockHash, malformedUrnArtMetadata, fakeUint256)
|
||||
|
||||
@ -326,11 +254,7 @@ var _ = Describe("Vat storage repository", func() {
|
||||
|
||||
Describe("urn ink", func() {
|
||||
It("writes row", func() {
|
||||
urnInkMetadata := shared.StorageValueMetadata{
|
||||
Name: vat.UrnInk,
|
||||
Keys: map[shared.Key]string{shared.Ilk: fakeIlk, shared.Guy: fakeGuy},
|
||||
Type: shared.Uint256,
|
||||
}
|
||||
urnInkMetadata := shared.GetStorageValueMetadata(vat.UrnInk, map[shared.Key]string{shared.Ilk: fakeIlk, shared.Guy: fakeGuy}, shared.Uint256)
|
||||
|
||||
err := repo.Create(fakeBlockNumber, fakeBlockHash, urnInkMetadata, fakeUint256)
|
||||
|
||||
@ -345,11 +269,7 @@ var _ = Describe("Vat storage repository", func() {
|
||||
})
|
||||
|
||||
It("returns error if metadata missing ilk", func() {
|
||||
malformedUrnInkMetadata := shared.StorageValueMetadata{
|
||||
Name: vat.UrnInk,
|
||||
Keys: map[shared.Key]string{shared.Guy: fakeGuy},
|
||||
Type: shared.Uint256,
|
||||
}
|
||||
malformedUrnInkMetadata := shared.GetStorageValueMetadata(vat.UrnInk, map[shared.Key]string{shared.Guy: fakeGuy}, shared.Uint256)
|
||||
|
||||
err := repo.Create(fakeBlockNumber, fakeBlockHash, malformedUrnInkMetadata, fakeUint256)
|
||||
|
||||
@ -358,11 +278,7 @@ var _ = Describe("Vat storage repository", func() {
|
||||
})
|
||||
|
||||
It("returns error if metadata missing guy", func() {
|
||||
malformedUrnInkMetadata := shared.StorageValueMetadata{
|
||||
Name: vat.UrnInk,
|
||||
Keys: map[shared.Key]string{shared.Ilk: fakeIlk},
|
||||
Type: shared.Uint256,
|
||||
}
|
||||
malformedUrnInkMetadata := shared.GetStorageValueMetadata(vat.UrnInk, map[shared.Key]string{shared.Ilk: fakeIlk}, shared.Uint256)
|
||||
|
||||
err := repo.Create(fakeBlockNumber, fakeBlockHash, malformedUrnInkMetadata, fakeUint256)
|
||||
|
||||
@ -372,13 +288,7 @@ var _ = Describe("Vat storage repository", func() {
|
||||
})
|
||||
|
||||
It("persists vat debt", func() {
|
||||
debtMetadata := shared.StorageValueMetadata{
|
||||
Name: vat.VatDebt,
|
||||
Keys: nil,
|
||||
Type: shared.Uint256,
|
||||
}
|
||||
|
||||
err := repo.Create(fakeBlockNumber, fakeBlockHash, debtMetadata, fakeUint256)
|
||||
err := repo.Create(fakeBlockNumber, fakeBlockHash, vat.DebtMetadata, fakeUint256)
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
@ -389,13 +299,7 @@ var _ = Describe("Vat storage repository", func() {
|
||||
})
|
||||
|
||||
It("persists vat vice", func() {
|
||||
viceMetadata := shared.StorageValueMetadata{
|
||||
Name: vat.VatVice,
|
||||
Keys: nil,
|
||||
Type: shared.Uint256,
|
||||
}
|
||||
|
||||
err := repo.Create(fakeBlockNumber, fakeBlockHash, viceMetadata, fakeUint256)
|
||||
err := repo.Create(fakeBlockNumber, fakeBlockHash, vat.ViceMetadata, fakeUint256)
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user