github.com/turingchain2020/turingchain@v1.1.21/client/queueprotocol_test.go (about)

     1  // Copyright Turing Corp. 2018 All Rights Reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package client_test
     6  
     7  import (
     8  	"os"
     9  	"testing"
    10  	"time"
    11  
    12  	"github.com/turingchain2020/turingchain/client"
    13  	"github.com/turingchain2020/turingchain/common/version"
    14  	"github.com/turingchain2020/turingchain/pluginmgr"
    15  	"github.com/turingchain2020/turingchain/queue"
    16  	rpctypes "github.com/turingchain2020/turingchain/rpc/types"
    17  	_ "github.com/turingchain2020/turingchain/system"
    18  	"github.com/turingchain2020/turingchain/types"
    19  	"github.com/stretchr/testify/assert"
    20  	"github.com/stretchr/testify/require"
    21  )
    22  
    23  var (
    24  	mock     mockSystem
    25  	api      client.QueueProtocolAPI
    26  	jrpc     mockJRPCSystem
    27  	grpcMock mockGRPCSystem
    28  )
    29  
    30  func TestMain(m *testing.M) {
    31  	mock.grpcMock = &grpcMock
    32  	mock.jrpcMock = &jrpc
    33  	cfg := types.NewTuringchainConfig(types.GetDefaultCfgstring())
    34  	pluginmgr.InitExec(cfg)
    35  	api = mock.startup(0)
    36  	flag := m.Run()
    37  	mock.stop()
    38  	os.Exit(flag)
    39  }
    40  
    41  func TestQueueProtocolAPI(t *testing.T) {
    42  	var option client.QueueProtocolOption
    43  	option.SendTimeout = time.Millisecond
    44  	option.WaitTimeout = 2 * time.Millisecond
    45  
    46  	_, err := client.New(nil, nil)
    47  	if err == nil {
    48  		t.Error("client.New(nil, nil) need return error")
    49  	}
    50  
    51  	var q = queue.New("channel")
    52  	qc, err := client.New(q.Client(), &option)
    53  	if err != nil {
    54  		t.Errorf("client.New() cause error %v", err)
    55  	}
    56  	if qc == nil {
    57  		t.Error("queueprotoapi object is nil")
    58  	}
    59  	_, err = qc.Notify("", 1, "data")
    60  	assert.Nil(t, err)
    61  
    62  }
    63  
    64  func TestQueueProtocol(t *testing.T) {
    65  	testSendTx(t, api)
    66  	testGetTxList(t, api)
    67  	testGetBlocks(t, api)
    68  	testGetTransactionByAddr(t, api)
    69  	testQueryTx(t, api)
    70  	testGetTransactionByHash(t, api)
    71  	testGetMempool(t, api)
    72  	testPeerInfo(t, api)
    73  	testGetHeaders(t, api)
    74  	testGetLastMempool(t, api)
    75  	testGetProperFee(t, api)
    76  	testGetBlockOverview(t, api)
    77  	testGetAddrOverview(t, api)
    78  	testGetBlockHash(t, api)
    79  	testGetBlockByHashes(t, api)
    80  	testGetBlockSequences(t, api)
    81  	testAddSeqCallBack(t, api)
    82  	testListSeqCallBack(t, api)
    83  	testGetSeqCallBackLastNum(t, api)
    84  	testGetLastBlockSequence(t, api)
    85  	testIsSync(t, api)
    86  	testIsNtpClockSync(t, api)
    87  	testLocalGet(t, api)
    88  	testLocalTransaction(t, api)
    89  	testLocalList(t, api)
    90  	testGetLastHeader(t, api)
    91  	testStoreSet(t, api)
    92  	testStoreGet(t, api)
    93  	testStoreMemSet(t, api)
    94  	testStoreCommit(t, api)
    95  	testStoreRollback(t, api)
    96  	testStoreDel(t, api)
    97  	testStoreGetTotalCoins(t, api)
    98  	testStoreList(t, api)
    99  	testBlockChainQuery(t, api)
   100  	testQueryConsensus(t, api)
   101  	testExecWalletFunc(t, api)
   102  	testGetSequenceByHash(t, api)
   103  }
   104  
   105  func testGetSequenceByHash(t *testing.T, api client.QueueProtocolAPI) {
   106  	_, err := api.GetSequenceByHash(nil)
   107  	assert.Equal(t, types.ErrInvalidParam, err)
   108  	res, err := api.GetSequenceByHash(&types.ReqHash{})
   109  	assert.Nil(t, err)
   110  	assert.Equal(t, &types.Int64{Data: 1}, res)
   111  }
   112  
   113  func testBlockChainQuery(t *testing.T, api client.QueueProtocolAPI) {
   114  	testCases := []struct {
   115  		param     *types.ChainExecutor
   116  		actualRes types.Message
   117  		actualErr error
   118  	}{
   119  		{
   120  			actualErr: types.ErrInvalidParam,
   121  		},
   122  		{
   123  			param:     &types.ChainExecutor{},
   124  			actualRes: &types.Reply{},
   125  		},
   126  	}
   127  	for index, test := range testCases {
   128  		res, err := api.QueryChain(test.param)
   129  		require.Equalf(t, err, test.actualErr, "testBlockChainQuery case index %d", index)
   130  		require.Equalf(t, res, test.actualRes, "testBlockChainQuery case index %d", index)
   131  	}
   132  
   133  	_, err := api.Query("", "", nil)
   134  	assert.EqualError(t, types.ErrInvalidParam, err.Error())
   135  	res, err := api.Query("", "", testCases[1].param)
   136  	assert.Nil(t, err)
   137  	assert.Equal(t, res, testCases[1].actualRes)
   138  }
   139  
   140  func testQueryConsensus(t *testing.T, api client.QueueProtocolAPI) {
   141  	testCases := []struct {
   142  		param     *types.ChainExecutor
   143  		actualRes types.Message
   144  		actualErr error
   145  	}{
   146  		{
   147  			actualErr: types.ErrInvalidParam,
   148  		},
   149  		{
   150  			param:     &types.ChainExecutor{},
   151  			actualRes: &types.Reply{},
   152  		},
   153  	}
   154  	for index, test := range testCases {
   155  		res, err := api.QueryConsensus(test.param)
   156  		require.Equalf(t, err, test.actualErr, "testQueryConsensus case index %d", index)
   157  		require.Equalf(t, res, test.actualRes, "testQueryConsensus case index %d", index)
   158  	}
   159  
   160  	_, err := api.QueryConsensusFunc("", "", nil)
   161  	assert.EqualError(t, types.ErrInvalidParam, err.Error())
   162  	res, err := api.QueryConsensusFunc("", "", testCases[1].param)
   163  	assert.Nil(t, err)
   164  	assert.Equal(t, res, testCases[1].actualRes)
   165  }
   166  
   167  func testExecWalletFunc(t *testing.T, api client.QueueProtocolAPI) {
   168  	testCases := []struct {
   169  		param     *types.ChainExecutor
   170  		actualRes types.Message
   171  		actualErr error
   172  	}{
   173  		{
   174  			actualErr: types.ErrInvalidParam,
   175  		},
   176  		{
   177  			param:     &types.ChainExecutor{},
   178  			actualRes: &types.Reply{},
   179  		},
   180  	}
   181  	for index, test := range testCases {
   182  		res, err := api.ExecWallet(test.param)
   183  		require.Equalf(t, err, test.actualErr, "testQueryConsensus case index %d", index)
   184  		require.Equalf(t, res, test.actualRes, "testQueryConsensus case index %d", index)
   185  	}
   186  
   187  	_, err := api.ExecWalletFunc("", "", nil)
   188  	assert.EqualError(t, types.ErrInvalidParam, err.Error())
   189  	res, err := api.ExecWalletFunc("", "", testCases[1].param)
   190  	assert.Nil(t, err)
   191  	assert.Equal(t, res, testCases[1].actualRes)
   192  }
   193  
   194  func testGetBlockByHashes(t *testing.T, api client.QueueProtocolAPI) {
   195  	_, err := api.GetBlockByHashes(nil)
   196  	assert.EqualError(t, types.ErrInvalidParam, err.Error())
   197  	res, err := api.GetBlockByHashes(&types.ReqHashes{Hashes: [][]byte{}})
   198  	assert.Nil(t, err)
   199  	assert.Equal(t, &types.BlockDetails{}, res)
   200  }
   201  
   202  func testGetBlockSequences(t *testing.T, api client.QueueProtocolAPI) {
   203  	_, err := api.GetBlockSequences(nil)
   204  	assert.EqualError(t, types.ErrInvalidParam, err.Error())
   205  	res, err := api.GetBlockSequences(&types.ReqBlocks{Start: 0, End: 1})
   206  	assert.Nil(t, err)
   207  	assert.Equal(t, &types.BlockSequences{}, res)
   208  }
   209  
   210  func testAddSeqCallBack(t *testing.T, api client.QueueProtocolAPI) {
   211  	res, err := api.AddPushSubscribe(&types.PushSubscribeReq{})
   212  	assert.Nil(t, err)
   213  	assert.Equal(t, &types.ReplySubscribePush{}, res)
   214  }
   215  
   216  func testListSeqCallBack(t *testing.T, api client.QueueProtocolAPI) {
   217  	res, err := api.ListPushes()
   218  	assert.Nil(t, err)
   219  	assert.Equal(t, &types.PushSubscribes{}, res)
   220  }
   221  
   222  func testGetSeqCallBackLastNum(t *testing.T, api client.QueueProtocolAPI) {
   223  	res, err := api.GetPushSeqLastNum(&types.ReqString{})
   224  	assert.Nil(t, err)
   225  	assert.Equal(t, &types.Int64{}, res)
   226  }
   227  
   228  func testStoreSet(t *testing.T, api client.QueueProtocolAPI) {
   229  	_, err := api.StoreSet(&types.StoreSetWithSync{})
   230  	if err != nil {
   231  		t.Error("Call StoreSet Failed.", err)
   232  	}
   233  
   234  	_, err = api.StoreSet(nil)
   235  	if err == nil {
   236  		t.Error("StoreSet(nil) need return error.")
   237  	}
   238  }
   239  
   240  func testStoreGet(t *testing.T, api client.QueueProtocolAPI) {
   241  	_, err := api.StoreGet(&types.StoreGet{})
   242  	if err != nil {
   243  		t.Error("Call StoreGet Failed.", err)
   244  	}
   245  
   246  	_, err = api.StoreGet(nil)
   247  	if err == nil {
   248  		t.Error("StoreGet(nil) need return error.")
   249  	}
   250  }
   251  
   252  func testStoreMemSet(t *testing.T, api client.QueueProtocolAPI) {
   253  	_, err := api.StoreMemSet(&types.StoreSetWithSync{})
   254  	if err != nil {
   255  		t.Error("Call StoreMemSet Failed.", err)
   256  	}
   257  
   258  	_, err = api.StoreMemSet(nil)
   259  	if err == nil {
   260  		t.Error("StoreMemSet(nil) need return error.")
   261  	}
   262  }
   263  
   264  func testStoreCommit(t *testing.T, api client.QueueProtocolAPI) {
   265  	_, err := api.StoreCommit(&types.ReqHash{})
   266  	if err != nil {
   267  		t.Error("Call StoreCommit Failed.", err)
   268  	}
   269  
   270  	_, err = api.StoreCommit(nil)
   271  	if err == nil {
   272  		t.Error("StoreCommit(nil) need return error.")
   273  	}
   274  }
   275  
   276  func testStoreRollback(t *testing.T, api client.QueueProtocolAPI) {
   277  	_, err := api.StoreRollback(&types.ReqHash{})
   278  	if err != nil {
   279  		t.Error("Call StoreRollback Failed.", err)
   280  	}
   281  
   282  	_, err = api.StoreRollback(nil)
   283  	if err == nil {
   284  		t.Error("StoreRollback(nil) need return error.")
   285  	}
   286  }
   287  
   288  func testStoreDel(t *testing.T, api client.QueueProtocolAPI) {
   289  	_, err := api.StoreDel(&types.StoreDel{})
   290  	if err != nil {
   291  		t.Error("Call StoreDel Failed.", err)
   292  	}
   293  
   294  	_, err = api.StoreDel(nil)
   295  	if err == nil {
   296  		t.Error("StoreDel(nil) need return error.")
   297  	}
   298  }
   299  
   300  func testStoreGetTotalCoins(t *testing.T, api client.QueueProtocolAPI) {
   301  	_, err := api.StoreGetTotalCoins(&types.IterateRangeByStateHash{})
   302  	if err != nil {
   303  		t.Error("Call StoreGetTotalCoins Failed.", err)
   304  	}
   305  	_, err = api.StoreGetTotalCoins(nil)
   306  	if err == nil {
   307  		t.Error("StoreGetTotalCoins(nil) need return error.")
   308  	}
   309  	_, err = api.StoreGetTotalCoins(&types.IterateRangeByStateHash{Count: 10})
   310  	if err == nil {
   311  		t.Error("StoreGetTotalCoins(&types.IterateRangeByStateHash{Count:10}) need return error.")
   312  	}
   313  }
   314  
   315  func testStoreList(t *testing.T, api client.QueueProtocolAPI) {
   316  	_, err := api.StoreList(&types.StoreList{})
   317  	if err == nil {
   318  		t.Error("Call StoreList Failed.", err)
   319  	}
   320  
   321  	_, err = api.StoreList(nil)
   322  	if err == nil {
   323  		t.Error("StoreList(nil) need return error.")
   324  	}
   325  }
   326  
   327  func testGetLastHeader(t *testing.T, api client.QueueProtocolAPI) {
   328  	_, err := api.GetLastHeader()
   329  	if err != nil {
   330  		t.Error("Call GetLastHeader Failed.", err)
   331  	}
   332  }
   333  
   334  func testLocalGet(t *testing.T, api client.QueueProtocolAPI) {
   335  	_, err := api.LocalGet(nil)
   336  	if nil == err {
   337  		t.Error("LocalGet(nil) need return error.")
   338  	}
   339  	_, err = api.LocalGet(&types.LocalDBGet{})
   340  	if err != nil {
   341  		t.Error("Call LocalGet Failed.", err)
   342  	}
   343  }
   344  
   345  func testLocalList(t *testing.T, api client.QueueProtocolAPI) {
   346  	_, err := api.LocalList(nil)
   347  	if nil == err {
   348  		t.Error("LocalList(nil) need return error.")
   349  	}
   350  	_, err = api.LocalList(&types.LocalDBList{})
   351  	if nil != err {
   352  		t.Error("Call LocalList Failed.", err)
   353  	}
   354  }
   355  
   356  func testLocalTransaction(t *testing.T, api client.QueueProtocolAPI) {
   357  	txid, err := api.LocalNew(false)
   358  	assert.Nil(t, err)
   359  	assert.Equal(t, txid.Data, int64(9999))
   360  	err = api.LocalBegin(txid)
   361  	assert.Nil(t, err)
   362  	err = api.LocalCommit(nil)
   363  	assert.Equal(t, types.ErrInvalidParam, err)
   364  	err = api.LocalCommit(txid)
   365  	assert.Nil(t, err)
   366  	err = api.LocalRollback(nil)
   367  	assert.Equal(t, types.ErrInvalidParam, err)
   368  	err = api.LocalRollback(txid)
   369  	assert.Nil(t, err)
   370  	err = api.LocalSet(nil)
   371  	assert.Equal(t, types.ErrInvalidParam, err)
   372  	param := &types.LocalDBSet{Txid: txid.Data}
   373  	err = api.LocalSet(param)
   374  	assert.Nil(t, err)
   375  	err = api.LocalClose(txid)
   376  	assert.Nil(t, err)
   377  }
   378  
   379  func testIsNtpClockSync(t *testing.T, api client.QueueProtocolAPI) {
   380  	_, err := api.IsNtpClockSync()
   381  	if err != nil {
   382  		t.Error("Call IsNtpClockSync Failed.", err)
   383  	}
   384  }
   385  
   386  func testIsSync(t *testing.T, api client.QueueProtocolAPI) {
   387  	_, err := api.IsSync()
   388  	if err != nil {
   389  		t.Error("Call IsSync Failed.", err)
   390  	}
   391  }
   392  
   393  func testGetBlockHash(t *testing.T, api client.QueueProtocolAPI) {
   394  	_, err := api.GetBlockHash(&types.ReqInt{})
   395  	if err != nil {
   396  		t.Error("Call GetBlockHash Failed.", err)
   397  	}
   398  	_, err = api.GetBlockHash(nil)
   399  	if err == nil {
   400  		t.Error("GetBlockHash(nil) need return error.")
   401  	}
   402  	_, err = api.GetBlockHash(&types.ReqInt{Height: 10})
   403  	if err == nil {
   404  		t.Error("GetBlockHash(&types.ReqInt{Height:10}) need return error.")
   405  	}
   406  }
   407  
   408  func testGetAddrOverview(t *testing.T, api client.QueueProtocolAPI) {
   409  	_, err := api.GetAddrOverview(&types.ReqAddr{})
   410  	if err != nil {
   411  		t.Error("Call GetAddrOverview Failed.", err)
   412  	}
   413  	_, err = api.GetAddrOverview(nil)
   414  	if err == nil {
   415  		t.Error("GetAddrOverview(nil) need return error.")
   416  	}
   417  	_, err = api.GetAddrOverview(&types.ReqAddr{Addr: "case1"})
   418  	if err == nil {
   419  		t.Error("GetAddrOverview(&types.ReqAddr{Addr:\"case1\"}) need return error.")
   420  	}
   421  }
   422  
   423  func testGetBlockOverview(t *testing.T, api client.QueueProtocolAPI) {
   424  	_, err := api.GetBlockOverview(&types.ReqHash{})
   425  	if err != nil {
   426  		t.Error("Call GetBlockOverview Failed.", err)
   427  	}
   428  	_, err = api.GetBlockOverview(nil)
   429  	if err == nil {
   430  		t.Error("GetBlockOverview(nil) need return error.")
   431  	}
   432  	_, err = api.GetBlockOverview(&types.ReqHash{Hash: []byte("case1")})
   433  	if err == nil {
   434  		t.Error("GetBlockOverview(&types.ReqHash{Hash:[]byte(\"case1\")}) need return error.")
   435  	}
   436  }
   437  
   438  func testGetLastMempool(t *testing.T, api client.QueueProtocolAPI) {
   439  	_, err := api.GetLastMempool()
   440  	if err != nil {
   441  		t.Error("Call GetLastMempool Failed.", err)
   442  	}
   443  }
   444  
   445  func testGetProperFee(t *testing.T, api client.QueueProtocolAPI) {
   446  	_, err := api.GetProperFee(nil)
   447  	if err != nil {
   448  		t.Error("Call GetProperFee Failed.", err)
   449  	}
   450  	_, err = api.GetProperFee(&types.ReqProperFee{})
   451  	if err != nil {
   452  		t.Error("Call GetProperFee Failed.", err)
   453  	}
   454  }
   455  
   456  func testGetHeaders(t *testing.T, api client.QueueProtocolAPI) {
   457  	_, err := api.GetHeaders(&types.ReqBlocks{})
   458  	if err != nil {
   459  		t.Error("Call GetHeaders Failed.", err)
   460  	}
   461  	_, err = api.GetHeaders(nil)
   462  	if err == nil {
   463  		t.Error("GetHeaders(nil) need return error.")
   464  	}
   465  	_, err = api.GetHeaders(&types.ReqBlocks{Start: 10})
   466  	if err == nil {
   467  		t.Error("GetHeaders(&types.ReqBlocks{Start:10}) need return error.")
   468  	}
   469  }
   470  
   471  func testPeerInfo(t *testing.T, api client.QueueProtocolAPI) {
   472  	_, err := api.PeerInfo(&types.P2PGetPeerReq{})
   473  	if err != nil {
   474  		t.Error("Call PeerInfo Failed.", err)
   475  	}
   476  }
   477  
   478  func testGetMempool(t *testing.T, api client.QueueProtocolAPI) {
   479  	req := types.ReqGetMempool{IsAll: false}
   480  	_, err := api.GetMempool(&req)
   481  	if err != nil {
   482  		t.Error("Call GetMempool Failed.", err)
   483  	}
   484  }
   485  
   486  func testGetTransactionByHash(t *testing.T, api client.QueueProtocolAPI) {
   487  	hashs := types.ReqHashes{}
   488  	hashs.Hashes = make([][]byte, 1)
   489  
   490  	_, err := api.GetTransactionByHash(&hashs)
   491  	if err != nil {
   492  		t.Error("Call GetTransactionByHash Failed.", err)
   493  	}
   494  	_, err = api.GetTransactionByHash(nil)
   495  	if err == nil {
   496  		t.Error("GetTransactionByHash(nil) need return error.")
   497  	}
   498  
   499  	hashs.Hashes[0] = []byte("case1")
   500  	_, err = api.GetTransactionByHash(&hashs)
   501  	if err == nil {
   502  		t.Error("GetTransactionByHash(&hashs) need return error.")
   503  	}
   504  }
   505  
   506  func testQueryTx(t *testing.T, api client.QueueProtocolAPI) {
   507  	_, err := api.QueryTx(&types.ReqHash{})
   508  	if err != nil {
   509  		t.Error("Call QueryTx Failed.", err)
   510  	}
   511  	_, err = api.QueryTx(nil)
   512  	if err == nil {
   513  		t.Error("QueryTx(nil) need return error.")
   514  	}
   515  	_, err = api.QueryTx(&types.ReqHash{Hash: []byte("case1")})
   516  	if err == nil {
   517  		t.Error("QueryTx(&ReqHash{Hash:[]byte(\"case1\")}) need return error.")
   518  	}
   519  }
   520  
   521  func testGetTransactionByAddr(t *testing.T, api client.QueueProtocolAPI) {
   522  	_, err := api.GetTransactionByAddr(&types.ReqAddr{})
   523  	if err != nil {
   524  		t.Error("Call GetTransactionByAddr Failed.", err)
   525  	}
   526  	_, err = api.GetTransactionByAddr(nil)
   527  	if err == nil {
   528  		t.Error("GetTransactionByAddr(nil) need return error.")
   529  	}
   530  	_, err = api.GetTransactionByAddr(&types.ReqAddr{Flag: 1})
   531  	if err == nil {
   532  		t.Error("GetTransactionByAddr(&types.ReqAddr{Flag:1}) need return error.")
   533  	}
   534  }
   535  
   536  func testGetBlocks(t *testing.T, api client.QueueProtocolAPI) {
   537  	_, err := api.GetBlocks(&types.ReqBlocks{})
   538  	if err != nil {
   539  		t.Error("Call GetBlocks Failed.", err)
   540  	}
   541  	_, err = api.GetBlocks(nil)
   542  	if err == nil {
   543  		t.Error("GetBlocks(nil) need return error.")
   544  	}
   545  	_, err = api.GetBlocks(&types.ReqBlocks{Start: 1})
   546  	if err == nil {
   547  		t.Error("GetBlocks(&types.ReqBlocks{Start:1}) need return error.")
   548  	}
   549  }
   550  
   551  func testGetLastBlockSequence(t *testing.T, api client.QueueProtocolAPI) {
   552  	res, err := api.GetLastBlockSequence()
   553  	assert.Nil(t, err)
   554  	assert.Equal(t, &types.Int64{}, res)
   555  }
   556  
   557  func testGetTxList(t *testing.T, api client.QueueProtocolAPI) {
   558  	_, err := api.GetTxList(&types.TxHashList{})
   559  	if err != nil {
   560  		t.Error("Call GetTxList Failed.", err)
   561  	}
   562  	_, err = api.GetTxList(nil)
   563  	if err == nil {
   564  		t.Error("GetTxList(nil) need return error.")
   565  	}
   566  	_, err = api.GetTxList(&types.TxHashList{Count: 1})
   567  	if err == nil {
   568  		t.Error("SendTx(&types.TxHashList{Count:1}) need return error.")
   569  	}
   570  }
   571  
   572  func testSendTx(t *testing.T, api client.QueueProtocolAPI) {
   573  	_, err := api.SendTx(&types.Transaction{})
   574  	if err != nil {
   575  		t.Error("Call SendTx Failed.", err)
   576  	}
   577  	_, err = api.SendTx(nil)
   578  	if err == nil {
   579  		t.Error("SendTx(nil) need return error.")
   580  	}
   581  	_, err = api.SendTx(&types.Transaction{Execer: []byte("case1")})
   582  	if err == nil {
   583  		t.Error("SendTx(&types.Transaction{Execer:[]byte(\"case1\")}) need return error.")
   584  	}
   585  	_, err = api.SendTx(&types.Transaction{Execer: []byte("case2")})
   586  	if err == nil {
   587  		t.Error("SendTx(&types.Transaction{Execer:[]byte(\"case2\")}) need return error.")
   588  	}
   589  }
   590  
   591  func TestJsonRPC(t *testing.T) {
   592  	testGetBlocksJSONRPC(t, &jrpc)
   593  	testGetBlockOverviewJSONRPC(t, &jrpc)
   594  	testGetBlockHashJSONRPC(t, &jrpc)
   595  	testGetHeadersCmdJSONRPC(t, &jrpc)
   596  	testGetLastHeaderJSONRPC(t, &jrpc)
   597  	testGetMempoolJSONRPC(t, &jrpc)
   598  	testGetLastMemPoolJSONRPC(t, &jrpc)
   599  	testGetProperFeeJSONRPC(t, &jrpc)
   600  	testGenSeedJSONRPC(t, &jrpc)
   601  	testGetPeerInfoJSONRPC(t, &jrpc)
   602  	testIsNtpClockSyncJSONRPC(t, &jrpc)
   603  	testIsSyncJSONRPC(t, &jrpc)
   604  	testGetNetInfoJSONRPC(t, &jrpc)
   605  	testGetWalletStatusJSONRPC(t, &jrpc)
   606  	testDumpPrivkeyJSONRPC(t, &jrpc)
   607  	testDumpPrivkeysFileJSONRPC(t, &jrpc)
   608  	testImportPrivkeysFileJSONRPC(t, &jrpc)
   609  	testGetAccountsJSONRPC(t, &jrpc)
   610  }
   611  
   612  func testGetAccountsJSONRPC(t *testing.T, rpc *mockJRPCSystem) {
   613  	var res rpctypes.WalletAccounts
   614  	err := rpc.newRPCCtx("Turingchain.GetAccounts", &types.ReqNil{}, &res)
   615  	if err != nil {
   616  		t.Error("testGetAccountsJSONRPC Failed.", err)
   617  	}
   618  }
   619  
   620  func testDumpPrivkeyJSONRPC(t *testing.T, rpc *mockJRPCSystem) {
   621  	var res types.ReplyString
   622  	err := rpc.newRPCCtx("Turingchain.DumpPrivkey", &types.ReqString{}, &res)
   623  	if err != nil {
   624  		t.Error("testDumpPrivkeyJSONRPC Failed.", err)
   625  	}
   626  }
   627  
   628  func testDumpPrivkeysFileJSONRPC(t *testing.T, rpc *mockJRPCSystem) {
   629  	var res rpctypes.Reply
   630  	err := rpc.newRPCCtx("Turingchain.DumpPrivkeysFile", &types.ReqPrivkeysFile{}, &res)
   631  	if err != nil {
   632  		t.Error("testDumpPrivkeysFileJSONRPC Failed.", err)
   633  	}
   634  }
   635  
   636  func testImportPrivkeysFileJSONRPC(t *testing.T, rpc *mockJRPCSystem) {
   637  	var res rpctypes.Reply
   638  	err := rpc.newRPCCtx("Turingchain.ImportPrivkeysFile", &types.ReqPrivkeysFile{}, &res)
   639  	if err != nil {
   640  		t.Error("testImportPrivkeysFileJSONRPC Failed.", err)
   641  	}
   642  }
   643  
   644  func testGetWalletStatusJSONRPC(t *testing.T, rpc *mockJRPCSystem) {
   645  	var res rpctypes.WalletStatus
   646  	err := rpc.newRPCCtx("Turingchain.GetWalletStatus", &types.ReqNil{}, &res)
   647  	if err != nil {
   648  		t.Error("testGetWalletStatusJSONRPC Failed.", err)
   649  	} else {
   650  		if res.IsTicketLock || res.IsAutoMining || !res.IsHasSeed || !res.IsWalletLock {
   651  			t.Error("testGetWalletStatusJSONRPC return type error.")
   652  		}
   653  	}
   654  }
   655  
   656  func testGetNetInfoJSONRPC(t *testing.T, rpc *mockJRPCSystem) {
   657  	var res rpctypes.NodeNetinfo
   658  	err := rpc.newRPCCtx("Turingchain.GetNetInfo",
   659  		types.P2PGetNetInfoReq{}, &res)
   660  	if err != nil {
   661  		t.Error("testGetNetInfoJSONRPC failed. Error", err)
   662  	}
   663  }
   664  
   665  func testIsSyncJSONRPC(t *testing.T, rpc *mockJRPCSystem) {
   666  	var res bool
   667  	err := rpc.newRPCCtx("Turingchain.IsSync",
   668  		nil, &res)
   669  	if err != nil {
   670  		t.Error("testIsSyncJSONRPC failed. Error", err)
   671  	}
   672  }
   673  
   674  func testIsNtpClockSyncJSONRPC(t *testing.T, rpc *mockJRPCSystem) {
   675  	var res bool
   676  	err := rpc.newRPCCtx("Turingchain.IsNtpClockSync",
   677  		nil, &res)
   678  	if err != nil {
   679  		t.Error("testIsNtpClockSyncJSONRPC failed. Error", err)
   680  	}
   681  }
   682  
   683  func testGetPeerInfoJSONRPC(t *testing.T, rpc *mockJRPCSystem) {
   684  	var res types.PeerList
   685  	err := rpc.newRPCCtx("Turingchain.GetPeerInfo",
   686  		types.P2PGetPeerReq{}, &res)
   687  	if err != nil {
   688  		t.Error("testGetPeerInfoJSONRPC failed. Error", err)
   689  	}
   690  }
   691  
   692  func testGenSeedJSONRPC(t *testing.T, rpc *mockJRPCSystem) {
   693  	params := types.GenSeedLang{
   694  		Lang: 1,
   695  	}
   696  	var res types.ReplySeed
   697  	err := rpc.newRPCCtx("Turingchain.GenSeed",
   698  		params, &res)
   699  	if err != nil {
   700  		t.Error("testGenSeedJSONRPC failed. Error", err)
   701  	}
   702  }
   703  
   704  func testGetLastMemPoolJSONRPC(t *testing.T, rpc *mockJRPCSystem) {
   705  	var res rpctypes.ReplyTxList
   706  	err := rpc.newRPCCtx("Turingchain.GetLastMemPool",
   707  		nil, &res)
   708  	if err != nil {
   709  		t.Error("testGetLastMemPoolJSONRPC failed. Error", err)
   710  	}
   711  }
   712  
   713  func testGetProperFeeJSONRPC(t *testing.T, rpc *mockJRPCSystem) {
   714  	var res rpctypes.ReplyProperFee
   715  	err := rpc.newRPCCtx("Turingchain.GetProperFee",
   716  		nil, &res)
   717  	if err != nil {
   718  		t.Error("testGetProperFeeJSONRPC failed. Error", err)
   719  	}
   720  }
   721  
   722  func testGetMempoolJSONRPC(t *testing.T, rpc *mockJRPCSystem) {
   723  	var res rpctypes.ReplyTxList
   724  	err := rpc.newRPCCtx("Turingchain.GetMempool",
   725  		nil, &res)
   726  	if err != nil {
   727  		t.Error("testGetMempoolJSONRPC failed. Error", err)
   728  	}
   729  }
   730  
   731  func testGetLastHeaderJSONRPC(t *testing.T, rpc *mockJRPCSystem) {
   732  	var res rpctypes.Header
   733  	err := rpc.newRPCCtx("Turingchain.GetLastHeader",
   734  		nil, &res)
   735  	if err != nil {
   736  		t.Error("testGetLastHeaderJSONRPC failed. Error", err)
   737  	}
   738  }
   739  
   740  func testGetHeadersCmdJSONRPC(t *testing.T, rpc *mockJRPCSystem) {
   741  	params := types.ReqBlocks{
   742  		Start:    1,
   743  		End:      1,
   744  		IsDetail: true,
   745  	}
   746  
   747  	var res rpctypes.Headers
   748  	err := rpc.newRPCCtx("Turingchain.GetHeaders",
   749  		params, &res)
   750  	if err != nil {
   751  		t.Error("testGetHeadersCmdJSONRPC failed. Error", err)
   752  	}
   753  }
   754  
   755  func testGetBlockOverviewJSONRPC(t *testing.T, rpc *mockJRPCSystem) {
   756  	params := rpctypes.QueryParm{
   757  		Hash: "0x67c58d6ba9175313f0468ae4e0ddec946549af7748037c2fdd5d54298afd20b6",
   758  	}
   759  
   760  	var res rpctypes.BlockOverview
   761  	err := rpc.newRPCCtx("Turingchain.GetBlockOverview",
   762  		params, &res)
   763  	if err != nil {
   764  		t.Error("testGetBlockOverviewJSONRPC failed. Error", err)
   765  	}
   766  }
   767  
   768  func testGetBlocksJSONRPC(t *testing.T, rpc *mockJRPCSystem) {
   769  	params := rpctypes.BlockParam{
   770  		Start:    100,
   771  		End:      1000,
   772  		Isdetail: true,
   773  	}
   774  
   775  	var res rpctypes.BlockDetails
   776  	err := rpc.newRPCCtx("Turingchain.GetBlocks",
   777  		params, &res)
   778  	if err != nil {
   779  		t.Error("testGetBlocksJSONRPC failed. Error", err)
   780  	}
   781  }
   782  
   783  func testGetBlockHashJSONRPC(t *testing.T, rpc *mockJRPCSystem) {
   784  	params := types.ReqInt{
   785  		Height: 100,
   786  	}
   787  	var res rpctypes.ReplyHash
   788  	err := rpc.newRPCCtx("Turingchain.GetBlockHash",
   789  		params, &res)
   790  	if err != nil {
   791  		t.Error("testGetBlockHashJSONRPC failed. Error", err)
   792  	}
   793  }
   794  
   795  func TestGRPC(t *testing.T) {
   796  	testSendTxGRPC(t, &grpcMock)
   797  	testGetBlocksGRPC(t, &grpcMock)
   798  	testGetLastHeaderGRPC(t, &grpcMock)
   799  	testCreateRawTransactionGRPC(t, &grpcMock)
   800  	testQueryTransactionGRPC(t, &grpcMock)
   801  	testSendTransactionGRPC(t, &grpcMock)
   802  	testGetTransactionByAddrGRPC(t, &grpcMock)
   803  	testGetTransactionByHashesGRPC(t, &grpcMock)
   804  	testGetMemPoolGRPC(t, &grpcMock)
   805  	testGetAccountsGRPC(t, &grpcMock)
   806  	testNewAccountGRPC(t, &grpcMock)
   807  	testWalletTransactionListGRPC(t, &grpcMock)
   808  	testImportPrivKeyGRPC(t, &grpcMock)
   809  	testSendToAddressGRPC(t, &grpcMock)
   810  	testSetTxFeeGRPC(t, &grpcMock)
   811  	testSetLablGRPC(t, &grpcMock)
   812  	testMergeBalanceGRPC(t, &grpcMock)
   813  	testSetPasswdGRPC(t, &grpcMock)
   814  	testLockGRPC(t, &grpcMock)
   815  	testUnLockGRPC(t, &grpcMock)
   816  	testGetPeerInfoGRPC(t, &grpcMock)
   817  	testGetLastMemPoolGRPC(t, &grpcMock)
   818  	testGetProperFeeGRPC(t, &grpcMock)
   819  	testGetWalletStatusGRPC(t, &grpcMock)
   820  	testGetBlockOverviewGRPC(t, &grpcMock)
   821  	testGetAddrOverviewGRPC(t, &grpcMock)
   822  	testGetBlockHashGRPC(t, &grpcMock)
   823  	testGetSequenceByHashGRPC(t, &grpcMock)
   824  	testGetBlockBySeqGRPC(t, &grpcMock)
   825  	testGenSeedGRPC(t, &grpcMock)
   826  	testGetSeedGRPC(t, &grpcMock)
   827  	testSaveSeedGRPC(t, &grpcMock)
   828  	testGetBalanceGRPC(t, &grpcMock)
   829  	testQueryChainGRPC(t, &grpcMock)
   830  	testGetHexTxByHashGRPC(t, &grpcMock)
   831  	testDumpPrivkeyGRPC(t, &grpcMock)
   832  	testDumpPrivkeysFileGRPC(t, &grpcMock)
   833  	testImportPrivkeysFileGRPC(t, &grpcMock)
   834  	testVersionGRPC(t, &grpcMock)
   835  	testIsSyncGRPC(t, &grpcMock)
   836  	testIsNtpClockSyncGRPC(t, &grpcMock)
   837  	testNetInfoGRPC(t, &grpcMock)
   838  	testGetParaTxByTitleGRPC(t, &grpcMock)
   839  	testLoadParaTxByTitleGRPC(t, &grpcMock)
   840  	testGetParaTxByHeightGRPC(t, &grpcMock)
   841  }
   842  
   843  func testNetInfoGRPC(t *testing.T, rpc *mockGRPCSystem) {
   844  	var res types.NodeNetInfo
   845  	err := rpc.newRPCCtx("NetInfo", &types.P2PGetNetInfoReq{}, &res)
   846  	if err != nil {
   847  		t.Error("Call NetInfo Failed.", err)
   848  	}
   849  }
   850  
   851  func testIsNtpClockSyncGRPC(t *testing.T, rpc *mockGRPCSystem) {
   852  	var res types.Reply
   853  	err := rpc.newRPCCtx("IsNtpClockSync", &types.ReqNil{}, &res)
   854  	if err != nil {
   855  		t.Error("Call IsNtpClockSync Failed.", err)
   856  	}
   857  }
   858  
   859  func testIsSyncGRPC(t *testing.T, rpc *mockGRPCSystem) {
   860  	var res types.Reply
   861  	err := rpc.newRPCCtx("IsSync", &types.ReqNil{}, &res)
   862  	if err != nil {
   863  		t.Error("Call IsSync Failed.", err)
   864  	}
   865  }
   866  
   867  func testVersionGRPC(t *testing.T, rpc *mockGRPCSystem) {
   868  	var res types.VersionInfo
   869  	err := rpc.newRPCCtx("Version", &types.ReqNil{}, &res)
   870  	if err != nil {
   871  		t.Error("Call Version Failed.", err)
   872  	}
   873  	assert.Equal(t, version.GetVersion(), res.Turingchain)
   874  }
   875  
   876  func testDumpPrivkeyGRPC(t *testing.T, rpc *mockGRPCSystem) {
   877  	var res types.ReplyString
   878  	err := rpc.newRPCCtx("DumpPrivkey", &types.ReqString{}, &res)
   879  	if err != nil {
   880  		t.Error("Call DumpPrivkey Failed.", err)
   881  	}
   882  }
   883  
   884  func testDumpPrivkeysFileGRPC(t *testing.T, rpc *mockGRPCSystem) {
   885  	var res types.Reply
   886  	err := rpc.newRPCCtx("DumpPrivkeysFile", &types.ReqPrivkeysFile{}, &res)
   887  	if err != nil {
   888  		t.Error("Call DumpPrivkeysFile Failed.", err)
   889  	}
   890  }
   891  
   892  func testImportPrivkeysFileGRPC(t *testing.T, rpc *mockGRPCSystem) {
   893  	var res types.Reply
   894  	err := rpc.newRPCCtx("ImportPrivkeysFile", &types.ReqPrivkeysFile{}, &res)
   895  	if err != nil {
   896  		t.Error("Call ImportPrivkeysFile Failed.", err)
   897  	}
   898  }
   899  
   900  func testGetHexTxByHashGRPC(t *testing.T, rpc *mockGRPCSystem) {
   901  	var res types.HexTx
   902  	err := rpc.newRPCCtx("GetHexTxByHash", &types.ReqHash{Hash: []byte("fdafdsafds")}, &res)
   903  	if err != nil {
   904  		t.Error("Call GetHexTxByHash Failed.", err)
   905  	}
   906  }
   907  
   908  func testQueryChainGRPC(t *testing.T, rpc *mockGRPCSystem) {
   909  	var res types.Reply
   910  	err := rpc.newRPCCtx("QueryChain", &types.ChainExecutor{}, &res)
   911  	if err != nil {
   912  		t.Error("Call QueryChain Failed.", err)
   913  	}
   914  }
   915  
   916  func testGetBalanceGRPC(t *testing.T, rpc *mockGRPCSystem) {
   917  	var res types.Accounts
   918  	err := rpc.newRPCCtx("GetBalance", &types.ReqBalance{}, &res)
   919  	if err != nil {
   920  		t.Error("Call GetBalance Failed.", err)
   921  	}
   922  }
   923  
   924  func testSaveSeedGRPC(t *testing.T, rpc *mockGRPCSystem) {
   925  	var res types.Reply
   926  	err := rpc.newRPCCtx("SaveSeed", &types.SaveSeedByPw{}, &res)
   927  	if err != nil {
   928  		t.Error("Call SaveSeed Failed.", err)
   929  	}
   930  }
   931  
   932  func testGetSeedGRPC(t *testing.T, rpc *mockGRPCSystem) {
   933  	var res types.ReplySeed
   934  	err := rpc.newRPCCtx("GetSeed", &types.GetSeedByPw{}, &res)
   935  	if err != nil {
   936  		t.Error("Call GetSeed Failed.", err)
   937  	}
   938  }
   939  
   940  func testGenSeedGRPC(t *testing.T, rpc *mockGRPCSystem) {
   941  	var res types.ReplySeed
   942  	err := rpc.newRPCCtx("GenSeed", &types.GenSeedLang{}, &res)
   943  	if err != nil {
   944  		t.Error("Call GenSeed Failed.", err)
   945  	}
   946  }
   947  
   948  func testGetBlockHashGRPC(t *testing.T, rpc *mockGRPCSystem) {
   949  	var res types.ReplyHash
   950  	err := rpc.newRPCCtx("GetBlockHash", &types.ReqInt{}, &res)
   951  	if err != nil {
   952  		t.Error("Call GetBlockHash Failed.", err)
   953  	}
   954  }
   955  
   956  func testGetAddrOverviewGRPC(t *testing.T, rpc *mockGRPCSystem) {
   957  	var res types.AddrOverview
   958  	err := rpc.newRPCCtx("GetAddrOverview", &types.ReqAddr{Addr: "13cS5G1BDN2YfGudsxRxr7X25yu6ZdgxMU"}, &res)
   959  	if err != nil {
   960  		t.Error("Call GetAddrOverview Failed.", err)
   961  	}
   962  }
   963  
   964  func testGetBlockOverviewGRPC(t *testing.T, rpc *mockGRPCSystem) {
   965  	var res types.BlockOverview
   966  	err := rpc.newRPCCtx("GetBlockOverview", &types.ReqHash{}, &res)
   967  	if err != nil {
   968  		t.Error("Call GetBlockOverview Failed.", err)
   969  	}
   970  }
   971  
   972  func testGetWalletStatusGRPC(t *testing.T, rpc *mockGRPCSystem) {
   973  	var res types.WalletStatus
   974  	err := rpc.newRPCCtx("GetWalletStatus", &types.ReqNil{}, &res)
   975  	if err != nil {
   976  		t.Error("Call GetWalletStatus Failed.", err)
   977  	}
   978  }
   979  
   980  func testGetLastMemPoolGRPC(t *testing.T, rpc *mockGRPCSystem) {
   981  	var res types.ReplyTxList
   982  	err := rpc.newRPCCtx("GetLastMemPool", &types.ReqNil{}, &res)
   983  	if err != nil {
   984  		t.Error("Call GetLastMemPool Failed.", err)
   985  	}
   986  }
   987  
   988  func testGetProperFeeGRPC(t *testing.T, rpc *mockGRPCSystem) {
   989  	var res types.ReplyProperFee
   990  	err := rpc.newRPCCtx("GetProperFee", &types.ReqProperFee{}, &res)
   991  	if err != nil {
   992  		t.Error("Call GetProperFee Failed.", err)
   993  	}
   994  }
   995  
   996  func testGetPeerInfoGRPC(t *testing.T, rpc *mockGRPCSystem) {
   997  	var res types.PeerList
   998  	err := rpc.newRPCCtx("GetPeerInfo", &types.P2PGetPeerReq{}, &res)
   999  	if err != nil {
  1000  		t.Error("Call GetPeerInfo Failed.", err)
  1001  	}
  1002  }
  1003  
  1004  func testUnLockGRPC(t *testing.T, rpc *mockGRPCSystem) {
  1005  	var res types.Reply
  1006  	err := rpc.newRPCCtx("UnLock", &types.WalletUnLock{}, &res)
  1007  	if err != nil {
  1008  		t.Error("Call UnLock Failed.", err)
  1009  	}
  1010  }
  1011  
  1012  func testLockGRPC(t *testing.T, rpc *mockGRPCSystem) {
  1013  	var res types.Reply
  1014  	err := rpc.newRPCCtx("Lock", &types.ReqNil{}, &res)
  1015  	if err != nil {
  1016  		t.Error("Call Lock Failed.", err)
  1017  	}
  1018  }
  1019  
  1020  func testSetPasswdGRPC(t *testing.T, rpc *mockGRPCSystem) {
  1021  	var res types.Reply
  1022  	err := rpc.newRPCCtx("SetPasswd", &types.ReqWalletSetPasswd{}, &res)
  1023  	if err != nil {
  1024  		t.Error("Call SetPasswd Failed.", err)
  1025  	}
  1026  }
  1027  
  1028  func testMergeBalanceGRPC(t *testing.T, rpc *mockGRPCSystem) {
  1029  	var res types.ReplyHashes
  1030  	err := rpc.newRPCCtx("MergeBalance", &types.ReqWalletMergeBalance{}, &res)
  1031  	if err != nil {
  1032  		t.Error("Call MergeBalance Failed.", err)
  1033  	}
  1034  }
  1035  
  1036  func testSetLablGRPC(t *testing.T, rpc *mockGRPCSystem) {
  1037  	var res types.WalletAccount
  1038  	err := rpc.newRPCCtx("SetLabl", &types.ReqWalletSetLabel{}, &res)
  1039  	if err != nil {
  1040  		t.Error("Call SetLabl Failed.", err)
  1041  	}
  1042  }
  1043  
  1044  func testSetTxFeeGRPC(t *testing.T, rpc *mockGRPCSystem) {
  1045  	var res types.Reply
  1046  	err := rpc.newRPCCtx("SetTxFee", &types.ReqWalletSetFee{}, &res)
  1047  	if err != nil {
  1048  		t.Error("Call SetTxFee Failed.", err)
  1049  	}
  1050  }
  1051  
  1052  func testSendToAddressGRPC(t *testing.T, rpc *mockGRPCSystem) {
  1053  	var res types.ReplyHash
  1054  	err := rpc.newRPCCtx("SendToAddress", &types.ReqWalletSendToAddress{}, &res)
  1055  	if err != nil {
  1056  		t.Error("Call SendToAddress Failed.", err)
  1057  	}
  1058  }
  1059  
  1060  func testImportPrivKeyGRPC(t *testing.T, rpc *mockGRPCSystem) {
  1061  	var res types.WalletAccount
  1062  	err := rpc.newRPCCtx("ImportPrivkey", &types.ReqWalletImportPrivkey{}, &res)
  1063  	if err != nil {
  1064  		t.Error("Call ImportPrivKey Failed.", err)
  1065  	}
  1066  }
  1067  
  1068  func testWalletTransactionListGRPC(t *testing.T, rpc *mockGRPCSystem) {
  1069  	var res types.WalletTxDetails
  1070  	err := rpc.newRPCCtx("WalletTransactionList", &types.ReqWalletTransactionList{}, &res)
  1071  	if err != nil {
  1072  		t.Error("Call WalletTransactionList Failed.", err)
  1073  	}
  1074  }
  1075  
  1076  func testNewAccountGRPC(t *testing.T, rpc *mockGRPCSystem) {
  1077  	var res types.WalletAccount
  1078  	err := rpc.newRPCCtx("NewAccount", &types.ReqNewAccount{}, &res)
  1079  	if err != nil {
  1080  		t.Error("Call NewAccount Failed.", err)
  1081  	}
  1082  }
  1083  
  1084  func testGetAccountsGRPC(t *testing.T, rpc *mockGRPCSystem) {
  1085  	var res types.WalletAccounts
  1086  	err := rpc.newRPCCtx("GetAccounts", &types.ReqNil{}, &res)
  1087  	if err != nil {
  1088  		t.Error("Call GetAccounts Failed.", err)
  1089  	}
  1090  }
  1091  
  1092  func testGetMemPoolGRPC(t *testing.T, rpc *mockGRPCSystem) {
  1093  	var res types.ReplyTxList
  1094  	err := rpc.newRPCCtx("GetMemPool", &types.ReqGetMempool{}, &res)
  1095  	if err != nil {
  1096  		t.Error("Call GetMemPool Failed.", err)
  1097  	}
  1098  }
  1099  
  1100  func testGetTransactionByHashesGRPC(t *testing.T, rpc *mockGRPCSystem) {
  1101  	var res types.TransactionDetails
  1102  	err := rpc.newRPCCtx("GetTransactionByHashes", &types.ReqHashes{}, &res)
  1103  	if err != nil {
  1104  		t.Error("Call GetTransactionByHashes Failed.", err)
  1105  	}
  1106  }
  1107  
  1108  func testGetTransactionByAddrGRPC(t *testing.T, rpc *mockGRPCSystem) {
  1109  	var res types.ReplyTxInfos
  1110  	err := rpc.newRPCCtx("GetTransactionByAddr", &types.ReqAddr{}, &res)
  1111  	if err != nil {
  1112  		t.Error("Call GetTransactionByAddr Failed.", err)
  1113  	}
  1114  }
  1115  
  1116  func testSendTransactionGRPC(t *testing.T, rpc *mockGRPCSystem) {
  1117  	var res types.Reply
  1118  	err := rpc.newRPCCtx("SendTransaction", &types.Transaction{}, &res)
  1119  	if err != nil {
  1120  		t.Error("Call SendTransaction Failed.", err)
  1121  	}
  1122  }
  1123  
  1124  func testQueryTransactionGRPC(t *testing.T, rpc *mockGRPCSystem) {
  1125  	var res types.TransactionDetail
  1126  	err := rpc.newRPCCtx("QueryTransaction", &types.ReqHash{}, &res)
  1127  	if err != nil {
  1128  		t.Error("Call QueryTransaction Failed.", err)
  1129  	}
  1130  }
  1131  
  1132  func testCreateRawTransactionGRPC(t *testing.T, rpc *mockGRPCSystem) {
  1133  	var res types.UnsignTx
  1134  	err := rpc.newRPCCtx("CreateRawTransaction",
  1135  		&types.CreateTx{To: "1EDDghAtgBsamrNEtNmYdQzC1QEhLkr87t",
  1136  			Amount:     10000000,
  1137  			Fee:        1000000,
  1138  			IsWithdraw: false,
  1139  			IsToken:    false,
  1140  			ExecName:   "coins",
  1141  		},
  1142  		&res)
  1143  	if err != nil {
  1144  		t.Error("Call CreateRawTransaction Failed.", err)
  1145  	}
  1146  }
  1147  
  1148  func testGetLastHeaderGRPC(t *testing.T, rpc *mockGRPCSystem) {
  1149  	var res types.Header
  1150  	err := rpc.newRPCCtx("GetLastHeader", &types.ReqNil{}, &res)
  1151  	if err != nil {
  1152  		t.Error("Call GetLastHeader Failed.", err)
  1153  	}
  1154  }
  1155  
  1156  func testGetBlocksGRPC(t *testing.T, rpc *mockGRPCSystem) {
  1157  	var res types.Reply
  1158  	err := rpc.newRPCCtx("GetBlocks", &types.ReqBlocks{}, &res)
  1159  	if err != nil {
  1160  		t.Error("Call GetBlocks Failed.", err)
  1161  	}
  1162  }
  1163  
  1164  func testSendTxGRPC(t *testing.T, rpc *mockGRPCSystem) {
  1165  	var res types.Reply
  1166  	err := rpc.newRPCCtx("SendTransaction", &types.Transaction{}, &res)
  1167  	if err != nil {
  1168  		t.Error("Call SendTransaction Failed.", err)
  1169  	}
  1170  }
  1171  
  1172  func testGetSequenceByHashGRPC(t *testing.T, rpc *mockGRPCSystem) {
  1173  	var res types.Int64
  1174  	err := rpc.newRPCCtx("GetSequenceByHash", &types.ReqHash{}, &res)
  1175  	if err != nil {
  1176  		t.Error("Call GetSequenceByHash Failed.", err)
  1177  	}
  1178  }
  1179  
  1180  func testGetBlockBySeqGRPC(t *testing.T, rpc *mockGRPCSystem) {
  1181  	var res types.BlockSeq
  1182  	//just for coverage
  1183  	err := rpc.newRPCCtx("GetBlockBySeq", &types.Int64{Data: 1}, &res)
  1184  	assert.Nil(t, err)
  1185  
  1186  	err = rpc.newRPCCtx("GetBlockBySeq", &types.Int64{Data: 10}, &res)
  1187  	assert.NotNil(t, err)
  1188  
  1189  }
  1190  
  1191  func TestGetBlockBySeq(t *testing.T) {
  1192  	q := client.QueueProtocol{}
  1193  	_, err := q.GetBlockBySeq(nil)
  1194  	assert.NotNil(t, err)
  1195  
  1196  }
  1197  
  1198  func TestGetMainSeq(t *testing.T) {
  1199  	net := queue.New("test-seq-api")
  1200  	defer net.Close()
  1201  
  1202  	chain := &mockBlockChain{}
  1203  	chain.SetQueueClient(net)
  1204  	defer chain.Close()
  1205  
  1206  	api, err := client.New(net.Client(), nil)
  1207  	assert.Nil(t, err)
  1208  
  1209  	seq, err := api.GetMainSequenceByHash(&types.ReqHash{Hash: []byte("exist-hash")})
  1210  	assert.Nil(t, err)
  1211  	assert.Equal(t, int64(9999), seq.Data)
  1212  
  1213  	seq, err = api.GetMainSequenceByHash(&types.ReqHash{Hash: []byte("")})
  1214  	assert.NotNil(t, err)
  1215  
  1216  	seq1, err := api.GetLastBlockMainSequence()
  1217  	assert.Nil(t, err)
  1218  	assert.Equal(t, int64(9999), seq1.Data)
  1219  }
  1220  
  1221  func testGetParaTxByTitleGRPC(t *testing.T, rpc *mockGRPCSystem) {
  1222  	var res types.ParaTxDetails
  1223  	var req types.ReqParaTxByTitle
  1224  	req.Start = 0
  1225  	req.End = 0
  1226  	req.Title = "user"
  1227  	err := rpc.newRPCCtx("GetParaTxByTitle", &req, &res)
  1228  	assert.NotNil(t, err)
  1229  
  1230  	req.Title = "user.p.para."
  1231  	err = rpc.newRPCCtx("GetParaTxByTitle", &req, &res)
  1232  	assert.Nil(t, err)
  1233  
  1234  }
  1235  
  1236  func TestGetParaTxByTitle(t *testing.T) {
  1237  	q := client.QueueProtocol{}
  1238  	_, err := q.GetParaTxByTitle(nil)
  1239  	assert.NotNil(t, err)
  1240  
  1241  }
  1242  
  1243  func testLoadParaTxByTitleGRPC(t *testing.T, rpc *mockGRPCSystem) {
  1244  	var res types.ReplyHeightByTitle
  1245  	var req types.ReqHeightByTitle
  1246  	req.Count = 1
  1247  	req.Direction = 0
  1248  	req.Title = "user"
  1249  	req.Height = 0
  1250  
  1251  	err := rpc.newRPCCtx("LoadParaTxByTitle", &req, &res)
  1252  	assert.NotNil(t, err)
  1253  
  1254  	req.Title = "user.p.para."
  1255  	err = rpc.newRPCCtx("LoadParaTxByTitle", &req, &res)
  1256  	assert.Nil(t, err)
  1257  }
  1258  
  1259  func TestLoadParaTxByTitle(t *testing.T) {
  1260  	q := client.QueueProtocol{}
  1261  	_, err := q.LoadParaTxByTitle(nil)
  1262  	assert.NotNil(t, err)
  1263  }
  1264  
  1265  func testGetParaTxByHeightGRPC(t *testing.T, rpc *mockGRPCSystem) {
  1266  	var res types.ParaTxDetails
  1267  	var req types.ReqParaTxByHeight
  1268  	req.Items = append(req.Items, 0)
  1269  	req.Title = "user"
  1270  	err := rpc.newRPCCtx("GetParaTxByHeight", &req, &res)
  1271  	assert.NotNil(t, err)
  1272  
  1273  	req.Title = "user.p.para."
  1274  	err = rpc.newRPCCtx("GetParaTxByHeight", &req, &res)
  1275  	assert.Nil(t, err)
  1276  }
  1277  
  1278  func TestGetParaTxByHeight(t *testing.T) {
  1279  	q := client.QueueProtocol{}
  1280  	_, err := q.GetParaTxByHeight(nil)
  1281  	assert.NotNil(t, err)
  1282  }