-
Notifications
You must be signed in to change notification settings - Fork 524
Tests: E2E testing C2C with ClearStateProgram #3693
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
430552f
fixed off-by-one error in the assembler's typeDig() and improved unit…
algoidurovic 390f589
Merge branch 'master' of https://github.com/algorand/go-algorand
algoidurovic a8f4f2d
Merge branch 'algorand:master' into master
algoidurovic 6957542
Merge branch 'master' of github.com:algoidurovic/go-algorand
algoidurovic 1ed6da1
Merge branch 'master' of https://github.com/algorand/go-algorand
algoidurovic 578ea2e
Merge branch 'master' of https://github.com/algorand/go-algorand
algoidurovic ea3a983
Merge branch 'master' of https://github.com/algorand/go-algorand
algoidurovic 462e274
e2e test for CSP
algoidurovic a003e1c
added additional test and cleaned up unused variables
algoidurovic 42b6f24
minor changes
algoidurovic 2879188
broadened test and corrected erroneous assumption about csp inner app…
algoidurovic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,157 @@ | ||
| #!/usr/bin/env python | ||
|
|
||
| import os | ||
| import sys | ||
| from goal import Goal | ||
|
|
||
| from datetime import datetime | ||
|
|
||
| stamp = datetime.now().strftime("%Y%m%d_%H%M%S") | ||
| print(f"{os.path.basename(sys.argv[0])} start {stamp}") | ||
|
|
||
| goal = Goal(sys.argv[1], autosend=True) | ||
|
|
||
| joe = goal.new_account() | ||
|
|
||
| _, err = goal.pay(goal.account, joe, amt=500_000_000) | ||
| assert not err, err | ||
|
|
||
| _, err = goal.keyreg(joe, nonpart=True) | ||
| assert not err, err | ||
|
|
||
| # On creation app1 does nothing to avoid fee complications. Further calls to app1 must | ||
| # contain an app arg that determines the execution path. An arg value of 0 opts app1 | ||
| # into app2 while a nonzero value issues an inner app call to app2's CSP. This verifies | ||
| # that accessing a CSP with inner app calls is possible. | ||
| app1 = """ | ||
| #pragma version 6 | ||
| txn ApplicationID | ||
| bz end | ||
|
|
||
| int 0 | ||
| txn ApplicationArgs 0 | ||
| btoi | ||
| == | ||
| bz nxt | ||
|
|
||
| itxn_begin | ||
| int appl | ||
| itxn_field TypeEnum | ||
|
|
||
| txn Applications 1 | ||
| itxn_field ApplicationID | ||
|
|
||
| txn Applications 2 | ||
| itxn_field Applications | ||
|
|
||
| int OptIn | ||
| itxn_field OnCompletion | ||
|
|
||
| itxn_submit | ||
| b end | ||
|
|
||
| nxt: | ||
| itxn_begin | ||
| int appl | ||
| itxn_field TypeEnum | ||
|
|
||
| txn Applications 1 | ||
| itxn_field ApplicationID | ||
|
|
||
| txn Applications 2 | ||
| itxn_field Applications | ||
|
|
||
| int ClearState | ||
| itxn_field OnCompletion | ||
|
|
||
| itxn_submit | ||
|
|
||
|
|
||
| end: | ||
| int 1 | ||
| """ | ||
|
|
||
| app2 = """ | ||
| #pragma version 6 | ||
| txn ApplicationID | ||
| bz end | ||
|
|
||
| itxn_begin | ||
| int appl | ||
| itxn_field TypeEnum | ||
|
|
||
| txn Applications 1 | ||
| itxn_field ApplicationID | ||
| itxn_submit | ||
|
|
||
|
|
||
| end: | ||
| int 1 | ||
| """ | ||
|
|
||
| app3 = """ | ||
| #pragma version 6 | ||
| pushbytes "success" | ||
| log | ||
| int 1 | ||
| """ | ||
|
|
||
| goal.autosend = True | ||
michaeldiamant marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # app1 creation | ||
| txinfo1, err = goal.app_create(joe, goal.assemble(app1)) | ||
algoidurovic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| assert not err, err | ||
| app1ID = txinfo1['application-index'] | ||
| assert app1ID | ||
|
|
||
| # insert clear state program with inner app call | ||
| txinfo2, err = goal.app_create(joe, goal.assemble(app2), goal.assemble(app2)) | ||
| assert not err, err | ||
| app2ID = txinfo2['application-index'] | ||
| assert app2ID | ||
|
|
||
| # dummy destination app | ||
| txinfo3, err = goal.app_create(joe, goal.assemble(app3)) | ||
| assert not err, err | ||
| app3ID = txinfo3['application-index'] | ||
| assert app3ID | ||
|
|
||
| # fund app1 | ||
| _, err = goal.pay(goal.account, goal.app_address(app1ID), amt=4_000_000) | ||
| assert not err, err | ||
|
|
||
| # fund app2 | ||
| _, err = goal.pay(goal.account, goal.app_address(app2ID), amt=4_000_000) | ||
| assert not err, err | ||
|
|
||
| # execute c2c to opt app1 into app2 and verify that the response is structured as | ||
| # expected for a successful execution of all 3 apps. | ||
| txinfo, err = goal.app_call(joe, app1ID, app_args=[0x00], foreign_apps=[int(app2ID), int(app3ID)]) | ||
| assert not err, err | ||
| assert len(txinfo["inner-txns"]) == 1 | ||
| assert len(txinfo["inner-txns"][0]["inner-txns"]) == 1 | ||
| assert len(txinfo["inner-txns"][0]["inner-txns"][0]["logs"]) == 1 | ||
|
|
||
| # execute c2c w/ CSP to opt app1 out of app2. Note that the CSP of app2 attempts | ||
| # to issue an inner app call, which is not allowed. The expected behavior is for | ||
| # the CSP to fail (so app3 won't be called) but for the Clear State operation to | ||
| # succeed. | ||
| txinfo, err = goal.app_call(joe, app1ID, app_args=[0x01], foreign_apps=[int(app2ID), int(app3ID)]) | ||
| assert not err, err | ||
| assert len(txinfo["inner-txns"]) == 1 | ||
| assert "inner-txns" not in txinfo["inner-txns"][0] | ||
|
|
||
| # attempt additional CSP inner app call that's intended to fail because app1 is | ||
| # no longer opted into app2 after previous call to CSP. | ||
| _, err = goal.app_call(joe, app1ID, app_args=[0x01], foreign_apps=[int(app2ID), int(app3ID)]) | ||
| assert err | ||
algoidurovic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| assert "is not currently opted in" in str(err) | ||
|
|
||
| # opt app1 into app2 again and call CSP again to verify that re optin works as expected | ||
| _, err = goal.app_call(joe, app1ID, app_args=[0x00], foreign_apps=[int(app2ID), int(app3ID)]) | ||
| assert not err, err | ||
|
|
||
| _, err = goal.app_call(joe, app1ID, app_args=[0x01], foreign_apps=[int(app2ID), int(app3ID)]) | ||
| assert not err, err | ||
|
|
||
michaeldiamant marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| print(f"{os.path.basename(sys.argv[0])} OK {stamp}") | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.