2020-10-20 14:42:09 +00:00
|
|
|
// VulcanizeDB
|
|
|
|
// Copyright © 2019 Vulcanize
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2020-10-20 20:33:18 +00:00
|
|
|
package test_helpers
|
2020-10-20 14:42:09 +00:00
|
|
|
|
|
|
|
import (
|
2021-07-27 12:07:50 +00:00
|
|
|
"bytes"
|
2020-10-20 14:42:09 +00:00
|
|
|
"crypto/ecdsa"
|
|
|
|
"crypto/elliptic"
|
|
|
|
"crypto/rand"
|
2021-02-24 16:50:26 +00:00
|
|
|
"math/big"
|
|
|
|
|
2020-10-20 14:42:09 +00:00
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
|
|
"github.com/ethereum/go-ethereum/core/types"
|
|
|
|
"github.com/ethereum/go-ethereum/crypto"
|
|
|
|
"github.com/ethereum/go-ethereum/params"
|
|
|
|
"github.com/ethereum/go-ethereum/rlp"
|
2022-03-11 04:32:22 +00:00
|
|
|
"github.com/ethereum/go-ethereum/statediff/indexer/ipld"
|
2021-08-31 11:32:01 +00:00
|
|
|
"github.com/ethereum/go-ethereum/statediff/indexer/models"
|
|
|
|
"github.com/ethereum/go-ethereum/statediff/indexer/shared"
|
2022-03-11 04:32:22 +00:00
|
|
|
testhelpers "github.com/ethereum/go-ethereum/statediff/test_helpers"
|
2021-08-31 11:32:01 +00:00
|
|
|
sdtypes "github.com/ethereum/go-ethereum/statediff/types"
|
|
|
|
"github.com/ethereum/go-ethereum/trie"
|
2021-06-03 16:49:48 +00:00
|
|
|
blocks "github.com/ipfs/go-block-format"
|
2020-10-20 14:42:09 +00:00
|
|
|
"github.com/multiformats/go-multihash"
|
|
|
|
log "github.com/sirupsen/logrus"
|
2020-10-20 20:33:18 +00:00
|
|
|
|
2022-05-20 13:16:36 +00:00
|
|
|
"github.com/vulcanize/ipld-eth-server/v4/pkg/eth"
|
2020-10-20 14:42:09 +00:00
|
|
|
)
|
|
|
|
|
2020-10-20 20:33:18 +00:00
|
|
|
// Test variables
|
2020-10-20 14:42:09 +00:00
|
|
|
var (
|
|
|
|
// block data
|
2021-09-15 11:43:12 +00:00
|
|
|
BlockNumber = big.NewInt(1)
|
2020-10-20 14:42:09 +00:00
|
|
|
MockHeader = types.Header{
|
|
|
|
Time: 0,
|
|
|
|
Number: new(big.Int).Set(BlockNumber),
|
|
|
|
Root: common.HexToHash("0x0"),
|
|
|
|
TxHash: common.HexToHash("0x0"),
|
|
|
|
ReceiptHash: common.HexToHash("0x0"),
|
|
|
|
Difficulty: big.NewInt(5000000),
|
|
|
|
Extra: []byte{},
|
|
|
|
}
|
2021-07-27 12:07:50 +00:00
|
|
|
MockTransactions, MockReceipts, SenderAddr = createLegacyTransactionsAndReceipts()
|
2020-10-29 19:59:09 +00:00
|
|
|
MockUncles = []*types.Header{
|
|
|
|
{
|
|
|
|
Time: 1,
|
|
|
|
Number: new(big.Int).Add(BlockNumber, big.NewInt(1)),
|
|
|
|
Root: common.HexToHash("0x1"),
|
|
|
|
TxHash: common.HexToHash("0x1"),
|
|
|
|
ReceiptHash: common.HexToHash("0x1"),
|
|
|
|
Difficulty: big.NewInt(500001),
|
|
|
|
Extra: []byte{},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Time: 2,
|
|
|
|
Number: new(big.Int).Add(BlockNumber, big.NewInt(2)),
|
|
|
|
Root: common.HexToHash("0x2"),
|
|
|
|
TxHash: common.HexToHash("0x2"),
|
|
|
|
ReceiptHash: common.HexToHash("0x2"),
|
|
|
|
Difficulty: big.NewInt(500002),
|
|
|
|
Extra: []byte{},
|
|
|
|
},
|
|
|
|
}
|
2020-11-12 21:33:06 +00:00
|
|
|
ReceiptsRlp, _ = rlp.EncodeToBytes(MockReceipts)
|
2021-06-03 16:49:48 +00:00
|
|
|
MockBlock = createNewBlock(&MockHeader, MockTransactions, MockUncles, MockReceipts, new(trie.Trie))
|
2020-11-12 21:33:06 +00:00
|
|
|
MockHeaderRlp, _ = rlp.EncodeToBytes(MockBlock.Header())
|
|
|
|
MockChildHeader = types.Header{
|
|
|
|
Time: 0,
|
|
|
|
Number: new(big.Int).Add(BlockNumber, common.Big1),
|
|
|
|
Root: common.HexToHash("0x0"),
|
|
|
|
TxHash: common.HexToHash("0x0"),
|
|
|
|
ReceiptHash: common.HexToHash("0x0"),
|
|
|
|
Difficulty: big.NewInt(5000001),
|
|
|
|
Extra: []byte{},
|
|
|
|
ParentHash: MockBlock.Header().Hash(),
|
|
|
|
}
|
2021-02-19 20:23:45 +00:00
|
|
|
MockChild = types.NewBlock(&MockChildHeader, MockTransactions, MockUncles, MockReceipts, new(trie.Trie))
|
2020-11-12 21:33:06 +00:00
|
|
|
MockChildRlp, _ = rlp.EncodeToBytes(MockChild.Header())
|
2020-10-29 19:59:09 +00:00
|
|
|
Address = common.HexToAddress("0xaE9BEa628c4Ce503DcFD7E305CaB4e29E7476592")
|
|
|
|
AnotherAddress = common.HexToAddress("0xaE9BEa628c4Ce503DcFD7E305CaB4e29E7476593")
|
2021-08-20 07:37:11 +00:00
|
|
|
AnotherAddress1 = common.HexToAddress("0xaE9BEa628c4Ce503DcFD7E305CaB4e29E7476594")
|
2021-09-01 07:02:28 +00:00
|
|
|
AnotherAddress2 = common.HexToAddress("0xaE9BEa628c4Ce503DcFD7E305CaB4e29E7476596")
|
2020-10-29 19:59:09 +00:00
|
|
|
ContractAddress = crypto.CreateAddress(SenderAddr, MockTransactions[2].Nonce())
|
|
|
|
ContractHash = crypto.Keccak256Hash(ContractAddress.Bytes()).String()
|
|
|
|
MockContractByteCode = []byte{0, 1, 2, 3, 4, 5}
|
|
|
|
mockTopic11 = common.HexToHash("0x04")
|
|
|
|
mockTopic12 = common.HexToHash("0x06")
|
|
|
|
mockTopic21 = common.HexToHash("0x05")
|
|
|
|
mockTopic22 = common.HexToHash("0x07")
|
2021-08-20 07:37:11 +00:00
|
|
|
mockTopic31 = common.HexToHash("0x08")
|
|
|
|
mockTopic41 = common.HexToHash("0x09")
|
|
|
|
mockTopic42 = common.HexToHash("0x0a")
|
|
|
|
mockTopic43 = common.HexToHash("0x0b")
|
|
|
|
mockTopic51 = common.HexToHash("0x0c")
|
2021-09-01 07:02:28 +00:00
|
|
|
mockTopic61 = common.HexToHash("0x0d")
|
2020-10-29 19:59:09 +00:00
|
|
|
MockLog1 = &types.Log{
|
2021-06-03 16:49:48 +00:00
|
|
|
Address: Address,
|
|
|
|
Topics: []common.Hash{mockTopic11, mockTopic12},
|
|
|
|
Data: []byte{},
|
|
|
|
BlockNumber: BlockNumber.Uint64(),
|
|
|
|
TxIndex: 0,
|
|
|
|
Index: 0,
|
2020-10-20 14:42:09 +00:00
|
|
|
}
|
|
|
|
MockLog2 = &types.Log{
|
2021-06-03 16:49:48 +00:00
|
|
|
Address: AnotherAddress,
|
|
|
|
Topics: []common.Hash{mockTopic21, mockTopic22},
|
|
|
|
Data: []byte{},
|
|
|
|
BlockNumber: BlockNumber.Uint64(),
|
|
|
|
TxIndex: 1,
|
|
|
|
Index: 1,
|
2020-10-20 14:42:09 +00:00
|
|
|
}
|
2021-08-20 07:37:11 +00:00
|
|
|
MockLog3 = &types.Log{
|
|
|
|
Address: AnotherAddress1,
|
|
|
|
Topics: []common.Hash{mockTopic31},
|
|
|
|
Data: []byte{},
|
|
|
|
BlockNumber: BlockNumber.Uint64(),
|
2021-09-01 07:02:28 +00:00
|
|
|
TxIndex: 2,
|
|
|
|
Index: 2,
|
2021-08-20 07:37:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MockLog4 = &types.Log{
|
|
|
|
Address: AnotherAddress1,
|
|
|
|
Topics: []common.Hash{mockTopic41, mockTopic42, mockTopic43},
|
|
|
|
Data: []byte{},
|
|
|
|
BlockNumber: BlockNumber.Uint64(),
|
2021-09-01 07:02:28 +00:00
|
|
|
TxIndex: 2,
|
|
|
|
Index: 3,
|
2021-08-20 07:37:11 +00:00
|
|
|
}
|
|
|
|
MockLog5 = &types.Log{
|
|
|
|
Address: AnotherAddress1,
|
|
|
|
Topics: []common.Hash{mockTopic51},
|
|
|
|
Data: []byte{},
|
|
|
|
BlockNumber: BlockNumber.Uint64(),
|
2021-09-01 07:02:28 +00:00
|
|
|
TxIndex: 2,
|
|
|
|
Index: 4,
|
|
|
|
}
|
|
|
|
MockLog6 = &types.Log{
|
|
|
|
Address: AnotherAddress2,
|
|
|
|
Topics: []common.Hash{mockTopic61},
|
|
|
|
Data: []byte{},
|
|
|
|
BlockNumber: BlockNumber.Uint64(),
|
|
|
|
TxIndex: 3,
|
|
|
|
Index: 5,
|
2021-08-20 07:37:11 +00:00
|
|
|
}
|
2021-06-03 16:49:48 +00:00
|
|
|
|
2021-07-27 12:07:50 +00:00
|
|
|
Tx1 = GetTxnRlp(0, MockTransactions)
|
|
|
|
Tx2 = GetTxnRlp(1, MockTransactions)
|
|
|
|
Tx3 = GetTxnRlp(2, MockTransactions)
|
2021-09-01 07:02:28 +00:00
|
|
|
Tx4 = GetTxnRlp(3, MockTransactions)
|
2021-07-27 12:07:50 +00:00
|
|
|
|
2021-09-20 10:31:27 +00:00
|
|
|
rctCIDs, rctIPLDData, _ = eth.GetRctLeafNodeData(MockReceipts)
|
|
|
|
HeaderCID, _ = ipld.RawdataToCid(ipld.MEthHeader, MockHeaderRlp, multihash.KECCAK_256)
|
|
|
|
HeaderMhKey = shared.MultihashKeyFromCID(HeaderCID)
|
|
|
|
Trx1CID, _ = ipld.RawdataToCid(ipld.MEthTx, Tx1, multihash.KECCAK_256)
|
|
|
|
Trx1MhKey = shared.MultihashKeyFromCID(Trx1CID)
|
|
|
|
Trx2CID, _ = ipld.RawdataToCid(ipld.MEthTx, Tx2, multihash.KECCAK_256)
|
|
|
|
Trx2MhKey = shared.MultihashKeyFromCID(Trx2CID)
|
|
|
|
Trx3CID, _ = ipld.RawdataToCid(ipld.MEthTx, Tx3, multihash.KECCAK_256)
|
|
|
|
Trx3MhKey = shared.MultihashKeyFromCID(Trx3CID)
|
|
|
|
Trx4CID, _ = ipld.RawdataToCid(ipld.MEthTx, Tx4, multihash.KECCAK_256)
|
|
|
|
Trx4MhKey = shared.MultihashKeyFromCID(Trx4CID)
|
|
|
|
Rct1CID = rctCIDs[0]
|
|
|
|
Rct1MhKey = shared.MultihashKeyFromCID(Rct1CID)
|
|
|
|
Rct2CID = rctCIDs[1]
|
|
|
|
Rct2MhKey = shared.MultihashKeyFromCID(Rct2CID)
|
|
|
|
Rct3CID = rctCIDs[2]
|
|
|
|
Rct3MhKey = shared.MultihashKeyFromCID(Rct3CID)
|
|
|
|
Rct4CID = rctCIDs[3]
|
|
|
|
Rct4MhKey = shared.MultihashKeyFromCID(Rct4CID)
|
|
|
|
State1CID, _ = ipld.RawdataToCid(ipld.MEthStateTrie, ContractLeafNode, multihash.KECCAK_256)
|
|
|
|
State1MhKey = shared.MultihashKeyFromCID(State1CID)
|
|
|
|
State2CID, _ = ipld.RawdataToCid(ipld.MEthStateTrie, AccountLeafNode, multihash.KECCAK_256)
|
|
|
|
State2MhKey = shared.MultihashKeyFromCID(State2CID)
|
|
|
|
StorageCID, _ = ipld.RawdataToCid(ipld.MEthStorageTrie, StorageLeafNode, multihash.KECCAK_256)
|
|
|
|
StorageMhKey = shared.MultihashKeyFromCID(StorageCID)
|
|
|
|
Rct1IPLD = rctIPLDData[0]
|
|
|
|
Rct2IPLD = rctIPLDData[1]
|
|
|
|
Rct3IPLD = rctIPLDData[2]
|
|
|
|
Rct4IPLD = rctIPLDData[3]
|
|
|
|
MockTrxMeta = []models.TxModel{
|
2020-10-20 14:42:09 +00:00
|
|
|
{
|
2020-10-20 20:33:18 +00:00
|
|
|
CID: "", // This is empty until we go to publish to ipfs
|
|
|
|
MhKey: "",
|
|
|
|
Src: SenderAddr.Hex(),
|
|
|
|
Dst: Address.String(),
|
|
|
|
Index: 0,
|
|
|
|
TxHash: MockTransactions[0].Hash().String(),
|
|
|
|
Data: []byte{},
|
2020-10-20 14:42:09 +00:00
|
|
|
},
|
|
|
|
{
|
2020-10-20 20:33:18 +00:00
|
|
|
CID: "",
|
|
|
|
MhKey: "",
|
|
|
|
Src: SenderAddr.Hex(),
|
|
|
|
Dst: AnotherAddress.String(),
|
|
|
|
Index: 1,
|
|
|
|
TxHash: MockTransactions[1].Hash().String(),
|
|
|
|
Data: []byte{},
|
2020-10-20 14:42:09 +00:00
|
|
|
},
|
|
|
|
{
|
2020-10-20 20:33:18 +00:00
|
|
|
CID: "",
|
|
|
|
MhKey: "",
|
|
|
|
Src: SenderAddr.Hex(),
|
|
|
|
Dst: "",
|
|
|
|
Index: 2,
|
|
|
|
TxHash: MockTransactions[2].Hash().String(),
|
|
|
|
Data: MockContractByteCode,
|
2020-10-20 14:42:09 +00:00
|
|
|
},
|
2021-09-01 07:02:28 +00:00
|
|
|
{
|
|
|
|
CID: "",
|
|
|
|
MhKey: "",
|
|
|
|
Src: SenderAddr.Hex(),
|
|
|
|
Dst: "",
|
|
|
|
Index: 3,
|
|
|
|
TxHash: MockTransactions[3].Hash().String(),
|
|
|
|
Data: []byte{},
|
|
|
|
},
|
2020-10-20 14:42:09 +00:00
|
|
|
}
|
2021-08-12 06:23:41 +00:00
|
|
|
MockTrxMetaPostPublsh = []models.TxModel{
|
2020-10-20 14:42:09 +00:00
|
|
|
{
|
2022-04-26 14:10:06 +00:00
|
|
|
BlockNumber: "1",
|
|
|
|
CID: Trx1CID.String(), // This is empty until we go to publish to ipfs
|
|
|
|
MhKey: Trx1MhKey,
|
|
|
|
Src: SenderAddr.Hex(),
|
|
|
|
Dst: Address.String(),
|
|
|
|
Index: 0,
|
|
|
|
TxHash: MockTransactions[0].Hash().String(),
|
|
|
|
Data: []byte{},
|
2020-10-20 14:42:09 +00:00
|
|
|
},
|
|
|
|
{
|
2022-04-26 14:10:06 +00:00
|
|
|
BlockNumber: "1",
|
|
|
|
CID: Trx2CID.String(),
|
|
|
|
MhKey: Trx2MhKey,
|
|
|
|
Src: SenderAddr.Hex(),
|
|
|
|
Dst: AnotherAddress.String(),
|
|
|
|
Index: 1,
|
|
|
|
TxHash: MockTransactions[1].Hash().String(),
|
|
|
|
Data: []byte{},
|
2020-10-20 14:42:09 +00:00
|
|
|
},
|
|
|
|
{
|
2022-04-26 14:10:06 +00:00
|
|
|
BlockNumber: "1",
|
|
|
|
CID: Trx3CID.String(),
|
|
|
|
MhKey: Trx3MhKey,
|
|
|
|
Src: SenderAddr.Hex(),
|
|
|
|
Dst: "",
|
|
|
|
Index: 2,
|
|
|
|
TxHash: MockTransactions[2].Hash().String(),
|
|
|
|
Data: MockContractByteCode,
|
2020-10-20 14:42:09 +00:00
|
|
|
},
|
2021-09-01 07:02:28 +00:00
|
|
|
{
|
2022-04-26 14:10:06 +00:00
|
|
|
BlockNumber: "1",
|
|
|
|
CID: Trx4CID.String(),
|
|
|
|
MhKey: Trx4MhKey,
|
|
|
|
Src: SenderAddr.Hex(),
|
|
|
|
Dst: AnotherAddress1.String(),
|
|
|
|
Index: 3,
|
|
|
|
TxHash: MockTransactions[3].Hash().String(),
|
|
|
|
Data: []byte{},
|
2021-09-01 07:02:28 +00:00
|
|
|
},
|
2020-10-20 14:42:09 +00:00
|
|
|
}
|
2021-08-12 06:23:41 +00:00
|
|
|
MockRctMeta = []models.ReceiptModel{
|
2020-10-20 14:42:09 +00:00
|
|
|
{
|
2021-09-16 12:49:42 +00:00
|
|
|
LeafCID: "",
|
|
|
|
LeafMhKey: "",
|
2020-10-20 14:42:09 +00:00
|
|
|
Contract: "",
|
|
|
|
ContractHash: "",
|
|
|
|
},
|
|
|
|
{
|
2021-09-16 12:49:42 +00:00
|
|
|
LeafCID: "",
|
|
|
|
LeafMhKey: "",
|
2020-10-20 14:42:09 +00:00
|
|
|
Contract: "",
|
|
|
|
ContractHash: "",
|
|
|
|
},
|
|
|
|
{
|
2021-09-16 12:49:42 +00:00
|
|
|
LeafCID: "",
|
|
|
|
LeafMhKey: "",
|
2020-10-20 14:42:09 +00:00
|
|
|
Contract: ContractAddress.String(),
|
|
|
|
ContractHash: ContractHash,
|
|
|
|
},
|
2021-09-01 07:02:28 +00:00
|
|
|
{
|
2021-09-16 12:49:42 +00:00
|
|
|
LeafCID: "",
|
|
|
|
LeafMhKey: "",
|
2021-09-01 07:02:28 +00:00
|
|
|
Contract: "",
|
|
|
|
ContractHash: "",
|
|
|
|
},
|
2020-10-20 14:42:09 +00:00
|
|
|
}
|
2021-09-16 12:49:42 +00:00
|
|
|
|
2021-08-12 06:23:41 +00:00
|
|
|
MockRctMetaPostPublish = []models.ReceiptModel{
|
2020-10-20 14:42:09 +00:00
|
|
|
{
|
2022-04-26 14:10:06 +00:00
|
|
|
BlockNumber: "1",
|
2021-09-16 12:49:42 +00:00
|
|
|
LeafCID: Rct1CID.String(),
|
|
|
|
LeafMhKey: Rct1MhKey,
|
2020-10-20 14:42:09 +00:00
|
|
|
Contract: "",
|
|
|
|
ContractHash: "",
|
|
|
|
},
|
|
|
|
{
|
2022-04-26 14:10:06 +00:00
|
|
|
BlockNumber: "1",
|
2021-09-16 12:49:42 +00:00
|
|
|
LeafCID: Rct2CID.String(),
|
|
|
|
LeafMhKey: Rct2MhKey,
|
2020-10-20 14:42:09 +00:00
|
|
|
Contract: "",
|
|
|
|
ContractHash: "",
|
|
|
|
},
|
|
|
|
{
|
2022-04-26 14:10:06 +00:00
|
|
|
BlockNumber: "1",
|
2021-09-16 12:49:42 +00:00
|
|
|
LeafCID: Rct3CID.String(),
|
|
|
|
LeafMhKey: Rct3MhKey,
|
2020-10-20 14:42:09 +00:00
|
|
|
Contract: ContractAddress.String(),
|
|
|
|
ContractHash: ContractHash,
|
|
|
|
},
|
2021-09-01 07:02:28 +00:00
|
|
|
{
|
2022-04-26 14:10:06 +00:00
|
|
|
BlockNumber: "1",
|
2021-09-16 12:49:42 +00:00
|
|
|
LeafCID: Rct4CID.String(),
|
|
|
|
LeafMhKey: Rct4MhKey,
|
2021-09-01 07:02:28 +00:00
|
|
|
Contract: "",
|
|
|
|
ContractHash: "",
|
|
|
|
},
|
2020-10-20 14:42:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// statediff data
|
|
|
|
storageLocation = common.HexToHash("0")
|
|
|
|
StorageLeafKey = crypto.Keccak256Hash(storageLocation[:]).Bytes()
|
2020-10-30 03:08:26 +00:00
|
|
|
StorageValue = crypto.Keccak256([]byte{1, 2, 3, 4, 5})
|
2020-10-20 14:42:09 +00:00
|
|
|
StoragePartialPath = common.Hex2Bytes("20290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563")
|
2022-04-21 08:36:50 +00:00
|
|
|
StorageLeafNode, _ = rlp.EncodeToBytes(&[]interface{}{
|
2020-10-20 14:42:09 +00:00
|
|
|
StoragePartialPath,
|
|
|
|
StorageValue,
|
|
|
|
})
|
|
|
|
|
|
|
|
nonce1 = uint64(1)
|
|
|
|
ContractRoot = "0x821e2556a290c86405f8160a2d662042a431ba456b9db265c79bb837c04be5f0"
|
2020-10-30 03:08:26 +00:00
|
|
|
ContractCodeHash = crypto.Keccak256Hash(MockContractByteCode)
|
2020-10-20 14:42:09 +00:00
|
|
|
contractPath = common.Bytes2Hex([]byte{'\x06'})
|
|
|
|
ContractLeafKey = testhelpers.AddressToLeafKey(ContractAddress)
|
2022-04-21 08:36:50 +00:00
|
|
|
ContractAccount, _ = rlp.EncodeToBytes(&types.StateAccount{
|
2020-10-20 14:42:09 +00:00
|
|
|
Nonce: nonce1,
|
|
|
|
Balance: big.NewInt(0),
|
|
|
|
CodeHash: ContractCodeHash.Bytes(),
|
|
|
|
Root: common.HexToHash(ContractRoot),
|
|
|
|
})
|
|
|
|
ContractPartialPath = common.Hex2Bytes("3114658a74d9cc9f7acf2c5cd696c3494d7c344d78bfec3add0d91ec4e8d1c45")
|
2022-04-21 08:36:50 +00:00
|
|
|
ContractLeafNode, _ = rlp.EncodeToBytes(&[]interface{}{
|
2020-10-20 14:42:09 +00:00
|
|
|
ContractPartialPath,
|
|
|
|
ContractAccount,
|
|
|
|
})
|
|
|
|
|
|
|
|
nonce0 = uint64(0)
|
2020-10-30 03:08:26 +00:00
|
|
|
AccountBalance = big.NewInt(1000)
|
2020-10-20 14:42:09 +00:00
|
|
|
AccountRoot = "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"
|
|
|
|
AccountCodeHash = common.HexToHash("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470")
|
|
|
|
AccountAddresss = common.HexToAddress("0x0D3ab14BBaD3D99F4203bd7a11aCB94882050E7e")
|
|
|
|
AccountLeafKey = testhelpers.Account2LeafKey
|
2022-04-21 08:36:50 +00:00
|
|
|
Account, _ = rlp.EncodeToBytes(&types.StateAccount{
|
2020-10-20 14:42:09 +00:00
|
|
|
Nonce: nonce0,
|
2020-10-30 03:08:26 +00:00
|
|
|
Balance: AccountBalance,
|
2020-10-20 14:42:09 +00:00
|
|
|
CodeHash: AccountCodeHash.Bytes(),
|
|
|
|
Root: common.HexToHash(AccountRoot),
|
|
|
|
})
|
|
|
|
AccountPartialPath = common.Hex2Bytes("3957f3e2f04a0764c3a0491b175f69926da61efbcc8f61fa1455fd2d2b4cdd45")
|
2022-04-21 08:36:50 +00:00
|
|
|
AccountLeafNode, _ = rlp.EncodeToBytes(&[]interface{}{
|
2020-10-20 14:42:09 +00:00
|
|
|
AccountPartialPath,
|
|
|
|
Account,
|
|
|
|
})
|
|
|
|
|
2021-08-12 06:23:41 +00:00
|
|
|
MockStateNodes = []sdtypes.StateNode{
|
2020-10-20 14:42:09 +00:00
|
|
|
{
|
2021-08-12 06:23:41 +00:00
|
|
|
LeafKey: ContractLeafKey,
|
|
|
|
Path: []byte{'\x06'},
|
|
|
|
NodeValue: ContractLeafNode,
|
|
|
|
NodeType: sdtypes.Leaf,
|
|
|
|
StorageNodes: []sdtypes.StorageNode{
|
|
|
|
{
|
|
|
|
Path: []byte{},
|
|
|
|
NodeType: sdtypes.Leaf,
|
|
|
|
LeafKey: StorageLeafKey,
|
|
|
|
NodeValue: StorageLeafNode,
|
|
|
|
},
|
|
|
|
},
|
2020-10-20 14:42:09 +00:00
|
|
|
},
|
|
|
|
{
|
2021-08-12 06:23:41 +00:00
|
|
|
LeafKey: AccountLeafKey,
|
|
|
|
Path: []byte{'\x0c'},
|
|
|
|
NodeValue: AccountLeafNode,
|
|
|
|
NodeType: sdtypes.Leaf,
|
|
|
|
StorageNodes: []sdtypes.StorageNode{},
|
2020-10-20 14:42:09 +00:00
|
|
|
},
|
|
|
|
}
|
2021-08-12 06:23:41 +00:00
|
|
|
MockStateMetaPostPublish = []models.StateNodeModel{
|
2020-10-20 14:42:09 +00:00
|
|
|
{
|
2022-04-26 14:10:06 +00:00
|
|
|
BlockNumber: "1",
|
|
|
|
CID: State1CID.String(),
|
|
|
|
MhKey: State1MhKey,
|
|
|
|
Path: []byte{'\x06'},
|
|
|
|
NodeType: 2,
|
|
|
|
StateKey: common.BytesToHash(ContractLeafKey).Hex(),
|
2020-10-20 14:42:09 +00:00
|
|
|
},
|
|
|
|
{
|
2022-04-26 14:10:06 +00:00
|
|
|
BlockNumber: "1",
|
|
|
|
CID: State2CID.String(),
|
|
|
|
MhKey: State2MhKey,
|
|
|
|
Path: []byte{'\x0c'},
|
|
|
|
NodeType: 2,
|
|
|
|
StateKey: common.BytesToHash(AccountLeafKey).Hex(),
|
2020-10-20 14:42:09 +00:00
|
|
|
},
|
|
|
|
}
|
2021-08-12 06:23:41 +00:00
|
|
|
MockStorageNodes = map[string][]sdtypes.StorageNode{
|
2020-10-20 14:42:09 +00:00
|
|
|
contractPath: {
|
|
|
|
{
|
2021-08-12 06:23:41 +00:00
|
|
|
LeafKey: StorageLeafKey,
|
|
|
|
NodeValue: StorageLeafNode,
|
|
|
|
NodeType: sdtypes.Leaf,
|
|
|
|
Path: []byte{},
|
2020-10-20 14:42:09 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-10-20 20:33:18 +00:00
|
|
|
MockConvertedPayload = eth.ConvertedPayload{
|
2020-10-20 15:48:35 +00:00
|
|
|
TotalDifficulty: MockBlock.Difficulty(),
|
|
|
|
Block: MockBlock,
|
|
|
|
Receipts: MockReceipts,
|
|
|
|
TxMetaData: MockTrxMeta,
|
|
|
|
ReceiptMetaData: MockRctMeta,
|
|
|
|
StorageNodes: MockStorageNodes,
|
|
|
|
StateNodes: MockStateNodes,
|
|
|
|
}
|
2020-11-12 21:33:06 +00:00
|
|
|
MockConvertedPayloadForChild = eth.ConvertedPayload{
|
|
|
|
TotalDifficulty: MockChild.Difficulty(),
|
|
|
|
Block: MockChild,
|
|
|
|
Receipts: MockReceipts,
|
|
|
|
TxMetaData: MockTrxMeta,
|
|
|
|
ReceiptMetaData: MockRctMeta,
|
|
|
|
StorageNodes: MockStorageNodes,
|
|
|
|
StateNodes: MockStateNodes,
|
|
|
|
}
|
2020-10-20 15:48:35 +00:00
|
|
|
|
2022-03-11 04:32:22 +00:00
|
|
|
Reward = shared.CalcEthBlockReward(MockBlock.Header(), MockBlock.Uncles(), MockBlock.Transactions(), MockReceipts)
|
2021-08-12 06:23:41 +00:00
|
|
|
MockCIDWrapper = ð.CIDWrapper{
|
2020-10-20 14:42:09 +00:00
|
|
|
BlockNumber: new(big.Int).Set(BlockNumber),
|
2021-08-12 06:23:41 +00:00
|
|
|
Header: models.HeaderModel{
|
2021-09-15 11:43:12 +00:00
|
|
|
BlockNumber: "1",
|
2020-10-20 14:42:09 +00:00
|
|
|
BlockHash: MockBlock.Hash().String(),
|
|
|
|
ParentHash: "0x0000000000000000000000000000000000000000000000000000000000000000",
|
|
|
|
CID: HeaderCID.String(),
|
|
|
|
MhKey: HeaderMhKey,
|
|
|
|
TotalDifficulty: MockBlock.Difficulty().String(),
|
2021-06-03 16:49:48 +00:00
|
|
|
Reward: Reward.String(),
|
2020-10-20 14:42:09 +00:00
|
|
|
StateRoot: MockBlock.Root().String(),
|
|
|
|
RctRoot: MockBlock.ReceiptHash().String(),
|
|
|
|
TxRoot: MockBlock.TxHash().String(),
|
|
|
|
UncleRoot: MockBlock.UncleHash().String(),
|
|
|
|
Bloom: MockBlock.Bloom().Bytes(),
|
|
|
|
Timestamp: MockBlock.Time(),
|
|
|
|
TimesValidated: 1,
|
2022-03-14 09:57:58 +00:00
|
|
|
Coinbase: "0x0000000000000000000000000000000000000000",
|
2020-10-20 14:42:09 +00:00
|
|
|
},
|
|
|
|
Transactions: MockTrxMetaPostPublsh,
|
|
|
|
Receipts: MockRctMetaPostPublish,
|
2021-08-12 06:23:41 +00:00
|
|
|
Uncles: []models.UncleModel{},
|
2020-10-20 14:42:09 +00:00
|
|
|
StateNodes: MockStateMetaPostPublish,
|
2021-08-12 06:23:41 +00:00
|
|
|
StorageNodes: []models.StorageNodeWithStateKeyModel{
|
2020-10-20 14:42:09 +00:00
|
|
|
{
|
2022-04-26 14:10:06 +00:00
|
|
|
BlockNumber: "1",
|
|
|
|
Path: []byte{},
|
|
|
|
CID: StorageCID.String(),
|
|
|
|
MhKey: StorageMhKey,
|
|
|
|
NodeType: 2,
|
|
|
|
StateKey: common.BytesToHash(ContractLeafKey).Hex(),
|
|
|
|
StorageKey: common.BytesToHash(StorageLeafKey).Hex(),
|
2020-10-20 14:42:09 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
HeaderIPLD, _ = blocks.NewBlockWithCid(MockHeaderRlp, HeaderCID)
|
2021-07-27 12:07:50 +00:00
|
|
|
Trx1IPLD, _ = blocks.NewBlockWithCid(Tx1, Trx1CID)
|
|
|
|
Trx2IPLD, _ = blocks.NewBlockWithCid(Tx2, Trx2CID)
|
|
|
|
Trx3IPLD, _ = blocks.NewBlockWithCid(Tx3, Trx3CID)
|
2021-09-01 07:02:28 +00:00
|
|
|
Trx4IPLD, _ = blocks.NewBlockWithCid(Tx4, Trx4CID)
|
2020-10-20 14:42:09 +00:00
|
|
|
State1IPLD, _ = blocks.NewBlockWithCid(ContractLeafNode, State1CID)
|
|
|
|
State2IPLD, _ = blocks.NewBlockWithCid(AccountLeafNode, State2CID)
|
|
|
|
StorageIPLD, _ = blocks.NewBlockWithCid(StorageLeafNode, StorageCID)
|
|
|
|
|
2021-08-12 06:23:41 +00:00
|
|
|
MockIPLDs = eth.IPLDs{
|
2020-10-20 14:42:09 +00:00
|
|
|
BlockNumber: new(big.Int).Set(BlockNumber),
|
2022-03-11 04:32:22 +00:00
|
|
|
Header: models.IPLDModel{
|
2022-05-18 12:18:17 +00:00
|
|
|
BlockNumber: BlockNumber.String(),
|
|
|
|
Data: HeaderIPLD.RawData(),
|
|
|
|
Key: HeaderIPLD.Cid().String(),
|
2020-10-20 14:42:09 +00:00
|
|
|
},
|
2022-03-11 04:32:22 +00:00
|
|
|
Transactions: []models.IPLDModel{
|
2020-10-20 14:42:09 +00:00
|
|
|
{
|
2022-05-18 12:18:17 +00:00
|
|
|
BlockNumber: BlockNumber.String(),
|
|
|
|
Data: Trx1IPLD.RawData(),
|
|
|
|
Key: Trx1IPLD.Cid().String(),
|
2020-10-20 14:42:09 +00:00
|
|
|
},
|
|
|
|
{
|
2022-05-18 12:18:17 +00:00
|
|
|
BlockNumber: BlockNumber.String(),
|
|
|
|
Data: Trx2IPLD.RawData(),
|
|
|
|
Key: Trx2IPLD.Cid().String(),
|
2020-10-20 14:42:09 +00:00
|
|
|
},
|
|
|
|
{
|
2022-05-18 12:18:17 +00:00
|
|
|
BlockNumber: BlockNumber.String(),
|
|
|
|
Data: Trx3IPLD.RawData(),
|
|
|
|
Key: Trx3IPLD.Cid().String(),
|
2020-10-20 14:42:09 +00:00
|
|
|
},
|
2021-09-01 07:02:28 +00:00
|
|
|
{
|
2022-05-18 12:18:17 +00:00
|
|
|
BlockNumber: BlockNumber.String(),
|
|
|
|
Data: Trx4IPLD.RawData(),
|
|
|
|
Key: Trx4IPLD.Cid().String(),
|
2021-09-01 07:02:28 +00:00
|
|
|
},
|
2020-10-20 14:42:09 +00:00
|
|
|
},
|
2022-03-11 04:32:22 +00:00
|
|
|
Receipts: []models.IPLDModel{
|
2020-10-20 14:42:09 +00:00
|
|
|
{
|
2022-05-18 12:18:17 +00:00
|
|
|
BlockNumber: BlockNumber.String(),
|
|
|
|
Data: Rct1IPLD,
|
|
|
|
Key: Rct1CID.String(),
|
2020-10-20 14:42:09 +00:00
|
|
|
},
|
|
|
|
{
|
2022-05-18 12:18:17 +00:00
|
|
|
BlockNumber: BlockNumber.String(),
|
|
|
|
Data: Rct2IPLD,
|
|
|
|
Key: Rct2CID.String(),
|
2020-10-20 14:42:09 +00:00
|
|
|
},
|
|
|
|
{
|
2022-05-18 12:18:17 +00:00
|
|
|
BlockNumber: BlockNumber.String(),
|
|
|
|
Data: Rct3IPLD,
|
|
|
|
Key: Rct3CID.String(),
|
2020-10-20 14:42:09 +00:00
|
|
|
},
|
2021-09-01 07:02:28 +00:00
|
|
|
{
|
2022-05-18 12:18:17 +00:00
|
|
|
BlockNumber: BlockNumber.String(),
|
|
|
|
Data: Rct4IPLD,
|
|
|
|
Key: Rct4CID.String(),
|
2021-09-01 07:02:28 +00:00
|
|
|
},
|
2020-10-20 14:42:09 +00:00
|
|
|
},
|
2021-08-12 06:23:41 +00:00
|
|
|
StateNodes: []eth.StateNode{
|
2020-10-20 14:42:09 +00:00
|
|
|
{
|
|
|
|
StateLeafKey: common.BytesToHash(ContractLeafKey),
|
2021-02-19 20:23:45 +00:00
|
|
|
Type: sdtypes.Leaf,
|
2022-03-11 04:32:22 +00:00
|
|
|
IPLD: models.IPLDModel{
|
2022-05-18 12:18:17 +00:00
|
|
|
BlockNumber: BlockNumber.String(),
|
|
|
|
Data: State1IPLD.RawData(),
|
|
|
|
Key: State1IPLD.Cid().String(),
|
2020-10-20 14:42:09 +00:00
|
|
|
},
|
|
|
|
Path: []byte{'\x06'},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
StateLeafKey: common.BytesToHash(AccountLeafKey),
|
2021-02-19 20:23:45 +00:00
|
|
|
Type: sdtypes.Leaf,
|
2022-03-11 04:32:22 +00:00
|
|
|
IPLD: models.IPLDModel{
|
2022-05-18 12:18:17 +00:00
|
|
|
BlockNumber: BlockNumber.String(),
|
|
|
|
Data: State2IPLD.RawData(),
|
|
|
|
Key: State2IPLD.Cid().String(),
|
2020-10-20 14:42:09 +00:00
|
|
|
},
|
|
|
|
Path: []byte{'\x0c'},
|
|
|
|
},
|
|
|
|
},
|
2021-08-12 06:23:41 +00:00
|
|
|
StorageNodes: []eth.StorageNode{
|
2020-10-20 14:42:09 +00:00
|
|
|
{
|
|
|
|
StateLeafKey: common.BytesToHash(ContractLeafKey),
|
|
|
|
StorageLeafKey: common.BytesToHash(StorageLeafKey),
|
2021-02-19 20:23:45 +00:00
|
|
|
Type: sdtypes.Leaf,
|
2022-03-11 04:32:22 +00:00
|
|
|
IPLD: models.IPLDModel{
|
2022-05-18 12:18:17 +00:00
|
|
|
BlockNumber: BlockNumber.String(),
|
|
|
|
Data: StorageIPLD.RawData(),
|
|
|
|
Key: StorageIPLD.Cid().String(),
|
2020-10-20 14:42:09 +00:00
|
|
|
},
|
|
|
|
Path: []byte{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2021-07-27 12:07:50 +00:00
|
|
|
|
|
|
|
LondonBlockNum = new(big.Int).Add(BlockNumber, big.NewInt(2))
|
|
|
|
MockLondonHeader = types.Header{
|
|
|
|
Time: 0,
|
|
|
|
Number: LondonBlockNum,
|
|
|
|
Root: common.HexToHash("0x00"),
|
|
|
|
Difficulty: big.NewInt(5000000),
|
|
|
|
Extra: []byte{},
|
|
|
|
BaseFee: big.NewInt(params.InitialBaseFee),
|
|
|
|
}
|
|
|
|
|
2021-08-14 13:50:22 +00:00
|
|
|
MockLondonTransactions, MockLondonReceipts, _ = createDynamicTransactionsAndReceipts(LondonBlockNum)
|
|
|
|
MockLondonBlock = createNewBlock(&MockLondonHeader, MockLondonTransactions, nil, MockLondonReceipts, new(trie.Trie))
|
2020-10-20 14:42:09 +00:00
|
|
|
)
|
|
|
|
|
2021-07-27 12:07:50 +00:00
|
|
|
func createNewBlock(header *types.Header, txs []*types.Transaction, uncles []*types.Header, receipts []*types.Receipt, hasher types.TrieHasher) *types.Block {
|
2021-06-03 16:49:48 +00:00
|
|
|
block := types.NewBlock(header, txs, uncles, receipts, hasher)
|
|
|
|
bHash := block.Hash()
|
|
|
|
for _, r := range receipts {
|
|
|
|
for _, l := range r.Logs {
|
|
|
|
l.BlockHash = bHash
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return block
|
|
|
|
}
|
|
|
|
|
2021-07-27 12:07:50 +00:00
|
|
|
// createDynamicTransactionsAndReceipts is a helper function to generate signed mock transactions and mock receipts with mock logs
|
|
|
|
func createDynamicTransactionsAndReceipts(blockNumber *big.Int) (types.Transactions, types.Receipts, common.Address) {
|
|
|
|
// make transactions
|
|
|
|
config := params.TestChainConfig
|
|
|
|
config.LondonBlock = blockNumber
|
|
|
|
trx1 := types.NewTx(&types.DynamicFeeTx{
|
|
|
|
ChainID: config.ChainID,
|
|
|
|
Nonce: 1,
|
|
|
|
GasTipCap: big.NewInt(50),
|
|
|
|
GasFeeCap: big.NewInt(100),
|
|
|
|
Gas: 50,
|
|
|
|
To: &Address,
|
|
|
|
Value: big.NewInt(1000),
|
|
|
|
Data: []byte{},
|
|
|
|
})
|
|
|
|
|
|
|
|
transactionSigner := types.MakeSigner(config, blockNumber)
|
|
|
|
mockCurve := elliptic.P256()
|
|
|
|
mockPrvKey, err := ecdsa.GenerateKey(mockCurve, rand.Reader)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err.Error())
|
|
|
|
}
|
|
|
|
signedTrx1, err := types.SignTx(trx1, transactionSigner, mockPrvKey)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err.Error())
|
|
|
|
}
|
|
|
|
|
2021-09-15 11:43:12 +00:00
|
|
|
senderAddr, err := types.Sender(transactionSigner, signedTrx1) // same for both trx
|
2021-07-27 12:07:50 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
// make receipts
|
2021-09-15 11:43:12 +00:00
|
|
|
// TODO: Change the receipt type to DynamicFeeTxType once this PR is merged.
|
2021-07-27 12:07:50 +00:00
|
|
|
// https://github.com/ethereum/go-ethereum/pull/22806
|
|
|
|
mockReceipt1 := &types.Receipt{
|
2021-08-12 06:23:41 +00:00
|
|
|
Type: types.DynamicFeeTxType,
|
2021-08-14 13:50:22 +00:00
|
|
|
PostState: common.HexToHash("0x0").Bytes(),
|
2021-07-27 12:07:50 +00:00
|
|
|
Status: types.ReceiptStatusSuccessful,
|
|
|
|
CumulativeGasUsed: 50,
|
|
|
|
Logs: []*types.Log{},
|
|
|
|
TxHash: signedTrx1.Hash(),
|
|
|
|
}
|
|
|
|
|
|
|
|
return types.Transactions{signedTrx1}, types.Receipts{mockReceipt1}, senderAddr
|
|
|
|
}
|
|
|
|
|
|
|
|
// createLegacyTransactionsAndReceipts is a helper function to generate signed mock transactions and mock receipts with mock logs
|
|
|
|
func createLegacyTransactionsAndReceipts() (types.Transactions, types.Receipts, common.Address) {
|
2020-10-20 14:42:09 +00:00
|
|
|
// make transactions
|
|
|
|
trx1 := types.NewTransaction(0, Address, big.NewInt(1000), 50, big.NewInt(100), []byte{})
|
|
|
|
trx2 := types.NewTransaction(1, AnotherAddress, big.NewInt(2000), 100, big.NewInt(200), []byte{})
|
|
|
|
trx3 := types.NewContractCreation(2, big.NewInt(1500), 75, big.NewInt(150), MockContractByteCode)
|
2021-09-01 07:02:28 +00:00
|
|
|
trx4 := types.NewTransaction(3, AnotherAddress1, big.NewInt(2000), 100, big.NewInt(200), []byte{})
|
2020-10-20 14:42:09 +00:00
|
|
|
transactionSigner := types.MakeSigner(params.MainnetChainConfig, new(big.Int).Set(BlockNumber))
|
|
|
|
mockCurve := elliptic.P256()
|
|
|
|
mockPrvKey, err := ecdsa.GenerateKey(mockCurve, rand.Reader)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
signedTrx1, err := types.SignTx(trx1, transactionSigner, mockPrvKey)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
signedTrx2, err := types.SignTx(trx2, transactionSigner, mockPrvKey)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
signedTrx3, err := types.SignTx(trx3, transactionSigner, mockPrvKey)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2021-09-01 07:02:28 +00:00
|
|
|
signedTrx4, err := types.SignTx(trx4, transactionSigner, mockPrvKey)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2020-10-20 14:42:09 +00:00
|
|
|
SenderAddr, err := types.Sender(transactionSigner, signedTrx1) // same for both trx
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
// make receipts
|
2021-08-30 15:29:54 +00:00
|
|
|
mockReceipt1 := types.NewReceipt(nil, false, 50)
|
2021-06-03 16:49:48 +00:00
|
|
|
|
|
|
|
hash1 := signedTrx1.Hash()
|
|
|
|
MockLog1.TxHash = hash1
|
|
|
|
|
2020-10-20 14:42:09 +00:00
|
|
|
mockReceipt1.Logs = []*types.Log{MockLog1}
|
2021-06-03 16:49:48 +00:00
|
|
|
mockReceipt1.TxHash = hash1
|
|
|
|
mockReceipt1.GasUsed = mockReceipt1.CumulativeGasUsed
|
|
|
|
|
2020-10-20 14:42:09 +00:00
|
|
|
mockReceipt2 := types.NewReceipt(common.HexToHash("0x1").Bytes(), false, 100)
|
2021-06-03 16:49:48 +00:00
|
|
|
hash2 := signedTrx2.Hash()
|
|
|
|
MockLog2.TxHash = hash2
|
|
|
|
|
2020-10-20 14:42:09 +00:00
|
|
|
mockReceipt2.Logs = []*types.Log{MockLog2}
|
2021-06-03 16:49:48 +00:00
|
|
|
mockReceipt2.TxHash = hash2
|
|
|
|
mockReceipt2.GasUsed = mockReceipt2.CumulativeGasUsed - mockReceipt1.CumulativeGasUsed
|
|
|
|
|
|
|
|
mockReceipt3 := types.NewReceipt(common.HexToHash("0x2").Bytes(), false, 175)
|
2021-08-20 07:37:11 +00:00
|
|
|
mockReceipt3.Logs = []*types.Log{MockLog3, MockLog4, MockLog5}
|
2020-10-20 14:42:09 +00:00
|
|
|
mockReceipt3.TxHash = signedTrx3.Hash()
|
2021-06-03 16:49:48 +00:00
|
|
|
mockReceipt3.GasUsed = mockReceipt3.CumulativeGasUsed - mockReceipt2.CumulativeGasUsed
|
|
|
|
|
2021-09-01 07:02:28 +00:00
|
|
|
// Receipt with failed status.
|
|
|
|
mockReceipt4 := types.NewReceipt(nil, true, 250)
|
|
|
|
mockReceipt4.Logs = []*types.Log{MockLog6}
|
|
|
|
mockReceipt4.TxHash = signedTrx4.Hash()
|
|
|
|
mockReceipt4.GasUsed = mockReceipt4.CumulativeGasUsed - mockReceipt3.CumulativeGasUsed
|
|
|
|
|
|
|
|
return types.Transactions{signedTrx1, signedTrx2, signedTrx3, signedTrx4}, types.Receipts{mockReceipt1, mockReceipt2, mockReceipt3, mockReceipt4}, SenderAddr
|
2020-10-20 14:42:09 +00:00
|
|
|
}
|
2021-07-27 12:07:50 +00:00
|
|
|
|
|
|
|
func GetTxnRlp(num int, txs types.Transactions) []byte {
|
|
|
|
buf := new(bytes.Buffer)
|
|
|
|
txs.EncodeIndex(num, buf)
|
|
|
|
tx := make([]byte, buf.Len())
|
|
|
|
copy(tx, buf.Bytes())
|
|
|
|
buf.Reset()
|
|
|
|
return tx
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetRctRlp(num int, rcts types.Receipts) []byte {
|
|
|
|
buf := new(bytes.Buffer)
|
|
|
|
rcts.EncodeIndex(num, buf)
|
|
|
|
rct := make([]byte, buf.Len())
|
|
|
|
copy(rct, buf.Bytes())
|
|
|
|
buf.Reset()
|
|
|
|
return rct
|
|
|
|
}
|