-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update user guide docs to reflect addition of DynamicScratchVar (#226)
- Loading branch information
1 parent
51a6562
commit 7c953f6
Showing
5 changed files
with
100 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
tests/teal/user_guide_snippet_dynamic_scratch_var_expected.teal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#pragma version 6 | ||
int 0 | ||
store 1 | ||
int 7 | ||
store 0 | ||
load 1 | ||
load 1 | ||
loads | ||
int 3 | ||
+ | ||
stores | ||
load 0 | ||
int 10 | ||
== | ||
assert | ||
int 1 | ||
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import pytest | ||
|
||
from pyteal import * | ||
|
||
from .compile_asserts import assert_new_v_old, compile_and_save | ||
|
||
|
||
def user_guide_snippet_dynamic_scratch_var() -> Expr: | ||
""" | ||
The user guide docs use the test to illustrate `DynamicScratchVar` usage. If the test breaks, then the user guide docs must be updated along with the test. | ||
""" | ||
|
||
s = ScratchVar(TealType.uint64) | ||
d = DynamicScratchVar(TealType.uint64) | ||
|
||
return Seq( | ||
d.set_index(s), | ||
s.store(Int(7)), | ||
d.store(d.load() + Int(3)), | ||
Assert(s.load() == Int(10)), | ||
Int(1), | ||
) | ||
|
||
|
||
@pytest.mark.parametrize("snippet", [user_guide_snippet_dynamic_scratch_var]) | ||
def test_user_guide_snippets(snippet): | ||
assert_new_v_old(snippet) |