mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 23:26:44 +00:00
state sync tests on rpc methods
This commit is contained in:
parent
14ea2cafbc
commit
41134d0473
3 changed files with 86 additions and 22 deletions
|
|
@ -2074,7 +2074,10 @@ func (api *TransactionAPI) GetTransactionReceipt(ctx context.Context, hash commo
|
|||
}
|
||||
|
||||
if !found {
|
||||
tx, blockHash, blockNumber, index = rawdb.ReadBorTransaction(api.b.ChainDb(), hash)
|
||||
tx, blockHash, blockNumber, index, err = api.b.GetBorBlockTransaction(ctx, hash)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
borTx = true
|
||||
}
|
||||
|
||||
|
|
@ -2086,7 +2089,10 @@ func (api *TransactionAPI) GetTransactionReceipt(ctx context.Context, hash commo
|
|||
|
||||
if borTx {
|
||||
// Fetch bor block receipt
|
||||
receipt = rawdb.ReadBorReceipt(api.b.ChainDb(), blockHash, blockNumber, api.b.ChainConfig())
|
||||
receipt, err = api.b.GetBorBlockReceipt(ctx, blockHash)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
receipts, err := api.b.GetReceipts(ctx, blockHash)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -587,7 +587,11 @@ func (b testBackend) SendTx(ctx context.Context, signedTx *types.Transaction) er
|
|||
}
|
||||
func (b testBackend) GetTransaction(ctx context.Context, txHash common.Hash) (bool, *types.Transaction, common.Hash, uint64, uint64, error) {
|
||||
tx, blockHash, blockNumber, index := rawdb.ReadTransaction(b.db, txHash)
|
||||
return true, tx, blockHash, blockNumber, index, nil
|
||||
found := true
|
||||
if tx == nil {
|
||||
found = false
|
||||
}
|
||||
return found, tx, blockHash, blockNumber, index, nil
|
||||
}
|
||||
func (b testBackend) GetPoolTransactions() (types.Transactions, error) { panic("implement me") }
|
||||
func (b testBackend) GetPoolTransaction(txHash common.Hash) *types.Transaction { panic("implement me") }
|
||||
|
|
@ -625,7 +629,8 @@ func (b testBackend) ServiceFilter(ctx context.Context, session *bloombits.Match
|
|||
|
||||
// GetBorBlockTransaction returns bor block tx
|
||||
func (b testBackend) GetBorBlockTransaction(ctx context.Context, hash common.Hash) (*types.Transaction, common.Hash, uint64, uint64, error) {
|
||||
panic("implement me")
|
||||
tx, blockHash, blockNumber, index := rawdb.ReadBorTransaction(b.ChainDb(), hash)
|
||||
return tx, blockHash, blockNumber, index, nil
|
||||
}
|
||||
|
||||
func (b testBackend) GetBorBlockTransactionWithBlockHash(ctx context.Context, txHash common.Hash, blockHash common.Hash) (*types.Transaction, common.Hash, uint64, uint64, error) {
|
||||
|
|
@ -1935,7 +1940,7 @@ func setupReceiptBackend(t *testing.T, genBlocks int) (*testBackend, []common.Ha
|
|||
},
|
||||
}
|
||||
signer = types.LatestSignerForChainID(params.TestChainConfig.ChainID)
|
||||
txHashes = make([]common.Hash, genBlocks)
|
||||
txHashes = make([]common.Hash, genBlocks+1)
|
||||
)
|
||||
|
||||
// Set the terminal total difficulty in the config
|
||||
|
|
@ -1997,9 +2002,33 @@ func setupReceiptBackend(t *testing.T, genBlocks int) (*testBackend, []common.Ha
|
|||
txHashes[i] = tx.Hash()
|
||||
}
|
||||
})
|
||||
|
||||
txHashes[genBlocks] = mockStateSyncTxOnCurrentBlock(t, backend)
|
||||
|
||||
return backend, txHashes
|
||||
}
|
||||
|
||||
func mockStateSyncTxOnCurrentBlock(t *testing.T, backend *testBackend) common.Hash {
|
||||
// State Sync Tx Setup
|
||||
var stateSyncLogs []*types.Log
|
||||
block, err := backend.BlockByHash(context.Background(), backend.CurrentBlock().Hash())
|
||||
if err != nil {
|
||||
t.Errorf("failed to get current block: %v", err)
|
||||
}
|
||||
|
||||
types.DeriveFieldsForBorLogs(stateSyncLogs, block.Hash(), block.NumberU64(), 0, 0)
|
||||
|
||||
// Write bor receipt
|
||||
rawdb.WriteBorReceipt(backend.ChainDb(), block.Hash(), block.NumberU64(), &types.ReceiptForStorage{
|
||||
Status: types.ReceiptStatusSuccessful, // make receipt status successful
|
||||
Logs: stateSyncLogs,
|
||||
})
|
||||
|
||||
// Write bor tx reverse lookup
|
||||
rawdb.WriteBorTxLookupEntry(backend.ChainDb(), block.Hash(), block.NumberU64())
|
||||
return types.GetDerivedBorTxHash(types.BorReceiptKey(block.NumberU64(), block.Hash()))
|
||||
}
|
||||
|
||||
func TestRPCGetTransactionReceipt(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
|
@ -2052,6 +2081,11 @@ func TestRPCGetTransactionReceipt(t *testing.T) {
|
|||
txHash: txHashes[5],
|
||||
file: "blob-tx",
|
||||
},
|
||||
// 8. state sync tx found
|
||||
{
|
||||
txHash: txHashes[6],
|
||||
file: "state-sync-tx",
|
||||
},
|
||||
}
|
||||
|
||||
for i, tt := range testSuite {
|
||||
|
|
@ -2103,7 +2137,7 @@ func TestRPCGetTransactionReceiptsByBlock(t *testing.T) {
|
|||
contract: {Balance: big.NewInt(params.Ether), Code: common.FromHex("0x608060405234801561001057600080fd5b506004361061002b5760003560e01c8063a9059cbb14610030575b600080fd5b61004a6004803603810190610045919061016a565b610060565b60405161005791906101c5565b60405180910390f35b60008273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040516100bf91906101ef565b60405180910390a36001905092915050565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000610101826100d6565b9050919050565b610111816100f6565b811461011c57600080fd5b50565b60008135905061012e81610108565b92915050565b6000819050919050565b61014781610134565b811461015257600080fd5b50565b6000813590506101648161013e565b92915050565b60008060408385031215610181576101806100d1565b5b600061018f8582860161011f565b92505060206101a085828601610155565b9150509250929050565b60008115159050919050565b6101bf816101aa565b82525050565b60006020820190506101da60008301846101b6565b92915050565b6101e981610134565b82525050565b600060208201905061020460008301846101e0565b9291505056fea2646970667358221220b469033f4b77b9565ee84e0a2f04d496b18160d26034d54f9487e57788fd36d564736f6c63430008120033")},
|
||||
},
|
||||
}
|
||||
genTxs = 5
|
||||
genTxs = 6
|
||||
genBlocks = 1
|
||||
signer = types.LatestSignerForChainID(params.TestChainConfig.ChainID)
|
||||
txHashes = make([]common.Hash, 0, genTxs)
|
||||
|
|
@ -2149,6 +2183,11 @@ func TestRPCGetTransactionReceiptsByBlock(t *testing.T) {
|
|||
}
|
||||
})
|
||||
|
||||
txHashes = append(txHashes, mockStateSyncTxOnCurrentBlock(t, backend))
|
||||
|
||||
// map sprint 0 to block 1
|
||||
backend.ChainConfig().Bor.Sprint["0"] = 1
|
||||
|
||||
api := NewBlockChainAPI(backend)
|
||||
blockHashes := make([]common.Hash, genBlocks+1)
|
||||
ctx := context.Background()
|
||||
|
|
@ -2315,6 +2354,26 @@ func TestRPCGetTransactionReceiptsByBlock(t *testing.T) {
|
|||
"type": "0x1"
|
||||
}`,
|
||||
},
|
||||
// 5. state sync tx
|
||||
{
|
||||
txHash: txHashes[5],
|
||||
want: `{
|
||||
"blockHash": "0x1728b788dfe51e507d25f14f01414b5a17f807953c13833811d2afae1982b53b",
|
||||
"blockNumber": "0x1",
|
||||
"contractAddress": null,
|
||||
"cumulativeGasUsed": "0x0",
|
||||
"effectiveGasPrice": "0x0",
|
||||
"from": "0x0000000000000000000000000000000000000000",
|
||||
"gasUsed": "0x0",
|
||||
"logs": [],
|
||||
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
||||
"status": "0x1",
|
||||
"to": "0x0000000000000000000000000000000000000000",
|
||||
"transactionHash": "0xba46f68d5c3729ac3fb672fec579fc2cad543bc9edf5b2d47d7c6636ac2fbec9",
|
||||
"transactionIndex": "0x5",
|
||||
"type": "0x0"
|
||||
}`,
|
||||
},
|
||||
}
|
||||
|
||||
receipts, err := api.GetTransactionReceiptsByBlock(context.Background(), blockNrOrHash)
|
||||
|
|
|
|||
|
|
@ -1,17 +1,16 @@
|
|||
{
|
||||
"blockHash": "0x4d780246cde52e535f40603d47af8fa1aea807dd3065e1acd97127bea0922b3e",
|
||||
"blockNumber": "0x6",
|
||||
"contractAddress": null,
|
||||
"cumulativeGasUsed": "0xe01c",
|
||||
"effectiveGasPrice": "0x1ecb3fb4",
|
||||
"from": "0x703c4b2bd70c169f5717101caee543299fc946c7",
|
||||
"gasUsed": "0xe01c",
|
||||
"logs": [],
|
||||
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
||||
"status": "0x1",
|
||||
"to": null,
|
||||
"transactionHash": "0xb5a1148819cfdfff9bfe70035524fec940eb735d89b76960b97751d01ae2a9f2",
|
||||
"transactionIndex": "0x0",
|
||||
"type": "0x1"
|
||||
}
|
||||
|
||||
"blockHash": "0x4446b1498499cab37cfec330097fadf285c703444d431756940528d32fe0e97b",
|
||||
"blockNumber": "0x6",
|
||||
"contractAddress": null,
|
||||
"cumulativeGasUsed": "0x0",
|
||||
"effectiveGasPrice": "0x0",
|
||||
"from": "0x0000000000000000000000000000000000000000",
|
||||
"gasUsed": "0x0",
|
||||
"logs": [],
|
||||
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
||||
"status": "0x1",
|
||||
"to": "0x0000000000000000000000000000000000000000",
|
||||
"transactionHash": "0xfff9ab54386f3f5c5817e27cf1c8249968c13578c027389c021172d0568ebe12",
|
||||
"transactionIndex": "0x1",
|
||||
"type": "0x0"
|
||||
}
|
||||
Loading…
Reference in a new issue