From 1176d6ed52186180867f8cf9054833cd3e5ad630 Mon Sep 17 00:00:00 2001 From: Hang Su Date: Thu, 24 Aug 2023 11:01:34 -0400 Subject: [PATCH 1/5] steps --- features/integration/simulate.feature | 22 ++++++++++- .../resources/programs/state-changes.teal | 37 +++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 features/resources/programs/state-changes.teal diff --git a/features/integration/simulate.feature b/features/integration/simulate.feature index a0f322ac..bb9f8235 100644 --- a/features/integration/simulate.feature +++ b/features/integration/simulate.feature @@ -204,4 +204,24 @@ Feature: Simulating transactions Then 4th unit in the "approval" trace at txn-groups path "0" should add value "uint64:1" to stack, pop 2 values from stack, write value "" to scratch slot "". Then 29th unit in the "approval" trace at txn-groups path "0" should add value "bytes:MSE=,bytes:NSE=" to stack, pop 0 values from stack, write value "" to scratch slot "". - Then 31th unit in the "approval" trace at txn-groups path "0" should add value "" to stack, pop 1 values from stack, write value "uint64:18446744073709551615" to scratch slot "1". \ No newline at end of file + Then 31th unit in the "approval" trace at txn-groups path "0" should add value "" to stack, pop 1 values from stack, write value "uint64:18446744073709551615" to scratch slot "1". + + @simulate.exec_trace_with_state_change_and_hash + Scenario: Simulate app with response containing state changes and hash of executed byte code + Given a new AtomicTransactionComposer + When I build an application transaction with the transient account, the current application, suggested params, operation "create", approval-program "programs/state-changes.teal", clear-program "programs/eight.teal", global-bytes 0, global-ints 0, local-bytes 0, local-ints 0, app-args "", foreign-apps "", foreign-assets "", app-accounts "", extra-pages 0, boxes "" + And I sign and submit the transaction, saving the txid. If there is an error it is "". + And I wait for the transaction to be confirmed. + Given I remember the new application ID. + + Given I add the nonce "simulate-with-exec-trace-state-changes" + When I make a new simulate request. + When I create the Method object from method signature "local()void" + * I create a new method arguments array. + * I add a nonced method call with the transient account, the current application, suggested params, on complete "noop", current transaction signer, current method arguments. + + Then I allow exec trace options "stack,scratch" on that simulate request. + Then I simulate the transaction group with the simulate request. + And the simulation should succeed without any failure message + + # TODO \ No newline at end of file diff --git a/features/resources/programs/state-changes.teal b/features/resources/programs/state-changes.teal new file mode 100644 index 00000000..ad42b7b0 --- /dev/null +++ b/features/resources/programs/state-changes.teal @@ -0,0 +1,37 @@ +#pragma version 8 +txn ApplicationID +bz end // Do nothing during create + +txn OnCompletion +int OptIn +== +bnz end // Always allow optin + +method "local()void" +method "global()void" +txn ApplicationArgs 0 +match local global +err // Unknown command + +local: + txn Sender + byte "local-int-key" + int 0xcafeb0ba + app_local_put + int 0 + byte "local-bytes-key" + byte "xqcL" + app_local_put + b end + +global: + byte "global-int-key" + int 0xdeadbeef + app_global_put + byte "global-bytes-key" + byte "welt am draht" + app_global_put + b end + +end: + int 1 \ No newline at end of file From 98c9d64a76ea55d06882236e65f661edb73d1cf3 Mon Sep 17 00:00:00 2001 From: Hang Su Date: Thu, 24 Aug 2023 12:24:39 -0400 Subject: [PATCH 2/5] steps --- features/integration/simulate.feature | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/features/integration/simulate.feature b/features/integration/simulate.feature index bb9f8235..060da0f3 100644 --- a/features/integration/simulate.feature +++ b/features/integration/simulate.feature @@ -209,19 +209,21 @@ Feature: Simulating transactions @simulate.exec_trace_with_state_change_and_hash Scenario: Simulate app with response containing state changes and hash of executed byte code Given a new AtomicTransactionComposer - When I build an application transaction with the transient account, the current application, suggested params, operation "create", approval-program "programs/state-changes.teal", clear-program "programs/eight.teal", global-bytes 0, global-ints 0, local-bytes 0, local-ints 0, app-args "", foreign-apps "", foreign-assets "", app-accounts "", extra-pages 0, boxes "" + When I build an application transaction with the transient account, the current application, suggested params, operation "create", approval-program "programs/state-changes.teal", clear-program "programs/eight.teal", global-bytes 1, global-ints 1, local-bytes 1, local-ints 1, app-args "", foreign-apps "", foreign-assets "", app-accounts "", extra-pages 0, boxes "" And I sign and submit the transaction, saving the txid. If there is an error it is "". And I wait for the transaction to be confirmed. Given I remember the new application ID. Given I add the nonce "simulate-with-exec-trace-state-changes" When I make a new simulate request. - When I create the Method object from method signature "local()void" + When I create the Method object from method signature "global()void" * I create a new method arguments array. * I add a nonced method call with the transient account, the current application, suggested params, on complete "noop", current transaction signer, current method arguments. - Then I allow exec trace options "stack,scratch" on that simulate request. + Then I allow exec trace options "state" on that simulate request. Then I simulate the transaction group with the simulate request. And the simulation should succeed without any failure message - # TODO \ No newline at end of file + Then "approval" hash at txn-groups path "0" should be "4NiVKyKI3huK1nHi/etuy5rbgnP1ODRaN77WF2swNNY=". + Then 13th unit in the "approval" trace at txn-groups path "0" should write to "global" state "global-int-key" with new value "uint64:3735928559". + Then 16th unit in the "approval" trace at txn-groups path "0" should write to "global" state "global-bytes-key" with new value "bytes:d2VsdCBhbSBkcmFodA==". \ No newline at end of file From 40da7f67d9accfd0dd770ed4afb7c2609db1a66b Mon Sep 17 00:00:00 2001 From: Jason Paulos Date: Tue, 12 Sep 2023 11:52:46 -0400 Subject: [PATCH 3/5] Update scenario --- features/integration/simulate.feature | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/features/integration/simulate.feature b/features/integration/simulate.feature index 060da0f3..4405d8d5 100644 --- a/features/integration/simulate.feature +++ b/features/integration/simulate.feature @@ -207,23 +207,28 @@ Feature: Simulating transactions Then 31th unit in the "approval" trace at txn-groups path "0" should add value "" to stack, pop 1 values from stack, write value "uint64:18446744073709551615" to scratch slot "1". @simulate.exec_trace_with_state_change_and_hash - Scenario: Simulate app with response containing state changes and hash of executed byte code - Given a new AtomicTransactionComposer - When I build an application transaction with the transient account, the current application, suggested params, operation "create", approval-program "programs/state-changes.teal", clear-program "programs/eight.teal", global-bytes 1, global-ints 1, local-bytes 1, local-ints 1, app-args "", foreign-apps "", foreign-assets "", app-accounts "", extra-pages 0, boxes "" + Scenario Outline: Simulate app with response containing state changes and hash of executed byte code + Given a new AtomicTransactionComposer + When I build an application transaction with the transient account, the current application, suggested params, operation "create-and-optin", approval-program "programs/state-changes.teal", clear-program "programs/eight.teal", global-bytes 1, global-ints 1, local-bytes 1, local-ints 1, app-args "", foreign-apps "", foreign-assets "", app-accounts "", extra-pages 0, boxes "" And I sign and submit the transaction, saving the txid. If there is an error it is "". And I wait for the transaction to be confirmed. Given I remember the new application ID. Given I add the nonce "simulate-with-exec-trace-state-changes" When I make a new simulate request. - When I create the Method object from method signature "global()void" - * I create a new method arguments array. - * I add a nonced method call with the transient account, the current application, suggested params, on complete "noop", current transaction signer, current method arguments. + When I create the Method object from method signature "" + And I create a new method arguments array. + And I add a nonced method call with the transient account, the current application, suggested params, on complete "noop", current transaction signer, current method arguments. Then I allow exec trace options "state" on that simulate request. - Then I simulate the transaction group with the simulate request. + And I simulate the transaction group with the simulate request. And the simulation should succeed without any failure message Then "approval" hash at txn-groups path "0" should be "4NiVKyKI3huK1nHi/etuy5rbgnP1ODRaN77WF2swNNY=". - Then 13th unit in the "approval" trace at txn-groups path "0" should write to "global" state "global-int-key" with new value "uint64:3735928559". - Then 16th unit in the "approval" trace at txn-groups path "0" should write to "global" state "global-bytes-key" with new value "bytes:d2VsdCBhbSBkcmFodA==". \ No newline at end of file + And th unit in the "approval" trace at txn-groups path "0" should write to "" state "" with new value "". + And th unit in the "approval" trace at txn-groups path "0" should write to "" state "" with new value "". + + Examples: + | method | state | index1 | key1 | value1 | index2 | key2 | value2 | + | global()void | global | 13 | global-int-key | uint64:3735928559 | 16 | global-bytes-key | bytes:d2VsdCBhbSBkcmFodA== | + | local()void | local | 14 | local-int-key | uint64:3405689018 | 18 | local-bytes-key | bytes:eHFjTA== | From a275576d7b015dfb8e3693771f0bad290318754a Mon Sep 17 00:00:00 2001 From: Jason Paulos Date: Tue, 12 Sep 2023 12:32:05 -0400 Subject: [PATCH 4/5] Test boxes too --- features/integration/simulate.feature | 13 +++++++------ features/resources/programs/state-changes.teal | 13 +++++++++++-- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/features/integration/simulate.feature b/features/integration/simulate.feature index 4405d8d5..20edb292 100644 --- a/features/integration/simulate.feature +++ b/features/integration/simulate.feature @@ -213,22 +213,23 @@ Feature: Simulating transactions And I sign and submit the transaction, saving the txid. If there is an error it is "". And I wait for the transaction to be confirmed. Given I remember the new application ID. + And I fund the current application's address with 1000000 microalgos. - Given I add the nonce "simulate-with-exec-trace-state-changes" When I make a new simulate request. When I create the Method object from method signature "" And I create a new method arguments array. - And I add a nonced method call with the transient account, the current application, suggested params, on complete "noop", current transaction signer, current method arguments. + And I add a method call with the transient account, the current application, suggested params, on complete "noop", current transaction signer, current method arguments, boxes "0,str:box-key-1,0,str:box-key-2". Then I allow exec trace options "state" on that simulate request. And I simulate the transaction group with the simulate request. And the simulation should succeed without any failure message - Then "approval" hash at txn-groups path "0" should be "4NiVKyKI3huK1nHi/etuy5rbgnP1ODRaN77WF2swNNY=". + Then "approval" hash at txn-groups path "0" should be "elIoqp1XgWrLCBLPmaZlDsKE3sEMZBY1dlxOvBXPtak=". And th unit in the "approval" trace at txn-groups path "0" should write to "" state "" with new value "". And th unit in the "approval" trace at txn-groups path "0" should write to "" state "" with new value "". Examples: - | method | state | index1 | key1 | value1 | index2 | key2 | value2 | - | global()void | global | 13 | global-int-key | uint64:3735928559 | 16 | global-bytes-key | bytes:d2VsdCBhbSBkcmFodA== | - | local()void | local | 14 | local-int-key | uint64:3405689018 | 18 | local-bytes-key | bytes:eHFjTA== | + | method | state | index1 | key1 | value1 | index2 | key2 | value2 | + | global()void | global | 14 | global-int-key | uint64:3735928559 | 17 | global-bytes-key | bytes:d2VsdCBhbSBkcmFodA== | + | local()void | local | 15 | local-int-key | uint64:3405689018 | 19 | local-bytes-key | bytes:eHFjTA== | + | box()void | box | 14 | box-key-1 | bytes:Ym94LXZhbHVlLTE= | 17 | box-key-2 | bytes: | diff --git a/features/resources/programs/state-changes.teal b/features/resources/programs/state-changes.teal index ad42b7b0..05908408 100644 --- a/features/resources/programs/state-changes.teal +++ b/features/resources/programs/state-changes.teal @@ -9,8 +9,9 @@ bnz end // Always allow optin method "local()void" method "global()void" +method "box()void" txn ApplicationArgs 0 -match local global +match local global box err // Unknown command local: @@ -33,5 +34,13 @@ global: app_global_put b end +box: + byte "box-key-1" + byte "box-value-1" + box_put + byte "box-key-2" + byte "" + box_put + end: - int 1 \ No newline at end of file + int 1 From a9f549ccdfda2893d6da228b88404724b2a5eea5 Mon Sep 17 00:00:00 2001 From: Jason Paulos Date: Tue, 12 Sep 2023 14:20:26 -0400 Subject: [PATCH 5/5] Test initial state --- features/integration/simulate.feature | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/features/integration/simulate.feature b/features/integration/simulate.feature index 20edb292..f1948a98 100644 --- a/features/integration/simulate.feature +++ b/features/integration/simulate.feature @@ -216,7 +216,7 @@ Feature: Simulating transactions And I fund the current application's address with 1000000 microalgos. When I make a new simulate request. - When I create the Method object from method signature "" + And I create the Method object from method signature "" And I create a new method arguments array. And I add a method call with the transient account, the current application, suggested params, on complete "noop", current transaction signer, current method arguments, boxes "0,str:box-key-1,0,str:box-key-2". @@ -224,10 +224,29 @@ Feature: Simulating transactions And I simulate the transaction group with the simulate request. And the simulation should succeed without any failure message + Then the current application initial "" state should be empty. + Then "approval" hash at txn-groups path "0" should be "elIoqp1XgWrLCBLPmaZlDsKE3sEMZBY1dlxOvBXPtak=". And th unit in the "approval" trace at txn-groups path "0" should write to "" state "" with new value "". And th unit in the "approval" trace at txn-groups path "0" should write to "" state "" with new value "". + # Submit the group to the actual network + Then I execute the current transaction group with the composer. + + # Simulate again so we can check the reported initial state. + Given a new AtomicTransactionComposer + When I make a new simulate request. + And I create the Method object from method signature "" + And I create a new method arguments array. + And I add a method call with the transient account, the current application, suggested params, on complete "noop", current transaction signer, current method arguments, boxes "0,str:box-key-1,0,str:box-key-2,0,str:nonce-box". + + Then I allow exec trace options "state" on that simulate request. + And I simulate the transaction group with the simulate request. + And the simulation should succeed without any failure message + + Then the current application initial "" state should contain "" with value "". + And the current application initial "" state should contain "" with value "". + Examples: | method | state | index1 | key1 | value1 | index2 | key2 | value2 | | global()void | global | 14 | global-int-key | uint64:3735928559 | 17 | global-bytes-key | bytes:d2VsdCBhbSBkcmFodA== |