mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-25 14:52:17 +00:00
fix linter errors thrown by unconvert
, goconst
, and nakedret
(#3960)
* Remove unnecessary type conversions * Consolidate repeated strings into consts * Clothe return statements * Update blockchain/v1/reactor_fsm_test.go Co-Authored-By: Anton Kaliaev <anton.kalyaev@gmail.com> This PR repairs linter errors seen when running the following commands: golangci-lint run --no-config --disable-all=true --enable=unconvert golangci-lint run --no-config --disable-all=true --enable=goconst golangci-lint run --no-config --disable-all=true --enable=nakedret Contributes to #3262
This commit is contained in:
parent
7f0c55f249
commit
04d13d9945
@ -18,6 +18,11 @@ import (
|
|||||||
"github.com/tendermint/tendermint/abci/types"
|
"github.com/tendermint/tendermint/abci/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
testKey = "abc"
|
||||||
|
testValue = "def"
|
||||||
|
)
|
||||||
|
|
||||||
func testKVStore(t *testing.T, app types.Application, tx []byte, key, value string) {
|
func testKVStore(t *testing.T, app types.Application, tx []byte, key, value string) {
|
||||||
req := types.RequestDeliverTx{Tx: tx}
|
req := types.RequestDeliverTx{Tx: tx}
|
||||||
ar := app.DeliverTx(req)
|
ar := app.DeliverTx(req)
|
||||||
@ -46,12 +51,12 @@ func testKVStore(t *testing.T, app types.Application, tx []byte, key, value stri
|
|||||||
|
|
||||||
func TestKVStoreKV(t *testing.T) {
|
func TestKVStoreKV(t *testing.T) {
|
||||||
kvstore := NewKVStoreApplication()
|
kvstore := NewKVStoreApplication()
|
||||||
key := "abc"
|
key := testKey
|
||||||
value := key
|
value := key
|
||||||
tx := []byte(key)
|
tx := []byte(key)
|
||||||
testKVStore(t, kvstore, tx, key, value)
|
testKVStore(t, kvstore, tx, key, value)
|
||||||
|
|
||||||
value = "def"
|
value = testValue
|
||||||
tx = []byte(key + "=" + value)
|
tx = []byte(key + "=" + value)
|
||||||
testKVStore(t, kvstore, tx, key, value)
|
testKVStore(t, kvstore, tx, key, value)
|
||||||
}
|
}
|
||||||
@ -62,12 +67,12 @@ func TestPersistentKVStoreKV(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
kvstore := NewPersistentKVStoreApplication(dir)
|
kvstore := NewPersistentKVStoreApplication(dir)
|
||||||
key := "abc"
|
key := testKey
|
||||||
value := key
|
value := key
|
||||||
tx := []byte(key)
|
tx := []byte(key)
|
||||||
testKVStore(t, kvstore, tx, key, value)
|
testKVStore(t, kvstore, tx, key, value)
|
||||||
|
|
||||||
value = "def"
|
value = testValue
|
||||||
tx = []byte(key + "=" + value)
|
tx = []byte(key + "=" + value)
|
||||||
testKVStore(t, kvstore, tx, key, value)
|
testKVStore(t, kvstore, tx, key, value)
|
||||||
}
|
}
|
||||||
@ -90,7 +95,7 @@ func TestPersistentKVStoreInfo(t *testing.T) {
|
|||||||
height = int64(1)
|
height = int64(1)
|
||||||
hash := []byte("foo")
|
hash := []byte("foo")
|
||||||
header := types.Header{
|
header := types.Header{
|
||||||
Height: int64(height),
|
Height: height,
|
||||||
}
|
}
|
||||||
kvstore.BeginBlock(types.RequestBeginBlock{Hash: hash, Header: header})
|
kvstore.BeginBlock(types.RequestBeginBlock{Hash: hash, Header: header})
|
||||||
kvstore.EndBlock(types.RequestEndBlock{Height: header.Height})
|
kvstore.EndBlock(types.RequestEndBlock{Height: header.Height})
|
||||||
@ -272,12 +277,12 @@ func TestClientServer(t *testing.T) {
|
|||||||
|
|
||||||
func runClientTests(t *testing.T, client abcicli.Client) {
|
func runClientTests(t *testing.T, client abcicli.Client) {
|
||||||
// run some tests....
|
// run some tests....
|
||||||
key := "abc"
|
key := testKey
|
||||||
value := key
|
value := key
|
||||||
tx := []byte(key)
|
tx := []byte(key)
|
||||||
testClient(t, client, tx, key, value)
|
testClient(t, client, tx, key, value)
|
||||||
|
|
||||||
value = "def"
|
value = testValue
|
||||||
tx = []byte(key + "=" + value)
|
tx = []byte(key + "=" + value)
|
||||||
testClient(t, client, tx, key, value)
|
testClient(t, client, tx, key, value)
|
||||||
}
|
}
|
||||||
|
@ -198,7 +198,7 @@ func (app *PersistentKVStoreApplication) execValidatorTx(tx []byte) types.Respon
|
|||||||
}
|
}
|
||||||
|
|
||||||
// update
|
// update
|
||||||
return app.updateValidator(types.Ed25519ValidatorUpdate(pubkey, int64(power)))
|
return app.updateValidator(types.Ed25519ValidatorUpdate(pubkey, power))
|
||||||
}
|
}
|
||||||
|
|
||||||
// add, update, or remove a validator
|
// add, update, or remove a validator
|
||||||
|
@ -191,7 +191,7 @@ func (pool *BlockPool) makeRequestBatch(maxNumRequests int) []int {
|
|||||||
// - FSM timed out on waiting to advance the block execution due to missing blocks at h or h+1
|
// - FSM timed out on waiting to advance the block execution due to missing blocks at h or h+1
|
||||||
// Determine the number of requests needed by subtracting the number of requests already made from the maximum
|
// Determine the number of requests needed by subtracting the number of requests already made from the maximum
|
||||||
// allowed
|
// allowed
|
||||||
numNeeded := int(maxNumRequests) - len(pool.blocks)
|
numNeeded := maxNumRequests - len(pool.blocks)
|
||||||
for len(pool.plannedRequests) < numNeeded {
|
for len(pool.plannedRequests) < numNeeded {
|
||||||
if pool.nextRequestHeight > pool.MaxPeerHeight {
|
if pool.nextRequestHeight > pool.MaxPeerHeight {
|
||||||
break
|
break
|
||||||
|
@ -77,10 +77,10 @@ func makeBlockPool(bcr *testBcR, height int64, peers []BpPeer, blocks map[int64]
|
|||||||
bPool.MaxPeerHeight = maxH
|
bPool.MaxPeerHeight = maxH
|
||||||
for h, p := range blocks {
|
for h, p := range blocks {
|
||||||
bPool.blocks[h] = p.id
|
bPool.blocks[h] = p.id
|
||||||
bPool.peers[p.id].RequestSent(int64(h))
|
bPool.peers[p.id].RequestSent(h)
|
||||||
if p.create {
|
if p.create {
|
||||||
// simulate that a block at height h has been received
|
// simulate that a block at height h has been received
|
||||||
_ = bPool.peers[p.id].AddBlock(types.MakeBlock(int64(h), txs, nil, nil), 100)
|
_ = bPool.peers[p.id].AddBlock(types.MakeBlock(h, txs, nil, nil), 100)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return bPool
|
return bPool
|
||||||
|
@ -140,7 +140,7 @@ func sBlockRespEv(current, expected string, peerID p2p.ID, height int64, prevBlo
|
|||||||
data: bReactorEventData{
|
data: bReactorEventData{
|
||||||
peerID: peerID,
|
peerID: peerID,
|
||||||
height: height,
|
height: height,
|
||||||
block: types.MakeBlock(int64(height), txs, nil, nil),
|
block: types.MakeBlock(height, txs, nil, nil),
|
||||||
length: 100},
|
length: 100},
|
||||||
wantState: expected,
|
wantState: expected,
|
||||||
wantNewBlocks: append(prevBlocks, height),
|
wantNewBlocks: append(prevBlocks, height),
|
||||||
@ -157,7 +157,7 @@ func sBlockRespEvErrored(current, expected string,
|
|||||||
data: bReactorEventData{
|
data: bReactorEventData{
|
||||||
peerID: peerID,
|
peerID: peerID,
|
||||||
height: height,
|
height: height,
|
||||||
block: types.MakeBlock(int64(height), txs, nil, nil),
|
block: types.MakeBlock(height, txs, nil, nil),
|
||||||
length: 100},
|
length: 100},
|
||||||
wantState: expected,
|
wantState: expected,
|
||||||
wantErr: wantErr,
|
wantErr: wantErr,
|
||||||
@ -769,7 +769,7 @@ forLoop:
|
|||||||
for i := 0; i < int(numBlocks); i++ {
|
for i := 0; i < int(numBlocks); i++ {
|
||||||
|
|
||||||
// Add the makeRequestEv step periodically.
|
// Add the makeRequestEv step periodically.
|
||||||
if i%int(maxRequestsPerPeer) == 0 {
|
if i%maxRequestsPerPeer == 0 {
|
||||||
testSteps = append(
|
testSteps = append(
|
||||||
testSteps,
|
testSteps,
|
||||||
sMakeRequestsEv("waitForBlock", "waitForBlock", maxNumRequests),
|
sMakeRequestsEv("waitForBlock", "waitForBlock", maxNumRequests),
|
||||||
@ -786,7 +786,7 @@ forLoop:
|
|||||||
numBlocksReceived++
|
numBlocksReceived++
|
||||||
|
|
||||||
// Add the processedBlockEv step periodically.
|
// Add the processedBlockEv step periodically.
|
||||||
if numBlocksReceived >= int(maxRequestsPerPeer) || height >= numBlocks {
|
if numBlocksReceived >= maxRequestsPerPeer || height >= numBlocks {
|
||||||
for j := int(height) - numBlocksReceived; j < int(height); j++ {
|
for j := int(height) - numBlocksReceived; j < int(height); j++ {
|
||||||
if j >= int(numBlocks) {
|
if j >= int(numBlocks) {
|
||||||
// This is the last block that is processed, we should be in "finished" state.
|
// This is the last block that is processed, we should be in "finished" state.
|
||||||
@ -829,7 +829,7 @@ func makeCorrectTransitionSequenceWithRandomParameters() testFields {
|
|||||||
maxRequestsPerPeer := cmn.RandIntn(maxRequestsPerPeerTest) + 1
|
maxRequestsPerPeer := cmn.RandIntn(maxRequestsPerPeerTest) + 1
|
||||||
|
|
||||||
// Generate the maximum number of total pending requests, >= maxRequestsPerPeer.
|
// Generate the maximum number of total pending requests, >= maxRequestsPerPeer.
|
||||||
maxPendingRequests := cmn.RandIntn(maxTotalPendingRequestsTest-int(maxRequestsPerPeer)) + maxRequestsPerPeer
|
maxPendingRequests := cmn.RandIntn(maxTotalPendingRequestsTest-maxRequestsPerPeer) + maxRequestsPerPeer
|
||||||
|
|
||||||
// Generate the number of blocks to be synced.
|
// Generate the number of blocks to be synced.
|
||||||
numBlocks := int64(cmn.RandIntn(maxNumBlocksInChainTest)) + startingHeight
|
numBlocks := int64(cmn.RandIntn(maxNumBlocksInChainTest)) + startingHeight
|
||||||
|
@ -246,7 +246,7 @@ func (h *Handshaker) Handshake(proxyApp proxy.AppConns) error {
|
|||||||
return fmt.Errorf("Error calling Info: %v", err)
|
return fmt.Errorf("Error calling Info: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
blockHeight := int64(res.LastBlockHeight)
|
blockHeight := res.LastBlockHeight
|
||||||
if blockHeight < 0 {
|
if blockHeight < 0 {
|
||||||
return fmt.Errorf("Got a negative last block height (%d) from the app", blockHeight)
|
return fmt.Errorf("Got a negative last block height (%d) from the app", blockHeight)
|
||||||
}
|
}
|
||||||
|
@ -1458,7 +1458,7 @@ func (cs *ConsensusState) addProposalBlockPart(msg *BlockPartMessage, peerID p2p
|
|||||||
_, err = cdc.UnmarshalBinaryLengthPrefixedReader(
|
_, err = cdc.UnmarshalBinaryLengthPrefixedReader(
|
||||||
cs.ProposalBlockParts.GetReader(),
|
cs.ProposalBlockParts.GetReader(),
|
||||||
&cs.ProposalBlock,
|
&cs.ProposalBlock,
|
||||||
int64(cs.state.ConsensusParams.Block.MaxBytes),
|
cs.state.ConsensusParams.Block.MaxBytes,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return added, err
|
return added, err
|
||||||
@ -1675,7 +1675,7 @@ func (cs *ConsensusState) addVote(vote *types.Vote, peerID p2p.ID) (added bool,
|
|||||||
panic(fmt.Sprintf("Unexpected vote type %X", vote.Type)) // go-amino should prevent this.
|
panic(fmt.Sprintf("Unexpected vote type %X", vote.Type)) // go-amino should prevent this.
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return added, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cs *ConsensusState) signVote(type_ types.SignedMsgType, hash []byte, header types.PartSetHeader) (*types.Vote, error) {
|
func (cs *ConsensusState) signVote(type_ types.SignedMsgType, hash []byte, header types.PartSetHeader) (*types.Vote, error) {
|
||||||
|
@ -189,7 +189,7 @@ func TestStateBadProposal(t *testing.T) {
|
|||||||
if len(stateHash) == 0 {
|
if len(stateHash) == 0 {
|
||||||
stateHash = make([]byte, 32)
|
stateHash = make([]byte, 32)
|
||||||
}
|
}
|
||||||
stateHash[0] = byte((stateHash[0] + 1) % 255)
|
stateHash[0] = (stateHash[0] + 1) % 255
|
||||||
propBlock.AppHash = stateHash
|
propBlock.AppHash = stateHash
|
||||||
propBlockParts := propBlock.MakePartSet(partSize)
|
propBlockParts := propBlock.MakePartSet(partSize)
|
||||||
blockID := types.BlockID{Hash: propBlock.Hash(), PartsHeader: propBlockParts.Header()}
|
blockID := types.BlockID{Hash: propBlock.Hash(), PartsHeader: propBlockParts.Header()}
|
||||||
@ -364,7 +364,7 @@ func TestStateLockNoPOL(t *testing.T) {
|
|||||||
// lets add one for a different block
|
// lets add one for a different block
|
||||||
hash := make([]byte, len(theBlockHash))
|
hash := make([]byte, len(theBlockHash))
|
||||||
copy(hash, theBlockHash)
|
copy(hash, theBlockHash)
|
||||||
hash[0] = byte((hash[0] + 1) % 255)
|
hash[0] = (hash[0] + 1) % 255
|
||||||
signAddVotes(cs1, types.PrecommitType, hash, thePartSetHeader, vs2)
|
signAddVotes(cs1, types.PrecommitType, hash, thePartSetHeader, vs2)
|
||||||
ensurePrecommit(voteCh, height, round) // precommit
|
ensurePrecommit(voteCh, height, round) // precommit
|
||||||
|
|
||||||
|
@ -74,8 +74,8 @@ func (op SimpleValueOp) Run(args [][]byte) ([][]byte, error) {
|
|||||||
|
|
||||||
bz := new(bytes.Buffer)
|
bz := new(bytes.Buffer)
|
||||||
// Wrap <op.Key, vhash> to hash the KVPair.
|
// Wrap <op.Key, vhash> to hash the KVPair.
|
||||||
encodeByteSlice(bz, []byte(op.key)) // does not error
|
encodeByteSlice(bz, op.key) // does not error
|
||||||
encodeByteSlice(bz, []byte(vhash)) // does not error
|
encodeByteSlice(bz, vhash) // does not error
|
||||||
kvhash := leafHash(bz.Bytes())
|
kvhash := leafHash(bz.Bytes())
|
||||||
|
|
||||||
if !bytes.Equal(kvhash, op.Proof.LeafHash) {
|
if !bytes.Equal(kvhash, op.Proof.LeafHash) {
|
||||||
|
@ -21,7 +21,7 @@ func randCompactBitArray(bits int) (*CompactBitArray, []byte) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Set remaining bits
|
// Set remaining bits
|
||||||
for i := uint8(0); i < 8-uint8(bA.ExtraBitsStored); i++ {
|
for i := uint8(0); i < 8-bA.ExtraBitsStored; i++ {
|
||||||
bA.SetIndex(numBytes*8+int(i), src[numBytes-1]&(uint8(1)<<(8-i)) > 0)
|
bA.SetIndex(numBytes*8+int(i), src[numBytes-1]&(uint8(1)<<(8-i)) > 0)
|
||||||
}
|
}
|
||||||
return bA, src
|
return bA, src
|
||||||
|
@ -13,6 +13,8 @@ import (
|
|||||||
dbm "github.com/tendermint/tm-db"
|
dbm "github.com/tendermint/tm-db"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const testChainID = "inquiry-test"
|
||||||
|
|
||||||
func TestInquirerValidPath(t *testing.T) {
|
func TestInquirerValidPath(t *testing.T) {
|
||||||
assert, require := assert.New(t), require.New(t)
|
assert, require := assert.New(t), require.New(t)
|
||||||
trust := NewDBProvider("trust", dbm.NewMemDB())
|
trust := NewDBProvider("trust", dbm.NewMemDB())
|
||||||
@ -24,7 +26,7 @@ func TestInquirerValidPath(t *testing.T) {
|
|||||||
nkeys := keys.Extend(1)
|
nkeys := keys.Extend(1)
|
||||||
|
|
||||||
// Construct a bunch of commits, each with one more height than the last.
|
// Construct a bunch of commits, each with one more height than the last.
|
||||||
chainID := "inquiry-test"
|
chainID := testChainID
|
||||||
consHash := []byte("params")
|
consHash := []byte("params")
|
||||||
resHash := []byte("results")
|
resHash := []byte("results")
|
||||||
count := 50
|
count := 50
|
||||||
@ -146,7 +148,7 @@ func TestInquirerVerifyHistorical(t *testing.T) {
|
|||||||
nkeys := keys.Extend(1)
|
nkeys := keys.Extend(1)
|
||||||
|
|
||||||
// Construct a bunch of commits, each with one more height than the last.
|
// Construct a bunch of commits, each with one more height than the last.
|
||||||
chainID := "inquiry-test"
|
chainID := testChainID
|
||||||
count := 10
|
count := 10
|
||||||
consHash := []byte("special-params")
|
consHash := []byte("special-params")
|
||||||
fcz := make([]FullCommit, count)
|
fcz := make([]FullCommit, count)
|
||||||
@ -229,7 +231,7 @@ func TestConcurrencyInquirerVerify(t *testing.T) {
|
|||||||
nkeys := keys.Extend(1)
|
nkeys := keys.Extend(1)
|
||||||
|
|
||||||
// Construct a bunch of commits, each with one more height than the last.
|
// Construct a bunch of commits, each with one more height than the last.
|
||||||
chainID := "inquiry-test"
|
chainID := testChainID
|
||||||
count := 10
|
count := 10
|
||||||
consHash := []byte("special-params")
|
consHash := []byte("special-params")
|
||||||
fcz := make([]FullCommit, count)
|
fcz := make([]FullCommit, count)
|
||||||
|
@ -29,7 +29,7 @@ func GetWithProof(prt *merkle.ProofRuntime, key []byte, reqHeight int64, node rp
|
|||||||
}
|
}
|
||||||
|
|
||||||
res, err := GetWithProofOptions(prt, "/key", key,
|
res, err := GetWithProofOptions(prt, "/key", key,
|
||||||
rpcclient.ABCIQueryOptions{Height: int64(reqHeight), Prove: true},
|
rpcclient.ABCIQueryOptions{Height: reqHeight, Prove: true},
|
||||||
node, cert)
|
node, cert)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
@ -58,7 +58,7 @@ func (w Wrapper) Tx(hash []byte, prove bool) (*ctypes.ResultTx, error) {
|
|||||||
if !prove || err != nil {
|
if !prove || err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
h := int64(res.Height)
|
h := res.Height
|
||||||
sh, err := GetCertifiedCommit(h, w.Client, w.cert)
|
sh, err := GetCertifiedCommit(h, w.Client, w.cert)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
|
@ -564,7 +564,7 @@ func TestMempoolRemoteAppConcurrency(t *testing.T) {
|
|||||||
for i := 0; i < N; i++ {
|
for i := 0; i < N; i++ {
|
||||||
peerID := mrand.Intn(maxPeers)
|
peerID := mrand.Intn(maxPeers)
|
||||||
txNum := mrand.Intn(nTxs)
|
txNum := mrand.Intn(nTxs)
|
||||||
tx := txs[int(txNum)]
|
tx := txs[txNum]
|
||||||
|
|
||||||
// this will err with ErrTxInCache many times ...
|
// this will err with ErrTxInCache many times ...
|
||||||
mempool.CheckTxWithInfo(tx, nil, TxInfo{SenderID: uint16(peerID)})
|
mempool.CheckTxWithInfo(tx, nil, TxInfo{SenderID: uint16(peerID)})
|
||||||
|
@ -803,7 +803,7 @@ func (ch *Channel) isSendPending() bool {
|
|||||||
// Not goroutine-safe
|
// Not goroutine-safe
|
||||||
func (ch *Channel) nextPacketMsg() PacketMsg {
|
func (ch *Channel) nextPacketMsg() PacketMsg {
|
||||||
packet := PacketMsg{}
|
packet := PacketMsg{}
|
||||||
packet.ChannelID = byte(ch.desc.ID)
|
packet.ChannelID = ch.desc.ID
|
||||||
maxSize := ch.maxPacketMsgPayloadSize
|
maxSize := ch.maxPacketMsgPayloadSize
|
||||||
packet.Bytes = ch.sending[:cmn.MinInt(maxSize, len(ch.sending))]
|
packet.Bytes = ch.sending[:cmn.MinInt(maxSize, len(ch.sending))]
|
||||||
if len(ch.sending) <= maxSize {
|
if len(ch.sending) <= maxSize {
|
||||||
|
@ -133,7 +133,7 @@ func TestMConnectionReceive(t *testing.T) {
|
|||||||
|
|
||||||
select {
|
select {
|
||||||
case receivedBytes := <-receivedCh:
|
case receivedBytes := <-receivedCh:
|
||||||
assert.Equal(t, []byte(msg), receivedBytes)
|
assert.Equal(t, msg, receivedBytes)
|
||||||
case err := <-errorsCh:
|
case err := <-errorsCh:
|
||||||
t.Fatalf("Expected %s, got %+v", msg, err)
|
t.Fatalf("Expected %s, got %+v", msg, err)
|
||||||
case <-time.After(500 * time.Millisecond):
|
case <-time.After(500 * time.Millisecond):
|
||||||
|
@ -188,7 +188,7 @@ func (sc *SecretConnection) Write(data []byte) (n int, err error) {
|
|||||||
return n, err
|
return n, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return n, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// CONTRACT: data smaller than dataMaxSize is read atomically.
|
// CONTRACT: data smaller than dataMaxSize is read atomically.
|
||||||
@ -234,7 +234,7 @@ func (sc *SecretConnection) Read(data []byte) (n int, err error) {
|
|||||||
sc.recvBuffer = make([]byte, len(chunk)-n)
|
sc.recvBuffer = make([]byte, len(chunk)-n)
|
||||||
copy(sc.recvBuffer, chunk[n:])
|
copy(sc.recvBuffer, chunk[n:])
|
||||||
}
|
}
|
||||||
return
|
return n, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implements net.Conn
|
// Implements net.Conn
|
||||||
|
@ -87,7 +87,7 @@ func makeSecretConnPair(tb testing.TB) (fooSecConn, barSecConn *SecretConnection
|
|||||||
require.Nil(tb, trs.FirstError())
|
require.Nil(tb, trs.FirstError())
|
||||||
require.True(tb, ok, "Unexpected task abortion")
|
require.True(tb, ok, "Unexpected task abortion")
|
||||||
|
|
||||||
return
|
return fooSecConn, barSecConn
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSecretConnectionHandshake(t *testing.T) {
|
func TestSecretConnectionHandshake(t *testing.T) {
|
||||||
|
@ -784,12 +784,12 @@ func (a *addrBook) groupKey(na *p2p.NetAddress) string {
|
|||||||
}
|
}
|
||||||
if na.RFC6145() || na.RFC6052() {
|
if na.RFC6145() || na.RFC6052() {
|
||||||
// last four bytes are the ip address
|
// last four bytes are the ip address
|
||||||
ip := net.IP(na.IP[12:16])
|
ip := na.IP[12:16]
|
||||||
return (&net.IPNet{IP: ip, Mask: net.CIDRMask(16, 32)}).String()
|
return (&net.IPNet{IP: ip, Mask: net.CIDRMask(16, 32)}).String()
|
||||||
}
|
}
|
||||||
|
|
||||||
if na.RFC3964() {
|
if na.RFC3964() {
|
||||||
ip := net.IP(na.IP[2:7])
|
ip := na.IP[2:7]
|
||||||
return (&net.IPNet{IP: ip, Mask: net.CIDRMask(16, 32)}).String()
|
return (&net.IPNet{IP: ip, Mask: net.CIDRMask(16, 32)}).String()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -78,7 +78,7 @@ func testHairpin(listener net.Listener, extAddr string, logger log.Logger) (supp
|
|||||||
|
|
||||||
// Wait for data receipt
|
// Wait for data receipt
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
return
|
return supportsHairpin
|
||||||
}
|
}
|
||||||
|
|
||||||
func Probe(logger log.Logger) (caps UPNPCapabilities, err error) {
|
func Probe(logger log.Logger) (caps UPNPCapabilities, err error) {
|
||||||
|
@ -105,7 +105,7 @@ func Discover() (nat NAT, err error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
err = errors.New("UPnP port discovery failed")
|
err = errors.New("UPnP port discovery failed")
|
||||||
return
|
return nat, err
|
||||||
}
|
}
|
||||||
|
|
||||||
type Envelope struct {
|
type Envelope struct {
|
||||||
@ -241,7 +241,7 @@ func getServiceURL(rootURL string) (url, urnDomain string, err error) {
|
|||||||
// Extract the domain name, which isn't always 'schemas-upnp-org'
|
// Extract the domain name, which isn't always 'schemas-upnp-org'
|
||||||
urnDomain = strings.Split(d.ServiceType, ":")[1]
|
urnDomain = strings.Split(d.ServiceType, ":")[1]
|
||||||
url = combineURL(rootURL, d.ControlURL)
|
url = combineURL(rootURL, d.ControlURL)
|
||||||
return
|
return url, urnDomain, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func combineURL(rootURL, subURL string) string {
|
func combineURL(rootURL, subURL string) string {
|
||||||
@ -285,7 +285,7 @@ func soapRequest(url, function, message, domain string) (r *http.Response, err e
|
|||||||
r = nil
|
r = nil
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return
|
return r, err
|
||||||
}
|
}
|
||||||
|
|
||||||
type statusInfo struct {
|
type statusInfo struct {
|
||||||
@ -322,7 +322,7 @@ func (n *upnpNAT) getExternalIPAddress() (info statusInfo, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return info, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetExternalAddress returns an external IP. If GetExternalIPAddress action
|
// GetExternalAddress returns an external IP. If GetExternalIPAddress action
|
||||||
|
@ -147,7 +147,7 @@ func TestInfo(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Unexpected error: %v", err)
|
t.Errorf("Unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
if string(resInfo.Data) != "{\"size\":0}" {
|
if resInfo.Data != "{\"size\":0}" {
|
||||||
t.Error("Expected ResponseInfo with one element '{\"size\":0}' but got something else")
|
t.Error("Expected ResponseInfo with one element '{\"size\":0}' but got something else")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -559,7 +559,7 @@ func makeEvidences(t *testing.T, val *privval.FilePV, chainID string) (ev types.
|
|||||||
// exactly same vote
|
// exactly same vote
|
||||||
vote2 = deepcpVote(vote)
|
vote2 = deepcpVote(vote)
|
||||||
fakes[41] = newEvidence(t, val, vote, vote2, chainID)
|
fakes[41] = newEvidence(t, val, vote, vote2, chainID)
|
||||||
return
|
return ev, fakes
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBroadcastEvidenceDuplicateVote(t *testing.T) {
|
func TestBroadcastEvidenceDuplicateVote(t *testing.T) {
|
||||||
|
@ -106,7 +106,7 @@ func Tx(ctx *rpctypes.Context, hash []byte, prove bool) (*ctypes.ResultTx, error
|
|||||||
return &ctypes.ResultTx{
|
return &ctypes.ResultTx{
|
||||||
Hash: hash,
|
Hash: hash,
|
||||||
Height: height,
|
Height: height,
|
||||||
Index: uint32(index),
|
Index: index,
|
||||||
TxResult: r.Result,
|
TxResult: r.Result,
|
||||||
Tx: r.Tx,
|
Tx: r.Tx,
|
||||||
Proof: proof,
|
Proof: proof,
|
||||||
|
@ -33,6 +33,8 @@ const (
|
|||||||
unixAddr = "unix://" + unixSocket
|
unixAddr = "unix://" + unixSocket
|
||||||
|
|
||||||
websocketEndpoint = "/websocket/endpoint"
|
websocketEndpoint = "/websocket/endpoint"
|
||||||
|
|
||||||
|
testVal = "acbd"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ResultEcho struct {
|
type ResultEcho struct {
|
||||||
@ -189,7 +191,7 @@ func echoDataBytesViaHTTP(cl client.HTTPClient, bytes cmn.HexBytes) (cmn.HexByte
|
|||||||
}
|
}
|
||||||
|
|
||||||
func testWithHTTPClient(t *testing.T, cl client.HTTPClient) {
|
func testWithHTTPClient(t *testing.T, cl client.HTTPClient) {
|
||||||
val := "acbd"
|
val := testVal
|
||||||
got, err := echoViaHTTP(cl, val)
|
got, err := echoViaHTTP(cl, val)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
assert.Equal(t, got, val)
|
assert.Equal(t, got, val)
|
||||||
@ -255,7 +257,7 @@ func echoBytesViaWS(cl *client.WSClient, bytes []byte) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func testWithWSClient(t *testing.T, cl *client.WSClient) {
|
func testWithWSClient(t *testing.T, cl *client.WSClient) {
|
||||||
val := "acbd"
|
val := testVal
|
||||||
got, err := echoViaWS(cl, val)
|
got, err := echoViaWS(cl, val)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
assert.Equal(t, got, val)
|
assert.Equal(t, got, val)
|
||||||
@ -314,7 +316,7 @@ func TestWSNewWSRPCFunc(t *testing.T) {
|
|||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
defer cl.Stop()
|
defer cl.Stop()
|
||||||
|
|
||||||
val := "acbd"
|
val := testVal
|
||||||
params := map[string]interface{}{
|
params := map[string]interface{}{
|
||||||
"arg": val,
|
"arg": val,
|
||||||
}
|
}
|
||||||
@ -339,7 +341,7 @@ func TestWSHandlesArrayParams(t *testing.T) {
|
|||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
defer cl.Stop()
|
defer cl.Stop()
|
||||||
|
|
||||||
val := "acbd"
|
val := testVal
|
||||||
params := []interface{}{val}
|
params := []interface{}{val}
|
||||||
err = cl.CallWithArrayParams(context.Background(), "echo_ws", params)
|
err = cl.CallWithArrayParams(context.Background(), "echo_ws", params)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
@ -376,9 +376,9 @@ func _nonJSONStringToArg(cdc *amino.Codec, rt reflect.Type, arg string) (reflect
|
|||||||
rv, err := jsonStringToArg(cdc, rt, qarg)
|
rv, err := jsonStringToArg(cdc, rt, qarg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return rv, err, false
|
return rv, err, false
|
||||||
} else {
|
|
||||||
return rv, nil, true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return rv, nil, true
|
||||||
}
|
}
|
||||||
|
|
||||||
if isHexString {
|
if isHexString {
|
||||||
@ -396,7 +396,7 @@ func _nonJSONStringToArg(cdc *amino.Codec, rt reflect.Type, arg string) (reflect
|
|||||||
if rt.Kind() == reflect.String {
|
if rt.Kind() == reflect.String {
|
||||||
return reflect.ValueOf(string(value)), nil, true
|
return reflect.ValueOf(string(value)), nil, true
|
||||||
}
|
}
|
||||||
return reflect.ValueOf([]byte(value)), nil, true
|
return reflect.ValueOf(value), nil, true
|
||||||
}
|
}
|
||||||
|
|
||||||
if isQuotedString && expectingByteSlice {
|
if isQuotedString && expectingByteSlice {
|
||||||
|
@ -39,17 +39,17 @@ func TestResponses(t *testing.T) {
|
|||||||
a := NewRPCSuccessResponse(cdc, jsonid, &SampleResult{"hello"})
|
a := NewRPCSuccessResponse(cdc, jsonid, &SampleResult{"hello"})
|
||||||
b, _ := json.Marshal(a)
|
b, _ := json.Marshal(a)
|
||||||
s := fmt.Sprintf(`{"jsonrpc":"2.0","id":%v,"result":{"Value":"hello"}}`, tt.expected)
|
s := fmt.Sprintf(`{"jsonrpc":"2.0","id":%v,"result":{"Value":"hello"}}`, tt.expected)
|
||||||
assert.Equal(string(s), string(b))
|
assert.Equal(s, string(b))
|
||||||
|
|
||||||
d := RPCParseError(jsonid, errors.New("Hello world"))
|
d := RPCParseError(jsonid, errors.New("Hello world"))
|
||||||
e, _ := json.Marshal(d)
|
e, _ := json.Marshal(d)
|
||||||
f := fmt.Sprintf(`{"jsonrpc":"2.0","id":%v,"error":{"code":-32700,"message":"Parse error. Invalid JSON","data":"Hello world"}}`, tt.expected)
|
f := fmt.Sprintf(`{"jsonrpc":"2.0","id":%v,"error":{"code":-32700,"message":"Parse error. Invalid JSON","data":"Hello world"}}`, tt.expected)
|
||||||
assert.Equal(string(f), string(e))
|
assert.Equal(f, string(e))
|
||||||
|
|
||||||
g := RPCMethodNotFoundError(jsonid)
|
g := RPCMethodNotFoundError(jsonid)
|
||||||
h, _ := json.Marshal(g)
|
h, _ := json.Marshal(g)
|
||||||
i := fmt.Sprintf(`{"jsonrpc":"2.0","id":%v,"error":{"code":-32601,"message":"Method not found"}}`, tt.expected)
|
i := fmt.Sprintf(`{"jsonrpc":"2.0","id":%v,"error":{"code":-32601,"message":"Method not found"}}`, tt.expected)
|
||||||
assert.Equal(string(h), string(i))
|
assert.Equal(string(h), i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -645,7 +645,7 @@ func TestLargeGenesisValidator(t *testing.T) {
|
|||||||
tearDown, _, state := setupTestCase(t)
|
tearDown, _, state := setupTestCase(t)
|
||||||
defer tearDown(t)
|
defer tearDown(t)
|
||||||
|
|
||||||
genesisVotingPower := int64(types.MaxTotalVotingPower / 1000)
|
genesisVotingPower := types.MaxTotalVotingPower / 1000
|
||||||
genesisPubKey := ed25519.GenPrivKey().PubKey()
|
genesisPubKey := ed25519.GenPrivKey().PubKey()
|
||||||
// fmt.Println("genesis addr: ", genesisPubKey.Address())
|
// fmt.Println("genesis addr: ", genesisPubKey.Address())
|
||||||
genesisVal := &types.Validator{Address: genesisPubKey.Address(), PubKey: genesisPubKey, VotingPower: genesisVotingPower}
|
genesisVal := &types.Validator{Address: genesisPubKey.Address(), PubKey: genesisPubKey, VotingPower: genesisVotingPower}
|
||||||
|
@ -85,7 +85,7 @@ func (n *Network) NewBlock(b tmtypes.Header) {
|
|||||||
} else {
|
} else {
|
||||||
n.AvgBlockTime = 0.0
|
n.AvgBlockTime = 0.0
|
||||||
}
|
}
|
||||||
n.txThroughputMeter.Mark(int64(b.NumTxs))
|
n.txThroughputMeter.Mark(b.NumTxs)
|
||||||
n.AvgTxThroughput = n.txThroughputMeter.Rate1()
|
n.AvgTxThroughput = n.txThroughputMeter.Rate1()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,6 +133,6 @@ type TxResult struct {
|
|||||||
// fieldNum is also 1 (see BinFieldNum in amino.MarshalBinaryBare).
|
// fieldNum is also 1 (see BinFieldNum in amino.MarshalBinaryBare).
|
||||||
func ComputeAminoOverhead(tx Tx, fieldNum int) int64 {
|
func ComputeAminoOverhead(tx Tx, fieldNum int) int64 {
|
||||||
fnum := uint64(fieldNum)
|
fnum := uint64(fieldNum)
|
||||||
typ3AndFieldNum := (uint64(fnum) << 3) | uint64(amino.Typ3_ByteLength)
|
typ3AndFieldNum := (fnum << 3) | uint64(amino.Typ3_ByteLength)
|
||||||
return int64(amino.UvarintSize(typ3AndFieldNum)) + int64(amino.UvarintSize(uint64(len(tx))))
|
return int64(amino.UvarintSize(typ3AndFieldNum)) + int64(amino.UvarintSize(uint64(len(tx))))
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ import (
|
|||||||
const (
|
const (
|
||||||
// MaxVoteBytes is a maximum vote size (including amino overhead).
|
// MaxVoteBytes is a maximum vote size (including amino overhead).
|
||||||
MaxVoteBytes int64 = 223
|
MaxVoteBytes int64 = 223
|
||||||
|
nilVoteStr = "nil-Vote"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -84,7 +85,7 @@ func (vote *Vote) Copy() *Vote {
|
|||||||
|
|
||||||
func (vote *Vote) String() string {
|
func (vote *Vote) String() string {
|
||||||
if vote == nil {
|
if vote == nil {
|
||||||
return "nil-Vote"
|
return nilVoteStr
|
||||||
}
|
}
|
||||||
var typeString string
|
var typeString string
|
||||||
switch vote.Type {
|
switch vote.Type {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user