Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Nov 7, 2024
1 parent afb5ca7 commit a716dbc
Showing 1 changed file with 45 additions and 48 deletions.
93 changes: 45 additions & 48 deletions yarn-project/end-to-end/src/e2e_fees/private_payments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,21 @@ describe('e2e_fees private_payment', () => {
await t.teardown();
});

let InitialSequencerL1Gas: bigint;
let initialSequencerL1Gas: bigint;

let InitialAlicePublicBananas: bigint;
let InitialAlicePrivateBananas: bigint;
let InitialAliceGas: bigint;
let initialAlicePublicBananas: bigint;
let initialAlicePrivateBananas: bigint;
let initialAliceGas: bigint;

// eslint-disable-next-line @typescript-eslint/no-unused-vars
let InitialBobPublicBananas: bigint;
let InitialBobPrivateBananas: bigint;
let initialBobPublicBananas: bigint;
let initialBobPrivateBananas: bigint;

let InitialFPCPublicBananas: bigint;
let InitialFPCPrivateBananas: bigint;
let InitialFPCGas: bigint;
let initialFPCPublicBananas: bigint;
let initialSequencerPrivateBananas: bigint;
let initialFPCGas: bigint;

let InitialSequencerGas: bigint;
let initialSequencerGas: bigint;

let maxFee: bigint;

Expand All @@ -59,14 +59,14 @@ describe('e2e_fees private_payment', () => {

expect(gasSettings.getFeeLimit().toBigInt()).toEqual(maxFee);

InitialSequencerL1Gas = await t.getCoinbaseBalance();
initialSequencerL1Gas = await t.getCoinbaseBalance();

[
[InitialAlicePrivateBananas, InitialBobPrivateBananas, InitialFPCPrivateBananas],
[InitialAlicePublicBananas, InitialBobPublicBananas, InitialFPCPublicBananas],
[InitialAliceGas, InitialFPCGas, InitialSequencerGas],
[initialAlicePrivateBananas, initialBobPrivateBananas, initialSequencerPrivateBananas],
[initialAlicePublicBananas, initialBobPublicBananas, initialFPCPublicBananas],
[initialAliceGas, initialFPCGas, initialSequencerGas],
] = await Promise.all([
t.getBananaPrivateBalanceFn(aliceAddress, bobAddress, bananaFPC.address),
t.getBananaPrivateBalanceFn(aliceAddress, bobAddress, sequencerAddress),
t.getBananaPublicBalanceFn(aliceAddress, bobAddress, bananaFPC.address),
t.getGasBalanceFn(aliceAddress, bananaFPC.address, sequencerAddress),
]);
Expand All @@ -82,25 +82,21 @@ describe('e2e_fees private_payment', () => {
* PRIVATE SETUP (1 nullifier for tx)
* check authwit (1 nullifier)
* reduce alice BC.private by MaxFee (1 nullifier)
* enqueue public call to increase FPC BC.public by MaxFee
* enqueue public call for fpc.pay_fee_with_shielded_rebate
* setup fee and refund partial notes
* setup public teardown call
*
* PRIVATE APP LOGIC
* reduce Alice's BC.private by transferAmount (1 note)
* create note for Bob of transferAmount (1 note)
* encrypted logs of 944 bytes
* unencrypted logs of 20 bytes
*
* PUBLIC SETUP
* increase FPC BC.public by MaxFee
*
* PUBLIC APP LOGIC
* N/A
*
* PUBLIC TEARDOWN
* call banana.shield
* decrease FPC BC.public by RefundAmount
* create transparent note with RefundAmount
* increase sequencer/fee recipient/FPC admin private banana balance by feeAmount by finalizing partial note
* increase Alice's private banana balance by feeAmount by finalizing partial note
*
* this is expected to squash notes and nullifiers
*/
Expand All @@ -113,7 +109,7 @@ describe('e2e_fees private_payment', () => {
bananaCoin.address,
bananaFPC.address,
aliceWallet,
t.sequencerAddress,
sequencerAddress,
),
},
};
Expand Down Expand Up @@ -150,23 +146,24 @@ describe('e2e_fees private_payment', () => {
}

// expect(tx.transactionFee).toEqual(200032492n);
await expect(t.getCoinbaseBalance()).resolves.toEqual(InitialSequencerL1Gas + tx.transactionFee!);
const [feeAmount, refundAmount] = getFeeAndRefund(tx);
await expect(t.getCoinbaseBalance()).resolves.toEqual(initialSequencerL1Gas + tx.transactionFee!);
const [feeAmount, _] = getFeeAndRefund(tx);

await expectMapping(
t.getBananaPrivateBalanceFn,
[aliceAddress, bobAddress, bananaFPC.address, sequencerAddress],
[InitialAlicePrivateBananas - maxFee - transferAmount, transferAmount, InitialFPCPrivateBananas, 0n],
);
await expectMapping(
t.getBananaPublicBalanceFn,
[aliceAddress, bananaFPC.address, sequencerAddress],
[InitialAlicePublicBananas, InitialFPCPublicBananas + maxFee - refundAmount, 0n],
[
initialAlicePrivateBananas - feeAmount - transferAmount,
transferAmount,
0n,
initialSequencerPrivateBananas + feeAmount,
],
);

await expectMapping(
t.getGasBalanceFn,
[aliceAddress, bananaFPC.address, sequencerAddress],
[InitialAliceGas, InitialFPCGas - feeAmount, InitialSequencerGas],
[initialAliceGas, initialFPCGas - feeAmount, initialSequencerGas],
);
});

Expand Down Expand Up @@ -202,7 +199,7 @@ describe('e2e_fees private_payment', () => {
bananaCoin.address,
bananaFPC.address,
aliceWallet,
t.sequencerAddress,
sequencerAddress,
),
},
})
Expand All @@ -213,17 +210,17 @@ describe('e2e_fees private_payment', () => {
await expectMapping(
t.getBananaPrivateBalanceFn,
[aliceAddress, bananaFPC.address, sequencerAddress],
[InitialAlicePrivateBananas - maxFee + newlyMintedBananas, InitialFPCPrivateBananas, 0n],
[initialAlicePrivateBananas - maxFee + newlyMintedBananas, 0n, initialSequencerPrivateBananas],
);
await expectMapping(
t.getBananaPublicBalanceFn,
[aliceAddress, bananaFPC.address, sequencerAddress],
[InitialAlicePublicBananas, InitialFPCPublicBananas + maxFee - refundAmount, 0n],
[initialAlicePublicBananas, initialFPCPublicBananas + maxFee - refundAmount, 0n],
);
await expectMapping(
t.getGasBalanceFn,
[aliceAddress, bananaFPC.address, sequencerAddress],
[InitialAliceGas, InitialFPCGas - feeAmount, InitialSequencerGas],
[initialAliceGas, initialFPCGas - feeAmount, initialSequencerGas],
);
});

Expand Down Expand Up @@ -262,7 +259,7 @@ describe('e2e_fees private_payment', () => {
bananaCoin.address,
bananaFPC.address,
aliceWallet,
t.sequencerAddress,
sequencerAddress,
),
},
})
Expand All @@ -273,17 +270,17 @@ describe('e2e_fees private_payment', () => {
await expectMapping(
t.getBananaPrivateBalanceFn,
[aliceAddress, bananaFPC.address, sequencerAddress],
[InitialAlicePrivateBananas - maxFee, InitialFPCPrivateBananas, 0n],
[initialAlicePrivateBananas - maxFee, 0n, initialSequencerPrivateBananas],
);
await expectMapping(
t.getBananaPublicBalanceFn,
[aliceAddress, bananaFPC.address, sequencerAddress],
[InitialAlicePublicBananas - shieldedBananas, InitialFPCPublicBananas + maxFee - refundAmount, 0n],
[initialAlicePublicBananas - shieldedBananas, initialFPCPublicBananas + maxFee - refundAmount, 0n],
);
await expectMapping(
t.getGasBalanceFn,
[aliceAddress, bananaFPC.address, sequencerAddress],
[InitialAliceGas, InitialFPCGas - feeAmount, InitialSequencerGas],
[initialAliceGas, initialFPCGas - feeAmount, initialSequencerGas],
);

await expect(
Expand Down Expand Up @@ -331,7 +328,7 @@ describe('e2e_fees private_payment', () => {
bananaCoin.address,
bananaFPC.address,
aliceWallet,
t.sequencerAddress,
sequencerAddress,
),
},
})
Expand All @@ -343,21 +340,21 @@ describe('e2e_fees private_payment', () => {
t.getBananaPrivateBalanceFn,
[aliceAddress, bobAddress, bananaFPC.address, sequencerAddress],
[
InitialAlicePrivateBananas - maxFee - privateTransfer,
InitialBobPrivateBananas + privateTransfer,
InitialFPCPrivateBananas,
initialAlicePrivateBananas - maxFee - privateTransfer,
initialBobPrivateBananas + privateTransfer,
0n,
initialSequencerPrivateBananas,
],
);
await expectMapping(
t.getBananaPublicBalanceFn,
[aliceAddress, bananaFPC.address, sequencerAddress],
[InitialAlicePublicBananas - shieldedBananas, InitialFPCPublicBananas + maxFee - refundAmount, 0n],
[initialAlicePublicBananas - shieldedBananas, initialFPCPublicBananas + maxFee - refundAmount, 0n],
);
await expectMapping(
t.getGasBalanceFn,
[aliceAddress, bananaFPC.address, sequencerAddress],
[InitialAliceGas, InitialFPCGas - feeAmount, InitialSequencerGas],
[initialAliceGas, initialFPCGas - feeAmount, initialSequencerGas],
);

await expect(
Expand All @@ -383,7 +380,7 @@ describe('e2e_fees private_payment', () => {
bananaCoin.address,
bankruptFPC.address,
aliceWallet,
t.sequencerAddress,
sequencerAddress,
),
},
})
Expand Down

0 comments on commit a716dbc

Please sign in to comment.