Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Setup tests #129

Draft
wants to merge 20 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,6 @@ jobs:

- name: Build All Examples
run: forc build --path ${{ matrix.project }} --release

- name: Run Cargo Tests
run: cargo test --manifest-path ${{ matrix.project }}/Cargo.toml
65 changes: 65 additions & 0 deletions .github/workflows/nightly.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Standards Nightly Tests

on:
schedule:
- cron: '0 0 * * *' # Run every day at midnight UTC
pull_request:

env:
CARGO_TERM_COLOR: always
REGISTRY: ghcr.io

jobs:
examples-nightly-tests:
runs-on: ubuntu-latest

strategy:
matrix:
project:
[
"examples/src3-mint-burn",
"examples/src5-ownership",
"examples/src6-vault",
"examples/src7-metadata",
"examples/src11-security-information",
"examples/src12-contract-factory",
"examples/src14-simple-proxy",
"examples/src20-native-asset",
]

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly
components: rustfmt

- name: Init cache
uses: Swatinem/rust-cache@v2

- name: Install a modern linker (mold)
uses: rui314/setup-mold@v1

- name: Force Rust to use mold globally for compilation
run: |
touch ~/.cargo/config.toml
echo "[target.x86_64-unknown-linux-gnu]" > ~/.cargo/config.toml
echo 'linker = "clang"' >> ~/.cargo/config.toml
echo 'rustflags = ["-C", "link-arg=-fuse-ld=/usr/local/bin/mold"]' >> ~/.cargo/config.toml

- name: Install Fuel toolchain
uses: FuelLabs/[email protected]
with:
toolchain: nightly

- name: Check Sway Formatting Examples
run: forc fmt --path ${{ matrix.project }} --check

- name: Build All Examples
run: forc build --path ${{ matrix.project }} --release

- name: Run Cargo Tests
run: cargo test --manifest-path ${{ matrix.project }}/Cargo.toml
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Generated by Cargo
# will have compiled files and executables
/target/
target

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Expand Down
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ Description of the upcoming release here.

### Added

- Something new here 1
- Something new here 2
- [#129](https://github.com/FuelLabs/sway-standards/pull/129) Adds setup for testing this repository.

### Changed

Expand Down
4 changes: 0 additions & 4 deletions Cargo.toml

This file was deleted.

13 changes: 13 additions & 0 deletions examples/src11-security-information/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "src11_security_information"
version = "0.6.1"
edition = "2021"

[[test]]
harness = true
name = "src11_security_information_tests"
path = "tests/harness.rs"

[dependencies]
fuels = { version = "0.66.1" }
tokio = { version = "1.12", features = ["rt", "macros"] }
Empty file.
13 changes: 13 additions & 0 deletions examples/src12-contract-factory/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "src12_contract_factory"
version = "0.6.1"
edition = "2021"

[[test]]
harness = true
name = "src12_contract_factory_tests"
path = "tests/harness.rs"

[dependencies]
fuels = { version = "0.66.1" }
tokio = { version = "1.12", features = ["rt", "macros"] }
Empty file.
13 changes: 13 additions & 0 deletions examples/src14-simple-proxy/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "src14_simple_proxy"
version = "0.6.1"
edition = "2021"

[[test]]
harness = true
name = "src14_simple_proxy_tests"
path = "tests/harness.rs"

[dependencies]
fuels = { version = "0.66.1" }
tokio = { version = "1.12", features = ["rt", "macros"] }
Empty file.
13 changes: 13 additions & 0 deletions examples/src20-native-asset/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "src20_native_asset"
version = "0.6.1"
edition = "2021"

[[test]]
harness = true
name = "src20_native_asset_tests"
path = "tests/harness.rs"

[dependencies]
fuels = { version = "0.66.1" }
tokio = { version = "1.12", features = ["rt", "macros"] }
Empty file.
13 changes: 13 additions & 0 deletions examples/src3-mint-burn/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "src3_mint_burn"
version = "0.6.1"
edition = "2021"

[[test]]
harness = true
name = "src3_mint_burn_tests"
path = "tests/harness.rs"

[dependencies]
fuels = { version = "0.66.1" }
tokio = { version = "1.12", features = ["rt", "macros"] }
2 changes: 2 additions & 0 deletions examples/src3-mint-burn/tests/harness.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mod multi_asset;
mod single_asset;
47 changes: 47 additions & 0 deletions examples/src3-mint-burn/tests/multi_asset.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
use fuels::{
prelude::{
abigen, launch_custom_provider_and_get_wallets, AssetConfig, Contract, ContractId,
LoadConfiguration, TxPolicies, WalletUnlocked, WalletsConfig,
},
types::AssetId,
};

abigen!(Contract(
name = "MultiAsset",
abi = "./multi_asset/out/release/multi_src3_asset-abi.json"
));

const MULTI_ASSET_CONTRACT_BINARY_PATH: &str = "./multi_asset/out/release/multi_src3_asset.bin";

pub(crate) async fn setup() -> (WalletUnlocked, ContractId, MultiAsset<WalletUnlocked>) {
let number_of_coins = 1;
let coin_amount = 100_000_000;
let number_of_wallets = 1;

let base_asset = AssetConfig {
id: AssetId::zeroed(),
num_coins: number_of_coins,
coin_amount,
};
let assets = vec![base_asset];

let wallet_config = WalletsConfig::new_multiple_assets(number_of_wallets, assets);
let mut wallets = launch_custom_provider_and_get_wallets(wallet_config, None, None)
.await
.unwrap();

let wallet1 = wallets.pop().unwrap();

let id = Contract::load_from(
MULTI_ASSET_CONTRACT_BINARY_PATH,
LoadConfiguration::default(),
)
.unwrap()
.deploy(&wallet1, TxPolicies::default())
.await
.unwrap();

let instance_1 = MultiAsset::new(id.clone(), wallet1.clone());

(wallet1, id.into(), instance_1)
}
87 changes: 87 additions & 0 deletions examples/src3-mint-burn/tests/single_asset.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
use fuels::{
prelude::{
abigen, launch_custom_provider_and_get_wallets, AssetConfig, Contract, ContractId,
LoadConfiguration, TxPolicies, WalletUnlocked, WalletsConfig,
}, programs::calls::CallParameters, types::{transaction_builders::VariableOutputPolicy, AssetId, Bits256},
tx::ContractIdExt,
};

abigen!(Contract(
name = "SingleAsset",
abi = "./single_asset/out/release/single_src3_asset-abi.json"
));

const SINGLE_ASSET_CONTRACT_BINARY_PATH: &str =
"./single_asset/out/release/single_src3_asset.bin";

pub(crate) async fn setup() -> (WalletUnlocked, ContractId, SingleAsset<WalletUnlocked>) {
let number_of_coins = 1;
let coin_amount = 100_000_000;
let number_of_wallets = 1;

let base_asset = AssetConfig {
id: AssetId::zeroed(),
num_coins: number_of_coins,
coin_amount,
};
let assets = vec![base_asset];

let wallet_config = WalletsConfig::new_multiple_assets(number_of_wallets, assets);
let mut wallets = launch_custom_provider_and_get_wallets(wallet_config, None, None)
.await
.unwrap();

let wallet1 = wallets.pop().unwrap();

let id = Contract::load_from(
SINGLE_ASSET_CONTRACT_BINARY_PATH,
LoadConfiguration::default(),
)
.unwrap()
.deploy(&wallet1, TxPolicies::default())
.await
.unwrap();

let instance_1 = SingleAsset::new(id.clone(), wallet1.clone());

(wallet1, id.into(), instance_1)
}

#[tokio::test]
async fn test_mint_single_asset() {
let (wallet1, _id, instance) = setup().await;

let _mint_tx = instance
.methods()
.mint(wallet1.address().into(), Some(Bits256::zeroed()), 100)
.with_variable_output_policy(VariableOutputPolicy::Exactly(1))
.call()
.await
.unwrap();
}

#[tokio::test]
async fn test_burn_single_asset() {
let (wallet1, id, instance) = setup().await;

let _mint_tx = instance
.methods()
.mint(wallet1.address().into(), Some(Bits256::zeroed()), 100)
.with_variable_output_policy(VariableOutputPolicy::Exactly(1))
.call()
.await
.unwrap();

let _burn_tx = instance
.methods()
.burn(Bits256::zeroed(), 100)
.call_params(
CallParameters::default()
.with_asset_id(id.default_asset())
.with_amount(100),
)
.unwrap()
.call()
.await
.unwrap();
}
13 changes: 13 additions & 0 deletions examples/src5-ownership/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "src5_ownership"
version = "0.6.1"
edition = "2021"

[[test]]
harness = true
name = "src5_ownership_tests"
path = "tests/harness.rs"

[dependencies]
fuels = { version = "0.66.1" }
tokio = { version = "1.12", features = ["rt", "macros"] }
Empty file.
13 changes: 13 additions & 0 deletions examples/src6-vault/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "src6_vault"
version = "0.6.1"
edition = "2021"

[[test]]
harness = true
name = "src6_vault_tests"
path = "tests/harness.rs"

[dependencies]
fuels = { version = "0.66.1" }
tokio = { version = "1.12", features = ["rt", "macros"] }
Empty file.
13 changes: 13 additions & 0 deletions examples/src7-metadata/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "src7_metadata"
version = "0.6.1"
edition = "2021"

[[test]]
harness = true
name = "src7_metadata_tests"
path = "tests/harness.rs"

[dependencies]
fuels = { version = "0.66.1" }
tokio = { version = "1.12", features = ["rt", "macros"] }
Empty file.
Loading