Commit 121093cd authored by QM's avatar QM

updata bridgeBank_test.go

parent 89674d65
package test
import (
"encoding/hex"
"fmt"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
"math/big"
"strings"
"testing"
)
func TestUnpackEvent(t *testing.T) {
const abiJSON = `[{"constant":false,"inputs":[{"name":"memo","type":"bytes"}],"name":"receive","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"anonymous":false,"inputs":[{"indexed":false,"name":"sender","type":"address"},{"indexed":false,"name":"amount","type":"uint256"},{"indexed":false,"name":"memo","type":"bytes"}],"name":"received","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"sender","type":"address"}],"name":"receivedAddr","type":"event"}]`
abi, err := abi.JSON(strings.NewReader(abiJSON))
if err != nil {
t.Fatal(err)
}
const hexdata = `000000000000000000000000376c47978271565f56deb45495afa69e59c16ab200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000158`
data, err := hex.DecodeString(hexdata)
if err != nil {
t.Fatal(err)
}
if len(data)%32 == 0 {
t.Errorf("len(data) is %d, want a non-multiple of 32", len(data))
}
type ReceivedEvent struct {
Sender common.Address
Amount *big.Int
Memo []byte
}
var ev ReceivedEvent
err = abi.Unpack(&ev, "received", data)
if err != nil {
t.Error(err)
}
fmt.Printf("\nReceivedEvent sender:%s", ev.Sender.String())
type ReceivedAddrEvent struct {
Sender common.Address
}
var receivedAddrEv ReceivedAddrEvent
err = abi.Unpack(&receivedAddrEv, "receivedAddr", data)
if err != nil {
t.Error(err)
}
fmt.Printf("\nreceivedAddrEv=%s\n\n\n", receivedAddrEv.Sender.String())
}
\ No newline at end of file
package test package setup
import ( import (
"crypto/ecdsa" "crypto/ecdsa"
...@@ -21,8 +21,6 @@ func PrepareTestEnv() (bind.ContractBackend, *ethtxs.DeployPara) { ...@@ -21,8 +21,6 @@ func PrepareTestEnv() (bind.ContractBackend, *ethtxs.DeployPara) {
PrivateKey: crypto.FromECDSA(genesiskey), PrivateKey: crypto.FromECDSA(genesiskey),
} }
alloc[genesisAddr] = genesisAccount alloc[genesisAddr] = genesisAccount
gasLimit := uint64(2999280)
sim := backends.NewSimulatedBackend(alloc, gasLimit)
var InitValidators []common.Address var InitValidators []common.Address
var ValidatorPriKey []*ecdsa.PrivateKey var ValidatorPriKey []*ecdsa.PrivateKey
...@@ -31,8 +29,17 @@ func PrepareTestEnv() (bind.ContractBackend, *ethtxs.DeployPara) { ...@@ -31,8 +29,17 @@ func PrepareTestEnv() (bind.ContractBackend, *ethtxs.DeployPara) {
addr := crypto.PubkeyToAddress(key.PublicKey) addr := crypto.PubkeyToAddress(key.PublicKey)
InitValidators = append(InitValidators, addr) InitValidators = append(InitValidators, addr)
ValidatorPriKey = append(ValidatorPriKey, key) 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)} InitPowers := []*big.Int{big.NewInt(80), big.NewInt(10), big.NewInt(10)}
para := &ethtxs.DeployPara{ para := &ethtxs.DeployPara{
......
package executor package executor
import ( import (
//"github.com/33cn/chain33/client"
"testing" "testing"
apimock "github.com/33cn/chain33/client/mocks" apimock "github.com/33cn/chain33/client/mocks"
...@@ -73,7 +74,7 @@ func (x *suiteX2Ethereum) SetupSuite() { ...@@ -73,7 +74,7 @@ func (x *suiteX2Ethereum) SetupSuite() {
tx.Nonce = 1 tx.Nonce = 1
tx.Sign(types.SECP256K1, privFrom) tx.Sign(types.SECP256K1, privFrom)
x.action, _ = newAction(x2eth, tx, 0) x.action = newAction(x2eth, tx, 0)
x.x2eth = x2eth x.x2eth = x2eth
x.addrX2Eth = address.ExecAddress(driverName) x.addrX2Eth = address.ExecAddress(driverName)
...@@ -214,7 +215,7 @@ func (x *suiteX2Ethereum) Test_4_Eth2Chain33() { ...@@ -214,7 +215,7 @@ func (x *suiteX2Ethereum) Test_4_Eth2Chain33() {
x.NoError(err) x.NoError(err)
x.setDb(receipt) x.setDb(receipt)
x.query_GetEthProphecy("010x7B95B6EC7EbD73572298cEf32Bb54FA408207359", types2.EthBridgeStatus_WithdrawedStatusText) x.query_GetEthProphecy("010x7B95B6EC7EbD73572298cEf32Bb54FA408207359", types2.EthBridgeStatus_SuccessStatusText)
x.query_GetSymbolTotalAmount(symbol, 1, 7) x.query_GetSymbolTotalAmount(symbol, 1, 7)
x.query_GetSymbolTotalAmountByTxType(symbol, 1, "withdraw", 3) x.query_GetSymbolTotalAmountByTxType(symbol, 1, "withdraw", 3)
...@@ -333,10 +334,10 @@ func (x *suiteX2Ethereum) query_GetSymbolTotalAmountByTxType(tokenSymbol string, ...@@ -333,10 +334,10 @@ func (x *suiteX2Ethereum) query_GetSymbolTotalAmountByTxType(tokenSymbol string,
} }
func (x *suiteX2Ethereum) query_GetSymbolTotalAmount(tokenSymbol string, direction int64, equal int64) { func (x *suiteX2Ethereum) query_GetSymbolTotalAmount(tokenSymbol string, direction int64, equal int64) {
msg, err := x.x2eth.Query_GetSymbolTotalAmount(&types2.QuerySymbolAssetsParams{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.TotalAmount, uint64(equal)) x.Equal(reply.Res[0].TotalAmount, uint64(equal))
} }
func (x *suiteX2Ethereum) query_GetEthProphecy(id string, statusTest types2.EthBridgeStatus) { func (x *suiteX2Ethereum) query_GetEthProphecy(id string, statusTest types2.EthBridgeStatus) {
......
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