From d22500b3ca26393168d150217255ad2f50dd4373 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Wed, 21 Aug 2024 21:30:21 +0300 Subject: [PATCH] *: improve for range loops with 1.22+ syntax Signed-off-by: Roman Khimov --- dbft_test.go | 6 +++--- internal/consensus/amev_block.go | 2 +- internal/merkle/merkle_tree.go | 2 +- internal/merkle/merkle_tree_test.go | 2 +- internal/simulation/main.go | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/dbft_test.go b/dbft_test.go index f6ef2b75..75f003ea 100644 --- a/dbft_test.go +++ b/dbft_test.go @@ -409,8 +409,8 @@ func TestDBFT_OnReceiveRecoveryRequestResponds(t *testing.T) { var params []recoveryset for _, nodes := range []int{4, 5, 7, 10} { // 5 is a bad BFT number, but we want to test the logic anyway. - for sender := 0; sender < nodes; sender++ { - for recv := 0; recv < nodes; recv++ { + for sender := range nodes { + for recv := range nodes { params = append(params, recoveryset{nodes, sender, recv, false}) for i := 1; i <= ((nodes-1)/3)+1; i++ { @@ -1221,7 +1221,7 @@ func newConsensusPayload(c *dbft.Context[crypto.Uint256], t dbft.MessageType, ms } func getTestValidators(n int) (privs []dbft.PrivateKey, pubs []dbft.PublicKey) { - for i := 0; i < n; i++ { + for range n { priv, pub := crypto.Generate(rand.Reader) privs = append(privs, priv) pubs = append(pubs, pub) diff --git a/internal/consensus/amev_block.go b/internal/consensus/amev_block.go index 8e51c5b6..4df63057 100644 --- a/internal/consensus/amev_block.go +++ b/internal/consensus/amev_block.go @@ -30,7 +30,7 @@ func NewAMEVBlock(pre dbft.PreBlock[crypto.Uint256], cnData [][]byte, m int) dbf // Some artificial rules of new tx creation are invented here, but in Neo X there will // be well-defined custom rules for Envelope transactions. var sum uint32 - for i := 0; i < m; i++ { + for i := range m { sum += binary.BigEndian.Uint32(cnData[i]) } tx := Tx64(math.MaxInt64 - int64(sum)) diff --git a/internal/merkle/merkle_tree.go b/internal/merkle/merkle_tree.go index 5d6bb31e..1585006a 100644 --- a/internal/merkle/merkle_tree.go +++ b/internal/merkle/merkle_tree.go @@ -54,7 +54,7 @@ func buildTree(leaves ...TreeNode) *TreeNode { } parents := make([]TreeNode, (l+1)/2) - for i := 0; i < len(parents); i++ { + for i := range parents { parents[i].Left = &leaves[i*2] leaves[i*2].Parent = &parents[i] diff --git a/internal/merkle/merkle_tree_test.go b/internal/merkle/merkle_tree_test.go index 99706b16..5e769e03 100644 --- a/internal/merkle/merkle_tree_test.go +++ b/internal/merkle/merkle_tree_test.go @@ -25,7 +25,7 @@ func TestNewMerkleTree(t *testing.T) { t.Run("predefined tree on 4 leaves", func(t *testing.T) { hashes := make([]crypto.Uint256, 5) - for i := 0; i < 5; i++ { + for i := range hashes { hashes[i] = sha256.Sum256([]byte{byte(i)}) } diff --git a/internal/simulation/main.go b/internal/simulation/main.go index d47ba6a1..0a2973ec 100644 --- a/internal/simulation/main.go +++ b/internal/simulation/main.go @@ -199,7 +199,7 @@ func (n *simNode) VerifyPayload(p dbft.ConsensusPayload[crypto.Uint256]) error { } func (n *simNode) addTx(count int) { - for i := 0; i < count; i++ { + for i := range count { tx := consensus.Tx64(uint64(i)) n.pool.Add(&tx) }