Skip to content

Commit

Permalink
lint discriminator extractor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ilija42 committed Jan 23, 2025
1 parent 98de5b2 commit e8bf851
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
2 changes: 1 addition & 1 deletion pkg/solana/codec/discriminator.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (d Discriminator) FixedSize() (int, error) {
}

type DiscriminatorExtractor struct {
b64Index [256]byte
b64Index [128]byte
}

// NewDiscriminatorExtractor is optimised to extract discriminators from base64 encoded strings faster than the base64 lib.
Expand Down
19 changes: 5 additions & 14 deletions pkg/solana/codec/discriminator_extractor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ func FuzzExtractorHappyPath(f *testing.F) {
seeds := []struct {
Data string
}{
{"SGVbG8gd29ybGQ"}, // "Hello world!"
{"SGVsbG8gV29ybGQh"}, // Hello world!
{"AAAAAAAAAAAA"}, // Zero bytes
{"////////////"}, // Max value bytes
{"QUJDREVGR0hJSktM"}, // "ABCDEFGHIJKL"
{"QUJDREVGR0hJSktM"}, // ABCDEFGHIJKL
}

for _, seed := range seeds {
Expand All @@ -25,21 +25,12 @@ func FuzzExtractorHappyPath(f *testing.F) {

extractor := NewDiscriminatorExtractor()
f.Fuzz(func(t *testing.T, testString string) {
if len(testString) < 12 {
t.Fatalf("test string is shorter than 12 %s", testString)
}

data := testString[:12]
std, err := base64.StdEncoding.DecodeString(data)
stdDecoded, err := base64.StdEncoding.DecodeString(testString)
if err != nil {
t.Fatalf("failed to decode test string %s with stdlib", data)
}

if len(std) < 8 {
t.Fatal("stdlib decoded < 8 bytes")
t.Fatalf("failed to decode test string %s with stdlib, err: %s", testString, err)
}

require.Equal(t, std[:8], extractor.Extract(data))
require.Equal(t, stdDecoded[:8], extractor.Extract(testString))
})
}

Expand Down

0 comments on commit e8bf851

Please sign in to comment.