rebase; extract factories and the mocks they are dependent on to

libraries/shared; adjust omni test_helpers to drop and recreate
checked_headers table to avoid reaching 1600 column limit after repeated
tests (dropping columns doesn't actually remove them from contributing
to that limit)
This commit is contained in:
Ian Norden 2019-02-24 22:26:42 -06:00
parent 17f4d3dfa5
commit 708425c4d6
126 changed files with 1407 additions and 8454 deletions

View File

@ -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:

View File

@ -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

View File

@ -1,6 +0,0 @@
-- +goose Up
CREATE SCHEMA maker;
-- +goose Down
DROP SCHEMA maker;

View File

@ -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;

View File

@ -1,8 +0,0 @@
-- +goose Up
CREATE TABLE maker.ilks (
id SERIAL PRIMARY KEY,
ilk TEXT UNIQUE
);
-- +goose Down
DROP TABLE maker.ilks;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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: -
--

View File

@ -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

View File

@ -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 <http://www.gnu.org/licenses/>.
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)
})

View File

@ -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 <http://www.gnu.org/licenses/>.
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)
}

View File

@ -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 <http://www.gnu.org/licenses/>.
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)
})

View File

@ -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 <http://www.gnu.org/licenses/>.
package factories
import "github.com/ethereum/go-ethereum/core/types"
type LogNoteConverter interface {
ToModels(ethLog []types.Log) ([]interface{}, error)
}

View File

@ -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 <http://www.gnu.org/licenses/>.
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
}

View File

@ -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 <http://www.gnu.org/licenses/>.
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))
})
})

View File

@ -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 <http://www.gnu.org/licenses/>.
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)
}

View File

@ -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 <http://www.gnu.org/licenses/>.
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")
}

View File

@ -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 <http://www.gnu.org/licenses/>.
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)
}

View File

@ -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 <http://www.gnu.org/licenses/>.
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))
})
})

View File

@ -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 <http://www.gnu.org/licenses/>.
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
}

View File

@ -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 <http://www.gnu.org/licenses/>.
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))
})
})

View File

@ -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 <http://www.gnu.org/licenses/>.
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)
})

View File

@ -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 <http://www.gnu.org/licenses/>.
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
}

View File

@ -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 <http://www.gnu.org/licenses/>.
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
}

View File

@ -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 <http://www.gnu.org/licenses/>.
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")
}

View File

@ -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 <http://www.gnu.org/licenses/>.
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))
}

View File

@ -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 <http://www.gnu.org/licenses/>.
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
}

View File

@ -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 <http://www.gnu.org/licenses/>.
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")
}

View File

@ -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)

View File

@ -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 <http://www.gnu.org/licenses/>.
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)
})

View File

@ -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())
})
})

View File

@ -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 <http://www.gnu.org/licenses/>.
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
}

View File

@ -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))

View File

@ -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 <http://www.gnu.org/licenses/>.
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)
})

View File

@ -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() {

View File

@ -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

View File

@ -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
}

View File

@ -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 <http://www.gnu.org/licenses/>.
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)
}

View File

@ -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,

View File

@ -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`)

View File

@ -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()
}

View File

@ -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 <http://www.gnu.org/licenses/>.
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)
}

View File

@ -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 <http://www.gnu.org/licenses/>.
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)
})
})

View File

@ -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 <http://www.gnu.org/licenses/>.
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
}

View File

@ -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 <http://www.gnu.org/licenses/>.
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)
})
})

View File

@ -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 <http://www.gnu.org/licenses/>.
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
}

View File

@ -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 <http://www.gnu.org/licenses/>.
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)
})
})

View File

@ -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 <http://www.gnu.org/licenses/>.
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
}

View File

@ -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 <http://www.gnu.org/licenses/>.
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)
})
})

View File

@ -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 <http://www.gnu.org/licenses/>.
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
}

View File

@ -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 <http://www.gnu.org/licenses/>.
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)
})
})

View File

@ -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 <http://www.gnu.org/licenses/>.
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))
})
})

View File

@ -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 <http://www.gnu.org/licenses/>.
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] }

View File

@ -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 <http://www.gnu.org/licenses/>.
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())
})
})

View File

@ -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 <http://www.gnu.org/licenses/>.
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))
})
})

View File

@ -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 <http://www.gnu.org/licenses/>.
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"))
})
})

View File

@ -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 <http://www.gnu.org/licenses/>.
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)))
})
})

View File

@ -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 <http://www.gnu.org/licenses/>.
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"))
})
})

View File

@ -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 <http://www.gnu.org/licenses/>.
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)))
})
})

View File

@ -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 <http://www.gnu.org/licenses/>.
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)))
})
})

View File

@ -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))
})
})

View File

@ -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 <http://www.gnu.org/licenses/>.
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)))
})
})

View File

@ -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 <http://www.gnu.org/licenses/>.
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
}

View File

@ -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 <http://www.gnu.org/licenses/>.
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
}

View File

@ -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 <http://www.gnu.org/licenses/>.
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)
})
})

View File

@ -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)
})

View File

@ -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)
}

View File

@ -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))
})
})
})
})

View File

@ -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
}

View File

@ -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}))
})
})
})
})

View File

@ -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 <http://www.gnu.org/licenses/>.
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
}

Some files were not shown because too many files have changed in this diff Show More