Skip to content

Commit

Permalink
test bootstrap - wip
Browse files Browse the repository at this point in the history
  • Loading branch information
rian committed May 16, 2024
1 parent 713ed9c commit 16cb86b
Show file tree
Hide file tree
Showing 6 changed files with 37,407 additions and 35 deletions.
2 changes: 1 addition & 1 deletion builder/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

// bootstrap submits transactions inside a block directly into the mempool
// this allows us to bootstrap the network with unsupported transactions
func (b *Builder) bootstrapChain() error {
func (b *Builder) BootstrapChain() error {
if b.starknetData == nil {
return errors.New("can't bootstrap if the network isn't specified")
}
Expand Down
66 changes: 66 additions & 0 deletions builder/bootstrap_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package builder_test

import (
"context"
"crypto/rand"
"testing"
"time"

"github.com/NethermindEth/juno/blockchain"
"github.com/NethermindEth/juno/builder"
"github.com/NethermindEth/juno/clients/feeder"
"github.com/NethermindEth/juno/db/pebble"
"github.com/NethermindEth/juno/mempool"
"github.com/NethermindEth/juno/mocks"
adaptfeeder "github.com/NethermindEth/juno/starknetdata/feeder"
"github.com/NethermindEth/juno/utils"
"github.com/consensys/gnark-crypto/ecc/stark-curve/ecdsa"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
)

func TestBootstrapChain(t *testing.T) {
testDB := pebble.NewMemTest(t)
mockCtrl := gomock.NewController(t)
mockVM := mocks.NewMockVM(mockCtrl)
snData := mocks.NewMockStarknetData(mockCtrl)
network := &utils.Sepolia
client := feeder.NewTestClient(t, network)
gw := adaptfeeder.New(client)
bc := blockchain.New(testDB, network)

seqAddr := utils.HexToFelt(t, "0xDEADBEEF")
privKey, err := ecdsa.GenerateKey(rand.Reader)
require.NoError(t, err)
p := mempool.New(pebble.NewMemTest(t))

testBuilder := builder.New(privKey, seqAddr, bc, mockVM, time.Second*5, p,
utils.NewNopZapLogger()).WithBootstrapToBlock(2).WithStarknetData(snData).WithBootstrap(true)

block0, err := gw.BlockByNumber(context.Background(), 0)
require.NoError(t, err)
block1, err := gw.BlockByNumber(context.Background(), 1)
require.NoError(t, err)
classHash0 := utils.HexToFelt(t, "0x5c478ee27f2112411f86f207605b2e2c58cdb647bac0df27f660ef2252359c6")
class0, err := gw.Class(context.Background(), classHash0)
require.NoError(t, err)
classHash1 := utils.HexToFelt(t, "0xd0e183745e9dae3e4e78a8ffedcce0903fc4900beace4e0abf192d4c202da3")
class1, err := gw.Class(context.Background(), classHash1)
require.NoError(t, err)

err = bc.StorePending(&blockchain.Pending{
Block: nil,
StateUpdate: nil,
})
require.NoError(t, err)
t.Run("successfully bootstrap Sepolias first two block", func(t *testing.T) {

Check failure on line 57 in builder/bootstrap_test.go

View workflow job for this annotation

GitHub Actions / lint

unnecessary leading newline (whitespace)

Check failure on line 58 in builder/bootstrap_test.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed (gofumpt)
require.NoError(t, err)
snData.EXPECT().BlockByNumber(context.Background(), uint64(0)).Return(block0, nil)
snData.EXPECT().BlockByNumber(context.Background(), uint64(1)).Return(block1, nil)
snData.EXPECT().Class(context.Background(), classHash0).Return(class0, nil)
snData.EXPECT().Class(context.Background(), classHash1).Return(class1, nil)
assert.NoError(t, testBuilder.BootstrapChain(), "can't bootstrap if the network isn't specified", err.Error())
})
}
8 changes: 4 additions & 4 deletions builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (b *Builder) WithBootstrapToBlock(bootstrapToBlock uint64) *Builder {
}

func (b *Builder) Run(ctx context.Context) error {
if err := b.initPendingBlock(); err != nil {
if err := b.InitPendingBlock(); err != nil {
return err
}
defer func() {
Expand All @@ -106,7 +106,7 @@ func (b *Builder) Run(ctx context.Context) error {

if b.bootstrap {
b.log.Debugw("Starting process to bootstrap the Sequencer")
if err := b.bootstrapChain(); err != nil {
if err := b.BootstrapChain(); err != nil {
return err
}
b.log.Debugw("Finished process to bootstrap the Sequencer")
Expand All @@ -126,7 +126,7 @@ func (b *Builder) Run(ctx context.Context) error {
}
}

func (b *Builder) initPendingBlock() error {
func (b *Builder) InitPendingBlock() error {
if b.pendingBlock.Block != nil {
return nil
}
Expand Down Expand Up @@ -173,7 +173,7 @@ func (b *Builder) Finalise() error {
if err := b.clearPending(); err != nil {
return err
}
return b.initPendingBlock()
return b.InitPendingBlock()
}

// ValidateAgainstPendingState validates a user transaction against the pending state
Expand Down
Loading

0 comments on commit 16cb86b

Please sign in to comment.