Skip to content

Commit

Permalink
test: updates BigInt(0)/BigInt(1) to 0n/1n etc
Browse files Browse the repository at this point in the history
  • Loading branch information
PacificYield committed Dec 2, 2024
1 parent dd825a9 commit 72d058f
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 32 deletions.
2 changes: 1 addition & 1 deletion test/encryptedERC20/EncryptedERC20.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { deployEncryptedERC20Fixture, reencryptAllowance, reencryptBalance } fro

describe("EncryptedERC20", function () {
// @dev The placeholder is type(uint256).max --> 2**256 - 1.
const PLACEHOLDER = BigInt(2) ** BigInt(256) - BigInt(1);
const PLACEHOLDER = 2n ** 256n - 1n;

before(async function () {
await initSigners(2);
Expand Down
6 changes: 3 additions & 3 deletions test/encryptedERC20/EncryptedERC20WithErrors.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ export async function checkErrorCode(
const errorCodeHandle = await token.getErrorCodeForTransferId(transferId);
const errorCode = await reencryptEuint8(signers, instances, account, errorCodeHandle, tokenAddress);
switch (errorCode) {
case BigInt(0): {
case 0n: {
return "NO_ERROR";
}
case BigInt(1): {
case 1n: {
return "UNSUFFICIENT_BALANCE";
}
case BigInt(2): {
case 2n: {
return "UNSUFFICIENT_APPROVAL";
}
default: {
Expand Down
10 changes: 5 additions & 5 deletions test/encryptedERC20/EncryptedERC20WithErrors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { checkErrorCode, deployEncryptedERC20WithErrorsFixture } from "./Encrypt

describe("EncryptedERC20WithErrors", function () {
// @dev The placeholder is type(uint256).max --> 2**256 - 1.
const PLACEHOLDER = BigInt(2) ** BigInt(256) - BigInt(1);
const PLACEHOLDER = 2n ** 256n - 1n;

before(async function () {
await initSigners(2);
Expand Down Expand Up @@ -43,7 +43,7 @@ describe("EncryptedERC20WithErrors", function () {
it("should transfer tokens between two users", async function () {
const mintAmount = 10_000;
const transferAmount = 1337;
const expectedTransferId = BigInt(0);
const expectedTransferId = 0n;

let tx = await this.encryptedERC20.connect(this.signers.alice).mint(mintAmount);
await tx.wait();
Expand Down Expand Up @@ -102,7 +102,7 @@ describe("EncryptedERC20WithErrors", function () {
// amount.
const mintAmount = 1000;
const transferAmount = 1337;
const expectedTransferId = BigInt(0);
const expectedTransferId = 0n;

let tx = await this.encryptedERC20.connect(this.signers.alice).mint(mintAmount);
await tx.wait();
Expand Down Expand Up @@ -182,7 +182,7 @@ describe("EncryptedERC20WithErrors", function () {
),
).to.equal(transferAmount);

const expectedTransferId1 = BigInt(0);
const expectedTransferId1 = 0n;

const inputBob1 = this.instances.bob.createEncryptedInput(this.encryptedERC20Address, this.signers.bob.address);
inputBob1.add64(transferAmount + 1); // above allowance so next tx should actually not send any token
Expand Down Expand Up @@ -220,7 +220,7 @@ describe("EncryptedERC20WithErrors", function () {
),
).to.equal("UNSUFFICIENT_APPROVAL");

const expectedTransferId2 = BigInt(1);
const expectedTransferId2 = 1n;

const inputBob2 = this.instances.bob.createEncryptedInput(this.encryptedERC20Address, this.signers.bob.address);
inputBob2.add64(transferAmount); // below allowance so next tx should send token
Expand Down
9 changes: 4 additions & 5 deletions test/governance/Comp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import { delegateBySig } from "./DelegateBySig";

describe("Comp", function () {
// @dev The placeholder is type(uint256).max --> 2**256 - 1.
const PLACEHOLDER = BigInt(2) ** BigInt(256) - BigInt(1);

const PLACEHOLDER = 2n ** 256n - 1n;
const NULL_ADDRESS = "0x0000000000000000000000000000000000000000";

before(async function () {
Expand Down Expand Up @@ -301,7 +300,7 @@ describe("Comp", function () {
it("getCurrentVote/getPriorVotes without any vote cannot be decrypted", async function () {
// 1. If no checkpoint exists using getCurrentVotes
let currentVoteHandle = await this.comp.connect(this.signers.bob).getCurrentVotes(this.signers.bob.address);
expect(currentVoteHandle).to.be.eq(BigInt(0));
expect(currentVoteHandle).to.be.eq(0n);

await expect(
reencryptEuint64(this.signers, this.instances, "bob", currentVoteHandle, this.comp),
Expand All @@ -316,7 +315,7 @@ describe("Comp", function () {
.getPriorVotes(this.signers.bob.address, latestBlockNumber);

// It is an encrypted constant that is not reencryptable by Bob.
expect(currentVoteHandle).not.to.be.eq(BigInt(0));
expect(currentVoteHandle).not.to.be.eq(0n);

await expect(
reencryptEuint64(this.signers, this.instances, "bob", currentVoteHandle, this.comp),
Expand All @@ -334,7 +333,7 @@ describe("Comp", function () {
.getPriorVotes(this.signers.bob.address, latestBlockNumber);

// It is an encrypted constant that is not reencryptable by Bob.
expect(currentVoteHandle).not.to.be.eq(BigInt(0));
expect(currentVoteHandle).not.to.be.eq(0n);

await expect(
reencryptEuint64(this.signers, this.instances, "bob", currentVoteHandle, this.comp),
Expand Down
30 changes: 15 additions & 15 deletions test/governance/GovernorAlphaZama.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ describe("GovernorAlphaZama", function () {
await expect(tx)
.to.emit(this.governor, "ProposalCreated")
.withArgs(
BigInt(1),
1n,
this.signers.bob.address,
targets,
values,
signatures,
calldatas,
blockNumber + this.VOTING_DELAY + BigInt(1), // @dev We add one since the transaction incremented the block number
blockNumber + this.VOTING_DELAY + this.VOTING_PERIOD + BigInt(1),
blockNumber + this.VOTING_DELAY + 1n, // @dev We add one since the transaction incremented the block number
blockNumber + this.VOTING_DELAY + this.VOTING_PERIOD + 1n,
description,
);

Expand All @@ -103,7 +103,7 @@ describe("GovernorAlphaZama", function () {
});

it("anyone can propose a vote but it is rejected if votes are below the token threshold", async function () {
const transferAmount = (await this.governor.PROPOSAL_THRESHOLD()) - BigInt(1);
const transferAmount = (await this.governor.PROPOSAL_THRESHOLD()) - 1n;
const targets = [this.signers.bob.address];
const values = ["0"];
const signatures = ["getBalanceOf(address)"];
Expand Down Expand Up @@ -189,7 +189,7 @@ describe("GovernorAlphaZama", function () {

await expect(tx).to.emit(this.governor, "VoteCast").withArgs(
this.signers.bob,
BigInt(1), // @dev proposalId
1n, // @dev proposalId
);

input = this.instances.carol.createEncryptedInput(this.governorAddress, this.signers.carol.address);
Expand All @@ -201,7 +201,7 @@ describe("GovernorAlphaZama", function () {

await expect(tx).to.emit(this.governor, "VoteCast").withArgs(
this.signers.carol,
BigInt(1), // @dev proposalId
1n, // @dev proposalId
);

// Bob/Carol can reeencrypt his/her receipt
Expand Down Expand Up @@ -247,7 +247,7 @@ describe("GovernorAlphaZama", function () {
// POST-DECRYPTION RESULTS
await awaitAllDecryptionResults();
proposalInfo = await this.governor.getProposalInfo(proposalId);
expect(proposalInfo.forVotes).to.be.eq(transferAmount * BigInt(2));
expect(proposalInfo.forVotes).to.be.eq(transferAmount * 2n);
expect(proposalInfo.againstVotes).to.be.eq(parseUnits(String(0), 6));
// 7 ==> Succeeded
expect(proposalInfo.state).to.equal(7);
Expand All @@ -268,7 +268,7 @@ describe("GovernorAlphaZama", function () {
await expect(tx)
.to.emit(this.governor, "ProposalQueued")
.withArgs(
BigInt(1), // @dev proposalId,
1n, // @dev proposalId,
nextBlockTimestamp + this.TIMELOCK_DELAY,
);

Expand All @@ -282,7 +282,7 @@ describe("GovernorAlphaZama", function () {
await ethers.provider.send("evm_setNextBlockTimestamp", [eta.toString()]);
tx = await this.governor.execute(proposalId);
await expect(tx).to.emit(this.governor, "ProposalExecuted").withArgs(
BigInt(1), // @dev proposalId
1n, // @dev proposalId
);

proposalInfo = await this.governor.getProposalInfo(proposalId);
Expand All @@ -296,7 +296,7 @@ describe("GovernorAlphaZama", function () {
const signatures = ["getBalanceOf(address)"];
const calldatas = [ethers.AbiCoder.defaultAbiCoder().encode(["address"], [this.signers.bob.address])];
const description = "description";
const transferAmount = (await this.governor.QUORUM_VOTES()) - BigInt(1);
const transferAmount = (await this.governor.QUORUM_VOTES()) - 1n;

// Bob receives enough to create a proposal but not enough to match the quorum.
await transferTokensAndDelegate(
Expand Down Expand Up @@ -474,7 +474,7 @@ describe("GovernorAlphaZama", function () {
if (block === null) {
throw "Block is null. Check RPC config.";
} else {
expiry = BigInt(block.timestamp) + this.TIMELOCK_DELAY + BigInt(1);
expiry = BigInt(block.timestamp) + this.TIMELOCK_DELAY + 1n;
}

const tx = await this.governor.queueSetTimelockPendingAdmin(this.signers.bob, expiry);
Expand Down Expand Up @@ -511,7 +511,7 @@ describe("GovernorAlphaZama", function () {
if (block === null) {
throw "Block is null. Check RPC config.";
} else {
expiry2 = BigInt(block.timestamp) + this.TIMELOCK_DELAY + BigInt(1);
expiry2 = BigInt(block.timestamp) + this.TIMELOCK_DELAY + 1n;
}

const timeLockAdd = this.timelockAddress;
Expand Down Expand Up @@ -727,7 +727,7 @@ describe("GovernorAlphaZama", function () {
});

it("cannot cancel if state is Rejected/Defeated/Executed/Canceled", async function () {
let transferAmount = (await this.governor.PROPOSAL_THRESHOLD()) - BigInt(1);
let transferAmount = (await this.governor.PROPOSAL_THRESHOLD()) - 1n;
const targets = [this.signers.bob.address];
const values = ["0"];
const signatures = ["getBalanceOf(address)"];
Expand Down Expand Up @@ -757,7 +757,7 @@ describe("GovernorAlphaZama", function () {
);

// CANNOT CANCEL IF DEFEATED
transferAmount = (await this.governor.QUORUM_VOTES()) - BigInt(1);
transferAmount = (await this.governor.QUORUM_VOTES()) - 1n;

await transferTokensAndDelegate(
this.signers,
Expand Down Expand Up @@ -912,7 +912,7 @@ describe("GovernorAlphaZama", function () {
// @dev Alice is the governor's owner.
tx = await this.governor.connect(this.signers.alice).cancel(proposalId);
await expect(tx).to.emit(this.governor, "ProposalCanceled").withArgs(
BigInt(1), // @dev proposalId
1n, // @dev proposalId
);

// 5 ==> Canceled
Expand Down
6 changes: 3 additions & 3 deletions test/utils/EncryptedErrors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { getSigners, initSigners } from "../signers";
import { deployEncryptedErrors } from "./EncryptedErrors.fixture";

describe("EncryptedErrors", function () {
const NO_ERROR_CODE = BigInt(0);
const NO_ERROR_CODE = 0n;

before(async function () {
await initSigners(3);
Expand Down Expand Up @@ -201,7 +201,7 @@ describe("EncryptedErrors", function () {

it("cannot define errors if indexCode is greater or equal than totalNumberErrorCodes", async function () {
const condition = true;
const targetErrorCode = (await this.encryptedErrors.errorGetNumCodesDefined()) + BigInt(1);
const targetErrorCode = (await this.encryptedErrors.errorGetNumCodesDefined()) + 1n;

const input = this.instances.alice.createEncryptedInput(this.encryptedErrorsAddress, this.signers.alice.address);
const encryptedData = await input.addBool(condition).encrypt();
Expand Down Expand Up @@ -242,7 +242,7 @@ describe("EncryptedErrors", function () {
it("cannot change errors if indexCode is greater or equal than totalNumberErrorCodes", async function () {
const condition = true;
const errorCode = 1;
const targetErrorCode = (await this.encryptedErrors.errorGetNumCodesDefined()) + BigInt(1);
const targetErrorCode = (await this.encryptedErrors.errorGetNumCodesDefined()) + 1n;

const input = this.instances.alice.createEncryptedInput(this.encryptedErrorsAddress, this.signers.alice.address);
const encryptedData = await input.addBool(condition).add8(errorCode).encrypt();
Expand Down

0 comments on commit 72d058f

Please sign in to comment.