|
|
|
@ -443,7 +443,7 @@ func TestTransactionStatusLes2(t *testing.T) { |
|
|
|
|
|
|
|
|
|
var reqID uint64 |
|
|
|
|
|
|
|
|
|
test := func(tx *types.Transaction, send bool, expStatus txStatus) { |
|
|
|
|
test := func(tx *types.Transaction, send bool, expStatus light.TxStatus) { |
|
|
|
|
reqID++ |
|
|
|
|
if send { |
|
|
|
|
cost := peer.GetRequestCost(SendTxV2Msg, 1) |
|
|
|
@ -452,7 +452,7 @@ func TestTransactionStatusLes2(t *testing.T) { |
|
|
|
|
cost := peer.GetRequestCost(GetTxStatusMsg, 1) |
|
|
|
|
sendRequest(peer.app, GetTxStatusMsg, reqID, cost, []common.Hash{tx.Hash()}) |
|
|
|
|
} |
|
|
|
|
if err := expectResponse(peer.app, TxStatusMsg, reqID, testBufLimit, []txStatus{expStatus}); err != nil { |
|
|
|
|
if err := expectResponse(peer.app, TxStatusMsg, reqID, testBufLimit, []light.TxStatus{expStatus}); err != nil { |
|
|
|
|
t.Errorf("transaction status mismatch") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -461,20 +461,20 @@ func TestTransactionStatusLes2(t *testing.T) { |
|
|
|
|
|
|
|
|
|
// test error status by sending an underpriced transaction
|
|
|
|
|
tx0, _ := types.SignTx(types.NewTransaction(0, acc1Addr, big.NewInt(10000), params.TxGas, nil, nil), signer, testBankKey) |
|
|
|
|
test(tx0, true, txStatus{Status: core.TxStatusUnknown, Error: core.ErrUnderpriced.Error()}) |
|
|
|
|
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) |
|
|
|
|
test(tx1, false, txStatus{Status: core.TxStatusUnknown}) // query before sending, should be unknown
|
|
|
|
|
test(tx1, true, txStatus{Status: core.TxStatusPending}) // send valid processable tx, should return pending
|
|
|
|
|
test(tx1, true, txStatus{Status: core.TxStatusPending}) // adding it again should not return an error
|
|
|
|
|
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) |
|
|
|
|
// send transactions in the wrong order, tx3 should be queued
|
|
|
|
|
test(tx3, true, txStatus{Status: core.TxStatusQueued}) |
|
|
|
|
test(tx2, true, txStatus{Status: core.TxStatusPending}) |
|
|
|
|
test(tx3, true, light.TxStatus{Status: core.TxStatusQueued}) |
|
|
|
|
test(tx2, true, light.TxStatus{Status: core.TxStatusPending}) |
|
|
|
|
// query again, now tx3 should be pending too
|
|
|
|
|
test(tx3, false, txStatus{Status: core.TxStatusPending}) |
|
|
|
|
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) { |
|
|
|
@ -497,8 +497,8 @@ func TestTransactionStatusLes2(t *testing.T) { |
|
|
|
|
|
|
|
|
|
// check if their status is included now
|
|
|
|
|
block1hash := rawdb.ReadCanonicalHash(db, 1) |
|
|
|
|
test(tx1, false, txStatus{Status: core.TxStatusIncluded, Lookup: &rawdb.LegacyTxLookupEntry{BlockHash: block1hash, BlockIndex: 1, Index: 0}}) |
|
|
|
|
test(tx2, false, txStatus{Status: core.TxStatusIncluded, Lookup: &rawdb.LegacyTxLookupEntry{BlockHash: block1hash, BlockIndex: 1, Index: 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) {}) |
|
|
|
@ -516,6 +516,6 @@ func TestTransactionStatusLes2(t *testing.T) { |
|
|
|
|
t.Fatalf("pending count mismatch: have %d, want 3", pending) |
|
|
|
|
} |
|
|
|
|
// check if their status is pending again
|
|
|
|
|
test(tx1, false, txStatus{Status: core.TxStatusPending}) |
|
|
|
|
test(tx2, false, txStatus{Status: core.TxStatusPending}) |
|
|
|
|
test(tx1, false, light.TxStatus{Status: core.TxStatusPending}) |
|
|
|
|
test(tx2, false, light.TxStatus{Status: core.TxStatusPending}) |
|
|
|
|
} |
|
|
|
|