Compare commits

...

2 Commits

Author SHA1 Message Date
1e0c853d40
tests: update decode
Some checks failed
release / docker (push) Has been cancelled
2025-02-06 08:14:24 +03:00
6fff0ba538
feat: discard 0x2e in session_id bytes
0x2e was added herehttps://holbrook.no/src/go-vise/file/db/db.go.html#l147, so we discard the last 3 bytes
2025-01-15 14:24:03 +03:00
3 changed files with 5 additions and 3 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.vscode

View File

@ -8,12 +8,13 @@ const ()
// DecodeKey specifically only decodes user data keys stored as bytes into its respective session ID and data type
// TODO: Replace return data type with imported data types from the common package once lib-gdbm dependency is removed.
// Note: 0x2e was added herehttps://holbrook.no/src/go-vise/file/db/db.go.html#l147, so we discard the last 3 bytes
func DecodeKey(key []byte) (uint16, string) {
if key[0] != keyPrefix {
return 0, ""
}
return binary.BigEndian.Uint16(key[len(key)-2:]), string(key[1 : len(key)-2])
return binary.BigEndian.Uint16(key[len(key)-2:]), string(key[1 : len(key)-3])
}
// DecodeValue returns the utf-8 string representation of the value stored in the storage backend

View File

@ -21,10 +21,10 @@ func TestDecodeKey(t *testing.T) {
{
"blockchain_address",
args{
keyBytesHex: "202b3235343731313030303132330001",
keyBytesHex: "202b3235343731313737373733342e0001",
},
want{
sessionID: "+254711000123",
sessionID: "+254711777734",
dataType: ACCOUNT_BLOCKCHAIN_ADDRESS,
},
},