repository methods:

This commit is contained in:
Taka Goto 2019-02-11 16:34:02 -06:00
parent 764befef69
commit 4fe2ff4104
3 changed files with 225 additions and 17 deletions

View File

@ -26,14 +26,14 @@ import (
const (
VowVat = "vat"
CowVat = "cow"
RowVat = "row"
SinVat = "Sin"
AshVat = "ash"
WaitVat = "wait"
SumpVat = "sump"
BumpVat = "bump"
HumpVat = "hump"
VowCow = "cow"
VowRow = "row"
VowSin = "Sin"
VowAsh = "ash"
VowWait = "wait"
VowSump = "sump"
VowBump = "bump"
VowHump = "hump"
)
var (
@ -46,56 +46,56 @@ var (
CowKey = common.HexToHash(storage_diffs.IndexTwo)
CowMetadata = shared.StorageValueMetadata{
Name: CowVat,
Name: VowCow,
Keys: nil,
Type: shared.Uint256,
}
RowKey = common.HexToHash(storage_diffs.IndexThree)
RowMetadata = shared.StorageValueMetadata{
Name: RowVat,
Name: VowRow,
Keys: nil,
Type: shared.Uint256,
}
SinKey = common.HexToHash(storage_diffs.IndexFive)
SinMetadata = shared.StorageValueMetadata{
Name: SinVat,
Name: VowSin,
Keys: nil,
Type: shared.Uint256,
}
AshKey = common.HexToHash(storage_diffs.IndexSeven)
AshMetadata = shared.StorageValueMetadata{
Name: AshVat,
Name: VowAsh,
Keys: nil,
Type: shared.Uint256,
}
WaitKey = common.HexToHash(storage_diffs.IndexEight)
WaitMetadata = shared.StorageValueMetadata{
Name: WaitVat,
Name: VowWait,
Keys: nil,
Type: shared.Uint256,
}
SumpKey = common.HexToHash(storage_diffs.IndexNine)
SumpMetadata = shared.StorageValueMetadata{
Name: SumpVat,
Name: VowSump,
Keys: nil,
Type: shared.Uint256,
}
BumpKey = common.HexToHash(storage_diffs.IndexTen)
BumpMetadata = shared.StorageValueMetadata{
Name: BumpVat,
Name: VowBump,
Keys: nil,
Type: shared.Uint256,
}
HumpKey = common.HexToHash(storage_diffs.IndexEleven)
HumpMetadata = shared.StorageValueMetadata{
Name: HumpVat,
Name: VowHump,
Keys: nil,
Type: shared.Uint256,
}

View File

@ -33,6 +33,22 @@ func (repository VowStorageRepository) Create(blockNumber int, blockHash string,
switch metadata.Name {
case VowVat:
return repository.insertVowVat(blockNumber, blockHash, value.(string))
case VowCow:
return repository.insertVowCow(blockNumber, blockHash, value.(string))
case VowRow:
return repository.insertVowRow(blockNumber, blockHash, value.(string))
case VowSin:
return repository.insertVowSin(blockNumber, blockHash, value.(string))
case VowAsh:
return repository.insertVowAsh(blockNumber, blockHash, value.(string))
case VowWait:
return repository.insertVowWait(blockNumber, blockHash, value.(string))
case VowSump:
return repository.insertVowSump(blockNumber, blockHash, value.(string))
case VowBump:
return repository.insertVowBump(blockNumber, blockHash, value.(string))
case VowHump:
return repository.insertVowHump(blockNumber, blockHash, value.(string))
default:
panic("unrecognized storage metadata name")
}
@ -43,3 +59,51 @@ func (repository VowStorageRepository) insertVowVat(blockNumber int, blockHash s
return err
}
func (repository VowStorageRepository) insertVowCow(blockNumber int, blockHash string, cow string) error {
_, err := repository.db.Exec(`INSERT INTO maker.vow_cow (block_number, block_hash, cow) VALUES ($1, $2, $3)`, blockNumber, blockHash, cow)
return err
}
func (repository VowStorageRepository) insertVowRow(blockNumber int, blockHash string, row string) error {
_, err := repository.db.Exec(`INSERT INTO maker.vow_row (block_number, block_hash, row) VALUES ($1, $2, $3)`, blockNumber, blockHash, row)
return err
}
func (repository VowStorageRepository) insertVowSin(blockNumber int, blockHash string, sin string) error {
_, err := repository.db.Exec(`INSERT INTO maker.vow_sin (block_number, block_hash, sin) VALUES ($1, $2, $3)`, blockNumber, blockHash, sin)
return err
}
func (repository VowStorageRepository) insertVowAsh(blockNumber int, blockHash string, ash string) error {
_, err := repository.db.Exec(`INSERT INTO maker.vow_ash (block_number, block_hash, ash) VALUES ($1, $2, $3)`, blockNumber, blockHash, ash)
return err
}
func (repository VowStorageRepository) insertVowWait(blockNumber int, blockHash string, wait string) error {
_, err := repository.db.Exec(`INSERT INTO maker.vow_wait (block_number, block_hash, wait) VALUES ($1, $2, $3)`, blockNumber, blockHash, wait)
return err
}
func (repository VowStorageRepository) insertVowSump(blockNumber int, blockHash string, sump string) error {
_, err := repository.db.Exec(`INSERT INTO maker.vow_sump (block_number, block_hash, sump) VALUES ($1, $2, $3)`, blockNumber, blockHash, sump)
return err
}
func (repository VowStorageRepository) insertVowBump(blockNumber int, blockHash string, bump string) error {
_, err := repository.db.Exec(`INSERT INTO maker.vow_bump (block_number, block_hash, bump) VALUES ($1, $2, $3)`, blockNumber, blockHash, bump)
return err
}
func (repository VowStorageRepository) insertVowHump(blockNumber int, blockHash string, hump string) error {
_, err := repository.db.Exec(`INSERT INTO maker.vow_hump (block_number, block_hash, hump) VALUES ($1, $2, $3)`, blockNumber, blockHash, hump)
return err
}

View File

@ -44,7 +44,7 @@ var _ = Describe("Vow storage repository test", func() {
})
It("persists a vow vat", func() {
expectedVat := "yo"
expectedVat := "vat"
err = repo.Create(blockNumber, blockHash, vow.VatMetadata, expectedVat)
@ -60,6 +60,150 @@ var _ = Describe("Vow storage repository test", func() {
Expect(result.BlockHash).To(Equal(blockHash))
Expect(result.Vat).To(Equal(expectedVat))
})
It("persists a vow cow", func() {
expectedCow := "cow"
err = repo.Create(blockNumber, blockHash, vow.CowMetadata, expectedCow)
Expect(err).NotTo(HaveOccurred())
type VowCow struct {
BlockMetadata
Cow string
}
var result VowCow
err = db.Get(&result, `SELECT block_number, block_hash, cow from maker.vow_cow`)
Expect(err).NotTo(HaveOccurred())
Expect(result.BlockNumber).To(Equal(blockNumber))
Expect(result.BlockHash).To(Equal(blockHash))
Expect(result.Cow).To(Equal(expectedCow))
})
It("persists a vow row", func() {
expectedRow := "row"
err = repo.Create(blockNumber, blockHash, vow.RowMetadata, expectedRow)
Expect(err).NotTo(HaveOccurred())
type VowRow struct {
BlockMetadata
Row string
}
var result VowRow
err = db.Get(&result, `SELECT block_number, block_hash, row from maker.vow_row`)
Expect(err).NotTo(HaveOccurred())
Expect(result.BlockNumber).To(Equal(blockNumber))
Expect(result.BlockHash).To(Equal(blockHash))
Expect(result.Row).To(Equal(expectedRow))
})
It("persists a vow Sin", func() {
expectedSow := "sow"
err = repo.Create(blockNumber, blockHash, vow.SinMetadata, expectedSow)
Expect(err).NotTo(HaveOccurred())
type VowSin struct {
BlockMetadata
Sin string
}
var result VowSin
err = db.Get(&result, `SELECT block_number, block_hash, sin from maker.vow_sin`)
Expect(err).NotTo(HaveOccurred())
Expect(result.BlockNumber).To(Equal(blockNumber))
Expect(result.BlockHash).To(Equal(blockHash))
Expect(result.Sin).To(Equal(expectedSow))
})
It("persists a vow Ash", func() {
expectedAsh := "ash"
err = repo.Create(blockNumber, blockHash, vow.AshMetadata, expectedAsh)
Expect(err).NotTo(HaveOccurred())
type VowAsh struct {
BlockMetadata
Ash string
}
var result VowAsh
err = db.Get(&result, `SELECT block_number, block_hash, ash from maker.vow_ash`)
Expect(err).NotTo(HaveOccurred())
Expect(result.BlockNumber).To(Equal(blockNumber))
Expect(result.BlockHash).To(Equal(blockHash))
Expect(result.Ash).To(Equal(expectedAsh))
})
It("persists a vow Wait", func() {
expectedWait := "wait"
err = repo.Create(blockNumber, blockHash, vow.WaitMetadata, expectedWait)
Expect(err).NotTo(HaveOccurred())
type VowWait struct {
BlockMetadata
Wait string
}
var result VowWait
err = db.Get(&result, `SELECT block_number, block_hash, wait from maker.vow_wait`)
Expect(err).NotTo(HaveOccurred())
Expect(result.BlockNumber).To(Equal(blockNumber))
Expect(result.BlockHash).To(Equal(blockHash))
Expect(result.Wait).To(Equal(expectedWait))
})
It("persists a vow Bump", func() {
expectedBump := "bump"
err = repo.Create(blockNumber, blockHash, vow.BumpMetadata, expectedBump)
Expect(err).NotTo(HaveOccurred())
type VowBump struct {
BlockMetadata
Bump string
}
var result VowBump
err = db.Get(&result, `SELECT block_number, block_hash, bump from maker.vow_bump`)
Expect(err).NotTo(HaveOccurred())
Expect(result.BlockNumber).To(Equal(blockNumber))
Expect(result.BlockHash).To(Equal(blockHash))
Expect(result.Bump).To(Equal(expectedBump))
})
It("persists a vow Sump", func() {
expectedSump := "sump"
err = repo.Create(blockNumber, blockHash, vow.SumpMetadata, expectedSump)
Expect(err).NotTo(HaveOccurred())
type VowSump struct {
BlockMetadata
Sump string
}
var result VowSump
err = db.Get(&result, `SELECT block_number, block_hash, sump from maker.vow_sump`)
Expect(err).NotTo(HaveOccurred())
Expect(result.BlockNumber).To(Equal(blockNumber))
Expect(result.BlockHash).To(Equal(blockHash))
Expect(result.Sump).To(Equal(expectedSump))
})
It("persists a vow Hump", func() {
expectedHump := "hump"
err = repo.Create(blockNumber, blockHash, vow.HumpMetadata, expectedHump)
Expect(err).NotTo(HaveOccurred())
type VowHump struct {
BlockMetadata
Hump string
}
var result VowHump
err = db.Get(&result, `SELECT block_number, block_hash, hump from maker.vow_hump`)
Expect(err).NotTo(HaveOccurred())
Expect(result.BlockNumber).To(Equal(blockNumber))
Expect(result.BlockHash).To(Equal(blockHash))
Expect(result.Hump).To(Equal(expectedHump))
})
})
type BlockMetadata struct {