Skip to content

Commit

Permalink
fix test functions
Browse files Browse the repository at this point in the history
  • Loading branch information
SeienK committed Jan 19, 2018
1 parent 50b8c65 commit 27b8778
Show file tree
Hide file tree
Showing 16 changed files with 231 additions and 161 deletions.
4 changes: 2 additions & 2 deletions blockchain/error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

// TestErrorCodeStringer tests the stringized output for the ErrorCode type.
func DNWTestErrorCodeStringer(t *testing.T) {
func TestErrorCodeStringer(t *testing.T) {
tests := []struct {
in blockchain.ErrorCode
want string
Expand Down Expand Up @@ -69,7 +69,7 @@ func DNWTestErrorCodeStringer(t *testing.T) {
}

// TestRuleError tests the error output for the RuleError type.
func DNWTestRuleError(t *testing.T) {
func TestRuleError(t *testing.T) {
tests := []struct {
in blockchain.RuleError
want string
Expand Down
4 changes: 2 additions & 2 deletions blockchain/stake/error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

// TestErrorCodeStringer tests the stringized output for the ErrorCode type.
func DNWTestErrorCodeStringer(t *testing.T) {
func TestErrorCodeStringer(t *testing.T) {
tests := []struct {
in stake.ErrorCode
want string
Expand Down Expand Up @@ -71,7 +71,7 @@ func DNWTestErrorCodeStringer(t *testing.T) {
}

// TestRuleError tests the error output for the RuleError type.
func DNWTestRuleError(t *testing.T) {
func TestRuleError(t *testing.T) {
tests := []struct {
in stake.RuleError
want string
Expand Down
2 changes: 1 addition & 1 deletion blockchain/stake/staketx.go
Original file line number Diff line number Diff line change
Expand Up @@ -1002,7 +1002,7 @@ func IsSSGen(tx *wire.MsgTx) (bool, error) {
// Ensure that the first output is the correct size.
if len(zeroethOutputScript) != SSGenBlockReferenceOutSize {
return false, stakeRuleError(ErrSSGenBadReference, "First SSGen output "+
"should have been 43 bytes long, but was not")
"should have been 47 bytes long, but was not")
}

// The OP_RETURN output script prefix for block referencing should
Expand Down
25 changes: 13 additions & 12 deletions blockchain/stake/staketx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ func TestIsSSTxErrors(t *testing.T) {

// SSGEN TESTING ------------------------------------------------------------------

func DNWTestIsSSGen(t *testing.T) {
func TestIsSSGen(t *testing.T) {
var ssgen = hcashutil.NewTx(ssgenMsgTx)
ssgen.SetTree(wire.TxTreeStake)
ssgen.SetIndex(0)
Expand Down Expand Up @@ -293,7 +293,7 @@ func DNWTestIsSSGen(t *testing.T) {

}

func DNWTestIsSSGenErrors(t *testing.T) {
func TestIsSSGenErrors(t *testing.T) {
// Initialize the buffer for later manipulation
var buf bytes.Buffer
buf.Grow(ssgenMsgTx.SerializeSize())
Expand Down Expand Up @@ -406,20 +406,20 @@ func DNWTestIsSSGenErrors(t *testing.T) {

testDataPush0Length := bytes.Replace(bufBytes,
[]byte{
0x26, 0x6a, 0x24,
0x2a, 0x6a, 0x28,
0x94, 0x8c, 0x76, 0x5a, 0x69, 0x14, 0xd4, 0x3f,
0x2a, 0x7a, 0xc1, 0x77, 0xda, 0x2c, 0x2f, 0x6b,
0x52, 0xde, 0x3d, 0x7c, 0xda, 0x2c, 0x2f, 0x6b,
0x52, 0xde, 0x3d, 0x7c, 0x52, 0xde, 0x3d, 0x7c,
0x00, 0xe3, 0x23, 0x21,
0x00, 0xe3, 0x23, 0x21, 0x00, 0xe3, 0x23, 0x20,
},
[]byte{
0x25, 0x6a, 0x23,
0x29, 0x6a, 0x27,
0x94, 0x8c, 0x76, 0x5a, 0x69, 0x14, 0xd4, 0x3f,
0x2a, 0x7a, 0xc1, 0x77, 0xda, 0x2c, 0x2f, 0x6b,
0x52, 0xde, 0x3d, 0x7c, 0xda, 0x2c, 0x2f, 0x6b,
0x52, 0xde, 0x3d, 0x7c, 0x52, 0xde, 0x3d, 0x7c,
0x00, 0xe3, 0x23,
0x00, 0xe3, 0x23, 0x21, 0x00, 0xe3, 0x23,
},
1)

Expand All @@ -446,20 +446,20 @@ func DNWTestIsSSGenErrors(t *testing.T) {

testNullData0Prefix := bytes.Replace(bufBytes,
[]byte{
0x26, 0x6a, 0x24,
0x2a, 0x6a, 0x28,
0x94, 0x8c, 0x76, 0x5a, 0x69, 0x14, 0xd4, 0x3f,
0x2a, 0x7a, 0xc1, 0x77, 0xda, 0x2c, 0x2f, 0x6b,
0x52, 0xde, 0x3d, 0x7c, 0xda, 0x2c, 0x2f, 0x6b,
0x52, 0xde, 0x3d, 0x7c, 0x52, 0xde, 0x3d, 0x7c,
0x00, 0xe3, 0x23, 0x21,
0x00, 0xe3, 0x23, 0x21, 0x00, 0xe3, 0x23, 0x20,
},
[]byte{ // This uses an OP_PUSHDATA_1 35-byte push to achieve 36 bytes
0x26, 0x6a, 0x4c, 0x23,
[]byte{ // This uses an OP_PUSHDATA_1 39-byte push to achieve 40 bytes
0x2a, 0x6a, 0x4c, 0x27,
0x94, 0x8c, 0x76, 0x5a, 0x69, 0x14, 0xd4, 0x3f,
0x2a, 0x7a, 0xc1, 0x77, 0xda, 0x2c, 0x2f, 0x6b,
0x52, 0xde, 0x3d, 0x7c, 0xda, 0x2c, 0x2f, 0x6b,
0x52, 0xde, 0x3d, 0x7c, 0x52, 0xde, 0x3d, 0x7c,
0x00, 0xe3, 0x23,
0x00, 0xe3, 0x23, 0x21, 0x00, 0xe3, 0x23,
},
1)

Expand Down Expand Up @@ -1853,7 +1853,7 @@ var ssgenTxOut0 = wire.TxOut{
Version: 0x0000,
PkScript: []byte{
0x6a, // OP_RETURN
0x24, // 36 bytes to be pushed
0x28, // 40 bytes to be pushed
0x94, 0x8c, 0x76, 0x5a, // 32 byte hash
0x69, 0x14, 0xd4, 0x3f,
0x2a, 0x7a, 0xc1, 0x77,
Expand All @@ -1863,6 +1863,7 @@ var ssgenTxOut0 = wire.TxOut{
0x52, 0xde, 0x3d, 0x7c,
0x52, 0xde, 0x3d, 0x7c,
0x00, 0xe3, 0x23, 0x21, // 4 byte height
0x00, 0xe3, 0x23, 0x20, // 4 byte keyheight
},
}

Expand Down
2 changes: 1 addition & 1 deletion blockchain/stakeversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func genesisBlockNode(params *chaincfg.Params) *blockNode {
return node
}

func DNWTestCalcWantHeight(t *testing.T) {
func TestCalcWantHeight(t *testing.T) {
// For example, if StakeVersionInterval = 11 and StakeValidationHeight = 13 the
// windows start at 13 + (11 * 2) 25 and are as follows: 24-34, 35-45, 46-56 ...
// If height comes in at 35 we use the 24-34 window, up to height 45.
Expand Down
4 changes: 2 additions & 2 deletions database/error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

// TestErrorCodeStringer tests the stringized output for the ErrorCode type.
func DNWTestErrorCodeStringer(t *testing.T) {
func TestErrorCodeStringer(t *testing.T) {
tests := []struct {
in database.ErrorCode
want string
Expand Down Expand Up @@ -61,7 +61,7 @@ func DNWTestErrorCodeStringer(t *testing.T) {
}

// TestError tests the error output for the Error type.
func DNWTestError(t *testing.T) {
func TestError(t *testing.T) {
t.Parallel()

tests := []struct {
Expand Down
4 changes: 2 additions & 2 deletions database/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func Example_basicUsage() {
// This example demonstrates creating a new database, using a managed read-write
// transaction to store a block, and using a managed read-only transaction to
// fetch the block.
func DNWExample_blockStorageAndRetrieval() {
func Example_blockStorageAndRetrieval() {
// This example assumes the ffldb driver is imported.
//
// import (
Expand Down Expand Up @@ -174,5 +174,5 @@ func DNWExample_blockStorageAndRetrieval() {
fmt.Printf("Serialized block size: %d bytes\n", len(loadedBlockBytes))

// Output:
// Serialized block size: 300 bytes
// Serialized block size: 336 bytes
}
68 changes: 28 additions & 40 deletions peer/peer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package peer_test

import (
"encoding/binary"
"errors"
"io"
"net"
Expand Down Expand Up @@ -205,7 +206,7 @@ func testPeer(t *testing.T, p *peer.Peer, s peerStats) {
}

// TestPeerConnection tests connection between inbound and outbound peers.
func DNWTestPeerConnection(t *testing.T) {
func TestPeerConnection(t *testing.T) {
verack := make(chan struct{})
peerCfg := &peer.Config{
Listeners: peer.MessageListeners{
Expand Down Expand Up @@ -235,8 +236,8 @@ func DNWTestPeerConnection(t *testing.T) {
wantLastPingNonce: uint64(0),
wantLastPingMicros: int64(0),
wantTimeOffset: int64(0),
wantBytesSent: 158, // 134 version + 24 verack
wantBytesReceived: 158,
wantBytesSent: 164, // 140 version + 24 verack
wantBytesReceived: 164,
}
tests := []struct {
name string
Expand Down Expand Up @@ -313,7 +314,7 @@ func DNWTestPeerConnection(t *testing.T) {
}

// TestPeerListeners tests that the peer listeners are called as expected.
func DNWTestPeerListeners(t *testing.T) {
func TestPeerListeners(t *testing.T) {
verack := make(chan struct{}, 1)
ok := make(chan wire.Message, 20)
peerCfg := &peer.Config{
Expand Down Expand Up @@ -455,14 +456,10 @@ func DNWTestPeerListeners(t *testing.T) {
},
{
"OnBlock",
// revised by sammy at 2017-10-27
/*
wire.NewMsgBlock(wire.NewBlockHeader(0, &chainhash.Hash{},
&chainhash.Hash{}, &chainhash.Hash{}, &chainhash.Hash{}, 1, [6]byte{},
1, 1, 1, 1, 1, 1, 1, 1, 1, [32]byte{},
binary.LittleEndian.Uint32([]byte{0xb0, 0x1d, 0xfa, 0xce}))),
*/
nil,
wire.NewMsgBlock(wire.NewBlockHeader(0, &chainhash.Hash{},
&chainhash.Hash{}, &chainhash.Hash{}, &chainhash.Hash{},1, [6]byte{},
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, [32]byte{},
binary.LittleEndian.Uint32([]byte{0xb0, 0x1d, 0xfa, 0xce}))),
},
{
"OnInv",
Expand Down Expand Up @@ -506,15 +503,11 @@ func DNWTestPeerListeners(t *testing.T) {
},
{
"OnMerkleBlock",
// revise by sammy at 2017-10-27
/*
wire.NewMsgMerkleBlock(wire.NewBlockHeader(0,
&chainhash.Hash{}, &chainhash.Hash{},
&chainhash.Hash{}, 1, [6]byte{},
1, 1, 1, 1, 1, 1, 1, 1, 1, [32]byte{},
binary.LittleEndian.Uint32([]byte{0xb0, 0x1d, 0xfa, 0xce}))),
*/
nil,
wire.NewMsgMerkleBlock(wire.NewBlockHeader(0,
&chainhash.Hash{}, &chainhash.Hash{}, &chainhash.Hash{},
&chainhash.Hash{}, 1, [6]byte{},
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, [32]byte{},
binary.LittleEndian.Uint32([]byte{0xb0, 0x1d, 0xfa, 0xce}))),
},
// only one version message is allowed
// only one verack message is allowed
Expand Down Expand Up @@ -543,14 +536,11 @@ func DNWTestPeerListeners(t *testing.T) {
}

// TestOutboundPeer tests that the outbound peer works as expected.
func DNWTestOutboundPeer(t *testing.T) {
func TestOutboundPeer(t *testing.T) {
peerCfg := &peer.Config{
// revise by sammy at 2017-10-27
/*
NewestBlock: func() (*chainhash.Hash, int64, error) {
return nil, 0, errors.New("newest block not found")
},
*/
NewestBlock: func() (*chainhash.Hash, int64, int64, error) {
return nil, 0, 0, errors.New("newest block not found")
},
UserAgentName: "peer",
UserAgentVersion: "1.0",
ChainParams: &chaincfg.MainNetParams,
Expand Down Expand Up @@ -603,19 +593,17 @@ func DNWTestOutboundPeer(t *testing.T) {
<-done
p.Disconnect()

// revise by sammy at 2017-10-27
// Test NewestBlock
/*
var newestBlock = func() (*chainhash.Hash, int64, error) {
hashStr := "14a0810ac680a3eb3f82edc878cea25ec41d6b790744e5daeef"
hash, err := chainhash.NewHashFromStr(hashStr)
if err != nil {
return nil, 0, err
}
return hash, 234439, nil
//Test NewestBlock
var newestBlock = func() (*chainhash.Hash, int64, int64, error) {
hashStr := "14a0810ac680a3eb3f82edc878cea25ec41d6b790744e5daeef"
hash, err := chainhash.NewHashFromStr(hashStr)
if err != nil {
return nil, 0, 0, err
}
*/
//peerCfg.NewestBlock = newestBlock
return hash, 234439, 234438, nil
}

peerCfg.NewestBlock = newestBlock
peerCfg.NewestBlock = nil

r1, w1 := io.Pipe()
Expand Down
Loading

0 comments on commit 27b8778

Please sign in to comment.