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: return DecodedReturn instead of any[] #1540

Merged
merged 6 commits into from
Aug 14, 2023
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 yarn-project/acir-simulator/src/client/execution_result.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { PrivateCallStackItem, PublicCallRequest, ReadRequestMembershipWitness } from '@aztec/circuits.js';
import { DecodedReturn } from '@aztec/foundation/abi';
import { Fr } from '@aztec/foundation/fields';
import { FunctionL2Logs } from '@aztec/types';

Expand Down Expand Up @@ -56,7 +57,7 @@ export interface ExecutionResult {
/** The preimages of the executed function. */
preimages: ExecutionPreimages;
/** The decoded return values of the executed function. */
returnValues: any[];
returnValues: DecodedReturn;
/** The nested executions. */
nestedExecutions: this[];
/** Enqueued public function execution requests to be picked up by the sequencer. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,7 @@ describe('Private Execution test suite', () => {
it('gets the public key for an address', async () => {
// Tweak the contract ABI so we can extract return values
const abi = TestContractAbi.functions.find(f => f.name === 'getPublicKey')!;
abi.returnTypes = [{ kind: 'field' }, { kind: 'field' }];
abi.returnTypes = [{ kind: 'array', length: 2, type: { kind: 'field' } }];

// Generate a partial address, pubkey, and resulting address
const partialAddress = Fr.random();
Expand Down Expand Up @@ -1043,7 +1043,7 @@ describe('Private Execution test suite', () => {
// Overwrite the oracle return value
oracle.getPortalContractAddress.mockResolvedValue(portalContractAddress);
const result = await runSimulator({ origin: AztecAddress.random(), abi, args });
expect(result.returnValues).toEqual([portalContractAddress.toField().value]);
expect(result.returnValues).toEqual(portalContractAddress.toField().value);
});

it('this_address should return the current context address', async () => {
Expand All @@ -1055,7 +1055,7 @@ describe('Private Execution test suite', () => {

// Overwrite the oracle return value
const result = await runSimulator({ origin: AztecAddress.random(), abi, args: [], contractAddress });
expect(result.returnValues).toEqual([contractAddress.toField().value]);
expect(result.returnValues).toEqual(contractAddress.toField().value);
});

it("this_portal_address should return the current context's portal address", async () => {
Expand All @@ -1067,7 +1067,7 @@ describe('Private Execution test suite', () => {

// Overwrite the oracle return value
const result = await runSimulator({ origin: AztecAddress.random(), abi, args: [], portalContractAddress });
expect(result.returnValues).toEqual([portalContractAddress.toField().value]);
expect(result.returnValues).toEqual(portalContractAddress.toField().value);
});
});
});
4 changes: 2 additions & 2 deletions yarn-project/acir-simulator/src/client/simulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,13 @@ export class AcirSimulator {
args: encodeArguments(abi, [contractAddress, nonce, storageSlot, extendedPreimage]),
};

const [[innerNoteHash, siloedNoteHash, uniqueSiloedNoteHash, innerNullifier]] = await this.runUnconstrained(
const [innerNoteHash, siloedNoteHash, uniqueSiloedNoteHash, innerNullifier] = (await this.runUnconstrained(
execRequest,
AztecAddress.ZERO,
abi,
AztecAddress.ZERO,
EthAddress.ZERO,
);
)) as bigint[];

return {
innerNoteHash: new Fr(innerNoteHash),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ describe('Unconstrained Execution test suite', () => {
EthAddress.ZERO,
);

expect(result).toEqual([9n]);
expect(result).toEqual(9n);
}, 30_000);
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CallContext, FunctionData } from '@aztec/circuits.js';
import { FunctionAbi, decodeReturnValues } from '@aztec/foundation/abi';
import { DecodedReturn, FunctionAbi, decodeReturnValues } from '@aztec/foundation/abi';
import { AztecAddress } from '@aztec/foundation/aztec-address';
import { Fr } from '@aztec/foundation/fields';
import { createDebugLogger } from '@aztec/foundation/log';
Expand Down Expand Up @@ -30,7 +30,7 @@ export class UnconstrainedFunctionExecution {
* @param aztecNode - The aztec node.
* @returns The return values of the executed function.
*/
public async run(aztecNode?: AztecNode): Promise<any[]> {
public async run(aztecNode?: AztecNode): Promise<DecodedReturn> {
this.log(
`Executing unconstrained function ${this.contractAddress.toShortString()}:${this.functionData.functionSelectorBuffer.toString(
'hex',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ async function deployZKContract(owner: AztecAddress) {
* @returns The owner's current balance of the token.
*/
async function getBalance(contract: Contract, ownerAddress: AztecAddress) {
const [balance] = await contract.methods.getBalance(ownerAddress).view({ from: ownerAddress });
return balance;
return await contract.methods.getBalance(ownerAddress).view({ from: ownerAddress });
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@ async function deployAllContracts(owner: AztecAddress) {
}

const getL2BalanceOf = async (aztecRpcClient: AztecRPC, owner: AztecAddress, l2Contract: NonNativeTokenContract) => {
const [balance] = await l2Contract.methods.getBalance(owner).view({ from: owner });
return balance;
return await l2Contract.methods.getBalance(owner).view({ from: owner });
};

const logExpectedBalanceOnL2 = async (
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec.js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ console.log(`Transferred ${amount} to ${recipientAddress}!`);
import { Contract } from '@aztec/aztec.js';

const contract = await Contract.create(contractAddress, contractAbi, aztecRpcServer);
const [balance] = contract.methods
const balance = contract.methods
.getBalance(accountPublicKey))
.view({ from: accountAddress });
console.log(`Account balance: ${balance}.`);
Expand Down
8 changes: 5 additions & 3 deletions yarn-project/canary/src/uniswap_trade_on_l1_from_l2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,11 @@ async function deployAllContracts(
};
}

const getL2BalanceOf = async (owner: AztecAddress, l2Contract: NonNativeTokenContract) => {
const [balance] = await l2Contract.methods.getBalance(owner).view({ from: owner });
return balance;
const getL2BalanceOf = async (
owner: AztecAddress,
l2Contract: NonNativeTokenContract
) => {
return await l2Contract.methods.getBalance(owner).view({ from: owner });
};

const expectBalanceOnL2 = async (owner: AztecAddress, expectedBalance: bigint, l2Contract: NonNativeTokenContract) => {
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/end-to-end/src/e2e_2_rpc_servers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe('e2e_2_rpc_servers', () => {

// Then check the balance
const contractWithWallet = await PrivateTokenContract.create(tokenAddress, wallet);
const [balance] = await contractWithWallet.methods.getBalance(owner).view({ from: owner });
const balance = await contractWithWallet.methods.getBalance(owner).view({ from: owner });
logger(`Account ${owner} balance: ${balance}`);
expect(balance).toBe(expectedBalance);
};
Expand Down
5 changes: 2 additions & 3 deletions yarn-project/end-to-end/src/e2e_aztec_js_browser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ conditionalDescribe()('e2e_aztec.js_browser', () => {
PrivateTokenContractAbi,
wallet,
);
const [balance] = await contract.methods.getBalance(owner).view({ from: owner });
const balance = await contract.methods.getBalance(owner).view({ from: owner });
return balance;
},
SANDBOX_URL,
Expand Down Expand Up @@ -187,8 +187,7 @@ conditionalDescribe()('e2e_aztec.js_browser', () => {
);
await contract.methods.transfer(transferAmount, owner, receiver).send({ origin: owner }).wait();
console.log(`Transfered ${transferAmount} tokens to new Account`);
const [balance] = await contract.methods.getBalance(receiver).view({ from: receiver });
return balance;
return await contract.methods.getBalance(receiver).view({ from: receiver });
},
SANDBOX_URL,
privKey.toString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe('e2e_cross_chain_messaging', () => {
});

const expectBalance = async (owner: AztecAddress, expectedBalance: bigint) => {
const [balance] = await l2Contract.methods.getBalance(owner).view({ from: owner });
const balance = await l2Contract.methods.getBalance(owner).view({ from: owner });
logger(`Account ${owner} balance: ${balance}`);
expect(balance).toBe(expectedBalance);
};
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/end-to-end/src/e2e_escrow_contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('e2e_escrow_contract', () => {
}, 30_000);

const expectBalance = async (who: AztecAddress, expectedBalance: bigint) => {
const [balance] = await privateTokenContract.methods.getBalance(who).view({ from: who });
const balance = await privateTokenContract.methods.getBalance(who).view({ from: who });
logger(`Account ${who} balance: ${balance}`);
expect(balance).toBe(expectedBalance);
};
Expand Down
62 changes: 30 additions & 32 deletions yarn-project/end-to-end/src/e2e_lending_contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,17 @@ describe('e2e_lending_contract', () => {
const getStorageSnapshot = async (contract: LendingContract, aztecNode: AztecRPC, account: Account) => {
const storageValues: { [key: string]: Fr } = {};
const accountKey = await account.key();
const toFields = (res: any[]) => res[0].map((v: number | bigint | Fr) => new Fr(v));

[storageValues['interestAccumulator'], storageValues['last_updated_ts']] = toFields(
await contract.methods.getTot(0).view(),
);
const tot = await contract.methods.getTot(0).view();
const privatePos = await contract.methods.getPosition(accountKey).view();
const publicPos = await contract.methods.getPosition(account.address.toField()).view();

[storageValues['private_collateral'], storageValues['private_debt']] = toFields(
await contract.methods.getPosition(accountKey).view(),
);

[storageValues['public_collateral'], storageValues['public_debt']] = toFields(
await contract.methods.getPosition(account.address.toField()).view(),
);
storageValues['interest_accumulator'] = new Fr(tot['interest_accumulator']);
storageValues['last_updated_ts'] = new Fr(tot['last_updated_ts']);
storageValues['private_collateral'] = new Fr(privatePos['collateral']);
storageValues['private_debt'] = new Fr(privatePos['static_debt']);
storageValues['public_collateral'] = new Fr(publicPos['collateral']);
storageValues['public_debt'] = new Fr(publicPos['static_debt']);

return storageValues;
};
Expand Down Expand Up @@ -103,7 +101,7 @@ describe('e2e_lending_contract', () => {
expect(receipt.status).toBe(TxStatus.MINED);
storageSnapshots['initial'] = await getStorageSnapshot(deployedContract, aztecRpcServer, account);

expect(storageSnapshots['initial']['interestAccumulator']).toEqual(new Fr(1000000000n));
expect(storageSnapshots['initial']['interest_accumulator']).toEqual(new Fr(1000000000n));
expect(storageSnapshots['initial']['last_updated_ts'].value).toBeGreaterThan(0n);
}

Expand All @@ -121,8 +119,8 @@ describe('e2e_lending_contract', () => {
storageSnapshots['private_deposit'] = await getStorageSnapshot(deployedContract, aztecRpcServer, account);

// @todo The accumulator should not increase when there are no debt. But we don't have reads/writes enough right now to handle that.
expect(storageSnapshots['private_deposit']['interestAccumulator'].value).toBeGreaterThan(
storageSnapshots['initial']['interestAccumulator'].value,
expect(storageSnapshots['private_deposit']['interest_accumulator'].value).toBeGreaterThan(
storageSnapshots['initial']['interest_accumulator'].value,
);
expect(storageSnapshots['private_deposit']['last_updated_ts'].value).toBeGreaterThan(
storageSnapshots['initial']['last_updated_ts'].value,
Expand All @@ -147,8 +145,8 @@ describe('e2e_lending_contract', () => {
account,
);

expect(storageSnapshots['private_deposit_on_behalf']['interestAccumulator'].value).toBeGreaterThan(
storageSnapshots['private_deposit']['interestAccumulator'].value,
expect(storageSnapshots['private_deposit_on_behalf']['interest_accumulator'].value).toBeGreaterThan(
storageSnapshots['private_deposit']['interest_accumulator'].value,
);
expect(storageSnapshots['private_deposit_on_behalf']['last_updated_ts'].value).toBeGreaterThan(
storageSnapshots['private_deposit']['last_updated_ts'].value,
Expand All @@ -173,8 +171,8 @@ describe('e2e_lending_contract', () => {
expect(receipt.status).toBe(TxStatus.MINED);
storageSnapshots['public_deposit'] = await getStorageSnapshot(deployedContract, aztecRpcServer, account);

expect(storageSnapshots['public_deposit']['interestAccumulator'].value).toBeGreaterThan(
storageSnapshots['private_deposit_on_behalf']['interestAccumulator'].value,
expect(storageSnapshots['public_deposit']['interest_accumulator'].value).toBeGreaterThan(
storageSnapshots['private_deposit_on_behalf']['interest_accumulator'].value,
);
expect(storageSnapshots['public_deposit']['last_updated_ts'].value).toBeGreaterThan(
storageSnapshots['private_deposit_on_behalf']['last_updated_ts'].value,
Expand All @@ -201,8 +199,8 @@ describe('e2e_lending_contract', () => {
expect(receipt.status).toBe(TxStatus.MINED);
storageSnapshots['private_borrow'] = await getStorageSnapshot(deployedContract, aztecRpcServer, account);

expect(storageSnapshots['private_borrow']['interestAccumulator'].value).toBeGreaterThan(
storageSnapshots['public_deposit']['interestAccumulator'].value,
expect(storageSnapshots['private_borrow']['interest_accumulator'].value).toBeGreaterThan(
storageSnapshots['public_deposit']['interest_accumulator'].value,
);
expect(storageSnapshots['private_borrow']['last_updated_ts'].value).toBeGreaterThan(
storageSnapshots['public_deposit']['last_updated_ts'].value,
Expand Down Expand Up @@ -230,8 +228,8 @@ describe('e2e_lending_contract', () => {
expect(receipt.status).toBe(TxStatus.MINED);
storageSnapshots['public_borrow'] = await getStorageSnapshot(deployedContract, aztecRpcServer, account);

expect(storageSnapshots['public_borrow']['interestAccumulator'].value).toBeGreaterThan(
storageSnapshots['private_borrow']['interestAccumulator'].value,
expect(storageSnapshots['public_borrow']['interest_accumulator'].value).toBeGreaterThan(
storageSnapshots['private_borrow']['interest_accumulator'].value,
);
expect(storageSnapshots['public_borrow']['last_updated_ts'].value).toBeGreaterThan(
storageSnapshots['private_borrow']['last_updated_ts'].value,
Expand Down Expand Up @@ -262,8 +260,8 @@ describe('e2e_lending_contract', () => {
expect(receipt.status).toBe(TxStatus.MINED);
storageSnapshots['private_repay'] = await getStorageSnapshot(deployedContract, aztecRpcServer, account);

expect(storageSnapshots['private_repay']['interestAccumulator'].value).toBeGreaterThan(
storageSnapshots['public_borrow']['interestAccumulator'].value,
expect(storageSnapshots['private_repay']['interest_accumulator'].value).toBeGreaterThan(
storageSnapshots['public_borrow']['interest_accumulator'].value,
);
expect(storageSnapshots['private_repay']['last_updated_ts'].value).toBeGreaterThan(
storageSnapshots['public_borrow']['last_updated_ts'].value,
Expand Down Expand Up @@ -296,8 +294,8 @@ describe('e2e_lending_contract', () => {
expect(receipt.status).toBe(TxStatus.MINED);
storageSnapshots['private_repay_on_behalf'] = await getStorageSnapshot(deployedContract, aztecRpcServer, account);

expect(storageSnapshots['private_repay_on_behalf']['interestAccumulator'].value).toBeGreaterThan(
storageSnapshots['private_repay']['interestAccumulator'].value,
expect(storageSnapshots['private_repay_on_behalf']['interest_accumulator'].value).toBeGreaterThan(
storageSnapshots['private_repay']['interest_accumulator'].value,
);
expect(storageSnapshots['private_repay_on_behalf']['last_updated_ts'].value).toBeGreaterThan(
storageSnapshots['private_repay']['last_updated_ts'].value,
Expand Down Expand Up @@ -330,8 +328,8 @@ describe('e2e_lending_contract', () => {
expect(receipt.status).toBe(TxStatus.MINED);
storageSnapshots['public_repay'] = await getStorageSnapshot(deployedContract, aztecRpcServer, account);

expect(storageSnapshots['public_repay']['interestAccumulator'].value).toBeGreaterThan(
storageSnapshots['private_repay_on_behalf']['interestAccumulator'].value,
expect(storageSnapshots['public_repay']['interest_accumulator'].value).toBeGreaterThan(
storageSnapshots['private_repay_on_behalf']['interest_accumulator'].value,
);
expect(storageSnapshots['public_repay']['last_updated_ts'].value).toBeGreaterThan(
storageSnapshots['private_repay_on_behalf']['last_updated_ts'].value,
Expand Down Expand Up @@ -364,8 +362,8 @@ describe('e2e_lending_contract', () => {
expect(receipt.status).toBe(TxStatus.MINED);
storageSnapshots['public_withdraw'] = await getStorageSnapshot(deployedContract, aztecRpcServer, account);

expect(storageSnapshots['public_withdraw']['interestAccumulator'].value).toBeGreaterThan(
storageSnapshots['public_repay']['interestAccumulator'].value,
expect(storageSnapshots['public_withdraw']['interest_accumulator'].value).toBeGreaterThan(
storageSnapshots['public_repay']['interest_accumulator'].value,
);
expect(storageSnapshots['public_withdraw']['last_updated_ts'].value).toBeGreaterThan(
storageSnapshots['public_repay']['last_updated_ts'].value,
Expand Down Expand Up @@ -398,8 +396,8 @@ describe('e2e_lending_contract', () => {
expect(receipt.status).toBe(TxStatus.MINED);
storageSnapshots['private_withdraw'] = await getStorageSnapshot(deployedContract, aztecRpcServer, account);

expect(storageSnapshots['private_withdraw']['interestAccumulator'].value).toBeGreaterThan(
storageSnapshots['public_withdraw']['interestAccumulator'].value,
expect(storageSnapshots['private_withdraw']['interest_accumulator'].value).toBeGreaterThan(
storageSnapshots['public_withdraw']['interest_accumulator'].value,
);
expect(storageSnapshots['private_withdraw']['last_updated_ts'].value).toBeGreaterThan(
storageSnapshots['public_withdraw']['last_updated_ts'].value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe('e2e_multiple_accounts_1_enc_key', () => {

// Then check the balance
const contractWithWallet = await PrivateTokenContract.create(privateTokenAddress, wallet);
const [balance] = await contractWithWallet.methods.getBalance(owner).view({ from: owner });
const balance = await contractWithWallet.methods.getBalance(owner).view({ from: owner });
logger(`Account ${owner} balance: ${balance}`);
expect(balance).toBe(expectedBalance);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('e2e_non_contract_account', () => {
});

const expectBalance = async (owner: AztecAddress, expectedBalance: bigint) => {
const [balance] = await contract.methods.getBalance(owner).view({ from: owner });
const balance = await contract.methods.getBalance(owner).view({ from: owner });
logger(`Account ${owner} balance: ${balance}`);
expect(balance).toBe(expectedBalance);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('e2e_private_token_contract', () => {
});

const expectBalance = async (owner: AztecAddress, expectedBalance: bigint) => {
const [balance] = await contract.methods.getBalance(owner).view({ from: owner });
const balance = await contract.methods.getBalance(owner).view({ from: owner });
logger(`Account ${owner} balance: ${balance}`);
expect(balance).toBe(expectedBalance);
};
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/end-to-end/src/e2e_public_token_contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe('e2e_public_token_contract', () => {

expect(receipt.status).toBe(TxStatus.MINED);

const balance = (await contract.methods.publicBalanceOf(recipient.toField()).view({ from: recipient }))[0];
const balance = await contract.methods.publicBalanceOf(recipient.toField()).view({ from: recipient });
expect(balance).toBe(mintAmount);

await expectLogsFromLastBlockToBe(['Coins minted']);
Expand All @@ -91,7 +91,7 @@ describe('e2e_public_token_contract', () => {
expect(receipts.map(r => r.status)).toEqual(times(3, () => TxStatus.MINED));
expect(receipts.map(r => r.blockNumber)).toEqual(times(3, () => receipts[0].blockNumber));

const balance = (await contract.methods.publicBalanceOf(recipient.toField()).view({ from: recipient }))[0];
const balance = await contract.methods.publicBalanceOf(recipient.toField()).view({ from: recipient });
expect(balance).toBe(mintAmount * 3n);

await expectLogsFromLastBlockToBe(['Coins minted', 'Coins minted', 'Coins minted']);
Expand Down
Loading