Skip to content

Commit

Permalink
Coverage and spec wording improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
jannotti committed Oct 13, 2023
1 parent 20e5c0f commit b45fd21
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 12 deletions.
4 changes: 2 additions & 2 deletions data/transactions/logic/README.md
Expand Up @@ -756,15 +756,15 @@ are sure to be _available_.

| Opcode | Description |
| - | -- |
| `box_create` | create a box named A, of length B. Fail if A is empty or B exceeds 32,768. Returns 0 if A already existed, else 1 |
| `box_create` | create a box named A, of length B. Fail if the name A is empty or B exceeds 32,768. Returns 0 if A already existed, else 1 |
| `box_extract` | read C bytes from box A, starting at offset B. Fail if A does not exist, or the byte range is outside A's size. |
| `box_replace` | write byte-array C into box A, starting at offset B. Fail if A does not exist, or the byte range is outside A's size. |
| `box_splice` | set box A to contain its previous bytes up to index B, followed by D, followed by the original bytes of A that began at index B+C. |
| `box_del` | delete box named A if it exists. Return 1 if A existed, 0 otherwise |
| `box_len` | X is the length of box A if A exists, else 0. Y is 1 if A exists, else 0. |
| `box_get` | X is the contents of box A if A exists, else ''. Y is 1 if A exists, else 0. |
| `box_put` | replaces the contents of box A with byte-array B. Fails if A exists and len(B) != len(box A). Creates A if it does not exist |
| `box_resize` | change the size of box A to be of length B, adding zero bytes to end or removing bytes from the end, as needed. Fail if A is empty, is not an existing box, or B exceeds 32,768. |
| `box_resize` | change the size of box named A to be of length B, adding zero bytes to end or removing bytes from the end, as needed. Fail if the name A is empty, A is not an existing box, or B exceeds 32,768. |

### Inner Transactions

Expand Down
4 changes: 2 additions & 2 deletions data/transactions/logic/TEAL_opcodes_v10.md
Expand Up @@ -1487,7 +1487,7 @@ The notation A,B indicates that A and B are interpreted as a uint128 value, with

- Bytecode: 0xb9
- Stack: ..., A: boxName, B: uint64 → ..., bool
- create a box named A, of length B. Fail if A is empty or B exceeds 32,768. Returns 0 if A already existed, else 1
- create a box named A, of length B. Fail if the name A is empty or B exceeds 32,768. Returns 0 if A already existed, else 1
- Availability: v8
- Mode: Application

Expand Down Expand Up @@ -1655,7 +1655,7 @@ Boxes are of constant length. If C < len(D), then len(D)-C bytes will be removed

- Bytecode: 0xd3
- Stack: ..., A: boxName, B: uint64 &rarr; ...
- change the size of box A to be of length B, adding zero bytes to end or removing bytes from the end, as needed. Fail if A is empty, is not an existing box, or B exceeds 32,768.
- change the size of box named A to be of length B, adding zero bytes to end or removing bytes from the end, as needed. Fail if the name A is empty, A is not an existing box, or B exceeds 32,768.
- Availability: v10
- Mode: Application

Expand Down
2 changes: 1 addition & 1 deletion data/transactions/logic/TEAL_opcodes_v8.md
Expand Up @@ -1485,7 +1485,7 @@ The notation A,B indicates that A and B are interpreted as a uint128 value, with

- Bytecode: 0xb9
- Stack: ..., A: boxName, B: uint64 &rarr; ..., bool
- create a box named A, of length B. Fail if A is empty or B exceeds 32,768. Returns 0 if A already existed, else 1
- create a box named A, of length B. Fail if the name A is empty or B exceeds 32,768. Returns 0 if A already existed, else 1
- Availability: v8
- Mode: Application

Expand Down
2 changes: 1 addition & 1 deletion data/transactions/logic/TEAL_opcodes_v9.md
Expand Up @@ -1485,7 +1485,7 @@ The notation A,B indicates that A and B are interpreted as a uint128 value, with

- Bytecode: 0xb9
- Stack: ..., A: boxName, B: uint64 &rarr; ..., bool
- create a box named A, of length B. Fail if A is empty or B exceeds 32,768. Returns 0 if A already existed, else 1
- create a box named A, of length B. Fail if the name A is empty or B exceeds 32,768. Returns 0 if A already existed, else 1
- Availability: v8
- Mode: Application

Expand Down
12 changes: 12 additions & 0 deletions data/transactions/logic/box_test.go
Expand Up @@ -146,6 +146,11 @@ func TestBoxReadWrite(t *testing.T) {
"no such box")
TestApp(t, `byte "junk"; int 1; byte 0x3031; box_replace`, ep,
"invalid Box reference")

TestApp(t, `byte "self"; int 1; int 2; byte 0x3031; box_splice`, ep,
"no such box")
TestApp(t, `byte "junk"; int 1; int 2; byte 0x3031; box_splice`, ep,
"invalid Box reference")
}

func TestBoxSplice(t *testing.T) {
Expand Down Expand Up @@ -203,6 +208,11 @@ func TestBoxSplice(t *testing.T) {
TestApp(t, `byte "self"; int 5; int 0; byte 0x; box_splice;
byte "self"; box_get; assert; byte 0x22333300; ==`, ep,
"replacement start 5 beyond length")

// overflow doesn't work
TestApp(t, `byte "self"; int 2; int 18446744073709551615; byte 0x; box_splice;
byte "self"; box_get; assert; byte 0x22333300; ==`, ep,
"splice end exceeds uint64")
}

func TestBoxAcrossTxns(t *testing.T) {
Expand Down Expand Up @@ -603,6 +613,8 @@ func TestEarlyPanics(t *testing.T) {
"box_len": `byte "%s"; box_len`,
"box_put": `byte "%s"; byte "hello"; box_put`,
"box_replace": `byte "%s"; int 0; byte "new"; box_replace`,
"box_splice": `byte "%s"; int 0; int 2; byte "new"; box_splice`,
"box_resize": `byte "%s"; int 2; box_resize`,
}

for name, program := range tests {
Expand Down
4 changes: 2 additions & 2 deletions data/transactions/logic/doc.go
Expand Up @@ -286,15 +286,15 @@ var opDescByName = map[string]OpDesc{
"frame_bury": {"replace the Nth (signed) value from the frame pointer in the stack with A", "", []string{"frame slot"}},
"popn": {"remove N values from the top of the stack", "", []string{"stack depth"}},

"box_create": {"create a box named A, of length B. Fail if A is empty or B exceeds 32,768. Returns 0 if A already existed, else 1", "Newly created boxes are filled with 0 bytes. `box_create` will fail if the referenced box already exists with a different size. Otherwise, existing boxes are unchanged by `box_create`.", nil},
"box_create": {"create a box named A, of length B. Fail if the name A is empty or B exceeds 32,768. Returns 0 if A already existed, else 1", "Newly created boxes are filled with 0 bytes. `box_create` will fail if the referenced box already exists with a different size. Otherwise, existing boxes are unchanged by `box_create`.", nil},
"box_extract": {"read C bytes from box A, starting at offset B. Fail if A does not exist, or the byte range is outside A's size.", "", nil},
"box_replace": {"write byte-array C into box A, starting at offset B. Fail if A does not exist, or the byte range is outside A's size.", "", nil},
"box_splice": {"set box A to contain its previous bytes up to index B, followed by D, followed by the original bytes of A that began at index B+C.", "Boxes are of constant length. If C < len(D), then len(D)-C bytes will be removed from the end. If C > len(D), zero bytes will be appended to the end to reach the box length.", nil},
"box_del": {"delete box named A if it exists. Return 1 if A existed, 0 otherwise", "", nil},
"box_len": {"X is the length of box A if A exists, else 0. Y is 1 if A exists, else 0.", "", nil},
"box_get": {"X is the contents of box A if A exists, else ''. Y is 1 if A exists, else 0.", "For boxes that exceed 4,096 bytes, consider `box_create`, `box_extract`, and `box_replace`", nil},
"box_put": {"replaces the contents of box A with byte-array B. Fails if A exists and len(B) != len(box A). Creates A if it does not exist", "For boxes that exceed 4,096 bytes, consider `box_create`, `box_extract`, and `box_replace`", nil},
"box_resize": {"change the size of box A to be of length B, adding zero bytes to end or removing bytes from the end, as needed. Fail if A is empty, is not an existing box, or B exceeds 32,768.", "", nil},
"box_resize": {"change the size of box named A to be of length B, adding zero bytes to end or removing bytes from the end, as needed. Fail if the name A is empty, A is not an existing box, or B exceeds 32,768.", "", nil},
}

// OpDoc returns a description of the op
Expand Down
4 changes: 2 additions & 2 deletions data/transactions/logic/langspec_v10.json
Expand Up @@ -4224,7 +4224,7 @@
],
"Size": 1,
"DocCost": "1",
"Doc": "create a box named A, of length B. Fail if A is empty or B exceeds 32,768. Returns 0 if A already existed, else 1",
"Doc": "create a box named A, of length B. Fail if the name A is empty or B exceeds 32,768. Returns 0 if A already existed, else 1",
"DocExtra": "Newly created boxes are filled with 0 bytes. `box_create` will fail if the referenced box already exists with a different size. Otherwise, existing boxes are unchanged by `box_create`.",
"IntroducedVersion": 8,
"Groups": [
Expand Down Expand Up @@ -4653,7 +4653,7 @@
],
"Size": 1,
"DocCost": "1",
"Doc": "change the size of box A to be of length B, adding zero bytes to end or removing bytes from the end, as needed. Fail if A is empty, is not an existing box, or B exceeds 32,768.",
"Doc": "change the size of box named A to be of length B, adding zero bytes to end or removing bytes from the end, as needed. Fail if the name A is empty, A is not an existing box, or B exceeds 32,768.",
"IntroducedVersion": 10,
"Groups": [
"Box Access"
Expand Down
2 changes: 1 addition & 1 deletion data/transactions/logic/langspec_v8.json
Expand Up @@ -4220,7 +4220,7 @@
],
"Size": 1,
"DocCost": "1",
"Doc": "create a box named A, of length B. Fail if A is empty or B exceeds 32,768. Returns 0 if A already existed, else 1",
"Doc": "create a box named A, of length B. Fail if the name A is empty or B exceeds 32,768. Returns 0 if A already existed, else 1",
"DocExtra": "Newly created boxes are filled with 0 bytes. `box_create` will fail if the referenced box already exists with a different size. Otherwise, existing boxes are unchanged by `box_create`.",
"IntroducedVersion": 8,
"Groups": [
Expand Down
2 changes: 1 addition & 1 deletion data/transactions/logic/langspec_v9.json
Expand Up @@ -4220,7 +4220,7 @@
],
"Size": 1,
"DocCost": "1",
"Doc": "create a box named A, of length B. Fail if A is empty or B exceeds 32,768. Returns 0 if A already existed, else 1",
"Doc": "create a box named A, of length B. Fail if the name A is empty or B exceeds 32,768. Returns 0 if A already existed, else 1",
"DocExtra": "Newly created boxes are filled with 0 bytes. `box_create` will fail if the referenced box already exists with a different size. Otherwise, existing boxes are unchanged by `box_create`.",
"IntroducedVersion": 8,
"Groups": [
Expand Down

0 comments on commit b45fd21

Please sign in to comment.