diff --git a/blockchain/blockchain_test.go b/blockchain/blockchain_test.go index 76ebc1b164..af805becb2 100644 --- a/blockchain/blockchain_test.go +++ b/blockchain/blockchain_test.go @@ -268,6 +268,31 @@ func TestStore(t *testing.T) { }) } +func TestBlockCommitmetns(t *testing.T) { + chain := blockchain.New(pebble.NewMemTest(t), &utils.Mainnet) + client := feeder.NewTestClient(t, &utils.Mainnet) + gw := adaptfeeder.New(client) + + b, err := gw.BlockByNumber(context.Background(), 0) + require.NoError(t, err) + + su, err := gw.StateUpdate(context.Background(), 0) + require.NoError(t, err) + + expectedCommitments := &core.BlockCommitments{ + TransactionCommitment: new(felt.Felt).SetUint64(1), + EventCommitment: new(felt.Felt).SetUint64(2), + ReceiptCommitment: new(felt.Felt).SetUint64(3), + StateDiffCommitment: new(felt.Felt).SetUint64(4), + } + + require.NoError(t, chain.Store(b, expectedCommitments, su, nil)) + + commitments, err := chain.BlockCommitmentsByNumber(0) + require.NoError(t, err) + require.Equal(t, expectedCommitments, commitments) +} + func TestTransactionAndReceipt(t *testing.T) { chain := blockchain.New(pebble.NewMemTest(t), &utils.Mainnet) diff --git a/core/block.go b/core/block.go index 9eb620ded4..a59df0e721 100644 --- a/core/block.go +++ b/core/block.go @@ -69,6 +69,7 @@ type BlockCommitments struct { TransactionCommitment *felt.Felt EventCommitment *felt.Felt ReceiptCommitment *felt.Felt + StateDiffCommitment *felt.Felt } // VerifyBlockHash verifies the block hash. Due to bugs in Starknet alpha, not all blocks have @@ -247,6 +248,8 @@ func Post0132Hash(b *Block, stateDiff *StateDiff) (*felt.Felt, *BlockCommitments ), &BlockCommitments{ TransactionCommitment: txCommitment, EventCommitment: eCommitment, + ReceiptCommitment: rCommitment, + StateDiffCommitment: sdCommitment, }, nil }