-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6742fa1
commit b095982
Showing
4 changed files
with
534 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { ethers } from "hardhat"; | ||
|
||
import type { EncryptedERC20WithErrorsMintable } from "../../types"; | ||
import { reencryptEuint8 } from "../reencrypt"; | ||
import { Signers } from "../signers"; | ||
import { FhevmInstances } from "../types"; | ||
|
||
export async function deployEncryptedERC20WithErrorsFixture( | ||
signers: Signers, | ||
name: string, | ||
symbol: string, | ||
owner: string, | ||
): Promise<EncryptedERC20WithErrorsMintable> { | ||
const contractFactory = await ethers.getContractFactory("EncryptedERC20WithErrorsMintable"); | ||
const contract = await contractFactory | ||
.connect(signers[owner as keyof Signers]) | ||
.deploy(name, symbol, signers[owner as keyof Signers].address); | ||
await contract.waitForDeployment(); | ||
return contract; | ||
} | ||
|
||
export async function checkErrorCode( | ||
signers: Signers, | ||
instances: FhevmInstances, | ||
user: string, | ||
transferId: bigint, | ||
token: EncryptedERC20WithErrorsMintable, | ||
tokenAddress: string, | ||
): Promise<string> { | ||
const errorCodeHandle = await token.getErrorCodeForTransferId(transferId); | ||
const errorCode = await reencryptEuint8(signers, instances, user, errorCodeHandle, tokenAddress); | ||
switch (errorCode) { | ||
case BigInt(0): { | ||
return "NO_ERROR"; | ||
} | ||
case BigInt(1): { | ||
return "UNSUFFICIENT_BALANCE"; | ||
} | ||
case BigInt(2): { | ||
return "UNSUFFICIENT_APPROVAL"; | ||
} | ||
default: { | ||
throw "Error code is invalid"; | ||
} | ||
} | ||
} |
Oops, something went wrong.