update tests and import order per PR feedback

This commit is contained in:
Taka Goto 2018-08-30 15:06:14 -05:00
parent 4ca7c10f92
commit adc7c47244
5 changed files with 33 additions and 7 deletions

View File

@ -9,5 +9,6 @@ CREATE TABLE maker.bite (
tab NUMERIC,
flip VARCHAR,
tx_idx INTEGER NOT NUll,
raw_log JSONB
raw_log JSONB,
UNIQUE (header_id, tx_idx)
)

View File

@ -701,6 +701,14 @@ ALTER TABLE ONLY public.transactions ALTER COLUMN id SET DEFAULT nextval('public
ALTER TABLE ONLY public.watched_contracts ALTER COLUMN contract_id SET DEFAULT nextval('public.watched_contracts_contract_id_seq'::regclass);
--
-- Name: bite bite_header_id_tx_idx_key; Type: CONSTRAINT; Schema: maker; Owner: -
--
ALTER TABLE ONLY maker.bite
ADD CONSTRAINT bite_header_id_tx_idx_key UNIQUE (header_id, tx_idx);
--
-- Name: bite bite_pkey; Type: CONSTRAINT; Schema: maker; Owner: -
--

View File

@ -48,6 +48,7 @@ func (BiteConverter) ToEntity(contractAddress string, contractAbi string, ethLog
}
entity.Raw = ethLog
entity.TransactionIndex = ethLog.TxIndex
return entity, nil
}

View File

@ -17,14 +17,15 @@
package bite_test
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"math/big"
"encoding/json"
"github.com/ethereum/go-ethereum/core/types"
"github.com/vulcanize/vulcanizedb/pkg/transformers/bite"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
"math/big"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Bite Converter", func() {
@ -42,6 +43,8 @@ var _ = Describe("Bite Converter", func() {
Expect(entity.Tab).To(Equal(test_data.BiteEntity.Tab))
Expect(entity.Flip).To(Equal(test_data.BiteEntity.Flip))
Expect(entity.IArt).To(Equal(test_data.BiteEntity.IArt))
Expect(entity.TransactionIndex).To(Equal(test_data.BiteEntity.TransactionIndex))
Expect(entity.Raw).To(Equal(test_data.BiteEntity.Raw))
})
It("returns an error if converting log to entity fails", func() {
@ -63,10 +66,10 @@ var _ = Describe("Bite Converter", func() {
Expect(err).NotTo(HaveOccurred())
Expect(model).To(Equal(test_data.BiteModel))
Expect(model.TransactionIndex).To(Equal(test_data.BiteModel.TransactionIndex))
})
It("handles nil values", func() {
emptyEntity.Id = big.NewInt(1)
emptyLog, err := json.Marshal(types.Log{})
Expect(err).NotTo(HaveOccurred())
expectedModel := bite.BiteModel{

View File

@ -64,7 +64,20 @@ var _ = Describe("Bite repository", func() {
err = biteRepository.Create(headerID, test_data.BiteModel)
Expect(err).NotTo(HaveOccurred())
err = biteRepository.Create(headerID, test_data.BiteModel)
var anotherBiteModel = bite.BiteModel{
Id: "11",
Ilk: test_data.BiteModel.Ilk,
Lad: test_data.BiteModel.Lad,
Ink: test_data.BiteModel.Ink,
Art: test_data.BiteModel.Art,
Tab: test_data.BiteModel.Tab,
Flip: test_data.BiteModel.Flip,
IArt: test_data.BiteModel.IArt,
TransactionIndex: test_data.BiteModel.TransactionIndex,
Raw: test_data.BiteModel.Raw,
}
err = biteRepository.Create(headerID, anotherBiteModel)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("pq: duplicate key value violates unique constraint"))