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
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
85 additions
and
186 deletions
+85
-186
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
+0
-0
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
This diff is collapsed.
Click to expand it.
plugin/dapp/x2ethereum/ebrelayer/ethcontract/test/setup/setupTestEnv.go
View file @
62bf6d3d
package
setup
import
(
"context"
"crypto/ecdsa"
"github.com/ethereum/go-ethereum"
"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/ethtxs"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
...
...
@@ -26,7 +28,7 @@ func PrepareTestEnv() (*ethinterface.SimExtend, *ethtxs.DeployPara) {
var
InitValidators
[]
common
.
Address
var
ValidatorPriKey
[]
*
ecdsa
.
PrivateKey
for
i
:=
0
;
i
<
3
;
i
++
{
for
i
:=
0
;
i
<
4
;
i
++
{
key
,
_
:=
crypto
.
GenerateKey
()
addr
:=
crypto
.
PubkeyToAddress
(
key
.
PublicKey
)
InitValidators
=
append
(
InitValidators
,
addr
)
...
...
@@ -42,7 +44,7 @@ func PrepareTestEnv() (*ethinterface.SimExtend, *ethtxs.DeployPara) {
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
)
,
big
.
NewInt
(
10
)
}
para
:=
&
ethtxs
.
DeployPara
{
DeployPrivateKey
:
genesiskey
,
Deployer
:
genesisAddr
,
...
...
@@ -96,3 +98,25 @@ func PrepareTestEnvironment(deployerPrivateKey string, ethValidatorAddrKeys []st
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
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
)
x2EthContracts
:=
&
X2EthContracts
{
BridgeRegistry
:
registryInstance
,
BridgeBank
:
bridgeBank
,
Chain33Bridge
:
chain33Bridge
,
Oracle
:
oracle
,
Valset
:
valset
,
}
x2EthDeployInfo
:=
&
X2EthDeployInfo
{
...
...
@@ -49,6 +59,7 @@ func RecoverContractHandler(client ethinterface.EthClientSpec, sender, registry
BridgeBank
:
&
DeployResult
{
Address
:
*
bridgeBankAddr
},
Chain33Bridge
:
&
DeployResult
{
Address
:
*
chain33BridgeAddr
},
Oracle
:
&
DeployResult
{
Address
:
*
oracleAddr
},
Valset
:
&
DeployResult
{
Address
:
*
valsetAddr
},
}
return
x2EthContracts
,
x2EthDeployInfo
,
nil
...
...
plugin/dapp/x2ethereum/ebrelayer/relayer/ethereum/ethereum_test.go
View file @
62bf6d3d
This diff is collapsed.
Click to expand it.
plugin/dapp/x2ethereum/executor/exec_test.go
View file @
62bf6d3d
package
executor
import
(
"fmt"
"strconv"
//"github.com/33cn/chain33/client"
"testing"
...
...
@@ -190,10 +192,11 @@ func (x *suiteX2Ethereum) Test_4_Eth2Chain33() {
x
.
setDb
(
receipt
)
_
,
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
)
x
.
query_GetSymbolTotalAmountByTxType
(
symbol
,
1
,
"lock"
,
10
)
ID
:=
strconv
.
Itoa
(
0
)
+
strconv
.
Itoa
(
0
)
+
ethereumAddr
+
tokenContractAddress
+
"lock"
x
.
queryGetEthProphecy
(
ID
,
types2
.
EthBridgeStatus_SuccessStatusText
)
x
.
queryGetSymbolTotalAmountByTxType
(
1
,
symbol
,
"lock"
,
"10"
)
payload1
:=
&
types2
.
Chain33ToEth
{
TokenContract
:
tokenContractAddress
,
...
...
@@ -217,9 +220,9 @@ func (x *suiteX2Ethereum) Test_4_Eth2Chain33() {
x
.
NoError
(
err
)
x
.
setDb
(
receipt
)
x
.
query
_
GetEthProphecy
(
"010x7B95B6EC7EbD73572298cEf32Bb54FA408207359"
,
types2
.
EthBridgeStatus_SuccessStatusText
)
x
.
query
_
GetSymbolTotalAmount
(
symbol
,
1
,
7
)
x
.
query
_GetSymbolTotalAmountByTxType
(
symbol
,
1
,
"withdraw"
,
3
)
x
.
queryGetEthProphecy
(
"010x7B95B6EC7EbD73572298cEf32Bb54FA408207359"
,
types2
.
EthBridgeStatus_SuccessStatusText
)
x
.
queryGetSymbolTotalAmount
(
symbol
,
1
,
7
)
x
.
query
GetSymbolTotalAmountByTxType
(
1
,
symbol
,
"withdraw"
,
"3"
)
//payload.Amount = "10"
//payload.Nonce = 2
...
...
@@ -242,8 +245,8 @@ func (x *suiteX2Ethereum) Test_4_Eth2Chain33() {
x
.
NoError
(
err
)
x
.
setDb
(
receipt
)
x
.
query
_
GetEthProphecy
(
"030x7B95B6EC7EbD73572298cEf32Bb54FA408207359"
,
types2
.
EthBridgeStatus_SuccessStatusText
)
x
.
query
_GetSymbolTotalAmountByTxType
(
symbol
,
1
,
"lock"
,
11
)
x
.
queryGetEthProphecy
(
"030x7B95B6EC7EbD73572298cEf32Bb54FA408207359"
,
types2
.
EthBridgeStatus_SuccessStatusText
)
x
.
query
GetSymbolTotalAmountByTxType
(
1
,
symbol
,
"lock"
,
"11"
)
}
func
(
x
*
suiteX2Ethereum
)
Test_5_Chain33ToEth
()
{
...
...
@@ -259,16 +262,16 @@ func (x *suiteX2Ethereum) Test_5_Chain33ToEth() {
x
.
NoError
(
err
)
x
.
setDb
(
receipt
)
x
.
query
_
GetSymbolTotalAmount
(
"bty"
,
2
,
5
)
x
.
query
_GetSymbolTotalAmountByTxType
(
"bty"
,
2
,
"lock"
,
5
)
x
.
queryGetSymbolTotalAmount
(
"bty"
,
2
,
5
)
x
.
query
GetSymbolTotalAmountByTxType
(
2
,
"bty"
,
"lock"
,
"5"
)
//msgLock.Amount = "4"
//receipt, err = x.action.procEth2Chain33_burn(msgLock)
//x.NoError(err)
//x.setDb(receipt)
//
//x.query
_
GetSymbolTotalAmount("bty", 2, 1)
//x.query
_
GetSymbolTotalAmountByTxType("bty", 2, "withdraw", 4)
//x.queryGetSymbolTotalAmount("bty", 2, 1)
//x.queryGetSymbolTotalAmountByTxType("bty", 2, "withdraw", 4)
//
//receipt, err = x.action.procEth2Chain33_burn(msgLock)
//x.Equal(err, types.ErrNoBalance)
...
...
@@ -278,8 +281,8 @@ func (x *suiteX2Ethereum) Test_5_Chain33ToEth() {
//x.NoError(err)
//x.setDb(receipt)
x
.
query
_
GetSymbolTotalAmount
(
"bty"
,
2
,
0
)
x
.
query
_GetSymbolTotalAmountByTxType
(
"bty"
,
2
,
"withdraw"
,
5
)
x
.
queryGetSymbolTotalAmount
(
"bty"
,
2
,
0
)
x
.
query
GetSymbolTotalAmountByTxType
(
2
,
"bty"
,
"withdraw"
,
"5"
)
}
func
(
x
*
suiteX2Ethereum
)
accountSetup
()
{
...
...
@@ -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
{
TokenSymbol
:
tokenSymbol
,
Direction
:
direction
,
...
...
@@ -332,18 +335,20 @@ func (x *suiteX2Ethereum) query_GetSymbolTotalAmountByTxType(tokenSymbol string,
msg
,
err
:=
x
.
x2eth
.
Query_GetSymbolTotalAmountByTxType
(
params
)
x
.
NoError
(
err
)
symbolAmount
:=
msg
.
(
*
types2
.
ReceiptQuerySymbolAssetsByTxType
)
x
.
Equal
(
symbolAmount
.
TotalAmount
,
uint64
(
equal
))
fmt
.
Println
(
"***"
,
msg
,
err
)
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
})
x
.
NoError
(
err
)
reply
:=
msg
.
(
*
types2
.
ReceiptQuerySymbolAssets
)
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
})
x
.
NoError
(
err
)
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
if
err
!=
nil
{
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
{
return
nil
,
err
}
...
...
plugin/dapp/x2ethereum/executor/x2ethereumdb.go
View file @
62bf6d3d
...
...
@@ -75,7 +75,7 @@ func (o *Oracle) ProcessSuccessfulClaimForBurn(claim, execAddr, tokenSymbol stri
}
// 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
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