Skip to content

Commit

Permalink
Feature: Box Storage (#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
algochoi authored Nov 1, 2022
1 parent b8c2bae commit 176928d
Show file tree
Hide file tree
Showing 16 changed files with 293 additions and 53 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@ These reside in the [integration features directory](features/integration)
| ---------------------- | -------------------------------------------------------------------------------------- |
| @abi | Test the Application Binary Interface (ABI) with atomic txn composition and execution. |
| @algod | General tests against algod REST endpoints. |
| @applications.boxes | Test application boxes and box references functionality. |
| @applications.verified | Submit all types of application transactions and verify account state. |
| @assets | Submit all types of asset transactions. |
| @auction | Encode and decode bids for an auction. |
| @c2c | Test Contract to Contract invocations and injestion. |
| @compile | Test the algod compile endpoint. |
| @compile.sourcemap | Test the algod compile endpoint returns a valid Source Map |
| @compile.sourcemap | Test the algod compile endpoint returns a valid Source Map |
| @dryrun | Test the algod dryrun endpoint. |
| @dryrun.testing | Test the testing harness that relies on dryrun endpoint. Python only. |
| @kmd | Test the kmd REST endpoints. |
Expand Down
4 changes: 2 additions & 2 deletions features/integration/abi.feature
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Feature: ABI Interaction
And suggested transaction parameters from the algod v2 client
And I create a new transient account and fund it with 100000000 microalgos.
And I make a transaction signer for the transient account.
And I build an application transaction with the transient account, the current application, suggested params, operation "create", approval-program "programs/abi_method_call.teal.tok", clear-program "programs/one.teal.tok", global-bytes 0, global-ints 0, local-bytes 1, local-ints 0, app-args "", foreign-apps "", foreign-assets "", app-accounts "", extra-pages 0
And I build an application transaction with the transient account, the current application, suggested params, operation "create", approval-program "programs/abi_method_call.teal.tok", clear-program "programs/one.teal.tok", global-bytes 0, global-ints 0, local-bytes 1, 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.
And I remember the new application ID.
Expand Down Expand Up @@ -100,7 +100,7 @@ Feature: ABI Interaction
Scenario: Method call delete execution
Given I create a new transient account and fund it with 100000000 microalgos.
And I make a transaction signer for the transient account.
And I build an application transaction with the transient account, the current application, suggested params, operation "create", approval-program "programs/abi_method_call.teal.tok", clear-program "programs/one.teal.tok", global-bytes 0, global-ints 0, local-bytes 1, local-ints 0, app-args "", foreign-apps "", foreign-assets "", app-accounts "", extra-pages 0
And I build an application transaction with the transient account, the current application, suggested params, operation "create", approval-program "programs/abi_method_call.teal.tok", clear-program "programs/one.teal.tok", global-bytes 0, global-ints 0, local-bytes 1, 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.
And I remember the new application ID.
Expand Down
154 changes: 139 additions & 15 deletions features/integration/applications.feature

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions features/integration/c2c.feature
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Feature: Contract to Contract Interaction
* I reset the array of application IDs to remember.

###### ------ app at context index 0: FakeRandom ------ ######
When I build an application transaction with the transient account, the current application, suggested params, operation "create", approval-program "programs/fake_random.teal", clear-program "programs/six.teal", global-bytes 0, global-ints 1, local-bytes 0, local-ints 0, app-args "", foreign-apps "", foreign-assets "", app-accounts "", extra-pages 0
When I build an application transaction with the transient account, the current application, suggested params, operation "create", approval-program "programs/fake_random.teal", clear-program "programs/six.teal", global-bytes 0, global-ints 1, 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.
Expand Down Expand Up @@ -42,7 +42,7 @@ Feature: Contract to Contract Interaction
And I can dig the 1th atomic result with path "txn.txn.type" and see the value "appl"

###### ------ app at context index 1: RandomByte ------ ######
When I build an application transaction with the transient account, the current application, suggested params, operation "create", approval-program "programs/random_byte.teal", clear-program "programs/six.teal", global-bytes 0, global-ints 0, local-bytes 0, local-ints 0, app-args "", foreign-apps "", foreign-assets "", app-accounts "", extra-pages 0
When I build an application transaction with the transient account, the current application, suggested params, operation "create", approval-program "programs/random_byte.teal", clear-program "programs/six.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.
Expand Down Expand Up @@ -80,7 +80,7 @@ Feature: Contract to Contract Interaction
And I can dig the 1th atomic result with path "inner-txns.0.txn.txn.type" and see the value "appl"

###### ----- app at context index 2: SlotMachine ----- ######
When I build an application transaction with the transient account, the current application, suggested params, operation "create", approval-program "programs/slot_machine.teal", clear-program "programs/six.teal", global-bytes 3, global-ints 1, local-bytes 0, local-ints 0, app-args "", foreign-apps "", foreign-assets "", app-accounts "", extra-pages 0
When I build an application transaction with the transient account, the current application, suggested params, operation "create", approval-program "programs/slot_machine.teal", clear-program "programs/six.teal", global-bytes 3, global-ints 1, 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.
Expand Down
5 changes: 3 additions & 2 deletions features/integration/compile.feature
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ Feature: Compile
| teal | program |
| programs/one.teal | programs/one.teal.tok |
| programs/zero.teal | programs/zero.teal.tok |
| programs/eight.teal | programs/eight.teal.tok |
| programs/abi_method_call.teal | programs/abi_method_call.teal.tok |

@compile.sourcemap
Scenario Outline: Algod compiling Teal returns a valid Source Map
When I compile a teal program "<teal>" with mapping enabled
Then the resulting source map is the same as the json "<sourcemap>"
Examples:
| teal | sourcemap |
| programs/quine.teal | v2algodclient_responsejsons/sourcemap.json |
| teal | sourcemap |
| programs/quine.teal | v2algodclient_responsejsons/sourcemap.json |
58 changes: 58 additions & 0 deletions features/resources/programs/box_app.teal
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#pragma version 8
txn ApplicationID
bz end
txn ApplicationArgs 0 // [arg[0]] // fails if no args && app already exists
byte "create" // [arg[0], "create"] // create box named arg[1]
== // [arg[0]=?="create"]
bz del // "create" ? continue : goto del
int 24 // [24]
txn NumAppArgs // [24, NumAppArgs]
int 2 // [24, NumAppArgs, 2]
== // [24, NumAppArgs=?=2]
bnz default // THIS IS POORLY BEHAVED WHEN "create" && NumAppArgs != 2
pop // get rid of 24 // NumAppArgs != 2
txn ApplicationArgs 2 // [arg[2]]
btoi // [btoi(arg[2])]
default: // [24] // NumAppArgs == 2
txn ApplicationArgs 1 // [24, arg[1]]
swap
box_create // [] // boxes: arg[1] -> [24]byte
assert
b end
del: // delete box arg[1]
txn ApplicationArgs 0 // [arg[0]]
byte "delete" // [arg[0], "delete"]
== // [arg[0]=?="delete"]
bz set // "delete" ? continue : goto set
txn ApplicationArgs 1 // [arg[1]]
box_del // del boxes[arg[1]]
assert
b end
set: // put arg[1] at start of box arg[0] ... so actually a _partial_ "set"
txn ApplicationArgs 0 // [arg[0]]
byte "set" // [arg[0], "set"]
== // [arg[0]=?="set"]
bz test // "set" ? continue : goto test
txn ApplicationArgs 1 // [arg[1]]
int 0 // [arg[1], 0]
txn ApplicationArgs 2 // [arg[1], 0, arg[2]]
box_replace // [] // boxes: arg[1] -> replace(boxes[arg[1]], 0, arg[2])
b end
test: // fail unless arg[2] is the prefix of box arg[1]
txn ApplicationArgs 0 // [arg[0]]
byte "check" // [arg[0], "check"]
== // [arg[0]=?="check"]
bz bad // "check" ? continue : goto bad
txn ApplicationArgs 1 // [arg[1]]
int 0 // [arg[1], 0]
txn ApplicationArgs 2 // [arg[1], 0, arg[2]]
len // [arg[1], 0, len(arg[2])]
box_extract // [ boxes[arg[1]][0:len(arg[2])] ]
txn ApplicationArgs 2 // [ boxes[arg[1]][0:len(arg[2])], arg[2] ]
== // [ boxes[arg[1]][0:len(arg[2])]=?=arg[2] ]
assert // boxes[arg[1]].startwith(arg[2]) ? pop : ERROR
b end
bad:
err
end:
int 1
Binary file added features/resources/programs/box_app.teal.tok
Binary file not shown.
2 changes: 2 additions & 0 deletions features/resources/programs/eight.teal
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#pragma version 8
int 8
1 change: 1 addition & 0 deletions features/resources/programs/eight.teal.tok
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
�
2 changes: 2 additions & 0 deletions features/resources/programs/four.teal
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#pragma version 4
int 4
1 change: 1 addition & 0 deletions features/resources/programs/four.teal.tok
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
�
4 changes: 2 additions & 2 deletions features/unit/feetest.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Feature: Transaction fee test
Given a signing account with address "BH55E5RMBD4GYWXGX5W5PJ5JAHPGM5OXKDQH5DC4O2MGI7NW4H6VOE4CP4" and mnemonic "awful drop leaf tennis indoor begin mandate discover uncle seven only coil atom any hospital uncover make any climb actor armed measure need above hundred"

Scenario Outline: App Call Fee Test
When I build an application transaction with operation "<operation>", application-id <application-id>, sender "<sender>", approval-program "<approval-prog-file>", clear-program "<clear-prog-file>", global-bytes <global-bytes>, global-ints <global-ints>, local-bytes <local-bytes>, local-ints <local-ints>, app-args "<app-args>", foreign-apps "<foreign-apps>", foreign-assets "<foreign-assets>", app-accounts "<app-accounts>", fee <fee>, first-valid <first-valid>, last-valid <last-valid>, genesis-hash "<genesis-hash>", extra-pages <extra-pages>
When I build an application transaction with operation "<operation>", application-id <application-id>, sender "<sender>", approval-program "<approval-prog-file>", clear-program "<clear-prog-file>", global-bytes <global-bytes>, global-ints <global-ints>, local-bytes <local-bytes>, local-ints <local-ints>, app-args "<app-args>", foreign-apps "<foreign-apps>", foreign-assets "<foreign-assets>", app-accounts "<app-accounts>", fee <fee>, first-valid <first-valid>, last-valid <last-valid>, genesis-hash "<genesis-hash>", extra-pages <extra-pages>, boxes ""
And sign the transaction
Then fee field is in txn
When I build an application transaction with operation "<operation>", application-id <application-id>, sender "<sender>", approval-program "<approval-prog-file>", clear-program "<clear-prog-file>", global-bytes <global-bytes>, global-ints <global-ints>, local-bytes <local-bytes>, local-ints <local-ints>, app-args "<app-args>", foreign-apps "<foreign-apps>", foreign-assets "<foreign-assets>", app-accounts "<app-accounts>", fee 0, first-valid <first-valid>, last-valid <last-valid>, genesis-hash "<genesis-hash>", extra-pages <extra-pages>
When I build an application transaction with operation "<operation>", application-id <application-id>, sender "<sender>", approval-program "<approval-prog-file>", clear-program "<clear-prog-file>", global-bytes <global-bytes>, global-ints <global-ints>, local-bytes <local-bytes>, local-ints <local-ints>, app-args "<app-args>", foreign-apps "<foreign-apps>", foreign-assets "<foreign-assets>", app-accounts "<app-accounts>", fee 0, first-valid <first-valid>, last-valid <last-valid>, genesis-hash "<genesis-hash>", extra-pages <extra-pages>, boxes ""
And sign the transaction
Then fee field not in txn

Expand Down
Loading

0 comments on commit 176928d

Please sign in to comment.