From 0d92829fe27d5d9711f68ac3f4f5616c895d43b6 Mon Sep 17 00:00:00 2001 From: Taka Goto Date: Mon, 11 Feb 2019 15:11:36 -0600 Subject: [PATCH 1/5] vow contract storage diffing excluding sin --- cmd/parseStorageDiffs.go | 1 + ...074_create_vow_contract_storage_tables.sql | 74 +++ db/schema.sql | 427 +++++++++++++++++- pkg/datastore/postgres/postgres.go | 2 - .../storage_diffs/maker/vow/mappings.go | 143 ++++++ .../storage_diffs/maker/vow/mappings_test.go | 41 ++ .../storage_diffs/maker/vow/repository.go | 45 ++ .../maker/vow/repository_test.go | 68 +++ .../storage_diffs/maker/vow/vow_suite_test.go | 13 + pkg/transformers/storage_diffs/mappings.go | 20 +- pkg/transformers/storage_transformers.go | 9 + 11 files changed, 831 insertions(+), 12 deletions(-) create mode 100644 db/migrations/00074_create_vow_contract_storage_tables.sql create mode 100644 pkg/transformers/storage_diffs/maker/vow/mappings.go create mode 100644 pkg/transformers/storage_diffs/maker/vow/mappings_test.go create mode 100644 pkg/transformers/storage_diffs/maker/vow/repository.go create mode 100644 pkg/transformers/storage_diffs/maker/vow/repository_test.go create mode 100644 pkg/transformers/storage_diffs/maker/vow/vow_suite_test.go diff --git a/cmd/parseStorageDiffs.go b/cmd/parseStorageDiffs.go index 5fa9dc7c6..f826d3cba 100644 --- a/cmd/parseStorageDiffs.go +++ b/cmd/parseStorageDiffs.go @@ -60,6 +60,7 @@ func parseStorageDiffs() { watcher.AddTransformers([]storage.TransformerInitializer{ transformers.GetPitStorageTransformer().NewTransformer, transformers.GetVatStorageTransformer().NewTransformer, + transformers.GetVowStorageTransformer().NewTransformer, }) err = watcher.Execute() diff --git a/db/migrations/00074_create_vow_contract_storage_tables.sql b/db/migrations/00074_create_vow_contract_storage_tables.sql new file mode 100644 index 000000000..751ee1e22 --- /dev/null +++ b/db/migrations/00074_create_vow_contract_storage_tables.sql @@ -0,0 +1,74 @@ +-- +goose Up +CREATE TABLE maker.vow_vat ( + id SERIAL PRIMARY KEY, + block_number BIGINT, + block_hash TEXT, + vat TEXT +); + +CREATE TABLE maker.vow_cow ( + id SERIAL PRIMARY KEY, + block_number BIGINT, + block_hash TEXT, + cow TEXT +); + +CREATE TABLE maker.vow_row ( + id SERIAL PRIMARY KEY, + block_number BIGINT, + block_hash TEXT, + row TEXT +); + +CREATE TABLE maker.vow_sin ( + id SERIAL PRIMARY KEY, + block_number BIGINT, + block_hash TEXT, + sin TEXT +); + +CREATE TABLE maker.vow_ash ( + id SERIAL PRIMARY KEY, + block_number BIGINT, + block_hash TEXT, + ash TEXT +); + +CREATE TABLE maker.vow_wait ( + id SERIAL PRIMARY KEY, + block_number BIGINT, + block_hash TEXT, + wait TEXT +); + +CREATE TABLE maker.vow_sump ( + id SERIAL PRIMARY KEY, + block_number BIGINT, + block_hash TEXT, + sump TEXT +); + +CREATE TABLE maker.vow_bump ( + id SERIAL PRIMARY KEY, + block_number BIGINT, + block_hash TEXT, + bump TEXT +); + +CREATE TABLE maker.vow_hump ( + id SERIAL PRIMARY KEY, + block_number BIGINT, + block_hash TEXT, + hump TEXT +); + +-- +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_ash +DROP TABLE maker.vow_wait +DROP TABLE maker.vow_sump +DROP TABLE maker.vow_bump +DROP TABLE maker.vow_hump diff --git a/db/schema.sql b/db/schema.sql index 223a84d2f..6db1d44e5 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -2,8 +2,8 @@ -- PostgreSQL database dump -- --- Dumped from database version 10.5 --- Dumped by pg_dump version 10.5 +-- Dumped from database version 10.4 +-- Dumped by pg_dump version 10.4 SET statement_timeout = 0; SET lock_timeout = 0; @@ -1605,6 +1605,102 @@ CREATE SEQUENCE maker.vat_vice_id_seq ALTER SEQUENCE maker.vat_vice_id_seq OWNED BY maker.vat_vice.id; +-- +-- Name: vow_ash; Type: TABLE; Schema: maker; Owner: - +-- + +CREATE TABLE maker.vow_ash ( + id integer NOT NULL, + block_number bigint, + block_hash text, + ash text +); + + +-- +-- Name: vow_ash_id_seq; Type: SEQUENCE; Schema: maker; Owner: - +-- + +CREATE SEQUENCE maker.vow_ash_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: vow_ash_id_seq; Type: SEQUENCE OWNED BY; Schema: maker; Owner: - +-- + +ALTER SEQUENCE maker.vow_ash_id_seq OWNED BY maker.vow_ash.id; + + +-- +-- Name: vow_bump; Type: TABLE; Schema: maker; Owner: - +-- + +CREATE TABLE maker.vow_bump ( + id integer NOT NULL, + block_number bigint, + block_hash text, + bump text +); + + +-- +-- Name: vow_bump_id_seq; Type: SEQUENCE; Schema: maker; Owner: - +-- + +CREATE SEQUENCE maker.vow_bump_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: vow_bump_id_seq; Type: SEQUENCE OWNED BY; Schema: maker; Owner: - +-- + +ALTER SEQUENCE maker.vow_bump_id_seq OWNED BY maker.vow_bump.id; + + +-- +-- Name: vow_cow; Type: TABLE; Schema: maker; Owner: - +-- + +CREATE TABLE maker.vow_cow ( + id integer NOT NULL, + block_number bigint, + block_hash text, + cow text +); + + +-- +-- Name: vow_cow_id_seq; Type: SEQUENCE; Schema: maker; Owner: - +-- + +CREATE SEQUENCE maker.vow_cow_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: vow_cow_id_seq; Type: SEQUENCE OWNED BY; Schema: maker; Owner: - +-- + +ALTER SEQUENCE maker.vow_cow_id_seq OWNED BY maker.vow_cow.id; + + -- -- Name: vow_flog; Type: TABLE; Schema: maker; Owner: - -- @@ -1639,6 +1735,198 @@ CREATE SEQUENCE maker.vow_flog_id_seq ALTER SEQUENCE maker.vow_flog_id_seq OWNED BY maker.vow_flog.id; +-- +-- Name: vow_hump; Type: TABLE; Schema: maker; Owner: - +-- + +CREATE TABLE maker.vow_hump ( + id integer NOT NULL, + block_number bigint, + block_hash text, + hump text +); + + +-- +-- Name: vow_hump_id_seq; Type: SEQUENCE; Schema: maker; Owner: - +-- + +CREATE SEQUENCE maker.vow_hump_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: vow_hump_id_seq; Type: SEQUENCE OWNED BY; Schema: maker; Owner: - +-- + +ALTER SEQUENCE maker.vow_hump_id_seq OWNED BY maker.vow_hump.id; + + +-- +-- Name: vow_row; Type: TABLE; Schema: maker; Owner: - +-- + +CREATE TABLE maker.vow_row ( + id integer NOT NULL, + block_number bigint, + block_hash text, + "row" text +); + + +-- +-- Name: vow_row_id_seq; Type: SEQUENCE; Schema: maker; Owner: - +-- + +CREATE SEQUENCE maker.vow_row_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: vow_row_id_seq; Type: SEQUENCE OWNED BY; Schema: maker; Owner: - +-- + +ALTER SEQUENCE maker.vow_row_id_seq OWNED BY maker.vow_row.id; + + +-- +-- Name: vow_sin; Type: TABLE; Schema: maker; Owner: - +-- + +CREATE TABLE maker.vow_sin ( + id integer NOT NULL, + block_number bigint, + block_hash text, + sin text +); + + +-- +-- Name: vow_sin_id_seq; Type: SEQUENCE; Schema: maker; Owner: - +-- + +CREATE SEQUENCE maker.vow_sin_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: vow_sin_id_seq; Type: SEQUENCE OWNED BY; Schema: maker; Owner: - +-- + +ALTER SEQUENCE maker.vow_sin_id_seq OWNED BY maker.vow_sin.id; + + +-- +-- Name: vow_sump; Type: TABLE; Schema: maker; Owner: - +-- + +CREATE TABLE maker.vow_sump ( + id integer NOT NULL, + block_number bigint, + block_hash text, + sump text +); + + +-- +-- Name: vow_sump_id_seq; Type: SEQUENCE; Schema: maker; Owner: - +-- + +CREATE SEQUENCE maker.vow_sump_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: vow_sump_id_seq; Type: SEQUENCE OWNED BY; Schema: maker; Owner: - +-- + +ALTER SEQUENCE maker.vow_sump_id_seq OWNED BY maker.vow_sump.id; + + +-- +-- Name: vow_vat; Type: TABLE; Schema: maker; Owner: - +-- + +CREATE TABLE maker.vow_vat ( + id integer NOT NULL, + block_number bigint, + block_hash text, + vat text +); + + +-- +-- Name: vow_vat_id_seq; Type: SEQUENCE; Schema: maker; Owner: - +-- + +CREATE SEQUENCE maker.vow_vat_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: vow_vat_id_seq; Type: SEQUENCE OWNED BY; Schema: maker; Owner: - +-- + +ALTER SEQUENCE maker.vow_vat_id_seq OWNED BY maker.vow_vat.id; + + +-- +-- Name: vow_wait; Type: TABLE; Schema: maker; Owner: - +-- + +CREATE TABLE maker.vow_wait ( + id integer NOT NULL, + block_number bigint, + block_hash text, + wait text +); + + +-- +-- Name: vow_wait_id_seq; Type: SEQUENCE; Schema: maker; Owner: - +-- + +CREATE SEQUENCE maker.vow_wait_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: vow_wait_id_seq; Type: SEQUENCE OWNED BY; Schema: maker; Owner: - +-- + +ALTER SEQUENCE maker.vow_wait_id_seq OWNED BY maker.vow_wait.id; + + -- -- Name: logs; Type: TABLE; Schema: public; Owner: - -- @@ -2400,6 +2688,27 @@ ALTER TABLE ONLY maker.vat_urn_ink ALTER COLUMN id SET DEFAULT nextval('maker.va ALTER TABLE ONLY maker.vat_vice ALTER COLUMN id SET DEFAULT nextval('maker.vat_vice_id_seq'::regclass); +-- +-- Name: vow_ash id; Type: DEFAULT; Schema: maker; Owner: - +-- + +ALTER TABLE ONLY maker.vow_ash ALTER COLUMN id SET DEFAULT nextval('maker.vow_ash_id_seq'::regclass); + + +-- +-- Name: vow_bump id; Type: DEFAULT; Schema: maker; Owner: - +-- + +ALTER TABLE ONLY maker.vow_bump ALTER COLUMN id SET DEFAULT nextval('maker.vow_bump_id_seq'::regclass); + + +-- +-- Name: vow_cow id; Type: DEFAULT; Schema: maker; Owner: - +-- + +ALTER TABLE ONLY maker.vow_cow ALTER COLUMN id SET DEFAULT nextval('maker.vow_cow_id_seq'::regclass); + + -- -- Name: vow_flog id; Type: DEFAULT; Schema: maker; Owner: - -- @@ -2407,6 +2716,48 @@ ALTER TABLE ONLY maker.vat_vice ALTER COLUMN id SET DEFAULT nextval('maker.vat_v ALTER TABLE ONLY maker.vow_flog ALTER COLUMN id SET DEFAULT nextval('maker.vow_flog_id_seq'::regclass); +-- +-- Name: vow_hump id; Type: DEFAULT; Schema: maker; Owner: - +-- + +ALTER TABLE ONLY maker.vow_hump ALTER COLUMN id SET DEFAULT nextval('maker.vow_hump_id_seq'::regclass); + + +-- +-- Name: vow_row id; Type: DEFAULT; Schema: maker; Owner: - +-- + +ALTER TABLE ONLY maker.vow_row ALTER COLUMN id SET DEFAULT nextval('maker.vow_row_id_seq'::regclass); + + +-- +-- Name: vow_sin id; Type: DEFAULT; Schema: maker; Owner: - +-- + +ALTER TABLE ONLY maker.vow_sin ALTER COLUMN id SET DEFAULT nextval('maker.vow_sin_id_seq'::regclass); + + +-- +-- Name: vow_sump id; Type: DEFAULT; Schema: maker; Owner: - +-- + +ALTER TABLE ONLY maker.vow_sump ALTER COLUMN id SET DEFAULT nextval('maker.vow_sump_id_seq'::regclass); + + +-- +-- Name: vow_vat id; Type: DEFAULT; Schema: maker; Owner: - +-- + +ALTER TABLE ONLY maker.vow_vat ALTER COLUMN id SET DEFAULT nextval('maker.vow_vat_id_seq'::regclass); + + +-- +-- Name: vow_wait id; Type: DEFAULT; Schema: maker; Owner: - +-- + +ALTER TABLE ONLY maker.vow_wait ALTER COLUMN id SET DEFAULT nextval('maker.vow_wait_id_seq'::regclass); + + -- -- Name: blocks id; Type: DEFAULT; Schema: public; Owner: - -- @@ -3052,6 +3403,30 @@ ALTER TABLE ONLY maker.vat_vice ADD CONSTRAINT vat_vice_pkey PRIMARY KEY (id); +-- +-- Name: vow_ash vow_ash_pkey; Type: CONSTRAINT; Schema: maker; Owner: - +-- + +ALTER TABLE ONLY maker.vow_ash + ADD CONSTRAINT vow_ash_pkey PRIMARY KEY (id); + + +-- +-- Name: vow_bump vow_bump_pkey; Type: CONSTRAINT; Schema: maker; Owner: - +-- + +ALTER TABLE ONLY maker.vow_bump + ADD CONSTRAINT vow_bump_pkey PRIMARY KEY (id); + + +-- +-- Name: vow_cow vow_cow_pkey; Type: CONSTRAINT; Schema: maker; Owner: - +-- + +ALTER TABLE ONLY maker.vow_cow + ADD CONSTRAINT vow_cow_pkey PRIMARY KEY (id); + + -- -- Name: vow_flog vow_flog_header_id_tx_idx_log_idx_key; Type: CONSTRAINT; Schema: maker; Owner: - -- @@ -3068,6 +3443,54 @@ ALTER TABLE ONLY maker.vow_flog ADD CONSTRAINT vow_flog_pkey PRIMARY KEY (id); +-- +-- Name: vow_hump vow_hump_pkey; Type: CONSTRAINT; Schema: maker; Owner: - +-- + +ALTER TABLE ONLY maker.vow_hump + ADD CONSTRAINT vow_hump_pkey PRIMARY KEY (id); + + +-- +-- Name: vow_row vow_row_pkey; Type: CONSTRAINT; Schema: maker; Owner: - +-- + +ALTER TABLE ONLY maker.vow_row + ADD CONSTRAINT vow_row_pkey PRIMARY KEY (id); + + +-- +-- Name: vow_sin vow_sin_pkey; Type: CONSTRAINT; Schema: maker; Owner: - +-- + +ALTER TABLE ONLY maker.vow_sin + ADD CONSTRAINT vow_sin_pkey PRIMARY KEY (id); + + +-- +-- Name: vow_sump vow_sump_pkey; Type: CONSTRAINT; Schema: maker; Owner: - +-- + +ALTER TABLE ONLY maker.vow_sump + ADD CONSTRAINT vow_sump_pkey PRIMARY KEY (id); + + +-- +-- Name: vow_vat vow_vat_pkey; Type: CONSTRAINT; Schema: maker; Owner: - +-- + +ALTER TABLE ONLY maker.vow_vat + ADD CONSTRAINT vow_vat_pkey PRIMARY KEY (id); + + +-- +-- Name: vow_wait vow_wait_pkey; Type: CONSTRAINT; Schema: maker; Owner: - +-- + +ALTER TABLE ONLY maker.vow_wait + ADD CONSTRAINT vow_wait_pkey PRIMARY KEY (id); + + -- -- Name: blocks blocks_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- diff --git a/pkg/datastore/postgres/postgres.go b/pkg/datastore/postgres/postgres.go index dc43e3514..82a1b2acb 100644 --- a/pkg/datastore/postgres/postgres.go +++ b/pkg/datastore/postgres/postgres.go @@ -18,7 +18,6 @@ package postgres import ( "errors" - "github.com/sirupsen/logrus" "github.com/jmoiron/sqlx" _ "github.com/lib/pq" //postgres driver @@ -41,7 +40,6 @@ var ( func NewDB(databaseConfig config.Database, node core.Node) (*DB, error) { connectString := config.DbConnectionString(databaseConfig) - logrus.Info("Using connection string: ", connectString) db, err := sqlx.Connect("postgres", connectString) if err != nil { return &DB{}, ErrDBConnectionFailed diff --git a/pkg/transformers/storage_diffs/maker/vow/mappings.go b/pkg/transformers/storage_diffs/maker/vow/mappings.go new file mode 100644 index 000000000..1c126f0ed --- /dev/null +++ b/pkg/transformers/storage_diffs/maker/vow/mappings.go @@ -0,0 +1,143 @@ +/* + * Copyright 2018 Vulcanize + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package vow + +import ( + "github.com/ethereum/go-ethereum/common" + "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" + "github.com/vulcanize/vulcanizedb/pkg/transformers/storage_diffs" + "github.com/vulcanize/vulcanizedb/pkg/transformers/storage_diffs/maker" + "github.com/vulcanize/vulcanizedb/pkg/transformers/storage_diffs/shared" +) + +const ( + VowVat = "vat" + CowVat = "cow" + RowVat = "row" + SinVat = "Sin" + AshVat = "ash" + WaitVat = "wait" + SumpVat = "sump" + BumpVat = "bump" + HumpVat = "hump" +) + +var ( + VatKey = common.HexToHash(storage_diffs.IndexOne) + VatMetadata = shared.StorageValueMetadata{ + Name: VowVat, + Keys: nil, + Type: shared.Address, + } + + CowKey = common.HexToHash(storage_diffs.IndexTwo) + CowMetadata = shared.StorageValueMetadata{ + Name: CowVat, + Keys: nil, + Type: shared.Uint256, + } + + RowKey = common.HexToHash(storage_diffs.IndexThree) + RowMetadata = shared.StorageValueMetadata{ + Name: RowVat, + Keys: nil, + Type: shared.Uint256, + } + + SinKey = common.HexToHash(storage_diffs.IndexFive) + SinMetadata = shared.StorageValueMetadata{ + Name: SinVat, + Keys: nil, + Type: shared.Uint256, + } + + AshKey = common.HexToHash(storage_diffs.IndexSeven) + AshMetadata = shared.StorageValueMetadata{ + Name: AshVat, + Keys: nil, + Type: shared.Uint256, + } + + WaitKey = common.HexToHash(storage_diffs.IndexEight) + WaitMetadata = shared.StorageValueMetadata{ + Name: WaitVat, + Keys: nil, + Type: shared.Uint256, + } + + SumpKey = common.HexToHash(storage_diffs.IndexNine) + SumpMetadata = shared.StorageValueMetadata{ + Name: SumpVat, + Keys: nil, + Type: shared.Uint256, + } + + BumpKey = common.HexToHash(storage_diffs.IndexTen) + BumpMetadata = shared.StorageValueMetadata{ + Name: BumpVat, + Keys: nil, + Type: shared.Uint256, + } + + HumpKey = common.HexToHash(storage_diffs.IndexEleven) + HumpMetadata = shared.StorageValueMetadata{ + Name: HumpVat, + Keys: nil, + Type: shared.Uint256, + } +) + +type VowMappings struct { + StorageRepository maker.IMakerStorageRepository + mappings map[common.Hash]shared.StorageValueMetadata +} + +func (mappings *VowMappings) Lookup(key common.Hash) (shared.StorageValueMetadata, error) { + metadata, ok := mappings.mappings[key] + if !ok { + err := mappings.loadMappings() + if err != nil { + return metadata, err + } + metadata, ok = mappings.mappings[key] + if !ok { + return metadata, shared.ErrStorageKeyNotFound{Key: key.Hex()} + } + } + return metadata, nil +} + +func (mappings *VowMappings) loadMappings() error { + staticMappings := make(map[common.Hash]shared.StorageValueMetadata) + staticMappings[VatKey] = VatMetadata + staticMappings[CowKey] = CowMetadata + staticMappings[RowKey] = RowMetadata + staticMappings[SinKey] = SinMetadata + staticMappings[AshKey] = AshMetadata + staticMappings[WaitKey] = WaitMetadata + staticMappings[SumpKey] = SumpMetadata + staticMappings[BumpKey] = BumpMetadata + staticMappings[HumpKey] = HumpMetadata + + mappings.mappings = staticMappings + + return nil +} + +func (mappings *VowMappings) SetDB(db *postgres.DB) { + mappings.StorageRepository.SetDB(db) +} diff --git a/pkg/transformers/storage_diffs/maker/vow/mappings_test.go b/pkg/transformers/storage_diffs/maker/vow/mappings_test.go new file mode 100644 index 000000000..df2860805 --- /dev/null +++ b/pkg/transformers/storage_diffs/maker/vow/mappings_test.go @@ -0,0 +1,41 @@ +package vow_test + +import ( + "github.com/ethereum/go-ethereum/common" + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + "github.com/vulcanize/vulcanizedb/pkg/fakes" + "github.com/vulcanize/vulcanizedb/pkg/transformers/storage_diffs/maker/test_helpers" + "github.com/vulcanize/vulcanizedb/pkg/transformers/storage_diffs/maker/vow" + "github.com/vulcanize/vulcanizedb/pkg/transformers/storage_diffs/shared" +) + +var _ = Describe("Vow storage mappings", func() { + Describe("looking up static keys", func() { + It("returns value metadata if key exists", func() { + storageRepository := &test_helpers.MockMakerStorageRepository{} + + mappings := vow.VowMappings{StorageRepository: storageRepository} + + Expect(mappings.Lookup(vow.VatKey)).To(Equal(vow.VatMetadata)) + 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.AshKey)).To(Equal(vow.AshMetadata)) + Expect(mappings.Lookup(vow.WaitKey)).To(Equal(vow.WaitMetadata)) + Expect(mappings.Lookup(vow.SumpKey)).To(Equal(vow.SumpMetadata)) + Expect(mappings.Lookup(vow.BumpKey)).To(Equal(vow.BumpMetadata)) + Expect(mappings.Lookup(vow.HumpKey)).To(Equal(vow.HumpMetadata)) + }) + + It("returns error if key does not exist", func() { + storageRepository := &test_helpers.MockMakerStorageRepository{} + + mappings := vow.VowMappings{StorageRepository: storageRepository} + _, err := mappings.Lookup(common.HexToHash(fakes.FakeHash.Hex())) + + Expect(err).To(HaveOccurred()) + Expect(err).To(MatchError(shared.ErrStorageKeyNotFound{Key: fakes.FakeHash.Hex()})) + }) + }) +}) diff --git a/pkg/transformers/storage_diffs/maker/vow/repository.go b/pkg/transformers/storage_diffs/maker/vow/repository.go new file mode 100644 index 000000000..d7fdab2e0 --- /dev/null +++ b/pkg/transformers/storage_diffs/maker/vow/repository.go @@ -0,0 +1,45 @@ +/* + * Copyright 2018 Vulcanize + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package vow + +import ( + "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" + "github.com/vulcanize/vulcanizedb/pkg/transformers/storage_diffs/shared" +) + +type VowStorageRepository struct { + db *postgres.DB +} + +func (repository *VowStorageRepository) SetDB(db *postgres.DB) { + repository.db = db +} + +func (repository VowStorageRepository) Create(blockNumber int, blockHash string, metadata shared.StorageValueMetadata, value interface{}) error { + switch metadata.Name { + case VowVat: + return repository.insertVowVat(blockNumber, blockHash, value.(string)) + default: + panic("unrecognized storage metadata name") + } +} + +func (repository VowStorageRepository) insertVowVat(blockNumber int, blockHash string, vat string) error { + _, err := repository.db.Exec(`INSERT INTO maker.vow_vat (block_number, block_hash, vat) VALUES ($1, $2, $3)`, blockNumber, blockHash, vat) + + return err +} diff --git a/pkg/transformers/storage_diffs/maker/vow/repository_test.go b/pkg/transformers/storage_diffs/maker/vow/repository_test.go new file mode 100644 index 000000000..f6bca63e7 --- /dev/null +++ b/pkg/transformers/storage_diffs/maker/vow/repository_test.go @@ -0,0 +1,68 @@ +/* + * Copyright 2018 Vulcanize + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package vow_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/vow" + "github.com/vulcanize/vulcanizedb/test_config" +) + +var _ = Describe("Vow storage repository test", func() { + var ( + blockNumber int + blockHash string + db *postgres.DB + err error + repo vow.VowStorageRepository + ) + + BeforeEach(func() { + blockNumber = 123 + blockHash = "expected_block_hash" + db = test_config.NewTestDB(test_config.NewTestNode()) + test_config.CleanTestDB(db) + repo = vow.VowStorageRepository{} + repo.SetDB(db) + }) + + It("persists a vow vat", func() { + expectedVat := "yo" + + err = repo.Create(blockNumber, blockHash, vow.VatMetadata, expectedVat) + + Expect(err).NotTo(HaveOccurred()) + type VowVat struct { + BlockMetadata + Vat string + } + var result VowVat + err = db.Get(&result, `SELECT block_number, block_hash, vat from maker.vow_vat`) + Expect(err).NotTo(HaveOccurred()) + Expect(result.BlockNumber).To(Equal(blockNumber)) + Expect(result.BlockHash).To(Equal(blockHash)) + Expect(result.Vat).To(Equal(expectedVat)) + }) +}) + +type BlockMetadata struct { + BlockNumber int `db:"block_number"` + BlockHash string `db:"block_hash"` +} diff --git a/pkg/transformers/storage_diffs/maker/vow/vow_suite_test.go b/pkg/transformers/storage_diffs/maker/vow/vow_suite_test.go new file mode 100644 index 000000000..d5f42d1e8 --- /dev/null +++ b/pkg/transformers/storage_diffs/maker/vow/vow_suite_test.go @@ -0,0 +1,13 @@ +package vow_test + +import ( + "testing" + + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" +) + +func TestVow(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "Storage Diff Vow Suite") +} diff --git a/pkg/transformers/storage_diffs/mappings.go b/pkg/transformers/storage_diffs/mappings.go index 32bbe3b82..c3df75558 100644 --- a/pkg/transformers/storage_diffs/mappings.go +++ b/pkg/transformers/storage_diffs/mappings.go @@ -30,14 +30,18 @@ type Mappings interface { } const ( - IndexZero = "0000000000000000000000000000000000000000000000000000000000000000" - IndexOne = "0000000000000000000000000000000000000000000000000000000000000001" - IndexTwo = "0000000000000000000000000000000000000000000000000000000000000002" - IndexThree = "0000000000000000000000000000000000000000000000000000000000000003" - IndexFour = "0000000000000000000000000000000000000000000000000000000000000004" - IndexFive = "0000000000000000000000000000000000000000000000000000000000000005" - IndexSix = "0000000000000000000000000000000000000000000000000000000000000006" - IndexSeven = "0000000000000000000000000000000000000000000000000000000000000007" + IndexZero = "0000000000000000000000000000000000000000000000000000000000000000" + IndexOne = "0000000000000000000000000000000000000000000000000000000000000001" + IndexTwo = "0000000000000000000000000000000000000000000000000000000000000002" + IndexThree = "0000000000000000000000000000000000000000000000000000000000000003" + IndexFour = "0000000000000000000000000000000000000000000000000000000000000004" + IndexFive = "0000000000000000000000000000000000000000000000000000000000000005" + IndexSix = "0000000000000000000000000000000000000000000000000000000000000006" + IndexSeven = "0000000000000000000000000000000000000000000000000000000000000007" + IndexEight = "0000000000000000000000000000000000000000000000000000000000000008" + IndexNine = "0000000000000000000000000000000000000000000000000000000000000009" + IndexTen = "0000000000000000000000000000000000000000000000000000000000000010" + IndexEleven = "0000000000000000000000000000000000000000000000000000000000000011 " ) func GetMapping(indexOnContract, key string) common.Hash { diff --git a/pkg/transformers/storage_transformers.go b/pkg/transformers/storage_transformers.go index b052798eb..a0d80d1dc 100644 --- a/pkg/transformers/storage_transformers.go +++ b/pkg/transformers/storage_transformers.go @@ -7,6 +7,7 @@ import ( "github.com/vulcanize/vulcanizedb/pkg/transformers/storage_diffs/maker" "github.com/vulcanize/vulcanizedb/pkg/transformers/storage_diffs/maker/pit" "github.com/vulcanize/vulcanizedb/pkg/transformers/storage_diffs/maker/vat" + "github.com/vulcanize/vulcanizedb/pkg/transformers/storage_diffs/maker/vow" ) func GetPitStorageTransformer() storage.Transformer { @@ -24,3 +25,11 @@ func GetVatStorageTransformer() storage.Transformer { Repository: &vat.VatStorageRepository{}, } } + +func GetVowStorageTransformer() storage.Transformer { + return storage.Transformer{ + Address: common.HexToAddress(constants.VowContractAddress()), + Mappings: &vow.VowMappings{StorageRepository: &maker.MakerStorageRepository{}}, + Repository: &vow.VowStorageRepository{}, + } +} From cda3bd2eb404a9556b665ecb57b33ce6093a9076 Mon Sep 17 00:00:00 2001 From: Taka Goto Date: Mon, 11 Feb 2019 15:32:38 -0600 Subject: [PATCH 2/5] fix rollback migration --- ...0073_create_vat_contract_storage_tables.sql | 2 +- ...0074_create_vow_contract_storage_tables.sql | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/db/migrations/00073_create_vat_contract_storage_tables.sql b/db/migrations/00073_create_vat_contract_storage_tables.sql index a7ba7da9c..e7402896f 100644 --- a/db/migrations/00073_create_vat_contract_storage_tables.sql +++ b/db/migrations/00073_create_vat_contract_storage_tables.sql @@ -99,4 +99,4 @@ DROP TABLE maker.vat_urn_art; DROP TABLE maker.vat_urn_ink; DROP TABLE maker.vat_gem; DROP TABLE maker.vat_dai; -DROP TABLE maker.vat_sin; \ No newline at end of file +DROP TABLE maker.vat_sin; diff --git a/db/migrations/00074_create_vow_contract_storage_tables.sql b/db/migrations/00074_create_vow_contract_storage_tables.sql index 751ee1e22..c3b21843e 100644 --- a/db/migrations/00074_create_vow_contract_storage_tables.sql +++ b/db/migrations/00074_create_vow_contract_storage_tables.sql @@ -63,12 +63,12 @@ CREATE TABLE maker.vow_hump ( ); -- +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_ash -DROP TABLE maker.vow_wait -DROP TABLE maker.vow_sump -DROP TABLE maker.vow_bump -DROP TABLE maker.vow_hump +DROP TABLE maker.vow_vat; +DROP TABLE maker.vow_cow; +DROP TABLE maker.vow_row; +DROP TABLE maker.vow_sin; +DROP TABLE maker.vow_ash; +DROP TABLE maker.vow_wait; +DROP TABLE maker.vow_sump; +DROP TABLE maker.vow_bump; +DROP TABLE maker.vow_hump; From 4fd839c4276495c351d9b4c88362f426c6d25b86 Mon Sep 17 00:00:00 2001 From: Taka Goto Date: Mon, 11 Feb 2019 16:34:02 -0600 Subject: [PATCH 3/5] repository methods: --- .../storage_diffs/maker/vow/mappings.go | 32 ++-- .../storage_diffs/maker/vow/repository.go | 64 ++++++++ .../maker/vow/repository_test.go | 146 +++++++++++++++++- 3 files changed, 225 insertions(+), 17 deletions(-) diff --git a/pkg/transformers/storage_diffs/maker/vow/mappings.go b/pkg/transformers/storage_diffs/maker/vow/mappings.go index 1c126f0ed..10d39ad04 100644 --- a/pkg/transformers/storage_diffs/maker/vow/mappings.go +++ b/pkg/transformers/storage_diffs/maker/vow/mappings.go @@ -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, } diff --git a/pkg/transformers/storage_diffs/maker/vow/repository.go b/pkg/transformers/storage_diffs/maker/vow/repository.go index d7fdab2e0..92caa87ac 100644 --- a/pkg/transformers/storage_diffs/maker/vow/repository.go +++ b/pkg/transformers/storage_diffs/maker/vow/repository.go @@ -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 +} diff --git a/pkg/transformers/storage_diffs/maker/vow/repository_test.go b/pkg/transformers/storage_diffs/maker/vow/repository_test.go index f6bca63e7..7aac127e3 100644 --- a/pkg/transformers/storage_diffs/maker/vow/repository_test.go +++ b/pkg/transformers/storage_diffs/maker/vow/repository_test.go @@ -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 { From 30cf2ffc560171286e34e2e9c1372428ccf92af7 Mon Sep 17 00:00:00 2001 From: Taka Goto Date: Tue, 12 Feb 2019 21:50:52 -0600 Subject: [PATCH 4/5] add woe to storage diff vow contract --- ...074_create_vow_contract_storage_tables.sql | 20 +++++-- db/schema.sql | 59 +++++++++++++++++-- .../storage_diffs/maker/vow/mappings.go | 13 +++- .../storage_diffs/maker/vow/mappings_test.go | 1 + .../storage_diffs/maker/vow/repository.go | 8 +++ .../maker/vow/repository_test.go | 36 ++++++++--- 6 files changed, 114 insertions(+), 23 deletions(-) diff --git a/db/migrations/00074_create_vow_contract_storage_tables.sql b/db/migrations/00074_create_vow_contract_storage_tables.sql index c3b21843e..2027a599e 100644 --- a/db/migrations/00074_create_vow_contract_storage_tables.sql +++ b/db/migrations/00074_create_vow_contract_storage_tables.sql @@ -24,42 +24,49 @@ 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 @@ -67,6 +74,7 @@ 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; diff --git a/db/schema.sql b/db/schema.sql index 6db1d44e5..46f371181 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -1613,7 +1613,7 @@ CREATE TABLE maker.vow_ash ( id integer NOT NULL, block_number bigint, block_hash text, - ash text + ash numeric ); @@ -1645,7 +1645,7 @@ CREATE TABLE maker.vow_bump ( id integer NOT NULL, block_number bigint, block_hash text, - bump text + bump numeric ); @@ -1743,7 +1743,7 @@ CREATE TABLE maker.vow_hump ( id integer NOT NULL, block_number bigint, block_hash text, - hump text + hump numeric ); @@ -1807,7 +1807,7 @@ CREATE TABLE maker.vow_sin ( id integer NOT NULL, block_number bigint, block_hash text, - sin text + sin numeric ); @@ -1839,7 +1839,7 @@ CREATE TABLE maker.vow_sump ( id integer NOT NULL, block_number bigint, block_hash text, - sump text + sump numeric ); @@ -1903,7 +1903,7 @@ CREATE TABLE maker.vow_wait ( id integer NOT NULL, block_number bigint, block_hash text, - wait text + wait numeric ); @@ -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: - -- @@ -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: - -- @@ -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: - -- diff --git a/pkg/transformers/storage_diffs/maker/vow/mappings.go b/pkg/transformers/storage_diffs/maker/vow/mappings.go index 10d39ad04..d3b4b138d 100644 --- a/pkg/transformers/storage_diffs/maker/vow/mappings.go +++ b/pkg/transformers/storage_diffs/maker/vow/mappings.go @@ -29,6 +29,7 @@ const ( VowCow = "cow" VowRow = "row" VowSin = "Sin" + VowWoe = "woe" VowAsh = "ash" VowWait = "wait" VowSump = "sump" @@ -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) @@ -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, @@ -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 diff --git a/pkg/transformers/storage_diffs/maker/vow/mappings_test.go b/pkg/transformers/storage_diffs/maker/vow/mappings_test.go index df2860805..44c7970fc 100644 --- a/pkg/transformers/storage_diffs/maker/vow/mappings_test.go +++ b/pkg/transformers/storage_diffs/maker/vow/mappings_test.go @@ -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)) diff --git a/pkg/transformers/storage_diffs/maker/vow/repository.go b/pkg/transformers/storage_diffs/maker/vow/repository.go index 92caa87ac..0a655d9a5 100644 --- a/pkg/transformers/storage_diffs/maker/vow/repository.go +++ b/pkg/transformers/storage_diffs/maker/vow/repository.go @@ -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: @@ -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) diff --git a/pkg/transformers/storage_diffs/maker/vow/repository_test.go b/pkg/transformers/storage_diffs/maker/vow/repository_test.go index 7aac127e3..e7540106b 100644 --- a/pkg/transformers/storage_diffs/maker/vow/repository_test.go +++ b/pkg/transformers/storage_diffs/maker/vow/repository_test.go @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) From f7e486ae6d7072b4a865b1173b201c371accf705 Mon Sep 17 00:00:00 2001 From: Taka Goto Date: Fri, 15 Feb 2019 06:15:47 -0600 Subject: [PATCH 5/5] uppercase Woe and Ash --- pkg/transformers/storage_diffs/maker/vow/mappings.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/transformers/storage_diffs/maker/vow/mappings.go b/pkg/transformers/storage_diffs/maker/vow/mappings.go index d3b4b138d..8f9a7d26b 100644 --- a/pkg/transformers/storage_diffs/maker/vow/mappings.go +++ b/pkg/transformers/storage_diffs/maker/vow/mappings.go @@ -29,8 +29,8 @@ const ( VowCow = "cow" VowRow = "row" VowSin = "Sin" - VowWoe = "woe" - VowAsh = "ash" + VowWoe = "Woe" + VowAsh = "Ash" VowWait = "wait" VowSump = "sump" VowBump = "bump"