From 0edeef646113abedce986e353c420a5425c3bead Mon Sep 17 00:00:00 2001 From: jacksoom Date: Wed, 31 Mar 2021 17:35:36 +0800 Subject: [PATCH] feat(bytom2.0 net): fix unit test and other (#1847) --- common/bech32/bech32_test.go | 11 ++++++----- net/http/authn/authn_test.go | 2 +- net/websocket/wsnotificationmaneger.go | 7 ++++++- p2p/upnp/upnp.go | 2 +- test/tx_test_util.go | 2 +- wallet/utxo_test.go | 15 ++------------- 6 files changed, 17 insertions(+), 22 deletions(-) diff --git a/common/bech32/bech32_test.go b/common/bech32/bech32_test.go index da9beb83..634f5665 100644 --- a/common/bech32/bech32_test.go +++ b/common/bech32/bech32_test.go @@ -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 } diff --git a/net/http/authn/authn_test.go b/net/http/authn/authn_test.go index 22eaf477..c7fefe06 100644 --- a/net/http/authn/authn_test.go +++ b/net/http/authn/authn_test.go @@ -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) { diff --git a/net/websocket/wsnotificationmaneger.go b/net/websocket/wsnotificationmaneger.go index bfe403b9..0d0ea05f 100644 --- a/net/websocket/wsnotificationmaneger.go +++ b/net/websocket/wsnotificationmaneger.go @@ -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 } diff --git a/p2p/upnp/upnp.go b/p2p/upnp/upnp.go index eda7d53c..4d38e752 100644 --- a/p2p/upnp/upnp.go +++ b/p2p/upnp/upnp.go @@ -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 diff --git a/test/tx_test_util.go b/test/tx_test_util.go index cb6b9eee..adc93e44 100644 --- a/test/tx_test_util.go +++ b/test/tx_test_util.go @@ -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 { diff --git a/wallet/utxo_test.go b/wallet/utxo_test.go index e3174226..27400acf 100644 --- a/wallet/utxo_test.go +++ b/wallet/utxo_test.go @@ -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{ -- 2.11.0