From 4a98b7942f1ccca50d474a6c99ba2e0d9fcb7fc8 Mon Sep 17 00:00:00 2001 From: Rob Mulholand Date: Fri, 18 Oct 2019 12:34:22 -0500 Subject: [PATCH] Don't return unexported types --- .../shared/helpers/test_helpers/database.go | 8 +++--- .../helpers/test_helpers/mocks/parser.go | 25 +++++++++++-------- .../shared/parser/parser_test.go | 2 +- pkg/plugin/builder/builder.go | 2 +- pkg/plugin/generator.go | 2 +- pkg/plugin/manager/manager.go | 2 +- pkg/plugin/writer/writer.go | 2 +- 7 files changed, 23 insertions(+), 20 deletions(-) diff --git a/pkg/contract_watcher/shared/helpers/test_helpers/database.go b/pkg/contract_watcher/shared/helpers/test_helpers/database.go index d631bc72..66426f46 100644 --- a/pkg/contract_watcher/shared/helpers/test_helpers/database.go +++ b/pkg/contract_watcher/shared/helpers/test_helpers/database.go @@ -159,7 +159,7 @@ func SetupTusdRepo(vulcanizeLogID *int64, wantedEvents, wantedMethods []string) func SetupTusdContract(wantedEvents, wantedMethods []string) *contract.Contract { p := mocks.NewParser(constants.TusdAbiString) - err := p.Parse() + err := p.Parse(constants.TusdContractAddress) Expect(err).ToNot(HaveOccurred()) return contract.Contract{ @@ -205,7 +205,7 @@ func SetupENSRepo(vulcanizeLogID *int64, wantedEvents, wantedMethods []string) ( func SetupENSContract(wantedEvents, wantedMethods []string) *contract.Contract { p := mocks.NewParser(constants.ENSAbiString) - err := p.Parse() + err := p.Parse(constants.EnsContractAddress) Expect(err).ToNot(HaveOccurred()) return contract.Contract{ @@ -223,7 +223,7 @@ func SetupENSContract(wantedEvents, wantedMethods []string) *contract.Contract { func SetupMarketPlaceContract(wantedEvents, wantedMethods []string) *contract.Contract { p := mocks.NewParser(constants.MarketPlaceAbiString) - err := p.Parse() + err := p.Parse(constants.MarketPlaceContractAddress) Expect(err).NotTo(HaveOccurred()) return contract.Contract{ @@ -241,7 +241,7 @@ func SetupMarketPlaceContract(wantedEvents, wantedMethods []string) *contract.Co func SetupMolochContract(wantedEvents, wantedMethods []string) *contract.Contract { p := mocks.NewParser(constants.MolochAbiString) - err := p.Parse() + err := p.Parse(constants.MolochContractAddress) Expect(err).NotTo(HaveOccurred()) return contract.Contract{ diff --git a/pkg/contract_watcher/shared/helpers/test_helpers/mocks/parser.go b/pkg/contract_watcher/shared/helpers/test_helpers/mocks/parser.go index f8784a04..96bc14f6 100644 --- a/pkg/contract_watcher/shared/helpers/test_helpers/mocks/parser.go +++ b/pkg/contract_watcher/shared/helpers/test_helpers/mocks/parser.go @@ -18,7 +18,7 @@ package mocks import ( "github.com/ethereum/go-ethereum/accounts/abi" - + "github.com/vulcanize/vulcanizedb/pkg/contract_watcher/shared/parser" "github.com/vulcanize/vulcanizedb/pkg/contract_watcher/shared/types" "github.com/vulcanize/vulcanizedb/pkg/eth" ) @@ -26,29 +26,32 @@ import ( // Mock parser // Is given ABI string instead of address // Performs all other functions of the real parser -type parser struct { +type mockParser struct { abi string parsedAbi abi.ABI } -func NewParser(abi string) *parser { - - return &parser{ +func NewParser(abi string) parser.Parser { + return &mockParser{ abi: abi, } } -func (p *parser) Abi() string { +func (p *mockParser) Abi() string { return p.abi } -func (p *parser) ParsedAbi() abi.ABI { +func (p *mockParser) ParsedAbi() abi.ABI { return p.parsedAbi } +func (p *mockParser) ParseAbiStr(abiStr string) error { + panic("implement me") +} + // Retrieves and parses the abi string // for the given contract address -func (p *parser) Parse() error { +func (p *mockParser) Parse(contractAddr string) error { var err error p.parsedAbi, err = eth.ParseAbi(p.abi) @@ -58,7 +61,7 @@ func (p *parser) Parse() error { // Returns only specified methods, if they meet the criteria // Returns as array with methods in same order they were specified // Nil wanted array => no events are returned -func (p *parser) GetSelectMethods(wanted []string) []types.Method { +func (p *mockParser) GetSelectMethods(wanted []string) []types.Method { wLen := len(wanted) if wLen == 0 { return nil @@ -78,7 +81,7 @@ func (p *parser) GetSelectMethods(wanted []string) []types.Method { // Returns wanted methods // Empty wanted array => all methods are returned // Nil wanted array => no methods are returned -func (p *parser) GetMethods(wanted []string) []types.Method { +func (p *mockParser) GetMethods(wanted []string) []types.Method { if wanted == nil { return nil } @@ -95,7 +98,7 @@ func (p *parser) GetMethods(wanted []string) []types.Method { // Returns wanted events as map of types.Events // If no events are specified, all events are returned -func (p *parser) GetEvents(wanted []string) map[string]types.Event { +func (p *mockParser) GetEvents(wanted []string) map[string]types.Event { events := map[string]types.Event{} for _, e := range p.parsedAbi.Events { diff --git a/pkg/contract_watcher/shared/parser/parser_test.go b/pkg/contract_watcher/shared/parser/parser_test.go index 3830fbe7..b76c9e15 100644 --- a/pkg/contract_watcher/shared/parser/parser_test.go +++ b/pkg/contract_watcher/shared/parser/parser_test.go @@ -40,7 +40,7 @@ var _ = Describe("Parser", func() { Describe("Mock Parse", func() { It("Uses parses given abi string", func() { mp := mocks.NewParser(constants.DaiAbiString) - err = mp.Parse() + err = mp.Parse(constants.DaiContractAddress) Expect(err).ToNot(HaveOccurred()) parsedAbi := mp.ParsedAbi() diff --git a/pkg/plugin/builder/builder.go b/pkg/plugin/builder/builder.go index d6de5ba5..d045dff5 100644 --- a/pkg/plugin/builder/builder.go +++ b/pkg/plugin/builder/builder.go @@ -42,7 +42,7 @@ type builder struct { } // Requires populated plugin config -func NewPluginBuilder(gc config.Plugin) *builder { +func NewPluginBuilder(gc config.Plugin) PluginBuilder { return &builder{ GenConfig: gc, tmpVenDirs: make([]string, 0), diff --git a/pkg/plugin/generator.go b/pkg/plugin/generator.go index 7b3310f2..d0038ee7 100644 --- a/pkg/plugin/generator.go +++ b/pkg/plugin/generator.go @@ -36,7 +36,7 @@ type generator struct { } // Creates a new generator from a plugin and database config -func NewGenerator(gc config.Plugin, dbc config.Database) (*generator, error) { +func NewGenerator(gc config.Plugin, dbc config.Database) (Generator, error) { if len(gc.Transformers) < 1 { return nil, errors.New("plugin generator is not configured with any transformers") } diff --git a/pkg/plugin/manager/manager.go b/pkg/plugin/manager/manager.go index 0b96c764..a1a0abe8 100644 --- a/pkg/plugin/manager/manager.go +++ b/pkg/plugin/manager/manager.go @@ -41,7 +41,7 @@ type manager struct { } // Manager requires both filled in generator and database configs -func NewMigrationManager(gc config.Plugin, dbc config.Database) *manager { +func NewMigrationManager(gc config.Plugin, dbc config.Database) MigrationManager { return &manager{ GenConfig: gc, DBConfig: dbc, diff --git a/pkg/plugin/writer/writer.go b/pkg/plugin/writer/writer.go index 3cc1a71d..e56a477d 100644 --- a/pkg/plugin/writer/writer.go +++ b/pkg/plugin/writer/writer.go @@ -37,7 +37,7 @@ type writer struct { } // Requires populated plugin config -func NewPluginWriter(gc config.Plugin) *writer { +func NewPluginWriter(gc config.Plugin) PluginWriter { return &writer{ GenConfig: gc, }