Commit 62bf6d3d authored by QM's avatar QM

updata ethereum_test.go

parent 81684945
package setup package setup
import ( import (
"context"
"crypto/ecdsa" "crypto/ecdsa"
"github.com/ethereum/go-ethereum"
"math/big" "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/ethinterface"
"github.com/33cn/plugin/plugin/dapp/x2ethereum/ebrelayer/ethtxs" "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"
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends" "github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
...@@ -26,7 +28,7 @@ func PrepareTestEnv() (*ethinterface.SimExtend, *ethtxs.DeployPara) { ...@@ -26,7 +28,7 @@ func PrepareTestEnv() (*ethinterface.SimExtend, *ethtxs.DeployPara) {
var InitValidators []common.Address var InitValidators []common.Address
var ValidatorPriKey []*ecdsa.PrivateKey var ValidatorPriKey []*ecdsa.PrivateKey
for i := 0; i < 3; i++ { for i := 0; i < 4; i++ {
key, _ := crypto.GenerateKey() key, _ := crypto.GenerateKey()
addr := crypto.PubkeyToAddress(key.PublicKey) addr := crypto.PubkeyToAddress(key.PublicKey)
InitValidators = append(InitValidators, addr) InitValidators = append(InitValidators, addr)
...@@ -42,7 +44,7 @@ func PrepareTestEnv() (*ethinterface.SimExtend, *ethtxs.DeployPara) { ...@@ -42,7 +44,7 @@ func PrepareTestEnv() (*ethinterface.SimExtend, *ethtxs.DeployPara) {
sim := new(ethinterface.SimExtend) sim := new(ethinterface.SimExtend)
sim.SimulatedBackend = backends.NewSimulatedBackend(alloc, gasLimit) 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{ para := &ethtxs.DeployPara{
DeployPrivateKey: genesiskey, DeployPrivateKey: genesiskey,
Deployer: genesisAddr, Deployer: genesisAddr,
...@@ -96,3 +98,25 @@ func PrepareTestEnvironment(deployerPrivateKey string, ethValidatorAddrKeys []st ...@@ -96,3 +98,25 @@ func PrepareTestEnvironment(deployerPrivateKey string, ethValidatorAddrKeys []st
return sim, para 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
}
...@@ -36,12 +36,22 @@ func RecoverContractHandler(client ethinterface.EthClientSpec, sender, registry ...@@ -36,12 +36,22 @@ func RecoverContractHandler(client ethinterface.EthClientSpec, sender, registry
return nil, nil, errors.New("failed to NewOracle") 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) registryInstance, _ := generated.NewBridgeRegistry(registry, client)
x2EthContracts := &X2EthContracts{ x2EthContracts := &X2EthContracts{
BridgeRegistry: registryInstance, BridgeRegistry: registryInstance,
BridgeBank: bridgeBank, BridgeBank: bridgeBank,
Chain33Bridge: chain33Bridge, Chain33Bridge: chain33Bridge,
Oracle: oracle, Oracle: oracle,
Valset: valset,
} }
x2EthDeployInfo := &X2EthDeployInfo{ x2EthDeployInfo := &X2EthDeployInfo{
...@@ -49,6 +59,7 @@ func RecoverContractHandler(client ethinterface.EthClientSpec, sender, registry ...@@ -49,6 +59,7 @@ func RecoverContractHandler(client ethinterface.EthClientSpec, sender, registry
BridgeBank: &DeployResult{Address: *bridgeBankAddr}, BridgeBank: &DeployResult{Address: *bridgeBankAddr},
Chain33Bridge: &DeployResult{Address: *chain33BridgeAddr}, Chain33Bridge: &DeployResult{Address: *chain33BridgeAddr},
Oracle: &DeployResult{Address: *oracleAddr}, Oracle: &DeployResult{Address: *oracleAddr},
Valset: &DeployResult{Address: *valsetAddr},
} }
return x2EthContracts, x2EthDeployInfo, nil return x2EthContracts, x2EthDeployInfo, nil
......
package executor package executor
import ( import (
"fmt"
"strconv"
//"github.com/33cn/chain33/client" //"github.com/33cn/chain33/client"
"testing" "testing"
...@@ -190,10 +192,11 @@ func (x *suiteX2Ethereum) Test_4_Eth2Chain33() { ...@@ -190,10 +192,11 @@ func (x *suiteX2Ethereum) Test_4_Eth2Chain33() {
x.setDb(receipt) x.setDb(receipt)
_, err = x.x2eth.Query_GetEthProphecy(&types2.QueryEthProphecyParams{ID: "010x7B95B6EC7EbD73572298cEf32Bb54FA408207359"}) _, err = x.x2eth.Query_GetEthProphecy(&types2.QueryEthProphecyParams{ID: "010x7B95B6EC7EbD73572298cEf32Bb54FA408207359"})
x.Equal(err, types2.ErrInvalidProphecyID) x.Equal(err, types.ErrNotFound)
x.query_GetEthProphecy("000x7B95B6EC7EbD73572298cEf32Bb54FA408207359", types2.EthBridgeStatus_SuccessStatusText) ID := strconv.Itoa(0) + strconv.Itoa(0) + ethereumAddr + tokenContractAddress + "lock"
x.query_GetSymbolTotalAmountByTxType(symbol, 1, "lock", 10) x.queryGetEthProphecy(ID, types2.EthBridgeStatus_SuccessStatusText)
x.queryGetSymbolTotalAmountByTxType(1, symbol, "lock", "10")
payload1 := &types2.Chain33ToEth{ payload1 := &types2.Chain33ToEth{
TokenContract: tokenContractAddress, TokenContract: tokenContractAddress,
...@@ -217,9 +220,9 @@ func (x *suiteX2Ethereum) Test_4_Eth2Chain33() { ...@@ -217,9 +220,9 @@ func (x *suiteX2Ethereum) Test_4_Eth2Chain33() {
x.NoError(err) x.NoError(err)
x.setDb(receipt) x.setDb(receipt)
x.query_GetEthProphecy("010x7B95B6EC7EbD73572298cEf32Bb54FA408207359", types2.EthBridgeStatus_SuccessStatusText) x.queryGetEthProphecy("010x7B95B6EC7EbD73572298cEf32Bb54FA408207359", types2.EthBridgeStatus_SuccessStatusText)
x.query_GetSymbolTotalAmount(symbol, 1, 7) x.queryGetSymbolTotalAmount(symbol, 1, 7)
x.query_GetSymbolTotalAmountByTxType(symbol, 1, "withdraw", 3) x.queryGetSymbolTotalAmountByTxType(1, symbol, "withdraw", "3")
//payload.Amount = "10" //payload.Amount = "10"
//payload.Nonce = 2 //payload.Nonce = 2
...@@ -242,8 +245,8 @@ func (x *suiteX2Ethereum) Test_4_Eth2Chain33() { ...@@ -242,8 +245,8 @@ func (x *suiteX2Ethereum) Test_4_Eth2Chain33() {
x.NoError(err) x.NoError(err)
x.setDb(receipt) x.setDb(receipt)
x.query_GetEthProphecy("030x7B95B6EC7EbD73572298cEf32Bb54FA408207359", types2.EthBridgeStatus_SuccessStatusText) x.queryGetEthProphecy("030x7B95B6EC7EbD73572298cEf32Bb54FA408207359", types2.EthBridgeStatus_SuccessStatusText)
x.query_GetSymbolTotalAmountByTxType(symbol, 1, "lock", 11) x.queryGetSymbolTotalAmountByTxType(1, symbol, "lock", "11")
} }
func (x *suiteX2Ethereum) Test_5_Chain33ToEth() { func (x *suiteX2Ethereum) Test_5_Chain33ToEth() {
...@@ -259,16 +262,16 @@ func (x *suiteX2Ethereum) Test_5_Chain33ToEth() { ...@@ -259,16 +262,16 @@ func (x *suiteX2Ethereum) Test_5_Chain33ToEth() {
x.NoError(err) x.NoError(err)
x.setDb(receipt) x.setDb(receipt)
x.query_GetSymbolTotalAmount("bty", 2, 5) x.queryGetSymbolTotalAmount("bty", 2, 5)
x.query_GetSymbolTotalAmountByTxType("bty", 2, "lock", 5) x.queryGetSymbolTotalAmountByTxType(2, "bty", "lock", "5")
//msgLock.Amount = "4" //msgLock.Amount = "4"
//receipt, err = x.action.procEth2Chain33_burn(msgLock) //receipt, err = x.action.procEth2Chain33_burn(msgLock)
//x.NoError(err) //x.NoError(err)
//x.setDb(receipt) //x.setDb(receipt)
// //
//x.query_GetSymbolTotalAmount("bty", 2, 1) //x.queryGetSymbolTotalAmount("bty", 2, 1)
//x.query_GetSymbolTotalAmountByTxType("bty", 2, "withdraw", 4) //x.queryGetSymbolTotalAmountByTxType("bty", 2, "withdraw", 4)
// //
//receipt, err = x.action.procEth2Chain33_burn(msgLock) //receipt, err = x.action.procEth2Chain33_burn(msgLock)
//x.Equal(err, types.ErrNoBalance) //x.Equal(err, types.ErrNoBalance)
...@@ -278,8 +281,8 @@ func (x *suiteX2Ethereum) Test_5_Chain33ToEth() { ...@@ -278,8 +281,8 @@ func (x *suiteX2Ethereum) Test_5_Chain33ToEth() {
//x.NoError(err) //x.NoError(err)
//x.setDb(receipt) //x.setDb(receipt)
x.query_GetSymbolTotalAmount("bty", 2, 0) x.queryGetSymbolTotalAmount("bty", 2, 0)
x.query_GetSymbolTotalAmountByTxType("bty", 2, "withdraw", 5) x.queryGetSymbolTotalAmountByTxType(2, "bty", "withdraw", "5")
} }
func (x *suiteX2Ethereum) accountSetup() { func (x *suiteX2Ethereum) accountSetup() {
...@@ -323,7 +326,7 @@ func (x *suiteX2Ethereum) setDb(receipt *chain33types.Receipt) { ...@@ -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) queryGetSymbolTotalAmountByTxType(direction int64, tokenSymbol, txType, equal string) {
params := &types2.QuerySymbolAssetsByTxTypeParams{ params := &types2.QuerySymbolAssetsByTxTypeParams{
TokenSymbol: tokenSymbol, TokenSymbol: tokenSymbol,
Direction: direction, Direction: direction,
...@@ -332,18 +335,20 @@ func (x *suiteX2Ethereum) query_GetSymbolTotalAmountByTxType(tokenSymbol string, ...@@ -332,18 +335,20 @@ func (x *suiteX2Ethereum) query_GetSymbolTotalAmountByTxType(tokenSymbol string,
msg, err := x.x2eth.Query_GetSymbolTotalAmountByTxType(params) msg, err := x.x2eth.Query_GetSymbolTotalAmountByTxType(params)
x.NoError(err) x.NoError(err)
symbolAmount := msg.(*types2.ReceiptQuerySymbolAssetsByTxType) fmt.Println("***", msg, err)
x.Equal(symbolAmount.TotalAmount, uint64(equal))
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}) msg, err := x.x2eth.Query_GetSymbolTotalAmountByTxType(&types2.QuerySymbolAssetsByTxTypeParams{TokenSymbol: tokenSymbol, Direction: direction})
x.NoError(err) x.NoError(err)
reply := msg.(*types2.ReceiptQuerySymbolAssets) reply := msg.(*types2.ReceiptQuerySymbolAssets)
x.Equal(reply.Res[0].TotalAmount, uint64(equal)) 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}) msg, err := x.x2eth.Query_GetEthProphecy(&types2.QueryEthProphecyParams{ID: id})
x.NoError(err) x.NoError(err)
reply := msg.(*types2.ReceiptEthProphecy) reply := msg.(*types2.ReceiptEthProphecy)
......
...@@ -125,7 +125,7 @@ func (a *action) procChain33ToEth_burn(msgBurn *x2eTy.Chain33ToEth) (*types.Rece ...@@ -125,7 +125,7 @@ func (a *action) procChain33ToEth_burn(msgBurn *x2eTy.Chain33ToEth) (*types.Rece
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "relay procMsgBurn,exec=%s,sym=%s", x2eTy.X2ethereumX, msgBurn.IssuerDotSymbol) 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 { if err != nil {
return nil, err return nil, err
} }
......
...@@ -75,7 +75,7 @@ func (o *Oracle) ProcessSuccessfulClaimForBurn(claim, execAddr, tokenSymbol stri ...@@ -75,7 +75,7 @@ func (o *Oracle) ProcessSuccessfulClaimForBurn(claim, execAddr, tokenSymbol stri
} }
// ProcessBurn processes the burn of bridged coins from the given sender // 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 var a int64
a, _ = strconv.ParseInt(x2eTy.TrimZeroAndDot(amount), 10, 64) a, _ = strconv.ParseInt(x2eTy.TrimZeroAndDot(amount), 10, 64)
......
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