Skip to content

Commit

Permalink
chore: minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
LHerskind committed Aug 2, 2023
1 parent 42be3e0 commit 2a13836
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 37 deletions.
21 changes: 8 additions & 13 deletions yarn-project/end-to-end/src/e2e_lending_contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ describe('e2e_lending_contract', () => {

// Fetch a storage snapshot from the contract that we can use to compare between transitions.
const getStorageSnapshot = async (contract: Contract, aztecNode: AztecRPC, account: Account) => {
const loadPublicStorageInMap = async (slot: Fr | bigint, key: Fr | bigint) => {
return await cc.l2.loadPublic(contract.address, cc.l2.computeSlotInMap(slot, key));
};

const storageValues: { [key: string]: any } = {};
{
const baseSlot = cc.l2.computeSlotInMap(1n, 0n);
Expand All @@ -56,19 +60,10 @@ describe('e2e_lending_contract', () => {

const accountKey = await account.key();

storageValues['private_collateral'] = await cc.l2.loadPublic(
contract.address,
cc.l2.computeSlotInMap(2n, accountKey),
);
storageValues['public_collateral'] = await cc.l2.loadPublic(
contract.address,
cc.l2.computeSlotInMap(2n, account.address.toField()),
);
storageValues['private_debt'] = await cc.l2.loadPublic(contract.address, cc.l2.computeSlotInMap(3n, accountKey));
storageValues['public_debt'] = await cc.l2.loadPublic(
contract.address,
cc.l2.computeSlotInMap(3n, account.address.toField()),
);
storageValues['private_collateral'] = await loadPublicStorageInMap(2n, accountKey);
storageValues['public_collateral'] = await loadPublicStorageInMap(2n, account.address.toField());
storageValues['private_debt'] = await loadPublicStorageInMap(3n, accountKey);
storageValues['public_debt'] = await loadPublicStorageInMap(3n, account.address.toField());

return storageValues;
};
Expand Down
25 changes: 1 addition & 24 deletions yarn-project/end-to-end/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@ import {
getL1ContractAddresses,
} from '@aztec/aztec.js';
import {
CircuitsWasm,
DeploymentInfo,
PartialContractAddress,
PrivateKey,
PublicKey,
getContractDeploymentInfo,
} from '@aztec/circuits.js';
import { Schnorr, pedersenPlookupCommitInputs } from '@aztec/circuits.js/barretenberg';
import { Schnorr } from '@aztec/circuits.js/barretenberg';
import { DeployL1Contracts, deployL1Contract, deployL1Contracts } from '@aztec/ethereum';
import { ContractAbi } from '@aztec/foundation/abi';
import { Fr } from '@aztec/foundation/fields';
Expand Down Expand Up @@ -518,28 +517,6 @@ export function delay(ms: number): Promise<void> {
return new Promise<void>(resolve => setTimeout(resolve, ms));
}

/**
* Calculates the slot value of a mapping within noir.
* @param slot - The storage slot of the mapping.
* @param key - The key within the mapping.
* @returns The mapping's key.
*/
export async function calculateAztecStorageSlot(slot: bigint, key: Fr): Promise<Fr> {
const wasm = await CircuitsWasm.get();
const mappingStorageSlot = new Fr(slot); // this value is manually set in the Noir contract

// Based on `at` function in
// aztec3-packages/yarn-project/noir-contracts/src/contracts/noir-aztec/src/state_vars/map.nr
const storageSlot = Fr.fromBuffer(
pedersenPlookupCommitInputs(
wasm,
[mappingStorageSlot, key].map(f => f.toBuffer()),
),
);

return storageSlot; //.value;
}

/**
* Checks the number of encrypted logs in the last block is as expected.
* @param aztecNode - The instance of aztec node for retrieving the logs.
Expand Down

0 comments on commit 2a13836

Please sign in to comment.