Merge pull request #1334 from 0xfandom/accounts/test-checklabel
Some checks failed
CI / frontend tests on macOS-latest (push) Has been cancelled
CI / frontend tests on ubuntu-latest (push) Has been cancelled
CI / frontend tests on windows-latest (push) Has been cancelled
CI / backend build on macOS-latest (push) Has been cancelled
CI / backend build on ubuntu-latest (push) Has been cancelled
CI / backend build on windows-latest (push) Has been cancelled
CI / cross compilation (push) Has been cancelled
CI / cross compilation-1 (push) Has been cancelled
CI / cross compilation-2 (push) Has been cancelled
CI / RPC proto compilation check (push) Has been cancelled
CI / check commits (push) Has been cancelled
CI / Sqlc check (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / run unit tests (push) Has been cancelled
CI / run unit tests-1 (push) Has been cancelled
CI / run unit tests-2 (push) Has been cancelled
CI / run unit tests-3 (push) Has been cancelled
CI / build itest binaries (push) Has been cancelled
CI / check release notes updated (push) Has been cancelled
CI / integration test (push) Has been cancelled
CI / integration test-1 (push) Has been cancelled
CI / integration test-2 (push) Has been cancelled

accounts: add test coverage for checkLabel
This commit is contained in:
Viktor Torstensson 2026-06-24 12:07:30 +02:00 committed by GitHub
commit 69eb14cc63
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -848,3 +848,61 @@ func TestLastInvoiceIndexes(t *testing.T) {
require.EqualValues(t, 7, add)
require.EqualValues(t, 99, settle)
}
// TestCheckLabel ensures that only labels that could be mistaken for a hex
// encoded account ID are rejected, while all other labels (including the empty
// label) are accepted.
func TestCheckLabel(t *testing.T) {
t.Parallel()
tests := []struct {
name string
label string
expectErr bool
}{{
name: "empty label is allowed",
label: "",
}, {
name: "plain text label is allowed",
label: "my account",
}, {
name: "short hex label is allowed",
label: "00112233",
}, {
name: "non-hex label with account ID length is allowed",
// 16 characters long, matching an encoded account ID, but not
// valid hex.
label: "zzzzzzzzzzzzzzzz",
}, {
name: "lowercase hex label with account ID length is rejected",
// 16 characters of valid hex, exactly the length of an encoded
// account ID.
label: "0011223344556677",
expectErr: true,
}, {
name: "uppercase hex label with account ID length is rejected",
// hex.DecodeString also accepts uppercase digits, so this must
// be rejected as well.
label: "00112233445566AA",
expectErr: true,
}}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
err := checkLabel(tc.label)
if tc.expectErr {
require.ErrorContains(
t, err, "is not allowed as it can be "+
"mistaken",
)
return
}
require.NoError(t, err)
})
}
}