@@ -17,10 +17,11 @@ import (
1717 "github.com/dgraph-io/badger/v4/options"
1818 "github.com/fystack/mpcium/pkg/client"
1919 "github.com/fystack/mpcium/pkg/event"
20+ "github.com/fystack/mpcium/pkg/infra"
2021 "github.com/fystack/mpcium/pkg/kvstore"
2122 "github.com/fystack/mpcium/pkg/types"
22- "github.com/hashicorp/consul/api"
2323 "github.com/nats-io/nats.go"
24+ "github.com/nats-io/nats.go/jetstream"
2425 "github.com/stretchr/testify/require"
2526 "gopkg.in/yaml.v2"
2627)
@@ -35,9 +36,6 @@ type TestConfig struct {
3536 Nats struct {
3637 URL string `yaml:"url"`
3738 } `yaml:"nats"`
38- Consul struct {
39- Address string `yaml:"address"`
40- } `yaml:"consul"`
4139 MPCThreshold int `yaml:"mpc_threshold"`
4240 Environment string `yaml:"environment"`
4341 BadgerPassword string `yaml:"badger_password"`
@@ -49,7 +47,7 @@ type TestConfig struct {
4947
5048type E2ETestSuite struct {
5149 ctx context.Context
52- consulClient * api. Client
50+ cancel context. CancelFunc
5351 natsConn * nats.Conn
5452 mpcClient client.MPCClient
5553 testDir string
@@ -62,9 +60,10 @@ type E2ETestSuite struct {
6260}
6361
6462func NewE2ETestSuite (testDir string ) * E2ETestSuite {
65- ctx , _ := context .WithCancel (context .Background ())
63+ ctx , cancel := context .WithCancel (context .Background ())
6664 return & E2ETestSuite {
6765 ctx : ctx ,
66+ cancel : cancel ,
6867 testDir : testDir ,
6968 walletIDs : make ([]string , 0 ),
7069 keygenResults : make (map [string ]* event.KeygenResultEvent ),
@@ -148,18 +147,7 @@ func (s *E2ETestSuite) setupClients(t *testing.T) {
148147 var err error
149148
150149 // Use the fixed ports from docker-compose.test.yaml
151- consulPort := 8501 // consul-test service maps 8501:8500
152- natsPort := 4223 // nats-server-test service maps 4223:4222
153-
154- // Setup Consul client
155- consulConfig := api .DefaultConfig ()
156- consulConfig .Address = fmt .Sprintf ("localhost:%d" , consulPort )
157- s .consulClient , err = api .NewClient (consulConfig )
158- require .NoError (t , err , "Failed to create Consul client" )
159-
160- // Test Consul connection
161- _ , err = s .consulClient .Agent ().Self ()
162- require .NoError (t , err , "Failed to connect to Consul" )
150+ natsPort := 4223 // nats-server-test service maps 4223:4222
163151
164152 // Setup NATS client
165153 natsConn , err := nats .Connect (fmt .Sprintf ("nats://localhost:%d" , natsPort ))
@@ -216,13 +204,7 @@ func (s *E2ETestSuite) SetupTestNodes(t *testing.T) {
216204}
217205
218206func (s * E2ETestSuite ) RegisterPeers (t * testing.T ) {
219- t .Log ("Registering peers in Consul..." )
220-
221- // Check Consul health before proceeding
222- t .Log ("Checking Consul health..." )
223- _ , err := s .consulClient .Status ().Leader ()
224- require .NoError (t , err , "Consul is not healthy" )
225- t .Log ("Consul is healthy" )
207+ t .Log ("Registering peers in NATS KV..." )
226208
227209 // Use mpcium register-peers command instead of manual registration
228210 t .Log ("Running mpcium-cli register-peers..." )
@@ -237,20 +219,24 @@ func (s *E2ETestSuite) RegisterPeers(t *testing.T) {
237219 require .NoError (t , err , "Failed to register peers" )
238220 }
239221
240- t .Log ("Peers registered in Consul " )
222+ t .Log ("Peers registered in NATS KV " )
241223
242224 // List current peers to verify registration
243- t .Log ("Listing current peers in Consul..." )
244- kv := s .consulClient .KV ()
225+ t .Log ("Listing current peers in NATS KV..." )
226+ js , err := jetstream .New (s .natsConn )
227+ require .NoError (t , err , "Failed to get JetStream context" )
228+
229+ peersKV , err := infra .NewNatsKVStore (js , "mpc-peers" )
230+ require .NoError (t , err , "Failed to init mpc-peers KV bucket" )
245231
246- // Get all keys under the mpc_peers/ prefix (matches register-peers command )
247- pairs , _ , err := kv .List ("mpc_peers/" , nil )
232+ // Get all keys (empty prefix )
233+ pairs , err := peersKV .List ("" )
248234 if err != nil {
249235 t .Logf ("Failed to list peers: %v" , err )
250236 } else {
251- t .Logf ("Found %d peer entries in Consul under 'mpc_peers/':" , len (pairs ))
252- for _ , pair := range pairs {
253- t .Logf (" - Key: %s, Value: %s" , pair . Key , string (pair . Value ))
237+ t .Logf ("Found %d peer entries in NATS KV under 'mpc_peers/':" , len (pairs ))
238+ for k , v := range pairs {
239+ t .Logf (" - Key: %s, Value: %s" , k , string (v ))
254240 }
255241 }
256242
@@ -267,13 +253,12 @@ func (s *E2ETestSuite) RegisterPeers(t *testing.T) {
267253func (s * E2ETestSuite ) StartNodes (t * testing.T ) {
268254 t .Log ("Starting MPC nodes..." )
269255
270- // Double-check that Consul is still accessible before starting nodes
271- t .Log ("Verifying Consul is still accessible..." )
272- _ , err := s .consulClient .Status ().Leader ()
273- if err != nil {
274- t .Logf ("Consul connection test failed: %v" , err )
256+ // Double-check that NATS is still accessible before starting nodes
257+ t .Log ("Verifying NATS is still accessible..." )
258+ if ! s .natsConn .IsConnected () {
259+ t .Log ("NATS connection lost" )
275260 } else {
276- t .Log ("Consul is still accessible" )
261+ t .Log ("NATS is still accessible" )
277262 }
278263
279264 s .mpciumProcesses = make ([]* exec.Cmd , numNodes )
@@ -318,12 +303,11 @@ func (s *E2ETestSuite) StartNodes(t *testing.T) {
318303 time .Sleep (5 * time .Second )
319304
320305 // Verify containers are still accessible
321- t .Log ("Final verification that Consul is still accessible..." )
322- _ , err = s .consulClient .Status ().Leader ()
323- if err != nil {
324- t .Logf ("Consul connection test failed after starting nodes: %v" , err )
306+ t .Log ("Final verification that NATS is still accessible..." )
307+ if ! s .natsConn .IsConnected () {
308+ t .Log ("NATS connection lost after starting nodes" )
325309 } else {
326- t .Log ("Consul is still accessible after starting nodes" )
310+ t .Log ("NATS is still accessible after starting nodes" )
327311 }
328312
329313 // Show recent logs from each node
@@ -562,6 +546,11 @@ func (s *E2ETestSuite) Cleanup(t *testing.T) {
562546 s .natsConn .Close ()
563547 }
564548
549+ // Cancel the context to release resources
550+ if s .cancel != nil {
551+ s .cancel ()
552+ }
553+
565554 // Stop Docker Compose stack
566555 t .Log ("Stopping Docker Compose stack..." )
567556 cmd := exec .Command ("docker" , "compose" , "-f" , "docker-compose.test.yaml" , "down" , "-v" )
0 commit comments