-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode_test.go
63 lines (50 loc) · 1.2 KB
/
node_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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package anvil_test
import (
"context"
"fmt"
"testing"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/rpc"
"github.com/lmittmann/w3"
"github.com/sprintertech/go-anvil"
)
func TestClient(t *testing.T) {
port := 8547
chainid := 13451
cli := anvil.NewNode(
anvil.WithPort(port),
anvil.WithChainID(chainid),
)
err := cli.Start()
if err != nil {
t.Fatal(err)
}
defer cli.Stop()
rpccli, err := rpc.Dial(fmt.Sprintf("http://127.0.0.1:%d", port))
if err != nil {
t.Fatal(err)
}
ethcli := ethclient.NewClient(rpccli)
acli := anvil.NewClient(rpccli)
addr := common.HexToAddress("0xc0de000000000000000000000000000000000000")
balance := w3.I("53 eth")
err = acli.SetBalance(addr, balance)
if err != nil {
t.Fatal(err)
}
bal, err := ethcli.BalanceAt(context.Background(), addr, nil)
if err != nil {
t.Fatal(err)
}
if bal.Cmp(balance) != 0 {
t.Fatalf("unexpected balance actual: %s, expected: %s", bal, balance)
}
id, err := ethcli.ChainID(context.Background())
if err != nil {
t.Fatal(err)
}
if id.Uint64() != uint64(chainid) {
t.Fatalf("chain ids do not match, actual: %s expected: %d", id, chainid)
}
}