NewTestServer unreachable rpc address
huahuayu opened this issue · 3 comments
Env
Mac m1 macos 12.4
Docker Desktop 4.10.1
Issue
When run abi/encoding_test.go/TestEncoding(t *testing.T)
function
The testsuit/server.go
NewTestServer()
created a geth client, but port 8545 can't be reached.
func (t *TestServer) HTTPAddr() string {
return fmt.Sprintf("http://%s:8545", t.resource.Container.NetworkSettings.IPAddress)
}
Error screenshot
The docker container info
$ docker ps | grep ethereum
03e1459341a8 ethereum/client-go:v1.10.15 "geth --dev --datadi…" 8 minutes ago Up 8 minutes 0.0.0.0:55020->8545/tcp, 0.0.0.0:55019->8546/tcp, 0.0.0.0:55006->30303/udp, 0.0.0.0:55018->30303/tcp serene_ardinghelli
Inside the container the command is
geth --dev --datadir /eth1data --ipcpath /eth1data/geth.ipc --http --http.addr 0.0.0.0 --http.api eth,net,web3,debug --ws --ws.addr 0.0.0.0
--verbosity 4
$ifconfig
eth0 Link encap:Ethernet HWaddr 02:42:AC:11:00:04
inet addr:172.17.0.4 Bcast:172.17.255.255 Mask:255.255.0.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2006 errors:0 dropped:0 overruns:0 frame:0
TX packets:1378 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:2466217 (2.3 MiB) TX bytes:77013 (75.2 KiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:18 errors:0 dropped:0 overruns:0 frame:0
TX packets:18 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1073 (1.0 KiB) TX bytes:1073 (1.0 KiB)
$ telnet 172.17.0.4 8545
Connected to 172.17.0.4
Connection closed by foreign host
I think it's because of the wrong geth command, it's actually equivalent to using blew docker-compose.yml
to start a geth client, the container can get up, but inside the container, telnet 127.0.0.1 8545, doesn't work.
version: '2'
services:
geth:
image: ethereum/client-go:v1.10.15
command: --dev --datadir /eth1data --ipcpath /eth1data/geth.ipc --http --http.addr 0.0.0.0 --http.api eth,net,web3,debug --ws --ws.addr 0.0.0.0 --verbosity 4
ports:
- "30303:30303"
- "30303:30303/udp"
- "8545:8545"
After some dig, I found there are two issues:
- The geth version is hardcode 1.10.15 which may not support mac m1 chip good, but 1.10.25(the latest) is ok
- The
HTTPAddr()
get the container's ip address but it can be accessed from the host
func (t *TestServer) HTTPAddr() string {
return fmt.Sprintf("http://%s:8545", t.resource.Container.NetworkSettings.IPAddress)
}
I changed it to localhost with binding port then it's ok
func (t *TestServer) HTTPAddr() string {
port := t.resource.GetPort("8545/tcp")
return fmt.Sprintf("http://localhost:%s", port)
}
Now the tests can be run but some tests failed, FYI
GOROOT=/usr/local/go #gosetup
GOPATH=/Users/shiming/go #gosetup
/usr/local/go/bin/go test -c -o /private/var/folders/z4/sqccl7ys2yjbj3qrjl62q45m0000gn/T/GoLand/___1TestEncoding_in_github_com_umbracle_ethgo_abi.test -gcflags all=-N -l github.com/umbracle/ethgo/abi #gosetup
/usr/local/go/bin/go tool test2json -t /private/var/folders/z4/sqccl7ys2yjbj3qrjl62q45m0000gn/T/dlvLauncher.sh /Applications/GoLand.app/Contents/plugins/go/lib/dlv/macarm/dlv --listen=127.0.0.1:55297 --headless=true --api-version=2 --check-go-version=false --only-same-user=false exec /private/var/folders/z4/sqccl7ys2yjbj3qrjl62q45m0000gn/T/GoLand/___1TestEncoding_in_github_com_umbracle_ethgo_abi.test -- -test.v -test.paniconexit0 -test.run ^\QTestEncoding\E$
=== RUN TestEncoding
[]
--- FAIL: TestEncoding (5.09s)
=== RUN TestEncoding/#00
--- PASS: TestEncoding/#00 (0.00s)
=== RUN TestEncoding/#01
--- PASS: TestEncoding/#01 (0.00s)
=== RUN TestEncoding/#02
--- PASS: TestEncoding/#02 (0.00s)
=== RUN TestEncoding/#03
--- PASS: TestEncoding/#03 (0.00s)
=== RUN TestEncoding/#04
--- PASS: TestEncoding/#04 (0.00s)
=== RUN TestEncoding/#05
--- PASS: TestEncoding/#05 (0.00s)
=== RUN TestEncoding/#06
--- PASS: TestEncoding/#06 (0.00s)
=== RUN TestEncoding/#07
--- PASS: TestEncoding/#07 (0.00s)
=== RUN TestEncoding/#08
--- PASS: TestEncoding/#08 (0.00s)
=== RUN TestEncoding/#09
--- PASS: TestEncoding/#09 (0.00s)
=== RUN TestEncoding/#10
--- PASS: TestEncoding/#10 (0.00s)
=== RUN TestEncoding/#11
--- PASS: TestEncoding/#11 (0.00s)
=== RUN TestEncoding/#12
--- PASS: TestEncoding/#12 (0.00s)
=== RUN TestEncoding/#13
--- PASS: TestEncoding/#13 (0.00s)
=== RUN TestEncoding/#14
--- PASS: TestEncoding/#14 (0.00s)
=== RUN TestEncoding/#15
--- PASS: TestEncoding/#15 (0.00s)
=== RUN TestEncoding/#16
--- PASS: TestEncoding/#16 (0.00s)
=== RUN TestEncoding/#17
--- PASS: TestEncoding/#17 (0.00s)
=== RUN TestEncoding/#18
--- PASS: TestEncoding/#18 (0.00s)
=== RUN TestEncoding/#19
encoding_test.go:328: failed to compile:
--- FAIL: TestEncoding/#19 (0.00s)
=== RUN TestEncoding/#20
encoding_test.go:328: failed to compile:
--- FAIL: TestEncoding/#20 (0.00s)
=== RUN TestEncoding/#21
encoding_test.go:328: failed to compile:
--- FAIL: TestEncoding/#21 (0.00s)
=== RUN TestEncoding/#22
encoding_test.go:328: failed to compile:
--- FAIL: TestEncoding/#22 (0.00s)
=== RUN TestEncoding/#23
encoding_test.go:328: failed to compile:
--- FAIL: TestEncoding/#23 (0.00s)
=== RUN TestEncoding/#24
encoding_test.go:328: failed to compile:
--- FAIL: TestEncoding/#24 (0.00s)
=== RUN TestEncoding/#25
encoding_test.go:328: failed to compile:
--- FAIL: TestEncoding/#25 (0.00s)
=== RUN TestEncoding/#26
encoding_test.go:328: failed to compile:
--- FAIL: TestEncoding/#26 (0.00s)
=== RUN TestEncoding/#27
encoding_test.go:328: failed to compile:
--- FAIL: TestEncoding/#27 (0.00s)
=== RUN TestEncoding/#28
encoding_test.go:328: failed to compile:
--- FAIL: TestEncoding/#28 (0.00s)
=== RUN TestEncoding/#29
encoding_test.go:328: failed to compile:
--- FAIL: TestEncoding/#29 (0.00s)
=== RUN TestEncoding/#30
encoding_test.go:328: failed to compile:
--- FAIL: TestEncoding/#30 (0.00s)
=== RUN TestEncoding/#31
--- PASS: TestEncoding/#31 (0.00s)
=== RUN TestEncoding/#32
--- PASS: TestEncoding/#32 (0.00s)
=== RUN TestEncoding/#33
--- PASS: TestEncoding/#33 (0.00s)
=== RUN TestEncoding/#34
encoding_test.go:328: failed to compile:
--- FAIL: TestEncoding/#34 (0.00s)
=== RUN TestEncoding/#35
encoding_test.go:328: failed to compile:
--- FAIL: TestEncoding/#35 (0.00s)
=== RUN TestEncoding/#36
--- PASS: TestEncoding/#36 (0.00s)
=== RUN TestEncoding/#37
encoding_test.go:328: failed to compile:
--- FAIL: TestEncoding/#37 (0.00s)
FAIL
Debugger finished with the exit code 0
This has been fixed in another way, instead of relying on a custom server for each test (which requires dealing with nuances from MacOs and Linux), there is a helper bash script that deploys the blockchain at startup. Now, the test cannot rely on an independent and isolated environment for the execution but it is easier to scale and remove these issues.