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
84724970
Commit
84724970
authored
Jun 05, 2020
by
QM
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updata unit test
parent
ba06759c
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
122 additions
and
134 deletions
+122
-134
bridgeBank_test.go
.../x2ethereum/ebrelayer/ethcontract/test/bridgeBank_test.go
+69
-70
setupTestEnv.go
...ethereum/ebrelayer/ethcontract/test/setup/setupTestEnv.go
+4
-2
chain33_test.go
...dapp/x2ethereum/ebrelayer/relayer/chain33/chain33_test.go
+46
-62
ethereum_test.go
...pp/x2ethereum/ebrelayer/relayer/ethereum/ethereum_test.go
+3
-0
No files found.
plugin/dapp/x2ethereum/ebrelayer/ethcontract/test/bridgeBank_test.go
View file @
84724970
...
@@ -13,7 +13,6 @@ import (
...
@@ -13,7 +13,6 @@ import (
"github.com/33cn/plugin/plugin/dapp/x2ethereum/ebrelayer/events"
"github.com/33cn/plugin/plugin/dapp/x2ethereum/ebrelayer/events"
"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"
"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/core/types"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto"
...
@@ -25,8 +24,7 @@ func TestBrigeTokenCreat(t *testing.T) {
...
@@ -25,8 +24,7 @@ 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部署相关合约
backend
,
para
:=
setup
.
PrepareTestEnv
()
sim
,
para
:=
setup
.
PrepareTestEnv
()
sim
:=
backend
.
(
*
backends
.
SimulatedBackend
)
balance
,
_
:=
sim
.
BalanceAt
(
ctx
,
para
.
Deployer
,
nil
)
balance
,
_
:=
sim
.
BalanceAt
(
ctx
,
para
.
Deployer
,
nil
)
fmt
.
Println
(
"deployer addr,"
,
para
.
Deployer
.
String
(),
"balance ="
,
balance
.
String
())
fmt
.
Println
(
"deployer addr,"
,
para
.
Deployer
.
String
(),
"balance ="
,
balance
.
String
())
...
@@ -44,7 +42,7 @@ func TestBrigeTokenCreat(t *testing.T) {
...
@@ -44,7 +42,7 @@ func TestBrigeTokenCreat(t *testing.T) {
fmt
.
Printf
(
"
\n
The estimated gas=%d"
,
gas
)
fmt
.
Printf
(
"
\n
The estimated gas=%d"
,
gas
)
////////////////////////////////////////////////////
////////////////////////////////////////////////////
x2EthContracts
,
x2EthDeployInfo
,
err
:=
ethtxs
.
DeployAndInit
(
backend
,
para
)
x2EthContracts
,
x2EthDeployInfo
,
err
:=
ethtxs
.
DeployAndInit
(
sim
,
para
)
if
nil
!=
err
{
if
nil
!=
err
{
t
.
Fatalf
(
"DeployAndInit failed due to:%s"
,
err
.
Error
())
t
.
Fatalf
(
"DeployAndInit failed due to:%s"
,
err
.
Error
())
}
}
...
@@ -63,9 +61,8 @@ func TestBrigeTokenCreat(t *testing.T) {
...
@@ -63,9 +61,8 @@ func TestBrigeTokenCreat(t *testing.T) {
sub
,
err
:=
sim
.
SubscribeFilterLogs
(
ctx
,
query
,
logs
)
sub
,
err
:=
sim
.
SubscribeFilterLogs
(
ctx
,
query
,
logs
)
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
err
)
//fmt.Printf("\n*****BridgeBank addr:%s, BridgeBank:%v***\n\n", deployInfo.BridgeBank.Address.String(), x2EthContracts.BridgeBank)
t
.
Logf
(
"x2EthDeployInfo.BridgeBank.Address is:%s"
,
x2EthDeployInfo
.
BridgeBank
.
Address
.
String
())
t
.
Logf
(
"x2EthDeployInfo.BridgeBank.Address is:%s"
,
x2EthDeployInfo
.
BridgeBank
.
Address
.
String
())
bridgeBank
,
err
:=
generated
.
NewBridgeBank
(
x2EthDeployInfo
.
BridgeBank
.
Address
,
backend
)
bridgeBank
,
err
:=
generated
.
NewBridgeBank
(
x2EthDeployInfo
.
BridgeBank
.
Address
,
sim
)
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
err
)
opts
:=
&
bind
.
CallOpts
{
opts
:=
&
bind
.
CallOpts
{
...
@@ -77,13 +74,12 @@ func TestBrigeTokenCreat(t *testing.T) {
...
@@ -77,13 +74,12 @@ func TestBrigeTokenCreat(t *testing.T) {
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
err
)
t
.
Logf
(
"BridgeBankAddr is:%s"
,
BridgeBankAddr
.
String
())
t
.
Logf
(
"BridgeBankAddr is:%s"
,
BridgeBankAddr
.
String
())
//tokenCount, err := x2EthContracts.BridgeBank.BridgeTokenCount(opts)
tokenCount
,
err
:=
bridgeBank
.
BridgeBankCaller
.
BridgeTokenCount
(
opts
)
tokenCount
,
err
:=
bridgeBank
.
BridgeBankCaller
.
BridgeTokenCount
(
opts
)
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
err
)
require
.
Equal
(
t
,
tokenCount
.
Int64
(),
int64
(
0
))
require
.
Equal
(
t
,
tokenCount
.
Int64
(),
int64
(
0
))
//3rd:创建token
//3rd:创建token
auth
,
err
:=
ethtxs
.
PrepareAuth
(
backend
,
para
.
DeployPrivateKey
,
para
.
Operator
)
auth
,
err
:=
ethtxs
.
PrepareAuth
(
sim
,
para
.
DeployPrivateKey
,
para
.
Operator
)
if
nil
!=
err
{
if
nil
!=
err
{
t
.
Fatalf
(
"PrepareAuth failed due to:%s"
,
err
.
Error
())
t
.
Fatalf
(
"PrepareAuth failed due to:%s"
,
err
.
Error
())
}
}
...
@@ -134,8 +130,7 @@ func TestBrigeTokenMint(t *testing.T) {
...
@@ -134,8 +130,7 @@ 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部署相关合约
backend
,
para
:=
setup
.
PrepareTestEnv
()
sim
,
para
:=
setup
.
PrepareTestEnv
()
sim
:=
backend
.
(
*
backends
.
SimulatedBackend
)
balance
,
_
:=
sim
.
BalanceAt
(
ctx
,
para
.
Deployer
,
nil
)
balance
,
_
:=
sim
.
BalanceAt
(
ctx
,
para
.
Deployer
,
nil
)
fmt
.
Println
(
"deployer addr,"
,
para
.
Deployer
.
String
(),
"balance ="
,
balance
.
String
())
fmt
.
Println
(
"deployer addr,"
,
para
.
Deployer
.
String
(),
"balance ="
,
balance
.
String
())
...
@@ -153,12 +148,12 @@ func TestBrigeTokenMint(t *testing.T) {
...
@@ -153,12 +148,12 @@ func TestBrigeTokenMint(t *testing.T) {
fmt
.
Printf
(
"
\n
The estimated gas=%d"
,
gas
)
fmt
.
Printf
(
"
\n
The estimated gas=%d"
,
gas
)
////////////////////////////////////////////////////
////////////////////////////////////////////////////
x2EthContracts
,
x2EthDeployInfo
,
err
:=
ethtxs
.
DeployAndInit
(
backend
,
para
)
x2EthContracts
,
x2EthDeployInfo
,
err
:=
ethtxs
.
DeployAndInit
(
sim
,
para
)
if
nil
!=
err
{
if
nil
!=
err
{
t
.
Fatalf
(
"DeployAndInit failed due to:%s"
,
err
.
Error
())
t
.
Fatalf
(
"DeployAndInit failed due to:%s"
,
err
.
Error
())
}
}
sim
.
Commit
()
sim
.
Commit
()
auth
,
err
:=
ethtxs
.
PrepareAuth
(
backend
,
para
.
DeployPrivateKey
,
para
.
Operator
)
auth
,
err
:=
ethtxs
.
PrepareAuth
(
sim
,
para
.
DeployPrivateKey
,
para
.
Operator
)
if
nil
!=
err
{
if
nil
!=
err
{
t
.
Fatalf
(
"PrepareAuth failed due to:%s"
,
err
.
Error
())
t
.
Fatalf
(
"PrepareAuth failed due to:%s"
,
err
.
Error
())
}
}
...
@@ -183,6 +178,7 @@ func TestBrigeTokenMint(t *testing.T) {
...
@@ -183,6 +178,7 @@ func TestBrigeTokenMint(t *testing.T) {
}
}
tokenCount
,
err
:=
x2EthContracts
.
BridgeBank
.
BridgeTokenCount
(
opts
)
tokenCount
,
err
:=
x2EthContracts
.
BridgeBank
.
BridgeTokenCount
(
opts
)
require
.
Nil
(
t
,
err
)
require
.
Equal
(
t
,
tokenCount
.
Int64
(),
int64
(
0
))
require
.
Equal
(
t
,
tokenCount
.
Int64
(),
int64
(
0
))
//3rd:创建token
//3rd:创建token
...
@@ -212,6 +208,7 @@ func TestBrigeTokenMint(t *testing.T) {
...
@@ -212,6 +208,7 @@ func TestBrigeTokenMint(t *testing.T) {
//tokenCount正确加1
//tokenCount正确加1
tokenCount
,
err
=
x2EthContracts
.
BridgeBank
.
BridgeTokenCount
(
opts
)
tokenCount
,
err
=
x2EthContracts
.
BridgeBank
.
BridgeTokenCount
(
opts
)
require
.
Nil
(
t
,
err
)
require
.
Equal
(
t
,
tokenCount
.
Int64
(),
int64
(
1
))
require
.
Equal
(
t
,
tokenCount
.
Int64
(),
int64
(
1
))
break
break
}
}
...
@@ -226,13 +223,13 @@ func TestBrigeTokenMint(t *testing.T) {
...
@@ -226,13 +223,13 @@ func TestBrigeTokenMint(t *testing.T) {
ethReceiver
:=
para
.
InitValidators
[
2
]
ethReceiver
:=
para
.
InitValidators
[
2
]
claimID
:=
crypto
.
Keccak256Hash
(
chain33Sender
,
ethReceiver
.
Bytes
(),
logEvent
.
Token
.
Bytes
(),
big
.
NewInt
(
amount
)
.
Bytes
())
claimID
:=
crypto
.
Keccak256Hash
(
chain33Sender
,
ethReceiver
.
Bytes
(),
logEvent
.
Token
.
Bytes
(),
big
.
NewInt
(
amount
)
.
Bytes
())
authOracle
,
err
:=
ethtxs
.
PrepareAuth
(
backend
,
para
.
ValidatorPriKey
[
0
],
para
.
InitValidators
[
0
])
authOracle
,
err
:=
ethtxs
.
PrepareAuth
(
sim
,
para
.
ValidatorPriKey
[
0
],
para
.
InitValidators
[
0
])
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
err
)
signature
,
err
:=
ethtxs
.
SignClaim4Eth
(
claimID
,
para
.
ValidatorPriKey
[
0
])
signature
,
err
:=
ethtxs
.
SignClaim4Eth
(
claimID
,
para
.
ValidatorPriKey
[
0
])
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
err
)
bridgeToken
,
err
:=
generated
.
NewBridgeToken
(
logEvent
.
Token
,
backend
)
bridgeToken
,
err
:=
generated
.
NewBridgeToken
(
logEvent
.
Token
,
sim
)
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
err
)
opts
=
&
bind
.
CallOpts
{
opts
=
&
bind
.
CallOpts
{
Pending
:
true
,
Pending
:
true
,
...
@@ -268,8 +265,7 @@ func TestBridgeDepositLock(t *testing.T) {
...
@@ -268,8 +265,7 @@ 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部署相关合约
backend
,
para
:=
setup
.
PrepareTestEnv
()
sim
,
para
:=
setup
.
PrepareTestEnv
()
sim
:=
backend
.
(
*
backends
.
SimulatedBackend
)
balance
,
_
:=
sim
.
BalanceAt
(
ctx
,
para
.
Deployer
,
nil
)
balance
,
_
:=
sim
.
BalanceAt
(
ctx
,
para
.
Deployer
,
nil
)
fmt
.
Println
(
"deployer addr,"
,
para
.
Deployer
.
String
(),
"balance ="
,
balance
.
String
())
fmt
.
Println
(
"deployer addr,"
,
para
.
Deployer
.
String
(),
"balance ="
,
balance
.
String
())
...
@@ -287,16 +283,16 @@ func TestBridgeDepositLock(t *testing.T) {
...
@@ -287,16 +283,16 @@ func TestBridgeDepositLock(t *testing.T) {
fmt
.
Printf
(
"
\n
The estimated gas=%d"
,
gas
)
fmt
.
Printf
(
"
\n
The estimated gas=%d"
,
gas
)
////////////////////////////////////////////////////
////////////////////////////////////////////////////
x2EthContracts
,
x2EthDeployInfo
,
err
:=
ethtxs
.
DeployAndInit
(
backend
,
para
)
x2EthContracts
,
x2EthDeployInfo
,
err
:=
ethtxs
.
DeployAndInit
(
sim
,
para
)
if
nil
!=
err
{
if
nil
!=
err
{
t
.
Fatalf
(
"DeployAndInit failed due to:%s"
,
err
.
Error
())
t
.
Fatalf
(
"DeployAndInit failed due to:%s"
,
err
.
Error
())
}
}
sim
.
Commit
()
sim
.
Commit
()
//创建token
//创建token
operatorAuth
,
err
:=
ethtxs
.
PrepareAuth
(
backend
,
para
.
DeployPrivateKey
,
para
.
Operator
)
operatorAuth
,
err
:=
ethtxs
.
PrepareAuth
(
sim
,
para
.
DeployPrivateKey
,
para
.
Operator
)
symbol
:=
"USDT"
symbol
:=
"USDT"
bridgeTokenAddr
,
_
,
bridgeTokenInstance
,
err
:=
generated
.
DeployBridgeToken
(
operatorAuth
,
backend
,
symbol
)
bridgeTokenAddr
,
_
,
bridgeTokenInstance
,
err
:=
generated
.
DeployBridgeToken
(
operatorAuth
,
sim
,
symbol
)
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
err
)
sim
.
Commit
()
sim
.
Commit
()
t
.
Logf
(
"The new creaded symbol:%s, address:%s"
,
symbol
,
bridgeTokenAddr
.
String
())
t
.
Logf
(
"The new creaded symbol:%s, address:%s"
,
symbol
,
bridgeTokenAddr
.
String
())
...
@@ -316,7 +312,7 @@ func TestBridgeDepositLock(t *testing.T) {
...
@@ -316,7 +312,7 @@ func TestBridgeDepositLock(t *testing.T) {
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
err
)
require
.
Equal
(
t
,
isMiner
,
true
)
require
.
Equal
(
t
,
isMiner
,
true
)
operatorAuth
,
err
=
ethtxs
.
PrepareAuth
(
backend
,
para
.
DeployPrivateKey
,
para
.
Operator
)
operatorAuth
,
err
=
ethtxs
.
PrepareAuth
(
sim
,
para
.
DeployPrivateKey
,
para
.
Operator
)
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
err
)
mintAmount
:=
int64
(
1000
)
mintAmount
:=
int64
(
1000
)
...
@@ -325,7 +321,7 @@ func TestBridgeDepositLock(t *testing.T) {
...
@@ -325,7 +321,7 @@ func TestBridgeDepositLock(t *testing.T) {
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
err
)
sim
.
Commit
()
sim
.
Commit
()
userOneAuth
,
err
:=
ethtxs
.
PrepareAuth
(
backend
,
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
)
_
,
err
=
bridgeTokenInstance
.
Approve
(
userOneAuth
,
x2EthDeployInfo
.
BridgeBank
.
Address
,
big
.
NewInt
(
allowAmount
))
_
,
err
=
bridgeTokenInstance
.
Approve
(
userOneAuth
,
x2EthDeployInfo
.
BridgeBank
.
Address
,
big
.
NewInt
(
allowAmount
))
...
@@ -338,7 +334,7 @@ func TestBridgeDepositLock(t *testing.T) {
...
@@ -338,7 +334,7 @@ func TestBridgeDepositLock(t *testing.T) {
require
.
Equal
(
t
,
userOneBalance
.
Int64
(),
mintAmount
)
require
.
Equal
(
t
,
userOneBalance
.
Int64
(),
mintAmount
)
// 测试子项目:should allow users to lock ERC20 tokens
// 测试子项目:should allow users to lock ERC20 tokens
userOneAuth
,
err
=
ethtxs
.
PrepareAuth
(
backend
,
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
...
@@ -366,7 +362,7 @@ func TestBridgeDepositLock(t *testing.T) {
...
@@ -366,7 +362,7 @@ func TestBridgeDepositLock(t *testing.T) {
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
err
)
t
.
Logf
(
"origin eth bridgeBankBalance is:%d"
,
bridgeBankBalance
.
Int64
())
t
.
Logf
(
"origin eth bridgeBankBalance is:%d"
,
bridgeBankBalance
.
Int64
())
userOneAuth
,
err
=
ethtxs
.
PrepareAuth
(
backend
,
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
)
ethAmount
:=
big
.
NewInt
(
50
)
ethAmount
:=
big
.
NewInt
(
50
)
userOneAuth
.
Value
=
ethAmount
userOneAuth
.
Value
=
ethAmount
...
@@ -390,8 +386,7 @@ func TestBridgeBankUnlock(t *testing.T) {
...
@@ -390,8 +386,7 @@ 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部署相关合约
backend
,
para
:=
setup
.
PrepareTestEnv
()
sim
,
para
:=
setup
.
PrepareTestEnv
()
sim
:=
backend
.
(
*
backends
.
SimulatedBackend
)
balance
,
_
:=
sim
.
BalanceAt
(
ctx
,
para
.
Deployer
,
nil
)
balance
,
_
:=
sim
.
BalanceAt
(
ctx
,
para
.
Deployer
,
nil
)
fmt
.
Println
(
"deployer addr,"
,
para
.
Deployer
.
String
(),
"balance ="
,
balance
.
String
())
fmt
.
Println
(
"deployer addr,"
,
para
.
Deployer
.
String
(),
"balance ="
,
balance
.
String
())
...
@@ -409,7 +404,7 @@ func TestBridgeBankUnlock(t *testing.T) {
...
@@ -409,7 +404,7 @@ func TestBridgeBankUnlock(t *testing.T) {
fmt
.
Printf
(
"
\n
The estimated gas=%d"
,
gas
)
fmt
.
Printf
(
"
\n
The estimated gas=%d"
,
gas
)
////////////////////////////////////////////////////
////////////////////////////////////////////////////
x2EthContracts
,
x2EthDeployInfo
,
err
:=
ethtxs
.
DeployAndInit
(
backend
,
para
)
x2EthContracts
,
x2EthDeployInfo
,
err
:=
ethtxs
.
DeployAndInit
(
sim
,
para
)
if
nil
!=
err
{
if
nil
!=
err
{
t
.
Fatalf
(
"DeployAndInit failed due to:%s"
,
err
.
Error
())
t
.
Fatalf
(
"DeployAndInit failed due to:%s"
,
err
.
Error
())
}
}
...
@@ -417,8 +412,9 @@ func TestBridgeBankUnlock(t *testing.T) {
...
@@ -417,8 +412,9 @@ func TestBridgeBankUnlock(t *testing.T) {
//1.lockEth资产
//1.lockEth资产
ethAddr
:=
common
.
Address
{}
ethAddr
:=
common
.
Address
{}
ethToken
,
err
:=
generated
.
NewBridgeToken
(
ethAddr
,
backend
)
ethToken
,
err
:=
generated
.
NewBridgeToken
(
ethAddr
,
sim
)
userOneAuth
,
err
:=
ethtxs
.
PrepareAuth
(
backend
,
para
.
ValidatorPriKey
[
0
],
para
.
InitValidators
[
0
])
userOneAuth
,
err
:=
ethtxs
.
PrepareAuth
(
sim
,
para
.
ValidatorPriKey
[
0
],
para
.
InitValidators
[
0
])
require
.
Nil
(
t
,
err
)
userOneAuth
.
Value
=
big
.
NewInt
(
300
)
userOneAuth
.
Value
=
big
.
NewInt
(
300
)
_
,
err
=
ethToken
.
Transfer
(
userOneAuth
,
x2EthDeployInfo
.
BridgeBank
.
Address
,
userOneAuth
.
Value
)
_
,
err
=
ethToken
.
Transfer
(
userOneAuth
,
x2EthDeployInfo
.
BridgeBank
.
Address
,
userOneAuth
.
Value
)
sim
.
Commit
()
sim
.
Commit
()
...
@@ -435,12 +431,12 @@ func TestBridgeBankUnlock(t *testing.T) {
...
@@ -435,12 +431,12 @@ func TestBridgeBankUnlock(t *testing.T) {
//2.lockErc20资产
//2.lockErc20资产
//创建token
//创建token
operatorAuth
,
err
:=
ethtxs
.
PrepareAuth
(
backend
,
para
.
DeployPrivateKey
,
para
.
Operator
)
operatorAuth
,
err
:=
ethtxs
.
PrepareAuth
(
sim
,
para
.
DeployPrivateKey
,
para
.
Operator
)
symbol
_u
sdt
:=
"USDT"
symbol
U
sdt
:=
"USDT"
bridgeTokenAddr
,
_
,
bridgeTokenInstance
,
err
:=
generated
.
DeployBridgeToken
(
operatorAuth
,
backend
,
symbol_u
sdt
)
bridgeTokenAddr
,
_
,
bridgeTokenInstance
,
err
:=
generated
.
DeployBridgeToken
(
operatorAuth
,
sim
,
symbolU
sdt
)
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
err
)
sim
.
Commit
()
sim
.
Commit
()
t
.
Logf
(
"The new creaded symbol
_usdt:%s, address:%s"
,
symbol_u
sdt
,
bridgeTokenAddr
.
String
())
t
.
Logf
(
"The new creaded symbol
Usdt:%s, address:%s"
,
symbolU
sdt
,
bridgeTokenAddr
.
String
())
//创建实例
//创建实例
//为userOne铸币
//为userOne铸币
...
@@ -452,21 +448,21 @@ func TestBridgeBankUnlock(t *testing.T) {
...
@@ -452,21 +448,21 @@ func TestBridgeBankUnlock(t *testing.T) {
Context
:
ctx
,
Context
:
ctx
,
}
}
symQuery
,
err
:=
bridgeTokenInstance
.
Symbol
(
callopts
)
symQuery
,
err
:=
bridgeTokenInstance
.
Symbol
(
callopts
)
require
.
Equal
(
t
,
symQuery
,
symbol
_u
sdt
)
require
.
Equal
(
t
,
symQuery
,
symbol
U
sdt
)
t
.
Logf
(
"symQuery = %s"
,
symQuery
)
t
.
Logf
(
"symQuery = %s"
,
symQuery
)
isMiner
,
err
:=
bridgeTokenInstance
.
IsMinter
(
callopts
,
para
.
Operator
)
isMiner
,
err
:=
bridgeTokenInstance
.
IsMinter
(
callopts
,
para
.
Operator
)
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
err
)
require
.
Equal
(
t
,
isMiner
,
true
)
require
.
Equal
(
t
,
isMiner
,
true
)
operatorAuth
,
err
=
ethtxs
.
PrepareAuth
(
backend
,
para
.
DeployPrivateKey
,
para
.
Operator
)
operatorAuth
,
err
=
ethtxs
.
PrepareAuth
(
sim
,
para
.
DeployPrivateKey
,
para
.
Operator
)
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
(
backend
,
para
.
ValidatorPriKey
[
0
],
para
.
InitValidators
[
0
])
userOneAuth
,
err
=
ethtxs
.
PrepareAuth
(
sim
,
para
.
ValidatorPriKey
[
0
],
para
.
InitValidators
[
0
])
allowAmount
:=
int64
(
100
)
allowAmount
:=
int64
(
100
)
_
,
err
=
bridgeTokenInstance
.
Approve
(
userOneAuth
,
x2EthDeployInfo
.
BridgeBank
.
Address
,
big
.
NewInt
(
allowAmount
))
_
,
err
=
bridgeTokenInstance
.
Approve
(
userOneAuth
,
x2EthDeployInfo
.
BridgeBank
.
Address
,
big
.
NewInt
(
allowAmount
))
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
err
)
...
@@ -478,7 +474,7 @@ func TestBridgeBankUnlock(t *testing.T) {
...
@@ -478,7 +474,7 @@ func TestBridgeBankUnlock(t *testing.T) {
require
.
Equal
(
t
,
userOneBalance
.
Int64
(),
mintAmount
)
require
.
Equal
(
t
,
userOneBalance
.
Int64
(),
mintAmount
)
//***测试子项目:should allow users to lock ERC20 tokens
//***测试子项目:should allow users to lock ERC20 tokens
userOneAuth
,
err
=
ethtxs
.
PrepareAuth
(
backend
,
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
...
@@ -493,7 +489,7 @@ func TestBridgeBankUnlock(t *testing.T) {
...
@@ -493,7 +489,7 @@ func TestBridgeBankUnlock(t *testing.T) {
ethSym
:=
"eth"
ethSym
:=
"eth"
claimID
:=
crypto
.
Keccak256Hash
(
chain33Sender
,
ethReceiver
.
Bytes
(),
ethAddr
.
Bytes
(),
big
.
NewInt
(
newProphecyAmount
)
.
Bytes
())
claimID
:=
crypto
.
Keccak256Hash
(
chain33Sender
,
ethReceiver
.
Bytes
(),
ethAddr
.
Bytes
(),
big
.
NewInt
(
newProphecyAmount
)
.
Bytes
())
authOracle
,
err
:=
ethtxs
.
PrepareAuth
(
backend
,
para
.
ValidatorPriKey
[
0
],
para
.
InitValidators
[
0
])
authOracle
,
err
:=
ethtxs
.
PrepareAuth
(
sim
,
para
.
ValidatorPriKey
[
0
],
para
.
InitValidators
[
0
])
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
err
)
signature
,
err
:=
ethtxs
.
SignClaim4Eth
(
claimID
,
para
.
ValidatorPriKey
[
0
])
signature
,
err
:=
ethtxs
.
SignClaim4Eth
(
claimID
,
para
.
ValidatorPriKey
[
0
])
...
@@ -527,7 +523,7 @@ func TestBridgeBankUnlock(t *testing.T) {
...
@@ -527,7 +523,7 @@ func TestBridgeBankUnlock(t *testing.T) {
ethReceiver
=
para
.
InitValidators
[
2
]
ethReceiver
=
para
.
InitValidators
[
2
]
claimID
=
crypto
.
Keccak256Hash
(
chain33Sender
,
ethReceiver
.
Bytes
(),
bridgeTokenAddr
.
Bytes
(),
big
.
NewInt
(
newProphecyAmount
)
.
Bytes
())
claimID
=
crypto
.
Keccak256Hash
(
chain33Sender
,
ethReceiver
.
Bytes
(),
bridgeTokenAddr
.
Bytes
(),
big
.
NewInt
(
newProphecyAmount
)
.
Bytes
())
authOracle
,
err
=
ethtxs
.
PrepareAuth
(
backend
,
para
.
ValidatorPriKey
[
0
],
para
.
InitValidators
[
0
])
authOracle
,
err
=
ethtxs
.
PrepareAuth
(
sim
,
para
.
ValidatorPriKey
[
0
],
para
.
InitValidators
[
0
])
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
err
)
signature
,
err
=
ethtxs
.
SignClaim4Eth
(
claimID
,
para
.
ValidatorPriKey
[
0
])
signature
,
err
=
ethtxs
.
SignClaim4Eth
(
claimID
,
para
.
ValidatorPriKey
[
0
])
...
@@ -539,13 +535,14 @@ func TestBridgeBankUnlock(t *testing.T) {
...
@@ -539,13 +535,14 @@ func TestBridgeBankUnlock(t *testing.T) {
chain33Sender
,
chain33Sender
,
ethReceiver
,
ethReceiver
,
bridgeTokenAddr
,
bridgeTokenAddr
,
symbol
_u
sdt
,
symbol
U
sdt
,
big
.
NewInt
(
newProphecyAmount
),
big
.
NewInt
(
newProphecyAmount
),
claimID
,
claimID
,
signature
)
signature
)
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
err
)
userUSDTbalance
,
err
:=
bridgeTokenInstance
.
BalanceOf
(
callopts
,
ethReceiver
)
userUSDTbalance
,
err
:=
bridgeTokenInstance
.
BalanceOf
(
callopts
,
ethReceiver
)
require
.
Nil
(
t
,
err
)
t
.
Logf
(
"userEthbalance for addr:%s balance=%d"
,
ethReceiver
.
String
(),
userUSDTbalance
.
Int64
())
t
.
Logf
(
"userEthbalance for addr:%s balance=%d"
,
ethReceiver
.
String
(),
userUSDTbalance
.
Int64
())
require
.
Equal
(
t
,
userUSDTbalance
.
Int64
(),
newProphecyAmount
)
require
.
Equal
(
t
,
userUSDTbalance
.
Int64
(),
newProphecyAmount
)
}
}
...
@@ -556,8 +553,7 @@ func TestBridgeBankSecondUnlockEth(t *testing.T) {
...
@@ -556,8 +553,7 @@ 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部署相关合约
backend
,
para
:=
setup
.
PrepareTestEnv
()
sim
,
para
:=
setup
.
PrepareTestEnv
()
sim
:=
backend
.
(
*
backends
.
SimulatedBackend
)
balance
,
_
:=
sim
.
BalanceAt
(
ctx
,
para
.
Deployer
,
nil
)
balance
,
_
:=
sim
.
BalanceAt
(
ctx
,
para
.
Deployer
,
nil
)
fmt
.
Println
(
"deployer addr,"
,
para
.
Deployer
.
String
(),
"balance ="
,
balance
.
String
())
fmt
.
Println
(
"deployer addr,"
,
para
.
Deployer
.
String
(),
"balance ="
,
balance
.
String
())
...
@@ -575,7 +571,7 @@ func TestBridgeBankSecondUnlockEth(t *testing.T) {
...
@@ -575,7 +571,7 @@ func TestBridgeBankSecondUnlockEth(t *testing.T) {
fmt
.
Printf
(
"
\n
The estimated gas=%d"
,
gas
)
fmt
.
Printf
(
"
\n
The estimated gas=%d"
,
gas
)
////////////////////////////////////////////////////
////////////////////////////////////////////////////
x2EthContracts
,
x2EthDeployInfo
,
err
:=
ethtxs
.
DeployAndInit
(
backend
,
para
)
x2EthContracts
,
x2EthDeployInfo
,
err
:=
ethtxs
.
DeployAndInit
(
sim
,
para
)
if
nil
!=
err
{
if
nil
!=
err
{
t
.
Fatalf
(
"DeployAndInit failed due to:%s"
,
err
.
Error
())
t
.
Fatalf
(
"DeployAndInit failed due to:%s"
,
err
.
Error
())
}
}
...
@@ -583,8 +579,9 @@ func TestBridgeBankSecondUnlockEth(t *testing.T) {
...
@@ -583,8 +579,9 @@ func TestBridgeBankSecondUnlockEth(t *testing.T) {
//1.lockEth资产
//1.lockEth资产
ethAddr
:=
common
.
Address
{}
ethAddr
:=
common
.
Address
{}
ethToken
,
err
:=
generated
.
NewBridgeToken
(
ethAddr
,
backend
)
ethToken
,
err
:=
generated
.
NewBridgeToken
(
ethAddr
,
sim
)
userOneAuth
,
err
:=
ethtxs
.
PrepareAuth
(
backend
,
para
.
ValidatorPriKey
[
0
],
para
.
InitValidators
[
0
])
userOneAuth
,
err
:=
ethtxs
.
PrepareAuth
(
sim
,
para
.
ValidatorPriKey
[
0
],
para
.
InitValidators
[
0
])
require
.
Nil
(
t
,
err
)
userOneAuth
.
Value
=
big
.
NewInt
(
300
)
userOneAuth
.
Value
=
big
.
NewInt
(
300
)
_
,
err
=
ethToken
.
Transfer
(
userOneAuth
,
x2EthDeployInfo
.
BridgeBank
.
Address
,
userOneAuth
.
Value
)
_
,
err
=
ethToken
.
Transfer
(
userOneAuth
,
x2EthDeployInfo
.
BridgeBank
.
Address
,
userOneAuth
.
Value
)
sim
.
Commit
()
sim
.
Commit
()
...
@@ -600,12 +597,12 @@ func TestBridgeBankSecondUnlockEth(t *testing.T) {
...
@@ -600,12 +597,12 @@ func TestBridgeBankSecondUnlockEth(t *testing.T) {
//2.lockErc20资产
//2.lockErc20资产
//创建token
//创建token
operatorAuth
,
err
:=
ethtxs
.
PrepareAuth
(
backend
,
para
.
DeployPrivateKey
,
para
.
Operator
)
operatorAuth
,
err
:=
ethtxs
.
PrepareAuth
(
sim
,
para
.
DeployPrivateKey
,
para
.
Operator
)
symbol
_u
sdt
:=
"USDT"
symbol
U
sdt
:=
"USDT"
bridgeTokenAddr
,
_
,
bridgeTokenInstance
,
err
:=
generated
.
DeployBridgeToken
(
operatorAuth
,
backend
,
symbol_u
sdt
)
bridgeTokenAddr
,
_
,
bridgeTokenInstance
,
err
:=
generated
.
DeployBridgeToken
(
operatorAuth
,
sim
,
symbolU
sdt
)
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
err
)
sim
.
Commit
()
sim
.
Commit
()
t
.
Logf
(
"The new creaded symbol
_usdt:%s, address:%s"
,
symbol_u
sdt
,
bridgeTokenAddr
.
String
())
t
.
Logf
(
"The new creaded symbol
Usdt:%s, address:%s"
,
symbolU
sdt
,
bridgeTokenAddr
.
String
())
//创建实例
//创建实例
//为userOne铸币
//为userOne铸币
...
@@ -617,21 +614,21 @@ func TestBridgeBankSecondUnlockEth(t *testing.T) {
...
@@ -617,21 +614,21 @@ func TestBridgeBankSecondUnlockEth(t *testing.T) {
Context
:
ctx
,
Context
:
ctx
,
}
}
symQuery
,
err
:=
bridgeTokenInstance
.
Symbol
(
callopts
)
symQuery
,
err
:=
bridgeTokenInstance
.
Symbol
(
callopts
)
require
.
Equal
(
t
,
symQuery
,
symbol
_u
sdt
)
require
.
Equal
(
t
,
symQuery
,
symbol
U
sdt
)
t
.
Logf
(
"symQuery = %s"
,
symQuery
)
t
.
Logf
(
"symQuery = %s"
,
symQuery
)
isMiner
,
err
:=
bridgeTokenInstance
.
IsMinter
(
callopts
,
para
.
Operator
)
isMiner
,
err
:=
bridgeTokenInstance
.
IsMinter
(
callopts
,
para
.
Operator
)
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
err
)
require
.
Equal
(
t
,
isMiner
,
true
)
require
.
Equal
(
t
,
isMiner
,
true
)
operatorAuth
,
err
=
ethtxs
.
PrepareAuth
(
backend
,
para
.
DeployPrivateKey
,
para
.
Operator
)
operatorAuth
,
err
=
ethtxs
.
PrepareAuth
(
sim
,
para
.
DeployPrivateKey
,
para
.
Operator
)
require
.
Nil
(
t
,
err
)
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
(
backend
,
para
.
ValidatorPriKey
[
0
],
para
.
InitValidators
[
0
])
userOneAuth
,
err
=
ethtxs
.
PrepareAuth
(
sim
,
para
.
ValidatorPriKey
[
0
],
para
.
InitValidators
[
0
])
allowAmount
:=
int64
(
100
)
allowAmount
:=
int64
(
100
)
_
,
err
=
bridgeTokenInstance
.
Approve
(
userOneAuth
,
x2EthDeployInfo
.
BridgeBank
.
Address
,
big
.
NewInt
(
allowAmount
))
_
,
err
=
bridgeTokenInstance
.
Approve
(
userOneAuth
,
x2EthDeployInfo
.
BridgeBank
.
Address
,
big
.
NewInt
(
allowAmount
))
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
err
)
...
@@ -643,7 +640,7 @@ func TestBridgeBankSecondUnlockEth(t *testing.T) {
...
@@ -643,7 +640,7 @@ func TestBridgeBankSecondUnlockEth(t *testing.T) {
require
.
Equal
(
t
,
userOneBalance
.
Int64
(),
mintAmount
)
require
.
Equal
(
t
,
userOneBalance
.
Int64
(),
mintAmount
)
//***测试子项目:should allow users to lock ERC20 tokens
//***测试子项目:should allow users to lock ERC20 tokens
userOneAuth
,
err
=
ethtxs
.
PrepareAuth
(
backend
,
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
...
@@ -658,7 +655,7 @@ func TestBridgeBankSecondUnlockEth(t *testing.T) {
...
@@ -658,7 +655,7 @@ func TestBridgeBankSecondUnlockEth(t *testing.T) {
ethSym
:=
"eth"
ethSym
:=
"eth"
claimID
:=
crypto
.
Keccak256Hash
(
chain33Sender
,
ethReceiver
.
Bytes
(),
ethAddr
.
Bytes
(),
big
.
NewInt
(
newProphecyAmount
)
.
Bytes
())
claimID
:=
crypto
.
Keccak256Hash
(
chain33Sender
,
ethReceiver
.
Bytes
(),
ethAddr
.
Bytes
(),
big
.
NewInt
(
newProphecyAmount
)
.
Bytes
())
authOracle
,
err
:=
ethtxs
.
PrepareAuth
(
backend
,
para
.
ValidatorPriKey
[
0
],
para
.
InitValidators
[
0
])
authOracle
,
err
:=
ethtxs
.
PrepareAuth
(
sim
,
para
.
ValidatorPriKey
[
0
],
para
.
InitValidators
[
0
])
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
err
)
signature
,
err
:=
ethtxs
.
SignClaim4Eth
(
claimID
,
para
.
ValidatorPriKey
[
0
])
signature
,
err
:=
ethtxs
.
SignClaim4Eth
(
claimID
,
para
.
ValidatorPriKey
[
0
])
...
@@ -688,7 +685,7 @@ func TestBridgeBankSecondUnlockEth(t *testing.T) {
...
@@ -688,7 +685,7 @@ func TestBridgeBankSecondUnlockEth(t *testing.T) {
//第二次 newOracleClaim
//第二次 newOracleClaim
newProphecyAmountSecond
:=
int64
(
33
)
newProphecyAmountSecond
:=
int64
(
33
)
claimID
=
crypto
.
Keccak256Hash
(
chain33Sender
,
ethReceiver
.
Bytes
(),
ethAddr
.
Bytes
(),
big
.
NewInt
(
newProphecyAmountSecond
)
.
Bytes
())
claimID
=
crypto
.
Keccak256Hash
(
chain33Sender
,
ethReceiver
.
Bytes
(),
ethAddr
.
Bytes
(),
big
.
NewInt
(
newProphecyAmountSecond
)
.
Bytes
())
authOracle
,
err
=
ethtxs
.
PrepareAuth
(
backend
,
para
.
ValidatorPriKey
[
0
],
para
.
InitValidators
[
0
])
authOracle
,
err
=
ethtxs
.
PrepareAuth
(
sim
,
para
.
ValidatorPriKey
[
0
],
para
.
InitValidators
[
0
])
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
err
)
signature
,
err
=
ethtxs
.
SignClaim4Eth
(
claimID
,
para
.
ValidatorPriKey
[
0
])
signature
,
err
=
ethtxs
.
SignClaim4Eth
(
claimID
,
para
.
ValidatorPriKey
[
0
])
...
@@ -721,8 +718,7 @@ func TestBridgeBankSedondUnlockErc20(t *testing.T) {
...
@@ -721,8 +718,7 @@ 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部署相关合约
backend
,
para
:=
setup
.
PrepareTestEnv
()
sim
,
para
:=
setup
.
PrepareTestEnv
()
sim
:=
backend
.
(
*
backends
.
SimulatedBackend
)
balance
,
_
:=
sim
.
BalanceAt
(
ctx
,
para
.
Deployer
,
nil
)
balance
,
_
:=
sim
.
BalanceAt
(
ctx
,
para
.
Deployer
,
nil
)
fmt
.
Println
(
"deployer addr,"
,
para
.
Deployer
.
String
(),
"balance ="
,
balance
.
String
())
fmt
.
Println
(
"deployer addr,"
,
para
.
Deployer
.
String
(),
"balance ="
,
balance
.
String
())
...
@@ -740,14 +736,14 @@ func TestBridgeBankSedondUnlockErc20(t *testing.T) {
...
@@ -740,14 +736,14 @@ func TestBridgeBankSedondUnlockErc20(t *testing.T) {
fmt
.
Printf
(
"
\n
The estimated gas=%d"
,
gas
)
fmt
.
Printf
(
"
\n
The estimated gas=%d"
,
gas
)
////////////////////////////////////////////////////
////////////////////////////////////////////////////
x2EthContracts
,
x2EthDeployInfo
,
err
:=
ethtxs
.
DeployAndInit
(
backend
,
para
)
x2EthContracts
,
x2EthDeployInfo
,
err
:=
ethtxs
.
DeployAndInit
(
sim
,
para
)
if
nil
!=
err
{
if
nil
!=
err
{
t
.
Fatalf
(
"DeployAndInit failed due to:%s"
,
err
.
Error
())
t
.
Fatalf
(
"DeployAndInit failed due to:%s"
,
err
.
Error
())
}
}
sim
.
Commit
()
sim
.
Commit
()
//1.lockEth资产
//1.lockEth资产
userOneAuth
,
err
:=
ethtxs
.
PrepareAuth
(
backend
,
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
...
@@ -760,12 +756,12 @@ func TestBridgeBankSedondUnlockErc20(t *testing.T) {
...
@@ -760,12 +756,12 @@ func TestBridgeBankSedondUnlockErc20(t *testing.T) {
//2.lockErc20资产
//2.lockErc20资产
//创建token
//创建token
operatorAuth
,
err
:=
ethtxs
.
PrepareAuth
(
backend
,
para
.
DeployPrivateKey
,
para
.
Operator
)
operatorAuth
,
err
:=
ethtxs
.
PrepareAuth
(
sim
,
para
.
DeployPrivateKey
,
para
.
Operator
)
symbol
_u
sdt
:=
"USDT"
symbol
U
sdt
:=
"USDT"
bridgeTokenAddr
,
_
,
bridgeTokenInstance
,
err
:=
generated
.
DeployBridgeToken
(
operatorAuth
,
backend
,
symbol_u
sdt
)
bridgeTokenAddr
,
_
,
bridgeTokenInstance
,
err
:=
generated
.
DeployBridgeToken
(
operatorAuth
,
sim
,
symbolU
sdt
)
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
err
)
sim
.
Commit
()
sim
.
Commit
()
t
.
Logf
(
"The new creaded symbol
_usdt:%s, address:%s"
,
symbol_u
sdt
,
bridgeTokenAddr
.
String
())
t
.
Logf
(
"The new creaded symbol
Usdt:%s, address:%s"
,
symbolU
sdt
,
bridgeTokenAddr
.
String
())
//创建实例
//创建实例
//为userOne铸币
//为userOne铸币
...
@@ -777,19 +773,19 @@ func TestBridgeBankSedondUnlockErc20(t *testing.T) {
...
@@ -777,19 +773,19 @@ func TestBridgeBankSedondUnlockErc20(t *testing.T) {
Context
:
ctx
,
Context
:
ctx
,
}
}
symQuery
,
err
:=
bridgeTokenInstance
.
Symbol
(
callopts
)
symQuery
,
err
:=
bridgeTokenInstance
.
Symbol
(
callopts
)
require
.
Equal
(
t
,
symQuery
,
symbol
_u
sdt
)
require
.
Equal
(
t
,
symQuery
,
symbol
U
sdt
)
t
.
Logf
(
"symQuery = %s"
,
symQuery
)
t
.
Logf
(
"symQuery = %s"
,
symQuery
)
isMiner
,
err
:=
bridgeTokenInstance
.
IsMinter
(
callopts
,
para
.
Operator
)
isMiner
,
err
:=
bridgeTokenInstance
.
IsMinter
(
callopts
,
para
.
Operator
)
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
err
)
require
.
Equal
(
t
,
isMiner
,
true
)
require
.
Equal
(
t
,
isMiner
,
true
)
operatorAuth
,
err
=
ethtxs
.
PrepareAuth
(
backend
,
para
.
DeployPrivateKey
,
para
.
Operator
)
operatorAuth
,
err
=
ethtxs
.
PrepareAuth
(
sim
,
para
.
DeployPrivateKey
,
para
.
Operator
)
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
(
backend
,
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
)
_
,
err
=
bridgeTokenInstance
.
Approve
(
userOneAuth
,
x2EthDeployInfo
.
BridgeBank
.
Address
,
big
.
NewInt
(
allowAmount
))
_
,
err
=
bridgeTokenInstance
.
Approve
(
userOneAuth
,
x2EthDeployInfo
.
BridgeBank
.
Address
,
big
.
NewInt
(
allowAmount
))
...
@@ -802,7 +798,7 @@ func TestBridgeBankSedondUnlockErc20(t *testing.T) {
...
@@ -802,7 +798,7 @@ func TestBridgeBankSedondUnlockErc20(t *testing.T) {
require
.
Equal
(
t
,
userOneBalance
.
Int64
(),
mintAmount
)
require
.
Equal
(
t
,
userOneBalance
.
Int64
(),
mintAmount
)
//测试子项目:should allow users to lock ERC20 tokens
//测试子项目:should allow users to lock ERC20 tokens
userOneAuth
,
err
=
ethtxs
.
PrepareAuth
(
backend
,
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
...
@@ -817,11 +813,12 @@ func TestBridgeBankSedondUnlockErc20(t *testing.T) {
...
@@ -817,11 +813,12 @@ func TestBridgeBankSedondUnlockErc20(t *testing.T) {
claimID
:=
crypto
.
Keccak256Hash
(
chain33Sender
,
ethReceiver
.
Bytes
(),
bridgeTokenAddr
.
Bytes
(),
big
.
NewInt
(
newProphecyAmount
)
.
Bytes
())
claimID
:=
crypto
.
Keccak256Hash
(
chain33Sender
,
ethReceiver
.
Bytes
(),
bridgeTokenAddr
.
Bytes
(),
big
.
NewInt
(
newProphecyAmount
)
.
Bytes
())
userUSDTbalance0
,
err
:=
bridgeTokenInstance
.
BalanceOf
(
callopts
,
ethReceiver
)
userUSDTbalance0
,
err
:=
bridgeTokenInstance
.
BalanceOf
(
callopts
,
ethReceiver
)
require
.
Nil
(
t
,
err
)
t
.
Logf
(
"userEthbalance for addr:%s balance=%d"
,
ethReceiver
.
String
(),
userUSDTbalance0
.
Int64
())
t
.
Logf
(
"userEthbalance for addr:%s balance=%d"
,
ethReceiver
.
String
(),
userUSDTbalance0
.
Int64
())
require
.
Equal
(
t
,
userUSDTbalance0
.
Int64
(),
int64
(
0
))
require
.
Equal
(
t
,
userUSDTbalance0
.
Int64
(),
int64
(
0
))
///////////newOracleClaim///////////////////////////
///////////newOracleClaim///////////////////////////
authOracle
,
err
:=
ethtxs
.
PrepareAuth
(
backend
,
para
.
ValidatorPriKey
[
0
],
para
.
InitValidators
[
0
])
authOracle
,
err
:=
ethtxs
.
PrepareAuth
(
sim
,
para
.
ValidatorPriKey
[
0
],
para
.
InitValidators
[
0
])
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
err
)
signature
,
err
:=
ethtxs
.
SignClaim4Eth
(
claimID
,
para
.
ValidatorPriKey
[
0
])
signature
,
err
:=
ethtxs
.
SignClaim4Eth
(
claimID
,
para
.
ValidatorPriKey
[
0
])
...
@@ -832,20 +829,21 @@ func TestBridgeBankSedondUnlockErc20(t *testing.T) {
...
@@ -832,20 +829,21 @@ func TestBridgeBankSedondUnlockErc20(t *testing.T) {
chain33Sender
,
chain33Sender
,
ethReceiver
,
ethReceiver
,
bridgeTokenAddr
,
bridgeTokenAddr
,
symbol
_u
sdt
,
symbol
U
sdt
,
big
.
NewInt
(
newProphecyAmount
),
big
.
NewInt
(
newProphecyAmount
),
claimID
,
claimID
,
signature
)
signature
)
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
err
)
userUSDTbalance1
,
err
:=
bridgeTokenInstance
.
BalanceOf
(
callopts
,
ethReceiver
)
userUSDTbalance1
,
err
:=
bridgeTokenInstance
.
BalanceOf
(
callopts
,
ethReceiver
)
require
.
Nil
(
t
,
err
)
t
.
Logf
(
"userEthbalance for addr:%s balance=%d"
,
ethReceiver
.
String
(),
userUSDTbalance1
.
Int64
())
t
.
Logf
(
"userEthbalance for addr:%s balance=%d"
,
ethReceiver
.
String
(),
userUSDTbalance1
.
Int64
())
require
.
Equal
(
t
,
userUSDTbalance1
.
Int64
(),
userUSDTbalance0
.
Int64
()
+
newProphecyAmount
)
require
.
Equal
(
t
,
userUSDTbalance1
.
Int64
(),
userUSDTbalance0
.
Int64
()
+
newProphecyAmount
)
// newOracleClaim
// newOracleClaim
newProphecyAmountSecond
:=
int64
(
66
)
newProphecyAmountSecond
:=
int64
(
66
)
claimID
=
crypto
.
Keccak256Hash
(
chain33Sender
,
ethReceiver
.
Bytes
(),
bridgeTokenAddr
.
Bytes
(),
big
.
NewInt
(
newProphecyAmountSecond
)
.
Bytes
())
claimID
=
crypto
.
Keccak256Hash
(
chain33Sender
,
ethReceiver
.
Bytes
(),
bridgeTokenAddr
.
Bytes
(),
big
.
NewInt
(
newProphecyAmountSecond
)
.
Bytes
())
authOracle
,
err
=
ethtxs
.
PrepareAuth
(
backend
,
para
.
ValidatorPriKey
[
0
],
para
.
InitValidators
[
0
])
authOracle
,
err
=
ethtxs
.
PrepareAuth
(
sim
,
para
.
ValidatorPriKey
[
0
],
para
.
InitValidators
[
0
])
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
err
)
signature
,
err
=
ethtxs
.
SignClaim4Eth
(
claimID
,
para
.
ValidatorPriKey
[
0
])
signature
,
err
=
ethtxs
.
SignClaim4Eth
(
claimID
,
para
.
ValidatorPriKey
[
0
])
...
@@ -856,13 +854,14 @@ func TestBridgeBankSedondUnlockErc20(t *testing.T) {
...
@@ -856,13 +854,14 @@ func TestBridgeBankSedondUnlockErc20(t *testing.T) {
chain33Sender
,
chain33Sender
,
ethReceiver
,
ethReceiver
,
bridgeTokenAddr
,
bridgeTokenAddr
,
symbol
_u
sdt
,
symbol
U
sdt
,
big
.
NewInt
(
newProphecyAmountSecond
),
big
.
NewInt
(
newProphecyAmountSecond
),
claimID
,
claimID
,
signature
)
signature
)
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
err
)
userUSDTbalance2
,
err
:=
bridgeTokenInstance
.
BalanceOf
(
callopts
,
ethReceiver
)
userUSDTbalance2
,
err
:=
bridgeTokenInstance
.
BalanceOf
(
callopts
,
ethReceiver
)
require
.
Nil
(
t
,
err
)
t
.
Logf
(
"userEthbalance for addr:%s balance=%d"
,
ethReceiver
.
String
(),
userUSDTbalance2
.
Int64
())
t
.
Logf
(
"userEthbalance for addr:%s balance=%d"
,
ethReceiver
.
String
(),
userUSDTbalance2
.
Int64
())
require
.
Equal
(
t
,
userUSDTbalance2
.
Int64
(),
userUSDTbalance1
.
Int64
()
+
newProphecyAmountSecond
)
require
.
Equal
(
t
,
userUSDTbalance2
.
Int64
(),
userUSDTbalance1
.
Int64
()
+
newProphecyAmountSecond
)
}
}
plugin/dapp/x2ethereum/ebrelayer/ethcontract/test/setup/setupTestEnv.go
View file @
84724970
...
@@ -2,6 +2,7 @@ package setup
...
@@ -2,6 +2,7 @@ package setup
import
(
import
(
"crypto/ecdsa"
"crypto/ecdsa"
"github.com/33cn/plugin/plugin/dapp/x2ethereum/ebrelayer/ethinterface"
"math/big"
"math/big"
"github.com/33cn/plugin/plugin/dapp/x2ethereum/ebrelayer/ethtxs"
"github.com/33cn/plugin/plugin/dapp/x2ethereum/ebrelayer/ethtxs"
...
@@ -12,7 +13,7 @@ import (
...
@@ -12,7 +13,7 @@ import (
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto"
)
)
func
PrepareTestEnv
()
(
bind
.
ContractBack
end
,
*
ethtxs
.
DeployPara
)
{
func
PrepareTestEnv
()
(
*
ethinterface
.
SimExt
end
,
*
ethtxs
.
DeployPara
)
{
genesiskey
,
_
:=
crypto
.
GenerateKey
()
genesiskey
,
_
:=
crypto
.
GenerateKey
()
alloc
:=
make
(
core
.
GenesisAlloc
)
alloc
:=
make
(
core
.
GenesisAlloc
)
genesisAddr
:=
crypto
.
PubkeyToAddress
(
genesiskey
.
PublicKey
)
genesisAddr
:=
crypto
.
PubkeyToAddress
(
genesiskey
.
PublicKey
)
...
@@ -37,7 +38,8 @@ func PrepareTestEnv() (bind.ContractBackend, *ethtxs.DeployPara) {
...
@@ -37,7 +38,8 @@ func PrepareTestEnv() (bind.ContractBackend, *ethtxs.DeployPara) {
alloc
[
addr
]
=
account
alloc
[
addr
]
=
account
}
}
gasLimit
:=
uint64
(
100000000
)
gasLimit
:=
uint64
(
100000000
)
sim
:=
backends
.
NewSimulatedBackend
(
alloc
,
gasLimit
)
sim
:=
new
(
ethinterface
.
SimExtend
)
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
)}
para
:=
&
ethtxs
.
DeployPara
{
para
:=
&
ethtxs
.
DeployPara
{
...
...
plugin/dapp/x2ethereum/ebrelayer/relayer/chain33/chain33_test.go
View file @
84724970
...
@@ -18,6 +18,7 @@ import (
...
@@ -18,6 +18,7 @@ import (
"github.com/33cn/chain33/util/testnode"
"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/ethtxs"
"github.com/33cn/plugin/plugin/dapp/x2ethereum/ebrelayer/ethtxs"
syncTx
"github.com/33cn/plugin/plugin/dapp/x2ethereum/ebrelayer/relayer/chain33/transceiver/sync"
syncTx
"github.com/33cn/plugin/plugin/dapp/x2ethereum/ebrelayer/relayer/chain33/transceiver/sync"
ebTypes
"github.com/33cn/plugin/plugin/dapp/x2ethereum/ebrelayer/types"
ebTypes
"github.com/33cn/plugin/plugin/dapp/x2ethereum/ebrelayer/types"
...
@@ -47,13 +48,30 @@ var (
...
@@ -47,13 +48,30 @@ var (
type
suiteChain33Relayer
struct
{
type
suiteChain33Relayer
struct
{
suite
.
Suite
suite
.
Suite
chain33Relayer
*
Relayer4Chain33
chain33Relayer
*
Relayer4Chain33
sim
*
backends
.
SimulatedBack
end
sim
*
ethinterface
.
SimExt
end
x2EthContracts
*
ethtxs
.
X2EthContracts
x2EthContracts
*
ethtxs
.
X2EthContracts
x2EthDeployInfo
*
ethtxs
.
X2EthDeployInfo
x2EthDeployInfo
*
ethtxs
.
X2EthDeployInfo
para
*
ethtxs
.
DeployPara
para
*
ethtxs
.
DeployPara
}
}
func
TestRunSuiteX2Ethereum
(
t
*
testing
.
T
)
{
func
TestRunSuiteX2Ethereum
(
t
*
testing
.
T
)
{
var
ret
=
types
.
ReplySubscribePush
{
IsOk
:
true
}
var
he
=
types
.
Header
{
Height
:
10000
}
mockapi
:=
&
mocks
.
QueueProtocolAPI
{}
// 这里对需要mock的方法打桩,Close是必须的,其它方法根据需要
mockapi
.
On
(
"Close"
)
.
Return
()
mockapi
.
On
(
"AddPushSubscribe"
,
mock
.
Anything
)
.
Return
(
&
ret
,
nil
)
mockapi
.
On
(
"GetLastHeader"
,
mock
.
Anything
)
.
Return
(
&
he
,
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
()
log
:=
new
(
suiteChain33Relayer
)
log
:=
new
(
suiteChain33Relayer
)
suite
.
Run
(
t
,
log
)
suite
.
Run
(
t
,
log
)
}
}
...
@@ -89,7 +107,6 @@ func (r *suiteChain33Relayer) Test_2_HandleRequest() {
...
@@ -89,7 +107,6 @@ func (r *suiteChain33Relayer) Test_2_HandleRequest() {
err
=
syncTx
.
HandleRequest
(
body
)
err
=
syncTx
.
HandleRequest
(
body
)
r
.
NoError
(
err
)
r
.
NoError
(
err
)
//time.Sleep(50 * time.Second)
time
.
Sleep
(
50
*
time
.
Millisecond
)
time
.
Sleep
(
50
*
time
.
Millisecond
)
}
}
...
@@ -98,28 +115,36 @@ func (r *suiteChain33Relayer) Test_3_QueryTxhashRelay2Eth() {
...
@@ -98,28 +115,36 @@ func (r *suiteChain33Relayer) Test_3_QueryTxhashRelay2Eth() {
r
.
NotEmpty
(
ret
)
r
.
NotEmpty
(
ret
)
}
}
func
(
r
*
suiteChain33Relayer
)
Test_4_StoreAccountWithNewPassphase
()
{
func
(
r
*
suiteChain33Relayer
)
Test_4_getEthTxhash
()
{
err
:=
r
.
chain33Relayer
.
StoreAccountWithNewPassphase
(
passphrase
,
passphrase
)
r
.
NoError
(
err
)
}
func
(
r
*
suiteChain33Relayer
)
Test_5_getEthTxhash
()
{
txIndex
:=
atomic
.
LoadInt64
(
&
r
.
chain33Relayer
.
totalTx4Chain33ToEth
)
txIndex
:=
atomic
.
LoadInt64
(
&
r
.
chain33Relayer
.
totalTx4Chain33ToEth
)
hash
,
err
:=
r
.
chain33Relayer
.
getEthTxhash
(
txIndex
)
hash
,
err
:=
r
.
chain33Relayer
.
getEthTxhash
(
txIndex
)
r
.
NoError
(
err
)
r
.
NoError
(
err
)
r
.
Equal
(
hash
.
String
(),
"0x6fa087c7a2a8a4421f6e269fbc6c0838e99fa59d5760155a71cd7eb1c01aafad"
)
r
.
Equal
(
hash
.
String
(),
"0x6fa087c7a2a8a4421f6e269fbc6c0838e99fa59d5760155a71cd7eb1c01aafad"
)
}
}
func
(
r
*
suiteChain33Relayer
)
Test_7_RestorePrivateKeys
()
{
func
(
r
*
suiteChain33Relayer
)
Test_5_RestorePrivateKeys
()
{
//err := r.chain33Relayer.RestorePrivateKeys("123") // 不会报错
//r.Error(err)
go
func
()
{
go
func
()
{
time
.
Sleep
(
1
*
time
.
Millisecond
)
for
range
r
.
chain33Relayer
.
unlock
{
<-
r
.
chain33Relayer
.
unlock
}
}()
}()
err
:=
r
.
chain33Relayer
.
RestorePrivateKeys
(
passphrase
)
temp
:=
r
.
chain33Relayer
.
ethSender
err
:=
r
.
chain33Relayer
.
RestorePrivateKeys
(
"123"
)
r
.
NotEqual
(
hex
.
EncodeToString
(
temp
.
Bytes
()),
hex
.
EncodeToString
(
r
.
chain33Relayer
.
ethSender
.
Bytes
()))
r
.
NoError
(
err
)
r
.
NoError
(
err
)
err
=
r
.
chain33Relayer
.
RestorePrivateKeys
(
passphrase
)
r
.
Equal
(
hex
.
EncodeToString
(
temp
.
Bytes
()),
hex
.
EncodeToString
(
r
.
chain33Relayer
.
ethSender
.
Bytes
()))
r
.
NoError
(
err
)
err
=
r
.
chain33Relayer
.
StoreAccountWithNewPassphase
(
"new123"
,
passphrase
)
r
.
NoError
(
err
)
err
=
r
.
chain33Relayer
.
RestorePrivateKeys
(
"new123"
)
r
.
Equal
(
hex
.
EncodeToString
(
temp
.
Bytes
()),
hex
.
EncodeToString
(
r
.
chain33Relayer
.
ethSender
.
Bytes
()))
r
.
NoError
(
err
)
time
.
Sleep
(
time
.
Second
)
}
}
func
(
r
*
suiteChain33Relayer
)
newChain33Relayer
()
*
Relayer4Chain33
{
func
(
r
*
suiteChain33Relayer
)
newChain33Relayer
()
*
Relayer4Chain33
{
...
@@ -139,12 +164,12 @@ func (r *suiteChain33Relayer) newChain33Relayer() *Relayer4Chain33 {
...
@@ -139,12 +164,12 @@ func (r *suiteChain33Relayer) newChain33Relayer() *Relayer4Chain33 {
unlock
:
make
(
chan
int
),
unlock
:
make
(
chan
int
),
db
:
db
,
db
:
db
,
ctx
:
ctx
,
ctx
:
ctx
,
bridgeRegistryAddr
:
r
.
x2EthDeployInfo
.
BridgeRegistry
.
Address
,
}
}
err
:=
relayer
.
setStatusCheckedIndex
(
1
)
err
:=
relayer
.
setStatusCheckedIndex
(
1
)
r
.
NoError
(
err
)
r
.
NoError
(
err
)
relayer
.
ethBackend
=
r
.
sim
relayer
.
ethClient
=
r
.
sim
relayer
.
bridgeRegistryAddr
=
r
.
para
.
Deployer
relayer
.
totalTx4Chain33ToEth
=
relayer
.
getTotalTxAmount2Eth
()
relayer
.
totalTx4Chain33ToEth
=
relayer
.
getTotalTxAmount2Eth
()
relayer
.
statusCheckedIndex
=
relayer
.
getStatusCheckedIndex
()
relayer
.
statusCheckedIndex
=
relayer
.
getStatusCheckedIndex
()
r
.
Equal
(
relayer
.
statusCheckedIndex
,
int64
(
1
))
r
.
Equal
(
relayer
.
statusCheckedIndex
,
int64
(
1
))
...
@@ -158,8 +183,7 @@ func (r *suiteChain33Relayer) newChain33Relayer() *Relayer4Chain33 {
...
@@ -158,8 +183,7 @@ func (r *suiteChain33Relayer) newChain33Relayer() *Relayer4Chain33 {
StartSyncSequence
:
cfg
.
SyncTxConfig
.
StartSyncSequence
,
StartSyncSequence
:
cfg
.
SyncTxConfig
.
StartSyncSequence
,
StartSyncHash
:
cfg
.
SyncTxConfig
.
StartSyncHash
,
StartSyncHash
:
cfg
.
SyncTxConfig
.
StartSyncHash
,
}
}
_
=
syncCfg
go
relayer
.
syncProc
(
syncCfg
)
go
r
.
syncProc
(
syncCfg
)
var
wg
sync
.
WaitGroup
var
wg
sync
.
WaitGroup
ch
:=
make
(
chan
os
.
Signal
,
1
)
ch
:=
make
(
chan
os
.
Signal
,
1
)
...
@@ -191,7 +215,8 @@ func (r *suiteChain33Relayer) deployContracts() {
...
@@ -191,7 +215,8 @@ func (r *suiteChain33Relayer) deployContracts() {
ctx
:=
context
.
Background
()
ctx
:=
context
.
Background
()
var
backend
bind
.
ContractBackend
var
backend
bind
.
ContractBackend
backend
,
r
.
para
=
setup
.
PrepareTestEnvironment
(
deployerPrivateKey
,
ethValidatorAddrKeys
)
backend
,
r
.
para
=
setup
.
PrepareTestEnvironment
(
deployerPrivateKey
,
ethValidatorAddrKeys
)
r
.
sim
=
backend
.
(
*
backends
.
SimulatedBackend
)
r
.
sim
=
new
(
ethinterface
.
SimExtend
)
r
.
sim
.
SimulatedBackend
=
backend
.
(
*
backends
.
SimulatedBackend
)
balance
,
_
:=
r
.
sim
.
BalanceAt
(
ctx
,
r
.
para
.
Deployer
,
nil
)
balance
,
_
:=
r
.
sim
.
BalanceAt
(
ctx
,
r
.
para
.
Deployer
,
nil
)
fmt
.
Println
(
"deployer addr,"
,
r
.
para
.
Deployer
.
String
(),
"balance ="
,
balance
.
String
())
fmt
.
Println
(
"deployer addr,"
,
r
.
para
.
Deployer
.
String
(),
"balance ="
,
balance
.
String
())
...
@@ -207,52 +232,11 @@ func (r *suiteChain33Relayer) deployContracts() {
...
@@ -207,52 +232,11 @@ func (r *suiteChain33Relayer) deployContracts() {
fmt
.
Printf
(
"
\n
The estimated gas=%d
\n
"
,
gas
)
fmt
.
Printf
(
"
\n
The estimated gas=%d
\n
"
,
gas
)
////////////////////////////////////////////////////
////////////////////////////////////////////////////
r
.
x2EthContracts
,
r
.
x2EthDeployInfo
,
err
=
ethtxs
.
DeployAndInit
(
backend
,
r
.
para
)
r
.
x2EthContracts
,
r
.
x2EthDeployInfo
,
err
=
ethtxs
.
DeployAndInit
(
r
.
sim
,
r
.
para
)
r
.
NoError
(
err
)
r
.
NoError
(
err
)
r
.
sim
.
Commit
()
r
.
sim
.
Commit
()
}
}
func
(
r
*
suiteChain33Relayer
)
syncProc
(
syncCfg
*
ebTypes
.
SyncTxReceiptConfig
)
{
var
ret
=
types
.
ReplySubscribePush
{
IsOk
:
true
}
var
he
=
types
.
Header
{
Height
:
10000
}
mockapi
:=
&
mocks
.
QueueProtocolAPI
{}
// 这里对需要mock的方法打桩,Close是必须的,其它方法根据需要
mockapi
.
On
(
"Close"
)
.
Return
()
mockapi
.
On
(
"AddPushSubscribe"
,
mock
.
Anything
)
.
Return
(
&
ret
,
nil
)
mockapi
.
On
(
"GetLastHeader"
,
mock
.
Anything
)
.
Return
(
&
he
,
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
()
fmt
.
Println
(
"Pls unlock or import private key for Chain33 relayer"
)
<-
r
.
chain33Relayer
.
unlock
fmt
.
Println
(
"Chain33 relayer starts to run..."
)
r
.
chain33Relayer
.
syncTxReceipts
=
syncTx
.
StartSyncTxReceipt
(
syncCfg
,
r
.
chain33Relayer
.
db
)
r
.
chain33Relayer
.
lastHeight4Tx
=
r
.
chain33Relayer
.
loadLastSyncHeight
()
r
.
chain33Relayer
.
oracleInstance
=
r
.
x2EthContracts
.
Oracle
timer
:=
time
.
NewTicker
(
time
.
Duration
(
r
.
chain33Relayer
.
fetchHeightPeriodMs
)
*
time
.
Millisecond
)
for
{
select
{
case
<-
timer
.
C
:
height
:=
r
.
chain33Relayer
.
getCurrentHeight
()
relayerLog
.
Debug
(
"syncProc"
,
"getCurrentHeight"
,
height
)
r
.
chain33Relayer
.
onNewHeightProc
(
height
)
case
<-
r
.
chain33Relayer
.
ctx
.
Done
()
:
timer
.
Stop
()
return
}
}
}
func
initCfg
(
path
string
)
*
relayerTypes
.
RelayerConfig
{
func
initCfg
(
path
string
)
*
relayerTypes
.
RelayerConfig
{
var
cfg
relayerTypes
.
RelayerConfig
var
cfg
relayerTypes
.
RelayerConfig
if
_
,
err
:=
tml
.
DecodeFile
(
path
,
&
cfg
);
err
!=
nil
{
if
_
,
err
:=
tml
.
DecodeFile
(
path
,
&
cfg
);
err
!=
nil
{
...
...
plugin/dapp/x2ethereum/ebrelayer/relayer/ethereum/ethereum_test.go
View file @
84724970
...
@@ -116,6 +116,9 @@ func Test_ShowAddr(t *testing.T) {
...
@@ -116,6 +116,9 @@ func Test_ShowAddr(t *testing.T) {
addr
,
err
=
ethRelayer
.
ShowOperator
()
addr
,
err
=
ethRelayer
.
ShowOperator
()
assert
.
NoError
(
t
,
err
)
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
addr
,
para
.
Operator
.
String
())
assert
.
Equal
(
t
,
addr
,
para
.
Operator
.
String
())
_
,
err
=
ethRelayer
.
DeployContrcts
()
require
.
Error
(
t
,
err
)
}
}
func
Test_CreateBridgeToken
(
t
*
testing
.
T
)
{
func
Test_CreateBridgeToken
(
t
*
testing
.
T
)
{
...
...
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