Skip to content

Commit

Permalink
refactor: rename to parseNamespaceID
Browse files Browse the repository at this point in the history
  • Loading branch information
rootulp authored and distractedm1nd committed Jun 16, 2023
1 parent 6280735 commit 819315b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
22 changes: 11 additions & 11 deletions cmd/celestia/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,17 @@ func parseParams(method string, params []string) []interface{} {
}
parsedParams[0] = root
// 2. NamespaceID
nID, err := parseNamespace(params[1])
nID, err := parseNamespaceID(params[1])
if err != nil {
panic(fmt.Sprintf("Error parsing namespace: %v", err))
panic(fmt.Sprintf("Error parsing namespace ID: %v", err))
}
parsedParams[1] = nID
case "Submit":
// 1. NamespaceID
var err error
nID, err := parseNamespace(params[0])
nID, err := parseNamespaceID(params[0])
if err != nil {
panic(fmt.Sprintf("Error parsing namespace: %v", err))
panic(fmt.Sprintf("Error parsing namespace ID: %v", err))
}
// 2. Blob data
var blobData []byte
Expand Down Expand Up @@ -163,9 +163,9 @@ func parseParams(method string, params []string) []interface{} {
}
parsedParams[1] = num
// 3. NamespaceID
nID, err := parseNamespace(params[2])
nID, err := parseNamespaceID(params[2])
if err != nil {
panic(fmt.Sprintf("Error parsing namespace: %v", err))
panic(fmt.Sprintf("Error parsing namespace ID: %v", err))
}
// 4. Blob data
var blobData []byte
Expand Down Expand Up @@ -202,9 +202,9 @@ func parseParams(method string, params []string) []interface{} {
}
parsedParams[0] = num
// 2. NamespaceID
nID, err := parseNamespace(params[1])
nID, err := parseNamespaceID(params[1])
if err != nil {
panic(fmt.Sprintf("Error parsing namespace: %v", err))
panic(fmt.Sprintf("Error parsing namespace ID: %v", err))
}
parsedParams[1] = nID
// 3: Commitment
Expand All @@ -222,9 +222,9 @@ func parseParams(method string, params []string) []interface{} {
}
parsedParams[0] = num
// 2. NamespaceID
nID, err := parseNamespace(params[1])
nID, err := parseNamespaceID(params[1])
if err != nil {
panic(fmt.Sprintf("Error parsing namespace: %v", err))
panic(fmt.Sprintf("Error parsing namespace ID: %v", err))
}
parsedParams[1] = []namespace.ID{nID}
return parsedParams
Expand Down Expand Up @@ -419,7 +419,7 @@ func parseSignatureForHelpstring(methodSig reflect.StructField) string {
return simplifiedSignature
}

func parseNamespace(param string) (namespace.ID, error) {
func parseNamespaceID(param string) (namespace.ID, error) {
var nID []byte
var err error
if strings.HasPrefix(param, "0x") {
Expand Down
16 changes: 8 additions & 8 deletions cmd/celestia/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/celestiaorg/nmt/namespace"
)

func Test_parseNamespace(t *testing.T) {
func Test_parseNamespaceID(t *testing.T) {
type testCase struct {
name string
param string
Expand All @@ -17,7 +17,7 @@ func Test_parseNamespace(t *testing.T) {
}
testCases := []testCase{
{
name: "8 byte hex encoded namespace gets right padded",
name: "8 byte hex encoded namespace ID gets right padded",
param: "0x0c204d39600fddd3",
want: namespace.ID{
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
Expand All @@ -26,7 +26,7 @@ func Test_parseNamespace(t *testing.T) {
wantErr: false,
},
{
name: "10 byte hex encoded namespace",
name: "10 byte hex encoded namespace ID",
param: "0x42690c204d39600fddd3",
want: namespace.ID{
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
Expand All @@ -35,7 +35,7 @@ func Test_parseNamespace(t *testing.T) {
wantErr: false,
},
{
name: "29 byte hex encoded namespace",
name: "29 byte hex encoded namespace ID",
param: "0x0000000000000000000000000000000000000001010101010101010101",
want: namespace.ID{
0x0, // namespace version
Expand All @@ -45,13 +45,13 @@ func Test_parseNamespace(t *testing.T) {
wantErr: false,
},
{
name: "11 byte hex encoded namespace returns error",
name: "11 byte hex encoded namespace ID returns error",
param: "0x42690c204d39600fddd3a3",
want: namespace.ID{},
wantErr: true,
},
{
name: "10 byte base64 encoded namespace",
name: "10 byte base64 encoded namespace ID",
param: "QmkMIE05YA/d0w==",
want: namespace.ID{
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
Expand All @@ -60,7 +60,7 @@ func Test_parseNamespace(t *testing.T) {
wantErr: false,
},
{
name: "not base64 or hex encoded namespace returns error",
name: "not base64 or hex encoded namespace ID returns error",
param: "5748493939429",
want: namespace.ID{},
wantErr: true,
Expand All @@ -69,7 +69,7 @@ func Test_parseNamespace(t *testing.T) {

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
got, err := parseNamespace(tc.param)
got, err := parseNamespaceID(tc.param)
if tc.wantErr {
assert.Error(t, err)
return
Expand Down

0 comments on commit 819315b

Please sign in to comment.