File tree Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Original file line number Diff line number Diff line change 8
8
"errors"
9
9
"fmt"
10
10
"reflect"
11
+ "regexp"
11
12
"strings"
12
13
"testing"
13
14
@@ -204,12 +205,18 @@ func InitializeDataAccount(
204
205
}
205
206
206
207
func GetDiscriminator (instruction string ) [8 ]byte {
207
- fullHash := sha256 .Sum256 ([]byte ("global:" + instruction ))
208
+ fullHash := sha256 .Sum256 ([]byte ("global:" + ToSnakeCase ( instruction ) ))
208
209
var discriminator [8 ]byte
209
210
copy (discriminator [:], fullHash [:8 ])
210
211
return discriminator
211
212
}
212
213
214
+ func ToSnakeCase (s string ) string {
215
+ s = regexp .MustCompile (`([a-z0-9])([A-Z])` ).ReplaceAllString (s , "${1}_${2}" )
216
+ s = regexp .MustCompile (`([A-Z]+)([A-Z][a-z])` ).ReplaceAllString (s , "${1}_${2}" )
217
+ return strings .ToLower (s )
218
+ }
219
+
213
220
func GetRandomPubKey (t * testing.T ) solana.PublicKey {
214
221
privKey , err := solana .NewRandomPrivateKey ()
215
222
require .NoError (t , err )
Original file line number Diff line number Diff line change
1
+ package chainwriter_test
2
+
3
+ import (
4
+ "testing"
5
+
6
+ "github.com/smartcontractkit/chainlink-solana/pkg/solana/chainwriter"
7
+ )
8
+
9
+ func TestToSnakeCase (t * testing.T ) {
10
+ testCases := []struct {
11
+ input string
12
+ expected string
13
+ }{
14
+ {"testCamelCase" , "test_camel_case" },
15
+ {"oneword" , "oneword" },
16
+ {"" , "" },
17
+ {"testCamelCaseWithCAPS" , "test_camel_case_with_caps" },
18
+ {"testCamelCaseWithCAPSAndNumbers123" , "test_camel_case_with_caps_and_numbers123" },
19
+ }
20
+
21
+ for _ , tc := range testCases {
22
+ t .Run (tc .input , func (t * testing.T ) {
23
+ actual := chainwriter .ToSnakeCase (tc .input )
24
+ if actual != tc .expected {
25
+ t .Errorf ("expected %s, got %s" , tc .expected , actual )
26
+ }
27
+ })
28
+ }
29
+ }
You can’t perform that action at this time.
0 commit comments