Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linter fixes #114

Merged
merged 4 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
name: Nightly Build
on: # yamllint disable-line rule:truthy
workflow_dispatch: {}
schedule:
# * is a special character in YAML so you have to quote this string
- cron: '0 0 * * *'
Expand Down
5 changes: 5 additions & 0 deletions archive/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ func Test_determineTo(t *testing.T) {

resTo, resToHash, err := determineTo(context.Background(), tt.systemClientMock, tt.targetTo)
assert.Equal(t, tt.err, err)

if tt.err == nil {
assert.Equal(t, tt.resTo, resTo)
assert.Equal(t, tt.resToHash, resToHash)
Expand Down Expand Up @@ -255,6 +256,7 @@ func Test_processExportStream(t *testing.T) {
from, to, err := processExportStream(tt.mockSystemExportClient, hclog.NewNullLogger(), &buffer, 0, 0)

assert.Equal(t, tt.err, err)

if err != nil {
return
}
Expand All @@ -264,12 +266,15 @@ func Test_processExportStream(t *testing.T) {

// create expected data
expectedData := make([]byte, 0)

for _, rv := range tt.mockSystemExportClient.recvs {
if rv.err != nil {
break
}

expectedData = append(expectedData, rv.event.Data...)
}

assert.Equal(t, expectedData, buffer.Bytes())
})
}
Expand Down
9 changes: 3 additions & 6 deletions blockchain/blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,13 +459,10 @@ func TestInsertHeaders(t *testing.T) {
}

checkEvents := func(a []*header, b []*types.Header) {
if len(a) != len(b) {
t.Fatal("bad size")
}
require.Equal(t, len(a), len(b), "unexpected size")

for indx := range a {
if chain.headers[a[indx].hash].Hash != b[indx].Hash {
t.Fatal("bad")
}
require.Equal(t, chain.headers[a[indx].hash].Hash, b[indx].Hash)
}
}

Expand Down
1 change: 1 addition & 0 deletions blockchain/storage/leveldb/leveldb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ func dirSize(t *testing.T, path string) int64 {
if err != nil {
t.Fail()
}

if !info.IsDir() {
size += info.Size()
}
Expand Down
1 change: 1 addition & 0 deletions command/genesis/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ func Test_validatePremineInfo(t *testing.T) {

p := &genesisParams{premine: c.premineRaw, nativeTokenConfig: &polybft.TokenConfig{IsMintable: c.isTokenMintable}}
err := p.parsePremineInfo()

if c.expectedParseErrMsg != "" {
require.ErrorContains(t, err, c.expectedParseErrMsg)

Expand Down
1 change: 1 addition & 0 deletions command/peers/list/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func (r *PeersListResult) GetOutput() string {
for i, p := range r.Peers {
rows[i] = fmt.Sprintf("[%d]|%s", i, p)
}

buffer.WriteString(helper.FormatKV(rows))
}

Expand Down
7 changes: 7 additions & 0 deletions consensus/polybft/checkpoint_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func TestCheckpointManager_SubmitCheckpoint(t *testing.T) {

validators.IterAcct(aliases, func(t *validator.TestValidator) {
bitmap.Set(idx)

signatures = append(signatures, t.MustSign(dummyMsg, signer.DomainCheckpointManager))
idx++
})
Expand Down Expand Up @@ -172,7 +173,9 @@ func TestCheckpointManager_abiEncodeCheckpointBlock(t *testing.T) {

currentValidators.IterAcct(nil, func(v *validator.TestValidator) {
signatures = append(signatures, v.MustSign(proposalHash, signer.DomainCheckpointManager))

bmp.Set(i)

i++
})

Expand Down Expand Up @@ -245,6 +248,7 @@ func TestCheckpointManager_getCurrentCheckpointID(t *testing.T) {
txRelayerMock.On("Call", mock.Anything, mock.Anything, mock.Anything).
Return(c.checkpointID, c.returnError).
Once()

acc, err := wallet.GenerateAccount()
require.NoError(t, err)

Expand All @@ -253,6 +257,7 @@ func TestCheckpointManager_getCurrentCheckpointID(t *testing.T) {
key: acc.Ecdsa,
logger: hclog.NewNullLogger(),
}

actualCheckpointID, err := getCurrentCheckpointBlock(checkpointMgr.rootChainRelayer,
checkpointMgr.checkpointManagerAddr)
if c.errSubstring == "" {
Expand Down Expand Up @@ -417,7 +422,9 @@ func TestCheckpointManager_GenerateExitProof(t *testing.T) {

// copy and make proof invalid
invalidProof := make([]types.Hash, len(proof.Data))

copy(invalidProof, proof.Data)

invalidProof[0][0]++

// verify generated proof on desired tree
Expand Down
1 change: 1 addition & 0 deletions consensus/polybft/consensus_runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1060,6 +1060,7 @@ func createTestBitmaps(t *testing.T, validators validator.AccountSet, numberOfBl

if !bitmap.IsSet(index) {
bitmap.Set(index)

j++
}
}
Expand Down
6 changes: 5 additions & 1 deletion consensus/polybft/extra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ func TestSignature_Verify(t *testing.T) {
validatorSet := vals.ToValidatorSet()

var signatures bls.Signatures

bitmap := bitmap.Bitmap{}
signers := make(map[types.Address]struct{}, len(validatorsMetadata))

Expand Down Expand Up @@ -502,13 +503,15 @@ func TestExtra_InitGenesisValidatorsDelta(t *testing.T) {
Removed: bitmap.Bitmap{},
}

var i int
i := 0

for _, val := range vals.Validators {
delta.Added[i] = &validator.ValidatorMetadata{
Address: types.Address(val.Account.Ecdsa.Address()),
BlsKey: val.Account.Bls.PublicKey(),
VotingPower: new(big.Int).SetUint64(val.VotingPower),
}

i++
}

Expand Down Expand Up @@ -732,6 +735,7 @@ func TestCheckpointData_Validate(t *testing.T) {
c := c
t.Run(c.name, func(t *testing.T) {
t.Parallel()

checkpoint := &CheckpointData{
EpochNumber: c.epochNumber,
CurrentValidatorsHash: c.currentValidatorsHash,
Expand Down
2 changes: 2 additions & 0 deletions consensus/polybft/governance_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,10 @@ func TestGovernanceManager_PostBlock(t *testing.T) {
governanceManager, err := newGovernanceManager(chainParams, genesisPolybftConfig,
hclog.NewNullLogger(), state, blockchainMock, nil)
require.NoError(t, err)

// this cheats that we have this fork in code
governanceManager.allForksHashes[newForkHash] = newForkName

require.NoError(t, state.GovernanceStore.insertGovernanceEvent(1, newForkBlock.Uint64(),
&contractsapi.NewFeatureEvent{
Feature: newForkHash, Block: newForkBlock,
Expand Down
1 change: 1 addition & 0 deletions consensus/polybft/mocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ func (m *systemStateMock) GetEpoch() (uint64, error) {
return epochNumber, nil
} else if len(args) == 2 {
epochNumber, _ := args.Get(0).(uint64)

err, ok := args.Get(1).(error)
if ok {
return epochNumber, err
Expand Down
1 change: 1 addition & 0 deletions consensus/polybft/runtime_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func TestHelpers_isEpochEndingBlock_DeltaNotEmpty(t *testing.T) {
t.Parallel()

validators := validator.NewTestValidators(t, 3).GetPublicIdentities()

bitmap := bitmap.Bitmap{}
bitmap.Set(0)

Expand Down
2 changes: 2 additions & 0 deletions consensus/polybft/sc_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,9 @@ func TestIntegration_PerformExit(t *testing.T) {

currentValidators.IterAcct(nil, func(v *validator.TestValidator) {
signatures = append(signatures, v.MustSign(checkpointHash[:], signer.DomainCheckpointManager))

bmp.Set(i)

i++
})

Expand Down
18 changes: 14 additions & 4 deletions consensus/polybft/stake_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,15 @@ func TestStakeManager_PostBlock(t *testing.T) {

fullValidatorSet, err := state.StakeStore.getFullValidatorSet(nil)
require.NoError(t, err)

var firstValidatorMeta *validator.ValidatorMetadata
firstValidatorMeta = nil

for _, validator := range fullValidatorSet.Validators {
if validator.Address.String() == validators.GetValidator(initialSetAliases[firstValidator]).Address().String() {
firstValidatorMeta = validator
}
}

require.NotNil(t, firstValidatorMeta)
require.Equal(t, bigZero, firstValidatorMeta.VotingPower)
require.False(t, firstValidatorMeta.IsActive)
Expand Down Expand Up @@ -133,13 +135,15 @@ func TestStakeManager_PostBlock(t *testing.T) {

fullValidatorSet, err := state.StakeStore.getFullValidatorSet(nil)
require.NoError(t, err)

var firstValidator *validator.ValidatorMetadata
firstValidator = nil

for _, validator := range fullValidatorSet.Validators {
if validator.Address.String() == validators.GetValidator(initialSetAliases[secondValidator]).Address().String() {
firstValidator = validator
}
}

require.NotNil(t, firstValidator)
require.Equal(t, big.NewInt(251), firstValidator.VotingPower) // 250 + initial 1
require.True(t, firstValidator.IsActive)
Expand All @@ -149,13 +153,11 @@ func TestStakeManager_PostBlock(t *testing.T) {
t.Parallel()

state := newTestState(t)

validators := validator.NewTestValidatorsWithAliases(t, allAliases, []uint64{1, 2, 3, 4, 5, 6})

txRelayerMock := newDummyStakeTxRelayer(t, func() *validator.ValidatorMetadata {
return validators.GetValidator("F").ValidatorMetadata()
})

// just mock the call however, the dummy relayer should do its magic
txRelayerMock.On("Call", mock.Anything, mock.Anything, mock.Anything).
Return(nil, error(nil))
Expand Down Expand Up @@ -251,6 +253,7 @@ func TestStakeManager_UpdateValidatorSet(t *testing.T) {
updateDelta, err := stakeManager.UpdateValidatorSet(epoch, maxValidatorSetSize,
validators.GetPublicIdentities())
require.NoError(t, err)

require.Len(t, updateDelta.Added, 0)
require.Len(t, updateDelta.Updated, 1)
require.Len(t, updateDelta.Removed, 0)
Expand All @@ -267,6 +270,7 @@ func TestStakeManager_UpdateValidatorSet(t *testing.T) {

updateDelta, err := stakeManager.UpdateValidatorSet(epoch+1, maxValidatorSetSize,
validators.GetPublicIdentities())

require.NoError(t, err)
require.Len(t, updateDelta.Added, 0)
require.Len(t, updateDelta.Updated, 0)
Expand All @@ -282,6 +286,7 @@ func TestStakeManager_UpdateValidatorSet(t *testing.T) {

updateDelta, err := stakeManager.UpdateValidatorSet(epoch+2, maxValidatorSetSize,
validators.GetPublicIdentities(aliases[1:]...))

require.NoError(t, err)
require.Len(t, updateDelta.Added, 1)
require.Len(t, updateDelta.Updated, 0)
Expand All @@ -293,12 +298,14 @@ func TestStakeManager_UpdateValidatorSet(t *testing.T) {
fullValidatorSet := validators.GetPublicIdentities().Copy()
validatorToUpdate := fullValidatorSet[2]
validatorToUpdate.VotingPower = big.NewInt(5)

require.NoError(t, state.StakeStore.insertFullValidatorSet(validatorSetState{
Validators: newValidatorStakeMap(fullValidatorSet),
}, nil))

updateDelta, err := stakeManager.UpdateValidatorSet(epoch+3, maxValidatorSetSize,
validators.GetPublicIdentities())

require.NoError(t, err)
require.Len(t, updateDelta.Added, 0)
require.Len(t, updateDelta.Updated, 1)
Expand All @@ -310,12 +317,14 @@ func TestStakeManager_UpdateValidatorSet(t *testing.T) {
fullValidatorSet := validators.GetPublicIdentities().Copy()
validatorToUpdate := fullValidatorSet[3]
validatorToUpdate.VotingPower = bigZero

require.NoError(t, state.StakeStore.insertFullValidatorSet(validatorSetState{
Validators: newValidatorStakeMap(fullValidatorSet),
}, nil))

updateDelta, err := stakeManager.UpdateValidatorSet(epoch+4, maxValidatorSetSize,
validators.GetPublicIdentities())

require.NoError(t, err)
require.Len(t, updateDelta.Added, 0)
require.Len(t, updateDelta.Updated, 0)
Expand All @@ -325,6 +334,7 @@ func TestStakeManager_UpdateValidatorSet(t *testing.T) {
fullValidatorSet := validators.GetPublicIdentities().Copy()
validatorsToUpdate := fullValidatorSet[4]
validatorsToUpdate.VotingPower = bigZero

require.NoError(t, state.StakeStore.insertFullValidatorSet(validatorSetState{
Validators: newValidatorStakeMap(fullValidatorSet),
}, nil))
Expand Down
4 changes: 4 additions & 0 deletions consensus/polybft/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,19 @@ func (s *State) initStorages() error {
if err := s.StateSyncStore.initialize(tx); err != nil {
return err
}

if err := s.ExitStore.initialize(tx); err != nil {
return err
}

if err := s.EpochStore.initialize(tx); err != nil {
return err
}

if err := s.ProposerSnapshotStore.initialize(tx); err != nil {
return err
}

if err := s.StakeStore.initialize(tx); err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions consensus/polybft/state_store_epoch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func TestState_cleanValidatorSnapshotsFromDb(t *testing.T) {
snapshotFromDB, err = state.EpochStore.getValidatorSnapshot(epoch)
assert.NoError(t, err)
assert.NotNil(t, snapshotFromDB)

epoch--
}
}
Expand Down
1 change: 1 addition & 0 deletions consensus/polybft/state_store_exit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ func insertTestExitEvents(t *testing.T, state *State,
}
index++
}

block++
}
}
Expand Down
2 changes: 2 additions & 0 deletions consensus/polybft/state_store_state_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ func (s *StateSyncStore) list() ([]*contractsapi.StateSyncedEvent, error) {
if err := json.Unmarshal(v, &event); err != nil {
return err
}

events = append(events, event)

return nil
Expand Down Expand Up @@ -297,6 +298,7 @@ func (s *StateSyncStore) getMessageVotes(epoch uint64, hash []byte) ([]*MessageS
if err != nil {
return err
}

signatures = res

return nil
Expand Down
1 change: 1 addition & 0 deletions consensus/polybft/state_store_state_sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ func TestState_GetNestedBucketInEpoch(t *testing.T) {

s := newTestState(t)
require.NoError(t, s.EpochStore.insertEpoch(c.epochNumber, nil))

err = s.db.View(func(tx *bbolt.Tx) error {
nestedBucket, err = getNestedBucketInEpoch(tx, c.epochNumber, c.bucketName)

Expand Down
Loading
Loading