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 sway tests to create-fuels #3100

Closed
wants to merge 15 commits into from
Closed
5 changes: 5 additions & 0 deletions .changeset/green-cars-happen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-fuels": patch
---

feat: add sway tests to `create-fuels`
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:*",
Dhaiwat10 marked this conversation as resolved.
Show resolved Hide resolved
"test:e2e": "vitest",
Dhaiwat10 marked this conversation as resolved.
Show resolved Hide resolved
"test:unit": "cd sway-programs && forc test"
},
"dependencies": {
"@fuels/connectors": "^0.26.0",
Expand Down
15 changes: 15 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,18 @@ impl Counter for Contract {
storage.counter.read()
}
}

#[test]
fn test_get_count() {
let contract_instance = abi(Counter, CONTRACT_ID);
let count = contract_instance.get_count();
assert(count == 0);
}

#[test]
fn test_increment_counter() {
let contract_instance = abi(Counter, CONTRACT_ID);
let count_before = contract_instance.get_count();
let count_after = contract_instance.increment_counter(1);
assert(count_after == count_before + 1);
}
9 changes: 9 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,12 @@ predicate;
fn main(password: u64) -> bool {
return password == 1337;
}

#[test]
fn test_main() {
let result1 = main(1337);
assert(result1 == true);

let result2 = main(1338);
assert(result2 == false);
}
6 changes: 6 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,9 @@ script;
fn main(input: u64) -> u64 {
return input;
}

#[test]
fn test_main() {
let result = main(1337);
assert(result == 1337);
}
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:*",
Dhaiwat10 marked this conversation as resolved.
Show resolved Hide resolved
"test:e2e": "vitest",
"test:unit": "cd sway-programs && forc test"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably run these tests in the CI to ensure they pass. Same for all packages.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried adding them to CI but this would require us to install forc in CI. One thing we could do is use our internal binaries to run these tests only for CI instead of forc. Mind if I tackle this in a separate issue?

},
"dependencies": {
"@fuels/connectors": "^0.26.0",
Expand Down
15 changes: 15 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,18 @@ impl Counter for Contract {
storage.counter.read()
}
}

#[test]
fn test_get_count() {
let contract_instance = abi(Counter, CONTRACT_ID);
let count = contract_instance.get_count();
assert(count == 0);
}

#[test]
fn test_increment_counter() {
let contract_instance = abi(Counter, CONTRACT_ID);
let count_before = contract_instance.get_count();
let count_after = contract_instance.increment_counter(1);
assert(count_after == count_before + 1);
}
9 changes: 9 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,12 @@ predicate;
fn main(password: u64) -> bool {
return password == 1337;
}

#[test]
fn test_main() {
let result1 = main(1337);
assert(result1 == true);

let result2 = main(1338);
assert(result2 == false);
}
6 changes: 6 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,9 @@ script;
fn main(input: u64) -> u64 {
return input;
}

#[test]
fn test_main() {
let result = main(1337);
assert(result == 1337);
}
Loading