forked from HydroProtocol/ethereum-watcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
watcher_with_block_plugin_test.go
43 lines (32 loc) · 1.02 KB
/
watcher_with_block_plugin_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package ethereum_watcher
import (
"context"
"testing"
"github.com/mobazha/ethereum-watcher/plugin"
"github.com/mobazha/ethereum-watcher/structs"
"github.com/sirupsen/logrus"
)
func TestNewBlockNumPlugin(t *testing.T) {
logrus.SetLevel(logrus.InfoLevel)
api := "https://mainnet.infura.io/v3/19d753b2600445e292d54b1ef58d4df4"
w, err := NewHttpBasedEthWatcher(context.Background(), api)
if err != nil {
logrus.Panicln("RPC error:", err)
}
logrus.Println("waiting for new block...")
w.RegisterBlockPlugin(plugin.NewBlockNumPlugin(func(i uint64, b bool) {
logrus.Printf(">> found new block: %d, is removed: %t", i, b)
}))
w.RunTillExit()
}
func TestSimpleBlockPlugin(t *testing.T) {
api := "https://mainnet.infura.io/v3/19d753b2600445e292d54b1ef58d4df4"
w, err := NewHttpBasedEthWatcher(context.Background(), api)
if err != nil {
logrus.Panicln("RPC error:", err)
}
w.RegisterBlockPlugin(plugin.NewSimpleBlockPlugin(func(block *structs.RemovableBlock) {
logrus.Infof(">> %+v", block.Block)
}))
w.RunTillExit()
}