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
9e27e744
Commit
9e27e744
authored
Jun 08, 2020
by
QM
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
uodata relayer unit test
parent
59458523
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
72 additions
and
19 deletions
+72
-19
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
+8
-12
No files found.
plugin/dapp/x2ethereum/ebrelayer/ethtxs/ethtxs_test.go
0 → 100644
View file @
9e27e744
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 @
9e27e744
...
@@ -27,7 +27,7 @@ const (
...
@@ -27,7 +27,7 @@ const (
// String : returns the event type as a string
// String : returns the event type as a string
func
(
d
ContractRegistry
)
String
()
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
// GetAddressFromBridgeRegistry : utility method which queries the requested contract address from the BridgeRegistry
...
...
plugin/dapp/x2ethereum/ebrelayer/events/ethereumEvents.go
View file @
9e27e744
...
@@ -14,9 +14,9 @@ func NewEventWrite(txHash string, event LockEvent) {
...
@@ -14,9 +14,9 @@ func NewEventWrite(txHash string, event LockEvent) {
}
}
// IsEventRecorded : checks the sessions stored events for this transaction hash
// IsEventRecorded : checks the sessions stored events for this transaction hash
func
IsEventRecorded
(
txHash
string
)
bool
{
//
func IsEventRecorded(txHash string) bool {
return
EventRecords
[
txHash
]
.
Nonce
!=
nil
//
return EventRecords[txHash].Nonce != nil
}
//
}
//// PrintLockEventByTx : prints any witnessed events associated with a given transaction hash
//// PrintLockEventByTx : prints any witnessed events associated with a given transaction hash
//func PrintLockEventByTx(txHash string) {
//func PrintLockEventByTx(txHash string) {
...
...
plugin/dapp/x2ethereum/ebrelayer/relayer/chain33/chain33.go
View file @
9e27e744
...
@@ -128,6 +128,7 @@ func (chain33Relayer *Relayer4Chain33) getCurrentHeight() int64 {
...
@@ -128,6 +128,7 @@ func (chain33Relayer *Relayer4Chain33) getCurrentHeight() int64 {
func
(
chain33Relayer
*
Relayer4Chain33
)
onNewHeightProc
(
currentHeight
int64
)
{
func
(
chain33Relayer
*
Relayer4Chain33
)
onNewHeightProc
(
currentHeight
int64
)
{
//检查已经提交的交易结果
//检查已经提交的交易结果
chain33Relayer
.
rwLock
.
Lock
()
for
chain33Relayer
.
statusCheckedIndex
<
chain33Relayer
.
totalTx4Chain33ToEth
{
for
chain33Relayer
.
statusCheckedIndex
<
chain33Relayer
.
totalTx4Chain33ToEth
{
index
:=
chain33Relayer
.
statusCheckedIndex
+
1
index
:=
chain33Relayer
.
statusCheckedIndex
+
1
txhash
,
err
:=
chain33Relayer
.
getEthTxhash
(
index
)
txhash
,
err
:=
chain33Relayer
.
getEthTxhash
(
index
)
...
@@ -145,6 +146,7 @@ func (chain33Relayer *Relayer4Chain33) onNewHeightProc(currentHeight int64) {
...
@@ -145,6 +146,7 @@ func (chain33Relayer *Relayer4Chain33) onNewHeightProc(currentHeight int64) {
atomic
.
AddInt64
(
&
chain33Relayer
.
statusCheckedIndex
,
1
)
atomic
.
AddInt64
(
&
chain33Relayer
.
statusCheckedIndex
,
1
)
_
=
chain33Relayer
.
setStatusCheckedIndex
(
chain33Relayer
.
statusCheckedIndex
)
_
=
chain33Relayer
.
setStatusCheckedIndex
(
chain33Relayer
.
statusCheckedIndex
)
}
}
chain33Relayer
.
rwLock
.
Unlock
()
//未达到足够的成熟度,不进行处理
//未达到足够的成熟度,不进行处理
// +++++++++||++++++++++++||++++++++++||
// +++++++++||++++++++++++||++++++++++||
// ^ ^ ^
// ^ ^ ^
...
...
plugin/dapp/x2ethereum/ebrelayer/relayer/chain33/chain33_test.go
View file @
9e27e744
This diff is collapsed.
Click to expand it.
plugin/dapp/x2ethereum/ebrelayer/relayer/chain33/transceiver/sync/sync_tx_receipts.go
View file @
9e27e744
...
@@ -36,9 +36,9 @@ func StartSyncTxReceipt(cfg *relayerTypes.SyncTxReceiptConfig, db dbm.DB) *TxRec
...
@@ -36,9 +36,9 @@ func StartSyncTxReceipt(cfg *relayerTypes.SyncTxReceiptConfig, db dbm.DB) *TxRec
return
syncTxReceipts
return
syncTxReceipts
}
}
func
StopSyncTxReceipt
()
{
//
func StopSyncTxReceipt() {
syncTxReceipts
.
Stop
()
//
syncTxReceipts.Stop()
}
//
}
func
startHTTPService
(
url
string
,
clientHost
string
)
{
func
startHTTPService
(
url
string
,
clientHost
string
)
{
listen
,
err
:=
net
.
Listen
(
"tcp"
,
url
)
listen
,
err
:=
net
.
Listen
(
"tcp"
,
url
)
...
...
plugin/dapp/x2ethereum/ebrelayer/relayer/ethereum/ethereum_test.go
View file @
9e27e744
...
@@ -4,7 +4,6 @@ import (
...
@@ -4,7 +4,6 @@ import (
"context"
"context"
"encoding/hex"
"encoding/hex"
"flag"
"flag"
"fmt"
"math/big"
"math/big"
"os"
"os"
"testing"
"testing"
...
@@ -436,16 +435,6 @@ func Test_BurnBty(t *testing.T) {
...
@@ -436,16 +435,6 @@ func Test_BurnBty(t *testing.T) {
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
err
)
sim
.
Commit
()
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
())
balanceNew
,
err
=
ethRelayer
.
GetBalance
(
tokenAddrbty
,
ethReceiver
.
String
())
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
err
)
require
.
Equal
(
t
,
balanceNew
,
"90"
)
require
.
Equal
(
t
,
balanceNew
,
"90"
)
...
@@ -462,8 +451,15 @@ func Test_BurnBty(t *testing.T) {
...
@@ -462,8 +451,15 @@ func Test_BurnBty(t *testing.T) {
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
err
)
require
.
Equal
(
t
,
balanceNew
,
"80"
)
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
)
time
.
Sleep
(
time
.
Second
)
fmt
.
Println
(
"---------------------- end ----------------------"
)
}
}
func
Test_RestorePrivateKeys
(
t
*
testing
.
T
)
{
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