helpers

package
v0.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 4, 2026 License: AGPL-3.0 Imports: 47 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// first account private key created by anvil with default mnemonic
	LocalAccountPrivKey   = "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
	LocalCSPSeed          = "1f1e0cd27b4ecd1b71b6333790864ace2870222c"
	WorkerSeed            = "test-seed"
	WorkerTokenExpiration = 24 * time.Hour
	WorkerTimeout         = time.Second * 5
	// envarionment variable names
	DeployerServerPortEnvVarName      = "DEPLOYER_SERVER"                        // environment variable name for deployer server port
	ContractsBranchNameEnvVarName     = "SEQUENCER_CONTRACTS_BRANCH"             // environment variable name for z-contracts branch
	ContractsCommitHashEnvVarName     = "SEQUENCER_CONTRACTS_COMMIT"             // environment variable name for z-contracts commit hash
	PrivKeyEnvVarName                 = "SEQUENCER_PRIV_KEY"                     // environment variable name for private key
	RPCUrlEnvVarName                  = "SEQUENCER_RPC_URL"                      // environment variable name for RPC URL
	AnvilPortEnvVarName               = "ANVIL_PORT_RPC_HTTP"                    // environment variable name for Anvil port
	ProcessRegistryEnvVarName         = "SEQUENCER_PROCESS_REGISTRY"             // environment variable name for process registry
	ResultsVerifierEnvVarName         = "SEQUENCER_RESULTS_ZK_VERIFIER"          // environment variable name for results zk verifier
	StateTransitionVerifierEnvVarName = "SEQUENCER_STATE_TRANSITION_ZK_VERIFIER" // environment variable name for state transition zk verifier
	CSPCensusEnvVarName               = "CSP_CENSUS"                             // environment variable name to select between csp or merkle tree census (by default merkle tree)

	DefaultBatchTimeWindow = 45 * time.Second // default batch time window for sequencer
)

Variables

View Source
var (
	DefaultAPIPort     = util.RandomInt(40000, 60000)
	DefaultCensus3Port = util.RandomInt(40000, 60000)
	DefaultCensus3URL  = fmt.Sprintf("http://localhost:%d", DefaultCensus3Port)
)

Functions

func CalculateExpectedResults added in v0.0.2

func CalculateExpectedResults(fieldValuesPerVoter [][]*types.BigInt) []*types.BigInt

func CreateCensusProof

func CreateCensusProof(origin types.CensusOrigin, pid types.ProcessID, address common.Address) (types.CensusProof, error)

func CurrentCensusOrigin

func CurrentCensusOrigin() types.CensusOrigin

func EnsureVotesStatus

func EnsureVotesStatus(cli *client.HTTPclient, pid types.ProcessID, voteIDs []types.VoteID, expectedStatus string) (bool, []types.VoteID, error)

func FetchProcessOnChainOverwrittenVotesCount

func FetchProcessOnChainOverwrittenVotesCount(contracts *web3.Contracts, pid types.ProcessID) (int, error)

func FetchProcessVotersCountOnChain

func FetchProcessVotersCountOnChain(contracts *web3.Contracts, pid types.ProcessID) (int, error)

func FetchResultsOnChain

func FetchResultsOnChain(contracts *web3.Contracts, pid types.ProcessID) ([]*types.BigInt, error)

func FinishProcessOnChain

func FinishProcessOnChain(contracts *web3.Contracts, pid types.ProcessID) error

func HasAddressAlreadyVoted added in v0.0.2

func HasAddressAlreadyVoted(cli *client.HTTPclient, pid types.ProcessID, address common.Address) (bool, error)

func IsCSPCensus

func IsCSPCensus() bool

func IsDebugTest

func IsDebugTest() bool

func MaxTestTimeout

func MaxTestTimeout(t *testing.T) time.Duration

func NewCensusWithRandomVoters

func NewCensusWithRandomVoters(ctx context.Context, origin types.CensusOrigin, nVoters int) ([]byte, string, []*ethereum.Signer, error)

func NewCensusWithVoters

func NewCensusWithVoters(ctx context.Context, origin types.CensusOrigin, signers ...*ethereum.Signer) ([]byte, string, []*ethereum.Signer, error)

func NewProcess

func NewProcess(
	contracts *web3.Contracts,
	cli *client.HTTPclient,
) (types.ProcessID, *types.EncryptionKey, error)

func NewProcessOnChain

func NewProcessOnChain(
	contracts *web3.Contracts,
	censusOrigin types.CensusOrigin,
	censusURI string,
	censusRoot []byte,
	ballotMode spec.BallotMode,
	encryptionKey *types.EncryptionKey,
	numVoters int,
	duration ...time.Duration,
) (types.ProcessID, error)

func NewVote

func NewVote(pid types.ProcessID, bm spec.BallotMode, encKey *types.EncryptionKey, privKey *ethereum.Signer, k *big.Int, fields []*types.BigInt) (api.Vote, error)

func NewVoteFromNonCensusVoter

func NewVoteFromNonCensusVoter(pid types.ProcessID, bm spec.BallotMode, encKey *types.EncryptionKey) (api.Vote, error)

func NewVoteWithRandomFields

func NewVoteWithRandomFields(pid types.ProcessID, bm spec.BallotMode, encKey *types.EncryptionKey, privKey *ethereum.Signer, k *big.Int) (api.Vote, []*types.BigInt, error)

func UpdateCensusOnChain

func UpdateCensusOnChain(
	contracts *web3.Contracts,
	pid types.ProcessID,
	census types.Census,
) error

func UpdateMaxVotersOnChain

func UpdateMaxVotersOnChain(
	contracts *web3.Contracts,
	pid types.ProcessID,
	numVoters int,
) error

func WaitUntilCondition

func WaitUntilCondition(ctx context.Context, interval time.Duration, condition func() bool) error

Types

type TestServices

type TestServices struct {
	API              *service.APIService
	Census3          *c3service.Service
	Sequencer        *sequencer.Sequencer
	CensusDownloader *service.CensusDownloader
	Storage          *storage.Storage
	Contracts        *web3.Contracts
	HTTPClient       *client.HTTPclient
}

TestServices struct holds all test services

func NewTestServices

func NewTestServices(
	ctx context.Context,
	tempDir string,
	workerSecret string,
	workerTokenExpiration time.Duration,
	workerTimeout time.Duration,
	banRules *workers.WorkerBanRules,
) (*TestServices, func(), error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL