@ -52,7 +52,7 @@ var (
func newCanonical ( engine consensus . Engine , n int , full bool ) ( ethdb . Database , * BlockChain , error ) {
var (
db = rawdb . NewMemoryDatabase ( )
genesis = new ( Genesis ) . MustCommit ( db )
genesis = ( & Genesis { BaseFee : big . NewInt ( params . InitialBaseFee ) } ) . MustCommit ( db )
)
// Initialize a fresh chain with only a genesis block
@ -598,10 +598,11 @@ func TestFastVsFullChains(t *testing.T) {
gendb = rawdb . NewMemoryDatabase ( )
key , _ = crypto . HexToECDSA ( "b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291" )
address = crypto . PubkeyToAddress ( key . PublicKey )
funds = big . NewInt ( 1000000000 )
funds = big . NewInt ( 1000000000000000 )
gspec = & Genesis {
Config : params . TestChainConfig ,
Alloc : GenesisAlloc { address : { Balance : funds } } ,
Config : params . TestChainConfig ,
Alloc : GenesisAlloc { address : { Balance : funds } } ,
BaseFee : big . NewInt ( params . InitialBaseFee ) ,
}
genesis = gspec . MustCommit ( gendb )
signer = types . LatestSigner ( gspec . Config )
@ -612,7 +613,7 @@ func TestFastVsFullChains(t *testing.T) {
// If the block number is multiple of 3, send a few bonus transactions to the miner
if i % 3 == 2 {
for j := 0 ; j < i % 4 + 1 ; j ++ {
tx , err := types . SignTx ( types . NewTransaction ( block . TxNonce ( address ) , common . Address { 0x00 } , big . NewInt ( 1000 ) , params . TxGas , nil , nil ) , signer , key )
tx , err := types . SignTx ( types . NewTransaction ( block . TxNonce ( address ) , common . Address { 0x00 } , big . NewInt ( 1000 ) , params . TxGas , block . header . BaseFee , nil ) , signer , key )
if err != nil {
panic ( err )
}
@ -715,8 +716,12 @@ func TestLightVsFastVsFullChainHeads(t *testing.T) {
gendb = rawdb . NewMemoryDatabase ( )
key , _ = crypto . HexToECDSA ( "b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291" )
address = crypto . PubkeyToAddress ( key . PublicKey )
funds = big . NewInt ( 1000000000 )
gspec = & Genesis { Config : params . TestChainConfig , Alloc : GenesisAlloc { address : { Balance : funds } } }
funds = big . NewInt ( 1000000000000000 )
gspec = & Genesis {
Config : params . TestChainConfig ,
Alloc : GenesisAlloc { address : { Balance : funds } } ,
BaseFee : big . NewInt ( params . InitialBaseFee ) ,
}
genesis = gspec . MustCommit ( gendb )
)
height := uint64 ( 1024 )
@ -837,9 +842,9 @@ func TestChainTxReorgs(t *testing.T) {
Config : params . TestChainConfig ,
GasLimit : 3141592 ,
Alloc : GenesisAlloc {
addr1 : { Balance : big . NewInt ( 1000000 ) } ,
addr2 : { Balance : big . NewInt ( 1000000 ) } ,
addr3 : { Balance : big . NewInt ( 1000000 ) } ,
addr1 : { Balance : big . NewInt ( 1000000000000000 ) } ,
addr2 : { Balance : big . NewInt ( 1000000000000000 ) } ,
addr3 : { Balance : big . NewInt ( 1000000000000000 ) } ,
} ,
}
genesis = gspec . MustCommit ( db )
@ -849,8 +854,8 @@ func TestChainTxReorgs(t *testing.T) {
// Create two transactions shared between the chains:
// - postponed: transaction included at a later block in the forked chain
// - swapped: transaction included at the same block number in the forked chain
postponed , _ := types . SignTx ( types . NewTransaction ( 0 , addr1 , big . NewInt ( 1000 ) , params . TxGas , nil , nil ) , signer , key1 )
swapped , _ := types . SignTx ( types . NewTransaction ( 1 , addr1 , big . NewInt ( 1000 ) , params . TxGas , nil , nil ) , signer , key1 )
postponed , _ := types . SignTx ( types . NewTransaction ( 0 , addr1 , big . NewInt ( 1000 ) , params . TxGas , big . NewInt ( params . InitialBaseFee ) , nil ) , signer , key1 )
swapped , _ := types . SignTx ( types . NewTransaction ( 1 , addr1 , big . NewInt ( 1000 ) , params . TxGas , big . NewInt ( params . InitialBaseFee ) , nil ) , signer , key1 )
// Create two transactions that will be dropped by the forked chain:
// - pastDrop: transaction dropped retroactively from a past block
@ -866,13 +871,13 @@ func TestChainTxReorgs(t *testing.T) {
chain , _ := GenerateChain ( gspec . Config , genesis , ethash . NewFaker ( ) , db , 3 , func ( i int , gen * BlockGen ) {
switch i {
case 0 :
pastDrop , _ = types . SignTx ( types . NewTransaction ( gen . TxNonce ( addr2 ) , addr2 , big . NewInt ( 1000 ) , params . TxGas , nil , nil ) , signer , key2 )
pastDrop , _ = types . SignTx ( types . NewTransaction ( gen . TxNonce ( addr2 ) , addr2 , big . NewInt ( 1000 ) , params . TxGas , gen . header . BaseFee , nil ) , signer , key2 )
gen . AddTx ( pastDrop ) // This transaction will be dropped in the fork from below the split point
gen . AddTx ( postponed ) // This transaction will be postponed till block #3 in the fork
case 2 :
freshDrop , _ = types . SignTx ( types . NewTransaction ( gen . TxNonce ( addr2 ) , addr2 , big . NewInt ( 1000 ) , params . TxGas , nil , nil ) , signer , key2 )
freshDrop , _ = types . SignTx ( types . NewTransaction ( gen . TxNonce ( addr2 ) , addr2 , big . NewInt ( 1000 ) , params . TxGas , gen . header . BaseFee , nil ) , signer , key2 )
gen . AddTx ( freshDrop ) // This transaction will be dropped in the fork from exactly at the split point
gen . AddTx ( swapped ) // This transaction will be swapped out at the exact height
@ -891,18 +896,18 @@ func TestChainTxReorgs(t *testing.T) {
chain , _ = GenerateChain ( gspec . Config , genesis , ethash . NewFaker ( ) , db , 5 , func ( i int , gen * BlockGen ) {
switch i {
case 0 :
pastAdd , _ = types . SignTx ( types . NewTransaction ( gen . TxNonce ( addr3 ) , addr3 , big . NewInt ( 1000 ) , params . TxGas , nil , nil ) , signer , key3 )
pastAdd , _ = types . SignTx ( types . NewTransaction ( gen . TxNonce ( addr3 ) , addr3 , big . NewInt ( 1000 ) , params . TxGas , gen . header . BaseFee , nil ) , signer , key3 )
gen . AddTx ( pastAdd ) // This transaction needs to be injected during reorg
case 2 :
gen . AddTx ( postponed ) // This transaction was postponed from block #1 in the original chain
gen . AddTx ( swapped ) // This transaction was swapped from the exact current spot in the original chain
freshAdd , _ = types . SignTx ( types . NewTransaction ( gen . TxNonce ( addr3 ) , addr3 , big . NewInt ( 1000 ) , params . TxGas , nil , nil ) , signer , key3 )
freshAdd , _ = types . SignTx ( types . NewTransaction ( gen . TxNonce ( addr3 ) , addr3 , big . NewInt ( 1000 ) , params . TxGas , gen . header . BaseFee , nil ) , signer , key3 )
gen . AddTx ( freshAdd ) // This transaction will be added exactly at reorg time
case 3 :
futureAdd , _ = types . SignTx ( types . NewTransaction ( gen . TxNonce ( addr3 ) , addr3 , big . NewInt ( 1000 ) , params . TxGas , nil , nil ) , signer , key3 )
futureAdd , _ = types . SignTx ( types . NewTransaction ( gen . TxNonce ( addr3 ) , addr3 , big . NewInt ( 1000 ) , params . TxGas , gen . header . BaseFee , nil ) , signer , key3 )
gen . AddTx ( futureAdd ) // This transaction will be added after a full reorg
}
} )
@ -946,7 +951,7 @@ func TestLogReorgs(t *testing.T) {
db = rawdb . NewMemoryDatabase ( )
// this code generates a log
code = common . Hex2Bytes ( "60606040525b7f24ec1d3ff24c2f6ff210738839dbc339cd45a5294d85c79361016243157aae7b60405180905060405180910390a15b600a8060416000396000f360606040526008565b00" )
gspec = & Genesis { Config : params . TestChainConfig , Alloc : GenesisAlloc { addr1 : { Balance : big . NewInt ( 10000000000000 ) } } }
gspec = & Genesis { Config : params . TestChainConfig , Alloc : GenesisAlloc { addr1 : { Balance : big . NewInt ( 10000000000000000 ) } } }
genesis = gspec . MustCommit ( db )
signer = types . LatestSigner ( gspec . Config )
)
@ -958,7 +963,7 @@ func TestLogReorgs(t *testing.T) {
blockchain . SubscribeRemovedLogsEvent ( rmLogsCh )
chain , _ := GenerateChain ( params . TestChainConfig , genesis , ethash . NewFaker ( ) , db , 2 , func ( i int , gen * BlockGen ) {
if i == 1 {
tx , err := types . SignTx ( types . NewContractCreation ( gen . TxNonce ( addr1 ) , new ( big . Int ) , 1000000 , new ( big . Int ) , code ) , signer , key1 )
tx , err := types . SignTx ( types . NewContractCreation ( gen . TxNonce ( addr1 ) , new ( big . Int ) , 1000000 , gen . header . BaseFee , code ) , signer , key1 )
if err != nil {
t . Fatalf ( "failed to create tx: %v" , err )
}
@ -1000,7 +1005,7 @@ func TestLogRebirth(t *testing.T) {
key1 , _ = crypto . HexToECDSA ( "b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291" )
addr1 = crypto . PubkeyToAddress ( key1 . PublicKey )
db = rawdb . NewMemoryDatabase ( )
gspec = & Genesis { Config : params . TestChainConfig , Alloc : GenesisAlloc { addr1 : { Balance : big . NewInt ( 10000000000000 ) } } }
gspec = & Genesis { Config : params . TestChainConfig , Alloc : GenesisAlloc { addr1 : { Balance : big . NewInt ( 10000000000000000 ) } } }
genesis = gspec . MustCommit ( db )
signer = types . LatestSigner ( gspec . Config )
engine = ethash . NewFaker ( )
@ -1018,7 +1023,7 @@ func TestLogRebirth(t *testing.T) {
// This chain contains a single log.
chain , _ := GenerateChain ( params . TestChainConfig , genesis , engine , db , 2 , func ( i int , gen * BlockGen ) {
if i == 1 {
tx , err := types . SignTx ( types . NewContractCreation ( gen . TxNonce ( addr1 ) , new ( big . Int ) , 1000000 , new ( big . Int ) , logCode ) , signer , key1 )
tx , err := types . SignTx ( types . NewContractCreation ( gen . TxNonce ( addr1 ) , new ( big . Int ) , 1000000 , gen . header . BaseFee , logCode ) , signer , key1 )
if err != nil {
t . Fatalf ( "failed to create tx: %v" , err )
}
@ -1034,7 +1039,7 @@ func TestLogRebirth(t *testing.T) {
// chain removes one log and adds one.
forkChain , _ := GenerateChain ( params . TestChainConfig , genesis , engine , db , 2 , func ( i int , gen * BlockGen ) {
if i == 1 {
tx , err := types . SignTx ( types . NewContractCreation ( gen . TxNonce ( addr1 ) , new ( big . Int ) , 1000000 , new ( big . Int ) , logCode ) , signer , key1 )
tx , err := types . SignTx ( types . NewContractCreation ( gen . TxNonce ( addr1 ) , new ( big . Int ) , 1000000 , gen . header . BaseFee , logCode ) , signer , key1 )
if err != nil {
t . Fatalf ( "failed to create tx: %v" , err )
}
@ -1064,7 +1069,7 @@ func TestSideLogRebirth(t *testing.T) {
key1 , _ = crypto . HexToECDSA ( "b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291" )
addr1 = crypto . PubkeyToAddress ( key1 . PublicKey )
db = rawdb . NewMemoryDatabase ( )
gspec = & Genesis { Config : params . TestChainConfig , Alloc : GenesisAlloc { addr1 : { Balance : big . NewInt ( 10000000000000 ) } } }
gspec = & Genesis { Config : params . TestChainConfig , Alloc : GenesisAlloc { addr1 : { Balance : big . NewInt ( 10000000000000000 ) } } }
genesis = gspec . MustCommit ( db )
signer = types . LatestSigner ( gspec . Config )
blockchain , _ = NewBlockChain ( db , nil , gspec . Config , ethash . NewFaker ( ) , vm . Config { } , nil , nil )
@ -1091,7 +1096,7 @@ func TestSideLogRebirth(t *testing.T) {
// Generate side chain with lower difficulty
sideChain , _ := GenerateChain ( params . TestChainConfig , genesis , ethash . NewFaker ( ) , db , 2 , func ( i int , gen * BlockGen ) {
if i == 1 {
tx , err := types . SignTx ( types . NewContractCreation ( gen . TxNonce ( addr1 ) , new ( big . Int ) , 1000000 , new ( big . Int ) , logCode ) , signer , key1 )
tx , err := types . SignTx ( types . NewContractCreation ( gen . TxNonce ( addr1 ) , new ( big . Int ) , 1000000 , gen . header . BaseFee , logCode ) , signer , key1 )
if err != nil {
t . Fatalf ( "failed to create tx: %v" , err )
}
@ -1136,7 +1141,7 @@ func TestReorgSideEvent(t *testing.T) {
addr1 = crypto . PubkeyToAddress ( key1 . PublicKey )
gspec = & Genesis {
Config : params . TestChainConfig ,
Alloc : GenesisAlloc { addr1 : { Balance : big . NewInt ( 10000000000000 ) } } ,
Alloc : GenesisAlloc { addr1 : { Balance : big . NewInt ( 10000000000000000 ) } } ,
}
genesis = gspec . MustCommit ( db )
signer = types . LatestSigner ( gspec . Config )
@ -1151,7 +1156,7 @@ func TestReorgSideEvent(t *testing.T) {
}
replacementBlocks , _ := GenerateChain ( gspec . Config , genesis , ethash . NewFaker ( ) , db , 4 , func ( i int , gen * BlockGen ) {
tx , err := types . SignTx ( types . NewContractCreation ( gen . TxNonce ( addr1 ) , new ( big . Int ) , 1000000 , new ( big . Int ) , nil ) , signer , key1 )
tx , err := types . SignTx ( types . NewContractCreation ( gen . TxNonce ( addr1 ) , new ( big . Int ) , 1000000 , gen . header . BaseFee , nil ) , signer , key1 )
if i == 2 {
gen . OffsetTime ( - 9 )
}
@ -1439,7 +1444,7 @@ func TestBlockchainHeaderchainReorgConsistency(t *testing.T) {
engine := ethash . NewFaker ( )
db := rawdb . NewMemoryDatabase ( )
genesis := new ( Genesis ) . MustCommit ( db )
genesis := ( & Genesis { BaseFee : big . NewInt ( params . InitialBaseFee ) } ) . MustCommit ( db )
blocks , _ := GenerateChain ( params . TestChainConfig , genesis , engine , db , 64 , func ( i int , b * BlockGen ) { b . SetCoinbase ( common . Address { 1 } ) } )
// Generate a bunch of fork blocks, each side forking from the canonical chain
@ -1455,7 +1460,7 @@ func TestBlockchainHeaderchainReorgConsistency(t *testing.T) {
// Import the canonical and fork chain side by side, verifying the current block
// and current header consistency
diskdb := rawdb . NewMemoryDatabase ( )
new ( Genesis ) . MustCommit ( diskdb )
( & Genesis { BaseFee : big . NewInt ( params . InitialBaseFee ) } ) . MustCommit ( diskdb )
chain , err := NewBlockChain ( diskdb , nil , params . TestChainConfig , engine , vm . Config { } , nil , nil )
if err != nil {
@ -1484,7 +1489,7 @@ func TestTrieForkGC(t *testing.T) {
engine := ethash . NewFaker ( )
db := rawdb . NewMemoryDatabase ( )
genesis := new ( Genesis ) . MustCommit ( db )
genesis := ( & Genesis { BaseFee : big . NewInt ( params . InitialBaseFee ) } ) . MustCommit ( db )
blocks , _ := GenerateChain ( params . TestChainConfig , genesis , engine , db , 2 * TriesInMemory , func ( i int , b * BlockGen ) { b . SetCoinbase ( common . Address { 1 } ) } )
// Generate a bunch of fork blocks, each side forking from the canonical chain
@ -1499,7 +1504,7 @@ func TestTrieForkGC(t *testing.T) {
}
// Import the canonical and fork chain side by side, forcing the trie cache to cache both
diskdb := rawdb . NewMemoryDatabase ( )
new ( Genesis ) . MustCommit ( diskdb )
( & Genesis { BaseFee : big . NewInt ( params . InitialBaseFee ) } ) . MustCommit ( diskdb )
chain , err := NewBlockChain ( diskdb , nil , params . TestChainConfig , engine , vm . Config { } , nil , nil )
if err != nil {
@ -1530,7 +1535,7 @@ func TestLargeReorgTrieGC(t *testing.T) {
engine := ethash . NewFaker ( )
db := rawdb . NewMemoryDatabase ( )
genesis := new ( Genesis ) . MustCommit ( db )
genesis := ( & Genesis { BaseFee : big . NewInt ( params . InitialBaseFee ) } ) . MustCommit ( db )
shared , _ := GenerateChain ( params . TestChainConfig , genesis , engine , db , 64 , func ( i int , b * BlockGen ) { b . SetCoinbase ( common . Address { 1 } ) } )
original , _ := GenerateChain ( params . TestChainConfig , shared [ len ( shared ) - 1 ] , engine , db , 2 * TriesInMemory , func ( i int , b * BlockGen ) { b . SetCoinbase ( common . Address { 2 } ) } )
@ -1538,7 +1543,7 @@ func TestLargeReorgTrieGC(t *testing.T) {
// Import the shared chain and the original canonical one
diskdb := rawdb . NewMemoryDatabase ( )
new ( Genesis ) . MustCommit ( diskdb )
( & Genesis { BaseFee : big . NewInt ( params . InitialBaseFee ) } ) . MustCommit ( diskdb )
chain , err := NewBlockChain ( diskdb , nil , params . TestChainConfig , engine , vm . Config { } , nil , nil )
if err != nil {
@ -1702,7 +1707,7 @@ func TestLowDiffLongChain(t *testing.T) {
// Generate a canonical chain to act as the main dataset
engine := ethash . NewFaker ( )
db := rawdb . NewMemoryDatabase ( )
genesis := new ( Genesis ) . MustCommit ( db )
genesis := ( & Genesis { BaseFee : big . NewInt ( params . InitialBaseFee ) } ) . MustCommit ( db )
// We must use a pretty long chain to ensure that the fork doesn't overtake us
// until after at least 128 blocks post tip
@ -1713,7 +1718,7 @@ func TestLowDiffLongChain(t *testing.T) {
// Import the canonical chain
diskdb := rawdb . NewMemoryDatabase ( )
new ( Genesis ) . MustCommit ( diskdb )
( & Genesis { BaseFee : big . NewInt ( params . InitialBaseFee ) } ) . MustCommit ( diskdb )
chain , err := NewBlockChain ( diskdb , nil , params . TestChainConfig , engine , vm . Config { } , nil , nil )
if err != nil {
@ -1756,12 +1761,12 @@ func testSideImport(t *testing.T, numCanonBlocksInSidechain, blocksBetweenCommon
// Generate a canonical chain to act as the main dataset
engine := ethash . NewFaker ( )
db := rawdb . NewMemoryDatabase ( )
genesis := new ( Genesis ) . MustCommit ( db )
genesis := ( & Genesis { BaseFee : big . NewInt ( params . InitialBaseFee ) } ) . MustCommit ( db )
// Generate and import the canonical chain
blocks , _ := GenerateChain ( params . TestChainConfig , genesis , engine , db , 2 * TriesInMemory , nil )
diskdb := rawdb . NewMemoryDatabase ( )
new ( Genesis ) . MustCommit ( diskdb )
( & Genesis { BaseFee : big . NewInt ( params . InitialBaseFee ) } ) . MustCommit ( diskdb )
chain , err := NewBlockChain ( diskdb , nil , params . TestChainConfig , engine , vm . Config { } , nil , nil )
if err != nil {
t . Fatalf ( "failed to create tester chain: %v" , err )
@ -1836,7 +1841,7 @@ func testInsertKnownChainData(t *testing.T, typ string) {
engine := ethash . NewFaker ( )
db := rawdb . NewMemoryDatabase ( )
genesis := new ( Genesis ) . MustCommit ( db )
genesis := ( & Genesis { BaseFee : big . NewInt ( params . InitialBaseFee ) } ) . MustCommit ( db )
blocks , receipts := GenerateChain ( params . TestChainConfig , genesis , engine , db , 32 , func ( i int , b * BlockGen ) { b . SetCoinbase ( common . Address { 1 } ) } )
// A longer chain but total difficulty is lower.
@ -1856,7 +1861,7 @@ func testInsertKnownChainData(t *testing.T, typ string) {
if err != nil {
t . Fatalf ( "failed to create temp freezer db: %v" , err )
}
new ( Genesis ) . MustCommit ( chaindb )
( & Genesis { BaseFee : big . NewInt ( params . InitialBaseFee ) } ) . MustCommit ( chaindb )
defer os . RemoveAll ( dir )
chain , err := NewBlockChain ( chaindb , nil , params . TestChainConfig , engine , vm . Config { } , nil , nil )
@ -1959,7 +1964,7 @@ func getLongAndShortChains() (*BlockChain, []*types.Block, []*types.Block, error
// Generate a canonical chain to act as the main dataset
engine := ethash . NewFaker ( )
db := rawdb . NewMemoryDatabase ( )
genesis := new ( Genesis ) . MustCommit ( db )
genesis := ( & Genesis { BaseFee : big . NewInt ( params . InitialBaseFee ) } ) . MustCommit ( db )
// Generate and import the canonical chain,
// Offset the time, to keep the difficulty low
@ -1967,7 +1972,7 @@ func getLongAndShortChains() (*BlockChain, []*types.Block, []*types.Block, error
b . SetCoinbase ( common . Address { 1 } )
} )
diskdb := rawdb . NewMemoryDatabase ( )
new ( Genesis ) . MustCommit ( diskdb )
( & Genesis { BaseFee : big . NewInt ( params . InitialBaseFee ) } ) . MustCommit ( diskdb )
chain , err := NewBlockChain ( diskdb , nil , params . TestChainConfig , engine , vm . Config { } , nil , nil )
if err != nil {
@ -2079,14 +2084,18 @@ func TestTransactionIndices(t *testing.T) {
gendb = rawdb . NewMemoryDatabase ( )
key , _ = crypto . HexToECDSA ( "b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291" )
address = crypto . PubkeyToAddress ( key . PublicKey )
funds = big . NewInt ( 1000000000 )
gspec = & Genesis { Config : params . TestChainConfig , Alloc : GenesisAlloc { address : { Balance : funds } } }
funds = big . NewInt ( 100000000000000000 )
gspec = & Genesis {
Config : params . TestChainConfig ,
Alloc : GenesisAlloc { address : { Balance : funds } } ,
BaseFee : big . NewInt ( params . InitialBaseFee ) ,
}
genesis = gspec . MustCommit ( gendb )
signer = types . LatestSigner ( gspec . Config )
)
height := uint64 ( 128 )
blocks , receipts := GenerateChain ( gspec . Config , genesis , ethash . NewFaker ( ) , gendb , int ( height ) , func ( i int , block * BlockGen ) {
tx , err := types . SignTx ( types . NewTransaction ( block . TxNonce ( address ) , common . Address { 0x00 } , big . NewInt ( 1000 ) , params . TxGas , nil , nil ) , signer , key )
tx , err := types . SignTx ( types . NewTransaction ( block . TxNonce ( address ) , common . Address { 0x00 } , big . NewInt ( 1000 ) , params . TxGas , block . header . BaseFee , nil ) , signer , key )
if err != nil {
panic ( err )
}
@ -2206,14 +2215,14 @@ func TestSkipStaleTxIndicesInFastSync(t *testing.T) {
gendb = rawdb . NewMemoryDatabase ( )
key , _ = crypto . HexToECDSA ( "b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291" )
address = crypto . PubkeyToAddress ( key . PublicKey )
funds = big . NewInt ( 1000000000 )
funds = big . NewInt ( 100000000000000000 )
gspec = & Genesis { Config : params . TestChainConfig , Alloc : GenesisAlloc { address : { Balance : funds } } }
genesis = gspec . MustCommit ( gendb )
signer = types . LatestSigner ( gspec . Config )
)
height := uint64 ( 128 )
blocks , receipts := GenerateChain ( gspec . Config , genesis , ethash . NewFaker ( ) , gendb , int ( height ) , func ( i int , block * BlockGen ) {
tx , err := types . SignTx ( types . NewTransaction ( block . TxNonce ( address ) , common . Address { 0x00 } , big . NewInt ( 1000 ) , params . TxGas , nil , nil ) , signer , key )
tx , err := types . SignTx ( types . NewTransaction ( block . TxNonce ( address ) , common . Address { 0x00 } , big . NewInt ( 1000 ) , params . TxGas , block . header . BaseFee , nil ) , signer , key )
if err != nil {
panic ( err )
}
@ -2407,12 +2416,12 @@ func TestSideImportPrunedBlocks(t *testing.T) {
// Generate a canonical chain to act as the main dataset
engine := ethash . NewFaker ( )
db := rawdb . NewMemoryDatabase ( )
genesis := new ( Genesis ) . MustCommit ( db )
genesis := ( & Genesis { BaseFee : big . NewInt ( params . InitialBaseFee ) } ) . MustCommit ( db )
// Generate and import the canonical chain
blocks , _ := GenerateChain ( params . TestChainConfig , genesis , engine , db , 2 * TriesInMemory , nil )
diskdb := rawdb . NewMemoryDatabase ( )
new ( Genesis ) . MustCommit ( diskdb )
( & Genesis { BaseFee : big . NewInt ( params . InitialBaseFee ) } ) . MustCommit ( diskdb )
chain , err := NewBlockChain ( diskdb , nil , params . TestChainConfig , engine , vm . Config { } , nil , nil )
if err != nil {
t . Fatalf ( "failed to create tester chain: %v" , err )
@ -2460,7 +2469,7 @@ func TestDeleteCreateRevert(t *testing.T) {
// A sender who makes transactions, has some funds
key , _ = crypto . HexToECDSA ( "b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291" )
address = crypto . PubkeyToAddress ( key . PublicKey )
funds = big . NewInt ( 1000000000 )
funds = big . NewInt ( 100000000000000000 )
gspec = & Genesis {
Config : params . TestChainConfig ,
Alloc : GenesisAlloc {
@ -2496,11 +2505,11 @@ func TestDeleteCreateRevert(t *testing.T) {
b . SetCoinbase ( common . Address { 1 } )
// One transaction to AAAA
tx , _ := types . SignTx ( types . NewTransaction ( 0 , aa ,
big . NewInt ( 0 ) , 50000 , big . NewInt ( 1 ) , nil ) , types . HomesteadSigner { } , key )
big . NewInt ( 0 ) , 50000 , b . header . BaseFee , nil ) , types . HomesteadSigner { } , key )
b . AddTx ( tx )
// One transaction to BBBB
tx , _ = types . SignTx ( types . NewTransaction ( 1 , bb ,
big . NewInt ( 0 ) , 100000 , big . NewInt ( 1 ) , nil ) , types . HomesteadSigner { } , key )
big . NewInt ( 0 ) , 100000 , b . header . BaseFee , nil ) , types . HomesteadSigner { } , key )
b . AddTx ( tx )
} )
// Import the canonical chain
@ -2531,7 +2540,7 @@ func TestDeleteRecreateSlots(t *testing.T) {
// A sender who makes transactions, has some funds
key , _ = crypto . HexToECDSA ( "b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291" )
address = crypto . PubkeyToAddress ( key . PublicKey )
funds = big . NewInt ( 1000000000 )
funds = big . NewInt ( 1000000000000000 )
bb = common . HexToAddress ( "0x000000000000000000000000000000000000bbbb" )
aaStorage = make ( map [ common . Hash ] common . Hash ) // Initial storage in AA
aaCode = [ ] byte { byte ( vm . PC ) , byte ( vm . SELFDESTRUCT ) } // Code for AA (simple selfdestruct)
@ -2608,11 +2617,11 @@ func TestDeleteRecreateSlots(t *testing.T) {
b . SetCoinbase ( common . Address { 1 } )
// One transaction to AA, to kill it
tx , _ := types . SignTx ( types . NewTransaction ( 0 , aa ,
big . NewInt ( 0 ) , 50000 , big . NewInt ( 1 ) , nil ) , types . HomesteadSigner { } , key )
big . NewInt ( 0 ) , 50000 , b . header . BaseFee , nil ) , types . HomesteadSigner { } , key )
b . AddTx ( tx )
// One transaction to BB, to recreate AA
tx , _ = types . SignTx ( types . NewTransaction ( 1 , bb ,
big . NewInt ( 0 ) , 100000 , big . NewInt ( 1 ) , nil ) , types . HomesteadSigner { } , key )
big . NewInt ( 0 ) , 100000 , b . header . BaseFee , nil ) , types . HomesteadSigner { } , key )
b . AddTx ( tx )
} )
// Import the canonical chain
@ -2658,7 +2667,7 @@ func TestDeleteRecreateAccount(t *testing.T) {
// A sender who makes transactions, has some funds
key , _ = crypto . HexToECDSA ( "b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291" )
address = crypto . PubkeyToAddress ( key . PublicKey )
funds = big . NewInt ( 1000000000 )
funds = big . NewInt ( 1000000000000000 )
aa = common . HexToAddress ( "0x7217d81b76bdd8707601e959454e3d776aee5f43" )
aaStorage = make ( map [ common . Hash ] common . Hash ) // Initial storage in AA
@ -2688,11 +2697,11 @@ func TestDeleteRecreateAccount(t *testing.T) {
b . SetCoinbase ( common . Address { 1 } )
// One transaction to AA, to kill it
tx , _ := types . SignTx ( types . NewTransaction ( 0 , aa ,
big . NewInt ( 0 ) , 50000 , big . NewInt ( 1 ) , nil ) , types . HomesteadSigner { } , key )
big . NewInt ( 0 ) , 50000 , b . header . BaseFee , nil ) , types . HomesteadSigner { } , key )
b . AddTx ( tx )
// One transaction to AA, to recreate it (but without storage
tx , _ = types . SignTx ( types . NewTransaction ( 1 , aa ,
big . NewInt ( 1 ) , 100000 , big . NewInt ( 1 ) , nil ) , types . HomesteadSigner { } , key )
big . NewInt ( 1 ) , 100000 , b . header . BaseFee , nil ) , types . HomesteadSigner { } , key )
b . AddTx ( tx )
} )
// Import the canonical chain
@ -2734,7 +2743,7 @@ func TestDeleteRecreateSlotsAcrossManyBlocks(t *testing.T) {
// A sender who makes transactions, has some funds
key , _ = crypto . HexToECDSA ( "b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291" )
address = crypto . PubkeyToAddress ( key . PublicKey )
funds = big . NewInt ( 1000000000 )
funds = big . NewInt ( 1000000000000000 )
bb = common . HexToAddress ( "0x000000000000000000000000000000000000bbbb" )
aaStorage = make ( map [ common . Hash ] common . Hash ) // Initial storage in AA
aaCode = [ ] byte { byte ( vm . PC ) , byte ( vm . SELFDESTRUCT ) } // Code for AA (simple selfdestruct)
@ -2820,9 +2829,9 @@ func TestDeleteRecreateSlotsAcrossManyBlocks(t *testing.T) {
values : map [ int ] int { 1 : 1 , 2 : 2 } ,
}
var expectations [ ] * expectation
var newDestruct = func ( e * expectation ) * types . Transaction {
var newDestruct = func ( e * expectation , b * BlockGen ) * types . Transaction {
tx , _ := types . SignTx ( types . NewTransaction ( nonce , aa ,
big . NewInt ( 0 ) , 50000 , big . NewInt ( 1 ) , nil ) , types . HomesteadSigner { } , key )
big . NewInt ( 0 ) , 50000 , b . header . BaseFee , nil ) , types . HomesteadSigner { } , key )
nonce ++
if e . exist {
e . exist = false
@ -2831,9 +2840,9 @@ func TestDeleteRecreateSlotsAcrossManyBlocks(t *testing.T) {
t . Logf ( "block %d; adding destruct\n" , e . blocknum )
return tx
}
var newResurrect = func ( e * expectation ) * types . Transaction {
var newResurrect = func ( e * expectation , b * BlockGen ) * types . Transaction {
tx , _ := types . SignTx ( types . NewTransaction ( nonce , bb ,
big . NewInt ( 0 ) , 100000 , big . NewInt ( 1 ) , nil ) , types . HomesteadSigner { } , key )
big . NewInt ( 0 ) , 100000 , b . header . BaseFee , nil ) , types . HomesteadSigner { } , key )
nonce ++
if ! e . exist {
e . exist = true
@ -2854,16 +2863,16 @@ func TestDeleteRecreateSlotsAcrossManyBlocks(t *testing.T) {
b . SetCoinbase ( common . Address { 1 } )
if i % 2 == 0 {
b . AddTx ( newDestruct ( exp ) )
b . AddTx ( newDestruct ( exp , b ) )
}
if i % 3 == 0 {
b . AddTx ( newResurrect ( exp ) )
b . AddTx ( newResurrect ( exp , b ) )
}
if i % 5 == 0 {
b . AddTx ( newDestruct ( exp ) )
b . AddTx ( newDestruct ( exp , b ) )
}
if i % 7 == 0 {
b . AddTx ( newResurrect ( exp ) )
b . AddTx ( newResurrect ( exp , b ) )
}
expectations = append ( expectations , exp )
current = exp
@ -2936,7 +2945,7 @@ func TestInitThenFailCreateContract(t *testing.T) {
// A sender who makes transactions, has some funds
key , _ = crypto . HexToECDSA ( "b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291" )
address = crypto . PubkeyToAddress ( key . PublicKey )
funds = big . NewInt ( 1000000000 )
funds = big . NewInt ( 1000000000000000 )
bb = common . HexToAddress ( "0x000000000000000000000000000000000000bbbb" )
)
@ -2997,7 +3006,7 @@ func TestInitThenFailCreateContract(t *testing.T) {
b . SetCoinbase ( common . Address { 1 } )
// One transaction to BB
tx , _ := types . SignTx ( types . NewTransaction ( nonce , bb ,
big . NewInt ( 0 ) , 100000 , big . NewInt ( 1 ) , nil ) , types . HomesteadSigner { } , key )
big . NewInt ( 0 ) , 100000 , b . header . BaseFee , nil ) , types . HomesteadSigner { } , key )
b . AddTx ( tx )
nonce ++
} )
@ -3051,7 +3060,7 @@ func TestEIP2718Transition(t *testing.T) {
// A sender who makes transactions, has some funds
key , _ = crypto . HexToECDSA ( "b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291" )
address = crypto . PubkeyToAddress ( key . PublicKey )
funds = big . NewInt ( 1000000000 )
funds = big . NewInt ( 1000000000000000 )
gspec = & Genesis {
Config : params . TestChainConfig ,
Alloc : GenesisAlloc {
@ -3082,7 +3091,7 @@ func TestEIP2718Transition(t *testing.T) {
Nonce : 0 ,
To : & aa ,
Gas : 30000 ,
GasPrice : big . NewInt ( 1 ) ,
GasPrice : b . header . BaseFee ,
AccessList : types . AccessList { {
Address : aa ,
StorageKeys : [ ] common . Hash { { 0 } } ,