Skip to content

Commit 464d030

Browse files
committed
add watcher_test.go
1 parent 63a78af commit 464d030

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

node/pkg/watchers/watchers_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package watchers
2+
3+
import (
4+
"slices"
5+
"testing"
6+
7+
"github.com/wormhole-foundation/wormhole/sdk/vaa"
8+
)
9+
10+
func TestRegisterRPCURL(t *testing.T) {
11+
rpcURLsMu.Lock()
12+
rpcURLs = map[vaa.ChainID][]string{}
13+
rpcURLsMu.Unlock()
14+
15+
RegisterRPCURL(vaa.ChainIDEthereum, "")
16+
if urls := RPCURLs(vaa.ChainIDEthereum); urls != nil {
17+
t.Fatalf("expected empty URLs to be ignored, got %v", urls)
18+
}
19+
20+
RegisterRPCURL(vaa.ChainIDEthereum, "https://eth.example")
21+
RegisterRPCURL(vaa.ChainIDEthereum, "https://eth.example")
22+
RegisterRPCURL(vaa.ChainIDEthereum, "https://eth-backup.example")
23+
24+
urls := RPCURLs(vaa.ChainIDEthereum)
25+
want := []string{"https://eth.example", "https://eth-backup.example"}
26+
if !slices.Equal(urls, want) {
27+
t.Fatalf("unexpected URLs: got %v, want %v", urls, want)
28+
}
29+
30+
urls[0] = "https://mutated.example"
31+
if got := RPCURLs(vaa.ChainIDEthereum); !slices.Equal(got, want) {
32+
t.Fatalf("RPCURLs returned mutable backing storage: got %v, want %v", got, want)
33+
}
34+
}

0 commit comments

Comments
 (0)