Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
sidecar
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
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
link33
sidecar
Commits
f7fdb365
Commit
f7fdb365
authored
Oct 22, 2021
by
suyanlong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
🐛
Fixed unit test
parent
e86d2fae
Pipeline
#8154
failed with stages
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
22 deletions
+21
-22
mock_txcrypto.go
internal/txcrypto/mock_txcrypto/mock_txcrypto.go
+8
-8
txcrypto_test.go
internal/txcrypto/txcrypto_test.go
+13
-14
No files found.
internal/txcrypto/mock_txcrypto/mock_txcrypto.go
View file @
f7fdb365
...
@@ -34,31 +34,31 @@ func (m *MockCryptor) EXPECT() *MockCryptorMockRecorder {
...
@@ -34,31 +34,31 @@ func (m *MockCryptor) EXPECT() *MockCryptorMockRecorder {
}
}
// Decrypt mocks base method.
// Decrypt mocks base method.
func
(
m
*
MockCryptor
)
Decrypt
(
content
[]
byte
,
address
string
)
([]
byte
,
error
)
{
func
(
m
*
MockCryptor
)
Decrypt
(
content
[]
byte
,
address
,
mode
string
)
([]
byte
,
error
)
{
m
.
ctrl
.
T
.
Helper
()
m
.
ctrl
.
T
.
Helper
()
ret
:=
m
.
ctrl
.
Call
(
m
,
"Decrypt"
,
content
,
address
)
ret
:=
m
.
ctrl
.
Call
(
m
,
"Decrypt"
,
content
,
address
,
mode
)
ret0
,
_
:=
ret
[
0
]
.
([]
byte
)
ret0
,
_
:=
ret
[
0
]
.
([]
byte
)
ret1
,
_
:=
ret
[
1
]
.
(
error
)
ret1
,
_
:=
ret
[
1
]
.
(
error
)
return
ret0
,
ret1
return
ret0
,
ret1
}
}
// Decrypt indicates an expected call of Decrypt.
// Decrypt indicates an expected call of Decrypt.
func
(
mr
*
MockCryptorMockRecorder
)
Decrypt
(
content
,
address
interface
{})
*
gomock
.
Call
{
func
(
mr
*
MockCryptorMockRecorder
)
Decrypt
(
content
,
address
,
mode
interface
{})
*
gomock
.
Call
{
mr
.
mock
.
ctrl
.
T
.
Helper
()
mr
.
mock
.
ctrl
.
T
.
Helper
()
return
mr
.
mock
.
ctrl
.
RecordCallWithMethodType
(
mr
.
mock
,
"Decrypt"
,
reflect
.
TypeOf
((
*
MockCryptor
)(
nil
)
.
Decrypt
),
content
,
address
)
return
mr
.
mock
.
ctrl
.
RecordCallWithMethodType
(
mr
.
mock
,
"Decrypt"
,
reflect
.
TypeOf
((
*
MockCryptor
)(
nil
)
.
Decrypt
),
content
,
address
,
mode
)
}
}
// Encrypt mocks base method.
// Encrypt mocks base method.
func
(
m
*
MockCryptor
)
Encrypt
(
content
[]
byte
,
address
string
)
([]
byte
,
error
)
{
func
(
m
*
MockCryptor
)
Encrypt
(
content
[]
byte
,
address
,
mode
string
)
([]
byte
,
error
)
{
m
.
ctrl
.
T
.
Helper
()
m
.
ctrl
.
T
.
Helper
()
ret
:=
m
.
ctrl
.
Call
(
m
,
"Encrypt"
,
content
,
address
)
ret
:=
m
.
ctrl
.
Call
(
m
,
"Encrypt"
,
content
,
address
,
mode
)
ret0
,
_
:=
ret
[
0
]
.
([]
byte
)
ret0
,
_
:=
ret
[
0
]
.
([]
byte
)
ret1
,
_
:=
ret
[
1
]
.
(
error
)
ret1
,
_
:=
ret
[
1
]
.
(
error
)
return
ret0
,
ret1
return
ret0
,
ret1
}
}
// Encrypt indicates an expected call of Encrypt.
// Encrypt indicates an expected call of Encrypt.
func
(
mr
*
MockCryptorMockRecorder
)
Encrypt
(
content
,
address
interface
{})
*
gomock
.
Call
{
func
(
mr
*
MockCryptorMockRecorder
)
Encrypt
(
content
,
address
,
mode
interface
{})
*
gomock
.
Call
{
mr
.
mock
.
ctrl
.
T
.
Helper
()
mr
.
mock
.
ctrl
.
T
.
Helper
()
return
mr
.
mock
.
ctrl
.
RecordCallWithMethodType
(
mr
.
mock
,
"Encrypt"
,
reflect
.
TypeOf
((
*
MockCryptor
)(
nil
)
.
Encrypt
),
content
,
address
)
return
mr
.
mock
.
ctrl
.
RecordCallWithMethodType
(
mr
.
mock
,
"Encrypt"
,
reflect
.
TypeOf
((
*
MockCryptor
)(
nil
)
.
Encrypt
),
content
,
address
,
mode
)
}
}
internal/txcrypto/txcrypto_test.go
View file @
f7fdb365
...
@@ -12,6 +12,7 @@ import (
...
@@ -12,6 +12,7 @@ import (
rpcx
"github.com/link33/sidecar/hub/client"
rpcx
"github.com/link33/sidecar/hub/client"
"github.com/link33/sidecar/hub/client/mock_client"
"github.com/link33/sidecar/hub/client/mock_client"
"github.com/link33/sidecar/internal/repo"
"github.com/link33/sidecar/model/pb"
"github.com/link33/sidecar/model/pb"
)
)
...
@@ -33,8 +34,7 @@ func TestRelayCryptor(t *testing.T) {
...
@@ -33,8 +34,7 @@ func TestRelayCryptor(t *testing.T) {
Ret
:
pubBytes2
,
Ret
:
pubBytes2
,
}
}
rc1
,
err
:=
NewRelayCryptor
(
mockClient
,
privKey1
)
rc1
:=
NewCryptor
(
mockClient
,
nil
,
privKey1
)
require
.
Nil
(
t
,
err
)
address1
,
err
:=
privKey1
.
PublicKey
()
.
Address
()
address1
,
err
:=
privKey1
.
PublicKey
()
.
Address
()
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
err
)
...
@@ -43,7 +43,7 @@ func TestRelayCryptor(t *testing.T) {
...
@@ -43,7 +43,7 @@ func TestRelayCryptor(t *testing.T) {
addr1
:=
address1
.
String
()
addr1
:=
address1
.
String
()
keyMap2
:=
make
(
map
[
string
][]
byte
)
keyMap2
:=
make
(
map
[
string
][]
byte
)
keyMap2
[
addr1
]
=
pubBytes1
keyMap2
[
addr1
]
=
pubBytes1
rc2
:=
&
RelayC
ryptor
{
rc2
:=
&
c
ryptor
{
privKey
:
privKey2
,
privKey
:
privKey2
,
keyMap
:
keyMap2
,
keyMap
:
keyMap2
,
}
}
...
@@ -53,21 +53,21 @@ func TestRelayCryptor(t *testing.T) {
...
@@ -53,21 +53,21 @@ func TestRelayCryptor(t *testing.T) {
mockClient
.
EXPECT
()
.
InvokeBVMContract
(
gomock
.
Any
(),
gomock
.
Any
(),
gomock
.
Any
(),
rpcx
.
String
(
""
))
.
Return
(
nil
,
fmt
.
Errorf
(
"invoke bvm contract error"
))
.
AnyTimes
()
mockClient
.
EXPECT
()
.
InvokeBVMContract
(
gomock
.
Any
(),
gomock
.
Any
(),
gomock
.
Any
(),
rpcx
.
String
(
""
))
.
Return
(
nil
,
fmt
.
Errorf
(
"invoke bvm contract error"
))
.
AnyTimes
()
content
:=
[]
byte
(
"bitxhub cryptor test"
)
content
:=
[]
byte
(
"bitxhub cryptor test"
)
encryptBytes
,
err
:=
rc1
.
Encrypt
(
content
,
addr2
)
encryptBytes
,
err
:=
rc1
.
Encrypt
(
content
,
addr2
,
repo
.
RelayMode
)
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
err
)
decryptBytes
,
err
:=
rc2
.
Decrypt
(
encryptBytes
,
addr1
)
decryptBytes
,
err
:=
rc2
.
Decrypt
(
encryptBytes
,
addr1
,
repo
.
RelayMode
)
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
err
)
require
.
Equal
(
t
,
decryptBytes
,
content
)
require
.
Equal
(
t
,
decryptBytes
,
content
)
fmt
.
Println
(
string
(
decryptBytes
))
fmt
.
Println
(
string
(
decryptBytes
))
// encrypt with invoke bvm contract error
// encrypt with invoke bvm contract error
_
,
err
=
rc1
.
Encrypt
(
content
,
""
)
_
,
err
=
rc1
.
Encrypt
(
content
,
""
,
repo
.
RelayMode
)
require
.
NotNil
(
t
,
err
)
require
.
NotNil
(
t
,
err
)
// decrypt with wrong pubkey
// decrypt with wrong pubkey
rc2
.
keyMap
[
addr1
]
=
[]
byte
(
""
)
rc2
.
keyMap
[
addr1
]
=
[]
byte
(
""
)
_
,
err
=
rc2
.
Decrypt
(
encryptBytes
,
addr1
)
_
,
err
=
rc2
.
Decrypt
(
encryptBytes
,
addr1
,
repo
.
RelayMode
)
require
.
NotNil
(
t
,
err
)
require
.
NotNil
(
t
,
err
)
}
}
...
@@ -86,8 +86,7 @@ func TestDirectCryptor(t *testing.T) {
...
@@ -86,8 +86,7 @@ func TestDirectCryptor(t *testing.T) {
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
err
)
addr2
:=
address2
.
String
()
addr2
:=
address2
.
String
()
rc1
,
err
:=
NewDirectCryptor
(
mockAppchainMgr
,
privKey1
)
rc1
:=
NewCryptor
(
nil
,
mockAppchainMgr
,
privKey1
)
require
.
Nil
(
t
,
err
)
address1
,
err
:=
privKey1
.
PublicKey
()
.
Address
()
address1
,
err
:=
privKey1
.
PublicKey
()
.
Address
()
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
err
)
...
@@ -96,7 +95,7 @@ func TestDirectCryptor(t *testing.T) {
...
@@ -96,7 +95,7 @@ func TestDirectCryptor(t *testing.T) {
addr1
:=
address1
.
String
()
addr1
:=
address1
.
String
()
keyMap2
:=
make
(
map
[
string
][]
byte
)
keyMap2
:=
make
(
map
[
string
][]
byte
)
keyMap2
[
addr1
]
=
pubBytes1
keyMap2
[
addr1
]
=
pubBytes1
rc2
:=
&
DirectC
ryptor
{
rc2
:=
&
c
ryptor
{
privKey
:
privKey2
,
privKey
:
privKey2
,
keyMap
:
keyMap2
,
keyMap
:
keyMap2
,
}
}
...
@@ -106,20 +105,20 @@ func TestDirectCryptor(t *testing.T) {
...
@@ -106,20 +105,20 @@ func TestDirectCryptor(t *testing.T) {
mockAppchainMgr
.
EXPECT
()
.
GetPubKeyByChainID
(
""
)
.
Return
(
false
,
nil
)
.
AnyTimes
()
mockAppchainMgr
.
EXPECT
()
.
GetPubKeyByChainID
(
""
)
.
Return
(
false
,
nil
)
.
AnyTimes
()
content
:=
[]
byte
(
"bitxhub cryptor test"
)
content
:=
[]
byte
(
"bitxhub cryptor test"
)
encryptBytes
,
err
:=
rc1
.
Encrypt
(
content
,
addr2
)
encryptBytes
,
err
:=
rc1
.
Encrypt
(
content
,
addr2
,
repo
.
DirectMode
)
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
err
)
decryptBytes
,
err
:=
rc2
.
Decrypt
(
encryptBytes
,
addr1
)
decryptBytes
,
err
:=
rc2
.
Decrypt
(
encryptBytes
,
addr1
,
repo
.
DirectMode
)
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
err
)
require
.
Equal
(
t
,
decryptBytes
,
content
)
require
.
Equal
(
t
,
decryptBytes
,
content
)
fmt
.
Println
(
string
(
decryptBytes
))
fmt
.
Println
(
string
(
decryptBytes
))
// encrypt with nil address
// encrypt with nil address
_
,
err
=
rc1
.
Encrypt
(
content
,
""
)
_
,
err
=
rc1
.
Encrypt
(
content
,
""
,
repo
.
DirectMode
)
require
.
NotNil
(
t
,
err
)
require
.
NotNil
(
t
,
err
)
// decrypt with wrong pubkey
// decrypt with wrong pubkey
rc2
.
keyMap
[
addr1
]
=
[]
byte
(
""
)
rc2
.
keyMap
[
addr1
]
=
[]
byte
(
""
)
_
,
err
=
rc2
.
Decrypt
(
encryptBytes
,
addr1
)
_
,
err
=
rc2
.
Decrypt
(
encryptBytes
,
addr1
,
repo
.
DirectMode
)
require
.
NotNil
(
t
,
err
)
require
.
NotNil
(
t
,
err
)
}
}
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