Commit 62bf6d3d authored by QM's avatar QM

updata ethereum_test.go

parent 81684945
......@@ -24,29 +24,8 @@ func TestBrigeTokenCreat(t *testing.T) {
ctx := context.Background()
println("TEST:BridgeToken creation (Chain33 assets)")
//1st部署相关合约
sim, para := setup.PrepareTestEnv()
balance, _ := sim.BalanceAt(ctx, para.Deployer, nil)
fmt.Println("deployer addr,", para.Deployer.String(), "balance =", balance.String())
/////////////////////////EstimateGas///////////////////////////
callMsg := ethereum.CallMsg{
From: para.Deployer,
Data: common.FromHex(generated.BridgeBankBin),
}
gas, err := sim.EstimateGas(ctx, callMsg)
if nil != err {
panic("failed to estimate gas due to:" + err.Error())
}
fmt.Printf("\nThe estimated gas=%d", gas)
////////////////////////////////////////////////////
x2EthContracts, x2EthDeployInfo, err := ethtxs.DeployAndInit(sim, para)
if nil != err {
t.Fatalf("DeployAndInit failed due to:%s", err.Error())
}
sim.Commit()
para, sim, x2EthContracts, x2EthDeployInfo, err := setup.DeployContracts()
require.NoError(t, err)
//2nd:订阅事件
eventName := "LogNewBridgeToken"
......@@ -130,33 +109,8 @@ func TestBrigeTokenMint(t *testing.T) {
ctx := context.Background()
println("TEST:BridgeToken creation (Chain33 assets)")
//1st部署相关合约
sim, para := setup.PrepareTestEnv()
balance, _ := sim.BalanceAt(ctx, para.Deployer, nil)
fmt.Println("deployer addr,", para.Deployer.String(), "balance =", balance.String())
/////////////////////////EstimateGas///////////////////////////
callMsg := ethereum.CallMsg{
From: para.Deployer,
Data: common.FromHex(generated.BridgeBankBin),
}
gas, err := sim.EstimateGas(ctx, callMsg)
if nil != err {
panic("failed to estimate gas due to:" + err.Error())
}
fmt.Printf("\nThe estimated gas=%d", gas)
////////////////////////////////////////////////////
x2EthContracts, x2EthDeployInfo, err := ethtxs.DeployAndInit(sim, para)
if nil != err {
t.Fatalf("DeployAndInit failed due to:%s", err.Error())
}
sim.Commit()
auth, err := ethtxs.PrepareAuth(sim, para.DeployPrivateKey, para.Operator)
if nil != err {
t.Fatalf("PrepareAuth failed due to:%s", err.Error())
}
para, sim, x2EthContracts, x2EthDeployInfo, err := setup.DeployContracts()
require.NoError(t, err)
//2nd:订阅事件
eventName := "LogNewBridgeToken"
......@@ -183,6 +137,10 @@ func TestBrigeTokenMint(t *testing.T) {
//3rd:创建token
symbol := "BTY"
auth, err := ethtxs.PrepareAuth(sim, para.DeployPrivateKey, para.Operator)
if nil != err {
t.Fatalf("PrepareAuth failed due to:%s", err.Error())
}
_, err = x2EthContracts.BridgeBank.BridgeBankTransactor.CreateNewBridgeToken(auth, symbol)
if nil != err {
t.Fatalf("CreateNewBridgeToken failed due to:%s", err.Error())
......@@ -215,7 +173,7 @@ func TestBrigeTokenMint(t *testing.T) {
}
///////////newOracleClaim///////////////////////////
balance, _ = sim.BalanceAt(ctx, para.InitValidators[0], nil)
balance, _ := sim.BalanceAt(ctx, para.InitValidators[0], nil)
fmt.Println("InitValidators[0] addr,", para.InitValidators[0].String(), "balance =", balance.String())
chain33Sender := []byte("14KEKbYtKKQm4wMthSK9J4La4nAiidGozt")
......@@ -265,29 +223,8 @@ func TestBridgeDepositLock(t *testing.T) {
ctx := context.Background()
println("TEST:Bridge deposit locking (Erc20/Eth assets)")
//1st部署相关合约
sim, para := setup.PrepareTestEnv()
balance, _ := sim.BalanceAt(ctx, para.Deployer, nil)
fmt.Println("deployer addr,", para.Deployer.String(), "balance =", balance.String())
/////////////////////////EstimateGas///////////////////////////
callMsg := ethereum.CallMsg{
From: para.Deployer,
Data: common.FromHex(generated.BridgeBankBin),
}
gas, err := sim.EstimateGas(ctx, callMsg)
if nil != err {
panic("failed to estimate gas due to:" + err.Error())
}
fmt.Printf("\nThe estimated gas=%d", gas)
////////////////////////////////////////////////////
x2EthContracts, x2EthDeployInfo, err := ethtxs.DeployAndInit(sim, para)
if nil != err {
t.Fatalf("DeployAndInit failed due to:%s", err.Error())
}
sim.Commit()
para, sim, x2EthContracts, x2EthDeployInfo, err := setup.DeployContracts()
require.NoError(t, err)
//创建token
operatorAuth, err := ethtxs.PrepareAuth(sim, para.DeployPrivateKey, para.Operator)
......@@ -386,41 +323,13 @@ func TestBridgeBankUnlock(t *testing.T) {
ctx := context.Background()
println("TEST:Ethereum/ERC20 token unlocking (for burned chain33 assets)")
//1st部署相关合约
sim, para := setup.PrepareTestEnv()
balance, _ := sim.BalanceAt(ctx, para.Deployer, nil)
fmt.Println("deployer addr,", para.Deployer.String(), "balance =", balance.String())
/////////////////////////EstimateGas///////////////////////////
callMsg := ethereum.CallMsg{
From: para.Deployer,
Data: common.FromHex(generated.BridgeBankBin),
}
gas, err := sim.EstimateGas(ctx, callMsg)
if nil != err {
panic("failed to estimate gas due to:" + err.Error())
}
fmt.Printf("\nThe estimated gas=%d", gas)
////////////////////////////////////////////////////
x2EthContracts, x2EthDeployInfo, err := ethtxs.DeployAndInit(sim, para)
if nil != err {
t.Fatalf("DeployAndInit failed due to:%s", err.Error())
}
sim.Commit()
para, sim, x2EthContracts, x2EthDeployInfo, err := setup.DeployContracts()
require.NoError(t, err)
//1.lockEth资产
ethAddr := common.Address{}
ethToken, err := generated.NewBridgeToken(ethAddr, sim)
userOneAuth, err := ethtxs.PrepareAuth(sim, para.ValidatorPriKey[0], para.InitValidators[0])
require.Nil(t, err)
userOneAuth.Value = big.NewInt(300)
_, err = ethToken.Transfer(userOneAuth, x2EthDeployInfo.BridgeBank.Address, userOneAuth.Value)
sim.Commit()
//ToDO://///////////////////////////////////////////////
////////????####To check the balance by hzj/////////////
////////////////////////////////////////////////////////
ethLockAmount := big.NewInt(150)
userOneAuth.Value = ethLockAmount
chain33Sender := []byte("14KEKbYtKKQm4wMthSK9J4La4nAiidGozt")
......@@ -553,42 +462,16 @@ func TestBridgeBankSecondUnlockEth(t *testing.T) {
ctx := context.Background()
println("TEST:to be unlocked incrementally by successive burn prophecies (for burned chain33 assets)")
//1st部署相关合约
sim, para := setup.PrepareTestEnv()
balance, _ := sim.BalanceAt(ctx, para.Deployer, nil)
fmt.Println("deployer addr,", para.Deployer.String(), "balance =", balance.String())
/////////////////////////EstimateGas///////////////////////////
callMsg := ethereum.CallMsg{
From: para.Deployer,
Data: common.FromHex(generated.BridgeBankBin),
}
gas, err := sim.EstimateGas(ctx, callMsg)
if nil != err {
panic("failed to estimate gas due to:" + err.Error())
}
fmt.Printf("\nThe estimated gas=%d", gas)
////////////////////////////////////////////////////
x2EthContracts, x2EthDeployInfo, err := ethtxs.DeployAndInit(sim, para)
if nil != err {
t.Fatalf("DeployAndInit failed due to:%s", err.Error())
}
sim.Commit()
para, sim, x2EthContracts, x2EthDeployInfo, err := setup.DeployContracts()
require.NoError(t, err)
//1.lockEth资产
ethAddr := common.Address{}
ethToken, err := generated.NewBridgeToken(ethAddr, sim)
userOneAuth, err := ethtxs.PrepareAuth(sim, para.ValidatorPriKey[0], para.InitValidators[0])
require.Nil(t, err)
userOneAuth.Value = big.NewInt(300)
_, err = ethToken.Transfer(userOneAuth, x2EthDeployInfo.BridgeBank.Address, userOneAuth.Value)
sim.Commit()
ethLockAmount := big.NewInt(150)
userOneAuth.Value = ethLockAmount
chain33Sender := []byte("14KEKbYtKKQm4wMthSK9J4La4nAiidGozt")
//lock 150 eth
_, err = x2EthContracts.BridgeBank.Lock(userOneAuth, chain33Sender, common.Address{}, ethLockAmount)
......@@ -718,36 +601,14 @@ func TestBridgeBankSedondUnlockErc20(t *testing.T) {
ctx := context.Background()
println("TEST:ERC20 to be unlocked incrementally by successive burn prophecies (for burned chain33 assets))")
//1st部署相关合约
sim, para := setup.PrepareTestEnv()
balance, _ := sim.BalanceAt(ctx, para.Deployer, nil)
fmt.Println("deployer addr,", para.Deployer.String(), "balance =", balance.String())
/////////////////////////EstimateGas///////////////////////////
callMsg := ethereum.CallMsg{
From: para.Deployer,
Data: common.FromHex(generated.BridgeBankBin),
}
gas, err := sim.EstimateGas(ctx, callMsg)
if nil != err {
panic("failed to estimate gas due to:" + err.Error())
}
fmt.Printf("\nThe estimated gas=%d", gas)
////////////////////////////////////////////////////
x2EthContracts, x2EthDeployInfo, err := ethtxs.DeployAndInit(sim, para)
if nil != err {
t.Fatalf("DeployAndInit failed due to:%s", err.Error())
}
sim.Commit()
para, sim, x2EthContracts, x2EthDeployInfo, err := setup.DeployContracts()
require.NoError(t, err)
//1.lockEth资产
userOneAuth, err := ethtxs.PrepareAuth(sim, para.ValidatorPriKey[0], para.InitValidators[0])
require.Nil(t, err)
ethLockAmount := big.NewInt(150)
userOneAuth.Value = ethLockAmount
chain33Sender := []byte("14KEKbYtKKQm4wMthSK9J4La4nAiidGozt")
//lock 150 eth
_, err = x2EthContracts.BridgeBank.Lock(userOneAuth, chain33Sender, common.Address{}, ethLockAmount)
......@@ -763,9 +624,7 @@ func TestBridgeBankSedondUnlockErc20(t *testing.T) {
sim.Commit()
t.Logf("The new creaded symbolUsdt:%s, address:%s", symbolUsdt, bridgeTokenAddr.String())
//创建实例
//为userOne铸币
//userOne为bridgebank允许allowance设置数额
//创建实例 为userOne铸币 userOne为bridgebank允许allowance设置数额
userOne := para.InitValidators[0]
callopts := &bind.CallOpts{
Pending: true,
......@@ -780,11 +639,12 @@ func TestBridgeBankSedondUnlockErc20(t *testing.T) {
require.Equal(t, isMiner, true)
operatorAuth, err = ethtxs.PrepareAuth(sim, para.DeployPrivateKey, para.Operator)
require.Nil(t, err)
mintAmount := int64(1000)
_, err = bridgeTokenInstance.Mint(operatorAuth, userOne, big.NewInt(mintAmount))
require.Nil(t, err)
sim.Commit()
userOneAuth, err = ethtxs.PrepareAuth(sim, para.ValidatorPriKey[0], para.InitValidators[0])
require.Nil(t, err)
allowAmount := int64(100)
......@@ -800,7 +660,6 @@ func TestBridgeBankSedondUnlockErc20(t *testing.T) {
//测试子项目:should allow users to lock ERC20 tokens
userOneAuth, err = ethtxs.PrepareAuth(sim, para.ValidatorPriKey[0], para.InitValidators[0])
require.Nil(t, err)
//lock 100
lockAmount := big.NewInt(100)
_, err = x2EthContracts.BridgeBank.Lock(userOneAuth, chain33Sender, bridgeTokenAddr, lockAmount)
......
package setup
import (
"context"
"crypto/ecdsa"
"github.com/ethereum/go-ethereum"
"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/ethtxs"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
......@@ -26,7 +28,7 @@ func PrepareTestEnv() (*ethinterface.SimExtend, *ethtxs.DeployPara) {
var InitValidators []common.Address
var ValidatorPriKey []*ecdsa.PrivateKey
for i := 0; i < 3; i++ {
for i := 0; i < 4; i++ {
key, _ := crypto.GenerateKey()
addr := crypto.PubkeyToAddress(key.PublicKey)
InitValidators = append(InitValidators, addr)
......@@ -42,7 +44,7 @@ func PrepareTestEnv() (*ethinterface.SimExtend, *ethtxs.DeployPara) {
sim := new(ethinterface.SimExtend)
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{
DeployPrivateKey: genesiskey,
Deployer: genesisAddr,
......@@ -96,3 +98,25 @@ func PrepareTestEnvironment(deployerPrivateKey string, ethValidatorAddrKeys []st
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
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)
x2EthContracts := &X2EthContracts{
BridgeRegistry: registryInstance,
BridgeBank: bridgeBank,
Chain33Bridge: chain33Bridge,
Oracle: oracle,
Valset: valset,
}
x2EthDeployInfo := &X2EthDeployInfo{
......@@ -49,6 +59,7 @@ func RecoverContractHandler(client ethinterface.EthClientSpec, sender, registry
BridgeBank: &DeployResult{Address: *bridgeBankAddr},
Chain33Bridge: &DeployResult{Address: *chain33BridgeAddr},
Oracle: &DeployResult{Address: *oracleAddr},
Valset: &DeployResult{Address: *valsetAddr},
}
return x2EthContracts, x2EthDeployInfo, nil
......
......@@ -5,36 +5,32 @@ import (
"encoding/hex"
"flag"
"fmt"
"github.com/33cn/chain33/client/mocks"
"github.com/33cn/chain33/util/testnode"
//"github.com/ethereum/go-ethereum/core/types"
"github.com/33cn/plugin/plugin/dapp/x2ethereum/ebrelayer/events"
"math/big"
"os"
"testing"
"time"
"github.com/influxdata/influxdb/pkg/testing/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/33cn/chain33/client/mocks"
dbm "github.com/33cn/chain33/common/db"
_ "github.com/33cn/chain33/system"
chain33Types "github.com/33cn/chain33/types"
"github.com/33cn/chain33/util/testnode"
"github.com/33cn/plugin/plugin/dapp/x2ethereum/ebrelayer/ethcontract/generated"
"github.com/33cn/plugin/plugin/dapp/x2ethereum/ebrelayer/ethcontract/test/setup"
"github.com/33cn/plugin/plugin/dapp/x2ethereum/ebrelayer/ethinterface"
"github.com/33cn/plugin/plugin/dapp/x2ethereum/ebrelayer/ethtxs"
ebTypes "github.com/33cn/plugin/plugin/dapp/x2ethereum/ebrelayer/types"
relayerTypes "github.com/33cn/plugin/plugin/dapp/x2ethereum/ebrelayer/types"
tml "github.com/BurntSushi/toml"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/crypto"
"github.com/influxdata/influxdb/pkg/testing/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
)
var (
......@@ -51,133 +47,236 @@ var (
ethValidatorAddrKeyB = "a5f3063552f4483cfc20ac4f40f45b798791379862219de9e915c64722c1d400"
ethValidatorAddrKeyC = "bbf5e65539e9af0eb0cfac30bad475111054b09c11d668fc0731d54ea777471e"
ethValidatorAddrKeyD = "c9fa31d7984edf81b8ef3b40c761f1847f6fcd5711ab2462da97dc458f1f896b"
ethRelayer *Relayer4Ethereum
sim *ethinterface.SimExtend
x2EthContracts *ethtxs.X2EthContracts
x2EthDeployInfo *ethtxs.X2EthDeployInfo
para *ethtxs.DeployPara
)
func init() {
deployContracts()
ethRelayer = newEthRelayer()
func Test_GetValidatorAddr(t *testing.T) {
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)
}
func Test_GetValidatorAddr(t *testing.T) {
_, _, err := ethRelayer.NewAccount("123")
assert.NoError(t, err)
_, _, err = ethRelayer.NewAccount("123")
require.Nil(t, err)
privateKey, addr, err := ethRelayer.GetAccount("123")
assert.NoError(t, err)
require.Nil(t, err)
assert.NotEqual(t, privateKey, chain33PrivateKeyStr)
privateKey, addr, err = ethRelayer.GetAccount(passphrase)
assert.NoError(t, err)
require.Nil(t, err)
assert.Equal(t, privateKey, chain33PrivateKeyStr)
assert.Equal(t, addr, chain33AccountAddr)
validators, err := ethRelayer.GetValidatorAddr()
assert.NoError(t, err)
require.Nil(t, err)
assert.Equal(t, validators.Chain33Validator, chain33AccountAddr)
}
func Test_IsValidatorActive(t *testing.T) {
ethRelayer.x2EthContracts = x2EthContracts
ethRelayer.x2EthDeployInfo = x2EthDeployInfo
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)
fmt.Println("ethRelayer.x2EthContracts.Valset", ethRelayer.x2EthContracts.Valset)
//fmt.Println("ethRelayer.x2EthContracts.Valset", ethRelayer.x2EthContracts.Valset)
is, err := ethRelayer.IsValidatorActive("0x92c8b16afd6d423652559c6e266cbe1c29bfd84f")
is, err := ethRelayer.IsValidatorActive(para.InitValidators[0].String())
assert.Equal(t, is, true)
assert.NoError(t, err)
require.Nil(t, err)
is, err = ethRelayer.IsValidatorActive("0x0C05bA5c230fDaA503b53702aF1962e08D0C60BF")
assert.Equal(t, is, false)
assert.NoError(t, err)
require.Nil(t, err)
is, err = ethRelayer.IsValidatorActive("123")
require.Error(t, err)
}
func Test_ShowAddr(t *testing.T) {
{
cfg := initCfg(*configPath)
relayer := &Relayer4Ethereum{
provider: cfg.EthProvider,
unlockchan: make(chan int, 2),
rpcURL2Chain33: cfg.SyncTxConfig.Chain33Host,
maturityDegree: cfg.EthMaturityDegree,
fetchHeightPeriodMs: cfg.EthBlockFetchPeriod,
}
_, err := relayer.ShowBridgeBankAddr()
require.Error(t, err)
_, err = relayer.ShowBridgeRegistryAddr()
require.Error(t, err)
}
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)
ethRelayer.prePareSubscribeEvent()
addr, err := ethRelayer.ShowBridgeBankAddr()
assert.NoError(t, err)
require.Nil(t, err)
assert.Equal(t, addr, x2EthDeployInfo.BridgeBank.Address.String())
addr, err = ethRelayer.ShowBridgeRegistryAddr()
assert.NoError(t, err)
require.Nil(t, err)
assert.Equal(t, addr, x2EthDeployInfo.BridgeRegistry.Address.String())
addr, err = ethRelayer.ShowOperator()
assert.NoError(t, err)
require.Nil(t, err)
assert.Equal(t, addr, para.Operator.String())
_, err = ethRelayer.DeployContrcts()
require.Error(t, err)
}
func Test_SetBridgeRegistryAddr(t *testing.T) {
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)
_ = ethRelayer.setBridgeRegistryAddr(x2EthDeployInfo.BridgeRegistry.Address.String())
registrAddrInDB, err := ethRelayer.getBridgeRegistryAddr()
require.Nil(t, err)
assert.Equal(t, registrAddrInDB, x2EthDeployInfo.BridgeRegistry.Address.String())
}
func Test_CreateBridgeToken(t *testing.T) {
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)
balance, err := ethRelayer.GetBalance("", para.InitValidators[0].String())
assert.NoError(t, err)
require.Nil(t, err)
assert.Equal(t, balance, "10000000000")
tokenAddrbty, err := ethRelayer.CreateBridgeToken("BTY")
assert.NoError(t, err)
require.Nil(t, err)
require.NotEmpty(t, tokenAddrbty)
sim.Commit()
addr, err := ethRelayer.ShowTokenAddrBySymbol("BTY")
assert.NoError(t, err)
require.Nil(t, err)
assert.Equal(t, addr, tokenAddrbty)
decimals, err := ethRelayer.GetDecimals(tokenAddrbty)
assert.NoError(t, err)
require.Nil(t, err)
assert.Equal(t, decimals, uint8(8))
_, err = ethRelayer.Burn(ethValidatorAddrKeyA, tokenAddrbty, chain33AccountAddr, "10")
_, err = ethRelayer.Burn(para.InitValidators[0].String(), tokenAddrbty, chain33AccountAddr, "10")
require.Error(t, err)
_, err = ethRelayer.BurnAsync(ethValidatorAddrKeyA, tokenAddrbty, chain33AccountAddr, "10")
_, err = ethRelayer.BurnAsync(para.InitValidators[0].String(), tokenAddrbty, chain33AccountAddr, "10")
require.Error(t, err)
}
func Test_LockEth(t *testing.T) {
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)
var tx chain33Types.Transaction
var ret chain33Types.Reply
ret.IsOk = true
mockapi := &mocks.QueueProtocolAPI{}
// 这里对需要mock的方法打桩,Close是必须的,其它方法根据需要
mockapi.On("Close").Return()
mockapi.On("AddPushSubscribe", mock.Anything).Return(&ret, nil)
mockapi.On("CreateTransaction", mock.Anything).Return(&tx, nil)
mockapi.On("SendTx", mock.Anything).Return(&ret, nil)
mockapi.On("SendTransaction", mock.Anything).Return(&ret, nil)
mockapi.On("GetConfig", mock.Anything).Return(chainTestCfg, nil)
mock33 := testnode.New("", mockapi)
defer mock33.Close()
rpcCfg := mock33.GetCfg().RPC
// 这里必须设置监听端口,默认的是无效值
rpcCfg.JrpcBindAddr = "127.0.0.1:8801"
mock33.GetRPC().Listen()
ctx := context.Background()
bridgeBankBalance, err := sim.BalanceAt(ctx, x2EthDeployInfo.BridgeBank.Address, nil)
require.Nil(t, err)
assert.Equal(t, bridgeBankBalance.Int64(), int64(0))
userOneAuth, err := ethtxs.PrepareAuth(sim, para.ValidatorPriKey[0], para.InitValidators[0])
require.Nil(t, err)
//lock 50 eth
chain33Sender := []byte("14KEKbYtKKQm4wMthSK9J4La4nAiidGozt")
ethAmount := big.NewInt(50)
userOneAuth.Value = ethAmount
_, err = x2EthContracts.BridgeBank.Lock(userOneAuth, chain33Sender, common.Address{}, ethAmount)
require.Nil(t, err)
sim.Commit()
bridgeBankBalance, err = sim.BalanceAt(ctx, x2EthDeployInfo.BridgeBank.Address, nil)
require.Nil(t, err)
assert.Equal(t, bridgeBankBalance.Int64(), ethAmount.Int64())
for i := 0; i < 11; i++ {
sim.Commit()
}
time.Sleep(time.Duration(ethRelayer.fetchHeightPeriodMs) * time.Millisecond)
balance, err := ethRelayer.ShowLockStatics("")
require.Nil(t, err)
assert.Equal(t, balance, "50")
time.Sleep(time.Second)
}
func Test_CreateERC20Token(t *testing.T) {
para, sim, x2EthContracts, x2EthDeployInfo := deployContracts()
ethRelayer := newEthRelayer(para, sim, x2EthContracts, x2EthDeployInfo)
_ = ethRelayer.ImportChain33PrivateKey(passphrase, chain33PrivateKeyStr)
time.Sleep(time.Second)
tokenErc20Addr, err := ethRelayer.CreateERC20Token("testcc")
assert.NoError(t, err)
require.Nil(t, err)
require.NotEmpty(t, tokenErc20Addr)
sim.Commit()
_, err = ethRelayer.MintERC20Token(tokenErc20Addr, para.Deployer.String(), "20000000000000")
assert.NoError(t, err)
require.Nil(t, err)
sim.Commit()
balance, err := ethRelayer.ShowDepositStatics(tokenErc20Addr)
assert.NoError(t, err)
require.Nil(t, err)
assert.Equal(t, balance, "20000000000000")
//claimID := crypto.Keccak256Hash(big.NewInt(50).Bytes())
//ret, err = ethRelayer.IsProphecyPending(claimID)
//assert.NoError(t, err)
//assert.Equal(t,ret, false)
claimID := crypto.Keccak256Hash(big.NewInt(50).Bytes())
bret, err := ethRelayer.IsProphecyPending(claimID)
require.Nil(t, err)
assert.Equal(t, bret, false)
txhash, err := ethRelayer.TransferToken(tokenErc20Addr, hexutil.Encode(crypto.FromECDSA(para.DeployPrivateKey)), ethRelayer.deployInfo.ValidatorsAddr[0], "100")
assert.NoError(t, err)
require.Nil(t, err)
sim.Commit()
_, err = ethRelayer.ShowTxReceipt(txhash)
assert.NoError(t, err)
require.Nil(t, err)
balance, err = ethRelayer.GetBalance(tokenErc20Addr, ethRelayer.deployInfo.ValidatorsAddr[0])
assert.NoError(t, err)
require.Nil(t, err)
assert.Equal(t, balance, "100")
balance, err = ethRelayer.GetBalance(tokenErc20Addr, para.Deployer.String())
assert.NoError(t, err)
require.Nil(t, err)
assert.Equal(t, balance, "19999999999900")
tx1 := ethRelayer.QueryTxhashRelay2Eth()
......@@ -185,9 +284,7 @@ func Test_CreateERC20Token(t *testing.T) {
tx2 := ethRelayer.QueryTxhashRelay2Chain33()
require.Empty(t, tx2)
}
func Test_LockEth(t *testing.T) {
var tx chain33Types.Transaction
var ret chain33Types.Reply
ret.IsOk = true
......@@ -208,182 +305,170 @@ func Test_LockEth(t *testing.T) {
rpcCfg.JrpcBindAddr = "127.0.0.1:8801"
mock33.GetRPC().Listen()
ctx := context.Background()
bridgeBankBalance, err := sim.BalanceAt(ctx, x2EthDeployInfo.BridgeBank.Address, nil)
assert.NoError(t, err)
assert.Equal(t, bridgeBankBalance.Int64(), int64(0))
tokenErc20Addrtestc, err := ethRelayer.CreateERC20Token("testc")
require.Nil(t, err)
require.NotEmpty(t, tokenErc20Addrtestc)
sim.Commit()
userOneAuth, err := ethtxs.PrepareAuth(sim, para.ValidatorPriKey[0], para.InitValidators[0])
assert.NoError(t, err)
_, err = ethRelayer.MintERC20Token(tokenErc20Addrtestc, para.Deployer.String(), "10000000000000")
require.Nil(t, err)
sim.Commit()
//lock 50 eth
chain33Sender := []byte("14KEKbYtKKQm4wMthSK9J4La4nAiidGozt")
ethAmount := big.NewInt(50)
userOneAuth.Value = ethAmount
_, err = x2EthContracts.BridgeBank.Lock(userOneAuth, chain33Sender, common.Address{}, ethAmount)
assert.NoError(t, err)
balance, err = ethRelayer.ShowDepositStatics(tokenErc20Addrtestc)
require.Nil(t, err)
assert.Equal(t, balance, "10000000000000")
chain33Receiver := "14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
_, err = ethRelayer.LockEthErc20Asset(hexutil.Encode(crypto.FromECDSA(para.DeployPrivateKey)), tokenErc20Addrtestc, "100", chain33Receiver)
require.Nil(t, err)
sim.Commit()
bridgeBankBalance, err = sim.BalanceAt(ctx, x2EthDeployInfo.BridgeBank.Address, nil)
assert.NoError(t, err)
assert.Equal(t, bridgeBankBalance.Int64(), ethAmount.Int64())
balance, err = ethRelayer.GetBalance(tokenErc20Addrtestc, para.Deployer.String())
require.Nil(t, err)
assert.Equal(t, balance, "9999999999900")
_, err = ethRelayer.ApproveAllowance(hexutil.Encode(crypto.FromECDSA(para.DeployPrivateKey)), tokenErc20Addrtestc, "500")
require.Nil(t, err)
sim.Commit()
_, err = ethRelayer.LockEthErc20AssetAsync(hexutil.Encode(crypto.FromECDSA(para.DeployPrivateKey)), tokenErc20Addrtestc, "100", chain33Receiver)
require.Nil(t, err)
sim.Commit()
balance, err = ethRelayer.GetBalance(tokenErc20Addrtestc, para.Deployer.String())
require.Nil(t, err)
assert.Equal(t, balance, "9999999999800")
for i := 0; i < 11; i++ {
sim.Commit()
}
time.Sleep(time.Duration(ethRelayer.fetchHeightPeriodMs) * time.Millisecond)
}
func Test_BurnBty(t *testing.T) {
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)
var tx chain33Types.Transaction
var ret chain33Types.Reply
ret.IsOk = true
mockapi := &mocks.QueueProtocolAPI{}
// 这里对需要mock的方法打桩,Close是必须的,其它方法根据需要
mockapi.On("Close").Return()
mockapi.On("AddPushSubscribe", mock.Anything).Return(&ret, nil)
mockapi.On("CreateTransaction", mock.Anything).Return(&tx, nil)
mockapi.On("SendTx", mock.Anything).Return(&ret, nil)
mockapi.On("SendTransaction", mock.Anything).Return(&ret, nil)
mockapi.On("GetConfig", mock.Anything).Return(chainTestCfg, nil)
mock33 := testnode.New("", mockapi)
defer mock33.Close()
rpcCfg := mock33.GetCfg().RPC
// 这里必须设置监听端口,默认的是无效值
rpcCfg.JrpcBindAddr = "127.0.0.1:8801"
mock33.GetRPC().Listen()
tokenAddrbty, err := ethRelayer.CreateBridgeToken("bty")
require.Nil(t, err)
require.NotEmpty(t, tokenAddrbty)
sim.Commit()
chain33Sender := []byte("14KEKbYtKKQm4wMthSK9J4La4nAiidGozt")
amount := int64(100)
ethReceiver := para.InitValidators[2]
claimID := crypto.Keccak256Hash(chain33Sender, ethReceiver.Bytes(), big.NewInt(amount).Bytes())
authOracle, err := ethtxs.PrepareAuth(ethRelayer.clientSpec, para.ValidatorPriKey[0], para.InitValidators[0])
require.Nil(t, err)
signature, err := ethtxs.SignClaim4Eth(claimID, para.ValidatorPriKey[0])
require.Nil(t, err)
_, err = x2EthContracts.Oracle.NewOracleClaim(
authOracle,
events.ClaimTypeLock,
chain33Sender,
ethReceiver,
common.HexToAddress(tokenAddrbty),
"bty",
big.NewInt(amount),
claimID,
signature)
require.Nil(t, err)
sim.Commit()
balanceNew, err := ethRelayer.GetBalance(tokenAddrbty, ethReceiver.String())
require.Nil(t, err)
require.Equal(t, balanceNew, "100")
_, err = ethRelayer.Burn(hexutil.Encode(crypto.FromECDSA(para.ValidatorPriKey[2])), tokenAddrbty, chain33AccountAddr, "10")
require.NoError(t, err)
sim.Commit()
time.Sleep(time.Duration(ethRelayer.fetchHeightPeriodMs) * time.Millisecond)
balance, err := ethRelayer.ShowLockStatics("")
assert.NoError(t, err)
assert.Equal(t, balance, "50")
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")
_, err = ethRelayer.ApproveAllowance(hexutil.Encode(crypto.FromECDSA(para.ValidatorPriKey[2])), tokenAddrbty, "10")
require.Nil(t, err)
sim.Commit()
_, err = ethRelayer.BurnAsync(hexutil.Encode(crypto.FromECDSA(para.ValidatorPriKey[2])), tokenAddrbty, chain33AccountAddr, "10")
require.NoError(t, err)
sim.Commit()
balanceNew, err = ethRelayer.GetBalance(tokenAddrbty, ethReceiver.String())
require.Nil(t, err)
require.Equal(t, balanceNew, "80")
time.Sleep(time.Second)
fmt.Println("---------------------- end ----------------------")
}
//func Test_LockErc20(t *testing.T) {
// var tx chain33Types.Transaction
// var ret chain33Types.Reply
// ret.IsOk = true
//
// mockapi := &mocks.QueueProtocolAPI{}
// // 这里对需要mock的方法打桩,Close是必须的,其它方法根据需要
// mockapi.On("Close").Return()
// mockapi.On("AddPushSubscribe", mock.Anything).Return(&ret, nil)
// mockapi.On("CreateTransaction", mock.Anything).Return(&tx, nil)
// mockapi.On("SendTx", mock.Anything).Return(&ret, nil)
// mockapi.On("SendTransaction", mock.Anything).Return(&ret, nil)
// mockapi.On("GetConfig", mock.Anything).Return(chainTestCfg, nil)
//
// mock33 := testnode.New("", mockapi)
// defer mock33.Close()
// rpcCfg := mock33.GetCfg().RPC
// // 这里必须设置监听端口,默认的是无效值
// rpcCfg.JrpcBindAddr = "127.0.0.1:8801"
// mock33.GetRPC().Listen()
//
// tokenErc20Addr, err := ethRelayer.CreateERC20Token("testc")
// assert.NoError(t, err)
// require.NotEmpty(t, tokenErc20Addr)
// sim.Commit()
//
// fmt.Println("tokenErc20Addr**************", tokenErc20Addr)
//
// _, err = ethRelayer.MintERC20Token(tokenErc20Addr, para.Deployer.String(), "10000000000000")
// assert.NoError(t, err)
// sim.Commit()
//
// balance, err := ethRelayer.ShowDepositStatics(tokenErc20Addr)
// assert.NoError(t, err)
// assert.Equal(t, balance, "10000000000000")
//
// chain33Receiver := "14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
// _, err = ethRelayer.LockEthErc20Asset(hexutil.Encode(crypto.FromECDSA(para.DeployPrivateKey)), tokenErc20Addr, "100", chain33Receiver)
// assert.NoError(t, err)
// sim.Commit()
//
// balance, err = ethRelayer.GetBalance(tokenErc20Addr, para.Deployer.String())
// assert.NoError(t, err)
// assert.Equal(t, balance, "9999999999900")
//
// _, err = ethRelayer.ApproveAllowance(hexutil.Encode(crypto.FromECDSA(para.DeployPrivateKey)), tokenErc20Addr, "500")
// assert.NoError(t, err)
// sim.Commit()
//
// _, err = ethRelayer.LockEthErc20AssetAsync(hexutil.Encode(crypto.FromECDSA(para.DeployPrivateKey)), tokenErc20Addr, "100", chain33Receiver)
// assert.NoError(t, err)
// sim.Commit()
//
// balance, err = ethRelayer.GetBalance(tokenErc20Addr, para.Deployer.String())
// assert.NoError(t, err)
// assert.Equal(t, balance, "9999999999800")
// //
// //for i := 0; i < 11; i++ {
// // sim.Commit()
// //}
// //time.Sleep(time.Duration(ethRelayer.fetchHeightPeriodMs) * time.Millisecond)
//}
//func Test_BurnBty(t *testing.T) {
// tokenAddrbty, err := ethRelayer.CreateBridgeToken("bty")
// assert.NoError(t, err)
// require.NotEmpty(t, tokenAddrbty)
// sim.Commit()
//
// chain33Sender := []byte("14KEKbYtKKQm4wMthSK9J4La4nAiidGozt")
// amount := int64(100)
// ethReceiver := para.InitValidators[2]
// claimID := crypto.Keccak256Hash(chain33Sender, ethReceiver.Bytes(), big.NewInt(amount).Bytes())
//
// authOracle, err := ethtxs.PrepareAuth(ethRelayer.clientSpec, para.ValidatorPriKey[0], para.InitValidators[0])
// require.Nil(t, err)
// signature, err := ethtxs.SignClaim4Eth(claimID, para.ValidatorPriKey[0])
// require.Nil(t, err)
//
// _, err = x2EthContracts.Oracle.NewOracleClaim(
// authOracle,
// events.ClaimTypeLock,
// chain33Sender,
// ethReceiver,
// common.HexToAddress(tokenAddrbty),
// "bty",
// big.NewInt(amount),
// claimID,
// signature)
// require.Nil(t, err)
// sim.Commit()
//
// balanceNew, err := ethRelayer.GetBalance(tokenAddrbty, ethReceiver.String())
// require.Nil(t, err)
// require.Equal(t, balanceNew, "100")
//
// _, err = ethRelayer.Burn(hexutil.Encode(crypto.FromECDSA(para.ValidatorPriKey[2])), tokenAddrbty, chain33AccountAddr, "10")
// require.NoError(t, err)
// sim.Commit()
//
// balanceNew, err = ethRelayer.GetBalance(tokenAddrbty, ethReceiver.String())
// require.Nil(t, err)
// require.Equal(t, balanceNew, "90")
//
// _, err = ethRelayer.ApproveAllowance(hexutil.Encode(crypto.FromECDSA(para.ValidatorPriKey[2])), tokenAddrbty, "10")
// assert.NoError(t, err)
// sim.Commit()
//
// _, err = ethRelayer.BurnAsync(hexutil.Encode(crypto.FromECDSA(para.ValidatorPriKey[2])), tokenAddrbty, chain33AccountAddr, "10")
// require.NoError(t, err)
// sim.Commit()
//
// balanceNew, err = ethRelayer.GetBalance(tokenAddrbty, ethReceiver.String())
// require.Nil(t, err)
// require.Equal(t, balanceNew, "80")
//}
func Test_RestorePrivateKeys(t *testing.T) {
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)
go func() {
for range ethRelayer.unlockchan {
}
}()
temp := ethRelayer.privateKey4Chain33
err := ethRelayer.RestorePrivateKeys("123")
err = ethRelayer.RestorePrivateKeys("123")
assert.NotEqual(t, hex.EncodeToString(temp.Bytes()), hex.EncodeToString(ethRelayer.privateKey4Chain33.Bytes()))
assert.NoError(t, err)
require.Nil(t, err)
err = ethRelayer.RestorePrivateKeys(passphrase)
assert.Equal(t, hex.EncodeToString(temp.Bytes()), hex.EncodeToString(ethRelayer.privateKey4Chain33.Bytes()))
assert.NoError(t, err)
require.Nil(t, err)
err = ethRelayer.StoreAccountWithNewPassphase("new123", passphrase)
assert.NoError(t, err)
require.Nil(t, err)
err = ethRelayer.RestorePrivateKeys("new123")
assert.Equal(t, hex.EncodeToString(temp.Bytes()), hex.EncodeToString(ethRelayer.privateKey4Chain33.Bytes()))
assert.NoError(t, err)
require.Nil(t, err)
time.Sleep(time.Second)
}
func newEthRelayer() *Relayer4Ethereum {
func newEthRelayer(para *ethtxs.DeployPara, sim *ethinterface.SimExtend, x2EthContracts *ethtxs.X2EthContracts, x2EthDeployInfo *ethtxs.X2EthDeployInfo) *Relayer4Ethereum {
cfg := initCfg(*configPath)
cfg.SyncTxConfig.Chain33Host = "http://127.0.0.1:8801"
cfg.BridgeRegistry = x2EthDeployInfo.BridgeRegistry.Address.String()
......@@ -402,16 +487,21 @@ func newEthRelayer() *Relayer4Ethereum {
bridgeRegistryAddr: x2EthDeployInfo.BridgeRegistry.Address,
maturityDegree: cfg.EthMaturityDegree,
fetchHeightPeriodMs: cfg.EthBlockFetchPeriod,
deployInfo: cfg.Deploy,
//deployInfo: cfg.Deploy,
}
relayer.deployInfo = &ebTypes.Deploy{}
relayer.deployInfo.DeployerPrivateKey = common.ToHex(crypto.FromECDSA(para.DeployPrivateKey))
relayer.deployInfo.OperatorAddr = para.Operator.String()
for _, v := range para.InitValidators {
relayer.deployInfo.ValidatorsAddr = append(relayer.deployInfo.ValidatorsAddr, v.String())
}
for _, v := range para.InitPowers {
relayer.deployInfo.InitPowers = append(relayer.deployInfo.InitPowers, v.Int64())
}
//_ = relayer.setBridgeRegistryAddr(cfg.BridgeRegistry)
//registrAddrInDB, err := relayer.getBridgeRegistryAddr()
//assert.NoError(t, err)
//assert.Equal(t, registrAddrInDB, cfg.BridgeRegistry)
relayer.eventLogIndex = relayer.getLastBridgeBankProcessedHeight()
relayer.initBridgeBankTx()
relayer.clientSpec = sim
relayer.clientChainID = big.NewInt(1)
......@@ -429,7 +519,7 @@ func newEthRelayer() *Relayer4Ethereum {
return relayer
}
func deployContracts() {
func deployContracts() (*ethtxs.DeployPara, *ethinterface.SimExtend, *ethtxs.X2EthContracts, *ethtxs.X2EthDeployInfo) {
ethValidatorAddrKeys := make([]string, 0)
ethValidatorAddrKeys = append(ethValidatorAddrKeys, ethValidatorAddrKeyA)
ethValidatorAddrKeys = append(ethValidatorAddrKeys, ethValidatorAddrKeyB)
......@@ -437,25 +527,21 @@ func deployContracts() {
ethValidatorAddrKeys = append(ethValidatorAddrKeys, ethValidatorAddrKeyD)
ctx := context.Background()
var backend bind.ContractBackend
backend, para = setup.PrepareTestEnvironment(deployerPrivateKey, ethValidatorAddrKeys)
sim = new(ethinterface.SimExtend)
//var backend bind.ContractBackend
backend, para := setup.PrepareTestEnvironment(deployerPrivateKey, ethValidatorAddrKeys)
sim := new(ethinterface.SimExtend)
sim.SimulatedBackend = backend.(*backends.SimulatedBackend)
//balance, _ := sim.BalanceAt(ctx, para.Deployer, nil)
//assert.Equal(t, balance.Int64(), int64(10000000000*10000))
callMsg := ethereum.CallMsg{
From: para.Deployer,
Data: common.FromHex(generated.BridgeBankBin),
}
_, _ = sim.EstimateGas(ctx, callMsg)
//assert.NoError(t, err)
x2EthContracts, x2EthDeployInfo, _ = ethtxs.DeployAndInit(sim, para)
//assert.NoError(t, err)
x2EthContracts, x2EthDeployInfo, _ := ethtxs.DeployAndInit(sim, para)
sim.Commit()
return para, sim, x2EthContracts, x2EthDeployInfo
}
func initCfg(path string) *relayerTypes.RelayerConfig {
......
package executor
import (
"fmt"
"strconv"
//"github.com/33cn/chain33/client"
"testing"
......@@ -190,10 +192,11 @@ func (x *suiteX2Ethereum) Test_4_Eth2Chain33() {
x.setDb(receipt)
_, 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)
x.query_GetSymbolTotalAmountByTxType(symbol, 1, "lock", 10)
ID := strconv.Itoa(0) + strconv.Itoa(0) + ethereumAddr + tokenContractAddress + "lock"
x.queryGetEthProphecy(ID, types2.EthBridgeStatus_SuccessStatusText)
x.queryGetSymbolTotalAmountByTxType(1, symbol, "lock", "10")
payload1 := &types2.Chain33ToEth{
TokenContract: tokenContractAddress,
......@@ -217,9 +220,9 @@ func (x *suiteX2Ethereum) Test_4_Eth2Chain33() {
x.NoError(err)
x.setDb(receipt)
x.query_GetEthProphecy("010x7B95B6EC7EbD73572298cEf32Bb54FA408207359", types2.EthBridgeStatus_SuccessStatusText)
x.query_GetSymbolTotalAmount(symbol, 1, 7)
x.query_GetSymbolTotalAmountByTxType(symbol, 1, "withdraw", 3)
x.queryGetEthProphecy("010x7B95B6EC7EbD73572298cEf32Bb54FA408207359", types2.EthBridgeStatus_SuccessStatusText)
x.queryGetSymbolTotalAmount(symbol, 1, 7)
x.queryGetSymbolTotalAmountByTxType(1, symbol, "withdraw", "3")
//payload.Amount = "10"
//payload.Nonce = 2
......@@ -242,8 +245,8 @@ func (x *suiteX2Ethereum) Test_4_Eth2Chain33() {
x.NoError(err)
x.setDb(receipt)
x.query_GetEthProphecy("030x7B95B6EC7EbD73572298cEf32Bb54FA408207359", types2.EthBridgeStatus_SuccessStatusText)
x.query_GetSymbolTotalAmountByTxType(symbol, 1, "lock", 11)
x.queryGetEthProphecy("030x7B95B6EC7EbD73572298cEf32Bb54FA408207359", types2.EthBridgeStatus_SuccessStatusText)
x.queryGetSymbolTotalAmountByTxType(1, symbol, "lock", "11")
}
func (x *suiteX2Ethereum) Test_5_Chain33ToEth() {
......@@ -259,16 +262,16 @@ func (x *suiteX2Ethereum) Test_5_Chain33ToEth() {
x.NoError(err)
x.setDb(receipt)
x.query_GetSymbolTotalAmount("bty", 2, 5)
x.query_GetSymbolTotalAmountByTxType("bty", 2, "lock", 5)
x.queryGetSymbolTotalAmount("bty", 2, 5)
x.queryGetSymbolTotalAmountByTxType(2, "bty", "lock", "5")
//msgLock.Amount = "4"
//receipt, err = x.action.procEth2Chain33_burn(msgLock)
//x.NoError(err)
//x.setDb(receipt)
//
//x.query_GetSymbolTotalAmount("bty", 2, 1)
//x.query_GetSymbolTotalAmountByTxType("bty", 2, "withdraw", 4)
//x.queryGetSymbolTotalAmount("bty", 2, 1)
//x.queryGetSymbolTotalAmountByTxType("bty", 2, "withdraw", 4)
//
//receipt, err = x.action.procEth2Chain33_burn(msgLock)
//x.Equal(err, types.ErrNoBalance)
......@@ -278,8 +281,8 @@ func (x *suiteX2Ethereum) Test_5_Chain33ToEth() {
//x.NoError(err)
//x.setDb(receipt)
x.query_GetSymbolTotalAmount("bty", 2, 0)
x.query_GetSymbolTotalAmountByTxType("bty", 2, "withdraw", 5)
x.queryGetSymbolTotalAmount("bty", 2, 0)
x.queryGetSymbolTotalAmountByTxType(2, "bty", "withdraw", "5")
}
func (x *suiteX2Ethereum) accountSetup() {
......@@ -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{
TokenSymbol: tokenSymbol,
Direction: direction,
......@@ -332,18 +335,20 @@ func (x *suiteX2Ethereum) query_GetSymbolTotalAmountByTxType(tokenSymbol string,
msg, err := x.x2eth.Query_GetSymbolTotalAmountByTxType(params)
x.NoError(err)
symbolAmount := msg.(*types2.ReceiptQuerySymbolAssetsByTxType)
x.Equal(symbolAmount.TotalAmount, uint64(equal))
fmt.Println("***", msg, err)
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})
x.NoError(err)
reply := msg.(*types2.ReceiptQuerySymbolAssets)
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})
x.NoError(err)
reply := msg.(*types2.ReceiptEthProphecy)
......
......@@ -125,7 +125,7 @@ func (a *action) procChain33ToEth_burn(msgBurn *x2eTy.Chain33ToEth) (*types.Rece
if err != nil {
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 {
return nil, err
}
......
......@@ -75,7 +75,7 @@ func (o *Oracle) ProcessSuccessfulClaimForBurn(claim, execAddr, tokenSymbol stri
}
// 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
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