aboutsummaryrefslogtreecommitdiffstats
path: root/les/handler_test.go
diff options
context:
space:
mode:
authorgary rong <garyrong0905@gmail.com>2019-06-28 15:34:02 +0800
committerPéter Szilágyi <peterke@gmail.com>2019-06-28 15:34:02 +0800
commitf7cdea2bdcd7ff3cec99731cb912cde0b233d6c9 (patch)
treeb463c8dd42547edceb778d946927d2c363303324 /les/handler_test.go
parent702f52fb99d60b4b6bab05799c14dafdd8648854 (diff)
downloadgo-tangerine-f7cdea2bdcd7ff3cec99731cb912cde0b233d6c9.tar
go-tangerine-f7cdea2bdcd7ff3cec99731cb912cde0b233d6c9.tar.gz
go-tangerine-f7cdea2bdcd7ff3cec99731cb912cde0b233d6c9.tar.bz2
go-tangerine-f7cdea2bdcd7ff3cec99731cb912cde0b233d6c9.tar.lz
go-tangerine-f7cdea2bdcd7ff3cec99731cb912cde0b233d6c9.tar.xz
go-tangerine-f7cdea2bdcd7ff3cec99731cb912cde0b233d6c9.tar.zst
go-tangerine-f7cdea2bdcd7ff3cec99731cb912cde0b233d6c9.zip
all: on-chain oracle checkpoint syncing (#19543)
* all: implement simple checkpoint syncing cmd, les, node: remove callback mechanism cmd, node: remove callback definition les: simplify the registrar les: expose checkpoint rpc services in the light client les, light: don't store untrusted receipt cmd, contracts, les: discard stale checkpoint cmd, contracts/registrar: loose restriction of registeration cmd, contracts: add replay-protection all: off-chain multi-signature contract params: deploy checkpoint contract for rinkeby cmd/registrar: add raw signing mode for registrar cmd/registrar, contracts/registrar, les: fixed messages * cmd/registrar, contracts/registrar: fix lints * accounts/abi/bind, les: address comments * cmd, contracts, les, light, params: minor checkpoint sync cleanups * cmd, eth, les, light: move checkpoint config to config file * cmd, eth, les, params: address comments * eth, les, params: address comments * cmd: polish up the checkpoint admin CLI * cmd, contracts, params: deploy new version contract * cmd/checkpoint-admin: add another flag for clef mode signing * cmd, contracts, les: rename and regen checkpoint oracle with abigen
Diffstat (limited to 'les/handler_test.go')
-rw-r--r--les/handler_test.go47
1 files changed, 23 insertions, 24 deletions
diff --git a/les/handler_test.go b/les/handler_test.go
index dd7f1dbc4..e48db216a 100644
--- a/les/handler_test.go
+++ b/les/handler_test.go
@@ -259,7 +259,6 @@ func testGetCode(t *testing.T, protocol int) {
var codereqs []*CodeReq
var codes [][]byte
-
for i := uint64(0); i <= bc.CurrentBlock().NumberU64(); i++ {
header := bc.GetHeaderByNumber(i)
req := &CodeReq{
@@ -342,11 +341,10 @@ func testGetProofs(t *testing.T, protocol int) {
var proofreqs []ProofReq
proofsV2 := light.NewNodeSet()
- accounts := []common.Address{testBankAddress, acc1Addr, acc2Addr, {}}
+ accounts := []common.Address{bankAddr, userAddr1, userAddr2, {}}
for i := uint64(0); i <= bc.CurrentBlock().NumberU64(); i++ {
header := bc.GetHeaderByNumber(i)
- root := header.Root
- trie, _ := trie.New(root, trie.NewDatabase(server.db))
+ trie, _ := trie.New(header.Root, trie.NewDatabase(server.db))
for _, acc := range accounts {
req := ProofReq{
@@ -377,7 +375,7 @@ func testGetStaleProof(t *testing.T, protocol int) {
check := func(number uint64, wantOK bool) {
var (
header = bc.GetHeaderByNumber(number)
- account = crypto.Keccak256(testBankAddress.Bytes())
+ account = crypto.Keccak256(userAddr1.Bytes())
)
req := &ProofReq{
BHash: header.Hash(),
@@ -390,7 +388,7 @@ func testGetStaleProof(t *testing.T, protocol int) {
if wantOK {
proofsV2 := light.NewNodeSet()
t, _ := trie.New(header.Root, trie.NewDatabase(server.db))
- t.Prove(crypto.Keccak256(account), 0, proofsV2)
+ t.Prove(account, 0, proofsV2)
expected = proofsV2.NodeList()
}
if err := expectResponse(server.tPeer.app, ProofsV2Msg, 42, testBufLimit, expected); err != nil {
@@ -496,14 +494,15 @@ func TestGetBloombitsProofs(t *testing.T) {
}
func TestTransactionStatusLes2(t *testing.T) {
- db := rawdb.NewMemoryDatabase()
- pm := newTestProtocolManagerMust(t, false, 0, nil, nil, nil, db, nil)
- chain := pm.blockchain.(*core.BlockChain)
+ server, tearDown := newServerEnv(t, 0, 2, nil)
+ defer tearDown()
+
+ chain := server.pm.blockchain.(*core.BlockChain)
config := core.DefaultTxPoolConfig
config.Journal = ""
txpool := core.NewTxPool(config, params.TestChainConfig, chain)
- pm.txpool = txpool
- peer, _ := newTestPeer(t, "peer", 2, pm, true, 0)
+ server.pm.txpool = txpool
+ peer, _ := newTestPeer(t, "peer", 2, server.pm, true, 0)
defer peer.close()
var reqID uint64
@@ -511,13 +510,13 @@ func TestTransactionStatusLes2(t *testing.T) {
test := func(tx *types.Transaction, send bool, expStatus light.TxStatus) {
reqID++
if send {
- cost := peer.GetRequestCost(SendTxV2Msg, 1)
- sendRequest(peer.app, SendTxV2Msg, reqID, cost, types.Transactions{tx})
+ cost := server.tPeer.GetRequestCost(SendTxV2Msg, 1)
+ sendRequest(server.tPeer.app, SendTxV2Msg, reqID, cost, types.Transactions{tx})
} else {
- cost := peer.GetRequestCost(GetTxStatusMsg, 1)
- sendRequest(peer.app, GetTxStatusMsg, reqID, cost, []common.Hash{tx.Hash()})
+ cost := server.tPeer.GetRequestCost(GetTxStatusMsg, 1)
+ sendRequest(server.tPeer.app, GetTxStatusMsg, reqID, cost, []common.Hash{tx.Hash()})
}
- if err := expectResponse(peer.app, TxStatusMsg, reqID, testBufLimit, []light.TxStatus{expStatus}); err != nil {
+ if err := expectResponse(server.tPeer.app, TxStatusMsg, reqID, testBufLimit, []light.TxStatus{expStatus}); err != nil {
t.Errorf("transaction status mismatch")
}
}
@@ -525,16 +524,16 @@ func TestTransactionStatusLes2(t *testing.T) {
signer := types.HomesteadSigner{}
// test error status by sending an underpriced transaction
- tx0, _ := types.SignTx(types.NewTransaction(0, acc1Addr, big.NewInt(10000), params.TxGas, nil, nil), signer, testBankKey)
+ tx0, _ := types.SignTx(types.NewTransaction(0, userAddr1, big.NewInt(10000), params.TxGas, nil, nil), signer, bankKey)
test(tx0, true, light.TxStatus{Status: core.TxStatusUnknown, Error: core.ErrUnderpriced.Error()})
- tx1, _ := types.SignTx(types.NewTransaction(0, acc1Addr, big.NewInt(10000), params.TxGas, big.NewInt(100000000000), nil), signer, testBankKey)
+ tx1, _ := types.SignTx(types.NewTransaction(0, userAddr1, big.NewInt(10000), params.TxGas, big.NewInt(100000000000), nil), signer, bankKey)
test(tx1, false, light.TxStatus{Status: core.TxStatusUnknown}) // query before sending, should be unknown
test(tx1, true, light.TxStatus{Status: core.TxStatusPending}) // send valid processable tx, should return pending
test(tx1, true, light.TxStatus{Status: core.TxStatusPending}) // adding it again should not return an error
- tx2, _ := types.SignTx(types.NewTransaction(1, acc1Addr, big.NewInt(10000), params.TxGas, big.NewInt(100000000000), nil), signer, testBankKey)
- tx3, _ := types.SignTx(types.NewTransaction(2, acc1Addr, big.NewInt(10000), params.TxGas, big.NewInt(100000000000), nil), signer, testBankKey)
+ tx2, _ := types.SignTx(types.NewTransaction(1, userAddr1, big.NewInt(10000), params.TxGas, big.NewInt(100000000000), nil), signer, bankKey)
+ tx3, _ := types.SignTx(types.NewTransaction(2, userAddr1, big.NewInt(10000), params.TxGas, big.NewInt(100000000000), nil), signer, bankKey)
// send transactions in the wrong order, tx3 should be queued
test(tx3, true, light.TxStatus{Status: core.TxStatusQueued})
test(tx2, true, light.TxStatus{Status: core.TxStatusPending})
@@ -542,7 +541,7 @@ func TestTransactionStatusLes2(t *testing.T) {
test(tx3, false, light.TxStatus{Status: core.TxStatusPending})
// generate and add a block with tx1 and tx2 included
- gchain, _ := core.GenerateChain(params.TestChainConfig, chain.GetBlockByNumber(0), ethash.NewFaker(), db, 1, func(i int, block *core.BlockGen) {
+ gchain, _ := core.GenerateChain(params.TestChainConfig, chain.GetBlockByNumber(0), ethash.NewFaker(), server.db, 1, func(i int, block *core.BlockGen) {
block.AddTx(tx1)
block.AddTx(tx2)
})
@@ -561,12 +560,12 @@ func TestTransactionStatusLes2(t *testing.T) {
}
// check if their status is included now
- block1hash := rawdb.ReadCanonicalHash(db, 1)
+ block1hash := rawdb.ReadCanonicalHash(server.db, 1)
test(tx1, false, light.TxStatus{Status: core.TxStatusIncluded, Lookup: &rawdb.LegacyTxLookupEntry{BlockHash: block1hash, BlockIndex: 1, Index: 0}})
test(tx2, false, light.TxStatus{Status: core.TxStatusIncluded, Lookup: &rawdb.LegacyTxLookupEntry{BlockHash: block1hash, BlockIndex: 1, Index: 1}})
// create a reorg that rolls them back
- gchain, _ = core.GenerateChain(params.TestChainConfig, chain.GetBlockByNumber(0), ethash.NewFaker(), db, 2, func(i int, block *core.BlockGen) {})
+ gchain, _ = core.GenerateChain(params.TestChainConfig, chain.GetBlockByNumber(0), ethash.NewFaker(), server.db, 2, func(i int, block *core.BlockGen) {})
if _, err := chain.InsertChain(gchain); err != nil {
panic(err)
}
@@ -589,7 +588,7 @@ func TestStopResumeLes3(t *testing.T) {
db := rawdb.NewMemoryDatabase()
clock := &mclock.Simulated{}
testCost := testBufLimit / 10
- pm, err := newTestProtocolManager(false, 0, nil, nil, nil, db, nil, testCost, clock)
+ pm, _, err := newTestProtocolManager(false, 0, nil, nil, nil, db, nil, testCost, clock)
if err != nil {
t.Fatalf("Failed to create protocol manager: %v", err)
}