Testing workflow
During blockchain application development, a "local" blockchain (generally consisting of a single node) is used to simulate deployment and interaction with smart contracts. When developing an application that leverages NEBRA UPA, a few extra components are required in order to test the end-to-end workflow in this simulation environment:
UPA contracts must be deployed to the target chain, AND
An aggregator must monitor the chain and supply aggregated proofs
The upa tool can be used to run a "development" aggregator, which aggregates all submitted proofs, and the UPA contracts can be deployed in a specific configuration which accepts these aggreagtions.
In this way, the complete UPA pipeline is available on the local development chain, and applications can be fully tested.
NOTE: In contrast to the production deployments, the development aggregator accepts and aggregates invalid proofs. Submission of invalid proofs should be tested against a NEBRA UPA testnet deployment.
Unit testing using the dev-aggregator
dev-aggregatorLaunch a development node
For example, in a separate terminal, run:
yarn hardhat nodeNOTE: Unless otherwise specified, the
upacommand will attempt to connect to an RPC node athttp://localhost:8545. If your development node listens on a different port, use the--rpc-endpointoption, or theRPC_ENDPOINTenv variable (see ./setup.md) to specify the correct endpoint.
Create a deployer account
In order to deploy the UPA contracts and submit aggregated proofs, a keyfile for a funded account is required. A suitable keyfile can be created using the upa tool.
NOTE: This keyfile should only be used on development networks, not on live networks holding tokens of real value.
upa dev ethkeygen --keyfile upa-dev.keyfileThe keyfile can be recorded in a .env file for convenience:
echo KEYFILE=upa-dev.keyfile >> .env
echo KEYFILE_PASSWORD= >> .env(Otherwise, it must be specified in subsequent commands)
NOTE: For development chains, the
upa dev fundcommand can be used to fund the keyfile from a hosted account. (Seeupa dev fund --help)
Deploy a development version of UPA
upa owner deploy \
--verifier "node_modules/@nebrazkp/upa/test/data/test.bin" \
--use-test-configThis creates a upa.instance file in the current directory.
NOTE: The development version of the UPA contracts behave exactly the same as the production versions, except that they accept fake aggregation proofs. All other checks are performed identically. This allows any issues to be caught during local testing.
NOTE: The command above deploys a upa contract with a default test config. This can be customized by providing a
upa_config.jsonfile, and replacing the flag--use-test-configwith--config upa_config.json
Launch a development aggregator
upa dev aggregatorNOTE: By default
dev-aggregatorchecks for aupa.instancefile in the current directory. Therefore, if run from the same directory as deployment above, the instance file does not need to be specified. (See--helpfor how to specify the instance file).
Execute tests
Application tests can then be run against the local node, using upa.instance to initialize a UpaClient.
For example, if unit tests are written to always initialize a UpaClient from a upa.instance, they can be executed, pointing at the local node:
yarn hardhat test --network localhostSimilarly any CLI or browser client code can now be exercised against the local node.
Last updated
Was this helpful?

