-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathexport_address_details_test.go
More file actions
67 lines (55 loc) · 1.99 KB
/
Copy pathexport_address_details_test.go
File metadata and controls
67 lines (55 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
import (
"strings"
"testing"
)
func TestCollectAllAddrs(t *testing.T) {
// two valid T-addrs (34 chars), plus an invalid entry that should be ignored
src := strings.NewReader("TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t,invalid,THPvaUhoh2Qn2y9THCZML3H815hhFhn5YC\n")
options := &ExportAddressDetailsOptions{
addrSource: src,
Addresses: []string{"TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t"}, // duplicate on purpose
}
all := collectAllAddrs(options)
if len(all) != 2 { // two unique addresses (duplicate is removed)
t.Fatalf("expected 2 addresses, got %d", len(all))
}
// Check that all addresses are valid T-addresses
expectedAddrs := map[string]bool{
"TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t": false,
"THPvaUhoh2Qn2y9THCZML3H815hhFhn5YC": false,
}
for _, addr := range all {
if len(addr) != 34 || addr[0] != 'T' {
t.Fatalf("addr %s is not a valid T-address", addr)
}
if _, ok := expectedAddrs[addr]; !ok {
t.Fatalf("unexpected address: %s", addr)
}
expectedAddrs[addr] = true
}
// Ensure both expected addresses were found
for addr, found := range expectedAddrs {
if !found {
t.Fatalf("expected address %s not found", addr)
}
}
}
func TestCollectAllAddrs_HexDeduplication(t *testing.T) {
// Test that hex addresses are properly converted to T-addr and deduplicated
// 41a614f803b6fd780986a42c78ec9c7f77e6ded13c is the hex for TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t
options := &ExportAddressDetailsOptions{
Addresses: []string{
"TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t", // T-addr
"41a614f803b6fd780986a42c78ec9c7f77e6ded13c", // Hex (same address)
"a614f803b6fd780986a42c78ec9c7f77e6ded13c", // Hex without 41 prefix (same address)
},
}
all := collectAllAddrs(options)
if len(all) != 1 { // should be deduplicated to 1 address
t.Fatalf("expected 1 address after deduplication, got %d", len(all))
}
if all[0] != "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t" {
t.Fatalf("expected TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t, got %s", all[0])
}
}