Skip to content

Latest commit

 

History

History
25 lines (16 loc) · 687 Bytes

File metadata and controls

25 lines (16 loc) · 687 Bytes

Test

Sway provides the #[test] attribute which enables unit tests to be written in Sway.

Success case

The #[test] attribute indicates that a test has passed if it did not revert.

{{#include ../../../../code/language/annotations/src/main.sw:success_test}}

Revert Case

To test a case where code should revert we can use the #[test(should_revert)] annotation. If the test reverts then it will be reported as a passing test.

{{#include ../../../../code/language/annotations/src/main.sw:revert_test}}

We may specify a code to specifically test against.

{{#include ../../../../code/language/annotations/src/main.sw:revert_code_test}}