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
e50e04e7
Commit
e50e04e7
authored
Jun 08, 2020
by
whisker
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'x2eth_200507' of
https://github.com/zhengjunhe/plugin
into x2eth_200507
parents
69d83df8
5b0092b7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
103 additions
and
22 deletions
+103
-22
ethtxs_test.go
plugin/dapp/x2ethereum/ebrelayer/ethtxs/ethtxs_test.go
+55
-0
registry.go
plugin/dapp/x2ethereum/ebrelayer/ethtxs/registry.go
+1
-1
ethereumEvents.go
plugin/dapp/x2ethereum/ebrelayer/events/ethereumEvents.go
+3
-3
chain33.go
plugin/dapp/x2ethereum/ebrelayer/relayer/chain33/chain33.go
+2
-0
chain33_test.go
...dapp/x2ethereum/ebrelayer/relayer/chain33/chain33_test.go
+0
-0
sync_tx_receipts.go
...ayer/relayer/chain33/transceiver/sync/sync_tx_receipts.go
+3
-3
ethereum_test.go
...pp/x2ethereum/ebrelayer/relayer/ethereum/ethereum_test.go
+39
-15
No files found.
plugin/dapp/x2ethereum/ebrelayer/ethtxs/ethtxs_test.go
0 → 100644
View file @
e50e04e7
package
ethtxs
import
(
"math/big"
"testing"
"github.com/33cn/plugin/plugin/dapp/x2ethereum/ebrelayer/ethinterface"
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/crypto"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func
Test_LoadABI
(
t
*
testing
.
T
)
{
abi1
:=
LoadABI
(
Chain33BankABI
)
abi2
:=
LoadABI
(
Chain33BridgeABI
)
abi3
:=
LoadABI
(
EthereumBankABI
)
assert
.
NotEmpty
(
t
,
abi1
,
abi2
,
abi3
)
}
func
Test_isWebsocketURL
(
t
*
testing
.
T
)
{
bret
:=
isWebsocketURL
(
"ws://127.0.0.1:7545/"
)
assert
.
Equal
(
t
,
bret
,
true
)
bret
=
isWebsocketURL
(
"https://127.0.0.1:7545/"
)
assert
.
Equal
(
t
,
bret
,
false
)
}
func
TestContractRegistry_String
(
t
*
testing
.
T
)
{
assert
.
Equal
(
t
,
Valset
.
String
(),
"valset"
)
assert
.
Equal
(
t
,
Oracle
.
String
(),
"oracle"
)
assert
.
Equal
(
t
,
BridgeBank
.
String
(),
"bridgebank"
)
assert
.
Equal
(
t
,
Chain33Bridge
.
String
(),
"chain33bridge"
)
}
func
Test_GetAddressFromBridgeRegistry
(
t
*
testing
.
T
)
{
genesiskey
,
_
:=
crypto
.
GenerateKey
()
alloc
:=
make
(
core
.
GenesisAlloc
)
genesisAddr
:=
crypto
.
PubkeyToAddress
(
genesiskey
.
PublicKey
)
genesisAccount
:=
core
.
GenesisAccount
{
Balance
:
big
.
NewInt
(
10000000000
*
10000
),
PrivateKey
:
crypto
.
FromECDSA
(
genesiskey
),
}
alloc
[
genesisAddr
]
=
genesisAccount
gasLimit
:=
uint64
(
100000000
)
sim
:=
new
(
ethinterface
.
SimExtend
)
sim
.
SimulatedBackend
=
backends
.
NewSimulatedBackend
(
alloc
,
gasLimit
)
var
bridgebankTest
ContractRegistry
bridgebankTest
=
5
_
,
err
:=
GetAddressFromBridgeRegistry
(
sim
,
genesisAddr
,
genesisAddr
,
bridgebankTest
)
require
.
NotNil
(
t
,
err
)
}
plugin/dapp/x2ethereum/ebrelayer/ethtxs/registry.go
View file @
e50e04e7
...
...
@@ -27,7 +27,7 @@ const (
// String : returns the event type as a string
func
(
d
ContractRegistry
)
String
()
string
{
return
[
...
]
string
{
"valset"
,
"oracle"
,
"bridgebank"
,
"chain33bridge"
}[
d
-
1
]
return
[
...
]
string
{
"valset"
,
"oracle"
,
"bridgebank"
,
"chain33bridge"
,
"notsupport"
}[
d
-
1
]
}
// GetAddressFromBridgeRegistry : utility method which queries the requested contract address from the BridgeRegistry
...
...
plugin/dapp/x2ethereum/ebrelayer/events/ethereumEvents.go
View file @
e50e04e7
...
...
@@ -14,9 +14,9 @@ func NewEventWrite(txHash string, event LockEvent) {
}
// IsEventRecorded : checks the sessions stored events for this transaction hash
func
IsEventRecorded
(
txHash
string
)
bool
{
return
EventRecords
[
txHash
]
.
Nonce
!=
nil
}
//
func IsEventRecorded(txHash string) bool {
//
return EventRecords[txHash].Nonce != nil
//
}
//// PrintLockEventByTx : prints any witnessed events associated with a given transaction hash
//func PrintLockEventByTx(txHash string) {
...
...
plugin/dapp/x2ethereum/ebrelayer/relayer/chain33/chain33.go
View file @
e50e04e7
...
...
@@ -128,6 +128,7 @@ func (chain33Relayer *Relayer4Chain33) getCurrentHeight() int64 {
func
(
chain33Relayer
*
Relayer4Chain33
)
onNewHeightProc
(
currentHeight
int64
)
{
//检查已经提交的交易结果
chain33Relayer
.
rwLock
.
Lock
()
for
chain33Relayer
.
statusCheckedIndex
<
chain33Relayer
.
totalTx4Chain33ToEth
{
index
:=
chain33Relayer
.
statusCheckedIndex
+
1
txhash
,
err
:=
chain33Relayer
.
getEthTxhash
(
index
)
...
...
@@ -145,6 +146,7 @@ func (chain33Relayer *Relayer4Chain33) onNewHeightProc(currentHeight int64) {
atomic
.
AddInt64
(
&
chain33Relayer
.
statusCheckedIndex
,
1
)
_
=
chain33Relayer
.
setStatusCheckedIndex
(
chain33Relayer
.
statusCheckedIndex
)
}
chain33Relayer
.
rwLock
.
Unlock
()
//未达到足够的成熟度,不进行处理
// +++++++++||++++++++++++||++++++++++||
// ^ ^ ^
...
...
plugin/dapp/x2ethereum/ebrelayer/relayer/chain33/chain33_test.go
View file @
e50e04e7
This diff is collapsed.
Click to expand it.
plugin/dapp/x2ethereum/ebrelayer/relayer/chain33/transceiver/sync/sync_tx_receipts.go
View file @
e50e04e7
...
...
@@ -36,9 +36,9 @@ func StartSyncTxReceipt(cfg *relayerTypes.SyncTxReceiptConfig, db dbm.DB) *TxRec
return
syncTxReceipts
}
func
StopSyncTxReceipt
()
{
syncTxReceipts
.
Stop
()
}
//
func StopSyncTxReceipt() {
//
syncTxReceipts.Stop()
//
}
func
startHTTPService
(
url
string
,
clientHost
string
)
{
listen
,
err
:=
net
.
Listen
(
"tcp"
,
url
)
...
...
plugin/dapp/x2ethereum/ebrelayer/relayer/ethereum/ethereum_test.go
View file @
e50e04e7
...
...
@@ -4,7 +4,6 @@ import (
"context"
"encoding/hex"
"flag"
"fmt"
"math/big"
"os"
"testing"
...
...
@@ -132,9 +131,36 @@ func Test_ShowAddr(t *testing.T) {
require
.
Nil
(
t
,
err
)
assert
.
Equal
(
t
,
addr
,
para
.
Operator
.
String
())
_
,
err
=
ethRelayer
.
DeployContrcts
()
require
.
Error
(
t
,
err
)
}
func
Test_DeployContrcts
(
t
*
testing
.
T
)
{
_
,
sim
,
_
,
_
:=
deployContracts
()
cfg
:=
initCfg
(
*
configPath
)
cfg
.
SyncTxConfig
.
Dbdriver
=
"memdb"
db
:=
dbm
.
NewDB
(
"relayer_db_service"
,
cfg
.
SyncTxConfig
.
Dbdriver
,
cfg
.
SyncTxConfig
.
DbPath
,
cfg
.
SyncTxConfig
.
DbCache
)
relayer
:=
&
Relayer4Ethereum
{
provider
:
cfg
.
EthProvider
,
db
:
db
,
unlockchan
:
make
(
chan
int
,
2
),
rpcURL2Chain33
:
cfg
.
SyncTxConfig
.
Chain33Host
,
maturityDegree
:
cfg
.
EthMaturityDegree
,
fetchHeightPeriodMs
:
cfg
.
EthBlockFetchPeriod
,
deployInfo
:
cfg
.
Deploy
,
}
relayer
.
clientSpec
=
sim
relayer
.
clientChainID
=
big
.
NewInt
(
1
)
deployPrivateKey
,
_
:=
crypto
.
ToECDSA
(
common
.
FromHex
(
relayer
.
deployInfo
.
DeployerPrivateKey
))
deployerAddr
:=
crypto
.
PubkeyToAddress
(
deployPrivateKey
.
PublicKey
)
relayer
.
operatorInfo
=
&
ethtxs
.
OperatorInfo
{
PrivateKey
:
deployPrivateKey
,
Address
:
deployerAddr
,
}
_
,
err
:=
relayer
.
DeployContrcts
()
require
.
NoError
(
t
,
err
)
}
func
Test_SetBridgeRegistryAddr
(
t
*
testing
.
T
)
{
...
...
@@ -242,7 +268,8 @@ func Test_LockEth(t *testing.T) {
}
func
Test_CreateERC20Token
(
t
*
testing
.
T
)
{
para
,
sim
,
x2EthContracts
,
x2EthDeployInfo
:=
deployContracts
()
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
)
...
...
@@ -408,16 +435,6 @@ func Test_BurnBty(t *testing.T) {
require
.
NoError
(
t
,
err
)
sim
.
Commit
()
time
.
Sleep
(
time
.
Second
*
2
)
fetchCnt
:=
int32
(
10
)
logs
,
err
:=
ethRelayer
.
getNextValidEthTxEventLogs
(
ethRelayer
.
eventLogIndex
.
Height
,
ethRelayer
.
eventLogIndex
.
Index
,
fetchCnt
)
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"
)
...
...
@@ -434,8 +451,15 @@ func Test_BurnBty(t *testing.T) {
require
.
Nil
(
t
,
err
)
require
.
Equal
(
t
,
balanceNew
,
"80"
)
fetchCnt
:=
int32
(
10
)
logs
,
err
:=
ethRelayer
.
getNextValidEthTxEventLogs
(
ethRelayer
.
eventLogIndex
.
Height
,
ethRelayer
.
eventLogIndex
.
Index
,
fetchCnt
)
require
.
NoError
(
t
,
err
)
for
_
,
vLog
:=
range
logs
{
ethRelayer
.
procBridgeBankLogs
(
*
vLog
)
}
time
.
Sleep
(
time
.
Second
)
fmt
.
Println
(
"---------------------- end ----------------------"
)
}
func
Test_RestorePrivateKeys
(
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