Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( Testdb = rawdb.NewMemoryDatabase() TestBankKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291") TestBankAddress = crypto.PubkeyToAddress(TestBankKey.PublicKey) //0x71562b71999873DB5b286dF957af199Ec94617F7 TestBankFunds = big.NewInt(100000000) Genesis = test_helpers.GenesisBlockForTesting(Testdb, TestBankAddress, TestBankFunds) Account1Key, _ = crypto.HexToECDSA("8a1f9a8f95be41cd7ccb6168179afb4504aefe388d1e14474d32c45c72ce7b7a") Account2Key, _ = crypto.HexToECDSA("49a7b37aa6f6645917e7b807e9d1c00d4fa71f18343b0d4122a4d2df64dd6fee") Account1Addr = crypto.PubkeyToAddress(Account1Key.PublicKey) //0x703c4b2bD70c169f5717101CaeE543299Fc946C7 Account2Addr = crypto.PubkeyToAddress(Account2Key.PublicKey) //0x0D3ab14BBaD3D99F4203bd7a11aCB94882050E7e DeploymentTxData = common.Hex2Bytes("608060405234801561001057600080fd5b50336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550600180819055506101e2806100676000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c806343d726d61461004657806365f3c31a1461005057806373d4a13a1461007e575b600080fd5b61004e61009c565b005b61007c6004803603602081101561006657600080fd5b810190808035906020019092919050505061017b565b005b610086610185565b6040518082815260200191505060405180910390f35b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610141576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602281526020018061018c6022913960400191505060405180910390fd5b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16ff5b8060018190555050565b6001548156fe4f6e6c79206f776e65722063616e2063616c6c20746869732066756e6374696f6e2ea265627a7a723158205ba91466129f45285f53176d805117208c231ec6343d7896790e6fc4165b802b64736f6c63430005110032") ContractCode = common.Hex2Bytes("608060405234801561001057600080fd5b50600436106100415760003560e01c806343d726d61461004657806365f3c31a1461005057806373d4a13a1461007e575b600080fd5b61004e61009c565b005b61007c6004803603602081101561006657600080fd5b810190808035906020019092919050505061017b565b005b610086610185565b6040518082815260200191505060405180910390f35b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610141576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602281526020018061018c6022913960400191505060405180910390fd5b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16ff5b8060018190555050565b6001548156fe4f6e6c79206f776e65722063616e2063616c6c20746869732066756e6374696f6e2ea265627a7a723158205ba91466129f45285f53176d805117208c231ec6343d7896790e6fc4165b802b64736f6c63430005110032") CodeHash = crypto.Keccak256Hash(ContractCode) ContractAddr common.Address IndexZero = "0000000000000000000000000000000000000000000000000000000000000000" IndexOne = "0000000000000000000000000000000000000000000000000000000000000001" ContractSlotPosition = common.FromHex(IndexOne) ContractSlotKeyHash = crypto.Keccak256Hash(ContractSlotPosition) MiningReward = big.NewInt(2000000000000000000) )
Test variables
View Source
var ( // block data BlockNumber = big.NewInt(1) 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{}, } MockTransactions, MockReceipts, SenderAddr = createLegacyTransactionsAndReceipts() 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{}, }, } ReceiptsRlp, _ = rlp.EncodeToBytes(MockReceipts) MockBlock = createNewBlock(&MockHeader, MockTransactions, MockUncles, MockReceipts, trie.NewEmpty(nil)) 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(), } MockChild = types.NewBlock(&MockChildHeader, MockTransactions, MockUncles, MockReceipts, trie.NewEmpty(nil)) MockChildRlp, _ = rlp.EncodeToBytes(MockChild.Header()) Address = common.HexToAddress("0xaE9BEa628c4Ce503DcFD7E305CaB4e29E7476592") AnotherAddress = common.HexToAddress("0xaE9BEa628c4Ce503DcFD7E305CaB4e29E7476593") AnotherAddress1 = common.HexToAddress("0xaE9BEa628c4Ce503DcFD7E305CaB4e29E7476594") AnotherAddress2 = common.HexToAddress("0xaE9BEa628c4Ce503DcFD7E305CaB4e29E7476596") ContractAddress = crypto.CreateAddress(SenderAddr, MockTransactions[2].Nonce()) ContractHash = crypto.Keccak256Hash(ContractAddress.Bytes()).String() MockContractByteCode = []byte{0, 1, 2, 3, 4, 5} MockLog1 = &types.Log{ Address: Address, Topics: []common.Hash{mockTopic11, mockTopic12}, Data: []byte{}, BlockNumber: BlockNumber.Uint64(), TxIndex: 0, Index: 0, } MockLog2 = &types.Log{ Address: AnotherAddress, Topics: []common.Hash{mockTopic21, mockTopic22}, Data: []byte{}, BlockNumber: BlockNumber.Uint64(), TxIndex: 1, Index: 1, } MockLog3 = &types.Log{ Address: AnotherAddress1, Topics: []common.Hash{mockTopic31}, Data: []byte{}, BlockNumber: BlockNumber.Uint64(), TxIndex: 2, Index: 2, } MockLog4 = &types.Log{ Address: AnotherAddress1, Topics: []common.Hash{mockTopic41, mockTopic42, mockTopic43}, Data: []byte{}, BlockNumber: BlockNumber.Uint64(), TxIndex: 2, Index: 3, } MockLog5 = &types.Log{ Address: AnotherAddress1, Topics: []common.Hash{mockTopic51}, Data: []byte{}, BlockNumber: BlockNumber.Uint64(), TxIndex: 2, Index: 4, } MockLog6 = &types.Log{ Address: AnotherAddress2, Topics: []common.Hash{mockTopic61}, Data: []byte{}, BlockNumber: BlockNumber.Uint64(), TxIndex: 3, Index: 5, } Tx1 = GetTxnRlp(0, MockTransactions) Tx2 = GetTxnRlp(1, MockTransactions) Tx3 = GetTxnRlp(2, MockTransactions) Tx4 = GetTxnRlp(3, MockTransactions) 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{ { CID: "", MhKey: "", Src: SenderAddr.Hex(), Dst: Address.String(), Index: 0, TxHash: MockTransactions[0].Hash().String(), Data: []byte{}, }, { CID: "", MhKey: "", Src: SenderAddr.Hex(), Dst: AnotherAddress.String(), Index: 1, TxHash: MockTransactions[1].Hash().String(), Data: []byte{}, }, { CID: "", MhKey: "", Src: SenderAddr.Hex(), Dst: "", Index: 2, TxHash: MockTransactions[2].Hash().String(), Data: MockContractByteCode, }, { CID: "", MhKey: "", Src: SenderAddr.Hex(), Dst: "", Index: 3, TxHash: MockTransactions[3].Hash().String(), Data: []byte{}, }, } MockTrxMetaPostPublsh = []models.TxModel{ { BlockNumber: "1", CID: Trx1CID.String(), MhKey: Trx1MhKey, Src: SenderAddr.Hex(), Dst: Address.String(), Index: 0, TxHash: MockTransactions[0].Hash().String(), Data: []byte{}, }, { BlockNumber: "1", CID: Trx2CID.String(), MhKey: Trx2MhKey, Src: SenderAddr.Hex(), Dst: AnotherAddress.String(), Index: 1, TxHash: MockTransactions[1].Hash().String(), Data: []byte{}, }, { BlockNumber: "1", CID: Trx3CID.String(), MhKey: Trx3MhKey, Src: SenderAddr.Hex(), Dst: "", Index: 2, TxHash: MockTransactions[2].Hash().String(), Data: MockContractByteCode, }, { BlockNumber: "1", CID: Trx4CID.String(), MhKey: Trx4MhKey, Src: SenderAddr.Hex(), Dst: AnotherAddress1.String(), Index: 3, TxHash: MockTransactions[3].Hash().String(), Data: []byte{}, }, } MockRctMeta = []models.ReceiptModel{ { LeafCID: "", LeafMhKey: "", Contract: "", ContractHash: "", }, { LeafCID: "", LeafMhKey: "", Contract: "", ContractHash: "", }, { LeafCID: "", LeafMhKey: "", Contract: ContractAddress.String(), ContractHash: ContractHash, }, { LeafCID: "", LeafMhKey: "", Contract: "", ContractHash: "", }, } MockRctMetaPostPublish = []models.ReceiptModel{ { BlockNumber: "1", HeaderID: MockBlock.Hash().String(), LeafCID: Rct1CID.String(), LeafMhKey: Rct1MhKey, Contract: "", ContractHash: "", }, { BlockNumber: "1", HeaderID: MockBlock.Hash().String(), LeafCID: Rct2CID.String(), LeafMhKey: Rct2MhKey, Contract: "", ContractHash: "", }, { BlockNumber: "1", HeaderID: MockBlock.Hash().String(), LeafCID: Rct3CID.String(), LeafMhKey: Rct3MhKey, Contract: ContractAddress.String(), ContractHash: ContractHash, }, { BlockNumber: "1", HeaderID: MockBlock.Hash().String(), LeafCID: Rct4CID.String(), LeafMhKey: Rct4MhKey, Contract: "", ContractHash: "", }, } StorageLeafKey = crypto.Keccak256Hash(storageLocation[:]).Bytes() StorageValue = crypto.Keccak256([]byte{1, 2, 3, 4, 5}) StoragePartialPath = common.Hex2Bytes("20290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563") StorageLeafNode, _ = rlp.EncodeToBytes(&[]interface{}{ StoragePartialPath, StorageValue, }) ContractRoot = "0x821e2556a290c86405f8160a2d662042a431ba456b9db265c79bb837c04be5f0" ContractCodeHash = crypto.Keccak256Hash(MockContractByteCode) ContractLeafKey = testhelpers.AddressToLeafKey(ContractAddress) ContractAccount, _ = rlp.EncodeToBytes(&types.StateAccount{ Nonce: nonce1, Balance: big.NewInt(0), CodeHash: ContractCodeHash.Bytes(), Root: common.HexToHash(ContractRoot), }) ContractPartialPath = common.Hex2Bytes("3114658a74d9cc9f7acf2c5cd696c3494d7c344d78bfec3add0d91ec4e8d1c45") ContractLeafNode, _ = rlp.EncodeToBytes(&[]interface{}{ ContractPartialPath, ContractAccount, }) AccountBalance = big.NewInt(1000) AccountRoot = "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421" AccountCodeHash = common.HexToHash("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470") AccountAddresss = common.HexToAddress("0x0D3ab14BBaD3D99F4203bd7a11aCB94882050E7e") AccountLeafKey = testhelpers.Account2LeafKey Account, _ = rlp.EncodeToBytes(&types.StateAccount{ Nonce: nonce0, Balance: AccountBalance, CodeHash: AccountCodeHash.Bytes(), Root: common.HexToHash(AccountRoot), }) AccountPartialPath = common.Hex2Bytes("3957f3e2f04a0764c3a0491b175f69926da61efbcc8f61fa1455fd2d2b4cdd45") AccountLeafNode, _ = rlp.EncodeToBytes(&[]interface{}{ AccountPartialPath, Account, }) MockStateNodes = []sdtypes.StateNode{ { LeafKey: ContractLeafKey, Path: []byte{'\x06'}, NodeValue: ContractLeafNode, NodeType: sdtypes.Leaf, StorageNodes: []sdtypes.StorageNode{ { Path: []byte{}, NodeType: sdtypes.Leaf, LeafKey: StorageLeafKey, NodeValue: StorageLeafNode, }, }, }, { LeafKey: AccountLeafKey, Path: []byte{'\x0c'}, NodeValue: AccountLeafNode, NodeType: sdtypes.Leaf, StorageNodes: []sdtypes.StorageNode{}, }, } MockStateMetaPostPublish = []models.StateNodeModel{ { BlockNumber: "1", CID: State1CID.String(), MhKey: State1MhKey, Path: []byte{'\x06'}, NodeType: 2, StateKey: common.BytesToHash(ContractLeafKey).Hex(), }, { BlockNumber: "1", CID: State2CID.String(), MhKey: State2MhKey, Path: []byte{'\x0c'}, NodeType: 2, StateKey: common.BytesToHash(AccountLeafKey).Hex(), }, } MockStorageNodes = map[string][]sdtypes.StorageNode{ // contains filtered or unexported fields } MockConvertedPayload = eth.ConvertedPayload{ TotalDifficulty: MockBlock.Difficulty(), Block: MockBlock, Receipts: MockReceipts, TxMetaData: MockTrxMeta, ReceiptMetaData: MockRctMeta, StorageNodes: MockStorageNodes, StateNodes: MockStateNodes, } MockConvertedPayloadForChild = eth.ConvertedPayload{ TotalDifficulty: MockChild.Difficulty(), Block: MockChild, Receipts: MockReceipts, TxMetaData: MockTrxMeta, ReceiptMetaData: MockRctMeta, StorageNodes: MockStorageNodes, StateNodes: MockStateNodes, } Reward = shared.CalcEthBlockReward(MockBlock.Header(), MockBlock.Uncles(), MockBlock.Transactions(), MockReceipts) MockCIDWrapper = ð.CIDWrapper{ BlockNumber: new(big.Int).Set(BlockNumber), Header: models.HeaderModel{ BlockNumber: "1", BlockHash: MockBlock.Hash().String(), ParentHash: "0x0000000000000000000000000000000000000000000000000000000000000000", CID: HeaderCID.String(), MhKey: HeaderMhKey, TotalDifficulty: MockBlock.Difficulty().String(), Reward: Reward.String(), 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, Coinbase: "0x0000000000000000000000000000000000000000", }, Transactions: MockTrxMetaPostPublsh, Receipts: MockRctMetaPostPublish, Uncles: []models.UncleModel{}, StateNodes: MockStateMetaPostPublish, StorageNodes: []models.StorageNodeWithStateKeyModel{ { BlockNumber: "1", Path: []byte{}, CID: StorageCID.String(), MhKey: StorageMhKey, NodeType: 2, StateKey: common.BytesToHash(ContractLeafKey).Hex(), StorageKey: common.BytesToHash(StorageLeafKey).Hex(), }, }, } HeaderIPLD, _ = blocks.NewBlockWithCid(MockHeaderRlp, HeaderCID) Trx1IPLD, _ = blocks.NewBlockWithCid(Tx1, Trx1CID) Trx2IPLD, _ = blocks.NewBlockWithCid(Tx2, Trx2CID) Trx3IPLD, _ = blocks.NewBlockWithCid(Tx3, Trx3CID) Trx4IPLD, _ = blocks.NewBlockWithCid(Tx4, Trx4CID) State1IPLD, _ = blocks.NewBlockWithCid(ContractLeafNode, State1CID) State2IPLD, _ = blocks.NewBlockWithCid(AccountLeafNode, State2CID) StorageIPLD, _ = blocks.NewBlockWithCid(StorageLeafNode, StorageCID) MockIPLDs = eth.IPLDs{ BlockNumber: new(big.Int).Set(BlockNumber), Header: models.IPLDModel{ BlockNumber: BlockNumber.String(), Data: HeaderIPLD.RawData(), Key: HeaderIPLD.Cid().String(), }, Transactions: []models.IPLDModel{ { BlockNumber: BlockNumber.String(), Data: Trx1IPLD.RawData(), Key: Trx1IPLD.Cid().String(), }, { BlockNumber: BlockNumber.String(), Data: Trx2IPLD.RawData(), Key: Trx2IPLD.Cid().String(), }, { BlockNumber: BlockNumber.String(), Data: Trx3IPLD.RawData(), Key: Trx3IPLD.Cid().String(), }, { BlockNumber: BlockNumber.String(), Data: Trx4IPLD.RawData(), Key: Trx4IPLD.Cid().String(), }, }, Receipts: []models.IPLDModel{ { BlockNumber: BlockNumber.String(), Data: Rct1IPLD, Key: Rct1CID.String(), }, { BlockNumber: BlockNumber.String(), Data: Rct2IPLD, Key: Rct2CID.String(), }, { BlockNumber: BlockNumber.String(), Data: Rct3IPLD, Key: Rct3CID.String(), }, { BlockNumber: BlockNumber.String(), Data: Rct4IPLD, Key: Rct4CID.String(), }, }, StateNodes: []eth.StateNode{ { StateLeafKey: common.BytesToHash(ContractLeafKey), Type: sdtypes.Leaf, IPLD: models.IPLDModel{ BlockNumber: BlockNumber.String(), Data: State1IPLD.RawData(), Key: State1IPLD.Cid().String(), }, Path: []byte{'\x06'}, }, { StateLeafKey: common.BytesToHash(AccountLeafKey), Type: sdtypes.Leaf, IPLD: models.IPLDModel{ BlockNumber: BlockNumber.String(), Data: State2IPLD.RawData(), Key: State2IPLD.Cid().String(), }, Path: []byte{'\x0c'}, }, }, StorageNodes: []eth.StorageNode{ { StateLeafKey: common.BytesToHash(ContractLeafKey), StorageLeafKey: common.BytesToHash(StorageLeafKey), Type: sdtypes.Leaf, IPLD: models.IPLDModel{ BlockNumber: BlockNumber.String(), Data: StorageIPLD.RawData(), Key: StorageIPLD.Cid().String(), }, Path: []byte{}, }, }, } 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), } MockLondonTransactions, MockLondonReceipts, _ = createDynamicTransactionsAndReceipts(LondonBlockNum) MockLondonUncles = []*types.Header{ { Time: 1, Number: new(big.Int).Add(BlockNumber, big.NewInt(1)), ParentHash: common.HexToHash("0x2"), 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(1)), ParentHash: common.HexToHash("0x1"), Root: common.HexToHash("0x2"), TxHash: common.HexToHash("0x2"), ReceiptHash: common.HexToHash("0x2"), Difficulty: big.NewInt(500002), Extra: []byte{}, }, } MockLondonBlock = createNewBlock(&MockLondonHeader, MockLondonTransactions, MockLondonUncles, MockLondonReceipts, trie.NewEmpty(nil)) )
Test variables
Functions ¶
func MakeChain ¶
func MakeChain(n int, parent *types.Block, chainGen func(int, *core.BlockGen)) ([]*types.Block, []types.Receipts, *core.BlockChain)
MakeChain creates a chain of n blocks starting at and including parent. the returned hash chain is ordered head->parent.
func TestChainGen ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.