Skip to content

Commit

Permalink
attempt to update many tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lastmjs committed Jan 18, 2025
1 parent a5aec79 commit f4f5dce
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default Canister({
owner: ic.id(),
subaccount: [
padPrincipalWithZeros(
ic.caller().toUint8Array()
ic.msgCaller().toUint8Array()
)
]
}
Expand All @@ -58,7 +58,7 @@ export default Canister({
{
owner: ic.id(),
subaccount: Some(
padPrincipalWithZeros(ic.caller().toUint8Array())
padPrincipalWithZeros(ic.msgCaller().toUint8Array())
)
}
]
Expand All @@ -77,7 +77,7 @@ export default Canister({
owner: [ic.id()],
subaccount: [
padPrincipalWithZeros(
ic.caller().toUint8Array()
ic.msgCaller().toUint8Array()
)
]
}
Expand All @@ -94,7 +94,7 @@ export default Canister({
{
owner: Some(ic.id()),
subaccount: Some(
padPrincipalWithZeros(ic.caller().toUint8Array())
padPrincipalWithZeros(ic.msgCaller().toUint8Array())
)
}
]
Expand All @@ -113,7 +113,7 @@ export default Canister({
owner: [ic.id()],
subaccount: [
padPrincipalWithZeros(
ic.caller().toUint8Array()
ic.msgCaller().toUint8Array()
)
]
}
Expand All @@ -130,7 +130,7 @@ export default Canister({
{
owner: Some(ic.id()),
subaccount: Some(
padPrincipalWithZeros(ic.caller().toUint8Array())
padPrincipalWithZeros(ic.msgCaller().toUint8Array())
)
}
]
Expand All @@ -151,7 +151,7 @@ export default Canister({
{
from_subaccount: [
padPrincipalWithZeros(
ic.caller().toUint8Array()
ic.msgCaller().toUint8Array()
)
],
to: {
Expand Down Expand Up @@ -182,7 +182,7 @@ export default Canister({
{
from_subaccount: Some(
padPrincipalWithZeros(
ic.caller().toUint8Array()
ic.msgCaller().toUint8Array()
)
),
to: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default Canister({
),
// returns the principal of the identity that called this function
caller: query([], Principal, () => {
return ic.caller();
return ic.msgCaller();
}),
// returns the amount of cycles available in the canister
canisterBalance: query([], nat, () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default Canister({
});

async function getPublicKeyResult(): Promise<any> {
const caller = ic.caller().toUint8Array();
const caller = ic.msgCaller().toUint8Array();

if (process.env.AZLE_TEST_FETCH === 'true') {
const publicKeyResponse = await fetch(
Expand Down Expand Up @@ -77,7 +77,7 @@ async function getPublicKeyResult(): Promise<any> {
}

async function getSignatureResult(messageHash: Uint8Array): Promise<any> {
const caller = ic.caller().toUint8Array();
const caller = ic.msgCaller().toUint8Array();

if (process.env.AZLE_TEST_FETCH === 'true') {
const publicKeyResponse = await fetch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ let someone: Principal = Principal.fromText('aaaaa-aa');
const WhoAmI = Canister({
// Manually save the calling principal and argument for later access.
init: init([Principal], (somebody) => {
install = ic.caller();
install = ic.msgCaller();
someone = somebody;
}),
// Manually re-save these variables after new deploys.
postUpgrade: postUpgrade([Principal], (somebody) => {
install = ic.caller();
install = ic.msgCaller();
someone = somebody;
}),
// Return the principal identifier of the wallet canister that installed this
Expand All @@ -36,7 +36,7 @@ const WhoAmI = Canister({
}),
// Return the principal identifier of the caller of this method.
whoami: update([], Principal, () => {
return ic.caller();
return ic.msgCaller();
}),
// Return the principal identifier of this canister.
id: update([], Principal, async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ app.use(express.json());
app.get('/caller-address', async (_req, res) => {
const wallet = new ThresholdWallet(
{
derivationPath: [ic.caller().toUint8Array()]
derivationPath: [ic.msgCaller().toUint8Array()]
},
ethers.getDefaultProvider('https://sepolia.base.org')
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ app.get('/headers-array', (req, res) => {
res.setHeader('X-Azle-Response-Key-2', 'X-Azle-Response-Value-2');

res.json({
whoami: ic.caller().toString(),
whoami: ic.msgCaller().toString(),
value: req.headers
});
});
Expand All @@ -22,7 +22,7 @@ app.get('/headers-object', (req, res) => {
res.setHeader('X-Azle-Response-Key-2', 'X-Azle-Response-Value-2');

res.json({
whoami: ic.caller().toString(),
whoami: ic.msgCaller().toString(),
value: req.headers
});
});
Expand All @@ -33,7 +33,7 @@ app.post('/body-uint8array', (req, res) => {
res.setHeader('X-Azle-Response-Key-2', 'X-Azle-Response-Value-2');

res.json({
whoami: ic.caller().toString(),
whoami: ic.msgCaller().toString(),
value: req.body
});
});
Expand All @@ -44,7 +44,7 @@ app.put('/body-string', (req, res) => {
res.setHeader('X-Azle-Response-Key-2', 'X-Azle-Response-Value-2');

res.json({
whoami: ic.caller().toString(),
whoami: ic.msgCaller().toString(),
value: req.body
});
});
Expand All @@ -55,7 +55,7 @@ app.patch('/body-array-buffer', (req, res) => {
res.setHeader('X-Azle-Response-Key-2', 'X-Azle-Response-Value-2');

res.json({
whoami: ic.caller().toString(),
whoami: ic.msgCaller().toString(),
value: req.body
});
});
Expand All @@ -66,7 +66,7 @@ app.delete('/body-blob', (req, res) => {
res.setHeader('X-Azle-Response-Key-2', 'X-Azle-Response-Value-2');

res.json({
whoami: ic.caller().toString(),
whoami: ic.msgCaller().toString(),
value: req.body
});
});
Expand All @@ -77,7 +77,7 @@ app.post('/body-data-view', (req, res) => {
res.setHeader('X-Azle-Response-Key-2', 'X-Azle-Response-Value-2');

res.json({
whoami: ic.caller().toString(),
whoami: ic.msgCaller().toString(),
value: req.body
});
});
Expand All @@ -88,7 +88,7 @@ app.get('/url-query-params-get', (req, res) => {
res.setHeader('X-Azle-Response-Key-2', 'X-Azle-Response-Value-2');

res.json({
whoami: ic.caller().toString(),
whoami: ic.msgCaller().toString(),
value: req.query
});
});
Expand All @@ -99,7 +99,7 @@ app.post('/url-query-params-post', (req, res) => {
res.setHeader('X-Azle-Response-Key-2', 'X-Azle-Response-Value-2');

res.json({
whoami: ic.caller().toString(),
whoami: ic.msgCaller().toString(),
value: req.query
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ app.use(express.json());

app.get('/caller-address', async (_req, res) => {
const address = ethers.computeAddress(
ethers.hexlify(await ecdsaPublicKey([ic.caller().toUint8Array()]))
ethers.hexlify(await ecdsaPublicKey([ic.msgCaller().toUint8Array()]))
);

res.send(address);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import express from 'express';
const app = express();

app.get('/whoami', (req, res) => {
res.send(ic.caller().toString());
res.send(ic.msgCaller().toString());
});

app.use(express.static('/dist'));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// TODO we should pull the wallet out into its own repo

import {
caller,
IDL,
msgCaller,
msgCyclesAccept,
msgCyclesAvailable,
Principal,
Expand Down Expand Up @@ -58,7 +58,7 @@ export default class {
console.info(`cycles available: ${msgCyclesAvailable()}`);

const callerInWhitelist = this.principalsWhitelist.includes(
caller().toText()
msgCaller().toText()
);

if (callerInWhitelist === true) {
Expand All @@ -69,7 +69,7 @@ export default class {
this.payments.push({
time: time(),
amount: cyclesAvailable,
principal: caller()
principal: msgCaller()
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ function generateInspectMessageMethodBody(): string {
const returnPrincipal = getPrincipal(AZLE_RETURN_IDENTITY_NAME);
const throwPrincipal = getPrincipal(AZLE_THROW_IDENTITY_NAME);
return `
if (ic.caller().toText() === "${acceptPrincipal}") {
if (ic.msgCaller().toText() === "${acceptPrincipal}") {
ic.acceptMessage();
return;
}
if (ic.caller().toText() === "${returnPrincipal}") {
if (ic.msgCaller().toText() === "${returnPrincipal}") {
return;
}
if (ic.caller().toText() === "${throwPrincipal}") {
if (ic.msgCaller().toText() === "${throwPrincipal}") {
throw new Error(\`Method "$\{ic.methodName()}" not allowed\`);
}
throw new Error("Unexpected caller");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { call, caller, IDL, trap, update } from 'azle';
import { call, IDL, msgCaller, trap, update } from 'azle';
import {
ecdsa_public_key_args,
ecdsa_public_key_result,
Expand Down Expand Up @@ -54,7 +54,7 @@ async function getPublicKeyResult(): Promise<ecdsa_public_key_result> {
args: [
{
canister_id: [],
derivation_path: [caller().toUint8Array()],
derivation_path: [msgCaller().toUint8Array()],
key_id: {
curve: { secp256k1: null },
name: 'dfx_test_key'
Expand All @@ -77,7 +77,7 @@ async function getSignatureResult(
args: [
{
message_hash: messageHash,
derivation_path: [caller().toUint8Array()],
derivation_path: [msgCaller().toUint8Array()],
key_id: {
curve: { secp256k1: null },
name: 'dfx_test_key'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
import {
call,
caller,
id,
IDL,
init,
msgCaller,
postUpgrade,
Principal,
query,
update
} from 'azle';

class WhoAmI {
// We use the zero principal but any principal could be used.
install: Principal = Principal.fromText('aaaaa-aa');
someone: Principal = Principal.fromText('aaaaa-aa');

// Manually save the calling principal and argument for later access.
@init([IDL.Principal])
init(somebody: Principal): void {
this.install = caller();
this.install = msgCaller();
this.someone = somebody;
}

// Manually re-save these variables after new deploys.
@postUpgrade([IDL.Principal])
postUpgrade(somebody: Principal): void {
this.install = caller();
this.install = msgCaller();
this.someone = somebody;
}

Expand All @@ -46,7 +45,7 @@ class WhoAmI {
// Return the principal identifier of the caller of this method.
@update([], IDL.Principal)
whoami(): Principal {
return caller();
return msgCaller();
}

// Return the principal identifier of this canister.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ function generateInspectMessageMethodBody(): string {
const returnPrincipal = getPrincipal(AZLE_RETURN_IDENTITY_NAME);
const throwPrincipal = getPrincipal(AZLE_THROW_IDENTITY_NAME);
return `
if (caller().toText() === "${acceptPrincipal}") {
if (msgCaller().toText() === "${acceptPrincipal}") {
acceptMessage();
return;
}
if (caller().toText() === "${returnPrincipal}") {
if (msgCaller().toText() === "${returnPrincipal}") {
return;
}
if (caller().toText() === "${throwPrincipal}") {
if (msgCaller().toText() === "${throwPrincipal}") {
throw new Error(\`Method "$\{methodName()}" not allowed\`);
}
throw new Error("Unexpected caller");
Expand Down

0 comments on commit f4f5dce

Please sign in to comment.