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 typo (or wrong implementation) in 'runtime/src/ctx.ts' #798

Closed
wants to merge 3 commits into from

Conversation

PabloLION
Copy link
Contributor

@PabloLION PabloLION commented Oct 2, 2022

I think this implementation doesn't return the same result as algod sandbox (not tested yet) If so, these related tests also needs a change.

it("Tealv6: CalllerApplicationAddress", () => {
// caller app id = 2
const op = new Global(["CallerApplicationAddress"], 1, interpreter);
op.execute(stack);
assert.deepEqual(decodeAddress(getApplicationAddress(2n)).publicKey, stack.pop());
// no caller
interpreter.runtime.ctx.innerTxAppIDCallStack = [];
op.execute(stack);
assert.deepEqual(ZERO_ADDRESS, stack.pop());
});
it("Tealv6: CallerApplicationID", () => {
// caller app id = 2
const op = new Global(["CallerApplicationID"], 1, interpreter);
op.execute(stack);
assert.equal(2n, stack.pop());
// no caller
interpreter.runtime.ctx.innerTxAppIDCallStack = [];
op.execute(stack);
assert.equal(0n, stack.pop());
});

In both pyteal doc and algorand doc says that global CallerApplicationID returns

The application ID of the application that called this application. 0 if this application is at the top-level. Application mode only.

But the current implementation of global CallerApplicationID seems to return a same uint64 as the global CurrentApplicationID

TODO

  • test it with sandbox private network

Potential followups

@PabloLION PabloLION changed the title fix typo in 'runtime/src/ctx.ts' fix typo (or wrong implementation) in 'runtime/src/ctx.ts' Oct 2, 2022
@thdailong
Copy link
Contributor

This implementation should be right since global CallerApplicationID would return uint64
While global CurrentApplicationAddress return bytes which is address.
Is there anything wrong?

@PabloLION
Copy link
Contributor Author

PabloLION commented Oct 5, 2022

@thdailong Sorry that I made typo. I was trying to say global CurrentApplicationID instead of global CurrentApplicationAddress. I've edited the description.

Because the this.innerTxAppIDCallStack[this.innerTxAppIDCallStack.length - 1] returns the ID of the last App on AppCallStack, and the last app seems to be always the current app (callee of the inner transaction, not caller)

@thdailong
Copy link
Contributor

@PabloLION I have a check on that test and the application ID of the current app is 1828.
https://github.com/scale-it/algo-builder/blob/develop/packages/runtime/test/src/interpreter/opcode-list.ts#L2932-L2935
And yes, we set innerTxAppIDCallStack here
https://github.com/scale-it/algo-builder/blob/develop/packages/runtime/test/src/interpreter/opcode-list.ts#L3098
So it should be correct base on my understand

@PabloLION
Copy link
Contributor Author

Then I'm making an edge case here. I'll try to offer a MRE next week and reopen this. I close it for now.

@PabloLION PabloLION closed this Oct 5, 2022
@PabloLION
Copy link
Contributor Author

I've finished the MRE here

https://github.com/PabloLION/algo-builder-example/blob/f0ab2b3d50b7b1653f16438b67989f2fb0c13d80/test/caller-app-id.test.ts#L68-L69

run yarn then yarn algob test and you'll see that the expects (should fail) passes


During which, I noticed that

  1. the yarn run algob init --typescript is missing a parameter of path, like yarn run algob init --typescript .
  2. the ts-mocha (required by yarn algob test) was not installed by yarn run algob init --typescript.

Should I make a new fix-typo PR on this?

@PabloLION PabloLION reopened this Oct 5, 2022
@thdailong
Copy link
Contributor

Thanks for your suggestion. I am on the way find out why this error exist.

@PabloLION
Copy link
Contributor Author

@thdailong So the current version is at least incorrect👍. With the version of my PR, my MRE worked as intended (tho the test in this repo fails).

I tried to add a commit with resolutions overriding the @algo-builder/runtime, to use the version of my PR. But I can only build it locally and then use a local path in the resolutions. I don't know how this should be done. For now I guess you'd have to try it yourself🥲.

@thdailong
Copy link
Contributor

@PabloLION After, I assert the code carefully and check the source code. It is great to have person like contribute to our code. I will close this PR and create a new PR with that PR have update test. You can check: PR

@thdailong thdailong closed this Oct 11, 2022
@rmeena840 rmeena840 reopened this Oct 12, 2022
@rmeena840 rmeena840 changed the base branch from master to FixCallerAppID October 12, 2022 16:43
@thdailong thdailong closed this Oct 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants