Skip to content

Commit

Permalink
Merge pull request #77 from algorand-devrel/dev
Browse files Browse the repository at this point in the history
0.27.3
  • Loading branch information
joe-p authored Jul 15, 2023
2 parents c7c27a0 + 129217d commit 74137ea
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@algorandfoundation/tealscript",
"version": "0.27.2",
"version": "0.27.3",
"description": "Enables Algorand smart contract development with native TypeScript syntax, tooling, and IDE support",
"homepage": "https://github.com/algorand-devrel/TEALScript",
"bugs": {
Expand Down
5 changes: 5 additions & 0 deletions src/lib/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1668,6 +1668,11 @@ export default class Compiler {
if (this.typeHint === undefined) throw new Error('Type hint is undefined');
let { typeHint } = this;

if (this.getABIType(typeHint).endsWith('[]') && node.elements.length === 0) {
this.push(node, 'byte 0x', this.getABIType(this.typeHint));
return;
}

const baseType = typeHint.replace(/\[\d*\]$/, '');

if (this.isDynamicType(baseType) || (typeHint.startsWith('[') && !typeHint.match(/\[\d*\]$/))) {
Expand Down
6 changes: 6 additions & 0 deletions tests/abi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -601,4 +601,10 @@ describe('ABI', function () {

expect(await runMethod(appClient, 'partialStaticArray')).toEqual([1n, 0n, 0n]);
});

test.concurrent('emptyDynamicArray', async () => {
const { appClient } = await compileAndCreate('emptyDynamicArray');

expect(await runMethod(appClient, 'emptyDynamicArray')).toEqual([]);
});
});
6 changes: 6 additions & 0 deletions tests/contracts/abi.algo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -829,3 +829,9 @@ class ABITestStorageTypeHint extends Contract {
return this.gKey.get();
}
}

class ABITestEmptyDynamicArray extends Contract {
emptyDynamicArray(): uint64[] {
return [];
}
}
15 changes: 15 additions & 0 deletions tests/contracts/artifacts/ABITestEmptyDynamicArray.abi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "ABITestEmptyDynamicArray",
"desc": "",
"methods": [
{
"name": "emptyDynamicArray",
"args": [],
"desc": "",
"returns": {
"type": "uint64[]",
"desc": ""
}
}
]
}
57 changes: 57 additions & 0 deletions tests/contracts/artifacts/ABITestEmptyDynamicArray.approval.teal
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#pragma version 8
b main

abi_route_emptyDynamicArray:
txn OnCompletion
int NoOp
==
txn ApplicationID
int 0
!=
&&
assert

// no dupn needed
callsub emptyDynamicArray
int 1
return

emptyDynamicArray:
proto 0 0

// tests/contracts/abi.algo.ts:835
// return [];
byte 0x
dup
len
int 8
/
itob
extract 6 2
swap
concat
byte 0x151f7c75
swap
concat
log
retsub

main:
txn NumAppArgs
bnz route_abi

// default createApplication
txn ApplicationID
int 0
==
txn OnCompletion
int NoOp
==
&&
return

route_abi:
method "emptyDynamicArray()uint64[]"
txna ApplicationArgs 0
match abi_route_emptyDynamicArray
err
3 changes: 3 additions & 0 deletions tests/contracts/artifacts/ABITestEmptyDynamicArray.clear.teal
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma version 8
int 1
return
51 changes: 51 additions & 0 deletions tests/contracts/artifacts/ABITestEmptyDynamicArray.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"hints": {
"emptyDynamicArray()uint64[]": {
"call_config": {
"no_op": "CALL"
}
}
},
"bare_call_config": {
"no_op": "CREATE"
},
"schema": {
"local": {
"declared": {},
"reserved": {}
},
"global": {
"declared": {},
"reserved": {}
}
},
"state": {
"global": {
"num_byte_slices": 0,
"num_uints": 0
},
"local": {
"num_byte_slices": 0,
"num_uints": 0
}
},
"source": {
"approval": "I3ByYWdtYSB2ZXJzaW9uIDgKCWIgbWFpbgoKYWJpX3JvdXRlX2VtcHR5RHluYW1pY0FycmF5OgoJdHhuIE9uQ29tcGxldGlvbgoJaW50IE5vT3AKCT09Cgl0eG4gQXBwbGljYXRpb25JRAoJaW50IDAKCSE9CgkmJgoJYXNzZXJ0CgoJLy8gbm8gZHVwbiBuZWVkZWQKCWNhbGxzdWIgZW1wdHlEeW5hbWljQXJyYXkKCWludCAxCglyZXR1cm4KCmVtcHR5RHluYW1pY0FycmF5OgoJcHJvdG8gMCAwCgoJLy8gdGVzdHMvY29udHJhY3RzL2FiaS5hbGdvLnRzOjgzNQoJLy8gcmV0dXJuIFtdOwoJYnl0ZSAweAoJZHVwCglsZW4KCWludCA4CgkvCglpdG9iCglleHRyYWN0IDYgMgoJc3dhcAoJY29uY2F0CglieXRlIDB4MTUxZjdjNzUKCXN3YXAKCWNvbmNhdAoJbG9nCglyZXRzdWIKCm1haW46Cgl0eG4gTnVtQXBwQXJncwoJYm56IHJvdXRlX2FiaQoKCS8vIGRlZmF1bHQgY3JlYXRlQXBwbGljYXRpb24KCXR4biBBcHBsaWNhdGlvbklECglpbnQgMAoJPT0KCXR4biBPbkNvbXBsZXRpb24KCWludCBOb09wCgk9PQoJJiYKCXJldHVybgoKcm91dGVfYWJpOgoJbWV0aG9kICJlbXB0eUR5bmFtaWNBcnJheSgpdWludDY0W10iCgl0eG5hIEFwcGxpY2F0aW9uQXJncyAwCgltYXRjaCBhYmlfcm91dGVfZW1wdHlEeW5hbWljQXJyYXkKCWVycg==",
"clear": "I3ByYWdtYSB2ZXJzaW9uIDgKaW50IDEKcmV0dXJu"
},
"contract": {
"name": "ABITestEmptyDynamicArray",
"desc": "",
"methods": [
{
"name": "emptyDynamicArray",
"args": [],
"desc": "",
"returns": {
"type": "uint64[]",
"desc": ""
}
}
]
}
}

0 comments on commit 74137ea

Please sign in to comment.