Skip to content

Commit

Permalink
move testing
Browse files Browse the repository at this point in the history
  • Loading branch information
nialexsan committed Nov 6, 2023
1 parent b4f63b5 commit 1e5fb5f
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion docs/build/building-vs-other-chains.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,6 @@ If you’re already familiar with blockchain development, here's a comparison be
- [Flow Playground](https://play.flow.com/) provides basic experimentation on the web
- [Cadence VSCode Extension](https://marketplace.visualstudio.com/items?itemName=onflow.cadence) is strongly suggested to install for local development
- [Testing Smart Contracts](https://ethereum.org/en/developers/docs/smart-contracts/testing/)
- [Cadence testing framework](../cadence/testing-framework.mdx) enables native tests in Cadence.
- [Cadence testing framework](./guides/smart-contracts/testing/testing-framework.md) enables native tests in Cadence.
- [overflow](https://github.com/bjartek/overflow) for testing in Go.
- [js-testing](https://github.com/onflow/flow-js-testing) for testing in JS.
6 changes: 3 additions & 3 deletions docs/build/getting-started/explore-more.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Below are some additional tutorials to help you get started with Flow:
{
type: 'link',
label: 'Flow App Quickstart',
href: '/guides/flow-app-quickstart',
href: '/build/guides/flow-app-quickstart',
description: 'Simple walkthrough building a web3 app using the Flow Client Library (FCL)',
customProps: {
icon: <FontAwesomeIcon icon={faWindowMaximize} className="h-16" />,
Expand All @@ -30,7 +30,7 @@ Below are some additional tutorials to help you get started with Flow:
{
type: 'link',
label: 'Fungible Token Guide',
href: '/guides/fungible-token',
href: '/build/guides/fungible-token',
description: 'Steps to create, deploy, mint, and transfer fungible tokens on Flow',
customProps: {
icon: <FontAwesomeIcon icon={faCoins} className="h-16" />,
Expand Down Expand Up @@ -58,7 +58,7 @@ Below are some additional tutorials to help you get started with Flow:
{
type: 'link',
label: 'Walkthrough Guides',
href: '/guides/flow-app-quickstart',
href: '/build/guides/flow-app-quickstart',
description: 'Longer form guides to help you get started with Flow',
customProps: {
icon: <FontAwesomeIcon icon={faBook} className="h-16" />,
Expand Down
2 changes: 1 addition & 1 deletion docs/build/guides/smart-contracts/deploying.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Anyone can deploy and update contracts on mainnet. Audits are encouraged but not

### Create and deploy a mainnet project
The tool of choice is Flow CLI, there are quickstarts and guides that use Flow CLI, [Getting Started](../../getting-started/quickstarts/flow-cli)
- It is highly encouraged to test your contracts, transactions and scripts on Testnet, have strong smart contract test coverage and follow any additional guidelines set out here: [Smart Contract Testing Guidelines](./testing).
- It is highly encouraged to test your contracts, transactions and scripts on Testnet, have strong smart contract test coverage and follow any additional guidelines set out here: [Smart Contract Testing Guidelines](./testing/testing.md).
- Follow the Flow CLI instructions to [Create a Project](../../../tools/flow-cli/index.md). You have the Flow CLI installed and ran `flow init` or `flow setup` in your project folder and generating a `flow.json` file
- Mainnet account: You completed the mainnet account setup, (see above) and have your key pair and mainnet address ready.
- [Deploy your project](../../../tools/flow-cli/deployment/deploy-project-contracts.md), notice that your account now has contracts deployed on mainnet.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ Testing is an essential part of smart contract development to ensure the correct

## Install Flow CLI

The [Flow CLI](../../tools/flow-cli/index.md) is the primary tool for developing, testing, and deploying smart contracts to the Flow network.
The [Flow CLI](../../../../tools/flow-cli/index.md) is the primary tool for developing, testing, and deploying smart contracts to the Flow network.

If you haven't installed the Flow CLI yet and have [homebrew](https://brew.sh/) installed, simply run `brew install flow-cli`. Alternatively, refer to the Flow CLI [installation instructions](../../tools/flow-cli/install.md).
If you haven't installed the Flow CLI yet and have [homebrew](https://brew.sh/) installed, simply run `brew install flow-cli`. Alternatively, refer to the Flow CLI [installation instructions](../../../../tools/flow-cli/install.md).

## Create a new project

In your preferred code editor, create a new directory for your project and navigate to it in the terminal. Then
initialize a new Flow project by running the command `flow init`. This will create a `flow.json` file that contains the [project configuration](../../tools/flow-cli/flow.json/configuration.md).
initialize a new Flow project by running the command `flow init`. This will create a `flow.json` file that contains the [project configuration](../../../../tools/flow-cli/flow.json/configuration.md).

```bash
mkdir test-cadence
Expand Down Expand Up @@ -95,17 +95,17 @@ The Cadence testing framework provides various features and techniques for writi

- [**Code Coverage**](https://github.com/m-Peter/flow-code-coverage): You can use the `--cover` flag with the `flow test` command to view code coverage results when running your tests. This allows you to identify areas of your code that are not adequately covered by your test inputs;
- **Test Fixtures**: Test fixtures are reusable components that help you set up the initial state for your test cases. You can create test fixtures in Cadence by defining resource types and using them in your test functions;
- [**Assertions**](../../cadence/testing-framework.mdx#assertions): The testing framework provides built-in assertion functions, such as `assertEqual`, `beNil`, `beEmpty`, `contain`, to help you verify the expected behavior of your smart contracts;
- [**Assertions**](./testing-framework.md#assertions): The testing framework provides built-in assertion functions, such as `assertEqual`, `beNil`, `beEmpty`, `contain`, to help you verify the expected behavior of your smart contracts;
- **Test Suites**: You can organize your test cases into test suites to improve the readability and maintainability of your test code. Test suites allow you to group related test cases and set up common test fixtures for all the tests in the suite.
- [**Integration tests**](https://github.com/bjartek/overflow): You can use [Overflow tool](https://github.com/bjartek/overflow) to run integration tests against either an local emulator, testnet, mainnet or an in memory instance of the flow-emulator.

By leveraging these advanced testing techniques, you can write more robust and reliable smart contracts in Cadence. In this example, we set up a basic testing environment, wrote a simple smart contract in Cadence, and created a test case to verify its functionality. We then used the Flow CLI to run the test case and confirm that the smart contract is working correctly.

This is a basic example, and there are many more advanced features and techniques you can explore when working with the Cadence Testing Framework.

For more in-depth tutorials and documentation, refer to the official [Cadence language documentation](https://cadencelang.org/) and the [Flow CLI documentation](../../tools/flow-cli/index.md).
For more in-depth tutorials and documentation, refer to the official [Cadence language documentation](https://cadencelang.org/) and the [Flow CLI documentation](../../../../tools/flow-cli/index.md).

## References

- [Reference documentation for Cadence testing](../../cadence/testing-framework.mdx)
- [Reference documentation for Cadence testing](./testing-framework.md)
- https://github.com/bjartek/overflow
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The Cadence testing framework provides a convenient way to write tests for Caden
This functionality is provided by the built-in `Test` contract.

<Callout type="info">
The testing framework can only be used off-chain, e.g. by using the [Flow CLI](../tools/flow-cli).
The testing framework can only be used off-chain, e.g. by using the [Flow CLI](../../../../tools/flow-cli/index.md).
</Callout>

Tests must be written in the form of a Cadence script.
Expand Down Expand Up @@ -759,7 +759,7 @@ access(all) struct interface BlockchainBackend {
### Creating a blockchain

A new blockchain instance can be created using the `Test.newEmulatorBlockchain` method.
It returns a `Blockchain` which is backed by a new [Flow Emulator](../tools/emulator) instance.
It returns a `Blockchain` which is backed by a new [Flow Emulator](../../../../tools/emulator/index.md) instance.

```cadence
import Test
Expand Down Expand Up @@ -1009,7 +1009,7 @@ An `Error` is returned if the contract deployment fails. Otherwise, a `nil` is r
### Configuring import addresses

A common pattern in Cadence projects is to define the imports as file locations and specify the addresses
corresponding to each network in the [Flow CLI configuration file](../tools/flow-cli/flow.json/configuration.md#contracts).
corresponding to each network in the [Flow CLI configuration file](../../../../tools/flow-cli/flow.json/configuration.md#contracts).
When writing tests for such a project, it may also require to specify the addresses to be used during the tests as well.
However, during tests, since accounts are created dynamically and the addresses are also generated dynamically,
specifying the addresses statically in a configuration file is not an option.
Expand All @@ -1034,7 +1034,7 @@ access(all) struct Configuration {

<Callout type="info">
The `Blockchain.useConfiguration` is a run-time alternative for
[statically defining contract addresses in the flow.json config file](../tools/flow-cli/flow.json/configuration.md#advanced-format).
[statically defining contract addresses in the flow.json config file](../../../../tools/flow-cli/flow.json/configuration.md#advanced-format).
</Callout>

The configurations can be specified during the test setup as a best-practice.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Testing is an essential part of the development workflow and code coverage is an
Good test coverage is vital for assuring code quality.

<Callout type="success">
Leverage [Flow emulator](../../../tools/emulator/index.md) to automate test runs. Test on Flow testnet. Include unit tests; to exercise each feature, and integration tests; to exercise the behavior of different parts of the project as a whole.
Leverage [Flow emulator](../../../../tools/emulator/index.md) to automate test runs. Test on Flow testnet. Include unit tests; to exercise each feature, and integration tests; to exercise the behavior of different parts of the project as a whole.
The emulator can also provide [code coverage](https://github.com/m-Peter/flow-code-coverage#for-emulator) insights.
</Callout>

Expand Down Expand Up @@ -39,20 +39,20 @@ In all three cases, the test code will need to deploy the contracts, configure a
### Cadence tests

Cadence comes with built-in support for code coverage, as well as a native testing framework which allows developers to write their tests using Cadence.
This framework is bundled with the [Flow CLI](../../../tools/flow-cli/index.md) tool, which includes a dedicated command for running tests (`flow test`).
This framework is bundled with the [Flow CLI](../../../../tools/flow-cli/index.md) tool, which includes a dedicated command for running tests (`flow test`).

You can find examples of Cadence tests in the following projects: [hybrid-custody](https://github.com/onflow/hybrid-custody/tree/main/test), [flow-nft](https://github.com/onflow/flow-nft/tree/master/tests), [flow-ft](https://github.com/onflow/flow-ft/tree/master/tests).
Visit the [documentation](../../../cadence/testing-framework.mdx) to view all the available features.
Visit the [documentation](./testing-framework.md) to view all the available features.

The [Hybrid Custody](https://github.com/onflow/hybrid-custody#readme) project is a prime example which utilizes both the Cadence testing framework and code coverage in its CI.

![Hybrid Custody CI](hybrid-custody-ci.png)
![Hybrid Custody CI](../hybrid-custody-ci.png)

There is also a [repository](https://github.com/m-Peter/flow-code-coverage#readme) which contains some sample contracts and their tests.

![Automated CI Coverage Report](codecov-in-pr.png)
![Automated CI Coverage Report](../codecov-in-pr.png)

![Coverage Report Visualization](codecov-insights.png)
![Coverage Report Visualization](../codecov-insights.png)

<Callout type="info">
The Cadence testing framework utilizes the emulator under the hood.
Expand Down Expand Up @@ -87,5 +87,5 @@ Tests should also be runnable in automated environments (CI). You can use the [J
Once you deployed your application to the testnet, you should record how your application handles non-trivial amounts of traffic to ensure there are no issues.

<Callout type="success">
Get familiar with the [Cadence anti-patterns](../../../cadence/anti-patterns.md) to avoid avoid problematic or unintended behavior.
Get familiar with the [Cadence anti-patterns](../../../../cadence/anti-patterns.md) to avoid avoid problematic or unintended behavior.
</Callout>
2 changes: 1 addition & 1 deletion docs/tools/flow-cli/tests/run-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Test results: "test_script.cdc"

```

To learn more about writing tests in Cadence, take a look at the [Cadence testing framework](../../../cadence/testing-framework.mdx).
To learn more about writing tests in Cadence, take a look at the [Cadence testing framework](../../../build/guides/smart-contracts/testing/testing-framework.md).

## Flags

Expand Down
2 changes: 1 addition & 1 deletion docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ const config = {
label: 'FCL',
},
{
to: '/build/getting-started/testing',
to: '/build/guides/smart-contracts/testing/intro',
label: 'Testing',
},
{
Expand Down
2 changes: 1 addition & 1 deletion src/data/pages/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const homepageStartProjectData: HomepageStartItemProps[] = [
{
title: 'Developer Guides',
text: 'Create your first dApp in just a few minutes',
link: '/guides/flow-app-quickstart',
link: '/build/guides/flow-app-quickstart',
icon: 'quickstart',
},
{
Expand Down

0 comments on commit 1e5fb5f

Please sign in to comment.