Commit a3020b55 authored by QM's avatar QM

add ethtxs unit test

parent 9f49d98a
...@@ -5,11 +5,10 @@ import ( ...@@ -5,11 +5,10 @@ import (
"crypto/ecdsa" "crypto/ecdsa"
"math/big" "math/big"
"github.com/ethereum/go-ethereum"
"github.com/33cn/plugin/plugin/dapp/x2ethereum/ebrelayer/ethcontract/generated" "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"
"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"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
......
package ethtxs
import (
"context"
"crypto/ecdsa"
"fmt"
chain33Types "github.com/33cn/chain33/types"
"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/events"
ebrelayerTypes "github.com/33cn/plugin/plugin/dapp/x2ethereum/ebrelayer/types"
"github.com/33cn/plugin/plugin/dapp/x2ethereum/types"
x2ethTypes "github.com/33cn/plugin/plugin/dapp/x2ethereum/types"
"github.com/ethereum/go-ethereum"
"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/core"
"github.com/ethereum/go-ethereum/crypto"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"math/big"
"strings"
"testing"
)
var (
chain33Addr = "14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
ethAddr = "0x92C8b16aFD6d423652559C6E266cBE1c29Bfd84f"
ethTokenAddr = "0x0000000000000000000000000000000000000000"
)
type suiteContracts struct {
suite.Suite
para *DeployPara
sim *ethinterface.SimExtend
x2EthContracts *X2EthContracts
x2EthDeployInfo *X2EthDeployInfo
}
func TestRunSuiteX2Ethereum(t *testing.T) {
log := new(suiteContracts)
suite.Run(t, log)
}
func (c *suiteContracts) SetupSuite() {
var err error
c.para, c.sim, c.x2EthContracts, c.x2EthDeployInfo, err = DeployContracts()
require.Nil(c.T(), err)
}
func (c *suiteContracts) Test_GetOperator() {
operator, err := GetOperator(c.sim, c.para.InitValidators[0], c.x2EthDeployInfo.BridgeBank.Address)
require.Nil(c.T(), err)
assert.Equal(c.T(), operator.String(), c.para.Operator.String())
}
func (c *suiteContracts) Test_IsActiveValidator() {
bret, err := IsActiveValidator(c.para.InitValidators[0], c.x2EthContracts.Valset)
require.Nil(c.T(), err)
assert.Equal(c.T(), bret, true)
key, _ := crypto.GenerateKey()
addr := crypto.PubkeyToAddress(key.PublicKey)
bret, err = IsActiveValidator(addr, c.x2EthContracts.Valset)
require.Nil(c.T(), err) // ???
assert.Equal(c.T(), bret, false)
}
func (c *suiteContracts) Test_IsProphecyPending() {
claimID := crypto.Keccak256Hash(big.NewInt(50).Bytes())
bret, err := IsProphecyPending(claimID, c.para.InitValidators[0], c.x2EthContracts.Chain33Bridge)
require.Nil(c.T(), err)
assert.Equal(c.T(), bret, false)
}
func (c *suiteContracts) Test_LogLockToEthBridgeClaim() {
to := common.FromHex(chain33Addr)
event := &events.LockEvent{
From: c.para.InitValidators[0],
To: to,
Token: common.HexToAddress(ethTokenAddr),
Symbol: "eth",
Value: big.NewInt(10000 * 10000 * 10000),
Nonce: big.NewInt(1),
}
witnessClaim, err := LogLockToEthBridgeClaim(event, 1, c.x2EthDeployInfo.BridgeBank.Address.String(), 18)
require.Nil(c.T(), err)
assert.NotEmpty(c.T(), witnessClaim)
assert.Equal(c.T(), witnessClaim.EthereumChainID, int64(1))
assert.Equal(c.T(), witnessClaim.BridgeBrankAddr, c.x2EthDeployInfo.BridgeBank.Address.String())
assert.Equal(c.T(), witnessClaim.TokenAddr, ethTokenAddr)
assert.Equal(c.T(), witnessClaim.Symbol, event.Symbol)
assert.Equal(c.T(), witnessClaim.EthereumSender, event.From.String())
assert.Equal(c.T(), witnessClaim.Chain33Receiver, string(event.To))
assert.Equal(c.T(), witnessClaim.Amount, "100")
assert.Equal(c.T(), witnessClaim.Nonce, event.Nonce.Int64())
assert.Equal(c.T(), witnessClaim.Decimal, int64(18))
event.Token = common.HexToAddress("0x0000000000000000000000000000000000000001")
_, err = LogLockToEthBridgeClaim(event, 1, c.x2EthDeployInfo.BridgeBank.Address.String(), 18)
require.NotNil(c.T(), err)
assert.Equal(c.T(), err, ebrelayerTypes.ErrAddress4Eth)
}
func (c *suiteContracts) Test_LogBurnToEthBridgeClaim() {
to := common.FromHex(chain33Addr)
event := &events.BurnEvent{
OwnerFrom: c.para.InitValidators[0],
Chain33Receiver: to,
Token: common.HexToAddress(ethTokenAddr),
Symbol: "bty",
Amount: big.NewInt(100),
Nonce: big.NewInt(2),
}
witnessClaim, err := LogBurnToEthBridgeClaim(event, 1, c.x2EthDeployInfo.BridgeBank.Address.String(), 8)
require.Nil(c.T(), err)
assert.NotEmpty(c.T(), witnessClaim)
assert.Equal(c.T(), witnessClaim.EthereumChainID, int64(1))
assert.Equal(c.T(), witnessClaim.BridgeBrankAddr, c.x2EthDeployInfo.BridgeBank.Address.String())
assert.Equal(c.T(), witnessClaim.TokenAddr, ethTokenAddr)
assert.Equal(c.T(), witnessClaim.Symbol, event.Symbol)
assert.Equal(c.T(), witnessClaim.EthereumSender, event.OwnerFrom.String())
assert.Equal(c.T(), witnessClaim.Chain33Receiver, string(event.Chain33Receiver))
assert.Equal(c.T(), witnessClaim.Amount, "100")
assert.Equal(c.T(), witnessClaim.Nonce, event.Nonce.Int64())
assert.Equal(c.T(), witnessClaim.Decimal, int64(8))
}
func (c *suiteContracts) Test_ParseBurnLockTxReceipt_Chain33MsgToProphecyClaim() {
claimType := events.MsgBurn
chain33ToEth := types.ReceiptChain33ToEth{
Chain33Sender: chain33Addr,
EthereumReceiver: ethAddr,
TokenContract: ethTokenAddr,
IssuerDotSymbol: "bty",
Amount: "100",
Decimals: 8,
}
log := &chain33Types.ReceiptLog{
Ty: types.TyWithdrawChain33Log,
Log: chain33Types.Encode(&chain33ToEth),
}
var logs []*chain33Types.ReceiptLog
logs = append(logs, log)
receipt := &chain33Types.ReceiptData{
Ty: types.TyWithdrawChain33Log,
Logs: logs,
}
chain33Msg := ParseBurnLockTxReceipt(claimType, receipt)
require.NotNil(c.T(), chain33Msg)
assert.Equal(c.T(), chain33Msg.ClaimType, claimType)
assert.Equal(c.T(), chain33Msg.Chain33Sender, []byte(chain33ToEth.Chain33Sender))
assert.Equal(c.T(), chain33Msg.EthereumReceiver, common.HexToAddress(chain33ToEth.EthereumReceiver))
assert.Equal(c.T(), chain33Msg.TokenContractAddress, common.HexToAddress(chain33ToEth.TokenContract))
assert.Equal(c.T(), chain33Msg.Symbol, chain33ToEth.IssuerDotSymbol)
assert.Equal(c.T(), chain33Msg.Amount.String(), "100")
prophecyClaim := Chain33MsgToProphecyClaim(*chain33Msg)
assert.Equal(c.T(), chain33Msg.ClaimType, prophecyClaim.ClaimType)
assert.Equal(c.T(), chain33Msg.Chain33Sender, prophecyClaim.Chain33Sender)
assert.Equal(c.T(), chain33Msg.EthereumReceiver, prophecyClaim.EthereumReceiver)
assert.Equal(c.T(), chain33Msg.TokenContractAddress, prophecyClaim.TokenContractAddress)
assert.Equal(c.T(), strings.ToLower(chain33Msg.Symbol), prophecyClaim.Symbol)
assert.Equal(c.T(), chain33Msg.Amount, prophecyClaim.Amount)
}
func (c *suiteContracts) Test_RecoverContractHandler() {
_, _, err := RecoverContractHandler(c.sim, c.x2EthDeployInfo.BridgeRegistry.Address, c.x2EthDeployInfo.BridgeRegistry.Address)
require.Nil(c.T(), err)
}
func (c *suiteContracts) Test_RecoverOracleInstance() {
oracleInstance, err := RecoverOracleInstance(c.sim, c.x2EthDeployInfo.BridgeRegistry.Address, c.x2EthDeployInfo.BridgeRegistry.Address)
require.Nil(c.T(), err)
require.NotNil(c.T(), oracleInstance)
}
func (c *suiteContracts) Test_GetDeployHeight() {
height, err := GetDeployHeight(c.sim, c.x2EthDeployInfo.BridgeRegistry.Address, c.x2EthDeployInfo.BridgeRegistry.Address)
require.Nil(c.T(), err)
assert.True(c.T(), height > 0)
}
func (c *suiteContracts) Test_CreateBridgeToken() {
operatorInfo := &OperatorInfo{
PrivateKey: c.para.DeployPrivateKey,
Address: crypto.PubkeyToAddress(c.para.DeployPrivateKey.PublicKey),
}
tokenAddr, err := CreateBridgeToken("bty", c.sim, operatorInfo, c.x2EthDeployInfo, c.x2EthContracts)
require.Nil(c.T(), err)
c.sim.Commit()
addr, err := GetToken2address(c.x2EthContracts.BridgeBank, "bty")
require.Nil(c.T(), err)
assert.Equal(c.T(), addr, tokenAddr)
}
func (c *suiteContracts) Test_GetBalance() {
balance, err := GetBalance(c.sim, "", c.para.InitValidators[0].String())
require.Nil(c.T(), err)
assert.Equal(c.T(), balance, "10000000000")
}
func (c *suiteContracts) Test_CreateERC20Token() {
operatorInfo := &OperatorInfo{
PrivateKey: c.para.DeployPrivateKey,
Address: crypto.PubkeyToAddress(c.para.DeployPrivateKey.PublicKey),
}
tokenAddr, err := CreateERC20Token("testc", c.sim, operatorInfo)
require.Nil(c.T(), err)
c.sim.Commit()
amount := "10000000000000"
bn := big.NewInt(1)
bn, _ = bn.SetString(x2ethTypes.TrimZeroAndDot(amount), 10)
_, err = MintERC20Token(tokenAddr, c.para.Deployer.String(), bn, c.sim, operatorInfo)
require.Nil(c.T(), err)
c.sim.Commit()
balance, err := GetDepositFunds(c.sim, tokenAddr)
require.Nil(c.T(), err)
assert.Equal(c.T(), balance, amount)
amount = "100"
bn = big.NewInt(1)
bn, _ = bn.SetString(x2ethTypes.TrimZeroAndDot(amount), 10)
txhash, err := TransferToken(tokenAddr, hexutil.Encode(crypto.FromECDSA(c.para.DeployPrivateKey)), c.para.InitValidators[0].String(), bn, c.sim)
require.Nil(c.T(), err)
c.sim.Commit()
_, err = c.sim.TransactionReceipt(context.Background(), common.HexToHash(txhash))
require.Nil(c.T(), err)
balance, err = GetBalance(c.sim, tokenAddr, c.para.InitValidators[0].String())
require.Nil(c.T(), err)
assert.Equal(c.T(), balance, amount)
{
amount = "100"
bn := big.NewInt(1)
bn, _ = bn.SetString(x2ethTypes.TrimZeroAndDot(amount), 10)
chain33Receiver := "14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
_, err = LockEthErc20Asset(hexutil.Encode(crypto.FromECDSA(c.para.DeployPrivateKey)), tokenAddr, chain33Receiver, bn, c.sim, c.x2EthContracts.BridgeBank, c.x2EthDeployInfo.BridgeBank.Address)
require.Nil(c.T(), err)
c.sim.Commit()
balance, err = GetBalance(c.sim, tokenAddr, c.para.Deployer.String())
require.Nil(c.T(), err)
fmt.Println(balance)
assert.Equal(c.T(), balance, "9999999999800")
}
{
amount := "800"
bn := big.NewInt(1)
bn, _ = bn.SetString(x2ethTypes.TrimZeroAndDot(amount), 10)
_, err = ApproveAllowance(hexutil.Encode(crypto.FromECDSA(c.para.DeployPrivateKey)), tokenAddr, c.x2EthDeployInfo.BridgeBank.Address, bn, c.sim)
require.Nil(c.T(), err)
c.sim.Commit()
chain33Receiver := "14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
_, err = LockEthErc20AssetAsync(hexutil.Encode(crypto.FromECDSA(c.para.DeployPrivateKey)), tokenAddr, chain33Receiver, bn, c.sim, c.x2EthContracts.BridgeBank)
require.Nil(c.T(), err)
c.sim.Commit()
balance, err = GetBalance(c.sim, tokenAddr, c.para.Deployer.String())
require.Nil(c.T(), err)
fmt.Println(balance)
assert.Equal(c.T(), balance, "9999999999000")
}
}
func (c *suiteContracts) Test_GetLockedFunds() {
balance, err := GetLockedFunds(c.x2EthContracts.BridgeBank, "")
require.Nil(c.T(), err)
assert.Equal(c.T(), balance, "0")
}
//func (c *suiteContracts) Test_GetEthTxStatus() {
// hash := "0xc0c22aa6198fdde0dbe47ddadbe449f736b82ed4a498871de5d5f4ad9ae122a0"
// status := GetEthTxStatus(c.sim, common.HexToHash(hash))
// fmt.Println(status)
//}
func Test_All(t *testing.T) {
}
func PrepareTestEnv() (*ethinterface.SimExtend, *DeployPara) {
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
var InitValidators []common.Address
var ValidatorPriKey []*ecdsa.PrivateKey
for i := 0; i < 4; i++ {
key, _ := crypto.GenerateKey()
addr := crypto.PubkeyToAddress(key.PublicKey)
InitValidators = append(InitValidators, addr)
ValidatorPriKey = append(ValidatorPriKey, key)
account := core.GenesisAccount{
Balance: big.NewInt(100000000 * 100),
PrivateKey: crypto.FromECDSA(key),
}
alloc[addr] = account
}
gasLimit := uint64(100000000)
sim := new(ethinterface.SimExtend)
sim.SimulatedBackend = backends.NewSimulatedBackend(alloc, gasLimit)
InitPowers := []*big.Int{big.NewInt(80), big.NewInt(10), big.NewInt(10), big.NewInt(10)}
para := &DeployPara{
DeployPrivateKey: genesiskey,
Deployer: genesisAddr,
Operator: genesisAddr,
InitValidators: InitValidators,
ValidatorPriKey: ValidatorPriKey,
InitPowers: InitPowers,
}
return sim, para
}
func DeployContracts() (*DeployPara, *ethinterface.SimExtend, *X2EthContracts, *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 := DeployAndInit(sim, para)
if nil != err {
return nil, nil, nil, nil, err
}
sim.Commit()
return para, sim, x2EthContracts, x2EthDeployInfo, nil
}
package ethtxs package ethtxs
import ( import (
"context"
"crypto/ecdsa"
"math/big" "math/big"
"testing" "testing"
chain33Common "github.com/33cn/chain33/common"
"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/events"
"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/accounts/abi/bind/backends"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
...@@ -32,7 +40,6 @@ func TestContractRegistry_String(t *testing.T) { ...@@ -32,7 +40,6 @@ func TestContractRegistry_String(t *testing.T) {
assert.Equal(t, Oracle.String(), "oracle") assert.Equal(t, Oracle.String(), "oracle")
assert.Equal(t, BridgeBank.String(), "bridgebank") assert.Equal(t, BridgeBank.String(), "bridgebank")
assert.Equal(t, Chain33Bridge.String(), "chain33bridge") assert.Equal(t, Chain33Bridge.String(), "chain33bridge")
} }
func Test_GetAddressFromBridgeRegistry(t *testing.T) { func Test_GetAddressFromBridgeRegistry(t *testing.T) {
...@@ -52,3 +59,113 @@ func Test_GetAddressFromBridgeRegistry(t *testing.T) { ...@@ -52,3 +59,113 @@ func Test_GetAddressFromBridgeRegistry(t *testing.T) {
_, err := GetAddressFromBridgeRegistry(sim, genesisAddr, genesisAddr, bridgebankTest) _, err := GetAddressFromBridgeRegistry(sim, genesisAddr, genesisAddr, bridgebankTest)
require.NotNil(t, err) require.NotNil(t, err)
} }
func Test_RelayOracleClaimToEthereum(t *testing.T) {
para, sim, x2EthContracts, _, err := deployContracts()
require.NoError(t, err)
claimType := events.MsgBurn
privateKeySlice, err := chain33Common.FromHex("0x3fa21584ae2e4fd74db9b58e2386f5481607dfa4d7ba0617aaa7858e5025dc1e")
require.Nil(t, err)
privateKey, err := crypto.ToECDSA(privateKeySlice)
require.Nil(t, err)
prophecyClaim := ProphecyClaim{
ClaimType: events.MsgBurn,
Chain33Sender: []byte("12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"),
EthereumReceiver: common.HexToAddress("0x0C05bA5c230fDaA503b53702aF1962e08D0C60BF"),
TokenContractAddress: common.HexToAddress("0x0000000000000000000000000000000000000000"),
Symbol: "eth",
Amount: big.NewInt(100000000000000000),
}
chain33TxHash := common.Hex2Bytes("fd5747c43d1460bb6f8a7a26c66b4ccab5500d05668278efe5c0fd5951dfd909")
txhash, err := RelayOracleClaimToEthereum(x2EthContracts.Oracle, sim, para.InitValidators[0], claimType, prophecyClaim, privateKey, chain33TxHash)
require.Nil(t, err)
assert.Equal(t, txhash, "0x6fa087c7a2a8a4421f6e269fbc6c0838e99fa59d5760155a71cd7eb1c01aafad")
//hash := "0xc0c22aa6198fdde0dbe47ddadbe449f736b82ed4a498871de5d5f4ad9ae122a0"
//status := GetEthTxStatus(sim, common.HexToHash(hash))
//fmt.Println(status)
}
func deployContracts() (*DeployPara, *ethinterface.SimExtend, *X2EthContracts, *X2EthDeployInfo, error) {
// 0x8AFDADFC88a1087c9A1D6c0F5Dd04634b87F303a
deployerPrivateKey := "8656d2bc732a8a816a461ba5e2d8aac7c7f85c26a813df30d5327210465eb230"
// 0x92C8b16aFD6d423652559C6E266cBE1c29Bfd84f
ethValidatorAddrKeyA := "3fa21584ae2e4fd74db9b58e2386f5481607dfa4d7ba0617aaa7858e5025dc1e"
ethValidatorAddrKeyB := "a5f3063552f4483cfc20ac4f40f45b798791379862219de9e915c64722c1d400"
ethValidatorAddrKeyC := "bbf5e65539e9af0eb0cfac30bad475111054b09c11d668fc0731d54ea777471e"
ethValidatorAddrKeyD := "c9fa31d7984edf81b8ef3b40c761f1847f6fcd5711ab2462da97dc458f1f896b"
ethValidatorAddrKeys := make([]string, 0)
ethValidatorAddrKeys = append(ethValidatorAddrKeys, ethValidatorAddrKeyA)
ethValidatorAddrKeys = append(ethValidatorAddrKeys, ethValidatorAddrKeyB)
ethValidatorAddrKeys = append(ethValidatorAddrKeys, ethValidatorAddrKeyC)
ethValidatorAddrKeys = append(ethValidatorAddrKeys, ethValidatorAddrKeyD)
ctx := context.Background()
//var backend bind.ContractBackend
backend, para := PrepareTestEnvironment(deployerPrivateKey, ethValidatorAddrKeys)
sim := new(ethinterface.SimExtend)
sim.SimulatedBackend = backend.(*backends.SimulatedBackend)
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 := DeployAndInit(sim, para)
if nil != err {
return nil, nil, nil, nil, err
}
sim.Commit()
return para, sim, x2EthContracts, x2EthDeployInfo, nil
}
func PrepareTestEnvironment(deployerPrivateKey string, ethValidatorAddrKeys []string) (bind.ContractBackend, *DeployPara) {
genesiskey, _ := crypto.HexToECDSA(deployerPrivateKey)
alloc := make(core.GenesisAlloc)
genesisAddr := crypto.PubkeyToAddress(genesiskey.PublicKey)
genesisAccount := core.GenesisAccount{
Balance: big.NewInt(10000000000 * 10000),
PrivateKey: crypto.FromECDSA(genesiskey),
}
alloc[genesisAddr] = genesisAccount
var InitValidators []common.Address
var ValidatorPriKey []*ecdsa.PrivateKey
for _, v := range ethValidatorAddrKeys {
key, _ := crypto.HexToECDSA(v)
addr := crypto.PubkeyToAddress(key.PublicKey)
InitValidators = append(InitValidators, addr)
ValidatorPriKey = append(ValidatorPriKey, key)
account := core.GenesisAccount{
Balance: big.NewInt(100000000 * 100),
PrivateKey: crypto.FromECDSA(key),
}
alloc[addr] = account
}
gasLimit := uint64(100000000)
sim := backends.NewSimulatedBackend(alloc, gasLimit)
InitPowers := []*big.Int{big.NewInt(80), big.NewInt(10), big.NewInt(10), big.NewInt(10)}
para := &DeployPara{
DeployPrivateKey: genesiskey,
Deployer: genesisAddr,
Operator: genesisAddr,
InitValidators: InitValidators,
ValidatorPriKey: ValidatorPriKey,
InitPowers: InitPowers,
}
return sim, para
}
...@@ -14,7 +14,6 @@ import ( ...@@ -14,7 +14,6 @@ import (
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/common/math" "github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto/secp256k1" "github.com/ethereum/go-ethereum/crypto/secp256k1"
solsha3 "github.com/miguelmota/go-solidity-sha3" solsha3 "github.com/miguelmota/go-solidity-sha3"
) )
...@@ -38,13 +37,13 @@ const ( ...@@ -38,13 +37,13 @@ const (
) )
// GenerateClaimHash : Generates an OracleClaim hash from a ProphecyClaim's event data // GenerateClaimHash : Generates an OracleClaim hash from a ProphecyClaim's event data
func GenerateClaimHash(prophecyID []byte, sender []byte, recipient []byte, token []byte, amount []byte, validator []byte) common.Hash { //func GenerateClaimHash(prophecyID []byte, sender []byte, recipient []byte, token []byte, amount []byte, validator []byte) common.Hash {
// Generate a hash containing the information // // Generate a hash containing the information
rawHash := crypto.Keccak256Hash(prophecyID, sender, recipient, token, amount, validator) // rawHash := crypto.Keccak256Hash(prophecyID, sender, recipient, token, amount, validator)
//
// Cast hash to hex encoded string // // Cast hash to hex encoded string
return rawHash // return rawHash
} //}
func SignClaim4Eth(hash common.Hash, privateKey *ecdsa.PrivateKey) ([]byte, error) { func SignClaim4Eth(hash common.Hash, privateKey *ecdsa.PrivateKey) ([]byte, error) {
rawSignature, _ := prefixMessage(hash, privateKey) rawSignature, _ := prefixMessage(hash, privateKey)
......
...@@ -51,7 +51,6 @@ var ( ...@@ -51,7 +51,6 @@ var (
func Test_LockAndBurn(t *testing.T) { func Test_LockAndBurn(t *testing.T) {
var tx chain33Types.Transaction var tx chain33Types.Transaction
//tx.Nonce = 12
var ret chain33Types.Reply var ret chain33Types.Reply
ret.IsOk = true ret.IsOk = true
......
...@@ -172,9 +172,7 @@ func (x *x2ethereum) Query_GetRelayerBalance(in *x2eTy.QueryRelayerBalance) (typ ...@@ -172,9 +172,7 @@ func (x *x2ethereum) Query_GetRelayerBalance(in *x2eTy.QueryRelayerBalance) (typ
res.TokenSymbol = in.TokenSymbol res.TokenSymbol = in.TokenSymbol
res.Balance = x2eTy.TrimZeroAndDot(strconv.FormatFloat(float64(acc.Balance)/1e8, 'f', 4, 64)) res.Balance = x2eTy.TrimZeroAndDot(strconv.FormatFloat(float64(acc.Balance)/1e8, 'f', 4, 64))
symbolAmount.Res = append(symbolAmount.Res, res) symbolAmount.Res = append(symbolAmount.Res, res)
} else { } else {
tokenAddressesBytes, err := x.GetLocalDB().Get(x2eTy.CalTokenSymbolToTokenAddress(in.TokenSymbol)) tokenAddressesBytes, err := x.GetLocalDB().Get(x2eTy.CalTokenSymbolToTokenAddress(in.TokenSymbol))
if err != nil && err != types.ErrNotFound { if err != nil && err != types.ErrNotFound {
return nil, err return nil, err
......
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