Commit e50e04e7 authored by whisker's avatar whisker

Merge branch 'x2eth_200507' of https://github.com/zhengjunhe/plugin into x2eth_200507

parents 69d83df8 5b0092b7
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)
}
......@@ -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
......
......@@ -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) {
......
......@@ -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()
//未达到足够的成熟度,不进行处理
// +++++++++||++++++++++++||++++++++++||
// ^ ^ ^
......
......@@ -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)
......
......@@ -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) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment