Motoko interpreter determines caller incorrectly
reginleif888 opened this issue · comments
Problem statement: The interpreter determines the caller incorrectly if the call is made not from the actor directly, but inside the object that the actor uses. In a call made from an object, the caller is always ID:0
Command used: moc -r
Motoko version: 0.11.1
Code:
import Debug "mo:base/Debug";
import Principal "mo:base/Principal";
import Text "mo:base/Text";
actor exampleActor {
public shared (msg) func printCaller() : async () {
Debug.print("caller: " # debug_show Text.decodeUtf8(Principal.toBlob(msg.caller)));
};
};
class ExampleClass() {
public func exampleMethod() : async* () {
await exampleActor.printCaller();
};
};
actor agent = {
public func test() : async () {
let example : ExampleClass = ExampleClass();
let agentPrincipal = Principal.fromActor(agent);
Debug.print("agent: " # debug_show Text.decodeUtf8(Principal.toBlob(agentPrincipal)));
await exampleActor.printCaller();
await* example.exampleMethod();
};
};
await agent.test();
Actual output:
agent: ?"ID:2"
caller: ?"ID:2"
caller: ?"ID:0"
Expected output:
agent: ?"ID:2"
caller: ?"ID:2"
caller: ?"ID:2"
If we move the definition of ExampleClass
inside the agent
actor then it works (not surprising).
Would be nice to get this fixed in the interpreter.
Yeah, that looks like a bug. Thanks for reporting it! I would regard this as low priority, since the IC doesn't support multiple actors in the same canister.
How important is the fix to you?
It's low priority. Thanks!