47

Spectrum链开发准备篇-Windows环境下调通测试代码,执行单元测试

 5 years ago
source link: https://studygolang.com/articles/14732?amp%3Butm_medium=referral
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

系统环境 win10

注:不同windows发布版本安装过程可能略有不同

环境依赖:

Go, GCC

Go下载地址: https://golang.org/dl/

笔者下载的是1.10.2.   64位版本:

完整下载地址: https://dl.google.com/go/go1.10.2.windows-amd64.msi

安装:

mUbmmuu.png!web

笔者安装的路径为 C:\Go目录下. 添加   C:\Go\bin到环境变量中.

任意目录下执行go version,显示版本号则安装配置成功.

C:\Users\tangshua>go version

go version go1.10.2 windows/amd64

MinGw下载地址 : https://sourceforge.net/projects/mingw-w64/

笔者下载的GW完整下载地址: https://jaist.dl.sourceforge.net/project/mingw-w64/Toolchains%20targetting%20Win32/Personal%20Builds/mingw-builds/installer/mingw-w64-install.exe

安装MinGW:

VJfQja3.png!web

笔者安装在D:\mingw-w64,安装完成后如下. 添加D:\mingw-w64\bin到环境变量中.

nieqAnY.png!web

Spectrum安装

下载源文件

https://github.com/SmartMeshFoundation/Spectrum

笔者放在了D盘.切换到tests目录.  执行Go test -v

vqy6N3N.png!web
ryAZNfZ.png!web

其它点:

执行报错解决办法:

1.   将代码放在Go目录下.

C:\Go\src\github.com\SmartMeshFoundation\Spectrum

笔者在block_test_util.go代码中发现如下定义,可能导致相应类库无法找到而报错.

import ( "bytes" "encoding/hex" "encoding/json" "fmt" "math/big" "github.com/SmartMeshFoundation/Spectrum/common" "github.com/SmartMeshFoundation/Spectrum/common/hexutil" "github.com/SmartMeshFoundation/Spectrum/common/math" "github.com/SmartMeshFoundation/Spectrum/consensus/ethash" "github.com/SmartMeshFoundation/Spectrum/core" "github.com/SmartMeshFoundation/Spectrum/core/state" "github.com/SmartMeshFoundation/Spectrum/core/types" "github.com/SmartMeshFoundation/Spectrum/core/vm" "github.com/SmartMeshFoundation/Spectrum/ethdb" "github.com/SmartMeshFoundation/Spectrum/params" "github.com/SmartMeshFoundation/Spectrum/rlp" )

2.   在tests目录下创建testdata目录,同时在testdata目录下分别创建

BlockchainTests,GeneralStateTests,TransactionTests,VMTests,RLPTests,BasicTests目录。

笔者在init_test.go 文件中发现如下定义:

var ( baseDir = filepath.Join(".", "testdata") blockTestDir = filepath.Join(baseDir, "BlockchainTests") stateTestDir = filepath.Join(baseDir, "GeneralStateTests") transactionTestDir = filepath.Join(baseDir, "TransactionTests") vmTestDir = filepath.Join(baseDir, "VMTests") rlpTestDir = filepath.Join(baseDir, "RLPTests") difficultyTestDir = filepath.Join(baseDir, "BasicTests") )

但是并未在文件夹中发现,因此手动创建了改文件夹.

BVrARzU.png!web
nMBnyq7.png!web

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK