@@ -41,6 +41,7 @@ import (
41
41
"github.com/ethereum/go-ethereum/ethdb"
42
42
"github.com/ethereum/go-ethereum/params"
43
43
"github.com/ethereum/go-ethereum/trie"
44
+ "github.com/protolambda/ztyp/view"
44
45
)
45
46
46
47
// So we can deterministically seed different blockchains
@@ -3704,3 +3705,87 @@ func TestEIP1559Transition(t *testing.T) {
3704
3705
t .Fatalf ("sender balance incorrect: expected %d, got %d" , expected , actual )
3705
3706
}
3706
3707
}
3708
+
3709
+ // TestDataBlobTxs tests the following:
3710
+ //
3711
+ // 1. Writes data hash from transaction to storage.
3712
+ func TestDataBlobTxs (t * testing.T ) {
3713
+ var (
3714
+ one = common.Hash {1 }
3715
+ two = common.Hash {2 }
3716
+ aa = common .HexToAddress ("0x000000000000000000000000000000000000aaaa" )
3717
+
3718
+ // Generate a canonical chain to act as the main dataset
3719
+ engine = ethash .NewFaker ()
3720
+ db = rawdb .NewMemoryDatabase ()
3721
+
3722
+ // A sender who makes transactions, has some funds
3723
+ key1 , _ = crypto .HexToECDSA ("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291" )
3724
+ addr1 = crypto .PubkeyToAddress (key1 .PublicKey )
3725
+ funds = new (big.Int ).Mul (common .Big1 , big .NewInt (params .Ether ))
3726
+ gspec = & Genesis {
3727
+ Config : params .AllEthashProtocolChanges ,
3728
+ Alloc : GenesisAlloc {
3729
+ addr1 : {Balance : funds },
3730
+ // The address 0xAAAA writes dataHashes[1] to storage slot 0x0.
3731
+ aa : {
3732
+ Code : []byte {
3733
+ byte (vm .PUSH1 ),
3734
+ byte (0x1 ),
3735
+ byte (vm .DATAHASH ),
3736
+ byte (vm .PUSH1 ),
3737
+ byte (0x0 ),
3738
+ byte (vm .SSTORE ),
3739
+ },
3740
+ Nonce : 0 ,
3741
+ Balance : big .NewInt (0 ),
3742
+ },
3743
+ },
3744
+ }
3745
+ )
3746
+
3747
+ gspec .Config .BerlinBlock = common .Big0
3748
+ gspec .Config .LondonBlock = common .Big0
3749
+ gspec .Config .ShardingForkBlock = common .Big0
3750
+ genesis := gspec .MustCommit (db )
3751
+ signer := types .LatestSigner (gspec .Config )
3752
+
3753
+ blocks , _ := GenerateChain (gspec .Config , genesis , engine , db , 1 , func (i int , b * BlockGen ) {
3754
+ b .SetCoinbase (common.Address {1 })
3755
+ msg := types.BlobTxMessage {
3756
+ Nonce : 0 ,
3757
+ Gas : 500000 ,
3758
+ }
3759
+ msg .To .Address = (* types .AddressSSZ )(& aa )
3760
+ msg .ChainID .SetFromBig ((* big .Int )(gspec .Config .ChainID ))
3761
+ msg .Nonce = view .Uint64View (0 )
3762
+ msg .GasFeeCap .SetFromBig (newGwei (5 ))
3763
+ msg .GasTipCap .SetFromBig (big .NewInt (2 ))
3764
+ msg .BlobVersionedHashes = []common.Hash {one , two }
3765
+ txdata := & types.SignedBlobTx {Message : msg }
3766
+
3767
+ tx := types .NewTx (txdata )
3768
+ tx , _ = types .SignTx (tx , signer , key1 )
3769
+
3770
+ b .AddTx (tx )
3771
+ })
3772
+
3773
+ diskdb := rawdb .NewMemoryDatabase ()
3774
+ gspec .MustCommit (diskdb )
3775
+
3776
+ chain , err := NewBlockChain (diskdb , nil , gspec .Config , engine , vm.Config {}, nil , nil )
3777
+ if err != nil {
3778
+ t .Fatalf ("failed to create tester chain: %v" , err )
3779
+ }
3780
+ if n , err := chain .InsertChain (blocks ); err != nil {
3781
+ t .Fatalf ("block %d: failed to insert into chain: %v" , n , err )
3782
+ }
3783
+
3784
+ state , _ := chain .State ()
3785
+
3786
+ // 1. Check that the storage slot is set to dataHashes[1].
3787
+ actual := state .GetState (aa , common.Hash {0 })
3788
+ if actual != two {
3789
+ t .Fatalf ("incorrect data hash written to state (want: %s, got: %s)" , two , actual )
3790
+ }
3791
+ }
0 commit comments