diff --git a/api/api.go b/api/api.go index f021e5765..7eb0823bf 100644 --- a/api/api.go +++ b/api/api.go @@ -103,7 +103,8 @@ func NewAPI(router *httprouter.HTTProuter, baseRoute, dataDir, dbType string) (* // Attach takes a list of modules which are used by the handlers in order to interact with the system. // Attach must be called before EnableHandlers. func (a *API) Attach(vocdoniAPP *vochain.BaseApplication, vocdoniInfo *vochaininfo.VochainInfo, - indexer *indexer.Indexer, data data.Storage, censusdb *censusdb.CensusDB) { + indexer *indexer.Indexer, data data.Storage, censusdb *censusdb.CensusDB, +) { a.vocapp = vocdoniAPP a.vocinfo = vocdoniInfo a.indexer = indexer diff --git a/api/census_helpers.go b/api/census_helpers.go index 58e1e441a..fd91ba0f8 100644 --- a/api/census_helpers.go +++ b/api/census_helpers.go @@ -43,7 +43,6 @@ func censusIDparse(censusID string) ([]byte, error) { censusID = util.TrimHex(censusID) if len(censusID) != censusIDsize*2 { return nil, ErrCensusIDLengthInvalid.Withf("(%d != %d)", len(censusID), censusIDsize*2) - } return hex.DecodeString(censusID) } diff --git a/api/censusdb/censusdb.go b/api/censusdb/censusdb.go index 10b0bf4ae..6bd63f1ea 100644 --- a/api/censusdb/censusdb.go +++ b/api/censusdb/censusdb.go @@ -96,12 +96,15 @@ func NewCensusDB(db db.Database) *CensusDB { // New creates a new census and adds it to the database. func (c *CensusDB) New(censusID []byte, censusType models.Census_Type, - uri string, authToken *uuid.UUID, maxLevels int) (*CensusRef, error) { + uri string, authToken *uuid.UUID, maxLevels int, +) (*CensusRef, error) { if c.Exists(censusID) { return nil, ErrCensusAlreadyExists } - tree, err := censustree.New(censustree.Options{Name: censusName(censusID), - ParentDB: c.db, MaxLevels: maxLevels, CensusType: censusType}) + tree, err := censustree.New(censustree.Options{ + Name: censusName(censusID), + ParentDB: c.db, MaxLevels: maxLevels, CensusType: censusType, + }) if err != nil { return nil, err } @@ -274,7 +277,8 @@ func (c *CensusDB) importTreeCommon(censusID []byte, data []byte) error { // addCensusRefToDB adds a censusRef to the database. func (c *CensusDB) addCensusRefToDB(censusID []byte, authToken *uuid.UUID, - t models.Census_Type, uri string, maxLevels int) (*CensusRef, error) { + t models.Census_Type, uri string, maxLevels int, +) (*CensusRef, error) { wtx := c.db.WriteTx() defer wtx.Discard() refData := bytes.Buffer{} diff --git a/api/chain.go b/api/chain.go index c165d1398..c3fd54955 100644 --- a/api/chain.go +++ b/api/chain.go @@ -275,7 +275,6 @@ func (a *API) organizationCountHandler(_ *apirest.APIdata, ctx *httprouter.HTTPC return err } return ctx.Send(data, apirest.HTTPstatusOK) - } // chainInfoHandler diff --git a/api/faucet/faucet.go b/api/faucet/faucet.go index c26cdf5d4..a68a6d482 100644 --- a/api/faucet/faucet.go +++ b/api/faucet/faucet.go @@ -31,7 +31,8 @@ type FaucetAPI struct { // The networks map defines the amount of tokens to send for each network. Networks not defined are // considered invalid. func AttachFaucetAPI(signingKey *ethereum.SignKeys, amount uint64, - api *apirest.API, pathPrefix string) error { + api *apirest.API, pathPrefix string, +) error { f := &FaucetAPI{ signingKey: signingKey, amount: amount, diff --git a/api/helpers.go b/api/helpers.go index b5ecab447..8303ced8a 100644 --- a/api/helpers.go +++ b/api/helpers.go @@ -118,7 +118,8 @@ func convertKeysToCamelInner(val any) any { // in this case we encode the organizationId the censusRoot and the results that will be translated in the EVM // contract to the corresponding struct{address, bytes32, uint256[][]} func encodeEVMResultsArgs(electionId common.Hash, organizationId common.Address, censusRoot common.Hash, - sourceContractAddress common.Address, results [][]*types.BigInt) (string, error) { + sourceContractAddress common.Address, results [][]*types.BigInt, +) (string, error) { address, _ := abi.NewType("address", "", nil) bytes32, _ := abi.NewType("bytes32", "", nil) uint256SliceNested, _ := abi.NewType("uint256[][]", "", nil) diff --git a/api/wallet.go b/api/wallet.go index 303e48a0f..9d952e812 100644 --- a/api/wallet.go +++ b/api/wallet.go @@ -223,7 +223,8 @@ func (a *API) walletCreateHandler(msg *apirest.APIdata, ctx *httprouter.HTTPCont Account: wallet.Address().Bytes(), FaucetPackage: nil, }, - }}) + }, + }) if err != nil { return err } @@ -285,7 +286,8 @@ func (a *API) walletTransferHandler(msg *apirest.APIdata, ctx *httprouter.HTTPCo To: dst.Bytes(), Value: amount, }, - }}) + }, + }) if err != nil { return err } diff --git a/apiclient/account.go b/apiclient/account.go index b600b2f54..756ae7881 100644 --- a/apiclient/account.go +++ b/apiclient/account.go @@ -25,10 +25,8 @@ var DefaultFaucetURLs = map[string]string{ "prod": "https://api-faucet.vocdoni.io/v2/open/claim/", } -var ( - // ErrAccountNotConfigured is returned when the client has not been configured with an account. - ErrAccountNotConfigured = fmt.Errorf("account not configured") -) +// ErrAccountNotConfigured is returned when the client has not been configured with an account. +var ErrAccountNotConfigured = fmt.Errorf("account not configured") // Account returns the information about a Vocdoni account. If address is empty, it returns the information // about the account associated with the client. @@ -103,7 +101,8 @@ func (c *HTTPclient) TransferWithNonce(to common.Address, amount uint64, nonce u To: to.Bytes(), Value: amount, }, - }}) + }, + }) if err != nil { return nil, err } @@ -143,7 +142,8 @@ func (c *HTTPclient) AccountBootstrap(faucetPkg *models.FaucetPackage, metadata InfoURI: &metadataURI, SIK: sik, }, - }}) + }, + }) if err != nil { return nil, err } @@ -367,7 +367,8 @@ func (c *HTTPclient) DelSIK() (types.HexBytes, error) { DelSIK: &models.SIKTx{ Txtype: models.TxType_DEL_ACCOUNT_SIK, }, - }}) + }, + }) if err != nil { return nil, err } diff --git a/apiclient/blockchain.go b/apiclient/blockchain.go index 66efab0df..78007c0d7 100644 --- a/apiclient/blockchain.go +++ b/apiclient/blockchain.go @@ -13,10 +13,8 @@ import ( "google.golang.org/protobuf/proto" ) -var ( - // ErrTransactionDoesNotExist is returned when the transaction does not exist - ErrTransactionDoesNotExist = fmt.Errorf("transaction does not exist") -) +// ErrTransactionDoesNotExist is returned when the transaction does not exist +var ErrTransactionDoesNotExist = fmt.Errorf("transaction does not exist") // ChainInfo returns some information about the chain, such as block height. func (c *HTTPclient) ChainInfo() (*api.ChainInfo, error) { @@ -106,7 +104,8 @@ func (c *HTTPclient) TransactionByHash(txHash types.HexBytes) (*models.Tx, error // OrganizationsBySearchTermPaginated returns a paginated list of organizations // that match the given search term. func (c *HTTPclient) OrganizationsBySearchTermPaginated( - organizationID types.HexBytes, page int) ([]types.HexBytes, error) { + organizationID types.HexBytes, page int, +) ([]types.HexBytes, error) { // make a post request to /chain/organizations/filter/page/ with the organizationID // as the body and page as the url parameter resp, code, err := c.Request(HTTPPOST, diff --git a/apiclient/election.go b/apiclient/election.go index e3a8a8b32..c2c8e1ec1 100644 --- a/apiclient/election.go +++ b/apiclient/election.go @@ -295,7 +295,8 @@ func (c *HTTPclient) SetElectionStatus(electionID types.HexBytes, status string) txb, err := proto.Marshal(&models.Tx{ Payload: &models.Tx_SetProcess{ SetProcess: &tx, - }}) + }, + }) if err != nil { return nil, err } @@ -366,7 +367,8 @@ func (c *HTTPclient) ElectionResults(electionID types.HexBytes) (*api.ElectionRe // POST /elections/filter/page/ // Returns a list of elections filtered by the given parameters. func (c *HTTPclient) ElectionFilterPaginated(organizationID types.HexBytes, electionID types.HexBytes, - status models.ProcessStatus, withResults bool, page int) (*[]api.ElectionSummary, error) { + status models.ProcessStatus, withResults bool, page int, +) (*[]api.ElectionSummary, error) { body := struct { OrganizationID types.HexBytes `json:"organizationId,omitempty"` ElectionID types.HexBytes `json:"electionId,omitempty"` diff --git a/benchmark/zk_census_benchmark_test.go b/benchmark/zk_census_benchmark_test.go index de5abd89c..b47dc2d63 100644 --- a/benchmark/zk_census_benchmark_test.go +++ b/benchmark/zk_census_benchmark_test.go @@ -121,7 +121,6 @@ func zkCensusBenchmark(b *testing.B, cc, sc *testutil.TestHTTPclient, vapp *voch qt.Assert(b, json.Unmarshal(resp, sikData), qt.IsNil) genProofZk(b, electionID, admin, censusData, sikData) - } func genProofZk(b *testing.B, electionID []byte, acc *ethereum.SignKeys, censusData, sikData *api.Census) { diff --git a/censustree/censustree.go b/censustree/censustree.go index 50ce22d21..515648b73 100644 --- a/censustree/censustree.go +++ b/censustree/censustree.go @@ -74,7 +74,7 @@ func DeleteCensusTreeFromDatabase(kv db.Database, name string) (int, error) { // New returns a new Tree, if there already is a Tree in the // database, it will load it. func New(opts Options) (*Tree, error) { - var maxLevels = opts.MaxLevels + maxLevels := opts.MaxLevels if maxLevels > DefaultMaxLevels { maxLevels = DefaultMaxLevels } diff --git a/censustree/censustree_test.go b/censustree/censustree_test.go index f25f6a239..7064e5965 100644 --- a/censustree/censustree_test.go +++ b/censustree/censustree_test.go @@ -18,8 +18,10 @@ import ( func TestImportWeighted(t *testing.T) { db := metadb.NewTest(t) - censusTree, err := New(Options{Name: "test", ParentDB: db, MaxLevels: DefaultMaxLevels, - CensusType: models.Census_ARBO_BLAKE2B}) + censusTree, err := New(Options{ + Name: "test", ParentDB: db, MaxLevels: DefaultMaxLevels, + CensusType: models.Census_ARBO_BLAKE2B, + }) qt.Assert(t, err, qt.IsNil) rnd := testutil.NewRandom(0) @@ -46,8 +48,10 @@ func TestImportWeighted(t *testing.T) { qt.Assert(t, err, qt.IsNil) // import into a new tree - censusTree2, err := New(Options{Name: "test2", ParentDB: db, MaxLevels: DefaultMaxLevels, - CensusType: models.Census_ARBO_BLAKE2B}) + censusTree2, err := New(Options{ + Name: "test2", ParentDB: db, MaxLevels: DefaultMaxLevels, + CensusType: models.Census_ARBO_BLAKE2B, + }) qt.Assert(t, err, qt.IsNil) err = censusTree2.ImportDump(dump) @@ -74,8 +78,10 @@ func TestImportWeighted(t *testing.T) { func TestWeightedProof(t *testing.T) { db := metadb.NewTest(t) - censusTree, err := New(Options{Name: "test", ParentDB: db, MaxLevels: DefaultMaxLevels, - CensusType: models.Census_ARBO_POSEIDON}) + censusTree, err := New(Options{ + Name: "test", ParentDB: db, MaxLevels: DefaultMaxLevels, + CensusType: models.Census_ARBO_POSEIDON, + }) qt.Assert(t, err, qt.IsNil) rnd := testutil.NewRandom(0) @@ -111,8 +117,10 @@ func TestWeightedProof(t *testing.T) { func TestGetCensusWeight(t *testing.T) { db := metadb.NewTest(t) - tree, err := New(Options{Name: "test", ParentDB: db, MaxLevels: DefaultMaxLevels, - CensusType: models.Census_ARBO_BLAKE2B}) + tree, err := New(Options{ + Name: "test", ParentDB: db, MaxLevels: DefaultMaxLevels, + CensusType: models.Census_ARBO_BLAKE2B, + }) qt.Assert(t, err, qt.IsNil) w, err := tree.GetCensusWeight() @@ -196,8 +204,10 @@ func TestGetCensusWeight(t *testing.T) { // dump the leaves & import them into a new empty tree, and check that // the censusWeight is correctly recomputed db2 := metadb.NewTest(t) - tree2, err := New(Options{Name: "test2", ParentDB: db2, MaxLevels: DefaultMaxLevels, - CensusType: models.Census_ARBO_BLAKE2B}) + tree2, err := New(Options{ + Name: "test2", ParentDB: db2, MaxLevels: DefaultMaxLevels, + CensusType: models.Census_ARBO_BLAKE2B, + }) qt.Assert(t, err, qt.IsNil) dump, err := tree.Dump() diff --git a/cmd/cli/main.go b/cmd/cli/main.go index 9ab5a88fb..c3c8277ba 100644 --- a/cmd/cli/main.go +++ b/cmd/cli/main.go @@ -167,7 +167,6 @@ func main() { errorp.Println("unknown option or not yet implemented") } } - } func accountIsSet(c *VocdoniCLI) bool { @@ -626,16 +625,21 @@ func electionHandler(cli *VocdoniCLI) error { VoteType: api.VoteType{MaxVoteOverwrites: 1}, ElectionType: api.ElectionType{Autostart: true, Interruptible: true}, Questions: []api.Question{ - {Title: map[string]string{"default": "question title"}, + { + Title: map[string]string{"default": "question title"}, Description: map[string]string{"default": "question description"}, Choices: []api.ChoiceMetadata{ { Title: map[string]string{"default": "1 choice title"}, - Value: 0}, + Value: 0, + }, { Title: map[string]string{"default": "2 choice title"}, - Value: 1}, - }}}, + Value: 1, + }, + }, + }, + }, Census: api.CensusTypeDescription{ Type: "weighted", RootHash: make(types.HexBytes, 32), diff --git a/cmd/end2endtest/account.go b/cmd/end2endtest/account.go index c2489b265..c140b5bc6 100644 --- a/cmd/end2endtest/account.go +++ b/cmd/end2endtest/account.go @@ -330,7 +330,8 @@ func checkTokenTransfersCount(api *apiclient.HTTPclient, address common.Address) } func ensureAccountExists(api *apiclient.HTTPclient, - faucetPkg *models.FaucetPackage) (*apipkg.Account, error) { + faucetPkg *models.FaucetPackage, +) (*apipkg.Account, error) { for i := 0; i < retries; i++ { acct, err := api.Account("") if err != nil { diff --git a/cmd/end2endtest/ballot.go b/cmd/end2endtest/ballot.go index eeaf86b97..d7f6069cf 100644 --- a/cmd/end2endtest/ballot.go +++ b/cmd/end2endtest/ballot.go @@ -51,21 +51,25 @@ func init() { } } -var _ VochainTest = (*E2EBallotRanked)(nil) -var _ VochainTest = (*E2EBallotQuadratic)(nil) -var _ VochainTest = (*E2EBallotRange)(nil) -var _ VochainTest = (*E2EBallotApproval)(nil) +var ( + _ VochainTest = (*E2EBallotRanked)(nil) + _ VochainTest = (*E2EBallotQuadratic)(nil) + _ VochainTest = (*E2EBallotRange)(nil) + _ VochainTest = (*E2EBallotApproval)(nil) +) -type E2EBallotRanked struct{ e2eElection } -type E2EBallotQuadratic struct{ e2eElection } -type E2EBallotRange struct{ e2eElection } -type E2EBallotApproval struct{ e2eElection } +type ( + E2EBallotRanked struct{ e2eElection } + E2EBallotQuadratic struct{ e2eElection } + E2EBallotRange struct{ e2eElection } + E2EBallotApproval struct{ e2eElection } +) func (t *E2EBallotRanked) Setup(api *apiclient.HTTPclient, c *config) error { t.api = api t.config = c - //setup for ranked voting + // setup for ranked voting p := newTestProcess() p.VoteOptions = &models.ProcessVoteOptions{ MaxCount: 4, @@ -275,9 +279,16 @@ func ballotVotes(vop vapi.TallyMode, nvotes int, ballotType string, expectUnique // fill initial 10 votes to be sent by the ballot test case rankedVote: v = [][]int{ - {0, 5, 0, 2}, {3, 1, 0, 2}, {3, 2, 0, 1}, {1, 0, 3, 2}, - {2, 3, 1, 1}, {4, 1, 1, 0}, {0, 0, 2, 1}, {0, 2, 1, 3}, - {1, 1, 1, 4}, {0, 3, 2, 1}, + {0, 5, 0, 2}, + {3, 1, 0, 2}, + {3, 2, 0, 1}, + {1, 0, 3, 2}, + {2, 3, 1, 1}, + {4, 1, 1, 0}, + {0, 0, 2, 1}, + {0, 2, 1, 3}, + {1, 1, 1, 4}, + {0, 3, 2, 1}, } // default results on field 1,2,3,4 for 10 votes resultsFields = append(resultsFields, votesToBigInt(20, 10, 0, 20), @@ -286,9 +297,16 @@ func ballotVotes(vop vapi.TallyMode, nvotes int, ballotType string, expectUnique case quadraticVote: v = [][]int{ - {2, 4, 2, 0}, {3, 3, 2, 2}, {2, 3, 0, 1}, {0, 2, 3, 3}, - {1, 2, 1, 2}, {5, 0, 1, 0}, {0, 2, 2, 2}, {2, 1, 1, 2}, - {1, 3, 0, 1}, {1, 3, 1, 1}, + {2, 4, 2, 0}, + {3, 3, 2, 2}, + {2, 3, 0, 1}, + {0, 2, 3, 3}, + {1, 2, 1, 2}, + {5, 0, 1, 0}, + {0, 2, 2, 2}, + {2, 1, 1, 2}, + {1, 3, 0, 1}, + {1, 3, 1, 1}, } resultsFields = append(resultsFields, votesToBigInt(10, 30, 10, 0), votesToBigInt(0, 10, 20, 20), votesToBigInt(10, 30, 10, 0), @@ -296,9 +314,16 @@ func ballotVotes(vop vapi.TallyMode, nvotes int, ballotType string, expectUnique case rangeVote: v = [][]int{ - {5, 0, 4, 2}, {3, 1, 2, 4}, {6, 0, 1, 3}, {0, 3, 2, 1}, - {2, 1, 3, 0}, {3, 2, 1, 3}, {1, 3, 2, 0}, {2, 1, 1, 2}, - {1, 2, 0, 3}, {4, 3, 1, 1}, + {5, 0, 4, 2}, + {3, 1, 2, 4}, + {6, 0, 1, 3}, + {0, 3, 2, 1}, + {2, 1, 3, 0}, + {3, 2, 1, 3}, + {1, 3, 2, 0}, + {2, 1, 1, 2}, + {1, 2, 0, 3}, + {4, 3, 1, 1}, } resultsFields = append(resultsFields, votesToBigInt(10, 20, 10, 0), votesToBigInt(0, 10, 10, 20), votesToBigInt(10, 0, 20, 10), @@ -306,9 +331,16 @@ func ballotVotes(vop vapi.TallyMode, nvotes int, ballotType string, expectUnique case approvalVote: v = [][]int{ - {1, 0, 0, 0}, {2, 1, 0, 1}, {0, 1, 2, 3}, {0, 0, 0, 1}, - {0, 0, 1, 1}, {2, 2, 1, 0}, {1, 0, 1, 1}, {0, 0, 0, 0}, - {1, 1, 0, 3}, {1, 1, 1, 1}, + {1, 0, 0, 0}, + {2, 1, 0, 1}, + {0, 1, 2, 3}, + {0, 0, 0, 1}, + {0, 0, 1, 1}, + {2, 2, 1, 0}, + {1, 0, 1, 1}, + {0, 0, 0, 0}, + {1, 1, 0, 3}, + {1, 1, 1, 1}, } resultsFields = append(resultsFields, votesToBigInt(30, 30), votesToBigInt(50, 10), votesToBigInt(30, 30), diff --git a/cmd/end2endtest/csp.go b/cmd/end2endtest/csp.go index e62a86b3a..05632ec7e 100644 --- a/cmd/end2endtest/csp.go +++ b/cmd/end2endtest/csp.go @@ -30,7 +30,7 @@ func (t *E2ECSPElection) Setup(api *apiclient.HTTPclient, c *config) error { t.api = api t.config = c - //setup for ranked voting + // setup for ranked voting p := newTestProcess() // update to use csp origin p.CensusOrigin = models.CensusOrigin_OFF_CHAIN_CA diff --git a/cmd/end2endtest/dynamicensus.go b/cmd/end2endtest/dynamicensus.go index a06a6dedf..47cdf3ff8 100644 --- a/cmd/end2endtest/dynamicensus.go +++ b/cmd/end2endtest/dynamicensus.go @@ -155,7 +155,6 @@ func (t *E2EDynamicensusElection) Run() error { CensusRoot: censusRoot2, CensusURL: "http://test/census", }) - if err != nil { errCh <- fmt.Errorf("unexpected error from set process census %s", err) return @@ -212,7 +211,6 @@ func (t *E2EDynamicensusElection) Run() error { log.Infof("election %s status is RESULTS", electionID.String()) log.Infof("election results: %v %x %s", elres.Results, elres.CensusRoot, t.elections[0].election.Census.CensusURL) - }() // election with dynamic census disabled diff --git a/cmd/end2endtest/helpers.go b/cmd/end2endtest/helpers.go index 896a1152b..1c72820dc 100644 --- a/cmd/end2endtest/helpers.go +++ b/cmd/end2endtest/helpers.go @@ -132,7 +132,6 @@ func (t *e2eElection) createAccount(privateKey string) (*vapi.Account, *apiclien return nil, nil, err } return acc, accountApi, nil - } func (t *e2eElection) addParticipantsCensus(censusID types.HexBytes, voterAccounts []*ethereum.SignKeys) error { @@ -395,7 +394,6 @@ func (t *e2eElection) setupElection(ed *vapi.ElectionDescription, nvAccts int, w errorChan <- fmt.Errorf("unexpected invalid SIK for account %x", acc.Address()) } log.Infof("valid SIK for the account %x", acc.Address()) - }(i, acc) } @@ -818,5 +816,4 @@ func logElection(e *vapi.Election) { "tallyMaxTotalCost", e.TallyMode.MaxTotalCost, "tallyCostExponent", e.TallyMode.CostExponent, ) - } diff --git a/cmd/end2endtest/zkweighted.go b/cmd/end2endtest/zkweighted.go index ffc0f5d74..dda708ff5 100644 --- a/cmd/end2endtest/zkweighted.go +++ b/cmd/end2endtest/zkweighted.go @@ -38,13 +38,17 @@ func init() { } } -var _ VochainTest = (*E2EAnonElection)(nil) -var _ VochainTest = (*E2EAnonElectionTempSIKs)(nil) -var _ VochainTest = (*E2EAnonElectionEncrypted)(nil) +var ( + _ VochainTest = (*E2EAnonElection)(nil) + _ VochainTest = (*E2EAnonElectionTempSIKs)(nil) + _ VochainTest = (*E2EAnonElectionEncrypted)(nil) +) -type E2EAnonElection struct{ e2eElection } -type E2EAnonElectionTempSIKs struct{ e2eElection } -type E2EAnonElectionEncrypted struct{ e2eElection } +type ( + E2EAnonElection struct{ e2eElection } + E2EAnonElectionTempSIKs struct{ e2eElection } + E2EAnonElectionEncrypted struct{ e2eElection } +) func (t *E2EAnonElection) Setup(api *apiclient.HTTPclient, c *config) error { t.api = api diff --git a/cmd/tools/censusdump/main.go b/cmd/tools/censusdump/main.go index f172b014b..a7f9b09c0 100644 --- a/cmd/tools/censusdump/main.go +++ b/cmd/tools/censusdump/main.go @@ -140,7 +140,7 @@ func main() { log.Fatalf("could not marshal census data: %s", err) } - if err := os.WriteFile(*output, censusPrint, 0644); err != nil { + if err := os.WriteFile(*output, censusPrint, 0o644); err != nil { log.Fatalf("could not write census data: %s", err) } log.Infow("census data exported", "file", *output) diff --git a/crypto/ethereum/vocdoni_test.go b/crypto/ethereum/vocdoni_test.go index f3925c795..c436d49f5 100644 --- a/crypto/ethereum/vocdoni_test.go +++ b/crypto/ethereum/vocdoni_test.go @@ -33,7 +33,8 @@ func TestVocdoniSignature(t *testing.T) { To: toAddr, Value: value, Nonce: 123, - }}} + }, + }} message, err := proto.Marshal(tx) qt.Assert(t, err, qt.IsNil) @@ -59,7 +60,8 @@ func TestVocdoniSignature(t *testing.T) { InfoURI: &infoUri, Account: s.Address().Bytes(), Nonce: &nonce, - }}} + }, + }} message, err = proto.Marshal(tx) qt.Assert(t, err, qt.IsNil) diff --git a/crypto/zk/circuit/inputs_test.go b/crypto/zk/circuit/inputs_test.go index 674d51621..a063f0ba1 100644 --- a/crypto/zk/circuit/inputs_test.go +++ b/crypto/zk/circuit/inputs_test.go @@ -59,20 +59,26 @@ func TestGenerateCircuitInput(t *testing.T) { SIKSiblings: testSiblings, } // Generate correct inputs - rawInputs, err := GenerateCircuitInput(CircuitInputsParameters{acc, nil, + rawInputs, err := GenerateCircuitInput(CircuitInputsParameters{ + acc, nil, electionId, hexTestRoot, hexTestRoot, testVotePackage, testSiblings, testSiblings, nil, - availableWeight}) + availableWeight, + }) c.Assert(err, qt.IsNil) c.Assert(rawInputs, qt.DeepEquals, expected) - rawInputs, err = GenerateCircuitInput(CircuitInputsParameters{acc, nil, + rawInputs, err = GenerateCircuitInput(CircuitInputsParameters{ + acc, nil, electionId, hexTestRoot, hexTestRoot, testVotePackage, testSiblings, testSiblings, - big.NewInt(1), availableWeight}) + big.NewInt(1), availableWeight, + }) c.Assert(err, qt.IsNil) c.Assert(rawInputs, qt.Not(qt.DeepEquals), expected) - _, err = GenerateCircuitInput(CircuitInputsParameters{nil, nil, electionId, + _, err = GenerateCircuitInput(CircuitInputsParameters{ + nil, nil, electionId, hexTestRoot, hexTestRoot, testVotePackage, testSiblings, testSiblings, big.NewInt(1), - availableWeight}) + availableWeight, + }) c.Assert(err, qt.IsNotNil) } diff --git a/crypto/zk/prover/prover_test.go b/crypto/zk/prover/prover_test.go index c64b93094..1b6448d83 100644 --- a/crypto/zk/prover/prover_test.go +++ b/crypto/zk/prover/prover_test.go @@ -62,12 +62,11 @@ func TestBytes(t *testing.T) { expectedPubSignals, err := json.Marshal(expected.PubSignals) qt.Assert(t, err, qt.IsNil) qt.Assert(t, validPubSignals, qt.DeepEquals, expectedPubSignals) - } func Test_calcWitness(t *testing.T) { // Empty and first set of valid parameters - var emptyWasm, emptyInputs = []byte{}, []byte{} + emptyWasm, emptyInputs := []byte{}, []byte{} _, err := calcWitness(emptyWasm, inputs) qt.Assert(t, err, qt.IsNotNil) diff --git a/crypto/zk/utils.go b/crypto/zk/utils.go index 942bfc540..ad52869ce 100644 --- a/crypto/zk/utils.go +++ b/crypto/zk/utils.go @@ -57,7 +57,8 @@ func ProtobufZKProofToProverProof(p *models.ProofZkSNARK) (*prover.Proof, error) // a defined public signals and any of the rest of the parameters is nil, the // resulting struct will not contains any defined PublicInputs value. func ProverProofToProtobufZKProof(p *prover.Proof, electionId, sikRoot, - censusRoot, nullifier types.HexBytes, voteWeight *big.Int) (*models.ProofZkSNARK, error) { + censusRoot, nullifier types.HexBytes, voteWeight *big.Int, +) (*models.ProofZkSNARK, error) { if len(p.Data.A) != proofALen || len(p.Data.B) != proofBEncLen || len(p.Data.C) != proofCLen { return nil, fmt.Errorf("wrong ZkSnark prover proof format") } diff --git a/data/downloader/downloader.go b/data/downloader/downloader.go index 5a1754e8e..3b3eb8e2f 100644 --- a/data/downloader/downloader.go +++ b/data/downloader/downloader.go @@ -146,7 +146,6 @@ func (d *Downloader) handleImport(item *DownloadItem) { if item.Callback != nil { go item.Callback(item.URI, file) } - } // importQueueDaemon fetches and imports remote files added via importQueue. diff --git a/data/ipfs/init.go b/data/ipfs/init.go index 4ea85b9a5..00679093c 100644 --- a/data/ipfs/init.go +++ b/data/ipfs/init.go @@ -61,7 +61,7 @@ func initRepository() error { return fmt.Errorf("ipfs daemon is running. please stop it to run this command") } - if err := os.MkdirAll(ConfigRoot, 0750); err != nil { + if err := os.MkdirAll(ConfigRoot, 0o750); err != nil { return err } @@ -250,7 +250,7 @@ func checkWritable(dir string) error { if os.IsNotExist(err) { // dir doesn't exist, check that we can create it - return os.Mkdir(dir, 0750) + return os.Mkdir(dir, 0o750) } if os.IsPermission(err) { diff --git a/db/internal/dbtest/dbtest.go b/db/internal/dbtest/dbtest.go index 8b7d22e9d..dea3388b3 100644 --- a/db/internal/dbtest/dbtest.go +++ b/db/internal/dbtest/dbtest.go @@ -89,7 +89,7 @@ func TestIterate(t *testing.T, d db.Database) { // TestConcurrentWriteTx validates the behaviour of badgerdb when multiple // write transactions modify the same key. func TestConcurrentWriteTx(t *testing.T, database db.Database) { - var key = []byte{1} + key := []byte{1} wTx := database.WriteTx() qt.Assert(t, wTx.Set(key, []byte{0}), qt.IsNil) qt.Assert(t, wTx.Commit(), qt.IsNil) @@ -97,7 +97,7 @@ func TestConcurrentWriteTx(t *testing.T, database db.Database) { var wgSync sync.WaitGroup wgSync.Add(2) inc := func(t *testing.T, m *sync.Mutex, database db.Database) error { - var key = []byte{1} + key := []byte{1} wTx := database.WriteTx() // Sync here so that both goroutines have created a WriteTx // before operating with it. diff --git a/httprouter/apirest/apirest_test.go b/httprouter/apirest/apirest_test.go index 6f7a1743f..31eae157f 100644 --- a/httprouter/apirest/apirest_test.go +++ b/httprouter/apirest/apirest_test.go @@ -88,7 +88,6 @@ func TestRouterWithAPI(t *testing.T) { qt.Check(t, resp, qt.DeepEquals, []byte("hello admin!\n")) resp = doRequest(t, url+"/admin/do", "abcde", "POST", []byte("hello")) qt.Check(t, string(resp), qt.Contains, "admin token not valid\n") - } func doRequest(t *testing.T, url, authToken, method string, body []byte) []byte { diff --git a/httprouter/httprouter.go b/httprouter/httprouter.go index aa0fd2c48..96e2228d6 100644 --- a/httprouter/httprouter.go +++ b/httprouter/httprouter.go @@ -218,7 +218,8 @@ func (r *HTTProuter) getNamespace(id string) (RouterNamespace, bool) { // AddAdminHandler adds a handler function for the namespace, pattern and HTTPmethod. // The Admin requests are usually protected by some authorization mechanism. func (r *HTTProuter) AddAdminHandler(namespaceID, - pattern, HTTPmethod string, handler RouterHandlerFn) { + pattern, HTTPmethod string, handler RouterHandlerFn, +) { log.Infof("added admin handler for namespace %s with pattern %s", namespaceID, pattern) r.Mux.MethodFunc(HTTPmethod, pattern, r.routerHandler(namespaceID, AccessTypeAdmin, handler)) } @@ -226,7 +227,8 @@ func (r *HTTProuter) AddAdminHandler(namespaceID, // AddQuotaHandler adds a handler function for the namespace, pattern and HTTPmethod. // The Quota requests are rate-limited per bearer token func (r *HTTProuter) AddQuotaHandler(namespaceID, - pattern, HTTPmethod string, handler RouterHandlerFn) { + pattern, HTTPmethod string, handler RouterHandlerFn, +) { log.Infow("added handler", "type", "quota", "namespace", namespaceID, "pattern", pattern) r.Mux.MethodFunc(HTTPmethod, pattern, r.routerHandler(namespaceID, AccessTypeQuota, handler)) } @@ -235,7 +237,8 @@ func (r *HTTProuter) AddQuotaHandler(namespaceID, // The Private requests are usually protected by some authorization mechanism, such as signature verification, // which must be handled by the namespace implementation. func (r *HTTProuter) AddPrivateHandler(namespaceID, - pattern, HTTPmethod string, handler RouterHandlerFn) { + pattern, HTTPmethod string, handler RouterHandlerFn, +) { log.Infow("added handler", "type", "private", "namespace", namespaceID, "pattern", pattern) r.Mux.MethodFunc(HTTPmethod, pattern, r.routerHandler(namespaceID, AccessTypePrivate, handler)) } @@ -243,7 +246,8 @@ func (r *HTTProuter) AddPrivateHandler(namespaceID, // AddPublicHandler adds a handled function for the namespace, patter and HTTPmethod. // The public requests are not protected so all requests are allowed. func (r *HTTProuter) AddPublicHandler(namespaceID, - pattern, HTTPmethod string, handler RouterHandlerFn) { + pattern, HTTPmethod string, handler RouterHandlerFn, +) { log.Infow("added handler", "type", "public", "namespace", namespaceID, "pattern", pattern) r.Mux.MethodFunc(HTTPmethod, pattern, r.routerHandler(namespaceID, AccessTypePublic, handler)) } @@ -256,7 +260,8 @@ func (r *HTTProuter) AddRawHTTPHandler(pattern, HTTPmethod string, handler http. } func (r *HTTProuter) routerHandler(namespaceID string, accessType AuthAccessType, - handlerFunc RouterHandlerFn) func(w http.ResponseWriter, req *http.Request) { + handlerFunc RouterHandlerFn, +) func(w http.ResponseWriter, req *http.Request) { return func(w http.ResponseWriter, req *http.Request) { defer req.Body.Close() diff --git a/log/log.go b/log/log.go index 48d6e8f8c..746fd8aae 100644 --- a/log/log.go +++ b/log/log.go @@ -98,7 +98,7 @@ func Init(level, output string, errorOutput io.Writer) { case logTestWriterName: out = logTestWriter default: - f, err := os.OpenFile(output, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0600) + f, err := os.OpenFile(output, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0o600) if err != nil { panic(fmt.Sprintf("cannot create log output: %v", err)) } diff --git a/statedb/statedb_test.go b/statedb/statedb_test.go index 669593810..1a3f9f541 100644 --- a/statedb/statedb_test.go +++ b/statedb/statedb_test.go @@ -139,7 +139,6 @@ func TestStateDB(t *testing.T) { root2, err = sdb.Hash() qt.Assert(t, err, qt.IsNil) qt.Assert(t, root2, qt.DeepEquals, root1) - } // singleCfg is a test configuration for a singleton subTree diff --git a/statedb/treeupdate.go b/statedb/treeupdate.go index 4d86df6d6..cd1e90a37 100644 --- a/statedb/treeupdate.go +++ b/statedb/treeupdate.go @@ -50,7 +50,7 @@ type TreeUpdate struct { // is used in the TreeTx.Commit to traverse all opened subTrees in a // TreeTx in order to propagate the roots upwards to update the // corresponding parent leafs up to the mainTree. - //openSubs map[string]*TreeUpdate + // openSubs map[string]*TreeUpdate openSubs sync.Map // cfg points to this TreeUpdate configuration. cfg TreeConfig diff --git a/subpub/subpub.go b/subpub/subpub.go index cbf7c8bda..cad6ccb6a 100644 --- a/subpub/subpub.go +++ b/subpub/subpub.go @@ -141,7 +141,8 @@ func (s *SubPub) Stats() map[string]any { return map[string]any{ "peers": len(s.node.PeerHost.Network().Peers()), "known": len(s.node.PeerHost.Peerstore().PeersWithAddrs()), - "cluster": len(s.gossip.topic.ListPeers())} + "cluster": len(s.gossip.topic.ListPeers()), + } } // Address returns the node's ID. diff --git a/test/api_test.go b/test/api_test.go index 3b2985f78..dba1401dc 100644 --- a/test/api_test.go +++ b/test/api_test.go @@ -209,7 +209,6 @@ func TestAPIaccount(t *testing.T) { // compare the balance expected for the new account in the account list qt.Assert(t, gotAcct.Balance, qt.Equals, initBalance) - } func TestAPIElectionCost(t *testing.T) { @@ -387,7 +386,6 @@ func TestAPIAccountTokentxs(t *testing.T) { // compare the balance expected for the account 1 in the account list qt.Assert(t, gotAcct1.Balance, qt.Equals, initBalance+amountAcc2toAcct1-amountAcc1toAcct2) - } func runAPIElectionCostWithParams(t *testing.T, @@ -573,7 +571,8 @@ func predictPriceForElection(t testing.TB, c *testutil.TestHTTPclient, electionP } func createAccount(t testing.TB, c *testutil.TestHTTPclient, - server testcommon.APIserver, initialBalance uint64) *ethereum.SignKeys { + server testcommon.APIserver, initialBalance uint64, +) *ethereum.SignKeys { signer := ethereum.SignKeys{} qt.Assert(t, signer.Generate(), qt.IsNil) @@ -620,7 +619,8 @@ func createAccount(t testing.TB, c *testutil.TestHTTPclient, } func sendTokensTx(t testing.TB, c *testutil.TestHTTPclient, - signerFrom, signerTo *ethereum.SignKeys, chainID string, nonce uint32, amount uint64) { + signerFrom, signerTo *ethereum.SignKeys, chainID string, nonce uint32, amount uint64, +) { var err error stx := models.SignedTx{} stx.Tx, err = proto.Marshal(&models.Tx{ @@ -632,7 +632,8 @@ func sendTokensTx(t testing.TB, c *testutil.TestHTTPclient, To: signerTo.Address().Bytes(), Value: amount, }, - }}) + }, + }) qt.Assert(t, err, qt.IsNil) stx.Signature, err = signerFrom.SignVocdoniTx(stx.Tx, chainID) diff --git a/test/apierror_test.go b/test/apierror_test.go index f18c0e45a..6cb688b5f 100644 --- a/test/apierror_test.go +++ b/test/apierror_test.go @@ -72,34 +72,44 @@ func TestAPIerror(t *testing.T) { want: api.ErrCantParseAccountID, }, { - args: args{"GET", nil, []string{"votes", "verify", + args: args{"GET", nil, []string{ + "votes", "verify", "0123456789012345678901234567890123456789012345678901234567890123", - "000"}}, + "000", + }}, want: api.ErrCantParseVoteID, }, { - args: args{"GET", nil, []string{"votes", "verify", + args: args{"GET", nil, []string{ + "votes", "verify", "0123456789012345678901234567890123456789012345678901234567890123", - "0000"}}, + "0000", + }}, want: api.ErrVoteIDMalformed, }, { - args: args{"GET", nil, []string{"votes", "verify", + args: args{"GET", nil, []string{ + "votes", "verify", "0123456789012345678901234567890123456789012345678901234567890123", - "0123456789012345678901234567890123456789012345678901234567890123"}}, + "0123456789012345678901234567890123456789012345678901234567890123", + }}, want: api.ErrVoteNotFound, }, { - args: args{"GET", nil, []string{"votes", "verify", + args: args{"GET", nil, []string{ + "votes", "verify", "bbbbb", - "0123456789012345678901234567890123456789012345678901234567890123"}}, + "0123456789012345678901234567890123456789012345678901234567890123", + }}, want: api.ErrCantParseElectionID, }, { - args: args{"GET", nil, []string{"accounts", "0123456789012345678901234567890123456789", + args: args{"GET", nil, []string{ + "accounts", "0123456789012345678901234567890123456789", "elections", "status", "ready", - "page", "-1"}}, + "page", "-1", + }}, want: api.ErrCantFetchElectionList, }, { diff --git a/test/testcommon/testutil/types.go b/test/testcommon/testutil/types.go index 9e28eb6e0..118ace848 100644 --- a/test/testcommon/testutil/types.go +++ b/test/testcommon/testutil/types.go @@ -39,7 +39,8 @@ func (b *MockBlockStore) NewBlock(height int64, timestamp time.Time) { log.Infow("new block", "height", height, "timestamp", timestamp) b.set(height, &comettypes.Block{ Header: comettypes.Header{Height: height, Time: time.Now(), ChainID: "test"}, - Data: comettypes.Data{Txs: make([]comettypes.Tx, 0)}}, + Data: comettypes.Data{Txs: make([]comettypes.Tx, 0)}, + }, ) } diff --git a/test/testcommon/testvoteproof/voteproof.go b/test/testcommon/testvoteproof/voteproof.go index c8cee499d..875f62ffc 100644 --- a/test/testcommon/testvoteproof/voteproof.go +++ b/test/testcommon/testvoteproof/voteproof.go @@ -16,7 +16,8 @@ import ( ) func GetCSPproofBatch(signers []*ethereum.SignKeys, - csp *ethereum.SignKeys, pid []byte) ([]types.HexBytes, error) { + csp *ethereum.SignKeys, pid []byte, +) ([]types.HexBytes, error) { var proofs []types.HexBytes for _, k := range signers { bundle := &models.CAbundle{ @@ -50,8 +51,10 @@ func GetCSPproofBatch(signers []*ethereum.SignKeys, // It returns the keys, the census root and the proofs for each key. func CreateKeysAndBuildCensus(t *testing.T, size int) ([]*ethereum.SignKeys, []byte, [][]byte) { db := metadb.NewTest(t) - tr, err := censustree.New(censustree.Options{Name: "testcensus", ParentDB: db, - MaxLevels: censustree.DefaultMaxLevels, CensusType: models.Census_ARBO_BLAKE2B}) + tr, err := censustree.New(censustree.Options{ + Name: "testcensus", ParentDB: db, + MaxLevels: censustree.DefaultMaxLevels, CensusType: models.Census_ARBO_BLAKE2B, + }) if err != nil { t.Fatal(err) } @@ -80,7 +83,8 @@ func CreateKeysAndBuildCensus(t *testing.T, size int) ([]*ethereum.SignKeys, []b // BuildSignedVoteForOffChainTree builds a signed vote for an off-chain merkle-tree election. func BuildSignedVoteForOffChainTree(t *testing.T, electionID []byte, key *ethereum.SignKeys, - proof []byte, votePackage []int, chainID string) *models.SignedTx { + proof []byte, votePackage []int, chainID string, +) *models.SignedTx { var stx models.SignedTx var err error vp, err := json.Marshal(votePackage) diff --git a/tree/arbo/addbatch_test.go b/tree/arbo/addbatch_test.go index 90d4007f3..0c4cab15f 100644 --- a/tree/arbo/addbatch_test.go +++ b/tree/arbo/addbatch_test.go @@ -39,13 +39,17 @@ func debugTime(descr string, time1, time2 time.Duration) { func testInit(c *qt.C, n int) (*Tree, *Tree) { database1 := metadb.NewTest(c) - tree1, err := NewTree(Config{Database: database1, MaxLevels: 256, - HashFunction: HashFunctionPoseidon}) + tree1, err := NewTree(Config{ + Database: database1, MaxLevels: 256, + HashFunction: HashFunctionPoseidon, + }) c.Assert(err, qt.IsNil) database2 := metadb.NewTest(c) - tree2, err := NewTree(Config{Database: database2, MaxLevels: 256, - HashFunction: HashFunctionPoseidon}) + tree2, err := NewTree(Config{ + Database: database2, MaxLevels: 256, + HashFunction: HashFunctionPoseidon, + }) c.Assert(err, qt.IsNil) bLen := HashFunctionPoseidon.Len() @@ -116,8 +120,10 @@ func TestAddBatchTreeEmptyNotPowerOf2(t *testing.T) { nLeafs := 1027 database := metadb.NewTest(t) - tree, err := NewTree(Config{database, 256, DefaultThresholdNLeafs, - HashFunctionPoseidon}) + tree, err := NewTree(Config{ + database, 256, DefaultThresholdNLeafs, + HashFunctionPoseidon, + }) c.Assert(err, qt.IsNil) bLen := 32 @@ -130,8 +136,10 @@ func TestAddBatchTreeEmptyNotPowerOf2(t *testing.T) { } database2 := metadb.NewTest(t) - tree2, err := NewTree(Config{database2, 256, DefaultThresholdNLeafs, - HashFunctionPoseidon}) + tree2, err := NewTree(Config{ + database2, 256, DefaultThresholdNLeafs, + HashFunctionPoseidon, + }) c.Assert(err, qt.IsNil) var keys, values [][]byte @@ -161,13 +169,17 @@ func randomBytes(n int) []byte { func TestAddBatchTestVector1(t *testing.T) { c := qt.New(t) database1 := metadb.NewTest(t) - tree1, err := NewTree(Config{database1, 256, DefaultThresholdNLeafs, - HashFunctionBlake2b}) + tree1, err := NewTree(Config{ + database1, 256, DefaultThresholdNLeafs, + HashFunctionBlake2b, + }) c.Assert(err, qt.IsNil) database2 := metadb.NewTest(t) - tree2, err := NewTree(Config{database2, 256, DefaultThresholdNLeafs, - HashFunctionBlake2b}) + tree2, err := NewTree(Config{ + database2, 256, DefaultThresholdNLeafs, + HashFunctionBlake2b, + }) c.Assert(err, qt.IsNil) // leafs in 2nd level subtrees: [ 6, 0, 1, 1] @@ -199,13 +211,17 @@ func TestAddBatchTestVector1(t *testing.T) { // 2nd test vectors database1 = metadb.NewTest(t) - tree1, err = NewTree(Config{database1, 256, DefaultThresholdNLeafs, - HashFunctionBlake2b}) + tree1, err = NewTree(Config{ + database1, 256, DefaultThresholdNLeafs, + HashFunctionBlake2b, + }) c.Assert(err, qt.IsNil) database2 = metadb.NewTest(t) - tree2, err = NewTree(Config{database2, 256, DefaultThresholdNLeafs, - HashFunctionBlake2b}) + tree2, err = NewTree(Config{ + database2, 256, DefaultThresholdNLeafs, + HashFunctionBlake2b, + }) c.Assert(err, qt.IsNil) testvectorKeys = []string{ @@ -245,13 +261,17 @@ func TestAddBatchTestVector2(t *testing.T) { c := qt.New(t) database := metadb.NewTest(t) - tree1, err := NewTree(Config{database, 256, DefaultThresholdNLeafs, - HashFunctionPoseidon}) + tree1, err := NewTree(Config{ + database, 256, DefaultThresholdNLeafs, + HashFunctionPoseidon, + }) c.Assert(err, qt.IsNil) database2 := metadb.NewTest(t) - tree2, err := NewTree(Config{database2, 256, DefaultThresholdNLeafs, - HashFunctionPoseidon}) + tree2, err := NewTree(Config{ + database2, 256, DefaultThresholdNLeafs, + HashFunctionPoseidon, + }) c.Assert(err, qt.IsNil) bLen := tree1.HashFunction().Len() @@ -288,13 +308,17 @@ func TestAddBatchTestVector3(t *testing.T) { c := qt.New(t) database := metadb.NewTest(t) - tree1, err := NewTree(Config{database, 256, DefaultThresholdNLeafs, - HashFunctionPoseidon}) + tree1, err := NewTree(Config{ + database, 256, DefaultThresholdNLeafs, + HashFunctionPoseidon, + }) c.Assert(err, qt.IsNil) database2 := metadb.NewTest(t) - tree2, err := NewTree(Config{database2, 256, DefaultThresholdNLeafs, - HashFunctionPoseidon}) + tree2, err := NewTree(Config{ + database2, 256, DefaultThresholdNLeafs, + HashFunctionPoseidon, + }) c.Assert(err, qt.IsNil) bLen := tree1.HashFunction().Len() @@ -335,13 +359,17 @@ func TestAddBatchTreeEmptyRandomKeys(t *testing.T) { nLeafs := 8 database1 := metadb.NewTest(t) - tree1, err := NewTree(Config{database1, 256, DefaultThresholdNLeafs, - HashFunctionBlake2b}) + tree1, err := NewTree(Config{ + database1, 256, DefaultThresholdNLeafs, + HashFunctionBlake2b, + }) c.Assert(err, qt.IsNil) database2 := metadb.NewTest(t) - tree2, err := NewTree(Config{database2, 256, DefaultThresholdNLeafs, - HashFunctionBlake2b}) + tree2, err := NewTree(Config{ + database2, 256, DefaultThresholdNLeafs, + HashFunctionBlake2b, + }) c.Assert(err, qt.IsNil) var keys, values [][]byte @@ -683,8 +711,10 @@ func TestAddBatchNotEmptyUnbalanced(t *testing.T) { time1 := time.Since(start) database2 := metadb.NewTest(t) - tree2, err := NewTree(Config{database2, 256, DefaultThresholdNLeafs, - HashFunctionPoseidon}) + tree2, err := NewTree(Config{ + database2, 256, DefaultThresholdNLeafs, + HashFunctionPoseidon, + }) c.Assert(err, qt.IsNil) tree2.dbgInit() @@ -777,8 +807,10 @@ func benchAddBatch(t *testing.T, ks, vs [][]byte) { c := qt.New(t) database := metadb.NewTest(t) - tree, err := NewTree(Config{database, 256, DefaultThresholdNLeafs, - HashFunctionBlake2b}) + tree, err := NewTree(Config{ + database, 256, DefaultThresholdNLeafs, + HashFunctionBlake2b, + }) c.Assert(err, qt.IsNil) tree.dbgInit() @@ -809,8 +841,10 @@ func TestDbgStats(t *testing.T) { // 1 database1 := metadb.NewTest(t) - tree1, err := NewTree(Config{database1, 256, DefaultThresholdNLeafs, - HashFunctionBlake2b}) + tree1, err := NewTree(Config{ + database1, 256, DefaultThresholdNLeafs, + HashFunctionBlake2b, + }) c.Assert(err, qt.IsNil) tree1.dbgInit() @@ -822,8 +856,10 @@ func TestDbgStats(t *testing.T) { // 2 database2 := metadb.NewTest(t) - tree2, err := NewTree(Config{database2, 256, DefaultThresholdNLeafs, - HashFunctionBlake2b}) + tree2, err := NewTree(Config{ + database2, 256, DefaultThresholdNLeafs, + HashFunctionBlake2b, + }) c.Assert(err, qt.IsNil) tree2.dbgInit() @@ -834,8 +870,10 @@ func TestDbgStats(t *testing.T) { // 3 database3 := metadb.NewTest(t) - tree3, err := NewTree(Config{database3, 256, DefaultThresholdNLeafs, - HashFunctionBlake2b}) + tree3, err := NewTree(Config{ + database3, 256, DefaultThresholdNLeafs, + HashFunctionBlake2b, + }) c.Assert(err, qt.IsNil) tree3.dbgInit() @@ -868,8 +906,10 @@ func TestLoadVT(t *testing.T) { nLeafs := 1024 database := metadb.NewTest(t) - tree, err := NewTree(Config{database, 256, DefaultThresholdNLeafs, - HashFunctionPoseidon}) + tree, err := NewTree(Config{ + database, 256, DefaultThresholdNLeafs, + HashFunctionPoseidon, + }) c.Assert(err, qt.IsNil) var keys, values [][]byte @@ -901,8 +941,10 @@ func TestAddKeysWithEmptyValues(t *testing.T) { nLeafs := 1024 database := metadb.NewTest(t) - tree, err := NewTree(Config{database, 256, DefaultThresholdNLeafs, - HashFunctionPoseidon}) + tree, err := NewTree(Config{ + database, 256, DefaultThresholdNLeafs, + HashFunctionPoseidon, + }) c.Assert(err, qt.IsNil) bLen := 32 @@ -921,8 +963,10 @@ func TestAddKeysWithEmptyValues(t *testing.T) { } database2 := metadb.NewTest(t) - tree2, err := NewTree(Config{database2, 256, DefaultThresholdNLeafs, - HashFunctionPoseidon}) + tree2, err := NewTree(Config{ + database2, 256, DefaultThresholdNLeafs, + HashFunctionPoseidon, + }) c.Assert(err, qt.IsNil) tree2.dbgInit() @@ -934,8 +978,10 @@ func TestAddKeysWithEmptyValues(t *testing.T) { // use tree3 to add nil value array database3 := metadb.NewTest(t) - tree3, err := NewTree(Config{database3, 256, DefaultThresholdNLeafs, - HashFunctionPoseidon}) + tree3, err := NewTree(Config{ + database3, 256, DefaultThresholdNLeafs, + HashFunctionPoseidon, + }) c.Assert(err, qt.IsNil) invalids, err = tree3.AddBatch(keys, nil) @@ -962,8 +1008,10 @@ func TestAddKeysWithEmptyValues(t *testing.T) { c.Check(verif, qt.IsTrue) // check with array with 32 zeroes - e32 := []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} + e32 := []byte{ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + } c.Assert(len(e32), qt.Equals, 32) verif, err = CheckProof(tree.hashFunction, keys[9], e32, root, siblings) c.Assert(err, qt.IsNil) diff --git a/tree/arbo/circomproofs_test.go b/tree/arbo/circomproofs_test.go index 7c48c2c5b..a75eba83f 100644 --- a/tree/arbo/circomproofs_test.go +++ b/tree/arbo/circomproofs_test.go @@ -12,8 +12,10 @@ import ( func TestCircomVerifierProof(t *testing.T) { c := qt.New(t) database := metadb.NewTest(t) - tree, err := NewTree(Config{Database: database, MaxLevels: 4, - HashFunction: HashFunctionPoseidon}) + tree, err := NewTree(Config{ + Database: database, MaxLevels: 4, + HashFunction: HashFunctionPoseidon, + }) c.Assert(err, qt.IsNil) testVector := [][]int64{ diff --git a/tree/arbo/helpers_test.go b/tree/arbo/helpers_test.go index 7853f8ee4..22053d7c6 100644 --- a/tree/arbo/helpers_test.go +++ b/tree/arbo/helpers_test.go @@ -39,7 +39,7 @@ func checkRoots(c *qt.C, tree1, tree2 *Tree) { func storeTree(c *qt.C, tree *Tree, path string) { dump, err := tree.Dump(nil) c.Assert(err, qt.IsNil) - err = os.WriteFile(path+"-"+time.Now().String()+".debug", dump, 0600) + err = os.WriteFile(path+"-"+time.Now().String()+".debug", dump, 0o600) c.Assert(err, qt.IsNil) } @@ -85,13 +85,17 @@ func TestReadTreeDBG(t *testing.T) { c := qt.New(t) database1 := metadb.NewTest(t) - tree1, err := NewTree(Config{Database: database1, MaxLevels: 100, - HashFunction: HashFunctionBlake2b}) + tree1, err := NewTree(Config{ + Database: database1, MaxLevels: 100, + HashFunction: HashFunctionBlake2b, + }) c.Assert(err, qt.IsNil) database2 := metadb.NewTest(t) - tree2, err := NewTree(Config{Database: database2, MaxLevels: 100, - HashFunction: HashFunctionBlake2b}) + tree2, err := NewTree(Config{ + Database: database2, MaxLevels: 100, + HashFunction: HashFunctionBlake2b, + }) c.Assert(err, qt.IsNil) // tree1 is generated by a loop of .Add diff --git a/tree/arbo/navigate.go b/tree/arbo/navigate.go index 53e596a6c..a6a7d4d0a 100644 --- a/tree/arbo/navigate.go +++ b/tree/arbo/navigate.go @@ -10,7 +10,8 @@ import ( // down goes down to the leaf recursively func (t *Tree) down(rTx db.Reader, newKey, currKey []byte, siblings [][]byte, intermediates *[][]byte, - path []bool, currLvl int, getLeaf bool) ([]byte, []byte, [][]byte, error) { + path []bool, currLvl int, getLeaf bool, +) ([]byte, []byte, [][]byte, error) { if currLvl > t.maxLevels { return nil, nil, nil, ErrMaxLevel } diff --git a/tree/arbo/testvectors/circom/go-data-generator/generator_test.go b/tree/arbo/testvectors/circom/go-data-generator/generator_test.go index 2e1944051..6b681d9e1 100644 --- a/tree/arbo/testvectors/circom/go-data-generator/generator_test.go +++ b/tree/arbo/testvectors/circom/go-data-generator/generator_test.go @@ -14,8 +14,10 @@ import ( func TestGenerator(t *testing.T) { c := qt.New(t) database := metadb.NewTest(t) - tree, err := arbo.NewTree(arbo.Config{Database: database, MaxLevels: 4, - HashFunction: arbo.HashFunctionPoseidon}) + tree, err := arbo.NewTree(arbo.Config{ + Database: database, MaxLevels: 4, + HashFunction: arbo.HashFunctionPoseidon, + }) c.Assert(err, qt.IsNil) testVector := [][]int64{ @@ -40,7 +42,7 @@ func TestGenerator(t *testing.T) { jCvp, err := json.Marshal(cvp) c.Assert(err, qt.IsNil) // store the data into a file that will be used at the circom test - err = os.WriteFile("go-smt-verifier-inputs.json", jCvp, 0600) + err = os.WriteFile("go-smt-verifier-inputs.json", jCvp, 0o600) c.Assert(err, qt.IsNil) // proof of non-existence @@ -50,6 +52,6 @@ func TestGenerator(t *testing.T) { jCvp, err = json.Marshal(cvp) c.Assert(err, qt.IsNil) // store the data into a file that will be used at the circom test - err = os.WriteFile("go-smt-verifier-non-existence-inputs.json", jCvp, 0600) + err = os.WriteFile("go-smt-verifier-non-existence-inputs.json", jCvp, 0o600) c.Assert(err, qt.IsNil) } diff --git a/tree/arbo/tree_test.go b/tree/arbo/tree_test.go index d2a9750b9..9ff0e9679 100644 --- a/tree/arbo/tree_test.go +++ b/tree/arbo/tree_test.go @@ -74,8 +74,10 @@ func TestAddTestVectors(t *testing.T) { func testAdd(c *qt.C, hashFunc HashFunction, testVectors []string) { database := metadb.NewTest(c) - tree, err := NewTree(Config{Database: database, MaxLevels: 256, - HashFunction: hashFunc}) + tree, err := NewTree(Config{ + Database: database, MaxLevels: 256, + HashFunction: hashFunc, + }) c.Assert(err, qt.IsNil) root, err := tree.Root() @@ -331,8 +333,10 @@ func TestRootOnTx(t *testing.T) { func TestAux(t *testing.T) { // TODO split in proper tests c := qt.New(t) database := metadb.NewTest(t) - tree, err := NewTree(Config{Database: database, MaxLevels: 256, - HashFunction: HashFunctionPoseidon}) + tree, err := NewTree(Config{ + Database: database, MaxLevels: 256, + HashFunction: HashFunctionPoseidon, + }) c.Assert(err, qt.IsNil) bLen := 32 @@ -369,8 +373,10 @@ func TestAux(t *testing.T) { // TODO split in proper tests func TestGet(t *testing.T) { c := qt.New(t) database := metadb.NewTest(t) - tree, err := NewTree(Config{Database: database, MaxLevels: 256, - HashFunction: HashFunctionPoseidon}) + tree, err := NewTree(Config{ + Database: database, MaxLevels: 256, + HashFunction: HashFunctionPoseidon, + }) c.Assert(err, qt.IsNil) bLen := 32 @@ -394,17 +400,21 @@ func TestBitmapBytes(t *testing.T) { b := []byte{15} bits := bytesToBitmap(b) - c.Assert(bits, qt.DeepEquals, []bool{true, true, true, true, - false, false, false, false}) + c.Assert(bits, qt.DeepEquals, []bool{ + true, true, true, true, + false, false, false, false, + }) b2 := bitmapToBytes(bits) c.Assert(b2, qt.DeepEquals, b) b = []byte{0, 15, 50} bits = bytesToBitmap(b) - c.Assert(bits, qt.DeepEquals, []bool{false, false, false, + c.Assert(bits, qt.DeepEquals, []bool{ + false, false, false, false, false, false, false, false, true, true, true, true, false, false, false, false, false, true, false, false, true, - true, false, false}) + true, false, false, + }) b2 = bitmapToBytes(bits) c.Assert(b2, qt.DeepEquals, b) @@ -504,8 +514,10 @@ func TestPackAndUnpackSiblings(t *testing.T) { func TestGenProofAndVerify(t *testing.T) { c := qt.New(t) database := metadb.NewTest(t) - tree, err := NewTree(Config{Database: database, MaxLevels: 256, - HashFunction: HashFunctionPoseidon}) + tree, err := NewTree(Config{ + Database: database, MaxLevels: 256, + HashFunction: HashFunctionPoseidon, + }) c.Assert(err, qt.IsNil) bLen := 32 @@ -543,8 +555,10 @@ func TestDumpAndImportDumpInFile(t *testing.T) { func testDumpAndImportDump(t *testing.T, inFile bool) { c := qt.New(t) database1 := metadb.NewTest(t) - tree1, err := NewTree(Config{Database: database1, MaxLevels: 256, - HashFunction: HashFunctionPoseidon}) + tree1, err := NewTree(Config{ + Database: database1, MaxLevels: 256, + HashFunction: HashFunctionPoseidon, + }) c.Assert(err, qt.IsNil) bLen := 32 @@ -570,8 +584,10 @@ func testDumpAndImportDump(t *testing.T, inFile bool) { } database2 := metadb.NewTest(t) - tree2, err := NewTree(Config{Database: database2, MaxLevels: 256, - HashFunction: HashFunctionPoseidon}) + tree2, err := NewTree(Config{ + Database: database2, MaxLevels: 256, + HashFunction: HashFunctionPoseidon, + }) c.Assert(err, qt.IsNil) if inFile { @@ -596,8 +612,10 @@ func testDumpAndImportDump(t *testing.T, inFile bool) { func TestRWMutex(t *testing.T) { c := qt.New(t) database := metadb.NewTest(t) - tree, err := NewTree(Config{Database: database, MaxLevels: 256, - HashFunction: HashFunctionPoseidon}) + tree, err := NewTree(Config{ + Database: database, MaxLevels: 256, + HashFunction: HashFunctionPoseidon, + }) c.Assert(err, qt.IsNil) bLen := 32 @@ -627,13 +645,17 @@ func TestAddBatchFullyUsed(t *testing.T) { c := qt.New(t) database1 := metadb.NewTest(t) - tree1, err := NewTree(Config{Database: database1, MaxLevels: 4, - HashFunction: HashFunctionPoseidon}) + tree1, err := NewTree(Config{ + Database: database1, MaxLevels: 4, + HashFunction: HashFunctionPoseidon, + }) c.Assert(err, qt.IsNil) database2 := metadb.NewTest(t) - tree2, err := NewTree(Config{Database: database2, MaxLevels: 4, - HashFunction: HashFunctionPoseidon}) + tree2, err := NewTree(Config{ + Database: database2, MaxLevels: 4, + HashFunction: HashFunctionPoseidon, + }) c.Assert(err, qt.IsNil) var keys, values [][]byte @@ -686,8 +708,10 @@ func TestAddBatchFullyUsed(t *testing.T) { func TestSetRoot(t *testing.T) { c := qt.New(t) database := metadb.NewTest(t) - tree, err := NewTree(Config{Database: database, MaxLevels: 256, - HashFunction: HashFunctionPoseidon}) + tree, err := NewTree(Config{ + Database: database, MaxLevels: 256, + HashFunction: HashFunctionPoseidon, + }) c.Assert(err, qt.IsNil) expectedRoot := "13742386369878513332697380582061714160370929283209286127733983161245560237407" @@ -744,8 +768,10 @@ func TestSetRoot(t *testing.T) { func TestSnapshot(t *testing.T) { c := qt.New(t) database := metadb.NewTest(t) - tree, err := NewTree(Config{Database: database, MaxLevels: 256, - HashFunction: HashFunctionPoseidon}) + tree, err := NewTree(Config{ + Database: database, MaxLevels: 256, + HashFunction: HashFunctionPoseidon, + }) c.Assert(err, qt.IsNil) // fill the tree @@ -794,8 +820,10 @@ func TestGetFromSnapshotExpectArboErrKeyNotFound(t *testing.T) { c := qt.New(t) database := metadb.NewTest(t) - tree, err := NewTree(Config{Database: database, MaxLevels: 256, - HashFunction: HashFunctionPoseidon}) + tree, err := NewTree(Config{ + Database: database, MaxLevels: 256, + HashFunction: HashFunctionPoseidon, + }) c.Assert(err, qt.IsNil) bLen := 32 @@ -815,8 +843,10 @@ func TestKeyLen(t *testing.T) { database := metadb.NewTest(t) // maxLevels is 100, keyPath length = ceil(maxLevels/8) = 13 maxLevels := 100 - tree, err := NewTree(Config{Database: database, MaxLevels: maxLevels, - HashFunction: HashFunctionBlake2b}) + tree, err := NewTree(Config{ + Database: database, MaxLevels: maxLevels, + HashFunction: HashFunctionBlake2b, + }) c.Assert(err, qt.IsNil) // expect no errors when adding a key of only 4 bytes (when the @@ -847,8 +877,10 @@ func TestKeyLen(t *testing.T) { // tree: ceil(maxLevels/8) maxLevels = 32 database = metadb.NewTest(t) - tree, err = NewTree(Config{Database: database, MaxLevels: maxLevels, - HashFunction: HashFunctionBlake2b}) + tree, err = NewTree(Config{ + Database: database, MaxLevels: maxLevels, + HashFunction: HashFunctionBlake2b, + }) c.Assert(err, qt.IsNil) maxKeyLen := int(math.Ceil(float64(maxLevels) / float64(8))) @@ -917,8 +949,10 @@ func TestKeyLenBiggerThan32(t *testing.T) { c := qt.New(t) maxLevels := 264 database := metadb.NewTest(t) - tree, err := NewTree(Config{Database: database, MaxLevels: maxLevels, - HashFunction: HashFunctionBlake2b}) + tree, err := NewTree(Config{ + Database: database, MaxLevels: maxLevels, + HashFunction: HashFunctionBlake2b, + }) c.Assert(err, qt.IsNil) bLen := 33 @@ -940,8 +974,10 @@ func TestKeyLenBiggerThan32(t *testing.T) { func TestDelete(t *testing.T) { c := qt.New(t) database := metadb.NewTest(t) - tree, err := NewTree(Config{Database: database, MaxLevels: 256, - HashFunction: HashFunctionPoseidon}) + tree, err := NewTree(Config{ + Database: database, MaxLevels: 256, + HashFunction: HashFunctionPoseidon, + }) c.Assert(err, qt.IsNil) bLen := 32 @@ -1019,8 +1055,10 @@ func BenchmarkAdd(b *testing.B) { func benchmarkAdd(b *testing.B, hashFunc HashFunction, ks, vs [][]byte) { c := qt.New(b) database := metadb.NewTest(c) - tree, err := NewTree(Config{Database: database, MaxLevels: 140, - HashFunction: hashFunc}) + tree, err := NewTree(Config{ + Database: database, MaxLevels: 140, + HashFunction: hashFunc, + }) c.Assert(err, qt.IsNil) for i := 0; i < len(ks); i++ { @@ -1059,7 +1097,7 @@ func TestDiskSizeBench(t *testing.T) { countDBitems := func() int { count := 0 if err := tree.db.Iterate(nil, func(_, _ []byte) bool { - //fmt.Printf("db item: %x\n", k) + // fmt.Printf("db item: %x\n", k) count++ return true }); err != nil { @@ -1090,7 +1128,7 @@ func TestDiskSizeBench(t *testing.T) { for i := 0; i < len(ks)/2; i++ { err = tree.DeleteWithTx(tx, ks[i]) c.Assert(err, qt.IsNil) - //fmt.Printf("deleted %x\n", ks[i]) + // fmt.Printf("deleted %x\n", ks[i]) } c.Assert(tx.Commit(), qt.IsNil) printRes(" Delete loop", time.Since(start)) @@ -1130,7 +1168,7 @@ func TestDiskSizeBench(t *testing.T) { for i := 0; i < len(ks); i++ { err = tree.UpdateWithTx(tx, ks[i], vs[len(ks)-i-1]) c.Assert(err, qt.IsNil, qt.Commentf("k=%x", ks[i])) - //fmt.Printf("updated %x\n", ks[i]) + // fmt.Printf("updated %x\n", ks[i]) } c.Assert(tx.Commit(), qt.IsNil) printRes(" Update loop", time.Since(start)) @@ -1168,8 +1206,10 @@ func dirSize(path string) (int64, error) { func TestGetLeavesFromSubPath(t *testing.T) { c := qt.New(t) database := metadb.NewTest(t) - tree, err := NewTree(Config{Database: database, MaxLevels: 256, - HashFunction: HashFunctionPoseidon}) + tree, err := NewTree(Config{ + Database: database, MaxLevels: 256, + HashFunction: HashFunctionPoseidon, + }) c.Assert(err, qt.IsNil) bLen := 32 @@ -1248,8 +1288,10 @@ func TestTreeAfterDeleteAndReconstruct(t *testing.T) { database2 := metadb.NewTest(t) // 1. A new tree (tree1) is created and filled with some data - tree1, err := NewTree(Config{Database: database1, MaxLevels: 256, - HashFunction: HashFunctionBlake2b}) + tree1, err := NewTree(Config{ + Database: database1, MaxLevels: 256, + HashFunction: HashFunctionBlake2b, + }) c.Assert(err, qt.IsNil) // prepare inputs @@ -1274,8 +1316,10 @@ func TestTreeAfterDeleteAndReconstruct(t *testing.T) { } // 3. Create a second tree (tree2) - tree2, err := NewTree(Config{Database: database2, MaxLevels: 256, - HashFunction: HashFunctionBlake2b}) + tree2, err := NewTree(Config{ + Database: database2, MaxLevels: 256, + HashFunction: HashFunctionBlake2b, + }) c.Assert(err, qt.IsNil) // 4. Add the non-deleted keys from tree1 to tree2 @@ -1308,8 +1352,10 @@ func TestTreeWithSingleLeaf(t *testing.T) { c := qt.New(t) database := metadb.NewTest(t) - tree, err := NewTree(Config{Database: database, MaxLevels: 256, - HashFunction: HashFunctionPoseidon}) + tree, err := NewTree(Config{ + Database: database, MaxLevels: 256, + HashFunction: HashFunctionPoseidon, + }) c.Assert(err, qt.IsNil) // check empty root diff --git a/tree/arbo/vt.go b/tree/arbo/vt.go index 1bd8dfe98..40b5a8572 100644 --- a/tree/arbo/vt.go +++ b/tree/arbo/vt.go @@ -436,7 +436,7 @@ func (n *node) add(p *params, currLvl int, leaf *node) error { switch t { case vtMid: if leaf.path[currLvl] { - //right + // right if n.r == nil { // empty sub-node, add the leaf here n.r = leaf @@ -568,7 +568,8 @@ func flp2(n int) int { // computeHashes computes the hashes under the node from which is called the // method. Returns an array of key-values to store in the db func (n *node) computeHashes(currLvl, maxLvl int, p *params, pairs [][2][]byte) ( - [][2][]byte, error) { + [][2][]byte, error, +) { if n == nil || currLvl >= maxLvl { // no need to compute any hash return pairs, nil diff --git a/tree/arbo/vt_test.go b/tree/arbo/vt_test.go index 09d1e10b5..705796b15 100644 --- a/tree/arbo/vt_test.go +++ b/tree/arbo/vt_test.go @@ -17,8 +17,10 @@ func testVirtualTree(c *qt.C, maxLevels int, keys, values [][]byte) { // normal tree, to have an expected root value database := metadb.NewTest(c) - tree, err := NewTree(Config{Database: database, MaxLevels: maxLevels, - HashFunction: HashFunctionSha256}) + tree, err := NewTree(Config{ + Database: database, MaxLevels: maxLevels, + HashFunction: HashFunctionSha256, + }) c.Assert(err, qt.IsNil) for i := 0; i < len(keys); i++ { err := tree.Add(keys[i], values[i]) @@ -122,8 +124,10 @@ func TestVirtualTreeAddBatch(t *testing.T) { // normal tree, to have an expected root value database := metadb.NewTest(t) - tree, err := NewTree(Config{Database: database, MaxLevels: maxLevels, - HashFunction: HashFunctionBlake2b}) + tree, err := NewTree(Config{ + Database: database, MaxLevels: maxLevels, + HashFunction: HashFunctionBlake2b, + }) c.Assert(err, qt.IsNil) for i := 0; i < len(keys); i++ { err := tree.Add(keys[i], values[i]) diff --git a/vochain/account_test.go b/vochain/account_test.go index 927de93b2..a491ea940 100644 --- a/vochain/account_test.go +++ b/vochain/account_test.go @@ -36,7 +36,8 @@ func testCommitState(t *testing.T, app *BaseApplication) { } func setupTestBaseApplicationAndSigners(t *testing.T, - numberSigners int) (*BaseApplication, []*ethereum.SignKeys, error) { + numberSigners int, +) (*BaseApplication, []*ethereum.SignKeys, error) { app := TestBaseApplication(t) signers := make([]*ethereum.SignKeys, numberSigners) for i := 0; i < numberSigners; i++ { @@ -77,7 +78,8 @@ func TestSetAccountTx(t *testing.T) { // set account 0 qt.Assert(t, app.State.SetAccount(signers[0].Address(), &state.Account{ - Account: models.Account{Balance: 10000, InfoURI: infoURI}}), + Account: models.Account{Balance: 10000, InfoURI: infoURI}, + }), qt.IsNil, ) testCommitState(t, app) @@ -507,7 +509,8 @@ func testSetAccountTx(t *testing.T, app *BaseApplication, infoURI string, nonce uint32, - create bool) error { + create bool, +) error { var err error sik, err := signer.AccountSIK(nil) @@ -618,7 +621,6 @@ func TestSendTokensTxToTheSameAccount(t *testing.T) { err = testSendTokensTx(t, &signer, app, signer.Address(), 89, 0) qt.Assert(t, err, qt.IsNotNil) - } func testSendTokensTx(t *testing.T, @@ -626,7 +628,8 @@ func testSendTokensTx(t *testing.T, app *BaseApplication, toAddr common.Address, value uint64, - nonce uint32) error { + nonce uint32, +) error { var err error // tx @@ -730,7 +733,8 @@ func testSetAccountDelegateTx(t *testing.T, app *BaseApplication, delegate common.Address, op bool, // true == add, false == del - nonce uint32) error { + nonce uint32, +) error { var err error // tx @@ -854,7 +858,8 @@ func testCollectFaucetTx(t *testing.T, app *BaseApplication, nonce uint32, amount, - identifier uint64) error { + identifier uint64, +) error { var err error // tx diff --git a/vochain/appsetup.go b/vochain/appsetup.go index 54fa0d529..f927e5e78 100644 --- a/vochain/appsetup.go +++ b/vochain/appsetup.go @@ -98,7 +98,6 @@ func (app *BaseApplication) SetDefaultMethods() { } return result, err }) - } func (app *BaseApplication) getTxTendermint(height uint32, txIndex int32) (*models.SignedTx, error) { diff --git a/vochain/cometbft.go b/vochain/cometbft.go index 138380c7b..09d0e80fb 100644 --- a/vochain/cometbft.go +++ b/vochain/cometbft.go @@ -38,7 +38,8 @@ import ( // // We use this method to initialize some state variables. func (app *BaseApplication) Info(_ context.Context, - req *cometabcitypes.InfoRequest) (*cometabcitypes.InfoResponse, error) { + req *cometabcitypes.InfoRequest, +) (*cometabcitypes.InfoResponse, error) { lastHeight, err := app.State.LastHeight() if err != nil { return nil, fmt.Errorf("cannot get State.LastHeight: %w", err) @@ -66,7 +67,8 @@ func (app *BaseApplication) Info(_ context.Context, // InitChainResponse can return a list of validators. If the list is empty, // Tendermint will use the validators loaded in the genesis file. func (app *BaseApplication) InitChain(_ context.Context, - req *cometabcitypes.InitChainRequest) (*cometabcitypes.InitChainResponse, error) { + req *cometabcitypes.InitChainRequest, +) (*cometabcitypes.InitChainResponse, error) { // setting the app initial state with validators, height = 0 and empty apphash // unmarshal app state from genesis var genesisAppState genesis.AppState @@ -235,7 +237,8 @@ func (app *BaseApplication) CheckTx(_ context.Context, req *cometabcitypes.Check // Cryptographic commitments to the block and transaction results, returned via the corresponding // parameters in FinalizeBlockResponse, are included in the header of the next block. func (app *BaseApplication) FinalizeBlock(_ context.Context, - req *cometabcitypes.FinalizeBlockRequest) (*cometabcitypes.FinalizeBlockResponse, error) { + req *cometabcitypes.FinalizeBlockRequest, +) (*cometabcitypes.FinalizeBlockResponse, error) { app.prepareProposalLock.Lock() defer app.prepareProposalLock.Unlock() if req == nil { @@ -345,7 +348,8 @@ func (app *BaseApplication) Commit(_ context.Context, _ *cometabcitypes.CommitRe // order in which they appear, and returns the (potentially) modified proposal, called prepared proposal in // the PrepareProposalResponse call. The logic modifying the raw proposal MAY be non-deterministic. func (app *BaseApplication) PrepareProposal(ctx context.Context, - req *cometabcitypes.PrepareProposalRequest) (*cometabcitypes.PrepareProposalResponse, error) { + req *cometabcitypes.PrepareProposalRequest, +) (*cometabcitypes.PrepareProposalResponse, error) { app.prepareProposalLock.Lock() defer app.prepareProposalLock.Unlock() if req == nil { @@ -454,7 +458,8 @@ func (app *BaseApplication) PrepareProposal(ctx context.Context, // is invalid (e.g., an invalid transaction); the Application can ignore the invalid part of the prepared // proposal at block execution time. The logic in ProcessProposal MUST be deterministic. func (app *BaseApplication) ProcessProposal(_ context.Context, - req *cometabcitypes.ProcessProposalRequest) (*cometabcitypes.ProcessProposalResponse, error) { + req *cometabcitypes.ProcessProposalRequest, +) (*cometabcitypes.ProcessProposalResponse, error) { app.prepareProposalLock.Lock() defer app.prepareProposalLock.Unlock() if req == nil { @@ -569,7 +574,6 @@ func (app *BaseApplication) LoadSnapshotChunk(_ context.Context, "height", req.Height, "format", req.Format, "chunk", req.Chunk) buf, err := app.Snapshots.SliceChunk(req.Height, req.Format, req.Chunk) - if err != nil { return nil, err } @@ -669,18 +673,21 @@ func (app *BaseApplication) RestoreStateFromSnapshot(snap *snapshot.Snapshot) er // Query does nothing func (*BaseApplication) Query(_ context.Context, - _ *cometabcitypes.QueryRequest) (*cometabcitypes.QueryResponse, error) { + _ *cometabcitypes.QueryRequest, +) (*cometabcitypes.QueryResponse, error) { return &cometabcitypes.QueryResponse{}, nil } // ExtendVote creates application specific vote extension func (*BaseApplication) ExtendVote(_ context.Context, - req *cometabcitypes.ExtendVoteRequest) (*cometabcitypes.ExtendVoteResponse, error) { + req *cometabcitypes.ExtendVoteRequest, +) (*cometabcitypes.ExtendVoteResponse, error) { return &cometabcitypes.ExtendVoteResponse{}, nil } // VerifyVoteExtension verifies application's vote extension data func (*BaseApplication) VerifyVoteExtension(context.Context, - *cometabcitypes.VerifyVoteExtensionRequest) (*cometabcitypes.VerifyVoteExtensionResponse, error) { + *cometabcitypes.VerifyVoteExtensionRequest, +) (*cometabcitypes.VerifyVoteExtensionResponse, error) { return &cometabcitypes.VerifyVoteExtensionResponse{}, nil } diff --git a/vochain/genesis/genesis.go b/vochain/genesis/genesis.go index 13b9b7013..b349c2d07 100644 --- a/vochain/genesis/genesis.go +++ b/vochain/genesis/genesis.go @@ -38,7 +38,7 @@ var Genesis = map[string]Vochain{ } var devGenesis = Doc{ - GenesisTime: time.Date(2024, time.March, 04, 1, 0, 0, 0, time.UTC), + GenesisTime: time.Date(2024, time.March, 0o4, 1, 0, 0, 0, time.UTC), ChainID: "vocdoni/DEV/32", ConsensusParams: &ConsensusParams{ Block: BlockParams{ diff --git a/vochain/indexer/indexer.go b/vochain/indexer/indexer.go index 231b5f0f9..4d3c43ca9 100644 --- a/vochain/indexer/indexer.go +++ b/vochain/indexer/indexer.go @@ -268,7 +268,6 @@ func (idx *Indexer) ExportBackupAsBytes(ctx context.Context) ([]byte, error) { tmpDir, err := os.MkdirTemp("", "indexer") if err != nil { return nil, fmt.Errorf("error creating tmpDir: %w", err) - } tmpFilePath := filepath.Join(tmpDir, "indexer.sqlite3") if err := idx.SaveBackup(ctx, tmpFilePath); err != nil { @@ -897,7 +896,8 @@ func (idx *Indexer) GetTokenTransfersByAccount(acc []byte, offset, maxItems int3 return indexertypes.TokenTransfersAccount{ Received: transfersTo, - Sent: transfersFrom}, nil + Sent: transfersFrom, + }, nil } // CountTokenTransfersByAccount returns the count all the token transfers made from a given account diff --git a/vochain/indexer/indexer_test.go b/vochain/indexer/indexer_test.go index bd2cea58e..eec8dab4d 100644 --- a/vochain/indexer/indexer_test.go +++ b/vochain/indexer/indexer_test.go @@ -588,7 +588,8 @@ func TestResults(t *testing.T) { Status: models.ProcessStatus_READY, Mode: &models.ProcessMode{ AutoStart: true, - Interruptible: true}, + Interruptible: true, + }, BlockCount: 40, EncryptionPrivateKeys: make([]string, 16), EncryptionPublicKeys: make([]string, 16), @@ -627,7 +628,8 @@ func TestResults(t *testing.T) { Type: models.ProofArbo_BLAKE2B, Siblings: proofs[i], KeyType: models.ProofArbo_ADDRESS, - }}}, + }, + }}, ProcessId: pid, VotePackage: vp, Nullifier: util.RandomBytes(32), @@ -1178,7 +1180,8 @@ func TestOverwriteVotes(t *testing.T) { Type: models.ProofArbo_BLAKE2B, Siblings: proofs[0], KeyType: models.ProofArbo_ADDRESS, - }}}, + }, + }}, ProcessId: pid, VotePackage: vp, } @@ -1267,7 +1270,8 @@ func TestOverwriteVotes(t *testing.T) { Type: models.ProofArbo_BLAKE2B, Siblings: proofs[1], KeyType: models.ProofArbo_ADDRESS, - }}}, + }, + }}, ProcessId: pid, VotePackage: vp, } diff --git a/vochain/indexer/process.go b/vochain/indexer/process.go index d9e36c613..d0f2b2865 100644 --- a/vochain/indexer/process.go +++ b/vochain/indexer/process.go @@ -48,7 +48,8 @@ func (idx *Indexer) ProcessInfo(pid []byte) (*indexertypes.Process, error) { // declared as zero-values will be ignored. SearchTerm is a partial or full PID. // Status is one of READY, CANCELED, ENDED, PAUSED, RESULTS func (idx *Indexer) ProcessList(entityID []byte, from, max int, searchTerm string, namespace uint32, - srcNetworkId int32, status string, withResults bool) ([][]byte, error) { + srcNetworkId int32, status string, withResults bool, +) ([][]byte, error) { if from < 0 { return nil, fmt.Errorf("processList: invalid value: from is invalid value %d", from) } diff --git a/vochain/indexer/vote.go b/vochain/indexer/vote.go index 4b0412dd9..df415aed0 100644 --- a/vochain/indexer/vote.go +++ b/vochain/indexer/vote.go @@ -60,7 +60,8 @@ func (idx *Indexer) GetEnvelope(nullifier []byte) (*indexertypes.EnvelopePackage // GetEnvelopes retrieves all envelope metadata for a ProcessId. // Returns ErrVoteNotFound if the envelope reference is not found. func (idx *Indexer) GetEnvelopes(processId []byte, max, from int, - searchTerm string) ([]*indexertypes.EnvelopeMetadata, error) { + searchTerm string, +) ([]*indexertypes.EnvelopeMetadata, error) { if from < 0 { return nil, fmt.Errorf("GetEnvelopes: invalid value: from is invalid value %d", from) } @@ -94,7 +95,6 @@ func (idx *Indexer) GetEnvelopes(processId []byte, max, from int, envelopes = append(envelopes, envelopeMetadata) } return envelopes, nil - } // CountTotalVotes returns the total number of envelopes. diff --git a/vochain/offchaindatahandler/offchaindatahandler.go b/vochain/offchaindatahandler/offchaindatahandler.go index a21e85f54..b709ef698 100644 --- a/vochain/offchaindatahandler/offchaindatahandler.go +++ b/vochain/offchaindatahandler/offchaindatahandler.go @@ -52,7 +52,8 @@ type OffChainDataHandler struct { // NewOffChainDataHandler creates a new instance of the off chain data downloader daemon. // It will subscribe to Vochain events and perform data import. func NewOffChainDataHandler(v *vochain.BaseApplication, d *downloader.Downloader, - c *censusdb.CensusDB, importOnlyNew bool) *OffChainDataHandler { + c *censusdb.CensusDB, importOnlyNew bool, +) *OffChainDataHandler { od := OffChainDataHandler{ vochain: v, census: c, @@ -140,7 +141,6 @@ func (d *OffChainDataHandler) OnCensusUpdate(pid, censusRoot []byte, censusURI s itemType: itemTypeExternalCensus, }) } - } // OnProcessesStart is triggered when a process starts. Does nothing. diff --git a/vochain/process_test.go b/vochain/process_test.go index a9df232f7..6d0cdc566 100644 --- a/vochain/process_test.go +++ b/vochain/process_test.go @@ -93,7 +93,8 @@ func TestNewProcessCheckTxDeliverTxCommitTransitions(t *testing.T) { } func testNewProcess(t *testing.T, _ []byte, txSender *ethereum.SignKeys, - app *BaseApplication, process *models.Process) error { + app *BaseApplication, process *models.Process, +) error { var stx models.SignedTx var err error @@ -351,7 +352,8 @@ func TestProcessSetCensusCheckTxDeliverTxCommitTransitions(t *testing.T) { } func testSetProcessCensus(t *testing.T, pid []byte, txSender *ethereum.SignKeys, - app *BaseApplication, censusRoot []byte, censusURI *string) error { + app *BaseApplication, censusRoot []byte, censusURI *string, +) error { var stx models.SignedTx var err error @@ -368,7 +370,8 @@ func testSetProcessCensus(t *testing.T, pid []byte, txSender *ethereum.SignKeys, CensusURI: censusURI, } if stx.Tx, err = proto.Marshal(&models.Tx{ - Payload: &models.Tx_SetProcess{SetProcess: tx}}, + Payload: &models.Tx_SetProcess{SetProcess: tx}, + }, ); err != nil { return fmt.Errorf("cannot mashal tx %w", err) } @@ -396,7 +399,8 @@ func TestCount(t *testing.T) { // the application will have the accounts of the keys already initialized, as well as // the burn account and all tx costs set to txCostNumber func createTestBaseApplicationAndAccounts(t *testing.T, - txCostNumber uint64) (*BaseApplication, []*ethereum.SignKeys) { + txCostNumber uint64, +) (*BaseApplication, []*ethereum.SignKeys) { app := TestBaseApplication(t) keys := make([]*ethereum.SignKeys, 0) for i := 0; i < 4; i++ { @@ -430,7 +434,6 @@ func createTestBaseApplicationAndAccounts(t *testing.T, // set tx costs for _, cost := range genesis.TxCostNameToTxTypeMap { qt.Assert(t, app.State.SetTxBaseCost(cost, txCostNumber), qt.IsNil) - } testCommitState(t, app) return app, keys diff --git a/vochain/processid/process_id.go b/vochain/processid/process_id.go index 18d6bef06..71edaf57c 100644 --- a/vochain/processid/process_id.go +++ b/vochain/processid/process_id.go @@ -98,7 +98,6 @@ func (p *ProcessID) Unmarshal(pid []byte) error { func (p *ProcessID) String() string { return fmt.Sprintf("[chID:%s/addr:%s/co:%d/et:%d/nc:%d]", p.chainID, p.organizationAddr.Hex(), p.censusOrigin, p.envType, p.nonce) - } // SetChainID sets the process blockchain identifier diff --git a/vochain/processid/process_id_test.go b/vochain/processid/process_id_test.go index 0372e04ec..810704e61 100644 --- a/vochain/processid/process_id_test.go +++ b/vochain/processid/process_id_test.go @@ -9,8 +9,10 @@ import ( "go.vocdoni.io/proto/build/go/models" ) -const test_vbAddr = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045" -const test_chID = "vocdoni-bizono" +const ( + test_vbAddr = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045" + test_chID = "vocdoni-bizono" +) func TestProcessID(t *testing.T) { pid := ProcessID{} diff --git a/vochain/proof_erc20_test.go b/vochain/proof_erc20_test.go index 72af3d1ed..2a2b85818 100644 --- a/vochain/proof_erc20_test.go +++ b/vochain/proof_erc20_test.go @@ -64,7 +64,8 @@ func TestEthProof(t *testing.T) { } func testEthSendVotes(t *testing.T, s testStorageProof, - pid []byte, vp []byte, app *BaseApplication, expectedResult bool) { + pid []byte, vp []byte, app *BaseApplication, expectedResult bool, +) { cktx := new(cometabcitypes.CheckTxRequest) var cktxresp *cometabcitypes.CheckTxResponse var stx models.SignedTx diff --git a/vochain/proof_minime_test.go b/vochain/proof_minime_test.go index 7f8198363..761eec76b 100644 --- a/vochain/proof_minime_test.go +++ b/vochain/proof_minime_test.go @@ -85,7 +85,8 @@ func storageProofToModel(s *ethstorageproof.StorageResult) *models.ProofEthereum } func testMinimeSendVotes(t *testing.T, s ethstorageproof.StorageProof, addr common.Address, - pid []byte, vp []byte, app *BaseApplication, expectedResult bool) { + pid []byte, vp []byte, app *BaseApplication, expectedResult bool, +) { cktx := new(cometabcitypes.CheckTxRequest) var cktxresp *cometabcitypes.CheckTxResponse var stx models.SignedTx diff --git a/vochain/proof_test.go b/vochain/proof_test.go index 7f35fef40..85d57a792 100644 --- a/vochain/proof_test.go +++ b/vochain/proof_test.go @@ -195,7 +195,8 @@ func TestCSPproof(t *testing.T) { } func testCSPsendVotes(t *testing.T, pid []byte, vp []byte, signer *ethereum.SignKeys, - proof *models.ProofCA, app *BaseApplication, expectedResult bool) { + proof *models.ProofCA, app *BaseApplication, expectedResult bool, +) { cktx := new(cometabcitypes.CheckTxRequest) var cktxresp *cometabcitypes.CheckTxResponse var stx models.SignedTx diff --git a/vochain/proposal_test.go b/vochain/proposal_test.go index a17ad9edf..bf23ab04a 100644 --- a/vochain/proposal_test.go +++ b/vochain/proposal_test.go @@ -38,7 +38,8 @@ func TestTransactionsSorted(t *testing.T) { From: key.Address().Bytes(), To: keys[(i+1)%50].Address().Bytes(), Value: 1, - }}} + }}, + } txBytes, err := proto.Marshal(&tx) qt.Assert(err, quicktest.IsNil) @@ -62,7 +63,8 @@ func TestTransactionsSorted(t *testing.T) { From: key.Address().Bytes(), To: keys[(i+1)%50].Address().Bytes(), Value: 1, - }}} + }}, + } txBytes, err := proto.Marshal(&tx) qt.Assert(err, quicktest.IsNil) diff --git a/vochain/start.go b/vochain/start.go index a6528da0a..38fd4365a 100644 --- a/vochain/start.go +++ b/vochain/start.go @@ -112,15 +112,16 @@ func NewTenderLogger(artifact string, logLevel string) *TenderLogger { // newTendermint creates a new tendermint node attached to the given ABCI app func newTendermint(app *BaseApplication, - localConfig *config.VochainCfg, genesis []byte) (*cometnode.Node, error) { + localConfig *config.VochainCfg, genesis []byte, +) (*cometnode.Node, error) { var err error tconfig := cometconfig.DefaultConfig() tconfig.SetRoot(localConfig.DataDir) - if err := os.MkdirAll(filepath.Join(localConfig.DataDir, "config"), 0750); err != nil { + if err := os.MkdirAll(filepath.Join(localConfig.DataDir, "config"), 0o750); err != nil { log.Fatal(err) } - if err := os.MkdirAll(filepath.Join(localConfig.DataDir, "data"), 0750); err != nil { + if err := os.MkdirAll(filepath.Join(localConfig.DataDir, "data"), 0o750); err != nil { log.Fatal(err) } @@ -337,7 +338,6 @@ func newTendermint(app *BaseApplication, cometnode.DefaultMetricsProvider(tconfig.Instrumentation), logger, ) - if err != nil { return nil, fmt.Errorf("failed to create new Tendermint node: %w", err) } diff --git a/vochain/state/account.go b/vochain/state/account.go index c09c45371..3c733a3c3 100644 --- a/vochain/state/account.go +++ b/vochain/state/account.go @@ -276,7 +276,8 @@ func (v *State) BurnTxCostIncrementNonce(accountAddress common.Address, txType m // SetAccountDelegate sets a set of delegates for a given account func (v *State) SetAccountDelegate(accountAddr common.Address, delegateAddrs [][]byte, - txType models.TxType) error { + txType models.TxType, +) error { acc, err := v.GetAccount(accountAddr, false) if err != nil { return err diff --git a/vochain/state/electionprice/electionprice_test.go b/vochain/state/electionprice/electionprice_test.go index b1bccdd4a..3d3659e8b 100644 --- a/vochain/state/electionprice/electionprice_test.go +++ b/vochain/state/electionprice/electionprice_test.go @@ -136,10 +136,14 @@ func TestCalculatorPriceTable(_ *testing.T) { c.SetBasePrice(10) hour := uint32(340) - maxCensusSizes := []uint64{100, 200, 500, 1000, 1500, 2000, 2500, 3000, 5000, 10000, 20000, - 50000, 100000, 200000, 500000, 800000, 1000000} - electionDurations := []uint32{1 * hour, 12 * hour, 24 * hour, 24 * hour * 2, 24 * hour * 5, - 24 * hour * 7, 24 * hour * 15} + maxCensusSizes := []uint64{ + 100, 200, 500, 1000, 1500, 2000, 2500, 3000, 5000, 10000, 20000, + 50000, 100000, 200000, 500000, 800000, 1000000, + } + electionDurations := []uint32{ + 1 * hour, 12 * hour, 24 * hour, 24 * hour * 2, 24 * hour * 5, + 24 * hour * 7, 24 * hour * 15, + } encryptedVotes := true anonymousVotes := true maxVoteOverwrite := uint32(0) diff --git a/vochain/state/process.go b/vochain/state/process.go index 46015a4f1..9034619eb 100644 --- a/vochain/state/process.go +++ b/vochain/state/process.go @@ -15,9 +15,7 @@ import ( "google.golang.org/protobuf/proto" ) -var ( - emptyVotesRoot = make([]byte, StateChildTreeCfg(ChildTreeVotes).HashFunc().Len()) -) +var emptyVotesRoot = make([]byte, StateChildTreeCfg(ChildTreeVotes).HashFunc().Len()) // AddProcess adds a new process to the vochain. Adding a process with a // ProcessId that already exists will return an error. diff --git a/vochain/state/state_test.go b/vochain/state/state_test.go index e95157b01..b0dc6c06e 100644 --- a/vochain/state/state_test.go +++ b/vochain/state/state_test.go @@ -174,7 +174,6 @@ func TestBalanceTransfer(t *testing.T) { b2, err = s.GetAccount(addr2.Address(), true) qt.Assert(t, err, qt.IsNil) qt.Assert(t, b2.Balance, qt.Equals, uint64(5)) - } type Listener struct { @@ -197,6 +196,7 @@ func (*Listener) OnSpendTokens(_ []byte, _ models.TxType, _ uint64, _ string) func (l *Listener) OnProcessesStart(pids [][]byte) { l.processStart = append(l.processStart, pids) } + func (*Listener) Commit(_ uint32) (err error) { return nil } @@ -362,5 +362,4 @@ func TestNoState(t *testing.T) { // check that the value is not in the nostate _, err = ns.Get([]byte("foo")) qt.Assert(t, err, qt.Equals, db.ErrKeyNotFound) - } diff --git a/vochain/state/trees.go b/vochain/state/trees.go index ce83dee78..a6435e211 100644 --- a/vochain/state/trees.go +++ b/vochain/state/trees.go @@ -33,9 +33,7 @@ const ( ChildTreeVotes = "Votes" ) -var ( - ErrProcessChildLeafRootUnknown = fmt.Errorf("process child leaf root is unknown") -) +var ErrProcessChildLeafRootUnknown = fmt.Errorf("process child leaf root is unknown") // treeTxWithMutex is a wrapper over TreeTx with a mutex for convenient // RWLocking. diff --git a/vochain/state/votes.go b/vochain/state/votes.go index f1cc10f5c..4b64bf634 100644 --- a/vochain/state/votes.go +++ b/vochain/state/votes.go @@ -21,10 +21,8 @@ import ( "google.golang.org/protobuf/proto" ) -var ( - // keys; not constants because of []byte - voteCountKey = []byte("voteCount") -) +// keys; not constants because of []byte +var voteCountKey = []byte("voteCount") // Vote represents a vote in the Vochain state. type Vote struct { @@ -297,7 +295,8 @@ func (s *State) VoteExists(processID, nullifier []byte, committed bool) (bool, e // data from the currently open StateDB transaction. // When committed is true, the operation is executed on the last committed version. func (s *State) iterateVotes(processID []byte, - fn func(vid []byte, sdbVote *models.StateDBVote) bool, committed bool) error { + fn func(vid []byte, sdbVote *models.StateDBVote) bool, committed bool, +) error { if !committed { s.tx.RLock() defer s.tx.RUnlock() @@ -352,7 +351,8 @@ func (s *State) CountVotes(processID []byte, committed bool) (uint64, error) { // data from the currently open StateDB transaction. // When committed is true, the operation is executed on the last committed version. func (s *State) EnvelopeList(processID []byte, from, listSize int, - committed bool) (nullifiers [][]byte) { + committed bool, +) (nullifiers [][]byte) { idx := 0 s.iterateVotes(processID, func(vid []byte, sdbVote *models.StateDBVote) bool { if idx >= from+listSize { diff --git a/vochain/transaction_zk_test.go b/vochain/transaction_zk_test.go index 7b3cb34f6..73d3839ab 100644 --- a/vochain/transaction_zk_test.go +++ b/vochain/transaction_zk_test.go @@ -119,7 +119,8 @@ func TestVoteCheckZkSNARK(t *testing.T) { } func testBuildSignedRegisterSIKTx(t *testing.T, account *ethereum.SignKeys, pid, - proof, availableWeight []byte, chainID string) *vochaintx.Tx { + proof, availableWeight []byte, chainID string, +) *vochaintx.Tx { c := qt.New(t) sik, err := account.AccountSIK(nil) diff --git a/vochain/vote_test.go b/vochain/vote_test.go index 9943ffce2..0af7ba480 100644 --- a/vochain/vote_test.go +++ b/vochain/vote_test.go @@ -23,8 +23,10 @@ import ( // leaf value). It returns the keys, the census root and the proofs for each key. func testCreateKeysAndBuildWeightedZkCensus(t *testing.T, size int, weight *big.Int) ([]*ethereum.SignKeys, []byte, [][]byte) { db := metadb.NewTest(t) - tr, err := censustree.New(censustree.Options{Name: "testcensus", ParentDB: db, - MaxLevels: censustree.DefaultMaxLevels, CensusType: models.Census_ARBO_POSEIDON}) + tr, err := censustree.New(censustree.Options{ + Name: "testcensus", ParentDB: db, + MaxLevels: censustree.DefaultMaxLevels, CensusType: models.Census_ARBO_POSEIDON, + }) if err != nil { t.Fatal(err) } @@ -55,8 +57,10 @@ func testCreateKeysAndBuildWeightedZkCensus(t *testing.T, size int, weight *big. // It returns the keys, the census root and the proofs for each key. func testCreateKeysAndBuildCensus(t *testing.T, size int) ([]*ethereum.SignKeys, []byte, [][]byte) { db := metadb.NewTest(t) - tr, err := censustree.New(censustree.Options{Name: "testcensus", ParentDB: db, - MaxLevels: censustree.DefaultMaxLevels, CensusType: models.Census_ARBO_BLAKE2B}) + tr, err := censustree.New(censustree.Options{ + Name: "testcensus", ParentDB: db, + MaxLevels: censustree.DefaultMaxLevels, CensusType: models.Census_ARBO_BLAKE2B, + }) if err != nil { t.Fatal(err) } @@ -84,7 +88,8 @@ func testCreateKeysAndBuildCensus(t *testing.T, size int) ([]*ethereum.SignKeys, } func testBuildSignedVote(t *testing.T, electionID []byte, key *ethereum.SignKeys, - proof []byte, votePackage []int, chainID string) *models.SignedTx { + proof []byte, votePackage []int, chainID string, +) *models.SignedTx { var stx models.SignedTx var err error vp, err := json.Marshal(votePackage)