diff --git a/README.md b/README.md index d182ed47..c6b9a05c 100644 --- a/README.md +++ b/README.md @@ -239,7 +239,8 @@ The addition of '_' after table names is to prevent collisions with reserved Pos ### composeAndExecute The `composeAndExecute` command is used to compose and execute over an arbitrary set of custom transformers. This is accomplished by generating a Go pluggin which allows our `vulcanizedb` binary to link to external transformers, so -long as they abide by our standard [interfaces](https://github.com/vulcanize/maker-vulcanizedb/tree/compose_and_execute/libraries/shared/transformer). +long as they abide by our standard [interfaces](https://github.com/vulcanize/maker-vulcanizedb/tree/compose_and_execute/libraries/shared/transformer). +This command requires Go 1.11+ and [Go plugins](https://golang.org/pkg/plugin/) only work on Unix based systems. #### composeAndExecute configuration A config location is specified when executing the command: diff --git a/db/migrations/20180724233837_create_checked_headers_table.sql b/db/migrations/20180724233837_create_checked_headers_table.sql index 4a7069c3..acf0fbdb 100644 --- a/db/migrations/20180724233837_create_checked_headers_table.sql +++ b/db/migrations/20180724233837_create_checked_headers_table.sql @@ -1,8 +1,7 @@ -- +goose Up CREATE TABLE public.checked_headers ( id SERIAL PRIMARY KEY, - header_id INTEGER UNIQUE NOT NULL REFERENCES headers (id) ON DELETE CASCADE, - price_feeds_checked BOOLEAN NOT NULL DEFAULT FALSE + header_id INTEGER UNIQUE NOT NULL REFERENCES headers (id) ON DELETE CASCADE ); -- +goose Down diff --git a/db/migrations/20180724233838_create_maker_schema.sql b/db/migrations/20180724233838_create_maker_schema.sql deleted file mode 100644 index 2880a0fe..00000000 --- a/db/migrations/20180724233838_create_maker_schema.sql +++ /dev/null @@ -1,6 +0,0 @@ --- +goose Up -CREATE SCHEMA maker; - - --- +goose Down -DROP SCHEMA maker; diff --git a/db/migrations/20180724233839_create_flip_kick.sql b/db/migrations/20180724233839_create_flip_kick.sql deleted file mode 100644 index cb5b9d4d..00000000 --- a/db/migrations/20180724233839_create_flip_kick.sql +++ /dev/null @@ -1,26 +0,0 @@ --- +goose Up -CREATE TABLE maker.flip_kick ( - id SERIAL PRIMARY KEY, - header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE, - bid_id NUMERIC NOT NULL, - lot NUMERIC, - bid NUMERIC, - gal TEXT, - "end" TIMESTAMP WITH TIME ZONE, - urn TEXT, - tab NUMERIC, - tx_idx INTEGER NOT NUll, - log_idx INTEGER NOT NUll, - raw_log JSONB, - UNIQUE (header_id, tx_idx, log_idx) -); - -ALTER TABLE public.checked_headers - ADD COLUMN flip_kick_checked BOOLEAN NOT NULL DEFAULT FALSE; - - --- +goose Down -DROP TABLE maker.flip_kick; - -ALTER TABLE public.checked_headers - DROP COLUMN flip_kick_checked; diff --git a/db/migrations/20180809214844_create_ilks.sql b/db/migrations/20180809214844_create_ilks.sql deleted file mode 100644 index 5eec84cf..00000000 --- a/db/migrations/20180809214844_create_ilks.sql +++ /dev/null @@ -1,8 +0,0 @@ --- +goose Up -CREATE TABLE maker.ilks ( - id SERIAL PRIMARY KEY, - ilk TEXT UNIQUE -); - --- +goose Down -DROP TABLE maker.ilks; diff --git a/db/migrations/20180809214845_create_frob.sql b/db/migrations/20180809214845_create_frob.sql deleted file mode 100644 index a1762fd4..00000000 --- a/db/migrations/20180809214845_create_frob.sql +++ /dev/null @@ -1,26 +0,0 @@ --- +goose Up -CREATE TABLE maker.frob ( - id SERIAL PRIMARY KEY, - header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE, - ilk INTEGER NOT NULL REFERENCES maker.ilks (id), - urn TEXT, - dink NUMERIC, - dart NUMERIC, - ink NUMERIC, - art NUMERIC, - iart NUMERIC, - log_idx INTEGER NOT NUll, - tx_idx INTEGER NOT NUll, - raw_log JSONB, - UNIQUE (header_id, tx_idx, log_idx) -); - -ALTER TABLE public.checked_headers - ADD COLUMN frob_checked BOOLEAN NOT NULL DEFAULT FALSE; - - --- +goose Down -DROP TABLE maker.frob; - -ALTER TABLE public.checked_headers - DROP COLUMN frob_checked; diff --git a/db/migrations/20180814213505_create_price_feeds_table.sql b/db/migrations/20180814213505_create_price_feeds_table.sql deleted file mode 100644 index 10ea48f2..00000000 --- a/db/migrations/20180814213505_create_price_feeds_table.sql +++ /dev/null @@ -1,16 +0,0 @@ --- +goose Up -CREATE TABLE maker.price_feeds ( - id SERIAL PRIMARY KEY, - block_number BIGINT NOT NULL, - header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE, - medianizer_address TEXT, - usd_value NUMERIC, - log_idx INTEGER NOT NULL, - tx_idx INTEGER NOT NULL, - raw_log JSONB, - UNIQUE (header_id, medianizer_address, tx_idx, log_idx) -); - - --- +goose Down -DROP TABLE maker.price_feeds; diff --git a/db/migrations/20180815031512_create_tend.sql b/db/migrations/20180815031512_create_tend.sql deleted file mode 100644 index 85df5505..00000000 --- a/db/migrations/20180815031512_create_tend.sql +++ /dev/null @@ -1,24 +0,0 @@ --- +goose Up -CREATE TABLE maker.tend ( - id SERIAL PRIMARY KEY, - header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE, - bid_id NUMERIC NOT NULL, - lot NUMERIC, - bid NUMERIC, - guy TEXT, - tic NUMERIC, - log_idx INTEGER NOT NUll, - tx_idx INTEGER NOT NUll, - raw_log JSONB, - UNIQUE (header_id, tx_idx, log_idx) -); - -ALTER TABLE public.checked_headers - ADD COLUMN tend_checked BOOLEAN NOT NULL DEFAULT FALSE; - - --- +goose Down -DROP TABLE maker.tend; - -ALTER TABLE public.checked_headers - DROP COLUMN tend_checked; diff --git a/db/migrations/20180815031513_create_bite.sql b/db/migrations/20180815031513_create_bite.sql deleted file mode 100644 index 7af6f109..00000000 --- a/db/migrations/20180815031513_create_bite.sql +++ /dev/null @@ -1,26 +0,0 @@ --- +goose Up -CREATE TABLE maker.bite ( - id SERIAL PRIMARY KEY, - header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE, - ilk INTEGER NOT NULL REFERENCES maker.ilks (id), - urn TEXT, - ink NUMERIC, - art NUMERIC, - iArt NUMERIC, - tab NUMERIC, - nflip NUMERIC, - tx_idx INTEGER NOT NUll, - log_idx INTEGER NOT NUll, - raw_log JSONB, - UNIQUE (header_id, tx_idx, log_idx) -); - -ALTER TABLE public.checked_headers - ADD COLUMN bite_checked BOOLEAN NOT NULL DEFAULT FALSE; - - --- +goose Down -DROP TABLE maker.bite; - -ALTER TABLE public.checked_headers - DROP COLUMN bite_checked; diff --git a/db/migrations/20180820230607_create_dent.sql b/db/migrations/20180820230607_create_dent.sql deleted file mode 100644 index a0179aa4..00000000 --- a/db/migrations/20180820230607_create_dent.sql +++ /dev/null @@ -1,24 +0,0 @@ --- +goose Up -CREATE TABLE maker.dent ( - id SERIAL PRIMARY KEY, - header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE, - bid_id NUMERIC NOT NULL, - lot NUMERIC, - bid NUMERIC, - guy BYTEA, - tic NUMERIC, - log_idx INTEGER NOT NUll, - tx_idx INTEGER NOT NUll, - raw_log JSONB, - UNIQUE (header_id, tx_idx, log_idx) -); - -ALTER TABLE public.checked_headers - ADD COLUMN dent_checked BOOLEAN NOT NULL DEFAULT FALSE; - - --- +goose Down -DROP TABLE maker.dent; - -ALTER TABLE public.checked_headers - DROP COLUMN dent_checked; \ No newline at end of file diff --git a/db/migrations/20180831002535_create_pit_file.sql b/db/migrations/20180831002535_create_pit_file.sql deleted file mode 100644 index a1be6c5d..00000000 --- a/db/migrations/20180831002535_create_pit_file.sql +++ /dev/null @@ -1,58 +0,0 @@ --- +goose Up -CREATE TABLE maker.pit_file_ilk ( - id SERIAL PRIMARY KEY, - header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE, - ilk INTEGER NOT NULL REFERENCES maker.ilks (id), - what TEXT, - data NUMERIC, - log_idx INTEGER NOT NUll, - tx_idx INTEGER NOT NUll, - raw_log JSONB, - UNIQUE (header_id, tx_idx, log_idx) -); - -CREATE TABLE maker.pit_file_stability_fee ( - id SERIAL PRIMARY KEY, - header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE, - what TEXT, - data TEXT, - log_idx INTEGER NOT NULL, - tx_idx INTEGER NOT NULL, - raw_log JSONB, - UNIQUE (header_id, tx_idx, log_idx) -); - -CREATE TABLE maker.pit_file_debt_ceiling ( - id SERIAL PRIMARY KEY, - header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE, - what TEXT, - data NUMERIC, - log_idx INTEGER NOT NULL, - tx_idx INTEGER NOT NULL, - raw_log JSONB, - UNIQUE (header_id, tx_idx, log_idx) -); - -ALTER TABLE public.checked_headers - ADD COLUMN pit_file_debt_ceiling_checked BOOLEAN NOT NULL DEFAULT FALSE; - -ALTER TABLE public.checked_headers - ADD COLUMN pit_file_ilk_checked BOOLEAN NOT NULL DEFAULT FALSE; - -ALTER TABLE public.checked_headers - ADD COLUMN pit_file_stability_fee_checked BOOLEAN NOT NULL DEFAULT FALSE; - - --- +goose Down -DROP TABLE maker.pit_file_ilk; -DROP TABLE maker.pit_file_stability_fee; -DROP TABLE maker.pit_file_debt_ceiling; - -ALTER TABLE public.checked_headers - DROP COLUMN pit_file_debt_ceiling_checked; - -ALTER TABLE public.checked_headers - DROP COLUMN pit_file_ilk_checked; - -ALTER TABLE public.checked_headers - DROP COLUMN pit_file_stability_fee_checked; diff --git a/db/migrations/20180906225956_create_vat_init.sql b/db/migrations/20180906225956_create_vat_init.sql deleted file mode 100644 index 6fef3347..00000000 --- a/db/migrations/20180906225956_create_vat_init.sql +++ /dev/null @@ -1,20 +0,0 @@ --- +goose Up -CREATE TABLE maker.vat_init ( - id SERIAL PRIMARY KEY, - header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE, - ilk INTEGER NOT NULL REFERENCES maker.ilks (id), - log_idx INTEGER NOT NUll, - tx_idx INTEGER NOT NUll, - raw_log JSONB, - UNIQUE (header_id, tx_idx, log_idx) -); - -ALTER TABLE public.checked_headers - ADD COLUMN vat_init_checked BOOLEAN NOT NULL DEFAULT FALSE; - - --- +goose Down -DROP TABLE maker.vat_init; - -ALTER TABLE public.checked_headers - DROP COLUMN vat_init_checked; \ No newline at end of file diff --git a/db/migrations/20180910202607_create_drip_file.sql b/db/migrations/20180910202607_create_drip_file.sql deleted file mode 100644 index 9255c407..00000000 --- a/db/migrations/20180910202607_create_drip_file.sql +++ /dev/null @@ -1,58 +0,0 @@ --- +goose Up -CREATE TABLE maker.drip_file_ilk ( - id SERIAL PRIMARY KEY, - header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE, - ilk INTEGER NOT NULL REFERENCES maker.ilks (id), - vow TEXT, - tax NUMERIC, - log_idx INTEGER NOT NUll, - tx_idx INTEGER NOT NUll, - raw_log JSONB, - UNIQUE (header_id, tx_idx, log_idx) -); - -CREATE TABLE maker.drip_file_repo ( - id SERIAL PRIMARY KEY, - header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE, - what TEXT, - data NUMERIC, - log_idx INTEGER NOT NULL, - tx_idx INTEGER NOT NULL, - raw_log JSONB, - UNIQUE (header_id, tx_idx, log_idx) -); - -CREATE TABLE maker.drip_file_vow ( - id SERIAL PRIMARY KEY, - header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE, - what TEXT, - data TEXT, - log_idx INTEGER NOT NULL, - tx_idx INTEGER NOT NULL, - raw_log JSONB, - UNIQUE (header_id, tx_idx, log_idx) -); - -ALTER TABLE public.checked_headers - ADD COLUMN drip_file_ilk_checked BOOLEAN NOT NULL DEFAULT FALSE; - -ALTER TABLE public.checked_headers - ADD COLUMN drip_file_repo_checked BOOLEAN NOT NULL DEFAULT FALSE; - -ALTER TABLE public.checked_headers - ADD COLUMN drip_file_vow_checked BOOLEAN NOT NULL DEFAULT FALSE; - - --- +goose Down -DROP TABLE maker.drip_file_ilk; -DROP TABLE maker.drip_file_repo; -DROP TABLE maker.drip_file_vow; - -ALTER TABLE public.checked_headers - DROP COLUMN drip_file_ilk_checked; - -ALTER TABLE public.checked_headers - DROP COLUMN drip_file_repo_checked; - -ALTER TABLE public.checked_headers - DROP COLUMN drip_file_vow_checked; diff --git a/db/migrations/20180910233720_create_deal.sql b/db/migrations/20180910233720_create_deal.sql deleted file mode 100644 index 4d8ec2c4..00000000 --- a/db/migrations/20180910233720_create_deal.sql +++ /dev/null @@ -1,20 +0,0 @@ --- +goose Up -CREATE TABLE maker.deal ( - id SERIAL PRIMARY KEY, - header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE, - bid_id NUMERIC NOT NULL, - contract_address VARCHAR, - log_idx INTEGER NOT NUll, - tx_idx INTEGER NOT NUll, - raw_log JSONB, - UNIQUE (header_id, tx_idx, log_idx) -); - -ALTER TABLE public.checked_headers - ADD COLUMN deal_checked BOOLEAN NOT NULL DEFAULT FALSE; - --- +goose Down -DROP TABLE maker.deal; - -ALTER TABLE public.checked_headers - DROP COLUMN deal_checked; diff --git a/db/migrations/20180911235603_add_price_feed_trigger.sql b/db/migrations/20180911235603_add_price_feed_trigger.sql deleted file mode 100644 index b3bf0d2b..00000000 --- a/db/migrations/20180911235603_add_price_feed_trigger.sql +++ /dev/null @@ -1,21 +0,0 @@ --- +goose Up --- +goose StatementBegin -CREATE OR REPLACE FUNCTION notify_pricefeed() RETURNS trigger AS $$ -BEGIN - PERFORM pg_notify( - CAST('postgraphile:price_feed' AS text), - json_build_object('__node__', json_build_array('price_feeds', NEW.id))::text - ); - RETURN NEW; -END; -$$ LANGUAGE plpgsql; --- +goose StatementEnd - -CREATE TRIGGER notify_pricefeeds - AFTER INSERT ON maker.price_feeds - FOR EACH ROW - EXECUTE PROCEDURE notify_pricefeed(); - - --- +goose Down -DROP TRIGGER notify_pricefeeds ON maker.price_feeds; diff --git a/db/migrations/20180912015839_create_drip_drip.sql b/db/migrations/20180912015839_create_drip_drip.sql deleted file mode 100644 index 241dd088..00000000 --- a/db/migrations/20180912015839_create_drip_drip.sql +++ /dev/null @@ -1,20 +0,0 @@ --- +goose Up -CREATE TABLE maker.drip_drip ( - id SERIAL PRIMARY KEY, - header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE, - ilk INTEGER NOT NULL REFERENCES maker.ilks (id), - log_idx INTEGER NOT NUll, - tx_idx INTEGER NOT NUll, - raw_log JSONB, - UNIQUE (header_id, tx_idx, log_idx) -); - -ALTER TABLE public.checked_headers - ADD COLUMN drip_drip_checked BOOLEAN NOT NULL DEFAULT FALSE; - - --- +goose Down -DROP TABLE maker.drip_drip; - -ALTER TABLE public.checked_headers - DROP COLUMN drip_drip_checked; diff --git a/db/migrations/20180912171047_create_cat_file.sql b/db/migrations/20180912171047_create_cat_file.sql deleted file mode 100644 index d47dec9b..00000000 --- a/db/migrations/20180912171047_create_cat_file.sql +++ /dev/null @@ -1,59 +0,0 @@ --- +goose Up -CREATE TABLE maker.cat_file_chop_lump ( - id SERIAL PRIMARY KEY, - header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE, - ilk INTEGER NOT NULL REFERENCES maker.ilks (id), - what TEXT, - data NUMERIC, - tx_idx INTEGER NOT NUll, - log_idx INTEGER NOT NULL, - raw_log JSONB, - UNIQUE (header_id, tx_idx, log_idx) -); - -CREATE TABLE maker.cat_file_flip ( - id SERIAL PRIMARY KEY, - header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE, - ilk TEXT, - what TEXT, - flip TEXT, - tx_idx INTEGER NOT NUll, - log_idx INTEGER NOT NULL, - raw_log JSONB, - UNIQUE (header_id, tx_idx, log_idx) -); - -CREATE TABLE maker.cat_file_pit_vow ( - id SERIAL PRIMARY KEY, - header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE, - what TEXT, - data TEXT, - tx_idx INTEGER NOT NUll, - log_idx INTEGER NOT NULL, - raw_log JSONB, - UNIQUE (header_id, tx_idx, log_idx) -); - -ALTER TABLE public.checked_headers - ADD COLUMN cat_file_chop_lump_checked BOOLEAN NOT NULL DEFAULT FALSE; - -ALTER TABLE public.checked_headers - ADD COLUMN cat_file_flip_checked BOOLEAN NOT NULL DEFAULT FALSE; - -ALTER TABLE public.checked_headers - ADD COLUMN cat_file_pit_vow_checked BOOLEAN NOT NULL DEFAULT FALSE; - - --- +goose Down -DROP TABLE maker.cat_file_chop_lump; -DROP TABLE maker.cat_file_flip; -DROP TABLE maker.cat_file_pit_vow; - -ALTER TABLE public.checked_headers - DROP COLUMN cat_file_chop_lump_checked; - -ALTER TABLE public.checked_headers - DROP COLUMN cat_file_flip_checked; - -ALTER TABLE public.checked_headers - DROP COLUMN cat_file_pit_vow_checked; diff --git a/db/migrations/20180914182849_create_flop_kick.sql b/db/migrations/20180914182849_create_flop_kick.sql deleted file mode 100644 index ff46654c..00000000 --- a/db/migrations/20180914182849_create_flop_kick.sql +++ /dev/null @@ -1,23 +0,0 @@ --- +goose Up -CREATE TABLE maker.flop_kick ( - id SERIAL PRIMARY KEY, - header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE, - bid_id NUMERIC NOT NULL, - lot NUMERIC NOT NULL, - bid NUMERIC NOT NULL, - gal TEXT, - "end" TIMESTAMP WITH TIME ZONE, - tx_idx INTEGER NOT NULL, - log_idx INTEGER NOT NULL, - raw_log JSONB, - UNIQUE (header_id, tx_idx, log_idx) -); - -ALTER TABLE public.checked_headers - ADD COLUMN flop_kick_checked BOOLEAN NOT NULL DEFAULT FALSE; - - --- +goose Down -DROP TABLE maker.flop_kick; -ALTER TABLE public.checked_headers - DROP COLUMN flop_kick_checked; diff --git a/db/migrations/20181001142655_create_vat_move.sql b/db/migrations/20181001142655_create_vat_move.sql deleted file mode 100644 index 4f156233..00000000 --- a/db/migrations/20181001142655_create_vat_move.sql +++ /dev/null @@ -1,21 +0,0 @@ --- +goose Up -CREATE TABLE maker.vat_move ( - id SERIAL PRIMARY KEY, - header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE, - src TEXT NOT NULL, - dst TEXT NOT NULL, - rad NUMERIC NOT NULL, - log_idx INTEGER NOT NULL, - tx_idx INTEGER NOT NULL, - raw_log JSONB, - UNIQUE (header_id, tx_idx, log_idx) -); - -ALTER TABLE public.checked_headers - ADD COLUMN vat_move_checked BOOLEAN NOT NULL DEFAULT FALSE; - - --- +goose Down -DROP TABLE maker.vat_move; -ALTER TABLE public.checked_headers - DROP COLUMN vat_move_checked; diff --git a/db/migrations/20181002220302_create_vat_fold_table.sql b/db/migrations/20181002220302_create_vat_fold_table.sql deleted file mode 100644 index bd661e21..00000000 --- a/db/migrations/20181002220302_create_vat_fold_table.sql +++ /dev/null @@ -1,21 +0,0 @@ --- +goose Up -CREATE TABLE maker.vat_fold ( - id SERIAL PRIMARY KEY, - header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE, - ilk INTEGER NOT NULL REFERENCES maker.ilks (id), - urn TEXT, - rate NUMERIC, - log_idx INTEGER NOT NULL, - tx_idx INTEGER NOT NULL, - raw_log JSONB, - UNIQUE (header_id, tx_idx, log_idx) -); - -ALTER TABLE public.checked_headers - ADD COLUMN vat_fold_checked BOOLEAN NOT NULL DEFAULT FALSE; - - --- +goose Down -DROP TABLE maker.vat_fold; -ALTER TABLE public.checked_headers - DROP COLUMN vat_fold_checked; diff --git a/db/migrations/20181004184028_create_vat_heal.sql b/db/migrations/20181004184028_create_vat_heal.sql deleted file mode 100644 index a5524b4f..00000000 --- a/db/migrations/20181004184028_create_vat_heal.sql +++ /dev/null @@ -1,21 +0,0 @@ --- +goose Up -CREATE TABLE maker.vat_heal ( - id SERIAL PRIMARY KEY, - header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE, - urn TEXT, - v TEXT, - rad NUMERIC, - log_idx INTEGER NOT NULL, - tx_idx INTEGER NOT NULL, - raw_log JSONB, - UNIQUE (header_id, tx_idx, log_idx) -); - -ALTER TABLE public.checked_headers - ADD COLUMN vat_heal_checked BOOLEAN NOT NULL DEFAULT FALSE; - - --- +goose Down -DROP TABLE maker.vat_heal; -ALTER TABLE public.checked_headers - DROP COLUMN vat_heal_checked; diff --git a/db/migrations/20181004205815_create_vat_toll.sql b/db/migrations/20181004205815_create_vat_toll.sql deleted file mode 100644 index c838254e..00000000 --- a/db/migrations/20181004205815_create_vat_toll.sql +++ /dev/null @@ -1,21 +0,0 @@ --- +goose Up -CREATE TABLE maker.vat_toll ( - id SERIAL PRIMARY KEY, - header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE, - ilk INTEGER NOT NULL REFERENCES maker.ilks (id), - urn TEXT, - take NUMERIC, - tx_idx INTEGER NOT NULL, - log_idx INTEGER NOT NULL, - raw_log JSONB, - UNIQUE (header_id, tx_idx, log_idx) -); - -ALTER TABLE public.checked_headers - ADD COLUMN vat_toll_checked BOOLEAN NOT NULL DEFAULT FALSE; - - --- +goose Down -DROP TABLE maker.vat_toll; -ALTER TABLE public.checked_headers - DROP COLUMN vat_toll_checked; diff --git a/db/migrations/20181004233804_create_vat_tune.sql b/db/migrations/20181004233804_create_vat_tune.sql deleted file mode 100644 index 60cc3b54..00000000 --- a/db/migrations/20181004233804_create_vat_tune.sql +++ /dev/null @@ -1,24 +0,0 @@ --- +goose Up -CREATE TABLE maker.vat_tune ( - id SERIAL PRIMARY KEY, - header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE, - ilk INTEGER NOT NULL REFERENCES maker.ilks (id), - urn TEXT, - v TEXT, - w TEXT, - dink NUMERIC, - dart NUMERIC, - tx_idx INTEGER NOT NULL, - log_idx INTEGER NOT NULL, - raw_log JSONB, - UNIQUE (header_id, tx_idx, log_idx) -); - -ALTER TABLE public.checked_headers - ADD COLUMN vat_tune_checked BOOLEAN NOT NULL DEFAULT FALSE; - - --- +goose Down -DROP TABLE maker.vat_tune; -ALTER TABLE public.checked_headers - DROP COLUMN vat_tune_checked; diff --git a/db/migrations/20181008232020_create_vat_grab.sql b/db/migrations/20181008232020_create_vat_grab.sql deleted file mode 100644 index b222aa05..00000000 --- a/db/migrations/20181008232020_create_vat_grab.sql +++ /dev/null @@ -1,24 +0,0 @@ --- +goose Up -CREATE TABLE maker.vat_grab ( - id SERIAL PRIMARY KEY, - header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE, - ilk INTEGER NOT NULL REFERENCES maker.ilks (id), - urn TEXT, - v TEXT, - w TEXT, - dink NUMERIC, - dart NUMERIC, - log_idx INTEGER NOT NULL, - tx_idx INTEGER NOT NULL, - raw_log JSONB, - UNIQUE (header_id, tx_idx, log_idx) -); - -ALTER TABLE public.checked_headers - ADD COLUMN vat_grab_checked BOOLEAN NOT NULL DEFAULT FALSE; - - --- +goose Down -DROP TABLE maker.vat_grab; -ALTER TABLE public.checked_headers - DROP COLUMN vat_grab_checked; diff --git a/db/migrations/20181011184449_create_vat_flux_table.sql b/db/migrations/20181011184449_create_vat_flux_table.sql deleted file mode 100644 index 5fe48321..00000000 --- a/db/migrations/20181011184449_create_vat_flux_table.sql +++ /dev/null @@ -1,22 +0,0 @@ --- +goose Up -CREATE TABLE maker.vat_flux ( - id SERIAL PRIMARY KEY, - header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE, - ilk INTEGER NOT NULL REFERENCES maker.ilks (id), - src TEXT, - dst TEXT, - rad numeric, - tx_idx INTEGER NOT NULL, - log_idx INTEGER NOT NULL, - raw_log JSONB, - UNIQUE (header_id, tx_idx, log_idx) -); - -ALTER TABLE public.checked_headers - ADD COLUMN vat_flux_checked BOOLEAN NOT NULL DEFAULT FALSE; - - --- +goose Down -DROP TABLE maker.vat_flux; -ALTER TABLE public.checked_headers - DROP COLUMN vat_flux_checked; diff --git a/db/migrations/20181015231509_create_vat_slip.sql b/db/migrations/20181015231509_create_vat_slip.sql deleted file mode 100644 index 3694db52..00000000 --- a/db/migrations/20181015231509_create_vat_slip.sql +++ /dev/null @@ -1,21 +0,0 @@ --- +goose Up -CREATE TABLE maker.vat_slip ( - id SERIAL PRIMARY KEY, - header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE, - ilk INTEGER NOT NULL REFERENCES maker.ilks (id), - guy TEXT, - rad NUMERIC, - tx_idx INTEGER NOT NULL, - log_idx INTEGER NOT NULL, - raw_log JSONB, - UNIQUE (header_id, tx_idx, log_idx) -); - -ALTER TABLE public.checked_headers - ADD COLUMN vat_slip_checked BOOLEAN NOT NULL DEFAULT FALSE; - - --- +goose Down -DROP TABLE maker.vat_slip; -ALTER TABLE public.checked_headers - DROP COLUMN vat_slip_checked; diff --git a/db/migrations/20181023141856_create_vow_flog.sql b/db/migrations/20181023141856_create_vow_flog.sql deleted file mode 100644 index af429cca..00000000 --- a/db/migrations/20181023141856_create_vow_flog.sql +++ /dev/null @@ -1,19 +0,0 @@ --- +goose Up -CREATE TABLE maker.vow_flog ( - id SERIAL PRIMARY KEY, - header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE, - era INTEGER NOT NULL, - log_idx INTEGER NOT NULL, - tx_idx INTEGER NOT NULL, - raw_log JSONB, - UNIQUE (header_id, tx_idx, log_idx) -); - -ALTER TABLE public.checked_headers - ADD COLUMN vow_flog_checked BOOLEAN NOT NULL DEFAULT FALSE; - - --- +goose Down -DROP TABLE maker.vow_flog; -ALTER TABLE public.checked_headers - DROP COLUMN vow_flog_checked; diff --git a/db/migrations/20181106183140_create_flap_kick.sql b/db/migrations/20181106183140_create_flap_kick.sql deleted file mode 100644 index 71410fe4..00000000 --- a/db/migrations/20181106183140_create_flap_kick.sql +++ /dev/null @@ -1,23 +0,0 @@ --- +goose Up -CREATE TABLE maker.flap_kick ( - id SERIAL PRIMARY KEY, - header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE, - bid_id NUMERIC NOT NULL, - lot NUMERIC NOT NULL, - bid NUMERIC NOT NULL, - gal TEXT, - "end" TIMESTAMP WITH TIME ZONE, - tx_idx INTEGER NOT NULL, - log_idx INTEGER NOT NULL, - raw_log JSONB, - UNIQUE (header_id, tx_idx, log_idx) -); - -ALTER TABLE public.checked_headers - ADD COLUMN flap_kick_checked BOOLEAN NOT NULL DEFAULT FALSE; - - --- +goose Down -DROP TABLE maker.flap_kick; -ALTER TABLE public.checked_headers - DROP COLUMN flap_kick_checked; diff --git a/db/migrations/20181114200128_drop_pit_file_stability_fee.sql b/db/migrations/20181114200128_drop_pit_file_stability_fee.sql deleted file mode 100644 index 208be543..00000000 --- a/db/migrations/20181114200128_drop_pit_file_stability_fee.sql +++ /dev/null @@ -1,21 +0,0 @@ --- +goose Up -DROP TABLE maker.pit_file_stability_fee; - -ALTER TABLE public.checked_headers - DROP COLUMN pit_file_stability_fee_checked; - - --- +goose Down -CREATE TABLE maker.pit_file_stability_fee ( - id SERIAL PRIMARY KEY, - header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE, - what TEXT, - data TEXT, - log_idx INTEGER NOT NULL, - tx_idx INTEGER NOT NULL, - raw_log JSONB, - UNIQUE (header_id, tx_idx, log_idx) -); - -ALTER TABLE public.checked_headers - ADD COLUMN pit_file_stability_fee_checked BOOLEAN NOT NULL DEFAULT FALSE; diff --git a/db/migrations/20181114200129_create_pit_contract_storage_tables.sql b/db/migrations/20181114200129_create_pit_contract_storage_tables.sql deleted file mode 100644 index a3e54d47..00000000 --- a/db/migrations/20181114200129_create_pit_contract_storage_tables.sql +++ /dev/null @@ -1,52 +0,0 @@ --- +goose Up -CREATE TABLE maker.pit_drip ( - id SERIAL PRIMARY KEY, - block_number BIGINT, - block_hash TEXT, - drip TEXT -); - -CREATE TABLE maker.pit_ilk_spot ( - id SERIAL PRIMARY KEY, - block_number BIGINT, - block_hash TEXT, - ilk INTEGER NOT NULL REFERENCES maker.ilks (id), - spot NUMERIC NOT NULL -); - -CREATE TABLE maker.pit_ilk_line ( - id SERIAL PRIMARY KEY, - block_number BIGINT, - block_hash TEXT, - ilk INTEGER NOT NULL REFERENCES maker.ilks (id), - line NUMERIC NOT NULL -); - -CREATE TABLE maker.pit_line ( - id SERIAL PRIMARY KEY, - block_number BIGINT, - block_hash TEXT, - line NUMERIC NOT NULL -); - -CREATE TABLE maker.pit_live ( - id SERIAL PRIMARY KEY, - block_number BIGINT, - block_hash TEXT, - live NUMERIC NOT NULL -); - -CREATE TABLE maker.pit_vat ( - id SERIAL PRIMARY KEY, - block_number BIGINT, - block_hash TEXT, - vat TEXT -); - --- +goose Down -DROP TABLE maker.pit_drip; -DROP TABLE maker.pit_ilk_spot; -DROP TABLE maker.pit_ilk_line; -DROP TABLE maker.pit_line; -DROP TABLE maker.pit_live; -DROP TABLE maker.pit_vat; \ No newline at end of file diff --git a/db/migrations/20181114200130_change_checked_headers_headers_table_type_int.sql b/db/migrations/20181114200130_change_checked_headers_headers_table_type_int.sql deleted file mode 100644 index af9fa93f..00000000 --- a/db/migrations/20181114200130_change_checked_headers_headers_table_type_int.sql +++ /dev/null @@ -1,175 +0,0 @@ --- +goose Up -ALTER TABLE checked_headers - ALTER price_feeds_checked SET DEFAULT null, - ALTER flip_kick_checked SET DEFAULT null, - ALTER frob_checked SET DEFAULT null, - ALTER tend_checked SET DEFAULT null, - ALTER bite_checked SET DEFAULT null, - ALTER dent_checked SET DEFAULT null, - ALTER pit_file_debt_ceiling_checked SET DEFAULT null, - ALTER pit_file_ilk_checked SET DEFAULT null, - ALTER vat_init_checked SET DEFAULT null, - ALTER drip_file_ilk_checked SET DEFAULT null, - ALTER drip_file_repo_checked SET DEFAULT null, - ALTER drip_file_vow_checked SET DEFAULT null, - ALTER deal_checked SET DEFAULT null, - ALTER drip_drip_checked SET DEFAULT null, - ALTER cat_file_chop_lump_checked SET DEFAULT null, - ALTER cat_file_flip_checked SET DEFAULT null, - ALTER cat_file_pit_vow_checked SET DEFAULT null, - ALTER flop_kick_checked SET DEFAULT null, - ALTER vat_move_checked SET DEFAULT null, - ALTER vat_fold_checked SET DEFAULT null, - ALTER vat_heal_checked SET DEFAULT null, - ALTER vat_toll_checked SET DEFAULT null, - ALTER vat_tune_checked SET DEFAULT null, - ALTER vat_grab_checked SET DEFAULT null, - ALTER vat_flux_checked SET DEFAULT null, - ALTER vat_slip_checked SET DEFAULT null, - ALTER vow_flog_checked SET DEFAULT null, - ALTER flap_kick_checked SET DEFAULT null; - -ALTER TABLE checked_headers - ALTER COLUMN price_feeds_checked TYPE integer USING CASE WHEN false THEN 0 ELSE 1 END, - ALTER price_feeds_checked SET DEFAULT 0, - ALTER COLUMN flip_kick_checked TYPE integer USING CASE WHEN false THEN 0 ELSE 1 END, - ALTER flip_kick_checked SET DEFAULT 0, - ALTER COLUMN frob_checked TYPE integer USING CASE WHEN false THEN 0 ELSE 1 END, - ALTER frob_checked SET DEFAULT 0, - ALTER COLUMN tend_checked TYPE integer USING CASE WHEN false THEN 0 ELSE 1 END, - ALTER tend_checked SET DEFAULT 0, - ALTER COLUMN bite_checked TYPE integer USING CASE WHEN false THEN 0 ELSE 1 END, - ALTER bite_checked SET DEFAULT 0, - ALTER COLUMN dent_checked TYPE integer USING CASE WHEN false THEN 0 ELSE 1 END, - ALTER dent_checked SET DEFAULT 0, - ALTER COLUMN pit_file_debt_ceiling_checked TYPE integer USING CASE WHEN false THEN 0 ELSE 1 END, - ALTER pit_file_debt_ceiling_checked SET DEFAULT 0, - ALTER COLUMN pit_file_ilk_checked TYPE integer USING CASE WHEN false THEN 0 ELSE 1 END, - ALTER pit_file_ilk_checked SET DEFAULT 0, - ALTER COLUMN vat_init_checked TYPE integer USING CASE WHEN false THEN 0 ELSE 1 END, - ALTER vat_init_checked SET DEFAULT 0, - ALTER COLUMN drip_file_ilk_checked TYPE integer USING CASE WHEN false THEN 0 ELSE 1 END, - ALTER drip_file_ilk_checked SET DEFAULT 0, - ALTER COLUMN drip_file_repo_checked TYPE integer USING CASE WHEN false THEN 0 ELSE 1 END, - ALTER drip_file_repo_checked SET DEFAULT 0, - ALTER COLUMN drip_file_vow_checked TYPE integer USING CASE WHEN false THEN 0 ELSE 1 END, - ALTER drip_file_vow_checked SET DEFAULT 0, - ALTER COLUMN deal_checked TYPE integer USING CASE WHEN false THEN 0 ELSE 1 END, - ALTER deal_checked SET DEFAULT 0, - ALTER COLUMN drip_drip_checked TYPE integer USING CASE WHEN false THEN 0 ELSE 1 END, - ALTER drip_drip_checked SET DEFAULT 0, - ALTER COLUMN cat_file_chop_lump_checked TYPE integer USING CASE WHEN false THEN 0 ELSE 1 END, - ALTER cat_file_chop_lump_checked SET DEFAULT 0, - ALTER COLUMN cat_file_flip_checked TYPE integer USING CASE WHEN false THEN 0 ELSE 1 END, - ALTER cat_file_flip_checked SET DEFAULT 0, - ALTER COLUMN cat_file_pit_vow_checked TYPE integer USING CASE WHEN false THEN 0 ELSE 1 END, - ALTER cat_file_pit_vow_checked SET DEFAULT 0, - ALTER COLUMN flop_kick_checked TYPE integer USING CASE WHEN false THEN 0 ELSE 1 END, - ALTER flop_kick_checked SET DEFAULT 0, - ALTER COLUMN vat_move_checked TYPE integer USING CASE WHEN false THEN 0 ELSE 1 END, - ALTER vat_move_checked SET DEFAULT 0, - ALTER COLUMN vat_fold_checked TYPE integer USING CASE WHEN false THEN 0 ELSE 1 END, - ALTER vat_fold_checked SET DEFAULT 0, - ALTER COLUMN vat_heal_checked TYPE integer USING CASE WHEN false THEN 0 ELSE 1 END, - ALTER vat_heal_checked SET DEFAULT 0, - ALTER COLUMN vat_toll_checked TYPE integer USING CASE WHEN false THEN 0 ELSE 1 END, - ALTER vat_toll_checked SET DEFAULT 0, - ALTER COLUMN vat_tune_checked TYPE integer USING CASE WHEN false THEN 0 ELSE 1 END, - ALTER vat_tune_checked SET DEFAULT 0, - ALTER COLUMN vat_grab_checked TYPE integer USING CASE WHEN false THEN 0 ELSE 1 END, - ALTER vat_grab_checked SET DEFAULT 0, - ALTER COLUMN vat_flux_checked TYPE integer USING CASE WHEN false THEN 0 ELSE 1 END, - ALTER vat_flux_checked SET DEFAULT 0, - ALTER COLUMN vat_slip_checked TYPE integer USING CASE WHEN false THEN 0 ELSE 1 END, - ALTER vat_slip_checked SET DEFAULT 0, - ALTER COLUMN vow_flog_checked TYPE integer USING CASE WHEN false THEN 0 ELSE 1 END, - ALTER vow_flog_checked SET DEFAULT 0, - ALTER COLUMN flap_kick_checked TYPE integer USING CASE WHEN false THEN 0 ELSE 1 END, - ALTER flap_kick_checked SET DEFAULT 0; - --- +goose Down -ALTER TABLE checked_headers - ALTER price_feeds_checked drop default, - ALTER COLUMN price_feeds_checked SET DATA TYPE boolean USING CASE WHEN price_feeds_checked = 0 THEN FALSE ELSE TRUE END, - ALTER price_feeds_checked SET DEFAULT FALSE, - ALTER flip_kick_checked drop default, - ALTER COLUMN flip_kick_checked SET DATA TYPE boolean USING CASE WHEN flip_kick_checked = 0 THEN FALSE ELSE TRUE END, - ALTER flip_kick_checked SET DEFAULT FALSE, - ALTER frob_checked drop default, - ALTER COLUMN frob_checked SET DATA TYPE boolean USING CASE WHEN frob_checked = 0 THEN FALSE ELSE TRUE END, - ALTER frob_checked SET DEFAULT FALSE, - ALTER tend_checked drop default, - ALTER COLUMN tend_checked SET DATA TYPE boolean USING CASE WHEN tend_checked = 0 THEN FALSE ELSE TRUE END, - ALTER tend_checked SET DEFAULT FALSE, - ALTER bite_checked drop default, - ALTER COLUMN bite_checked SET DATA TYPE boolean USING CASE WHEN bite_checked = 0 THEN FALSE ELSE TRUE END, - ALTER bite_checked SET DEFAULT FALSE, - ALTER dent_checked drop default, - ALTER COLUMN dent_checked SET DATA TYPE boolean USING CASE WHEN dent_checked = 0 THEN FALSE ELSE TRUE END, - ALTER dent_checked SET DEFAULT FALSE, - ALTER pit_file_debt_ceiling_checked drop default, - ALTER COLUMN pit_file_debt_ceiling_checked SET DATA TYPE boolean USING CASE WHEN pit_file_debt_ceiling_checked = 0 THEN FALSE ELSE TRUE END, - ALTER pit_file_debt_ceiling_checked SET DEFAULT FALSE, - ALTER pit_file_ilk_checked drop default, - ALTER COLUMN pit_file_ilk_checked SET DATA TYPE boolean USING CASE WHEN pit_file_ilk_checked = 0 THEN FALSE ELSE TRUE END, - ALTER pit_file_ilk_checked SET DEFAULT FALSE, - ALTER vat_init_checked drop default, - ALTER COLUMN vat_init_checked SET DATA TYPE boolean USING CASE WHEN vat_init_checked = 0 THEN FALSE ELSE TRUE END, - ALTER vat_init_checked SET DEFAULT FALSE, - ALTER drip_file_ilk_checked drop default, - ALTER COLUMN drip_file_ilk_checked SET DATA TYPE boolean USING CASE WHEN drip_file_ilk_checked = 0 THEN FALSE ELSE TRUE END, - ALTER drip_file_ilk_checked SET DEFAULT FALSE, - ALTER drip_file_repo_checked drop default, - ALTER COLUMN drip_file_repo_checked SET DATA TYPE boolean USING CASE WHEN drip_file_repo_checked = 0 THEN FALSE ELSE TRUE END, - ALTER drip_file_repo_checked SET DEFAULT FALSE, - ALTER drip_file_vow_checked drop default, - ALTER COLUMN drip_file_vow_checked SET DATA TYPE boolean USING CASE WHEN drip_file_vow_checked = 0 THEN FALSE ELSE TRUE END, - ALTER drip_file_vow_checked SET DEFAULT FALSE, - ALTER deal_checked drop default, - ALTER COLUMN deal_checked SET DATA TYPE boolean USING CASE WHEN deal_checked = 0 THEN FALSE ELSE TRUE END, - ALTER deal_checked SET DEFAULT FALSE, - ALTER drip_drip_checked drop default, - ALTER COLUMN drip_drip_checked SET DATA TYPE boolean USING CASE WHEN drip_drip_checked = 0 THEN FALSE ELSE TRUE END, - ALTER drip_drip_checked SET DEFAULT FALSE, - ALTER cat_file_chop_lump_checked drop default, - ALTER COLUMN cat_file_chop_lump_checked SET DATA TYPE boolean USING CASE WHEN cat_file_chop_lump_checked = 0 THEN FALSE ELSE TRUE END, - ALTER cat_file_chop_lump_checked SET DEFAULT FALSE, - ALTER cat_file_flip_checked drop default, - ALTER COLUMN cat_file_flip_checked SET DATA TYPE boolean USING CASE WHEN cat_file_flip_checked = 0 THEN FALSE ELSE TRUE END, - ALTER cat_file_flip_checked SET DEFAULT FALSE, - ALTER cat_file_pit_vow_checked drop default, - ALTER COLUMN cat_file_pit_vow_checked SET DATA TYPE boolean USING CASE WHEN cat_file_pit_vow_checked = 0 THEN FALSE ELSE TRUE END, - ALTER cat_file_pit_vow_checked SET DEFAULT FALSE, - ALTER flop_kick_checked drop default, - ALTER COLUMN flop_kick_checked SET DATA TYPE boolean USING CASE WHEN flop_kick_checked = 0 THEN FALSE ELSE TRUE END, - ALTER flop_kick_checked SET DEFAULT FALSE, - ALTER vat_move_checked drop default, - ALTER COLUMN vat_move_checked SET DATA TYPE boolean USING CASE WHEN vat_move_checked = 0 THEN FALSE ELSE TRUE END, - ALTER vat_move_checked SET DEFAULT FALSE, - ALTER vat_fold_checked drop default, - ALTER COLUMN vat_fold_checked SET DATA TYPE boolean USING CASE WHEN vat_fold_checked = 0 THEN FALSE ELSE TRUE END, - ALTER vat_fold_checked SET DEFAULT FALSE, - ALTER vat_heal_checked drop default, - ALTER COLUMN vat_heal_checked SET DATA TYPE boolean USING CASE WHEN vat_heal_checked = 0 THEN FALSE ELSE TRUE END, - ALTER vat_heal_checked SET DEFAULT FALSE, - ALTER vat_toll_checked drop default, - ALTER COLUMN vat_toll_checked SET DATA TYPE boolean USING CASE WHEN vat_toll_checked = 0 THEN FALSE ELSE TRUE END, - ALTER vat_toll_checked SET DEFAULT FALSE, - ALTER vat_tune_checked drop default, - ALTER COLUMN vat_tune_checked SET DATA TYPE boolean USING CASE WHEN vat_tune_checked = 0 THEN FALSE ELSE TRUE END, - ALTER vat_tune_checked SET DEFAULT FALSE, - ALTER vat_grab_checked drop default, - ALTER COLUMN vat_grab_checked SET DATA TYPE boolean USING CASE WHEN vat_grab_checked = 0 THEN FALSE ELSE TRUE END, - ALTER vat_grab_checked SET DEFAULT FALSE, - ALTER vat_flux_checked drop default, - ALTER COLUMN vat_flux_checked SET DATA TYPE boolean USING CASE WHEN vat_flux_checked = 0 THEN FALSE ELSE TRUE END, - ALTER vat_flux_checked SET DEFAULT FALSE, - ALTER vat_slip_checked drop default, - ALTER COLUMN vat_slip_checked SET DATA TYPE boolean USING CASE WHEN vat_slip_checked = 0 THEN FALSE ELSE TRUE END, - ALTER vat_slip_checked SET DEFAULT FALSE, - ALTER vow_flog_checked drop default, - ALTER COLUMN vow_flog_checked SET DATA TYPE boolean USING CASE WHEN vow_flog_checked = 0 THEN FALSE ELSE TRUE END, - ALTER vow_flog_checked SET DEFAULT FALSE, - ALTER flap_kick_checked drop default, - ALTER COLUMN flap_kick_checked SET DATA TYPE boolean USING CASE WHEN flap_kick_checked = 0 THEN FALSE ELSE TRUE END, - ALTER flap_kick_checked SET DEFAULT FALSE; diff --git a/db/migrations/20181114200131_create_vat_contract_storage_tables.sql b/db/migrations/20181114200131_create_vat_contract_storage_tables.sql deleted file mode 100644 index 9c7f8b0c..00000000 --- a/db/migrations/20181114200131_create_vat_contract_storage_tables.sql +++ /dev/null @@ -1,102 +0,0 @@ --- +goose Up -CREATE TABLE maker.vat_debt ( - id SERIAL PRIMARY KEY, - block_number BIGINT, - block_hash TEXT, - debt NUMERIC NOT NULL -); - -CREATE TABLE maker.vat_vice ( - id SERIAL PRIMARY KEY, - block_number BIGINT, - block_hash TEXT, - vice NUMERIC NOT NULL -); - -CREATE TABLE maker.vat_ilk_art ( - id SERIAL PRIMARY KEY, - block_number BIGINT, - block_hash TEXT, - ilk INTEGER NOT NULL REFERENCES maker.ilks (id), - art NUMERIC NOT NULL -); - -CREATE TABLE maker.vat_ilk_ink ( - id SERIAL PRIMARY KEY, - block_number BIGINT, - block_hash TEXT, - ilk INTEGER NOT NULL REFERENCES maker.ilks (id), - ink NUMERIC NOT NULL -); - -CREATE TABLE maker.vat_ilk_rate ( - id SERIAL PRIMARY KEY, - block_number BIGINT, - block_hash TEXT, - ilk INTEGER NOT NULL REFERENCES maker.ilks (id), - rate NUMERIC NOT NULL -); - -CREATE TABLE maker.vat_ilk_take ( - id SERIAL PRIMARY KEY, - block_number BIGINT, - block_hash TEXT, - ilk INTEGER NOT NULL REFERENCES maker.ilks (id), - take NUMERIC NOT NULL -); - -CREATE TABLE maker.vat_urn_art ( - id SERIAL PRIMARY KEY, - block_number BIGINT, - block_hash TEXT, - ilk INTEGER NOT NULL REFERENCES maker.ilks (id), - urn TEXT, - art TEXT -); - -CREATE TABLE maker.vat_urn_ink ( - id SERIAL PRIMARY KEY, - block_number BIGINT, - block_hash TEXT, - ilk INTEGER NOT NULL REFERENCES maker.ilks (id), - urn TEXT, - ink NUMERIC NOT NULL -); - -CREATE TABLE maker.vat_gem ( - id SERIAL PRIMARY KEY, - block_number BIGINT, - block_hash TEXT, - ilk INTEGER NOT NULL REFERENCES maker.ilks (id), - guy TEXT, - gem NUMERIC NOT NULL -); - -CREATE TABLE maker.vat_dai ( - id SERIAL PRIMARY KEY, - block_number BIGINT, - block_hash TEXT, - guy TEXT, - dai NUMERIC NOT NULL -); - -CREATE TABLE maker.vat_sin ( - id SERIAL PRIMARY KEY, - block_number BIGINT, - block_hash TEXT, - guy TEXT, - sin NUMERIC NOT NULL -); - --- +goose Down -DROP TABLE maker.vat_debt; -DROP TABLE maker.vat_vice; -DROP TABLE maker.vat_ilk_art; -DROP TABLE maker.vat_ilk_ink; -DROP TABLE maker.vat_ilk_rate; -DROP TABLE maker.vat_ilk_take; -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; diff --git a/db/migrations/20181114200132_create_vow_contract_storage_tables.sql b/db/migrations/20181114200132_create_vow_contract_storage_tables.sql deleted file mode 100644 index 2027a599..00000000 --- a/db/migrations/20181114200132_create_vow_contract_storage_tables.sql +++ /dev/null @@ -1,82 +0,0 @@ --- +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 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 numeric -); - -CREATE TABLE maker.vow_wait ( - id SERIAL PRIMARY KEY, - block_number BIGINT, - block_hash TEXT, - wait numeric -); - -CREATE TABLE maker.vow_sump ( - id SERIAL PRIMARY KEY, - block_number BIGINT, - block_hash TEXT, - sump numeric -); - -CREATE TABLE maker.vow_bump ( - id SERIAL PRIMARY KEY, - block_number BIGINT, - block_hash TEXT, - bump numeric -); - -CREATE TABLE maker.vow_hump ( - id SERIAL PRIMARY KEY, - block_number BIGINT, - block_hash 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; -DROP TABLE maker.vow_bump; -DROP TABLE maker.vow_hump; diff --git a/db/migrations/20190215160236_create_cat_storage_tables.sql b/db/migrations/20190215160236_create_cat_storage_tables.sql deleted file mode 100644 index 8fc29e5f..00000000 --- a/db/migrations/20190215160236_create_cat_storage_tables.sql +++ /dev/null @@ -1,106 +0,0 @@ --- +goose Up -CREATE TABLE maker.cat_nflip ( - id SERIAL PRIMARY KEY, - block_number BIGINT, - block_hash TEXT, - nflip NUMERIC NOT NULL -); - -CREATE TABLE maker.cat_live ( - id SERIAL PRIMARY KEY, - block_number BIGINT, - block_hash TEXT, - live NUMERIC NOT NULL -); - -CREATE TABLE maker.cat_vat ( - id SERIAL PRIMARY KEY, - block_number BIGINT, - block_hash TEXT, - vat TEXT -); - -CREATE TABLE maker.cat_pit ( - id SERIAL PRIMARY KEY, - block_number BIGINT, - block_hash TEXT, - pit TEXT -); - -CREATE TABLE maker.cat_vow ( - id SERIAL PRIMARY KEY, - block_number BIGINT, - block_hash TEXT, - vow TEXT -); - -CREATE TABLE maker.cat_ilk_flip ( - id SERIAL PRIMARY KEY, - block_number BIGINT, - block_hash TEXT, - ilk INTEGER NOT NULL REFERENCES maker.ilks (id), - flip TEXT -); - -CREATE TABLE maker.cat_ilk_chop ( - id SERIAL PRIMARY KEY, - block_number BIGINT, - block_hash TEXT, - ilk INTEGER NOT NULL REFERENCES maker.ilks (id), - chop NUMERIC NOT NULL -); - -CREATE TABLE maker.cat_ilk_lump ( - id SERIAL PRIMARY KEY, - block_number BIGINT, - block_hash TEXT, - ilk INTEGER NOT NULL REFERENCES maker.ilks (id), - lump NUMERIC NOT NULL -); - -CREATE TABLE maker.cat_flip_ilk ( - id SERIAL PRIMARY KEY, - block_number BIGINT, - block_hash TEXT, - flip NUMERIC NOT NULL, - ilk INTEGER NOT NULL REFERENCES maker.ilks (id) -); - -CREATE TABLE maker.cat_flip_urn ( - id SERIAL PRIMARY KEY, - block_number BIGINT, - block_hash TEXT, - flip NUMERIC NOT NULL, - urn TEXT -); - -CREATE TABLE maker.cat_flip_ink ( - id SERIAL PRIMARY KEY, - block_number BIGINT, - block_hash TEXT, - flip NUMERIC NOT NULL, - ink NUMERIC NOT NULL -); - -CREATE TABLE maker.cat_flip_tab ( - id SERIAL PRIMARY KEY, - block_number BIGINT, - block_hash TEXT, - flip NUMERIC NOT NULL, - tab NUMERIC NOT NULL -); - - --- +goose Down -DROP TABLE maker.cat_nflip; -DROP TABLE maker.cat_live; -DROP TABLE maker.cat_vat; -DROP TABLE maker.cat_pit; -DROP TABLE maker.cat_vow; -DROP TABLE maker.cat_ilk_flip; -DROP TABLE maker.cat_ilk_chop; -DROP TABLE maker.cat_ilk_lump; -DROP TABLE maker.cat_flip_ilk; -DROP TABLE maker.cat_flip_urn; -DROP TABLE maker.cat_flip_ink; -DROP TABLE maker.cat_flip_tab; \ No newline at end of file diff --git a/db/schema.sql b/db/schema.sql index 32fadd1d..107de4a3 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -2,8 +2,8 @@ -- PostgreSQL database dump -- --- Dumped from database version 10.6 --- Dumped by pg_dump version 10.6 +-- Dumped from database version 10.5 +-- Dumped by pg_dump version 10.4 SET statement_timeout = 0; SET lock_timeout = 0; @@ -114,8 +114,7 @@ ALTER SEQUENCE public.blocks_id_seq OWNED BY public.blocks.id; CREATE TABLE public.checked_headers ( id integer NOT NULL, - header_id integer NOT NULL, - price_feeds_checked integer DEFAULT 0 NOT NULL + header_id integer NOT NULL ); @@ -299,6 +298,40 @@ CREATE SEQUENCE public.nodes_id_seq ALTER SEQUENCE public.nodes_id_seq OWNED BY public.eth_nodes.id; +-- +-- Name: queued_storage; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.queued_storage ( + id integer NOT NULL, + block_height bigint, + block_hash bytea, + contract bytea, + storage_key bytea, + storage_value bytea +); + + +-- +-- Name: queued_storage_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE public.queued_storage_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: queued_storage_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE public.queued_storage_id_seq OWNED BY public.queued_storage.id; + + -- -- Name: receipts; Type: TABLE; Schema: public; Owner: - -- @@ -335,6 +368,38 @@ CREATE SEQUENCE public.receipts_id_seq ALTER SEQUENCE public.receipts_id_seq OWNED BY public.receipts.id; +-- +-- Name: token_supply; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.token_supply ( + id integer NOT NULL, + block_id integer NOT NULL, + supply numeric NOT NULL, + token_address character varying(66) NOT NULL +); + + +-- +-- Name: token_supply_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE public.token_supply_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: token_supply_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE public.token_supply_id_seq OWNED BY public.token_supply.id; + + -- -- Name: transactions; Type: TABLE; Schema: public; Owner: - -- @@ -476,6 +541,13 @@ ALTER TABLE ONLY public.log_filters ALTER COLUMN id SET DEFAULT nextval('public. ALTER TABLE ONLY public.logs ALTER COLUMN id SET DEFAULT nextval('public.logs_id_seq'::regclass); +-- +-- Name: queued_storage id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.queued_storage ALTER COLUMN id SET DEFAULT nextval('public.queued_storage_id_seq'::regclass); + + -- -- Name: receipts id; Type: DEFAULT; Schema: public; Owner: - -- @@ -483,6 +555,13 @@ ALTER TABLE ONLY public.logs ALTER COLUMN id SET DEFAULT nextval('public.logs_id ALTER TABLE ONLY public.receipts ALTER COLUMN id SET DEFAULT nextval('public.receipts_id_seq'::regclass); +-- +-- Name: token_supply id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.token_supply ALTER COLUMN id SET DEFAULT nextval('public.token_supply_id_seq'::regclass); + + -- -- Name: transactions id; Type: DEFAULT; Schema: public; Owner: - -- @@ -668,6 +747,14 @@ ALTER TABLE ONLY public.receipts ADD CONSTRAINT blocks_fk FOREIGN KEY (block_id) REFERENCES public.blocks(id) ON DELETE CASCADE; +-- +-- Name: token_supply blocks_fk; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.token_supply + ADD CONSTRAINT blocks_fk FOREIGN KEY (block_id) REFERENCES public.blocks(id) ON DELETE CASCADE; + + -- -- Name: checked_headers checked_headers_header_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: - -- diff --git a/environments/staging.toml b/environments/staging.toml deleted file mode 100644 index 8954a483..00000000 --- a/environments/staging.toml +++ /dev/null @@ -1,52 +0,0 @@ -[database] - name = "vulcanize_public" - hostname = "localhost" - user = "vulcanize" - password = "vulcanize" - port = 5432 - -[client] - ipcPath = "http://kovan0.vulcanize.io:8545" - -[datadog] - name = "maker_vdb_staging" - -[filesystem] - storageDiffsPath = "INSERT-PATH-TO-STORAGE-DIFFS" - -[contract] - [contract.address] - cat = "0x2f34f22a00ee4b7a8f8bbc4eaee1658774c624e0" - drip = "0x891c04639a5edcae088e546fa125b5d7fb6a2b9d" - eth_flip = "0x32D496Ad866D110060866B7125981C73642cc509" - mcd_flap = "0x8868BAd8e74FcA4505676D1B5B21EcC23328d132" - mcd_flop = "0x6191C9b0086c2eBF92300cC507009b53996FbFFa" - pep = "0xB1997239Cfc3d15578A3a09730f7f84A90BB4975" - pip = "0x9FfFE440258B79c5d6604001674A4722FfC0f7Bc" - pit = "0xe7cf3198787c9a4daac73371a38f29aaeeced87e" - rep = "0xf88bbdc1e2718f8857f30a180076ec38d53cf296" - vat = "0xcd726790550afcd77e9a7a47e86a3f9010af126b" - vow = "0x3728e9777B2a0a611ee0F89e00E01044ce4736d1" - [contract.abi] - cat = '[{"constant":true,"inputs":[],"name":"vat","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function","signature":"0x36569e77"},{"constant":true,"inputs":[],"name":"vow","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function","signature":"0x626cb3c5"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"flips","outputs":[{"name":"ilk","type":"bytes32"},{"name":"urn","type":"bytes32"},{"name":"ink","type":"uint256"},{"name":"tab","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function","signature":"0x70d9235a"},{"constant":true,"inputs":[],"name":"nflip","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function","signature":"0x76181a51"},{"constant":true,"inputs":[],"name":"live","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function","signature":"0x957aa58c"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"wards","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function","signature":"0xbf353dbb"},{"constant":true,"inputs":[{"name":"","type":"bytes32"}],"name":"ilks","outputs":[{"name":"flip","type":"address"},{"name":"chop","type":"uint256"},{"name":"lump","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function","signature":"0xd9638d36"},{"constant":true,"inputs":[],"name":"pit","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function","signature":"0xf03c7c6e"},{"inputs":[{"name":"vat_","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor","signature":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"ilk","type":"bytes32"},{"indexed":true,"name":"urn","type":"bytes32"},{"indexed":false,"name":"ink","type":"uint256"},{"indexed":false,"name":"art","type":"uint256"},{"indexed":false,"name":"tab","type":"uint256"},{"indexed":false,"name":"flip","type":"uint256"},{"indexed":false,"name":"iArt","type":"uint256"}],"name":"Bite","type":"event","signature":"0x99b5620489b6ef926d4518936cfec15d305452712b88bd59da2d9c10fb0953e8"},{"anonymous":true,"inputs":[{"indexed":true,"name":"sig","type":"bytes4"},{"indexed":true,"name":"guy","type":"address"},{"indexed":true,"name":"foo","type":"bytes32"},{"indexed":true,"name":"bar","type":"bytes32"},{"indexed":false,"name":"wad","type":"uint256"},{"indexed":false,"name":"fax","type":"bytes"}],"name":"LogNote","type":"event","signature":"0x644843f351d3fba4abcd60109eaff9f54bac8fb8ccf0bab941009c21df21cf31"},{"constant":false,"inputs":[{"name":"guy","type":"address"}],"name":"rely","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x65fae35e"},{"constant":false,"inputs":[{"name":"guy","type":"address"}],"name":"deny","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x9c52a7f1"},{"constant":false,"inputs":[{"name":"ilk","type":"bytes32"},{"name":"what","type":"bytes32"},{"name":"data","type":"uint256"}],"name":"file","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x1a0b287e"},{"constant":false,"inputs":[{"name":"what","type":"bytes32"},{"name":"data","type":"address"}],"name":"file","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0xd4e8be83"},{"constant":false,"inputs":[{"name":"ilk","type":"bytes32"},{"name":"what","type":"bytes32"},{"name":"flip","type":"address"}],"name":"file","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0xebecb39d"},{"constant":false,"inputs":[{"name":"ilk","type":"bytes32"},{"name":"urn","type":"bytes32"}],"name":"bite","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x72f7b593"},{"constant":false,"inputs":[{"name":"n","type":"uint256"},{"name":"wad","type":"uint256"}],"name":"flip","outputs":[{"name":"id","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0xe6f95917"}]' - drip = '[{"constant":true,"inputs":[],"name":"vat","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function","signature":"0x36569e77"},{"constant":true,"inputs":[],"name":"repo","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function","signature":"0x56ff3122"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"wards","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function","signature":"0xbf353dbb"},{"constant":true,"inputs":[{"name":"","type":"bytes32"}],"name":"ilks","outputs":[{"name":"vow","type":"bytes32"},{"name":"tax","type":"uint256"},{"name":"rho","type":"uint48"}],"payable":false,"stateMutability":"view","type":"function","signature":"0xd9638d36"},{"inputs":[{"name":"vat_","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor","signature":"constructor"},{"anonymous":true,"inputs":[{"indexed":true,"name":"sig","type":"bytes4"},{"indexed":true,"name":"guy","type":"address"},{"indexed":true,"name":"foo","type":"bytes32"},{"indexed":true,"name":"bar","type":"bytes32"},{"indexed":false,"name":"wad","type":"uint256"},{"indexed":false,"name":"fax","type":"bytes"}],"name":"LogNote","type":"event","signature":"0x644843f351d3fba4abcd60109eaff9f54bac8fb8ccf0bab941009c21df21cf31"},{"constant":false,"inputs":[{"name":"guy","type":"address"}],"name":"rely","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x65fae35e"},{"constant":false,"inputs":[{"name":"guy","type":"address"}],"name":"deny","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x9c52a7f1"},{"constant":true,"inputs":[],"name":"era","outputs":[{"name":"","type":"uint48"}],"payable":false,"stateMutability":"view","type":"function","signature":"0x143e55e0"},{"constant":false,"inputs":[{"name":"ilk","type":"bytes32"},{"name":"vow","type":"bytes32"},{"name":"tax","type":"uint256"}],"name":"file","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x1a0b287e"},{"constant":false,"inputs":[{"name":"what","type":"bytes32"},{"name":"data","type":"uint256"}],"name":"file","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x29ae8114"},{"constant":false,"inputs":[{"name":"ilk","type":"bytes32"}],"name":"drip","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x44e2a5a8"}]' - mcd_flap = '[{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"bids","outputs":[{"name":"bid","type":"uint256"},{"name":"lot","type":"uint256"},{"name":"guy","type":"address"},{"name":"tic","type":"uint48"},{"name":"end","type":"uint48"},{"name":"gal","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"ttl","outputs":[{"name":"","type":"uint48"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"gem","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"beg","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"tau","outputs":[{"name":"","type":"uint48"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"kicks","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"dai","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"dai_","type":"address"},{"name":"gem_","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"id","type":"uint256"},{"indexed":false,"name":"lot","type":"uint256"},{"indexed":false,"name":"bid","type":"uint256"},{"indexed":false,"name":"gal","type":"address"},{"indexed":false,"name":"end","type":"uint48"}],"name":"Kick","type":"event"},{"anonymous":true,"inputs":[{"indexed":true,"name":"sig","type":"bytes4"},{"indexed":true,"name":"guy","type":"address"},{"indexed":true,"name":"foo","type":"bytes32"},{"indexed":true,"name":"bar","type":"bytes32"},{"indexed":false,"name":"wad","type":"uint256"},{"indexed":false,"name":"fax","type":"bytes"}],"name":"LogNote","type":"event"},{"constant":false,"inputs":[{"name":"gal","type":"address"},{"name":"lot","type":"uint256"},{"name":"bid","type":"uint256"}],"name":"kick","outputs":[{"name":"id","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"id","type":"uint256"},{"name":"lot","type":"uint256"},{"name":"bid","type":"uint256"}],"name":"tend","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"id","type":"uint256"}],"name":"deal","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}]' - eth_flip = '[{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"bids","outputs":[{"name":"bid","type":"uint256"},{"name":"lot","type":"uint256"},{"name":"guy","type":"address"},{"name":"tic","type":"uint48"},{"name":"end","type":"uint48"},{"name":"urn","type":"bytes32"},{"name":"gal","type":"address"},{"name":"tab","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function","signature":"0x4423c5f1"},{"constant":true,"inputs":[],"name":"ttl","outputs":[{"name":"","type":"uint48"}],"payable":false,"stateMutability":"view","type":"function","signature":"0x4e8b1dd5"},{"constant":true,"inputs":[],"name":"gem","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function","signature":"0x7bd2bea7"},{"constant":true,"inputs":[],"name":"beg","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function","signature":"0x7d780d82"},{"constant":true,"inputs":[],"name":"tau","outputs":[{"name":"","type":"uint48"}],"payable":false,"stateMutability":"view","type":"function","signature":"0xcfc4af55"},{"constant":true,"inputs":[],"name":"kicks","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function","signature":"0xcfdd3302"},{"constant":true,"inputs":[],"name":"dai","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function","signature":"0xf4b9fa75"},{"inputs":[{"name":"dai_","type":"address"},{"name":"gem_","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor","signature":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"id","type":"uint256"},{"indexed":false,"name":"lot","type":"uint256"},{"indexed":false,"name":"bid","type":"uint256"},{"indexed":false,"name":"gal","type":"address"},{"indexed":false,"name":"end","type":"uint48"},{"indexed":true,"name":"urn","type":"bytes32"},{"indexed":false,"name":"tab","type":"uint256"}],"name":"Kick","type":"event","signature":"0xbac86238bdba81d21995024470425ecb370078fa62b7271b90cf28cbd1e3e87e"},{"anonymous":true,"inputs":[{"indexed":true,"name":"sig","type":"bytes4"},{"indexed":true,"name":"guy","type":"address"},{"indexed":true,"name":"foo","type":"bytes32"},{"indexed":true,"name":"bar","type":"bytes32"},{"indexed":false,"name":"wad","type":"uint256"},{"indexed":false,"name":"fax","type":"bytes"}],"name":"LogNote","type":"event","signature":"0x644843f351d3fba4abcd60109eaff9f54bac8fb8ccf0bab941009c21df21cf31"},{"constant":true,"inputs":[],"name":"era","outputs":[{"name":"","type":"uint48"}],"payable":false,"stateMutability":"view","type":"function","signature":"0x143e55e0"},{"constant":false,"inputs":[{"name":"urn","type":"bytes32"},{"name":"gal","type":"address"},{"name":"tab","type":"uint256"},{"name":"lot","type":"uint256"},{"name":"bid","type":"uint256"}],"name":"kick","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0xeae19d9e"},{"constant":false,"inputs":[{"name":"id","type":"uint256"}],"name":"tick","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0xfc7b6aee"},{"constant":false,"inputs":[{"name":"id","type":"uint256"},{"name":"lot","type":"uint256"},{"name":"bid","type":"uint256"}],"name":"tend","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x4b43ed12"},{"constant":false,"inputs":[{"name":"id","type":"uint256"},{"name":"lot","type":"uint256"},{"name":"bid","type":"uint256"}],"name":"dent","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x5ff3a382"},{"constant":false,"inputs":[{"name":"id","type":"uint256"}],"name":"deal","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0xc959c42b"}]' - mcd_flop = '[{"constant":true,"inputs":[],"name":"era","outputs":[{"name":"","type":"uint48"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"bids","outputs":[{"name":"bid","type":"uint256"},{"name":"lot","type":"uint256"},{"name":"guy","type":"address"},{"name":"tic","type":"uint48"},{"name":"end","type":"uint48"},{"name":"vow","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"ttl","outputs":[{"name":"","type":"uint48"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"id","type":"uint256"},{"name":"lot","type":"uint256"},{"name":"bid","type":"uint256"}],"name":"dent","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"guy","type":"address"}],"name":"rely","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"gem","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"beg","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"guy","type":"address"}],"name":"deny","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"gal","type":"address"},{"name":"lot","type":"uint256"},{"name":"bid","type":"uint256"}],"name":"kick","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"wards","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"id","type":"uint256"}],"name":"deal","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"tau","outputs":[{"name":"","type":"uint48"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"kicks","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"dai","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"dai_","type":"address"},{"name":"gem_","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"id","type":"uint256"},{"indexed":false,"name":"lot","type":"uint256"},{"indexed":false,"name":"bid","type":"uint256"},{"indexed":false,"name":"gal","type":"address"},{"indexed":false,"name":"end","type":"uint48"}],"name":"Kick","type":"event"},{"anonymous":true,"inputs":[{"indexed":true,"name":"sig","type":"bytes4"},{"indexed":true,"name":"guy","type":"address"},{"indexed":true,"name":"foo","type":"bytes32"},{"indexed":true,"name":"bar","type":"bytes32"},{"indexed":false,"name":"wad","type":"uint256"},{"indexed":false,"name":"fax","type":"bytes"}],"name":"LogNote","type":"event"}]' - medianizer = '[{"constant":false,"inputs":[{"name":"owner_","type":"address"}],"name":"setOwner","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"","type":"bytes32"}],"name":"poke","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"poke","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"compute","outputs":[{"name":"","type":"bytes32"},{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"wat","type":"address"}],"name":"set","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"wat","type":"address"}],"name":"unset","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"indexes","outputs":[{"name":"","type":"bytes12"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"next","outputs":[{"name":"","type":"bytes12"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"read","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"peek","outputs":[{"name":"","type":"bytes32"},{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"bytes12"}],"name":"values","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"min_","type":"uint96"}],"name":"setMin","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"authority_","type":"address"}],"name":"setAuthority","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"void","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"pos","type":"bytes12"},{"name":"wat","type":"address"}],"name":"set","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"authority","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"pos","type":"bytes12"}],"name":"unset","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"next_","type":"bytes12"}],"name":"setNext","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"min","outputs":[{"name":"","type":"uint96"}],"payable":false,"stateMutability":"view","type":"function"},{"anonymous":false,"inputs":[{"indexed":false,"name":"val","type":"bytes32"}],"name":"LogValue","type":"event"},{"anonymous":true,"inputs":[{"indexed":true,"name":"sig","type":"bytes4"},{"indexed":true,"name":"guy","type":"address"},{"indexed":true,"name":"foo","type":"bytes32"},{"indexed":true,"name":"bar","type":"bytes32"},{"indexed":false,"name":"wad","type":"uint256"},{"indexed":false,"name":"fax","type":"bytes"}],"name":"LogNote","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"authority","type":"address"}],"name":"LogSetAuthority","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"}],"name":"LogSetOwner","type":"event"}]]' - # TODO: replace with updated ABI when contract is deployed (with no pit file stability fee method + modified Frob event) - pit = '[{"constant":true,"inputs":[],"name":"vat","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function","signature":"0x36569e77"},{"constant":true,"inputs":[],"name":"live","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function","signature":"0x957aa58c"},{"constant":true,"inputs":[],"name":"drip","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function","signature":"0x9f678cca"},{"constant":true,"inputs":[],"name":"Line","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function","signature":"0xbabe8a3f"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"wards","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function","signature":"0xbf353dbb"},{"constant":true,"inputs":[{"name":"","type":"bytes32"}],"name":"ilks","outputs":[{"name":"spot","type":"uint256"},{"name":"line","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function","signature":"0xd9638d36"},{"inputs":[{"name":"vat_","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor","signature":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"ilk","type":"bytes32"},{"indexed":true,"name":"urn","type":"bytes32"},{"indexed":false,"name":"ink","type":"uint256"},{"indexed":false,"name":"art","type":"uint256"},{"indexed":false,"name":"dink","type":"int256"},{"indexed":false,"name":"dart","type":"int256"},{"indexed":false,"name":"iArt","type":"uint256"}],"name":"Frob","type":"event","signature":"0xb2afa28318bcc689926b52835d844de174ef8de97e982a85c0199d584920791b"},{"anonymous":true,"inputs":[{"indexed":true,"name":"sig","type":"bytes4"},{"indexed":true,"name":"guy","type":"address"},{"indexed":true,"name":"foo","type":"bytes32"},{"indexed":true,"name":"bar","type":"bytes32"},{"indexed":false,"name":"wad","type":"uint256"},{"indexed":false,"name":"fax","type":"bytes"}],"name":"LogNote","type":"event","signature":"0x644843f351d3fba4abcd60109eaff9f54bac8fb8ccf0bab941009c21df21cf31"},{"constant":false,"inputs":[{"name":"guy","type":"address"}],"name":"rely","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x65fae35e"},{"constant":false,"inputs":[{"name":"guy","type":"address"}],"name":"deny","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x9c52a7f1"},{"constant":false,"inputs":[{"name":"ilk","type":"bytes32"},{"name":"what","type":"bytes32"},{"name":"data","type":"uint256"}],"name":"file","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x1a0b287e"},{"constant":false,"inputs":[{"name":"what","type":"bytes32"},{"name":"data","type":"uint256"}],"name":"file","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x29ae8114"},{"constant":false,"inputs":[{"name":"what","type":"bytes32"},{"name":"data","type":"address"}],"name":"file","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0xd4e8be83"},{"constant":false,"inputs":[{"name":"ilk","type":"bytes32"},{"name":"dink","type":"int256"},{"name":"dart","type":"int256"}],"name":"frob","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x5a984ded"}]' - vat = '[{"constant":true,"inputs":[],"name":"debt","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function","signature":"0x0dca59c1"},{"constant":true,"inputs":[{"name":"","type":"bytes32"},{"name":"","type":"bytes32"}],"name":"urns","outputs":[{"name":"ink","type":"uint256"},{"name":"art","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function","signature":"0x26e27482"},{"constant":true,"inputs":[],"name":"vice","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function","signature":"0x2d61a355"},{"constant":true,"inputs":[{"name":"","type":"bytes32"}],"name":"sin","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function","signature":"0xa60f1d3e"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"wards","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function","signature":"0xbf353dbb"},{"constant":true,"inputs":[{"name":"","type":"bytes32"},{"name":"","type":"bytes32"}],"name":"gem","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function","signature":"0xc0912683"},{"constant":true,"inputs":[{"name":"","type":"bytes32"}],"name":"ilks","outputs":[{"name":"take","type":"uint256"},{"name":"rate","type":"uint256"},{"name":"Ink","type":"uint256"},{"name":"Art","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function","signature":"0xd9638d36"},{"constant":true,"inputs":[{"name":"","type":"bytes32"}],"name":"dai","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function","signature":"0xf53e4e69"},{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor","signature":"constructor"},{"anonymous":true,"inputs":[{"indexed":true,"name":"sig","type":"bytes4"},{"indexed":true,"name":"foo","type":"bytes32"},{"indexed":true,"name":"bar","type":"bytes32"},{"indexed":true,"name":"too","type":"bytes32"},{"indexed":false,"name":"fax","type":"bytes"}],"name":"Note","type":"event","signature":"0x8c2dbbc2b33ffaa77c104b777e574a8a4ff79829dfee8b66f4dc63e3f8067152"},{"constant":false,"inputs":[{"name":"guy","type":"address"}],"name":"rely","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x65fae35e"},{"constant":false,"inputs":[{"name":"guy","type":"address"}],"name":"deny","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x9c52a7f1"},{"constant":false,"inputs":[{"name":"ilk","type":"bytes32"}],"name":"init","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x3b663195"},{"constant":false,"inputs":[{"name":"ilk","type":"bytes32"},{"name":"guy","type":"bytes32"},{"name":"rad","type":"int256"}],"name":"slip","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x42066cbb"},{"constant":false,"inputs":[{"name":"ilk","type":"bytes32"},{"name":"src","type":"bytes32"},{"name":"dst","type":"bytes32"},{"name":"rad","type":"int256"}],"name":"flux","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0xa6e41821"},{"constant":false,"inputs":[{"name":"src","type":"bytes32"},{"name":"dst","type":"bytes32"},{"name":"rad","type":"int256"}],"name":"move","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x78f19470"},{"constant":false,"inputs":[{"name":"i","type":"bytes32"},{"name":"u","type":"bytes32"},{"name":"v","type":"bytes32"},{"name":"w","type":"bytes32"},{"name":"dink","type":"int256"},{"name":"dart","type":"int256"}],"name":"tune","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x5dd6471a"},{"constant":false,"inputs":[{"name":"i","type":"bytes32"},{"name":"u","type":"bytes32"},{"name":"v","type":"bytes32"},{"name":"w","type":"bytes32"},{"name":"dink","type":"int256"},{"name":"dart","type":"int256"}],"name":"grab","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x3690ae4c"},{"constant":false,"inputs":[{"name":"u","type":"bytes32"},{"name":"v","type":"bytes32"},{"name":"rad","type":"int256"}],"name":"heal","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x990a5f63"},{"constant":false,"inputs":[{"name":"i","type":"bytes32"},{"name":"u","type":"bytes32"},{"name":"rate","type":"int256"}],"name":"fold","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0xe6a6a64d"},{"constant":false,"inputs":[{"name":"i","type":"bytes32"},{"name":"u","type":"bytes32"},{"name":"take","type":"int256"}],"name":"toll","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x09b7a0b5"}]' - vow = '[{"constant":true,"inputs":[],"name":"Awe","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"Joy","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"flap","outputs":[{"name":"id","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"hump","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"wad","type":"uint256"}],"name":"kiss","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"what","type":"bytes32"},{"name":"data","type":"uint256"}],"name":"file","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"Ash","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"era","type":"uint48"}],"name":"flog","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"vat","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"Woe","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"wait","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"guy","type":"address"}],"name":"rely","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"bump","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"tab","type":"uint256"}],"name":"fess","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"row","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint48"}],"name":"sin","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"guy","type":"address"}],"name":"deny","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"flop","outputs":[{"name":"id","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"wards","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"sump","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"Sin","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"what","type":"bytes32"},{"name":"addr","type":"address"}],"name":"file","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"cow","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"wad","type":"uint256"}],"name":"heal","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":true,"inputs":[{"indexed":true,"name":"sig","type":"bytes4"},{"indexed":true,"name":"guy","type":"address"},{"indexed":true,"name":"foo","type":"bytes32"},{"indexed":true,"name":"bar","type":"bytes32"},{"indexed":false,"name":"wad","type":"uint256"},{"indexed":false,"name":"fax","type":"bytes"}],"name":"LogNote","type":"event"}]' - [contract.deployment-block] - cat = 8751794 - drip = 8762197 - eth_flip = 8535561 - mcd_flap = 8535544 - mcd_flop = 8535545 - pep = 8760655 - pip = 8760588 - pit = 8535538 - rep = 8760681 - vat = 8535536 - vow = 8751792 diff --git a/libraries/shared/chunker/chunker_suite_test.go b/libraries/shared/chunker/chunker_suite_test.go new file mode 100644 index 00000000..f28d59d6 --- /dev/null +++ b/libraries/shared/chunker/chunker_suite_test.go @@ -0,0 +1,35 @@ +// VulcanizeDB +// Copyright © 2018 Vulcanize + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. + +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package chunker_test + +import ( + "testing" + + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + log "github.com/sirupsen/logrus" + "io/ioutil" +) + +func TestFactories(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "Shared Chunker Suite") +} + +var _ = BeforeSuite(func() { + log.SetOutput(ioutil.Discard) +}) diff --git a/libraries/shared/factories/converter.go b/libraries/shared/factories/converter.go new file mode 100644 index 00000000..1d46a048 --- /dev/null +++ b/libraries/shared/factories/converter.go @@ -0,0 +1,24 @@ +// VulcanizeDB +// Copyright © 2018 Vulcanize + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. + +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package factories + +import "github.com/ethereum/go-ethereum/core/types" + +type Converter interface { + ToEntities(contractAbi string, ethLog []types.Log) ([]interface{}, error) + ToModels([]interface{}) ([]interface{}, error) +} diff --git a/libraries/shared/factories/factories_suite_test.go b/libraries/shared/factories/factories_suite_test.go new file mode 100644 index 00000000..497c53d3 --- /dev/null +++ b/libraries/shared/factories/factories_suite_test.go @@ -0,0 +1,35 @@ +// VulcanizeDB +// Copyright © 2018 Vulcanize + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. + +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package factories_test + +import ( + "testing" + + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + log "github.com/sirupsen/logrus" + "io/ioutil" +) + +func TestFactories(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "Factories Suite") +} + +var _ = BeforeSuite(func() { + log.SetOutput(ioutil.Discard) +}) diff --git a/libraries/shared/factories/log_note_converter.go b/libraries/shared/factories/log_note_converter.go new file mode 100644 index 00000000..646ad13a --- /dev/null +++ b/libraries/shared/factories/log_note_converter.go @@ -0,0 +1,23 @@ +// VulcanizeDB +// Copyright © 2018 Vulcanize + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. + +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package factories + +import "github.com/ethereum/go-ethereum/core/types" + +type LogNoteConverter interface { + ToModels(ethLog []types.Log) ([]interface{}, error) +} diff --git a/libraries/shared/factories/log_note_transformer.go b/libraries/shared/factories/log_note_transformer.go new file mode 100644 index 00000000..7a96cfee --- /dev/null +++ b/libraries/shared/factories/log_note_transformer.go @@ -0,0 +1,73 @@ +// VulcanizeDB +// Copyright © 2018 Vulcanize + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. + +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package factories + +import ( + "github.com/ethereum/go-ethereum/core/types" + log "github.com/sirupsen/logrus" + + "github.com/vulcanize/vulcanizedb/libraries/shared/constants" + "github.com/vulcanize/vulcanizedb/libraries/shared/transformer" + "github.com/vulcanize/vulcanizedb/pkg/core" + "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" +) + +type LogNoteTransformer struct { + Config transformer.TransformerConfig + Converter LogNoteConverter + Repository Repository +} + +func (tr LogNoteTransformer) NewLogNoteTransformer(db *postgres.DB) transformer.EventTransformer { + tr.Repository.SetDB(db) + return tr +} + +func (tr LogNoteTransformer) Execute(logs []types.Log, header core.Header, recheckedHeader constants.TransformerExecution) error { + transformerName := tr.Config.TransformerName + + // No matching logs, mark the header as checked for this type of logs + if len(logs) < 1 { + err := tr.Repository.MarkHeaderChecked(header.Id) + if err != nil { + log.Printf("Error marking header as checked in %v: %v", transformerName, err) + return err + } + return nil + } + + models, err := tr.Converter.ToModels(logs) + if err != nil { + log.Printf("Error converting logs in %v: %v", transformerName, err) + return err + } + + err = tr.Repository.Create(header.Id, models) + if err != nil { + log.Printf("Error persisting %v record: %v", transformerName, err) + return err + } + return nil +} + +func (tr LogNoteTransformer) GetName() string { + return tr.Config.TransformerName +} + +func (tr LogNoteTransformer) GetConfig() transformer.TransformerConfig { + return tr.Config +} diff --git a/libraries/shared/factories/log_note_transformer_test.go b/libraries/shared/factories/log_note_transformer_test.go new file mode 100644 index 00000000..6d8ea569 --- /dev/null +++ b/libraries/shared/factories/log_note_transformer_test.go @@ -0,0 +1,126 @@ +// VulcanizeDB +// Copyright © 2018 Vulcanize + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. + +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package factories_test + +import ( + "math/rand" + + "github.com/ethereum/go-ethereum/core/types" + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + + "github.com/vulcanize/vulcanizedb/libraries/shared/constants" + "github.com/vulcanize/vulcanizedb/libraries/shared/factories" + "github.com/vulcanize/vulcanizedb/libraries/shared/mocks" + "github.com/vulcanize/vulcanizedb/libraries/shared/test_data" + "github.com/vulcanize/vulcanizedb/libraries/shared/transformer" + "github.com/vulcanize/vulcanizedb/pkg/core" + "github.com/vulcanize/vulcanizedb/pkg/fakes" +) + +var _ = Describe("LogNoteTransformer", func() { + var ( + repository mocks.MockRepository + converter mocks.MockLogNoteConverter + headerOne core.Header + t transformer.EventTransformer + model test_data.GenericModel + config = test_data.GenericTestConfig + logs = test_data.GenericTestLogs + ) + + BeforeEach(func() { + repository = mocks.MockRepository{} + converter = mocks.MockLogNoteConverter{} + t = factories.LogNoteTransformer{ + Config: config, + Converter: &converter, + Repository: &repository, + }.NewLogNoteTransformer(nil) + + headerOne = core.Header{Id: rand.Int63(), BlockNumber: rand.Int63()} + }) + + It("sets the database", func() { + Expect(repository.SetDbCalled).To(BeTrue()) + }) + + It("marks header checked if no logs are provided", func() { + err := t.Execute([]types.Log{}, headerOne, constants.HeaderMissing) + + Expect(err).NotTo(HaveOccurred()) + repository.AssertMarkHeaderCheckedCalledWith(headerOne.Id) + }) + + It("doesn't attempt to convert or persist an empty collection when there are no logs", func() { + err := t.Execute([]types.Log{}, headerOne, constants.HeaderMissing) + + Expect(err).NotTo(HaveOccurred()) + Expect(converter.ToModelsCalledCounter).To(Equal(0)) + Expect(repository.CreateCalledCounter).To(Equal(0)) + }) + + It("does not call repository.MarkCheckedHeader when there are logs", func() { + err := t.Execute(logs, headerOne, constants.HeaderMissing) + + Expect(err).NotTo(HaveOccurred()) + repository.AssertMarkHeaderCheckedNotCalled() + }) + + It("returns error if marking header checked returns err", func() { + repository.SetMarkHeaderCheckedError(fakes.FakeError) + + err := t.Execute([]types.Log{}, headerOne, constants.HeaderMissing) + + Expect(err).To(HaveOccurred()) + Expect(err).To(MatchError(fakes.FakeError)) + }) + + It("converts matching logs to models", func() { + err := t.Execute(logs, headerOne, constants.HeaderMissing) + + Expect(err).NotTo(HaveOccurred()) + Expect(converter.PassedLogs).To(Equal(logs)) + }) + + It("returns error if converter returns error", func() { + converter.SetConverterError(fakes.FakeError) + + err := t.Execute(logs, headerOne, constants.HeaderMissing) + + Expect(err).To(HaveOccurred()) + Expect(err).To(MatchError(fakes.FakeError)) + }) + + It("persists the model", func() { + converter.SetReturnModels([]interface{}{model}) + err := t.Execute(logs, headerOne, constants.HeaderMissing) + + Expect(err).NotTo(HaveOccurred()) + Expect(repository.PassedHeaderID).To(Equal(headerOne.Id)) + Expect(repository.PassedModels).To(Equal([]interface{}{model})) + }) + + It("returns error if repository returns error for create", func() { + repository.SetCreateError(fakes.FakeError) + + err := t.Execute(logs, headerOne, constants.HeaderMissing) + + Expect(err).To(HaveOccurred()) + Expect(err).To(MatchError(fakes.FakeError)) + }) +}) diff --git a/libraries/shared/factories/repository.go b/libraries/shared/factories/repository.go new file mode 100644 index 00000000..d953249b --- /dev/null +++ b/libraries/shared/factories/repository.go @@ -0,0 +1,30 @@ +// VulcanizeDB +// Copyright © 2018 Vulcanize + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. + +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package factories + +import ( + "github.com/vulcanize/vulcanizedb/pkg/core" + "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" +) + +type Repository interface { + Create(headerID int64, models []interface{}) error + MarkHeaderChecked(headerID int64) error + MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) + RecheckHeaders(startingBlockNumber, endingBlockNUmber int64) ([]core.Header, error) + SetDB(db *postgres.DB) +} diff --git a/libraries/shared/transformer/EXAMPLE.md b/libraries/shared/factories/storage/EXAMPLE.md similarity index 100% rename from libraries/shared/transformer/EXAMPLE.md rename to libraries/shared/factories/storage/EXAMPLE.md diff --git a/libraries/shared/transformer/README.md b/libraries/shared/factories/storage/README.md similarity index 100% rename from libraries/shared/transformer/README.md rename to libraries/shared/factories/storage/README.md diff --git a/libraries/shared/factories/storage/storage_suite_test.go b/libraries/shared/factories/storage/storage_suite_test.go new file mode 100644 index 00000000..3c2e86b8 --- /dev/null +++ b/libraries/shared/factories/storage/storage_suite_test.go @@ -0,0 +1,29 @@ +// VulcanizeDB +// Copyright © 2018 Vulcanize + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. + +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package storage_test + +import ( + "testing" + + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" +) + +func TestStorage(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "Storage Factories Suite") +} diff --git a/libraries/shared/factories/storage/transformer.go b/libraries/shared/factories/storage/transformer.go new file mode 100644 index 00000000..b3570019 --- /dev/null +++ b/libraries/shared/factories/storage/transformer.go @@ -0,0 +1,55 @@ +// VulcanizeDB +// Copyright © 2018 Vulcanize + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. + +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package storage + +import ( + "github.com/ethereum/go-ethereum/common" + + "github.com/vulcanize/vulcanizedb/libraries/shared/repository" + "github.com/vulcanize/vulcanizedb/libraries/shared/storage" + "github.com/vulcanize/vulcanizedb/libraries/shared/storage/utils" + "github.com/vulcanize/vulcanizedb/libraries/shared/transformer" + "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" +) + +type Transformer struct { + Address common.Address + Mappings storage.Mappings + Repository repository.StorageRepository +} + +func (transformer Transformer) NewTransformer(db *postgres.DB) transformer.StorageTransformer { + transformer.Mappings.SetDB(db) + transformer.Repository.SetDB(db) + return transformer +} + +func (transformer Transformer) ContractAddress() common.Address { + return transformer.Address +} + +func (transformer Transformer) Execute(row utils.StorageDiffRow) error { + metadata, lookupErr := transformer.Mappings.Lookup(row.StorageKey) + if lookupErr != nil { + return lookupErr + } + value, decodeErr := utils.Decode(row, metadata) + if decodeErr != nil { + return decodeErr + } + return transformer.Repository.Create(row.BlockHeight, row.BlockHash.Hex(), metadata, value) +} diff --git a/libraries/shared/factories/storage/transformer_test.go b/libraries/shared/factories/storage/transformer_test.go new file mode 100644 index 00000000..aa80fbfa --- /dev/null +++ b/libraries/shared/factories/storage/transformer_test.go @@ -0,0 +1,103 @@ +// VulcanizeDB +// Copyright © 2018 Vulcanize + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. + +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package storage_test + +import ( + "github.com/ethereum/go-ethereum/common" + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + + "github.com/vulcanize/vulcanizedb/libraries/shared/factories/storage" + "github.com/vulcanize/vulcanizedb/libraries/shared/mocks" + "github.com/vulcanize/vulcanizedb/libraries/shared/storage/utils" + "github.com/vulcanize/vulcanizedb/pkg/fakes" +) + +var _ = Describe("Storage transformer", func() { + var ( + mappings *mocks.MockMappings + repository *mocks.MockStorageRepository + t storage.Transformer + ) + + BeforeEach(func() { + mappings = &mocks.MockMappings{} + repository = &mocks.MockStorageRepository{} + t = storage.Transformer{ + Address: common.Address{}, + Mappings: mappings, + Repository: repository, + } + }) + + It("returns the contract address being watched", func() { + fakeAddress := common.HexToAddress("0x12345") + t.Address = fakeAddress + + Expect(t.ContractAddress()).To(Equal(fakeAddress)) + }) + + It("looks up metadata for storage key", func() { + t.Execute(utils.StorageDiffRow{}) + + Expect(mappings.LookupCalled).To(BeTrue()) + }) + + It("returns error if lookup fails", func() { + mappings.LookupErr = fakes.FakeError + + err := t.Execute(utils.StorageDiffRow{}) + + Expect(err).To(HaveOccurred()) + Expect(err).To(MatchError(fakes.FakeError)) + }) + + It("creates storage row with decoded data", func() { + fakeMetadata := utils.StorageValueMetadata{Type: utils.Address} + mappings.Metadata = fakeMetadata + rawValue := common.HexToAddress("0x12345") + fakeBlockNumber := 123 + fakeBlockHash := "0x67890" + fakeRow := utils.StorageDiffRow{ + Contract: common.Address{}, + BlockHash: common.HexToHash(fakeBlockHash), + BlockHeight: fakeBlockNumber, + StorageKey: common.Hash{}, + StorageValue: rawValue.Hash(), + } + + err := t.Execute(fakeRow) + + Expect(err).NotTo(HaveOccurred()) + Expect(repository.PassedBlockNumber).To(Equal(fakeBlockNumber)) + Expect(repository.PassedBlockHash).To(Equal(common.HexToHash(fakeBlockHash).Hex())) + Expect(repository.PassedMetadata).To(Equal(fakeMetadata)) + Expect(repository.PassedValue.(string)).To(Equal(rawValue.Hex())) + }) + + It("returns error if creating row fails", func() { + rawValue := common.HexToAddress("0x12345") + fakeMetadata := utils.StorageValueMetadata{Type: utils.Address} + mappings.Metadata = fakeMetadata + repository.CreateErr = fakes.FakeError + + err := t.Execute(utils.StorageDiffRow{StorageValue: rawValue.Hash()}) + + Expect(err).To(HaveOccurred()) + Expect(err).To(MatchError(fakes.FakeError)) + }) +}) diff --git a/libraries/shared/factories/transformer.go b/libraries/shared/factories/transformer.go new file mode 100644 index 00000000..7ef882bf --- /dev/null +++ b/libraries/shared/factories/transformer.go @@ -0,0 +1,80 @@ +// VulcanizeDB +// Copyright © 2018 Vulcanize + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. + +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package factories + +import ( + "github.com/ethereum/go-ethereum/core/types" + log "github.com/sirupsen/logrus" + + "github.com/vulcanize/vulcanizedb/libraries/shared/constants" + "github.com/vulcanize/vulcanizedb/libraries/shared/transformer" + "github.com/vulcanize/vulcanizedb/pkg/core" + "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" +) + +type Transformer struct { + Config transformer.TransformerConfig + Converter Converter + Repository Repository +} + +func (transformer Transformer) NewTransformer(db *postgres.DB) transformer.EventTransformer { + transformer.Repository.SetDB(db) + return transformer +} + +func (transformer Transformer) Execute(logs []types.Log, header core.Header, recheckHeaders constants.TransformerExecution) error { + transformerName := transformer.Config.TransformerName + config := transformer.Config + + if len(logs) < 1 { + err := transformer.Repository.MarkHeaderChecked(header.Id) + if err != nil { + log.Printf("Error marking header as checked in %v: %v", transformerName, err) + return err + } + return nil + } + + entities, err := transformer.Converter.ToEntities(config.ContractAbi, logs) + if err != nil { + log.Printf("Error converting logs to entities in %v: %v", transformerName, err) + return err + } + + models, err := transformer.Converter.ToModels(entities) + if err != nil { + log.Printf("Error converting entities to models in %v: %v", transformerName, err) + return err + } + + err = transformer.Repository.Create(header.Id, models) + if err != nil { + log.Printf("Error persisting %v record: %v", transformerName, err) + return err + } + + return nil +} + +func (transformer Transformer) GetName() string { + return transformer.Config.TransformerName +} + +func (transformer Transformer) GetConfig() transformer.TransformerConfig { + return transformer.Config +} diff --git a/libraries/shared/factories/transformer_test.go b/libraries/shared/factories/transformer_test.go new file mode 100644 index 00000000..201044f3 --- /dev/null +++ b/libraries/shared/factories/transformer_test.go @@ -0,0 +1,147 @@ +// VulcanizeDB +// Copyright © 2018 Vulcanize + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. + +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package factories_test + +import ( + "math/rand" + + "github.com/ethereum/go-ethereum/core/types" + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + + "github.com/vulcanize/vulcanizedb/libraries/shared/constants" + "github.com/vulcanize/vulcanizedb/libraries/shared/factories" + "github.com/vulcanize/vulcanizedb/libraries/shared/mocks" + "github.com/vulcanize/vulcanizedb/libraries/shared/test_data" + "github.com/vulcanize/vulcanizedb/libraries/shared/transformer" + "github.com/vulcanize/vulcanizedb/pkg/core" + "github.com/vulcanize/vulcanizedb/pkg/fakes" +) + +var _ = Describe("Transformer", func() { + var ( + repository mocks.MockRepository + converter mocks.MockConverter + t transformer.EventTransformer + headerOne core.Header + config = test_data.GenericTestConfig + logs = test_data.GenericTestLogs + ) + + BeforeEach(func() { + repository = mocks.MockRepository{} + converter = mocks.MockConverter{} + + t = factories.Transformer{ + Repository: &repository, + Converter: &converter, + Config: config, + }.NewTransformer(nil) + + headerOne = core.Header{Id: rand.Int63(), BlockNumber: rand.Int63()} + }) + + It("sets the db", func() { + Expect(repository.SetDbCalled).To(BeTrue()) + }) + + It("marks header checked if no logs returned", func() { + err := t.Execute([]types.Log{}, headerOne, constants.HeaderMissing) + + Expect(err).NotTo(HaveOccurred()) + repository.AssertMarkHeaderCheckedCalledWith(headerOne.Id) + }) + + It("doesn't attempt to convert or persist an empty collection when there are no logs", func() { + err := t.Execute([]types.Log{}, headerOne, constants.HeaderMissing) + + Expect(err).NotTo(HaveOccurred()) + Expect(converter.ToEntitiesCalledCounter).To(Equal(0)) + Expect(converter.ToModelsCalledCounter).To(Equal(0)) + Expect(repository.CreateCalledCounter).To(Equal(0)) + }) + + It("does not call repository.MarkCheckedHeader when there are logs", func() { + err := t.Execute(logs, headerOne, constants.HeaderMissing) + + Expect(err).NotTo(HaveOccurred()) + repository.AssertMarkHeaderCheckedNotCalled() + }) + + It("returns error if marking header checked returns err", func() { + repository.SetMarkHeaderCheckedError(fakes.FakeError) + + err := t.Execute([]types.Log{}, headerOne, constants.HeaderMissing) + + Expect(err).To(HaveOccurred()) + Expect(err).To(MatchError(fakes.FakeError)) + }) + + It("converts an eth log to an entity", func() { + err := t.Execute(logs, headerOne, constants.HeaderMissing) + + Expect(err).NotTo(HaveOccurred()) + Expect(converter.ContractAbi).To(Equal(config.ContractAbi)) + Expect(converter.LogsToConvert).To(Equal(logs)) + }) + + It("returns an error if converter fails", func() { + converter.ToEntitiesError = fakes.FakeError + + err := t.Execute(logs, headerOne, constants.HeaderMissing) + + Expect(err).To(HaveOccurred()) + Expect(err).To(MatchError(fakes.FakeError)) + }) + + It("converts an entity to a model", func() { + converter.EntitiesToReturn = []interface{}{test_data.GenericEntity{}} + + err := t.Execute(logs, headerOne, constants.HeaderMissing) + + Expect(err).NotTo(HaveOccurred()) + Expect(converter.EntitiesToConvert[0]).To(Equal(test_data.GenericEntity{})) + }) + + It("returns an error if converting to models fails", func() { + converter.EntitiesToReturn = []interface{}{test_data.GenericEntity{}} + converter.ToModelsError = fakes.FakeError + + err := t.Execute(logs, headerOne, constants.HeaderMissing) + + Expect(err).To(HaveOccurred()) + Expect(err).To(MatchError(fakes.FakeError)) + }) + + It("persists the record", func() { + converter.ModelsToReturn = []interface{}{test_data.GenericModel{}} + + err := t.Execute(logs, headerOne, constants.HeaderMissing) + + Expect(err).NotTo(HaveOccurred()) + Expect(repository.PassedHeaderID).To(Equal(headerOne.Id)) + Expect(repository.PassedModels[0]).To(Equal(test_data.GenericModel{})) + }) + + It("returns error if persisting the record fails", func() { + repository.SetCreateError(fakes.FakeError) + err := t.Execute(logs, headerOne, constants.HeaderMissing) + + Expect(err).To(HaveOccurred()) + Expect(err).To(MatchError(fakes.FakeError)) + }) +}) diff --git a/libraries/shared/fetcher/fetcher_suite_test.go b/libraries/shared/fetcher/fetcher_suite_test.go new file mode 100644 index 00000000..09f024bd --- /dev/null +++ b/libraries/shared/fetcher/fetcher_suite_test.go @@ -0,0 +1,35 @@ +// VulcanizeDB +// Copyright © 2018 Vulcanize + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. + +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package fetcher_test + +import ( + "testing" + + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + log "github.com/sirupsen/logrus" + "io/ioutil" +) + +func TestFactories(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "Shared Fetcher Suite") +} + +var _ = BeforeSuite(func() { + log.SetOutput(ioutil.Discard) +}) diff --git a/libraries/shared/mocks/converter.go b/libraries/shared/mocks/converter.go new file mode 100644 index 00000000..0d5a2ae3 --- /dev/null +++ b/libraries/shared/mocks/converter.go @@ -0,0 +1,58 @@ +// VulcanizeDB +// Copyright © 2018 Vulcanize + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. + +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package mocks + +import ( + "github.com/ethereum/go-ethereum/core/types" +) + +type MockConverter struct { + ToEntitiesError error + PassedContractAddresses []string + ToModelsError error + entityConverterError error + modelConverterError error + ContractAbi string + LogsToConvert []types.Log + EntitiesToConvert []interface{} + EntitiesToReturn []interface{} + ModelsToReturn []interface{} + ToEntitiesCalledCounter int + ToModelsCalledCounter int +} + +func (converter *MockConverter) ToEntities(contractAbi string, ethLogs []types.Log) ([]interface{}, error) { + for _, log := range ethLogs { + converter.PassedContractAddresses = append(converter.PassedContractAddresses, log.Address.Hex()) + } + converter.ContractAbi = contractAbi + converter.LogsToConvert = ethLogs + return converter.EntitiesToReturn, converter.ToEntitiesError +} + +func (converter *MockConverter) ToModels(entities []interface{}) ([]interface{}, error) { + converter.EntitiesToConvert = entities + return converter.ModelsToReturn, converter.ToModelsError +} + +func (converter *MockConverter) SetToEntityConverterError(err error) { + converter.entityConverterError = err +} + +func (c *MockConverter) SetToModelConverterError(err error) { + c.modelConverterError = err +} diff --git a/libraries/shared/mocks/log_note_converter.go b/libraries/shared/mocks/log_note_converter.go new file mode 100644 index 00000000..1ab9312a --- /dev/null +++ b/libraries/shared/mocks/log_note_converter.go @@ -0,0 +1,42 @@ +// VulcanizeDB +// Copyright © 2018 Vulcanize + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. + +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package mocks + +import ( + "github.com/ethereum/go-ethereum/core/types" +) + +type MockLogNoteConverter struct { + err error + returnModels []interface{} + PassedLogs []types.Log + ToModelsCalledCounter int +} + +func (converter *MockLogNoteConverter) ToModels(ethLogs []types.Log) ([]interface{}, error) { + converter.PassedLogs = ethLogs + converter.ToModelsCalledCounter++ + return converter.returnModels, converter.err +} + +func (converter *MockLogNoteConverter) SetConverterError(e error) { + converter.err = e +} + +func (converter *MockLogNoteConverter) SetReturnModels(models []interface{}) { + converter.returnModels = models +} diff --git a/libraries/shared/mocks/mappings.go b/libraries/shared/mocks/mappings.go new file mode 100644 index 00000000..0ad0dee9 --- /dev/null +++ b/libraries/shared/mocks/mappings.go @@ -0,0 +1,39 @@ +// VulcanizeDB +// Copyright © 2018 Vulcanize + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. + +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package mocks + +import ( + "github.com/ethereum/go-ethereum/common" + + "github.com/vulcanize/vulcanizedb/libraries/shared/storage/utils" + "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" +) + +type MockMappings struct { + Metadata utils.StorageValueMetadata + LookupCalled bool + LookupErr error +} + +func (mappings *MockMappings) Lookup(key common.Hash) (utils.StorageValueMetadata, error) { + mappings.LookupCalled = true + return mappings.Metadata, mappings.LookupErr +} + +func (*MockMappings) SetDB(db *postgres.DB) { + panic("implement me") +} diff --git a/libraries/shared/mocks/repository.go b/libraries/shared/mocks/repository.go new file mode 100644 index 00000000..4bd39e64 --- /dev/null +++ b/libraries/shared/mocks/repository.go @@ -0,0 +1,98 @@ +// VulcanizeDB +// Copyright © 2018 Vulcanize + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. + +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package mocks + +import ( + . "github.com/onsi/gomega" + + "github.com/vulcanize/vulcanizedb/pkg/core" + "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" +) + +type MockRepository struct { + createError error + markHeaderCheckedError error + MarkHeaderCheckedPassedHeaderIDs []int64 + CreatedHeaderIds []int64 + missingHeaders []core.Header + allHeaders []core.Header + missingHeadersError error + PassedStartingBlockNumber int64 + PassedEndingBlockNumber int64 + PassedHeaderID int64 + PassedModels []interface{} + SetDbCalled bool + CreateCalledCounter int +} + +func (repository *MockRepository) Create(headerID int64, models []interface{}) error { + repository.PassedHeaderID = headerID + repository.PassedModels = models + repository.CreatedHeaderIds = append(repository.CreatedHeaderIds, headerID) + repository.CreateCalledCounter++ + + return repository.createError +} + +func (repository *MockRepository) MarkHeaderChecked(headerID int64) error { + repository.MarkHeaderCheckedPassedHeaderIDs = append(repository.MarkHeaderCheckedPassedHeaderIDs, headerID) + return repository.markHeaderCheckedError +} + +func (repository *MockRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { + repository.PassedStartingBlockNumber = startingBlockNumber + repository.PassedEndingBlockNumber = endingBlockNumber + return repository.missingHeaders, repository.missingHeadersError +} + +func (repository *MockRepository) RecheckHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { + repository.PassedStartingBlockNumber = startingBlockNumber + repository.PassedEndingBlockNumber = endingBlockNumber + return repository.allHeaders, nil +} + +func (repository *MockRepository) SetDB(db *postgres.DB) { + repository.SetDbCalled = true +} + +func (repository *MockRepository) SetMissingHeadersError(e error) { + repository.missingHeadersError = e +} + +func (repository *MockRepository) SetAllHeaders(headers []core.Header) { + repository.allHeaders = headers +} + +func (repository *MockRepository) SetMissingHeaders(headers []core.Header) { + repository.missingHeaders = headers +} + +func (repository *MockRepository) SetMarkHeaderCheckedError(e error) { + repository.markHeaderCheckedError = e +} + +func (repository *MockRepository) SetCreateError(e error) { + repository.createError = e +} + +func (repository *MockRepository) AssertMarkHeaderCheckedCalledWith(i int64) { + Expect(repository.MarkHeaderCheckedPassedHeaderIDs).To(ContainElement(i)) +} + +func (repository *MockRepository) AssertMarkHeaderCheckedNotCalled() { + Expect(len(repository.MarkHeaderCheckedPassedHeaderIDs)).To(Equal(0)) +} diff --git a/libraries/shared/mocks/storage_queue.go b/libraries/shared/mocks/storage_queue.go new file mode 100644 index 00000000..ea668e54 --- /dev/null +++ b/libraries/shared/mocks/storage_queue.go @@ -0,0 +1,31 @@ +// VulcanizeDB +// Copyright © 2018 Vulcanize + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. + +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package mocks + +import ( + "github.com/vulcanize/vulcanizedb/libraries/shared/storage/utils" +) + +type MockStorageQueue struct { + AddCalled bool + AddError error +} + +func (queue *MockStorageQueue) Add(row utils.StorageDiffRow) error { + queue.AddCalled = true + return queue.AddError +} diff --git a/libraries/shared/mocks/storage_repository.go b/libraries/shared/mocks/storage_repository.go new file mode 100644 index 00000000..a370e745 --- /dev/null +++ b/libraries/shared/mocks/storage_repository.go @@ -0,0 +1,42 @@ +// VulcanizeDB +// Copyright © 2018 Vulcanize + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. + +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package mocks + +import ( + "github.com/vulcanize/vulcanizedb/libraries/shared/storage/utils" + "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" +) + +type MockStorageRepository struct { + CreateErr error + PassedBlockNumber int + PassedBlockHash string + PassedMetadata utils.StorageValueMetadata + PassedValue interface{} +} + +func (repository *MockStorageRepository) Create(blockNumber int, blockHash string, metadata utils.StorageValueMetadata, value interface{}) error { + repository.PassedBlockNumber = blockNumber + repository.PassedBlockHash = blockHash + repository.PassedMetadata = metadata + repository.PassedValue = value + return repository.CreateErr +} + +func (*MockStorageRepository) SetDB(db *postgres.DB) { + panic("implement me") +} diff --git a/libraries/shared/repository/repository.go b/libraries/shared/repository/repository.go index 35dd6935..04d9ea4c 100644 --- a/libraries/shared/repository/repository.go +++ b/libraries/shared/repository/repository.go @@ -27,30 +27,6 @@ import ( "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" ) -func GetOrCreateIlk(ilk string, db *postgres.DB) (int, error) { - var ilkID int - err := db.Get(&ilkID, `SELECT id FROM maker.ilks WHERE ilk = $1`, ilk) - if err != nil { - if err == sql.ErrNoRows { - insertErr := db.QueryRow(`INSERT INTO maker.ilks (ilk) VALUES ($1) RETURNING id`, ilk).Scan(&ilkID) - return ilkID, insertErr - } - } - return ilkID, err -} - -func GetOrCreateIlkInTransaction(ilk string, tx *sql.Tx) (int, error) { - var ilkID int - err := tx.QueryRow(`SELECT id FROM maker.ilks WHERE ilk = $1`, ilk).Scan(&ilkID) - if err != nil { - if err == sql.ErrNoRows { - insertErr := tx.QueryRow(`INSERT INTO maker.ilks (ilk) VALUES ($1) RETURNING id`, ilk).Scan(&ilkID) - return ilkID, insertErr - } - } - return ilkID, err -} - func MarkHeaderChecked(headerID int64, db *postgres.DB, checkedHeadersColumn string) error { _, err := db.Exec(`INSERT INTO public.checked_headers (header_id, `+checkedHeadersColumn+`) VALUES ($1, $2) diff --git a/libraries/shared/repository/repository_suite_test.go b/libraries/shared/repository/repository_suite_test.go new file mode 100644 index 00000000..3e467abc --- /dev/null +++ b/libraries/shared/repository/repository_suite_test.go @@ -0,0 +1,35 @@ +// VulcanizeDB +// Copyright © 2018 Vulcanize + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. + +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package repository_test + +import ( + "testing" + + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + log "github.com/sirupsen/logrus" + "io/ioutil" +) + +func TestFactories(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "Shared Repository Suite") +} + +var _ = BeforeSuite(func() { + log.SetOutput(ioutil.Discard) +}) diff --git a/libraries/shared/repository/repository_utility_test.go b/libraries/shared/repository/repository_utility_test.go index a66e3838..09791ec0 100644 --- a/libraries/shared/repository/repository_utility_test.go +++ b/libraries/shared/repository/repository_utility_test.go @@ -30,6 +30,7 @@ import ( "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories" "github.com/vulcanize/vulcanizedb/pkg/fakes" + r2 "github.com/vulcanize/vulcanizedb/pkg/omni/light/repository" "github.com/vulcanize/vulcanizedb/test_config" ) @@ -45,12 +46,15 @@ var _ = Describe("Repository utilities", func() { headerIDs []int64 notCheckedSQL string err error + hr r2.HeaderRepository ) BeforeEach(func() { db = test_config.NewTestDB(test_config.NewTestNode()) test_config.CleanTestDB(db) headerRepository = repositories.NewHeaderRepository(db) + hr = r2.NewHeaderRepository(db) + hr.AddCheckColumns(getExpectedColumnNames()) columnNames, err := shared.GetCheckedColumnNames(db) Expect(err).NotTo(HaveOccurred()) @@ -71,6 +75,10 @@ var _ = Describe("Repository utilities", func() { } }) + AfterEach(func() { + test_config.CleanCheckedHeadersTable(db, getExpectedColumnNames()) + }) + It("only treats headers as checked if the event specific logs have been checked", func() { _, err = db.Exec(`INSERT INTO public.checked_headers (header_id) VALUES ($1)`, headerIDs[1]) Expect(err).NotTo(HaveOccurred()) @@ -111,11 +119,14 @@ var _ = Describe("Repository utilities", func() { Describe("GetCheckedColumnNames", func() { It("gets the column names from checked_headers", func() { db := test_config.NewTestDB(test_config.NewTestNode()) + hr := r2.NewHeaderRepository(db) + hr.AddCheckColumns(getExpectedColumnNames()) test_config.CleanTestDB(db) expectedColumnNames := getExpectedColumnNames() actualColumnNames, err := shared.GetCheckedColumnNames(db) Expect(err).NotTo(HaveOccurred()) Expect(actualColumnNames).To(Equal(expectedColumnNames)) + test_config.CleanCheckedHeadersTable(db, getExpectedColumnNames()) }) }) diff --git a/libraries/shared/storage/storage_queue.go b/libraries/shared/storage/storage_queue.go new file mode 100644 index 00000000..9c5c7135 --- /dev/null +++ b/libraries/shared/storage/storage_queue.go @@ -0,0 +1,42 @@ +// VulcanizeDB +// Copyright © 2018 Vulcanize + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. + +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package storage + +import ( + "github.com/vulcanize/vulcanizedb/libraries/shared/storage/utils" + "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" +) + +type IStorageQueue interface { + Add(row utils.StorageDiffRow) error +} + +type StorageQueue struct { + db *postgres.DB +} + +func NewStorageQueue(db *postgres.DB) StorageQueue { + return StorageQueue{db: db} +} + +func (queue StorageQueue) Add(row utils.StorageDiffRow) error { + _, err := queue.db.Exec(`INSERT INTO public.queued_storage (contract, + block_hash, block_height, storage_key, storage_value) VALUES + ($1, $2, $3, $4, $5)`, row.Contract.Bytes(), row.BlockHash.Bytes(), + row.BlockHeight, row.StorageKey.Bytes(), row.StorageValue.Bytes()) + return err +} diff --git a/libraries/shared/storage_queue_test.go b/libraries/shared/storage/storage_queue_test.go similarity index 75% rename from libraries/shared/storage_queue_test.go rename to libraries/shared/storage/storage_queue_test.go index c1d7349f..9157fcda 100644 --- a/libraries/shared/storage_queue_test.go +++ b/libraries/shared/storage/storage_queue_test.go @@ -1,17 +1,18 @@ -package shared_test +package storage_test import ( "github.com/ethereum/go-ethereum/common" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - shared2 "github.com/vulcanize/vulcanizedb/libraries/shared" - "github.com/vulcanize/vulcanizedb/pkg/transformers/storage_diffs/shared" + + "github.com/vulcanize/vulcanizedb/libraries/shared/storage" + "github.com/vulcanize/vulcanizedb/libraries/shared/storage/utils" "github.com/vulcanize/vulcanizedb/test_config" ) var _ = Describe("Storage queue", func() { It("adds a storage row to the db", func() { - row := shared.StorageDiffRow{ + row := utils.StorageDiffRow{ Contract: common.HexToAddress("0x123456"), BlockHash: common.HexToHash("0x678901"), BlockHeight: 987, @@ -19,12 +20,12 @@ var _ = Describe("Storage queue", func() { StorageValue: common.HexToHash("0x198765"), } db := test_config.NewTestDB(test_config.NewTestNode()) - queue := shared2.NewStorageQueue(db) + queue := storage.NewStorageQueue(db) addErr := queue.Add(row) Expect(addErr).NotTo(HaveOccurred()) - var result shared.StorageDiffRow + var result utils.StorageDiffRow getErr := db.Get(&result, `SELECT contract, block_hash, block_height, storage_key, storage_value FROM public.queued_storage`) Expect(getErr).NotTo(HaveOccurred()) Expect(result).To(Equal(row)) diff --git a/libraries/shared/storage/storage_suite_test.go b/libraries/shared/storage/storage_suite_test.go new file mode 100644 index 00000000..7773fc65 --- /dev/null +++ b/libraries/shared/storage/storage_suite_test.go @@ -0,0 +1,35 @@ +// VulcanizeDB +// Copyright © 2018 Vulcanize + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. + +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package storage_test + +import ( + "testing" + + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + log "github.com/sirupsen/logrus" + "io/ioutil" +) + +func TestFactories(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "Shared Storage Suite") +} + +var _ = BeforeSuite(func() { + log.SetOutput(ioutil.Discard) +}) diff --git a/libraries/shared/storage/utils/utils_suite_test.go b/libraries/shared/storage/utils/utils_suite_test.go index 15f6b76c..e5bc1ace 100644 --- a/libraries/shared/storage/utils/utils_suite_test.go +++ b/libraries/shared/storage/utils/utils_suite_test.go @@ -27,7 +27,7 @@ import ( func TestShared(t *testing.T) { RegisterFailHandler(Fail) - RunSpecs(t, "Storage Utils Suite") + RunSpecs(t, "Shared Storage Utils Suite") } var _ = BeforeSuite(func() { diff --git a/libraries/shared/storage/utils/value.go b/libraries/shared/storage/utils/value.go index 6207da2d..bbefb1d7 100644 --- a/libraries/shared/storage/utils/value.go +++ b/libraries/shared/storage/utils/value.go @@ -26,12 +26,6 @@ const ( type Key string -const ( - Ilk Key = "ilk" - Guy Key = "guy" - Flip Key = "flip" -) - type StorageValueMetadata struct { Name string Keys map[Key]string diff --git a/libraries/shared/storage_queue.go b/libraries/shared/storage_queue.go deleted file mode 100644 index 485c1a76..00000000 --- a/libraries/shared/storage_queue.go +++ /dev/null @@ -1,26 +0,0 @@ -package shared - -import ( - "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" - "github.com/vulcanize/vulcanizedb/pkg/transformers/storage_diffs/shared" -) - -type IStorageQueue interface { - Add(row shared.StorageDiffRow) error -} - -type StorageQueue struct { - db *postgres.DB -} - -func NewStorageQueue(db *postgres.DB) StorageQueue { - return StorageQueue{db: db} -} - -func (queue StorageQueue) Add(row shared.StorageDiffRow) error { - _, err := queue.db.Exec(`INSERT INTO public.queued_storage (contract, - block_hash, block_height, storage_key, storage_value) VALUES - ($1, $2, $3, $4, $5)`, row.Contract.Bytes(), row.BlockHash.Bytes(), - row.BlockHeight, row.StorageKey.Bytes(), row.StorageValue.Bytes()) - return err -} diff --git a/libraries/shared/test_data/generic.go b/libraries/shared/test_data/generic.go new file mode 100644 index 00000000..d4a34a7a --- /dev/null +++ b/libraries/shared/test_data/generic.go @@ -0,0 +1,61 @@ +// VulcanizeDB +// Copyright © 2018 Vulcanize + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. + +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package test_data + +import ( + "math/rand" + "time" + + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" + + "github.com/vulcanize/vulcanizedb/libraries/shared/transformer" +) + +type GenericModel struct{} +type GenericEntity struct{} + +var startingBlockNumber = rand.Int63() +var topic = "0x" + randomString(64) +var address = "0x" + randomString(38) + +var GenericTestLogs = []types.Log{{ + Address: common.HexToAddress(address), + Topics: []common.Hash{common.HexToHash(topic)}, + BlockNumber: uint64(startingBlockNumber), +}} + +var GenericTestConfig = transformer.TransformerConfig{ + TransformerName: "generic-test-transformer", + ContractAddresses: []string{address}, + ContractAbi: randomString(100), + Topic: topic, + StartingBlockNumber: startingBlockNumber, + EndingBlockNumber: startingBlockNumber + 1, +} + +func randomString(length int) string { + var seededRand *rand.Rand = rand.New( + rand.NewSource(time.Now().UnixNano())) + charset := "abcdefghijklmnopqrstuvwxyz1234567890" + b := make([]byte, length) + for i := range b { + b[i] = charset[seededRand.Intn(len(charset))] + } + + return string(b) +} diff --git a/libraries/shared/watcher/storage_watcher.go b/libraries/shared/watcher/storage_watcher.go index 64dd31e7..87d078a0 100644 --- a/libraries/shared/watcher/storage_watcher.go +++ b/libraries/shared/watcher/storage_watcher.go @@ -17,12 +17,13 @@ package watcher import ( - "strings" "reflect" + "strings" "github.com/ethereum/go-ethereum/common" "github.com/sirupsen/logrus" + "github.com/vulcanize/vulcanizedb/libraries/shared/storage" "github.com/vulcanize/vulcanizedb/libraries/shared/storage/utils" "github.com/vulcanize/vulcanizedb/libraries/shared/transformer" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" @@ -32,13 +33,13 @@ import ( type StorageWatcher struct { db *postgres.DB tailer fs.Tailer - Queue IStorageQueue + Queue storage.IStorageQueue Transformers map[common.Address]transformer.StorageTransformer } func NewStorageWatcher(tailer fs.Tailer, db *postgres.DB) StorageWatcher { transformers := make(map[common.Address]transformer.StorageTransformer) - queue := NewStorageQueue(db) + queue := storage.NewStorageQueue(db) return StorageWatcher{ db: db, tailer: tailer, diff --git a/pkg/omni/shared/helpers/test_helpers/database.go b/pkg/omni/shared/helpers/test_helpers/database.go index 4c3c5059..1b9558b4 100644 --- a/pkg/omni/shared/helpers/test_helpers/database.go +++ b/pkg/omni/shared/helpers/test_helpers/database.go @@ -257,17 +257,10 @@ func TearDown(db *postgres.DB) { _, err = tx.Exec(`DELETE FROM receipts`) Expect(err).NotTo(HaveOccurred()) - _, err = tx.Exec(`ALTER TABLE checked_headers -DROP COLUMN IF EXISTS eventName_contractAddr, -DROP COLUMN IF EXISTS eventName_contractAddr2, -DROP COLUMN IF EXISTS eventName_contractAddr3, -DROP COLUMN IF EXISTS methodName_contractAddr, -DROP COLUMN IF EXISTS methodName_contractAddr2, -DROP COLUMN IF EXISTS methodName_contractAddr3, -DROP COLUMN IF EXISTS transfer_0x8dd5fbce2f6a956c3022ba3663759011dd51e73e, -DROP COLUMN IF EXISTS balanceof_0x8dd5fbce2f6a956c3022ba3663759011dd51e73e, -DROP COLUMN IF EXISTS newowner_0x314159265dd8dbb310642f98f50c066173c1259b, -DROP COLUMN IF EXISTS owner_0x314159265dd8dbb310642f98f50c066173c1259b`) + _, err = tx.Exec(`DROP TABLE checked_headers`) + Expect(err).NotTo(HaveOccurred()) + + _, err = tx.Exec(`CREATE TABLE checked_headers (id SERIAL PRIMARY KEY, header_id INTEGER UNIQUE NOT NULL REFERENCES headers (id) ON DELETE CASCADE);`) Expect(err).NotTo(HaveOccurred()) _, err = tx.Exec(`DROP SCHEMA IF EXISTS full_0x8dd5fbce2f6a956c3022ba3663759011dd51e73e CASCADE`) diff --git a/pkg/plugin/helpers/helpers.go b/pkg/plugin/helpers/helpers.go index dfefa9b0..2885cbef 100644 --- a/pkg/plugin/helpers/helpers.go +++ b/pkg/plugin/helpers/helpers.go @@ -62,18 +62,16 @@ func CopyFile(src, dst string) error { if err != nil { return err } + defer in.Close() out, err := os.OpenFile(dst, syscall.O_CREAT|syscall.O_EXCL|os.O_WRONLY, os.FileMode(0666)) // Doesn't overwrite files if err != nil { - in.Close() return err } + defer out.Close() _, err = io.Copy(out, in) if err != nil { - in.Close() - out.Close() return err } - in.Close() return out.Close() } diff --git a/pkg/transformers/bite/repository.go b/pkg/transformers/bite/repository.go deleted file mode 100644 index 927dc032..00000000 --- a/pkg/transformers/bite/repository.go +++ /dev/null @@ -1,99 +0,0 @@ -// VulcanizeDB -// Copyright © 2018 Vulcanize - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. - -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -package bite - -import ( - "fmt" - - log "github.com/sirupsen/logrus" - - "github.com/vulcanize/vulcanizedb/pkg/core" - "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" -) - -type BiteRepository struct { - db *postgres.DB -} - -func (repository *BiteRepository) SetDB(db *postgres.DB) { - repository.db = db -} - -func (repository BiteRepository) Create(headerID int64, models []interface{}) error { - tx, dBaseErr := repository.db.Begin() - if dBaseErr != nil { - return dBaseErr - } - for _, model := range models { - biteModel, ok := model.(BiteModel) - if !ok { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - log.Error("failed to rollback ", rollbackErr) - } - return fmt.Errorf("model of type %T, not %T", model, BiteModel{}) - } - - ilkID, ilkErr := shared.GetOrCreateIlkInTransaction(biteModel.Ilk, tx) - if ilkErr != nil { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - log.Error("failed to rollback ", rollbackErr) - } - return ilkErr - } - - _, execErr := tx.Exec( - `INSERT into maker.bite (header_id, ilk, urn, ink, art, iart, tab, nflip, log_idx, tx_idx, raw_log) - VALUES($1, $2, $3, $4::NUMERIC, $5::NUMERIC, $6::NUMERIC, $7::NUMERIC, $8::NUMERIC, $9, $10, $11) - ON CONFLICT (header_id, tx_idx, log_idx) DO UPDATE SET ilk = $2, urn = $3, ink = $4, art = $5, iart = $6, tab = $7, nflip = $8, raw_log = $11;`, - headerID, ilkID, biteModel.Urn, biteModel.Ink, biteModel.Art, biteModel.IArt, biteModel.Tab, biteModel.NFlip, biteModel.LogIndex, biteModel.TransactionIndex, biteModel.Raw, - ) - if execErr != nil { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - log.Error("failed to rollback ", rollbackErr) - } - return execErr - } - } - - checkHeaderErr := shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.BiteChecked) - if checkHeaderErr != nil { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - log.Error("failed to rollback ", rollbackErr) - } - return checkHeaderErr - } - - return tx.Commit() -} - -func (repository BiteRepository) MarkHeaderChecked(headerID int64) error { - return shared.MarkHeaderChecked(headerID, repository.db, constants.BiteChecked) -} - -func (repository BiteRepository) MissingHeaders(startingBlockNumber int64, endingBlockNumber int64) ([]core.Header, error) { - return shared.MissingHeaders(startingBlockNumber, endingBlockNumber, repository.db, constants.BiteChecked) -} - -func (repository BiteRepository) RecheckHeaders(startingBlockNumber int64, endingBlockNumber int64) ([]core.Header, error) { - return shared.RecheckHeaders(startingBlockNumber, endingBlockNumber, repository.db, constants.BiteChecked) -} diff --git a/pkg/transformers/bite/repository_test.go b/pkg/transformers/bite/repository_test.go deleted file mode 100644 index dc0f2b0c..00000000 --- a/pkg/transformers/bite/repository_test.go +++ /dev/null @@ -1,95 +0,0 @@ -// VulcanizeDB -// Copyright © 2018 Vulcanize - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. - -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -package bite_test - -import ( - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" - "strconv" - - "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" - "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories" - "github.com/vulcanize/vulcanizedb/pkg/fakes" - "github.com/vulcanize/vulcanizedb/pkg/transformers/bite" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" - "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" - "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/shared_behaviors" - "github.com/vulcanize/vulcanizedb/test_config" -) - -var _ = Describe("Bite repository", func() { - var ( - biteRepository bite.BiteRepository - db *postgres.DB - ) - - BeforeEach(func() { - db = test_config.NewTestDB(test_config.NewTestNode()) - test_config.CleanTestDB(db) - biteRepository = bite.BiteRepository{} - biteRepository.SetDB(db) - }) - - Describe("Create", func() { - modelWithDifferentLogIdx := test_data.BiteModel - modelWithDifferentLogIdx.LogIndex++ - inputs := shared_behaviors.CreateBehaviorInputs{ - CheckedHeaderColumnName: constants.BiteChecked, - LogEventTableName: "maker.bite", - TestModel: test_data.BiteModel, - ModelWithDifferentLogIdx: modelWithDifferentLogIdx, - Repository: &biteRepository, - } - - shared_behaviors.SharedRepositoryCreateBehaviors(&inputs) - - It("persists a bite record", func() { - headerRepository := repositories.NewHeaderRepository(db) - headerID, err := headerRepository.CreateOrUpdateHeader(fakes.FakeHeader) - Expect(err).NotTo(HaveOccurred()) - - err = biteRepository.Create(headerID, []interface{}{test_data.BiteModel}) - - Expect(err).NotTo(HaveOccurred()) - var dbBite bite.BiteModel - err = db.Get(&dbBite, `SELECT ilk, urn, ink, art, tab, nflip, iart, log_idx, tx_idx, raw_log FROM maker.bite WHERE header_id = $1`, headerID) - Expect(err).NotTo(HaveOccurred()) - ilkID, err := shared.GetOrCreateIlk(test_data.BiteModel.Ilk, db) - Expect(err).NotTo(HaveOccurred()) - Expect(dbBite.Ilk).To(Equal(strconv.Itoa(ilkID))) - Expect(dbBite.Urn).To(Equal(test_data.BiteModel.Urn)) - Expect(dbBite.Ink).To(Equal(test_data.BiteModel.Ink)) - Expect(dbBite.Art).To(Equal(test_data.BiteModel.Art)) - Expect(dbBite.Tab).To(Equal(test_data.BiteModel.Tab)) - Expect(dbBite.NFlip).To(Equal(test_data.BiteModel.NFlip)) - Expect(dbBite.IArt).To(Equal(test_data.BiteModel.IArt)) - Expect(dbBite.LogIndex).To(Equal(test_data.BiteModel.LogIndex)) - Expect(dbBite.TransactionIndex).To(Equal(test_data.BiteModel.TransactionIndex)) - Expect(dbBite.Raw).To(MatchJSON(test_data.BiteModel.Raw)) - }) - }) - - Describe("MarkHeaderChecked", func() { - inputs := shared_behaviors.MarkedHeaderCheckedBehaviorInputs{ - CheckedHeaderColumnName: constants.BiteChecked, - Repository: &biteRepository, - } - - shared_behaviors.SharedRepositoryMarkHeaderCheckedBehaviors(&inputs) - }) -}) diff --git a/pkg/transformers/cat_file/chop_lump/repository.go b/pkg/transformers/cat_file/chop_lump/repository.go deleted file mode 100644 index 4cc68b2e..00000000 --- a/pkg/transformers/cat_file/chop_lump/repository.go +++ /dev/null @@ -1,99 +0,0 @@ -// VulcanizeDB -// Copyright © 2018 Vulcanize - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. - -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -package chop_lump - -import ( - "fmt" - - log "github.com/sirupsen/logrus" - - "github.com/vulcanize/vulcanizedb/pkg/core" - "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" -) - -type CatFileChopLumpRepository struct { - db *postgres.DB -} - -func (repository CatFileChopLumpRepository) Create(headerID int64, models []interface{}) error { - tx, dBaseErr := repository.db.Begin() - if dBaseErr != nil { - return dBaseErr - } - - for _, model := range models { - chopLump, ok := model.(CatFileChopLumpModel) - if !ok { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - log.Error("failed to rollback ", rollbackErr) - } - return fmt.Errorf("model of type %T, not %T", model, CatFileChopLumpModel{}) - } - - ilkID, ilkErr := shared.GetOrCreateIlkInTransaction(chopLump.Ilk, tx) - if ilkErr != nil { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - log.Error("failed to rollback ", rollbackErr) - } - return ilkErr - } - - _, execErr := tx.Exec( - `INSERT into maker.cat_file_chop_lump (header_id, ilk, what, data, tx_idx, log_idx, raw_log) - VALUES($1, $2, $3, $4::NUMERIC, $5, $6, $7) - ON CONFLICT (header_id, tx_idx, log_idx) DO UPDATE SET ilk = $2, what = $3, data = $4, raw_log = $7;`, - headerID, ilkID, chopLump.What, chopLump.Data, chopLump.TransactionIndex, chopLump.LogIndex, chopLump.Raw, - ) - if execErr != nil { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - log.Error("failed to rollback ", rollbackErr) - } - return execErr - } - } - - checkHeaderErr := shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.CatFileChopLumpChecked) - if checkHeaderErr != nil { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - log.Error("failed to rollback ", rollbackErr) - } - return checkHeaderErr - } - return tx.Commit() -} - -func (repository CatFileChopLumpRepository) MarkHeaderChecked(headerID int64) error { - return shared.MarkHeaderChecked(headerID, repository.db, constants.CatFileChopLumpChecked) -} - -func (repository CatFileChopLumpRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { - return shared.MissingHeaders(startingBlockNumber, endingBlockNumber, repository.db, constants.CatFileChopLumpChecked) -} - -func (repository CatFileChopLumpRepository) RecheckHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { - return shared.RecheckHeaders(startingBlockNumber, endingBlockNumber, repository.db, constants.CatFileChopLumpChecked) -} - -func (repository *CatFileChopLumpRepository) SetDB(db *postgres.DB) { - repository.db = db -} diff --git a/pkg/transformers/cat_file/chop_lump/repository_test.go b/pkg/transformers/cat_file/chop_lump/repository_test.go deleted file mode 100644 index 7747a86b..00000000 --- a/pkg/transformers/cat_file/chop_lump/repository_test.go +++ /dev/null @@ -1,109 +0,0 @@ -// VulcanizeDB -// Copyright © 2018 Vulcanize - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. - -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -package chop_lump_test - -import ( - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" - "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories" - "github.com/vulcanize/vulcanizedb/pkg/fakes" - "github.com/vulcanize/vulcanizedb/pkg/transformers/cat_file/chop_lump" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" - "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" - "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/shared_behaviors" - "github.com/vulcanize/vulcanizedb/test_config" - "strconv" -) - -var _ = Describe("Cat file chop lump repository", func() { - var ( - catFileRepository chop_lump.CatFileChopLumpRepository - db *postgres.DB - ) - - BeforeEach(func() { - db = test_config.NewTestDB(test_config.NewTestNode()) - test_config.CleanTestDB(db) - catFileRepository = chop_lump.CatFileChopLumpRepository{} - catFileRepository.SetDB(db) - }) - - Describe("Create", func() { - modelWithDifferentLogIdx := test_data.CatFileChopModel - modelWithDifferentLogIdx.LogIndex++ - inputs := shared_behaviors.CreateBehaviorInputs{ - CheckedHeaderColumnName: constants.CatFileChopLumpChecked, - LogEventTableName: "maker.cat_file_chop_lump", - TestModel: test_data.CatFileChopModel, - ModelWithDifferentLogIdx: modelWithDifferentLogIdx, - Repository: &catFileRepository, - } - - shared_behaviors.SharedRepositoryCreateBehaviors(&inputs) - - It("adds a cat file chop event", func() { - headerRepository := repositories.NewHeaderRepository(db) - headerID, err := headerRepository.CreateOrUpdateHeader(fakes.FakeHeader) - Expect(err).NotTo(HaveOccurred()) - err = catFileRepository.Create(headerID, []interface{}{test_data.CatFileChopModel}) - - Expect(err).NotTo(HaveOccurred()) - var dbResult chop_lump.CatFileChopLumpModel - err = db.Get(&dbResult, `SELECT ilk, what, data, tx_idx, log_idx, raw_log FROM maker.cat_file_chop_lump WHERE header_id = $1`, headerID) - Expect(err).NotTo(HaveOccurred()) - ilkID, err := shared.GetOrCreateIlk(test_data.CatFileChopModel.Ilk, db) - Expect(err).NotTo(HaveOccurred()) - Expect(dbResult.Ilk).To(Equal(strconv.Itoa(ilkID))) - Expect(dbResult.What).To(Equal(test_data.CatFileChopModel.What)) - Expect(dbResult.Data).To(Equal(test_data.CatFileChopModel.Data)) - Expect(dbResult.TransactionIndex).To(Equal(test_data.CatFileChopModel.TransactionIndex)) - Expect(dbResult.LogIndex).To(Equal(test_data.CatFileChopModel.LogIndex)) - Expect(dbResult.Raw).To(MatchJSON(test_data.CatFileChopModel.Raw)) - }) - - It("adds a cat file lump event", func() { - headerRepository := repositories.NewHeaderRepository(db) - headerID, err := headerRepository.CreateOrUpdateHeader(fakes.FakeHeader) - Expect(err).NotTo(HaveOccurred()) - err = catFileRepository.Create(headerID, []interface{}{test_data.CatFileLumpModel}) - - Expect(err).NotTo(HaveOccurred()) - var dbResult chop_lump.CatFileChopLumpModel - err = db.Get(&dbResult, `SELECT ilk, what, data, tx_idx, log_idx, raw_log FROM maker.cat_file_chop_lump WHERE header_id = $1`, headerID) - Expect(err).NotTo(HaveOccurred()) - ilkID, err := shared.GetOrCreateIlk(test_data.CatFileLumpModel.Ilk, db) - Expect(err).NotTo(HaveOccurred()) - Expect(dbResult.Ilk).To(Equal(strconv.Itoa(ilkID))) - Expect(dbResult.What).To(Equal(test_data.CatFileLumpModel.What)) - Expect(dbResult.Data).To(Equal(test_data.CatFileLumpModel.Data)) - Expect(dbResult.TransactionIndex).To(Equal(test_data.CatFileLumpModel.TransactionIndex)) - Expect(dbResult.LogIndex).To(Equal(test_data.CatFileLumpModel.LogIndex)) - Expect(dbResult.Raw).To(MatchJSON(test_data.CatFileLumpModel.Raw)) - }) - }) - - Describe("MarkHeaderChecked", func() { - inputs := shared_behaviors.MarkedHeaderCheckedBehaviorInputs{ - CheckedHeaderColumnName: constants.CatFileChopLumpChecked, - Repository: &catFileRepository, - } - - shared_behaviors.SharedRepositoryMarkHeaderCheckedBehaviors(&inputs) - }) -}) diff --git a/pkg/transformers/drip_drip/repository.go b/pkg/transformers/drip_drip/repository.go deleted file mode 100644 index accf41f6..00000000 --- a/pkg/transformers/drip_drip/repository.go +++ /dev/null @@ -1,98 +0,0 @@ -// VulcanizeDB -// Copyright © 2018 Vulcanize - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. - -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -package drip_drip - -import ( - "fmt" - - log "github.com/sirupsen/logrus" - - "github.com/vulcanize/vulcanizedb/pkg/core" - "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" -) - -type DripDripRepository struct { - db *postgres.DB -} - -func (repository DripDripRepository) Create(headerID int64, models []interface{}) error { - tx, dBaseErr := repository.db.Begin() - if dBaseErr != nil { - return dBaseErr - } - for _, model := range models { - dripDrip, ok := model.(DripDripModel) - if !ok { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - log.Error("failed to rollback ", rollbackErr) - } - return fmt.Errorf("model of type %T, not %T", model, DripDripModel{}) - } - - ilkID, ilkErr := shared.GetOrCreateIlkInTransaction(dripDrip.Ilk, tx) - if ilkErr != nil { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - log.Error("failed to rollback ", rollbackErr) - } - return ilkErr - } - - _, execErr := tx.Exec( - `INSERT into maker.drip_drip (header_id, ilk, log_idx, tx_idx, raw_log) - VALUES($1, $2, $3, $4, $5) - ON CONFLICT (header_id, tx_idx, log_idx) DO UPDATE SET ilk= $2, raw_log = $5;`, - headerID, ilkID, dripDrip.LogIndex, dripDrip.TransactionIndex, dripDrip.Raw, - ) - if execErr != nil { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - log.Error("failed to rollback ", rollbackErr) - } - return execErr - } - } - - checkHeaderErr := shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.DripDripChecked) - if checkHeaderErr != nil { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - log.Error("failed to rollback ", rollbackErr) - } - return checkHeaderErr - } - return tx.Commit() -} - -func (repository DripDripRepository) MarkHeaderChecked(headerID int64) error { - return shared.MarkHeaderChecked(headerID, repository.db, constants.DripDripChecked) -} - -func (repository DripDripRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { - return shared.MissingHeaders(startingBlockNumber, endingBlockNumber, repository.db, constants.DripDripChecked) -} - -func (repository DripDripRepository) RecheckHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { - return shared.RecheckHeaders(startingBlockNumber, endingBlockNumber, repository.db, constants.DripDripChecked) -} - -func (repository *DripDripRepository) SetDB(db *postgres.DB) { - repository.db = db -} diff --git a/pkg/transformers/drip_drip/repository_test.go b/pkg/transformers/drip_drip/repository_test.go deleted file mode 100644 index c97e477c..00000000 --- a/pkg/transformers/drip_drip/repository_test.go +++ /dev/null @@ -1,89 +0,0 @@ -// VulcanizeDB -// Copyright © 2018 Vulcanize - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. - -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -package drip_drip_test - -import ( - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - "github.com/vulcanize/vulcanizedb/pkg/datastore" - "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" - "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories" - "github.com/vulcanize/vulcanizedb/pkg/fakes" - "github.com/vulcanize/vulcanizedb/pkg/transformers/drip_drip" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" - "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" - "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/shared_behaviors" - "github.com/vulcanize/vulcanizedb/test_config" - "strconv" -) - -var _ = Describe("Drip drip repository", func() { - var ( - db *postgres.DB - dripDripRepository drip_drip.DripDripRepository - headerRepository datastore.HeaderRepository - ) - - BeforeEach(func() { - db = test_config.NewTestDB(test_config.NewTestNode()) - test_config.CleanTestDB(db) - headerRepository = repositories.NewHeaderRepository(db) - dripDripRepository = drip_drip.DripDripRepository{} - dripDripRepository.SetDB(db) - }) - - Describe("Create", func() { - modelWithDifferentLogIdx := test_data.DripDripModel - modelWithDifferentLogIdx.LogIndex++ - inputs := shared_behaviors.CreateBehaviorInputs{ - CheckedHeaderColumnName: constants.DripDripChecked, - LogEventTableName: "maker.drip_drip", - TestModel: test_data.DripDripModel, - ModelWithDifferentLogIdx: modelWithDifferentLogIdx, - Repository: &dripDripRepository, - } - - shared_behaviors.SharedRepositoryCreateBehaviors(&inputs) - - It("adds a drip drip event", func() { - headerID, err := headerRepository.CreateOrUpdateHeader(fakes.FakeHeader) - Expect(err).NotTo(HaveOccurred()) - err = dripDripRepository.Create(headerID, []interface{}{test_data.DripDripModel}) - - Expect(err).NotTo(HaveOccurred()) - var dbDripDrip drip_drip.DripDripModel - err = db.Get(&dbDripDrip, `SELECT ilk, log_idx, tx_idx, raw_log FROM maker.drip_drip WHERE header_id = $1`, headerID) - Expect(err).NotTo(HaveOccurred()) - ilkID, err := shared.GetOrCreateIlk(test_data.DripDripModel.Ilk, db) - Expect(err).NotTo(HaveOccurred()) - Expect(dbDripDrip.Ilk).To(Equal(strconv.Itoa(ilkID))) - Expect(dbDripDrip.LogIndex).To(Equal(test_data.DripDripModel.LogIndex)) - Expect(dbDripDrip.TransactionIndex).To(Equal(test_data.DripDripModel.TransactionIndex)) - Expect(dbDripDrip.Raw).To(MatchJSON(test_data.DripDripModel.Raw)) - }) - }) - - Describe("MarkHeaderChecked", func() { - inputs := shared_behaviors.MarkedHeaderCheckedBehaviorInputs{ - CheckedHeaderColumnName: constants.DripDripChecked, - Repository: &dripDripRepository, - } - - shared_behaviors.SharedRepositoryMarkHeaderCheckedBehaviors(&inputs) - }) -}) diff --git a/pkg/transformers/drip_file/ilk/repository.go b/pkg/transformers/drip_file/ilk/repository.go deleted file mode 100644 index b0122520..00000000 --- a/pkg/transformers/drip_file/ilk/repository.go +++ /dev/null @@ -1,100 +0,0 @@ -// VulcanizeDB -// Copyright © 2018 Vulcanize - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. - -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -package ilk - -import ( - "fmt" - - log "github.com/sirupsen/logrus" - - "github.com/vulcanize/vulcanizedb/pkg/core" - "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" -) - -type DripFileIlkRepository struct { - db *postgres.DB -} - -func (repository DripFileIlkRepository) Create(headerID int64, models []interface{}) error { - tx, dBaseErr := repository.db.Begin() - if dBaseErr != nil { - return dBaseErr - } - - for _, model := range models { - ilk, ok := model.(DripFileIlkModel) - if !ok { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - log.Error("failed to rollback ", rollbackErr) - } - return fmt.Errorf("model of type %T, not %T", model, DripFileIlkModel{}) - } - - ilkID, ilkErr := shared.GetOrCreateIlkInTransaction(ilk.Ilk, tx) - if ilkErr != nil { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - log.Error("failed to rollback ", rollbackErr) - } - return ilkErr - } - - _, execErr := tx.Exec( - `INSERT into maker.drip_file_ilk (header_id, ilk, vow, tax, log_idx, tx_idx, raw_log) - VALUES($1, $2, $3, $4::NUMERIC, $5, $6, $7)`, - headerID, ilkID, ilk.Vow, ilk.Tax, ilk.LogIndex, ilk.TransactionIndex, ilk.Raw, - ) - - if execErr != nil { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - log.Error("failed to rollback ", rollbackErr) - } - return execErr - } - } - - checkHeaderErr := shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.DripFileIlkChecked) - if checkHeaderErr != nil { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - log.Error("failed to rollback ", rollbackErr) - } - return checkHeaderErr - } - - return tx.Commit() -} - -func (repository DripFileIlkRepository) MarkHeaderChecked(headerID int64) error { - return shared.MarkHeaderChecked(headerID, repository.db, constants.DripFileIlkChecked) -} - -func (repository DripFileIlkRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { - return shared.MissingHeaders(startingBlockNumber, endingBlockNumber, repository.db, constants.DripFileIlkChecked) -} - -func (repository DripFileIlkRepository) RecheckHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { - return shared.RecheckHeaders(startingBlockNumber, endingBlockNumber, repository.db, constants.DripFileIlkChecked) -} - -func (repository *DripFileIlkRepository) SetDB(db *postgres.DB) { - repository.db = db -} diff --git a/pkg/transformers/drip_file/ilk/repository_test.go b/pkg/transformers/drip_file/ilk/repository_test.go deleted file mode 100644 index f632e9f8..00000000 --- a/pkg/transformers/drip_file/ilk/repository_test.go +++ /dev/null @@ -1,91 +0,0 @@ -// VulcanizeDB -// Copyright © 2018 Vulcanize - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. - -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -package ilk_test - -import ( - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - "github.com/vulcanize/vulcanizedb/pkg/datastore" - "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" - "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories" - "github.com/vulcanize/vulcanizedb/pkg/fakes" - "github.com/vulcanize/vulcanizedb/pkg/transformers/drip_file/ilk" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" - "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" - "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/shared_behaviors" - "github.com/vulcanize/vulcanizedb/test_config" - "strconv" -) - -var _ = Describe("Drip file ilk repository", func() { - var ( - db *postgres.DB - dripFileIlkRepository ilk.DripFileIlkRepository - headerRepository datastore.HeaderRepository - ) - - BeforeEach(func() { - db = test_config.NewTestDB(test_config.NewTestNode()) - test_config.CleanTestDB(db) - headerRepository = repositories.NewHeaderRepository(db) - dripFileIlkRepository = ilk.DripFileIlkRepository{} - dripFileIlkRepository.SetDB(db) - }) - - Describe("Create", func() { - modelWithDifferentLogIdx := test_data.DripFileIlkModel - modelWithDifferentLogIdx.LogIndex++ - inputs := shared_behaviors.CreateBehaviorInputs{ - CheckedHeaderColumnName: constants.DripFileIlkChecked, - LogEventTableName: "maker.drip_file_ilk", - TestModel: test_data.DripFileIlkModel, - ModelWithDifferentLogIdx: modelWithDifferentLogIdx, - Repository: &dripFileIlkRepository, - } - - shared_behaviors.SharedRepositoryCreateBehaviors(&inputs) - - It("adds a drip file ilk event", func() { - headerID, err := headerRepository.CreateOrUpdateHeader(fakes.FakeHeader) - Expect(err).NotTo(HaveOccurred()) - err = dripFileIlkRepository.Create(headerID, []interface{}{test_data.DripFileIlkModel}) - - Expect(err).NotTo(HaveOccurred()) - var dbDripFileIlk ilk.DripFileIlkModel - err = db.Get(&dbDripFileIlk, `SELECT ilk, vow, tax, log_idx, tx_idx, raw_log FROM maker.drip_file_ilk WHERE header_id = $1`, headerID) - Expect(err).NotTo(HaveOccurred()) - ilkID, err := shared.GetOrCreateIlk(test_data.DripFileIlkModel.Ilk, db) - Expect(err).NotTo(HaveOccurred()) - Expect(dbDripFileIlk.Ilk).To(Equal(strconv.Itoa(ilkID))) - Expect(dbDripFileIlk.Vow).To(Equal(test_data.DripFileIlkModel.Vow)) - Expect(dbDripFileIlk.Tax).To(Equal(test_data.DripFileIlkModel.Tax)) - Expect(dbDripFileIlk.LogIndex).To(Equal(test_data.DripFileIlkModel.LogIndex)) - Expect(dbDripFileIlk.TransactionIndex).To(Equal(test_data.DripFileIlkModel.TransactionIndex)) - Expect(dbDripFileIlk.Raw).To(MatchJSON(test_data.DripFileIlkModel.Raw)) - }) - }) - - Describe("MarkHeaderChecked", func() { - inputs := shared_behaviors.MarkedHeaderCheckedBehaviorInputs{ - CheckedHeaderColumnName: constants.DripFileIlkChecked, - Repository: &dripFileIlkRepository, - } - - shared_behaviors.SharedRepositoryMarkHeaderCheckedBehaviors(&inputs) - }) -}) diff --git a/pkg/transformers/frob/repository.go b/pkg/transformers/frob/repository.go deleted file mode 100644 index 14cb20ae..00000000 --- a/pkg/transformers/frob/repository.go +++ /dev/null @@ -1,94 +0,0 @@ -// VulcanizeDB -// Copyright © 2018 Vulcanize - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. - -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -package frob - -import ( - "fmt" - log "github.com/sirupsen/logrus" - - "github.com/vulcanize/vulcanizedb/pkg/core" - "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" -) - -type FrobRepository struct { - db *postgres.DB -} - -func (repository FrobRepository) Create(headerID int64, models []interface{}) error { - tx, dBaseErr := repository.db.Begin() - if dBaseErr != nil { - return dBaseErr - } - for _, model := range models { - frobModel, ok := model.(FrobModel) - if !ok { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - log.Error("failed to rollback ", rollbackErr) - } - return fmt.Errorf("model of type %T, not %T", model, FrobModel{}) - } - - ilkID, ilkErr := shared.GetOrCreateIlkInTransaction(frobModel.Ilk, tx) - if ilkErr != nil { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - log.Error("failed to rollback ", rollbackErr) - } - return ilkErr - } - - _, execErr := tx.Exec(`INSERT INTO maker.frob (header_id, art, dart, dink, iart, ilk, ink, urn, raw_log, log_idx, tx_idx) - VALUES($1, $2::NUMERIC, $3::NUMERIC, $4::NUMERIC, $5::NUMERIC, $6, $7::NUMERIC, $8, $9, $10, $11) - ON CONFLICT (header_id, tx_idx, log_idx) DO UPDATE SET art = $2, dart = $3, dink = $4, iart = $5, ilk = $6, ink = $7, urn = $8, raw_log = $9;`, - headerID, frobModel.Art, frobModel.Dart, frobModel.Dink, frobModel.IArt, ilkID, frobModel.Ink, frobModel.Urn, frobModel.Raw, frobModel.LogIndex, frobModel.TransactionIndex) - if execErr != nil { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - log.Error("failed to rollback ", rollbackErr) - } - return execErr - } - } - checkHeaderErr := shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.FrobChecked) - if checkHeaderErr != nil { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - log.Error("failed to rollback ", rollbackErr) - } - return checkHeaderErr - } - return tx.Commit() -} - -func (repository FrobRepository) MarkHeaderChecked(headerID int64) error { - return shared.MarkHeaderChecked(headerID, repository.db, constants.FrobChecked) -} - -func (repository FrobRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { - return shared.MissingHeaders(startingBlockNumber, endingBlockNumber, repository.db, constants.FrobChecked) -} - -func (repository FrobRepository) RecheckHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { - return shared.RecheckHeaders(startingBlockNumber, endingBlockNumber, repository.db, constants.FrobChecked) -} - -func (repository *FrobRepository) SetDB(db *postgres.DB) { - repository.db = db -} diff --git a/pkg/transformers/frob/repository_test.go b/pkg/transformers/frob/repository_test.go deleted file mode 100644 index bcb095a4..00000000 --- a/pkg/transformers/frob/repository_test.go +++ /dev/null @@ -1,95 +0,0 @@ -// VulcanizeDB -// Copyright © 2018 Vulcanize - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. - -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -package frob_test - -import ( - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" - "strconv" - - "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" - "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories" - "github.com/vulcanize/vulcanizedb/pkg/fakes" - "github.com/vulcanize/vulcanizedb/pkg/transformers/frob" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" - "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" - "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/shared_behaviors" - "github.com/vulcanize/vulcanizedb/test_config" -) - -var _ = Describe("Frob repository", func() { - var ( - db *postgres.DB - frobRepository frob.FrobRepository - ) - - BeforeEach(func() { - db = test_config.NewTestDB(test_config.NewTestNode()) - test_config.CleanTestDB(db) - frobRepository = frob.FrobRepository{} - frobRepository.SetDB(db) - }) - - Describe("Create", func() { - modelWithDifferentLogIdx := test_data.FrobModel - modelWithDifferentLogIdx.LogIndex++ - inputs := shared_behaviors.CreateBehaviorInputs{ - CheckedHeaderColumnName: constants.FrobChecked, - LogEventTableName: "maker.frob", - TestModel: test_data.FrobModel, - ModelWithDifferentLogIdx: modelWithDifferentLogIdx, - Repository: &frobRepository, - } - - shared_behaviors.SharedRepositoryCreateBehaviors(&inputs) - - It("adds a frob", func() { - headerRepository := repositories.NewHeaderRepository(db) - headerID, err := headerRepository.CreateOrUpdateHeader(fakes.FakeHeader) - Expect(err).NotTo(HaveOccurred()) - - err = frobRepository.Create(headerID, []interface{}{test_data.FrobModel}) - Expect(err).NotTo(HaveOccurred()) - var dbFrob frob.FrobModel - err = db.Get(&dbFrob, `SELECT art, dart, dink, iart, ilk, ink, urn, log_idx, tx_idx, raw_log FROM maker.frob WHERE header_id = $1`, headerID) - - Expect(err).NotTo(HaveOccurred()) - ilkID, err := shared.GetOrCreateIlk(test_data.FrobModel.Ilk, db) - Expect(err).NotTo(HaveOccurred()) - Expect(dbFrob.Ilk).To(Equal(strconv.Itoa(ilkID))) - Expect(dbFrob.Urn).To(Equal(test_data.FrobModel.Urn)) - Expect(dbFrob.Ink).To(Equal(test_data.FrobModel.Ink)) - Expect(dbFrob.Art).To(Equal(test_data.FrobModel.Art)) - Expect(dbFrob.Dink).To(Equal(test_data.FrobModel.Dink)) - Expect(dbFrob.Dart).To(Equal(test_data.FrobModel.Dart)) - Expect(dbFrob.IArt).To(Equal(test_data.FrobModel.IArt)) - Expect(dbFrob.LogIndex).To(Equal(test_data.FrobModel.LogIndex)) - Expect(dbFrob.TransactionIndex).To(Equal(test_data.FrobModel.TransactionIndex)) - Expect(dbFrob.Raw).To(MatchJSON(test_data.FrobModel.Raw)) - }) - }) - - Describe("MarkHeaderChecked", func() { - inputs := shared_behaviors.MarkedHeaderCheckedBehaviorInputs{ - CheckedHeaderColumnName: constants.FrobChecked, - Repository: &frobRepository, - } - - shared_behaviors.SharedRepositoryMarkHeaderCheckedBehaviors(&inputs) - }) -}) diff --git a/pkg/transformers/integration_tests/bite.go b/pkg/transformers/integration_tests/bite.go deleted file mode 100644 index 9ebd3c67..00000000 --- a/pkg/transformers/integration_tests/bite.go +++ /dev/null @@ -1,182 +0,0 @@ -// VulcanizeDB -// Copyright © 2018 Vulcanize - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. - -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -package integration_tests - -import ( - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - "strconv" - - "github.com/ethereum/go-ethereum/accounts/abi/bind" - "github.com/ethereum/go-ethereum/common" - - shared_t "github.com/vulcanize/vulcanizedb/libraries/shared/transformer" - "github.com/vulcanize/vulcanizedb/pkg/geth" - "github.com/vulcanize/vulcanizedb/pkg/transformers/bite" - "github.com/vulcanize/vulcanizedb/pkg/transformers/factories" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" - "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" - "github.com/vulcanize/vulcanizedb/test_config" -) - -var testBiteConfig = shared_t.TransformerConfig{ - TransformerName: constants.BiteLabel, - ContractAddresses: []string{test_data.KovanCatContractAddress}, - ContractAbi: test_data.KovanCatABI, - Topic: test_data.KovanBiteSignature, - StartingBlockNumber: 0, - EndingBlockNumber: -1, -} - -var _ = Describe("Bite Transformer", func() { - It("fetches and transforms a Bite event from Kovan chain", func() { - blockNumber := int64(8956422) - config := testBiteConfig - config.StartingBlockNumber = blockNumber - config.EndingBlockNumber = blockNumber - - rpcClient, ethClient, err := getClients(ipc) - Expect(err).NotTo(HaveOccurred()) - blockChain, err := getBlockChain(rpcClient, ethClient) - Expect(err).NotTo(HaveOccurred()) - - db := test_config.NewTestDB(blockChain.Node()) - test_config.CleanTestDB(db) - - header, err := persistHeader(db, blockNumber, blockChain) - Expect(err).NotTo(HaveOccurred()) - - initializer := factories.Transformer{ - Config: config, - Converter: &bite.BiteConverter{}, - Repository: &bite.BiteRepository{}, - } - transformer := initializer.NewTransformer(db) - - fetcher := shared.NewFetcher(blockChain) - logs, err := fetcher.FetchLogs( - []common.Address{common.HexToAddress(config.ContractAddresses[0])}, - []common.Hash{common.HexToHash(config.Topic)}, - header) - Expect(err).NotTo(HaveOccurred()) - - err = transformer.Execute(logs, header, constants.HeaderMissing) - Expect(err).NotTo(HaveOccurred()) - - var dbResult []bite.BiteModel - err = db.Select(&dbResult, `SELECT art, iart, ilk, ink, nflip, tab, urn from maker.bite`) - Expect(err).NotTo(HaveOccurred()) - - Expect(len(dbResult)).To(Equal(1)) - Expect(dbResult[0].Art).To(Equal("149846666666666655744")) - Expect(dbResult[0].IArt).To(Equal("1645356666666666655736")) - ilkID, err := shared.GetOrCreateIlk("4554480000000000000000000000000000000000000000000000000000000000", db) - Expect(err).NotTo(HaveOccurred()) - Expect(dbResult[0].Ilk).To(Equal(strconv.Itoa(ilkID))) - Expect(dbResult[0].Ink).To(Equal("1000000000000000000")) - Expect(dbResult[0].NFlip).To(Equal("2")) - Expect(dbResult[0].Tab).To(Equal("149846666666666655744")) - Expect(dbResult[0].Urn).To(Equal("0000000000000000000000000000d8b4147eda80fec7122ae16da2479cbd7ffb")) - }) - - It("unpacks an event log", func() { - address := common.HexToAddress(test_data.KovanCatContractAddress) - abi, err := geth.ParseAbi(test_data.KovanCatABI) - Expect(err).NotTo(HaveOccurred()) - - contract := bind.NewBoundContract(address, abi, nil, nil, nil) - entity := &bite.BiteEntity{} - - var eventLog = test_data.EthBiteLog - - err = contract.UnpackLog(entity, "Bite", eventLog) - Expect(err).NotTo(HaveOccurred()) - - expectedEntity := test_data.BiteEntity - Expect(entity.Art).To(Equal(expectedEntity.Art)) - Expect(entity.Ilk).To(Equal(expectedEntity.Ilk)) - Expect(entity.Ink).To(Equal(expectedEntity.Ink)) - }) - - It("rechecks header for bite event", func() { - blockNumber := int64(8956422) - config := testBiteConfig - config.StartingBlockNumber = blockNumber - config.EndingBlockNumber = blockNumber - - rpcClient, ethClient, err := getClients(ipc) - Expect(err).NotTo(HaveOccurred()) - blockChain, err := getBlockChain(rpcClient, ethClient) - Expect(err).NotTo(HaveOccurred()) - - db := test_config.NewTestDB(blockChain.Node()) - test_config.CleanTestDB(db) - - header, err := persistHeader(db, blockNumber, blockChain) - Expect(err).NotTo(HaveOccurred()) - - initializer := factories.Transformer{ - Config: config, - Converter: &bite.BiteConverter{}, - Repository: &bite.BiteRepository{}, - } - transformer := initializer.NewTransformer(db) - - fetcher := shared.NewFetcher(blockChain) - logs, err := fetcher.FetchLogs( - []common.Address{common.HexToAddress(config.ContractAddresses[0])}, - []common.Hash{common.HexToHash(config.Topic)}, - header) - Expect(err).NotTo(HaveOccurred()) - - err = transformer.Execute(logs, header, constants.HeaderMissing) - Expect(err).NotTo(HaveOccurred()) - - err = transformer.Execute(logs, header, constants.HeaderRecheck) - Expect(err).NotTo(HaveOccurred()) - - var headerID int64 - err = db.Get(&headerID, `SELECT id FROM public.headers WHERE block_number = $1`, blockNumber) - Expect(err).NotTo(HaveOccurred()) - - var biteChecked []int - err = db.Select(&biteChecked, `SELECT bite_checked FROM public.checked_headers WHERE header_id = $1`, headerID) - Expect(err).NotTo(HaveOccurred()) - - Expect(biteChecked[0]).To(Equal(2)) - }) - - It("unpacks an event log", func() { - address := common.HexToAddress(test_data.KovanCatContractAddress) - abi, err := geth.ParseAbi(test_data.KovanCatABI) - Expect(err).NotTo(HaveOccurred()) - - contract := bind.NewBoundContract(address, abi, nil, nil, nil) - entity := &bite.BiteEntity{} - - var eventLog = test_data.EthBiteLog - - err = contract.UnpackLog(entity, "Bite", eventLog) - Expect(err).NotTo(HaveOccurred()) - - expectedEntity := test_data.BiteEntity - Expect(entity.Art).To(Equal(expectedEntity.Art)) - Expect(entity.Ilk).To(Equal(expectedEntity.Ilk)) - Expect(entity.Ink).To(Equal(expectedEntity.Ink)) - }) -}) diff --git a/pkg/transformers/integration_tests/cat_file.go b/pkg/transformers/integration_tests/cat_file.go deleted file mode 100644 index 8657422d..00000000 --- a/pkg/transformers/integration_tests/cat_file.go +++ /dev/null @@ -1,305 +0,0 @@ -// VulcanizeDB -// Copyright © 2018 Vulcanize - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. - -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -package integration_tests - -import ( - "github.com/ethereum/go-ethereum/common" - "github.com/vulcanize/vulcanizedb/pkg/transformers/factories" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" - "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" - "sort" - "strconv" - - "github.com/ethereum/go-ethereum/ethclient" - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - - shared_t "github.com/vulcanize/vulcanizedb/libraries/shared/transformer" - "github.com/vulcanize/vulcanizedb/pkg/core" - "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" - "github.com/vulcanize/vulcanizedb/pkg/geth/client" - "github.com/vulcanize/vulcanizedb/pkg/transformers/cat_file/chop_lump" - "github.com/vulcanize/vulcanizedb/pkg/transformers/cat_file/flip" - "github.com/vulcanize/vulcanizedb/pkg/transformers/cat_file/pit_vow" - "github.com/vulcanize/vulcanizedb/test_config" -) - -var _ = Describe("Cat File transformer", func() { - var ( - db *postgres.DB - blockChain core.BlockChain - rpcClient client.RpcClient - err error - ethClient *ethclient.Client - fetcher *shared.Fetcher - ) - - BeforeEach(func() { - rpcClient, ethClient, err = getClients(ipc) - Expect(err).NotTo(HaveOccurred()) - blockChain, err = getBlockChain(rpcClient, ethClient) - Expect(err).NotTo(HaveOccurred()) - db = test_config.NewTestDB(blockChain.Node()) - test_config.CleanTestDB(db) - - fetcher = shared.NewFetcher(blockChain) - }) - - // Cat contract Kovan address: 0x2f34f22a00ee4b7a8f8bbc4eaee1658774c624e0 - It("persists a chop lump event", func() { - // transaction: 0x98574bfba4d05c3875be10d2376e678d005dbebe9a4520363407508fd21f4014 - chopLumpBlockNumber := int64(8762253) - header, err := persistHeader(db, chopLumpBlockNumber, blockChain) - Expect(err).NotTo(HaveOccurred()) - - config := shared_t.TransformerConfig{ - TransformerName: constants.CatFileChopLumpLabel, - ContractAddresses: []string{test_data.KovanCatContractAddress}, - ContractAbi: test_data.KovanCatABI, - Topic: test_data.KovanCatFileChopLumpSignature, - StartingBlockNumber: chopLumpBlockNumber, - EndingBlockNumber: chopLumpBlockNumber, - } - - initializer := factories.LogNoteTransformer{ - Config: config, - Converter: &chop_lump.CatFileChopLumpConverter{}, - Repository: &chop_lump.CatFileChopLumpRepository{}, - } - transformer := initializer.NewLogNoteTransformer(db) - - logs, err := fetcher.FetchLogs( - []common.Address{common.HexToAddress(config.ContractAddresses[0])}, - []common.Hash{common.HexToHash(config.Topic)}, - header) - Expect(err).NotTo(HaveOccurred()) - - err = transformer.Execute(logs, header, constants.HeaderMissing) - Expect(err).NotTo(HaveOccurred()) - - var dbResult []chop_lump.CatFileChopLumpModel - err = db.Select(&dbResult, `SELECT ilk, what, data, log_idx FROM maker.cat_file_chop_lump`) - Expect(err).NotTo(HaveOccurred()) - - Expect(len(dbResult)).To(Equal(2)) - sort.Sort(byLogIndexChopLump(dbResult)) - - ilkID, err := shared.GetOrCreateIlk("5245500000000000000000000000000000000000000000000000000000000000", db) - Expect(err).NotTo(HaveOccurred()) - Expect(dbResult[0].Ilk).To(Equal(strconv.Itoa(ilkID))) - Expect(dbResult[0].What).To(Equal("lump")) - Expect(dbResult[0].Data).To(Equal("10000.000000000000000000")) - Expect(dbResult[0].LogIndex).To(Equal(uint(3))) - - Expect(dbResult[1].Ilk).To(Equal(strconv.Itoa(ilkID))) - Expect(dbResult[1].What).To(Equal("chop")) - Expect(dbResult[1].Data).To(Equal("1.000000000000000000000000000")) - Expect(dbResult[1].LogIndex).To(Equal(uint(4))) - }) - - It("rechecks header for chop lump event", func() { - // transaction: 0x98574bfba4d05c3875be10d2376e678d005dbebe9a4520363407508fd21f4014 - chopLumpBlockNumber := int64(8762253) - header, err := persistHeader(db, chopLumpBlockNumber, blockChain) - Expect(err).NotTo(HaveOccurred()) - - config := shared.TransformerConfig{ - TransformerName: constants.CatFileChopLumpLabel, - ContractAddresses: []string{test_data.KovanCatContractAddress}, - ContractAbi: test_data.KovanCatABI, - Topic: test_data.KovanCatFileChopLumpSignature, - StartingBlockNumber: chopLumpBlockNumber, - EndingBlockNumber: chopLumpBlockNumber, - } - - initializer := factories.LogNoteTransformer{ - Config: config, - Converter: &chop_lump.CatFileChopLumpConverter{}, - Repository: &chop_lump.CatFileChopLumpRepository{}, - } - transformer := initializer.NewLogNoteTransformer(db) - - logs, err := fetcher.FetchLogs( - []common.Address{common.HexToAddress(config.ContractAddresses[0])}, - []common.Hash{common.HexToHash(config.Topic)}, - header) - Expect(err).NotTo(HaveOccurred()) - - err = transformer.Execute(logs, header, constants.HeaderMissing) - Expect(err).NotTo(HaveOccurred()) - - err = transformer.Execute(logs, header, constants.HeaderRecheck) - Expect(err).NotTo(HaveOccurred()) - - var headerID int64 - err = db.Get(&headerID, `SELECT id FROM public.headers WHERE block_number = $1`, chopLumpBlockNumber) - Expect(err).NotTo(HaveOccurred()) - - var catChopLumpChecked []int - err = db.Select(&catChopLumpChecked, `SELECT cat_file_chop_lump_checked FROM public.checked_headers WHERE header_id = $1`, headerID) - Expect(err).NotTo(HaveOccurred()) - - Expect(catChopLumpChecked[0]).To(Equal(2)) - }) - - It("persists a flip event", func() { - // transaction: 0x44bc18fdb1a5a263db114e7879653304db3e19ceb4e4496f21bc0a76c5faccbe - flipBlockNumber := int64(8751794) - header, err := persistHeader(db, flipBlockNumber, blockChain) - Expect(err).NotTo(HaveOccurred()) - - config := shared_t.TransformerConfig{ - TransformerName: constants.CatFileFlipLabel, - ContractAddresses: []string{test_data.KovanCatContractAddress}, - ContractAbi: test_data.KovanCatABI, - Topic: test_data.KovanCatFileFlipSignature, - StartingBlockNumber: flipBlockNumber, - EndingBlockNumber: flipBlockNumber, - } - - initializer := factories.LogNoteTransformer{ - Config: config, - Converter: &flip.CatFileFlipConverter{}, - Repository: &flip.CatFileFlipRepository{}, - } - - transformer := initializer.NewLogNoteTransformer(db) - - logs, err := fetcher.FetchLogs( - []common.Address{common.HexToAddress(config.ContractAddresses[0])}, - []common.Hash{common.HexToHash(config.Topic)}, - header) - Expect(err).NotTo(HaveOccurred()) - - err = transformer.Execute(logs, header, constants.HeaderMissing) - Expect(err).NotTo(HaveOccurred()) - - var dbResult []flip.CatFileFlipModel - err = db.Select(&dbResult, `SELECT ilk, what, flip FROM maker.cat_file_flip`) - Expect(err).NotTo(HaveOccurred()) - - Expect(len(dbResult)).To(Equal(1)) - Expect(dbResult[0].Ilk).To(Equal("4554480000000000000000000000000000000000000000000000000000000000")) - Expect(dbResult[0].What).To(Equal("flip")) - Expect(dbResult[0].Flip).To(Equal("0x32D496Ad866D110060866B7125981C73642cc509")) - }) - - It("rechecks a flip event", func() { - // transaction: 0x44bc18fdb1a5a263db114e7879653304db3e19ceb4e4496f21bc0a76c5faccbe - flipBlockNumber := int64(8751794) - header, err := persistHeader(db, flipBlockNumber, blockChain) - Expect(err).NotTo(HaveOccurred()) - - config := shared.TransformerConfig{ - TransformerName: constants.CatFileFlipLabel, - ContractAddresses: []string{test_data.KovanCatContractAddress}, - ContractAbi: test_data.KovanCatABI, - Topic: test_data.KovanCatFileFlipSignature, - StartingBlockNumber: flipBlockNumber, - EndingBlockNumber: flipBlockNumber, - } - - initializer := factories.LogNoteTransformer{ - Config: config, - Converter: &flip.CatFileFlipConverter{}, - Repository: &flip.CatFileFlipRepository{}, - } - - transformer := initializer.NewLogNoteTransformer(db) - - logs, err := fetcher.FetchLogs( - []common.Address{common.HexToAddress(config.ContractAddresses[0])}, - []common.Hash{common.HexToHash(config.Topic)}, - header) - Expect(err).NotTo(HaveOccurred()) - - err = transformer.Execute(logs, header, constants.HeaderMissing) - Expect(err).NotTo(HaveOccurred()) - - err = transformer.Execute(logs, header, constants.HeaderRecheck) - Expect(err).NotTo(HaveOccurred()) - - var headerID int64 - err = db.Get(&headerID, `SELECT id FROM public.headers WHERE block_number = $1`, flipBlockNumber) - Expect(err).NotTo(HaveOccurred()) - - var catFlipChecked []int - err = db.Select(&catFlipChecked, `SELECT cat_file_flip_checked FROM public.checked_headers WHERE header_id = $1`, headerID) - Expect(err).NotTo(HaveOccurred()) - - Expect(catFlipChecked[0]).To(Equal(2)) - }) - - It("persists a pit vow event", func() { - // transaction: 0x44bc18fdb1a5a263db114e7879653304db3e19ceb4e4496f21bc0a76c5faccbe - pitVowBlockNumber := int64(8751794) - header, err := persistHeader(db, pitVowBlockNumber, blockChain) - Expect(err).NotTo(HaveOccurred()) - - config := shared_t.TransformerConfig{ - TransformerName: constants.CatFilePitVowLabel, - ContractAddresses: []string{test_data.KovanCatContractAddress}, - ContractAbi: test_data.KovanCatABI, - Topic: test_data.KovanCatFilePitVowSignature, - StartingBlockNumber: pitVowBlockNumber, - EndingBlockNumber: pitVowBlockNumber, - } - - initializer := factories.LogNoteTransformer{ - Config: config, - Converter: &pit_vow.CatFilePitVowConverter{}, - Repository: &pit_vow.CatFilePitVowRepository{}, - } - transformer := initializer.NewLogNoteTransformer(db) - - logs, err := fetcher.FetchLogs( - []common.Address{common.HexToAddress(config.ContractAddresses[0])}, - []common.Hash{common.HexToHash(config.Topic)}, - header) - Expect(err).NotTo(HaveOccurred()) - - err = transformer.Execute(logs, header, constants.HeaderMissing) - Expect(err).NotTo(HaveOccurred()) - - var dbResult []pit_vow.CatFilePitVowModel - err = db.Select(&dbResult, `SELECT what, data, log_idx FROM maker.cat_file_pit_vow`) - Expect(err).NotTo(HaveOccurred()) - - Expect(len(dbResult)).To(Equal(2)) - sort.Sort(byLogIndexPitVow(dbResult)) - Expect(dbResult[0].What).To(Equal("vow")) - Expect(dbResult[0].Data).To(Equal("0x3728e9777B2a0a611ee0F89e00E01044ce4736d1")) - Expect(dbResult[0].LogIndex).To(Equal(uint(1))) - - Expect(dbResult[1].What).To(Equal("pit")) - Expect(dbResult[1].Data).To(Equal("0xE7CF3198787C9A4daAc73371A38f29aAeECED87e")) - Expect(dbResult[1].LogIndex).To(Equal(uint(2))) - }) -}) - -type byLogIndexChopLump []chop_lump.CatFileChopLumpModel - -func (c byLogIndexChopLump) Len() int { return len(c) } -func (c byLogIndexChopLump) Less(i, j int) bool { return c[i].LogIndex < c[j].LogIndex } -func (c byLogIndexChopLump) Swap(i, j int) { c[i], c[j] = c[j], c[i] } - -type byLogIndexPitVow []pit_vow.CatFilePitVowModel - -func (c byLogIndexPitVow) Len() int { return len(c) } -func (c byLogIndexPitVow) Less(i, j int) bool { return c[i].LogIndex < c[j].LogIndex } -func (c byLogIndexPitVow) Swap(i, j int) { c[i], c[j] = c[j], c[i] } diff --git a/pkg/transformers/integration_tests/drip_drip.go b/pkg/transformers/integration_tests/drip_drip.go deleted file mode 100644 index ee747542..00000000 --- a/pkg/transformers/integration_tests/drip_drip.go +++ /dev/null @@ -1,133 +0,0 @@ -// VulcanizeDB -// Copyright © 2018 Vulcanize - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. - -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -package integration_tests - -import ( - "github.com/ethereum/go-ethereum/common" - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - - shared_t "github.com/vulcanize/vulcanizedb/libraries/shared/transformer" - "github.com/vulcanize/vulcanizedb/pkg/core" - "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" - "github.com/vulcanize/vulcanizedb/pkg/transformers/drip_drip" - "github.com/vulcanize/vulcanizedb/pkg/transformers/factories" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" - "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" - "strconv" - - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" - "github.com/vulcanize/vulcanizedb/test_config" -) - -var _ = Describe("DripDrip Transformer", func() { - var ( - db *postgres.DB - blockChain core.BlockChain - config shared_t.TransformerConfig - ) - - BeforeEach(func() { - rpcClient, ethClient, err := getClients(ipc) - Expect(err).NotTo(HaveOccurred()) - blockChain, err = getBlockChain(rpcClient, ethClient) - Expect(err).NotTo(HaveOccurred()) - db = test_config.NewTestDB(blockChain.Node()) - test_config.CleanTestDB(db) - - config = shared_t.TransformerConfig{ - ContractAddresses: []string{test_data.KovanDripContractAddress}, - ContractAbi: test_data.KovanDripABI, - Topic: test_data.KovanDripDripSignature, - StartingBlockNumber: 0, - EndingBlockNumber: -1, - } - }) - - It("transforms DripDrip log events", func() { - blockNumber := int64(8934775) - config.StartingBlockNumber = blockNumber - config.EndingBlockNumber = blockNumber - - header, err := persistHeader(db, blockNumber, blockChain) - Expect(err).NotTo(HaveOccurred()) - - initializer := factories.LogNoteTransformer{ - Config: config, - Converter: &drip_drip.DripDripConverter{}, - Repository: &drip_drip.DripDripRepository{}, - } - transformer := initializer.NewLogNoteTransformer(db) - - fetcher := shared.NewFetcher(blockChain) - logs, err := fetcher.FetchLogs( - shared_t.HexStringsToAddresses(config.ContractAddresses), - []common.Hash{common.HexToHash(config.Topic)}, - header) - Expect(err).NotTo(HaveOccurred()) - - err = transformer.Execute(logs, header, constants.HeaderMissing) - Expect(err).NotTo(HaveOccurred()) - - var dbResults []drip_drip.DripDripModel - err = db.Select(&dbResults, `SELECT ilk from maker.drip_drip`) - Expect(err).NotTo(HaveOccurred()) - - Expect(len(dbResults)).To(Equal(1)) - dbResult := dbResults[0] - ilkID, err := shared.GetOrCreateIlk("4554480000000000000000000000000000000000000000000000000000000000", db) - Expect(err).NotTo(HaveOccurred()) - Expect(dbResult.Ilk).To(Equal(strconv.Itoa(ilkID))) - }) - - It("rechecks drip drip event", func() { - blockNumber := int64(8934775) - config.StartingBlockNumber = blockNumber - config.EndingBlockNumber = blockNumber - - header, err := persistHeader(db, blockNumber, blockChain) - Expect(err).NotTo(HaveOccurred()) - - initializer := factories.LogNoteTransformer{ - Config: config, - Converter: &drip_drip.DripDripConverter{}, - Repository: &drip_drip.DripDripRepository{}, - } - transformer := initializer.NewLogNoteTransformer(db) - - fetcher := shared.NewFetcher(blockChain) - logs, err := fetcher.FetchLogs( - shared_t.HexStringsToAddresses(config.ContractAddresses), - []common.Hash{common.HexToHash(config.Topic)}, - header) - Expect(err).NotTo(HaveOccurred()) - - err = transformer.Execute(logs, header, constants.HeaderMissing) - Expect(err).NotTo(HaveOccurred()) - - err = transformer.Execute(logs, header, constants.HeaderRecheck) - Expect(err).NotTo(HaveOccurred()) - - var headerID int64 - err = db.Get(&headerID, `SELECT id FROM public.headers WHERE block_number = $1`, blockNumber) - Expect(err).NotTo(HaveOccurred()) - - var dripdripChecked []int - err = db.Select(&dripdripChecked, `SELECT drip_drip_checked FROM public.checked_headers WHERE header_id = $1`, headerID) - Expect(err).NotTo(HaveOccurred()) - }) -}) diff --git a/pkg/transformers/integration_tests/frob.go b/pkg/transformers/integration_tests/frob.go deleted file mode 100644 index 333f0b0c..00000000 --- a/pkg/transformers/integration_tests/frob.go +++ /dev/null @@ -1,173 +0,0 @@ -// VulcanizeDB -// Copyright © 2018 Vulcanize - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. - -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -package integration_tests - -import ( - "github.com/ethereum/go-ethereum/accounts/abi/bind" - "github.com/ethereum/go-ethereum/common" - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - "strconv" - - shared_t "github.com/vulcanize/vulcanizedb/libraries/shared/transformer" - "github.com/vulcanize/vulcanizedb/pkg/core" - "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" - "github.com/vulcanize/vulcanizedb/pkg/geth" - "github.com/vulcanize/vulcanizedb/pkg/transformers/factories" - "github.com/vulcanize/vulcanizedb/pkg/transformers/frob" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" - "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" - "github.com/vulcanize/vulcanizedb/test_config" -) - -var _ = Describe("Frob Transformer", func() { - var ( - db *postgres.DB - blockChain core.BlockChain - fetcher *shared.Fetcher - config shared_t.TransformerConfig - initializer factories.Transformer - ) - - BeforeEach(func() { - rpcClient, ethClient, err := getClients(ipc) - Expect(err).NotTo(HaveOccurred()) - blockChain, err = getBlockChain(rpcClient, ethClient) - Expect(err).NotTo(HaveOccurred()) - db = test_config.NewTestDB(blockChain.Node()) - test_config.CleanTestDB(db) - - fetcher = shared.NewFetcher(blockChain) - config = shared_t.TransformerConfig{ - TransformerName: constants.FrobLabel, - ContractAddresses: []string{test_data.KovanPitContractAddress}, - ContractAbi: test_data.KovanPitABI, - Topic: test_data.KovanFrobSignature, - StartingBlockNumber: 0, - EndingBlockNumber: -1, - } - - initializer = factories.Transformer{ - Config: config, - Converter: &frob.FrobConverter{}, - Repository: &frob.FrobRepository{}, - } - }) - - It("fetches and transforms a Frob event from Kovan chain", func() { - blockNumber := int64(8935258) - initializer.Config.StartingBlockNumber = blockNumber - initializer.Config.EndingBlockNumber = blockNumber - - header, err := persistHeader(db, blockNumber, blockChain) - Expect(err).NotTo(HaveOccurred()) - - logs, err := fetcher.FetchLogs( - shared_t.HexStringsToAddresses(config.ContractAddresses), - []common.Hash{common.HexToHash(config.Topic)}, - header) - Expect(err).NotTo(HaveOccurred()) - - transformer := initializer.NewTransformer(db) - err = transformer.Execute(logs, header, constants.HeaderMissing) - Expect(err).NotTo(HaveOccurred()) - - var dbResult []frob.FrobModel - err = db.Select(&dbResult, `SELECT art, dart, dink, iart, ilk, ink, urn from maker.frob`) - Expect(err).NotTo(HaveOccurred()) - - Expect(len(dbResult)).To(Equal(1)) - Expect(dbResult[0].Art).To(Equal("10000000000000000")) - Expect(dbResult[0].Dart).To(Equal("0")) - Expect(dbResult[0].Dink).To(Equal("10000000000000")) - Expect(dbResult[0].IArt).To(Equal("1495509999999999999992")) - ilkID, err := shared.GetOrCreateIlk("4554480000000000000000000000000000000000000000000000000000000000", db) - Expect(err).NotTo(HaveOccurred()) - Expect(dbResult[0].Ilk).To(Equal(strconv.Itoa(ilkID))) - Expect(dbResult[0].Ink).To(Equal("10050100000000000")) - Expect(dbResult[0].Urn).To(Equal("000000000000000000000000c8e093e5f3f9b5aa6a6b33ea45960b93c161430c")) - }) - - It("rechecks frob event", func() { - blockNumber := int64(8935258) - initializer.Config.StartingBlockNumber = blockNumber - initializer.Config.EndingBlockNumber = blockNumber - - header, err := persistHeader(db, blockNumber, blockChain) - Expect(err).NotTo(HaveOccurred()) - - logs, err := fetcher.FetchLogs( - shared.HexStringsToAddresses(config.ContractAddresses), - []common.Hash{common.HexToHash(config.Topic)}, - header) - Expect(err).NotTo(HaveOccurred()) - - transformer := initializer.NewTransformer(db) - err = transformer.Execute(logs, header, constants.HeaderMissing) - Expect(err).NotTo(HaveOccurred()) - - err = transformer.Execute(logs, header, constants.HeaderRecheck) - Expect(err).NotTo(HaveOccurred()) - - var headerID int64 - err = db.Get(&headerID, `SELECT id FROM public.headers WHERE block_number = $1`, blockNumber) - Expect(err).NotTo(HaveOccurred()) - - var frobChecked []int - err = db.Select(&frobChecked, `SELECT frob_checked FROM public.checked_headers WHERE header_id = $1`, headerID) - Expect(err).NotTo(HaveOccurred()) - - Expect(frobChecked[0]).To(Equal(2)) - - var dbResult []frob.FrobModel - err = db.Select(&dbResult, `SELECT art, dart, dink, iart, ilk, ink, urn from maker.frob`) - Expect(err).NotTo(HaveOccurred()) - - Expect(len(dbResult)).To(Equal(1)) - Expect(dbResult[0].Art).To(Equal("10000000000000000")) - Expect(dbResult[0].Dart).To(Equal("0")) - Expect(dbResult[0].Dink).To(Equal("10000000000000")) - Expect(dbResult[0].IArt).To(Equal("1495509999999999999992")) - ilkID, err := shared.GetOrCreateIlk("4554480000000000000000000000000000000000000000000000000000000000", db) - Expect(err).NotTo(HaveOccurred()) - Expect(dbResult[0].Ilk).To(Equal(strconv.Itoa(ilkID))) - Expect(dbResult[0].Ink).To(Equal("10050100000000000")) - Expect(dbResult[0].Urn).To(Equal("000000000000000000000000c8e093e5f3f9b5aa6a6b33ea45960b93c161430c")) - }) - - It("unpacks an event log", func() { - address := common.HexToAddress(test_data.KovanPitContractAddress) - abi, err := geth.ParseAbi(test_data.KovanPitABI) - Expect(err).NotTo(HaveOccurred()) - - contract := bind.NewBoundContract(address, abi, nil, nil, nil) - entity := &frob.FrobEntity{} - - var eventLog = test_data.EthFrobLog - - err = contract.UnpackLog(entity, "Frob", eventLog) - Expect(err).NotTo(HaveOccurred()) - - expectedEntity := test_data.FrobEntity - Expect(entity.Art).To(Equal(expectedEntity.Art)) - Expect(entity.IArt).To(Equal(expectedEntity.IArt)) - Expect(entity.Ilk).To(Equal(expectedEntity.Ilk)) - Expect(entity.Ink).To(Equal(expectedEntity.Ink)) - Expect(entity.Urn).To(Equal(expectedEntity.Urn)) - }) -}) diff --git a/pkg/transformers/integration_tests/pit_file_ilk.go b/pkg/transformers/integration_tests/pit_file_ilk.go deleted file mode 100644 index 7d35f6a5..00000000 --- a/pkg/transformers/integration_tests/pit_file_ilk.go +++ /dev/null @@ -1,172 +0,0 @@ -// VulcanizeDB -// Copyright © 2018 Vulcanize - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. - -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -package integration_tests - -import ( - "github.com/ethereum/go-ethereum/common" - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - "github.com/vulcanize/vulcanizedb/pkg/core" - "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" - "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" - "strconv" - - shared_t "github.com/vulcanize/vulcanizedb/libraries/shared/transformer" - "github.com/vulcanize/vulcanizedb/pkg/transformers/factories" - "github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file/ilk" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" - "github.com/vulcanize/vulcanizedb/test_config" -) - -var _ = Describe("PitFileIlk LogNoteTransformer", func() { - var ( - db *postgres.DB - blockChain core.BlockChain - initializer factories.LogNoteTransformer - addresses []common.Address - topics []common.Hash - ) - - BeforeEach(func() { - rpcClient, ethClient, err := getClients(ipc) - Expect(err).NotTo(HaveOccurred()) - blockChain, err = getBlockChain(rpcClient, ethClient) - Expect(err).NotTo(HaveOccurred()) - db = test_config.NewTestDB(blockChain.Node()) - test_config.CleanTestDB(db) - config := shared_t.TransformerConfig{ - TransformerName: constants.PitFileIlkLabel, - ContractAddresses: []string{test_data.KovanPitContractAddress}, - ContractAbi: test_data.KovanPitABI, - Topic: test_data.KovanPitFileIlkSignature, - StartingBlockNumber: 0, - EndingBlockNumber: -1, - } - - addresses = shared_t.HexStringsToAddresses(config.ContractAddresses) - topics = []common.Hash{common.HexToHash(config.Topic)} - - initializer = factories.LogNoteTransformer{ - Config: config, - Converter: &ilk.PitFileIlkConverter{}, - Repository: &ilk.PitFileIlkRepository{}, - } - }) - - It("fetches and transforms a Pit.file ilk 'spot' event from Kovan", func() { - blockNumber := int64(9103223) - initializer.Config.StartingBlockNumber = blockNumber - initializer.Config.EndingBlockNumber = blockNumber - - header, err := persistHeader(db, blockNumber, blockChain) - Expect(err).NotTo(HaveOccurred()) - - fetcher := shared.NewFetcher(blockChain) - logs, err := fetcher.FetchLogs(addresses, topics, header) - Expect(err).NotTo(HaveOccurred()) - - transformer := initializer.NewLogNoteTransformer(db) - err = transformer.Execute(logs, header, constants.HeaderMissing) - Expect(err).NotTo(HaveOccurred()) - - var dbResult []ilk.PitFileIlkModel - err = db.Select(&dbResult, `SELECT ilk, what, data from maker.pit_file_ilk`) - Expect(err).NotTo(HaveOccurred()) - - Expect(len(dbResult)).To(Equal(1)) - ilkID, err := shared.GetOrCreateIlk("4554480000000000000000000000000000000000000000000000000000000000", db) - Expect(err).NotTo(HaveOccurred()) - Expect(dbResult[0].Ilk).To(Equal(strconv.Itoa(ilkID))) - Expect(dbResult[0].What).To(Equal("spot")) - Expect(dbResult[0].Data).To(Equal("139.840000000000003410605131648")) - }) - - It("rechecks pit file ilk event", func() { - blockNumber := int64(9103223) - initializer.Config.StartingBlockNumber = blockNumber - initializer.Config.EndingBlockNumber = blockNumber - - header, err := persistHeader(db, blockNumber, blockChain) - Expect(err).NotTo(HaveOccurred()) - - fetcher := shared.NewFetcher(blockChain) - logs, err := fetcher.FetchLogs(addresses, topics, header) - Expect(err).NotTo(HaveOccurred()) - - transformer := initializer.NewLogNoteTransformer(db) - err = transformer.Execute(logs, header, constants.HeaderMissing) - Expect(err).NotTo(HaveOccurred()) - - err = transformer.Execute(logs, header, constants.HeaderRecheck) - Expect(err).NotTo(HaveOccurred()) - - var headerID int64 - err = db.Get(&headerID, `SELECT id FROM public.headers WHERE block_number = $1`, blockNumber) - Expect(err).NotTo(HaveOccurred()) - - var pitFileIlkChecked []int - err = db.Select(&pitFileIlkChecked, `SELECT pit_file_ilk_checked FROM public.checked_headers WHERE header_id = $1`, headerID) - Expect(err).NotTo(HaveOccurred()) - - Expect(pitFileIlkChecked[0]).To(Equal(2)) - - var dbResult []ilk.PitFileIlkModel - err = db.Select(&dbResult, `SELECT ilk, what, data from maker.pit_file_ilk`) - Expect(err).NotTo(HaveOccurred()) - - Expect(len(dbResult)).To(Equal(1)) - ilkID, err := shared.GetOrCreateIlk("4554480000000000000000000000000000000000000000000000000000000000", db) - Expect(err).NotTo(HaveOccurred()) - Expect(dbResult[0].Ilk).To(Equal(strconv.Itoa(ilkID))) - Expect(dbResult[0].What).To(Equal("spot")) - Expect(dbResult[0].Data).To(Equal("139.840000000000003410605131648")) - }) - - It("fetches and transforms a Pit.file ilk 'line' event from Kovan", func() { - blockNumber := int64(8762253) - initializer.Config.StartingBlockNumber = blockNumber - initializer.Config.EndingBlockNumber = blockNumber - - header, err := persistHeader(db, blockNumber, blockChain) - Expect(err).NotTo(HaveOccurred()) - - fetcher := shared.NewFetcher(blockChain) - logs, err := fetcher.FetchLogs(addresses, topics, header) - Expect(err).NotTo(HaveOccurred()) - - transformer := initializer.NewLogNoteTransformer(db) - err = transformer.Execute(logs, header, constants.HeaderMissing) - Expect(err).NotTo(HaveOccurred()) - - var dbResult []ilk.PitFileIlkModel - err = db.Select(&dbResult, `SELECT ilk, what, data from maker.pit_file_ilk`) - Expect(err).NotTo(HaveOccurred()) - - Expect(len(dbResult)).To(Equal(2)) - var pitFileIlkLineModel ilk.PitFileIlkModel - for _, result := range dbResult { - if result.What == "line" { - pitFileIlkLineModel = result - } - } - ilkID, err := shared.GetOrCreateIlk("5245500000000000000000000000000000000000000000000000000000000000", db) - Expect(err).NotTo(HaveOccurred()) - Expect(dbResult[0].Ilk).To(Equal(strconv.Itoa(ilkID))) - Expect(pitFileIlkLineModel.Data).To(Equal("2000000.000000000000000000")) - }) -}) diff --git a/pkg/transformers/integration_tests/vat_flux.go b/pkg/transformers/integration_tests/vat_flux.go deleted file mode 100644 index 896688ea..00000000 --- a/pkg/transformers/integration_tests/vat_flux.go +++ /dev/null @@ -1,153 +0,0 @@ -// VulcanizeDB -// Copyright © 2018 Vulcanize - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. - -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -package integration_tests - -import ( - "github.com/ethereum/go-ethereum/common" - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" - "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" - "strconv" - - shared_t "github.com/vulcanize/vulcanizedb/libraries/shared/transformer" - "github.com/vulcanize/vulcanizedb/pkg/transformers/factories" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" - "github.com/vulcanize/vulcanizedb/pkg/transformers/vat_flux" - "github.com/vulcanize/vulcanizedb/test_config" -) - -var _ = Describe("VatFlux LogNoteTransformer", func() { - It("transforms VatFlux log events", func() { - blockNumber := int64(9004474) - config := shared_t.TransformerConfig{ - TransformerName: constants.VatFluxLabel, - ContractAddresses: []string{test_data.KovanVatContractAddress}, - ContractAbi: test_data.KovanVatABI, - Topic: test_data.KovanVatFluxSignature, - StartingBlockNumber: blockNumber, - EndingBlockNumber: blockNumber, - } - - rpcClient, ethClient, err := getClients(ipc) - Expect(err).NotTo(HaveOccurred()) - blockChain, err := getBlockChain(rpcClient, ethClient) - Expect(err).NotTo(HaveOccurred()) - - db := test_config.NewTestDB(blockChain.Node()) - test_config.CleanTestDB(db) - - header, err := persistHeader(db, blockNumber, blockChain) - Expect(err).NotTo(HaveOccurred()) - - fetcher := shared.NewFetcher(blockChain) - logs, err := fetcher.FetchLogs( - shared_t.HexStringsToAddresses(config.ContractAddresses), - []common.Hash{common.HexToHash(config.Topic)}, - header) - Expect(err).NotTo(HaveOccurred()) - - initializer := factories.LogNoteTransformer{ - Config: config, - Converter: &vat_flux.VatFluxConverter{}, - Repository: &vat_flux.VatFluxRepository{}, - } - transformer := initializer.NewLogNoteTransformer(db) - - err = transformer.Execute(logs, header, constants.HeaderMissing) - Expect(err).NotTo(HaveOccurred()) - - var dbResult []vat_flux.VatFluxModel - err = db.Select(&dbResult, `SELECT ilk, src, dst, rad from maker.vat_flux`) - Expect(err).NotTo(HaveOccurred()) - - Expect(len(dbResult)).To(Equal(1)) - ilkID, err := shared.GetOrCreateIlk("5245500000000000000000000000000000000000000000000000000000000000", db) - Expect(err).NotTo(HaveOccurred()) - Expect(dbResult[0].Ilk).To(Equal(strconv.Itoa(ilkID))) - Expect(dbResult[0].Src).To(Equal("000000000000000000000000c0851f73cc8dd5c0765e71980ec7e7fd1ef74434")) - Expect(dbResult[0].Dst).To(Equal("0000000000000000000000000000d8b4147eda80fec7122ae16da2479cbd7ffb")) - Expect(dbResult[0].Rad).To(Equal("1800000000000000000000000000000000000000000000")) - Expect(dbResult[0].TransactionIndex).To(Equal(uint(0))) - }) - - It("rechecks vat flux event", func() { - blockNumber := int64(9004474) - config := shared.TransformerConfig{ - TransformerName: constants.VatFluxLabel, - ContractAddresses: []string{test_data.KovanVatContractAddress}, - ContractAbi: test_data.KovanVatABI, - Topic: test_data.KovanVatFluxSignature, - StartingBlockNumber: blockNumber, - EndingBlockNumber: blockNumber, - } - - rpcClient, ethClient, err := getClients(ipc) - Expect(err).NotTo(HaveOccurred()) - blockChain, err := getBlockChain(rpcClient, ethClient) - Expect(err).NotTo(HaveOccurred()) - - db := test_config.NewTestDB(blockChain.Node()) - test_config.CleanTestDB(db) - - header, err := persistHeader(db, blockNumber, blockChain) - Expect(err).NotTo(HaveOccurred()) - - fetcher := shared.NewFetcher(blockChain) - logs, err := fetcher.FetchLogs( - shared.HexStringsToAddresses(config.ContractAddresses), - []common.Hash{common.HexToHash(config.Topic)}, - header) - Expect(err).NotTo(HaveOccurred()) - - initializer := factories.LogNoteTransformer{ - Config: config, - Converter: &vat_flux.VatFluxConverter{}, - Repository: &vat_flux.VatFluxRepository{}, - } - transformer := initializer.NewLogNoteTransformer(db) - - err = transformer.Execute(logs, header, constants.HeaderMissing) - Expect(err).NotTo(HaveOccurred()) - - err = transformer.Execute(logs, header, constants.HeaderRecheck) - Expect(err).NotTo(HaveOccurred()) - - var headerID int64 - err = db.Get(&headerID, `SELECT id FROM public.headers WHERE block_number = $1`, blockNumber) - Expect(err).NotTo(HaveOccurred()) - - var vatFluxChecked []int - err = db.Select(&vatFluxChecked, `SELECT vat_flux_checked FROM public.checked_headers WHERE header_id = $1`, headerID) - Expect(err).NotTo(HaveOccurred()) - - Expect(vatFluxChecked[0]).To(Equal(2)) - - var dbResult []vat_flux.VatFluxModel - err = db.Select(&dbResult, `SELECT ilk, src, dst, rad from maker.vat_flux`) - Expect(err).NotTo(HaveOccurred()) - - Expect(len(dbResult)).To(Equal(1)) - ilkID, err := shared.GetOrCreateIlk("5245500000000000000000000000000000000000000000000000000000000000", db) - Expect(err).NotTo(HaveOccurred()) - Expect(dbResult[0].Ilk).To(Equal(strconv.Itoa(ilkID))) - Expect(dbResult[0].Src).To(Equal("000000000000000000000000c0851f73cc8dd5c0765e71980ec7e7fd1ef74434")) - Expect(dbResult[0].Dst).To(Equal("0000000000000000000000000000d8b4147eda80fec7122ae16da2479cbd7ffb")) - Expect(dbResult[0].Rad).To(Equal("1800000000000000000000000000000000000000000000")) - Expect(dbResult[0].TransactionIndex).To(Equal(uint(0))) - }) -}) diff --git a/pkg/transformers/integration_tests/vat_fold.go b/pkg/transformers/integration_tests/vat_fold.go deleted file mode 100644 index 92e1ea12..00000000 --- a/pkg/transformers/integration_tests/vat_fold.go +++ /dev/null @@ -1,149 +0,0 @@ -// VulcanizeDB -// Copyright © 2018 Vulcanize - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. - -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -package integration_tests - -import ( - "github.com/ethereum/go-ethereum/common" - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - "github.com/vulcanize/vulcanizedb/pkg/core" - "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" - "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" - "github.com/vulcanize/vulcanizedb/test_config" - "strconv" - - shared_t "github.com/vulcanize/vulcanizedb/libraries/shared/transformer" - "github.com/vulcanize/vulcanizedb/pkg/transformers/factories" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" - "github.com/vulcanize/vulcanizedb/pkg/transformers/vat_fold" -) - -var _ = Describe("VatFold Transformer", func() { - var ( - db *postgres.DB - blockChain core.BlockChain - ) - - BeforeEach(func() { - rpcClient, ethClient, err := getClients(ipc) - Expect(err).NotTo(HaveOccurred()) - blockChain, err = getBlockChain(rpcClient, ethClient) - Expect(err).NotTo(HaveOccurred()) - db = test_config.NewTestDB(blockChain.Node()) - test_config.CleanTestDB(db) - }) - - It("transforms VatFold log events", func() { - blockNumber := int64(9367233) - config := shared_t.TransformerConfig{ - TransformerName: constants.VatFoldLabel, - ContractAddresses: []string{test_data.KovanVatContractAddress}, - ContractAbi: test_data.KovanVatABI, - Topic: test_data.KovanVatFoldSignature, - StartingBlockNumber: blockNumber, - EndingBlockNumber: blockNumber, - } - - header, err := persistHeader(db, blockNumber, blockChain) - Expect(err).NotTo(HaveOccurred()) - - fetcher := shared.NewFetcher(blockChain) - logs, err := fetcher.FetchLogs( - shared_t.HexStringsToAddresses(config.ContractAddresses), - []common.Hash{common.HexToHash(config.Topic)}, - header) - Expect(err).NotTo(HaveOccurred()) - - transformer := factories.LogNoteTransformer{ - Config: config, - Converter: &vat_fold.VatFoldConverter{}, - Repository: &vat_fold.VatFoldRepository{}, - }.NewLogNoteTransformer(db) - - err = transformer.Execute(logs, header, constants.HeaderMissing) - Expect(err).NotTo(HaveOccurred()) - - var dbResults []vat_fold.VatFoldModel - err = db.Select(&dbResults, `SELECT ilk, urn, rate from maker.vat_fold`) - Expect(err).NotTo(HaveOccurred()) - - Expect(len(dbResults)).To(Equal(1)) - dbResult := dbResults[0] - ilkID, err := shared.GetOrCreateIlk("5245500000000000000000000000000000000000000000000000000000000000", db) - Expect(err).NotTo(HaveOccurred()) - Expect(dbResult.Ilk).To(Equal(strconv.Itoa(ilkID))) - Expect(dbResult.Urn).To(Equal("0000000000000000000000003728e9777b2a0a611ee0f89e00e01044ce4736d1")) - Expect(dbResult.Rate).To(Equal("0.000000000000000000000000000")) - }) - - It("rechecks vat fold event", func() { - blockNumber := int64(9367233) - config := shared.TransformerConfig{ - TransformerName: constants.VatFoldLabel, - ContractAddresses: []string{test_data.KovanVatContractAddress}, - ContractAbi: test_data.KovanVatABI, - Topic: test_data.KovanVatFoldSignature, - StartingBlockNumber: blockNumber, - EndingBlockNumber: blockNumber, - } - - header, err := persistHeader(db, blockNumber, blockChain) - Expect(err).NotTo(HaveOccurred()) - - fetcher := shared.NewFetcher(blockChain) - logs, err := fetcher.FetchLogs( - shared.HexStringsToAddresses(config.ContractAddresses), - []common.Hash{common.HexToHash(config.Topic)}, - header) - Expect(err).NotTo(HaveOccurred()) - - transformer := factories.LogNoteTransformer{ - Config: config, - Converter: &vat_fold.VatFoldConverter{}, - Repository: &vat_fold.VatFoldRepository{}, - }.NewLogNoteTransformer(db) - - err = transformer.Execute(logs, header, constants.HeaderMissing) - Expect(err).NotTo(HaveOccurred()) - - err = transformer.Execute(logs, header, constants.HeaderRecheck) - Expect(err).NotTo(HaveOccurred()) - - var headerID int64 - err = db.Get(&headerID, `SELECT id FROM public.headers WHERE block_number = $1`, blockNumber) - Expect(err).NotTo(HaveOccurred()) - - var vatFoldChecked []int - err = db.Select(&vatFoldChecked, `SELECT vat_fold_checked FROM public.checked_headers WHERE header_id = $1`, headerID) - Expect(err).NotTo(HaveOccurred()) - - Expect(vatFoldChecked[0]).To(Equal(2)) - - var dbResults []vat_fold.VatFoldModel - err = db.Select(&dbResults, `SELECT ilk, urn, rate from maker.vat_fold`) - Expect(err).NotTo(HaveOccurred()) - - Expect(len(dbResults)).To(Equal(1)) - dbResult := dbResults[0] - ilkID, err := shared.GetOrCreateIlk("5245500000000000000000000000000000000000000000000000000000000000", db) - Expect(err).NotTo(HaveOccurred()) - Expect(dbResult.Ilk).To(Equal(strconv.Itoa(ilkID))) - Expect(dbResult.Urn).To(Equal("0000000000000000000000003728e9777b2a0a611ee0f89e00e01044ce4736d1")) - Expect(dbResult.Rate).To(Equal("0.000000000000000000000000000")) - }) -}) diff --git a/pkg/transformers/integration_tests/vat_grab.go b/pkg/transformers/integration_tests/vat_grab.go deleted file mode 100644 index 07546ded..00000000 --- a/pkg/transformers/integration_tests/vat_grab.go +++ /dev/null @@ -1,164 +0,0 @@ -// VulcanizeDB -// Copyright © 2018 Vulcanize - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. - -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -package integration_tests - -import ( - "github.com/ethereum/go-ethereum/common" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" - "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" - "math/big" - "strconv" - - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - - shared_t "github.com/vulcanize/vulcanizedb/libraries/shared/transformer" - "github.com/vulcanize/vulcanizedb/pkg/transformers/factories" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" - "github.com/vulcanize/vulcanizedb/pkg/transformers/vat_grab" - "github.com/vulcanize/vulcanizedb/test_config" -) - -var _ = Describe("Vat Grab Transformer", func() { - It("transforms VatGrab log events", func() { - blockNumber := int64(8958230) - config := shared_t.TransformerConfig{ - TransformerName: constants.VatGrabLabel, - ContractAddresses: []string{test_data.KovanVatContractAddress}, - ContractAbi: test_data.KovanVatABI, - Topic: test_data.KovanVatGrabSignature, - StartingBlockNumber: blockNumber, - EndingBlockNumber: blockNumber, - } - - rpcClient, ethClient, err := getClients(ipc) - Expect(err).NotTo(HaveOccurred()) - blockChain, err := getBlockChain(rpcClient, ethClient) - Expect(err).NotTo(HaveOccurred()) - - db := test_config.NewTestDB(blockChain.Node()) - test_config.CleanTestDB(db) - - header, err := persistHeader(db, blockNumber, blockChain) - Expect(err).NotTo(HaveOccurred()) - - fetcher := shared.NewFetcher(blockChain) - logs, err := fetcher.FetchLogs( - shared_t.HexStringsToAddresses(config.ContractAddresses), - []common.Hash{common.HexToHash(config.Topic)}, - header) - Expect(err).NotTo(HaveOccurred()) - - transformer := factories.LogNoteTransformer{ - Config: config, - Converter: &vat_grab.VatGrabConverter{}, - Repository: &vat_grab.VatGrabRepository{}, - }.NewLogNoteTransformer(db) - - err = transformer.Execute(logs, header, constants.HeaderMissing) - Expect(err).NotTo(HaveOccurred()) - - var dbResult []vat_grab.VatGrabModel - err = db.Select(&dbResult, `SELECT ilk, urn, v, w, dink, dart from maker.vat_grab`) - Expect(err).NotTo(HaveOccurred()) - - Expect(len(dbResult)).To(Equal(1)) - ilkID, err := shared.GetOrCreateIlk("5245500000000000000000000000000000000000000000000000000000000000", db) - Expect(err).NotTo(HaveOccurred()) - Expect(dbResult[0].Ilk).To(Equal(strconv.Itoa(ilkID))) - Expect(dbResult[0].Urn).To(Equal("0000000000000000000000006a3ae20c315e845b2e398e68effe39139ec6060c")) - Expect(dbResult[0].V).To(Equal("0000000000000000000000002f34f22a00ee4b7a8f8bbc4eaee1658774c624e0")) //cat contract address as bytes32 - Expect(dbResult[0].W).To(Equal("0000000000000000000000003728e9777b2a0a611ee0f89e00e01044ce4736d1")) - expectedDink := new(big.Int) - expectedDink.SetString("115792089237316195423570985008687907853269984665640564039455584007913129639936", 10) - Expect(dbResult[0].Dink).To(Equal(expectedDink.String())) - expectedDart := new(big.Int) - expectedDart.SetString("115792089237316195423570985008687907853269984665640564039441803007913129639936", 10) - Expect(dbResult[0].Dart).To(Equal(expectedDart.String())) - Expect(dbResult[0].TransactionIndex).To(Equal(uint(0))) - }) - - It("rechecks vat grab event", func() { - blockNumber := int64(8958230) - config := shared.TransformerConfig{ - TransformerName: constants.VatGrabLabel, - ContractAddresses: []string{test_data.KovanVatContractAddress}, - ContractAbi: test_data.KovanVatABI, - Topic: test_data.KovanVatGrabSignature, - StartingBlockNumber: blockNumber, - EndingBlockNumber: blockNumber, - } - - rpcClient, ethClient, err := getClients(ipc) - Expect(err).NotTo(HaveOccurred()) - blockChain, err := getBlockChain(rpcClient, ethClient) - Expect(err).NotTo(HaveOccurred()) - - db := test_config.NewTestDB(blockChain.Node()) - test_config.CleanTestDB(db) - - header, err := persistHeader(db, blockNumber, blockChain) - Expect(err).NotTo(HaveOccurred()) - - fetcher := shared.NewFetcher(blockChain) - logs, err := fetcher.FetchLogs( - shared.HexStringsToAddresses(config.ContractAddresses), - []common.Hash{common.HexToHash(config.Topic)}, - header) - Expect(err).NotTo(HaveOccurred()) - transformer := factories.LogNoteTransformer{ - Config: config, - Converter: &vat_grab.VatGrabConverter{}, - Repository: &vat_grab.VatGrabRepository{}, - }.NewLogNoteTransformer(db) - - err = transformer.Execute(logs, header, constants.HeaderMissing) - Expect(err).NotTo(HaveOccurred()) - - err = transformer.Execute(logs, header, constants.HeaderRecheck) - Expect(err).NotTo(HaveOccurred()) - - var headerID int64 - err = db.Get(&headerID, `SELECT id FROM public.headers WHERE block_number = $1`, blockNumber) - Expect(err).NotTo(HaveOccurred()) - - var vatGrabChecked []int - err = db.Select(&vatGrabChecked, `SELECT vat_grab_checked FROM public.checked_headers WHERE header_id = $1`, headerID) - Expect(err).NotTo(HaveOccurred()) - - Expect(vatGrabChecked[0]).To(Equal(2)) - - var dbResult []vat_grab.VatGrabModel - err = db.Select(&dbResult, `SELECT ilk, urn, v, w, dink, dart from maker.vat_grab`) - Expect(err).NotTo(HaveOccurred()) - - Expect(len(dbResult)).To(Equal(1)) - ilkID, err := shared.GetOrCreateIlk("5245500000000000000000000000000000000000000000000000000000000000", db) - Expect(err).NotTo(HaveOccurred()) - Expect(dbResult[0].Ilk).To(Equal(strconv.Itoa(ilkID))) - Expect(dbResult[0].Urn).To(Equal("0000000000000000000000006a3ae20c315e845b2e398e68effe39139ec6060c")) - Expect(dbResult[0].V).To(Equal("0000000000000000000000002f34f22a00ee4b7a8f8bbc4eaee1658774c624e0")) //cat contract address - Expect(dbResult[0].W).To(Equal("0000000000000000000000003728e9777b2a0a611ee0f89e00e01044ce4736d1")) - expectedDink := new(big.Int) - expectedDink.SetString("115792089237316195423570985008687907853269984665640564039455584007913129639936", 10) - Expect(dbResult[0].Dink).To(Equal(expectedDink.String())) - expectedDart := new(big.Int) - expectedDart.SetString("115792089237316195423570985008687907853269984665640564039441803007913129639936", 10) - Expect(dbResult[0].Dart).To(Equal(expectedDart.String())) - Expect(dbResult[0].TransactionIndex).To(Equal(uint(0))) - }) -}) diff --git a/pkg/transformers/integration_tests/vat_init.go b/pkg/transformers/integration_tests/vat_init.go deleted file mode 100644 index 23c9beb8..00000000 --- a/pkg/transformers/integration_tests/vat_init.go +++ /dev/null @@ -1,145 +0,0 @@ -// VulcanizeDB -// Copyright © 2018 Vulcanize - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. - -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -package integration_tests - -import ( - "github.com/ethereum/go-ethereum/common" - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - "github.com/vulcanize/vulcanizedb/pkg/transformers/factories" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" - "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" - "strconv" - - shared_t "github.com/vulcanize/vulcanizedb/libraries/shared/transformer" - "github.com/vulcanize/vulcanizedb/pkg/transformers/vat_init" - "github.com/vulcanize/vulcanizedb/test_config" -) - -var _ = Describe("VatInit LogNoteTransformer", func() { - It("transforms VatInit log events", func() { - blockNumber := int64(8535561) - config := shared_t.TransformerConfig{ - TransformerName: constants.VatInitLabel, - ContractAddresses: []string{test_data.KovanVatContractAddress}, - ContractAbi: test_data.KovanVatABI, - Topic: test_data.KovanVatInitSignature, - StartingBlockNumber: blockNumber, - EndingBlockNumber: blockNumber, - } - - rpcClient, ethClient, err := getClients(ipc) - Expect(err).NotTo(HaveOccurred()) - blockChain, err := getBlockChain(rpcClient, ethClient) - Expect(err).NotTo(HaveOccurred()) - - db := test_config.NewTestDB(blockChain.Node()) - test_config.CleanTestDB(db) - - header, err := persistHeader(db, blockNumber, blockChain) - Expect(err).NotTo(HaveOccurred()) - - fetcher := shared.NewFetcher(blockChain) - logs, err := fetcher.FetchLogs( - shared_t.HexStringsToAddresses(config.ContractAddresses), - []common.Hash{common.HexToHash(config.Topic)}, - header) - Expect(err).NotTo(HaveOccurred()) - - transformer := factories.LogNoteTransformer{ - Config: config, - Converter: &vat_init.VatInitConverter{}, - Repository: &vat_init.VatInitRepository{}, - }.NewLogNoteTransformer(db) - - err = transformer.Execute(logs, header, constants.HeaderMissing) - Expect(err).NotTo(HaveOccurred()) - - var dbResults []vat_init.VatInitModel - err = db.Select(&dbResults, `SELECT ilk from maker.vat_init`) - Expect(err).NotTo(HaveOccurred()) - - Expect(len(dbResults)).To(Equal(1)) - dbResult := dbResults[0] - ilkID, err := shared.GetOrCreateIlk("4554480000000000000000000000000000000000000000000000000000000000", db) - Expect(err).NotTo(HaveOccurred()) - Expect(dbResult.Ilk).To(Equal(strconv.Itoa(ilkID))) - }) - - It("rechecks vat init event", func() { - blockNumber := int64(8535561) - config := shared.TransformerConfig{ - TransformerName: constants.VatInitLabel, - ContractAddresses: []string{test_data.KovanVatContractAddress}, - ContractAbi: test_data.KovanVatABI, - Topic: test_data.KovanVatInitSignature, - StartingBlockNumber: blockNumber, - EndingBlockNumber: blockNumber, - } - - rpcClient, ethClient, err := getClients(ipc) - Expect(err).NotTo(HaveOccurred()) - blockChain, err := getBlockChain(rpcClient, ethClient) - Expect(err).NotTo(HaveOccurred()) - - db := test_config.NewTestDB(blockChain.Node()) - test_config.CleanTestDB(db) - - header, err := persistHeader(db, blockNumber, blockChain) - Expect(err).NotTo(HaveOccurred()) - - fetcher := shared.NewFetcher(blockChain) - logs, err := fetcher.FetchLogs( - shared.HexStringsToAddresses(config.ContractAddresses), - []common.Hash{common.HexToHash(config.Topic)}, - header) - Expect(err).NotTo(HaveOccurred()) - - transformer := factories.LogNoteTransformer{ - Config: config, - Converter: &vat_init.VatInitConverter{}, - Repository: &vat_init.VatInitRepository{}, - }.NewLogNoteTransformer(db) - - err = transformer.Execute(logs, header, constants.HeaderMissing) - Expect(err).NotTo(HaveOccurred()) - - err = transformer.Execute(logs, header, constants.HeaderMissing) - Expect(err).NotTo(HaveOccurred()) - - var headerID int64 - err = db.Get(&headerID, `SELECT id FROM public.headers WHERE block_number = $1`, blockNumber) - Expect(err).NotTo(HaveOccurred()) - - var vatInitChecked []int - err = db.Select(&vatInitChecked, `SELECT vat_init_checked FROM public.checked_headers WHERE header_id = $1`, headerID) - Expect(err).NotTo(HaveOccurred()) - - Expect(vatInitChecked[0]).To(Equal(2)) - - var dbResults []vat_init.VatInitModel - err = db.Select(&dbResults, `SELECT ilk from maker.vat_init`) - Expect(err).NotTo(HaveOccurred()) - - Expect(len(dbResults)).To(Equal(1)) - dbResult := dbResults[0] - ilkID, err := shared.GetOrCreateIlk("4554480000000000000000000000000000000000000000000000000000000000", db) - Expect(err).NotTo(HaveOccurred()) - Expect(dbResult.Ilk).To(Equal(strconv.Itoa(ilkID))) - }) -}) diff --git a/pkg/transformers/integration_tests/vat_slip.go b/pkg/transformers/integration_tests/vat_slip.go deleted file mode 100644 index 5b723c5c..00000000 --- a/pkg/transformers/integration_tests/vat_slip.go +++ /dev/null @@ -1,142 +0,0 @@ -package integration_tests - -import ( - "github.com/ethereum/go-ethereum/common" - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" - "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" - "strconv" - - shared_t "github.com/vulcanize/vulcanizedb/libraries/shared/transformer" - "github.com/vulcanize/vulcanizedb/pkg/core" - "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" - "github.com/vulcanize/vulcanizedb/pkg/transformers/factories" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" - "github.com/vulcanize/vulcanizedb/pkg/transformers/vat_slip" - "github.com/vulcanize/vulcanizedb/test_config" -) - -var _ = Describe("Vat slip transformer", func() { - var ( - db *postgres.DB - blockChain core.BlockChain - ) - - BeforeEach(func() { - rpcClient, ethClient, err := getClients(ipc) - Expect(err).NotTo(HaveOccurred()) - blockChain, err = getBlockChain(rpcClient, ethClient) - Expect(err).NotTo(HaveOccurred()) - db = test_config.NewTestDB(blockChain.Node()) - test_config.CleanTestDB(db) - }) - - It("persists vat slip event", func() { - blockNumber := int64(8953655) - config := shared_t.TransformerConfig{ - TransformerName: constants.VatSlipLabel, - ContractAddresses: []string{test_data.KovanVatContractAddress}, - ContractAbi: test_data.KovanVatABI, - Topic: test_data.KovanVatSlipSignature, - StartingBlockNumber: blockNumber, - EndingBlockNumber: blockNumber, - } - - header, err := persistHeader(db, blockNumber, blockChain) - Expect(err).NotTo(HaveOccurred()) - - fetcher := shared.NewFetcher(blockChain) - logs, err := fetcher.FetchLogs( - shared_t.HexStringsToAddresses(config.ContractAddresses), - []common.Hash{common.HexToHash(config.Topic)}, - header) - Expect(err).NotTo(HaveOccurred()) - - transformer := factories.LogNoteTransformer{ - Config: config, - Converter: &vat_slip.VatSlipConverter{}, - Repository: &vat_slip.VatSlipRepository{}, - }.NewLogNoteTransformer(db) - - err = transformer.Execute(logs, header, constants.HeaderMissing) - - Expect(err).NotTo(HaveOccurred()) - var headerID int64 - err = db.Get(&headerID, `SELECT id FROM public.headers WHERE block_number = $1`, blockNumber) - Expect(err).NotTo(HaveOccurred()) - var model vat_slip.VatSlipModel - err = db.Get(&model, `SELECT ilk, guy, rad, tx_idx FROM maker.vat_slip WHERE header_id = $1`, headerID) - Expect(err).NotTo(HaveOccurred()) - ilkID, err := shared.GetOrCreateIlk("4554480000000000000000000000000000000000000000000000000000000000", db) - Expect(err).NotTo(HaveOccurred()) - Expect(model.Ilk).To(Equal(strconv.Itoa(ilkID))) - Expect(model.Guy).To(Equal("000000000000000000000000da15dce70ab462e66779f23ee14f21d993789ee3")) - Expect(model.Rad).To(Equal("100000000000000000000000000000000000000000000000")) - Expect(model.TransactionIndex).To(Equal(uint(0))) - var headerChecked bool - err = db.Get(&headerChecked, `SELECT vat_slip_checked FROM public.checked_headers WHERE header_id = $1`, headerID) - Expect(err).NotTo(HaveOccurred()) - Expect(headerChecked).To(BeTrue()) - }) - - It("rechecks vat slip event", func() { - blockNumber := int64(8953655) - config := shared.TransformerConfig{ - TransformerName: constants.VatSlipLabel, - ContractAddresses: []string{test_data.KovanVatContractAddress}, - ContractAbi: test_data.KovanVatABI, - Topic: test_data.KovanVatSlipSignature, - StartingBlockNumber: blockNumber, - EndingBlockNumber: blockNumber, - } - - header, err := persistHeader(db, blockNumber, blockChain) - Expect(err).NotTo(HaveOccurred()) - - fetcher := shared.NewFetcher(blockChain) - logs, err := fetcher.FetchLogs( - shared.HexStringsToAddresses(config.ContractAddresses), - []common.Hash{common.HexToHash(config.Topic)}, - header) - Expect(err).NotTo(HaveOccurred()) - - transformer := factories.LogNoteTransformer{ - Config: config, - Converter: &vat_slip.VatSlipConverter{}, - Repository: &vat_slip.VatSlipRepository{}, - }.NewLogNoteTransformer(db) - - err = transformer.Execute(logs, header, constants.HeaderMissing) - Expect(err).NotTo(HaveOccurred()) - - err = transformer.Execute(logs, header, constants.HeaderRecheck) - Expect(err).NotTo(HaveOccurred()) - - var headerID int64 - err = db.Get(&headerID, `SELECT id FROM public.headers WHERE block_number = $1`, blockNumber) - Expect(err).NotTo(HaveOccurred()) - - var vatSlipChecked []int - err = db.Select(&vatSlipChecked, `SELECT vat_slip_checked FROM public.checked_headers WHERE header_id = $1`, headerID) - Expect(err).NotTo(HaveOccurred()) - - Expect(vatSlipChecked[0]).To(Equal(2)) - - err = db.Get(&headerID, `SELECT id FROM public.headers WHERE block_number = $1`, blockNumber) - Expect(err).NotTo(HaveOccurred()) - var model vat_slip.VatSlipModel - err = db.Get(&model, `SELECT ilk, guy, rad, tx_idx FROM maker.vat_slip WHERE header_id = $1`, headerID) - Expect(err).NotTo(HaveOccurred()) - ilkID, err := shared.GetOrCreateIlk("4554480000000000000000000000000000000000000000000000000000000000", db) - Expect(err).NotTo(HaveOccurred()) - Expect(model.Ilk).To(Equal(strconv.Itoa(ilkID))) - Expect(model.Guy).To(Equal("000000000000000000000000da15dce70ab462e66779f23ee14f21d993789ee3")) - Expect(model.Rad).To(Equal("100000000000000000000000000000000000000000000000")) - Expect(model.TransactionIndex).To(Equal(uint(0))) - var headerChecked int - err = db.Get(&headerChecked, `SELECT vat_slip_checked FROM public.checked_headers WHERE header_id = $1`, headerID) - Expect(err).NotTo(HaveOccurred()) - Expect(headerChecked).To(Equal(2)) - }) -}) diff --git a/pkg/transformers/integration_tests/vat_tune.go b/pkg/transformers/integration_tests/vat_tune.go deleted file mode 100644 index 674d963d..00000000 --- a/pkg/transformers/integration_tests/vat_tune.go +++ /dev/null @@ -1,161 +0,0 @@ -// VulcanizeDB -// Copyright © 2018 Vulcanize - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. - -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -package integration_tests - -import ( - "github.com/ethereum/go-ethereum/common" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" - "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" - "math/big" - "strconv" - - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - - shared_t "github.com/vulcanize/vulcanizedb/libraries/shared/transformer" - "github.com/vulcanize/vulcanizedb/pkg/transformers/factories" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" - "github.com/vulcanize/vulcanizedb/pkg/transformers/vat_tune" - "github.com/vulcanize/vulcanizedb/test_config" -) - -var _ = Describe("VatTune LogNoteTransformer", func() { - It("transforms VatTune log events", func() { - blockNumber := int64(8761670) - config := shared_t.TransformerConfig{ - TransformerName: constants.VatTuneLabel, - ContractAddresses: []string{test_data.KovanVatContractAddress}, - ContractAbi: test_data.KovanVatABI, - Topic: test_data.KovanVatTuneSignature, - StartingBlockNumber: blockNumber, - EndingBlockNumber: blockNumber, - } - - rpcClient, ethClient, err := getClients(ipc) - Expect(err).NotTo(HaveOccurred()) - blockChain, err := getBlockChain(rpcClient, ethClient) - Expect(err).NotTo(HaveOccurred()) - - db := test_config.NewTestDB(blockChain.Node()) - test_config.CleanTestDB(db) - - header, err := persistHeader(db, blockNumber, blockChain) - Expect(err).NotTo(HaveOccurred()) - - fetcher := shared.NewFetcher(blockChain) - logs, err := fetcher.FetchLogs( - shared_t.HexStringsToAddresses(config.ContractAddresses), - []common.Hash{common.HexToHash(config.Topic)}, - header) - Expect(err).NotTo(HaveOccurred()) - - transformer := factories.LogNoteTransformer{ - Config: config, - Converter: &vat_tune.VatTuneConverter{}, - Repository: &vat_tune.VatTuneRepository{}, - }.NewLogNoteTransformer(db) - - err = transformer.Execute(logs, header, constants.HeaderMissing) - Expect(err).NotTo(HaveOccurred()) - - var dbResult []vat_tune.VatTuneModel - err = db.Select(&dbResult, `SELECT ilk, urn, v, w, dink, dart from maker.vat_tune`) - Expect(err).NotTo(HaveOccurred()) - - Expect(len(dbResult)).To(Equal(1)) - ilkID, err := shared.GetOrCreateIlk("4554480000000000000000000000000000000000000000000000000000000000", db) - Expect(err).NotTo(HaveOccurred()) - Expect(dbResult[0].Ilk).To(Equal(strconv.Itoa(ilkID))) - Expect(dbResult[0].Urn).To(Equal("0000000000000000000000004f26ffbe5f04ed43630fdc30a87638d53d0b0876")) - Expect(dbResult[0].V).To(Equal("0000000000000000000000004f26ffbe5f04ed43630fdc30a87638d53d0b0876")) - Expect(dbResult[0].W).To(Equal("0000000000000000000000004f26ffbe5f04ed43630fdc30a87638d53d0b0876")) - Expect(dbResult[0].Dink).To(Equal("0")) - expectedDart := new(big.Int) - expectedDart.SetString("115792089237316195423570985008687907853269984665640564039455584007913129639936", 10) - Expect(dbResult[0].Dart).To(Equal(expectedDart.String())) - Expect(dbResult[0].TransactionIndex).To(Equal(uint(0))) - }) - - It("transforms VatTune log events", func() { - blockNumber := int64(8761670) - config := shared.TransformerConfig{ - TransformerName: constants.VatTuneLabel, - ContractAddresses: []string{test_data.KovanVatContractAddress}, - ContractAbi: test_data.KovanVatABI, - Topic: test_data.KovanVatTuneSignature, - StartingBlockNumber: blockNumber, - EndingBlockNumber: blockNumber, - } - - rpcClient, ethClient, err := getClients(ipc) - Expect(err).NotTo(HaveOccurred()) - blockChain, err := getBlockChain(rpcClient, ethClient) - Expect(err).NotTo(HaveOccurred()) - - db := test_config.NewTestDB(blockChain.Node()) - test_config.CleanTestDB(db) - - header, err := persistHeader(db, blockNumber, blockChain) - Expect(err).NotTo(HaveOccurred()) - - fetcher := shared.NewFetcher(blockChain) - logs, err := fetcher.FetchLogs( - shared.HexStringsToAddresses(config.ContractAddresses), - []common.Hash{common.HexToHash(config.Topic)}, - header) - Expect(err).NotTo(HaveOccurred()) - - transformer := factories.LogNoteTransformer{ - Config: config, - Converter: &vat_tune.VatTuneConverter{}, - Repository: &vat_tune.VatTuneRepository{}, - }.NewLogNoteTransformer(db) - - err = transformer.Execute(logs, header, constants.HeaderMissing) - Expect(err).NotTo(HaveOccurred()) - - err = transformer.Execute(logs, header, constants.HeaderRecheck) - Expect(err).NotTo(HaveOccurred()) - - var headerID int64 - err = db.Get(&headerID, `SELECT id FROM public.headers WHERE block_number = $1`, blockNumber) - Expect(err).NotTo(HaveOccurred()) - - var vatTuneChecked []int - err = db.Select(&vatTuneChecked, `SELECT vat_tune_checked FROM public.checked_headers WHERE header_id = $1`, headerID) - Expect(err).NotTo(HaveOccurred()) - - Expect(vatTuneChecked[0]).To(Equal(2)) - - var dbResult []vat_tune.VatTuneModel - err = db.Select(&dbResult, `SELECT ilk, urn, v, w, dink, dart from maker.vat_tune`) - Expect(err).NotTo(HaveOccurred()) - - Expect(len(dbResult)).To(Equal(1)) - ilkID, err := shared.GetOrCreateIlk("4554480000000000000000000000000000000000000000000000000000000000", db) - Expect(err).NotTo(HaveOccurred()) - Expect(dbResult[0].Ilk).To(Equal(strconv.Itoa(ilkID))) - Expect(dbResult[0].Urn).To(Equal("0000000000000000000000004f26ffbe5f04ed43630fdc30a87638d53d0b0876")) - Expect(dbResult[0].V).To(Equal("0000000000000000000000004f26ffbe5f04ed43630fdc30a87638d53d0b0876")) - Expect(dbResult[0].W).To(Equal("0000000000000000000000004f26ffbe5f04ed43630fdc30a87638d53d0b0876")) - Expect(dbResult[0].Dink).To(Equal("0")) - expectedDart := new(big.Int) - expectedDart.SetString("115792089237316195423570985008687907853269984665640564039455584007913129639936", 10) - Expect(dbResult[0].Dart).To(Equal(expectedDart.String())) - Expect(dbResult[0].TransactionIndex).To(Equal(uint(0))) - }) -}) diff --git a/pkg/transformers/pit_file/ilk/converter.go b/pkg/transformers/pit_file/ilk/converter.go deleted file mode 100644 index 3013b032..00000000 --- a/pkg/transformers/pit_file/ilk/converter.go +++ /dev/null @@ -1,84 +0,0 @@ -// VulcanizeDB -// Copyright © 2018 Vulcanize - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. - -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -package ilk - -import ( - "bytes" - "encoding/json" - "errors" - "math/big" - - "github.com/ethereum/go-ethereum/core/types" - - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" -) - -type PitFileIlkConverter struct{} - -func (PitFileIlkConverter) ToModels(ethLogs []types.Log) ([]interface{}, error) { - var models []interface{} - for _, ethLog := range ethLogs { - err := verifyLog(ethLog) - if err != nil { - return nil, err - } - ilk := shared.GetHexWithoutPrefix(ethLog.Topics[2].Bytes()) - what := string(bytes.Trim(ethLog.Topics[3].Bytes(), "\x00")) - dataBytes := ethLog.Data[len(ethLog.Data)-constants.DataItemLength:] - data, err := getData(dataBytes, what) - if err != nil { - return nil, err - } - - raw, err := json.Marshal(ethLog) - if err != nil { - return nil, err - } - model := PitFileIlkModel{ - Ilk: ilk, - What: what, - Data: data, - LogIndex: ethLog.Index, - TransactionIndex: ethLog.TxIndex, - Raw: raw, - } - models = append(models, model) - } - return models, nil -} - -func getData(dataBytes []byte, what string) (string, error) { - n := big.NewInt(0).SetBytes(dataBytes).String() - if what == "spot" { - return shared.ConvertToRay(n), nil - } else if what == "line" { - return shared.ConvertToWad(n), nil - } else { - return "", errors.New("unexpected payload for 'what'") - } -} - -func verifyLog(log types.Log) error { - if len(log.Topics) < 4 { - return errors.New("log missing topics") - } - if len(log.Data) < constants.DataItemLength { - return errors.New("log missing data") - } - return nil -} diff --git a/pkg/transformers/pit_file/ilk/repository.go b/pkg/transformers/pit_file/ilk/repository.go deleted file mode 100644 index 25b5af34..00000000 --- a/pkg/transformers/pit_file/ilk/repository.go +++ /dev/null @@ -1,99 +0,0 @@ -// VulcanizeDB -// Copyright © 2018 Vulcanize - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. - -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -package ilk - -import ( - "fmt" - - log "github.com/sirupsen/logrus" - - "github.com/vulcanize/vulcanizedb/pkg/core" - "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" -) - -type PitFileIlkRepository struct { - db *postgres.DB -} - -func (repository PitFileIlkRepository) Create(headerID int64, models []interface{}) error { - tx, dBaseErr := repository.db.Begin() - if dBaseErr != nil { - return dBaseErr - } - - for _, model := range models { - pitFileIlk, ok := model.(PitFileIlkModel) - if !ok { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - log.Error("failed to rollback ", rollbackErr) - } - return fmt.Errorf("model of type %T, not %T", model, PitFileIlkModel{}) - } - - ilkID, ilkErr := shared.GetOrCreateIlkInTransaction(pitFileIlk.Ilk, tx) - if ilkErr != nil { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - log.Error("failed to rollback ", rollbackErr) - } - return ilkErr - } - - _, execErr := tx.Exec( - `INSERT into maker.pit_file_ilk (header_id, ilk, what, data, log_idx, tx_idx, raw_log) - VALUES($1, $2, $3, $4::NUMERIC, $5, $6, $7) - ON CONFLICT (header_id, tx_idx, log_idx) DO UPDATE SET ilk = $2, what = $3, data = $4, raw_log = $7;`, - headerID, ilkID, pitFileIlk.What, pitFileIlk.Data, pitFileIlk.LogIndex, pitFileIlk.TransactionIndex, pitFileIlk.Raw, - ) - if execErr != nil { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - log.Error("failed to rollback ", rollbackErr) - } - return execErr - } - } - - checkHeaderErr := shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.PitFileIlkChecked) - if checkHeaderErr != nil { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - log.Error("failed to rollback ", rollbackErr) - } - return checkHeaderErr - } - return tx.Commit() -} - -func (repository PitFileIlkRepository) MarkHeaderChecked(headerID int64) error { - return shared.MarkHeaderChecked(headerID, repository.db, constants.PitFileIlkChecked) -} - -func (repository PitFileIlkRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { - return shared.MissingHeaders(startingBlockNumber, endingBlockNumber, repository.db, constants.PitFileIlkChecked) -} - -func (repository PitFileIlkRepository) RecheckHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { - return shared.RecheckHeaders(startingBlockNumber, endingBlockNumber, repository.db, constants.PitFileIlkChecked) -} - -func (repository *PitFileIlkRepository) SetDB(db *postgres.DB) { - repository.db = db -} diff --git a/pkg/transformers/pit_file/ilk/repository_test.go b/pkg/transformers/pit_file/ilk/repository_test.go deleted file mode 100644 index f4b79681..00000000 --- a/pkg/transformers/pit_file/ilk/repository_test.go +++ /dev/null @@ -1,91 +0,0 @@ -// VulcanizeDB -// Copyright © 2018 Vulcanize - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. - -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -package ilk_test - -import ( - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" - "strconv" - - "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" - "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories" - "github.com/vulcanize/vulcanizedb/pkg/fakes" - "github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file/ilk" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" - "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" - "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/shared_behaviors" - "github.com/vulcanize/vulcanizedb/test_config" -) - -var _ = Describe("Pit file ilk repository", func() { - var ( - db *postgres.DB - pitFileIlkRepository ilk.PitFileIlkRepository - headerRepository repositories.HeaderRepository - ) - - BeforeEach(func() { - db = test_config.NewTestDB(test_config.NewTestNode()) - test_config.CleanTestDB(db) - pitFileIlkRepository = ilk.PitFileIlkRepository{} - pitFileIlkRepository.SetDB(db) - headerRepository = repositories.NewHeaderRepository(db) - }) - - Describe("Create", func() { - modelWithDifferentLogIdx := test_data.PitFileIlkSpotModel - modelWithDifferentLogIdx.LogIndex = modelWithDifferentLogIdx.LogIndex + 1 - inputs := shared_behaviors.CreateBehaviorInputs{ - CheckedHeaderColumnName: constants.PitFileIlkChecked, - LogEventTableName: "maker.pit_file_ilk", - TestModel: test_data.PitFileIlkSpotModel, - ModelWithDifferentLogIdx: modelWithDifferentLogIdx, - Repository: &pitFileIlkRepository, - } - - shared_behaviors.SharedRepositoryCreateBehaviors(&inputs) - - It("adds a pit file ilk event", func() { - headerID, err := headerRepository.CreateOrUpdateHeader(fakes.FakeHeader) - Expect(err).NotTo(HaveOccurred()) - err = pitFileIlkRepository.Create(headerID, []interface{}{test_data.PitFileIlkSpotModel}) - - Expect(err).NotTo(HaveOccurred()) - var dbPitFile ilk.PitFileIlkModel - err = db.Get(&dbPitFile, `SELECT ilk, what, data, log_idx, tx_idx, raw_log FROM maker.pit_file_ilk WHERE header_id = $1`, headerID) - Expect(err).NotTo(HaveOccurred()) - ilkID, err := shared.GetOrCreateIlk(test_data.PitFileIlkSpotModel.Ilk, db) - Expect(err).NotTo(HaveOccurred()) - Expect(dbPitFile.Ilk).To(Equal(strconv.Itoa(ilkID))) - Expect(dbPitFile.What).To(Equal(test_data.PitFileIlkSpotModel.What)) - Expect(dbPitFile.Data).To(Equal(test_data.PitFileIlkSpotModel.Data)) - Expect(dbPitFile.LogIndex).To(Equal(test_data.PitFileIlkSpotModel.LogIndex)) - Expect(dbPitFile.TransactionIndex).To(Equal(test_data.PitFileIlkSpotModel.TransactionIndex)) - Expect(dbPitFile.Raw).To(MatchJSON(test_data.PitFileIlkSpotModel.Raw)) - }) - }) - - Describe("MarkHeaderChecked", func() { - inputs := shared_behaviors.MarkedHeaderCheckedBehaviorInputs{ - CheckedHeaderColumnName: constants.PitFileIlkChecked, - Repository: &pitFileIlkRepository, - } - - shared_behaviors.SharedRepositoryMarkHeaderCheckedBehaviors(&inputs) - }) -}) diff --git a/pkg/transformers/storage_diffs/maker/cat/cat_suite_test.go b/pkg/transformers/storage_diffs/maker/cat/cat_suite_test.go deleted file mode 100644 index 98207fa0..00000000 --- a/pkg/transformers/storage_diffs/maker/cat/cat_suite_test.go +++ /dev/null @@ -1,19 +0,0 @@ -package cat_test - -import ( - "github.com/sirupsen/logrus" - "io/ioutil" - "testing" - - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" -) - -func TestCat(t *testing.T) { - RegisterFailHandler(Fail) - RunSpecs(t, "Cat Suite") -} - -var _ = BeforeSuite(func() { - logrus.SetOutput(ioutil.Discard) -}) diff --git a/pkg/transformers/storage_diffs/maker/cat/mappings.go b/pkg/transformers/storage_diffs/maker/cat/mappings.go deleted file mode 100644 index 46ade008..00000000 --- a/pkg/transformers/storage_diffs/maker/cat/mappings.go +++ /dev/null @@ -1,198 +0,0 @@ -package cat - -import ( - "github.com/ethereum/go-ethereum/common" - "github.com/sirupsen/logrus" - "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" - "strconv" -) - -const ( - NFlip = "nflip" - Live = "live" - Vat = "vat" - Pit = "pit" - Vow = "vow" - - IlkFlip = "flip" - IlkChop = "chop" - IlkLump = "lump" - - FlipIlk = "ilk" - FlipUrn = "urn" - FlipInk = "ink" - FlipTab = "tab" -) - -var ( - // wards takes up index 0 - IlksMappingIndex = storage_diffs.IndexOne // bytes32 => flip address; chop (ray), lump (wad) uint256 - FlipsMappingIndex = storage_diffs.IndexTwo // uint256 => ilk, urn bytes32; ink, tab uint256 (both wad) - - NFlipKey = common.HexToHash(storage_diffs.IndexThree) - NFlipMetadata = shared.GetStorageValueMetadata(NFlip, nil, shared.Uint256) - - LiveKey = common.HexToHash(storage_diffs.IndexFour) - LiveMetadata = shared.GetStorageValueMetadata(Live, nil, shared.Uint256) - - VatKey = common.HexToHash(storage_diffs.IndexFive) - VatMetadata = shared.GetStorageValueMetadata(Vat, nil, shared.Address) - - PitKey = common.HexToHash(storage_diffs.IndexSix) - PitMetadata = shared.GetStorageValueMetadata(Pit, nil, shared.Address) - - VowKey = common.HexToHash(storage_diffs.IndexSeven) - VowMetadata = shared.GetStorageValueMetadata(Vow, nil, shared.Address) -) - -type CatMappings struct { - StorageRepository maker.IMakerStorageRepository - mappings map[common.Hash]shared.StorageValueMetadata -} - -func (mappings CatMappings) 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 *CatMappings) SetDB(db *postgres.DB) { - mappings.StorageRepository.SetDB(db) -} - -func (mappings *CatMappings) loadMappings() error { - mappings.mappings = loadStaticMappings() - ilkErr := mappings.loadIlkKeys() - if ilkErr != nil { - return ilkErr - } - - flipsErr := mappings.loadFlipsKeys() - if flipsErr != nil { - return flipsErr - } - - return nil -} - -func loadStaticMappings() map[common.Hash]shared.StorageValueMetadata { - mappings := make(map[common.Hash]shared.StorageValueMetadata) - mappings[NFlipKey] = NFlipMetadata - mappings[LiveKey] = LiveMetadata - mappings[VatKey] = VatMetadata - mappings[PitKey] = PitMetadata - mappings[VowKey] = VowMetadata - return mappings -} - -// Ilks -func (mappings *CatMappings) loadIlkKeys() error { - ilks, err := mappings.StorageRepository.GetIlks() - if err != nil { - return err - } - for _, ilk := range ilks { - mappings.mappings[getIlkFlipKey(ilk)] = getIlkFlipMetadata(ilk) - mappings.mappings[getIlkChopKey(ilk)] = getIlkChopMetadata(ilk) - mappings.mappings[getIlkLumpKey(ilk)] = getIlkLumpMetadata(ilk) - } - return nil -} - -func getIlkFlipKey(ilk string) common.Hash { - return storage_diffs.GetMapping(IlksMappingIndex, ilk) -} - -func getIlkFlipMetadata(ilk string) shared.StorageValueMetadata { - keys := map[shared.Key]string{shared.Ilk: ilk} - return shared.GetStorageValueMetadata(IlkFlip, keys, shared.Address) -} - -func getIlkChopKey(ilk string) common.Hash { - return storage_diffs.GetIncrementedKey(getIlkFlipKey(ilk), 1) -} - -func getIlkChopMetadata(ilk string) shared.StorageValueMetadata { - keys := map[shared.Key]string{shared.Ilk: ilk} - return shared.GetStorageValueMetadata(IlkChop, keys, shared.Uint256) -} - -func getIlkLumpKey(ilk string) common.Hash { - return storage_diffs.GetIncrementedKey(getIlkFlipKey(ilk), 2) -} - -func getIlkLumpMetadata(ilk string) shared.StorageValueMetadata { - keys := map[shared.Key]string{shared.Ilk: ilk} - return shared.GetStorageValueMetadata(IlkLump, keys, shared.Uint256) -} - -// Flip ID increments each time it happens, so we just need the biggest flip ID from the DB -// and we can interpolate the sequence [0..max]. This makes sure we track all earlier flips, -// even if we've missed events -func (mappings CatMappings) loadFlipsKeys() error { - maxFlip, err := mappings.StorageRepository.GetMaxFlip() - if err != nil { - logrus.Error("loadFlipsKeys: error getting max flip: ", err) - return err - } else if maxFlip == nil { // No flips occurred yet - return nil - } - - last := maxFlip.Int64() - for flip := 0; int64(flip) <= last; flip++ { - flipStr := strconv.Itoa(flip) - mappings.mappings[getFlipIlkKey(flipStr)] = getFlipIlkMetadata(flipStr) - mappings.mappings[getFlipUrnKey(flipStr)] = getFlipUrnMetadata(flipStr) - mappings.mappings[getFlipInkKey(flipStr)] = getFlipInkMetadata(flipStr) - mappings.mappings[getFlipTabKey(flipStr)] = getFlipTabMetadata(flipStr) - } - return nil -} - -func getFlipIlkKey(flip string) common.Hash { - return storage_diffs.GetMapping(FlipsMappingIndex, flip) -} - -func getFlipIlkMetadata(flip string) shared.StorageValueMetadata { - keys := map[shared.Key]string{shared.Flip: flip} - return shared.GetStorageValueMetadata(FlipIlk, keys, shared.Bytes32) -} - -func getFlipUrnKey(flip string) common.Hash { - return storage_diffs.GetIncrementedKey(getFlipIlkKey(flip), 1) -} - -func getFlipUrnMetadata(flip string) shared.StorageValueMetadata { - keys := map[shared.Key]string{shared.Flip: flip} - return shared.GetStorageValueMetadata(FlipUrn, keys, shared.Bytes32) -} - -func getFlipInkKey(flip string) common.Hash { - return storage_diffs.GetIncrementedKey(getFlipIlkKey(flip), 2) -} - -func getFlipInkMetadata(flip string) shared.StorageValueMetadata { - keys := map[shared.Key]string{shared.Flip: flip} - return shared.GetStorageValueMetadata(FlipInk, keys, shared.Uint256) -} - -func getFlipTabKey(flip string) common.Hash { - return storage_diffs.GetIncrementedKey(getFlipIlkKey(flip), 3) -} - -func getFlipTabMetadata(flip string) shared.StorageValueMetadata { - keys := map[shared.Key]string{shared.Flip: flip} - return shared.GetStorageValueMetadata(FlipTab, keys, shared.Uint256) -} diff --git a/pkg/transformers/storage_diffs/maker/cat/mappings_test.go b/pkg/transformers/storage_diffs/maker/cat/mappings_test.go deleted file mode 100644 index 4cf725b7..00000000 --- a/pkg/transformers/storage_diffs/maker/cat/mappings_test.go +++ /dev/null @@ -1,177 +0,0 @@ -package cat_test - -import ( - "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/crypto" - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - "github.com/vulcanize/vulcanizedb/pkg/fakes" - "github.com/vulcanize/vulcanizedb/pkg/transformers/storage_diffs" - "github.com/vulcanize/vulcanizedb/pkg/transformers/storage_diffs/maker/cat" - "github.com/vulcanize/vulcanizedb/pkg/transformers/storage_diffs/maker/test_helpers" - "github.com/vulcanize/vulcanizedb/pkg/transformers/storage_diffs/shared" - "math/big" -) - -var _ = Describe("Cat storage mappings", func() { - const ( - fakeIlk = "fakeIlk" - fakeFlip = "2" - ) - - var ( - storageRepository *test_helpers.MockMakerStorageRepository - mappings cat.CatMappings - ) - - BeforeEach(func() { - storageRepository = &test_helpers.MockMakerStorageRepository{} - mappings = cat.CatMappings{StorageRepository: storageRepository} - }) - - Describe("looking up static keys", func() { - It("returns value metadata if key exists", func() { - Expect(mappings.Lookup(cat.NFlipKey)).To(Equal(cat.NFlipMetadata)) - Expect(mappings.Lookup(cat.LiveKey)).To(Equal(cat.LiveMetadata)) - Expect(mappings.Lookup(cat.VatKey)).To(Equal(cat.VatMetadata)) - Expect(mappings.Lookup(cat.PitKey)).To(Equal(cat.PitMetadata)) - Expect(mappings.Lookup(cat.VowKey)).To(Equal(cat.VowMetadata)) - }) - - It("returns error if key does not exist", func() { - _, err := mappings.Lookup(common.HexToHash(fakes.FakeHash.Hex())) - - Expect(err).To(HaveOccurred()) - Expect(err).To(MatchError(shared.ErrStorageKeyNotFound{Key: fakes.FakeHash.Hex()})) - }) - }) - - Describe("looking up dynamic keys", func() { - It("refreshes mappings from repository if key not found", func() { - _, _ = mappings.Lookup(fakes.FakeHash) - - Expect(storageRepository.GetIlksCalled).To(BeTrue()) - Expect(storageRepository.GetMaxFlipCalled).To(BeTrue()) - }) - - It("returns error if ilks lookup fails", func() { - storageRepository.GetIlksError = fakes.FakeError - - _, err := mappings.Lookup(fakes.FakeHash) - - Expect(err).To(HaveOccurred()) - Expect(err).To(MatchError(fakes.FakeError)) - }) - - It("returns error if max flip lookup fails", func() { - storageRepository.GetMaxFlipError = fakes.FakeError - - _, err := mappings.Lookup(fakes.FakeHash) - - Expect(err).To(HaveOccurred()) - Expect(err).To(MatchError(fakes.FakeError)) - }) - - It("interpolates flips up to max", func() { - storageRepository.MaxFlip = big.NewInt(1) - - _, err := mappings.Lookup(storage_diffs.GetMapping(storage_diffs.IndexTwo, "0")) - Expect(err).NotTo(HaveOccurred()) - - _, err = mappings.Lookup(storage_diffs.GetMapping(storage_diffs.IndexTwo, "1")) - Expect(err).NotTo(HaveOccurred()) - }) - - Describe("ilk", func() { - var ilkFlipKey = common.BytesToHash(crypto.Keccak256(common.FromHex(fakeIlk + cat.IlksMappingIndex))) - - BeforeEach(func() { - storageRepository.Ilks = []string{fakeIlk} - }) - - It("returns value metadata for ilk flip", func() { - expectedMetadata := shared.StorageValueMetadata{ - Name: cat.IlkFlip, - Keys: map[shared.Key]string{shared.Ilk: fakeIlk}, - Type: shared.Address, - } - Expect(mappings.Lookup(ilkFlipKey)).To(Equal(expectedMetadata)) - }) - - It("returns value metadata for ilk chop", func() { - ilkChopKey := storage_diffs.GetIncrementedKey(ilkFlipKey, 1) - expectedMetadata := shared.StorageValueMetadata{ - Name: cat.IlkChop, - Keys: map[shared.Key]string{shared.Ilk: fakeIlk}, - Type: shared.Uint256, - } - Expect(mappings.Lookup(ilkChopKey)).To(Equal(expectedMetadata)) - }) - - It("returns value metadata for ilk lump", func() { - ilkLumpKey := storage_diffs.GetIncrementedKey(ilkFlipKey, 2) - expectedMetadata := shared.StorageValueMetadata{ - Name: cat.IlkLump, - Keys: map[shared.Key]string{shared.Ilk: fakeIlk}, - Type: shared.Uint256, - } - Expect(mappings.Lookup(ilkLumpKey)).To(Equal(expectedMetadata)) - }) - }) - - Describe("flip", func() { - var flipIlkKey = common.BytesToHash(crypto.Keccak256(common.FromHex(fakeFlip + cat.FlipsMappingIndex))) - - BeforeEach(func() { - storageRepository.MaxFlip = big.NewInt(2) - }) - - It("returns value metadata for flip ilk", func() { - expectedMetadata := shared.StorageValueMetadata{ - Name: cat.FlipIlk, - Keys: map[shared.Key]string{shared.Flip: fakeFlip}, - Type: shared.Bytes32, - } - actualMetadata, err := mappings.Lookup(flipIlkKey) - Expect(err).NotTo(HaveOccurred()) - Expect(actualMetadata).To(Equal(expectedMetadata)) - }) - - It("returns value metadata for flip urn", func() { - flipUrnKey := storage_diffs.GetIncrementedKey(flipIlkKey, 1) - expectedMetadata := shared.StorageValueMetadata{ - Name: cat.FlipUrn, - Keys: map[shared.Key]string{shared.Flip: fakeFlip}, - Type: shared.Bytes32, - } - actualMetadata, err := mappings.Lookup(flipUrnKey) - Expect(err).NotTo(HaveOccurred()) - Expect(actualMetadata).To(Equal(expectedMetadata)) - }) - - It("returns value metadata for flip ink", func() { - flipInkKey := storage_diffs.GetIncrementedKey(flipIlkKey, 2) - expectedMetadata := shared.StorageValueMetadata{ - Name: cat.FlipInk, - Keys: map[shared.Key]string{shared.Flip: fakeFlip}, - Type: shared.Uint256, - } - actualMetadata, err := mappings.Lookup(flipInkKey) - Expect(err).NotTo(HaveOccurred()) - Expect(actualMetadata).To(Equal(expectedMetadata)) - }) - - It("returns value metadata for flip tab", func() { - flipTabKey := storage_diffs.GetIncrementedKey(flipIlkKey, 3) - expectedMetadata := shared.StorageValueMetadata{ - Name: cat.FlipTab, - Keys: map[shared.Key]string{shared.Flip: fakeFlip}, - Type: shared.Uint256, - } - actualMetadata, err := mappings.Lookup(flipTabKey) - Expect(err).NotTo(HaveOccurred()) - Expect(actualMetadata).To(Equal(expectedMetadata)) - }) - }) - }) -}) diff --git a/pkg/transformers/storage_diffs/maker/cat/repository.go b/pkg/transformers/storage_diffs/maker/cat/repository.go deleted file mode 100644 index 51c4e8ef..00000000 --- a/pkg/transformers/storage_diffs/maker/cat/repository.go +++ /dev/null @@ -1,253 +0,0 @@ -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" -) - -type CatStorageRepository struct { - db *postgres.DB -} - -func (repository *CatStorageRepository) Create(blockNumber int, blockHash string, metadata shared.StorageValueMetadata, value interface{}) error { - switch metadata.Name { - case NFlip: - return repository.insertNFlip(blockNumber, blockHash, value.(string)) - case Live: - return repository.insertLive(blockNumber, blockHash, value.(string)) - case Vat: - return repository.insertVat(blockNumber, blockHash, value.(string)) - case Pit: - return repository.insertPit(blockNumber, blockHash, value.(string)) - case Vow: - return repository.insertVow(blockNumber, blockHash, value.(string)) - case IlkFlip: - return repository.insertIlkFlip(blockNumber, blockHash, metadata, value.(string)) - case IlkChop: - return repository.insertIlkChop(blockNumber, blockHash, metadata, value.(string)) - case IlkLump: - return repository.insertIlkLump(blockNumber, blockHash, metadata, value.(string)) - case FlipIlk: - return repository.insertFlipIlk(blockNumber, blockHash, metadata, value.(string)) - case FlipUrn: - return repository.insertFlipUrn(blockNumber, blockHash, metadata, value.(string)) - case FlipInk: - return repository.insertFlipInk(blockNumber, blockHash, metadata, value.(string)) - case FlipTab: - return repository.insertFlipTab(blockNumber, blockHash, metadata, value.(string)) - default: - panic(fmt.Sprintf("unrecognized cat contract storage name: %s", metadata.Name)) - } -} - -func (repository *CatStorageRepository) SetDB(db *postgres.DB) { - repository.db = db -} - -func (repository *CatStorageRepository) insertNFlip(blockNumber int, blockHash string, nflip string) error { - _, writeErr := repository.db.Exec( - `INSERT INTO maker.cat_nflip (block_number, block_hash, nflip) VALUES ($1, $2, $3)`, - blockNumber, blockHash, nflip) - return writeErr -} - -func (repository *CatStorageRepository) insertLive(blockNumber int, blockHash string, live string) error { - _, writeErr := repository.db.Exec( - `INSERT INTO maker.cat_live (block_number, block_hash, live) VALUES ($1, $2, $3 )`, - blockNumber, blockHash, live) - return writeErr -} - -func (repository *CatStorageRepository) insertVat(blockNumber int, blockHash string, vat string) error { - _, writeErr := repository.db.Exec( - `INSERT INTO maker.cat_vat (block_number, block_hash, vat) VALUES ($1, $2, $3 )`, - blockNumber, blockHash, vat) - return writeErr -} - -func (repository *CatStorageRepository) insertPit(blockNumber int, blockHash string, pit string) error { - _, writeErr := repository.db.Exec( - `INSERT INTO maker.cat_pit (block_number, block_hash, pit) VALUES ($1, $2, $3 )`, - blockNumber, blockHash, pit) - return writeErr -} - -func (repository *CatStorageRepository) insertVow(blockNumber int, blockHash string, vow string) error { - _, writeErr := repository.db.Exec( - `INSERT INTO maker.cat_vow (block_number, block_hash, vow) VALUES ($1, $2, $3 )`, - blockNumber, blockHash, vow) - return writeErr -} - -// Ilks mapping: bytes32 => flip address; chop (ray), lump (wad) uint256 -func (repository *CatStorageRepository) insertIlkFlip(blockNumber int, blockHash string, metadata shared.StorageValueMetadata, flip string) error { - ilk, err := getIlk(metadata.Keys) - if err != nil { - return err - } - 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, 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 { - ilk, err := getIlk(metadata.Keys) - if err != nil { - return err - } - 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, 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 { - ilk, err := getIlk(metadata.Keys) - if err != nil { - return err - } - 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, 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) -func (repository *CatStorageRepository) insertFlipIlk(blockNumber int, blockHash string, metadata shared.StorageValueMetadata, ilk string) error { - flip, err := getFlip(metadata.Keys) - if err != nil { - return err - } - 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, 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 { - flip, err := getFlip(metadata.Keys) - if err != nil { - return err - } - _, writeErr := repository.db.Exec( - `INSERT INTO maker.cat_flip_urn (block_number, block_hash, flip, urn) VALUES ($1, $2, $3, $4)`, - blockNumber, blockHash, flip, urn) - return writeErr -} - -func (repository *CatStorageRepository) insertFlipInk(blockNumber int, blockHash string, metadata shared.StorageValueMetadata, ink string) error { - flip, err := getFlip(metadata.Keys) - if err != nil { - return err - } - _, writeErr := repository.db.Exec( - `INSERT INTO maker.cat_flip_ink (block_number, block_hash, flip, ink) VALUES ($1, $2, $3, $4)`, - blockNumber, blockHash, flip, ink) - return writeErr -} - -func (repository *CatStorageRepository) insertFlipTab(blockNumber int, blockHash string, metadata shared.StorageValueMetadata, tab string) error { - flip, err := getFlip(metadata.Keys) - if err != nil { - return err - } - _, writeErr := repository.db.Exec( - `INSERT INTO maker.cat_flip_tab (block_number, block_hash, flip, tab) VALUES ($1, $2, $3, $4)`, - blockNumber, blockHash, flip, tab) - return writeErr -} - -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 -} - -func getFlip(keys map[shared.Key]string) (string, error) { - flip, ok := keys[shared.Flip] - if !ok { - return "", shared.ErrMetadataMalformed{MissingData: shared.Flip} - } - return flip, nil -} diff --git a/pkg/transformers/storage_diffs/maker/cat/repository_test.go b/pkg/transformers/storage_diffs/maker/cat/repository_test.go deleted file mode 100644 index 525ae845..00000000 --- a/pkg/transformers/storage_diffs/maker/cat/repository_test.go +++ /dev/null @@ -1,258 +0,0 @@ -package cat_test - -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() { - var ( - db *postgres.DB - repo cat.CatStorageRepository - fakeBlockNumber = 123 - fakeBlockHash = "expected_block_hash" - fakeAddress = "0x12345" - fakeIlk = "fake_ilk" - fakeUint256 = "12345" - fakeBytes32 = "fake_bytes32" - ) - - BeforeEach(func() { - db = test_config.NewTestDB(test_config.NewTestNode()) - test_config.CleanTestDB(db) - repo = cat.CatStorageRepository{} - repo.SetDB(db) - }) - - Describe("Variable", func() { - var result VariableRes - - Describe("NFlip", func() { - It("writes a row", func() { - nFlipMetadata := shared.GetStorageValueMetadata(cat.NFlip, nil, shared.Uint256) - - err := repo.Create(fakeBlockNumber, fakeBlockHash, nFlipMetadata, fakeUint256) - Expect(err).NotTo(HaveOccurred()) - - err = db.Get(&result, `SELECT block_number, block_hash, nflip AS value FROM maker.cat_nflip`) - Expect(err).NotTo(HaveOccurred()) - AssertVariable(result, fakeBlockNumber, fakeBlockHash, fakeUint256) - }) - }) - - Describe("Live", func() { - It("writes a row", func() { - liveMetadata := shared.GetStorageValueMetadata(cat.Live, nil, shared.Uint256) - - err := repo.Create(fakeBlockNumber, fakeBlockHash, liveMetadata, fakeUint256) - Expect(err).NotTo(HaveOccurred()) - - err = db.Get(&result, `SELECT block_number, block_hash, live AS value FROM maker.cat_live`) - Expect(err).NotTo(HaveOccurred()) - AssertVariable(result, fakeBlockNumber, fakeBlockHash, fakeUint256) - }) - }) - - Describe("Vat", func() { - It("writes a row", func() { - vatMetadata := shared.GetStorageValueMetadata(cat.Vat, nil, shared.Address) - - err := repo.Create(fakeBlockNumber, fakeBlockHash, vatMetadata, fakeAddress) - Expect(err).NotTo(HaveOccurred()) - - err = db.Get(&result, `SELECT block_number, block_hash, vat AS value FROM maker.cat_vat`) - Expect(err).NotTo(HaveOccurred()) - AssertVariable(result, fakeBlockNumber, fakeBlockHash, fakeAddress) - }) - }) - - Describe("Pit", func() { - It("writes a row", func() { - pitMetadata := shared.GetStorageValueMetadata(cat.Pit, nil, shared.Address) - - err := repo.Create(fakeBlockNumber, fakeBlockHash, pitMetadata, fakeAddress) - Expect(err).NotTo(HaveOccurred()) - - err = db.Get(&result, `SELECT block_number, block_hash, pit AS value FROM maker.cat_pit`) - Expect(err).NotTo(HaveOccurred()) - AssertVariable(result, fakeBlockNumber, fakeBlockHash, fakeAddress) - }) - }) - - Describe("Vow", func() { - It("writes a row", func() { - vowMetadata := shared.GetStorageValueMetadata(cat.Vow, nil, shared.Address) - - err := repo.Create(fakeBlockNumber, fakeBlockHash, vowMetadata, fakeAddress) - Expect(err).NotTo(HaveOccurred()) - - err = db.Get(&result, `SELECT block_number, block_hash, vow AS value FROM maker.cat_vow`) - Expect(err).NotTo(HaveOccurred()) - AssertVariable(result, fakeBlockNumber, fakeBlockHash, fakeAddress) - }) - }) - }) - - Describe("Ilk", func() { - var result MappingRes - - Describe("Flip", func() { - It("writes a row", func() { - ilkFlipMetadata := shared.GetStorageValueMetadata(cat.IlkFlip, map[shared.Key]string{shared.Ilk: fakeIlk}, shared.Address) - - err := repo.Create(fakeBlockNumber, fakeBlockHash, ilkFlipMetadata, fakeAddress) - Expect(err).NotTo(HaveOccurred()) - - err = db.Get(&result, `SELECT block_number, block_hash, ilk AS key, flip AS value FROM maker.cat_ilk_flip`) - Expect(err).NotTo(HaveOccurred()) - 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() { - malformedIlkFlipMetadata := shared.GetStorageValueMetadata(cat.IlkFlip, map[shared.Key]string{}, shared.Address) - - err := repo.Create(fakeBlockNumber, fakeBlockHash, malformedIlkFlipMetadata, fakeAddress) - Expect(err).To(MatchError(shared.ErrMetadataMalformed{MissingData: shared.Ilk})) - }) - }) - - Describe("Chop", func() { - It("writes a row", func() { - ilkChopMetadata := shared.GetStorageValueMetadata(cat.IlkChop, map[shared.Key]string{shared.Ilk: fakeIlk}, shared.Uint256) - - err := repo.Create(fakeBlockNumber, fakeBlockHash, ilkChopMetadata, fakeUint256) - Expect(err).NotTo(HaveOccurred()) - - err = db.Get(&result, `SELECT block_number, block_hash, ilk AS key, chop AS value FROM maker.cat_ilk_chop`) - Expect(err).NotTo(HaveOccurred()) - 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() { - malformedIlkChopMetadata := shared.GetStorageValueMetadata(cat.IlkChop, map[shared.Key]string{}, shared.Uint256) - - err := repo.Create(fakeBlockNumber, fakeBlockHash, malformedIlkChopMetadata, fakeAddress) - Expect(err).To(MatchError(shared.ErrMetadataMalformed{MissingData: shared.Ilk})) - }) - }) - - Describe("Lump", func() { - It("writes a row", func() { - ilkLumpMetadata := shared.GetStorageValueMetadata(cat.IlkLump, map[shared.Key]string{shared.Ilk: fakeIlk}, shared.Uint256) - - err := repo.Create(fakeBlockNumber, fakeBlockHash, ilkLumpMetadata, fakeUint256) - Expect(err).NotTo(HaveOccurred()) - - err = db.Get(&result, `SELECT block_number, block_hash, ilk AS key, lump AS value FROM maker.cat_ilk_lump`) - Expect(err).NotTo(HaveOccurred()) - 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() { - malformedIlkLumpMetadata := shared.GetStorageValueMetadata(cat.IlkLump, map[shared.Key]string{}, shared.Uint256) - - err := repo.Create(fakeBlockNumber, fakeBlockHash, malformedIlkLumpMetadata, fakeAddress) - Expect(err).To(MatchError(shared.ErrMetadataMalformed{MissingData: shared.Ilk})) - }) - }) - }) - - Describe("Flip", func() { - var result MappingRes - - Describe("FlipIlk", func() { - It("writes a row", func() { - flipIlkMetadata := shared.GetStorageValueMetadata(cat.FlipIlk, map[shared.Key]string{shared.Flip: fakeUint256}, shared.Bytes32) - - err := repo.Create(fakeBlockNumber, fakeBlockHash, flipIlkMetadata, fakeBytes32) - Expect(err).NotTo(HaveOccurred()) - - err = db.Get(&result, `SELECT block_number, block_hash, flip AS key, ilk AS value FROM maker.cat_flip_ilk`) - Expect(err).NotTo(HaveOccurred()) - 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() { - malformedFlipIlkMetadata := shared.GetStorageValueMetadata(cat.FlipIlk, map[shared.Key]string{}, shared.Bytes32) - - err := repo.Create(fakeBlockNumber, fakeBlockHash, malformedFlipIlkMetadata, fakeBytes32) - Expect(err).To(MatchError(shared.ErrMetadataMalformed{MissingData: shared.Flip})) - }) - }) - - Describe("FlipUrn", func() { - It("writes a row", func() { - flipUrnMetadata := shared.GetStorageValueMetadata(cat.FlipUrn, map[shared.Key]string{shared.Flip: fakeUint256}, shared.Bytes32) - - err := repo.Create(fakeBlockNumber, fakeBlockHash, flipUrnMetadata, fakeBytes32) - Expect(err).NotTo(HaveOccurred()) - - err = db.Get(&result, `SELECT block_number, block_hash, flip AS key, urn AS value FROM maker.cat_flip_urn`) - Expect(err).NotTo(HaveOccurred()) - AssertMapping(result, fakeBlockNumber, fakeBlockHash, fakeUint256, fakeBytes32) - }) - - It("returns an error if metadata missing flip", func() { - malformedFlipUrnMetadata := shared.GetStorageValueMetadata(cat.FlipUrn, map[shared.Key]string{}, shared.Bytes32) - - err := repo.Create(fakeBlockNumber, fakeBlockHash, malformedFlipUrnMetadata, fakeBytes32) - Expect(err).To(MatchError(shared.ErrMetadataMalformed{MissingData: shared.Flip})) - }) - }) - - Describe("FlipInk", func() { - It("writes a row", func() { - flipInkMetadata := shared.GetStorageValueMetadata(cat.FlipInk, map[shared.Key]string{shared.Flip: fakeUint256}, shared.Uint256) - - err := repo.Create(fakeBlockNumber, fakeBlockHash, flipInkMetadata, fakeUint256) - Expect(err).NotTo(HaveOccurred()) - - err = db.Get(&result, `SELECT block_number, block_hash, flip AS key, ink AS value FROM maker.cat_flip_ink`) - Expect(err).NotTo(HaveOccurred()) - AssertMapping(result, fakeBlockNumber, fakeBlockHash, fakeUint256, fakeUint256) - }) - - It("returns an error if metadata missing flip", func() { - malformedFlipInkMetadata := shared.GetStorageValueMetadata(cat.FlipInk, map[shared.Key]string{}, shared.Uint256) - - err := repo.Create(fakeBlockNumber, fakeBlockHash, malformedFlipInkMetadata, fakeUint256) - Expect(err).To(MatchError(shared.ErrMetadataMalformed{MissingData: shared.Flip})) - }) - }) - - Describe("FlipTab", func() { - It("writes a row", func() { - flipTabMetadata := shared.GetStorageValueMetadata(cat.FlipTab, map[shared.Key]string{shared.Flip: fakeUint256}, shared.Uint256) - - err := repo.Create(fakeBlockNumber, fakeBlockHash, flipTabMetadata, fakeUint256) - Expect(err).NotTo(HaveOccurred()) - - err = db.Get(&result, `SELECT block_number, block_hash, flip AS key, tab AS value FROM maker.cat_flip_tab`) - Expect(err).NotTo(HaveOccurred()) - AssertMapping(result, fakeBlockNumber, fakeBlockHash, fakeUint256, fakeUint256) - }) - - It("returns an error if metadata missing flip", func() { - malformedFlipTabMetadata := shared.GetStorageValueMetadata(cat.FlipTab, map[shared.Key]string{}, shared.Uint256) - - err := repo.Create(fakeBlockNumber, fakeBlockHash, malformedFlipTabMetadata, fakeUint256) - Expect(err).To(MatchError(shared.ErrMetadataMalformed{MissingData: shared.Flip})) - }) - }) - }) -}) diff --git a/pkg/transformers/storage_diffs/maker/maker_storage_repository.go b/pkg/transformers/storage_diffs/maker/maker_storage_repository.go deleted file mode 100644 index 7916b059..00000000 --- a/pkg/transformers/storage_diffs/maker/maker_storage_repository.go +++ /dev/null @@ -1,125 +0,0 @@ -// VulcanizeDB -// Copyright © 2018 Vulcanize - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. - -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -package maker - -import ( - "database/sql" - "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" - "math/big" -) - -type Urn struct { - Ilk string - Guy string -} - -type IMakerStorageRepository interface { - GetDaiKeys() ([]string, error) - GetMaxFlip() (*big.Int, error) - GetGemKeys() ([]Urn, error) - GetIlks() ([]string, error) - GetSinKeys() ([]string, error) - GetUrns() ([]Urn, error) - SetDB(db *postgres.DB) -} - -type MakerStorageRepository struct { - db *postgres.DB -} - -func (repository *MakerStorageRepository) GetDaiKeys() ([]string, error) { - var daiKeys []string - err := repository.db.Select(&daiKeys, ` - SELECT DISTINCT src FROM maker.vat_move UNION - SELECT DISTINCT dst FROM maker.vat_move UNION - SELECT DISTINCT w FROM maker.vat_tune UNION - SELECT DISTINCT v FROM maker.vat_heal UNION - SELECT DISTINCT urn FROM maker.vat_fold - `) - return daiKeys, err -} - -func (repository *MakerStorageRepository) GetMaxFlip() (*big.Int, error) { - var maxFlip big.Int - err := repository.db.Get(&maxFlip, `SELECT MAX(nflip) FROM maker.cat_nflip`) - if err == sql.ErrNoRows { - // No flips have occurred; this is different from flip 0 having occurred - return nil, nil - } - return &maxFlip, err -} - -func (repository *MakerStorageRepository) GetGemKeys() ([]Urn, error) { - var gems []Urn - err := repository.db.Select(&gems, ` - SELECT DISTINCT ilks.ilk, slip.guy - FROM maker.vat_slip slip - INNER JOIN maker.ilks ilks ON ilks.id = slip.ilk - UNION - SELECT DISTINCT ilks.ilk, flux.src AS guy - FROM maker.vat_flux flux - INNER JOIN maker.ilks ilks ON ilks.id = flux.ilk - UNION - SELECT DISTINCT ilks.ilk, flux.dst AS guy - FROM maker.vat_flux flux - INNER JOIN maker.ilks ilks ON ilks.id = flux.ilk - UNION - SELECT DISTINCT ilks.ilk, tune.v AS guy - FROM maker.vat_tune tune - INNER JOIN maker.ilks ilks ON ilks.id = tune.ilk - UNION - SELECT DISTINCT ilks.ilk, grab.v AS guy - FROM maker.vat_grab grab - INNER JOIN maker.ilks ilks ON ilks.id = grab.ilk - UNION - SELECT DISTINCT ilks.ilk, toll.urn AS guy - FROM maker.vat_toll toll - INNER JOIN maker.ilks ilks ON ilks.id = toll.ilk - `) - return gems, err -} - -func (repository MakerStorageRepository) GetIlks() ([]string, error) { - var ilks []string - err := repository.db.Select(&ilks, `SELECT DISTINCT ilk FROM maker.ilks`) - return ilks, err -} - -func (repository *MakerStorageRepository) GetSinKeys() ([]string, error) { - var sinKeys []string - err := repository.db.Select(&sinKeys, `SELECT DISTINCT w FROM maker.vat_grab UNION - SELECT DISTINCT urn FROM maker.vat_heal`) - return sinKeys, err -} - -func (repository *MakerStorageRepository) GetUrns() ([]Urn, error) { - var urns []Urn - err := repository.db.Select(&urns, ` - SELECT DISTINCT ilks.ilk, tune.urn AS guy - FROM maker.vat_tune tune - INNER JOIN maker.ilks ilks ON ilks.id = tune.ilk - UNION - SELECT DISTINCT ilks.ilk, grab.urn AS guy - FROM maker.vat_grab grab - INNER JOIN maker.ilks ilks ON ilks.id = grab.ilk -`) - return urns, err -} - -func (repository *MakerStorageRepository) SetDB(db *postgres.DB) { - repository.db = db -} diff --git a/pkg/transformers/storage_diffs/maker/maker_storage_repository_test.go b/pkg/transformers/storage_diffs/maker/maker_storage_repository_test.go deleted file mode 100644 index ac8a5e68..00000000 --- a/pkg/transformers/storage_diffs/maker/maker_storage_repository_test.go +++ /dev/null @@ -1,409 +0,0 @@ -// VulcanizeDB -// Copyright © 2018 Vulcanize - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. - -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -package maker_test - -import ( - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" - "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories" - "github.com/vulcanize/vulcanizedb/pkg/fakes" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" - "github.com/vulcanize/vulcanizedb/pkg/transformers/storage_diffs/maker" - "github.com/vulcanize/vulcanizedb/test_config" -) - -var _ = Describe("Maker storage repository", func() { - var ( - db *postgres.DB - repository maker.IMakerStorageRepository - ilk1 = "ilk1" - ilk2 = "ilk2" - guy1 = "guy1" - guy2 = "guy2" - guy3 = "guy3" - ) - - BeforeEach(func() { - db = test_config.NewTestDB(test_config.NewTestNode()) - test_config.CleanTestDB(db) - repository = &maker.MakerStorageRepository{} - repository.SetDB(db) - }) - - Describe("getting dai keys", func() { - It("fetches guy from both src and dst field on vat_move", func() { - insertVatMove(guy1, guy2, 1, db) - - keys, err := repository.GetDaiKeys() - - Expect(err).NotTo(HaveOccurred()) - Expect(len(keys)).To(Equal(2)) - Expect(keys).To(ConsistOf(guy1, guy2)) - }) - - It("fetches guy from w field on vat_tune", func() { - insertVatTune(guy1, guy1, guy1, guy2, 1, db) - - keys, err := repository.GetDaiKeys() - - Expect(err).NotTo(HaveOccurred()) - Expect(len(keys)).To(Equal(1)) - Expect(keys).To(ConsistOf(guy2)) - }) - - It("fetches guy from v field on vat_heal", func() { - insertVatHeal(guy2, guy1, 1, db) - - keys, err := repository.GetDaiKeys() - - Expect(err).NotTo(HaveOccurred()) - Expect(len(keys)).To(Equal(1)) - Expect(keys).To(ConsistOf(guy1)) - }) - - It("fetches unique guys from vat_move + vat_tune + vat_heal + vat_fold", func() { - guy4 := "guy4" - guy5 := "guy5" - guy6 := "guy6" - insertVatMove(guy1, guy2, 1, db) - insertVatTune(guy1, guy1, guy1, guy3, 2, db) - insertVatHeal(guy6, guy4, 3, db) - insertVatFold(guy5, 4, db) - // duplicates - insertVatMove(guy3, guy1, 5, db) - insertVatTune(guy2, guy2, guy2, guy5, 6, db) - insertVatHeal(guy6, guy2, 7, db) - insertVatFold(guy4, 8, db) - - keys, err := repository.GetDaiKeys() - - Expect(err).NotTo(HaveOccurred()) - Expect(len(keys)).To(Equal(5)) - Expect(keys).To(ConsistOf(guy1, guy2, guy3, guy4, guy5)) - }) - - It("does not return error if no matching rows", func() { - daiKeys, err := repository.GetDaiKeys() - - Expect(err).NotTo(HaveOccurred()) - Expect(len(daiKeys)).To(BeZero()) - }) - }) - - Describe("getting gem keys", func() { - It("fetches guy from both src and dst field on vat_flux", func() { - insertVatFlux(ilk1, guy1, guy2, 1, db) - - gems, err := repository.GetGemKeys() - - Expect(err).NotTo(HaveOccurred()) - Expect(len(gems)).To(Equal(2)) - Expect(gems).To(ConsistOf([]maker.Urn{{ - Ilk: ilk1, - Guy: guy1, - }, { - Ilk: ilk1, - Guy: guy2, - }})) - }) - - It("fetches guy from v field on vat_tune + vat_grab", func() { - insertVatTune(ilk1, guy1, guy2, guy1, 1, db) - insertVatGrab(ilk1, guy1, guy3, guy1, 2, db) - - gems, err := repository.GetGemKeys() - - Expect(err).NotTo(HaveOccurred()) - Expect(len(gems)).To(Equal(2)) - Expect(gems).To(ConsistOf([]maker.Urn{{ - Ilk: ilk1, - Guy: guy2, - }, { - Ilk: ilk1, - Guy: guy3, - }})) - }) - - It("fetches unique urns from vat_slip + vat_flux + vat_tune + vat_grab + vat_toll events", func() { - insertVatSlip(ilk1, guy1, 1, db) - insertVatFlux(ilk1, guy2, guy3, 2, db) - insertVatTune(ilk2, guy1, guy1, guy1, 3, db) - insertVatGrab(ilk2, guy1, guy2, guy1, 4, db) - insertVatToll(ilk2, guy3, 5, db) - // duplicates - insertVatSlip(ilk1, guy2, 6, db) - insertVatFlux(ilk2, guy2, guy3, 7, db) - insertVatTune(ilk2, guy1, guy1, guy1, 8, db) - insertVatGrab(ilk1, guy1, guy1, guy1, 9, db) - insertVatToll(ilk1, guy3, 10, db) - - gems, err := repository.GetGemKeys() - - Expect(err).NotTo(HaveOccurred()) - Expect(len(gems)).To(Equal(6)) - Expect(gems).To(ConsistOf([]maker.Urn{{ - Ilk: ilk1, - Guy: guy1, - }, { - Ilk: ilk1, - Guy: guy2, - }, { - Ilk: ilk1, - Guy: guy3, - }, { - Ilk: ilk2, - Guy: guy1, - }, { - Ilk: ilk2, - Guy: guy2, - }, { - Ilk: ilk2, - Guy: guy3, - }})) - }) - - It("does not return error if no matching rows", func() { - gemKeys, err := repository.GetGemKeys() - - Expect(err).NotTo(HaveOccurred()) - Expect(len(gemKeys)).To(BeZero()) - }) - }) - - Describe("getting ilks", func() { - It("fetches unique ilks from vat init events", func() { - insertVatInit(ilk1, 1, db) - insertVatInit(ilk2, 2, db) - insertVatInit(ilk2, 3, db) - - ilks, err := repository.GetIlks() - - Expect(err).NotTo(HaveOccurred()) - Expect(len(ilks)).To(Equal(2)) - Expect(ilks).To(ConsistOf(ilk1, ilk2)) - }) - - It("does not return error if no matching rows", func() { - ilks, err := repository.GetIlks() - - Expect(err).NotTo(HaveOccurred()) - Expect(len(ilks)).To(BeZero()) - }) - }) - - Describe("getting sin keys", func() { - It("fetches guy from w field of vat grab", func() { - insertVatGrab(guy1, guy1, guy1, guy2, 1, db) - - sinKeys, err := repository.GetSinKeys() - - Expect(err).NotTo(HaveOccurred()) - Expect(len(sinKeys)).To(Equal(1)) - Expect(sinKeys).To(ConsistOf(guy2)) - }) - - It("fetches guy from u field of vat heal", func() { - insertVatHeal(guy1, guy2, 1, db) - - sinKeys, err := repository.GetSinKeys() - - Expect(err).NotTo(HaveOccurred()) - Expect(len(sinKeys)).To(Equal(1)) - Expect(sinKeys).To(ConsistOf(guy1)) - }) - - It("fetches unique sin keys from vat_grab + vat_heal", func() { - insertVatGrab(guy3, guy3, guy3, guy1, 1, db) - insertVatHeal(guy2, guy3, 2, db) - // duplicates - insertVatGrab(guy2, guy2, guy2, guy2, 3, db) - insertVatHeal(guy1, guy2, 4, db) - - sinKeys, err := repository.GetSinKeys() - - Expect(err).NotTo(HaveOccurred()) - Expect(len(sinKeys)).To(Equal(2)) - Expect(sinKeys).To(ConsistOf(guy1, guy2)) - }) - - It("does not return error if no matching rows", func() { - sinKeys, err := repository.GetSinKeys() - - Expect(err).NotTo(HaveOccurred()) - Expect(len(sinKeys)).To(BeZero()) - }) - }) - - Describe("getting urns", func() { - It("fetches unique urns from vat_tune + vat_grab events", func() { - insertVatTune(ilk1, guy1, guy1, guy1, 1, db) - insertVatTune(ilk1, guy2, guy1, guy1, 2, db) - insertVatTune(ilk2, guy1, guy1, guy1, 3, db) - insertVatTune(ilk1, guy1, guy1, guy1, 4, db) - insertVatGrab(ilk1, guy1, guy1, guy1, 5, db) - insertVatGrab(ilk1, guy3, guy1, guy1, 6, db) - - urns, err := repository.GetUrns() - - Expect(err).NotTo(HaveOccurred()) - Expect(len(urns)).To(Equal(4)) - Expect(urns).To(ConsistOf([]maker.Urn{{ - Ilk: ilk1, - Guy: guy1, - }, { - Ilk: ilk1, - Guy: guy2, - }, { - Ilk: ilk2, - Guy: guy1, - }, { - Ilk: ilk1, - Guy: guy3, - }})) - }) - - It("does not return error if no matching rows", func() { - urns, err := repository.GetUrns() - - Expect(err).NotTo(HaveOccurred()) - Expect(len(urns)).To(BeZero()) - }) - }) -}) - -func insertVatFold(urn string, blockNumber int64, db *postgres.DB) { - headerRepository := repositories.NewHeaderRepository(db) - headerID, err := headerRepository.CreateOrUpdateHeader(fakes.GetFakeHeader(blockNumber)) - Expect(err).NotTo(HaveOccurred()) - ilkID, err := shared.GetOrCreateIlk("fake_ilk", db) - Expect(err).NotTo(HaveOccurred()) - _, execErr := db.Exec( - `INSERT INTO maker.vat_fold (header_id, urn, ilk, log_idx, tx_idx) - VALUES($1, $2, $3, $4, $5)`, - headerID, urn, ilkID, 0, 0, - ) - Expect(execErr).NotTo(HaveOccurred()) -} - -func insertVatFlux(ilk, src, dst string, blockNumber int64, db *postgres.DB) { - headerRepository := repositories.NewHeaderRepository(db) - headerID, err := headerRepository.CreateOrUpdateHeader(fakes.GetFakeHeader(blockNumber)) - Expect(err).NotTo(HaveOccurred()) - ilkID, err := shared.GetOrCreateIlk(ilk, db) - Expect(err).NotTo(HaveOccurred()) - _, execErr := db.Exec( - `INSERT INTO maker.vat_flux (header_id, ilk, src, dst, log_idx, tx_idx) - VALUES($1, $2, $3, $4, $5, $6)`, - headerID, ilkID, src, dst, 0, 0, - ) - Expect(execErr).NotTo(HaveOccurred()) -} - -func insertVatGrab(ilk, urn, v, w string, blockNumber int64, db *postgres.DB) { - headerRepository := repositories.NewHeaderRepository(db) - headerID, err := headerRepository.CreateOrUpdateHeader(fakes.GetFakeHeader(blockNumber)) - Expect(err).NotTo(HaveOccurred()) - ilkID, err := shared.GetOrCreateIlk(ilk, db) - Expect(err).NotTo(HaveOccurred()) - _, execErr := db.Exec( - `INSERT INTO maker.vat_grab (header_id, ilk, urn, v, w, log_idx, tx_idx) - VALUES($1, $2, $3, $4, $5, $6, $7)`, - headerID, ilkID, urn, v, w, 0, 0, - ) - Expect(execErr).NotTo(HaveOccurred()) -} - -func insertVatHeal(urn, v string, blockNumber int64, db *postgres.DB) { - headerRepository := repositories.NewHeaderRepository(db) - headerID, err := headerRepository.CreateOrUpdateHeader(fakes.GetFakeHeader(blockNumber)) - Expect(err).NotTo(HaveOccurred()) - _, execErr := db.Exec( - `INSERT INTO maker.vat_heal (header_id, urn, v, log_idx, tx_idx) - VALUES($1, $2, $3, $4, $5)`, - headerID, urn, v, 0, 0, - ) - Expect(execErr).NotTo(HaveOccurred()) -} - -func insertVatInit(ilk string, blockNumber int64, db *postgres.DB) { - headerRepository := repositories.NewHeaderRepository(db) - headerID, err := headerRepository.CreateOrUpdateHeader(fakes.GetFakeHeader(blockNumber)) - Expect(err).NotTo(HaveOccurred()) - ilkID, err := shared.GetOrCreateIlk(ilk, db) - Expect(err).NotTo(HaveOccurred()) - _, execErr := db.Exec( - `INSERT INTO maker.vat_init (header_id, ilk, log_idx, tx_idx) - VALUES($1, $2, $3, $4)`, - headerID, ilkID, 0, 0, - ) - Expect(execErr).NotTo(HaveOccurred()) -} - -func insertVatMove(src, dst string, blockNumber int64, db *postgres.DB) { - headerRepository := repositories.NewHeaderRepository(db) - headerID, err := headerRepository.CreateOrUpdateHeader(fakes.GetFakeHeader(blockNumber)) - Expect(err).NotTo(HaveOccurred()) - _, execErr := db.Exec( - `INSERT INTO maker.vat_move (header_id, src, dst, rad, log_idx, tx_idx) - VALUES($1, $2, $3, $4, $5, $6)`, - headerID, src, dst, 0, 0, 0, - ) - Expect(execErr).NotTo(HaveOccurred()) -} - -func insertVatSlip(ilk, guy string, blockNumber int64, db *postgres.DB) { - headerRepository := repositories.NewHeaderRepository(db) - headerID, err := headerRepository.CreateOrUpdateHeader(fakes.GetFakeHeader(blockNumber)) - Expect(err).NotTo(HaveOccurred()) - ilkID, err := shared.GetOrCreateIlk(ilk, db) - Expect(err).NotTo(HaveOccurred()) - _, execErr := db.Exec( - `INSERT INTO maker.vat_slip (header_id, ilk, guy, log_idx, tx_idx) - VALUES($1, $2, $3, $4, $5)`, - headerID, ilkID, guy, 0, 0, - ) - Expect(execErr).NotTo(HaveOccurred()) -} - -func insertVatToll(ilk, urn string, blockNumber int64, db *postgres.DB) { - headerRepository := repositories.NewHeaderRepository(db) - headerID, err := headerRepository.CreateOrUpdateHeader(fakes.GetFakeHeader(blockNumber)) - Expect(err).NotTo(HaveOccurred()) - ilkID, err := shared.GetOrCreateIlk(ilk, db) - Expect(err).NotTo(HaveOccurred()) - _, execErr := db.Exec( - `INSERT INTO maker.vat_toll (header_id, ilk, urn, log_idx, tx_idx) - VALUES($1, $2, $3, $4, $5)`, - headerID, ilkID, urn, 0, 0, - ) - Expect(execErr).NotTo(HaveOccurred()) -} - -func insertVatTune(ilk, urn, v, w string, blockNumber int64, db *postgres.DB) { - headerRepository := repositories.NewHeaderRepository(db) - headerID, err := headerRepository.CreateOrUpdateHeader(fakes.GetFakeHeader(blockNumber)) - Expect(err).NotTo(HaveOccurred()) - ilkID, err := shared.GetOrCreateIlk(ilk, db) - Expect(err).NotTo(HaveOccurred()) - _, execErr := db.Exec( - `INSERT INTO maker.vat_tune (header_id, ilk, urn, v, w, log_idx, tx_idx) - VALUES($1, $2, $3, $4, $5, $6, $7)`, - headerID, ilkID, urn, v, w, 0, 0, - ) - Expect(execErr).NotTo(HaveOccurred()) -} diff --git a/pkg/transformers/storage_diffs/maker/pit/repository.go b/pkg/transformers/storage_diffs/maker/pit/repository.go deleted file mode 100644 index fc73faa3..00000000 --- a/pkg/transformers/storage_diffs/maker/pit/repository.go +++ /dev/null @@ -1,135 +0,0 @@ -// VulcanizeDB -// Copyright © 2018 Vulcanize - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. - -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -package pit - -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" -) - -type PitStorageRepository struct { - db *postgres.DB -} - -func (repository *PitStorageRepository) SetDB(db *postgres.DB) { - repository.db = 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, value.(string)) - case IlkSpot: - return repository.insertIlkSpot(blockNumber, blockHash, metadata, value.(string)) - case PitDrip: - return repository.insertPitDrip(blockNumber, blockHash, value.(string)) - case PitLine: - return repository.insertPitLine(blockNumber, blockHash, value.(string)) - case PitLive: - return repository.insertPitLive(blockNumber, blockHash, value.(string)) - case PitVat: - return repository.insertPitVat(blockNumber, blockHash, value.(string)) - default: - panic(fmt.Sprintf("unrecognized pit contract storage name: %s", metadata.Name)) - } -} - -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 - } - 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.pit_ilk_line (block_number, block_hash, ilk, line) VALUES ($1, $2, $3, $4)`, blockNumber, blockHash, ilkID, line) - if writeErr != nil { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - return fmt.Errorf("failed to rollback transaction after failing to insert pit ilk line: %s", writeErr.Error()) - } - return writeErr - } - return tx.Commit() -} - -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 - } - 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.pit_ilk_spot (block_number, block_hash, ilk, spot) VALUES ($1, $2, $3, $4)`, blockNumber, blockHash, ilkID, spot) - if writeErr != nil { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - return fmt.Errorf("failed to rollback transaction after failing to insert pit ilk spot: %s", writeErr.Error()) - } - return writeErr - } - return tx.Commit() -} - -func (repository PitStorageRepository) insertPitDrip(blockNumber int, blockHash string, drip string) error { - _, err := repository.db.Exec(`INSERT INTO maker.pit_drip (block_number, block_hash, drip) VALUES ($1, $2, $3)`, blockNumber, blockHash, drip) - return err -} - -func (repository PitStorageRepository) insertPitLine(blockNumber int, blockHash string, line string) error { - _, err := repository.db.Exec(`INSERT INTO maker.pit_line (block_number, block_hash, line) VALUES ($1, $2, $3)`, blockNumber, blockHash, line) - return err -} - -func (repository PitStorageRepository) insertPitLive(blockNumber int, blockHash string, live string) error { - _, err := repository.db.Exec(`INSERT INTO maker.pit_live (block_number, block_hash, live) VALUES ($1, $2, $3)`, blockNumber, blockHash, live) - return err -} - -func (repository PitStorageRepository) insertPitVat(blockNumber int, blockHash string, vat string) error { - _, 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 -} diff --git a/pkg/transformers/storage_diffs/maker/pit/repository_test.go b/pkg/transformers/storage_diffs/maker/pit/repository_test.go deleted file mode 100644 index 4b58befb..00000000 --- a/pkg/transformers/storage_diffs/maker/pit/repository_test.go +++ /dev/null @@ -1,137 +0,0 @@ -// VulcanizeDB -// Copyright © 2018 Vulcanize - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. - -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -package pit_test - -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/pit" - . "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("Pit storage repository", func() { - var ( - db *postgres.DB - err error - repo pit.PitStorageRepository - fakeAddress = "0x12345" - fakeBlockHash = "expected_block_hash" - fakeBlockNumber = 123 - fakeIlk = "fake_ilk" - fakeUint256 = "12345" - ) - - BeforeEach(func() { - db = test_config.NewTestDB(test_config.NewTestNode()) - test_config.CleanTestDB(db) - repo = pit.PitStorageRepository{} - repo.SetDB(db) - }) - - 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(fakeIlk, db) - Expect(err).NotTo(HaveOccurred()) - AssertMapping(result, fakeBlockNumber, fakeBlockHash, strconv.Itoa(ilkID), fakeUint256) - }) - - 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(fakeIlk, db) - Expect(err).NotTo(HaveOccurred()) - 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() { - 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, fakeBlockNumber, fakeBlockHash, fakeAddress) - }) - - It("persists a pit line", func() { - 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, fakeBlockNumber, fakeBlockHash, fakeUint256) - }) - - It("persists a pit live", func() { - 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, fakeBlockNumber, fakeBlockHash, fakeUint256) - }) - - It("persists a pit vat", func() { - 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, fakeBlockNumber, fakeBlockHash, fakeAddress) - }) -}) diff --git a/pkg/transformers/storage_diffs/maker/test_helpers/datatypes.go b/pkg/transformers/storage_diffs/maker/test_helpers/datatypes.go deleted file mode 100644 index 09c6bcc6..00000000 --- a/pkg/transformers/storage_diffs/maker/test_helpers/datatypes.go +++ /dev/null @@ -1,49 +0,0 @@ -package test_helpers - -import ( - . "github.com/onsi/gomega" -) - -type BlockMetadata struct { - BlockNumber int `db:"block_number"` - BlockHash string `db:"block_hash"` -} - -type VariableRes struct { - BlockMetadata - Value string -} - -type MappingRes struct { - BlockMetadata - Key string - Value string -} - -type DoubleMappingRes struct { - BlockMetadata - KeyOne string `db:"key_one"` - KeyTwo string `db:"key_two"` - Value string -} - -func AssertVariable(res VariableRes, blockNumber int, blockHash, value string) { - Expect(res.BlockNumber).To(Equal(blockNumber)) - Expect(res.BlockHash).To(Equal(blockHash)) - Expect(res.Value).To(Equal(value)) -} - -func AssertMapping(res MappingRes, blockNumber int, blockHash, key, value string) { - Expect(res.BlockNumber).To(Equal(blockNumber)) - Expect(res.BlockHash).To(Equal(blockHash)) - Expect(res.Key).To(Equal(key)) - Expect(res.Value).To(Equal(value)) -} - -func AssertDoubleMapping(res DoubleMappingRes, blockNumber int, blockHash, keyOne, keyTwo, value string) { - Expect(res.BlockNumber).To(Equal(blockNumber)) - Expect(res.BlockHash).To(Equal(blockHash)) - Expect(res.KeyOne).To(Equal(keyOne)) - Expect(res.KeyTwo).To(Equal(keyTwo)) - Expect(res.Value).To(Equal(value)) -} diff --git a/pkg/transformers/storage_diffs/maker/test_helpers/maker_storage_repository.go b/pkg/transformers/storage_diffs/maker/test_helpers/maker_storage_repository.go deleted file mode 100644 index 3ce7c08c..00000000 --- a/pkg/transformers/storage_diffs/maker/test_helpers/maker_storage_repository.go +++ /dev/null @@ -1,60 +0,0 @@ -package test_helpers - -import ( - "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" - "github.com/vulcanize/vulcanizedb/pkg/transformers/storage_diffs/maker" - "math/big" -) - -type MockMakerStorageRepository struct { - DaiKeys []string - GemKeys []maker.Urn - GetDaiKeysCalled bool - GetDaiKeysError error - GetGemKeysCalled bool - GetGemKeysError error - GetIlksCalled bool - GetIlksError error - GetMaxFlipCalled bool - GetMaxFlipError error - GetSinKeysCalled bool - GetSinKeysError error - GetUrnsCalled bool - GetUrnsError error - Ilks []string - MaxFlip *big.Int - SinKeys []string - Urns []maker.Urn -} - -func (repository *MockMakerStorageRepository) GetDaiKeys() ([]string, error) { - repository.GetDaiKeysCalled = true - return repository.DaiKeys, repository.GetDaiKeysError -} - -func (repository *MockMakerStorageRepository) GetGemKeys() ([]maker.Urn, error) { - repository.GetGemKeysCalled = true - return repository.GemKeys, repository.GetGemKeysError -} - -func (repository *MockMakerStorageRepository) GetIlks() ([]string, error) { - repository.GetIlksCalled = true - return repository.Ilks, repository.GetIlksError -} - -func (repository *MockMakerStorageRepository) GetMaxFlip() (*big.Int, error) { - repository.GetMaxFlipCalled = true - return repository.MaxFlip, repository.GetMaxFlipError -} - -func (repository *MockMakerStorageRepository) GetSinKeys() ([]string, error) { - repository.GetSinKeysCalled = true - return repository.SinKeys, repository.GetSinKeysError -} - -func (repository *MockMakerStorageRepository) GetUrns() ([]maker.Urn, error) { - repository.GetUrnsCalled = true - return repository.Urns, repository.GetUrnsError -} - -func (repository *MockMakerStorageRepository) SetDB(db *postgres.DB) {} diff --git a/pkg/transformers/storage_diffs/maker/vat/repository.go b/pkg/transformers/storage_diffs/maker/vat/repository.go deleted file mode 100644 index 65dcf5b9..00000000 --- a/pkg/transformers/storage_diffs/maker/vat/repository.go +++ /dev/null @@ -1,297 +0,0 @@ -package vat - -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" -) - -type VatStorageRepository struct { - db *postgres.DB -} - -func (repository *VatStorageRepository) Create(blockNumber int, blockHash string, metadata shared.StorageValueMetadata, value interface{}) error { - switch metadata.Name { - case Dai: - return repository.insertDai(blockNumber, blockHash, metadata, value.(string)) - case Gem: - return repository.insertGem(blockNumber, blockHash, metadata, value.(string)) - case IlkArt: - return repository.insertIlkArt(blockNumber, blockHash, metadata, value.(string)) - case IlkInk: - return repository.insertIlkInk(blockNumber, blockHash, metadata, value.(string)) - case IlkRate: - return repository.insertIlkRate(blockNumber, blockHash, metadata, value.(string)) - case IlkTake: - return repository.insertIlkTake(blockNumber, blockHash, metadata, value.(string)) - case Sin: - return repository.insertSin(blockNumber, blockHash, metadata, value.(string)) - case UrnArt: - return repository.insertUrnArt(blockNumber, blockHash, metadata, value.(string)) - case UrnInk: - return repository.insertUrnInk(blockNumber, blockHash, metadata, value.(string)) - case VatDebt: - return repository.insertVatDebt(blockNumber, blockHash, value.(string)) - case VatVice: - return repository.insertVatVice(blockNumber, blockHash, value.(string)) - default: - panic(fmt.Sprintf("unrecognized vat contract storage name: %s", metadata.Name)) - } -} - -func (repository *VatStorageRepository) SetDB(db *postgres.DB) { - repository.db = db -} - -func (repository *VatStorageRepository) insertDai(blockNumber int, blockHash string, metadata shared.StorageValueMetadata, dai string) error { - guy, err := getGuy(metadata.Keys) - if err != nil { - return err - } - _, writeErr := repository.db.Exec(`INSERT INTO maker.vat_dai (block_number, block_hash, guy, dai) VALUES ($1, $2, $3, $4)`, blockNumber, blockHash, guy, dai) - return writeErr -} - -func (repository *VatStorageRepository) insertGem(blockNumber int, blockHash string, metadata shared.StorageValueMetadata, gem string) error { - ilk, err := getIlk(metadata.Keys) - if err != nil { - return err - } - guy, guyErr := getGuy(metadata.Keys) - if guyErr != nil { - return guyErr - } - 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.vat_gem (block_number, block_hash, ilk, guy, gem) VALUES ($1, $2, $3, $4, $5)`, blockNumber, blockHash, ilkID, guy, gem) - if writeErr != nil { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - return fmt.Errorf("failed to rollback transaction after failing to insert gem: %s", writeErr.Error()) - } - return writeErr - } - return tx.Commit() -} - -func (repository *VatStorageRepository) insertIlkArt(blockNumber int, blockHash string, metadata shared.StorageValueMetadata, art string) error { - ilk, err := getIlk(metadata.Keys) - if err != nil { - return err - } - 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.vat_ilk_art (block_number, block_hash, ilk, art) VALUES ($1, $2, $3, $4)`, blockNumber, blockHash, ilkID, art) - if writeErr != nil { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - return fmt.Errorf("failed to rollback transaction after failing to insert ilk art: %s", writeErr.Error()) - } - return writeErr - } - return tx.Commit() -} - -func (repository *VatStorageRepository) insertIlkInk(blockNumber int, blockHash string, metadata shared.StorageValueMetadata, ink string) error { - ilk, err := getIlk(metadata.Keys) - if err != nil { - return err - } - 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.vat_ilk_ink (block_number, block_hash, ilk, ink) VALUES ($1, $2, $3, $4)`, blockNumber, blockHash, ilkID, ink) - if writeErr != nil { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - return fmt.Errorf("failed to rollback transaction after failing to insert ilk ink: %s", writeErr.Error()) - } - return writeErr - } - return tx.Commit() -} - -func (repository *VatStorageRepository) insertIlkRate(blockNumber int, blockHash string, metadata shared.StorageValueMetadata, rate string) error { - ilk, err := getIlk(metadata.Keys) - if err != nil { - return err - } - 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.vat_ilk_rate (block_number, block_hash, ilk, rate) VALUES ($1, $2, $3, $4)`, blockNumber, blockHash, ilkID, rate) - if writeErr != nil { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - return fmt.Errorf("failed to rollback transaction after failing to insert ilk rate: %s", writeErr.Error()) - } - return writeErr - } - return tx.Commit() -} - -func (repository *VatStorageRepository) insertIlkTake(blockNumber int, blockHash string, metadata shared.StorageValueMetadata, take string) error { - ilk, err := getIlk(metadata.Keys) - if err != nil { - return err - } - 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.vat_ilk_take (block_number, block_hash, ilk, take) VALUES ($1, $2, $3, $4)`, blockNumber, blockHash, ilkID, take) - if writeErr != nil { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - return fmt.Errorf("failed to rollback transaction after failing to insert ilk take: %s", writeErr.Error()) - } - return writeErr - } - return tx.Commit() -} - -func (repository *VatStorageRepository) insertSin(blockNumber int, blockHash string, metadata shared.StorageValueMetadata, sin string) error { - guy, err := getGuy(metadata.Keys) - if err != nil { - return err - } - _, writeErr := repository.db.Exec(`INSERT INTO maker.vat_sin (block_number, block_hash, guy, sin) VALUES ($1, $2, $3, $4)`, blockNumber, blockHash, guy, sin) - return writeErr -} - -func (repository *VatStorageRepository) insertUrnArt(blockNumber int, blockHash string, metadata shared.StorageValueMetadata, art string) error { - ilk, err := getIlk(metadata.Keys) - if err != nil { - return err - } - guy, guyErr := getGuy(metadata.Keys) - if guyErr != nil { - return guyErr - } - 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.vat_urn_art (block_number, block_hash, ilk, urn, art) VALUES ($1, $2, $3, $4, $5)`, blockNumber, blockHash, ilkID, guy, art) - if writeErr != nil { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - return fmt.Errorf("failed to rollback transaction after failing to insert urn art: %s", writeErr.Error()) - } - return writeErr - } - return tx.Commit() -} - -func (repository *VatStorageRepository) insertUrnInk(blockNumber int, blockHash string, metadata shared.StorageValueMetadata, ink string) error { - ilk, err := getIlk(metadata.Keys) - if err != nil { - return err - } - guy, guyErr := getGuy(metadata.Keys) - if guyErr != nil { - return guyErr - } - 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.vat_urn_ink (block_number, block_hash, ilk, urn, ink) VALUES ($1, $2, $3, $4, $5)`, blockNumber, blockHash, ilkID, guy, ink) - if writeErr != nil { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - return fmt.Errorf("failed to rollback transaction after failing to insert urn ink: %s", writeErr.Error()) - } - return writeErr - } - return tx.Commit() -} - -func (repository *VatStorageRepository) insertVatDebt(blockNumber int, blockHash, debt string) error { - _, err := repository.db.Exec(`INSERT INTO maker.vat_debt (block_number, block_hash, debt) VALUES ($1, $2, $3)`, blockNumber, blockHash, debt) - return err -} - -func (repository *VatStorageRepository) insertVatVice(blockNumber int, blockHash, vice string) error { - _, err := repository.db.Exec(`INSERT INTO maker.vat_vice (block_number, block_hash, vice) VALUES ($1, $2, $3)`, blockNumber, blockHash, vice) - return err -} - -func getGuy(keys map[shared.Key]string) (string, error) { - guy, ok := keys[shared.Guy] - if !ok { - return "", shared.ErrMetadataMalformed{MissingData: shared.Guy} - } - return guy, nil -} - -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 -} diff --git a/pkg/transformers/storage_diffs/maker/vat/repository_test.go b/pkg/transformers/storage_diffs/maker/vat/repository_test.go deleted file mode 100644 index 9553f26d..00000000 --- a/pkg/transformers/storage_diffs/maker/vat/repository_test.go +++ /dev/null @@ -1,311 +0,0 @@ -package vat_test - -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/test_helpers" - "github.com/vulcanize/vulcanizedb/pkg/transformers/storage_diffs/maker/vat" - "github.com/vulcanize/vulcanizedb/pkg/transformers/storage_diffs/shared" - "github.com/vulcanize/vulcanizedb/test_config" - "strconv" -) - -var _ = Describe("Vat storage repository", func() { - var ( - db *postgres.DB - repo vat.VatStorageRepository - fakeBlockNumber = 123 - fakeBlockHash = "expected_block_hash" - fakeIlk = "fake_ilk" - fakeGuy = "fake_urn" - fakeUint256 = "12345" - ) - - BeforeEach(func() { - db = test_config.NewTestDB(test_config.NewTestNode()) - test_config.CleanTestDB(db) - repo = vat.VatStorageRepository{} - repo.SetDB(db) - }) - - Describe("dai", func() { - It("writes a row", func() { - daiMetadata := shared.GetStorageValueMetadata(vat.Dai, map[shared.Key]string{shared.Guy: fakeGuy}, shared.Uint256) - - err := repo.Create(fakeBlockNumber, fakeBlockHash, daiMetadata, fakeUint256) - - Expect(err).NotTo(HaveOccurred()) - - var result MappingRes - err = db.Get(&result, `SELECT block_number, block_hash, guy AS key, dai AS value FROM maker.vat_dai`) - Expect(err).NotTo(HaveOccurred()) - AssertMapping(result, fakeBlockNumber, fakeBlockHash, fakeGuy, fakeUint256) - }) - - It("returns error if metadata missing guy", func() { - malformedDaiMetadata := shared.GetStorageValueMetadata(vat.Dai, nil, shared.Uint256) - - err := repo.Create(fakeBlockNumber, fakeBlockHash, malformedDaiMetadata, fakeUint256) - - Expect(err).To(HaveOccurred()) - Expect(err).To(MatchError(shared.ErrMetadataMalformed{MissingData: shared.Guy})) - }) - }) - - Describe("gem", func() { - It("writes row", func() { - gemMetadata := shared.GetStorageValueMetadata(vat.Gem, map[shared.Key]string{shared.Ilk: fakeIlk, shared.Guy: fakeGuy}, shared.Uint256) - - err := repo.Create(fakeBlockNumber, fakeBlockHash, gemMetadata, fakeUint256) - - Expect(err).NotTo(HaveOccurred()) - - var result DoubleMappingRes - err = db.Get(&result, `SELECT block_number, block_hash, ilk AS key_one, guy AS key_two, gem AS value FROM maker.vat_gem`) - Expect(err).NotTo(HaveOccurred()) - ilkID, err := shared2.GetOrCreateIlk(fakeIlk, db) - Expect(err).NotTo(HaveOccurred()) - AssertDoubleMapping(result, fakeBlockNumber, fakeBlockHash, strconv.Itoa(ilkID), fakeGuy, fakeUint256) - }) - - It("returns error if metadata missing ilk", func() { - malformedGemMetadata := shared.GetStorageValueMetadata(vat.Gem, map[shared.Key]string{shared.Guy: fakeGuy}, shared.Uint256) - - err := repo.Create(fakeBlockNumber, fakeBlockHash, malformedGemMetadata, fakeUint256) - - Expect(err).To(HaveOccurred()) - Expect(err).To(MatchError(shared.ErrMetadataMalformed{MissingData: shared.Ilk})) - }) - - It("returns error if metadata missing guy", func() { - malformedGemMetadata := shared.GetStorageValueMetadata(vat.Gem, map[shared.Key]string{shared.Ilk: fakeIlk}, shared.Uint256) - - err := repo.Create(fakeBlockNumber, fakeBlockHash, malformedGemMetadata, fakeUint256) - - Expect(err).To(HaveOccurred()) - Expect(err).To(MatchError(shared.ErrMetadataMalformed{MissingData: shared.Guy})) - }) - }) - - Describe("ilk Art", func() { - It("writes row", func() { - ilkArtMetadata := shared.GetStorageValueMetadata(vat.IlkArt, map[shared.Key]string{shared.Ilk: fakeIlk}, shared.Uint256) - - err := repo.Create(fakeBlockNumber, fakeBlockHash, ilkArtMetadata, fakeUint256) - - Expect(err).NotTo(HaveOccurred()) - - var result MappingRes - err = db.Get(&result, `SELECT block_number, block_hash, ilk AS key, art AS value FROM maker.vat_ilk_art`) - Expect(err).NotTo(HaveOccurred()) - ilkID, err := shared2.GetOrCreateIlk(fakeIlk, db) - Expect(err).NotTo(HaveOccurred()) - AssertMapping(result, fakeBlockNumber, fakeBlockHash, strconv.Itoa(ilkID), fakeUint256) - }) - - It("returns error if metadata missing ilk", func() { - malformedIlkArtMetadata := shared.GetStorageValueMetadata(vat.IlkArt, nil, shared.Uint256) - - err := repo.Create(fakeBlockNumber, fakeBlockHash, malformedIlkArtMetadata, fakeUint256) - - Expect(err).To(HaveOccurred()) - Expect(err).To(MatchError(shared.ErrMetadataMalformed{MissingData: shared.Ilk})) - }) - }) - - Describe("ilk Ink", func() { - It("writes row", func() { - ilkInkMetadata := shared.GetStorageValueMetadata(vat.IlkInk, map[shared.Key]string{shared.Ilk: fakeIlk}, shared.Uint256) - - err := repo.Create(fakeBlockNumber, fakeBlockHash, ilkInkMetadata, fakeUint256) - - Expect(err).NotTo(HaveOccurred()) - - var result MappingRes - err = db.Get(&result, `SELECT block_number, block_hash, ilk AS key, ink AS value FROM maker.vat_ilk_ink`) - Expect(err).NotTo(HaveOccurred()) - ilkID, err := shared2.GetOrCreateIlk(fakeIlk, db) - Expect(err).NotTo(HaveOccurred()) - AssertMapping(result, fakeBlockNumber, fakeBlockHash, strconv.Itoa(ilkID), fakeUint256) - }) - - It("returns error if metadata missing ilk", func() { - malformedIlkInkMetadata := shared.GetStorageValueMetadata(vat.IlkInk, nil, shared.Uint256) - - err := repo.Create(fakeBlockNumber, fakeBlockHash, malformedIlkInkMetadata, fakeUint256) - - Expect(err).To(HaveOccurred()) - Expect(err).To(MatchError(shared.ErrMetadataMalformed{MissingData: shared.Ilk})) - }) - }) - - Describe("ilk rate", func() { - It("writes row", func() { - ilkRateMetadata := shared.GetStorageValueMetadata(vat.IlkRate, map[shared.Key]string{shared.Ilk: fakeIlk}, shared.Uint256) - - err := repo.Create(fakeBlockNumber, fakeBlockHash, ilkRateMetadata, fakeUint256) - - Expect(err).NotTo(HaveOccurred()) - - var result MappingRes - err = db.Get(&result, `SELECT block_number, block_hash, ilk AS key, rate AS value FROM maker.vat_ilk_rate`) - Expect(err).NotTo(HaveOccurred()) - ilkID, err := shared2.GetOrCreateIlk(fakeIlk, db) - Expect(err).NotTo(HaveOccurred()) - AssertMapping(result, fakeBlockNumber, fakeBlockHash, strconv.Itoa(ilkID), fakeUint256) - }) - - It("returns error if metadata missing ilk", func() { - malformedIlkRateMetadata := shared.GetStorageValueMetadata(vat.IlkRate, nil, shared.Uint256) - - err := repo.Create(fakeBlockNumber, fakeBlockHash, malformedIlkRateMetadata, fakeUint256) - - Expect(err).To(HaveOccurred()) - Expect(err).To(MatchError(shared.ErrMetadataMalformed{MissingData: shared.Ilk})) - }) - }) - - Describe("ilk take", func() { - It("writes row", func() { - ilkTakeMetadata := shared.GetStorageValueMetadata(vat.IlkTake, map[shared.Key]string{shared.Ilk: fakeIlk}, shared.Uint256) - - err := repo.Create(fakeBlockNumber, fakeBlockHash, ilkTakeMetadata, fakeUint256) - - Expect(err).NotTo(HaveOccurred()) - - var result MappingRes - err = db.Get(&result, `SELECT block_number, block_hash, ilk AS key, take AS value FROM maker.vat_ilk_take`) - Expect(err).NotTo(HaveOccurred()) - ilkID, err := shared2.GetOrCreateIlk(fakeIlk, db) - Expect(err).NotTo(HaveOccurred()) - AssertMapping(result, fakeBlockNumber, fakeBlockHash, strconv.Itoa(ilkID), fakeUint256) - }) - - It("returns error if metadata missing ilk", func() { - malformedIlkTakeMetadata := shared.GetStorageValueMetadata(vat.IlkTake, nil, shared.Uint256) - - err := repo.Create(fakeBlockNumber, fakeBlockHash, malformedIlkTakeMetadata, fakeUint256) - - Expect(err).To(HaveOccurred()) - Expect(err).To(MatchError(shared.ErrMetadataMalformed{MissingData: shared.Ilk})) - }) - }) - - Describe("sin", func() { - It("writes a row", func() { - sinMetadata := shared.GetStorageValueMetadata(vat.Sin, map[shared.Key]string{shared.Guy: fakeGuy}, shared.Uint256) - - err := repo.Create(fakeBlockNumber, fakeBlockHash, sinMetadata, fakeUint256) - - Expect(err).NotTo(HaveOccurred()) - - var result MappingRes - err = db.Get(&result, `SELECT block_number, block_hash, guy AS key, sin AS value FROM maker.vat_sin`) - Expect(err).NotTo(HaveOccurred()) - AssertMapping(result, fakeBlockNumber, fakeBlockHash, fakeGuy, fakeUint256) - }) - - It("returns error if metadata missing guy", func() { - malformedSinMetadata := shared.GetStorageValueMetadata(vat.Sin, nil, shared.Uint256) - - err := repo.Create(fakeBlockNumber, fakeBlockHash, malformedSinMetadata, fakeUint256) - - Expect(err).To(HaveOccurred()) - Expect(err).To(MatchError(shared.ErrMetadataMalformed{MissingData: shared.Guy})) - }) - }) - - Describe("urn art", func() { - It("writes row", func() { - urnArtMetadata := shared.GetStorageValueMetadata(vat.UrnArt, map[shared.Key]string{shared.Ilk: fakeIlk, shared.Guy: fakeGuy}, shared.Uint256) - - err := repo.Create(fakeBlockNumber, fakeBlockHash, urnArtMetadata, fakeUint256) - - Expect(err).NotTo(HaveOccurred()) - - var result DoubleMappingRes - err = db.Get(&result, `SELECT block_number, block_hash, ilk AS key_one, urn AS key_two, art AS value FROM maker.vat_urn_art`) - Expect(err).NotTo(HaveOccurred()) - ilkID, err := shared2.GetOrCreateIlk(fakeIlk, db) - Expect(err).NotTo(HaveOccurred()) - AssertDoubleMapping(result, fakeBlockNumber, fakeBlockHash, strconv.Itoa(ilkID), fakeGuy, fakeUint256) - }) - - It("returns error if metadata missing ilk", func() { - malformedUrnArtMetadata := shared.GetStorageValueMetadata(vat.UrnArt, map[shared.Key]string{shared.Guy: fakeGuy}, shared.Uint256) - - err := repo.Create(fakeBlockNumber, fakeBlockHash, malformedUrnArtMetadata, fakeUint256) - - Expect(err).To(HaveOccurred()) - Expect(err).To(MatchError(shared.ErrMetadataMalformed{MissingData: shared.Ilk})) - }) - - It("returns error if metadata missing guy", func() { - malformedUrnArtMetadata := shared.GetStorageValueMetadata(vat.UrnArt, map[shared.Key]string{shared.Ilk: fakeIlk}, shared.Uint256) - - err := repo.Create(fakeBlockNumber, fakeBlockHash, malformedUrnArtMetadata, fakeUint256) - - Expect(err).To(HaveOccurred()) - Expect(err).To(MatchError(shared.ErrMetadataMalformed{MissingData: shared.Guy})) - }) - }) - - Describe("urn ink", func() { - It("writes row", func() { - urnInkMetadata := shared.GetStorageValueMetadata(vat.UrnInk, map[shared.Key]string{shared.Ilk: fakeIlk, shared.Guy: fakeGuy}, shared.Uint256) - - err := repo.Create(fakeBlockNumber, fakeBlockHash, urnInkMetadata, fakeUint256) - - Expect(err).NotTo(HaveOccurred()) - - var result DoubleMappingRes - err = db.Get(&result, `SELECT block_number, block_hash, ilk AS key_one, urn AS key_two, ink AS value FROM maker.vat_urn_ink`) - Expect(err).NotTo(HaveOccurred()) - ilkID, err := shared2.GetOrCreateIlk(fakeIlk, db) - Expect(err).NotTo(HaveOccurred()) - AssertDoubleMapping(result, fakeBlockNumber, fakeBlockHash, strconv.Itoa(ilkID), fakeGuy, fakeUint256) - }) - - It("returns error if metadata missing ilk", func() { - malformedUrnInkMetadata := shared.GetStorageValueMetadata(vat.UrnInk, map[shared.Key]string{shared.Guy: fakeGuy}, shared.Uint256) - - err := repo.Create(fakeBlockNumber, fakeBlockHash, malformedUrnInkMetadata, fakeUint256) - - Expect(err).To(HaveOccurred()) - Expect(err).To(MatchError(shared.ErrMetadataMalformed{MissingData: shared.Ilk})) - }) - - It("returns error if metadata missing guy", func() { - malformedUrnInkMetadata := shared.GetStorageValueMetadata(vat.UrnInk, map[shared.Key]string{shared.Ilk: fakeIlk}, shared.Uint256) - - err := repo.Create(fakeBlockNumber, fakeBlockHash, malformedUrnInkMetadata, fakeUint256) - - Expect(err).To(HaveOccurred()) - Expect(err).To(MatchError(shared.ErrMetadataMalformed{MissingData: shared.Guy})) - }) - }) - - It("persists vat debt", func() { - err := repo.Create(fakeBlockNumber, fakeBlockHash, vat.DebtMetadata, fakeUint256) - - Expect(err).NotTo(HaveOccurred()) - - var result VariableRes - err = db.Get(&result, `SELECT block_number, block_hash, debt AS value FROM maker.vat_debt`) - Expect(err).NotTo(HaveOccurred()) - AssertVariable(result, fakeBlockNumber, fakeBlockHash, fakeUint256) - }) - - It("persists vat vice", func() { - err := repo.Create(fakeBlockNumber, fakeBlockHash, vat.ViceMetadata, fakeUint256) - - Expect(err).NotTo(HaveOccurred()) - - var result VariableRes - err = db.Get(&result, `SELECT block_number, block_hash, vice AS value FROM maker.vat_vice`) - Expect(err).NotTo(HaveOccurred()) - AssertVariable(result, fakeBlockNumber, fakeBlockHash, fakeUint256) - }) -}) diff --git a/pkg/transformers/storage_diffs/maker/vow/repository_test.go b/pkg/transformers/storage_diffs/maker/vow/repository_test.go deleted file mode 100644 index eb116342..00000000 --- a/pkg/transformers/storage_diffs/maker/vow/repository_test.go +++ /dev/null @@ -1,176 +0,0 @@ -/* - * 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/transformers/storage_diffs/maker/test_helpers" - - "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 := "123" - - err = repo.Create(blockNumber, blockHash, vow.VatMetadata, expectedVat) - - Expect(err).NotTo(HaveOccurred()) - - var result VariableRes - err = db.Get(&result, `SELECT block_number, block_hash, vat AS value from maker.vow_vat`) - Expect(err).NotTo(HaveOccurred()) - AssertVariable(result, blockNumber, blockHash, expectedVat) - }) - - It("persists a vow cow", func() { - expectedCow := "123" - - err = repo.Create(blockNumber, blockHash, vow.CowMetadata, expectedCow) - - Expect(err).NotTo(HaveOccurred()) - - var result VariableRes - err = db.Get(&result, `SELECT block_number, block_hash, cow AS value from maker.vow_cow`) - Expect(err).NotTo(HaveOccurred()) - AssertVariable(result, blockNumber, blockHash, expectedCow) - }) - - It("persists a vow row", func() { - expectedRow := "123" - - err = repo.Create(blockNumber, blockHash, vow.RowMetadata, expectedRow) - - Expect(err).NotTo(HaveOccurred()) - - var result VariableRes - err = db.Get(&result, `SELECT block_number, block_hash, row AS value from maker.vow_row`) - Expect(err).NotTo(HaveOccurred()) - AssertVariable(result, blockNumber, blockHash, expectedRow) - }) - - It("persists a vow Sin", func() { - expectedSow := "123" - - err = repo.Create(blockNumber, blockHash, vow.SinMetadata, expectedSow) - - Expect(err).NotTo(HaveOccurred()) - - var result VariableRes - err = db.Get(&result, `SELECT block_number, block_hash, sin AS value from maker.vow_sin`) - Expect(err).NotTo(HaveOccurred()) - AssertVariable(result, blockNumber, blockHash, expectedSow) - }) - - It("persists a vow woe", func() { - expectedWoe := "123" - - err = repo.Create(blockNumber, blockHash, vow.WoeMetadata, expectedWoe) - - Expect(err).NotTo(HaveOccurred()) - - var result VariableRes - err = db.Get(&result, `SELECT block_number, block_hash, woe AS value from maker.vow_woe`) - Expect(err).NotTo(HaveOccurred()) - AssertVariable(result, blockNumber, blockHash, expectedWoe) - }) - - It("persists a vow Ash", func() { - expectedAsh := "123" - - err = repo.Create(blockNumber, blockHash, vow.AshMetadata, expectedAsh) - - Expect(err).NotTo(HaveOccurred()) - - var result VariableRes - err = db.Get(&result, `SELECT block_number, block_hash, ash AS value from maker.vow_ash`) - Expect(err).NotTo(HaveOccurred()) - AssertVariable(result, blockNumber, blockHash, expectedAsh) - }) - - It("persists a vow Wait", func() { - expectedWait := "123" - - err = repo.Create(blockNumber, blockHash, vow.WaitMetadata, expectedWait) - - Expect(err).NotTo(HaveOccurred()) - - var result VariableRes - err = db.Get(&result, `SELECT block_number, block_hash, wait AS value from maker.vow_wait`) - Expect(err).NotTo(HaveOccurred()) - AssertVariable(result, blockNumber, blockHash, expectedWait) - }) - - It("persists a vow Bump", func() { - expectedBump := "123" - - err = repo.Create(blockNumber, blockHash, vow.BumpMetadata, expectedBump) - - Expect(err).NotTo(HaveOccurred()) - - var result VariableRes - err = db.Get(&result, `SELECT block_number, block_hash, bump AS value from maker.vow_bump`) - Expect(err).NotTo(HaveOccurred()) - AssertVariable(result, blockNumber, blockHash, expectedBump) - }) - - It("persists a vow Sump", func() { - expectedSump := "123" - - err = repo.Create(blockNumber, blockHash, vow.SumpMetadata, expectedSump) - - Expect(err).NotTo(HaveOccurred()) - - var result VariableRes - err = db.Get(&result, `SELECT block_number, block_hash, sump AS value from maker.vow_sump`) - Expect(err).NotTo(HaveOccurred()) - AssertVariable(result, blockNumber, blockHash, expectedSump) - }) - - It("persists a vow Hump", func() { - expectedHump := "123" - - err = repo.Create(blockNumber, blockHash, vow.HumpMetadata, expectedHump) - - Expect(err).NotTo(HaveOccurred()) - - var result VariableRes - err = db.Get(&result, `SELECT block_number, block_hash, hump AS value from maker.vow_hump`) - Expect(err).NotTo(HaveOccurred()) - AssertVariable(result, blockNumber, blockHash, expectedHump) - }) -}) diff --git a/pkg/transformers/storage_transformers.go b/pkg/transformers/storage_transformers.go deleted file mode 100644 index 48e2771b..00000000 --- a/pkg/transformers/storage_transformers.go +++ /dev/null @@ -1,44 +0,0 @@ -package transformers - -import ( - "github.com/ethereum/go-ethereum/common" - "github.com/vulcanize/vulcanizedb/pkg/transformers/factories/storage" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" - "github.com/vulcanize/vulcanizedb/pkg/transformers/storage_diffs/maker" - "github.com/vulcanize/vulcanizedb/pkg/transformers/storage_diffs/maker/cat" - "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 GetCatStorageTransformer() storage.Transformer { - return storage.Transformer{ - Address: common.HexToAddress(constants.CatContractAddress()), - Mappings: &cat.CatMappings{StorageRepository: &maker.MakerStorageRepository{}}, - Repository: &cat.CatStorageRepository{}, - } -} - -func GetPitStorageTransformer() storage.Transformer { - return storage.Transformer{ - Address: common.HexToAddress(constants.PitContractAddress()), - Mappings: &pit.PitMappings{StorageRepository: &maker.MakerStorageRepository{}}, - Repository: &pit.PitStorageRepository{}, - } -} - -func GetVatStorageTransformer() storage.Transformer { - return storage.Transformer{ - Address: common.HexToAddress(constants.VatContractAddress()), - Mappings: &vat.VatMappings{StorageRepository: &maker.MakerStorageRepository{}}, - Repository: &vat.VatStorageRepository{}, - } -} - -func GetVowStorageTransformer() storage.Transformer { - return storage.Transformer{ - Address: common.HexToAddress(constants.VowContractAddress()), - Mappings: &vow.VowMappings{StorageRepository: &maker.MakerStorageRepository{}}, - Repository: &vow.VowStorageRepository{}, - } -} diff --git a/pkg/transformers/test_data/mocks/storage_queue.go b/pkg/transformers/test_data/mocks/storage_queue.go deleted file mode 100644 index 6a4cda74..00000000 --- a/pkg/transformers/test_data/mocks/storage_queue.go +++ /dev/null @@ -1,15 +0,0 @@ -package mocks - -import ( - "github.com/vulcanize/vulcanizedb/pkg/transformers/storage_diffs/shared" -) - -type MockStorageQueue struct { - AddCalled bool - AddError error -} - -func (queue *MockStorageQueue) Add(row shared.StorageDiffRow) error { - queue.AddCalled = true - return queue.AddError -} diff --git a/pkg/transformers/test_data/pit_file.go b/pkg/transformers/test_data/pit_file.go deleted file mode 100644 index 155578b5..00000000 --- a/pkg/transformers/test_data/pit_file.go +++ /dev/null @@ -1,111 +0,0 @@ -// VulcanizeDB -// Copyright © 2018 Vulcanize - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. - -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -package test_data - -import ( - "encoding/json" - "math/big" - - "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/common/hexutil" - "github.com/ethereum/go-ethereum/core/types" - - "github.com/vulcanize/vulcanizedb/pkg/fakes" - "github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file/debt_ceiling" - ilk2 "github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file/ilk" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" -) - -var EthPitFileDebtCeilingLog = types.Log{ - Address: common.HexToAddress(KovanPitContractAddress), - Topics: []common.Hash{ - common.HexToHash("0x29ae811400000000000000000000000000000000000000000000000000000000"), - common.HexToHash("0x00000000000000000000000064d922894153be9eef7b7218dc565d1d0ce2a092"), - common.HexToHash("0x4c696e6500000000000000000000000000000000000000000000000000000000"), - common.HexToHash("0x000000000000000000000000000000000000000000000000000000000001e240"), - }, - Data: hexutil.MustDecode("0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000004429ae81144c696e6500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001e240"), - BlockNumber: 22, - TxHash: common.HexToHash("0xd744878a0b6655e3ba729e1019f56b563b4a16750196b8ad6104f3977db43f42"), - TxIndex: 333, - BlockHash: fakes.FakeHash, - Index: 15, - Removed: false, -} - -var rawPitFileDebtCeilingLog, _ = json.Marshal(EthPitFileDebtCeilingLog) -var PitFileDebtCeilingModel = debt_ceiling.PitFileDebtCeilingModel{ - What: "Line", - Data: shared.ConvertToWad(big.NewInt(123456).String()), - LogIndex: EthPitFileDebtCeilingLog.Index, - TransactionIndex: EthPitFileDebtCeilingLog.TxIndex, - Raw: rawPitFileDebtCeilingLog, -} - -var EthPitFileIlkLineLog = types.Log{ - Address: common.HexToAddress(KovanPitContractAddress), - Topics: []common.Hash{ - common.HexToHash("0x1a0b287e00000000000000000000000000000000000000000000000000000000"), - common.HexToHash("0x00000000000000000000000064d922894153be9eef7b7218dc565d1d0ce2a092"), - common.HexToHash("0x66616b6520696c6b000000000000000000000000000000000000000000000000"), - common.HexToHash("0x6c696e6500000000000000000000000000000000000000000000000000000000"), - }, - Data: hexutil.MustDecode("0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000641a0b287e66616b6520696c6b0000000000000000000000000000000000000000000000006c696e6500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e8d4a51000"), - BlockNumber: 12, - TxHash: common.HexToHash("0x2e27c962a697d4f7ec5d3206d0c058bd510f7593a711f082e55f3b62d44d8dd9"), - TxIndex: 112, - BlockHash: fakes.FakeHash, - Index: 15, - Removed: false, -} - -var rawPitFileIlkLineLog, _ = json.Marshal(EthPitFileIlkLineLog) -var PitFileIlkLineModel = ilk2.PitFileIlkModel{ - Ilk: "66616b6520696c6b000000000000000000000000000000000000000000000000", - What: "line", - Data: "0.000001000000000000", - LogIndex: EthPitFileIlkLineLog.Index, - TransactionIndex: EthPitFileIlkLineLog.TxIndex, - Raw: rawPitFileIlkLineLog, -} - -var EthPitFileIlkSpotLog = types.Log{ - Address: common.HexToAddress(KovanPitContractAddress), - Topics: []common.Hash{ - common.HexToHash("0x1a0b287e00000000000000000000000000000000000000000000000000000000"), - common.HexToHash("0x00000000000000000000000064d922894153be9eef7b7218dc565d1d0ce2a092"), - common.HexToHash("0x66616b6520696c6b000000000000000000000000000000000000000000000000"), - common.HexToHash("0x73706f7400000000000000000000000000000000000000000000000000000000"), - }, - Data: hexutil.MustDecode("0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000641a0b287e66616b6520696c6b00000000000000000000000000000000000000000000000073706f7400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e8d4a51000"), - BlockNumber: 11, - TxHash: common.HexToHash("0x1ba8125f60fa045c85b35df3983bee37db8627fbc32e3442a5cf17c85bb83f09"), - TxIndex: 111, - BlockHash: fakes.FakeHash, - Index: 14, - Removed: false, -} - -var rawPitFileIlkSpotLog, _ = json.Marshal(EthPitFileIlkSpotLog) -var PitFileIlkSpotModel = ilk2.PitFileIlkModel{ - Ilk: "66616b6520696c6b000000000000000000000000000000000000000000000000", - What: "spot", - Data: "0.000000000000001000000000000", - LogIndex: EthPitFileIlkSpotLog.Index, - TransactionIndex: EthPitFileIlkSpotLog.TxIndex, - Raw: rawPitFileIlkSpotLog, -} diff --git a/pkg/transformers/vat_flux/repository.go b/pkg/transformers/vat_flux/repository.go deleted file mode 100644 index 516405e2..00000000 --- a/pkg/transformers/vat_flux/repository.go +++ /dev/null @@ -1,98 +0,0 @@ -// VulcanizeDB -// Copyright © 2018 Vulcanize - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. - -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -package vat_flux - -import ( - "fmt" - - log "github.com/sirupsen/logrus" - - "github.com/vulcanize/vulcanizedb/pkg/core" - "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" -) - -type VatFluxRepository struct { - db *postgres.DB -} - -func (repository VatFluxRepository) Create(headerID int64, models []interface{}) error { - tx, dBaseErr := repository.db.Begin() - if dBaseErr != nil { - return dBaseErr - } - - for _, model := range models { - vatFlux, ok := model.(VatFluxModel) - if !ok { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - log.Error("failed to rollback ", rollbackErr) - } - return fmt.Errorf("model of type %T, not %T", model, VatFluxModel{}) - } - - ilkID, ilkErr := shared.GetOrCreateIlkInTransaction(vatFlux.Ilk, tx) - if ilkErr != nil { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - log.Error("failed to rollback ", rollbackErr) - } - return ilkErr - } - - _, execErr := tx.Exec(`INSERT INTO maker.vat_flux (header_id, ilk, dst, src, rad, tx_idx, log_idx, raw_log) - VALUES($1, $2, $3, $4, $5::NUMERIC, $6, $7, $8) - ON CONFLICT (header_id, tx_idx, log_idx) DO UPDATE SET ilk = $2, dst = $3, src = $4, rad = $5, raw_log = $8;`, - headerID, ilkID, vatFlux.Dst, vatFlux.Src, vatFlux.Rad, vatFlux.TransactionIndex, vatFlux.LogIndex, vatFlux.Raw) - if execErr != nil { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - log.Error("failed to rollback ", rollbackErr) - } - return execErr - } - } - - checkHeaderErr := shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatFluxChecked) - if checkHeaderErr != nil { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - log.Error("failed to rollback ", rollbackErr) - } - return checkHeaderErr - } - - return tx.Commit() -} - -func (repository VatFluxRepository) MarkHeaderChecked(headerId int64) error { - return shared.MarkHeaderChecked(headerId, repository.db, constants.VatFluxChecked) -} - -func (repository VatFluxRepository) MissingHeaders(startingBlock, endingBlock int64) ([]core.Header, error) { - return shared.MissingHeaders(startingBlock, endingBlock, repository.db, constants.VatFluxChecked) -} - -func (repository VatFluxRepository) RecheckHeaders(startingBlock, endingBlock int64) ([]core.Header, error) { - return shared.RecheckHeaders(startingBlock, endingBlock, repository.db, constants.VatFluxChecked) -} - -func (repository *VatFluxRepository) SetDB(db *postgres.DB) { - repository.db = db -} diff --git a/pkg/transformers/vat_flux/repository_test.go b/pkg/transformers/vat_flux/repository_test.go deleted file mode 100644 index 8bbde4ba..00000000 --- a/pkg/transformers/vat_flux/repository_test.go +++ /dev/null @@ -1,103 +0,0 @@ -// VulcanizeDB -// Copyright © 2018 Vulcanize - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. - -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -package vat_flux_test - -import ( - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" - "strconv" - - "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" - "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories" - "github.com/vulcanize/vulcanizedb/pkg/fakes" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" - "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" - "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/shared_behaviors" - "github.com/vulcanize/vulcanizedb/pkg/transformers/vat_flux" - "github.com/vulcanize/vulcanizedb/test_config" -) - -var _ = Describe("VatFlux Repository", func() { - var ( - db *postgres.DB - repository vat_flux.VatFluxRepository - ) - - BeforeEach(func() { - node := test_config.NewTestNode() - db = test_config.NewTestDB(node) - test_config.CleanTestDB(db) - repository = vat_flux.VatFluxRepository{} - repository.SetDB(db) - }) - - type VatFluxDBResult struct { - vat_flux.VatFluxModel - Id int - HeaderId int64 `db:"header_id"` - } - - Describe("Create", func() { - vatFluxWithDifferentLogIdx := test_data.VatFluxModel - vatFluxWithDifferentLogIdx.LogIndex++ - inputs := shared_behaviors.CreateBehaviorInputs{ - CheckedHeaderColumnName: constants.VatFluxChecked, - LogEventTableName: "maker.vat_flux", - TestModel: test_data.VatFluxModel, - ModelWithDifferentLogIdx: vatFluxWithDifferentLogIdx, - Repository: &repository, - } - - shared_behaviors.SharedRepositoryCreateBehaviors(&inputs) - - It("persists vat flux records", func() { - headerRepository := repositories.NewHeaderRepository(db) - headerId, err := headerRepository.CreateOrUpdateHeader(fakes.FakeHeader) - Expect(err).NotTo(HaveOccurred()) - - anotherVatFlux := test_data.VatFluxModel - anotherVatFlux.TransactionIndex = test_data.VatFluxModel.TransactionIndex + 1 - err = repository.Create(headerId, []interface{}{test_data.VatFluxModel, anotherVatFlux}) - - var dbResult []VatFluxDBResult - err = db.Select(&dbResult, `SELECT * from maker.vat_flux where header_id = $1`, headerId) - Expect(err).NotTo(HaveOccurred()) - Expect(len(dbResult)).To(Equal(2)) - ilkID, err := shared.GetOrCreateIlk(test_data.VatFluxModel.Ilk, db) - Expect(err).NotTo(HaveOccurred()) - Expect(dbResult[0].Ilk).To(Equal(strconv.Itoa(ilkID))) - Expect(dbResult[0].Dst).To(Equal(test_data.VatFluxModel.Dst)) - Expect(dbResult[0].Src).To(Equal(test_data.VatFluxModel.Src)) - Expect(dbResult[0].Rad).To(Equal(test_data.VatFluxModel.Rad)) - Expect(dbResult[0].TransactionIndex).To(Equal(test_data.VatFluxModel.TransactionIndex)) - Expect(dbResult[1].TransactionIndex).To(Equal(test_data.VatFluxModel.TransactionIndex + 1)) - Expect(dbResult[0].LogIndex).To(Equal(test_data.VatFluxModel.LogIndex)) - Expect(dbResult[0].Raw).To(MatchJSON(test_data.VatFluxModel.Raw)) - Expect(dbResult[0].HeaderId).To(Equal(headerId)) - }) - }) - - Describe("MarkHeaderChecked", func() { - inputs := shared_behaviors.MarkedHeaderCheckedBehaviorInputs{ - CheckedHeaderColumnName: constants.VatFluxChecked, - Repository: &repository, - } - - shared_behaviors.SharedRepositoryMarkHeaderCheckedBehaviors(&inputs) - }) -}) diff --git a/pkg/transformers/vat_fold/repository.go b/pkg/transformers/vat_fold/repository.go deleted file mode 100644 index 96fa1c44..00000000 --- a/pkg/transformers/vat_fold/repository.go +++ /dev/null @@ -1,98 +0,0 @@ -// VulcanizeDB -// Copyright © 2018 Vulcanize - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. - -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -package vat_fold - -import ( - "fmt" - log "github.com/sirupsen/logrus" - - "github.com/vulcanize/vulcanizedb/pkg/core" - "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" -) - -type VatFoldRepository struct { - db *postgres.DB -} - -func (repository VatFoldRepository) Create(headerID int64, models []interface{}) error { - tx, dBaseErr := repository.db.Begin() - if dBaseErr != nil { - return dBaseErr - } - for _, model := range models { - vatFold, ok := model.(VatFoldModel) - if !ok { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - log.Error("failed to rollback ", rollbackErr) - } - return fmt.Errorf("model of type %T, not %T", model, VatFoldModel{}) - } - - ilkID, ilkErr := shared.GetOrCreateIlkInTransaction(vatFold.Ilk, tx) - if ilkErr != nil { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - log.Error("failed to rollback ", rollbackErr) - } - return ilkErr - } - - _, execErr := tx.Exec( - `INSERT into maker.vat_fold (header_id, ilk, urn, rate, log_idx, tx_idx, raw_log) - VALUES($1, $2, $3, $4::NUMERIC, $5, $6, $7) - ON CONFLICT (header_id, tx_idx, log_idx) DO UPDATE SET ilk = $2, urn = $3, rate = $4, raw_log = $7;`, - headerID, ilkID, vatFold.Urn, vatFold.Rate, vatFold.LogIndex, vatFold.TransactionIndex, vatFold.Raw, - ) - if execErr != nil { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - log.Error("failed to rollback ", rollbackErr) - } - return execErr - } - } - - checkHeaderErr := shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatFoldChecked) - if checkHeaderErr != nil { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - log.Error("failed to rollback ", rollbackErr) - } - return checkHeaderErr - } - - return tx.Commit() -} - -func (repository VatFoldRepository) MarkHeaderChecked(headerID int64) error { - return shared.MarkHeaderChecked(headerID, repository.db, constants.VatFoldChecked) -} - -func (repository VatFoldRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { - return shared.MissingHeaders(startingBlockNumber, endingBlockNumber, repository.db, constants.VatFoldChecked) -} - -func (repository VatFoldRepository) RecheckHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { - return shared.RecheckHeaders(startingBlockNumber, endingBlockNumber, repository.db, constants.VatFoldChecked) -} - -func (repository *VatFoldRepository) SetDB(db *postgres.DB) { - repository.db = db -} diff --git a/pkg/transformers/vat_fold/repository_test.go b/pkg/transformers/vat_fold/repository_test.go deleted file mode 100644 index 8ac0f679..00000000 --- a/pkg/transformers/vat_fold/repository_test.go +++ /dev/null @@ -1,93 +0,0 @@ -// VulcanizeDB -// Copyright © 2018 Vulcanize - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. - -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -package vat_fold_test - -import ( - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" - "strconv" - - "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" - "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories" - "github.com/vulcanize/vulcanizedb/pkg/fakes" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" - "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" - "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/shared_behaviors" - "github.com/vulcanize/vulcanizedb/pkg/transformers/vat_fold" - "github.com/vulcanize/vulcanizedb/test_config" -) - -var _ = Describe("Vat.fold repository", func() { - var ( - db *postgres.DB - repository vat_fold.VatFoldRepository - ) - - BeforeEach(func() { - node := test_config.NewTestNode() - db = test_config.NewTestDB(node) - test_config.CleanTestDB(db) - repository = vat_fold.VatFoldRepository{} - repository.SetDB(db) - }) - - Describe("Create", func() { - modelWithDifferentLogIdx := test_data.VatFoldModel - modelWithDifferentLogIdx.LogIndex++ - - inputs := shared_behaviors.CreateBehaviorInputs{ - CheckedHeaderColumnName: constants.VatFoldChecked, - LogEventTableName: "maker.vat_fold", - TestModel: test_data.VatFoldModel, - ModelWithDifferentLogIdx: modelWithDifferentLogIdx, - Repository: &repository, - } - - shared_behaviors.SharedRepositoryCreateBehaviors(&inputs) - - It("adds a vat fold event", func() { - headerRepository := repositories.NewHeaderRepository(db) - headerID, err := headerRepository.CreateOrUpdateHeader(fakes.FakeHeader) - Expect(err).NotTo(HaveOccurred()) - err = repository.Create(headerID, []interface{}{test_data.VatFoldModel}) - - Expect(err).NotTo(HaveOccurred()) - var dbVatFold vat_fold.VatFoldModel - err = db.Get(&dbVatFold, `SELECT ilk, urn, rate, log_idx, tx_idx, raw_log FROM maker.vat_fold WHERE header_id = $1`, headerID) - Expect(err).NotTo(HaveOccurred()) - - ilkID, err := shared.GetOrCreateIlk(test_data.VatFoldModel.Ilk, db) - Expect(err).NotTo(HaveOccurred()) - Expect(dbVatFold.Ilk).To(Equal(strconv.Itoa(ilkID))) - Expect(dbVatFold.Urn).To(Equal(test_data.VatFoldModel.Urn)) - Expect(dbVatFold.Rate).To(Equal(test_data.VatFoldModel.Rate)) - Expect(dbVatFold.LogIndex).To(Equal(test_data.VatFoldModel.LogIndex)) - Expect(dbVatFold.TransactionIndex).To(Equal(test_data.VatFoldModel.TransactionIndex)) - Expect(dbVatFold.Raw).To(MatchJSON(test_data.VatFoldModel.Raw)) - }) - }) - - Describe("MarkHeaderChecked", func() { - inputs := shared_behaviors.MarkedHeaderCheckedBehaviorInputs{ - CheckedHeaderColumnName: constants.VatFoldChecked, - Repository: &repository, - } - - shared_behaviors.SharedRepositoryMarkHeaderCheckedBehaviors(&inputs) - }) -}) diff --git a/pkg/transformers/vat_grab/repository.go b/pkg/transformers/vat_grab/repository.go deleted file mode 100644 index 80dbcfdd..00000000 --- a/pkg/transformers/vat_grab/repository.go +++ /dev/null @@ -1,80 +0,0 @@ -package vat_grab - -import ( - "fmt" - log "github.com/sirupsen/logrus" - - "github.com/vulcanize/vulcanizedb/pkg/core" - "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" -) - -type VatGrabRepository struct { - db *postgres.DB -} - -func (repository VatGrabRepository) Create(headerID int64, models []interface{}) error { - tx, dBaseErr := repository.db.Begin() - if dBaseErr != nil { - return dBaseErr - } - for _, model := range models { - vatGrab, ok := model.(VatGrabModel) - if !ok { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - log.Error("failed to rollback ", rollbackErr) - } - return fmt.Errorf("model of type %T, not %T", model, VatGrabModel{}) - } - - ilkID, ilkErr := shared.GetOrCreateIlkInTransaction(vatGrab.Ilk, tx) - if ilkErr != nil { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - log.Error("failed to rollback ", rollbackErr) - } - return ilkErr - } - - _, execErr := tx.Exec( - `INSERT into maker.vat_grab (header_id, ilk, urn, v, w, dink, dart, log_idx, tx_idx, raw_log) - VALUES($1, $2, $3, $4, $5, $6::NUMERIC, $7::NUMERIC, $8, $9, $10) - ON CONFLICT (header_id, tx_idx, log_idx) DO UPDATE SET ilk = $2, urn = $3, v = $4, w = $5, dink = $6, dart = $7, raw_log = $10;`, - headerID, ilkID, vatGrab.Urn, vatGrab.V, vatGrab.W, vatGrab.Dink, vatGrab.Dart, vatGrab.LogIndex, vatGrab.TransactionIndex, vatGrab.Raw, - ) - if execErr != nil { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - log.Error("failed to rollback ", rollbackErr) - } - return execErr - } - } - checkHeaderErr := shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatGrabChecked) - if checkHeaderErr != nil { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - log.Error("failed to rollback ", rollbackErr) - } - return checkHeaderErr - } - return tx.Commit() -} - -func (repository VatGrabRepository) MarkHeaderChecked(headerID int64) error { - return shared.MarkHeaderChecked(headerID, repository.db, constants.VatGrabChecked) -} - -func (repository VatGrabRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { - return shared.MissingHeaders(startingBlockNumber, endingBlockNumber, repository.db, constants.VatGrabChecked) -} - -func (repository VatGrabRepository) RecheckHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { - return shared.RecheckHeaders(startingBlockNumber, endingBlockNumber, repository.db, constants.VatGrabChecked) -} - -func (repository *VatGrabRepository) SetDB(db *postgres.DB) { - repository.db = db -} diff --git a/pkg/transformers/vat_grab/repository_test.go b/pkg/transformers/vat_grab/repository_test.go deleted file mode 100644 index ac77c075..00000000 --- a/pkg/transformers/vat_grab/repository_test.go +++ /dev/null @@ -1,80 +0,0 @@ -package vat_grab_test - -import ( - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" - "strconv" - - "github.com/vulcanize/vulcanizedb/pkg/datastore" - "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" - "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories" - "github.com/vulcanize/vulcanizedb/pkg/fakes" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" - "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" - "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/shared_behaviors" - "github.com/vulcanize/vulcanizedb/pkg/transformers/vat_grab" - "github.com/vulcanize/vulcanizedb/test_config" -) - -var _ = Describe("Vat grab repository", func() { - var ( - db *postgres.DB - vatGrabRepository vat_grab.VatGrabRepository - headerRepository datastore.HeaderRepository - ) - - BeforeEach(func() { - db = test_config.NewTestDB(test_config.NewTestNode()) - test_config.CleanTestDB(db) - headerRepository = repositories.NewHeaderRepository(db) - vatGrabRepository = vat_grab.VatGrabRepository{} - vatGrabRepository.SetDB(db) - }) - - Describe("Create", func() { - modelWithDifferentLogIdx := test_data.VatGrabModel - modelWithDifferentLogIdx.LogIndex++ - - inputs := shared_behaviors.CreateBehaviorInputs{ - CheckedHeaderColumnName: constants.VatGrabChecked, - LogEventTableName: "maker.vat_grab", - TestModel: test_data.VatGrabModel, - ModelWithDifferentLogIdx: modelWithDifferentLogIdx, - Repository: &vatGrabRepository, - } - - shared_behaviors.SharedRepositoryCreateBehaviors(&inputs) - - It("adds a vat grab event", func() { - headerID, err := headerRepository.CreateOrUpdateHeader(fakes.FakeHeader) - Expect(err).NotTo(HaveOccurred()) - - err = vatGrabRepository.Create(headerID, []interface{}{test_data.VatGrabModel}) - Expect(err).NotTo(HaveOccurred()) - var dbVatGrab vat_grab.VatGrabModel - err = db.Get(&dbVatGrab, `SELECT ilk, urn, v, w, dink, dart, log_idx, tx_idx, raw_log FROM maker.vat_grab WHERE header_id = $1`, headerID) - Expect(err).NotTo(HaveOccurred()) - ilkID, err := shared.GetOrCreateIlk(test_data.VatGrabModel.Ilk, db) - Expect(err).NotTo(HaveOccurred()) - Expect(dbVatGrab.Ilk).To(Equal(strconv.Itoa(ilkID))) - Expect(dbVatGrab.Urn).To(Equal(test_data.VatGrabModel.Urn)) - Expect(dbVatGrab.V).To(Equal(test_data.VatGrabModel.V)) - Expect(dbVatGrab.W).To(Equal(test_data.VatGrabModel.W)) - Expect(dbVatGrab.Dink).To(Equal(test_data.VatGrabModel.Dink)) - Expect(dbVatGrab.Dart).To(Equal(test_data.VatGrabModel.Dart)) - Expect(dbVatGrab.LogIndex).To(Equal(test_data.VatGrabModel.LogIndex)) - Expect(dbVatGrab.TransactionIndex).To(Equal(test_data.VatGrabModel.TransactionIndex)) - Expect(dbVatGrab.Raw).To(MatchJSON(test_data.VatGrabModel.Raw)) - }) - }) - - Describe("MarkHeaderChecked", func() { - inputs := shared_behaviors.MarkedHeaderCheckedBehaviorInputs{ - CheckedHeaderColumnName: constants.VatGrabChecked, - Repository: &vatGrabRepository, - } - - shared_behaviors.SharedRepositoryMarkHeaderCheckedBehaviors(&inputs) - }) -}) diff --git a/pkg/transformers/vat_init/repository.go b/pkg/transformers/vat_init/repository.go deleted file mode 100644 index 0c8bcb8a..00000000 --- a/pkg/transformers/vat_init/repository.go +++ /dev/null @@ -1,100 +0,0 @@ -// VulcanizeDB -// Copyright © 2018 Vulcanize - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. - -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -package vat_init - -import ( - "fmt" - - log "github.com/sirupsen/logrus" - - "github.com/vulcanize/vulcanizedb/pkg/core" - "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" -) - -type VatInitRepository struct { - db *postgres.DB -} - -func (repository VatInitRepository) Create(headerID int64, models []interface{}) error { - tx, dBaseErr := repository.db.Begin() - if dBaseErr != nil { - return dBaseErr - } - - for _, model := range models { - vatInit, ok := model.(VatInitModel) - if !ok { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - log.Error("failed to rollback ", rollbackErr) - } - return fmt.Errorf("model of type %T, not %T", model, VatInitModel{}) - } - - ilkID, ilkErr := shared.GetOrCreateIlkInTransaction(vatInit.Ilk, tx) - if ilkErr != nil { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - log.Error("failed to rollback ", rollbackErr) - } - return ilkErr - } - - _, execErr := tx.Exec( - `INSERT INTO maker.vat_init (header_id, ilk, log_idx, tx_idx, raw_log) - VALUES($1, $2, $3, $4, $5) - ON CONFLICT (header_id, tx_idx, log_idx) DO UPDATE SET ilk = $2, raw_log = $5;`, - headerID, ilkID, vatInit.LogIndex, vatInit.TransactionIndex, vatInit.Raw, - ) - if execErr != nil { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - log.Error("failed to rollback ", rollbackErr) - } - return execErr - } - } - - checkHeaderErr := shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatInitChecked) - if checkHeaderErr != nil { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - log.Error("failed to rollback ", rollbackErr) - } - return checkHeaderErr - } - - return tx.Commit() -} - -func (repository VatInitRepository) MarkHeaderChecked(headerID int64) error { - return shared.MarkHeaderChecked(headerID, repository.db, constants.VatInitChecked) -} - -func (repository VatInitRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { - return shared.MissingHeaders(startingBlockNumber, endingBlockNumber, repository.db, constants.VatInitChecked) -} - -func (repository VatInitRepository) RecheckHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { - return shared.RecheckHeaders(startingBlockNumber, endingBlockNumber, repository.db, constants.VatInitChecked) -} - -func (repository *VatInitRepository) SetDB(db *postgres.DB) { - repository.db = db -} diff --git a/pkg/transformers/vat_init/repository_test.go b/pkg/transformers/vat_init/repository_test.go deleted file mode 100644 index 36142337..00000000 --- a/pkg/transformers/vat_init/repository_test.go +++ /dev/null @@ -1,89 +0,0 @@ -// VulcanizeDB -// Copyright © 2018 Vulcanize - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. - -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -package vat_init_test - -import ( - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" - "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/shared_behaviors" - "strconv" - - "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" - "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories" - "github.com/vulcanize/vulcanizedb/pkg/fakes" - "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" - "github.com/vulcanize/vulcanizedb/pkg/transformers/vat_init" - "github.com/vulcanize/vulcanizedb/test_config" -) - -var _ = Describe("Vat init repository", func() { - var ( - db *postgres.DB - repository vat_init.VatInitRepository - ) - - BeforeEach(func() { - db = test_config.NewTestDB(test_config.NewTestNode()) - test_config.CleanTestDB(db) - repository = vat_init.VatInitRepository{} - repository.SetDB(db) - }) - - Describe("Create", func() { - modelWithDifferentLogIdx := test_data.VatInitModel - modelWithDifferentLogIdx.LogIndex++ - inputs := shared_behaviors.CreateBehaviorInputs{ - CheckedHeaderColumnName: constants.VatInitChecked, - LogEventTableName: "maker.vat_init", - TestModel: test_data.VatInitModel, - ModelWithDifferentLogIdx: modelWithDifferentLogIdx, - Repository: &repository, - } - - shared_behaviors.SharedRepositoryCreateBehaviors(&inputs) - - It("persists vat init records", func() { - headerRepository := repositories.NewHeaderRepository(db) - headerID, err := headerRepository.CreateOrUpdateHeader(fakes.FakeHeader) - Expect(err).NotTo(HaveOccurred()) - - err = repository.Create(headerID, []interface{}{test_data.VatInitModel}) - - Expect(err).NotTo(HaveOccurred()) - var dbVatInit vat_init.VatInitModel - err = db.Get(&dbVatInit, `SELECT ilk, log_idx, tx_idx, raw_log FROM maker.vat_init WHERE header_id = $1`, headerID) - Expect(err).NotTo(HaveOccurred()) - ilkID, err := shared.GetOrCreateIlk(test_data.VatInitModel.Ilk, db) - Expect(err).NotTo(HaveOccurred()) - Expect(dbVatInit.Ilk).To(Equal(strconv.Itoa(ilkID))) - Expect(dbVatInit.LogIndex).To(Equal(test_data.VatInitModel.LogIndex)) - Expect(dbVatInit.TransactionIndex).To(Equal(test_data.VatInitModel.TransactionIndex)) - Expect(dbVatInit.Raw).To(MatchJSON(test_data.VatInitModel.Raw)) - }) - }) - - Describe("MarkHeaderChecked", func() { - inputs := shared_behaviors.MarkedHeaderCheckedBehaviorInputs{ - CheckedHeaderColumnName: constants.VatInitChecked, - Repository: &repository, - } - - shared_behaviors.SharedRepositoryMarkHeaderCheckedBehaviors(&inputs) - }) -}) diff --git a/pkg/transformers/vat_slip/repository.go b/pkg/transformers/vat_slip/repository.go deleted file mode 100644 index 5ca09c93..00000000 --- a/pkg/transformers/vat_slip/repository.go +++ /dev/null @@ -1,83 +0,0 @@ -package vat_slip - -import ( - "fmt" - - log "github.com/sirupsen/logrus" - - "github.com/vulcanize/vulcanizedb/pkg/core" - "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" -) - -type VatSlipRepository struct { - db *postgres.DB -} - -func (repository VatSlipRepository) Create(headerID int64, models []interface{}) error { - tx, dBaseErr := repository.db.Begin() - if dBaseErr != nil { - return dBaseErr - } - for _, model := range models { - vatSlip, ok := model.(VatSlipModel) - if !ok { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - log.Error("failed to rollback ", rollbackErr) - } - return fmt.Errorf("model of type %T, not %T", model, VatSlipModel{}) - } - - ilkID, ilkErr := shared.GetOrCreateIlkInTransaction(vatSlip.Ilk, tx) - if ilkErr != nil { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - log.Error("failed to rollback ", rollbackErr) - } - return ilkErr - } - - _, execErr := tx.Exec( - `INSERT into maker.vat_slip (header_id, ilk, guy, rad, tx_idx, log_idx, raw_log) - VALUES($1, $2, $3, $4::NUMERIC, $5, $6, $7) - ON CONFLICT (header_id, tx_idx, log_idx) DO UPDATE SET ilk = $2, guy = $3, rad = $4, raw_log = $7;`, - headerID, ilkID, vatSlip.Guy, vatSlip.Rad, vatSlip.TransactionIndex, vatSlip.LogIndex, vatSlip.Raw, - ) - if execErr != nil { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - log.Error("failed to rollback ", rollbackErr) - } - return execErr - } - } - - checkHeaderErr := shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatSlipChecked) - if checkHeaderErr != nil { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - log.Error("failed to rollback ", rollbackErr) - } - return checkHeaderErr - } - - return tx.Commit() -} - -func (repository VatSlipRepository) MarkHeaderChecked(headerID int64) error { - return shared.MarkHeaderChecked(headerID, repository.db, constants.VatSlipChecked) -} - -func (repository VatSlipRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { - return shared.MissingHeaders(startingBlockNumber, endingBlockNumber, repository.db, constants.VatSlipChecked) -} - -func (repository VatSlipRepository) RecheckHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { - return shared.RecheckHeaders(startingBlockNumber, endingBlockNumber, repository.db, constants.VatSlipChecked) -} - -func (repository *VatSlipRepository) SetDB(db *postgres.DB) { - repository.db = db -} diff --git a/pkg/transformers/vat_slip/repository_test.go b/pkg/transformers/vat_slip/repository_test.go deleted file mode 100644 index 1c6d6371..00000000 --- a/pkg/transformers/vat_slip/repository_test.go +++ /dev/null @@ -1,75 +0,0 @@ -package vat_slip_test - -import ( - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" - "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/shared_behaviors" - "strconv" - - "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" - "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories" - "github.com/vulcanize/vulcanizedb/pkg/fakes" - "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" - "github.com/vulcanize/vulcanizedb/pkg/transformers/vat_slip" - "github.com/vulcanize/vulcanizedb/test_config" -) - -var _ = Describe("Vat slip repository", func() { - var ( - db *postgres.DB - repository vat_slip.VatSlipRepository - ) - - BeforeEach(func() { - db = test_config.NewTestDB(test_config.NewTestNode()) - test_config.CleanTestDB(db) - repository = vat_slip.VatSlipRepository{} - repository.SetDB(db) - }) - - Describe("Create", func() { - modelWithDifferentLogIdx := test_data.VatSlipModel - modelWithDifferentLogIdx.LogIndex++ - inputs := shared_behaviors.CreateBehaviorInputs{ - CheckedHeaderColumnName: constants.VatSlipChecked, - LogEventTableName: "maker.vat_slip", - TestModel: test_data.VatSlipModel, - ModelWithDifferentLogIdx: modelWithDifferentLogIdx, - Repository: &repository, - } - - shared_behaviors.SharedRepositoryCreateBehaviors(&inputs) - - It("adds a vat slip event", func() { - headerRepository := repositories.NewHeaderRepository(db) - headerID, err := headerRepository.CreateOrUpdateHeader(fakes.FakeHeader) - Expect(err).NotTo(HaveOccurred()) - - err = repository.Create(headerID, []interface{}{test_data.VatSlipModel}) - Expect(err).NotTo(HaveOccurred()) - - var dbVatSlip vat_slip.VatSlipModel - err = db.Get(&dbVatSlip, `SELECT ilk, guy, rad, tx_idx, log_idx, raw_log FROM maker.vat_slip WHERE header_id = $1`, headerID) - Expect(err).NotTo(HaveOccurred()) - ilkID, err := shared.GetOrCreateIlk(test_data.VatSlipModel.Ilk, db) - Expect(err).NotTo(HaveOccurred()) - Expect(dbVatSlip.Ilk).To(Equal(strconv.Itoa(ilkID))) - Expect(dbVatSlip.Guy).To(Equal(test_data.VatSlipModel.Guy)) - Expect(dbVatSlip.Rad).To(Equal(test_data.VatSlipModel.Rad)) - Expect(dbVatSlip.TransactionIndex).To(Equal(test_data.VatSlipModel.TransactionIndex)) - Expect(dbVatSlip.LogIndex).To(Equal(test_data.VatSlipModel.LogIndex)) - Expect(dbVatSlip.Raw).To(MatchJSON(test_data.VatSlipModel.Raw)) - }) - }) - - Describe("MarkHeaderChecked", func() { - inputs := shared_behaviors.MarkedHeaderCheckedBehaviorInputs{ - CheckedHeaderColumnName: constants.VatSlipChecked, - Repository: &repository, - } - - shared_behaviors.SharedRepositoryMarkHeaderCheckedBehaviors(&inputs) - }) -}) diff --git a/pkg/transformers/vat_toll/repository.go b/pkg/transformers/vat_toll/repository.go deleted file mode 100644 index 425e3301..00000000 --- a/pkg/transformers/vat_toll/repository.go +++ /dev/null @@ -1,81 +0,0 @@ -package vat_toll - -import ( - "fmt" - - log "github.com/sirupsen/logrus" - - "github.com/vulcanize/vulcanizedb/pkg/core" - "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" -) - -type VatTollRepository struct { - db *postgres.DB -} - -func (repository VatTollRepository) Create(headerID int64, models []interface{}) error { - tx, dBaseErr := repository.db.Begin() - if dBaseErr != nil { - return dBaseErr - } - for _, model := range models { - vatToll, ok := model.(VatTollModel) - if !ok { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - log.Error("failed to rollback ", rollbackErr) - } - return fmt.Errorf("model of type %T, not %T", model, VatTollModel{}) - } - - ilkID, ilkErr := shared.GetOrCreateIlkInTransaction(vatToll.Ilk, tx) - if ilkErr != nil { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - log.Error("failed to rollback ", rollbackErr) - } - return ilkErr - } - - _, execErr := tx.Exec( - `INSERT into maker.vat_toll (header_id, ilk, urn, take, tx_idx, log_idx, raw_log) - VALUES($1, $2, $3, $4::NUMERIC, $5, $6, $7)`, - headerID, ilkID, vatToll.Urn, vatToll.Take, vatToll.TransactionIndex, vatToll.LogIndex, vatToll.Raw, - ) - if execErr != nil { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - log.Error("failed to rollback ", rollbackErr) - } - return execErr - } - } - - checkHeaderErr := shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatTollChecked) - if checkHeaderErr != nil { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - log.Error("failed to rollback ", rollbackErr) - } - return checkHeaderErr - } - return tx.Commit() -} - -func (repository VatTollRepository) MarkHeaderChecked(headerID int64) error { - return shared.MarkHeaderChecked(headerID, repository.db, constants.VatTollChecked) -} - -func (repository VatTollRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { - return shared.MissingHeaders(startingBlockNumber, endingBlockNumber, repository.db, constants.VatTollChecked) -} - -func (repository VatTollRepository) RecheckHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { - return shared.RecheckHeaders(startingBlockNumber, endingBlockNumber, repository.db, constants.VatTollChecked) -} - -func (repository *VatTollRepository) SetDB(db *postgres.DB) { - repository.db = db -} diff --git a/pkg/transformers/vat_toll/repository_test.go b/pkg/transformers/vat_toll/repository_test.go deleted file mode 100644 index fd8b228d..00000000 --- a/pkg/transformers/vat_toll/repository_test.go +++ /dev/null @@ -1,75 +0,0 @@ -package vat_toll_test - -import ( - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" - "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/shared_behaviors" - "strconv" - - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - - "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" - "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories" - "github.com/vulcanize/vulcanizedb/pkg/fakes" - "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" - "github.com/vulcanize/vulcanizedb/pkg/transformers/vat_toll" - "github.com/vulcanize/vulcanizedb/test_config" -) - -var _ = Describe("Vat toll repository", func() { - var ( - db *postgres.DB - repository vat_toll.VatTollRepository - ) - - BeforeEach(func() { - db = test_config.NewTestDB(test_config.NewTestNode()) - test_config.CleanTestDB(db) - repository = vat_toll.VatTollRepository{} - repository.SetDB(db) - }) - - Describe("Create", func() { - modelWithDifferentLogIdx := test_data.VatTollModel - modelWithDifferentLogIdx.LogIndex++ - inputs := shared_behaviors.CreateBehaviorInputs{ - CheckedHeaderColumnName: constants.VatTollChecked, - LogEventTableName: "maker.vat_toll", - TestModel: test_data.VatTollModel, - ModelWithDifferentLogIdx: modelWithDifferentLogIdx, - Repository: &repository, - } - - shared_behaviors.SharedRepositoryCreateBehaviors(&inputs) - - It("adds a vat toll event", func() { - headerRepository := repositories.NewHeaderRepository(db) - headerID, err := headerRepository.CreateOrUpdateHeader(fakes.FakeHeader) - Expect(err).NotTo(HaveOccurred()) - err = repository.Create(headerID, []interface{}{test_data.VatTollModel}) - Expect(err).NotTo(HaveOccurred()) - - var dbVatToll vat_toll.VatTollModel - err = db.Get(&dbVatToll, `SELECT ilk, urn, take, tx_idx, log_idx, raw_log FROM maker.vat_toll WHERE header_id = $1`, headerID) - Expect(err).NotTo(HaveOccurred()) - ilkID, err := shared.GetOrCreateIlk(test_data.VatTollModel.Ilk, db) - Expect(err).NotTo(HaveOccurred()) - Expect(dbVatToll.Ilk).To(Equal(strconv.Itoa(ilkID))) - Expect(dbVatToll.Urn).To(Equal(test_data.VatTollModel.Urn)) - Expect(dbVatToll.Take).To(Equal(test_data.VatTollModel.Take)) - Expect(dbVatToll.TransactionIndex).To(Equal(test_data.VatTollModel.TransactionIndex)) - Expect(dbVatToll.LogIndex).To(Equal(test_data.VatTollModel.LogIndex)) - Expect(dbVatToll.Raw).To(MatchJSON(test_data.VatTollModel.Raw)) - }) - }) - - Describe("MarkHeaderChecked", func() { - inputs := shared_behaviors.MarkedHeaderCheckedBehaviorInputs{ - CheckedHeaderColumnName: constants.VatTollChecked, - Repository: &repository, - } - - shared_behaviors.SharedRepositoryMarkHeaderCheckedBehaviors(&inputs) - }) -}) diff --git a/pkg/transformers/vat_tune/repository.go b/pkg/transformers/vat_tune/repository.go deleted file mode 100644 index e7ea9228..00000000 --- a/pkg/transformers/vat_tune/repository.go +++ /dev/null @@ -1,82 +0,0 @@ -package vat_tune - -import ( - "fmt" - - log "github.com/sirupsen/logrus" - - "github.com/vulcanize/vulcanizedb/pkg/core" - "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" -) - -type VatTuneRepository struct { - db *postgres.DB -} - -func (repository VatTuneRepository) Create(headerID int64, models []interface{}) error { - tx, dBaseErr := repository.db.Begin() - if dBaseErr != nil { - return dBaseErr - } - for _, model := range models { - vatTune, ok := model.(VatTuneModel) - if !ok { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - log.Error("failed to rollback ", rollbackErr) - } - return fmt.Errorf("model of type %T, not %T", model, VatTuneModel{}) - } - - ilkID, ilkErr := shared.GetOrCreateIlkInTransaction(vatTune.Ilk, tx) - if ilkErr != nil { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - log.Error("failed to rollback ", rollbackErr) - } - return ilkErr - } - - _, execErr := tx.Exec( - `INSERT into maker.vat_tune (header_id, ilk, urn, v, w, dink, dart, tx_idx, log_idx, raw_log) - VALUES($1, $2, $3, $4, $5, $6::NUMERIC, $7::NUMERIC, $8, $9, $10) - ON CONFLICT (header_id, tx_idx, log_idx) DO UPDATE SET ilk = $2, urn = $3, v = $4, w = $5, dink = $6, dart = $7, raw_log = $10;`, - headerID, ilkID, vatTune.Urn, vatTune.V, vatTune.W, vatTune.Dink, vatTune.Dart, vatTune.TransactionIndex, vatTune.LogIndex, vatTune.Raw, - ) - if execErr != nil { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - log.Error("failed to rollback ", rollbackErr) - } - return execErr - } - } - - checkHeaderErr := shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatTuneChecked) - if checkHeaderErr != nil { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - log.Error("failed to rollback ", rollbackErr) - } - return checkHeaderErr - } - return tx.Commit() -} - -func (repository VatTuneRepository) MarkHeaderChecked(headerID int64) error { - return shared.MarkHeaderChecked(headerID, repository.db, constants.VatTuneChecked) -} - -func (repository VatTuneRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { - return shared.MissingHeaders(startingBlockNumber, endingBlockNumber, repository.db, constants.VatTuneChecked) -} - -func (repository VatTuneRepository) RecheckHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { - return shared.RecheckHeaders(startingBlockNumber, endingBlockNumber, repository.db, constants.VatTuneChecked) -} - -func (repository *VatTuneRepository) SetDB(db *postgres.DB) { - repository.db = db -} diff --git a/pkg/transformers/vat_tune/repository_test.go b/pkg/transformers/vat_tune/repository_test.go deleted file mode 100644 index fe047c03..00000000 --- a/pkg/transformers/vat_tune/repository_test.go +++ /dev/null @@ -1,78 +0,0 @@ -package vat_tune_test - -import ( - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" - "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/shared_behaviors" - "strconv" - - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - - "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" - "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories" - "github.com/vulcanize/vulcanizedb/pkg/fakes" - "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" - "github.com/vulcanize/vulcanizedb/pkg/transformers/vat_tune" - "github.com/vulcanize/vulcanizedb/test_config" -) - -var _ = Describe("Vat tune repository", func() { - var ( - db *postgres.DB - repository vat_tune.VatTuneRepository - ) - - BeforeEach(func() { - db = test_config.NewTestDB(test_config.NewTestNode()) - test_config.CleanTestDB(db) - repository = vat_tune.VatTuneRepository{} - repository.SetDB(db) - }) - - Describe("Create", func() { - modelWithDifferentLogIdx := test_data.VatTuneModel - modelWithDifferentLogIdx.LogIndex++ - inputs := shared_behaviors.CreateBehaviorInputs{ - CheckedHeaderColumnName: constants.VatTuneChecked, - LogEventTableName: "maker.vat_heal", - TestModel: test_data.VatTuneModel, - ModelWithDifferentLogIdx: modelWithDifferentLogIdx, - Repository: &repository, - } - shared_behaviors.SharedRepositoryCreateBehaviors(&inputs) - - It("adds a vat tune event", func() { - headerRepository := repositories.NewHeaderRepository(db) - headerID, err := headerRepository.CreateOrUpdateHeader(fakes.FakeHeader) - Expect(err).NotTo(HaveOccurred()) - - err = repository.Create(headerID, []interface{}{test_data.VatTuneModel}) - Expect(err).NotTo(HaveOccurred()) - - var dbVatTune vat_tune.VatTuneModel - err = db.Get(&dbVatTune, `SELECT ilk, urn, v, w, dink, dart, tx_idx, log_idx, raw_log FROM maker.vat_tune WHERE header_id = $1`, headerID) - Expect(err).NotTo(HaveOccurred()) - ilkID, err := shared.GetOrCreateIlk(test_data.VatTuneModel.Ilk, db) - Expect(err).NotTo(HaveOccurred()) - Expect(dbVatTune.Ilk).To(Equal(strconv.Itoa(ilkID))) - Expect(dbVatTune.Urn).To(Equal(test_data.VatTuneModel.Urn)) - Expect(dbVatTune.V).To(Equal(test_data.VatTuneModel.V)) - Expect(dbVatTune.W).To(Equal(test_data.VatTuneModel.W)) - Expect(dbVatTune.Dink).To(Equal(test_data.VatTuneModel.Dink)) - Expect(dbVatTune.Dart).To(Equal(test_data.VatTuneModel.Dart)) - Expect(dbVatTune.TransactionIndex).To(Equal(test_data.VatTuneModel.TransactionIndex)) - Expect(dbVatTune.LogIndex).To(Equal(test_data.VatTuneModel.LogIndex)) - Expect(dbVatTune.Raw).To(MatchJSON(test_data.VatTuneModel.Raw)) - }) - }) - - Describe("MarkHeaderChecked", func() { - inputs := shared_behaviors.MarkedHeaderCheckedBehaviorInputs{ - CheckedHeaderColumnName: constants.VatTuneChecked, - Repository: &repository, - } - - shared_behaviors.SharedRepositoryMarkHeaderCheckedBehaviors(&inputs) - }) -}) diff --git a/test_config/test_config.go b/test_config/test_config.go index f3961456..b6a323d4 100644 --- a/test_config/test_config.go +++ b/test_config/test_config.go @@ -102,19 +102,12 @@ func CleanTestDB(db *postgres.DB) { db.MustExec("DELETE FROM receipts") db.MustExec("DELETE FROM transactions") db.MustExec("DELETE FROM watched_contracts") - db.MustExec("DELETE FROM maker.cat_nflip") - db.MustExec("DELETE FROM maker.cat_live") - db.MustExec("DELETE FROM maker.cat_vat") - db.MustExec("DELETE FROM maker.cat_pit") - db.MustExec("DELETE FROM maker.cat_vow") - db.MustExec("DELETE FROM maker.cat_ilk_flip") - db.MustExec("DELETE FROM maker.cat_ilk_chop") - db.MustExec("DELETE FROM maker.cat_ilk_lump") - db.MustExec("DELETE FROM maker.cat_flip_ilk") - db.MustExec("DELETE FROM maker.cat_flip_ink") - db.MustExec("DELETE FROM maker.cat_flip_tab") - // TODO: add ON DELETE CASCADE? otherwise this needs to come after deleting tables that reference it - db.MustExec("DELETE FROM maker.ilks") +} + +func CleanCheckedHeadersTable(db *postgres.DB, columnNames []string) { + for _, name := range columnNames { + db.MustExec("ALTER TABLE checked_headers DROP COLUMN IF EXISTS " + name) + } } // Returns a new test node, with the same ID