Skip to content
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

fix: bool encoding when first in tuple #502

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/lib/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3376,7 +3376,8 @@ export default class Compiler {
if (consecutiveBools.length > 0) {
this.processBools(consecutiveBools);
if (!isStatic) this.pushVoid(e, 'callsub *process_static_tuple_element');
else if (i !== 0) this.pushVoid(e, 'concat');
// Don't concat if bools are the first elements
else if (consecutiveBools.length !== i) this.pushVoid(e, `concat // ${i}`);

consecutiveBools = [];
}
Expand Down
8 changes: 8 additions & 0 deletions tests/contracts/abi.algo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1576,3 +1576,11 @@ class ABITestUpdateStaticFieldInDynamicObjectInBox extends Contract {
return this.bMap('bMap').value.str;
}
}

class ABITestBoolFirstInTuple extends Contract {
boolFirstInTuple(): [boolean, uint64, uint64] {
const a: [boolean, uint64, uint64] = [true, 1, 2];

return a;
}
}
82 changes: 82 additions & 0 deletions tests/contracts/artifacts/ABITestBoolFirstInTuple.approval.teal
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#pragma version 10

// This TEAL was generated by TEALScript v0.95.1
// https://github.com/algorandfoundation/TEALScript

// This contract is compliant with and/or implements the following ARCs: [ ARC4 ]

// The following ten lines of TEAL handle initial program flow
// This pattern is used to make it easy for anyone to parse the start of the program and determine if a specific action is allowed
// Here, action refers to the OnComplete in combination with whether the app is being created or called
// Every possible action for this contract is represented in the switch statement
// If the action is not implemented in the contract, its respective branch will be "*NOT_IMPLEMENTED" which just contains "err"
txn ApplicationID
!
int 6
*
txn OnCompletion
+
switch *call_NoOp *NOT_IMPLEMENTED *NOT_IMPLEMENTED *NOT_IMPLEMENTED *NOT_IMPLEMENTED *NOT_IMPLEMENTED *create_NoOp *NOT_IMPLEMENTED *NOT_IMPLEMENTED *NOT_IMPLEMENTED *NOT_IMPLEMENTED *NOT_IMPLEMENTED

*NOT_IMPLEMENTED:
// The requested action is not implemented in this contract. Are you using the correct OnComplete? Did you set your app ID?
err

// boolFirstInTuple()(bool,uint64,uint64)
*abi_route_boolFirstInTuple:
// The ABI return prefix
byte 0x151f7c75

// execute boolFirstInTuple()(bool,uint64,uint64)
callsub boolFirstInTuple
concat
log
int 1
return

// boolFirstInTuple(): [boolean, uint64, uint64]
boolFirstInTuple:
proto 0 1

// Push empty bytes after the frame pointer to reserve space for local variables
byte 0x

// tests/contracts/abi.algo.ts:1582
// a: [boolean, uint64, uint64] = [true, 1, 2]
byte 0x00
int 0
int 1
setbit
byte 0x0000000000000001
concat
byte 0x0000000000000002
concat
frame_bury 0 // a: [boolean, uint64, uint64]

// tests/contracts/abi.algo.ts:1584
// return a;
frame_dig 0 // a: [boolean, uint64, uint64]

// set the subroutine return value
frame_bury 0
retsub

*abi_route_createApplication:
int 1
return

*create_NoOp:
method "createApplication()void"
txna ApplicationArgs 0
match *abi_route_createApplication

// this contract does not implement the given ABI method for create NoOp
err

*call_NoOp:
method "boolFirstInTuple()(bool,uint64,uint64)"
txna ApplicationArgs 0
match *abi_route_boolFirstInTuple

// this contract does not implement the given ABI method for call NoOp
err
65 changes: 65 additions & 0 deletions tests/contracts/artifacts/ABITestBoolFirstInTuple.arc32.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"hints": {
"boolFirstInTuple()(bool,uint64,uint64)": {
"call_config": {
"no_op": "CALL"
}
},
"createApplication()void": {
"call_config": {
"no_op": "CREATE"
}
}
},
"bare_call_config": {
"no_op": "NEVER",
"opt_in": "NEVER",
"close_out": "NEVER",
"update_application": "NEVER",
"delete_application": "NEVER"
},
"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": "I3ByYWdtYSB2ZXJzaW9uIDEwCgovLyBUaGlzIFRFQUwgd2FzIGdlbmVyYXRlZCBieSBURUFMU2NyaXB0IHYwLjk1LjEKLy8gaHR0cHM6Ly9naXRodWIuY29tL2FsZ29yYW5kZm91bmRhdGlvbi9URUFMU2NyaXB0CgovLyBUaGlzIGNvbnRyYWN0IGlzIGNvbXBsaWFudCB3aXRoIGFuZC9vciBpbXBsZW1lbnRzIHRoZSBmb2xsb3dpbmcgQVJDczogWyBBUkM0IF0KCi8vIFRoZSBmb2xsb3dpbmcgdGVuIGxpbmVzIG9mIFRFQUwgaGFuZGxlIGluaXRpYWwgcHJvZ3JhbSBmbG93Ci8vIFRoaXMgcGF0dGVybiBpcyB1c2VkIHRvIG1ha2UgaXQgZWFzeSBmb3IgYW55b25lIHRvIHBhcnNlIHRoZSBzdGFydCBvZiB0aGUgcHJvZ3JhbSBhbmQgZGV0ZXJtaW5lIGlmIGEgc3BlY2lmaWMgYWN0aW9uIGlzIGFsbG93ZWQKLy8gSGVyZSwgYWN0aW9uIHJlZmVycyB0byB0aGUgT25Db21wbGV0ZSBpbiBjb21iaW5hdGlvbiB3aXRoIHdoZXRoZXIgdGhlIGFwcCBpcyBiZWluZyBjcmVhdGVkIG9yIGNhbGxlZAovLyBFdmVyeSBwb3NzaWJsZSBhY3Rpb24gZm9yIHRoaXMgY29udHJhY3QgaXMgcmVwcmVzZW50ZWQgaW4gdGhlIHN3aXRjaCBzdGF0ZW1lbnQKLy8gSWYgdGhlIGFjdGlvbiBpcyBub3QgaW1wbGVtZW50ZWQgaW4gdGhlIGNvbnRyYWN0LCBpdHMgcmVzcGVjdGl2ZSBicmFuY2ggd2lsbCBiZSAiKk5PVF9JTVBMRU1FTlRF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QgZm9yIGNhbGwgTm9PcAoJZXJy",
"clear": "I3ByYWdtYSB2ZXJzaW9uIDEw"
},
"contract": {
"name": "ABITestBoolFirstInTuple",
"desc": "",
"methods": [
{
"name": "boolFirstInTuple",
"args": [],
"returns": {
"type": "(bool,uint64,uint64)"
}
},
{
"name": "createApplication",
"args": [],
"returns": {
"type": "void"
}
}
]
}
}
20 changes: 20 additions & 0 deletions tests/contracts/artifacts/ABITestBoolFirstInTuple.arc4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "ABITestBoolFirstInTuple",
"desc": "",
"methods": [
{
"name": "boolFirstInTuple",
"args": [],
"returns": {
"type": "(bool,uint64,uint64)"
}
},
{
"name": "createApplication",
"args": [],
"returns": {
"type": "void"
}
}
]
}
Loading
Loading