github.com/Blockdaemon/celo-blockchain@v0.0.0-20200129231733-e667f6b08419/consensus/consensustest/mockprotocol.go (about)

     1  // Copyright 2017 The Celo Authors
     2  // This file is part of the celo library.
     3  //
     4  // The celo library is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU Lesser General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // The celo library is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    12  // GNU Lesser General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU Lesser General Public License
    15  // along with the celo library. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  package consensustest
    18  
    19  import (
    20  	"crypto/ecdsa"
    21  	"net"
    22  
    23  	"github.com/ethereum/go-ethereum/common/hexutil"
    24  	"github.com/ethereum/go-ethereum/consensus"
    25  	"github.com/ethereum/go-ethereum/core/types"
    26  	"github.com/ethereum/go-ethereum/crypto"
    27  	"github.com/ethereum/go-ethereum/p2p"
    28  	"github.com/ethereum/go-ethereum/p2p/enode"
    29  )
    30  
    31  type MockBroadcaster struct{}
    32  
    33  func (b *MockBroadcaster) Enqueue(id string, block *types.Block) {
    34  }
    35  
    36  func (b *MockBroadcaster) FindPeers(targets map[enode.ID]bool, purpose p2p.PurposeFlag) map[enode.ID]consensus.Peer {
    37  	return make(map[enode.ID]consensus.Peer)
    38  }
    39  
    40  type MockP2PServer struct {
    41  	Node *enode.Node
    42  }
    43  
    44  func NewMockP2PServer() *MockP2PServer {
    45  	mockNode := enode.NewV4(
    46  		&ecdsa.PublicKey{
    47  			Curve: crypto.S256(),
    48  			X:     hexutil.MustDecodeBig("0x760c4460e5336ac9bbd87952a3c7ec4363fc0a97bd31c86430806e287b437fd1"),
    49  			Y:     hexutil.MustDecodeBig("0xb01abc6e1db640cf3106b520344af1d58b00b57823db3e1407cbc433e1b6d04d")},
    50  		net.IP{192, 168, 0, 1},
    51  		30303,
    52  		30303)
    53  
    54  	return &MockP2PServer{Node: mockNode}
    55  }
    56  
    57  func (serv *MockP2PServer) Self() *enode.Node {
    58  	return serv.Node
    59  }
    60  
    61  func (serv *MockP2PServer) AddPeer(node *enode.Node, purpose p2p.PurposeFlag) {}
    62  
    63  func (serv *MockP2PServer) RemovePeer(node *enode.Node, purpose p2p.PurposeFlag) {}
    64  
    65  func (serv *MockP2PServer) AddTrustedPeer(node *enode.Node, purpose p2p.PurposeFlag) {}
    66  
    67  func (serv *MockP2PServer) RemoveTrustedPeer(node *enode.Node, purpose p2p.PurposeFlag) {}