Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
plugin
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
plugin
Commits
62bf6d3d
Commit
62bf6d3d
authored
Jun 05, 2020
by
QM
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updata ethereum_test.go
parent
81684945
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
385 additions
and
400 deletions
+385
-400
bridgeBank_test.go
.../x2ethereum/ebrelayer/ethcontract/test/bridgeBank_test.go
+21
-162
setupTestEnv.go
...ethereum/ebrelayer/ethcontract/test/setup/setupTestEnv.go
+27
-3
recover.go
plugin/dapp/x2ethereum/ebrelayer/ethtxs/recover.go
+11
-0
ethereum_test.go
...pp/x2ethereum/ebrelayer/relayer/ethereum/ethereum_test.go
+300
-214
exec_test.go
plugin/dapp/x2ethereum/executor/exec_test.go
+24
-19
x2ethereumaction.go
plugin/dapp/x2ethereum/executor/x2ethereumaction.go
+1
-1
x2ethereumdb.go
plugin/dapp/x2ethereum/executor/x2ethereumdb.go
+1
-1
No files found.
plugin/dapp/x2ethereum/ebrelayer/ethcontract/test/bridgeBank_test.go
View file @
62bf6d3d
...
@@ -24,29 +24,8 @@ func TestBrigeTokenCreat(t *testing.T) {
...
@@ -24,29 +24,8 @@ func TestBrigeTokenCreat(t *testing.T) {
ctx
:=
context
.
Background
()
ctx
:=
context
.
Background
()
println
(
"TEST:BridgeToken creation (Chain33 assets)"
)
println
(
"TEST:BridgeToken creation (Chain33 assets)"
)
//1st部署相关合约
//1st部署相关合约
sim
,
para
:=
setup
.
PrepareTestEnv
()
para
,
sim
,
x2EthContracts
,
x2EthDeployInfo
,
err
:=
setup
.
DeployContracts
()
require
.
NoError
(
t
,
err
)
balance
,
_
:=
sim
.
BalanceAt
(
ctx
,
para
.
Deployer
,
nil
)
fmt
.
Println
(
"deployer addr,"
,
para
.
Deployer
.
String
(),
"balance ="
,
balance
.
String
())
/////////////////////////EstimateGas///////////////////////////
callMsg
:=
ethereum
.
CallMsg
{
From
:
para
.
Deployer
,
Data
:
common
.
FromHex
(
generated
.
BridgeBankBin
),
}
gas
,
err
:=
sim
.
EstimateGas
(
ctx
,
callMsg
)
if
nil
!=
err
{
panic
(
"failed to estimate gas due to:"
+
err
.
Error
())
}
fmt
.
Printf
(
"
\n
The estimated gas=%d"
,
gas
)
////////////////////////////////////////////////////
x2EthContracts
,
x2EthDeployInfo
,
err
:=
ethtxs
.
DeployAndInit
(
sim
,
para
)
if
nil
!=
err
{
t
.
Fatalf
(
"DeployAndInit failed due to:%s"
,
err
.
Error
())
}
sim
.
Commit
()
//2nd:订阅事件
//2nd:订阅事件
eventName
:=
"LogNewBridgeToken"
eventName
:=
"LogNewBridgeToken"
...
@@ -130,33 +109,8 @@ func TestBrigeTokenMint(t *testing.T) {
...
@@ -130,33 +109,8 @@ func TestBrigeTokenMint(t *testing.T) {
ctx
:=
context
.
Background
()
ctx
:=
context
.
Background
()
println
(
"TEST:BridgeToken creation (Chain33 assets)"
)
println
(
"TEST:BridgeToken creation (Chain33 assets)"
)
//1st部署相关合约
//1st部署相关合约
sim
,
para
:=
setup
.
PrepareTestEnv
()
para
,
sim
,
x2EthContracts
,
x2EthDeployInfo
,
err
:=
setup
.
DeployContracts
()
require
.
NoError
(
t
,
err
)
balance
,
_
:=
sim
.
BalanceAt
(
ctx
,
para
.
Deployer
,
nil
)
fmt
.
Println
(
"deployer addr,"
,
para
.
Deployer
.
String
(),
"balance ="
,
balance
.
String
())
/////////////////////////EstimateGas///////////////////////////
callMsg
:=
ethereum
.
CallMsg
{
From
:
para
.
Deployer
,
Data
:
common
.
FromHex
(
generated
.
BridgeBankBin
),
}
gas
,
err
:=
sim
.
EstimateGas
(
ctx
,
callMsg
)
if
nil
!=
err
{
panic
(
"failed to estimate gas due to:"
+
err
.
Error
())
}
fmt
.
Printf
(
"
\n
The estimated gas=%d"
,
gas
)
////////////////////////////////////////////////////
x2EthContracts
,
x2EthDeployInfo
,
err
:=
ethtxs
.
DeployAndInit
(
sim
,
para
)
if
nil
!=
err
{
t
.
Fatalf
(
"DeployAndInit failed due to:%s"
,
err
.
Error
())
}
sim
.
Commit
()
auth
,
err
:=
ethtxs
.
PrepareAuth
(
sim
,
para
.
DeployPrivateKey
,
para
.
Operator
)
if
nil
!=
err
{
t
.
Fatalf
(
"PrepareAuth failed due to:%s"
,
err
.
Error
())
}
//2nd:订阅事件
//2nd:订阅事件
eventName
:=
"LogNewBridgeToken"
eventName
:=
"LogNewBridgeToken"
...
@@ -183,6 +137,10 @@ func TestBrigeTokenMint(t *testing.T) {
...
@@ -183,6 +137,10 @@ func TestBrigeTokenMint(t *testing.T) {
//3rd:创建token
//3rd:创建token
symbol
:=
"BTY"
symbol
:=
"BTY"
auth
,
err
:=
ethtxs
.
PrepareAuth
(
sim
,
para
.
DeployPrivateKey
,
para
.
Operator
)
if
nil
!=
err
{
t
.
Fatalf
(
"PrepareAuth failed due to:%s"
,
err
.
Error
())
}
_
,
err
=
x2EthContracts
.
BridgeBank
.
BridgeBankTransactor
.
CreateNewBridgeToken
(
auth
,
symbol
)
_
,
err
=
x2EthContracts
.
BridgeBank
.
BridgeBankTransactor
.
CreateNewBridgeToken
(
auth
,
symbol
)
if
nil
!=
err
{
if
nil
!=
err
{
t
.
Fatalf
(
"CreateNewBridgeToken failed due to:%s"
,
err
.
Error
())
t
.
Fatalf
(
"CreateNewBridgeToken failed due to:%s"
,
err
.
Error
())
...
@@ -215,7 +173,7 @@ func TestBrigeTokenMint(t *testing.T) {
...
@@ -215,7 +173,7 @@ func TestBrigeTokenMint(t *testing.T) {
}
}
///////////newOracleClaim///////////////////////////
///////////newOracleClaim///////////////////////////
balance
,
_
=
sim
.
BalanceAt
(
ctx
,
para
.
InitValidators
[
0
],
nil
)
balance
,
_
:
=
sim
.
BalanceAt
(
ctx
,
para
.
InitValidators
[
0
],
nil
)
fmt
.
Println
(
"InitValidators[0] addr,"
,
para
.
InitValidators
[
0
]
.
String
(),
"balance ="
,
balance
.
String
())
fmt
.
Println
(
"InitValidators[0] addr,"
,
para
.
InitValidators
[
0
]
.
String
(),
"balance ="
,
balance
.
String
())
chain33Sender
:=
[]
byte
(
"14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
)
chain33Sender
:=
[]
byte
(
"14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
)
...
@@ -265,29 +223,8 @@ func TestBridgeDepositLock(t *testing.T) {
...
@@ -265,29 +223,8 @@ func TestBridgeDepositLock(t *testing.T) {
ctx
:=
context
.
Background
()
ctx
:=
context
.
Background
()
println
(
"TEST:Bridge deposit locking (Erc20/Eth assets)"
)
println
(
"TEST:Bridge deposit locking (Erc20/Eth assets)"
)
//1st部署相关合约
//1st部署相关合约
sim
,
para
:=
setup
.
PrepareTestEnv
()
para
,
sim
,
x2EthContracts
,
x2EthDeployInfo
,
err
:=
setup
.
DeployContracts
()
require
.
NoError
(
t
,
err
)
balance
,
_
:=
sim
.
BalanceAt
(
ctx
,
para
.
Deployer
,
nil
)
fmt
.
Println
(
"deployer addr,"
,
para
.
Deployer
.
String
(),
"balance ="
,
balance
.
String
())
/////////////////////////EstimateGas///////////////////////////
callMsg
:=
ethereum
.
CallMsg
{
From
:
para
.
Deployer
,
Data
:
common
.
FromHex
(
generated
.
BridgeBankBin
),
}
gas
,
err
:=
sim
.
EstimateGas
(
ctx
,
callMsg
)
if
nil
!=
err
{
panic
(
"failed to estimate gas due to:"
+
err
.
Error
())
}
fmt
.
Printf
(
"
\n
The estimated gas=%d"
,
gas
)
////////////////////////////////////////////////////
x2EthContracts
,
x2EthDeployInfo
,
err
:=
ethtxs
.
DeployAndInit
(
sim
,
para
)
if
nil
!=
err
{
t
.
Fatalf
(
"DeployAndInit failed due to:%s"
,
err
.
Error
())
}
sim
.
Commit
()
//创建token
//创建token
operatorAuth
,
err
:=
ethtxs
.
PrepareAuth
(
sim
,
para
.
DeployPrivateKey
,
para
.
Operator
)
operatorAuth
,
err
:=
ethtxs
.
PrepareAuth
(
sim
,
para
.
DeployPrivateKey
,
para
.
Operator
)
...
@@ -386,41 +323,13 @@ func TestBridgeBankUnlock(t *testing.T) {
...
@@ -386,41 +323,13 @@ func TestBridgeBankUnlock(t *testing.T) {
ctx
:=
context
.
Background
()
ctx
:=
context
.
Background
()
println
(
"TEST:Ethereum/ERC20 token unlocking (for burned chain33 assets)"
)
println
(
"TEST:Ethereum/ERC20 token unlocking (for burned chain33 assets)"
)
//1st部署相关合约
//1st部署相关合约
sim
,
para
:=
setup
.
PrepareTestEnv
()
para
,
sim
,
x2EthContracts
,
x2EthDeployInfo
,
err
:=
setup
.
DeployContracts
()
require
.
NoError
(
t
,
err
)
balance
,
_
:=
sim
.
BalanceAt
(
ctx
,
para
.
Deployer
,
nil
)
fmt
.
Println
(
"deployer addr,"
,
para
.
Deployer
.
String
(),
"balance ="
,
balance
.
String
())
/////////////////////////EstimateGas///////////////////////////
callMsg
:=
ethereum
.
CallMsg
{
From
:
para
.
Deployer
,
Data
:
common
.
FromHex
(
generated
.
BridgeBankBin
),
}
gas
,
err
:=
sim
.
EstimateGas
(
ctx
,
callMsg
)
if
nil
!=
err
{
panic
(
"failed to estimate gas due to:"
+
err
.
Error
())
}
fmt
.
Printf
(
"
\n
The estimated gas=%d"
,
gas
)
////////////////////////////////////////////////////
x2EthContracts
,
x2EthDeployInfo
,
err
:=
ethtxs
.
DeployAndInit
(
sim
,
para
)
if
nil
!=
err
{
t
.
Fatalf
(
"DeployAndInit failed due to:%s"
,
err
.
Error
())
}
sim
.
Commit
()
//1.lockEth资产
//1.lockEth资产
ethAddr
:=
common
.
Address
{}
ethAddr
:=
common
.
Address
{}
ethToken
,
err
:=
generated
.
NewBridgeToken
(
ethAddr
,
sim
)
userOneAuth
,
err
:=
ethtxs
.
PrepareAuth
(
sim
,
para
.
ValidatorPriKey
[
0
],
para
.
InitValidators
[
0
])
userOneAuth
,
err
:=
ethtxs
.
PrepareAuth
(
sim
,
para
.
ValidatorPriKey
[
0
],
para
.
InitValidators
[
0
])
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
err
)
userOneAuth
.
Value
=
big
.
NewInt
(
300
)
_
,
err
=
ethToken
.
Transfer
(
userOneAuth
,
x2EthDeployInfo
.
BridgeBank
.
Address
,
userOneAuth
.
Value
)
sim
.
Commit
()
//ToDO://///////////////////////////////////////////////
////////????####To check the balance by hzj/////////////
////////////////////////////////////////////////////////
ethLockAmount
:=
big
.
NewInt
(
150
)
ethLockAmount
:=
big
.
NewInt
(
150
)
userOneAuth
.
Value
=
ethLockAmount
userOneAuth
.
Value
=
ethLockAmount
chain33Sender
:=
[]
byte
(
"14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
)
chain33Sender
:=
[]
byte
(
"14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
)
...
@@ -553,42 +462,16 @@ func TestBridgeBankSecondUnlockEth(t *testing.T) {
...
@@ -553,42 +462,16 @@ func TestBridgeBankSecondUnlockEth(t *testing.T) {
ctx
:=
context
.
Background
()
ctx
:=
context
.
Background
()
println
(
"TEST:to be unlocked incrementally by successive burn prophecies (for burned chain33 assets)"
)
println
(
"TEST:to be unlocked incrementally by successive burn prophecies (for burned chain33 assets)"
)
//1st部署相关合约
//1st部署相关合约
sim
,
para
:=
setup
.
PrepareTestEnv
()
para
,
sim
,
x2EthContracts
,
x2EthDeployInfo
,
err
:=
setup
.
DeployContracts
()
require
.
NoError
(
t
,
err
)
balance
,
_
:=
sim
.
BalanceAt
(
ctx
,
para
.
Deployer
,
nil
)
fmt
.
Println
(
"deployer addr,"
,
para
.
Deployer
.
String
(),
"balance ="
,
balance
.
String
())
/////////////////////////EstimateGas///////////////////////////
callMsg
:=
ethereum
.
CallMsg
{
From
:
para
.
Deployer
,
Data
:
common
.
FromHex
(
generated
.
BridgeBankBin
),
}
gas
,
err
:=
sim
.
EstimateGas
(
ctx
,
callMsg
)
if
nil
!=
err
{
panic
(
"failed to estimate gas due to:"
+
err
.
Error
())
}
fmt
.
Printf
(
"
\n
The estimated gas=%d"
,
gas
)
////////////////////////////////////////////////////
x2EthContracts
,
x2EthDeployInfo
,
err
:=
ethtxs
.
DeployAndInit
(
sim
,
para
)
if
nil
!=
err
{
t
.
Fatalf
(
"DeployAndInit failed due to:%s"
,
err
.
Error
())
}
sim
.
Commit
()
//1.lockEth资产
//1.lockEth资产
ethAddr
:=
common
.
Address
{}
ethAddr
:=
common
.
Address
{}
ethToken
,
err
:=
generated
.
NewBridgeToken
(
ethAddr
,
sim
)
userOneAuth
,
err
:=
ethtxs
.
PrepareAuth
(
sim
,
para
.
ValidatorPriKey
[
0
],
para
.
InitValidators
[
0
])
userOneAuth
,
err
:=
ethtxs
.
PrepareAuth
(
sim
,
para
.
ValidatorPriKey
[
0
],
para
.
InitValidators
[
0
])
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
err
)
userOneAuth
.
Value
=
big
.
NewInt
(
300
)
_
,
err
=
ethToken
.
Transfer
(
userOneAuth
,
x2EthDeployInfo
.
BridgeBank
.
Address
,
userOneAuth
.
Value
)
sim
.
Commit
()
ethLockAmount
:=
big
.
NewInt
(
150
)
ethLockAmount
:=
big
.
NewInt
(
150
)
userOneAuth
.
Value
=
ethLockAmount
userOneAuth
.
Value
=
ethLockAmount
chain33Sender
:=
[]
byte
(
"14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
)
chain33Sender
:=
[]
byte
(
"14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
)
//lock 150 eth
//lock 150 eth
_
,
err
=
x2EthContracts
.
BridgeBank
.
Lock
(
userOneAuth
,
chain33Sender
,
common
.
Address
{},
ethLockAmount
)
_
,
err
=
x2EthContracts
.
BridgeBank
.
Lock
(
userOneAuth
,
chain33Sender
,
common
.
Address
{},
ethLockAmount
)
...
@@ -718,36 +601,14 @@ func TestBridgeBankSedondUnlockErc20(t *testing.T) {
...
@@ -718,36 +601,14 @@ func TestBridgeBankSedondUnlockErc20(t *testing.T) {
ctx
:=
context
.
Background
()
ctx
:=
context
.
Background
()
println
(
"TEST:ERC20 to be unlocked incrementally by successive burn prophecies (for burned chain33 assets))"
)
println
(
"TEST:ERC20 to be unlocked incrementally by successive burn prophecies (for burned chain33 assets))"
)
//1st部署相关合约
//1st部署相关合约
sim
,
para
:=
setup
.
PrepareTestEnv
()
para
,
sim
,
x2EthContracts
,
x2EthDeployInfo
,
err
:=
setup
.
DeployContracts
()
require
.
NoError
(
t
,
err
)
balance
,
_
:=
sim
.
BalanceAt
(
ctx
,
para
.
Deployer
,
nil
)
fmt
.
Println
(
"deployer addr,"
,
para
.
Deployer
.
String
(),
"balance ="
,
balance
.
String
())
/////////////////////////EstimateGas///////////////////////////
callMsg
:=
ethereum
.
CallMsg
{
From
:
para
.
Deployer
,
Data
:
common
.
FromHex
(
generated
.
BridgeBankBin
),
}
gas
,
err
:=
sim
.
EstimateGas
(
ctx
,
callMsg
)
if
nil
!=
err
{
panic
(
"failed to estimate gas due to:"
+
err
.
Error
())
}
fmt
.
Printf
(
"
\n
The estimated gas=%d"
,
gas
)
////////////////////////////////////////////////////
x2EthContracts
,
x2EthDeployInfo
,
err
:=
ethtxs
.
DeployAndInit
(
sim
,
para
)
if
nil
!=
err
{
t
.
Fatalf
(
"DeployAndInit failed due to:%s"
,
err
.
Error
())
}
sim
.
Commit
()
//1.lockEth资产
//1.lockEth资产
userOneAuth
,
err
:=
ethtxs
.
PrepareAuth
(
sim
,
para
.
ValidatorPriKey
[
0
],
para
.
InitValidators
[
0
])
userOneAuth
,
err
:=
ethtxs
.
PrepareAuth
(
sim
,
para
.
ValidatorPriKey
[
0
],
para
.
InitValidators
[
0
])
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
err
)
ethLockAmount
:=
big
.
NewInt
(
150
)
ethLockAmount
:=
big
.
NewInt
(
150
)
userOneAuth
.
Value
=
ethLockAmount
userOneAuth
.
Value
=
ethLockAmount
chain33Sender
:=
[]
byte
(
"14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
)
chain33Sender
:=
[]
byte
(
"14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
)
//lock 150 eth
//lock 150 eth
_
,
err
=
x2EthContracts
.
BridgeBank
.
Lock
(
userOneAuth
,
chain33Sender
,
common
.
Address
{},
ethLockAmount
)
_
,
err
=
x2EthContracts
.
BridgeBank
.
Lock
(
userOneAuth
,
chain33Sender
,
common
.
Address
{},
ethLockAmount
)
...
@@ -763,9 +624,7 @@ func TestBridgeBankSedondUnlockErc20(t *testing.T) {
...
@@ -763,9 +624,7 @@ func TestBridgeBankSedondUnlockErc20(t *testing.T) {
sim
.
Commit
()
sim
.
Commit
()
t
.
Logf
(
"The new creaded symbolUsdt:%s, address:%s"
,
symbolUsdt
,
bridgeTokenAddr
.
String
())
t
.
Logf
(
"The new creaded symbolUsdt:%s, address:%s"
,
symbolUsdt
,
bridgeTokenAddr
.
String
())
//创建实例
//创建实例 为userOne铸币 userOne为bridgebank允许allowance设置数额
//为userOne铸币
//userOne为bridgebank允许allowance设置数额
userOne
:=
para
.
InitValidators
[
0
]
userOne
:=
para
.
InitValidators
[
0
]
callopts
:=
&
bind
.
CallOpts
{
callopts
:=
&
bind
.
CallOpts
{
Pending
:
true
,
Pending
:
true
,
...
@@ -780,11 +639,12 @@ func TestBridgeBankSedondUnlockErc20(t *testing.T) {
...
@@ -780,11 +639,12 @@ func TestBridgeBankSedondUnlockErc20(t *testing.T) {
require
.
Equal
(
t
,
isMiner
,
true
)
require
.
Equal
(
t
,
isMiner
,
true
)
operatorAuth
,
err
=
ethtxs
.
PrepareAuth
(
sim
,
para
.
DeployPrivateKey
,
para
.
Operator
)
operatorAuth
,
err
=
ethtxs
.
PrepareAuth
(
sim
,
para
.
DeployPrivateKey
,
para
.
Operator
)
require
.
Nil
(
t
,
err
)
mintAmount
:=
int64
(
1000
)
mintAmount
:=
int64
(
1000
)
_
,
err
=
bridgeTokenInstance
.
Mint
(
operatorAuth
,
userOne
,
big
.
NewInt
(
mintAmount
))
_
,
err
=
bridgeTokenInstance
.
Mint
(
operatorAuth
,
userOne
,
big
.
NewInt
(
mintAmount
))
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
err
)
sim
.
Commit
()
sim
.
Commit
()
userOneAuth
,
err
=
ethtxs
.
PrepareAuth
(
sim
,
para
.
ValidatorPriKey
[
0
],
para
.
InitValidators
[
0
])
userOneAuth
,
err
=
ethtxs
.
PrepareAuth
(
sim
,
para
.
ValidatorPriKey
[
0
],
para
.
InitValidators
[
0
])
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
err
)
allowAmount
:=
int64
(
100
)
allowAmount
:=
int64
(
100
)
...
@@ -800,7 +660,6 @@ func TestBridgeBankSedondUnlockErc20(t *testing.T) {
...
@@ -800,7 +660,6 @@ func TestBridgeBankSedondUnlockErc20(t *testing.T) {
//测试子项目:should allow users to lock ERC20 tokens
//测试子项目:should allow users to lock ERC20 tokens
userOneAuth
,
err
=
ethtxs
.
PrepareAuth
(
sim
,
para
.
ValidatorPriKey
[
0
],
para
.
InitValidators
[
0
])
userOneAuth
,
err
=
ethtxs
.
PrepareAuth
(
sim
,
para
.
ValidatorPriKey
[
0
],
para
.
InitValidators
[
0
])
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
err
)
//lock 100
//lock 100
lockAmount
:=
big
.
NewInt
(
100
)
lockAmount
:=
big
.
NewInt
(
100
)
_
,
err
=
x2EthContracts
.
BridgeBank
.
Lock
(
userOneAuth
,
chain33Sender
,
bridgeTokenAddr
,
lockAmount
)
_
,
err
=
x2EthContracts
.
BridgeBank
.
Lock
(
userOneAuth
,
chain33Sender
,
bridgeTokenAddr
,
lockAmount
)
...
...
plugin/dapp/x2ethereum/ebrelayer/ethcontract/test/setup/setupTestEnv.go
View file @
62bf6d3d
package
setup
package
setup
import
(
import
(
"context"
"crypto/ecdsa"
"crypto/ecdsa"
"github.com/ethereum/go-ethereum"
"math/big"
"math/big"
"github.com/33cn/plugin/plugin/dapp/x2ethereum/ebrelayer/ethcontract/generated"
"github.com/33cn/plugin/plugin/dapp/x2ethereum/ebrelayer/ethinterface"
"github.com/33cn/plugin/plugin/dapp/x2ethereum/ebrelayer/ethinterface"
"github.com/33cn/plugin/plugin/dapp/x2ethereum/ebrelayer/ethtxs"
"github.com/33cn/plugin/plugin/dapp/x2ethereum/ebrelayer/ethtxs"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
...
@@ -26,7 +28,7 @@ func PrepareTestEnv() (*ethinterface.SimExtend, *ethtxs.DeployPara) {
...
@@ -26,7 +28,7 @@ func PrepareTestEnv() (*ethinterface.SimExtend, *ethtxs.DeployPara) {
var
InitValidators
[]
common
.
Address
var
InitValidators
[]
common
.
Address
var
ValidatorPriKey
[]
*
ecdsa
.
PrivateKey
var
ValidatorPriKey
[]
*
ecdsa
.
PrivateKey
for
i
:=
0
;
i
<
3
;
i
++
{
for
i
:=
0
;
i
<
4
;
i
++
{
key
,
_
:=
crypto
.
GenerateKey
()
key
,
_
:=
crypto
.
GenerateKey
()
addr
:=
crypto
.
PubkeyToAddress
(
key
.
PublicKey
)
addr
:=
crypto
.
PubkeyToAddress
(
key
.
PublicKey
)
InitValidators
=
append
(
InitValidators
,
addr
)
InitValidators
=
append
(
InitValidators
,
addr
)
...
@@ -42,7 +44,7 @@ func PrepareTestEnv() (*ethinterface.SimExtend, *ethtxs.DeployPara) {
...
@@ -42,7 +44,7 @@ func PrepareTestEnv() (*ethinterface.SimExtend, *ethtxs.DeployPara) {
sim
:=
new
(
ethinterface
.
SimExtend
)
sim
:=
new
(
ethinterface
.
SimExtend
)
sim
.
SimulatedBackend
=
backends
.
NewSimulatedBackend
(
alloc
,
gasLimit
)
sim
.
SimulatedBackend
=
backends
.
NewSimulatedBackend
(
alloc
,
gasLimit
)
InitPowers
:=
[]
*
big
.
Int
{
big
.
NewInt
(
80
),
big
.
NewInt
(
10
),
big
.
NewInt
(
10
)}
InitPowers
:=
[]
*
big
.
Int
{
big
.
NewInt
(
80
),
big
.
NewInt
(
10
),
big
.
NewInt
(
10
)
,
big
.
NewInt
(
10
)
}
para
:=
&
ethtxs
.
DeployPara
{
para
:=
&
ethtxs
.
DeployPara
{
DeployPrivateKey
:
genesiskey
,
DeployPrivateKey
:
genesiskey
,
Deployer
:
genesisAddr
,
Deployer
:
genesisAddr
,
...
@@ -96,3 +98,25 @@ func PrepareTestEnvironment(deployerPrivateKey string, ethValidatorAddrKeys []st
...
@@ -96,3 +98,25 @@ func PrepareTestEnvironment(deployerPrivateKey string, ethValidatorAddrKeys []st
return
sim
,
para
return
sim
,
para
}
}
func
DeployContracts
()
(
*
ethtxs
.
DeployPara
,
*
ethinterface
.
SimExtend
,
*
ethtxs
.
X2EthContracts
,
*
ethtxs
.
X2EthDeployInfo
,
error
)
{
ctx
:=
context
.
Background
()
sim
,
para
:=
PrepareTestEnv
()
callMsg
:=
ethereum
.
CallMsg
{
From
:
para
.
Deployer
,
Data
:
common
.
FromHex
(
generated
.
BridgeBankBin
),
}
_
,
err
:=
sim
.
EstimateGas
(
ctx
,
callMsg
)
if
nil
!=
err
{
panic
(
"failed to estimate gas due to:"
+
err
.
Error
())
}
x2EthContracts
,
x2EthDeployInfo
,
err
:=
ethtxs
.
DeployAndInit
(
sim
,
para
)
if
nil
!=
err
{
return
nil
,
nil
,
nil
,
nil
,
err
}
sim
.
Commit
()
return
para
,
sim
,
x2EthContracts
,
x2EthDeployInfo
,
nil
}
plugin/dapp/x2ethereum/ebrelayer/ethtxs/recover.go
View file @
62bf6d3d
...
@@ -36,12 +36,22 @@ func RecoverContractHandler(client ethinterface.EthClientSpec, sender, registry
...
@@ -36,12 +36,22 @@ func RecoverContractHandler(client ethinterface.EthClientSpec, sender, registry
return
nil
,
nil
,
errors
.
New
(
"failed to NewOracle"
)
return
nil
,
nil
,
errors
.
New
(
"failed to NewOracle"
)
}
}
valsetAddr
,
err
:=
GetAddressFromBridgeRegistry
(
client
,
sender
,
registry
,
Valset
)
if
nil
!=
err
{
return
nil
,
nil
,
errors
.
New
(
"failed to get addr for valset from registry"
)
}
valset
,
err
:=
generated
.
NewValset
(
*
valsetAddr
,
client
)
if
nil
!=
err
{
return
nil
,
nil
,
errors
.
New
(
"failed to NewValset"
)
}
registryInstance
,
_
:=
generated
.
NewBridgeRegistry
(
registry
,
client
)
registryInstance
,
_
:=
generated
.
NewBridgeRegistry
(
registry
,
client
)
x2EthContracts
:=
&
X2EthContracts
{
x2EthContracts
:=
&
X2EthContracts
{
BridgeRegistry
:
registryInstance
,
BridgeRegistry
:
registryInstance
,
BridgeBank
:
bridgeBank
,
BridgeBank
:
bridgeBank
,
Chain33Bridge
:
chain33Bridge
,
Chain33Bridge
:
chain33Bridge
,
Oracle
:
oracle
,
Oracle
:
oracle
,
Valset
:
valset
,
}
}
x2EthDeployInfo
:=
&
X2EthDeployInfo
{
x2EthDeployInfo
:=
&
X2EthDeployInfo
{
...
@@ -49,6 +59,7 @@ func RecoverContractHandler(client ethinterface.EthClientSpec, sender, registry
...
@@ -49,6 +59,7 @@ func RecoverContractHandler(client ethinterface.EthClientSpec, sender, registry
BridgeBank
:
&
DeployResult
{
Address
:
*
bridgeBankAddr
},
BridgeBank
:
&
DeployResult
{
Address
:
*
bridgeBankAddr
},
Chain33Bridge
:
&
DeployResult
{
Address
:
*
chain33BridgeAddr
},
Chain33Bridge
:
&
DeployResult
{
Address
:
*
chain33BridgeAddr
},
Oracle
:
&
DeployResult
{
Address
:
*
oracleAddr
},
Oracle
:
&
DeployResult
{
Address
:
*
oracleAddr
},
Valset
:
&
DeployResult
{
Address
:
*
valsetAddr
},
}
}
return
x2EthContracts
,
x2EthDeployInfo
,
nil
return
x2EthContracts
,
x2EthDeployInfo
,
nil
...
...
plugin/dapp/x2ethereum/ebrelayer/relayer/ethereum/ethereum_test.go
View file @
62bf6d3d
...
@@ -5,36 +5,32 @@ import (
...
@@ -5,36 +5,32 @@ import (
"encoding/hex"
"encoding/hex"
"flag"
"flag"
"fmt"
"fmt"
"github.com/33cn/plugin/plugin/dapp/x2ethereum/ebrelayer/events"
"github.com/33cn/chain33/client/mocks"
"github.com/33cn/chain33/util/testnode"
//"github.com/ethereum/go-ethereum/core/types"
"math/big"
"math/big"
"os"
"os"
"testing"
"testing"
"time"
"time"
"github.com/influxdata/influxdb/pkg/testing/assert"
"github.com/33cn/chain33/client/mocks"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"github.com/ethereum/go-ethereum/common/hexutil"
dbm
"github.com/33cn/chain33/common/db"
dbm
"github.com/33cn/chain33/common/db"
_
"github.com/33cn/chain33/system"
_
"github.com/33cn/chain33/system"
chain33Types
"github.com/33cn/chain33/types"
chain33Types
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/util/testnode"
"github.com/33cn/plugin/plugin/dapp/x2ethereum/ebrelayer/ethcontract/generated"
"github.com/33cn/plugin/plugin/dapp/x2ethereum/ebrelayer/ethcontract/generated"
"github.com/33cn/plugin/plugin/dapp/x2ethereum/ebrelayer/ethcontract/test/setup"
"github.com/33cn/plugin/plugin/dapp/x2ethereum/ebrelayer/ethcontract/test/setup"
"github.com/33cn/plugin/plugin/dapp/x2ethereum/ebrelayer/ethinterface"
"github.com/33cn/plugin/plugin/dapp/x2ethereum/ebrelayer/ethinterface"
"github.com/33cn/plugin/plugin/dapp/x2ethereum/ebrelayer/ethtxs"
"github.com/33cn/plugin/plugin/dapp/x2ethereum/ebrelayer/ethtxs"
ebTypes
"github.com/33cn/plugin/plugin/dapp/x2ethereum/ebrelayer/types"
relayerTypes
"github.com/33cn/plugin/plugin/dapp/x2ethereum/ebrelayer/types"
relayerTypes
"github.com/33cn/plugin/plugin/dapp/x2ethereum/ebrelayer/types"
tml
"github.com/BurntSushi/toml"
tml
"github.com/BurntSushi/toml"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto"
"github.com/influxdata/influxdb/pkg/testing/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
)
)
var
(
var
(
...
@@ -51,133 +47,236 @@ var (
...
@@ -51,133 +47,236 @@ var (
ethValidatorAddrKeyB
=
"a5f3063552f4483cfc20ac4f40f45b798791379862219de9e915c64722c1d400"
ethValidatorAddrKeyB
=
"a5f3063552f4483cfc20ac4f40f45b798791379862219de9e915c64722c1d400"
ethValidatorAddrKeyC
=
"bbf5e65539e9af0eb0cfac30bad475111054b09c11d668fc0731d54ea777471e"
ethValidatorAddrKeyC
=
"bbf5e65539e9af0eb0cfac30bad475111054b09c11d668fc0731d54ea777471e"
ethValidatorAddrKeyD
=
"c9fa31d7984edf81b8ef3b40c761f1847f6fcd5711ab2462da97dc458f1f896b"
ethValidatorAddrKeyD
=
"c9fa31d7984edf81b8ef3b40c761f1847f6fcd5711ab2462da97dc458f1f896b"
ethRelayer
*
Relayer4Ethereum
sim
*
ethinterface
.
SimExtend
x2EthContracts
*
ethtxs
.
X2EthContracts
x2EthDeployInfo
*
ethtxs
.
X2EthDeployInfo
para
*
ethtxs
.
DeployPara
)
)
func
init
()
{
func
Test_GetValidatorAddr
(
t
*
testing
.
T
)
{
deployContracts
()
para
,
sim
,
x2EthContracts
,
x2EthDeployInfo
,
err
:=
setup
.
DeployContracts
()
ethRelayer
=
newEthRelayer
()
require
.
NoError
(
t
,
err
)
ethRelayer
:=
newEthRelayer
(
para
,
sim
,
x2EthContracts
,
x2EthDeployInfo
)
_
=
ethRelayer
.
ImportChain33PrivateKey
(
passphrase
,
chain33PrivateKeyStr
)
_
=
ethRelayer
.
ImportChain33PrivateKey
(
passphrase
,
chain33PrivateKeyStr
)
time
.
Sleep
(
time
.
Second
)
time
.
Sleep
(
time
.
Second
)
}
func
Test_GetValidatorAddr
(
t
*
testing
.
T
)
{
_
,
_
,
err
=
ethRelayer
.
NewAccount
(
"123"
)
_
,
_
,
err
:=
ethRelayer
.
NewAccount
(
"123"
)
require
.
Nil
(
t
,
err
)
assert
.
NoError
(
t
,
err
)
privateKey
,
addr
,
err
:=
ethRelayer
.
GetAccount
(
"123"
)
privateKey
,
addr
,
err
:=
ethRelayer
.
GetAccount
(
"123"
)
assert
.
NoError
(
t
,
err
)
require
.
Nil
(
t
,
err
)
assert
.
NotEqual
(
t
,
privateKey
,
chain33PrivateKeyStr
)
assert
.
NotEqual
(
t
,
privateKey
,
chain33PrivateKeyStr
)
privateKey
,
addr
,
err
=
ethRelayer
.
GetAccount
(
passphrase
)
privateKey
,
addr
,
err
=
ethRelayer
.
GetAccount
(
passphrase
)
assert
.
NoError
(
t
,
err
)
require
.
Nil
(
t
,
err
)
assert
.
Equal
(
t
,
privateKey
,
chain33PrivateKeyStr
)
assert
.
Equal
(
t
,
privateKey
,
chain33PrivateKeyStr
)
assert
.
Equal
(
t
,
addr
,
chain33AccountAddr
)
assert
.
Equal
(
t
,
addr
,
chain33AccountAddr
)
validators
,
err
:=
ethRelayer
.
GetValidatorAddr
()
validators
,
err
:=
ethRelayer
.
GetValidatorAddr
()
assert
.
NoError
(
t
,
err
)
require
.
Nil
(
t
,
err
)
assert
.
Equal
(
t
,
validators
.
Chain33Validator
,
chain33AccountAddr
)
assert
.
Equal
(
t
,
validators
.
Chain33Validator
,
chain33AccountAddr
)
}
}
func
Test_IsValidatorActive
(
t
*
testing
.
T
)
{
func
Test_IsValidatorActive
(
t
*
testing
.
T
)
{
ethRelayer
.
x2EthContracts
=
x2EthContracts
para
,
sim
,
x2EthContracts
,
x2EthDeployInfo
,
err
:=
setup
.
DeployContracts
()
ethRelayer
.
x2EthDeployInfo
=
x2EthDeployInfo
require
.
NoError
(
t
,
err
)
ethRelayer
:=
newEthRelayer
(
para
,
sim
,
x2EthContracts
,
x2EthDeployInfo
)
_
=
ethRelayer
.
ImportChain33PrivateKey
(
passphrase
,
chain33PrivateKeyStr
)
time
.
Sleep
(
time
.
Second
)
fmt
.
Println
(
"ethRelayer.x2EthContracts.Valset"
,
ethRelayer
.
x2EthContracts
.
Valset
)
//
fmt.Println("ethRelayer.x2EthContracts.Valset", ethRelayer.x2EthContracts.Valset)
is
,
err
:=
ethRelayer
.
IsValidatorActive
(
"0x92c8b16afd6d423652559c6e266cbe1c29bfd84f"
)
is
,
err
:=
ethRelayer
.
IsValidatorActive
(
para
.
InitValidators
[
0
]
.
String
()
)
assert
.
Equal
(
t
,
is
,
true
)
assert
.
Equal
(
t
,
is
,
true
)
assert
.
NoError
(
t
,
err
)
require
.
Nil
(
t
,
err
)
is
,
err
=
ethRelayer
.
IsValidatorActive
(
"0x0C05bA5c230fDaA503b53702aF1962e08D0C60BF"
)
is
,
err
=
ethRelayer
.
IsValidatorActive
(
"0x0C05bA5c230fDaA503b53702aF1962e08D0C60BF"
)
assert
.
Equal
(
t
,
is
,
false
)
assert
.
Equal
(
t
,
is
,
false
)
assert
.
NoError
(
t
,
err
)
require
.
Nil
(
t
,
err
)
is
,
err
=
ethRelayer
.
IsValidatorActive
(
"123"
)
is
,
err
=
ethRelayer
.
IsValidatorActive
(
"123"
)
require
.
Error
(
t
,
err
)
require
.
Error
(
t
,
err
)
}
}
func
Test_ShowAddr
(
t
*
testing
.
T
)
{
func
Test_ShowAddr
(
t
*
testing
.
T
)
{
{
cfg
:=
initCfg
(
*
configPath
)
relayer
:=
&
Relayer4Ethereum
{
provider
:
cfg
.
EthProvider
,
unlockchan
:
make
(
chan
int
,
2
),
rpcURL2Chain33
:
cfg
.
SyncTxConfig
.
Chain33Host
,
maturityDegree
:
cfg
.
EthMaturityDegree
,
fetchHeightPeriodMs
:
cfg
.
EthBlockFetchPeriod
,
}
_
,
err
:=
relayer
.
ShowBridgeBankAddr
()
require
.
Error
(
t
,
err
)
_
,
err
=
relayer
.
ShowBridgeRegistryAddr
()
require
.
Error
(
t
,
err
)
}
para
,
sim
,
x2EthContracts
,
x2EthDeployInfo
,
err
:=
setup
.
DeployContracts
()
require
.
NoError
(
t
,
err
)
ethRelayer
:=
newEthRelayer
(
para
,
sim
,
x2EthContracts
,
x2EthDeployInfo
)
_
=
ethRelayer
.
ImportChain33PrivateKey
(
passphrase
,
chain33PrivateKeyStr
)
time
.
Sleep
(
time
.
Second
)
ethRelayer
.
prePareSubscribeEvent
()
ethRelayer
.
prePareSubscribeEvent
()
addr
,
err
:=
ethRelayer
.
ShowBridgeBankAddr
()
addr
,
err
:=
ethRelayer
.
ShowBridgeBankAddr
()
assert
.
NoError
(
t
,
err
)
require
.
Nil
(
t
,
err
)
assert
.
Equal
(
t
,
addr
,
x2EthDeployInfo
.
BridgeBank
.
Address
.
String
())
assert
.
Equal
(
t
,
addr
,
x2EthDeployInfo
.
BridgeBank
.
Address
.
String
())
addr
,
err
=
ethRelayer
.
ShowBridgeRegistryAddr
()
addr
,
err
=
ethRelayer
.
ShowBridgeRegistryAddr
()
assert
.
NoError
(
t
,
err
)
require
.
Nil
(
t
,
err
)
assert
.
Equal
(
t
,
addr
,
x2EthDeployInfo
.
BridgeRegistry
.
Address
.
String
())
assert
.
Equal
(
t
,
addr
,
x2EthDeployInfo
.
BridgeRegistry
.
Address
.
String
())
addr
,
err
=
ethRelayer
.
ShowOperator
()
addr
,
err
=
ethRelayer
.
ShowOperator
()
assert
.
NoError
(
t
,
err
)
require
.
Nil
(
t
,
err
)
assert
.
Equal
(
t
,
addr
,
para
.
Operator
.
String
())
assert
.
Equal
(
t
,
addr
,
para
.
Operator
.
String
())
_
,
err
=
ethRelayer
.
DeployContrcts
()
_
,
err
=
ethRelayer
.
DeployContrcts
()
require
.
Error
(
t
,
err
)
require
.
Error
(
t
,
err
)
}
func
Test_SetBridgeRegistryAddr
(
t
*
testing
.
T
)
{
para
,
sim
,
x2EthContracts
,
x2EthDeployInfo
,
err
:=
setup
.
DeployContracts
()
require
.
NoError
(
t
,
err
)
ethRelayer
:=
newEthRelayer
(
para
,
sim
,
x2EthContracts
,
x2EthDeployInfo
)
_
=
ethRelayer
.
ImportChain33PrivateKey
(
passphrase
,
chain33PrivateKeyStr
)
time
.
Sleep
(
time
.
Second
)
_
=
ethRelayer
.
setBridgeRegistryAddr
(
x2EthDeployInfo
.
BridgeRegistry
.
Address
.
String
())
registrAddrInDB
,
err
:=
ethRelayer
.
getBridgeRegistryAddr
()
require
.
Nil
(
t
,
err
)
assert
.
Equal
(
t
,
registrAddrInDB
,
x2EthDeployInfo
.
BridgeRegistry
.
Address
.
String
())
}
}
func
Test_CreateBridgeToken
(
t
*
testing
.
T
)
{
func
Test_CreateBridgeToken
(
t
*
testing
.
T
)
{
para
,
sim
,
x2EthContracts
,
x2EthDeployInfo
,
err
:=
setup
.
DeployContracts
()
require
.
NoError
(
t
,
err
)
ethRelayer
:=
newEthRelayer
(
para
,
sim
,
x2EthContracts
,
x2EthDeployInfo
)
_
=
ethRelayer
.
ImportChain33PrivateKey
(
passphrase
,
chain33PrivateKeyStr
)
time
.
Sleep
(
time
.
Second
)
balance
,
err
:=
ethRelayer
.
GetBalance
(
""
,
para
.
InitValidators
[
0
]
.
String
())
balance
,
err
:=
ethRelayer
.
GetBalance
(
""
,
para
.
InitValidators
[
0
]
.
String
())
assert
.
NoError
(
t
,
err
)
require
.
Nil
(
t
,
err
)
assert
.
Equal
(
t
,
balance
,
"10000000000"
)
assert
.
Equal
(
t
,
balance
,
"10000000000"
)
tokenAddrbty
,
err
:=
ethRelayer
.
CreateBridgeToken
(
"BTY"
)
tokenAddrbty
,
err
:=
ethRelayer
.
CreateBridgeToken
(
"BTY"
)
assert
.
NoError
(
t
,
err
)
require
.
Nil
(
t
,
err
)
require
.
NotEmpty
(
t
,
tokenAddrbty
)
require
.
NotEmpty
(
t
,
tokenAddrbty
)
sim
.
Commit
()
sim
.
Commit
()
addr
,
err
:=
ethRelayer
.
ShowTokenAddrBySymbol
(
"BTY"
)
addr
,
err
:=
ethRelayer
.
ShowTokenAddrBySymbol
(
"BTY"
)
assert
.
NoError
(
t
,
err
)
require
.
Nil
(
t
,
err
)
assert
.
Equal
(
t
,
addr
,
tokenAddrbty
)
assert
.
Equal
(
t
,
addr
,
tokenAddrbty
)
decimals
,
err
:=
ethRelayer
.
GetDecimals
(
tokenAddrbty
)
decimals
,
err
:=
ethRelayer
.
GetDecimals
(
tokenAddrbty
)
assert
.
NoError
(
t
,
err
)
require
.
Nil
(
t
,
err
)
assert
.
Equal
(
t
,
decimals
,
uint8
(
8
))
assert
.
Equal
(
t
,
decimals
,
uint8
(
8
))
_
,
err
=
ethRelayer
.
Burn
(
ethValidatorAddrKeyA
,
tokenAddrbty
,
chain33AccountAddr
,
"10"
)
_
,
err
=
ethRelayer
.
Burn
(
para
.
InitValidators
[
0
]
.
String
()
,
tokenAddrbty
,
chain33AccountAddr
,
"10"
)
require
.
Error
(
t
,
err
)
require
.
Error
(
t
,
err
)
_
,
err
=
ethRelayer
.
BurnAsync
(
ethValidatorAddrKeyA
,
tokenAddrbty
,
chain33AccountAddr
,
"10"
)
_
,
err
=
ethRelayer
.
BurnAsync
(
para
.
InitValidators
[
0
]
.
String
()
,
tokenAddrbty
,
chain33AccountAddr
,
"10"
)
require
.
Error
(
t
,
err
)
require
.
Error
(
t
,
err
)
}
}
func
Test_LockEth
(
t
*
testing
.
T
)
{
para
,
sim
,
x2EthContracts
,
x2EthDeployInfo
,
err
:=
setup
.
DeployContracts
()
require
.
NoError
(
t
,
err
)
ethRelayer
:=
newEthRelayer
(
para
,
sim
,
x2EthContracts
,
x2EthDeployInfo
)
_
=
ethRelayer
.
ImportChain33PrivateKey
(
passphrase
,
chain33PrivateKeyStr
)
time
.
Sleep
(
time
.
Second
)
var
tx
chain33Types
.
Transaction
var
ret
chain33Types
.
Reply
ret
.
IsOk
=
true
mockapi
:=
&
mocks
.
QueueProtocolAPI
{}
// 这里对需要mock的方法打桩,Close是必须的,其它方法根据需要
mockapi
.
On
(
"Close"
)
.
Return
()
mockapi
.
On
(
"AddPushSubscribe"
,
mock
.
Anything
)
.
Return
(
&
ret
,
nil
)
mockapi
.
On
(
"CreateTransaction"
,
mock
.
Anything
)
.
Return
(
&
tx
,
nil
)
mockapi
.
On
(
"SendTx"
,
mock
.
Anything
)
.
Return
(
&
ret
,
nil
)
mockapi
.
On
(
"SendTransaction"
,
mock
.
Anything
)
.
Return
(
&
ret
,
nil
)
mockapi
.
On
(
"GetConfig"
,
mock
.
Anything
)
.
Return
(
chainTestCfg
,
nil
)
mock33
:=
testnode
.
New
(
""
,
mockapi
)
defer
mock33
.
Close
()
rpcCfg
:=
mock33
.
GetCfg
()
.
RPC
// 这里必须设置监听端口,默认的是无效值
rpcCfg
.
JrpcBindAddr
=
"127.0.0.1:8801"
mock33
.
GetRPC
()
.
Listen
()
ctx
:=
context
.
Background
()
bridgeBankBalance
,
err
:=
sim
.
BalanceAt
(
ctx
,
x2EthDeployInfo
.
BridgeBank
.
Address
,
nil
)
require
.
Nil
(
t
,
err
)
assert
.
Equal
(
t
,
bridgeBankBalance
.
Int64
(),
int64
(
0
))
userOneAuth
,
err
:=
ethtxs
.
PrepareAuth
(
sim
,
para
.
ValidatorPriKey
[
0
],
para
.
InitValidators
[
0
])
require
.
Nil
(
t
,
err
)
//lock 50 eth
chain33Sender
:=
[]
byte
(
"14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
)
ethAmount
:=
big
.
NewInt
(
50
)
userOneAuth
.
Value
=
ethAmount
_
,
err
=
x2EthContracts
.
BridgeBank
.
Lock
(
userOneAuth
,
chain33Sender
,
common
.
Address
{},
ethAmount
)
require
.
Nil
(
t
,
err
)
sim
.
Commit
()
bridgeBankBalance
,
err
=
sim
.
BalanceAt
(
ctx
,
x2EthDeployInfo
.
BridgeBank
.
Address
,
nil
)
require
.
Nil
(
t
,
err
)
assert
.
Equal
(
t
,
bridgeBankBalance
.
Int64
(),
ethAmount
.
Int64
())
for
i
:=
0
;
i
<
11
;
i
++
{
sim
.
Commit
()
}
time
.
Sleep
(
time
.
Duration
(
ethRelayer
.
fetchHeightPeriodMs
)
*
time
.
Millisecond
)
balance
,
err
:=
ethRelayer
.
ShowLockStatics
(
""
)
require
.
Nil
(
t
,
err
)
assert
.
Equal
(
t
,
balance
,
"50"
)
time
.
Sleep
(
time
.
Second
)
}
func
Test_CreateERC20Token
(
t
*
testing
.
T
)
{
func
Test_CreateERC20Token
(
t
*
testing
.
T
)
{
para
,
sim
,
x2EthContracts
,
x2EthDeployInfo
:=
deployContracts
()
ethRelayer
:=
newEthRelayer
(
para
,
sim
,
x2EthContracts
,
x2EthDeployInfo
)
_
=
ethRelayer
.
ImportChain33PrivateKey
(
passphrase
,
chain33PrivateKeyStr
)
time
.
Sleep
(
time
.
Second
)
tokenErc20Addr
,
err
:=
ethRelayer
.
CreateERC20Token
(
"testcc"
)
tokenErc20Addr
,
err
:=
ethRelayer
.
CreateERC20Token
(
"testcc"
)
assert
.
NoError
(
t
,
err
)
require
.
Nil
(
t
,
err
)
require
.
NotEmpty
(
t
,
tokenErc20Addr
)
require
.
NotEmpty
(
t
,
tokenErc20Addr
)
sim
.
Commit
()
sim
.
Commit
()
_
,
err
=
ethRelayer
.
MintERC20Token
(
tokenErc20Addr
,
para
.
Deployer
.
String
(),
"20000000000000"
)
_
,
err
=
ethRelayer
.
MintERC20Token
(
tokenErc20Addr
,
para
.
Deployer
.
String
(),
"20000000000000"
)
assert
.
NoError
(
t
,
err
)
require
.
Nil
(
t
,
err
)
sim
.
Commit
()
sim
.
Commit
()
balance
,
err
:=
ethRelayer
.
ShowDepositStatics
(
tokenErc20Addr
)
balance
,
err
:=
ethRelayer
.
ShowDepositStatics
(
tokenErc20Addr
)
assert
.
NoError
(
t
,
err
)
require
.
Nil
(
t
,
err
)
assert
.
Equal
(
t
,
balance
,
"20000000000000"
)
assert
.
Equal
(
t
,
balance
,
"20000000000000"
)
//
claimID := crypto.Keccak256Hash(big.NewInt(50).Bytes())
claimID
:=
crypto
.
Keccak256Hash
(
big
.
NewInt
(
50
)
.
Bytes
())
//ret, err
= ethRelayer.IsProphecyPending(claimID)
bret
,
err
:
=
ethRelayer
.
IsProphecyPending
(
claimID
)
//assert.NoError
(t, err)
require
.
Nil
(
t
,
err
)
//assert.Equal(t,
ret, false)
assert
.
Equal
(
t
,
b
ret
,
false
)
txhash
,
err
:=
ethRelayer
.
TransferToken
(
tokenErc20Addr
,
hexutil
.
Encode
(
crypto
.
FromECDSA
(
para
.
DeployPrivateKey
)),
ethRelayer
.
deployInfo
.
ValidatorsAddr
[
0
],
"100"
)
txhash
,
err
:=
ethRelayer
.
TransferToken
(
tokenErc20Addr
,
hexutil
.
Encode
(
crypto
.
FromECDSA
(
para
.
DeployPrivateKey
)),
ethRelayer
.
deployInfo
.
ValidatorsAddr
[
0
],
"100"
)
assert
.
NoError
(
t
,
err
)
require
.
Nil
(
t
,
err
)
sim
.
Commit
()
sim
.
Commit
()
_
,
err
=
ethRelayer
.
ShowTxReceipt
(
txhash
)
_
,
err
=
ethRelayer
.
ShowTxReceipt
(
txhash
)
assert
.
NoError
(
t
,
err
)
require
.
Nil
(
t
,
err
)
balance
,
err
=
ethRelayer
.
GetBalance
(
tokenErc20Addr
,
ethRelayer
.
deployInfo
.
ValidatorsAddr
[
0
])
balance
,
err
=
ethRelayer
.
GetBalance
(
tokenErc20Addr
,
ethRelayer
.
deployInfo
.
ValidatorsAddr
[
0
])
assert
.
NoError
(
t
,
err
)
require
.
Nil
(
t
,
err
)
assert
.
Equal
(
t
,
balance
,
"100"
)
assert
.
Equal
(
t
,
balance
,
"100"
)
balance
,
err
=
ethRelayer
.
GetBalance
(
tokenErc20Addr
,
para
.
Deployer
.
String
())
balance
,
err
=
ethRelayer
.
GetBalance
(
tokenErc20Addr
,
para
.
Deployer
.
String
())
assert
.
NoError
(
t
,
err
)
require
.
Nil
(
t
,
err
)
assert
.
Equal
(
t
,
balance
,
"19999999999900"
)
assert
.
Equal
(
t
,
balance
,
"19999999999900"
)
tx1
:=
ethRelayer
.
QueryTxhashRelay2Eth
()
tx1
:=
ethRelayer
.
QueryTxhashRelay2Eth
()
...
@@ -185,9 +284,7 @@ func Test_CreateERC20Token(t *testing.T) {
...
@@ -185,9 +284,7 @@ func Test_CreateERC20Token(t *testing.T) {
tx2
:=
ethRelayer
.
QueryTxhashRelay2Chain33
()
tx2
:=
ethRelayer
.
QueryTxhashRelay2Chain33
()
require
.
Empty
(
t
,
tx2
)
require
.
Empty
(
t
,
tx2
)
}
func
Test_LockEth
(
t
*
testing
.
T
)
{
var
tx
chain33Types
.
Transaction
var
tx
chain33Types
.
Transaction
var
ret
chain33Types
.
Reply
var
ret
chain33Types
.
Reply
ret
.
IsOk
=
true
ret
.
IsOk
=
true
...
@@ -208,182 +305,170 @@ func Test_LockEth(t *testing.T) {
...
@@ -208,182 +305,170 @@ func Test_LockEth(t *testing.T) {
rpcCfg
.
JrpcBindAddr
=
"127.0.0.1:8801"
rpcCfg
.
JrpcBindAddr
=
"127.0.0.1:8801"
mock33
.
GetRPC
()
.
Listen
()
mock33
.
GetRPC
()
.
Listen
()
ctx
:=
context
.
Background
(
)
tokenErc20Addrtestc
,
err
:=
ethRelayer
.
CreateERC20Token
(
"testc"
)
bridgeBankBalance
,
err
:=
sim
.
BalanceAt
(
ctx
,
x2EthDeployInfo
.
BridgeBank
.
Address
,
nil
)
require
.
Nil
(
t
,
err
)
assert
.
NoError
(
t
,
err
)
require
.
NotEmpty
(
t
,
tokenErc20Addrtestc
)
assert
.
Equal
(
t
,
bridgeBankBalance
.
Int64
(),
int64
(
0
)
)
sim
.
Commit
(
)
userOneAuth
,
err
:=
ethtxs
.
PrepareAuth
(
sim
,
para
.
ValidatorPriKey
[
0
],
para
.
InitValidators
[
0
])
_
,
err
=
ethRelayer
.
MintERC20Token
(
tokenErc20Addrtestc
,
para
.
Deployer
.
String
(),
"10000000000000"
)
assert
.
NoError
(
t
,
err
)
require
.
Nil
(
t
,
err
)
sim
.
Commit
()
//lock 50 eth
balance
,
err
=
ethRelayer
.
ShowDepositStatics
(
tokenErc20Addrtestc
)
chain33Sender
:=
[]
byte
(
"14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
)
require
.
Nil
(
t
,
err
)
ethAmount
:=
big
.
NewInt
(
50
)
assert
.
Equal
(
t
,
balance
,
"10000000000000"
)
userOneAuth
.
Value
=
ethAmount
_
,
err
=
x2EthContracts
.
BridgeBank
.
Lock
(
userOneAuth
,
chain33Sender
,
common
.
Address
{},
ethAmount
)
chain33Receiver
:=
"14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
assert
.
NoError
(
t
,
err
)
_
,
err
=
ethRelayer
.
LockEthErc20Asset
(
hexutil
.
Encode
(
crypto
.
FromECDSA
(
para
.
DeployPrivateKey
)),
tokenErc20Addrtestc
,
"100"
,
chain33Receiver
)
require
.
Nil
(
t
,
err
)
sim
.
Commit
()
sim
.
Commit
()
bridgeBankBalance
,
err
=
sim
.
BalanceAt
(
ctx
,
x2EthDeployInfo
.
BridgeBank
.
Address
,
nil
)
balance
,
err
=
ethRelayer
.
GetBalance
(
tokenErc20Addrtestc
,
para
.
Deployer
.
String
())
assert
.
NoError
(
t
,
err
)
require
.
Nil
(
t
,
err
)
assert
.
Equal
(
t
,
bridgeBankBalance
.
Int64
(),
ethAmount
.
Int64
())
assert
.
Equal
(
t
,
balance
,
"9999999999900"
)
_
,
err
=
ethRelayer
.
ApproveAllowance
(
hexutil
.
Encode
(
crypto
.
FromECDSA
(
para
.
DeployPrivateKey
)),
tokenErc20Addrtestc
,
"500"
)
require
.
Nil
(
t
,
err
)
sim
.
Commit
()
_
,
err
=
ethRelayer
.
LockEthErc20AssetAsync
(
hexutil
.
Encode
(
crypto
.
FromECDSA
(
para
.
DeployPrivateKey
)),
tokenErc20Addrtestc
,
"100"
,
chain33Receiver
)
require
.
Nil
(
t
,
err
)
sim
.
Commit
()
balance
,
err
=
ethRelayer
.
GetBalance
(
tokenErc20Addrtestc
,
para
.
Deployer
.
String
())
require
.
Nil
(
t
,
err
)
assert
.
Equal
(
t
,
balance
,
"9999999999800"
)
for
i
:=
0
;
i
<
11
;
i
++
{
for
i
:=
0
;
i
<
11
;
i
++
{
sim
.
Commit
()
sim
.
Commit
()
}
}
time
.
Sleep
(
time
.
Duration
(
ethRelayer
.
fetchHeightPeriodMs
)
*
time
.
Millisecond
)
}
func
Test_BurnBty
(
t
*
testing
.
T
)
{
para
,
sim
,
x2EthContracts
,
x2EthDeployInfo
,
err
:=
setup
.
DeployContracts
()
require
.
NoError
(
t
,
err
)
ethRelayer
:=
newEthRelayer
(
para
,
sim
,
x2EthContracts
,
x2EthDeployInfo
)
_
=
ethRelayer
.
ImportChain33PrivateKey
(
passphrase
,
chain33PrivateKeyStr
)
time
.
Sleep
(
time
.
Second
)
var
tx
chain33Types
.
Transaction
var
ret
chain33Types
.
Reply
ret
.
IsOk
=
true
mockapi
:=
&
mocks
.
QueueProtocolAPI
{}
// 这里对需要mock的方法打桩,Close是必须的,其它方法根据需要
mockapi
.
On
(
"Close"
)
.
Return
()
mockapi
.
On
(
"AddPushSubscribe"
,
mock
.
Anything
)
.
Return
(
&
ret
,
nil
)
mockapi
.
On
(
"CreateTransaction"
,
mock
.
Anything
)
.
Return
(
&
tx
,
nil
)
mockapi
.
On
(
"SendTx"
,
mock
.
Anything
)
.
Return
(
&
ret
,
nil
)
mockapi
.
On
(
"SendTransaction"
,
mock
.
Anything
)
.
Return
(
&
ret
,
nil
)
mockapi
.
On
(
"GetConfig"
,
mock
.
Anything
)
.
Return
(
chainTestCfg
,
nil
)
mock33
:=
testnode
.
New
(
""
,
mockapi
)
defer
mock33
.
Close
()
rpcCfg
:=
mock33
.
GetCfg
()
.
RPC
// 这里必须设置监听端口,默认的是无效值
rpcCfg
.
JrpcBindAddr
=
"127.0.0.1:8801"
mock33
.
GetRPC
()
.
Listen
()
tokenAddrbty
,
err
:=
ethRelayer
.
CreateBridgeToken
(
"bty"
)
require
.
Nil
(
t
,
err
)
require
.
NotEmpty
(
t
,
tokenAddrbty
)
sim
.
Commit
()
chain33Sender
:=
[]
byte
(
"14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
)
amount
:=
int64
(
100
)
ethReceiver
:=
para
.
InitValidators
[
2
]
claimID
:=
crypto
.
Keccak256Hash
(
chain33Sender
,
ethReceiver
.
Bytes
(),
big
.
NewInt
(
amount
)
.
Bytes
())
authOracle
,
err
:=
ethtxs
.
PrepareAuth
(
ethRelayer
.
clientSpec
,
para
.
ValidatorPriKey
[
0
],
para
.
InitValidators
[
0
])
require
.
Nil
(
t
,
err
)
signature
,
err
:=
ethtxs
.
SignClaim4Eth
(
claimID
,
para
.
ValidatorPriKey
[
0
])
require
.
Nil
(
t
,
err
)
_
,
err
=
x2EthContracts
.
Oracle
.
NewOracleClaim
(
authOracle
,
events
.
ClaimTypeLock
,
chain33Sender
,
ethReceiver
,
common
.
HexToAddress
(
tokenAddrbty
),
"bty"
,
big
.
NewInt
(
amount
),
claimID
,
signature
)
require
.
Nil
(
t
,
err
)
sim
.
Commit
()
balanceNew
,
err
:=
ethRelayer
.
GetBalance
(
tokenAddrbty
,
ethReceiver
.
String
())
require
.
Nil
(
t
,
err
)
require
.
Equal
(
t
,
balanceNew
,
"100"
)
_
,
err
=
ethRelayer
.
Burn
(
hexutil
.
Encode
(
crypto
.
FromECDSA
(
para
.
ValidatorPriKey
[
2
])),
tokenAddrbty
,
chain33AccountAddr
,
"10"
)
require
.
NoError
(
t
,
err
)
sim
.
Commit
()
time
.
Sleep
(
time
.
Duration
(
ethRelayer
.
fetchHeightPeriodMs
)
*
time
.
Millisecond
)
time
.
Sleep
(
time
.
Duration
(
ethRelayer
.
fetchHeightPeriodMs
)
*
time
.
Millisecond
)
balance
,
err
:=
ethRelayer
.
ShowLockStatics
(
""
)
fetchCnt
:=
int32
(
10
)
assert
.
NoError
(
t
,
err
)
logs
,
err
:=
ethRelayer
.
getNextValidEthTxEventLogs
(
ethRelayer
.
eventLogIndex
.
Height
,
ethRelayer
.
eventLogIndex
.
Index
,
fetchCnt
)
assert
.
Equal
(
t
,
balance
,
"50"
)
require
.
NoError
(
t
,
err
)
for
_
,
vLog
:=
range
logs
{
ethRelayer
.
procBridgeBankLogs
(
*
vLog
)
}
balanceNew
,
err
=
ethRelayer
.
GetBalance
(
tokenAddrbty
,
ethReceiver
.
String
())
require
.
Nil
(
t
,
err
)
require
.
Equal
(
t
,
balanceNew
,
"90"
)
_
,
err
=
ethRelayer
.
ApproveAllowance
(
hexutil
.
Encode
(
crypto
.
FromECDSA
(
para
.
ValidatorPriKey
[
2
])),
tokenAddrbty
,
"10"
)
require
.
Nil
(
t
,
err
)
sim
.
Commit
()
_
,
err
=
ethRelayer
.
BurnAsync
(
hexutil
.
Encode
(
crypto
.
FromECDSA
(
para
.
ValidatorPriKey
[
2
])),
tokenAddrbty
,
chain33AccountAddr
,
"10"
)
require
.
NoError
(
t
,
err
)
sim
.
Commit
()
balanceNew
,
err
=
ethRelayer
.
GetBalance
(
tokenAddrbty
,
ethReceiver
.
String
())
require
.
Nil
(
t
,
err
)
require
.
Equal
(
t
,
balanceNew
,
"80"
)
time
.
Sleep
(
time
.
Second
)
time
.
Sleep
(
time
.
Second
)
fmt
.
Println
(
"---------------------- end ----------------------"
)
}
}
//func Test_LockErc20(t *testing.T) {
// var tx chain33Types.Transaction
// var ret chain33Types.Reply
// ret.IsOk = true
//
// mockapi := &mocks.QueueProtocolAPI{}
// // 这里对需要mock的方法打桩,Close是必须的,其它方法根据需要
// mockapi.On("Close").Return()
// mockapi.On("AddPushSubscribe", mock.Anything).Return(&ret, nil)
// mockapi.On("CreateTransaction", mock.Anything).Return(&tx, nil)
// mockapi.On("SendTx", mock.Anything).Return(&ret, nil)
// mockapi.On("SendTransaction", mock.Anything).Return(&ret, nil)
// mockapi.On("GetConfig", mock.Anything).Return(chainTestCfg, nil)
//
// mock33 := testnode.New("", mockapi)
// defer mock33.Close()
// rpcCfg := mock33.GetCfg().RPC
// // 这里必须设置监听端口,默认的是无效值
// rpcCfg.JrpcBindAddr = "127.0.0.1:8801"
// mock33.GetRPC().Listen()
//
// tokenErc20Addr, err := ethRelayer.CreateERC20Token("testc")
// assert.NoError(t, err)
// require.NotEmpty(t, tokenErc20Addr)
// sim.Commit()
//
// fmt.Println("tokenErc20Addr**************", tokenErc20Addr)
//
// _, err = ethRelayer.MintERC20Token(tokenErc20Addr, para.Deployer.String(), "10000000000000")
// assert.NoError(t, err)
// sim.Commit()
//
// balance, err := ethRelayer.ShowDepositStatics(tokenErc20Addr)
// assert.NoError(t, err)
// assert.Equal(t, balance, "10000000000000")
//
// chain33Receiver := "14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
// _, err = ethRelayer.LockEthErc20Asset(hexutil.Encode(crypto.FromECDSA(para.DeployPrivateKey)), tokenErc20Addr, "100", chain33Receiver)
// assert.NoError(t, err)
// sim.Commit()
//
// balance, err = ethRelayer.GetBalance(tokenErc20Addr, para.Deployer.String())
// assert.NoError(t, err)
// assert.Equal(t, balance, "9999999999900")
//
// _, err = ethRelayer.ApproveAllowance(hexutil.Encode(crypto.FromECDSA(para.DeployPrivateKey)), tokenErc20Addr, "500")
// assert.NoError(t, err)
// sim.Commit()
//
// _, err = ethRelayer.LockEthErc20AssetAsync(hexutil.Encode(crypto.FromECDSA(para.DeployPrivateKey)), tokenErc20Addr, "100", chain33Receiver)
// assert.NoError(t, err)
// sim.Commit()
//
// balance, err = ethRelayer.GetBalance(tokenErc20Addr, para.Deployer.String())
// assert.NoError(t, err)
// assert.Equal(t, balance, "9999999999800")
// //
// //for i := 0; i < 11; i++ {
// // sim.Commit()
// //}
// //time.Sleep(time.Duration(ethRelayer.fetchHeightPeriodMs) * time.Millisecond)
//}
//func Test_BurnBty(t *testing.T) {
// tokenAddrbty, err := ethRelayer.CreateBridgeToken("bty")
// assert.NoError(t, err)
// require.NotEmpty(t, tokenAddrbty)
// sim.Commit()
//
// chain33Sender := []byte("14KEKbYtKKQm4wMthSK9J4La4nAiidGozt")
// amount := int64(100)
// ethReceiver := para.InitValidators[2]
// claimID := crypto.Keccak256Hash(chain33Sender, ethReceiver.Bytes(), big.NewInt(amount).Bytes())
//
// authOracle, err := ethtxs.PrepareAuth(ethRelayer.clientSpec, para.ValidatorPriKey[0], para.InitValidators[0])
// require.Nil(t, err)
// signature, err := ethtxs.SignClaim4Eth(claimID, para.ValidatorPriKey[0])
// require.Nil(t, err)
//
// _, err = x2EthContracts.Oracle.NewOracleClaim(
// authOracle,
// events.ClaimTypeLock,
// chain33Sender,
// ethReceiver,
// common.HexToAddress(tokenAddrbty),
// "bty",
// big.NewInt(amount),
// claimID,
// signature)
// require.Nil(t, err)
// sim.Commit()
//
// balanceNew, err := ethRelayer.GetBalance(tokenAddrbty, ethReceiver.String())
// require.Nil(t, err)
// require.Equal(t, balanceNew, "100")
//
// _, err = ethRelayer.Burn(hexutil.Encode(crypto.FromECDSA(para.ValidatorPriKey[2])), tokenAddrbty, chain33AccountAddr, "10")
// require.NoError(t, err)
// sim.Commit()
//
// balanceNew, err = ethRelayer.GetBalance(tokenAddrbty, ethReceiver.String())
// require.Nil(t, err)
// require.Equal(t, balanceNew, "90")
//
// _, err = ethRelayer.ApproveAllowance(hexutil.Encode(crypto.FromECDSA(para.ValidatorPriKey[2])), tokenAddrbty, "10")
// assert.NoError(t, err)
// sim.Commit()
//
// _, err = ethRelayer.BurnAsync(hexutil.Encode(crypto.FromECDSA(para.ValidatorPriKey[2])), tokenAddrbty, chain33AccountAddr, "10")
// require.NoError(t, err)
// sim.Commit()
//
// balanceNew, err = ethRelayer.GetBalance(tokenAddrbty, ethReceiver.String())
// require.Nil(t, err)
// require.Equal(t, balanceNew, "80")
//}
func
Test_RestorePrivateKeys
(
t
*
testing
.
T
)
{
func
Test_RestorePrivateKeys
(
t
*
testing
.
T
)
{
para
,
sim
,
x2EthContracts
,
x2EthDeployInfo
,
err
:=
setup
.
DeployContracts
()
require
.
NoError
(
t
,
err
)
ethRelayer
:=
newEthRelayer
(
para
,
sim
,
x2EthContracts
,
x2EthDeployInfo
)
_
=
ethRelayer
.
ImportChain33PrivateKey
(
passphrase
,
chain33PrivateKeyStr
)
time
.
Sleep
(
time
.
Second
)
go
func
()
{
go
func
()
{
for
range
ethRelayer
.
unlockchan
{
for
range
ethRelayer
.
unlockchan
{
}
}
}()
}()
temp
:=
ethRelayer
.
privateKey4Chain33
temp
:=
ethRelayer
.
privateKey4Chain33
err
:
=
ethRelayer
.
RestorePrivateKeys
(
"123"
)
err
=
ethRelayer
.
RestorePrivateKeys
(
"123"
)
assert
.
NotEqual
(
t
,
hex
.
EncodeToString
(
temp
.
Bytes
()),
hex
.
EncodeToString
(
ethRelayer
.
privateKey4Chain33
.
Bytes
()))
assert
.
NotEqual
(
t
,
hex
.
EncodeToString
(
temp
.
Bytes
()),
hex
.
EncodeToString
(
ethRelayer
.
privateKey4Chain33
.
Bytes
()))
assert
.
NoError
(
t
,
err
)
require
.
Nil
(
t
,
err
)
err
=
ethRelayer
.
RestorePrivateKeys
(
passphrase
)
err
=
ethRelayer
.
RestorePrivateKeys
(
passphrase
)
assert
.
Equal
(
t
,
hex
.
EncodeToString
(
temp
.
Bytes
()),
hex
.
EncodeToString
(
ethRelayer
.
privateKey4Chain33
.
Bytes
()))
assert
.
Equal
(
t
,
hex
.
EncodeToString
(
temp
.
Bytes
()),
hex
.
EncodeToString
(
ethRelayer
.
privateKey4Chain33
.
Bytes
()))
assert
.
NoError
(
t
,
err
)
require
.
Nil
(
t
,
err
)
err
=
ethRelayer
.
StoreAccountWithNewPassphase
(
"new123"
,
passphrase
)
err
=
ethRelayer
.
StoreAccountWithNewPassphase
(
"new123"
,
passphrase
)
assert
.
NoError
(
t
,
err
)
require
.
Nil
(
t
,
err
)
err
=
ethRelayer
.
RestorePrivateKeys
(
"new123"
)
err
=
ethRelayer
.
RestorePrivateKeys
(
"new123"
)
assert
.
Equal
(
t
,
hex
.
EncodeToString
(
temp
.
Bytes
()),
hex
.
EncodeToString
(
ethRelayer
.
privateKey4Chain33
.
Bytes
()))
assert
.
Equal
(
t
,
hex
.
EncodeToString
(
temp
.
Bytes
()),
hex
.
EncodeToString
(
ethRelayer
.
privateKey4Chain33
.
Bytes
()))
assert
.
NoError
(
t
,
err
)
require
.
Nil
(
t
,
err
)
time
.
Sleep
(
time
.
Second
)
time
.
Sleep
(
time
.
Second
)
}
}
func
newEthRelayer
()
*
Relayer4Ethereum
{
func
newEthRelayer
(
para
*
ethtxs
.
DeployPara
,
sim
*
ethinterface
.
SimExtend
,
x2EthContracts
*
ethtxs
.
X2EthContracts
,
x2EthDeployInfo
*
ethtxs
.
X2EthDeployInfo
)
*
Relayer4Ethereum
{
cfg
:=
initCfg
(
*
configPath
)
cfg
:=
initCfg
(
*
configPath
)
cfg
.
SyncTxConfig
.
Chain33Host
=
"http://127.0.0.1:8801"
cfg
.
SyncTxConfig
.
Chain33Host
=
"http://127.0.0.1:8801"
cfg
.
BridgeRegistry
=
x2EthDeployInfo
.
BridgeRegistry
.
Address
.
String
()
cfg
.
BridgeRegistry
=
x2EthDeployInfo
.
BridgeRegistry
.
Address
.
String
()
...
@@ -402,16 +487,21 @@ func newEthRelayer() *Relayer4Ethereum {
...
@@ -402,16 +487,21 @@ func newEthRelayer() *Relayer4Ethereum {
bridgeRegistryAddr
:
x2EthDeployInfo
.
BridgeRegistry
.
Address
,
bridgeRegistryAddr
:
x2EthDeployInfo
.
BridgeRegistry
.
Address
,
maturityDegree
:
cfg
.
EthMaturityDegree
,
maturityDegree
:
cfg
.
EthMaturityDegree
,
fetchHeightPeriodMs
:
cfg
.
EthBlockFetchPeriod
,
fetchHeightPeriodMs
:
cfg
.
EthBlockFetchPeriod
,
deployInfo
:
cfg
.
Deploy
,
//deployInfo: cfg.Deploy,
}
relayer
.
deployInfo
=
&
ebTypes
.
Deploy
{}
relayer
.
deployInfo
.
DeployerPrivateKey
=
common
.
ToHex
(
crypto
.
FromECDSA
(
para
.
DeployPrivateKey
))
relayer
.
deployInfo
.
OperatorAddr
=
para
.
Operator
.
String
()
for
_
,
v
:=
range
para
.
InitValidators
{
relayer
.
deployInfo
.
ValidatorsAddr
=
append
(
relayer
.
deployInfo
.
ValidatorsAddr
,
v
.
String
())
}
for
_
,
v
:=
range
para
.
InitPowers
{
relayer
.
deployInfo
.
InitPowers
=
append
(
relayer
.
deployInfo
.
InitPowers
,
v
.
Int64
())
}
}
//_ = relayer.setBridgeRegistryAddr(cfg.BridgeRegistry)
//registrAddrInDB, err := relayer.getBridgeRegistryAddr()
//assert.NoError(t, err)
//assert.Equal(t, registrAddrInDB, cfg.BridgeRegistry)
relayer
.
eventLogIndex
=
relayer
.
getLastBridgeBankProcessedHeight
()
relayer
.
eventLogIndex
=
relayer
.
getLastBridgeBankProcessedHeight
()
relayer
.
initBridgeBankTx
()
relayer
.
initBridgeBankTx
()
relayer
.
clientSpec
=
sim
relayer
.
clientSpec
=
sim
relayer
.
clientChainID
=
big
.
NewInt
(
1
)
relayer
.
clientChainID
=
big
.
NewInt
(
1
)
...
@@ -429,7 +519,7 @@ func newEthRelayer() *Relayer4Ethereum {
...
@@ -429,7 +519,7 @@ func newEthRelayer() *Relayer4Ethereum {
return
relayer
return
relayer
}
}
func
deployContracts
()
{
func
deployContracts
()
(
*
ethtxs
.
DeployPara
,
*
ethinterface
.
SimExtend
,
*
ethtxs
.
X2EthContracts
,
*
ethtxs
.
X2EthDeployInfo
)
{
ethValidatorAddrKeys
:=
make
([]
string
,
0
)
ethValidatorAddrKeys
:=
make
([]
string
,
0
)
ethValidatorAddrKeys
=
append
(
ethValidatorAddrKeys
,
ethValidatorAddrKeyA
)
ethValidatorAddrKeys
=
append
(
ethValidatorAddrKeys
,
ethValidatorAddrKeyA
)
ethValidatorAddrKeys
=
append
(
ethValidatorAddrKeys
,
ethValidatorAddrKeyB
)
ethValidatorAddrKeys
=
append
(
ethValidatorAddrKeys
,
ethValidatorAddrKeyB
)
...
@@ -437,25 +527,21 @@ func deployContracts() {
...
@@ -437,25 +527,21 @@ func deployContracts() {
ethValidatorAddrKeys
=
append
(
ethValidatorAddrKeys
,
ethValidatorAddrKeyD
)
ethValidatorAddrKeys
=
append
(
ethValidatorAddrKeys
,
ethValidatorAddrKeyD
)
ctx
:=
context
.
Background
()
ctx
:=
context
.
Background
()
var
backend
bind
.
ContractBackend
//
var backend bind.ContractBackend
backend
,
para
=
setup
.
PrepareTestEnvironment
(
deployerPrivateKey
,
ethValidatorAddrKeys
)
backend
,
para
:
=
setup
.
PrepareTestEnvironment
(
deployerPrivateKey
,
ethValidatorAddrKeys
)
sim
=
new
(
ethinterface
.
SimExtend
)
sim
:
=
new
(
ethinterface
.
SimExtend
)
sim
.
SimulatedBackend
=
backend
.
(
*
backends
.
SimulatedBackend
)
sim
.
SimulatedBackend
=
backend
.
(
*
backends
.
SimulatedBackend
)
//balance, _ := sim.BalanceAt(ctx, para.Deployer, nil)
//assert.Equal(t, balance.Int64(), int64(10000000000*10000))
callMsg
:=
ethereum
.
CallMsg
{
callMsg
:=
ethereum
.
CallMsg
{
From
:
para
.
Deployer
,
From
:
para
.
Deployer
,
Data
:
common
.
FromHex
(
generated
.
BridgeBankBin
),
Data
:
common
.
FromHex
(
generated
.
BridgeBankBin
),
}
}
_
,
_
=
sim
.
EstimateGas
(
ctx
,
callMsg
)
_
,
_
=
sim
.
EstimateGas
(
ctx
,
callMsg
)
//assert.NoError(t, err)
x2EthContracts
,
x2EthDeployInfo
,
_
:=
ethtxs
.
DeployAndInit
(
sim
,
para
)
x2EthContracts
,
x2EthDeployInfo
,
_
=
ethtxs
.
DeployAndInit
(
sim
,
para
)
//assert.NoError(t, err)
sim
.
Commit
()
sim
.
Commit
()
return
para
,
sim
,
x2EthContracts
,
x2EthDeployInfo
}
}
func
initCfg
(
path
string
)
*
relayerTypes
.
RelayerConfig
{
func
initCfg
(
path
string
)
*
relayerTypes
.
RelayerConfig
{
...
...
plugin/dapp/x2ethereum/executor/exec_test.go
View file @
62bf6d3d
package
executor
package
executor
import
(
import
(
"fmt"
"strconv"
//"github.com/33cn/chain33/client"
//"github.com/33cn/chain33/client"
"testing"
"testing"
...
@@ -190,10 +192,11 @@ func (x *suiteX2Ethereum) Test_4_Eth2Chain33() {
...
@@ -190,10 +192,11 @@ func (x *suiteX2Ethereum) Test_4_Eth2Chain33() {
x
.
setDb
(
receipt
)
x
.
setDb
(
receipt
)
_
,
err
=
x
.
x2eth
.
Query_GetEthProphecy
(
&
types2
.
QueryEthProphecyParams
{
ID
:
"010x7B95B6EC7EbD73572298cEf32Bb54FA408207359"
})
_
,
err
=
x
.
x2eth
.
Query_GetEthProphecy
(
&
types2
.
QueryEthProphecyParams
{
ID
:
"010x7B95B6EC7EbD73572298cEf32Bb54FA408207359"
})
x
.
Equal
(
err
,
types
2
.
ErrInvalidProphecyID
)
x
.
Equal
(
err
,
types
.
ErrNotFound
)
x
.
query_GetEthProphecy
(
"000x7B95B6EC7EbD73572298cEf32Bb54FA408207359"
,
types2
.
EthBridgeStatus_SuccessStatusText
)
ID
:=
strconv
.
Itoa
(
0
)
+
strconv
.
Itoa
(
0
)
+
ethereumAddr
+
tokenContractAddress
+
"lock"
x
.
query_GetSymbolTotalAmountByTxType
(
symbol
,
1
,
"lock"
,
10
)
x
.
queryGetEthProphecy
(
ID
,
types2
.
EthBridgeStatus_SuccessStatusText
)
x
.
queryGetSymbolTotalAmountByTxType
(
1
,
symbol
,
"lock"
,
"10"
)
payload1
:=
&
types2
.
Chain33ToEth
{
payload1
:=
&
types2
.
Chain33ToEth
{
TokenContract
:
tokenContractAddress
,
TokenContract
:
tokenContractAddress
,
...
@@ -217,9 +220,9 @@ func (x *suiteX2Ethereum) Test_4_Eth2Chain33() {
...
@@ -217,9 +220,9 @@ func (x *suiteX2Ethereum) Test_4_Eth2Chain33() {
x
.
NoError
(
err
)
x
.
NoError
(
err
)
x
.
setDb
(
receipt
)
x
.
setDb
(
receipt
)
x
.
query
_
GetEthProphecy
(
"010x7B95B6EC7EbD73572298cEf32Bb54FA408207359"
,
types2
.
EthBridgeStatus_SuccessStatusText
)
x
.
queryGetEthProphecy
(
"010x7B95B6EC7EbD73572298cEf32Bb54FA408207359"
,
types2
.
EthBridgeStatus_SuccessStatusText
)
x
.
query
_
GetSymbolTotalAmount
(
symbol
,
1
,
7
)
x
.
queryGetSymbolTotalAmount
(
symbol
,
1
,
7
)
x
.
query
_GetSymbolTotalAmountByTxType
(
symbol
,
1
,
"withdraw"
,
3
)
x
.
query
GetSymbolTotalAmountByTxType
(
1
,
symbol
,
"withdraw"
,
"3"
)
//payload.Amount = "10"
//payload.Amount = "10"
//payload.Nonce = 2
//payload.Nonce = 2
...
@@ -242,8 +245,8 @@ func (x *suiteX2Ethereum) Test_4_Eth2Chain33() {
...
@@ -242,8 +245,8 @@ func (x *suiteX2Ethereum) Test_4_Eth2Chain33() {
x
.
NoError
(
err
)
x
.
NoError
(
err
)
x
.
setDb
(
receipt
)
x
.
setDb
(
receipt
)
x
.
query
_
GetEthProphecy
(
"030x7B95B6EC7EbD73572298cEf32Bb54FA408207359"
,
types2
.
EthBridgeStatus_SuccessStatusText
)
x
.
queryGetEthProphecy
(
"030x7B95B6EC7EbD73572298cEf32Bb54FA408207359"
,
types2
.
EthBridgeStatus_SuccessStatusText
)
x
.
query
_GetSymbolTotalAmountByTxType
(
symbol
,
1
,
"lock"
,
11
)
x
.
query
GetSymbolTotalAmountByTxType
(
1
,
symbol
,
"lock"
,
"11"
)
}
}
func
(
x
*
suiteX2Ethereum
)
Test_5_Chain33ToEth
()
{
func
(
x
*
suiteX2Ethereum
)
Test_5_Chain33ToEth
()
{
...
@@ -259,16 +262,16 @@ func (x *suiteX2Ethereum) Test_5_Chain33ToEth() {
...
@@ -259,16 +262,16 @@ func (x *suiteX2Ethereum) Test_5_Chain33ToEth() {
x
.
NoError
(
err
)
x
.
NoError
(
err
)
x
.
setDb
(
receipt
)
x
.
setDb
(
receipt
)
x
.
query
_
GetSymbolTotalAmount
(
"bty"
,
2
,
5
)
x
.
queryGetSymbolTotalAmount
(
"bty"
,
2
,
5
)
x
.
query
_GetSymbolTotalAmountByTxType
(
"bty"
,
2
,
"lock"
,
5
)
x
.
query
GetSymbolTotalAmountByTxType
(
2
,
"bty"
,
"lock"
,
"5"
)
//msgLock.Amount = "4"
//msgLock.Amount = "4"
//receipt, err = x.action.procEth2Chain33_burn(msgLock)
//receipt, err = x.action.procEth2Chain33_burn(msgLock)
//x.NoError(err)
//x.NoError(err)
//x.setDb(receipt)
//x.setDb(receipt)
//
//
//x.query
_
GetSymbolTotalAmount("bty", 2, 1)
//x.queryGetSymbolTotalAmount("bty", 2, 1)
//x.query
_
GetSymbolTotalAmountByTxType("bty", 2, "withdraw", 4)
//x.queryGetSymbolTotalAmountByTxType("bty", 2, "withdraw", 4)
//
//
//receipt, err = x.action.procEth2Chain33_burn(msgLock)
//receipt, err = x.action.procEth2Chain33_burn(msgLock)
//x.Equal(err, types.ErrNoBalance)
//x.Equal(err, types.ErrNoBalance)
...
@@ -278,8 +281,8 @@ func (x *suiteX2Ethereum) Test_5_Chain33ToEth() {
...
@@ -278,8 +281,8 @@ func (x *suiteX2Ethereum) Test_5_Chain33ToEth() {
//x.NoError(err)
//x.NoError(err)
//x.setDb(receipt)
//x.setDb(receipt)
x
.
query
_
GetSymbolTotalAmount
(
"bty"
,
2
,
0
)
x
.
queryGetSymbolTotalAmount
(
"bty"
,
2
,
0
)
x
.
query
_GetSymbolTotalAmountByTxType
(
"bty"
,
2
,
"withdraw"
,
5
)
x
.
query
GetSymbolTotalAmountByTxType
(
2
,
"bty"
,
"withdraw"
,
"5"
)
}
}
func
(
x
*
suiteX2Ethereum
)
accountSetup
()
{
func
(
x
*
suiteX2Ethereum
)
accountSetup
()
{
...
@@ -323,7 +326,7 @@ func (x *suiteX2Ethereum) setDb(receipt *chain33types.Receipt) {
...
@@ -323,7 +326,7 @@ func (x *suiteX2Ethereum) setDb(receipt *chain33types.Receipt) {
}
}
}
}
func
(
x
*
suiteX2Ethereum
)
query
_GetSymbolTotalAmountByTxType
(
tokenSymbol
string
,
direction
int64
,
txType
string
,
equal
int64
)
{
func
(
x
*
suiteX2Ethereum
)
query
GetSymbolTotalAmountByTxType
(
direction
int64
,
tokenSymbol
,
txType
,
equal
string
)
{
params
:=
&
types2
.
QuerySymbolAssetsByTxTypeParams
{
params
:=
&
types2
.
QuerySymbolAssetsByTxTypeParams
{
TokenSymbol
:
tokenSymbol
,
TokenSymbol
:
tokenSymbol
,
Direction
:
direction
,
Direction
:
direction
,
...
@@ -332,18 +335,20 @@ func (x *suiteX2Ethereum) query_GetSymbolTotalAmountByTxType(tokenSymbol string,
...
@@ -332,18 +335,20 @@ func (x *suiteX2Ethereum) query_GetSymbolTotalAmountByTxType(tokenSymbol string,
msg
,
err
:=
x
.
x2eth
.
Query_GetSymbolTotalAmountByTxType
(
params
)
msg
,
err
:=
x
.
x2eth
.
Query_GetSymbolTotalAmountByTxType
(
params
)
x
.
NoError
(
err
)
x
.
NoError
(
err
)
symbolAmount
:=
msg
.
(
*
types2
.
ReceiptQuerySymbolAssetsByTxType
)
fmt
.
Println
(
"***"
,
msg
,
err
)
x
.
Equal
(
symbolAmount
.
TotalAmount
,
uint64
(
equal
))
symbolAmount
:=
msg
.
(
*
types2
.
ReceiptQuerySymbolAssets
)
x
.
Equal
(
symbolAmount
.
Res
[
0
]
.
TotalAmount
,
equal
)
}
}
func
(
x
*
suiteX2Ethereum
)
query
_
GetSymbolTotalAmount
(
tokenSymbol
string
,
direction
int64
,
equal
int64
)
{
func
(
x
*
suiteX2Ethereum
)
queryGetSymbolTotalAmount
(
tokenSymbol
string
,
direction
int64
,
equal
int64
)
{
msg
,
err
:=
x
.
x2eth
.
Query_GetSymbolTotalAmountByTxType
(
&
types2
.
QuerySymbolAssetsByTxTypeParams
{
TokenSymbol
:
tokenSymbol
,
Direction
:
direction
})
msg
,
err
:=
x
.
x2eth
.
Query_GetSymbolTotalAmountByTxType
(
&
types2
.
QuerySymbolAssetsByTxTypeParams
{
TokenSymbol
:
tokenSymbol
,
Direction
:
direction
})
x
.
NoError
(
err
)
x
.
NoError
(
err
)
reply
:=
msg
.
(
*
types2
.
ReceiptQuerySymbolAssets
)
reply
:=
msg
.
(
*
types2
.
ReceiptQuerySymbolAssets
)
x
.
Equal
(
reply
.
Res
[
0
]
.
TotalAmount
,
uint64
(
equal
))
x
.
Equal
(
reply
.
Res
[
0
]
.
TotalAmount
,
uint64
(
equal
))
}
}
func
(
x
*
suiteX2Ethereum
)
query
_
GetEthProphecy
(
id
string
,
statusTest
types2
.
EthBridgeStatus
)
{
func
(
x
*
suiteX2Ethereum
)
queryGetEthProphecy
(
id
string
,
statusTest
types2
.
EthBridgeStatus
)
{
msg
,
err
:=
x
.
x2eth
.
Query_GetEthProphecy
(
&
types2
.
QueryEthProphecyParams
{
ID
:
id
})
msg
,
err
:=
x
.
x2eth
.
Query_GetEthProphecy
(
&
types2
.
QueryEthProphecyParams
{
ID
:
id
})
x
.
NoError
(
err
)
x
.
NoError
(
err
)
reply
:=
msg
.
(
*
types2
.
ReceiptEthProphecy
)
reply
:=
msg
.
(
*
types2
.
ReceiptEthProphecy
)
...
...
plugin/dapp/x2ethereum/executor/x2ethereumaction.go
View file @
62bf6d3d
...
@@ -125,7 +125,7 @@ func (a *action) procChain33ToEth_burn(msgBurn *x2eTy.Chain33ToEth) (*types.Rece
...
@@ -125,7 +125,7 @@ func (a *action) procChain33ToEth_burn(msgBurn *x2eTy.Chain33ToEth) (*types.Rece
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
errors
.
Wrapf
(
err
,
"relay procMsgBurn,exec=%s,sym=%s"
,
x2eTy
.
X2ethereumX
,
msgBurn
.
IssuerDotSymbol
)
return
nil
,
errors
.
Wrapf
(
err
,
"relay procMsgBurn,exec=%s,sym=%s"
,
x2eTy
.
X2ethereumX
,
msgBurn
.
IssuerDotSymbol
)
}
}
r
,
err
:=
a
.
oracle
.
ProcessBurn
(
a
.
fromaddr
,
a
.
execaddr
,
msgBurn
.
Amount
,
msgBurn
.
TokenContract
,
msgBurn
.
Decimals
,
accDB
)
r
,
err
:=
a
.
oracle
.
ProcessBurn
(
a
.
fromaddr
,
msgBurn
.
Amount
,
accDB
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
...
plugin/dapp/x2ethereum/executor/x2ethereumdb.go
View file @
62bf6d3d
...
@@ -75,7 +75,7 @@ func (o *Oracle) ProcessSuccessfulClaimForBurn(claim, execAddr, tokenSymbol stri
...
@@ -75,7 +75,7 @@ func (o *Oracle) ProcessSuccessfulClaimForBurn(claim, execAddr, tokenSymbol stri
}
}
// ProcessBurn processes the burn of bridged coins from the given sender
// ProcessBurn processes the burn of bridged coins from the given sender
func
(
o
*
Oracle
)
ProcessBurn
(
address
,
execAddr
,
amount
,
tokenAddress
string
,
d
int64
,
accDB
*
account
.
DB
)
(
*
types
.
Receipt
,
error
)
{
func
(
o
*
Oracle
)
ProcessBurn
(
address
,
amount
string
,
accDB
*
account
.
DB
)
(
*
types
.
Receipt
,
error
)
{
var
a
int64
var
a
int64
a
,
_
=
strconv
.
ParseInt
(
x2eTy
.
TrimZeroAndDot
(
amount
),
10
,
64
)
a
,
_
=
strconv
.
ParseInt
(
x2eTy
.
TrimZeroAndDot
(
amount
),
10
,
64
)
...
...
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