good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
0ec5ab41
Commit
0ec5ab41
authored
Nov 21, 2019
by
Felix Lange
Committed by
Péter Szilágyi
Nov 21, 2019
Browse files
Options
Downloads
Patches
Plain Diff
common: improve GraphQL error messages (#20354)
parent
07541004
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
common/bytes_test.go
+27
-25
27 additions, 25 deletions
common/bytes_test.go
common/main_test.go
+0
-25
0 additions, 25 deletions
common/main_test.go
common/types.go
+5
-4
5 additions, 4 deletions
common/types.go
with
32 additions
and
54 deletions
common/bytes_test.go
+
27
−
25
View file @
0ec5ab41
...
...
@@ -19,41 +19,43 @@ package common
import
(
"bytes"
"testing"
checker
"gopkg.in/check.v1"
)
type
BytesSuite
struct
{}
var
_
=
checker
.
Suite
(
&
BytesSuite
{})
func
TestCopyBytes
(
t
*
testing
.
T
)
{
input
:=
[]
byte
{
1
,
2
,
3
,
4
}
func
(
s
*
BytesSuite
)
TestCopyBytes
(
c
*
checker
.
C
)
{
data1
:=
[]
byte
{
1
,
2
,
3
,
4
}
exp1
:=
[]
byte
{
1
,
2
,
3
,
4
}
res1
:=
CopyBytes
(
data1
)
c
.
Assert
(
res1
,
checker
.
DeepEquals
,
exp1
)
v
:=
CopyBytes
(
input
)
if
!
bytes
.
Equal
(
v
,
[]
byte
{
1
,
2
,
3
,
4
})
{
t
.
Fatal
(
"not equal after copy"
)
}
v
[
0
]
=
99
if
bytes
.
Equal
(
v
,
input
)
{
t
.
Fatal
(
"result is not a copy"
)
}
}
func
(
s
*
BytesSuite
)
TestLeftPadBytes
(
c
*
checker
.
C
)
{
val1
:=
[]
byte
{
1
,
2
,
3
,
4
}
exp1
:=
[]
byte
{
0
,
0
,
0
,
0
,
1
,
2
,
3
,
4
}
res1
:=
LeftPadBytes
(
val1
,
8
)
res2
:=
LeftPadBytes
(
val1
,
2
)
func
TestLeftPadBytes
(
t
*
testing
.
T
)
{
val
:=
[]
byte
{
1
,
2
,
3
,
4
}
padded
:=
[]
byte
{
0
,
0
,
0
,
0
,
1
,
2
,
3
,
4
}
c
.
Assert
(
res1
,
checker
.
DeepEquals
,
exp1
)
c
.
Assert
(
res2
,
checker
.
DeepEquals
,
val1
)
if
r
:=
LeftPadBytes
(
val
,
8
);
!
bytes
.
Equal
(
r
,
padded
)
{
t
.
Fatalf
(
"LeftPadBytes(%v, 8) == %v"
,
val
,
r
)
}
if
r
:=
LeftPadBytes
(
val
,
2
);
!
bytes
.
Equal
(
r
,
val
)
{
t
.
Fatalf
(
"LeftPadBytes(%v, 2) == %v"
,
val
,
r
)
}
}
func
(
s
*
BytesSuite
)
TestRightPadBytes
(
c
*
checker
.
C
)
{
func
TestRightPadBytes
(
t
*
testing
.
T
)
{
val
:=
[]
byte
{
1
,
2
,
3
,
4
}
exp
:=
[]
byte
{
1
,
2
,
3
,
4
,
0
,
0
,
0
,
0
}
resstd
:=
RightPadBytes
(
val
,
8
)
resshrt
:=
RightPadBytes
(
val
,
2
)
padded
:=
[]
byte
{
1
,
2
,
3
,
4
,
0
,
0
,
0
,
0
}
c
.
Assert
(
resstd
,
checker
.
DeepEquals
,
exp
)
c
.
Assert
(
resshrt
,
checker
.
DeepEquals
,
val
)
if
r
:=
RightPadBytes
(
val
,
8
);
!
bytes
.
Equal
(
r
,
padded
)
{
t
.
Fatalf
(
"RightPadBytes(%v, 8) == %v"
,
val
,
r
)
}
if
r
:=
RightPadBytes
(
val
,
2
);
!
bytes
.
Equal
(
r
,
val
)
{
t
.
Fatalf
(
"RightPadBytes(%v, 2) == %v"
,
val
,
r
)
}
}
func
TestFromHex
(
t
*
testing
.
T
)
{
...
...
This diff is collapsed.
Click to expand it.
common/main_test.go
deleted
100644 → 0
+
0
−
25
View file @
07541004
// Copyright 2014 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package
common
import
(
"testing"
checker
"gopkg.in/check.v1"
)
func
Test
(
t
*
testing
.
T
)
{
checker
.
TestingT
(
t
)
}
This diff is collapsed.
Click to expand it.
common/types.go
+
5
−
4
View file @
0ec5ab41
...
...
@@ -20,6 +20,7 @@ import (
"database/sql/driver"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"math/big"
"math/rand"
...
...
@@ -142,7 +143,7 @@ func (h Hash) Value() (driver.Value, error) {
}
// ImplementsGraphQLType returns true if Hash implements the specified GraphQL type.
func
(
_
Hash
)
ImplementsGraphQLType
(
name
string
)
bool
{
return
name
==
"Bytes32"
}
func
(
Hash
)
ImplementsGraphQLType
(
name
string
)
bool
{
return
name
==
"Bytes32"
}
// UnmarshalGraphQL unmarshals the provided GraphQL query data.
func
(
h
*
Hash
)
UnmarshalGraphQL
(
input
interface
{})
error
{
...
...
@@ -151,7 +152,7 @@ func (h *Hash) UnmarshalGraphQL(input interface{}) error {
case
string
:
err
=
h
.
UnmarshalText
([]
byte
(
input
))
default
:
err
=
fmt
.
Errorf
(
"
U
nexpected type for
Bytes32: %v
"
,
input
)
err
=
fmt
.
Errorf
(
"
u
nexpected type
%T
for
Hash
"
,
input
)
}
return
err
}
...
...
@@ -290,7 +291,7 @@ func (a *Address) UnmarshalGraphQL(input interface{}) error {
case
string
:
err
=
a
.
UnmarshalText
([]
byte
(
input
))
default
:
err
=
fmt
.
Errorf
(
"
U
nexpected type for Address
: %v
"
,
input
)
err
=
fmt
.
Errorf
(
"
u
nexpected type
%T
for Address"
,
input
)
}
return
err
}
...
...
@@ -323,7 +324,7 @@ func NewMixedcaseAddress(addr Address) MixedcaseAddress {
// NewMixedcaseAddressFromString is mainly meant for unit-testing
func
NewMixedcaseAddressFromString
(
hexaddr
string
)
(
*
MixedcaseAddress
,
error
)
{
if
!
IsHexAddress
(
hexaddr
)
{
return
nil
,
fmt
.
Errorf
(
"
I
nvalid address"
)
return
nil
,
errors
.
New
(
"
i
nvalid address"
)
}
a
:=
FromHex
(
hexaddr
)
return
&
MixedcaseAddress
{
addr
:
BytesToAddress
(
a
),
original
:
hexaddr
},
nil
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment