Skip to content

Commit ae801d5

Browse files
fix(chain): rename AllChains to All and return iterator (#136)
Returning Iterator instead of map for All method
1 parent a09cfcb commit ae801d5

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

.changeset/grumpy-apples-speak.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"chainlink-deployments-framework": patch
3+
---
4+
5+
rename AllChains to All

chain/blockchain.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package chain
22

33
import (
4+
"iter"
5+
"maps"
46
"slices"
57

68
"github.com/smartcontractkit/chainlink-deployments-framework/chain/aptos"
@@ -83,15 +85,9 @@ func (b BlockChains) ExistsN(selectors ...uint64) bool {
8385
return true
8486
}
8587

86-
// AllChains returns a map of all chains with their selectors as key.
87-
func (b BlockChains) AllChains() map[uint64]BlockChain {
88-
// Return a copy of the chains map to avoid external mutations
89-
chainsCopy := make(map[uint64]BlockChain, len(b.chains))
90-
for k, v := range b.chains {
91-
chainsCopy[k] = v
92-
}
93-
94-
return chainsCopy
88+
// All returns an iterator over all chains with their selectors.
89+
func (b BlockChains) All() iter.Seq2[uint64, BlockChain] {
90+
return maps.All(b.chains)
9591
}
9692

9793
// EVMChains returns a map of all EVM chains with their selectors.

chain/blockchain_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package chain_test
22

33
import (
4+
"maps"
45
"testing"
56

67
"github.com/stretchr/testify/assert"
@@ -56,7 +57,7 @@ func TestNewBlockChainsFromSlice(t *testing.T) {
5657
chains := chain.NewBlockChainsFromSlice(nil)
5758

5859
require.NotNil(t, chains)
59-
assert.Empty(t, chains.AllChains(), "expected empty chains map")
60+
assert.Empty(t, maps.Collect(chains.All()), "expected empty chains map")
6061
})
6162

6263
t.Run("populated slice", func(t *testing.T) {
@@ -65,7 +66,7 @@ func TestNewBlockChainsFromSlice(t *testing.T) {
6566
chains := chain.NewBlockChainsFromSlice([]chain.BlockChain{evmChain1, solanaChain1})
6667

6768
require.NotNil(t, chains)
68-
assert.Len(t, chains.AllChains(), 2, "expected 2 chains")
69+
assert.Len(t, maps.Collect(chains.All()), 2, "expected 2 chains")
6970
})
7071
}
7172

@@ -138,17 +139,16 @@ func TestBlockChainsAllChains(t *testing.T) {
138139

139140
chains := buildBlockChains()
140141

141-
allChains := chains.AllChains()
142+
allChains := maps.Collect(chains.All())
142143

143-
assert.Len(t, allChains, 6, "expected 6 chains")
144-
145-
// Check if all expected chains are present
146144
expectedSelectors := []uint64{
147145
evmChain1.Selector, evmChain2.Selector,
148146
solanaChain1.Selector, aptosChain1.Selector,
149147
suiChain1.Selector, tonChain1.Selector,
150148
}
151149

150+
assert.Len(t, allChains, len(expectedSelectors))
151+
152152
for _, selector := range expectedSelectors {
153153
_, exists := allChains[selector]
154154
assert.True(t, exists, "expected chain with selector %d", selector)

0 commit comments

Comments
 (0)