Commit 4ddc2e22 authored by QM's avatar QM

updata test sh

parent 9ce4e51b
......@@ -625,9 +625,9 @@ func (ethRelayer *Relayer4Ethereum) QueryTxhashRelay2Eth() ebTypes.Txhashes {
return ebTypes.Txhashes{Txhash: txhashs}
}
func (ethRelayer *Relayer4Ethereum) QueryTxhashRelay2Chain33() *ebTypes.Txhashes {
func (ethRelayer *Relayer4Ethereum) QueryTxhashRelay2Chain33() ebTypes.Txhashes {
txhashs := ethRelayer.queryTxhashes([]byte(eth2chain33TxHashPrefix))
return &ebTypes.Txhashes{Txhash: txhashs}
return ebTypes.Txhashes{Txhash: txhashs}
}
// handleLogLockEvent : unpacks a LogLock event, converts it to a ProphecyClaim, and relays a tx to chain33
......
......@@ -94,17 +94,6 @@ func (r *suiteEthRelayer) Test_1_ImportPrivateKey() {
r.Equal(validators.Chain33Validator, chain33AccountAddr)
}
func (r *suiteEthRelayer) Test_3_RestorePrivateKeys() {
// 错误的密码 也不报错
err := r.ethRelayer.RestorePrivateKeys(passphrase)
r.NoError(err)
err = r.ethRelayer.StoreAccountWithNewPassphase(passphrase, passphrase)
r.NoError(err)
time.Sleep(1 * time.Second)
}
func (r *suiteEthRelayer) Test_2_LockEth() {
ctx := context.Background()
bridgeBankBalance, err := r.sim.BalanceAt(ctx, r.x2EthDeployInfo.BridgeBank.Address, nil)
......@@ -135,13 +124,21 @@ func (r *suiteEthRelayer) Test_2_LockEth() {
r.NoError(err)
for _, logv := range logs {
//err := r.ethRelayer.setEthTxEvent(logv)
//r.NoError(err)
r.ethRelayer.storeBridgeBankLogs(logv, true)
}
time.Sleep(time.Duration(r.ethRelayer.fetchHeightPeriodMs) * time.Millisecond)
//time.Sleep(time.Second * 5)
}
func (r *suiteEthRelayer) Test_3_RestorePrivateKeys() {
// 错误的密码 也不报错
err := r.ethRelayer.RestorePrivateKeys(passphrase)
r.NoError(err)
err = r.ethRelayer.StoreAccountWithNewPassphase(passphrase, passphrase)
r.NoError(err)
time.Sleep(1 * time.Second)
}
func (r *suiteEthRelayer) Test_4_handleLogLockEvent() {
......@@ -250,14 +247,6 @@ func (r *suiteEthRelayer) newEthRelayer() *Relayer4Ethereum {
}
relayer.deployInfo = &ebTypes.Deploy{}
//relayer.deployInfo.DeployerPrivateKey = "0x9dc6df3a8ab139a54d8a984f54958ae0661f880229bf3bdbb886b87d58b56a08"
//relayer.deployInfo.OperatorAddr = "0x0C05bA5c230fDaA503b53702aF1962e08D0C60BF"
//relayer.deployInfo.ValidatorsAddr = append(relayer.deployInfo.ValidatorsAddr, "0xA4Ea64a583F6e51C3799335b28a8F0529570A635")
//relayer.deployInfo.ValidatorsAddr = append(relayer.deployInfo.ValidatorsAddr, "0x1919203bA8b325278d28Fb8fFeac49F2CD881A4e")
//relayer.deployInfo.ValidatorsAddr = append(relayer.deployInfo.ValidatorsAddr, "0x9cBA1fF8D0b0c9Bc95d5762533F8CddBE795f687")
//relayer.deployInfo.ValidatorsAddr = append(relayer.deployInfo.ValidatorsAddr, "0xdb15E7327aDc83F2878624bBD6307f5Af1B477b4")
//InitPowers := []int64{int64(80), int64(10), int64(10), int64(10)}
//relayer.deployInfo.InitPowers = InitPowers
relayer.deployInfo.DeployerPrivateKey = common.ToHex(crypto.FromECDSA(r.para.DeployPrivateKey))
relayer.deployInfo.OperatorAddr = r.para.Operator.String()
for _, v := range r.para.InitValidators {
......@@ -339,19 +328,6 @@ latter:
}
func (r *suiteEthRelayer) deployContracts() {
//// 0x0C05bA5c230fDaA503b53702aF1962e08D0C60BF
//var deployerPrivateKey = "9dc6df3a8ab139a54d8a984f54958ae0661f880229bf3bdbb886b87d58b56a08"
//// 0xA4Ea64a583F6e51C3799335b28a8F0529570A635
//var ethValidatorAddrKeyA = "355b876d7cbcb930d5dfab767f66336ce327e082cbaa1877210c1bae89b1df71"
//var ethValidatorAddrKeyB = "62ca4122aac0e6f35bed02fc15c7ddbdaa07f2f2a1821c8b8210b891051e3ee9"
//var ethValidatorAddrKeyC = "4ae589fe3837dcfc90d1c85b8423dc30841525cbebc41dfb537868b0f8376bbf"
//var ethValidatorAddrKeyD = "1385016736f7379884763f4a39811d1391fa156a7ca017be6afffa52bb327695"
//ethValidatorAddrKeys := make([]string, 0)
//ethValidatorAddrKeys = append(ethValidatorAddrKeys, ethValidatorAddrKeyA)
//ethValidatorAddrKeys = append(ethValidatorAddrKeys, ethValidatorAddrKeyB)
//ethValidatorAddrKeys = append(ethValidatorAddrKeys, ethValidatorAddrKeyC)
//ethValidatorAddrKeys = append(ethValidatorAddrKeys, ethValidatorAddrKeyD)
ctx := context.Background()
r.backend, r.para = setup.PrepareTestEnv()
r.sim = r.backend.(*backends.SimulatedBackend)
......
......@@ -2,6 +2,7 @@ package ethereum
import (
"context"
"encoding/hex"
"fmt"
"math/big"
"testing"
......@@ -66,15 +67,31 @@ func (r *suiteEthRelayerSim) TestSim_1_ImportPrivateKey() {
}
func (r *suiteEthRelayerSim) TestSim_2_RestorePrivateKeys() {
// 错误的密码 也不报错
err := r.ethRelayer.RestorePrivateKeys(passphrase)
go func() {
for range r.ethRelayer.unlockchan {
}
}()
temp := r.ethRelayer.privateKey4Chain33
err := r.ethRelayer.RestorePrivateKeys("123")
r.NotEqual(hex.EncodeToString(temp.Bytes()), hex.EncodeToString(r.ethRelayer.privateKey4Chain33.Bytes()))
r.NoError(err)
err = r.ethRelayer.RestorePrivateKeys(passphrase)
r.Equal(hex.EncodeToString(temp.Bytes()), hex.EncodeToString(r.ethRelayer.privateKey4Chain33.Bytes()))
r.NoError(err)
err = r.ethRelayer.StoreAccountWithNewPassphase(passphrase, passphrase)
err = r.ethRelayer.StoreAccountWithNewPassphase("new123", passphrase)
r.NoError(err)
err = r.ethRelayer.RestorePrivateKeys("new123")
r.Equal(hex.EncodeToString(temp.Bytes()), hex.EncodeToString(r.ethRelayer.privateKey4Chain33.Bytes()))
r.NoError(err)
}
func (r *suiteEthRelayerSim) TestSim_3_IsValidatorActive() {
// 有时候会不通过
is, err := r.ethRelayer.IsValidatorActive("0x92c8b16afd6d423652559c6e266cbe1c29bfd84f")
r.Equal(is, true)
r.NoError(err)
......@@ -92,164 +109,6 @@ func (r *suiteEthRelayerSim) Test_4_DeployContrcts() {
r.Error(err)
}
func (r *suiteEthRelayerSim) Test_5_Show() {
//addr, err = r.ethRelayer.ShowLockStatics("123")
//fmt.Println(addr, err)
//
//addr, err = r.ethRelayer.ShowDepositStatics("123")
//fmt.Println(addr, err)
//
//addr, err = r.ethRelayer.ShowTokenAddrBySymbol("bty")
//fmt.Println(addr, err)
//addr, err := r.ethRelayer.CreateBridgeToken("bty")
//r.NoError(err)
//ethtxs.PendingDuration4TxExeuction = 10
//tokenAddr, err := r.ethRelayer.CreateERC20Token("testc")
//r.Error(err)
//fmt.Println(addr, err)
//
//addr, err = r.ethRelayer.MintERC20Token(tokenAddr, r.ethRelayer.ethValidator.String(), "20000000000000")
//r.Error(err)
//fmt.Println(addr, err)
}
//func (r *suiteEthRelayerSim) TestSim_4_LockEth() {
// ctx := context.Background()
// bridgeBankBalance, err := r.sim.BalanceAt(ctx, r.x2EthDeployInfo.BridgeBank.Address, nil)
// fmt.Println(bridgeBankBalance, err)
// r.NoError(err)
//
// userOneAuth, err := ethtxs.PrepareAuth(r.backend, r.para.ValidatorPriKey[0], r.para.InitValidators[0])
// r.NoError(err)
// ethAmount := big.NewInt(50)
// userOneAuth.Value = ethAmount
//
// //lock 50 eth
// chain33Sender := []byte("14KEKbYtKKQm4wMthSK9J4La4nAiidGozt")
// _, err = r.x2EthContracts.BridgeBank.Lock(userOneAuth, chain33Sender, common.Address{}, ethAmount)
// r.NoError(err)
// r.sim.Commit()
//
// bridgeBankBalance, err = r.sim.BalanceAt(ctx, r.x2EthDeployInfo.BridgeBank.Address, nil)
// r.NoError(err)
// //require.Equal(t, bridgeBankBalance.Int64(), ethAmount.Int64())
// fmt.Println(bridgeBankBalance, err)
// //
// ///* ctx := context.Background()
// // auth, err := ethtxs.PrepareAuth(r.backend, r.para.DeployPrivateKey, r.para.Operator)
// // r.NoError(err)
// //
// // opts := &bind.CallOpts{
// // Pending: true,
// // From: r.para.Operator,
// // Context: ctx,
// // }
// //
// // tokenCount, err := r.x2EthContracts.BridgeBank.BridgeTokenCount(opts)
// // r.Equal(tokenCount.Int64(), int64(0))
// // //创建token
// // symbol := "bty"
// // _, err = r.ethRelayer.x2EthContracts.BridgeBank.BridgeBankTransactor.CreateNewBridgeToken(auth, symbol)
// // r.NoError(err)
// // r.sim.Commit()
// //
// // eventName := "LogNewBridgeToken"
// // bridgeBankABI := ethtxs.LoadABI(ethtxs.BridgeBankABI)
// // logNewBridgeTokenSig := bridgeBankABI.Events[eventName].ID().Hex()
// //
// // logEvent := &events.LogNewBridgeToken{}
// // select {
// // // Handle any errors
// // case err := <-r.ethRelayer.bridgeBankSub.Err():
// // r.NoError(err)
// // // vLog is raw event data
// // case vLog := <-r.ethRelayer.bridgeBankLog:
// // // Check if the event is a 'LogLock' event
// // if vLog.Topics[0].Hex() == logNewBridgeTokenSig {
// // //_ = fmt.Sprint("Witnessed new event:%s, Block number:%d, Tx hash:%s", eventName, vLog.BlockNumber, vLog.TxHash.Hex())
// //
// // err = bridgeBankABI.Unpack(logEvent, eventName, vLog.Data)
// // r.NoError(err)
// // //_ = fmt.Sprint("token addr:%s, symbol:%s", logEvent.Token.String(), logEvent.Symbol)
// // r.Equal(symbol, logEvent.Symbol)
// //
// // //tokenCount正确加1
// // tokenCount, err = r.x2EthContracts.BridgeBank.BridgeTokenCount(opts)
// // r.Equal(tokenCount.Int64(), int64(1))
// // break
// // }
// // }
// //
// // ///////////newOracleClaim///////////////////////////
// // balance, _ := r.sim.BalanceAt(ctx, r.para.InitValidators[0], nil)
// // fmt.Println("InitValidators[0] addr,", r.para.InitValidators[0].String(), "balance =", balance.String())
// //
// // chain33Sender := []byte("14KEKbYtKKQm4wMthSK9J4La4nAiidGozt")
// // amount := int64(99)
// // ethReceiver := r.para.InitValidators[2]
// // claimID := crypto.Keccak256Hash(chain33Sender, ethReceiver.Bytes(), logEvent.Token.Bytes(), big.NewInt(amount).Bytes())
// //
// // authOracle, err := ethtxs.PrepareAuth(r.backend, r.para.ValidatorPriKey[0], r.para.InitValidators[0])
// // r.NoError(err)
// //
// // signature, err := ethtxs.SignClaim4Eth(claimID, r.para.ValidatorPriKey[0])
// // r.NoError(err)
// //
// // bridgeToken, err := generated.NewBridgeToken(logEvent.Token, r.backend)
// // r.NoError(err)
// // opts = &bind.CallOpts{
// // Pending: true,
// // Context: ctx,
// // }
// //
// // balance, err = bridgeToken.BalanceOf(opts, ethReceiver)
// // r.NoError(err)
// // r.Equal(balance.Int64(), int64(0))
// //
// // _, err = r.x2EthContracts.Oracle.NewOracleClaim(
// // authOracle,
// // events.ClaimTypeLock,
// // chain33Sender,
// // ethReceiver,
// // logEvent.Token,
// // logEvent.Symbol,
// // big.NewInt(amount),
// // claimID,
// // signature)
// // r.NoError(err)
// //
// // r.sim.Commit()
// // balance, err = bridgeToken.BalanceOf(opts, ethReceiver)
// // r.NoError(err)
// // r.Equal(balance.Int64(), amount)
// // fmt.Println("the minted amount is:", balance.Int64())
// //*/
// time.Sleep(1 * time.Second)
//
// query := ethereum.FilterQuery{
// Addresses: []common.Address{r.ethRelayer.bridgeBankAddr},
// }
// logs, err := r.sim.FilterLogs(context.Background(), query)
// if err != nil {
// errinfo := fmt.Sprintf("Failed to filterLogEvents due to:%s", err.Error())
// fmt.Println(errinfo)
// }
//
// for _, logv := range logs {
// if err := r.ethRelayer.setEthTxEvent(logv); nil != err {
// // panic(err.Error())
// }
// }
//
// time.Sleep(5 * time.Second)
//}
//func (r *suiteEthRelayerSim) TestRelayer4Ethereum_ApproveAllowance(t *testing.T) {
// r.ethRelayer.ApproveAllowance()
//}
func (r *suiteEthRelayerSim) newSimEthRelayer() *Relayer4Ethereum {
cfg := initCfg(*configPath)
cfg.SyncTxConfig.Chain33Host = "http://127.0.0.1:8801"
......@@ -284,6 +143,9 @@ func (r *suiteEthRelayerSim) newSimEthRelayer() *Relayer4Ethereum {
relayer.eventLogIndex = relayer.getLastBridgeBankProcessedHeight()
relayer.initBridgeBankTx()
relayer.x2EthContracts = r.x2EthContracts
relayer.x2EthDeployInfo = r.x2EthDeployInfo
go r.procSim()
return relayer
......@@ -297,9 +159,6 @@ func (r *suiteEthRelayerSim) procSim() {
relayerLog.Info("Please unlock or import private key for Ethereum relayer")
nilAddr := common.Address{}
if nilAddr != r.ethRelayer.bridgeRegistryAddr {
r.ethRelayer.x2EthContracts = r.x2EthContracts
r.ethRelayer.x2EthDeployInfo = r.x2EthDeployInfo
relayerLog.Info("^-^ ^-^ Succeed to recover corresponding solidity contract handler")
if nil != r.ethRelayer.recoverDeployPara() {
panic("Failed to recoverDeployPara")
......
......@@ -15,15 +15,9 @@ import (
var (
eth2chain33TxHashPrefix = "Eth2chain33TxHash"
eth2chain33TxTotalAmount = []byte("Eth2chain33TxTotalAmount")
chain33ToEthTxHashPrefix = "chain33ToEthTxHash"
chain33ToEthTxTotalAmount = []byte("chain33ToEthTxTotalAmount")
bridgeRegistryAddrPrefix = []byte("x2EthBridgeRegistryAddr")
chain33BridgeLogProcessedAt = []byte("chain33BridgeLogProcessedAt")
bridgeBankLogProcessedAt = []byte("bridgeBankLogProcessedAt")
ethTxEventPrefix = []byte("ethTxEventPrefix")
lastBridgeBankHeightProcPrefix = []byte("lastBridgeBankHeight")
)
......@@ -36,10 +30,6 @@ func calcRelay2Chain33Txhash(txindex int64) []byte {
return []byte(fmt.Sprintf("%s-%012d", eth2chain33TxHashPrefix, txindex))
}
func calcRelay2EthTxhash(txindex int64) []byte {
return []byte(fmt.Sprintf("%s-%012d", chain33ToEthTxHashPrefix, txindex))
}
func (ethRelayer *Relayer4Ethereum) setBridgeRegistryAddr(bridgeRegistryAddr string) error {
return ethRelayer.db.Set(bridgeRegistryAddrPrefix, []byte(bridgeRegistryAddr))
}
......@@ -65,31 +55,10 @@ func (ethRelayer *Relayer4Ethereum) setLastestRelay2Chain33Txhash(txhash string,
return ethRelayer.db.Set(key, []byte(txhash))
}
func (ethRelayer *Relayer4Ethereum) updateTotalTxAmount2Eth(total int64) error {
totalTx := &chain33Types.Int64{
Data: atomic.LoadInt64(&ethRelayer.totalTx4Chain33ToEth),
}
//更新成功见证的交易数
return ethRelayer.db.Set(chain33ToEthTxTotalAmount, chain33Types.Encode(totalTx))
}
func (ethRelayer *Relayer4Ethereum) setLastestRelay2EthTxhash(txhash string, txIndex int64) error {
key := calcRelay2EthTxhash(txIndex)
return ethRelayer.db.Set(key, []byte(txhash))
}
func (ethRelayer *Relayer4Ethereum) queryTxhashes(prefix []byte) []string {
return utils.QueryTxhashes(prefix, ethRelayer.db)
}
func (ethRelayer *Relayer4Ethereum) setHeight4chain33BridgeLogAt(height uint64) error {
return ethRelayer.setLogProcHeight(chain33BridgeLogProcessedAt, height)
}
func (ethRelayer *Relayer4Ethereum) getHeight4chain33BridgeLogAt() uint64 {
return ethRelayer.getLogProcHeight(chain33BridgeLogProcessedAt)
}
func (ethRelayer *Relayer4Ethereum) setHeight4BridgeBankLogAt(height uint64) error {
return ethRelayer.setLogProcHeight(bridgeBankLogProcessedAt, height)
}
......
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