Skip to content
This repository has been archived by the owner on Aug 31, 2021. It is now read-only.

Commit

Permalink
add woe to storage diff vow contract
Browse files Browse the repository at this point in the history
  • Loading branch information
TakaGoto committed Feb 13, 2019
1 parent 4fe2ff4 commit a8322c7
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 23 deletions.
20 changes: 14 additions & 6 deletions db/migrations/00074_create_vow_contract_storage_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -24,49 +24,57 @@ CREATE TABLE maker.vow_sin (
id SERIAL PRIMARY KEY,
block_number BIGINT,
block_hash TEXT,
sin TEXT
sin numeric
);

CREATE TABLE maker.vow_woe (
id SERIAL PRIMARY KEY,
block_number BIGINT,
block_hash TEXT,
woe numeric
);

CREATE TABLE maker.vow_ash (
id SERIAL PRIMARY KEY,
block_number BIGINT,
block_hash TEXT,
ash TEXT
ash numeric
);

CREATE TABLE maker.vow_wait (
id SERIAL PRIMARY KEY,
block_number BIGINT,
block_hash TEXT,
wait TEXT
wait numeric
);

CREATE TABLE maker.vow_sump (
id SERIAL PRIMARY KEY,
block_number BIGINT,
block_hash TEXT,
sump TEXT
sump numeric
);

CREATE TABLE maker.vow_bump (
id SERIAL PRIMARY KEY,
block_number BIGINT,
block_hash TEXT,
bump TEXT
bump numeric
);

CREATE TABLE maker.vow_hump (
id SERIAL PRIMARY KEY,
block_number BIGINT,
block_hash TEXT,
hump TEXT
hump numeric
);

-- +goose Down
DROP TABLE maker.vow_vat;
DROP TABLE maker.vow_cow;
DROP TABLE maker.vow_row;
DROP TABLE maker.vow_sin;
DROP TABLE maker.vow_woe;
DROP TABLE maker.vow_ash;
DROP TABLE maker.vow_wait;
DROP TABLE maker.vow_sump;
Expand Down
59 changes: 53 additions & 6 deletions db/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1613,7 +1613,7 @@ CREATE TABLE maker.vow_ash (
id integer NOT NULL,
block_number bigint,
block_hash text,
ash text
ash numeric
);


Expand Down Expand Up @@ -1645,7 +1645,7 @@ CREATE TABLE maker.vow_bump (
id integer NOT NULL,
block_number bigint,
block_hash text,
bump text
bump numeric
);


Expand Down Expand Up @@ -1743,7 +1743,7 @@ CREATE TABLE maker.vow_hump (
id integer NOT NULL,
block_number bigint,
block_hash text,
hump text
hump numeric
);


Expand Down Expand Up @@ -1807,7 +1807,7 @@ CREATE TABLE maker.vow_sin (
id integer NOT NULL,
block_number bigint,
block_hash text,
sin text
sin numeric
);


Expand Down Expand Up @@ -1839,7 +1839,7 @@ CREATE TABLE maker.vow_sump (
id integer NOT NULL,
block_number bigint,
block_hash text,
sump text
sump numeric
);


Expand Down Expand Up @@ -1903,7 +1903,7 @@ CREATE TABLE maker.vow_wait (
id integer NOT NULL,
block_number bigint,
block_hash text,
wait text
wait numeric
);


Expand All @@ -1927,6 +1927,38 @@ CREATE SEQUENCE maker.vow_wait_id_seq
ALTER SEQUENCE maker.vow_wait_id_seq OWNED BY maker.vow_wait.id;


--
-- Name: vow_woe; Type: TABLE; Schema: maker; Owner: -
--

CREATE TABLE maker.vow_woe (
id integer NOT NULL,
block_number bigint,
block_hash text,
woe numeric
);


--
-- Name: vow_woe_id_seq; Type: SEQUENCE; Schema: maker; Owner: -
--

CREATE SEQUENCE maker.vow_woe_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;


--
-- Name: vow_woe_id_seq; Type: SEQUENCE OWNED BY; Schema: maker; Owner: -
--

ALTER SEQUENCE maker.vow_woe_id_seq OWNED BY maker.vow_woe.id;


--
-- Name: logs; Type: TABLE; Schema: public; Owner: -
--
Expand Down Expand Up @@ -2758,6 +2790,13 @@ ALTER TABLE ONLY maker.vow_vat ALTER COLUMN id SET DEFAULT nextval('maker.vow_va
ALTER TABLE ONLY maker.vow_wait ALTER COLUMN id SET DEFAULT nextval('maker.vow_wait_id_seq'::regclass);


--
-- Name: vow_woe id; Type: DEFAULT; Schema: maker; Owner: -
--

ALTER TABLE ONLY maker.vow_woe ALTER COLUMN id SET DEFAULT nextval('maker.vow_woe_id_seq'::regclass);


--
-- Name: blocks id; Type: DEFAULT; Schema: public; Owner: -
--
Expand Down Expand Up @@ -3491,6 +3530,14 @@ ALTER TABLE ONLY maker.vow_wait
ADD CONSTRAINT vow_wait_pkey PRIMARY KEY (id);


--
-- Name: vow_woe vow_woe_pkey; Type: CONSTRAINT; Schema: maker; Owner: -
--

ALTER TABLE ONLY maker.vow_woe
ADD CONSTRAINT vow_woe_pkey PRIMARY KEY (id);


--
-- Name: blocks blocks_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
Expand Down
13 changes: 11 additions & 2 deletions pkg/transformers/storage_diffs/maker/vow/mappings.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const (
VowCow = "cow"
VowRow = "row"
VowSin = "Sin"
VowWoe = "woe"
VowAsh = "ash"
VowWait = "wait"
VowSump = "sump"
Expand All @@ -48,14 +49,14 @@ var (
CowMetadata = shared.StorageValueMetadata{
Name: VowCow,
Keys: nil,
Type: shared.Uint256,
Type: shared.Address,
}

RowKey = common.HexToHash(storage_diffs.IndexThree)
RowMetadata = shared.StorageValueMetadata{
Name: VowRow,
Keys: nil,
Type: shared.Uint256,
Type: shared.Address,
}

SinKey = common.HexToHash(storage_diffs.IndexFive)
Expand All @@ -65,6 +66,13 @@ var (
Type: shared.Uint256,
}

WoeKey = common.HexToHash(storage_diffs.IndexSix)
WoeMetadata = shared.StorageValueMetadata{
Name: VowWoe,
Keys: nil,
Type: shared.Uint256,
}

AshKey = common.HexToHash(storage_diffs.IndexSeven)
AshMetadata = shared.StorageValueMetadata{
Name: VowAsh,
Expand Down Expand Up @@ -127,6 +135,7 @@ func (mappings *VowMappings) loadMappings() error {
staticMappings[CowKey] = CowMetadata
staticMappings[RowKey] = RowMetadata
staticMappings[SinKey] = SinMetadata
staticMappings[WoeKey] = WoeMetadata
staticMappings[AshKey] = AshMetadata
staticMappings[WaitKey] = WaitMetadata
staticMappings[SumpKey] = SumpMetadata
Expand Down
1 change: 1 addition & 0 deletions pkg/transformers/storage_diffs/maker/vow/mappings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ var _ = Describe("Vow storage mappings", func() {
Expect(mappings.Lookup(vow.CowKey)).To(Equal(vow.CowMetadata))
Expect(mappings.Lookup(vow.RowKey)).To(Equal(vow.RowMetadata))
Expect(mappings.Lookup(vow.SinKey)).To(Equal(vow.SinMetadata))
Expect(mappings.Lookup(vow.WoeKey)).To(Equal(vow.WoeMetadata))
Expect(mappings.Lookup(vow.AshKey)).To(Equal(vow.AshMetadata))
Expect(mappings.Lookup(vow.WaitKey)).To(Equal(vow.WaitMetadata))
Expect(mappings.Lookup(vow.SumpKey)).To(Equal(vow.SumpMetadata))
Expand Down
8 changes: 8 additions & 0 deletions pkg/transformers/storage_diffs/maker/vow/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ func (repository VowStorageRepository) Create(blockNumber int, blockHash string,
return repository.insertVowRow(blockNumber, blockHash, value.(string))
case VowSin:
return repository.insertVowSin(blockNumber, blockHash, value.(string))
case VowWoe:
return repository.insertVowWoe(blockNumber, blockHash, value.(string))
case VowAsh:
return repository.insertVowAsh(blockNumber, blockHash, value.(string))
case VowWait:
Expand Down Expand Up @@ -78,6 +80,12 @@ func (repository VowStorageRepository) insertVowSin(blockNumber int, blockHash s
return err
}

func (repository VowStorageRepository) insertVowWoe(blockNumber int, blockHash string, woe string) error {
_, err := repository.db.Exec(`INSERT INTO maker.vow_woe (block_number, block_hash, woe) VALUES ($1, $2, $3)`, blockNumber, blockHash, woe)

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)

Expand Down
36 changes: 27 additions & 9 deletions pkg/transformers/storage_diffs/maker/vow/repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ var _ = Describe("Vow storage repository test", func() {
})

It("persists a vow vat", func() {
expectedVat := "vat"
expectedVat := "123"

err = repo.Create(blockNumber, blockHash, vow.VatMetadata, expectedVat)

Expand All @@ -62,7 +62,7 @@ var _ = Describe("Vow storage repository test", func() {
})

It("persists a vow cow", func() {
expectedCow := "cow"
expectedCow := "123"

err = repo.Create(blockNumber, blockHash, vow.CowMetadata, expectedCow)

Expand All @@ -80,7 +80,7 @@ var _ = Describe("Vow storage repository test", func() {
})

It("persists a vow row", func() {
expectedRow := "row"
expectedRow := "123"

err = repo.Create(blockNumber, blockHash, vow.RowMetadata, expectedRow)

Expand All @@ -98,7 +98,7 @@ var _ = Describe("Vow storage repository test", func() {
})

It("persists a vow Sin", func() {
expectedSow := "sow"
expectedSow := "123"

err = repo.Create(blockNumber, blockHash, vow.SinMetadata, expectedSow)

Expand All @@ -115,8 +115,26 @@ var _ = Describe("Vow storage repository test", func() {
Expect(result.Sin).To(Equal(expectedSow))
})

It("persists a vow woe", func() {
expectedWoe := "123"

err = repo.Create(blockNumber, blockHash, vow.WoeMetadata, expectedWoe)

Expect(err).NotTo(HaveOccurred())
type VowWoe struct {
BlockMetadata
Woe string
}
var result VowWoe
err = db.Get(&result, `SELECT block_number, block_hash, woe from maker.vow_woe`)
Expect(err).NotTo(HaveOccurred())
Expect(result.BlockNumber).To(Equal(blockNumber))
Expect(result.BlockHash).To(Equal(blockHash))
Expect(result.Woe).To(Equal(expectedWoe))
})

It("persists a vow Ash", func() {
expectedAsh := "ash"
expectedAsh := "123"

err = repo.Create(blockNumber, blockHash, vow.AshMetadata, expectedAsh)

Expand All @@ -134,7 +152,7 @@ var _ = Describe("Vow storage repository test", func() {
})

It("persists a vow Wait", func() {
expectedWait := "wait"
expectedWait := "123"

err = repo.Create(blockNumber, blockHash, vow.WaitMetadata, expectedWait)

Expand All @@ -152,7 +170,7 @@ var _ = Describe("Vow storage repository test", func() {
})

It("persists a vow Bump", func() {
expectedBump := "bump"
expectedBump := "123"

err = repo.Create(blockNumber, blockHash, vow.BumpMetadata, expectedBump)

Expand All @@ -170,7 +188,7 @@ var _ = Describe("Vow storage repository test", func() {
})

It("persists a vow Sump", func() {
expectedSump := "sump"
expectedSump := "123"

err = repo.Create(blockNumber, blockHash, vow.SumpMetadata, expectedSump)

Expand All @@ -188,7 +206,7 @@ var _ = Describe("Vow storage repository test", func() {
})

It("persists a vow Hump", func() {
expectedHump := "hump"
expectedHump := "123"

err = repo.Create(blockNumber, blockHash, vow.HumpMetadata, expectedHump)

Expand Down

0 comments on commit a8322c7

Please sign in to comment.