2018-03-14 09:36:59 +00:00
|
|
|
package network
|
|
|
|
|
|
|
|
import (
|
2019-08-23 15:19:07 +00:00
|
|
|
"math/rand"
|
2019-09-09 14:54:38 +00:00
|
|
|
"net"
|
2018-03-14 09:36:59 +00:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2019-02-20 17:39:32 +00:00
|
|
|
"github.com/CityOfZion/neo-go/config"
|
2018-03-14 09:36:59 +00:00
|
|
|
"github.com/CityOfZion/neo-go/pkg/core"
|
2019-02-20 17:39:32 +00:00
|
|
|
"github.com/CityOfZion/neo-go/pkg/core/transaction"
|
2018-03-14 09:36:59 +00:00
|
|
|
"github.com/CityOfZion/neo-go/pkg/network/payload"
|
|
|
|
"github.com/CityOfZion/neo-go/pkg/util"
|
|
|
|
)
|
|
|
|
|
|
|
|
type testChain struct{}
|
|
|
|
|
2019-02-20 17:39:32 +00:00
|
|
|
func (chain testChain) GetConfig() config.ProtocolConfiguration {
|
|
|
|
panic("TODO")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (chain testChain) References(t *transaction.Transaction) map[util.Uint256]*transaction.Output {
|
|
|
|
panic("TODO")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (chain testChain) FeePerByte(t *transaction.Transaction) util.Fixed8 {
|
|
|
|
panic("TODO")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (chain testChain) SystemFee(t *transaction.Transaction) util.Fixed8 {
|
|
|
|
panic("TODO")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (chain testChain) NetworkFee(t *transaction.Transaction) util.Fixed8 {
|
|
|
|
panic("TODO")
|
|
|
|
}
|
|
|
|
|
2018-03-14 09:36:59 +00:00
|
|
|
func (chain testChain) AddHeaders(...*core.Header) error {
|
2019-02-20 17:39:32 +00:00
|
|
|
panic("TODO")
|
2018-03-14 09:36:59 +00:00
|
|
|
}
|
|
|
|
func (chain testChain) AddBlock(*core.Block) error {
|
2019-02-20 17:39:32 +00:00
|
|
|
panic("TODO")
|
2018-03-14 09:36:59 +00:00
|
|
|
}
|
|
|
|
func (chain testChain) BlockHeight() uint32 {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
func (chain testChain) HeaderHeight() uint32 {
|
|
|
|
return 0
|
|
|
|
}
|
2018-03-23 20:36:59 +00:00
|
|
|
func (chain testChain) GetBlock(hash util.Uint256) (*core.Block, error) {
|
2019-02-20 17:39:32 +00:00
|
|
|
panic("TODO")
|
2018-03-23 20:36:59 +00:00
|
|
|
}
|
2018-03-14 09:36:59 +00:00
|
|
|
func (chain testChain) GetHeaderHash(int) util.Uint256 {
|
|
|
|
return util.Uint256{}
|
|
|
|
}
|
2019-02-20 17:39:32 +00:00
|
|
|
func (chain testChain) GetHeader(hash util.Uint256) (*core.Header, error) {
|
|
|
|
panic("TODO")
|
|
|
|
}
|
|
|
|
|
2018-11-26 21:12:33 +00:00
|
|
|
func (chain testChain) GetAssetState(util.Uint256) *core.AssetState {
|
2019-02-20 17:39:32 +00:00
|
|
|
panic("TODO")
|
2018-11-26 21:12:33 +00:00
|
|
|
}
|
2019-02-08 08:04:38 +00:00
|
|
|
func (chain testChain) GetAccountState(util.Uint160) *core.AccountState {
|
2019-02-20 17:39:32 +00:00
|
|
|
panic("TODO")
|
2019-02-08 08:04:38 +00:00
|
|
|
}
|
2018-03-14 09:36:59 +00:00
|
|
|
func (chain testChain) CurrentHeaderHash() util.Uint256 {
|
|
|
|
return util.Uint256{}
|
|
|
|
}
|
|
|
|
func (chain testChain) CurrentBlockHash() util.Uint256 {
|
|
|
|
return util.Uint256{}
|
|
|
|
}
|
|
|
|
func (chain testChain) HasBlock(util.Uint256) bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
func (chain testChain) HasTransaction(util.Uint256) bool {
|
|
|
|
return false
|
|
|
|
}
|
2019-02-20 17:39:32 +00:00
|
|
|
func (chain testChain) GetTransaction(util.Uint256) (*transaction.Transaction, uint32, error) {
|
|
|
|
panic("TODO")
|
|
|
|
}
|
2018-03-14 09:36:59 +00:00
|
|
|
|
Implement rpc server method: sendrawtransaction (#174)
* Added new config attributes: 'SecondsPerBlock','LowPriorityThreshold'
* Added new files:
* Added new method: CompareTo
* Fixed empty Slice case
* Added new methods: LessThan, GreaterThan, Equal, CompareTo
* Added new method: InputIntersection
* Added MaxTransactionSize, GroupOutputByAssetID
* Added ned method: ScriptHash
* Added new method: IsDoubleSpend
* Refactor blockchainer, Added Feer interface, Verify and GetMemPool method
* 1) Added MemPool
2) Added new methods to satisfy the blockchainer interface: IsLowPriority, Verify, GetMemPool
* Added new methods: RelayTxn, RelayDirectly
* Fixed tests
* Implemented RPC server method sendrawtransaction
* Refactor getrawtransaction, sendrawtransaction in separate methods
* Moved 'secondsPerBlock' to config file
* Implemented Kim suggestions:
1) Fixed data race issues
2) refactor Verify method
3) Get rid of unused InputIntersection method due to refactoring Verify method
4) Fixed bug in https://github.com/CityOfZion/neo-go/pull/174#discussion_r264108135
5) minor simplications of the code
* Fixed minor issues related to
1) space
2) getter methods do not need pointer on the receiver
3) error message
4) refactoring CompareTo method in uint256.go
* Fixed small issues
* Use sync.RWMutex instead of sync.Mutex
* Refined (R)Lock/(R)Unlock
* return error instead of bool in Verify methods
2019-03-20 12:30:05 +00:00
|
|
|
func (chain testChain) GetMemPool() core.MemPool {
|
|
|
|
panic("TODO")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (chain testChain) IsLowPriority(*transaction.Transaction) bool {
|
|
|
|
panic("TODO")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (chain testChain) Verify(*transaction.Transaction) error {
|
|
|
|
panic("TODO")
|
|
|
|
}
|
|
|
|
|
2018-03-14 09:36:59 +00:00
|
|
|
type testDiscovery struct{}
|
|
|
|
|
2019-09-13 16:51:58 +00:00
|
|
|
func (d testDiscovery) BackFill(addrs ...string) {}
|
|
|
|
func (d testDiscovery) PoolCount() int { return 0 }
|
|
|
|
func (d testDiscovery) RegisterBadAddr(string) {}
|
|
|
|
func (d testDiscovery) RegisterGoodAddr(string) {}
|
|
|
|
func (d testDiscovery) UnregisterConnectedAddr(string) {}
|
|
|
|
func (d testDiscovery) UnconnectedPeers() []string { return []string{} }
|
|
|
|
func (d testDiscovery) RequestRemote(n int) {}
|
|
|
|
func (d testDiscovery) BadPeers() []string { return []string{} }
|
|
|
|
func (d testDiscovery) GoodPeers() []string { return []string{} }
|
2018-03-14 09:36:59 +00:00
|
|
|
|
|
|
|
type localTransport struct{}
|
|
|
|
|
|
|
|
func (t localTransport) Dial(addr string, timeout time.Duration) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
func (t localTransport) Accept() {}
|
|
|
|
func (t localTransport) Proto() string { return "local" }
|
|
|
|
func (t localTransport) Close() {}
|
|
|
|
|
|
|
|
var defaultMessageHandler = func(t *testing.T, msg *Message) {}
|
|
|
|
|
|
|
|
type localPeer struct {
|
2019-09-09 14:54:38 +00:00
|
|
|
netaddr net.TCPAddr
|
2018-03-14 09:36:59 +00:00
|
|
|
version *payload.Version
|
2019-09-13 12:43:22 +00:00
|
|
|
handshaked bool
|
2018-03-14 09:36:59 +00:00
|
|
|
t *testing.T
|
|
|
|
messageHandler func(t *testing.T, msg *Message)
|
|
|
|
}
|
|
|
|
|
|
|
|
func newLocalPeer(t *testing.T) *localPeer {
|
2019-09-09 14:54:38 +00:00
|
|
|
naddr, _ := net.ResolveTCPAddr("tcp", "0.0.0.0:0")
|
2018-03-14 09:36:59 +00:00
|
|
|
return &localPeer{
|
|
|
|
t: t,
|
2019-09-09 14:54:38 +00:00
|
|
|
netaddr: *naddr,
|
2018-03-14 09:36:59 +00:00
|
|
|
messageHandler: defaultMessageHandler,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-09 14:54:38 +00:00
|
|
|
func (p *localPeer) NetAddr() *net.TCPAddr {
|
|
|
|
return &p.netaddr
|
2018-03-14 09:36:59 +00:00
|
|
|
}
|
|
|
|
func (p *localPeer) Disconnect(err error) {}
|
2018-04-13 10:14:08 +00:00
|
|
|
func (p *localPeer) WriteMsg(msg *Message) error {
|
2018-03-14 09:36:59 +00:00
|
|
|
p.messageHandler(p.t, msg)
|
2018-04-13 10:14:08 +00:00
|
|
|
return nil
|
2018-03-14 09:36:59 +00:00
|
|
|
}
|
|
|
|
func (p *localPeer) Done() chan error {
|
|
|
|
done := make(chan error)
|
|
|
|
return done
|
|
|
|
}
|
|
|
|
func (p *localPeer) Version() *payload.Version {
|
|
|
|
return p.version
|
|
|
|
}
|
2019-09-13 12:43:22 +00:00
|
|
|
func (p *localPeer) HandleVersion(v *payload.Version) error {
|
2018-04-13 10:14:08 +00:00
|
|
|
p.version = v
|
2019-09-13 12:43:22 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
func (p *localPeer) SendVersion(m *Message) error {
|
|
|
|
return p.WriteMsg(m)
|
|
|
|
}
|
|
|
|
func (p *localPeer) SendVersionAck(m *Message) error {
|
|
|
|
return p.WriteMsg(m)
|
|
|
|
}
|
|
|
|
func (p *localPeer) HandleVersionAck() error {
|
|
|
|
p.handshaked = true
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *localPeer) Handshaked() bool {
|
|
|
|
return p.handshaked
|
2018-04-13 10:14:08 +00:00
|
|
|
}
|
2018-03-14 09:36:59 +00:00
|
|
|
|
|
|
|
func newTestServer() *Server {
|
|
|
|
return &Server{
|
2018-03-15 20:45:37 +00:00
|
|
|
ServerConfig: ServerConfig{},
|
|
|
|
chain: testChain{},
|
|
|
|
transport: localTransport{},
|
|
|
|
discovery: testDiscovery{},
|
2019-08-23 15:19:07 +00:00
|
|
|
id: rand.Uint32(),
|
2018-03-15 20:45:37 +00:00
|
|
|
quit: make(chan struct{}),
|
|
|
|
register: make(chan Peer),
|
|
|
|
unregister: make(chan peerDrop),
|
|
|
|
peers: make(map[Peer]bool),
|
2018-03-14 09:36:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|