@@ -2363,14 +2363,14 @@ func TestDeleteCreateRevert(t *testing.T) {
23632363 }
23642364}
23652365
2366- // TestDeleteRecreate tests a state-transition that contains both deletion
2366+ // TestDeleteRecreateSlots tests a state-transition that contains both deletion
23672367// and recreation of contract state.
23682368// Contract A exists, has slots 1 and 2 set
23692369// Tx 1: Selfdestruct A
23702370// Tx 2: Re-create A, set slots 3 and 4
23712371// Expected outcome is that _all_ slots are cleared from A, due to the selfdestruct,
23722372// and then the new slots exist
2373- func TestDeleteRecreate (t * testing.T ) {
2373+ func TestDeleteRecreateSlots (t * testing.T ) {
23742374 var (
23752375 // Generate a canonical chain to act as the main dataset
23762376 engine = ethash .NewFaker ()
@@ -2490,3 +2490,76 @@ func TestDeleteRecreate(t *testing.T) {
24902490 t .Fatalf ("got %x exp %x" , got , exp )
24912491 }
24922492}
2493+
2494+ // TestDeleteRecreateAccount tests a state-transition that contains deletion of a
2495+ // contract with storage, and a recreate of the same contract via a
2496+ // regular value-transfer
2497+ // Expected outcome is that _all_ slots are cleared from A
2498+ func TestDeleteRecreateAccount (t * testing.T ) {
2499+ var (
2500+ // Generate a canonical chain to act as the main dataset
2501+ engine = ethash .NewFaker ()
2502+ db = rawdb .NewMemoryDatabase ()
2503+ // A sender who makes transactions, has some funds
2504+ key , _ = crypto .HexToECDSA ("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291" )
2505+ address = crypto .PubkeyToAddress (key .PublicKey )
2506+ funds = big .NewInt (1000000000 )
2507+
2508+ aa = common .HexToAddress ("0x7217d81b76bdd8707601e959454e3d776aee5f43" )
2509+ aaStorage = make (map [common.Hash ]common.Hash ) // Initial storage in AA
2510+ aaCode = []byte {byte (vm .PC ), 0xFF } // Code for AA (simple selfdestruct)
2511+ )
2512+ // Populate two slots
2513+ aaStorage [common .HexToHash ("01" )] = common .HexToHash ("01" )
2514+ aaStorage [common .HexToHash ("02" )] = common .HexToHash ("02" )
2515+
2516+ gspec := & Genesis {
2517+ Config : params .TestChainConfig ,
2518+ Alloc : GenesisAlloc {
2519+ address : {Balance : funds },
2520+ // The address 0xAAAAA selfdestructs if called
2521+ aa : {
2522+ // Code needs to just selfdestruct
2523+ Code : aaCode ,
2524+ Nonce : 1 ,
2525+ Balance : big .NewInt (0 ),
2526+ Storage : aaStorage ,
2527+ },
2528+ },
2529+ }
2530+ genesis := gspec .MustCommit (db )
2531+
2532+ blocks , _ := GenerateChain (params .TestChainConfig , genesis , engine , db , 1 , func (i int , b * BlockGen ) {
2533+ b .SetCoinbase (common.Address {1 })
2534+ // One transaction to AA, to kill it
2535+ tx , _ := types .SignTx (types .NewTransaction (0 , aa ,
2536+ big .NewInt (0 ), 50000 , big .NewInt (1 ), nil ), types.HomesteadSigner {}, key )
2537+ b .AddTx (tx )
2538+ // One transaction to AA, to recreate it (but without storage
2539+ tx , _ = types .SignTx (types .NewTransaction (1 , aa ,
2540+ big .NewInt (1 ), 100000 , big .NewInt (1 ), nil ), types.HomesteadSigner {}, key )
2541+ b .AddTx (tx )
2542+ })
2543+ // Import the canonical chain
2544+ diskdb := rawdb .NewMemoryDatabase ()
2545+ gspec .MustCommit (diskdb )
2546+ chain , err := NewBlockChain (diskdb , nil , params .TestChainConfig , engine , vm.Config {
2547+ Debug : true ,
2548+ Tracer : vm .NewJSONLogger (nil , os .Stdout ),
2549+ }, nil )
2550+ if err != nil {
2551+ t .Fatalf ("failed to create tester chain: %v" , err )
2552+ }
2553+ if n , err := chain .InsertChain (blocks ); err != nil {
2554+ t .Fatalf ("block %d: failed to insert into chain: %v" , n , err )
2555+ }
2556+ statedb , _ := chain .State ()
2557+
2558+ // If all is correct, then both slots are zero
2559+ if got , exp := statedb .GetState (aa , common .HexToHash ("01" )), (common.Hash {}); got != exp {
2560+ t .Errorf ("got %x exp %x" , got , exp )
2561+ }
2562+ if got , exp := statedb .GetState (aa , common .HexToHash ("02" )), (common.Hash {}); got != exp {
2563+ t .Errorf ("got %x exp %x" , got , exp )
2564+ }
2565+ }
0 commit comments