From 006f6ebc9683e16fe6541598750da0ab1a60d074 Mon Sep 17 00:00:00 2001 From: Agusx1211 Date: Thu, 18 Jan 2024 16:12:41 +0100 Subject: [PATCH] Mention functions and test compatibility Tests must return to avoid executing code that exists after them. This issue arises when a function is declared in the contract, leading to all tests failing as they execute function code, resulting in stack underflows. This can be resolved by including a return statement at the end of every test. --- src/get-started/huff-by-example/README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/get-started/huff-by-example/README.md b/src/get-started/huff-by-example/README.md index 952ce23..dd926f1 100644 --- a/src/get-started/huff-by-example/README.md +++ b/src/get-started/huff-by-example/README.md @@ -521,6 +521,12 @@ Available decorators include: * `calldata` - Set the calldata for the transaction environment. Accepts a single string of calldata bytes. * `value` - Set the callvalue for the transaction environment. Accepts a single literal. +#### Testing with functions + +Huff functions are appended at the end of the contract bytecode, which may conflict with the execution of the tests, as function code may be executed after them. + +Always include a return statement at the end of each of your tests to ensure compatibility with functions. + #### Example ```plaintext #include "huffmate/utils/Errors.huff" @@ -536,5 +542,7 @@ Available decorators include: 0x00 calldataload // [0x01] callvalue // [0x01, 0x01] eq ASSERT() + + 0x00 0x00 return } ```