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
4d05bbf2
Unverified
Commit
4d05bbf2
authored
Dec 19, 2016
by
Péter Szilágyi
Browse files
Options
Downloads
Patches
Plain Diff
accounts/abi: clean up PR and add type parsing tests
parent
471990f7
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
accounts/abi/type.go
+4
-5
4 additions, 5 deletions
accounts/abi/type.go
accounts/abi/type_test.go
+78
-0
78 additions, 0 deletions
accounts/abi/type_test.go
with
82 additions
and
5 deletions
accounts/abi/type.go
+
4
−
5
View file @
4d05bbf2
...
@@ -33,7 +33,7 @@ const (
...
@@ -33,7 +33,7 @@ const (
FixedBytesTy
FixedBytesTy
BytesTy
BytesTy
HashTy
HashTy
Fixed
P
ointTy
Fixed
p
ointTy
)
)
// Type is the reflection of the supported argument type
// Type is the reflection of the supported argument type
...
@@ -46,7 +46,6 @@ type Type struct {
...
@@ -46,7 +46,6 @@ type Type struct {
Kind
reflect
.
Kind
Kind
reflect
.
Kind
Type
reflect
.
Type
Type
reflect
.
Type
Size
int
Size
int
DecimalSize
int
// Determines the length of the binary coded decimal in fixed point types.
T
byte
// Our own type checking
T
byte
// Our own type checking
stringKind
string
// holds the unparsed string for deriving signatures
stringKind
string
// holds the unparsed string for deriving signatures
...
@@ -65,9 +64,9 @@ var (
...
@@ -65,9 +64,9 @@ var (
// string int uint fixed
// string int uint fixed
// string32 int8 uint8 uint[]
// string32 int8 uint8 uint[]
// address int256 uint256 fixed128x128[2]
// address int256 uint256 fixed128x128[2]
fullTypeRegex
=
regexp
.
MustCompile
(
"([a-zA-Z0-9]+)(
\\
[([0-9]*)
?
\\
])?"
)
fullTypeRegex
=
regexp
.
MustCompile
(
"([a-zA-Z0-9]+)(
\\
[([0-9]*)
\\
])?"
)
// typeRegex parses the abi sub types
// typeRegex parses the abi sub types
typeRegex
=
regexp
.
MustCompile
(
"([a-zA-Z]+)([0-9]
*)?x?
([0-9]
*
)?"
)
typeRegex
=
regexp
.
MustCompile
(
"([a-zA-Z]+)(
(
[0-9]
+)(x
([0-9]
+))?
)?"
)
)
)
// NewType creates a new reflection type of abi type given in t.
// NewType creates a new reflection type of abi type given in t.
...
@@ -98,7 +97,7 @@ func NewType(t string) (typ Type, err error) {
...
@@ -98,7 +97,7 @@ func NewType(t string) (typ Type, err error) {
parsedType
:=
typeRegex
.
FindAllStringSubmatch
(
res
[
1
],
-
1
)[
0
]
parsedType
:=
typeRegex
.
FindAllStringSubmatch
(
res
[
1
],
-
1
)[
0
]
// varSize is the size of the variable
// varSize is the size of the variable
var
varSize
int
var
varSize
int
if
len
(
parsedType
[
2
])
>
0
{
if
len
(
parsedType
[
3
])
>
0
{
var
err
error
var
err
error
varSize
,
err
=
strconv
.
Atoi
(
parsedType
[
2
])
varSize
,
err
=
strconv
.
Atoi
(
parsedType
[
2
])
if
err
!=
nil
{
if
err
!=
nil
{
...
...
This diff is collapsed.
Click to expand it.
accounts/abi/type_test.go
0 → 100644
+
78
−
0
View file @
4d05bbf2
// Copyright 2016 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
abi
import
(
"reflect"
"testing"
)
// typeWithoutStringer is a alias for the Type type which simply doesn't implement
// the stringer interface to allow printing type details in the tests below.
type
typeWithoutStringer
Type
// Tests that all allowed types get recognized by the type parser.
func
TestTypeRegexp
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
blob
string
kind
Type
}{
{
"int"
,
Type
{
Kind
:
reflect
.
Ptr
,
Type
:
big_t
,
Size
:
256
,
T
:
IntTy
,
stringKind
:
"int256"
}},
{
"int8"
,
Type
{
Kind
:
reflect
.
Int8
,
Type
:
big_t
,
Size
:
8
,
T
:
IntTy
,
stringKind
:
"int8"
}},
{
"int256"
,
Type
{
Kind
:
reflect
.
Ptr
,
Type
:
big_t
,
Size
:
256
,
T
:
IntTy
,
stringKind
:
"int256"
}},
{
"int[]"
,
Type
{
IsSlice
:
true
,
SliceSize
:
-
1
,
Elem
:
&
Type
{
Kind
:
reflect
.
Ptr
,
Type
:
big_t
,
Size
:
256
,
T
:
IntTy
,
stringKind
:
"int256"
},
stringKind
:
"int256[]"
}},
{
"int[2]"
,
Type
{
IsArray
:
true
,
SliceSize
:
2
,
Elem
:
&
Type
{
Kind
:
reflect
.
Ptr
,
Type
:
big_t
,
Size
:
256
,
T
:
IntTy
,
stringKind
:
"int256"
},
stringKind
:
"int256[2]"
}},
{
"int32[]"
,
Type
{
IsSlice
:
true
,
SliceSize
:
-
1
,
Elem
:
&
Type
{
Kind
:
reflect
.
Int32
,
Type
:
big_t
,
Size
:
32
,
T
:
IntTy
,
stringKind
:
"int32"
},
stringKind
:
"int32[]"
}},
{
"int32[2]"
,
Type
{
IsArray
:
true
,
SliceSize
:
2
,
Elem
:
&
Type
{
Kind
:
reflect
.
Int32
,
Type
:
big_t
,
Size
:
32
,
T
:
IntTy
,
stringKind
:
"int32"
},
stringKind
:
"int32[2]"
}},
{
"uint"
,
Type
{
Kind
:
reflect
.
Ptr
,
Type
:
ubig_t
,
Size
:
256
,
T
:
UintTy
,
stringKind
:
"uint256"
}},
{
"uint8"
,
Type
{
Kind
:
reflect
.
Uint8
,
Type
:
ubig_t
,
Size
:
8
,
T
:
UintTy
,
stringKind
:
"uint8"
}},
{
"uint256"
,
Type
{
Kind
:
reflect
.
Ptr
,
Type
:
ubig_t
,
Size
:
256
,
T
:
UintTy
,
stringKind
:
"uint256"
}},
{
"uint[]"
,
Type
{
IsSlice
:
true
,
SliceSize
:
-
1
,
Elem
:
&
Type
{
Kind
:
reflect
.
Ptr
,
Type
:
ubig_t
,
Size
:
256
,
T
:
UintTy
,
stringKind
:
"uint256"
},
stringKind
:
"uint256[]"
}},
{
"uint[2]"
,
Type
{
IsArray
:
true
,
SliceSize
:
2
,
Elem
:
&
Type
{
Kind
:
reflect
.
Ptr
,
Type
:
ubig_t
,
Size
:
256
,
T
:
UintTy
,
stringKind
:
"uint256"
},
stringKind
:
"uint256[2]"
}},
{
"uint32[]"
,
Type
{
IsSlice
:
true
,
SliceSize
:
-
1
,
Elem
:
&
Type
{
Kind
:
reflect
.
Uint32
,
Type
:
big_t
,
Size
:
32
,
T
:
UintTy
,
stringKind
:
"uint32"
},
stringKind
:
"uint32[]"
}},
{
"uint32[2]"
,
Type
{
IsArray
:
true
,
SliceSize
:
2
,
Elem
:
&
Type
{
Kind
:
reflect
.
Uint32
,
Type
:
big_t
,
Size
:
32
,
T
:
UintTy
,
stringKind
:
"uint32"
},
stringKind
:
"uint32[2]"
}},
{
"bytes"
,
Type
{
IsSlice
:
true
,
SliceSize
:
-
1
,
Elem
:
&
Type
{
Kind
:
reflect
.
Uint8
,
Type
:
ubig_t
,
Size
:
8
,
T
:
UintTy
,
stringKind
:
"uint8"
},
T
:
BytesTy
,
stringKind
:
"bytes"
}},
{
"bytes32"
,
Type
{
IsArray
:
true
,
SliceSize
:
32
,
Elem
:
&
Type
{
Kind
:
reflect
.
Uint8
,
Type
:
ubig_t
,
Size
:
8
,
T
:
UintTy
,
stringKind
:
"uint8"
},
T
:
FixedBytesTy
,
stringKind
:
"bytes32"
}},
{
"bytes[]"
,
Type
{
IsSlice
:
true
,
SliceSize
:
-
1
,
Elem
:
&
Type
{
IsSlice
:
true
,
SliceSize
:
-
1
,
Elem
:
&
Type
{
Kind
:
reflect
.
Uint8
,
Type
:
ubig_t
,
Size
:
8
,
T
:
UintTy
,
stringKind
:
"uint8"
},
T
:
BytesTy
,
stringKind
:
"bytes"
},
stringKind
:
"bytes[]"
}},
{
"bytes[2]"
,
Type
{
IsArray
:
true
,
SliceSize
:
2
,
Elem
:
&
Type
{
IsSlice
:
true
,
SliceSize
:
-
1
,
Elem
:
&
Type
{
Kind
:
reflect
.
Uint8
,
Type
:
ubig_t
,
Size
:
8
,
T
:
UintTy
,
stringKind
:
"uint8"
},
T
:
BytesTy
,
stringKind
:
"bytes"
},
stringKind
:
"bytes[2]"
}},
{
"bytes32[]"
,
Type
{
IsSlice
:
true
,
SliceSize
:
-
1
,
Elem
:
&
Type
{
IsArray
:
true
,
SliceSize
:
32
,
Elem
:
&
Type
{
Kind
:
reflect
.
Uint8
,
Type
:
ubig_t
,
Size
:
8
,
T
:
UintTy
,
stringKind
:
"uint8"
},
T
:
FixedBytesTy
,
stringKind
:
"bytes32"
},
stringKind
:
"bytes32[]"
}},
{
"bytes32[2]"
,
Type
{
IsArray
:
true
,
SliceSize
:
2
,
Elem
:
&
Type
{
IsArray
:
true
,
SliceSize
:
32
,
Elem
:
&
Type
{
Kind
:
reflect
.
Uint8
,
Type
:
ubig_t
,
Size
:
8
,
T
:
UintTy
,
stringKind
:
"uint8"
},
T
:
FixedBytesTy
,
stringKind
:
"bytes32"
},
stringKind
:
"bytes32[2]"
}},
{
"string"
,
Type
{
Kind
:
reflect
.
String
,
Size
:
-
1
,
T
:
StringTy
,
stringKind
:
"string"
}},
{
"string[]"
,
Type
{
IsSlice
:
true
,
SliceSize
:
-
1
,
Elem
:
&
Type
{
Kind
:
reflect
.
String
,
Size
:
-
1
,
T
:
StringTy
,
stringKind
:
"string"
},
stringKind
:
"string[]"
}},
{
"string[2]"
,
Type
{
IsArray
:
true
,
SliceSize
:
2
,
Elem
:
&
Type
{
Kind
:
reflect
.
String
,
Size
:
-
1
,
T
:
StringTy
,
stringKind
:
"string"
},
stringKind
:
"string[2]"
}},
{
"address"
,
Type
{
Kind
:
reflect
.
Array
,
Type
:
address_t
,
Size
:
20
,
T
:
AddressTy
,
stringKind
:
"address"
}},
{
"address[]"
,
Type
{
IsSlice
:
true
,
SliceSize
:
-
1
,
Elem
:
&
Type
{
Kind
:
reflect
.
Array
,
Type
:
address_t
,
Size
:
20
,
T
:
AddressTy
,
stringKind
:
"address"
},
stringKind
:
"address[]"
}},
{
"address[2]"
,
Type
{
IsArray
:
true
,
SliceSize
:
2
,
Elem
:
&
Type
{
Kind
:
reflect
.
Array
,
Type
:
address_t
,
Size
:
20
,
T
:
AddressTy
,
stringKind
:
"address"
},
stringKind
:
"address[2]"
}},
// TODO when fixed types are implemented properly
// {"fixed", Type{}},
// {"fixed128x128", Type{}},
// {"fixed[]", Type{}},
// {"fixed[2]", Type{}},
// {"fixed128x128[]", Type{}},
// {"fixed128x128[2]", Type{}},
}
for
i
,
tt
:=
range
tests
{
typ
,
err
:=
NewType
(
tt
.
blob
)
if
err
!=
nil
{
t
.
Errorf
(
"type %d: failed to parse type string: %v"
,
i
,
err
)
}
if
!
reflect
.
DeepEqual
(
typ
,
tt
.
kind
)
{
t
.
Errorf
(
"type %d: parsed type mismatch:
\n
have %+v
\n
want %+v"
,
i
,
typeWithoutStringer
(
typ
),
typeWithoutStringer
(
tt
.
kind
))
}
}
}
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