OSDN Git Service

feat(bytom2.0 net): fix unit test and other (#1847)
authorjacksoom <lifengliu1994@gmail.com>
Wed, 31 Mar 2021 09:35:36 +0000 (17:35 +0800)
committerGitHub <noreply@github.com>
Wed, 31 Mar 2021 09:35:36 +0000 (17:35 +0800)
common/bech32/bech32_test.go
net/http/authn/authn_test.go
net/websocket/wsnotificationmaneger.go
p2p/upnp/upnp.go
test/tx_test_util.go
wallet/utxo_test.go

index da9beb8..634f566 100644 (file)
@@ -1,6 +1,7 @@
 package bech32
 
 import (
+       "fmt"
        "strings"
        "testing"
 )
@@ -15,11 +16,11 @@ func TestBech32(t *testing.T) {
                {"abcdef1qpzry9x8gf2tvdw0s3jn54khce6mua7lmqqqxw", true},
                {"11qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqc8247j", true},
                {"split1checkupstagehandshakeupstreamerranterredcaperred2y9e3w", true},
-               {"split1checkupstagehandshakeupstreamerranterredcaperred2y9e2w", false},                                // invalid checksum
-               {"s lit1checkupstagehandshakeupstreamerranterredcaperredp8hs2p", false},                                // invalid character (space) in hrp
-               {"spl" + string(127) + "t1checkupstagehandshakeupstreamerranterredcaperred2y9e3w", false},              // invalid character (DEL) in hrp
-               {"split1cheo2y9e2w", false},                                                                            // invalid character (o) in data part
-               {"split1a2y9w", false},                                                                                 // too short data part
+               {"split1checkupstagehandshakeupstreamerranterredcaperred2y9e2w", false},                       // invalid checksum
+               {"s lit1checkupstagehandshakeupstreamerranterredcaperredp8hs2p", false},                       // invalid character (space) in hrp
+               {"spl" + fmt.Sprint(127) + "t1checkupstagehandshakeupstreamerranterredcaperred2y9e3w", false}, // invalid character (DEL) in hrp
+               {"split1cheo2y9e2w", false}, // invalid character (o) in data part
+               {"split1a2y9w", false},      // too short data part
                {"1checkupstagehandshakeupstreamerranterredcaperred2y9e3w", false},                                     // empty hrp
                {"11qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqsqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqc8247j", false}, // too long
        }
index 22eaf47..c7fefe0 100644 (file)
@@ -7,8 +7,8 @@ import (
        "testing"
 
        "github.com/bytom/bytom/accesstoken"
-       "github.com/bytom/bytom/errors"
        dbm "github.com/bytom/bytom/database/leveldb"
+       "github.com/bytom/bytom/errors"
 )
 
 func TestAuthenticate(t *testing.T) {
index bfe403b..0d0ea05 100644 (file)
@@ -445,7 +445,12 @@ out:
                }
 
                if m.status.BestHash != block.PreviousBlockHash {
-                       log.WithFields(log.Fields{"module": logModule, "blockHeight": block.Height, "previousBlockHash": m.status.BestHash, "rcvBlockPrevHash": block.PreviousBlockHash}).Warning("The previousBlockHash of the received block is not the same as the hash of the previous block")
+                       log.WithFields(log.Fields{
+                               "module":                 logModule,
+                               "block_height":           block.Height,
+                               "status_block_hash":      m.status.BestHash.String(),
+                               "retrive_block_PrevHash": block.PreviousBlockHash.String(),
+                       }).Warning("The previousBlockHash of the received block is not the same as the hash of the previous block")
                        continue
                }
 
index eda7d53..4d38e75 100644 (file)
@@ -207,7 +207,7 @@ func getServiceURL(rootURL string) (url, urnDomain string, err error) {
        defer r.Body.Close() // nolint: errcheck
 
        if r.StatusCode >= 400 {
-               err = errors.New(string(r.StatusCode))
+               err = errors.New(fmt.Sprint(r.StatusCode))
                return
        }
        var root Root
index cb6b9ee..adc93e4 100644 (file)
@@ -359,7 +359,7 @@ func SignInstructionFor(input *types.SpendInput, db dbm.DB, signer *signers.Sign
 func CreateCoinbaseTx(controlProgram []byte, height, txsFee uint64) (*types.Tx, error) {
        coinbaseValue := consensus.BlockSubsidy(height) + txsFee
        builder := txbuilder.NewBuilder(time.Now())
-       if err := builder.AddInput(types.NewCoinbaseInput([]byte(string(height))), &txbuilder.SigningInstruction{}); err != nil {
+       if err := builder.AddInput(types.NewCoinbaseInput([]byte(fmt.Sprint(height))), &txbuilder.SigningInstruction{}); err != nil {
                return nil, err
        }
        if err := builder.AddOutput(types.NewTxOutput(*consensus.BTMAssetID, coinbaseValue, controlProgram)); err != nil {
index e317422..27400ac 100644 (file)
@@ -10,10 +10,10 @@ import (
 
        "github.com/bytom/bytom/account"
        "github.com/bytom/bytom/consensus"
+       dbm "github.com/bytom/bytom/database/leveldb"
        "github.com/bytom/bytom/protocol/bc"
        "github.com/bytom/bytom/protocol/bc/types"
        "github.com/bytom/bytom/testutil"
-       dbm "github.com/bytom/bytom/database/leveldb"
 )
 
 func TestGetAccountUtxos(t *testing.T) {
@@ -250,11 +250,6 @@ func TestFilterAccountUtxo(t *testing.T) {
                                        ControlProgramIndex: 53,
                                        Change:              true,
                                },
-                               &account.UTXO{
-                                       ControlProgram: []byte{0x91},
-                                       AssetID:        bc.AssetID{V0: 1},
-                                       Amount:         4,
-                               },
                        },
                },
                {
@@ -271,13 +266,7 @@ func TestFilterAccountUtxo(t *testing.T) {
                                        Amount:         3,
                                },
                        },
-                       wantUtxos: []*account.UTXO{
-                               &account.UTXO{
-                                       ControlProgram: []byte{0x91},
-                                       AssetID:        bc.AssetID{V0: 1},
-                                       Amount:         3,
-                               },
-                       },
+                       wantUtxos: []*account.UTXO{},
                },
                {
                        dbPrograms: map[string]*account.CtrlProgram{