mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-19 21:31:37 +00:00
This commit is contained in:
parent
0ef3edf183
commit
67df2bcb29
2 changed files with 158 additions and 6 deletions
|
|
@ -1698,6 +1698,11 @@ func newRPCTransaction(tx *types.Transaction, blockHash common.Hash, blockNumber
|
|||
result.TransactionIndex = (*hexutil.Uint64)(&index)
|
||||
}
|
||||
switch tx.Type() {
|
||||
case types.LegacyTxType:
|
||||
// if a legacy transaction has an EIP-155 chain id, include it explicitly
|
||||
if id := tx.ChainId(); id.Sign() > 0 {
|
||||
result.ChainID = (*hexutil.Big)(id)
|
||||
}
|
||||
case types.AccessListTxType:
|
||||
al := tx.AccessList()
|
||||
result.Accesses = &al
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import (
|
|||
"github.com/XinFinOrg/XDPoSChain/common"
|
||||
"github.com/XinFinOrg/XDPoSChain/core/types"
|
||||
"github.com/XinFinOrg/XDPoSChain/params"
|
||||
"github.com/stretchr/testify/require"
|
||||
"golang.org/x/crypto/sha3"
|
||||
)
|
||||
|
||||
|
|
@ -92,20 +93,168 @@ func TestRPCMarshalBlock(t *testing.T) {
|
|||
{
|
||||
inclTx: false,
|
||||
fullTx: false,
|
||||
want: `{"difficulty":"0x0","extraData":"0x","gasLimit":"0x0","gasUsed":"0x0","hash":"0x2cb4e4b5b5be5a2520377e87e8d7d2cf83fc0783fa6518d67b9606d3c5317b50","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","miner":"0x0000000000000000000000000000000000000000","mixHash":"0x0000000000000000000000000000000000000000000000000000000000000000","nonce":"0x0000000000000000","number":"0x64","parentHash":"0x0000000000000000000000000000000000000000000000000000000000000000","penalties":"0x","receiptsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347","size":"0x299","stateRoot":"0x0000000000000000000000000000000000000000000000000000000000000000","timestamp":"0x0","transactionsRoot":"0x661a9febcfa8f1890af549b874faf9fa274aede26ef489d9db0b25daa569450e","uncles":[],"validator":"0x","validators":"0x"}`,
|
||||
want: `{
|
||||
"difficulty":"0x0",
|
||||
"extraData":"0x",
|
||||
"gasLimit":"0x0",
|
||||
"gasUsed":"0x0",
|
||||
"hash":"0x2cb4e4b5b5be5a2520377e87e8d7d2cf83fc0783fa6518d67b9606d3c5317b50",
|
||||
"logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
||||
"miner":"0x0000000000000000000000000000000000000000",
|
||||
"mixHash":"0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||
"nonce":"0x0000000000000000",
|
||||
"number":"0x64",
|
||||
"parentHash":"0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||
"penalties":"0x",
|
||||
"receiptsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
|
||||
"sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
|
||||
"size":"0x299",
|
||||
"stateRoot":"0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||
"timestamp":"0x0",
|
||||
"transactionsRoot":"0x661a9febcfa8f1890af549b874faf9fa274aede26ef489d9db0b25daa569450e",
|
||||
"uncles":[],
|
||||
"validator":"0x",
|
||||
"validators":"0x"
|
||||
}`,
|
||||
},
|
||||
// only tx hashes
|
||||
{
|
||||
inclTx: true,
|
||||
fullTx: false,
|
||||
want: `{"difficulty":"0x0","extraData":"0x","gasLimit":"0x0","gasUsed":"0x0","hash":"0x2cb4e4b5b5be5a2520377e87e8d7d2cf83fc0783fa6518d67b9606d3c5317b50","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","miner":"0x0000000000000000000000000000000000000000","mixHash":"0x0000000000000000000000000000000000000000000000000000000000000000","nonce":"0x0000000000000000","number":"0x64","parentHash":"0x0000000000000000000000000000000000000000000000000000000000000000","penalties":"0x","receiptsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347","size":"0x299","stateRoot":"0x0000000000000000000000000000000000000000000000000000000000000000","timestamp":"0x0","transactions":["0x7d39df979e34172322c64983a9ad48302c2b889e55bda35324afecf043a77605","0x9bba4c34e57c875ff57ac8d172805a26ae912006985395dc1bdf8f44140a7bf4","0x98909ea1ff040da6be56bc4231d484de1414b3c1dac372d69293a4beb9032cb5","0x12e1f81207b40c3bdcc13c0ee18f5f86af6d31754d57a0ea1b0d4cfef21abef1"],"transactionsRoot":"0x661a9febcfa8f1890af549b874faf9fa274aede26ef489d9db0b25daa569450e","uncles":[],"validator":"0x","validators":"0x"}`,
|
||||
want: `{
|
||||
"difficulty":"0x0",
|
||||
"extraData":"0x",
|
||||
"gasLimit":"0x0",
|
||||
"gasUsed":"0x0",
|
||||
"hash":"0x2cb4e4b5b5be5a2520377e87e8d7d2cf83fc0783fa6518d67b9606d3c5317b50",
|
||||
"logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
||||
"miner":"0x0000000000000000000000000000000000000000",
|
||||
"mixHash":"0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||
"nonce":"0x0000000000000000",
|
||||
"number":"0x64",
|
||||
"parentHash":"0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||
"penalties":"0x",
|
||||
"receiptsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
|
||||
"sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
|
||||
"size":"0x299",
|
||||
"stateRoot":"0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||
"timestamp":"0x0",
|
||||
"transactions": [
|
||||
"0x7d39df979e34172322c64983a9ad48302c2b889e55bda35324afecf043a77605",
|
||||
"0x9bba4c34e57c875ff57ac8d172805a26ae912006985395dc1bdf8f44140a7bf4",
|
||||
"0x98909ea1ff040da6be56bc4231d484de1414b3c1dac372d69293a4beb9032cb5",
|
||||
"0x12e1f81207b40c3bdcc13c0ee18f5f86af6d31754d57a0ea1b0d4cfef21abef1"
|
||||
],
|
||||
"transactionsRoot":"0x661a9febcfa8f1890af549b874faf9fa274aede26ef489d9db0b25daa569450e",
|
||||
"uncles":[],
|
||||
"validator":"0x",
|
||||
"validators":"0x"
|
||||
}`,
|
||||
},
|
||||
|
||||
// full tx details
|
||||
{
|
||||
inclTx: true,
|
||||
fullTx: true,
|
||||
want: `{"difficulty":"0x0","extraData":"0x","gasLimit":"0x0","gasUsed":"0x0","hash":"0x2cb4e4b5b5be5a2520377e87e8d7d2cf83fc0783fa6518d67b9606d3c5317b50","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","miner":"0x0000000000000000000000000000000000000000","mixHash":"0x0000000000000000000000000000000000000000000000000000000000000000","nonce":"0x0000000000000000","number":"0x64","parentHash":"0x0000000000000000000000000000000000000000000000000000000000000000","penalties":"0x","receiptsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347","size":"0x299","stateRoot":"0x0000000000000000000000000000000000000000000000000000000000000000","timestamp":"0x0","transactions":[{"blockHash":"0x2cb4e4b5b5be5a2520377e87e8d7d2cf83fc0783fa6518d67b9606d3c5317b50","blockNumber":"0x64","from":"0x0000000000000000000000000000000000000000","gas":"0x457","gasPrice":"0x2b67","hash":"0x7d39df979e34172322c64983a9ad48302c2b889e55bda35324afecf043a77605","input":"0x111111","nonce":"0x1","to":"0x0000000000000000000000000000000000000011","transactionIndex":"0x0","value":"0x6f","type":"0x1","accessList":[],"chainId":"0x539","v":"0x0","r":"0x0","s":"0x0"},{"blockHash":"0x2cb4e4b5b5be5a2520377e87e8d7d2cf83fc0783fa6518d67b9606d3c5317b50","blockNumber":"0x64","from":"0x0000000000000000000000000000000000000000","gas":"0x457","gasPrice":"0x2b67","hash":"0x9bba4c34e57c875ff57ac8d172805a26ae912006985395dc1bdf8f44140a7bf4","input":"0x111111","nonce":"0x2","to":"0x0000000000000000000000000000000000000011","transactionIndex":"0x1","value":"0x6f","type":"0x0","v":"0x0","r":"0x0","s":"0x0"},{"blockHash":"0x2cb4e4b5b5be5a2520377e87e8d7d2cf83fc0783fa6518d67b9606d3c5317b50","blockNumber":"0x64","from":"0x0000000000000000000000000000000000000000","gas":"0x457","gasPrice":"0x2b67","hash":"0x98909ea1ff040da6be56bc4231d484de1414b3c1dac372d69293a4beb9032cb5","input":"0x111111","nonce":"0x3","to":"0x0000000000000000000000000000000000000011","transactionIndex":"0x2","value":"0x6f","type":"0x1","accessList":[],"chainId":"0x539","v":"0x0","r":"0x0","s":"0x0"},{"blockHash":"0x2cb4e4b5b5be5a2520377e87e8d7d2cf83fc0783fa6518d67b9606d3c5317b50","blockNumber":"0x64","from":"0x0000000000000000000000000000000000000000","gas":"0x457","gasPrice":"0x2b67","hash":"0x12e1f81207b40c3bdcc13c0ee18f5f86af6d31754d57a0ea1b0d4cfef21abef1","input":"0x111111","nonce":"0x4","to":"0x0000000000000000000000000000000000000011","transactionIndex":"0x3","value":"0x6f","type":"0x0","v":"0x0","r":"0x0","s":"0x0"}],"transactionsRoot":"0x661a9febcfa8f1890af549b874faf9fa274aede26ef489d9db0b25daa569450e","uncles":[],"validator":"0x","validators":"0x"}`,
|
||||
want: `{
|
||||
"difficulty":"0x0",
|
||||
"extraData":"0x",
|
||||
"gasLimit":"0x0",
|
||||
"gasUsed":"0x0",
|
||||
"hash":"0x2cb4e4b5b5be5a2520377e87e8d7d2cf83fc0783fa6518d67b9606d3c5317b50",
|
||||
"logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
||||
"miner":"0x0000000000000000000000000000000000000000",
|
||||
"mixHash":"0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||
"nonce":"0x0000000000000000",
|
||||
"number":"0x64",
|
||||
"parentHash":"0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||
"penalties":"0x",
|
||||
"receiptsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
|
||||
"sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
|
||||
"size":"0x299",
|
||||
"stateRoot":"0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||
"timestamp":"0x0",
|
||||
"transactions": [
|
||||
{
|
||||
"blockHash":"0x2cb4e4b5b5be5a2520377e87e8d7d2cf83fc0783fa6518d67b9606d3c5317b50",
|
||||
"blockNumber":"0x64",
|
||||
"from":"0x0000000000000000000000000000000000000000",
|
||||
"gas":"0x457",
|
||||
"gasPrice":"0x2b67",
|
||||
"hash":"0x7d39df979e34172322c64983a9ad48302c2b889e55bda35324afecf043a77605",
|
||||
"input":"0x111111",
|
||||
"nonce":"0x1",
|
||||
"to":"0x0000000000000000000000000000000000000011",
|
||||
"transactionIndex":"0x0",
|
||||
"value":"0x6f",
|
||||
"type":"0x1",
|
||||
"accessList":[],
|
||||
"chainId": "0x539",
|
||||
"chainId":"0x539",
|
||||
"v":"0x0",
|
||||
"r":"0x0",
|
||||
"s":"0x0"
|
||||
},
|
||||
{
|
||||
"blockHash":"0x2cb4e4b5b5be5a2520377e87e8d7d2cf83fc0783fa6518d67b9606d3c5317b50",
|
||||
"blockNumber":"0x64",
|
||||
"from":"0x0000000000000000000000000000000000000000",
|
||||
"gas":"0x457",
|
||||
"gasPrice":"0x2b67","hash":"0x9bba4c34e57c875ff57ac8d172805a26ae912006985395dc1bdf8f44140a7bf4",
|
||||
"input":"0x111111",
|
||||
"nonce":"0x2",
|
||||
"to":"0x0000000000000000000000000000000000000011",
|
||||
"transactionIndex":"0x1",
|
||||
"value":"0x6f",
|
||||
"type":"0x0",
|
||||
"chainId": "0x7fffffffffffffee",
|
||||
"v":"0x0",
|
||||
"r":"0x0",
|
||||
"s":"0x0"
|
||||
},
|
||||
{
|
||||
"blockHash":"0x2cb4e4b5b5be5a2520377e87e8d7d2cf83fc0783fa6518d67b9606d3c5317b50",
|
||||
"blockNumber":"0x64",
|
||||
"from":"0x0000000000000000000000000000000000000000",
|
||||
"gas":"0x457",
|
||||
"gasPrice":"0x2b67",
|
||||
"hash":"0x98909ea1ff040da6be56bc4231d484de1414b3c1dac372d69293a4beb9032cb5",
|
||||
"input":"0x111111",
|
||||
"nonce":"0x3",
|
||||
"to":"0x0000000000000000000000000000000000000011",
|
||||
"transactionIndex":"0x2",
|
||||
"value":"0x6f",
|
||||
"type":"0x1",
|
||||
"accessList":[],
|
||||
"chainId":"0x539",
|
||||
"v":"0x0",
|
||||
"r":"0x0",
|
||||
"s":"0x0"
|
||||
},
|
||||
{
|
||||
"blockHash":"0x2cb4e4b5b5be5a2520377e87e8d7d2cf83fc0783fa6518d67b9606d3c5317b50",
|
||||
"blockNumber":"0x64",
|
||||
"from":"0x0000000000000000000000000000000000000000",
|
||||
"gas":"0x457",
|
||||
"gasPrice":"0x2b67",
|
||||
"hash":"0x12e1f81207b40c3bdcc13c0ee18f5f86af6d31754d57a0ea1b0d4cfef21abef1",
|
||||
"input":"0x111111",
|
||||
"nonce":"0x4",
|
||||
"to":"0x0000000000000000000000000000000000000011",
|
||||
"transactionIndex":"0x3",
|
||||
"value":"0x6f",
|
||||
"type":"0x0",
|
||||
"chainId": "0x7fffffffffffffee",
|
||||
"v":"0x0",
|
||||
"r":"0x0",
|
||||
"s":"0x0"
|
||||
}
|
||||
],
|
||||
"transactionsRoot":"0x661a9febcfa8f1890af549b874faf9fa274aede26ef489d9db0b25daa569450e",
|
||||
"uncles":[],
|
||||
"validator":"0x",
|
||||
"validators":"0x"
|
||||
}`,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -116,8 +265,6 @@ func TestRPCMarshalBlock(t *testing.T) {
|
|||
t.Errorf("test %d: json marshal error: %v", i, err)
|
||||
continue
|
||||
}
|
||||
if have := string(out); have != tc.want {
|
||||
t.Errorf("test %d:\nwant: %s\nhave: %s", i, tc.want, have)
|
||||
}
|
||||
require.JSONEqf(t, tc.want, string(out), "test %d", i)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue