2018-02-02 21:53:16 +00:00
|
|
|
package postgres_test
|
2018-02-02 19:58:59 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
. "github.com/onsi/ginkgo"
|
|
|
|
. "github.com/onsi/gomega"
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/core"
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/filters"
|
2018-02-02 21:53:16 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/repositories/postgres"
|
2018-02-02 19:58:59 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var _ = Describe("Watched Events Repository", func() {
|
2018-02-12 16:54:05 +00:00
|
|
|
var db *postgres.DB
|
|
|
|
var logRepository postgres.LogRepository
|
|
|
|
var filterRepository postgres.FilterRepository
|
|
|
|
var watchedEventRepository postgres.WatchedEventRepository
|
2018-02-02 19:58:59 +00:00
|
|
|
|
|
|
|
BeforeEach(func() {
|
2018-02-12 16:54:05 +00:00
|
|
|
db = postgres.NewTestDB(core.Node{})
|
|
|
|
logRepository = postgres.LogRepository{DB: db}
|
|
|
|
filterRepository = postgres.FilterRepository{DB: db}
|
|
|
|
watchedEventRepository = postgres.WatchedEventRepository{DB: db}
|
2018-02-02 19:58:59 +00:00
|
|
|
})
|
|
|
|
|
2018-02-08 16:12:08 +00:00
|
|
|
It("retrieves watched event logs that match the event filter", func() {
|
2018-02-02 19:58:59 +00:00
|
|
|
filter := filters.LogFilter{
|
|
|
|
Name: "Filter1",
|
|
|
|
FromBlock: 0,
|
|
|
|
ToBlock: 10,
|
|
|
|
Address: "0x123",
|
|
|
|
Topics: core.Topics{0: "event1=10", 2: "event3=hello"},
|
|
|
|
}
|
|
|
|
logs := []core.Log{
|
|
|
|
{
|
|
|
|
BlockNumber: 0,
|
|
|
|
TxHash: "0x1",
|
|
|
|
Address: "0x123",
|
|
|
|
Topics: core.Topics{0: "event1=10", 2: "event3=hello"},
|
|
|
|
Index: 0,
|
|
|
|
Data: "",
|
|
|
|
},
|
|
|
|
}
|
2018-02-08 16:12:08 +00:00
|
|
|
expectedWatchedEventLog := []*core.WatchedEvent{
|
2018-02-02 19:58:59 +00:00
|
|
|
{
|
|
|
|
Name: "Filter1",
|
|
|
|
BlockNumber: 0,
|
|
|
|
TxHash: "0x1",
|
|
|
|
Address: "0x123",
|
|
|
|
Topic0: "event1=10",
|
|
|
|
Topic2: "event3=hello",
|
|
|
|
Index: 0,
|
|
|
|
Data: "",
|
|
|
|
},
|
|
|
|
}
|
2018-02-12 16:54:05 +00:00
|
|
|
err := filterRepository.CreateFilter(filter)
|
2018-02-02 19:58:59 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2018-02-12 16:54:05 +00:00
|
|
|
err = logRepository.CreateLogs(logs)
|
2018-02-02 19:58:59 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2018-02-12 16:54:05 +00:00
|
|
|
matchingLogs, err := watchedEventRepository.GetWatchedEvents("Filter1")
|
2018-02-08 16:12:08 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(matchingLogs).To(Equal(expectedWatchedEventLog))
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
It("retrieves a watched event log by name", func() {
|
|
|
|
filter := filters.LogFilter{
|
|
|
|
Name: "Filter1",
|
|
|
|
FromBlock: 0,
|
|
|
|
ToBlock: 10,
|
|
|
|
Address: "0x123",
|
|
|
|
Topics: core.Topics{0: "event1=10", 2: "event3=hello"},
|
|
|
|
}
|
|
|
|
logs := []core.Log{
|
|
|
|
{
|
|
|
|
BlockNumber: 0,
|
|
|
|
TxHash: "0x1",
|
|
|
|
Address: "0x123",
|
|
|
|
Topics: core.Topics{0: "event1=10", 2: "event3=hello"},
|
|
|
|
Index: 0,
|
|
|
|
Data: "",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
BlockNumber: 100,
|
|
|
|
TxHash: "",
|
|
|
|
Address: "",
|
|
|
|
Topics: core.Topics{},
|
|
|
|
Index: 0,
|
|
|
|
Data: "",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
expectedWatchedEventLog := []*core.WatchedEvent{{
|
|
|
|
Name: "Filter1",
|
|
|
|
BlockNumber: 0,
|
|
|
|
TxHash: "0x1",
|
|
|
|
Address: "0x123",
|
|
|
|
Topic0: "event1=10",
|
|
|
|
Topic2: "event3=hello",
|
|
|
|
Index: 0,
|
|
|
|
Data: "",
|
|
|
|
}}
|
2018-02-12 16:54:05 +00:00
|
|
|
err := filterRepository.CreateFilter(filter)
|
2018-02-08 16:12:08 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2018-02-12 16:54:05 +00:00
|
|
|
err = logRepository.CreateLogs(logs)
|
2018-02-08 16:12:08 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2018-02-12 16:54:05 +00:00
|
|
|
matchingLogs, err := watchedEventRepository.GetWatchedEvents("Filter1")
|
2018-02-02 19:58:59 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(matchingLogs).To(Equal(expectedWatchedEventLog))
|
|
|
|
|
|
|
|
})
|
|
|
|
})
|