Commit b6105c0a authored by liuyuhang's avatar liuyuhang

modify evm and paracross

parent 8150a333
...@@ -10,16 +10,19 @@ import ( ...@@ -10,16 +10,19 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
// 因为测试程序在外层,而合约类型的初始化在里面,所以需要显示引用,否则不会加载合约插件 // 因为测试程序在外层,而合约类型的初始化在里面,所以需要显示引用,否则不会加载合约插件
_ "github.com/33cn/plugin/plugin/dapp/evm/executor" evm "github.com/33cn/plugin/plugin/dapp/evm/executor"
evmtypes "github.com/33cn/plugin/plugin/dapp/evm/types" evmtypes "github.com/33cn/plugin/plugin/dapp/evm/types"
// 需要显示引用系统插件,以加载系统内置合约 // 需要显示引用系统插件,以加载系统内置合约
"github.com/33cn/chain33/client/mocks" "github.com/33cn/chain33/client/mocks"
_ "github.com/33cn/chain33/system" _ "github.com/33cn/chain33/system"
"github.com/stretchr/testify/mock"
) )
// TestQueryDebug 测试命令行调用rpc接口 // TestQueryDebug 测试命令行调用rpc接口
func TestQueryDebug(t *testing.T) { func TestQueryDebug(t *testing.T) {
var cfg = types.NewChain33Config(types.GetDefaultCfgstring())
evm.Init(evmtypes.ExecutorName, cfg, nil)
var debugReq = evmtypes.EvmDebugReq{Optype: 1} var debugReq = evmtypes.EvmDebugReq{Optype: 1}
js, err := types.PBToJSON(&debugReq) js, err := types.PBToJSON(&debugReq)
assert.Nil(t, err) assert.Nil(t, err)
...@@ -35,6 +38,7 @@ func TestQueryDebug(t *testing.T) { ...@@ -35,6 +38,7 @@ func TestQueryDebug(t *testing.T) {
// 这里对需要mock的方法打桩,Close是必须的,其它方法根据需要 // 这里对需要mock的方法打桩,Close是必须的,其它方法根据需要
mockapi.On("Close").Return() mockapi.On("Close").Return()
mockapi.On("Query", "evm", "EvmDebug", &debugReq).Return(&mockResp, nil) mockapi.On("Query", "evm", "EvmDebug", &debugReq).Return(&mockResp, nil)
mockapi.On("GetConfig", mock.Anything).Return(cfg, nil)
mock33 := testnode.New("", mockapi) mock33 := testnode.New("", mockapi)
defer mock33.Close() defer mock33.Close()
......
...@@ -22,9 +22,10 @@ import ( ...@@ -22,9 +22,10 @@ import (
evmtypes "github.com/33cn/plugin/plugin/dapp/evm/types" evmtypes "github.com/33cn/plugin/plugin/dapp/evm/types"
"github.com/33cn/chain33/queue" "github.com/33cn/chain33/queue"
"github.com/33cn/chain33/client" "github.com/33cn/chain33/client"
"strings"
) )
var chainTestCfg = types.NewChain33Config(types.GetDefaultCfgstring()) var chainTestCfg = types.NewChain33Config(strings.Replace(types.GetDefaultCfgstring(), "Title=\"local\"", "Title=\"chain33\"" , 1))
func init() { func init() {
evm.Init(evmtypes.ExecutorName, chainTestCfg, nil) evm.Init(evmtypes.ExecutorName, chainTestCfg, nil)
......
...@@ -18,6 +18,8 @@ import ( ...@@ -18,6 +18,8 @@ import (
dbmock "github.com/33cn/chain33/common/db/mocks" dbmock "github.com/33cn/chain33/common/db/mocks"
"github.com/33cn/chain33/types" "github.com/33cn/chain33/types"
pt "github.com/33cn/plugin/plugin/dapp/paracross/types" pt "github.com/33cn/plugin/plugin/dapp/paracross/types"
"strings"
"github.com/33cn/plugin/plugin/dapp/paracross/testnode"
"github.com/stretchr/testify/mock" "github.com/stretchr/testify/mock"
) )
...@@ -55,10 +57,10 @@ func (suite *AssetTransferTestSuite) SetupTest() { ...@@ -55,10 +57,10 @@ func (suite *AssetTransferTestSuite) SetupTest() {
// memdb 不支持KVDB接口, 等测试完Exec , 再扩展 memdb // memdb 不支持KVDB接口, 等测试完Exec , 再扩展 memdb
//suite.localDB, _ = dbm.NewGoMemDB("local", "local", 1024) //suite.localDB, _ = dbm.NewGoMemDB("local", "local", 1024)
suite.localDB = new(dbmock.KVDB) suite.localDB = new(dbmock.KVDB)
suite.api = new(apimock.QueueProtocolAPI)
suite.api.On("GetConfig", mock.Anything).Return(chain33TestCfg, nil)
suite.exec = newParacross().(*Paracross) suite.exec = newParacross().(*Paracross)
suite.api = new(apimock.QueueProtocolAPI)
suite.api.On("GetConfig", mock.Anything).Return(chain33TestCfg, nil)
suite.exec.SetAPI(suite.api) suite.exec.SetAPI(suite.api)
suite.exec.SetLocalDB(suite.localDB) suite.exec.SetLocalDB(suite.localDB)
suite.exec.SetStateDB(suite.stateDB) suite.exec.SetStateDB(suite.stateDB)
...@@ -101,6 +103,10 @@ func (suite *AssetTransferTestSuite) SetupTest() { ...@@ -101,6 +103,10 @@ func (suite *AssetTransferTestSuite) SetupTest() {
func (suite *AssetTransferTestSuite) TestExecTransferNobalance() { func (suite *AssetTransferTestSuite) TestExecTransferNobalance() {
//types.Init("test", nil) //types.Init("test", nil)
suite.api = new(apimock.QueueProtocolAPI)
suite.api.On("GetConfig", mock.Anything).Return(chain33TestMainCfg, nil)
suite.exec.SetAPI(suite.api)
toB := Nodes[1] toB := Nodes[1]
tx, err := createAssetTransferTx(suite.Suite, PrivKeyD, toB) tx, err := createAssetTransferTx(suite.Suite, PrivKeyD, toB)
if err != nil { if err != nil {
...@@ -117,6 +123,10 @@ func (suite *AssetTransferTestSuite) TestExecTransferNobalance() { ...@@ -117,6 +123,10 @@ func (suite *AssetTransferTestSuite) TestExecTransferNobalance() {
func (suite *AssetTransferTestSuite) TestExecTransfer() { func (suite *AssetTransferTestSuite) TestExecTransfer() {
//types.Init("test", nil) //types.Init("test", nil)
suite.api = new(apimock.QueueProtocolAPI)
suite.api.On("GetConfig", mock.Anything).Return(chain33TestMainCfg, nil)
suite.exec.SetAPI(suite.api)
toB := Nodes[1] toB := Nodes[1]
total := 1000 * types.Coin total := 1000 * types.Coin
...@@ -163,6 +173,7 @@ func (suite *AssetTransferTestSuite) TestExecTransfer() { ...@@ -163,6 +173,7 @@ func (suite *AssetTransferTestSuite) TestExecTransfer() {
} }
func (suite *AssetTransferTestSuite) TestExecTransferInPara() { func (suite *AssetTransferTestSuite) TestExecTransferInPara() {
chain33TestCfg = types.NewChain33Config(strings.Replace(testnode.DefaultConfig, "Title=\"user.p.guodun.\"", "Title=\"user.p.test.\"" , 1))
//para_init(Title) //para_init(Title)
toB := Nodes[1] toB := Nodes[1]
...@@ -222,6 +233,10 @@ const TestSymbol = "TEST" ...@@ -222,6 +233,10 @@ const TestSymbol = "TEST"
func (suite *AssetTransferTestSuite) TestExecTransferToken() { func (suite *AssetTransferTestSuite) TestExecTransferToken() {
//types.Init("test", nil) //types.Init("test", nil)
suite.api = new(apimock.QueueProtocolAPI)
suite.api.On("GetConfig", mock.Anything).Return(chain33TestMainCfg, nil)
suite.exec.SetAPI(suite.api)
toB := Nodes[1] toB := Nodes[1]
total := 1000 * types.Coin total := 1000 * types.Coin
...@@ -267,6 +282,7 @@ func (suite *AssetTransferTestSuite) TestExecTransferToken() { ...@@ -267,6 +282,7 @@ func (suite *AssetTransferTestSuite) TestExecTransferToken() {
} }
func (suite *AssetTransferTestSuite) TestExecTransferTokenInPara() { func (suite *AssetTransferTestSuite) TestExecTransferTokenInPara() {
chain33TestCfg = types.NewChain33Config(strings.Replace(testnode.DefaultConfig, "Title=\"user.p.guodun.\"", "Title=\"user.p.test.\"" , 1))
// para_init(Title) // para_init(Title)
toB := Nodes[1] toB := Nodes[1]
......
...@@ -92,6 +92,9 @@ func (suite *AssetWithdrawTestSuite) SetupTest() { ...@@ -92,6 +92,9 @@ func (suite *AssetWithdrawTestSuite) SetupTest() {
// 主链先不执行 // 主链先不执行
func (suite *AssetWithdrawTestSuite) TestExecAssetWithdrawOnMainChain() { func (suite *AssetWithdrawTestSuite) TestExecAssetWithdrawOnMainChain() {
//types.Init("test", nil) //types.Init("test", nil)
suite.api = new(apimock.QueueProtocolAPI)
suite.api.On("GetConfig", mock.Anything).Return(chain33TestMainCfg, nil)
suite.exec.SetAPI(suite.api)
tx, err := createAssetWithdrawTx(suite.Suite, PrivKeyA, Nodes[1]) tx, err := createAssetWithdrawTx(suite.Suite, PrivKeyA, Nodes[1])
if err != nil { if err != nil {
suite.T().Error("createAssetWithdrawTx", "err", err) suite.T().Error("createAssetWithdrawTx", "err", err)
...@@ -147,6 +150,10 @@ func (suite *AssetWithdrawTestSuite) TestExecAssetWithdrawOnParaChain() { ...@@ -147,6 +150,10 @@ func (suite *AssetWithdrawTestSuite) TestExecAssetWithdrawOnParaChain() {
// 主链在平行链执行成功后执行 // 主链在平行链执行成功后执行
func (suite *AssetWithdrawTestSuite) TestExecAssetWithdrawAfterPara() { func (suite *AssetWithdrawTestSuite) TestExecAssetWithdrawAfterPara() {
// types.Init("test", nil) // types.Init("test", nil)
suite.api = new(apimock.QueueProtocolAPI)
suite.api.On("GetConfig", mock.Anything).Return(chain33TestMainCfg, nil)
suite.exec.SetAPI(suite.api)
// make coins for transfer // make coins for transfer
acc := account.NewCoinsAccount(chain33TestCfg) acc := account.NewCoinsAccount(chain33TestCfg)
acc.SetDB(suite.stateDB) acc.SetDB(suite.stateDB)
......
...@@ -21,8 +21,8 @@ import ( ...@@ -21,8 +21,8 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
"github.com/stretchr/testify/mock" "github.com/stretchr/testify/mock"
"github.com/33cn/plugin/plugin/dapp/paracross/testnode"
"strings" "strings"
"github.com/33cn/plugin/plugin/dapp/paracross/testnode"
) )
// 构造一个4个节点的平行链数据, 进行测试 // 构造一个4个节点的平行链数据, 进行测试
...@@ -56,7 +56,7 @@ var ( ...@@ -56,7 +56,7 @@ var (
MainBlockHeightForTransfer = int64(9) MainBlockHeightForTransfer = int64(9)
tempTitle = "" tempTitle = ""
chain33TestCfg = types.NewChain33Config(strings.Replace(testnode.DefaultConfig, "Title=\"user.p.guodun.\"", "Title=\"user.p.test.\"" , 1)) chain33TestCfg = types.NewChain33Config(strings.Replace(testnode.DefaultConfig, "Title=\"user.p.guodun.\"", "Title=\"user.p.test.\"" , 1))
//chain33TestCfg = types.NewChain33Config(testnode.DefaultConfig) chain33TestMainCfg = types.NewChain33Config(strings.Replace(types.GetDefaultCfgstring(), "Title=\"local\"", "Title=\"test\"" , 1))
) )
type CommitTestSuite struct { type CommitTestSuite struct {
......
...@@ -7,10 +7,19 @@ import ( ...@@ -7,10 +7,19 @@ import (
_ "github.com/33cn/chain33/system" _ "github.com/33cn/chain33/system"
_ "github.com/33cn/plugin/plugin" _ "github.com/33cn/plugin/plugin"
"github.com/33cn/chain33/util/testnode"
"github.com/33cn/chain33/types"
"strings"
) )
func TestParaNode(t *testing.T) { func TestParaNode(t *testing.T) {
para := NewParaNode(nil, nil) cfg := types.NewChain33Config(strings.Replace(types.GetDefaultCfgstring(), "Title=\"local\"", "Title=\"chain33\"" , 1))
cfg.GetModuleConfig().Consensus.Name = "ticket"
main := testnode.NewWithConfig(cfg, nil)
main.Listen()
para := NewParaNode(main, nil)
paraCfg := para.Para.GetAPI().GetConfig() paraCfg := para.Para.GetAPI().GetConfig()
defer para.Close() defer para.Close()
//通过rpc 发生信息 //通过rpc 发生信息
......
...@@ -17,18 +17,13 @@ import ( ...@@ -17,18 +17,13 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
var mocker *testnode.Chain33Mock func TestJRPCChannel(t *testing.T) {
func TestMain(m *testing.M) {
cfg := types.NewChain33Config(types.GetDefaultCfgstring()) cfg := types.NewChain33Config(types.GetDefaultCfgstring())
cfg.GetModuleConfig().Consensus.Name = "ticket" cfg.GetModuleConfig().Consensus.Name = "ticket"
mocker = testnode.NewWithConfig(cfg, nil) mocker := testnode.NewWithConfig(cfg, nil)
mocker.Listen() mocker.Listen()
m.Run() defer mocker.Close()
mocker.Close()
}
func TestJRPCChannel(t *testing.T) {
jrpcClient := mocker.GetJSONC() jrpcClient := mocker.GetJSONC()
testCases := []struct { testCases := []struct {
......
...@@ -13,10 +13,18 @@ import ( ...@@ -13,10 +13,18 @@ import (
_ "github.com/33cn/plugin/plugin" _ "github.com/33cn/plugin/plugin"
ty "github.com/33cn/plugin/plugin/dapp/ticket/types" ty "github.com/33cn/plugin/plugin/dapp/ticket/types"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/util/testnode"
) )
func TestNewTicket(t *testing.T) { func TestNewTicket(t *testing.T) {
//选票(可以用hotwallet 关闭选票) //选票(可以用hotwallet 关闭选票)
cfg := types.NewChain33Config(types.GetDefaultCfgstring())
cfg.GetModuleConfig().Consensus.Name = "ticket"
mocker := testnode.NewWithConfig(cfg, nil)
mocker.Listen()
defer mocker.Close()
in := &ty.TicketClose{MinerAddress: mocker.GetHotAddress()} in := &ty.TicketClose{MinerAddress: mocker.GetHotAddress()}
var res rpctypes.ReplyHashes var res rpctypes.ReplyHashes
err := mocker.GetJSONC().Call("ticket.CloseTickets", in, &res) err := mocker.GetJSONC().Call("ticket.CloseTickets", in, &res)
......
...@@ -116,8 +116,7 @@ func newJrpc(api client.QueueProtocolAPI) *Jrpc { ...@@ -116,8 +116,7 @@ func newJrpc(api client.QueueProtocolAPI) *Jrpc {
} }
func TestChannelClient_BindMiner(t *testing.T) { func TestChannelClient_BindMiner(t *testing.T) {
cfg := types.NewChain33Config(types.GetDefaultCfgstring()) cfg := types.NewChain33Config(cfgstring)
cfg.SetTitleOnlyForTest("test")
api := new(mocks.QueueProtocolAPI) api := new(mocks.QueueProtocolAPI)
api.On("GetConfig", mock.Anything).Return(cfg, nil) api.On("GetConfig", mock.Anything).Return(cfg, nil)
client := newGrpc(api) client := newGrpc(api)
...@@ -131,10 +130,6 @@ func TestChannelClient_BindMiner(t *testing.T) { ...@@ -131,10 +130,6 @@ func TestChannelClient_BindMiner(t *testing.T) {
storevalue.Values = append(storevalue.Values, accv) storevalue.Values = append(storevalue.Values, accv)
api.On("StoreGet", mock.Anything).Return(storevalue, nil).Twice() api.On("StoreGet", mock.Anything).Return(storevalue, nil).Twice()
//cfg, _ := types.InitCfgString(cfgstring)
//types.Init("test", cfg)
//var addrs = make([]string, 1) //var addrs = make([]string, 1)
//addrs = append(addrs, "1Jn2qu84Z1SUUosWjySggBS9pKWdAP3tZt") //addrs = append(addrs, "1Jn2qu84Z1SUUosWjySggBS9pKWdAP3tZt")
var in = &ty.ReqBindMiner{ var in = &ty.ReqBindMiner{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment