2019-01-25 08:59:23 +00:00
|
|
|
// 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/>.
|
|
|
|
|
2019-02-02 22:15:09 +00:00
|
|
|
package plugin_test
|
2019-01-25 08:59:23 +00:00
|
|
|
|
2019-02-06 19:22:47 +00:00
|
|
|
/* comment out til mcd_transformers is updated
|
2019-01-25 08:59:23 +00:00
|
|
|
import (
|
|
|
|
"plugin"
|
|
|
|
|
|
|
|
. "github.com/onsi/ginkgo"
|
|
|
|
. "github.com/onsi/gomega"
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
|
|
|
|
"github.com/vulcanize/vulcanizedb/libraries/shared/transformer"
|
|
|
|
"github.com/vulcanize/vulcanizedb/libraries/shared/watcher"
|
2019-01-31 01:38:56 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/config"
|
2019-01-25 08:59:23 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/core"
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories"
|
2019-02-02 22:15:09 +00:00
|
|
|
p2 "github.com/vulcanize/vulcanizedb/pkg/plugin"
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/plugin/helpers"
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/plugin/test_helpers"
|
2019-01-25 08:59:23 +00:00
|
|
|
)
|
|
|
|
|
2019-02-02 22:15:09 +00:00
|
|
|
var genConfig = config.Plugin{
|
2019-01-31 01:38:56 +00:00
|
|
|
Initializers: map[string]string{
|
2019-02-02 22:15:09 +00:00
|
|
|
"bite": "github.com/vulcanize/mcd_transformers/transformers/bite/initializer",
|
|
|
|
"deal": "github.com/vulcanize/mcd_transformers/transformers/deal/initializer",
|
2019-01-31 01:38:56 +00:00
|
|
|
},
|
|
|
|
Dependencies: map[string]string{
|
|
|
|
"mcd_transformers": "github.com/vulcanize/mcd_transformers",
|
2019-01-25 08:59:23 +00:00
|
|
|
},
|
2019-02-02 22:15:09 +00:00
|
|
|
//Migrations: map[string]string{"mcd_transformers" : "db/migrations"},
|
2019-01-31 01:38:56 +00:00
|
|
|
FileName: "externalTestTransformerSet",
|
2019-02-02 22:15:09 +00:00
|
|
|
FilePath: "$GOPATH/src/github.com/vulcanize/vulcanizedb/pkg/plugin/test_helpers/test",
|
2019-01-31 23:14:42 +00:00
|
|
|
Save: false,
|
2019-01-25 08:59:23 +00:00
|
|
|
}
|
|
|
|
|
2019-02-02 22:15:09 +00:00
|
|
|
var dbConfig = config.Database{
|
|
|
|
Hostname: "localhost",
|
|
|
|
Port: 5432,
|
|
|
|
Name: "vulcanize_private",
|
|
|
|
}
|
|
|
|
|
2019-01-25 08:59:23 +00:00
|
|
|
type Exporter interface {
|
|
|
|
Export() []transformer.TransformerInitializer
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ = Describe("Generator test", func() {
|
2019-02-02 22:15:09 +00:00
|
|
|
var g p2.Generator
|
2019-01-25 08:59:23 +00:00
|
|
|
var goPath, soPath string
|
|
|
|
var err error
|
|
|
|
var bc core.BlockChain
|
|
|
|
var db *postgres.DB
|
|
|
|
var hr repositories.HeaderRepository
|
|
|
|
var headerID int64
|
|
|
|
viper.SetConfigName("compose")
|
|
|
|
viper.AddConfigPath("$GOPATH/src/github.com/vulcanize/vulcanizedb/environments/")
|
|
|
|
|
2019-01-31 23:14:42 +00:00
|
|
|
BeforeEach(func() {
|
|
|
|
goPath, soPath, err = genConfig.GetPluginPaths()
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2019-02-02 22:15:09 +00:00
|
|
|
g, err = p2.NewGenerator(genConfig, dbConfig)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2019-01-31 23:14:42 +00:00
|
|
|
err = g.GenerateExporterPlugin()
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
})
|
|
|
|
|
|
|
|
AfterEach(func() {
|
2019-02-02 22:15:09 +00:00
|
|
|
err := helpers.ClearFiles(goPath, soPath)
|
2019-01-31 23:14:42 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
})
|
|
|
|
|
|
|
|
Describe("GenerateTransformerPlugin", func() {
|
|
|
|
It("It bundles the specified transformer initializers into a Exporter object and creates .so", func() {
|
|
|
|
plug, err := plugin.Open(soPath)
|
2019-01-25 08:59:23 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2019-01-31 23:14:42 +00:00
|
|
|
symExporter, err := plug.Lookup("Exporter")
|
2019-01-25 08:59:23 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2019-01-31 23:14:42 +00:00
|
|
|
exporter, ok := symExporter.(Exporter)
|
|
|
|
Expect(ok).To(Equal(true))
|
|
|
|
initializers := exporter.Export()
|
|
|
|
Expect(len(initializers)).To(Equal(2))
|
2019-01-25 08:59:23 +00:00
|
|
|
})
|
|
|
|
|
2019-01-31 23:14:42 +00:00
|
|
|
It("Loads our generated Exporter and uses it to import an arbitrary set of TransformerInitializers that we can execute over", func() {
|
|
|
|
db, bc = test_helpers.SetupDBandBC()
|
|
|
|
defer test_helpers.TearDown(db)
|
2019-01-25 08:59:23 +00:00
|
|
|
|
2019-01-31 23:14:42 +00:00
|
|
|
hr = repositories.NewHeaderRepository(db)
|
|
|
|
header1, err := bc.GetHeaderByNumber(9377319)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
headerID, err = hr.CreateOrUpdateHeader(header1)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2019-01-31 01:38:56 +00:00
|
|
|
|
2019-01-31 23:14:42 +00:00
|
|
|
plug, err := plugin.Open(soPath)
|
2019-01-25 08:59:23 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2019-01-31 23:14:42 +00:00
|
|
|
symExporter, err := plug.Lookup("Exporter")
|
2019-01-25 08:59:23 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2019-01-31 23:14:42 +00:00
|
|
|
exporter, ok := symExporter.(Exporter)
|
|
|
|
Expect(ok).To(Equal(true))
|
|
|
|
initializers := exporter.Export()
|
2019-01-25 08:59:23 +00:00
|
|
|
|
2019-01-31 23:14:42 +00:00
|
|
|
w := watcher.NewWatcher(db, bc)
|
|
|
|
w.AddTransformers(initializers)
|
|
|
|
err = w.Execute()
|
2019-01-25 08:59:23 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
2019-01-31 23:14:42 +00:00
|
|
|
type model struct {
|
|
|
|
Ilk string
|
|
|
|
Urn string
|
|
|
|
Ink string
|
|
|
|
Art string
|
|
|
|
IArt string
|
|
|
|
Tab string
|
|
|
|
NFlip string
|
|
|
|
LogIndex uint `db:"log_idx"`
|
|
|
|
TransactionIndex uint `db:"tx_idx"`
|
|
|
|
Raw []byte `db:"raw_log"`
|
|
|
|
Id int64 `db:"id"`
|
|
|
|
HeaderId int64 `db:"header_id"`
|
|
|
|
}
|
|
|
|
|
|
|
|
returned := model{}
|
|
|
|
|
|
|
|
err = db.Get(&returned, `SELECT * FROM maker.bite WHERE header_id = $1`, headerID)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(returned.Ilk).To(Equal("ETH"))
|
|
|
|
Expect(returned.Urn).To(Equal("0x0000d8b4147eDa80Fec7122AE16DA2479Cbd7ffB"))
|
|
|
|
Expect(returned.Ink).To(Equal("80000000000000000000"))
|
|
|
|
Expect(returned.Art).To(Equal("11000000000000000000000"))
|
|
|
|
Expect(returned.IArt).To(Equal("12496609999999999999992"))
|
|
|
|
Expect(returned.Tab).To(Equal("11000000000000000000000"))
|
|
|
|
Expect(returned.NFlip).To(Equal("7"))
|
|
|
|
Expect(returned.TransactionIndex).To(Equal(uint(1)))
|
|
|
|
Expect(returned.LogIndex).To(Equal(uint(4)))
|
2019-01-25 08:59:23 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2019-02-06 19:22:47 +00:00
|
|
|
*/
|