github.com/turingchain2020/turingchain@v1.1.21/client/mock_store_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 mockStore struct {
    13  }
    14  
    15  func (m *mockStore) SetQueueClient(q queue.Queue) {
    16  	go func() {
    17  		client := q.Client()
    18  		client.Sub("store")
    19  		for msg := range client.Recv() {
    20  			switch msg.Ty {
    21  			case types.EventStoreSet:
    22  				msg.Reply(client.NewMessage("store", types.EventStoreSetReply, &types.ReplyHash{}))
    23  			case types.EventStoreGet:
    24  				msg.Reply(client.NewMessage("store", types.EventStoreGetReply, &types.StoreReplyValue{}))
    25  			case types.EventStoreMemSet:
    26  				msg.Reply(client.NewMessage("store", types.EventStoreSetReply, &types.ReplyHash{}))
    27  			case types.EventStoreCommit:
    28  				msg.Reply(client.NewMessage("store", types.EventStoreCommit, &types.ReplyHash{}))
    29  			case types.EventStoreRollback:
    30  				msg.Reply(client.NewMessage("store", types.EventStoreRollback, &types.ReplyHash{}))
    31  			case types.EventStoreDel:
    32  				msg.Reply(client.NewMessage("store", types.EventStoreDel, &types.ReplyHash{}))
    33  			case types.EventStoreGetTotalCoins:
    34  				if req, ok := msg.GetData().(*types.IterateRangeByStateHash); ok {
    35  					if req.Count == 10 {
    36  						msg.Reply(client.NewMessage("store", types.EventStoreGetReply, &types.Transaction{}))
    37  					} else {
    38  						msg.Reply(client.NewMessage("store", types.EventStoreGetReply, &types.ReplyGetTotalCoins{}))
    39  					}
    40  				} else {
    41  					msg.ReplyErr("Do not support", types.ErrInvalidParam)
    42  				}
    43  			default:
    44  				msg.ReplyErr("Do not support", types.ErrNotSupport)
    45  			}
    46  		}
    47  	}()
    48  }
    49  
    50  func (m *mockStore) Close() {
    51  }