Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mybee
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
mybee
Commits
0f035326
Commit
0f035326
authored
Jan 28, 2020
by
Janos Guljas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add swarm Address tests
parent
f8886987
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
65 additions
and
0 deletions
+65
-0
swarm_test.go
pkg/swarm/swarm_test.go
+65
-0
No files found.
pkg/swarm/swarm_test.go
0 → 100644
View file @
0f035326
// Copyright 2020 The Swarm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
swarm_test
import
(
"bytes"
"encoding/hex"
"errors"
"testing"
"github.com/ethersphere/bee/pkg/swarm"
)
func
TestAddress
(
t
*
testing
.
T
)
{
for
_
,
tc
:=
range
[]
struct
{
name
string
hex
string
want
swarm
.
Address
wantErr
error
}{
{
name
:
"blank"
,
hex
:
""
,
want
:
swarm
.
ZeroAddress
,
},
{
name
:
"odd"
,
hex
:
"0"
,
wantErr
:
hex
.
ErrLength
,
},
{
name
:
"zero"
,
hex
:
"00"
,
want
:
[]
byte
{
0
},
},
{
name
:
"one"
,
hex
:
"01"
,
want
:
[]
byte
{
1
},
},
{
name
:
"arbitrary"
,
hex
:
"35a26b7bb6455cbabe7a0e05aafbd0b8b26feac843e3b9a649468d0ea37a12b2"
,
want
:
[]
byte
{
0x35
,
0xa2
,
0x6b
,
0x7b
,
0xb6
,
0x45
,
0x5c
,
0xba
,
0xbe
,
0x7a
,
0xe
,
0x5
,
0xaa
,
0xfb
,
0xd0
,
0xb8
,
0xb2
,
0x6f
,
0xea
,
0xc8
,
0x43
,
0xe3
,
0xb9
,
0xa6
,
0x49
,
0x46
,
0x8d
,
0xe
,
0xa3
,
0x7a
,
0x12
,
0xb2
},
},
}
{
t
.
Run
(
tc
.
name
,
func
(
t
*
testing
.
T
)
{
a
,
err
:=
swarm
.
NewAddress
(
tc
.
hex
)
if
!
errors
.
Is
(
err
,
tc
.
wantErr
)
{
t
.
Fatalf
(
"got error %v, want %v"
,
err
,
tc
.
wantErr
)
}
if
!
bytes
.
Equal
(
a
,
tc
.
want
)
{
t
.
Errorf
(
"got address %#v, want %#v"
,
a
,
tc
.
want
)
}
if
!
a
.
Equal
(
tc
.
want
)
{
t
.
Errorf
(
"address %v not equal to %v"
,
a
,
tc
.
want
)
}
if
a
.
IsZero
()
!=
tc
.
want
.
IsZero
()
{
t
.
Errorf
(
"got address as zero=%v, want zero=%v"
,
a
.
IsZero
(),
tc
.
want
.
IsZero
())
}
})
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment