Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
rian committed Aug 3, 2024
1 parent 3a5ce53 commit 6571a1c
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 12 deletions.
3 changes: 1 addition & 2 deletions builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,7 @@ func (b *Builder) runTxn(txn *mempool.BroadcastedTransaction) error {
feeUnit = core.STRK

Check warning on line 354 in builder/builder.go

View check run for this annotation

Codecov / codecov/patch

builder/builder.go#L354

Added line #L354 was not covered by tests
}
if trace[0].StateDiff.DeclaredClasses != nil {
switch t := (txn.Transaction).(type) {
case *core.DeclareTransaction:
if t, ok := (txn.Transaction).(*core.DeclareTransaction); ok {
err := state.SetContractClass(t.ClassHash, txn.DeclaredClass)
if err != nil {
b.log.Errorw("failed to set contract class : %s", err)

Check warning on line 360 in builder/builder.go

View check run for this annotation

Codecov / codecov/patch

builder/builder.go#L358-L360

Added lines #L358 - L360 were not covered by tests
Expand Down
2 changes: 1 addition & 1 deletion builder/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ func TestPrefundedAccounts(t *testing.T) {
genesisConfig, err := genesis.Read("../genesis/genesis_prefund_accounts.json")
require.NoError(t, err)
genesisConfig.Classes = []string{"../genesis/classes/strk.json", "../genesis/classes/account.json"}
diff, classes, err := genesis.GenesisStateDiff(genesisConfig, vm.New(false, log), bc.Network())
diff, classes, err := genesis.GenesisStateDiff(genesisConfig, vm.New(false, log), bc.Network(), 40000000) //nolint:gomnd
require.NoError(t, err)
require.NoError(t, bc.StoreGenesis(diff, classes))

Expand Down
3 changes: 1 addition & 2 deletions genesis/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func GenesisStateDiff(
config *GenesisConfig,
v vm.VM,
network *utils.Network,
maxSteps uint64,
) (*core.StateDiff, map[felt.Felt]core.Class, error) {
newClasses, err := loadClasses(config.Classes)
if err != nil {
Expand Down Expand Up @@ -132,7 +133,6 @@ func GenesisStateDiff(
Timestamp: 0,
},
}
maxSteps := uint64(100000) //nolint:gomnd
// Call the constructors
if _, err = v.Call(callInfo, &blockInfo, genesisState, network, maxSteps, false); err != nil {
return nil, nil, fmt.Errorf("execute function call: %v", err)

Check warning on line 138 in genesis/genesis.go

View check run for this annotation

Codecov / codecov/patch

genesis/genesis.go#L138

Added line #L138 was not covered by tests
Expand All @@ -158,7 +158,6 @@ func GenesisStateDiff(
Timestamp: 0,
},
}
maxSteps := uint64(100000) //nolint:gomnd
if _, err = v.Call(callInfo, &blockInfo, genesisState, network, maxSteps, false); err != nil {
return nil, nil, fmt.Errorf("execute function call: %v", err)

Check warning on line 162 in genesis/genesis.go

View check run for this annotation

Codecov / codecov/patch

genesis/genesis.go#L162

Added line #L162 was not covered by tests
}
Expand Down
4 changes: 2 additions & 2 deletions genesis/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ func TestGenesisStateDiff(t *testing.T) {

t.Run("empty genesis config", func(t *testing.T) {
genesisConfig := genesis.GenesisConfig{}
_, _, err := genesis.GenesisStateDiff(&genesisConfig, vm.New(false, log), network)
_, _, err := genesis.GenesisStateDiff(&genesisConfig, vm.New(false, log), network, 40000000) //nolint:gomnd
require.NoError(t, err)
})

t.Run("accounts with prefunded strk", func(t *testing.T) {
genesisConfig, err := genesis.Read("./genesis_prefund_accounts.json")
require.NoError(t, err)
genesisConfig.Classes = []string{"./classes/strk.json", "./classes/account.json"}
stateDiff, newClasses, err := genesis.GenesisStateDiff(genesisConfig, vm.New(false, log), network)
stateDiff, newClasses, err := genesis.GenesisStateDiff(genesisConfig, vm.New(false, log), network, 40000000) //nolint:gomnd
require.NoError(t, err)
require.Empty(t, stateDiff.Nonces)
require.Equal(t, 2, len(stateDiff.DeclaredV1Classes))
Expand Down
4 changes: 2 additions & 2 deletions node/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/NethermindEth/juno/vm"
)

func buildGenesis(genesisPath string, sequencerMode bool, bc *blockchain.Blockchain, v vm.VM) error {
func buildGenesis(genesisPath string, sequencerMode bool, bc *blockchain.Blockchain, v vm.VM, maxSteps uint64) error {
if _, err := bc.Height(); !errors.Is(err, db.ErrKeyNotFound) {
return err

Check warning on line 16 in node/genesis.go

View check run for this annotation

Codecov / codecov/patch

node/genesis.go#L14-L16

Added lines #L14 - L16 were not covered by tests
}
Expand All @@ -25,7 +25,7 @@ func buildGenesis(genesisPath string, sequencerMode bool, bc *blockchain.Blockch
return err

Check warning on line 25 in node/genesis.go

View check run for this annotation

Codecov / codecov/patch

node/genesis.go#L19-L25

Added lines #L19 - L25 were not covered by tests
}

diff, classes, err = genesis.GenesisStateDiff(genesisConfig, v, bc.Network())
diff, classes, err = genesis.GenesisStateDiff(genesisConfig, v, bc.Network(), maxSteps)
if err != nil {
return err

Check warning on line 30 in node/genesis.go

View check run for this annotation

Codecov / codecov/patch

node/genesis.go#L28-L30

Added lines #L28 - L30 were not covered by tests
}
Expand Down
6 changes: 3 additions & 3 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ func New(cfg *Config, version string) (*Node, error) { //nolint:gocyclo,funlen
}
poolDB, _ := pebble.NewMem()
p := mempool.New(poolDB)
sequencer := builder.New(pKey, new(felt.Felt).SetUint64(1337), chain, nodeVM, time.Second*time.Duration(cfg.SeqBlockTime), p, //nolint: gomnd,lll
log)
sequencer := builder.New(pKey, new(felt.Felt).SetUint64(1337), chain, nodeVM, //nolint:mnd
time.Second*time.Duration(cfg.SeqBlockTime), p, log)
rpcHandler = rpc.New(chain, sequencer, throttledVM, version, log).WithMempool(p).WithCallMaxSteps(uint64(cfg.RPCCallMaxSteps))
services = append(services, sequencer)

Check warning on line 177 in node/node.go

View check run for this annotation

Codecov / codecov/patch

node/node.go#L172-L177

Added lines #L172 - L177 were not covered by tests
} else {
Expand Down Expand Up @@ -374,7 +374,7 @@ func (n *Node) Run(ctx context.Context) {
n.log.Errorw("Error while migrating the DB", "err", err)
return
}
if err = buildGenesis(n.cfg.GenesisFile, n.cfg.Sequencer, n.blockchain, vm.New(false, n.log)); err != nil {
if err = buildGenesis(n.cfg.GenesisFile, n.cfg.Sequencer, n.blockchain, vm.New(false, n.log), uint64(n.cfg.RPCCallMaxSteps)); err != nil {
n.log.Errorw("Error building genesis state", "err", err)
return

Check warning on line 379 in node/node.go

View check run for this annotation

Codecov / codecov/patch

node/node.go#L377-L379

Added lines #L377 - L379 were not covered by tests
}
Expand Down

0 comments on commit 6571a1c

Please sign in to comment.