github.com/turingchain2020/turingchain@v1.1.21/client/mock_wallet_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  	"github.com/turingchain2020/turingchain/queue"
     9  	"github.com/turingchain2020/turingchain/types"
    10  )
    11  
    12  type mockWallet struct {
    13  }
    14  
    15  func (m *mockWallet) SetQueueClient(q queue.Queue) {
    16  	go func() {
    17  		walletKey := "wallet"
    18  		client := q.Client()
    19  		client.Sub(walletKey)
    20  		for msg := range client.Recv() {
    21  			switch msg.Ty {
    22  			case types.EventCloseTickets:
    23  				msg.Reply(client.NewMessage(walletKey, types.EventReplyHashes, &types.ReplyHashes{}))
    24  			case types.EventLocalGet:
    25  				msg.Reply(client.NewMessage(walletKey, types.EventLocalReplyValue, &types.LocalReplyValue{}))
    26  			case types.EventLocalList:
    27  				msg.Reply(client.NewMessage(walletKey, types.EventLocalReplyValue, &types.LocalReplyValue{}))
    28  			case types.EventWalletExecutor:
    29  				if req, ok := msg.GetData().(*types.ChainExecutor); ok {
    30  					switch req.FuncName {
    31  					case "WalletGetAccountList":
    32  						msg.Reply(client.NewMessage(walletKey, types.EventReply, &types.WalletAccounts{}))
    33  					case "NewAccount":
    34  						msg.Reply(client.NewMessage(walletKey, types.EventReply, &types.WalletAccount{}))
    35  					case "WalletTransactionList":
    36  						msg.Reply(client.NewMessage(walletKey, types.EventReply, &types.WalletTxDetails{}))
    37  					case "WalletImportPrivkey":
    38  						msg.Reply(client.NewMessage(walletKey, types.EventReply, &types.WalletAccount{}))
    39  					case "DumpPrivkey":
    40  						msg.Reply(client.NewMessage(walletKey, types.EventReply, &types.ReplyString{}))
    41  					case "WalletSendToAddress":
    42  						msg.Reply(client.NewMessage(walletKey, types.EventReply, &types.ReplyHash{}))
    43  					case "WalletSetLabel":
    44  						msg.Reply(client.NewMessage(walletKey, types.EventReply, &types.WalletAccount{}))
    45  					case "WalletMergeBalance":
    46  						msg.Reply(client.NewMessage(walletKey, types.EventReply, &types.ReplyHashes{}))
    47  					case "GenSeed":
    48  						msg.Reply(client.NewMessage(walletKey, types.EventReply, &types.ReplySeed{}))
    49  					case "GetSeed":
    50  						msg.Reply(client.NewMessage(walletKey, types.EventReply, &types.ReplySeed{}))
    51  					case "GetWalletStatus":
    52  						msg.Reply(client.NewMessage(walletKey, types.EventReplyWalletStatus, &types.WalletStatus{IsWalletLock: true, IsAutoMining: false, IsHasSeed: true, IsTicketLock: false}))
    53  					case "SignRawTx":
    54  						msg.Reply(client.NewMessage(walletKey, types.EventReply, &types.ReplySignRawTx{}))
    55  					case "FatalFailure":
    56  						msg.Reply(client.NewMessage(walletKey, types.EventReply, &types.Int32{}))
    57  					default:
    58  						msg.Reply(client.NewMessage(walletKey, types.EventReply, &types.Reply{}))
    59  					}
    60  				} else {
    61  					msg.ReplyErr("Do not support", types.ErrInvalidParam)
    62  				}
    63  			default:
    64  				msg.ReplyErr("Do not support", types.ErrNotSupport)
    65  			}
    66  		}
    67  	}()
    68  }
    69  
    70  func (m *mockWallet) Close() {
    71  }