more updates
This commit is contained in:
parent
023da9eddc
commit
00caabe030
@ -18,7 +18,6 @@ package statediff_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"math/big"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
@ -232,7 +231,7 @@ var (
|
|||||||
})
|
})
|
||||||
bankAccountAtBlock0 = &types.StateAccount{
|
bankAccountAtBlock0 = &types.StateAccount{
|
||||||
Nonce: 0,
|
Nonce: 0,
|
||||||
Balance: uint256.NewInt(test_helpers.TestBankFunds.Int64()),
|
Balance: uint256.MustFromBig(test_helpers.TestBankFunds),
|
||||||
CodeHash: test_helpers.NullCodeHash.Bytes(),
|
CodeHash: test_helpers.NullCodeHash.Bytes(),
|
||||||
Root: test_helpers.EmptyContractRoot,
|
Root: test_helpers.EmptyContractRoot,
|
||||||
}
|
}
|
||||||
@ -242,10 +241,10 @@ var (
|
|||||||
bankAccountAtBlock0RLP,
|
bankAccountAtBlock0RLP,
|
||||||
})
|
})
|
||||||
|
|
||||||
block1BankBalance = uint256.NewInt(test_helpers.TestBankFunds.Int64() - test_helpers.BalanceChange10000 - test_helpers.GasFees)
|
block1BankBalance = test_helpers.TestBankFunds.Int64() - test_helpers.BalanceChange10000 - test_helpers.GasFees
|
||||||
bankAccountAtBlock1 = &types.StateAccount{
|
bankAccountAtBlock1 = &types.StateAccount{
|
||||||
Nonce: 1,
|
Nonce: 1,
|
||||||
Balance: block1BankBalance,
|
Balance: uint256.NewInt(uint64(block1BankBalance)),
|
||||||
CodeHash: test_helpers.NullCodeHash.Bytes(),
|
CodeHash: test_helpers.NullCodeHash.Bytes(),
|
||||||
Root: test_helpers.EmptyContractRoot,
|
Root: test_helpers.EmptyContractRoot,
|
||||||
}
|
}
|
||||||
@ -255,10 +254,10 @@ var (
|
|||||||
bankAccountAtBlock1RLP,
|
bankAccountAtBlock1RLP,
|
||||||
})
|
})
|
||||||
|
|
||||||
block2BankBalance = block1BankBalance.Int64() - test_helpers.BalanceChange1Ether - test_helpers.GasFees
|
block2BankBalance = block1BankBalance - test_helpers.BalanceChange1Ether - test_helpers.GasFees
|
||||||
bankAccountAtBlock2 = &types.StateAccount{
|
bankAccountAtBlock2 = &types.StateAccount{
|
||||||
Nonce: 2,
|
Nonce: 2,
|
||||||
Balance: uint256.NewInt(block2BankBalance),
|
Balance: uint256.NewInt(uint64(block2BankBalance)),
|
||||||
CodeHash: test_helpers.NullCodeHash.Bytes(),
|
CodeHash: test_helpers.NullCodeHash.Bytes(),
|
||||||
Root: test_helpers.EmptyContractRoot,
|
Root: test_helpers.EmptyContractRoot,
|
||||||
}
|
}
|
||||||
@ -1867,8 +1866,8 @@ contract test {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
var (
|
var (
|
||||||
b = uint256.NewInt(0).Sub(test_helpers.TestBIGBankFunds, test_helpers.BalanceChangeBIG)
|
b = uint256.NewInt(0).Sub(uint256.MustFromBig(test_helpers.TestBIGBankFunds), test_helpers.BalanceChangeBIG)
|
||||||
block1BankBigBalance = uint256.NewInt(0).Sub(b, uint256.NewInt(test_helpers.GasFees2))
|
block1BankBigBalance = uint256.NewInt(0).Sub(b, uint256.NewInt(uint64(test_helpers.GasFees2)))
|
||||||
bankAccountAtBlock1b = &types.StateAccount{
|
bankAccountAtBlock1b = &types.StateAccount{
|
||||||
Nonce: 1,
|
Nonce: 1,
|
||||||
Balance: block1BankBigBalance,
|
Balance: block1BankBigBalance,
|
||||||
@ -1893,8 +1892,8 @@ var (
|
|||||||
account1AtBlock1bRLP,
|
account1AtBlock1bRLP,
|
||||||
})
|
})
|
||||||
|
|
||||||
account1AtBlock2bBalance, _ = uint256.NewInt(0).SetString("1999999999999999999999999761539571000000000", 10)
|
account1AtBlock2bBalance = uint256.MustFromDecimal("1999999999999999999999999761539571000000000")
|
||||||
account1AtBlock2b = &types.StateAccount{
|
account1AtBlock2b = &types.StateAccount{
|
||||||
Nonce: 1,
|
Nonce: 1,
|
||||||
Balance: account1AtBlock2bBalance,
|
Balance: account1AtBlock2bBalance,
|
||||||
CodeHash: test_helpers.NullCodeHash.Bytes(),
|
CodeHash: test_helpers.NullCodeHash.Bytes(),
|
||||||
@ -1930,8 +1929,8 @@ var (
|
|||||||
contractAccountAtBlock2bRLP,
|
contractAccountAtBlock2bRLP,
|
||||||
})
|
})
|
||||||
|
|
||||||
bankAccountAtBlock3bBalance, _ = uint256.NewInt(0).SetString("18000000000000000000000001999920365757724976", 10)
|
bankAccountAtBlock3bBalance = uint256.MustFromDecimal("18000000000000000000000001999920365757724976")
|
||||||
bankAccountAtBlock3b = &types.StateAccount{
|
bankAccountAtBlock3b = &types.StateAccount{
|
||||||
Nonce: 3,
|
Nonce: 3,
|
||||||
Balance: bankAccountAtBlock3bBalance,
|
Balance: bankAccountAtBlock3bBalance,
|
||||||
CodeHash: test_helpers.NullCodeHash.Bytes(),
|
CodeHash: test_helpers.NullCodeHash.Bytes(),
|
||||||
|
@ -28,6 +28,7 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/params"
|
"github.com/ethereum/go-ethereum/params"
|
||||||
"github.com/ethereum/go-ethereum/rlp"
|
"github.com/ethereum/go-ethereum/rlp"
|
||||||
"github.com/ethereum/go-ethereum/trie"
|
"github.com/ethereum/go-ethereum/trie"
|
||||||
|
"github.com/holiman/uint256"
|
||||||
|
|
||||||
"github.com/cerc-io/plugeth-statediff/indexer/ipld"
|
"github.com/cerc-io/plugeth-statediff/indexer/ipld"
|
||||||
"github.com/cerc-io/plugeth-statediff/indexer/shared"
|
"github.com/cerc-io/plugeth-statediff/indexer/shared"
|
||||||
@ -41,6 +42,7 @@ var (
|
|||||||
// block data
|
// block data
|
||||||
TestChainConfig = params.MainnetChainConfig
|
TestChainConfig = params.MainnetChainConfig
|
||||||
BlockNumber = TestChainConfig.LondonBlock
|
BlockNumber = TestChainConfig.LondonBlock
|
||||||
|
BlockTime = *TestChainConfig.CancunTime // TODO: verify this
|
||||||
|
|
||||||
// canonical block at London height
|
// canonical block at London height
|
||||||
// includes 5 transactions: 3 Legacy + 1 EIP-2930 + 1 EIP-1559
|
// includes 5 transactions: 3 Legacy + 1 EIP-2930 + 1 EIP-1559
|
||||||
@ -55,7 +57,7 @@ var (
|
|||||||
BaseFee: big.NewInt(params.InitialBaseFee),
|
BaseFee: big.NewInt(params.InitialBaseFee),
|
||||||
Coinbase: common.HexToAddress("0xaE9BEa628c4Ce503DcFD7E305CaB4e29E7476777"),
|
Coinbase: common.HexToAddress("0xaE9BEa628c4Ce503DcFD7E305CaB4e29E7476777"),
|
||||||
}
|
}
|
||||||
MockTransactions, MockReceipts, SenderAddr = createTransactionsAndReceipts(TestChainConfig, BlockNumber)
|
MockTransactions, MockReceipts, SenderAddr = createTransactionsAndReceipts(TestChainConfig, BlockNumber, BlockTime)
|
||||||
MockBlock = types.NewBlock(&MockHeader, MockTransactions, nil, MockReceipts, trie.NewEmpty(nil))
|
MockBlock = types.NewBlock(&MockHeader, MockTransactions, nil, MockReceipts, trie.NewEmpty(nil))
|
||||||
MockHeaderRlp, _ = rlp.EncodeToBytes(MockBlock.Header())
|
MockHeaderRlp, _ = rlp.EncodeToBytes(MockBlock.Header())
|
||||||
|
|
||||||
@ -63,13 +65,14 @@ var (
|
|||||||
// includes 2nd and 5th transactions from the canonical block
|
// includes 2nd and 5th transactions from the canonical block
|
||||||
MockNonCanonicalHeader = MockHeader
|
MockNonCanonicalHeader = MockHeader
|
||||||
MockNonCanonicalBlockTransactions = types.Transactions{MockTransactions[1], MockTransactions[4]}
|
MockNonCanonicalBlockTransactions = types.Transactions{MockTransactions[1], MockTransactions[4]}
|
||||||
MockNonCanonicalBlockReceipts = createNonCanonicalBlockReceipts(TestChainConfig, BlockNumber, MockNonCanonicalBlockTransactions)
|
MockNonCanonicalBlockReceipts = createNonCanonicalBlockReceipts(TestChainConfig, BlockNumber, BlockTime, MockNonCanonicalBlockTransactions)
|
||||||
MockNonCanonicalBlock = types.NewBlock(&MockNonCanonicalHeader, MockNonCanonicalBlockTransactions, nil, MockNonCanonicalBlockReceipts, trie.NewEmpty(nil))
|
MockNonCanonicalBlock = types.NewBlock(&MockNonCanonicalHeader, MockNonCanonicalBlockTransactions, nil, MockNonCanonicalBlockReceipts, trie.NewEmpty(nil))
|
||||||
MockNonCanonicalHeaderRlp, _ = rlp.EncodeToBytes(MockNonCanonicalBlock.Header())
|
MockNonCanonicalHeaderRlp, _ = rlp.EncodeToBytes(MockNonCanonicalBlock.Header())
|
||||||
|
|
||||||
// non-canonical block at London height + 1
|
// non-canonical block at London height + 1
|
||||||
// includes 3rd and 5th transactions from the canonical block
|
// includes 3rd and 5th transactions from the canonical block
|
||||||
Block2Number = big.NewInt(BlockNumber.Int64() + 1)
|
Block2Number = big.NewInt(BlockNumber.Int64() + 1)
|
||||||
|
Block2Time = BlockTime + 1
|
||||||
MockNonCanonicalHeader2 = types.Header{
|
MockNonCanonicalHeader2 = types.Header{
|
||||||
Time: 0,
|
Time: 0,
|
||||||
Number: new(big.Int).Set(Block2Number),
|
Number: new(big.Int).Set(Block2Number),
|
||||||
@ -82,7 +85,7 @@ var (
|
|||||||
Coinbase: common.HexToAddress("0xaE9BEa628c4Ce503DcFD7E305CaB4e29E7476777"),
|
Coinbase: common.HexToAddress("0xaE9BEa628c4Ce503DcFD7E305CaB4e29E7476777"),
|
||||||
}
|
}
|
||||||
MockNonCanonicalBlock2Transactions = types.Transactions{MockTransactions[2], MockTransactions[4]}
|
MockNonCanonicalBlock2Transactions = types.Transactions{MockTransactions[2], MockTransactions[4]}
|
||||||
MockNonCanonicalBlock2Receipts = createNonCanonicalBlockReceipts(TestChainConfig, Block2Number, MockNonCanonicalBlock2Transactions)
|
MockNonCanonicalBlock2Receipts = createNonCanonicalBlockReceipts(TestChainConfig, Block2Number, BlockTime, MockNonCanonicalBlock2Transactions)
|
||||||
MockNonCanonicalBlock2 = types.NewBlock(&MockNonCanonicalHeader2, MockNonCanonicalBlock2Transactions, nil, MockNonCanonicalBlock2Receipts, trie.NewEmpty(nil))
|
MockNonCanonicalBlock2 = types.NewBlock(&MockNonCanonicalHeader2, MockNonCanonicalBlock2Transactions, nil, MockNonCanonicalBlock2Receipts, trie.NewEmpty(nil))
|
||||||
MockNonCanonicalHeader2Rlp, _ = rlp.EncodeToBytes(MockNonCanonicalBlock2.Header())
|
MockNonCanonicalHeader2Rlp, _ = rlp.EncodeToBytes(MockNonCanonicalBlock2.Header())
|
||||||
|
|
||||||
@ -158,7 +161,7 @@ var (
|
|||||||
ContractLeafKey = test_helpers.AddressToLeafKey(ContractAddress)
|
ContractLeafKey = test_helpers.AddressToLeafKey(ContractAddress)
|
||||||
ContractAccount = &types.StateAccount{
|
ContractAccount = &types.StateAccount{
|
||||||
Nonce: nonce1,
|
Nonce: nonce1,
|
||||||
Balance: big.NewInt(0),
|
Balance: uint256.NewInt(0),
|
||||||
CodeHash: ContractCodeHash.Bytes(),
|
CodeHash: ContractCodeHash.Bytes(),
|
||||||
Root: common.HexToHash(ContractRoot),
|
Root: common.HexToHash(ContractRoot),
|
||||||
}
|
}
|
||||||
@ -182,7 +185,7 @@ var (
|
|||||||
AccountCodeHash = common.HexToHash("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470")
|
AccountCodeHash = common.HexToHash("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470")
|
||||||
AccountLeafKey = test_helpers.Account2LeafKey
|
AccountLeafKey = test_helpers.Account2LeafKey
|
||||||
RemovedLeafKey = test_helpers.Account1LeafKey
|
RemovedLeafKey = test_helpers.Account1LeafKey
|
||||||
Balance, _ = new(big.Int).SetString("106387458790507306766", 10)
|
Balance = uint256.MustFromDecimal("106387458790507306766")
|
||||||
Account = &types.StateAccount{
|
Account = &types.StateAccount{
|
||||||
Nonce: nonce0,
|
Nonce: nonce0,
|
||||||
Balance: Balance,
|
Balance: Balance,
|
||||||
@ -381,7 +384,9 @@ func createLegacyTransactionsAndReceipts(config *params.ChainConfig, blockNumber
|
|||||||
trx2 := types.NewTransaction(1, AnotherAddress, big.NewInt(2000), 100, big.NewInt(200), []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)
|
trx3 := types.NewContractCreation(2, big.NewInt(1500), 75, big.NewInt(150), MockContractByteCode)
|
||||||
|
|
||||||
transactionSigner := types.MakeSigner(config, blockNumber)
|
// For legacy data, block time is not relevant
|
||||||
|
blockTime := uint64(0)
|
||||||
|
transactionSigner := types.MakeSigner(config, blockNumber, blockTime)
|
||||||
mockCurve := elliptic.P256()
|
mockCurve := elliptic.P256()
|
||||||
mockPrvKey, err := ecdsa.GenerateKey(mockCurve, rand.Reader)
|
mockPrvKey, err := ecdsa.GenerateKey(mockCurve, rand.Reader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -420,7 +425,7 @@ func createLegacyTransactionsAndReceipts(config *params.ChainConfig, blockNumber
|
|||||||
}
|
}
|
||||||
|
|
||||||
// createTransactionsAndReceipts is a helper function to generate signed mock transactions and mock receipts with mock logs
|
// createTransactionsAndReceipts is a helper function to generate signed mock transactions and mock receipts with mock logs
|
||||||
func createTransactionsAndReceipts(config *params.ChainConfig, blockNumber *big.Int) (types.Transactions, types.Receipts, common.Address) {
|
func createTransactionsAndReceipts(config *params.ChainConfig, blockNumber *big.Int, blockTime uint64) (types.Transactions, types.Receipts, common.Address) {
|
||||||
// make transactions
|
// make transactions
|
||||||
trx1 := types.NewTransaction(0, Address, big.NewInt(1000), 50, big.NewInt(100), []byte{})
|
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{})
|
trx2 := types.NewTransaction(1, AnotherAddress, big.NewInt(2000), 100, big.NewInt(200), []byte{})
|
||||||
@ -453,7 +458,7 @@ func createTransactionsAndReceipts(config *params.ChainConfig, blockNumber *big.
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
transactionSigner := types.MakeSigner(config, blockNumber)
|
transactionSigner := types.MakeSigner(config, blockNumber, blockTime)
|
||||||
mockCurve := elliptic.P256()
|
mockCurve := elliptic.P256()
|
||||||
mockPrvKey, err := ecdsa.GenerateKey(mockCurve, rand.Reader)
|
mockPrvKey, err := ecdsa.GenerateKey(mockCurve, rand.Reader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -516,8 +521,8 @@ func createTransactionsAndReceipts(config *params.ChainConfig, blockNumber *big.
|
|||||||
}
|
}
|
||||||
|
|
||||||
// createNonCanonicalBlockReceipts is a helper function to generate mock receipts with mock logs for non-canonical blocks
|
// createNonCanonicalBlockReceipts is a helper function to generate mock receipts with mock logs for non-canonical blocks
|
||||||
func createNonCanonicalBlockReceipts(config *params.ChainConfig, blockNumber *big.Int, transactions types.Transactions) types.Receipts {
|
func createNonCanonicalBlockReceipts(config *params.ChainConfig, blockNumber *big.Int, blockTime uint64, transactions types.Transactions) types.Receipts {
|
||||||
transactionSigner := types.MakeSigner(config, blockNumber)
|
transactionSigner := types.MakeSigner(config, blockNumber, blockTime)
|
||||||
mockCurve := elliptic.P256()
|
mockCurve := elliptic.P256()
|
||||||
mockPrvKey, err := ecdsa.GenerateKey(mockCurve, rand.Reader)
|
mockPrvKey, err := ecdsa.GenerateKey(mockCurve, rand.Reader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -33,9 +33,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func GenesisBlockForTesting(db ethdb.Database, addr common.Address, balance, baseFee *big.Int, initialGasLimit uint64) *types.Block {
|
func GenesisBlockForTesting(db ethdb.Database, addr common.Address, balance, baseFee *big.Int, initialGasLimit uint64) *types.Block {
|
||||||
alloc := map[common.Address]types.Account{
|
alloc := map[common.Address]types.Account{addr: {Balance: balance}}
|
||||||
addr: types.Account{Balance: balance}}
|
|
||||||
g := core.Genesis{
|
g := core.Genesis{
|
||||||
|
Config: TestChainConfig,
|
||||||
Alloc: alloc,
|
Alloc: alloc,
|
||||||
BaseFee: baseFee,
|
BaseFee: baseFee,
|
||||||
}
|
}
|
||||||
@ -48,7 +48,7 @@ func GenesisBlockForTesting(db ethdb.Database, addr common.Address, balance, bas
|
|||||||
// MakeChain creates a chain of n blocks starting at and including parent.
|
// MakeChain creates a chain of n blocks starting at and including parent.
|
||||||
// the returned hash chain is ordered head->parent.
|
// the returned hash chain is ordered head->parent.
|
||||||
func MakeChain(n int, parent *types.Block, chainGen func(int, *core.BlockGen)) ([]*types.Block, *core.BlockChain) {
|
func MakeChain(n int, parent *types.Block, chainGen func(int, *core.BlockGen)) ([]*types.Block, *core.BlockChain) {
|
||||||
config := params.TestChainConfig
|
config := TestChainConfig
|
||||||
blocks, _ := core.GenerateChain(config, parent, ethash.NewFaker(), Testdb, n, chainGen)
|
blocks, _ := core.GenerateChain(config, parent, ethash.NewFaker(), Testdb, n, chainGen)
|
||||||
chain, _ := core.NewBlockChain(Testdb, nil, nil, nil, ethash.NewFaker(), vm.Config{}, nil, nil)
|
chain, _ := core.NewBlockChain(Testdb, nil, nil, nil, ethash.NewFaker(), vm.Config{}, nil, nil)
|
||||||
return blocks, chain
|
return blocks, chain
|
||||||
|
@ -52,6 +52,7 @@ var (
|
|||||||
StorageValue = utils.Hex2Bytes("0x03")
|
StorageValue = utils.Hex2Bytes("0x03")
|
||||||
NullHash = common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000")
|
NullHash = common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000")
|
||||||
|
|
||||||
|
TestChainConfig = &*params.TestChainConfig
|
||||||
Testdb = rawdb.NewMemoryDatabase()
|
Testdb = rawdb.NewMemoryDatabase()
|
||||||
TestBankKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
|
TestBankKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
|
||||||
TestBankAddress = crypto.PubkeyToAddress(TestBankKey.PublicKey) //0x71562b71999873DB5b286dF957af199Ec94617F7
|
TestBankAddress = crypto.PubkeyToAddress(TestBankKey.PublicKey) //0x71562b71999873DB5b286dF957af199Ec94617F7
|
||||||
|
Loading…
Reference in New Issue
Block a user