Skip to content

Commit

Permalink
calculate balance differences
Browse files Browse the repository at this point in the history
Signed-off-by: Jim Zhang <[email protected]>
  • Loading branch information
jimthematrix committed Aug 27, 2024
1 parent 6fb652c commit f8b7cc9
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 26 deletions.
11 changes: 7 additions & 4 deletions solidity/test/zeto_anon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,11 @@ describe("Zeto based fungible token with anonymity without encryption or nullifi
});

it("mint ERC20 tokens to Alice to deposit to Zeto should succeed", async function () {
const startingBalance = await erc20.balanceOf(Alice.ethAddress);
const tx = await erc20.connect(deployer).mint(Alice.ethAddress, 100);
await tx.wait();
const balance = await erc20.balanceOf(Alice.ethAddress);
expect(balance).to.be.gte(100);
const endingBalance = await erc20.balanceOf(Alice.ethAddress);
expect(endingBalance - startingBalance).to.be.equal(100);

const tx1 = await erc20.connect(Alice.signer).approve(zeto.target, 100);
await tx1.wait();
Expand Down Expand Up @@ -117,6 +118,8 @@ describe("Zeto based fungible token with anonymity without encryption or nullifi
});

it("Alice withdraws her UTXOs to ERC20 tokens should succeed", async function () {
const startingBalance = await erc20.balanceOf(Alice.ethAddress);

// Alice proposes the output ERC20 tokens
const outputCommitment = newUTXO(20, Alice);

Expand All @@ -127,8 +130,8 @@ describe("Zeto based fungible token with anonymity without encryption or nullifi
await tx.wait();

// Alice checks her ERC20 balance
const balance = await erc20.balanceOf(Alice.ethAddress);
expect(balance).to.be.gte(80);
const endingBalance = await erc20.balanceOf(Alice.ethAddress);
expect(endingBalance - startingBalance).to.be.equal(80);
});

describe('failure cases', function () {
Expand Down
10 changes: 6 additions & 4 deletions solidity/test/zeto_anon_enc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,11 @@ describe("Zeto based fungible token with anonymity and encryption", function ()
});

it("mint ERC20 tokens to Alice to deposit to Zeto should succeed", async function () {
const startingBalance = await erc20.balanceOf(Alice.ethAddress);
const tx = await erc20.connect(deployer).mint(Alice.ethAddress, 100);
await tx.wait();
const balance = await erc20.balanceOf(Alice.ethAddress);
expect(balance).to.be.gte(100);
const endingBalance = await erc20.balanceOf(Alice.ethAddress);
expect(endingBalance - startingBalance).to.be.equal(100);

const tx1 = await erc20.connect(Alice.signer).approve(zeto.target, 100);
await tx1.wait();
Expand Down Expand Up @@ -114,6 +115,7 @@ describe("Zeto based fungible token with anonymity and encryption", function ()
});

it("Alice withdraws her UTXOs to ERC20 tokens should succeed", async function () {
const startingBalance = await erc20.balanceOf(Alice.ethAddress);
// Alice proposes the output ERC20 tokens
const outputCommitment = newUTXO(20, Alice);

Expand All @@ -124,8 +126,8 @@ describe("Zeto based fungible token with anonymity and encryption", function ()
await tx.wait();

// Alice checks her ERC20 balance
const balance = await erc20.balanceOf(Alice.ethAddress);
expect(balance).to.be.gte(80);
const endingBalance = await erc20.balanceOf(Alice.ethAddress);
expect(endingBalance - startingBalance).to.be.equal(80);
});

describe("failure cases", function () {
Expand Down
11 changes: 7 additions & 4 deletions solidity/test/zeto_anon_enc_nullifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,11 @@ describe("Zeto based fungible token with anonymity using nullifiers and encrypti
});

it("mint ERC20 tokens to Alice to deposit to Zeto should succeed", async function () {
const startingBalance = await erc20.balanceOf(Alice.ethAddress);
const tx = await erc20.connect(deployer).mint(Alice.ethAddress, 100);
await tx.wait();
const balance = await erc20.balanceOf(Alice.ethAddress);
expect(balance).to.be.gte(100);
const endingBalance = await erc20.balanceOf(Alice.ethAddress);
expect(endingBalance - startingBalance).to.be.equal(100);

const tx1 = await erc20.connect(Alice.signer).approve(zeto.target, 100);
await tx1.wait();
Expand Down Expand Up @@ -179,6 +180,8 @@ describe("Zeto based fungible token with anonymity using nullifiers and encrypti
}).timeout(600000);

it("Alice withdraws her UTXOs to ERC20 tokens should succeed", async function () {
const startingBalance = await erc20.balanceOf(Alice.ethAddress);

// Alice generates the nullifiers for the UTXOs to be spent
const nullifier1 = newNullifier(utxo100, Alice);

Expand All @@ -198,8 +201,8 @@ describe("Zeto based fungible token with anonymity using nullifiers and encrypti
await tx.wait();

// Alice checks her ERC20 balance
const balance = await erc20.balanceOf(Alice.ethAddress);
expect(balance).to.be.gte(80);
const endingBalance = await erc20.balanceOf(Alice.ethAddress);
expect(endingBalance - startingBalance).to.be.equal(80);
});

describe("failure cases", function () {
Expand Down
10 changes: 6 additions & 4 deletions solidity/test/zeto_anon_enc_nullifier_non_repudiation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,11 @@ describe("Zeto based fungible token with anonymity using nullifiers and encrypti
});

it("mint ERC20 tokens to Alice to deposit to Zeto should succeed", async function () {
const startingBalance = await erc20.balanceOf(Alice.ethAddress);
const tx = await erc20.connect(deployer).mint(Alice.ethAddress, 100);
await tx.wait();
const balance = await erc20.balanceOf(Alice.ethAddress);
expect(balance).to.be.gte(100);
const endingBalance = await erc20.balanceOf(Alice.ethAddress);
expect(endingBalance - startingBalance).to.be.equal(100);

const tx1 = await erc20.connect(Alice.signer).approve(zeto.target, 100);
await tx1.wait();
Expand Down Expand Up @@ -216,6 +217,7 @@ describe("Zeto based fungible token with anonymity using nullifiers and encrypti
}).timeout(600000);

it("Alice withdraws her UTXOs to ERC20 tokens should succeed", async function () {
const startingBalance = await erc20.balanceOf(Alice.ethAddress);
// Alice generates the nullifiers for the UTXOs to be spent
const nullifier1 = newNullifier(utxo100, Alice);

Expand All @@ -235,8 +237,8 @@ describe("Zeto based fungible token with anonymity using nullifiers and encrypti
await tx.wait();

// Alice checks her ERC20 balance
const balance = await erc20.balanceOf(Alice.ethAddress);
expect(balance).to.be.gte(80);
const endingBalance = await erc20.balanceOf(Alice.ethAddress);
expect(endingBalance - startingBalance).to.be.equal(80);
});

describe("failure cases", function () {
Expand Down
11 changes: 7 additions & 4 deletions solidity/test/zeto_anon_nullifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,11 @@ describe("Zeto based fungible token with anonymity using nullifiers without encr
});

it("mint ERC20 tokens to Alice to deposit to Zeto should succeed", async function () {
const startingBalance = await erc20.balanceOf(Alice.ethAddress);
const tx = await erc20.connect(deployer).mint(Alice.ethAddress, 100);
await tx.wait();
const balance = await erc20.balanceOf(Alice.ethAddress);
expect(balance).to.be.gte(100);
const endingBalance = await erc20.balanceOf(Alice.ethAddress);
expect(endingBalance - startingBalance).to.be.equal(100);

const tx1 = await erc20.connect(Alice.signer).approve(zeto.target, 100);
await tx1.wait();
Expand Down Expand Up @@ -181,6 +182,8 @@ describe("Zeto based fungible token with anonymity using nullifiers without encr
}).timeout(600000);

it("Alice withdraws her UTXOs to ERC20 tokens should succeed", async function () {
const startingBalance = await erc20.balanceOf(Alice.ethAddress);

// Alice generates the nullifiers for the UTXOs to be spent
const nullifier1 = newNullifier(utxo100, Alice);

Expand All @@ -200,8 +203,8 @@ describe("Zeto based fungible token with anonymity using nullifiers without encr
await tx.wait();

// Alice checks her ERC20 balance
const balance = await erc20.balanceOf(Alice.ethAddress);
expect(balance).to.be.gte(80);
const endingBalance = await erc20.balanceOf(Alice.ethAddress);
expect(endingBalance - startingBalance).to.be.equal(80);
});

describe("failure cases", function () {
Expand Down
15 changes: 9 additions & 6 deletions solidity/test/zeto_anon_nullifier_kyc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,11 @@ describe("Zeto based fungible token with anonymity, KYC, using nullifiers withou
});

it("mint ERC20 tokens to Alice to deposit to Zeto should succeed", async function () {
const startingBalance = await erc20.balanceOf(Alice.ethAddress);
const tx = await erc20.connect(deployer).mint(Alice.ethAddress, 100);
await tx.wait();
const balance = await erc20.balanceOf(Alice.ethAddress);
expect(balance).to.be.gte(100);
const endingBalance = await erc20.balanceOf(Alice.ethAddress);
expect(endingBalance - startingBalance).to.be.equal(100);

const tx1 = await erc20.connect(Alice.signer).approve(zeto.target, 100);
await tx1.wait();
Expand Down Expand Up @@ -226,6 +227,7 @@ describe("Zeto based fungible token with anonymity, KYC, using nullifiers withou
}).timeout(600000);

it("Alice withdraws her UTXOs to ERC20 tokens should succeed", async function () {
const startingBalance = await erc20.balanceOf(Alice.ethAddress);
// Alice generates the nullifiers for the UTXOs to be spent
const nullifier1 = newNullifier(utxo100, Alice);

Expand All @@ -244,8 +246,8 @@ describe("Zeto based fungible token with anonymity, KYC, using nullifiers withou
await tx.wait();

// Alice checks her ERC20 balance
const balance = await erc20.balanceOf(Alice.ethAddress);
expect(balance).to.be.gte(80);
const endingBalance = await erc20.balanceOf(Alice.ethAddress);
expect(endingBalance - startingBalance).to.be.equal(80);
});

describe("unregistered user flows", function () {
Expand Down Expand Up @@ -303,6 +305,7 @@ describe("Zeto based fungible token with anonymity, KYC, using nullifiers withou
});

it("the unregistered user can still withdraw their UTXOs to ERC20 tokens", async function () {
const startingBalance = await erc20.balanceOf(unregistered.ethAddress);
// unregistered user generates the nullifiers for the UTXOs to be spent
const nullifier1 = newNullifier(unregisteredUtxo100, unregistered);

Expand All @@ -322,8 +325,8 @@ describe("Zeto based fungible token with anonymity, KYC, using nullifiers withou
await tx.wait();

// unregistered user checks her ERC20 balance
const balance = await erc20.balanceOf(unregistered.ethAddress);
expect(balance).to.be.gte(100);
const endingBalance = await erc20.balanceOf(unregistered.ethAddress);
expect(endingBalance - startingBalance).to.be.equal(100);
});
});

Expand Down

0 comments on commit f8b7cc9

Please sign in to comment.