@@ -4,6 +4,7 @@ package list
44
55import (
66 "fmt"
7+ "os"
78
89 "github.com/ava-labs/avalanche-cli/tests/e2e/commands"
910 "github.com/ava-labs/avalanche-cli/tests/e2e/utils"
@@ -12,7 +13,17 @@ import (
1213)
1314
1415const (
15- keyName = "e2eKey"
16+ keyName = "e2eKey"
17+ ledger1Seed = "ledger1"
18+ ledger2Seed = "ledger2"
19+
20+ // Expected addresses for ledger1 seed (deterministic)
21+ ledger1Index0PChain = "P-custom1jkjatcy2vxfx3st0kft8p0jup6k4ucxugtzhlc"
22+ ledger1Index0XChain = "X-custom1jkjatcy2vxfx3st0kft8p0jup6k4ucxugtzhlc"
23+ ledger1Index0CChain = "0x90f207c2D78E871CFd23071f0545e72233B33767"
24+ ledger1Index1PChain = "P-custom13wzadkyffwlk0a936u5y089dxtw3kx5fyaewc9"
25+ ledger1Index1XChain = "X-custom13wzadkyffwlk0a936u5y089dxtw3kx5fyaewc9"
26+ ledger1Index1CChain = "0x6235F11635BfDe6319E836e487A47D4686c4752E"
1627)
1728
1829var _ = ginkgo .Describe ("[Key] list" , func () {
@@ -58,4 +69,82 @@ var _ = ginkgo.Describe("[Key] list", func() {
5869 gomega .Expect (output ).Should (gomega .MatchRegexp (regex4 ))
5970 gomega .Expect (output ).Should (gomega .ContainSubstring (keyName ))
6071 })
72+
73+ ginkgo .It ("can list ledger addresses for multiple indices and chains" , func () {
74+ gomega .Expect (os .Getenv ("LEDGER_SIM" )).Should (gomega .Equal ("true" ), "ledger list test not designed for real ledgers: please set env var LEDGER_SIM to true" )
75+
76+ // Start ledger simulator once for all tests
77+ interactionEndCh , ledgerSimEndCh := utils .StartLedgerSim (0 , ledger1Seed , false )
78+
79+ // Test 1: List all chains (P-Chain, C-Chain, X-Chain) for multiple indices
80+ output , err := commands .ListLedgerKeys ("local" , []uint {0 , 1 }, "p,c,x" , "" )
81+ gomega .Expect (err ).Should (gomega .BeNil ())
82+
83+ // Verify output contains expected headers (case-insensitive check)
84+ gomega .Expect (output ).Should (gomega .ContainSubstring ("KIND" ))
85+ gomega .Expect (output ).Should (gomega .ContainSubstring ("NAME" ))
86+ gomega .Expect (output ).Should (gomega .ContainSubstring ("SUBNET" ))
87+ gomega .Expect (output ).Should (gomega .ContainSubstring ("ADDRESS" ))
88+ gomega .Expect (output ).Should (gomega .ContainSubstring ("TOKEN" ))
89+ gomega .Expect (output ).Should (gomega .ContainSubstring ("BALANCE" ))
90+
91+ // Verify ledger indices are shown
92+ gomega .Expect (output ).Should (gomega .ContainSubstring ("index 0" ))
93+ gomega .Expect (output ).Should (gomega .ContainSubstring ("index 1" ))
94+
95+ // Verify all chains are listed
96+ gomega .Expect (output ).Should (gomega .ContainSubstring ("P-Chain" ))
97+ gomega .Expect (output ).Should (gomega .ContainSubstring ("C-Chain" ))
98+ gomega .Expect (output ).Should (gomega .ContainSubstring ("X-Chain" ))
99+
100+ // Verify kind is "ledger"
101+ gomega .Expect (output ).Should (gomega .ContainSubstring ("ledger" ))
102+
103+ // Verify specific addresses for index 0 (deterministic with ledger1 seed)
104+ gomega .Expect (output ).Should (gomega .ContainSubstring (ledger1Index0PChain ))
105+ gomega .Expect (output ).Should (gomega .ContainSubstring (ledger1Index0XChain ))
106+ gomega .Expect (output ).Should (gomega .ContainSubstring (ledger1Index0CChain ))
107+
108+ // Verify specific addresses for index 1 (deterministic with ledger1 seed)
109+ gomega .Expect (output ).Should (gomega .ContainSubstring (ledger1Index1PChain ))
110+ gomega .Expect (output ).Should (gomega .ContainSubstring (ledger1Index1XChain ))
111+ gomega .Expect (output ).Should (gomega .ContainSubstring (ledger1Index1CChain ))
112+
113+ // Test 2: List only P-Chain addresses
114+ output , err = commands .ListLedgerKeys ("local" , []uint {0 }, "p" , "" )
115+ gomega .Expect (err ).Should (gomega .BeNil ())
116+ gomega .Expect (output ).Should (gomega .ContainSubstring ("P-Chain" ))
117+ gomega .Expect (output ).Should (gomega .ContainSubstring ("index 0" ))
118+ gomega .Expect (output ).Should (gomega .ContainSubstring (ledger1Index0PChain ))
119+ gomega .Expect (output ).ShouldNot (gomega .ContainSubstring ("C-Chain" ))
120+ gomega .Expect (output ).ShouldNot (gomega .ContainSubstring ("X-Chain" ))
121+ gomega .Expect (output ).ShouldNot (gomega .ContainSubstring (ledger1Index0CChain ))
122+ gomega .Expect (output ).ShouldNot (gomega .ContainSubstring (ledger1Index0XChain ))
123+
124+ // Test 3: List only C-Chain addresses
125+ output , err = commands .ListLedgerKeys ("local" , []uint {0 }, "c" , "" )
126+ gomega .Expect (err ).Should (gomega .BeNil ())
127+ gomega .Expect (output ).Should (gomega .ContainSubstring ("C-Chain" ))
128+ gomega .Expect (output ).Should (gomega .ContainSubstring ("index 0" ))
129+ gomega .Expect (output ).Should (gomega .ContainSubstring (ledger1Index0CChain ))
130+ gomega .Expect (output ).ShouldNot (gomega .ContainSubstring ("P-Chain" ))
131+ gomega .Expect (output ).ShouldNot (gomega .ContainSubstring ("X-Chain" ))
132+ gomega .Expect (output ).ShouldNot (gomega .ContainSubstring (ledger1Index0PChain ))
133+ gomega .Expect (output ).ShouldNot (gomega .ContainSubstring (ledger1Index0XChain ))
134+
135+ // Test 4: List only X-Chain addresses
136+ output , err = commands .ListLedgerKeys ("local" , []uint {0 }, "x" , "" )
137+ gomega .Expect (err ).Should (gomega .BeNil ())
138+ gomega .Expect (output ).Should (gomega .ContainSubstring ("X-Chain" ))
139+ gomega .Expect (output ).Should (gomega .ContainSubstring ("index 0" ))
140+ gomega .Expect (output ).Should (gomega .ContainSubstring (ledger1Index0XChain ))
141+ gomega .Expect (output ).ShouldNot (gomega .ContainSubstring ("P-Chain" ))
142+ gomega .Expect (output ).ShouldNot (gomega .ContainSubstring ("C-Chain" ))
143+ gomega .Expect (output ).ShouldNot (gomega .ContainSubstring (ledger1Index0PChain ))
144+ gomega .Expect (output ).ShouldNot (gomega .ContainSubstring (ledger1Index0CChain ))
145+
146+ // Close ledger simulator
147+ close (interactionEndCh )
148+ <- ledgerSimEndCh
149+ })
61150})
0 commit comments