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

feat: add forc tests to create fuels #3585

Draft
wants to merge 3 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
19 changes: 19 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,25 @@ jobs:
env:
PUBLISHED_NPM_TAG: next

forc:
runs-on: ubuntu-latest
timeout-minutes: 25
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Test Setup
uses: ./.github/actions/test-setup

- name: Setup forc and fuel-core paths
shell: bash
run: |
echo "$PWD/internal/forc/forc-binaries" >> $GITHUB_PATH
echo "$PWD/internal/fuel-core/fuel-core-binaries" >> $GITHUB_PATH

- name: Run Tests
run: pnpm test:forc

e2e:
runs-on: ubuntu-latest
timeout-minutes: 25
Expand Down
1 change: 1 addition & 0 deletions apps/create-fuels-counter-guide/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"type": "module",
"scripts": {
"test:ui": "sh ./test/ui/test-ui.sh",
"test:forc": "forc test --path ./sway-programs",
"original:dev": "vite",
"original:build": "tsc -b && vite build",
"original:start": "vite start",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,24 @@ impl Counter for Contract {
}
}
// #endregion create-fuels-counter-guide-impl

#[test]
fn should_get_count() {
let contract_instance = abi(Counter, CONTRACT_ID);
let expected = 0;

let actual = contract_instance.get_count();

assert(actual == expected);
}

#[test]
fn should_increment_counter() {
let contract_instance = abi(Counter, CONTRACT_ID);
let count_before = contract_instance.get_count();
let expected = count_before + 1;

let count_after = contract_instance.increment_counter(1);

assert(count_after == expected);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,21 @@ configurable {
fn main(pin: u64) -> bool {
return PIN == pin;
}

#[test]
fn should_return_true_when_password_is_1337() {
let expected = true;

let actual = main(1337);

assert(actual == expected);
}

#[test]
fn should_return_false_when_password_is_not_1337() {
let expected = false;

let actual = main(1338);

assert(actual == expected);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,12 @@ script;
fn main(input: u64) -> u64 {
return input;
}

#[test]
fn should_return_input() {
let expected = 1234;

let actual = main(1234);

assert(actual == expected);
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"test:browser:filter": "vitest --run --coverage false --config vitest.browser.config.mts",
"test:e2e": "vitest --run --config vitest.node.config.mts $(scripts/tests-find.sh --e2e)",
"test:integration": "vitest --run --config vitest.node.config.mts $(scripts/tests-find.sh --integration)",
"test:forc": "turbo run test:forc",
"test:network": "vitest --run --config vitest.node.config.mts $(scripts/tests-find.sh --network)",
"lint": "run-s type:check-tests lint:check prettier:check type:check",
"lint:check": "eslint . --ext .ts --max-warnings 0",
Expand Down
4 changes: 3 additions & 1 deletion templates/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"build": "pnpm run xprebuild && next build",
"start": "next start",
"lint": "next lint",
"test": "vitest",
"test": "run-s test:*",
"test:forc": "forc test --path ./sway-programs",
"test:e2e": "vitest",
"test:ui": "sh ./test/ui/test-ui.sh"
},
"dependencies": {
Expand Down
21 changes: 21 additions & 0 deletions templates/nextjs/sway-programs/contract/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,24 @@ impl Counter for Contract {
storage.counter.read()
}
}

#[test]
fn should_get_count() {
let contract_instance = abi(Counter, CONTRACT_ID);
let expected = 0;

let actual = contract_instance.get_count();

assert(actual == expected);
}

#[test]
fn should_increment_counter() {
let contract_instance = abi(Counter, CONTRACT_ID);
let count_before = contract_instance.get_count();
let expected = count_before + 1;

let count_after = contract_instance.increment_counter(1);

assert(count_after == expected);
}
18 changes: 18 additions & 0 deletions templates/nextjs/sway-programs/predicate/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,21 @@ predicate;
fn main(password: u64) -> bool {
return password == 1337;
}

#[test]
fn should_return_true_when_password_is_1337() {
let expected = true;

let actual = main(1337);

assert(actual == expected);
}

#[test]
fn should_return_false_when_password_is_not_1337() {
let expected = false;

let actual = main(1338);

assert(actual == expected);
}
9 changes: 9 additions & 0 deletions templates/nextjs/sway-programs/script/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,12 @@ script;
fn main(input: u64) -> u64 {
return input;
}

#[test]
fn should_return_input() {
let expected = 1234;

let actual = main(1234);

assert(actual == expected);
}
4 changes: 3 additions & 1 deletion templates/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"build": "pnpm run xprebuild && tsc -b && vite build",
"lint": "eslint .",
"fuels:dev": "fuels dev",
"test": "vitest",
"test": "run-s test:*",
"test:forc": "forc test --path ./sway-programs",
"test:e2e": "vitest",
"test:ui": "sh ./test/ui/test-ui.sh"
},
"dependencies": {
Expand Down
21 changes: 21 additions & 0 deletions templates/vite/sway-programs/contract/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,24 @@ impl Counter for Contract {
storage.counter.read()
}
}

#[test]
fn should_get_count() {
let contract_instance = abi(Counter, CONTRACT_ID);
let expected = 0;

let actual = contract_instance.get_count();

assert(actual == expected);
}

#[test]
fn should_increment_counter() {
let contract_instance = abi(Counter, CONTRACT_ID);
let count_before = contract_instance.get_count();
let expected = count_before + 1;

let count_after = contract_instance.increment_counter(1);

assert(count_after == expected);
}
18 changes: 18 additions & 0 deletions templates/vite/sway-programs/predicate/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,21 @@ predicate;
fn main(password: u64) -> bool {
return password == 1337;
}

#[test]
fn should_return_true_when_password_is_1337() {
let expected = true;

let actual = main(1337);

assert(actual == expected);
}

#[test]
fn should_return_false_when_password_is_not_1337() {
let expected = false;

let actual = main(1338);

assert(actual == expected);
}
9 changes: 9 additions & 0 deletions templates/vite/sway-programs/script/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,12 @@ script;
fn main(input: u64) -> u64 {
return input;
}

#[test]
fn should_return_input() {
let expected = 1234;

let actual = main(1234);

assert(actual == expected);
}
4 changes: 4 additions & 0 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
"test": {
"dependsOn": ["^test", "pretest"],
"outputLogs": "new-only"
},
"test:forc": {
"dependsOn": ["^test:forc", "build"],
"outputLogs": "new-only"
}
}
}
Loading