-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
rian
committed
May 16, 2024
1 parent
713ed9c
commit 16cb86b
Showing
6 changed files
with
37,407 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
|
||
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()) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.