2019-05-09 以太坊go客户端geth跑测试集

2022-05-13 08:27:30 浏览数 (1)

本意是搞定go客户端geth跑测试集,但是绕了一圈testeth,ethereumj,然后才搞定geth的测试集

由于后面要搞ewasm的测试集,而hera只能运行在ubuntu,mac上,因此这里使用系统ubuntu18

1、下载geth源代码

参考Installation Instructions for Ubuntu

代码语言:javascript复制
cd $GOPATH/src/github.com/ethereum
git clone https://github.com/ewasm/go-ethereum.git
sudo apt-get install -y build-essential
cd go-ethereum
make geth

这里需要注意的是我们需要把go-ethereum复制到gopath的下面:$GOPATH/src/github.com/ethereum

不是这个路径goland调试的时候各种找不到

这里下载的是ewasm分支的geth,如果你不需要测试ewasm,只需要按下面的方式下载主干的geth

代码语言:javascript复制
git clone https://github.com/ethereum/go-ethereum
sudo apt-get install -y build-essential
cd go-ethereum
make geth

2、项目导入到goland

参考文章2018-11-22 Debug以太坊go-ethereum实战

反正我还是没有搞定ubuntu下用goland调试geth,知道的麻烦告诉我一下

3、继续下载测试用例

还是在go-ethereum目录

代码语言:javascript复制
cd go-ethereum
git submodule init
git submodule update

4、运行测试集

在goland中打开文件tests/vm_test.go,右键run,就可以执行成功

如果需要执行单个文件,修改文件tests/init_test.go,找到下面的代码:

代码语言:javascript复制
        if filepath.Ext(path) == ".json" {
            t.Run(name, func(t *testing.T) { tm.runTestFile(t, path, name, runTest) })
        }

修改为:

代码语言:javascript复制
        //if filepath.Ext(path) == ".json" {
        if filepath.Base(path) == "sha3_0.json" {
            t.Run(name, func(t *testing.T) { tm.runTestFile(t, path, name, runTest) })
        }

执行结果:

代码语言:javascript复制
GOROOT=/usr/lib/go #gosetup
GOPATH=/home/elikong/go #gosetup
/usr/lib/go/bin/go test -c -o /tmp/___vm_test_go_linux github.com/ethereum/go-ethereum/tests #gosetup
/usr/lib/go/bin/go tool test2json -t /tmp/___vm_test_go_linux -test.v -test.run ^TestVM$ #gosetup
=== RUN   TestVM
=== PAUSE TestVM
=== CONT  TestVM
=== RUN   TestVM/vmSha3Test/sha3_0.json
=== PAUSE TestVM/vmSha3Test/sha3_0.json
=== CONT  TestVM/vmSha3Test/sha3_0.json
--- PASS: TestVM (0.00s)
    --- PASS: TestVM/vmSha3Test/sha3_0.json (0.00s)
PASS

Process finished with exit code 0

这样就只会执行sha3_0.json文件,

如果你测试其他目录,比如GeneralStateTests,就需要执行tests/state_test.go,而这里的修改应该是GeneralStateTests目录下的一个文件,否则会找不到测试用例

5、执行ewasm的测试

拉取ewasm的测试集

代码语言:javascript复制
cd $GOPATH/src/github.com/ethereum
git clone https://github.com/ewasm/tests.git

然后需要把ewasm的测试用例复制到go-ethereum

代码语言:javascript复制
cp tests/GeneralStateTests/stEWASMTests/* go-ethereum/tests/testdata/GeneralStateTests/stEWASMTests/

还需要把2019-04-26 使用Testeth跑ewasm测试集里面编译的hera复制过来

代码语言:javascript复制
cp hero/build/src/libhera.so .

然后把第三步里面修改的文件更换为:callCode.json

然后右键执行

tests/state_test.go

当然这个时候执行会失败,显示如下信息

代码语言:javascript复制
GOROOT=/usr/lib/go #gosetup
GOPATH=/home/elikong/go #gosetup
/usr/lib/go/bin/go test -c -o /tmp/___state_test_go_linux github.com/ethereum/go-ethereum/tests #gosetup
/usr/lib/go/bin/go tool test2json -t /tmp/___state_test_go_linux -test.v -test.run ^TestState$ #gosetup
=== RUN   TestState
=== PAUSE TestState
=== CONT  TestState
--- FAIL: TestState (0.01s)
=== RUN   TestState/stEWASMTests/callCode.json
=== PAUSE TestState/stEWASMTests/callCode.json
=== CONT  TestState/stEWASMTests/callCode.json
    --- FAIL: TestState/stEWASMTests/callCode.json (0.03s)
=== RUN   TestState/stEWASMTests/callCode.json/Byzantium/0
        --- FAIL: TestState/stEWASMTests/callCode.json/Byzantium/0 (0.00s)
            state_test.go:88: post state root mismatch: got b4796728d3390bd682204a2a339650101daaab49af13556c54ced7a542218bdd, want 6910e4bd33a6aaf192d4e599de3de2d0a01cb0a8c25acf537c5ef4ad8e7a90cf
            state_test.go:90: gas limit too high for EVM trace
FAIL

Process finished with exit code 1

需要在菜单run,edit configuration,选中state_test.go,设置program arguments为:

--vm.ewasm="/home/elikong/go/src/github.com/ethereum/libhera.so,metering=true,fallback=true"

然后执行,显示如下:

代码语言:javascript复制
GOROOT=/usr/lib/go #gosetup
GOPATH=/home/elikong/go #gosetup
/usr/lib/go/bin/go test -c -o /tmp/___state_test_go_linux github.com/ethereum/go-ethereum/tests #gosetup
/usr/lib/go/bin/go tool test2json -t /tmp/___state_test_go_linux -test.v -test.run ^TestState$ --vm.ewasm=/home/elikong/go/src/github.com/ethereum/libhera.so,metering=true,fallback=true #gosetup
=== RUN   TestState
=== PAUSE TestState
=== CONT  TestState
--- PASS: TestState (0.02s)
=== RUN   TestState/stEWASMTests/callCode.json
=== PAUSE TestState/stEWASMTests/callCode.json
=== CONT  TestState/stEWASMTests/callCode.json
    --- PASS: TestState/stEWASMTests/callCode.json (0.46s)
=== RUN   TestState/stEWASMTests/callCode.json/Byzantium/0
Executing message in Hera
importGlobals
[0] callCode 186a0 0 20 20 1
Executing message in Hera
importGlobals
[1] storageStore 0 20
[0] storageStore 80 60
        --- PASS: TestState/stEWASMTests/callCode.json/Byzantium/0 (0.46s)
PASS

Process finished with exit code 0

如果还有错误,需要更新一下代码:

git pull origin ewasm

0 人点赞