forked from cerc-io/ipld-eth-server
Add log index to Vat heal
This commit is contained in:
parent
650bbf5874
commit
702f90367a
@ -1,12 +1,13 @@
|
||||
CREATE TABLE maker.vat_heal (
|
||||
id SERIAL PRIMARY KEY,
|
||||
header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE,
|
||||
urn varchar,
|
||||
v varchar,
|
||||
rad int,
|
||||
urn TEXT,
|
||||
v TEXT,
|
||||
rad NUMERIC,
|
||||
log_idx INTEGER NOT NULL,
|
||||
tx_idx INTEGER NOT NULL,
|
||||
raw_log JSONB,
|
||||
UNIQUE (header_id, tx_idx)
|
||||
UNIQUE (header_id, tx_idx, log_idx)
|
||||
);
|
||||
|
||||
ALTER TABLE public.checked_headers
|
||||
|
@ -1 +0,0 @@
|
||||
ALTER TABLE maker.vat_heal ALTER COLUMN rad SET DATA TYPE int;
|
@ -1 +0,0 @@
|
||||
ALTER TABLE maker.vat_heal ALTER COLUMN rad SET DATA TYPE numeric;
|
@ -831,9 +831,10 @@ ALTER SEQUENCE maker.vat_grab_id_seq OWNED BY maker.vat_grab.id;
|
||||
CREATE TABLE maker.vat_heal (
|
||||
id integer NOT NULL,
|
||||
header_id integer NOT NULL,
|
||||
urn character varying,
|
||||
v character varying,
|
||||
urn text,
|
||||
v text,
|
||||
rad numeric,
|
||||
log_idx integer NOT NULL,
|
||||
tx_idx integer NOT NULL,
|
||||
raw_log jsonb
|
||||
);
|
||||
@ -2061,11 +2062,11 @@ ALTER TABLE ONLY maker.vat_grab
|
||||
|
||||
|
||||
--
|
||||
-- Name: vat_heal vat_heal_header_id_tx_idx_key; Type: CONSTRAINT; Schema: maker; Owner: -
|
||||
-- Name: vat_heal vat_heal_header_id_tx_idx_log_idx_key; Type: CONSTRAINT; Schema: maker; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY maker.vat_heal
|
||||
ADD CONSTRAINT vat_heal_header_id_tx_idx_key UNIQUE (header_id, tx_idx);
|
||||
ADD CONSTRAINT vat_heal_header_id_tx_idx_log_idx_key UNIQUE (header_id, tx_idx, log_idx);
|
||||
|
||||
|
||||
--
|
||||
|
@ -35,7 +35,7 @@ var VatHealLog = types.Log{
|
||||
TxHash: common.HexToHash("0x991b8079b1333024000dcaf2b00c24c5db0315e112a4ac4d912aa96a602e12b9"),
|
||||
TxIndex: 2,
|
||||
BlockHash: common.HexToHash("0x0c54bdadb149691a103cfa5ad57329bda1e0fe55f1ba1ce5dd49dc1ecfe03daa"),
|
||||
Index: 0,
|
||||
Index: 3,
|
||||
Removed: false,
|
||||
}
|
||||
|
||||
@ -44,6 +44,7 @@ var VatHealModel = vat_heal.VatHealModel{
|
||||
Urn: "0x7d7bEe5fCfD8028cf7b00876C5b1421c800561A6",
|
||||
V: "0x7340e006f4135BA6970D43bf43d88DCAD4e7a8CA",
|
||||
Rad: "120",
|
||||
TransactionIndex: 2,
|
||||
LogIndex: VatHealLog.Index,
|
||||
TransactionIndex: VatHealLog.TxIndex,
|
||||
Raw: rawHealLog,
|
||||
}
|
||||
|
@ -52,6 +52,7 @@ func (VatHealConverter) ToModels(ethLogs []types.Log) ([]VatHealModel, error) {
|
||||
Urn: urn.String(),
|
||||
V: v.String(),
|
||||
Rad: radInt.String(),
|
||||
LogIndex: ethLog.Index,
|
||||
TransactionIndex: ethLog.TxIndex,
|
||||
Raw: rawLogJson,
|
||||
}
|
||||
|
@ -30,11 +30,8 @@ var _ = Describe("VatHeal converter", func() {
|
||||
models, err := converter.ToModels([]types.Log{test_data.VatHealLog})
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(models[0].Urn).To(Equal(test_data.VatHealModel.Urn))
|
||||
Expect(models[0].V).To(Equal(test_data.VatHealModel.V))
|
||||
Expect(models[0].Rad).To(Equal(test_data.VatHealModel.Rad))
|
||||
Expect(models[0].TransactionIndex).To(Equal(test_data.VatHealModel.TransactionIndex))
|
||||
Expect(models[0].Raw).To(Equal(test_data.VatHealModel.Raw))
|
||||
Expect(len(models)).To(Equal(1))
|
||||
Expect(models[0]).To(Equal(test_data.VatHealModel))
|
||||
})
|
||||
|
||||
It("Returns an error there are missing topics", func() {
|
||||
|
@ -18,6 +18,7 @@ type VatHealModel struct {
|
||||
Urn string
|
||||
V string
|
||||
Rad string
|
||||
LogIndex uint `db:"log_idx"`
|
||||
TransactionIndex uint `db:"tx_idx"`
|
||||
Raw []byte `db:"raw_log"`
|
||||
}
|
||||
|
@ -40,9 +40,9 @@ func (repository VatHealRepository) Create(headerId int64, models []VatHealModel
|
||||
}
|
||||
|
||||
for _, model := range models {
|
||||
_, err := tx.Exec(`INSERT INTO maker.vat_heal (header_id, urn, v, rad, tx_idx, raw_log)
|
||||
VALUES($1, $2, $3, $4::NUMERIC, $5, $6)`,
|
||||
headerId, model.Urn, model.V, model.Rad, model.TransactionIndex, model.Raw)
|
||||
_, err := tx.Exec(`INSERT INTO maker.vat_heal (header_id, urn, v, rad, log_idx, tx_idx, raw_log)
|
||||
VALUES($1, $2, $3, $4::NUMERIC, $5, $6, $7)`,
|
||||
headerId, model.Urn, model.V, model.Rad, model.LogIndex, model.TransactionIndex, model.Raw)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
|
@ -62,7 +62,7 @@ var _ = Describe("VatHeal Repository", func() {
|
||||
|
||||
It("persists vat heal records", func() {
|
||||
anotherVatHeal := test_data.VatHealModel
|
||||
anotherVatHeal.TransactionIndex = test_data.VatHealModel.TransactionIndex + 1
|
||||
anotherVatHeal.LogIndex = test_data.VatHealModel.LogIndex + 1
|
||||
err = repository.Create(headerId, []vat_heal.VatHealModel{test_data.VatHealModel, anotherVatHeal})
|
||||
|
||||
var dbResult []VatHealDBResult
|
||||
@ -72,8 +72,9 @@ var _ = Describe("VatHeal Repository", func() {
|
||||
Expect(dbResult[0].Urn).To(Equal(test_data.VatHealModel.Urn))
|
||||
Expect(dbResult[0].V).To(Equal(test_data.VatHealModel.V))
|
||||
Expect(dbResult[0].Rad).To(Equal(test_data.VatHealModel.Rad))
|
||||
Expect(dbResult[0].LogIndex).To(Equal(test_data.VatHealModel.LogIndex))
|
||||
Expect(dbResult[1].LogIndex).To(Equal(test_data.VatHealModel.LogIndex + 1))
|
||||
Expect(dbResult[0].TransactionIndex).To(Equal(test_data.VatHealModel.TransactionIndex))
|
||||
Expect(dbResult[1].TransactionIndex).To(Equal(test_data.VatHealModel.TransactionIndex + 1))
|
||||
Expect(dbResult[0].Raw).To(MatchJSON(test_data.VatHealModel.Raw))
|
||||
Expect(dbResult[0].HeaderId).To(Equal(headerId))
|
||||
})
|
||||
@ -81,7 +82,9 @@ var _ = Describe("VatHeal Repository", func() {
|
||||
It("returns an error if the insertion fails", func() {
|
||||
err = repository.Create(headerId, []vat_heal.VatHealModel{test_data.VatHealModel})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
err = repository.Create(headerId, []vat_heal.VatHealModel{test_data.VatHealModel})
|
||||
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(err.Error()).To(ContainSubstring("pq: duplicate key value violates unique constraint"))
|
||||
})
|
||||
@ -96,6 +99,19 @@ var _ = Describe("VatHeal Repository", func() {
|
||||
Expect(headerChecked).To(BeTrue())
|
||||
})
|
||||
|
||||
It("updates the header to checked if checked headers row already exists", func() {
|
||||
_, err = db.Exec(`INSERT INTO public.checked_headers (header_id) VALUES ($1)`, headerId)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
err = repository.Create(headerId, []vat_heal.VatHealModel{test_data.VatHealModel})
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
var headerChecked bool
|
||||
err = db.Get(&headerChecked, `SELECT vat_heal_checked FROM public.checked_headers WHERE header_id = $1`, headerId)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(headerChecked).To(BeTrue())
|
||||
})
|
||||
|
||||
It("removes vat heal if corresponding header is deleted", func() {
|
||||
err = repository.Create(headerId, []vat_heal.VatHealModel{test_data.VatHealModel})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
Loading…
Reference in New Issue
Block a user